-
Notifications
You must be signed in to change notification settings - Fork 14
/
unveil.min.js
37 lines (37 loc) · 18.2 KB
/
unveil.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function(){var c={};c.EPSILON=1.0E-4;c.MAX_FLOAT=3.4028235E38;c.MIN_FLOAT=-3.4028235E38;c.MAX_INT=2147483647;c.MIN_INT=-2147483648;c.inherit=function(a){function b(){}b.prototype=a.prototype||a;return new b};c.each=function(a,b,d){if(a.forEach)a.forEach(b,d);else for(var e in a)hasOwnProperty.call(a,e)&&b.call(d,a[e],e,a);return a};c.rest=function(a,b,d){return Array.prototype.slice.call(a,b===undefined||d?1:b)};c.include=function(a,b){return a.indexOf(b)!=-1};c.isArray=function(a){return toString.call(a)===
"[object Array]"};c.select=c.filter=function(a,b,d){if(a.filter===Array.prototype.filter)return a.filter(b,d);var e=[];c.each(a,function(f,i,j){b.call(d,f,i,j)&&e.push(f)});return e};c.extend=function(a){c.rest(arguments).forEach(function(b){for(var d in b)a[d]=b[d]});return a};(function(){function a(d,e){return{x:d||0,y:e||0,add:function(f){return a(this.x+f.x,this.y+f.y)}}}function b(d,e,f,i,j,n){d=d!==undefined?d:1;i=i!==undefined?i:1;return{a:d,b:e||0,c:f||0,d:i,tx:j||0,ty:n||0,concat:function(g){return b(this.a*
g.a+this.c*g.b,this.b*g.a+this.d*g.b,this.a*g.c+this.c*g.d,this.b*g.c+this.d*g.d,this.a*g.tx+this.c*g.ty+this.tx,this.b*g.tx+this.d*g.ty+this.ty)},deltaTransformPoint:function(g){return a(this.a*g.x+this.c*g.y,this.b*g.x+this.d*g.y)},inverse:function(){var g=this.a*this.d-this.b*this.c;return b(this.d/g,-this.b/g,-this.c/g,this.a/g,(this.c*this.ty-this.d*this.tx)/g,(this.b*this.tx-this.a*this.ty)/g)},rotate:function(g,k){return this.concat(b.rotation(g,k))},scale:function(g,k,m){return this.concat(b.scale(g,
k,m))},transformPoint:function(g){return a(this.a*g.x+this.c*g.y+this.tx,this.b*g.x+this.d*g.y+this.ty)},translate:function(g,k){return this.concat(b.translation(g,k))}}}a.distance=function(d,e){return Math.sqrt(Math.pow(e.x-d.x,2)+Math.pow(e.y-d.y,2))};a.direction=function(d,e){return Math.atan2(e.y-d.y,e.x-d.x)};b.rotation=function(d,e){var f=b(Math.cos(d),Math.sin(d),-Math.sin(d),Math.cos(d));if(e)f=b.translation(e.x,e.y).concat(f).concat(b.translation(-e.x,-e.y));return f};b.scale=function(d,
e,f){e=e||d;d=b(d,0,0,e);if(f)d=b.translation(f.x,f.y).concat(d).concat(b.translation(-f.x,-f.y));return d};b.translation=function(d,e){return b(1,0,0,1,d,e)};b.IDENTITY=b();b.HORIZONTAL_FLIP=b(-1,0,0,1);b.VERTICAL_FLIP=b(1,0,0,-1);c.Point=a;c.Matrix=b})();c.Actor=function(a){Data.Node.call(this);this.childCount=0;this.properties=c.extend({x:0,y:0,scaleX:1,scaleY:1,rotation:0,localX:0,localY:0,localScaleX:1,localScaleY:1,localRotation:0,fillStyle:"#000",strokeStyle:"#000",lineWidth:1,lineCap:"butt",
lineJoin:"miter",globalAlpha:1,miterLimit:10,visible:true,transformMode:"object"},a);this.replace("children",new Data.Hash);this.tweens={};this.active=false;this.handlers={}};c.Actor.registeredActors={};c.Actor.prototype=c.inherit(Data.Node);c.Actor.prototype.bind=function(a,b){this.handlers[a]||(this.handlers[a]=[]);this.handlers[a].push(b)};c.Actor.prototype.trigger=function(a){if(this.handlers[a])for(var b in this.handlers[a])this.handlers[a][b].apply(this,[])};c.Actor.create=function(a){var b=
c.Actor.registeredActors[a.type];if(!b)throw"Actor type unregistered: '"+a.type+"'";return new b(a)};c.Actor.prototype.id=function(){return this.p("id")||this.nodeId};c.Actor.prototype.add=function(a){var b;b=a instanceof c.Actor?a:c.Actor.create(a);if(!this.scene)throw"You can't add childs to actors that don't have a scene reference";this.scene.registerActor(b);this.set("children",b.id(),b);b.parent=this;b.init&&b.init();a.actors&&a.actors.forEach(function(d){b.add(d)});return b};c.Actor.prototype.get=
function(){return arguments.length===1?this.scene.actors[arguments[0]]:Data.Node.prototype.get.call(this,arguments[0],arguments[1])};c.Actor.prototype.remove=function(a){var b=this;if(a instanceof Function)this.traverse().forEach(function(d){a(d)&&b.scene.remove(d.id())});else{if(this.get("children",a)){this.all("children").del(a);delete this.scene.actors[a];delete this.scene.interactiveActors[a]}this.all("children").each(function(d){d.remove(a)})}};c.Actor.prototype.traverse=function(){return this.scene.properties.traverser(this)};
c.Actor.prototype.property=function(a,b){if(b)return this.properties[a]=b;else return this.properties[a]instanceof Function?this.properties[a].call(this):this.properties[a]};c.Actor.prototype.p=c.Actor.prototype.property;c.Actor.prototype.animate=function(a,b,d){var e=this.scene,f=(new c.Tween(this.properties)).to(b||1,a).easing(d||c.Tween.Easing.Expo.EaseInOut).onComplete(function(){e.unexecute(c.cmds.RequestFramerate);c.TweenManager.remove(f)});e.execute(c.cmds.RequestFramerate);return f.start()};
c.Actor.prototype.tShape=function(){return c.Matrix().translate(this.p("localX"),this.p("localY")).rotate(this.p("localRotation")).scale(this.p("localScaleX"),this.p("localScaleY"))};c.Actor.prototype.tWorldParent=function(){return this.parent?this.parent._tWorld:c.Matrix()};c.Actor.prototype.tWorld=function(){return this.tWorldParent().translate(this.p("x"),this.p("y")).rotate(this.p("rotation")).scale(this.p("scaleX"),this.p("scaleY"))};c.Actor.prototype.compileMatrix=function(){this.update();this._tWorld=
this.tWorld();this.all("children")&&this.all("children").each(function(a){a.compileMatrix()})};c.Actor.prototype.update=function(){c.TweenManager.update()};c.Actor.prototype.applyStyles=function(a){a.fillStyle=this.p("fillStyle");a.strokeStyle=this.p("strokeStyle");a.lineWidth=this.p("lineWidth");a.lineCap=this.p("lineCap");a.lineJoin=this.p("lineJoin");a.globalAlpha=this.p("globalAlpha");a.miterLimit=this.p("miterLimit")};c.Actor.prototype.draw=function(){};c.Actor.prototype.checkActive=function(a,
b,d){b=new c.Point(b,d);d=this._tWorld.inverse().transformPoint(b);b=d.x;d=d.y;if(this.bounds&&a.isPointInPath){this.drawBounds(a);this.active=a.isPointInPath(b,d)?true:false}return this.active};c.Actor.prototype.drawBounds=function(a){var b=this.bounds(),d,e;d=b.shift();a.beginPath();for(a.moveTo(d.x,d.y);e=b.shift();)a.lineTo(e.x,e.y);a.lineTo(d.x,d.y)};c.Actor.prototype.render=function(a,b){if(this.p("visible")){this.applyStyles(a);this.transform(a,b);this.draw(a,b)}};c.Actor.prototype.transform=
function(a,b){var d=this.tShape().concat(b).concat(this._tWorld);if(this.p("transformMode")==="origin"){d=d.transformPoint(c.Point(0,0));a.setTransform(1,0,0,1,d.x,d.y)}else a.setTransform(d.a,d.b,d.c,d.d,d.tx,d.ty)};c.traverser={};c.traverser.BreadthFirst=function(a){var b=[],d=[];for(b.push(a);b.length>0;){a=b.shift();if(a.p("visible")){d.push(a);a.all("children").each(function(e){b.push(e)})}}return d};c.traverser.DepthFirst=function(a){var b=[],d=[];for(b.push(a);b.length>0;){a=b.pop();if(a.p("visible")){d.push(a);
a.all("children").each(function(e){b.push(e)})}}return d};c.behaviors={};c.behaviors.adjust=function(a,b){var d=a.bounds();if(a.bounded){b.a=b.d=Math.max(1,b.a);b.tx=Math.max(d.x,Math.min(0,b.tx));b.ty=Math.max(d.y,Math.min(0,b.ty))}return b};c.behaviors.Zoom=function(a){function b(d){d=d.wheelDelta/120||-d.detail;var e=a.tView.scale(1+0.0050*d,1+0.0050*d,c.Point(a.scene.mouseX,a.scene.mouseY));a.tView=d<0?c.behaviors.adjust(a,e):e;a.trigger("viewChange")}a.canvas.addEventListener("mousewheel",b,
false);a.canvas.addEventListener("DOMMouseScroll",b,false)};c.behaviors.Pan=function(a){function b(){e=false}var d,e=false;a.canvas.addEventListener("mousedown",function(){p=c.Point(a.mouseX,a.mouseY);d=a.tView;e=true},false);a.canvas.addEventListener("mousemove",function(){if(e){var f=c.Matrix.translation(a.mouseX-p.x,a.mouseY-p.y).concat(d);a.tView=c.behaviors.adjust(a,f);a.trigger("viewChange")}},false);a.canvas.addEventListener("mouseup",b,false);a.canvas.addEventListener("mouseout",b,false)};
c.Display=function(a,b){function d(){e.scene.trigger("interact")}var e=this;c.Actor.call(this,c.extend({fillStyle:""},b));this.scene=a;this.element=document.getElementById(b.container);this.canvas=document.createElement("canvas");this.canvas.setAttribute("width",b.width);this.canvas.setAttribute("height",b.height);this.canvas.style.position="relative";this.element.appendChild(this.canvas);this.width=b.width;this.height=b.height;this.bounded=b.bounded||true;this.ctx=this.canvas.getContext("2d");this.tView=
c.Matrix();if(b.zooming)this.zoombehavior=new c.behaviors.Zoom(this);if(b.panning)this.panbehavior=new c.behaviors.Pan(this);this.canvas.addEventListener("mousemove",d,false);this.canvas.addEventListener("DOMMouseScroll",d,false);this.canvas.addEventListener("mousemove",function(f){var i=e.tView.inverse(),j;if(f.offsetX)j=new c.Point(f.offsetX,f.offsetY);else if(f.layerX)j=new c.Point(f.layerX,f.layerY);if(j){e.mouseX=j.x;e.mouseY=j.y;worldPos=i.transformPoint(j);e.scene.mouseX=parseInt(worldPos.x,
10);e.scene.mouseY=parseInt(worldPos.y,10);e.scene.activeDisplay=e}},false);this.canvas.addEventListener("mousewheel",d,false);this.canvas.addEventListener("mouseout",function(){e.scene.mouseX=NaN;e.scene.mouseY=NaN},false);this.canvas.addEventListener("click",function(){c.each(e.scene.activeActors,function(f){f.trigger("click")})},false)};c.Display.prototype=c.inherit(c.Actor);c.Display.prototype.displayPos=function(){return this.tView.transformPoint(pos)};c.Display.prototype.zoom=function(){return this.tView.a};
c.Display.prototype.worldPos=function(a){return this.tView.inverse().transformPoint(a)};c.Display.prototype.bounds=function(){var a=Math.max(0,this.scene.p("width")-this.width),b=Math.max(0,this.scene.p("width")-this.width);return{x:(1-this.tView.a)*this.width-this.tView.a*a,y:(1-this.tView.a)*this.height-this.tView.a*b}};c.Display.prototype.refresh=function(){var a=this,b,d;this.ctx.clearRect(0,0,this.width,this.height);if(this.scene.p("fillStyle")!==""){this.ctx.fillStyle=this.scene.p("fillStyle");
this.ctx.fillRect(0,0,this.width,this.height)}this.ctx.save();b=this.scene.traverse();b.shift();c.each(b,function(e){e.render(a.ctx,a.tView)});d=this.traverse();b.shift();c.each(d,function(e){e.render(a.ctx,c.Matrix())});this.ctx.restore()};c.cmds={};c.cmds.RequestFramerate=function(a,b){this.scene=a;this.requests=0;this.framerate=b.framerate;this.originalFramerate=this.scene.framerate};c.cmds.RequestFramerate.className="RequestFramerate";c.cmds.RequestFramerate.prototype.execute=function(){this.requests+=
1;this.scene.setFramerate(this.framerate)};c.cmds.RequestFramerate.prototype.unexecute=function(){this.requests-=1;this.requests<=0&&this.scene.setFramerate(this.originalFramerate)};c.Scene=function(a){var b=this;c.Actor.call(this,c.extend({width:0,height:0,fillStyle:"",idleFramerate:0,framerate:50,traverser:c.traverser.DepthFirst},a));this.mouseY=this.mouseX=NaN;this.interactiveActors={};this.activeActors=[];this.actors={};this.scene=this;this.displays=[];a.displays&&c.each(a.displays,function(f){b.displays.push(new c.Display(b,
f))});this.activeDisplay=this.displays[0];this.fps=0;this.framerate=this.p("idleFramerate");this.commands={};this.register(c.cmds.RequestFramerate,{framerate:this.p("framerate")});a.actors&&c.each(a.actors,function(f){b.add(f)});var d,e=false;this.bind("interact",function(){if(!e){b.execute(c.cmds.RequestFramerate);e=true}clearTimeout(d);d=setTimeout(function(){e=false;b.unexecute(c.cmds.RequestFramerate)},1E3)})};c.Scene.prototype=c.inherit(c.Actor);c.Scene.prototype.registerActor=function(a){var b=
a.id();if(this.actors[b])throw"ID '"+b+"' already registered.";a.scene=this;this.actors[b]=a;if(a.p("interactive"))this.interactiveActors[a.id()]=a};c.Scene.prototype.start=function(){this.running=true;this.trigger("start");this.loop();this.checkActiveActors()};c.Scene.prototype.setFramerate=function(a){this.framerate=a;clearTimeout(this.nextLoop);clearTimeout(this.nextPick);this.loop();this.checkActiveActors()};c.Scene.prototype.loop=function(){var a=this,b;if(this.running){this.fps=1E3/b<a.framerate?
1E3/b:a.framerate;b=(new Date).getTime();this.render();b=(new Date).getTime()-b;if(this.framerate>0)this.nextLoop=setTimeout(function(){a.loop()},1E3/a.framerate-b)}};c.Scene.prototype.render=function(){this.trigger("frame");this.compileMatrix();this.refreshDisplays()};c.Scene.prototype.stop=function(){this.running=false;this.trigger("stop")};c.Scene.prototype.checkActiveActors=function(){var a=this.displays[0].ctx,b=this,d=this.activeActors;if(this.running){if(this.scene.mouseX!==NaN){this.activeActors=
[];c.each(this.interactiveActors,function(e){if(e.checkActive(a,b.scene.mouseX,b.scene.mouseY)){b.activeActors.push(e);c.include(d,e)||e.trigger("mouseover")}else c.include(d,e)&&e.trigger("mouseout")})}if(b.framerate>0)this.nextPick=setTimeout(function(){b.checkActiveActors()},1E3/Math.min(b.framerate,15))}};c.Scene.prototype.refreshDisplays=function(){c.each(this.displays,function(a){a.compileMatrix();a.refresh()})};c.Scene.prototype.display=function(a){a=new c.Display(this,a);this.displays.push(a);
return a};c.Scene.prototype.register=function(a,b){this.commands[a.className]=new a(this,b)};c.Scene.prototype.execute=function(a){this.commands[a.className].execute()};c.Scene.prototype.unexecute=function(a){this.commands[a.className].unexecute()};c.TweenManager=c.TweenManager||function(){var a,b,d=[];this.add=function(e){d.push(e)};this.remove=function(e){for(var f=0,i=d.length;f<i;f++)if(e==d[f]){d.splice(f,1);return}};this.update=function(){a=0;for(b=(new Date).getTime();a<d.length;)d[a].update(b)?
a++:d.splice(a,1)};return this}();c.Tween=function(a){c.TweenManager.add(this);var b={},d={},e={},f=1E3,i=0,j=null,n=c.Tween.Easing.Back.EaseInOut,g=null,k=null,m=null,o=false;this.to=function(h,l){f=h*1E3;for(var q in l)if(a[q]!==null)e[q]=l[q];return this};this.start=function(){o=false;j=(new Date).getTime()+i;for(var h in e)if(a[h]!==null){b[h]=a[h];d[h]=e[h]-a[h]}return this};this.delay=function(h){i=h*1E3;return this};this.easing=function(h){n=h;return this};this.chain=function(h){g=h};this.onUpdate=
function(h){k=h;return this};this.onComplete=function(h){m=h;return this};this.update=function(h){var l;if(h<j||j===null)return true;if(o)return g===null;h=h-j;if(h>f){o=true;j=null;m!==null&&m();if(g!==null){g.start();return true}else return false}for(l in d)a[l]=n(h,b[l],d[l],f);k!==null&&k.apply(a);return true};this.destroy=function(){c.TweenManager.remove(this)}};c.Tween.Easing={Back:{},Elastic:{},Expo:{},Linear:{}};c.Tween.Easing.Back.EaseIn=function(a,b,d,e){return d*(a/=e)*a*(2.70158*a-1.70158)+
b};c.Tween.Easing.Back.EaseOut=function(a,b,d,e){return d*((a=a/e-1)*a*(2.70158*a+1.70158)+1)+b};c.Tween.Easing.Back.EaseInOut=function(a,b,d,e){var f=1.70158;if((a/=e/2)<1)return d/2*a*a*(((f*=1.525)+1)*a-f)+b;return d/2*((a-=2)*a*(((f*=1.525)+1)*a+f)+2)+b};c.Tween.Easing.Elastic.EaseIn=function(a,b,d,e){if(a==0)return b;if((a/=e)==1)return b+d;var f=e*0.3,i=f/4;return-(d*Math.pow(2,10*(a-=1))*Math.sin((a*e-i)*2*Math.PI/f))+b};c.Tween.Easing.Elastic.EaseOut=function(a,b,d,e){if(a==0)return b;if((a/=
e)==1)return b+d;var f=e*0.3,i=f/4;return d*Math.pow(2,-10*a)*Math.sin((a*e-i)*2*Math.PI/f)+d+b};c.Tween.Easing.Elastic.EaseInOut=function(a,b,d,e){if(a==0)return b;if((a/=e/2)==2)return b+d;var f=e*0.3*1.5,i=f/4;if(a<1)return-0.5*d*Math.pow(2,10*(a-=1))*Math.sin((a*e-i)*2*Math.PI/f)+b;return d*Math.pow(2,-10*(a-=1))*Math.sin((a*e-i)*2*Math.PI/f)*0.5+d+b};c.Tween.Easing.Expo.EaseIn=function(a,b,d,e){return a==0?b:d*Math.pow(2,10*(a/e-1))+b};c.Tween.Easing.Expo.EaseOut=function(a,b,d,e){return a==
e?b+d:d*(-Math.pow(2,-10*a/e)+1)+b};c.Tween.Easing.Expo.EaseInOut=function(a,b,d,e){if(a==0)return b;if(a==e)return b+d;if((a/=e/2)<1)return d/2*Math.pow(2,10*(a-1))+b;return d/2*(-Math.pow(2,-10*--a)+2)+b};c.Tween.Easing.Linear.EaseNone=function(a,b,d,e){return d*a/e+b};c.Tween.Easing.Linear.EaseIn=function(a,b,d,e){return d*a/e+b};c.Tween.Easing.Linear.EaseOut=function(a,b,d,e){return d*a/e+b};c.Tween.Easing.Linear.EaseInOut=function(a,b,d,e){return d*a/e+b};c.Rect=function(a){c.Actor.call(this,
c.extend({width:0,height:0,fillStyle:"#777",strokeStyle:"#000",lineWidth:0},a))};c.Actor.registeredActors.rect=c.Rect;c.Rect.prototype=c.inherit(c.Actor);c.Rect.prototype.bounds=function(){return[{x:0,y:0},{x:this.p("width"),y:0},{x:this.p("width"),y:this.p("height")},{x:0,y:this.p("height")}]};c.Rect.prototype.draw=function(a){this.p("fillStyle")&&a.fillRect(0,0,this.p("width"),this.p("height"));this.p("lineWidth")>0&&a.strokeRect(0,0,this.p("width"),this.p("height"))};c.Label=function(a){c.Actor.call(this,
c.extend({text:"",textAlign:"start",font:"12px Helvetica, Arial",fillStyle:"#444",lineWidth:0,backgroundStyle:"#eee",background:false},a))};c.Actor.registeredActors.label=c.Label;c.Label.prototype=c.inherit(c.Actor);c.Label.prototype.draw=function(a){a.font=this.p("font");a.textAlign=this.p("textAlign");a.fillText(this.p("text"),0,0)};c.Circle=function(a){c.Actor.call(this,c.extend({radius:20,strokeWeight:2,lineWidth:0,strokeStyle:"#fff"},a))};c.Actor.registeredActors.circle=c.Circle;c.Circle.prototype=
c.inherit(c.Actor);c.Circle.prototype.bounds=function(){return[{x:-this.p("radius"),y:-this.p("radius")},{x:this.p("radius"),y:-this.p("radius")},{x:this.p("radius"),y:this.p("radius")},{x:-this.p("radius"),y:this.p("radius")}]};c.Circle.prototype.draw=function(a){a.fillStyle=this.p("fillStyle");a.strokeStyle=this.p("strokeStyle");a.lineWidth=this.p("lineWidth");a.beginPath();a.arc(0,0,this.p("radius"),0,Math.PI*2,false);a.closePath();this.p("lineWidth")>0&&a.stroke();a.fill()};c.Path=function(a){c.Actor.call(this,
c.extend({points:[],lineWidth:1,strokeStyle:"#000",fillStyle:""},a));this.transformedPoints=this.points=[].concat(this.p("points"))};c.Actor.registeredActors.path=c.Path;c.Path.prototype=c.inherit(c.Actor);c.Path.prototype.transform=function(a,b){this.transformedPoints=this.points=[].concat(this.p("points"));if(this.p("transformMode")==="origin"){var d=this.tShape().concat(b).concat(this._tWorld);a.setTransform(1,0,0,1,0,0);this.transformedPoints=this.points.map(function(e){var f=d.transformPoint(e),
i=d.transformPoint(c.Point(e.cp1x,e.cp1y)),j=d.transformPoint(c.Point(e.cp2x,e.cp2y));f={x:f.x,y:f.y};if(e.cp1x&&e.cp1y){f.cp1x=i.x;f.cp1y=i.y}if(e.cp2x&&e.cp2y){f.cp2x=j.x;f.cp2y=j.y}return f})}else c.Actor.prototype.transform.call(this,a,b)};c.Path.prototype.draw=function(a){var b=[].concat(this.transformedPoints),d;if(b.length>=1){a.beginPath();d=b.shift();for(a.moveTo(d.x,d.y);d=b.shift();)if(d.cp1x&&d.cp2x)a.bezierCurveTo(d.cp1x,d.cp1y,d.cp2x,d.cp2y,d.x,d.y);else d.cp1x?a.quadraticCurveTo(d.cp1x,
d.cp1y,d.x,d.y):a.lineTo(d.x,d.y);this.p("lineWidth")>0&&this.p("strokeStyle")!==""&&a.stroke();this.p("fillStyle")!==""&&a.fill();a.closePath()}};this.uv=c;if(typeof exports!=="undefined")exports.uv=c})();