animationvideo
Version:
Javascript-Libary for animation and audio syncing
1 lines • 102 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.AnimationVideo={})}(this,function(t){function e(t){for(var e=[],i=arguments.length-1;i-- >0;)e[i]=arguments[i+1];return"function"==typeof t?t.apply(null,e):t}var i=function(t){var e=this,i=t;if("object"!=typeof t)throw new Error("No canvas given for Engine constructor");if(t.getContext)i={canvas:t};else if(!t.canvas)throw new Error("No canvas given for Engine constructor");var n=Object.assign({},{scene:null,canvas:null,autoSize:!1,clickToPlayAudio:!1},i);if(this._output={canvas:null,context:null,width:0,height:0,ratio:1},this._scene=null,this._isSceneInitialized=!1,this._newScene=null,this._lastTimestamp=0,this._timePassed=0,this._recalculateCanvas=!1,this._referenceRequestAnimationFrame=null,this._output.canvas=n.canvas,"object"!=typeof n.canvas||null===n.canvas||!n.canvas.getContext)throw new Error("Countn't create contect for canvas in Engine");if(n.autoSize){var r={enabled:!0,scaleLimitMin:1,scaleLimitMax:8,scaleFactor:1.1,referenceWidth:function(){return e._output.canvas.clientWidth},referenceHeight:function(){return e._output.canvas.clientHeight},currentScale:1,waitTime:800,currentWaitedTime:0,currentOffsetTime:0,offsetTimeLimitUp:300,offsetTimeLimitDown:300,offsetTimeTarget:1e3/60,offsetTimeDelta:3,registerResizeEvents:!0,registerVisibilityEvents:!0,setCanvasStyle:!1};this._autoSize="object"==typeof n.autoSize?Object.assign({},r,n.autoSize):r,this._autoSize.registerResizeEvents&&(window.addEventListener("resize",this.recalculateCanvas.bind(this),!1),window.addEventListener("orientationchange",this.recalculateCanvas.bind(this),!1)),this._autoSize.registerVisibilityEvents&&document.addEventListener("visibilitychange",this.handleVisibilityChange.bind(this),!1),this.recalculateCanvas()}else this._output.width=this._output.canvas.width,this._output.height=this._output.canvas.height,this._output.ratio=this._output.width/this._output.height;this._output.context=n.canvas.getContext("2d"),n.clickToPlayAudio&&n.canvas.addEventListener("click",this.playAudioOfScene.bind(this),!1),this.switchScene(n.scene),this.normalizeContext(this._output.context)};i.prototype.handleVisibilityChange=function(){this._autoSize.enabled=!("hidden"==document.visibilityState)},i.prototype.playAudioOfScene=function(){this._isSceneInitialized&&this._scene&&this._scene.audioElement&&this._scene.audioElement.play()},i.prototype.normalizeContext=function(t){t.textBaseline="middle",t.textAlign="center",t.globalAlpha=1,t.globalCompositeOperation="source-over"},i.prototype.getWidth=function(){return this._output.width},i.prototype.getHeight=function(){return this._output.height},i.prototype.recalculateCanvas=function(){if(this._autoSize){var t=e(this._autoSize.referenceWidth),i=e(this._autoSize.referenceHeight);if(t<=0||i<=0)return;this._output.canvas.width=Math.round(t/this._autoSize.currentScale),this._output.canvas.height=Math.round(i/this._autoSize.currentScale),this._autoSize.setCanvasStyle&&(this._output.canvas.style.width=t+"px",this._output.canvas.style.height=i+"px"),this._autoSize.currentWaitedTime=0,this._autoSize.currentOffsetTime=0}return this._output.width=this._output.canvas.width,this._output.height=this._output.canvas.height,this._output.ratio=this._output.width/this._output.height,this.resize(),this},i.prototype.resize=function(){return this._scene&&this._scene.resize&&this._scene.resize(this._output),this},i.prototype.switchScene=function(t){return t&&(this._newScene=t),this},i.prototype.run=function(t){return t=t||{},this._referenceRequestAnimationFrame=window.requestAnimationFrame(function e(i){if(this._referenceRequestAnimationFrame=window.requestAnimationFrame(e.bind(this)),this._recalculateCanvas&&(this.recalculateCanvas(),this._recalculateCanvas=!1),this._realLastTimestamp||(this._realLastTimestamp=i),null!==this._newScene){var n=this._scene?this._scene.destroy(this._output):t;n&&(this._newScene.callInit(this._output,n,this),this._scene=this._newScene,this._newScene=null,this._isSceneInitialized=!1)}if(this._scene&&this._output.canvas.width){var r=this._scene.currentTime();this._timePassed=this._scene.clampTime(r-this._lastTimestamp);var a=this._scene.shiftTime(this._timePassed);if(this._timePassed=this._timePassed+a,this._lastTimestamp=r+a,this._isSceneInitialized){if(0!==this._timePassed&&(this._autoSize&&this._autoSize.enabled&&(r=window.performance?performance.now():Date.now()),this._scene.move(this._output,this._timePassed),this._timePassed<0&&(this._timePassed=this._scene.totalTimePassed),this._scene.draw(this._output),this._autoSize&&this._autoSize.enabled)){var o=(window.performance?performance.now():Date.now())-r-this._autoSize.offsetTimeTarget;this._autoSize.currentWaitedTime<this._autoSize.waitTime?this._autoSize.currentWaitedTime+=i-this._realLastTimestamp:Math.abs(o)<=this._autoSize.offsetTimeDelta?this._autoSize.currentOffsetTime=this._autoSize.currentOffsetTime>=0?Math.max(0,this._autoSize.currentOffsetTime-this._autoSize.offsetTimeDelta):Math.min(0,this._autoSize.currentOffsetTime+this._autoSize.offsetTimeDelta):o<0&&this._autoSize.currentScale>this._autoSize.scaleLimitMin?(this._autoSize.currentOffsetTime+=o,this._autoSize.currentOffsetTime<=this._autoSize.offsetTimeLimitDown&&(this._autoSize.currentScale=Math.max(this._autoSize.scaleLimitMin,this._autoSize.currentScale/this._autoSize.scaleFactor),this._recalculateCanvas=!0)):o>0&&this._autoSize.currentScale<this._autoSize.scaleLimitMax&&(this._autoSize.currentOffsetTime+=o,this._autoSize.currentOffsetTime>=this._autoSize.offsetTimeLimitUp&&(this._autoSize.currentScale=Math.min(this._autoSize.scaleLimitMax,this._autoSize.currentScale*this._autoSize.scaleFactor),this._recalculateCanvas=!0))}}else this._isSceneInitialized=this._scene.callLoading(this._output),this._isSceneInitialized&&(this._scene.reset(this._output),this._autoSize&&(this._autoSize.currentWaitedTime=0))}this._realLastTimestamp=i}.bind(this)),this},i.prototype.destroy=function(){return this._referenceRequestAnimationFrame&&window.cancelAnimationFrame(this._referenceRequestAnimationFrame),this._referenceRequestAnimationFrame=null,this._scene&&this._scene.destroy(this._output),window.removeEventListener("resize",this.recalculateCanvas.bind(this),!1),window.removeEventListener("orientationchange",this.recalculateCanvas.bind(this),!1),document.removeEventListener("visibilitychange",this.handleVisibilityChange.bind(this),!1),this._output.canvas.removeEventListener("click",this.playAudioOfScene.bind(this),!1),this};var n=function(){};n.add=function(t,e){var i=this||n,r=function(n){if(i.Images[n])e&&"function"==typeof e[n]&&e[n](n,i.Images[n]);else{if(i.Images[n]=new window.Image,i.Images[n].onload=function(){i.loaded++,e&&"function"==typeof e?i.isLoaded()&&e():e&&"function"==typeof e[n]&&e[n](n,i.Images[n]),i.resolve&&i.isLoaded()&&(i.resolve(),i.resolve=null)},"<svg"===t[n].substr(0,4)){var r=window.URL||window.webkitURL||window,a=new window.Blob([t[n]],{type:"image/svg+xml"});i.Images[n].src=r.createObjectURL(a)}else i.Images[n].src=t[n];i.count++}};for(var a in t)r(a);return e&&"function"==typeof e&&i.isLoaded()&&e(),i.resolve&&i.isLoaded()&&(i.resolve(),i.resolve=null),i},n.reset=function(){var t=this||n;return t.Images={},t.count=0,t.loaded=0,t},n.getLoaded=function(){return(this||n).loaded},n.getCount=function(){return(this||n).count},n.isLoaded=function(){var t=this||n;return t.loaded===t.count},n.getImage=function(t){return"object"==typeof t?t:(this||n).Images[t]},n.isLoadedPromise=function(){var t=this||n;return!!t.isLoaded()||new Promise(function(e,i){t.resolve=e})},n.Images={},n.count=0,n.loaded=0;var r=function(){this.layer=[],this.isFunction=[],this.start=0,this.nextFree=0};r.prototype.addElement=function(t){return this.addElementForId(t),t},r.prototype.addElements=function(t){return this.addElementsForIds(t),t},r.prototype.addElementForId=function(t){var e=this.layer.length,i=this.nextFree;this.layer[i]=t,this.isFunction[i]="function"==typeof t,e===i&&e++;for(var n=this.nextFree+1;n!==e&&layer[n];)n++;return this.nextFree=n,this.start>i&&(this.start=i),i},r.prototype.addElementsForIds=function(t){var e=this,i=this.layer.length;return i===this.nextFree?(this.layer=this.layer.concat(t),this.nextFree=this.layer.length,t.forEach(function(t,n){e.isFunction[i+n]="function"==typeof t}),Array.from({length:t.length},function(t,e){return e+i})):t.map(function(t){return e.addElement(t)})},r.prototype.getById=function(t){return this.layer[t]},r.prototype.getIdByElement=function(t){return this.layer.indexOf(t)},r.prototype.deleteByElement=function(t){var e=this.getIdByElement(t);e>=0&&this.deleteById(e)},r.prototype.deleteById=function(t){var e=this.layer.length-1;if(e>0&&t===e){for(this.layer[t]=null;e&&!this.layer[e-1];)e--;this.layer.length=e,this.isFunction.length=e,this.nextFree=Math.min(this.nextFree,e),this.start=Math.min(this.start,e)}else this.layer[t]=null,this.nextFree=Math.min(this.nextFree,t),this.start===t&&(this.start=t+1)},r.prototype.forEach=function(t){var e,i,n=this.layer.length;for(e=this.start;e<n;e++)(i=this.layer[e])&&t({index:e,element:i,isFunction:this.isFunction[e],layer:this})},r.prototype.count=function(){for(var t=0,e=this.layer.length,i=this.start;i<e;i++)this.layer[i]&&t++;return t},r.prototype.clear=function(){this.layer=[],this.isFunction=[],this.start=0,this.nextFree=0};var a=function(){this.layers=[]};function o(t,e){return null==t||""===t?e:t}a.prototype.addLayer=function(){return this.layers[this.layers.length]=new r,this.layers[this.layers.length-1]},a.prototype.addLayers=function(t){void 0===t&&(t=1);var e=Array.from({length:t},function(t){return new r});return this.layers=this.layers.concat(e),e},a.prototype.addLayerForId=function(){return this.layers[this.layers.length]=new r,this.layers.length-1},a.prototype.addLayersForIds=function(t){var e=this;void 0===t&&(t=1);var i=Array.from({length:t},function(t,i){return i+e.layers.length});return this.layers=this.layers.concat(Array.from({length:t},function(t){return new r})),i},a.prototype.getById=function(t){return this.layers[t]},a.prototype.forEach=function(t){var e,i=this.layers.length;for(e=0;e<i;e++)this.layers[e].forEach(t)},a.prototype.count=function(){return this.layers.length},a.prototype.clear=function(){this.layers=[]};var s=function(t){this.configuration="function"==typeof t?new t:t,this.layerManager=new a,this.totalTimePassed=0,this.engine=null,this.initDone=!1,this.additionalModifier=void 0,this.tickChunk=o(e(this.configuration.tickChunk),100/6),this.maxSkippedTickChunk=o(e(this.configuration.maxSkippedTickChunk),3),this.tickChunkTolerance=o(e(this.configuration.tickChunkTolerance),.1)};s.prototype.currentTime=function(){return window.performance?performance.now():Date.now()},s.prototype.clampTime=function(t){var e=2e3;return this.tickChunk&&(e=this.tickChunk*this.maxSkippedTickChunk),t>e?e:t},s.prototype.shiftTime=function(t){return this.configuration.fixedUpdate?-t%this.tickChunk:0},s.prototype.callInit=function(t,i,r){var a=this;this.engine=r,this.resize(t);var o=e(this.configuration.images);o&&n.add(o),Promise.resolve(this.configuration.init&&this.configuration.init({engine:r,output:t,scene:this,parameter:i,imageManager:n})).then(function(t){return a.initDone=!0})},s.prototype.resize=function(t){var e=this;this.additionalModifier={alpha:1,x:0,y:0,width:t.width,height:t.height,widthInPixel:t.width,heightInPixel:t.height,visibleScreen:{x:0,y:0,width:t.width,height:t.height}},this.layerManager.forEach(function(i){i.isFunction||i.element.resize(t,e.additionalModifier)})},s.prototype.destroy=function(t){var e=this.configuration.destroy&&this.configuration.destroy({engine:this.engine,scene:this,output:t});return this.initDone=!1,e},s.prototype.loadingScreen=function(t,e){if(this.configuration.loading)return this.configuration.loading({engine:this.engine,scene:this,output:t,progress:e});var i=t.context,n="number"==typeof e?Math.max(1,e*t.h):t.h;i.globalCompositeOperation="source-over",i.globalAlpha=1,i.clearRect(0,0,t.w,t.h),i.fillStyle="#aaa",i.fillRect(0,t.height/2-n/2,t.width,n),i.font="20px Georgia",i.fillStyle="#fff",i.textAlign="left",i.textBaseline="bottom";var r=e;isNaN(parseFloat(e))||isNaN(e-0)||(r="Loading "+Math.round(100*e)+"%"),i.fillText(r,10+3*Math.random(),t.height-10+3*Math.random()),this.engine&&this.engine.normalizeContext(i)},s.prototype.callLoading=function(t){if(n.isLoaded()&&this.initDone)return!0;var e=n.getCount()?n.getLoaded()/n.getCount():"Loading...";return this.loadingScreen(t,e),!1},s.prototype.fixedUpdate=function(t,e){this.configuration.fixedUpdate&&this.configuration.fixedUpdate({engine:this.engine,scene:this,layerManager:this.layerManager,output:t,timePassed:e,totalTimePassed:this.totalTimePassed})},s.prototype.move=function(t,e){if(this.totalTimePassed+=e,e<0?(this.reset(t),e=this.totalTimePassed):this.configuration.endTime&&this.configuration.endTime<=this.totalTimePassed&&(e-=this.totalTimePassed-this.configuration.endTime,this.totalTimePassed=this.configuration.endTime,this.configuration.end&&this.configuration.end({engine:this.engine,scene:this,output:t,timePassed:e,totalTimePassed:this.totalTimePassed})),this.tickChunk){if(e>=this.tickChunk-this.tickChunkTolerance)for(var i=0,n=Math.min(this.maxSkippedTickChunk,Math.floor(e/this.tickChunk));i<n;i++)this.fixedUpdate(t,this.tickChunk,i===n-1)}else this.fixedUpdate(t,e,!0);this.configuration.update&&this.configuration.update({engine:this.engine,scene:this,layerManager:this.layerManager,output:t,timePassed:e,totalTimePassed:this.totalTimePassed}),this.layerManager.forEach(function(t){var i=t.layer,n=t.index;t.isFunction||t.element.animate(e)&&i.deleteById(n)})},s.prototype.draw=function(t){var e=this;this.layerManager.forEach(function(i){var n=i.layer,r=i.element,a=i.index;i.isFunction?r({engine:e.engine,scene:e,layerManager:e.layerManager,layer:n,output:t,totalTimePassed:e.totalTimePassed})&&n.deleteById(a):r.draw(t.context,e.additionalModifier)})},s.prototype.reset=function(t){var e=this.configuration.reset?this.configuration.reset({engine:this.engine,scene:this,layerManager:this.layerManager,output:t}):new a;if(Array.isArray(e)){var i=e;e=new a,i.forEach(function(t){e.addLayer().addElements(t)})}e&&(this.layerManager=e)};var h=function(t){function e(e){t.call(this,e),this.audioStartTime=null,this.audioPosition=null,this.enableAndroidHack=!1,this.audioElement=this.configuration.audioElement}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.currentTime=function(){var e=t.prototype.currentTime.call(this);if(this.audioElement){if(this.enableAndroidHack){if(null===this.audioStartTime)return this.audioStartTime=e,this.audioPosition=this.audioElement.currentTime,1e3*this.audioElement.currentTime;if("playing"===this.audioElement.controller.playbackState){if(this.audioElement.currentTime===this.audioPosition)return 1e3*this.audioPosition+Math.min(260,e-this.audioStartTime);if(this.audioElement.currentTime-this.audioPosition<.5&&this.audioElement.currentTime>this.audioPosition&&e-this.audioStartTime<350)return this.audioStartTime=this.audioStartTime+1e3*(this.audioElement.currentTime-this.audioPosition),this.audioPosition=this.audioElement.currentTime,1e3*this.audioPosition+e-this.audioStartTime}return this.audioStartTime=e,this.audioPosition=1e3*(this.audioElement.ended?this.audioElement.duration:this.audioElement.currentTime),1e3*this.audioPosition}return 1e3*(this.audioElement.ended?this.audioElement.duration:this.audioElement.currentTime)}return e},e.prototype.clampTime=function(t){return t},e.prototype.shiftTime=function(t){return 0},e.prototype.callInit=function(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];return this.audioElement&&(this.audioElement.canPlayType("audio/mp3").match(/maybe|probably/i),"function"==typeof MediaController&&(this.audioElement.controller=new MediaController,this.enableAndroidHack=!0),this.audioElement.preload="auto",this.audioElement.load()),t.prototype.callInit.apply(this,e)},e.prototype.callLoading=function(e){var i=t.prototype.callLoading.call(this,e);if(i&&this.audioElement){if(!(this.audioElement.readyState>=this.audioElement.HAVE_ENOUGH_DATA))return this.loadingScreen(e,"Waiting for Audio"),!1;var n=this.audioElement.play();n&&n.catch(function(t){}),this.configuration.endTime||(this.configuration.endTime=1e3*this.audioElement.duration),this.loadingScreen(e,"Click to play")}return i},e}(s);function u(){this.reset()}u.prototype.reset=function(){return this.m=[1,0,0,1,0,0],this},u.prototype.multiply=function(t){var e=this.m[1]*t.m[0]+this.m[3]*t.m[1],i=this.m[0]*t.m[2]+this.m[2]*t.m[3],n=this.m[1]*t.m[2]+this.m[3]*t.m[3],r=this.m[0]*t.m[4]+this.m[2]*t.m[5]+this.m[4],a=this.m[1]*t.m[4]+this.m[3]*t.m[5]+this.m[5];return this.m[0]=this.m[0]*t.m[0]+this.m[2]*t.m[1],this.m[1]=e,this.m[2]=i,this.m[3]=n,this.m[4]=r,this.m[5]=a,this},u.prototype.invert=function(){var t=1/(this.m[0]*this.m[3]-this.m[1]*this.m[2]),e=-this.m[1]*t,i=-this.m[2]*t,n=this.m[0]*t,r=t*(this.m[2]*this.m[5]-this.m[3]*this.m[4]),a=t*(this.m[1]*this.m[4]-this.m[0]*this.m[5]);return this.m[0]=this.m[3]*t,this.m[1]=e,this.m[2]=i,this.m[3]=n,this.m[4]=r,this.m[5]=a,this},u.prototype.rotate=function(t){var e=Math.cos(t),i=Math.sin(t),n=this.m[1]*e+this.m[3]*i,r=this.m[0]*-i+this.m[2]*e,a=this.m[1]*-i+this.m[3]*e;return this.m[0]=this.m[0]*e+this.m[2]*i,this.m[1]=n,this.m[2]=r,this.m[3]=a,this},u.prototype.translate=function(t,e){return this.m[4]+=this.m[0]*t+this.m[2]*e,this.m[5]+=this.m[1]*t+this.m[3]*e,this},u.prototype.scale=function(t,e){return this.m[0]*=t,this.m[1]*=t,this.m[2]*=e,this.m[3]*=e,this},u.prototype.transformPoint=function(t,e){var i=t;return[t=i*this.m[0]+e*this.m[2]+this.m[4],e=i*this.m[1]+e*this.m[3]+this.m[5]]},u.prototype.clone=function(){var t=new u;return t.m=this.m.slice(0),t};var c=function(t){function e(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];t.apply(this,e),this.transform=null,this.transformInvert=null,this.cam={zoom:1,x:0,y:0}}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype._getViewport=function(){return this.engine?(this.transform||(this.transform=this._getViewportByCam(this.cam),this.transformInvert=null),this.transform):new u},e.prototype._getViewportByCam=function(t){var e=this.engine._output.width/2,i=this.engine._output.height/2,n=this.engine._output.ratio>1?e:i;return(new u).translate(e,i).scale(n,n).scale(t.zoom,t.zoom).translate(-t.x,-t.y)},e.prototype.resize=function(t){var e=this;this.transform=null,this.transformInvert=null,this.additionalModifier={alpha:1,x:-1,y:-1,width:2,height:2,widthInPixel:t.width,heightInPixel:t.height,scaleCanvas:t.width/t.canvas.clientWidth};var i=this.transformPoint(0,0,1),n=i[0],r=i[1],a=this.transformPoint(t.width,t.height,1);this.additionalModifier.visibleScreen={x:n,y:r,width:a[0]-n,height:a[1]-r},this.layerManager.forEach(function(i){i.isFunction||i.element.resize(t,e.additionalModifier)})},e.prototype.transformPoint=function(t,e,i){return void 0===i&&(i=this.additionalModifier.scaleCanvas),this.transformInvert||(this.transformInvert=this._getViewport().clone().invert()),this.transformInvert.transformPoint(t*i,e*i)},e.prototype.draw=function(e){var i;e.context.save(),(i=e.context).setTransform.apply(i,this._getViewport().m),t.prototype.draw.call(this,e),e.context.restore()},e}(s),l=function(t){function e(){for(var e=[],i=arguments.length;i--;)e[i]=arguments[i];t.apply(this,e),this.transform=null,this.transformInvert=null}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype._getViewport=function(){if(!this.engine)return new Transform;if(!this.transform){var t=this.engine._output.width/2,e=this.engine._output.height/2,i=this.engine._output.ratio>1?t:e;this.transform=(new Transform).translate(t,e).scale(i,i),this.transformInvert=null}return this.transform},e.prototype.resize=function(t){var e=this;this.transform=null,this.transformInvert=null,this.additionalModifier={alpha:1,x:-1,y:-1,width:2,height:2,widthInPixel:t.width,heightInPixel:t.height,scaleCanvas:t.width/t.canvas.clientWidth};var i=this.transformPoint(0,0,1),n=i[0],r=i[1],a=this.transformPoint(t.width,t.height,1);this.additionalModifier.visibleScreen={x:n,y:r,width:a[0]-n,height:a[1]-r},this.layerManager.forEach(function(i){i.isFunction||i.element.resize(t,e.additionalModifier)})},e.prototype.transformPoint=function(t,e,i){return void 0===i&&(i=this.additionalModifier.scaleCanvas),this.transformInvert||(this.transformInvert=this._getViewport().clone().invert()),this.transformInvert.transformPoint(t*i,e*i)},e.prototype.draw=function(e){var i;e.context.save(),(i=e.context).setTransform.apply(i,this._getViewport().m),t.prototype.draw.call(this,e),e.context.restore()},e}(h),p=function(t){function i(){for(var i=[],n=arguments.length;n--;)i[n]=arguments[n];t.apply(this,i),this.clampView=function(){var t=this._getViewportByCam(this.toCam).invert(),e=t.transformPoint(0,0),i=e[0],n=e[1],r=t.transformPoint(this.engine._output.width,this.engine._output.height),a=r[0],o=r[1];a-i<=2?i<-1?a<=1&&(this.toCam.x+=-1-i):a>1&&(this.toCam.x+=1-a):i>-1?this.toCam.x+=-1-i:a<1&&(this.toCam.x+=1-a),o-n<=2?n<-1?o<=1&&(this.toCam.y+=-1-n):o>1&&(this.toCam.y+=1-o):n>-1?this.toCam.y+=-1-n:o<1&&(this.toCam.y+=1-o)},this.camConfig=Object.assign({},{zoomMax:10,zoomMin:.5,zoomFactor:1.2,tween:4,registerEvents:!0,enabled:!0,click:function(t,e,i){},dblClick:void 0,callResize:!0},e(this.configuration.cam)||{}),this.toCam={x:0,y:0,distance:void 0,zoom:1},this.mousePos={x:0,y:0,timestamp:0,isDown:!1}}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i.prototype.camEnable=function(){this.camConfig.enabled=!0},i.prototype.camDisable=function(){this.camConfig.enabled=!1},i.prototype.camReset=function(){this.toCam={x:0,y:0,zoom:1}},i.prototype.callInit=function(e,i,n){return this.camConfig.registerEvents&&this.registerCamEvents(e.canvas),t.prototype.callInit.call(this,e,i,n)},i.prototype.destroy=function(e){return this.camConfig.registerEvents&&this.destroyCamEvents(e.canvas),t.prototype.destroy.call(this,e)},i.prototype._hasCamChanged=function(){return this.toCam.x!==this.cam.x||this.toCam.y!==this.cam.y||this.toCam.zoom!==this.cam.zoom},i.prototype.fixedUpdate=function(e,i,n){var r=t.prototype.fixedUpdate.call(this,e,i);return this.camConfig.tween&&this._hasCamChanged()&&(this.cam.x+=(this.toCam.x-this.cam.x)/this.camConfig.tween,this.cam.y+=(this.toCam.y-this.cam.y)/this.camConfig.tween,this.cam.zoom+=(this.toCam.zoom-this.cam.zoom)/this.camConfig.tween,n&&(this.camConfig.callResize?this.resize(e):(this.transform=null,this.transformInvert=null))),r},i.prototype.move=function(e,i){var n=t.prototype.move.call(this,e,i);return!this.camConfig.tween&&this._hasCamChanged()&&(this.cam=Object.assign({},this.toCam),this.camConfig.callResize?this.resize(e):(this.transform=null,this.transformInvert=null)),n},i.prototype.registerCamEvents=function(t){void 0===t&&(t=this.engine._output.canvas);for(var e=0,i=["touchstart","mousedown"];e<i.length;e+=1)t.addEventListener(i[e],this._mouseDown.bind(this),!0);for(var n=0,r=["touchend","mouseup"];n<r.length;n+=1)t.addEventListener(r[n],this._mouseUp.bind(this),!0);for(var a=0,o=["touchendoutside","mouseout"];a<o.length;a+=1)t.addEventListener(o[a],this._mouseOut.bind(this),!0);for(var s=0,h=["touchmove","mousemove"];s<h.length;s+=1)t.addEventListener(h[s],this._mouseMove.bind(this),!0);t.addEventListener("mousewheel",this._mouseWheel.bind(this),!0)},i.prototype.destroyCamEvents=function(t){void 0===t&&(t=this.engine._output.canvas);for(var e=0,i=["touchstart","mousedown"];e<i.length;e+=1)t.removeEventListener(i[e],this._mouseDown,!0);for(var n=0,r=["touchend","mouseup"];n<r.length;n+=1)t.removeEventListener(r[n],this._mouseUp,!0);for(var a=0,o=["touchendoutside","mouseout"];a<o.length;a+=1)t.removeEventListener(o[a],this._mouseOut,!0);for(var s=0,h=["touchmove","mousemove"];s<h.length;s+=1)t.removeEventListener(h[s],this._mouseMove,!0);t.removeEventListener("mousewheel",this._mouseWheel,!0)},i.prototype._getMousePosition=function(t){if(t&&t.touches&&t.touches.length>0){var e=t.target.getBoundingClientRect();return[t.targetTouches[0].pageX-e.left,t.targetTouches[0].pageY-e.top]}return[t.offsetX,t.offsetY]},i.prototype._mouseDown=function(t){if(t&&this.camConfig.enabled){var e=this._getMousePosition(t),i=e[1];this.mousePos.x=e[0],this.mousePos.y=i,this.mousePos.cx=this.toCam.x,this.mousePos.cy=this.toCam.y,this.mousePos.isDown=!0,this.mousePos.distance=void 0,this.mousePos.timestamp=Date.now()}},i.prototype._mouseUp=function(t){this.mousePos.isDown=!1;var e=this._getMousePosition(t),i=e[0],n=e[1];if(Date.now()-this.mousePos.timestamp<150&&Math.abs(this.mousePos.x-i)<5&&Math.abs(this.mousePos.y-n)<5){var r=this.transformPoint(i,n);this.camConfig.click(t,r[0],r[1])}},i.prototype._mouseOut=function(t){this.mousePos.isDown=!1},i.prototype._mouseMove=function(t){if(t&&this.camConfig.enabled&&this.mousePos.isDown)if(t.touches&&t.touches.length>=2){var e=t.touches,i=Math.sqrt((e[0].pageX-e[1].pageX)*(e[0].pageX-e[1].pageX)+(e[0].pageY-e[1].pageY)*(e[0].pageY-e[1].pageY));void 0!==this.mousePos.distance&&(i>this.mousePos.distance?this._zoomIn():i<this.mousePos.distance&&this._zoomOut()),this.mousePos.distance=i}else{this.mousePos.distance=void 0;var n=this._getMousePosition(t),r=n[0],a=n[1],o=this._getViewportByCam(this.toCam).invert(),s=o.transformPoint(this.mousePos.x,this.mousePos.y),h=s[0],u=s[1],c=o.transformPoint(r,a),l=c[1];this.toCam.x=this.mousePos.cx+h-c[0],this.toCam.y=this.mousePos.cy+u-l,this.clampView()}},i.prototype._mouseWheel=function(t){if(t&&this.camConfig.enabled){t.preventDefault();var e=this._getMousePosition(t),i=e[0],n=e[1],r=this._getViewportByCam(this.toCam).invert().transformPoint(i,n),a=r[0],o=r[1];if((t.wheelDelta||-1*t.deltaY)/120>0){this._zoomIn();var s=this._getViewportByCam(this.toCam).invert().transformPoint(i,n),h=s[1];this.toCam.x-=s[0]-a,this.toCam.y-=h-o,this.clampView()}else this._zoomOut()}},i.prototype._zoomIn=function(){this.toCam.zoom=Math.min(this.camConfig.zoomMax,this.toCam.zoom*this.camConfig.zoomFactor)},i.prototype._zoomOut=function(){this.toCam.zoom=Math.max(this.camConfig.zoomMin,this.toCam.zoom/this.camConfig.zoomFactor),this.clampView()},i}(c);NormCamera=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new(Function.prototype.bind.apply(p,[null].concat(t)))};var f={Default:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new(Function.prototype.bind.apply(s,[null].concat(t)))},Audio:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new(Function.prototype.bind.apply(h,[null].concat(t)))},Norm:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new(Function.prototype.bind.apply(c,[null].concat(t)))},NormAudio:function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];return new(Function.prototype.bind.apply(l,[null].concat(t)))},NormCamera:NormCamera},d=function(t){this.duration=e(t)};d.prototype.run=function(t,e){return this.duration?e-this.duration:-1};var m=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];var i=0;"number"==typeof t[0]&&(i=t.shift()),this.sequences=t.map(function(t){Array.isArray(t)||(t=[t]);var e=i;return"number"==typeof t[0]&&(e=t.shift()),{position:0,timelapsed:-e,sequence:t.map(function(t){return"function"!=typeof t.run?"number"==typeof t?new d(t):{run:t}:t}).filter(function(t){return"function"==typeof t.run}),label:t.reduce(function(t,e,i){return"string"==typeof e&&(t[e]=i-Object.keys(t).length),t},{}),enabled:!0}}),this.lastTimestamp=0,this.enabled=!0};m.prototype.reset=function(t){void 0===t&&(t=0),this.sequences.forEach(function(e){e.enabled=!0,e.position=0,e.timelapsed=t,e.sequence[0]&&e.sequence[0].reset&&e.sequence[0].reset(t)}),this.enabled=!0},m.prototype.play=function(t,e){if(void 0===t&&(t=""),void 0===e&&(e=0),t){var i=this.sequences.reduce(function(i,n){return n.label.hasOwnProperty(t)?(i=!0,n.position=n.label[t],n.enabled=!0,n.timelapsed=e,n.sequence[n.position]&&n.sequence[n.position].reset&&n.sequence[n.position].reset()):i|=n.sequence.find(function(i){return i.play&&i.play(t,e)})>=0,i},!1);return i&&(this.enabled=!0),i}return this.sequences.forEach(function(t){return t.enabled=!0}),this.enabled=!0,!0},m.prototype.runSequence=function(t,e,i){for(var n=i;e.sequence[e.position]&&n>=0;){if(e.timelapsed+=n,e.timelapsed<0)return-1;if(!0===(n=e.sequence[e.position].run(t,e.timelapsed)))n=0;else{if(!1===n)return-1;if(n===m.TIMELAPSE_TO_FORCE_DISABLE)return e.enabled=!1,this.enabled=!1,i;if(n===m.TIMELAPSE_TO_STOP)return e.enabled=!1,i;if(n===m.TIMELAPSE_TO_REMOVE)return!0}if(n>=0&&(e.position=(e.position+1)%e.sequence.length,e.sequence[e.position]&&e.sequence[e.position].reset&&e.sequence[e.position].reset(),e.timelapsed=0,0===e.position))return e.enabled=!1,n}return n},m.prototype.run=function(t,e,i){var n=e;if(i||(n=e-this.lastTimestamp,this.lastTimestamp=e),!this.enabled)return n;for(var r=this.sequences.length,a=0,o=Infinity,s=0;s<r;s++)if(this.sequences[s].enabled){var h=this.runSequence(t,this.sequences[s],n);if(!0===h)return!0;o=Math.min(o,h)}else a++;return a===r?(this.enabled=!1,n):o},m.TIMELAPSE_TO_FORCE_DISABLE="FORCE_DISABLE",m.TIMELAPSE_TO_STOP="STOP",m.TIMELAPSE_TO_REMOVE="REMOVE";var g=function(t){var i=this,n=this.getParameterList();Object.keys(n).forEach(function(r){var a=n[r];i[r]="function"==typeof a?a(t[r],t,i):o(e(t[r]),a)})};g.prototype.getBaseParameterList=function(){return{animation:function(t,i){var n=e(t);return Array.isArray(n)?new m(n):"object"==typeof n?n:void 0},enabled:!0}},g.prototype.getParameterList=function(){return Object.assign({},this.getBaseParameterList(),{x:0,y:0,rotation:function(t,e){return o(t,o(e.rotationInRadian,.017453292519943295*o(e.rotationInDegree,0)))},scaleX:1,scaleY:1,alpha:1,compositeOperation:"source-over",color:"#fff"})},g.prototype.animate=function(t){return!(!this.animation||!0!==this.animation.run(this,t,!0)||(this.enabled=!1,0))},g.prototype.play=function(t,e){void 0===t&&(t=""),void 0===e&&(e=0),this.animation&&this.animation.play&&this.animation.play(t,e)},g.prototype.resize=function(t,e){},g.prototype.draw=function(t,e){this.enabled&&(t.globalCompositeOperation=this.compositeOperation,t.globalAlpha=this.alpha*e.alpha,t.save(),t.translate(this.x,this.y),t.scale(this.scaleX,this.scaleY),t.beginPath(),t.fillStyle=this.color,t.arc(0,0,1,Math.PI/2+this.rotation,2.5*Math.PI-this.rotation,!1),t.fill(),t.closePath(),t.restore())};var v=function(t){function e(e){"function"==typeof e&&(e={callback:e}),t.call(this,e),this.timePassed=0,this.deltaTime=0}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.getParameterList=function(){return Object.assign({},this.getBaseParameterList(),{callback:function(t){return void 0===typeof t?function(){}:t}})},e.prototype.animate=function(e){return this.enabled&&(this.timePassed+=e,this.deltaTime+=e),t.prototype.animate.call(this,e)},e.prototype.draw=function(t,e){this.enabled&&this.callback(t,this.timePassed,e,this),this.deltaTime=0},e}(g),y=function(t){function e(e){t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.getParameterList=function(){return Object.assign({},t.prototype.getParameterList.call(this),{sprite:[]})},e.prototype.animate=function(e){var i=t.prototype.animate.call(this,e),n=!1;if(this.enabled)for(var r in this.sprite)n=n||!0===this.sprite[r].animate(e);return this.animation?i:(n&&(this.enabled=!1),n)},e.prototype.play=function(t,e){for(var i in void 0===t&&(t=""),void 0===e&&(e=0),this.animation&&this.animation.play&&this.animation.play(t,e),this.sprite)this.sprite[i].play&&this.sprite[i].play(t,e)},e.prototype.draw=function(t,e){if(this.enabled){for(var i in this.alpha<1&&((e=Object.assign({},e)).alpha*=this.alpha),t.save(),t.translate(this.x,this.y),t.scale(this.scaleX,this.scaleY),t.rotate(this.rotation),this.sprite)this.sprite[i].draw(t,e);t.restore()}},e}(g),b=function(t){function i(e){t.call(this,e),this.currentGridSize=!1}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i.prototype.getParameterList=function(){return Object.assign({},t.prototype.getParameterList.call(this),{x:void 0,y:void 0,width:void 0,height:void 0,gridSize:void 0,norm:function(t,i,n){return o(e(t),void 0===n.x&&void 0===n.y&&void 0===n.width&&void 0===n.height)}})},i.prototype.generateTempCanvas=function(t,e){var i=e.widthInPixel||t.canvas.width,n=e.heightInPixel||t.canvas.height;this.temp_canvas=document.createElement("canvas"),this.gridSize?(this.currentGridSize=this.gridSize,this.temp_canvas.width=Math.round(this.currentGridSize),this.temp_canvas.height=Math.round(this.currentGridSize)):(this.temp_canvas.width=Math.round(i/this.scaleX),this.temp_canvas.height=Math.round(n/this.scaleY)),this.tctx=this.temp_canvas.getContext("2d"),this.tctx.globalCompositeOperation="source-over",this.tctx.globalAlpha=1},i.prototype.normalizeFullScreen=function(t){(void 0===this.x||this.norm)&&(this.x=t.visibleScreen.x),(void 0===this.y||this.norm)&&(this.y=t.visibleScreen.y),(void 0===this.width||this.norm)&&(this.width=t.visibleScreen.width),(void 0===this.height||this.norm)&&(this.height=t.visibleScreen.height)},i.prototype.resize=function(t,e){if(this.temp_canvas&&this.currentGridSize!==this.gridSize){var i=this.temp_canvas;this.generateTempCanvas(t,e),this.tctx.globalCompositeOperation="copy",this.tctx.drawImage(i,0,0,i.width,i.height,0,0,this.temp_canvas.width,this.temp_canvas.height),this.tctx.globalCompositeOperation="source-over"}this.normalizeFullScreen(e)},i.prototype.draw=function(t,e){if(this.enabled){this.temp_canvas||(this.generateTempCanvas(t,e),this.normalizeFullScreen(e)),this.gridSize&&this.currentGridSize!==this.gridSize&&this.resize(t,e);var i=this.width,n=this.height,r=i/2,a=n/2,o=this.temp_canvas.width,s=this.temp_canvas.height;for(var h in this.sprite)this.sprite[h].draw(this.tctx,{alpha:1,x:0,y:0,width:o,height:s,widthInPixel:o,heightInPixel:s,visibleScreen:{x:0,y:0,width:o,height:s}});this.additionalBlur&&this.additionalBlur(o,s,e),t.save(),t.globalCompositeOperation=this.compositeOperation,t.globalAlpha=this.alpha*e.alpha,t.translate(this.x+r,this.y+a),t.scale(this.scaleX,this.scaleY),t.rotate(this.rotation),t.drawImage(this.temp_canvas,0,0,this.temp_canvas.width,this.temp_canvas.height,-r,-a,i,n),t.restore()}},i}(y),w=function(t){function i(i){t.call(this,i.self||{});var n={},r={};for(var a in i)["self","class","count"].includes(a)||("function"==typeof i[a]?r[a]=i[a]:n[a]=i[a]);var s=o(e(i.count),1);this.sprite=[];for(var h=0;h<s;h++){var u=i.class,c={};for(var l in n)c[l]=n[l];for(var p in r)c[p]=r[p].call(null,h);this.sprite[h]=new u(c)}}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i}(y),_=function(t){function i(e){t.call(this,e),this.currentGridSize=!1}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i.prototype.getParameterList=function(){return Object.assign({},t.prototype.getParameterList.call(this),{x:void 0,y:void 0,width:void 0,height:void 0,gridSize:void 0,darker:0,pixel:!1,clear:!1,norm:function(t,i,n){return o(e(t),void 0===n.x&&void 0===n.y&&void 0===n.width&&void 0===n.height)}})},i.prototype.generateTempCanvas=function(t,e){var i=e.widthInPixel||t.canvas.width,n=e.heightInPixel||t.canvas.height;this.temp_canvas=document.createElement("canvas"),this.gridSize?(this.currentGridSize=this.gridSize,this.temp_canvas.width=Math.round(this.currentGridSize),this.temp_canvas.height=Math.round(this.currentGridSize)):(this.temp_canvas.width=Math.ceil(i/this.scaleX),this.temp_canvas.height=Math.ceil(n/this.scaleY)),this.tctx=this.temp_canvas.getContext("2d"),this.tctx.globalCompositeOperation="source-over",this.tctx.globalAlpha=1},i.prototype.normalizeFullScreen=function(t){(void 0===this.x||this.norm)&&(this.x=t.visibleScreen.x),(void 0===this.y||this.norm)&&(this.y=t.visibleScreen.y),(void 0===this.width||this.norm)&&(this.width=t.visibleScreen.width),(void 0===this.height||this.norm)&&(this.height=t.visibleScreen.height)},i.prototype.resize=function(t,e){if(this.temp_canvas&&this.currentGridSize!==this.gridSize){var i=this.temp_canvas;this.generateTempCanvas(t,e),this.tctx.globalCompositeOperation="copy",this.tctx.drawImage(i,0,0,i.width,i.height,0,0,this.temp_canvas.width,this.temp_canvas.height),this.tctx.globalCompositeOperation="source-over"}this.normalizeFullScreen(e)},i.prototype.draw=function(t,e){if(this.enabled){this.temp_canvas||(this.generateTempCanvas(t,e),this.normalizeFullScreen(e)),this.gridSize&&this.currentGridSize!==this.gridSize&&this.resize(t,e);var i=this.alpha*e.alpha,n=this.width,r=this.height,a=this.temp_canvas.width,o=this.temp_canvas.height;i>0&&a&&o&&(this.tctx.globalCompositeOperation="copy",this.tctx.globalAlpha=1,this.tctx.drawImage(t.canvas,0,0,t.canvas.width,t.canvas.height,0,0,a,o),this.darker>0&&(this.tctx.globalCompositeOperation=this.clear?"source-atop":"source-over",this.tctx.fillStyle="rgba(0,0,0,"+this.darker+")",this.tctx.fillRect(0,0,a,o)),this.additionalBlur&&this.additionalBlur(a,o,e),this.clear&&t.clearRect(this.x,this.y,n,r),t.globalCompositeOperation=this.compositeOperation,t.globalAlpha=i,t.imageSmoothingEnabled=!this.pixel,t.drawImage(this.temp_canvas,0,0,a,o,this.x,this.y,n,r),t.imageSmoothingEnabled=!0)}else this.clear&&(this.x||(this.x=e.x),this.y||(this.y=e.y),this.width||(this.width=e.width),this.height||(this.height=e.height),t.clearRect(this.x,this.y,this.width,this.height))},i}(g),x=function(t){function i(e){t.call(this,e)}return t&&(i.__proto__=t),(i.prototype=Object.create(t&&t.prototype)).constructor=i,i.prototype.getParameterList=function(){return Object.assign({},t.prototype.getParameterList.call(this),{image:function(t){return n.getImage(e(t))},position:i.CENTER,frameX:0,frameY:0,frameWidth:0,frameHeight:0,norm:!1,normCover:!1})},i.prototype.resize=function(){this.normScale=void 0},i.prototype.draw=function(t,e){if(this.enabled&&this.image){var n=this.frameWidth||this.image.width,r=this.frameHeight||this.image.height;this.normScale||(this.normScale=this.normCover?Math.max(e.width/n,e.height/r):this.norm?Math.min(e.width/n,e.height/r):1);var a=n*this.normScale*this.scaleX,o=r*this.normScale*this.scaleY;t.globalCompositeOperation=this.compositeOperation,t.globalAlpha=this.alpha*e.alpha,0==this.rotation?this.position===i.LEFT_TOP?t.drawImage(this.image,this.frameX,this.frameY,n,r,this.x,this.y,a,o):t.drawImage(this.image,this.frameX,this.frameY,n,r,this.x-a/2,this.y-o/2,a,o):(t.save(),t.translate(this.x,this.y),t.rotate(this.rotation),t.drawImage(this.image,this.frameX,this.frameY,n,r,-a/2,-o/2,a,o),t.restore())}},i}(g);x.LEFT_TOP=0,x.CENTER=1;var M=function(t){function e(e){t.call(this,e)}return t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e,e.prototype.getParameterList=function(){return Object.assign({},t.prototype.getParameterList.call(this),{text:void 0,font:"26px monospace",position:e.CENTER,color:void 0,borderColor:void 0,lineWidth:1})},e.prototype.draw=function(t,i){this.enabled&&(t.globalCompositeOperation=this.compositeOperation,t.globalAlpha=this.alpha*i.alpha,t.save(),e.LEFT_TOP&&(t.textAlign="left",t.textBaseline="top"),t.translate(this.x,this.y),t.scale(this.scaleX,this.scaleY),t.rotate(this.rotation),t.font=this.font,this.color&&(t.fillStyle=this.color,t.fillText(this.text,0,0)),this.borderColor&&(t.strokeStyle=this.borderColor,t.lineWidth=this.lineWidth,t.strokeText(this.text,0,0)),t.restore())},e}(g);function S(t,e){return t(e={exports:{}},e.exports),e.exports}M.LEFT_TOP=0,M.CENTER=1,"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var C={aliceblue:[240,248,255],antiquewhite:[250,235,215],aqua:[0,255,255],aquamarine:[127,255,212],azure:[240,255,255],beige:[245,245,220],bisque:[255,228,196],black:[0,0,0],blanchedalmond:[255,235,205],blue:[0,0,255],blueviolet:[138,43,226],brown:[165,42,42],burlywood:[222,184,135],cadetblue:[95,158,160],chartreuse:[127,255,0],chocolate:[210,105,30],coral:[255,127,80],cornflowerblue:[100,149,237],cornsilk:[255,248,220],crimson:[220,20,60],cyan:[0,255,255],darkblue:[0,0,139],darkcyan:[0,139,139],darkgoldenrod:[184,134,11],darkgray:[169,169,169],darkgreen:[0,100,0],darkgrey:[169,169,169],darkkhaki:[189,183,107],darkmagenta:[139,0,139],darkolivegreen:[85,107,47],darkorange:[255,140,0],darkorchid:[153,50,204],darkred:[139,0,0],darksalmon:[233,150,122],darkseagreen:[143,188,143],darkslateblue:[72,61,139],darkslategray:[47,79,79],darkslategrey:[47,79,79],darkturquoise:[0,206,209],darkviolet:[148,0,211],deeppink:[255,20,147],deepskyblue:[0,191,255],dimgray:[105,105,105],dimgrey:[105,105,105],dodgerblue:[30,144,255],firebrick:[178,34,34],floralwhite:[255,250,240],forestgreen:[34,139,34],fuchsia:[255,0,255],gainsboro:[220,220,220],ghostwhite:[248,248,255],gold:[255,215,0],goldenrod:[218,165,32],gray:[128,128,128],green:[0,128,0],greenyellow:[173,255,47],grey:[128,128,128],honeydew:[240,255,240],hotpink:[255,105,180],indianred:[205,92,92],indigo:[75,0,130],ivory:[255,255,240],khaki:[240,230,140],lavender:[230,230,250],lavenderblush:[255,240,245],lawngreen:[124,252,0],lemonchiffon:[255,250,205],lightblue:[173,216,230],lightcoral:[240,128,128],lightcyan:[224,255,255],lightgoldenrodyellow:[250,250,210],lightgray:[211,211,211],lightgreen:[144,238,144],lightgrey:[211,211,211],lightpink:[255,182,193],lightsalmon:[255,160,122],lightseagreen:[32,178,170],lightskyblue:[135,206,250],lightslategray:[119,136,153],lightslategrey:[119,136,153],lightsteelblue:[176,196,222],lightyellow:[255,255,224],lime:[0,255,0],limegreen:[50,205,50],linen:[250,240,230],magenta:[255,0,255],maroon:[128,0,0],mediumaquamarine:[102,205,170],mediumblue:[0,0,205],mediumorchid:[186,85,211],mediumpurple:[147,112,219],mediumseagreen:[60,179,113],mediumslateblue:[123,104,238],mediumspringgreen:[0,250,154],mediumturquoise:[72,209,204],mediumvioletred:[199,21,133],midnightblue:[25,25,112],mintcream:[245,255,250],mistyrose:[255,228,225],moccasin:[255,228,181],navajowhite:[255,222,173],navy:[0,0,128],oldlace:[253,245,230],olive:[128,128,0],olivedrab:[107,142,35],orange:[255,165,0],orangered:[255,69,0],orchid:[218,112,214],palegoldenrod:[238,232,170],palegreen:[152,251,152],paleturquoise:[175,238,238],palevioletred:[219,112,147],papayawhip:[255,239,213],peachpuff:[255,218,185],peru:[205,133,63],pink:[255,192,203],plum:[221,160,221],powderblue:[176,224,230],purple:[128,0,128],rebeccapurple:[102,51,153],red:[255,0,0],rosybrown:[188,143,143],royalblue:[65,105,225],saddlebrown:[139,69,19],salmon:[250,128,114],sandybrown:[244,164,96],seagreen:[46,139,87],seashell:[255,245,238],sienna:[160,82,45],silver:[192,192,192],skyblue:[135,206,235],slateblue:[106,90,205],slategray:[112,128,144],slategrey:[112,128,144],snow:[255,250,250],springgreen:[0,255,127],steelblue:[70,130,180],tan:[210,180,140],teal:[0,128,128],thistle:[216,191,216],tomato:[255,99,71],turquoise:[64,224,208],violet:[238,130,238],wheat:[245,222,179],white:[255,255,255],whitesmoke:[245,245,245],yellow:[255,255,0],yellowgreen:[154,205,50]},P=S(function(t){var e=Array.prototype.concat,i=Array.prototype.slice,n=t.exports=function(t){for(var n,r=[],a=0,o=t.length;a<o;a++){var s=t[a];(n=s)&&"string"!=typeof n&&(n instanceof Array||Array.isArray(n)||n.length>=0&&(n.splice instanceof Function||Object.getOwnPropertyDescriptor(n,n.length-1)&&"String"!==n.constructor.name))?r=e.call(r,i.call(s)):r.push(s)}return r};n.wrap=function(t){return function(){return t(n(arguments))}}}),E=S(function(t){var e={};for(var i in C)C.hasOwnProperty(i)&&(e[C[i]]=i);var n=t.exports={to:{},get:{}};function r(t,e,i){return Math.min(Math.max(e,t),i)}function a(t){var e=t.toString(16).toUpperCase();return e.length<2?"0"+e:e}n.get=function(t){var e,i;switch(t.substring(0,3).toLowerCase()){case"hsl":e=n.get.hsl(t),i="hsl";break;case"hwb":e=n.get.hwb(t),i="hwb";break;default:e=n.get.rgb(t),i="rgb"}return e?{model:i,value:e}:null},n.get.rgb=function(t){if(!t)return null;var e,i,n,a=[0,0,0,1];if(e=t.match(/^#([a-f0-9]{6})([a-f0-9]{2})?$/i)){for(n=e[2],e=e[1],i=0;i<3;i++){var o=2*i;a[i]=parseInt(e.slice(o,o+2),16)}n&&(a[3]=Math.round(parseInt(n,16)/255*100)/100)}else if(e=t.match(/^#([a-f0-9]{3,4})$/i)){for(n=(e=e[1])[3],i=0;i<3;i++)a[i]=parseInt(e[i]+e[i],16);n&&(a[3]=Math.round(parseInt(n+n,16)/255*100)/100)}else if(e=t.match(/^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/)){for(i=0;i<3;i++)a[i]=parseInt(e[i+1],0);e[4]&&(a[3]=parseFloat(e[4]))}else{if(!(e=t.match(/^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/)))return(e=t.match(/(\D+)/))?"transparent"===e[1]?[0,0,0,0]:(a=C[e[1]])?(a[3]=1,a):null:null;for(i=0;i<3;i++)a[i]=Math.round(2.55*parseFloat(e[i+1]));e[4]&&(a[3]=parseFloat(e[4]))}for(i=0;i<3;i++)a[i]=r(a[i],0,255);return a[3]=r(a[3],0,1),a},n.get.hsl=function(t){if(!t)return null;var e=t.match(/^hsla?\(\s*([+-]?(?:\d*\.)?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/);if(e){var i=parseFloat(e[4]);return[(parseFloat(e[1])+360)%360,r(parseFloat(e[2]),0,100),r(parseFloat(e[3]),0,100),r(isNaN(i)?1:i,0,1)]}return null},n.get.hwb=function(t){if(!t)return null;var e=t.match(/^hwb\(\s*([+-]?\d*[\.]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/);if(e){var i=parseFloat(e[4]);return[(parseFloat(e[1])%360+360)%360,r(parseFloat(e[2]),0,100),r(parseFloat(e[3]),0,100),r(isNaN(i)?1:i,0,1)]}return null},n.to.hex=function(){var t=P(arguments);return"#"+a(t[0])+a(t[1])+a(t[2])+(t[3]<1?a(Math.round(255*t[3])):"")},n.to.rgb=function(){var t=P(arguments);return t.length<4||1===t[3]?"rgb("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+")":"rgba("+Math.round(t[0])+", "+Math.round(t[1])+", "+Math.round(t[2])+", "+t[3]+")"},n.to.rgb.percent=function(){var t=P(arguments),e=Math.round(t[0]/255*100),i=Math.round(t[1]/255*100),n=Math.round(t[2]/255*100);return t.length<4||1===t[3]?"rgb("+e+"%, "+i+"%, "+n+"%)":"rgba("+e+"%, "+i+"%, "+n+"%, "+t[3]+")"},n.to.hsl=function(){var t=P(arguments);return t.length<4||1===t[3]?"hsl("+t[0]+", "+t[1]+"%, "+t[2]+"%)":"hsla("+t[0]+", "+t[1]+"%, "+t[2]+"%, "+t[3]+")"},n.to.hwb=function(){var t=P(arguments),e="";return t.length>=4&&1!==t[3]&&(e=", "+t[3]),"hwb("+t[0]+", "+t[1]+"%, "+t[2]+"%"+e+")"},n.to.keyword=function(t){return e[t.slice(0,3)]}}),T=S(function(t){var e={};for(var i in C)C.hasOwnProperty(i)&&(e[C[i]]=i);var n=t.exports={rgb:{channels:3,labels:"rgb"},hsl:{channels:3,labels:"hsl"},hsv:{channels:3,labels:"hsv"},hwb:{channels:3,labels:"hwb"},cmyk:{channels:4,labels:"cmyk"},xyz:{channels:3,labels:"xyz"},lab:{channels:3,labels:"lab"},lch:{channels:3,labels:"lch"},hex:{channels:1,labels:["hex"]},keyword:{channels:1,labels:["keyword"]},ansi16:{channels:1,labels:["ansi16"]},ansi256:{channels:1,labels:["ansi256"]},hcg:{channels:3,labels:["h","c","g"]},apple:{channels:3,labels:["r16","g16","b16"]},gray:{channels:1,labels:["gray"]}};for(var r in n)if(n.hasOwnProperty(r)){if(!("channels"in n[r]))throw new Error("missing channels property: "+r);if(!("labels"in n[r]))throw new Error("missing channel labels property: "+r);if(n[r].labels.length!==n[r].channels)throw new Error("channel and label counts mismatch: "+r);var a=n[r].channels,o=n[r].labels;delete n[r].channels,delete n[r].labels,Object.defineProperty(n[r],"channels",{value:a}),Object.defineProperty(n[r],"labels",{value:o})}n.rgb.hsl=function(t){var e,i,n=t[0]/255,r=t[1]/255,a=t[2]/255,o=Math.min(n,r,a),s=Math.max(n,r,a),h=s-o;return s===o?e=0:n===s?e=(r-a)/h:r===s?e=2+(a-n)/h:a===s&&(e=4+(n-r)/h),(e=Math.min(60*e,360))<0&&(e+=360),i=(o+s)/2,[e,100*(s===o?0:i<=.5?h/(s+o):h/(2-s-o)),100*i]},n.rgb.hsv=function(t){var e,i,n,r,a,o=t[0]/255,s=t[1]/255,h=t[2]/255,u=Math.max(o,s,h),c=u-Math.min(o,s,h),l=function(t){return(u-t)/6/c+.5};return 0===c?r=a=0:(a=c/u,e=l(o),i=l(s),n=l(h),o===u?r=n-i:s===u?r=1/3+e-n:h===u&&(r=2/3+i-e),r<0?r+=1:r>1&&(r-=1)),[360*r,100*a,100*u]},n.rgb.hwb=function(t){var e=t[0],i=t[1],r=t[2];return[n.rgb.hsl(t)[0],1/255*Math.min(e,Math.min(i,r))*100,100*(r=1-1/255*Math.max(e,Math.max(i,r)))]},n.rgb.cmyk=function(t){var e,i=t[0]/255,n=t[1]/255,r=t[2]/255;return[100*((1-i-(e=Math.min(1-i,1-n,1-r)))/(1-e)||0),100*((1-n-e)/(1-e)||0),100*((1-r-e)/(1-e)||0),100*e]},n.rgb.keyword=function(t){var i=e[t];if(i)return i;var n,r,a,o=Infinity;for(var s in C)if(C.hasOwnProperty(s)){var h=(r=t,a=C[s],Math.pow(r[0]-a[0],2)+Math.pow(r[1]-a[1],2)+Math.pow(r[2]-a[2],2));h<o&&(o=h,n=s)}return n},n.keyword.rgb=function(t){return C[t]},n.rgb.xyz=function(t){var e=t[0]/255,i=t[1]/255,n=t[2]/255;return[100*(.4124*(e=e>.04045?Math.pow((e+.055)/1.055,2.4):e/12.92)+.3576*(i=i>.04045?Math.pow((i+.055)/1.055,2.4):i/12.92)+.1805*(n=n>.04045?Math.pow((n+.055)/1.055,2.4):n/12.92)),100*(.2126*e+.7152*i+.0722*n),100*(.0193*e+.1192*i+.9505*n)]},n.rgb.lab=function(t){var e=n.rgb.xyz(t),i=e[0],r=e[1],a=e[2];return r/=100,a/=108.883,i=(i/=95.047)>.008856?Math.pow(i,1/3):7.787*i+16/116,[116*(r=r>.008856?Math.pow(r,1/3):7.787*r+16/116)-16,500*(i-r),200*(r-(a=a>.008856?Math.pow(a,1/3):7.787*a+16/116))]},n.hsl.rgb=function(t){var e,i,n,r,a,o=t[0]/360,s=t[1]/100,h=t[2]/100;if(0===s)return[a=255*h,a,a];e=2*h-(i=h<.5?h*(1+s):h+s-h*s),r=[0,0,0];for(var u=0;u<3;u++)(n=o+1/3*-(u-1))<0&&n++,n>1&&n--,r[u]=255*(a=6*n<1?e+6*(i-e)*n:2*n<1?i:3*n<2?e+(i-e)*(2/3-n)*6:e);return r},n.hsl.hsv=function(t){var e=t[0],i=t[1]/100,n=t[2]/100,r=i,a=Math.max(n,.01);return i*=(n*=2)<=1?n:2-n,r*=a<=1?a:2-a,[e,100*(0===n?2*r/(a+r):2*i/(n+i)),(n+i)/2*100]},n.hsv.rgb=function(t){var e=