diff --git a/README.md b/README.md index 7007a23..331ee66 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ gem 'rails-assets-comment-core-library' - [Documentation](docs/) can be found inside the `docs/` folder. - Some sample extension modules may be found in `src/extend/`. - Experimental modules are in `experimental/`. -- You may test using test data found in `tests/`. +- You may test using test data found in `test/`. ## Contributing We encourage any contributions to this project, please read @@ -79,7 +79,7 @@ implementation of a video player with CommentCoreLibrary. - 有关本项目的[文档](docs/) 可以在 `docs/` 文件夹里面找到。 - 一些功能性扩展模块会出现在 `src/extend/` 中。 - 一些实验性模块在 `experimental/` 里。 -- 测试数据在 `tests/` 里。 +- 测试数据在 `test/` 里。 ## 做出贡献 非常欢迎提交问题报告和意见建议,同时你也可以在GitHub上Fork本工程,并发送Pull请求来提交 diff --git a/build/CommentCoreLibrary.js b/build/CommentCoreLibrary.js index 2cef58b..51b175d 100644 --- a/build/CommentCoreLibrary.js +++ b/build/CommentCoreLibrary.js @@ -34,7 +34,7 @@ var BinArray = (function(){ } if(count > 1500) { console.error('Too many run cycles.'); } } - return -1; //this line can never been run + return -1; // Never actually run }; BinArray.binsert = function(arr, what, how){ var index = BinArray.bsearch(arr,what,how); @@ -994,7 +994,6 @@ function AcfunParser(jsond){ data.position = "relative"; data.text = x.n; /*.replace(/\r/g,"\n");*/ data.text = data.text.replace(/\ /g,"\u00a0"); - console.log(data.text); if(x.a != null){ data.opacity = x.a; }else{ diff --git a/build/CommentCoreLibrary.min.js b/build/CommentCoreLibrary.min.js index db9e462..e70e178 100644 --- a/build/CommentCoreLibrary.min.js +++ b/build/CommentCoreLibrary.min.js @@ -1 +1 @@ -/*!Copyright(c) CommentCoreLibrary (//github.com/jabbany/CommentCoreLibrary) - Licensed under the MIT License */function CommentFilter(){this.modifiers=[],this.runtime=null,this.allowTypes={1:!0,4:!0,5:!0,6:!0,7:!0,8:!0,17:!0},this.doModify=function(a){for(var b=0;b0){if(f.stime=1e3*parseFloat(g[0]),f.color=parseInt(g[1]),f.mode=parseInt(g[2]),f.size=parseInt(g[3]),f.hash=g[4],f.date=parseInt(g[5]),f.position="absolute",7!=f.mode?(f.text=c[e].m.replace(/(\/n|\\n|\n|\r\n|\\r)/g,"\n"),f.text=f.text.replace(/\r/g,"\n"),f.text=f.text.replace(/\s/g," ")):f.text=c[e].m,7==f.mode){try{var h=JSON.parse(f.text)}catch(d){console.log("[Err] Error parsing internal data for comment"),console.log("[Dbg] "+f.text);continue}if(f.position="relative",f.text=h.n,f.text=f.text.replace(/\ /g," "),console.log(f.text),f.opacity=null!=h.a?h.a:1,null!=h.p?(f.x=h.p.x/1e3,f.y=h.p.y/1e3):(f.x=0,f.y=0),f.shadow=h.b,f.dur=4e3,null!=h.l&&(f.moveDelay=1e3*h.l),null!=h.z&&h.z.length>0){f.movable=!0,f.motion=[];for(var i=0,j={x:f.x,y:f.y,alpha:f.opacity,color:f.color},k=0;k=7&&(j.rZ=parseInt(adv[5],10),j.rY=parseInt(adv[6],10)),j.motion=[],j.movable=!1,adv.length>=11){j.movable=!0;var k=500,l={x:{from:j.x,to:parseFloat(adv[7]),dur:k,delay:0},y:{from:j.y,to:parseFloat(adv[8]),dur:k,delay:0}};if(""!==adv[9]&&(k=parseInt(adv[9],10),l.x.dur=k,l.y.dur=k),""!==adv[10]&&(l.x.delay=parseInt(adv[10],10),l.y.delay=parseInt(adv[10],10)),adv.length>11&&(j.shadow=adv[11],"true"===j.shadow&&(j.shadow=!0),"false"===j.shadow&&(j.shadow=!1),null!=adv[12]&&(j.font=adv[12]),adv.length>14)){"relative"===j.position&&(console.log("Cannot mix relative and absolute positioning"),j.position="absolute");for(var m=adv[14],n={x:l.x.from,y:l.y.from},o=[],p=new RegExp("([a-zA-Z])\\s*(\\d+)[, ](\\d+)","g"),q=m.split(/[a-zA-Z]/).length-1,r=p.exec(m);null!==r;){switch(r[1]){case"M":n.x=parseInt(r[2],10),n.y=parseInt(r[3],10);break;case"L":o.push({x:{from:n.x,to:parseInt(r[2],10),dur:k/q,delay:0},y:{from:n.y,to:parseInt(r[3],10),dur:k/q,delay:0}}),n.x=parseInt(r[2],10),n.y=parseInt(r[3],10)}r=p.exec(m)}l=null,j.motion=o}null!==l&&j.motion.push(l)}j.dur=2500,adv[3]<12&&(j.dur=1e3*adv[3]);var f=adv[2].split("-");if(null!=f&&f.length>1){var s=parseFloat(f[0]),t=parseFloat(f[1]);j.opacity=s,s!==t&&(j.alpha={from:s,to:t})}}catch(u){console.log("[Err] Error occurred in JSON parsing"),console.log("[Dbg] "+b)}else 8==j.mode&&(j.code=b);null!=j.text&&(j.text=j.text.replace(/\u25a0/g,"█")),g.push(j)}return g}var BinArray=function(){var a={};return a.bsearch=function(a,b,c){if(0===a.length)return 0;if(c(b,a[0])<0)return 0;if(c(b,a[a.length-1])>=0)return a.length;for(var d=0,e=0,f=0,g=a.length-1;g>=d;){if(e=Math.floor((g+d+1)/2),f++,c(b,a[e-1])>=0&&c(b,a[e])<0)return e;c(b,a[e-1])<0?g=e-1:c(b,a[e])>=0?d=e:console.error("Program Error"),f>1500&&console.error("Too many run cycles.")}return-1},a.binsert=function(b,c,d){var e=a.bsearch(b,c,d);return b.splice(e,0,c),e},a}(),__extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},CommentSpaceAllocator=function(){function a(a,b){"undefined"==typeof a&&(a=0),"undefined"==typeof b&&(b=0),this._pools=[[]],this.avoid=1,this._width=a,this._height=b}return a.prototype.willCollide=function(a,b){return a.stime+a.ttl>=b.stime+b.ttl/2},a.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=b.right,f=0;fd||c[f].bottome))return!1;if(this.willCollide(c[f],b))return!1}return!0},a.prototype.assign=function(a,b){for(;this._pools.length<=b;)this._pools.push([]);var c=this._pools[b];if(0===c.length)return a.cindex=b,0;if(this.pathCheck(0,a,c))return a.cindex=b,0;for(var d=0,e=0;ethis._height));e++)if(this.pathCheck(d,a,c))return a.cindex=b,d;return this.assign(a,b+1)},a.prototype.add=function(a){a.height>this._height?(a.cindex=-2,a.y=0):(a.y=this.assign(a,0),BinArray.binsert(this._pools[a.cindex],a,function(a,b){return a.bottomb.bottom?1:0}))},a.prototype.remove=function(a){if(!(a.cindex<0)){if(a.cindex>=this._pools.length)throw new Error("cindex out of bounds");var b=this._pools[a.cindex].indexOf(a);0>b||this._pools[a.cindex].splice(b,1)}},a.prototype.setBounds=function(a,b){this._width=a,this._height=b},a}(),AnchorCommentSpaceAllocator=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.add=function(b){a.prototype.add.call(this,b),b.x=(this._width-b.width)/2},b.prototype.willCollide=function(){return!0},b.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=0;ed||c[e].bottom0&&this.animate()},Object.defineProperty(a.prototype,"x",{get:function(){return(null===this._x||void 0===this._x)&&(this._x=this.align%2===0?this.dom.offsetLeft:this.parent.width-this.dom.offsetLeft-this.width),this.absolute?this._x:this._x/this.parent.width},set:function(a){this._x=a,this.absolute||(this._x*=this.parent.width),this.align%2===0?this.dom.style.left=this._x+"px":this.dom.style.right=this._x+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"y",{get:function(){return(null===this._y||void 0===this._y)&&(this._y=this.align<2?this.dom.offsetTop:this.parent.height-this.dom.offsetTop-this.height),this.absolute?this._y:this._y/this.parent.height},set:function(a){this._y=a,this.absolute||(this._y*=this.parent.height),this.align<2?this.dom.style.top=this._y+"px":this.dom.style.bottom=this._y+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"width",{get:function(){return(null===this._width||void 0===this._width)&&(this._width=this.dom.offsetWidth),this._width},set:function(a){this._width=a,this.dom.style.width=this._width+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"height",{get:function(){return(null===this._height||void 0===this._height)&&(this._height=this.dom.offsetHeight),this._height},set:function(a){this._height=a,this.dom.style.height=this._height+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"size",{get:function(){return this._size},set:function(a){this._size=a,this.dom.style.fontSize=this._size+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"color",{get:function(){return this._color},set:function(a){this._color=a;var b=a.toString(16);b=b.length>=6?b:new Array(6-b.length+1).join("0")+b,this.dom.style.color="#"+b,0===this._color&&(this.dom.className=this.parent.options.global.className+" rshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this._alpha},set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(this._alpha,this.parent.options.global.opacity)+""},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"border",{get:function(){return this._border},set:function(a){this._border=a,this.dom.style.border=this._border?"1px solid #00ffff":"none"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"shadow",{get:function(){return this._shadow},set:function(a){this._shadow=a,this._shadow||(this.dom.className=this.parent.options.global.className+" noshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"font",{get:function(){return this._font},set:function(a){this._font=a,this.dom.style.fontFamily=this._font.length>0?this._font:""},enumerable:!0,configurable:!0}),a.prototype.time=function(a){this.ttl-=a,this.ttl<0&&(this.ttl=0),this.movable&&this.update(),this.ttl<=0&&this.finish()},a.prototype.update=function(){this.animate()},a.prototype.invalidate=function(){this._x=null,this._y=null,this._width=null,this._height=null},a.prototype._execMotion=function(a,b){for(var c in a)if(a.hasOwnProperty(c)){var d=a[c];this[c]=d.easing(Math.min(Math.max(b-d.delay,0),d.dur),d.from,d.to-d.from,d.dur)}},a.prototype.animate=function(){if(this._alphaMotion&&(this.alpha=(this.dur-this.ttl)*(this._alphaMotion.to-this._alphaMotion.from)/this.dur+this._alphaMotion.from),0!==this.motion.length){var a=Math.max(this.ttl,0),b=this.dur-a-this._motionStart[this._curMotion];return this._execMotion(this.motion[this._curMotion],b),this.dur-a>this._motionEnd[this._curMotion]?(this._curMotion++,void(this._curMotion>=this.motion.length&&(this._curMotion=this.motion.length-1))):void 0}},a.prototype.finish=function(){this.parent.finish(this)},a.prototype.toString=function(){return["[",this.stime,"|",this.ttl,"/",this.dur,"]","(",this.mode,")",this.text].join("")},a.LINEAR=function(a,b,c,d){return a*c/d+b},a}(),ScrollComment=function(a){function b(b,c){a.call(this,b,c),this.dur*=this.parent.options.scroll.scale,this.ttl*=this.parent.options.scroll.scale}return __extends(b,a),Object.defineProperty(b.prototype,"alpha",{set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(Math.min(this._alpha,this.parent.options.global.opacity),this.parent.options.scroll.opacity)+""},enumerable:!0,configurable:!0}),b.prototype.init=function(b){"undefined"==typeof b&&(b=null),a.prototype.init.call(this,b),this.x=this.parent.width,this.parent.options.scroll.opacity<1&&(this.alpha=this._alpha),this.absolute=!0},b.prototype.update=function(){this.x=this.ttl/this.dur*(this.parent.width+this.width)-this.width},b}(CoreComment),CommentManager=function(){function a(a){var b=0;this._listeners={},this.stage=a,this.options={global:{opacity:1,scale:1,className:"cmt"},scroll:{opacity:1,scale:1},limit:0},this.timeline=[],this.runline=[],this.position=0,this.limiter=0,this.filter=null,this.csa={scroll:new CommentSpaceAllocator(0,0),top:new AnchorCommentSpaceAllocator(0,0),bottom:new AnchorCommentSpaceAllocator(0,0),reverse:new CommentSpaceAllocator(0,0),scrollbtm:new CommentSpaceAllocator(0,0)},this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.startTimer=function(){if(!(b>0)){var a=(new Date).getTime(),c=this;b=window.setInterval(function(){var b=(new Date).getTime()-a;a=(new Date).getTime(),c.onTimerEvent(b,c)},10)}},this.stopTimer=function(){window.clearInterval(b),b=0}}var b=function(a,b){for(var c=Math.PI/180,d=a*c,e=b*c,f=Math.cos,g=Math.sin,h=[f(d)*f(e),f(d)*g(e),g(d),0,-g(e),f(e),0,0,-g(d)*f(e),-g(d)*g(e),f(d),0,0,0,0,1],i=0;ib.stime?1:0})},a.prototype.validate=function(a){return null==a?!1:this.filter.doValidate(a)},a.prototype.load=function(a){this.timeline=a,this.timeline.sort(function(a,b){return a.stime>b.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbidb.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbid0;)this.runline[0].finish();this.dispatchEvent("clear")},a.prototype.setBounds=function(){this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.dispatchEvent("resize");for(var a in this.csa)this.csa[a].setBounds(this.width,this.height);this.stage.style.perspective=this.width*Math.tan(40*Math.PI/180)/2+"px",this.stage.style.webkitPerspective=this.width*Math.tan(40*Math.PI/180)/2+"px"},a.prototype.init=function(){this.setBounds(),null==this.filter&&(this.filter=new CommentFilter)},a.prototype.time=function(a){if(a-=1,this.position>=this.timeline.length||Math.abs(this.lastPos-a)>=2e3){if(this.seek(a),this.lastPos=a,this.timeline.length<=this.position)return}else this.lastPos=a;for(;this.position0&&this.runline.length>this.limiter)&&(this.validate(this.timeline[this.position])&&this.timeline[this.position].stime<=a);this.position++)this.send(this.timeline[this.position])},a.prototype.rescale=function(){},a.prototype.send=function(a){if(8===a.mode)return console.log(a),void(this.scripting&&console.log(this.scripting.eval(a.code)));if(null==this.filter||(a=this.filter.doModify(a),null!=a)){if(1===a.mode||2===a.mode||6===a.mode)var c=new ScrollComment(this,a);else var c=new CoreComment(this,a);switch(c.mode){case 1:c.align=0;break;case 2:c.align=2;break;case 4:c.align=2;break;case 5:c.align=0;break;case 6:c.align=1}switch(c.init(),this.stage.appendChild(c.dom),c.mode){default:case 1:this.csa.scroll.add(c);break;case 2:this.csa.scrollbtm.add(c);break;case 4:this.csa.bottom.add(c);break;case 5:this.csa.top.add(c);break;case 6:this.csa.reverse.add(c);break;case 17:case 7:(0!==a.rY||0!==a.rZ)&&(c.dom.style.transform=b(a.rY,a.rZ),c.dom.style.webkitTransform=b(a.rY,a.rZ),c.dom.style.OTransform=b(a.rY,a.rZ),c.dom.style.MozTransform=b(a.rY,a.rZ),c.dom.style.MSTransform=b(a.rY,a.rZ))}c.y=c.y,this.dispatchEvent("enterComment",c),this.runline.push(c)}},a.prototype.sendComment=function(a){console.log("CommentManager.sendComment is deprecated. Please use send instead"),this.send(a)},a.prototype.finish=function(a){this.dispatchEvent("exitComment",a),this.stage.removeChild(a.dom);var b=this.runline.indexOf(a);switch(b>=0&&this.runline.splice(b,1),a.mode){default:case 1:this.csa.scroll.remove(a);break;case 2:this.csa.scrollbtm.remove(a);break;case 4:this.csa.bottom.remove(a);break;case 5:this.csa.top.remove(a);break;case 6:this.csa.reverse.remove(a);break;case 7:}},a.prototype.addEventListener=function(a,b){"undefined"!=typeof this._listeners[a]?this._listeners[a].push(b):this._listeners[a]=[b]},a.prototype.dispatchEvent=function(a,b){if("undefined"!=typeof this._listeners[a])for(var c=0;c0){if(f.stime=1e3*parseFloat(g[0]),f.color=parseInt(g[1]),f.mode=parseInt(g[2]),f.size=parseInt(g[3]),f.hash=g[4],f.date=parseInt(g[5]),f.position="absolute",7!=f.mode?(f.text=c[e].m.replace(/(\/n|\\n|\n|\r\n|\\r)/g,"\n"),f.text=f.text.replace(/\r/g,"\n"),f.text=f.text.replace(/\s/g," ")):f.text=c[e].m,7==f.mode){try{var h=JSON.parse(f.text)}catch(d){console.log("[Err] Error parsing internal data for comment"),console.log("[Dbg] "+f.text);continue}if(f.position="relative",f.text=h.n,f.text=f.text.replace(/\ /g," "),f.opacity=null!=h.a?h.a:1,null!=h.p?(f.x=h.p.x/1e3,f.y=h.p.y/1e3):(f.x=0,f.y=0),f.shadow=h.b,f.dur=4e3,null!=h.l&&(f.moveDelay=1e3*h.l),null!=h.z&&h.z.length>0){f.movable=!0,f.motion=[];for(var i=0,j={x:f.x,y:f.y,alpha:f.opacity,color:f.color},k=0;k=7&&(j.rZ=parseInt(adv[5],10),j.rY=parseInt(adv[6],10)),j.motion=[],j.movable=!1,adv.length>=11){j.movable=!0;var k=500,l={x:{from:j.x,to:parseFloat(adv[7]),dur:k,delay:0},y:{from:j.y,to:parseFloat(adv[8]),dur:k,delay:0}};if(""!==adv[9]&&(k=parseInt(adv[9],10),l.x.dur=k,l.y.dur=k),""!==adv[10]&&(l.x.delay=parseInt(adv[10],10),l.y.delay=parseInt(adv[10],10)),adv.length>11&&(j.shadow=adv[11],"true"===j.shadow&&(j.shadow=!0),"false"===j.shadow&&(j.shadow=!1),null!=adv[12]&&(j.font=adv[12]),adv.length>14)){"relative"===j.position&&(console.log("Cannot mix relative and absolute positioning"),j.position="absolute");for(var m=adv[14],n={x:l.x.from,y:l.y.from},o=[],p=new RegExp("([a-zA-Z])\\s*(\\d+)[, ](\\d+)","g"),q=m.split(/[a-zA-Z]/).length-1,r=p.exec(m);null!==r;){switch(r[1]){case"M":n.x=parseInt(r[2],10),n.y=parseInt(r[3],10);break;case"L":o.push({x:{from:n.x,to:parseInt(r[2],10),dur:k/q,delay:0},y:{from:n.y,to:parseInt(r[3],10),dur:k/q,delay:0}}),n.x=parseInt(r[2],10),n.y=parseInt(r[3],10)}r=p.exec(m)}l=null,j.motion=o}null!==l&&j.motion.push(l)}j.dur=2500,adv[3]<12&&(j.dur=1e3*adv[3]);var f=adv[2].split("-");if(null!=f&&f.length>1){var s=parseFloat(f[0]),t=parseFloat(f[1]);j.opacity=s,s!==t&&(j.alpha={from:s,to:t})}}catch(u){console.log("[Err] Error occurred in JSON parsing"),console.log("[Dbg] "+b)}else 8==j.mode&&(j.code=b);null!=j.text&&(j.text=j.text.replace(/\u25a0/g,"█")),g.push(j)}return g}var BinArray=function(){var a={};return a.bsearch=function(a,b,c){if(0===a.length)return 0;if(c(b,a[0])<0)return 0;if(c(b,a[a.length-1])>=0)return a.length;for(var d=0,e=0,f=0,g=a.length-1;g>=d;){if(e=Math.floor((g+d+1)/2),f++,c(b,a[e-1])>=0&&c(b,a[e])<0)return e;c(b,a[e-1])<0?g=e-1:c(b,a[e])>=0?d=e:console.error("Program Error"),f>1500&&console.error("Too many run cycles.")}return-1},a.binsert=function(b,c,d){var e=a.bsearch(b,c,d);return b.splice(e,0,c),e},a}(),__extends=this.__extends||function(a,b){function c(){this.constructor=a}for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);c.prototype=b.prototype,a.prototype=new c},CommentSpaceAllocator=function(){function a(a,b){"undefined"==typeof a&&(a=0),"undefined"==typeof b&&(b=0),this._pools=[[]],this.avoid=1,this._width=a,this._height=b}return a.prototype.willCollide=function(a,b){return a.stime+a.ttl>=b.stime+b.ttl/2},a.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=b.right,f=0;fd||c[f].bottome))return!1;if(this.willCollide(c[f],b))return!1}return!0},a.prototype.assign=function(a,b){for(;this._pools.length<=b;)this._pools.push([]);var c=this._pools[b];if(0===c.length)return a.cindex=b,0;if(this.pathCheck(0,a,c))return a.cindex=b,0;for(var d=0,e=0;ethis._height));e++)if(this.pathCheck(d,a,c))return a.cindex=b,d;return this.assign(a,b+1)},a.prototype.add=function(a){a.height>this._height?(a.cindex=-2,a.y=0):(a.y=this.assign(a,0),BinArray.binsert(this._pools[a.cindex],a,function(a,b){return a.bottomb.bottom?1:0}))},a.prototype.remove=function(a){if(!(a.cindex<0)){if(a.cindex>=this._pools.length)throw new Error("cindex out of bounds");var b=this._pools[a.cindex].indexOf(a);0>b||this._pools[a.cindex].splice(b,1)}},a.prototype.setBounds=function(a,b){this._width=a,this._height=b},a}(),AnchorCommentSpaceAllocator=function(a){function b(){a.apply(this,arguments)}return __extends(b,a),b.prototype.add=function(b){a.prototype.add.call(this,b),b.x=(this._width-b.width)/2},b.prototype.willCollide=function(){return!0},b.prototype.pathCheck=function(a,b,c){for(var d=a+b.height,e=0;ed||c[e].bottom0&&this.animate()},Object.defineProperty(a.prototype,"x",{get:function(){return(null===this._x||void 0===this._x)&&(this._x=this.align%2===0?this.dom.offsetLeft:this.parent.width-this.dom.offsetLeft-this.width),this.absolute?this._x:this._x/this.parent.width},set:function(a){this._x=a,this.absolute||(this._x*=this.parent.width),this.align%2===0?this.dom.style.left=this._x+"px":this.dom.style.right=this._x+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"y",{get:function(){return(null===this._y||void 0===this._y)&&(this._y=this.align<2?this.dom.offsetTop:this.parent.height-this.dom.offsetTop-this.height),this.absolute?this._y:this._y/this.parent.height},set:function(a){this._y=a,this.absolute||(this._y*=this.parent.height),this.align<2?this.dom.style.top=this._y+"px":this.dom.style.bottom=this._y+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"right",{get:function(){return this.x+this.width},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"width",{get:function(){return(null===this._width||void 0===this._width)&&(this._width=this.dom.offsetWidth),this._width},set:function(a){this._width=a,this.dom.style.width=this._width+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"height",{get:function(){return(null===this._height||void 0===this._height)&&(this._height=this.dom.offsetHeight),this._height},set:function(a){this._height=a,this.dom.style.height=this._height+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"size",{get:function(){return this._size},set:function(a){this._size=a,this.dom.style.fontSize=this._size+"px"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"color",{get:function(){return this._color},set:function(a){this._color=a;var b=a.toString(16);b=b.length>=6?b:new Array(6-b.length+1).join("0")+b,this.dom.style.color="#"+b,0===this._color&&(this.dom.className=this.parent.options.global.className+" rshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"alpha",{get:function(){return this._alpha},set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(this._alpha,this.parent.options.global.opacity)+""},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"border",{get:function(){return this._border},set:function(a){this._border=a,this.dom.style.border=this._border?"1px solid #00ffff":"none"},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"shadow",{get:function(){return this._shadow},set:function(a){this._shadow=a,this._shadow||(this.dom.className=this.parent.options.global.className+" noshadow")},enumerable:!0,configurable:!0}),Object.defineProperty(a.prototype,"font",{get:function(){return this._font},set:function(a){this._font=a,this.dom.style.fontFamily=this._font.length>0?this._font:""},enumerable:!0,configurable:!0}),a.prototype.time=function(a){this.ttl-=a,this.ttl<0&&(this.ttl=0),this.movable&&this.update(),this.ttl<=0&&this.finish()},a.prototype.update=function(){this.animate()},a.prototype.invalidate=function(){this._x=null,this._y=null,this._width=null,this._height=null},a.prototype._execMotion=function(a,b){for(var c in a)if(a.hasOwnProperty(c)){var d=a[c];this[c]=d.easing(Math.min(Math.max(b-d.delay,0),d.dur),d.from,d.to-d.from,d.dur)}},a.prototype.animate=function(){if(this._alphaMotion&&(this.alpha=(this.dur-this.ttl)*(this._alphaMotion.to-this._alphaMotion.from)/this.dur+this._alphaMotion.from),0!==this.motion.length){var a=Math.max(this.ttl,0),b=this.dur-a-this._motionStart[this._curMotion];return this._execMotion(this.motion[this._curMotion],b),this.dur-a>this._motionEnd[this._curMotion]?(this._curMotion++,void(this._curMotion>=this.motion.length&&(this._curMotion=this.motion.length-1))):void 0}},a.prototype.finish=function(){this.parent.finish(this)},a.prototype.toString=function(){return["[",this.stime,"|",this.ttl,"/",this.dur,"]","(",this.mode,")",this.text].join("")},a.LINEAR=function(a,b,c,d){return a*c/d+b},a}(),ScrollComment=function(a){function b(b,c){a.call(this,b,c),this.dur*=this.parent.options.scroll.scale,this.ttl*=this.parent.options.scroll.scale}return __extends(b,a),Object.defineProperty(b.prototype,"alpha",{set:function(a){this._alpha=a,this.dom.style.opacity=Math.min(Math.min(this._alpha,this.parent.options.global.opacity),this.parent.options.scroll.opacity)+""},enumerable:!0,configurable:!0}),b.prototype.init=function(b){"undefined"==typeof b&&(b=null),a.prototype.init.call(this,b),this.x=this.parent.width,this.parent.options.scroll.opacity<1&&(this.alpha=this._alpha),this.absolute=!0},b.prototype.update=function(){this.x=this.ttl/this.dur*(this.parent.width+this.width)-this.width},b}(CoreComment),CommentManager=function(){function a(a){var b=0;this._listeners={},this.stage=a,this.options={global:{opacity:1,scale:1,className:"cmt"},scroll:{opacity:1,scale:1},limit:0},this.timeline=[],this.runline=[],this.position=0,this.limiter=0,this.filter=null,this.csa={scroll:new CommentSpaceAllocator(0,0),top:new AnchorCommentSpaceAllocator(0,0),bottom:new AnchorCommentSpaceAllocator(0,0),reverse:new CommentSpaceAllocator(0,0),scrollbtm:new CommentSpaceAllocator(0,0)},this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.startTimer=function(){if(!(b>0)){var a=(new Date).getTime(),c=this;b=window.setInterval(function(){var b=(new Date).getTime()-a;a=(new Date).getTime(),c.onTimerEvent(b,c)},10)}},this.stopTimer=function(){window.clearInterval(b),b=0}}var b=function(a,b){for(var c=Math.PI/180,d=a*c,e=b*c,f=Math.cos,g=Math.sin,h=[f(d)*f(e),f(d)*g(e),g(d),0,-g(e),f(e),0,0,-g(d)*f(e),-g(d)*g(e),f(d),0,0,0,0,1],i=0;ib.stime?1:0})},a.prototype.validate=function(a){return null==a?!1:this.filter.doValidate(a)},a.prototype.load=function(a){this.timeline=a,this.timeline.sort(function(a,b){return a.stime>b.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbidb.stime?2:a.stimeb.date?1:a.dateb.dbid?1:a.dbid0;)this.runline[0].finish();this.dispatchEvent("clear")},a.prototype.setBounds=function(){this.width=this.stage.offsetWidth,this.height=this.stage.offsetHeight,this.dispatchEvent("resize");for(var a in this.csa)this.csa[a].setBounds(this.width,this.height);this.stage.style.perspective=this.width*Math.tan(40*Math.PI/180)/2+"px",this.stage.style.webkitPerspective=this.width*Math.tan(40*Math.PI/180)/2+"px"},a.prototype.init=function(){this.setBounds(),null==this.filter&&(this.filter=new CommentFilter)},a.prototype.time=function(a){if(a-=1,this.position>=this.timeline.length||Math.abs(this.lastPos-a)>=2e3){if(this.seek(a),this.lastPos=a,this.timeline.length<=this.position)return}else this.lastPos=a;for(;this.position0&&this.runline.length>this.limiter)&&(this.validate(this.timeline[this.position])&&this.timeline[this.position].stime<=a);this.position++)this.send(this.timeline[this.position])},a.prototype.rescale=function(){},a.prototype.send=function(a){if(8===a.mode)return console.log(a),void(this.scripting&&console.log(this.scripting.eval(a.code)));if(null==this.filter||(a=this.filter.doModify(a),null!=a)){if(1===a.mode||2===a.mode||6===a.mode)var c=new ScrollComment(this,a);else var c=new CoreComment(this,a);switch(c.mode){case 1:c.align=0;break;case 2:c.align=2;break;case 4:c.align=2;break;case 5:c.align=0;break;case 6:c.align=1}switch(c.init(),this.stage.appendChild(c.dom),c.mode){default:case 1:this.csa.scroll.add(c);break;case 2:this.csa.scrollbtm.add(c);break;case 4:this.csa.bottom.add(c);break;case 5:this.csa.top.add(c);break;case 6:this.csa.reverse.add(c);break;case 17:case 7:(0!==a.rY||0!==a.rZ)&&(c.dom.style.transform=b(a.rY,a.rZ),c.dom.style.webkitTransform=b(a.rY,a.rZ),c.dom.style.OTransform=b(a.rY,a.rZ),c.dom.style.MozTransform=b(a.rY,a.rZ),c.dom.style.MSTransform=b(a.rY,a.rZ))}c.y=c.y,this.dispatchEvent("enterComment",c),this.runline.push(c)}},a.prototype.sendComment=function(a){console.log("CommentManager.sendComment is deprecated. Please use send instead"),this.send(a)},a.prototype.finish=function(a){this.dispatchEvent("exitComment",a),this.stage.removeChild(a.dom);var b=this.runline.indexOf(a);switch(b>=0&&this.runline.splice(b,1),a.mode){default:case 1:this.csa.scroll.remove(a);break;case 2:this.csa.scrollbtm.remove(a);break;case 4:this.csa.bottom.remove(a);break;case 5:this.csa.top.remove(a);break;case 6:this.csa.reverse.remove(a);break;case 7:}},a.prototype.addEventListener=function(a,b){"undefined"!=typeof this._listeners[a]?this._listeners[a].push(b):this._listeners[a]=[b]},a.prototype.dispatchEvent=function(a,b){if("undefined"!=typeof this._listeners[a])for(var c=0;c

Tests

diff --git a/demo/scripting/sandbox.js b/demo/scripting/sandbox.js index a026566..b9b367a 100644 --- a/demo/scripting/sandbox.js +++ b/demo/scripting/sandbox.js @@ -46,10 +46,10 @@ window.addEventListener('load',function(){ window.sandbox.send("Update:DimensionUpdate", window.sandbox.getContext().getDimensions()); } $("debug-basic").addEventListener("click", function(){ - fetchFile("../../tests/scripting/manzoku.biliscript"); + fetchFile("../../test/scripting/manzoku.biliscript"); }); $("debug-svg-madoka").addEventListener("click", function(){ - fetchFile("../../tests/scripting/madoka.biliscript"); + fetchFile("../../test/scripting/madoka.biliscript"); }); $("show-console").addEventListener("click", function(){ $("codediv").style.display="none"; @@ -60,12 +60,12 @@ window.addEventListener('load',function(){ $("consolediv").style.display="none"; }); $("debug-3dsphere").addEventListener("click", function(){ - fetchFile("../../tests/scripting/3dsphere.biliscript"); + fetchFile("../../test/scripting/3dsphere.biliscript"); }); $("debug-custom").addEventListener("click", function(){ var file = prompt("Please input test file name:"); if(file !== null && file !== ""){ - fetchFile("../../tests/scripting/" + file); + fetchFile("../../test/scripting/" + file); } }); $("debug-clear").addEventListener("click", function(){ diff --git a/docs/integration/README.md b/docs/integration/README.md new file mode 100644 index 0000000..e69de29 diff --git a/spec/CommentCoreLibrary_spec.coffee b/spec/CommentCoreLibrary_spec.coffee index 9d793b6..75f5bcf 100644 --- a/spec/CommentCoreLibrary_spec.coffee +++ b/spec/CommentCoreLibrary_spec.coffee @@ -51,7 +51,7 @@ describe 'CommentManager', -> expect(manager.timeline).toEqual [c1, c2, c3, c4, c5] it 'smoking test', -> - jasmine.getFixtures().fixturesPath = "tests/" + jasmine.getFixtures().fixturesPath = "test/" comments = AcfunParser(readFixtures 'ac940133.json') # TODO: Construct a json that cover all types of comments # and use it for smoking test diff --git a/spec/parsers/AcfunFormat_spec.coffee b/spec/parsers/AcfunFormat_spec.coffee index b6b46f5..ac71e8b 100644 --- a/spec/parsers/AcfunFormat_spec.coffee +++ b/spec/parsers/AcfunFormat_spec.coffee @@ -1,6 +1,6 @@ 'use strict' describe 'AcfunFormat', -> - jasmine.getFixtures().fixturesPath = "tests/" + jasmine.getFixtures().fixturesPath = "test/" it 'works', -> json = readFixtures 'ACFun.json' comments = AcfunParser(json) diff --git a/spec/parsers/BilibiliFormat_spec.coffee b/spec/parsers/BilibiliFormat_spec.coffee index dca5368..c537325 100644 --- a/spec/parsers/BilibiliFormat_spec.coffee +++ b/spec/parsers/BilibiliFormat_spec.coffee @@ -1,6 +1,6 @@ 'use strict' describe 'BilibiliFormat', -> - jasmine.getFixtures().fixturesPath = "tests/" + jasmine.getFixtures().fixturesPath = "test/" it 'parses normal comments', -> xml_text = readFixtures 'av207527.xml' comments = BilibiliParser(null, xml_text) diff --git a/src/Array.js b/src/Array.js index 93640ab..4fde615 100644 --- a/src/Array.js +++ b/src/Array.js @@ -34,7 +34,7 @@ var BinArray = (function(){ } if(count > 1500) { console.error('Too many run cycles.'); } } - return -1; //this line can never been run + return -1; // Never actually run }; BinArray.binsert = function(arr, what, how){ var index = BinArray.bsearch(arr,what,how); diff --git a/src/parsers/AcfunFormat.js b/src/parsers/AcfunFormat.js index c21fdea..095c749 100644 --- a/src/parsers/AcfunFormat.js +++ b/src/parsers/AcfunFormat.js @@ -42,7 +42,6 @@ function AcfunParser(jsond){ data.position = "relative"; data.text = x.n; /*.replace(/\r/g,"\n");*/ data.text = data.text.replace(/\ /g,"\u00a0"); - console.log(data.text); if(x.a != null){ data.opacity = x.a; }else{ diff --git a/tests/ACFun.json b/test/ACFun.json similarity index 100% rename from tests/ACFun.json rename to test/ACFun.json diff --git a/tests/Readme.md b/test/Readme.md similarity index 100% rename from tests/Readme.md rename to test/Readme.md diff --git a/tests/ac940133.json b/test/ac940133.json similarity index 100% rename from tests/ac940133.json rename to test/ac940133.json diff --git a/tests/av207527.xml b/test/av207527.xml similarity index 100% rename from tests/av207527.xml rename to test/av207527.xml diff --git a/tests/bilibili.xml b/test/bilibili.xml similarity index 100% rename from tests/bilibili.xml rename to test/bilibili.xml diff --git a/tests/boss.xml b/test/boss.xml similarity index 100% rename from tests/boss.xml rename to test/boss.xml diff --git a/tests/comment.xml b/test/comment.xml similarity index 100% rename from tests/comment.xml rename to test/comment.xml diff --git a/tests/extended.xml b/test/extended.xml similarity index 100% rename from tests/extended.xml rename to test/extended.xml diff --git a/tests/invalid/no_closing.xml b/test/invalid/no_closing.xml similarity index 100% rename from tests/invalid/no_closing.xml rename to test/invalid/no_closing.xml diff --git a/tests/invalid/syntax_error.xml b/test/invalid/syntax_error.xml similarity index 100% rename from tests/invalid/syntax_error.xml rename to test/invalid/syntax_error.xml diff --git a/tests/invalid/xss.xml b/test/invalid/xss.xml similarity index 100% rename from tests/invalid/xss.xml rename to test/invalid/xss.xml diff --git a/tests/mikunoshoushitsu.xml b/test/mikunoshoushitsu.xml similarity index 100% rename from tests/mikunoshoushitsu.xml rename to test/mikunoshoushitsu.xml diff --git a/tests/rokubunnoichi.xml b/test/rokubunnoichi.xml similarity index 100% rename from tests/rokubunnoichi.xml rename to test/rokubunnoichi.xml diff --git a/tests/scripting/3dmodeler-assets/2984.jmf b/test/scripting/3dmodeler-assets/2984.jmf similarity index 100% rename from tests/scripting/3dmodeler-assets/2984.jmf rename to test/scripting/3dmodeler-assets/2984.jmf diff --git a/tests/scripting/3dmodeler-assets/3404.jmf b/test/scripting/3dmodeler-assets/3404.jmf similarity index 100% rename from tests/scripting/3dmodeler-assets/3404.jmf rename to test/scripting/3dmodeler-assets/3404.jmf diff --git a/tests/scripting/3dmodeler-assets/difficult_model.jmf b/test/scripting/3dmodeler-assets/difficult_model.jmf similarity index 100% rename from tests/scripting/3dmodeler-assets/difficult_model.jmf rename to test/scripting/3dmodeler-assets/difficult_model.jmf diff --git a/tests/scripting/3dmodeler.biliscript b/test/scripting/3dmodeler.biliscript similarity index 100% rename from tests/scripting/3dmodeler.biliscript rename to test/scripting/3dmodeler.biliscript diff --git a/tests/scripting/3dplane.biliscript b/test/scripting/3dplane.biliscript similarity index 100% rename from tests/scripting/3dplane.biliscript rename to test/scripting/3dplane.biliscript diff --git a/tests/scripting/3dsphere.biliscript b/test/scripting/3dsphere.biliscript similarity index 100% rename from tests/scripting/3dsphere.biliscript rename to test/scripting/3dsphere.biliscript diff --git a/tests/scripting/av734512.xml b/test/scripting/av734512.xml similarity index 100% rename from tests/scripting/av734512.xml rename to test/scripting/av734512.xml diff --git a/tests/scripting/boundingbox.biliscript b/test/scripting/boundingbox.biliscript similarity index 100% rename from tests/scripting/boundingbox.biliscript rename to test/scripting/boundingbox.biliscript diff --git a/tests/scripting/comment-festival-v3.xml b/test/scripting/comment-festival-v3.xml similarity index 100% rename from tests/scripting/comment-festival-v3.xml rename to test/scripting/comment-festival-v3.xml diff --git a/tests/scripting/crazy-night.xml b/test/scripting/crazy-night.xml similarity index 100% rename from tests/scripting/crazy-night.xml rename to test/scripting/crazy-night.xml diff --git a/tests/scripting/greendam.biliscript b/test/scripting/greendam.biliscript similarity index 100% rename from tests/scripting/greendam.biliscript rename to test/scripting/greendam.biliscript diff --git a/tests/scripting/jinzou-enemy.xml b/test/scripting/jinzou-enemy.xml similarity index 100% rename from tests/scripting/jinzou-enemy.xml rename to test/scripting/jinzou-enemy.xml diff --git a/tests/scripting/kanpai-standards-compliant.xml b/test/scripting/kanpai-standards-compliant.xml similarity index 100% rename from tests/scripting/kanpai-standards-compliant.xml rename to test/scripting/kanpai-standards-compliant.xml diff --git a/tests/scripting/kanpai.xml b/test/scripting/kanpai.xml similarity index 100% rename from tests/scripting/kanpai.xml rename to test/scripting/kanpai.xml diff --git a/tests/scripting/madoka.biliscript b/test/scripting/madoka.biliscript similarity index 100% rename from tests/scripting/madoka.biliscript rename to test/scripting/madoka.biliscript diff --git a/tests/scripting/manzoku.biliscript b/test/scripting/manzoku.biliscript similarity index 100% rename from tests/scripting/manzoku.biliscript rename to test/scripting/manzoku.biliscript diff --git a/tests/scripting/round-and-round.xml b/test/scripting/round-and-round.xml similarity index 100% rename from tests/scripting/round-and-round.xml rename to test/scripting/round-and-round.xml diff --git a/tests/scripting/tsubasa.xml b/test/scripting/tsubasa.xml similarity index 100% rename from tests/scripting/tsubasa.xml rename to test/scripting/tsubasa.xml diff --git a/tests/subtitles/[YYDM-11FANS][Strike_Witches][BDRIP][01][X264_AAC][1280X720].uni_gb.ass b/test/subtitles/[YYDM-11FANS][Strike_Witches][BDRIP][01][X264_AAC][1280X720].uni_gb.ass similarity index 100% rename from tests/subtitles/[YYDM-11FANS][Strike_Witches][BDRIP][01][X264_AAC][1280X720].uni_gb.ass rename to test/subtitles/[YYDM-11FANS][Strike_Witches][BDRIP][01][X264_AAC][1280X720].uni_gb.ass diff --git a/tests/test.xml b/test/test.xml similarity index 100% rename from tests/test.xml rename to test/test.xml diff --git a/tests/test2.xml b/test/test2.xml similarity index 100% rename from tests/test2.xml rename to test/test2.xml diff --git a/tests/unowen.xml b/test/unowen.xml similarity index 100% rename from tests/unowen.xml rename to test/unowen.xml diff --git a/tests/utsukushiki_mono.xml b/test/utsukushiki_mono.xml similarity index 100% rename from tests/utsukushiki_mono.xml rename to test/utsukushiki_mono.xml