Files
tl-rtc-file/static/js/scroxt.min.js

1 line
17 KiB
JavaScript

!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var r in i)("object"==typeof exports?exports:t)[r]=i[r]}}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,e),n.l=!0,n.exports}var i={};return e.m=t,e.c=i,e.d=function(t,i,r){e.o(t,i)||Object.defineProperty(t,i,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var i=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(i,"a",i),i},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=5)}([function(t,e,i){"use strict";var r=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,1e3/60)}}();e.a=r},function(t,e,i){"use strict";var r=function(){return window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.clearTimeout}();e.a=r},function(t,e,i){"use strict";function r(t,e){return Object(n.a)(t)?window.getComputedStyle(t,null).getPropertyValue(e):"string"==typeof t&&document.querySelector(t)?window.getComputedStyle(document.querySelector(t),null).getPropertyValue(e):void 0}e.a=r;var n=i(7)},function(t,e,i){"use strict";function r(t){var e=document.createElement("style"),i=document.head||document.getElementsByTagName("head")[0];if(e.type="text/css",e.styleSheet){var r=function(){try{e.styleSheet.cssText=t}catch(t){console.error(t)}};e.styleSheet.disabled?setTimeout(r,10):r()}else{var n=document.createTextNode(t);e.appendChild(n)}i.appendChild(e)}e.a=r},function(t,e,i){"use strict";var r=function(){function t(t){t.target,t.data,t.speed;this.options={target:"",data:[],speed:5},this.extendOpt(arguments[0]),this.targetElement=document.querySelector(this.options.target)}return t.prototype.extendOpt=function(t){var e=this;for(var i in t)t.hasOwnProperty(i)&&(e.options[i]=t[i])},t.prototype.createElement=function(t){void 0===t&&(t="");var e=[];this.scroxtWrapper||(this.scroxtWrapper=document.createElement("div"),this.scroxtWrapper.className="scroxt-wrapper",this.targetElement=document.querySelector(this.options.target),this.targetElement.appendChild(this.scroxtWrapper));for(var i=0,r=this.options.data.length;i<r;i++){var n=document.createElement("div");n.className=t;var a=this.options.data[i];n.innerHTML=a,this.scroxtWrapper.appendChild(n),e.push(n)}return e},t.prototype.emptyElement=function(){this.scroxtWrapper&&(this.scroxtWrapper.innerHTML="")},t}();e.a=r},function(t,e,i){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=i(6),n=i(8),a=i(9),o=i(11),s={};Object.defineProperty(s,"Horizontal",{value:r.a,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(s,"Vertical",{value:n.a,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(s,"Barrage",{value:a.a,writable:!1,enumerable:!1,configurable:!1}),Object.defineProperty(s,"Live",{value:o.a,writable:!1,enumerable:!1,configurable:!1}),window.scroxt=s,e.default=s},function(t,e,i){"use strict";var r=i(4),n=i(0),a=i(1),o=i(2),s=i(3),h=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}(),p=function(t){function e(e){var i=e.target,r=e.data,n=e.speed,a=e.gap,o=void 0===a?10:a,s=t.call(this,{target:i,data:r,speed:n})||this;return s.sumWidth=0,s.distance=0,s.targetWidth=0,s.divWrapElementWidth=0,s.targetElementBorderWidth=0,s.ST=0,s.scroxtGap=o,s.createStyle(),s.init(),s}return h(e,t),e.prototype.createStyle=function(){Object(s.a)('\n .scroxt-wrapper::after{\n display: block;\n content: "";\n clear: both;\n }\n .scroxt-horizontal{\n float: left;\n margin-right: '+this.scroxtGap+"px;\n white-space: nowrap;\n box-sizing: border-box;\n }\n ")},e.prototype.init=function(){if(this.targetWidth=parseFloat(Object(o.a)(this.targetElement,"width")),this.targetElementBorderWidth=parseFloat(Object(o.a)(this.targetElement,"border-width")),this.createHorizontal(),this.divWrapElementWidth/2<this.targetWidth){this.emptyElement();var t=this.createElement("scroxt-horizontal");return this.divWrapElementWidth=this.computeWidth(t)+t.length*this.scroxtGap,this.scroxtWrapper.style.width=this.divWrapElementWidth+"px",void(this.scroxtWrapper.style.marginLeft="0px")}this.STRun()},e.prototype.createHorizontal=function(){this.emptyElement();var t=this.createElement("scroxt-horizontal"),e=this.createElement("scroxt-horizontal"),i=t.concat(e);this.divWrapElementWidth=this.computeWidth(i)+i.length*this.scroxtGap,this.scroxtWrapper.style.width=this.divWrapElementWidth+"px"},e.prototype.computeWidth=function(t){for(var e=0,i=0,r=t.length;i<r;i++)e+=Math.ceil(+Object(o.a)(t[i],"width").replace("px",""));return e},e.prototype.STRun=function(){this.divWrapElementWidth/2<this.targetWidth||(this.STMove(),this.ST=Object(n.a)(function(){this.STRun()}.bind(this)))},e.prototype.STMove=function(){var t=this.scroxtWrapper.getBoundingClientRect(),e=t.left+(t.right-t.left)/2,i=this.targetElement.getBoundingClientRect();if(this.options.speed<0){var r=i.left+this.targetElementBorderWidth;e+.1*this.options.speed<=r&&(this.distance=0,this.createHorizontal(),this.scroxtWrapper.style.left="0px",this.scroxtWrapper.style.marginLeft="0px")}else{var n=i.right-2*this.targetElementBorderWidth;e+.1*this.options.speed>=n&&(this.distance=-this.divWrapElementWidth+this.targetWidth,this.createHorizontal(),this.scroxtWrapper.style.right="0px",this.scroxtWrapper.style.marginRight="0px")}this.scroxtWrapper.style.transform="translate3d("+this.distance+"px, 0px, 0px)",this.scroxtWrapper.style.webkitTransform="translate3d("+this.distance+"px, 0px, 0px)",this.distance+=.1*this.options.speed},e.prototype.stopMove=function(){Object(a.a)(this.ST),this.ST=0},e.prototype.startMove=function(){0===this.ST&&this.STRun()},e}(r.a);e.a=p},function(t,e,i){"use strict";function r(t){return!(!t||!t.nodeType)&&1===t.nodeType}e.a=r},function(t,e,i){"use strict";var r=i(4),n=i(0),a=i(1),o=i(2),s=i(3),h=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}(),p=function(t){function e(e){var i=t.call(this,e)||this;return i.targetHeight=0,i.divWrapElementHeight=0,i.distance=0,i.ST=0,i.targetHeight=parseFloat(Object(o.a)(i.targetElement,"height")),i.createStyle(),i.startRun(),i}return h(e,t),e.prototype.startRun=function(){if(this.divWrapElementHeight=this.createVertical(),this.targetHeight>this.divWrapElementHeight/2)return this.emptyElement(),void this.createElement("scroxt-vertical");this.STRun()},e.prototype.createStyle=function(){Object(s.a)("\n .scroxt-vertical{\n box-sizing: border-box;\n }\n ")},e.prototype.createVertical=function(){this.emptyElement();var t=this.createElement("scroxt-vertical"),e=this.createElement("scroxt-vertical");return this.computeHeight(t.concat(e))},e.prototype.computeHeight=function(t){for(var e=0,i=0,r=t.length;i<r;i++)e+=Math.ceil(+Object(o.a)(t[i],"height").replace("px",""));return e},e.prototype.STRun=function(){this.targetHeight>this.divWrapElementHeight/2||(this.STMove(),this.ST=Object(n.a)(function(){this.STRun()}.bind(this)))},e.prototype.STMove=function(){this.options.speed<0?this.distance<=-this.divWrapElementHeight/2&&(this.createVertical(),this.distance=0):this.distance>=this.targetHeight-this.divWrapElementHeight/2&&(this.createVertical(),this.distance=this.targetHeight-this.divWrapElementHeight),this.scroxtWrapper.style.transform="translate3d(0px, "+this.distance+"px, 0px)",this.scroxtWrapper.style.webkitTransform="translate3d(0px, "+this.distance+"px, 0px)",this.distance+=.1*this.options.speed},e.prototype.stopMove=function(){Object(a.a)(this.ST),this.ST=0},e.prototype.startMove=function(){0===this.ST&&this.STRun()},e}(r.a);e.a=p},function(t,e,i){"use strict";var r=i(0),n=i(1),a=i(2),o=i(10),s=i(3),h=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])};return function(e,i){function r(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}(),p=function(t){function e(e){var i=e.video,r=e.dataTime,n=t.call(this)||this;return n.videoEnd=!1,n.barrageWrap=[],n.readyShowBarrage=[],n.staticBarrageST=null,n.runST=0,n.video=i,n.scroxtVideo=document.querySelector(n.video),n.dataTime=n.quickSort(r),console.log(n.dataTime),n.tempDataTime=JSON.parse(JSON.stringify(n.dataTime)),n.lineHeight=28,n.videoWidth=parseInt(Object(a.a)(n.video,"width")),n.MAX_LINE=~~(parseInt(Object(a.a)(n.video,"height"))/n.lineHeight),n.MAX_NUM=50,n.distance=-5,n.colorFont=["#ffff38","#c80115","#189add"],n.createStyle(),n.startRun(),n}return h(e,t),e.prototype.quickSort=function(t){if(t.length<=1)return t;for(var e=t.splice(Math.floor(t.length/2),1)[0],i=[],r=[],n=0,a=t.length;n<a;n++)t[n].time<e.time?i.push(t[n]):r.push(t[n]);return this.quickSort(i).concat(e,this.quickSort(r))},e.prototype.createStyle=function(){Object(s.a)('\n .multi-barrage-line{\n position: absolute;\n display: inline-block;\n top: 0;\n user-select:none;\n white-space: pre;\n color: #fff;\n font-size: 25px;\n font-family:SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;\n font-weight:bold;\n line-height: 1.125;\n text-shadow:rgb(0, 0, 0) 1px 0px 1px, rgb(0, 0, 0) 0px 1px 1px, rgb(0, 0, 0) 0px -1px 1px, rgb(0, 0, 0) -1px 0px 1px;\n transition:-webkit-transform 0s linear;\n z-index: 1;\n pointer-events: none;\n }\n .static-barrage-line{\n position: absolute;\n left: 50%;\n transform:translateX(-50%);\n -webkit-transform:translateX(-50%);\n top: 0;\n z-index: 2;\n }\n ')},e.prototype.startRun=function(){var t=this.scroxtVideo.className;this.scroxtVideo.className=t.indexOf("scroxt-video")>-1?t:t+" scroxt-video",this.timeUpdate()},e.prototype.play=function(){this.scroxtVideo.paused&&(this.scroxtVideo.play(),this.intervalRun())},e.prototype.stop=function(){this.scroxtVideo.paused||(this.scroxtVideo.pause(),this.intervalStop())},e.prototype.restart=function(){this.readyShowBarrage=[],this.tempDataTime=JSON.parse(JSON.stringify(this.dataTime)),this.scroxtVideo.currentTime=0,this.barrageWrap.forEach(function(t,e){var i=t.element.parentNode;i&&i.removeChild(t.element)}),this.barrageWrap=[]},e.prototype.moveInterval=function(t){void 0===t&&(t=0),this.readyShowBarrage=[],this.tempDataTime=JSON.parse(JSON.stringify(this.dataTime)),this.scroxtVideo.currentTime+=t,this.barrageWrap.forEach(function(t,e){var i=t.element.parentNode;i&&i.removeChild(t.element)}),this.barrageWrap=[]},e.prototype.timeUpdate=function(){this.scroxtVideo.addEventListener("timeupdate",function(){this.distribution(this.scroxtVideo.currentTime)}.bind(this))},e.prototype.distribution=function(t){for(var e=this.tempDataTime.length;0!==e&&this.tempDataTime[0].time<t;)this.tempDataTime[0].time>=t-2&&this.readyShowBarrage.push(this.tempDataTime[0].data),this.tempDataTime.shift(),e=this.tempDataTime.length},e.prototype.createBarrage=function(){var t=this.readyShowBarrage.length;if(t&&!(this.barrageWrap.length>this.MAX_NUM))for(var e=0;e<t;e++){if(e>this.MAX_LINE){t>20&&!this.staticBarrageST&&this.createStaticBarrage(this.readyShowBarrage.splice(0,this.MAX_LINE));break}var i=e%this.MAX_LINE,r=document.querySelectorAll("[data-line='"+i+"']"),n=r.length,a=void 0;if(n>0){a=r[n-1];var o=+a.getAttribute("data-width"),s=+a.getAttribute("data-move");if(Math.abs(s)+o>this.videoWidth)continue}var h=this.readyShowBarrage.shift(),p=Math.floor(1e3*Math.random())+ +new Date+e,c=e%2==0?10:0,l=document.createElement("div");l.className="multi-barrage-line";var u=document.createTextNode(""+h);l.appendChild(u),this.scroxtVideo.parentNode.appendChild(l);var d=parseInt(window.getComputedStyle(l,null).getPropertyValue("width")),f=d/600>=.5?.5:d/600,m="#fff";.5===f&&(m=this.colorFont[~~(Math.random()*this.colorFont.length)]),this.barrageWrap.push({element:l,scroxt:p,line:i,move:this.videoWidth+c+10,width:d,distance:f,color:m})}},e.prototype.createStaticBarrage=function(t){for(var e=this,i=0,r=t.length;i<r;i++)!function(i,r){var n=i%e.MAX_LINE,a=document.createElement("div");a.className="multi-barrage-line static-barrage-line",a.style.top=n*e.lineHeight+"px",a.style.color=e.colorFont[~~(Math.random()*e.colorFont.length)];var o=document.createTextNode(""+t[i]);a.appendChild(o),e.staticBarrageST=setTimeout(function(){this.staticBarrageST=null,this.scroxtVideo.parentNode.removeChild(a)}.bind(e),3e3),e.scroxtVideo.parentNode.appendChild(a)}(i)},e.prototype.moveLine=function(){for(var t=0;t<this.barrageWrap.length;t++){var e=this.barrageWrap[t],i=e.element,r=(e.scroxt,e.line),n=e.move,a=e.width,o=e.distance,s=e.color;if(n<=-a){this.barrageWrap.splice(t,1),t--;var h=i.parentNode;h&&h.removeChild(i)}else{var p=n+this.distance*o+this.distance/10;this.barrageWrap[t].move=p,i.style.cssText="color:"+s+";transform:translate3d("+p+"px,"+r*this.lineHeight+"px,0);"}}},e.prototype.intervalRun=function(){this.runST=Object(r.a)(function(){this.createBarrage(),this.moveLine(),this.intervalRun()}.bind(this))},e.prototype.intervalStop=function(){Object(n.a)(this.runST)},e}(o.a);e.a=p},function(t,e,i){"use strict";var r=function(){function t(){this.events={}}return t.prototype.on=function(t,e){this.events[t]?this.events[t].push(e):this.events[t]=[e]},t.prototype.off=function(t,e){this.events[t].splice(this.events[t].indexOf(e),1)},t.prototype.empty=function(t){this.events[t]=[]},t.prototype.triggle=function(t){this.events[t].forEach(function(t){t()})},t}();e.a=r},function(t,e,i){"use strict";var r=i(2),n=i(3),a=i(0),o=i(1),s=function(){function t(t){var e=t.target,i=t.strongLock,n=void 0!==i&&i;this.barrage=[],this.selfBarrage=[],this.barrageWrap={},this.MAX_LINE=4,this.lineHeight=28,this.sumLine=0,this.lineGap=10,this.runST=0,this.targetElement=document.querySelector(e),this.strongLock=n,this.TARGET_WIDTH=parseInt(Object(r.a)(this.targetElement,"width")),this.MAX_LINE=~~(parseInt(Object(r.a)(this.targetElement,"height"))/this.lineHeight),this.gear=-5,this.LINE_LIMIT=300,this.startRun()}return t.prototype.startRun=function(){this.createStyle(),this.intervalRun()},t.prototype.createStyle=function(){Object(n.a)('\n .multi-barrage-line{\n position: absolute;\n display: inline-block;\n top: 0;\n user-select:none;\n white-space: pre;\n color: #fff;\n font-size: 25px;\n font-family:SimHei, "Microsoft JhengHei", Arial, Helvetica, sans-serif;\n font-weight:bold;\n line-height: 1.125;\n text-shadow:rgb(0, 0, 0) 1px 0px 1px, rgb(0, 0, 0) 0px 1px 1px, rgb(0, 0, 0) 0px -1px 1px, rgb(0, 0, 0) -1px 0px 1px;\n transition:-webkit-transform 0s linear;\n z-index: 1;\n pointer-events: none;\n }\n ')},t.prototype.addBarrage=function(t,e){void 0===e&&(e=!1),e?this.selfBarrage.push(t):this.barrage.push(t)},t.prototype.createBarrage=function(){for(var t=0,e=this.barrage.length;e>0&&t<this.MAX_LINE;t++){var i=void 0,r=t%this.MAX_LINE;if(this.selfBarrage.length>0)i=this.selfBarrage.shift();else{if(this.strongLock&&this.sumLine>65){this.barrage=[];break}if(this.barrageWrap[r]){var n=this.barrageWrap[r].length;if(n>0){var a=this.barrageWrap[r][n-1];if(a.move+a.width>this.TARGET_WIDTH-this.lineGap)continue}}i=this.barrage.shift(),e--}this.generateBarrage(r,i)}},t.prototype.generateBarrage=function(t,e){var i=document.createElement("div");i.className="multi-barrage-line";var n=document.createTextNode(e);i.appendChild(n),i.style.opacity="0",this.targetElement.appendChild(i);var a=parseInt(Object(r.a)(i,"width")),o=a/600>=.5?.5:a/600;this.barrageWrap[t]?this.barrageWrap[t].push({element:i,line:t,move:this.TARGET_WIDTH,width:a,speed:o}):this.barrageWrap[t]=[{element:i,line:t,move:this.TARGET_WIDTH,width:a,speed:o}]},t.prototype.moveLine=function(){this.sumLine=0;for(var t in this.barrageWrap){var e=this.barrageWrap[t];this.sumLine+=e.length;for(var i=0;i<e.length;i++){var r=e[i],n=r.element,a=r.line,o=r.move,s=r.width,h=r.speed;if(o<=-s)e.splice(i,1),i--,this.targetElement.removeChild(n);else{var p=o+this.gear*h+this.gear/10;r.move=p,n.style.cssText="transform:translate3d("+p+"px,"+a*this.lineHeight+'px,0);opacity="1";'}}}},t.prototype.intervalRun=function(){this.runST=Object(a.a)(function(){this.moveLine(),this.createBarrage(),this.intervalRun()}.bind(this))},t.prototype.intervalStop=function(){Object(o.a)(this.runST)},t}();e.a=s}])});