-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanima.min.js
2 lines (2 loc) · 18.5 KB
/
anima.min.js
1
2
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.Anima=e()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){module.exports={KEYS:require("./keys.js"),FrameManager:require("./frames.js"),GL:require("./gl.js"),Movable:require("./movable.js"),Movable2D:require("./movable2d.js"),Movable3D:require("./movable3d.js"),Movable3DUpright:require("./movable3d-upright.js")}},{"./frames.js":2,"./gl.js":3,"./keys.js":4,"./movable.js":5,"./movable2d.js":6,"./movable3d-upright.js":7,"./movable3d.js":8}],2:[function(require,module,exports){var nativeRequestAnimFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(callback,element){window.setTimeout(function(){return callback((new Date).valueOf()+16)},16)},FrameManager=function(callback){this.next_id=NaN,this.prev_time=NaN,this.last_frame_start=NaN,this.dt=this.DEFAULT_DT,this.drawCallback=callback||function(){},this.requestFrame=this.requestFrame.bind(this),this.drawWrapper=this.drawWrapper.bind(this),this.lod=null,this.lod_modes={}};FrameManager.prototype={DEFAULT_DT:16,requestFrame:function(){return this.next_id||(this.next_id=nativeRequestAnimFrame(this.drawWrapper)),this.next_id},currentFrameTime:function(){return(new Date).valueOf()-this.last_frame_start||16},addLOD:function(name,options){this.lod_modes[name]=new FrameManager.LOD(this);for(var key in options)options.hasOwnProperty(key)&&(this.lod_modes[name][key]=options[key])},selectLOD:function(name){this.lod=this.lod_modes[name]},adjustLOD:function(){var frame_time=this.currentFrameTime();frame_time<this.lod.frame_min?this.lod.up():frame_time>this.lod.frame_max&&this.lod.down()},upLOD:function(){},downLOD:function(){},drawWrapper:function(time_scheduled){this.next_id=NaN,this.setFrameStart(time_scheduled),this.dt=time_scheduled-this.prev_time||this.DEFAULT_DT;var draw_again=this.drawCallback.apply(this,arguments);draw_again?(this.prev_time=time_scheduled,this.requestFrame()):this.prev_time=NaN},setFrameStart:function(time_scheduled){this.last_frame_start=(new Date).valueOf()}},window.performance&&window.performance.now&&(FrameManager.prototype.setFrameStart=function(time_scheduled){this.last_frame_start=time_scheduled},FrameManager.prototype.currentFrameTime=function(){return window.performance.now()-this.last_frame_start||16}),FrameManager.LOD=function(frame_manager){this.frame_manager=frame_manager},FrameManager.LOD.prototype={frame_min:8,frame_max:16,up:function(){this.frame_manager.upLOD()},down:function(){this.frame_manager.downLOD()}},module.exports=FrameManager},{}],3:[function(require,module,exports){(function(global){var $="undefined"!=typeof window?window.$:"undefined"!=typeof global?global.$:null,GLWrapper=function(canvas){this.gl=null,this.context_serial=0,this.shader_sources={},this.shaders={},this.projection_matrix=new Float32Array(16),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this),this.resize=this.resize.bind(this),canvas&&this.bindCanvas(canvas)},Texture=function(image_data,generators){this.image_data=image_data,this.size=image_data.width,this.generators=generators||[]};Texture.prototype={_gl_texture:null,_mipmaps:null,getGLTexture:function(gl){if(this._gl_texture)return this._gl_texture;var t=this._gl_texture=gl.createTexture();return gl.bindTexture(gl.TEXTURE_2D,t),gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL,!0),gl.texImage2D(gl.TEXTURE_2D,0,gl.RGBA,gl.RGBA,gl.UNSIGNED_BYTE,this.image_data),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MAG_FILTER,gl.LINEAR),gl.texParameteri(gl.TEXTURE_2D,gl.TEXTURE_MIN_FILTER,gl.LINEAR_MIPMAP_NEAREST),gl.generateMipmap(gl.TEXTURE_2D),gl.bindTexture(gl.TEXTURE_2D,null),t},getMipmaps:function(){return this._mipmaps?this._mipmaps:(this._mipmaps=generateMipmaps(this.image_data.data,this.size),this._mipmaps)}},GLWrapper.prototype={setupCallback:function(){},resizeCallback:function(w,h){},bindCanvas:function(canvas){if(this.canvas=canvas,!canvas.getContext)return null;if(this.gl=canvas.getContext("webgl")||canvas.getContext("experimental-webgl"),!this.gl)throw"WebGL unavailable.";this.context_serial++,this.canvas.addEventListener("webglcontextlost",this.handleContextLost,!1),this.canvas.addEventListener("webglcontextrestored",this.handleContextRestored,!1);for(var name in this.shader_sources)this.linkProgram(name);this.setupCallback()},resize:function(w,h){this.canvas.width=w,this.canvas.height=h,this.gl&&this.gl.viewport(0,0,w,h),this.resizeCallback(w,h)},handleContextLost:function(e){e.preventDefault(),this.canvas.removeEventListener("webglcontextlost",this.handleContextLost,!1)},handleContextRestored:function(e){this.bindCanvas(this.canvas)},setProjectionMatrix:function(w,h,n,f){var m=this.projection_matrix;m[0]=1/w,m[5]=1/h,m[10]=(n+f)/(n-f),m[11]=-1,m[14]=2*n*f/(n-f),m[1]=m[2]=m[3]=m[4]=m[6]=m[7]=m[8]=m[9]=m[12]=m[13]=m[15]=0},addProgram:function(name,vert,frag){this.shader_sources[name]=[vert,frag],this.gl&&this.linkProgram(name)},addProgramByURLs:function(name,vert,frag,callback){function tryCompiling(index,data){loaded|=1<<index,code[index]=data,3==(3&loaded)&&(this.addProgram(name,code[0],code[1]),callback())}var code=["",""],loaded=0;$.get(vert,tryCompiling.bind(this,0)),$.get(frag,tryCompiling.bind(this,1))},linkProgram:function(name){function compile(source,i){var ans=gl.createShader(TYPES[i]);if(gl.shaderSource(ans,source),gl.compileShader(ans),!gl.getShaderParameter(ans,gl.COMPILE_STATUS)&&!gl.isContextLost())throw"Shader compile error: "+gl.getShaderInfoLog(ans);return ans}if(!this.shader_sources[name])return null;var gl=this.gl,TYPES=[gl.VERTEX_SHADER,gl.FRAGMENT_SHADER],objs=this.shader_sources[name].map(compile),prog=gl.createProgram();if(gl.attachShader(prog,objs[0]),gl.attachShader(prog,objs[1]),gl.linkProgram(prog),!gl.getProgramParameter(prog,gl.LINK_STATUS)&&!gl.isContextLost())throw"Shader link error: "+gl.getProgramInfoLog(prog);return this.shaders[name]=prog,prog}},module.exports=GLWrapper}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],4:[function(require,module,exports){for(var keys={SHIFT:16,ESC:27,SPACE:32,LEFT:37,UP:38,RIGHT:39,DOWN:40,"<":188,">":190,QUESTION:191,TILDE:192,APOSTROPHE:222},i=0;10>i;i++)keys[i]=48+i;for(var i=65;91>i;i++)keys[String.fromCharCode(i)]=i;for(var i=1;13>i;i++)keys["F"+i]=111+i;module.exports=keys},{}],5:[function(require,module,exports){(function(global){var KEYS=require("./keys.js"),$="undefined"!=typeof window?window.$:"undefined"!=typeof global?global.$:null,Hammer="undefined"!=typeof window?window.Hammer:"undefined"!=typeof global?global.Hammer:null,Movable=function(){this.velocity=[0,0,0,0],this.speed=[1,1,.001,.001],this.key_map={},this.keys_down={},this.touch_map={pan_x:{which:0,amount:-1},pan_y:{which:1,amount:-1},rotate:{which:2,amount:1},pinch:{which:3,amount:1},wheel:{which:3,amount:1}},this.key_map[KEYS.LEFT]={which:0,amount:-1},this.key_map[KEYS.RIGHT]={which:0,amount:1},this.key_map[KEYS.UP]={which:1,amount:-1},this.key_map[KEYS.DOWN]={which:1,amount:1},this.key_map[KEYS["<"]]={which:2,amount:-1},this.key_map[KEYS[">"]]={which:2,amount:1},this.key_map[189]=this.key_map[173]=this.key_map[109]={which:3,amount:-1},this.key_map[187]=this.key_map[61]=this.key_map[107]={which:3,amount:1},this.decay_rate=this.decay_coast,this.is_hammer_busy=!1,this.zoom_center=null,this.screen_center=[0,0]};Movable.prototype={run_multiplier:4,decay_coast:.002,decay_brake:.01,overlay_selector:".overlay",default_dt:16,options:{pan:{threshold:0,pointers:0},rotate:{threshold:0},pinch:{threshold:0}},updateVelocity:function(dt){function decay(t,cap){var ds,s=Math.abs(t);return s>cap?t*Math.max(0,1-dt*accel_rate):(ds=dt*cap*decay_rate,t>ds?t-ds:-ds>t?t+ds:0)}dt=dt||this.default_dt;var vmax=1;this.keys_down[KEYS.SHIFT]&&(vmax*=this.run_multiplier);var decay_rate=this.decay_rate,accel_rate=this.decay_coast+this.decay_brake;if(this.canAccelerate())for(var key in this.key_map)if(this.key_map.hasOwnProperty(key)){var km=this.key_map[key],i=km.which;this.velocity[i]=this.velocity[i]||0,this.keys_down[key]&&(this.velocity[i]+=accel_rate*vmax*(this.speed[i]||1)*km.amount*dt)}for(var i=0;i<this.velocity.length;i++)this.velocity[i]=decay(this.velocity[i],vmax*(this.speed[i]||1))},update:function(dt){dt=this.last_dt=dt||this.default_dt,this.updateVelocity(dt),this.isMoving()&&(this.move(dt),this.motionCallback())},isMoving:function(){if(this.is_hammer_busy)return!1;for(var i=0;i<this.velocity.length;i++)if(this.velocity[i])return!0;for(var key in this.key_map)if(this.key_map.hasOwnProperty(key)&&this.keys_down[key])return!0;return!1},bind:function(element){this.bindKeyboard(element),this.bindTouch(element)},bindKeyboard:function(element){var t=this,press=function(e){var motion_changed=!0;t.key_map[e.which]&&(motion_changed=!t.keys_down[e.which],t.keys_down[e.which]=!0,t.decay_rate=t.decay_brake,t.zoom_center=null,motion_changed&&t.motionCallback()),t.keys_down[KEYS.SHIFT]=e.shiftKey,e.which==KEYS.ESC&&t.canAccelerate()&&(t.moveReset(),t.decay_rate=t.decay_brake,t.zoom_center=null,t.motionCallback())},release=function(e){t.keys_down[e.which]&&(t.keys_down[e.which]=!1),t.keys_down[KEYS.SHIFT]=e.shiftKey},releaseAll=function(e){if("mouseleave"!=e.type||!e.toElement)for(var k in t.keys_down)"mouse"!=k&&(t.keys_down[k]=!1)};element=$(element),element.on("keydown.mKeyboard",press),element.on("keyup.mKeyboard",release),element.on("blur.mKeyboard mouseleave.mKeyboard",releaseAll)},bindTouch:function(element){var h=this.hammer,t=this,last=null,last_pointers=null;$(element).on("wheel DOMMouseScroll mousewheel",function(e){e=e.originalEvent,isNaN(e.pageX)||(t.zoom_center=[e.pageX,e.pageY]);var delta_y=e.wheelDelta||-e.detail;Math.abs(delta_y)>20&&(delta_y/=120),t.decay_rate=t.decay_coast,t.touchVelocity("wheel",delta_y/400,.5),t.motionCallback()}),t.setScreenCenter(element),$(window).on("load scroll resize",function(e){t.setScreenCenter(element)}),$(element).on("mousedown selectstart",function(e){e.preventDefault()}),$(window).on("mouseup touchcancel touchend mouseleave touchleave",function(e){e.relatedTarget||t.touchEnd()}),Hammer&&!this.hammer&&(h=this.hammer=new Hammer.Manager($(element)[0]),h.add(new Hammer.Pan(this.options.pan)),h.add(new Hammer.Rotate(this.options.rotate).recognizeWith(h.get("pan"))),h.add(new Hammer.Pinch(this.options.pinch).recognizeWith([h.get("pan"),h.get("rotate")])),h.on("hammer.input",function(e){var prev=h.session.prevInput||e;e.incTime=e.deltaTime-prev.deltaTime,e.incX=e.deltaX-prev.deltaX,e.incY=e.deltaY-prev.deltaY,e.incScale=e.scale/prev.scale||1;var rot=(450+e.rotation-prev.rotation)%360-90;rot>90&&(rot-=180),e.incRotation=rot*Math.PI/180,t.is_hammer_busy=!e.isFinal,t.decay_rate=t.decay_coast,t.zoom_center=[e.center.x,e.center.y]}),this.hammer.on("pan rotate pinch",function(e){if(last!=e.timeStamp){if(last=e.timeStamp,e.incTime&&last_pointers==e.pointers.length){var scl=e.incScale;scl>.1&&10>scl||(scl=1),t.movePinch(scl),t.moveRotate(e.incRotation),t.movePan(e.incX,e.incY);var weight=Math.min(1,.01*e.incTime);t.touchVelocity("pan_x",e.incX/e.incTime,weight),t.touchVelocity("pan_y",e.incY/e.incTime,weight),t.touchVelocity("rotate",e.incRotation/e.incTime,weight),t.touchVelocity("pinch",(scl-1)/e.incTime,weight)}last_pointers=e.pointers.length,e.isFinal?(last=null,last_pointers=null):t.is_hammer_busy=!0,t.decay_rate=t.decay_coast,t.motionCallback()}}))},touchVelocity:function(key,value,weight){return(key=this.touch_map[key])?(isNaN(value)||(isNaN(weight)&&(weight=1),this.velocity[key.which]*=1-weight,this.velocity[key.which]+=weight*value*key.amount),this.velocity[key.which]):void 0},touchEnd:function(){this.is_hammer_busy=!1},setScreenCenter:function(element){var p=$(element).offset();this.screen_center=[p.left-$(window).scrollLeft()+$(element).width()/2,p.top-$(window).scrollTop()+$(element).height()/2]},canAccelerate:function(){return!$(this.overlay_selector).is(":target")},motionCallback:function(){}},module.exports=Movable}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./keys.js":4}],6:[function(require,module,exports){var Movable=(require("./keys.js"),require("./movable.js")),Movable2D=function(){Movable.apply(this,arguments),this.speed[0]=this.speed[1]=.002,this.position=[0,0,0,0],this.cos=1,this.sin=0,this.scale=1,this.units_per_px=1};Movable2D.prototype=Object.create(Movable.prototype),function(){this.move=function(dt){var s=1/this.units_per_px;this.moveRotate(this.velocity[this.touch_map.rotate.which]*dt),this.moveZoomWithCenter(this.velocity[this.touch_map.pinch.which]*dt),this.movePan(this.velocity[this.touch_map.pan_x.which]*dt*s,this.velocity[this.touch_map.pan_y.which]*dt*s)},this.moveReset=function(){for(var i=0;i<this.velocity.length;i++)this.position[i]=this.velocity[i]=0;this.cos=1,this.sin=0,this.scale=1},this.movePan=function(x,y){var ix=this.touch_map.pan_x.which,iy=this.touch_map.pan_y.which,s=this.units_per_px/this.scale;x*=s,y*=s,this.position[ix]=this.position[ix]||0,this.position[iy]=this.position[iy]||0,this.position[ix]+=this.cos*x+this.sin*y,this.position[iy]+=-this.sin*x+this.cos*y},this.moveRotate=function(angle){var i=this.touch_map.rotate.which,cx=0,cy=0;this.zoom_center&&(cx=this.zoom_center[0]-this.screen_center[0],cy=this.zoom_center[1]-this.screen_center[1]),this.position[i]=(this.position[i]||0)+angle,this.movePan(-cx,-cy),this.cos=Math.cos(this.position[i]),this.sin=Math.sin(this.position[i]),this.movePan(cx,cy)},this.moveZoom=function(amount){isFinite(this.scale)||(this.scale=1),this.scale*=Math.exp(amount||0)},this.movePinch=function(scale){this.moveZoomWithCenter(Math.log(scale))},this.moveZoomWithCenter=function(amount){var cx=0,cy=0;this.zoom_center&&this.screen_center&&(cx=this.zoom_center[0]-this.screen_center[0],cy=this.zoom_center[1]-this.screen_center[1]),this.movePan(-cx,-cy),this.moveZoom(amount),this.movePan(cx,cy)}}.call(Movable2D.prototype),module.exports=Movable2D},{"./keys.js":4,"./movable.js":5}],7:[function(require,module,exports){var Movable3D=require("./movable3d.js");Movable3DUpright=function(){Movable3D.apply(this,arguments),this.angle_xz=0,this.angle_zy=0},Movable3DUpright.prototype=Object.create(Movable3D.prototype),function(){var TWOPI=2*Math.PI,HALFPI=Math.PI/2;this.moveRotateMix=function(from,to,angle){2>from&&2>to||(0==from?this.angle_xz+=angle:0==to?this.angle_xz-=angle:1==to?this.angle_zy-=angle:this.angle_zy+=angle)},this.setRotation=function(){this.angle_xz%=TWOPI,this.angle_zy=Math.max(-HALFPI,Math.min(this.angle_zy,HALFPI));var cxz=Math.cos(this.angle_xz),sxz=Math.sin(this.angle_xz),czy=Math.cos(this.angle_zy),szy=Math.sin(this.angle_zy);this.rotation[0][0]=cxz,this.rotation[0][2]=sxz,this.rotation[1][0]=-sxz*szy,this.rotation[1][1]=czy,this.rotation[1][2]=cxz*szy,this.rotation[2][0]=-sxz*czy,this.rotation[2][1]=-szy,this.rotation[2][2]=cxz*czy};var moveResetSuper=this.moveReset;this.moveReset=function(){moveResetSuper.call(this),this.angle_xz=this.angle_zy=0};var movePanSuper=this.movePan;this.movePan=function(){movePanSuper.apply(this,arguments),this.setRotation()};var moveRBVSuper=this.moveRotateByVelocity;this.moveRotateByVelocity=function(dt){moveRBVSuper.call(this,dt),this.setRotation()}}.call(Movable3DUpright.prototype),module.exports=Movable3DUpright},{"./movable3d.js":8}],8:[function(require,module,exports){var KEYS=require("./keys.js"),Movable=require("./movable.js"),Movable3D=function(){Movable.apply(this,arguments),this.speed[0]=this.speed[1]=.001,this.speed[4]=.002,this.key_map[KEYS.DOWN].amount*=-1,this.key_map[KEYS.UP].amount*=-1,this.key_map.press=this.key_map[KEYS.SPACE]={which:4,amount:1},this.key_map[KEYS.Z]={which:4,amount:-1},this.origin=null,this.displacement=null,this.rotation=null,this.scale=1,this.units_per_px=1,this.fly_center=[0,0]};Movable3D.prototype=Object.create(Movable.prototype),function(){this.move=function(dt){this.keys_down.press&&(this.velocity[0]=this.speed[0]*(this.fly_center[0]-this.screen_center[0])*this.units_per_px,this.velocity[1]=this.speed[1]*(this.fly_center[1]-this.screen_center[1])*this.units_per_px),this.moveRotateByVelocity(dt),this.moveFly(dt*this.velocity[this.key_map.press.which]),this.moveZoom(dt*this.velocity[this.touch_map.pinch.which])},this.moveReset=function(){this.origin=[0,0,0],this.displacement=[0,0,0],this.rotation=[[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]]},this.moveRotateByVelocity=function(dt){this.moveRotateMix(0,2,this.velocity[this.touch_map.pan_x.which]*dt),this.moveRotateMix(1,2,-this.velocity[this.touch_map.pan_y.which]*dt),this.moveRotateMix(0,1,this.velocity[this.touch_map.rotate.which]*dt)},this.moveRotateMix=function(from,to,angle){angle=angle||0;for(var c=Math.cos(angle),s=Math.sin(angle),t=0,x=this.rotation[from],y=this.rotation[to],i=0;4>i;i++)t=x[i]*c+y[i]*s,y[i]=-x[i]*s+y[i]*c,x[i]=t},this.movePan=function(x,y){this.keys_down.press||(this.moveRotateMix(2,0,x*this.units_per_px),this.moveRotateMix(1,2,y*this.units_per_px))},this.moveRotate=function(angle){this.moveRotateMix(0,1,angle)},this.moveZoom=function(amount){isFinite(this.scale)||(this.scale=1),this.scale*=Math.exp(amount||0)},this.movePinch=function(scale){this.moveZoom(Math.log(scale))},this.moveFly=function(distance){if(distance)for(var d=distance/this.scale,i=0;3>i;i++)this.origin[i]+=this.rotation[2][i]*d};var isMovingSuper=this.isMoving;this.isMoving=function(){return this.keys_down.press?!0:isMovingSuper.call(this)};var touchEndSuper=this.touchEnd;this.touchEnd=function(){touchEndSuper.call(this),this.keys_down.press=!1};var bindTouchSuper=this.bindTouch;this.bindTouch=function(element){bindTouchSuper.call(this,element);var h=this.hammer;h.add(new Hammer.Press({threshold:10}).recognizeWith(h.get("pan"))),h.on("press",function(e){this.keys_down.press=!0,this.decay_rate=this.decay_coast,this.motionCallback()}.bind(this)),h.on("press pan",function(e){this.fly_center[0]=e.center.x,this.fly_center[1]=e.center.y}.bind(this))}}.call(Movable3D.prototype),module.exports=Movable3D},{"./keys.js":4,"./movable.js":5}]},{},[1])(1)});
//# sourceMappingURL=anima.min.js.map