pixi-viewport
Advanced tools
Comparing version 4.32.0 to 4.33.0
/* eslint-disable */ | ||
this.PIXI=this.PIXI||{},function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("@pixi/math"),require("penner"),require("@pixi/display"),require("@pixi/ticker")):"function"==typeof define&&define.amd?define(["exports","@pixi/math","penner","@pixi/display","@pixi/ticker"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).pixi_viewport={},t.PIXI,t.Penner,t.PIXI,t.PIXI)}(this,(function(t,i,e,s,n){"use strict";function h(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=h(e);class r{constructor(t){this.parent=t,this.paused=!1}destroy(){}down(t){return!1}move(t){return!1}up(t){return!1}wheel(t){return!1}update(t){}resize(){}reset(){}pause(){this.paused=!0}resume(){this.paused=!1}}function a(t,i){return t?"function"==typeof t?t:"string"==typeof t?o.default[t]:void 0:o.default[i]}const p={removeOnInterrupt:!1,ease:"linear",time:1e3};class l extends r{__init(){this.startWidth=null}__init2(){this.startHeight=null}__init3(){this.deltaWidth=null}__init4(){this.deltaHeight=null}__init5(){this.width=null}__init6(){this.height=null}__init7(){this.time=0}constructor(t,i={}){super(t),l.prototype.__init.call(this),l.prototype.__init2.call(this),l.prototype.__init3.call(this),l.prototype.__init4.call(this),l.prototype.__init5.call(this),l.prototype.__init6.call(this),l.prototype.__init7.call(this),this.options=Object.assign({},p,i),this.options.ease=a(this.options.ease),this.setupPosition(),this.setupZoom(),this.time=0}setupPosition(){void 0!==this.options.position?(this.startX=this.parent.center.x,this.startY=this.parent.center.y,this.deltaX=this.options.position.x-this.parent.center.x,this.deltaY=this.options.position.y-this.parent.center.y,this.keepCenter=!1):this.keepCenter=!0}setupZoom(){this.width=null,this.height=null,void 0!==this.options.scale?this.width=this.parent.screenWidth/this.options.scale:void 0!==this.options.scaleX||void 0!==this.options.scaleY?(void 0!==this.options.scaleX&&(this.width=this.parent.screenWidth/this.options.scaleX),void 0!==this.options.scaleY&&(this.height=this.parent.screenHeight/this.options.scaleY)):(void 0!==this.options.width&&(this.width=this.options.width),void 0!==this.options.height&&(this.height=this.options.height)),null!==this.width&&(this.startWidth=this.parent.screenWidthInWorldPixels,this.deltaWidth=this.width-this.startWidth),null!==this.height&&(this.startHeight=this.parent.screenHeightInWorldPixels,this.deltaHeight=this.height-this.startHeight)}down(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("animate"),!1}complete(){this.parent.plugins.remove("animate"),null!==this.width&&this.parent.fitWidth(this.width,this.keepCenter,null===this.height),null!==this.height&&this.parent.fitHeight(this.height,this.keepCenter,null===this.width),this.keepCenter||this.parent.moveCenter(this.options.position),this.parent.emit("animate-end",this.parent),this.options.callbackOnComplete&&this.options.callbackOnComplete(this.parent)}update(t){if(!this.paused)if(this.time+=t,this.time>=this.options.time)this.complete();else{const t=new i.Point(this.parent.scale.x,this.parent.scale.y),e=this.options.ease(this.time,0,1,this.options.time);if(null!==this.width){const t=this.startWidth,i=this.deltaWidth;this.parent.fitWidth(t+i*e,this.keepCenter,null===this.height)}if(null!==this.height){const t=this.startHeight,i=this.deltaHeight;this.parent.fitHeight(t+i*e,this.keepCenter,null===this.width)}if(null===this.width?this.parent.scale.x=this.parent.scale.y:null===this.height&&(this.parent.scale.y=this.parent.scale.x),!this.keepCenter){const t=this.startX,s=this.startY,n=this.deltaX,h=this.deltaY,o=new i.Point(this.parent.x,this.parent.y);this.parent.moveCenter(t+n*e,s+h*e),this.parent.emit("moved",{viewport:this.parent,original:o,type:"animate"})}(this.width||this.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:t,type:"animate"})}}}function c(t){let i,e=t[0],s=1;for(;s<t.length;){const n=t[s],h=t[s+1];if(s+=2,("optionalAccess"===n||"optionalCall"===n)&&null==e)return;"access"===n||"optionalAccess"===n?(i=e,e=h(e)):"call"!==n&&"optionalCall"!==n||(e=h(((...t)=>e.call(i,...t))),i=void 0)}return e}const d={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class u extends r{constructor(t,i={}){super(t),this.options=Object.assign({},d,i),this.ease=a(this.options.ease,"easeInOutSine"),this.options.sides?"all"===this.options.sides?this.top=this.bottom=this.left=this.right=!0:"horizontal"===this.options.sides?(this.right=this.left=!0,this.top=this.bottom=!1):"vertical"===this.options.sides?(this.left=this.right=!1,this.top=this.bottom=!0):(this.top=-1!==this.options.sides.indexOf("top"),this.bottom=-1!==this.options.sides.indexOf("bottom"),this.left=-1!==this.options.sides.indexOf("left"),this.right=-1!==this.options.sides.indexOf("right")):this.left=this.top=this.right=this.bottom=!1;const e=this.options.underflow.toLowerCase();"center"===e?(this.underflowX=0,this.underflowY=0):(this.underflowX=-1!==e.indexOf("left")?-1:-1!==e.indexOf("right")?1:0,this.underflowY=-1!==e.indexOf("top")?-1:-1!==e.indexOf("bottom")?1:0),this.reset()}isActive(){return null!==this.toX||null!==this.toY}down(){return this.toX=this.toY=null,!1}up(){return this.bounce(),!1}update(t){if(!this.paused){if(this.bounce(),this.toX){const i=this.toX;i.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-x"}),i.time>=this.options.time?(this.parent.x=i.end,this.toX=null,this.parent.emit("bounce-x-end",this.parent)):this.parent.x=this.ease(i.time,i.start,i.delta,this.options.time)}if(this.toY){const i=this.toY;i.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-y"}),i.time>=this.options.time?(this.parent.y=i.end,this.toY=null,this.parent.emit("bounce-y-end",this.parent)):this.parent.y=this.ease(i.time,i.start,i.delta,this.options.time)}}}calcUnderflowX(){let t;switch(this.underflowX){case-1:t=0;break;case 1:t=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:t=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}return t}calcUnderflowY(){let t;switch(this.underflowY){case-1:t=0;break;case 1:t=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:t=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}return t}oob(){const t=this.options.bounceBox;if(t){const e=void 0===t.x?0:t.x,s=void 0===t.y?0:t.y,n=void 0===t.width?this.parent.worldWidth:t.width,h=void 0===t.height?this.parent.worldHeight:t.height;return{left:this.parent.left<e,right:this.parent.right>n,top:this.parent.top<s,bottom:this.parent.bottom>h,topLeft:new i.Point(e*this.parent.scale.x,s*this.parent.scale.y),bottomRight:new i.Point(n*this.parent.scale.x-this.parent.screenWidth,h*this.parent.scale.y-this.parent.screenHeight)}}return{left:this.parent.left<0,right:this.parent.right>this.parent.worldWidth,top:this.parent.top<0,bottom:this.parent.bottom>this.parent.worldHeight,topLeft:new i.Point(0,0),bottomRight:new i.Point(this.parent.worldWidth*this.parent.scale.x-this.parent.screenWidth,this.parent.worldHeight*this.parent.scale.y-this.parent.screenHeight)}}bounce(){if(this.paused)return;let t,i=this.parent.plugins.get("decelerate",!0);i&&(i.x||i.y)&&(i.x&&i.percentChangeX===c([i,"access",t=>t.options,"optionalAccess",t=>t.friction])||i.y&&i.percentChangeY===c([i,"access",t=>t.options,"optionalAccess",t=>t.friction]))&&(t=this.oob(),(t.left&&this.left||t.right&&this.right)&&(i.percentChangeX=this.options.friction),(t.top&&this.top||t.bottom&&this.bottom)&&(i.percentChangeY=this.options.friction));const e=this.parent.plugins.get("drag",!0)||{},s=this.parent.plugins.get("pinch",!0)||{};if(i=i||{},!(c([e,"optionalAccess",t=>t.active])||c([s,"optionalAccess",t=>t.active])||this.toX&&this.toY||i.x&&i.y)){t=t||this.oob();const e=t.topLeft,s=t.bottomRight;if(!this.toX&&!i.x){let i=null;t.left&&this.left?i=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-e.x:t.right&&this.right&&(i=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-s.x),null!==i&&this.parent.x!==i&&(this.toX={time:0,start:this.parent.x,delta:i-this.parent.x,end:i},this.parent.emit("bounce-x-start",this.parent))}if(!this.toY&&!i.y){let i=null;t.top&&this.top?i=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-e.y:t.bottom&&this.bottom&&(i=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-s.y),null!==i&&this.parent.y!==i&&(this.toY={time:0,start:this.parent.y,delta:i-this.parent.y,end:i},this.parent.emit("bounce-y-start",this.parent))}}}reset(){this.toX=this.toY=null,this.bounce()}}const m={left:!1,right:!1,top:!1,bottom:!1,direction:null,underflow:"center"};class g extends r{constructor(t,i={}){super(t),this.options=Object.assign({},m,i),this.options.direction&&(this.options.left="x"===this.options.direction||"all"===this.options.direction||null,this.options.right="x"===this.options.direction||"all"===this.options.direction||null,this.options.top="y"===this.options.direction||"all"===this.options.direction||null,this.options.bottom="y"===this.options.direction||"all"===this.options.direction||null),this.parseUnderflow(),this.last={x:null,y:null,scaleX:null,scaleY:null},this.update()}parseUnderflow(){const t=this.options.underflow.toLowerCase();"none"===t?this.noUnderflow=!0:"center"===t?(this.underflowX=this.underflowY=0,this.noUnderflow=!1):(this.underflowX=-1!==t.indexOf("left")?-1:-1!==t.indexOf("right")?1:0,this.underflowY=-1!==t.indexOf("top")?-1:-1!==t.indexOf("bottom")?1:0,this.noUnderflow=!1)}move(){return this.update(),!1}update(){if(this.paused)return;if(this.parent.x===this.last.x&&this.parent.y===this.last.y&&this.parent.scale.x===this.last.scaleX&&this.parent.scale.y===this.last.scaleY)return;const t={x:this.parent.x,y:this.parent.y},i=this.parent.plugins.decelerate||{};if(null!==this.options.left||null!==this.options.right){let e=!1;if(!this.noUnderflow&&this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:0!==this.parent.x&&(this.parent.x=0,e=!0);break;case 1:this.parent.x!==this.parent.screenWidth-this.parent.screenWorldWidth&&(this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth,e=!0);break;default:this.parent.x!==(this.parent.screenWidth-this.parent.screenWorldWidth)/2&&(this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2,e=!0)}else null!==this.options.left&&this.parent.left<(!0===this.options.left?0:this.options.left)&&(this.parent.x=-(!0===this.options.left?0:this.options.left)*this.parent.scale.x,i.x=0,e=!0),null!==this.options.right&&this.parent.right>(!0===this.options.right?this.parent.worldWidth:this.options.right)&&(this.parent.x=-(!0===this.options.right?this.parent.worldWidth:this.options.right)*this.parent.scale.x+this.parent.screenWidth,i.x=0,e=!0);e&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-x"})}if(null!==this.options.top||null!==this.options.bottom){let e=!1;if(!this.noUnderflow&&this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:0!==this.parent.y&&(this.parent.y=0,e=!0);break;case 1:this.parent.y!==this.parent.screenHeight-this.parent.screenWorldHeight&&(this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight,e=!0);break;default:this.parent.y!==(this.parent.screenHeight-this.parent.screenWorldHeight)/2&&(this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2,e=!0)}else null!==this.options.top&&this.parent.top<(!0===this.options.top?0:this.options.top)&&(this.parent.y=-(!0===this.options.top?0:this.options.top)*this.parent.scale.y,i.y=0,e=!0),null!==this.options.bottom&&this.parent.bottom>(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)&&(this.parent.y=-(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)*this.parent.scale.y+this.parent.screenHeight,i.y=0,e=!0);e&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-y"})}this.last.x=this.parent.x,this.last.y=this.parent.y,this.last.scaleX=this.parent.scale.x,this.last.scaleY=this.parent.scale.y}reset(){this.update()}}const w={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class y extends r{constructor(t,i={}){super(t),this.options=Object.assign({},w,i),this.clamp()}resize(){this.clamp()}clamp(){if(!this.paused)if(this.options.minWidth||this.options.minHeight||this.options.maxWidth||this.options.maxHeight){let t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight;if(null!==this.options.minWidth&&t<this.options.minWidth){const e=this.parent.scale.x;this.parent.fitWidth(this.options.minWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxWidth&&t>this.options.maxWidth){const e=this.parent.scale.x;this.parent.fitWidth(this.options.maxWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.minHeight&&i<this.options.minHeight){const e=this.parent.scale.y;this.parent.fitHeight(this.options.minHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxHeight&&i>this.options.maxHeight){const t=this.parent.scale.y;this.parent.fitHeight(this.options.maxHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/t,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}}else if(this.options.minScale||this.options.maxScale){const t={x:null,y:null},i={x:null,y:null};if("number"==typeof this.options.minScale)t.x=this.options.minScale,t.y=this.options.minScale;else if(null!==this.options.minScale){const i=this.options.minScale;t.x=void 0===i.x?null:i.x,t.y=void 0===i.y?null:i.y}if("number"==typeof this.options.maxScale)i.x=this.options.maxScale,i.y=this.options.maxScale;else if(null!==this.options.maxScale){const t=this.options.maxScale;i.x=void 0===t.x?null:t.x,i.y=void 0===t.y?null:t.y}let e=this.parent.scale.x,s=this.parent.scale.y;null!==t.x&&e<t.x&&(e=t.x),null!==i.x&&e>i.x&&(e=i.x),null!==t.y&&s<t.y&&(s=t.y),null!==i.y&&s>i.y&&(s=i.y),e===this.parent.scale.x&&s===this.parent.scale.y||(this.parent.scale.set(e,s),this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"}))}}reset(){this.clamp()}}const x={friction:.98,bounce:.8,minSpeed:.01},f=16;class v extends r{constructor(t,i={}){super(t),this.options=Object.assign({},x,i),this.saved=[],this.timeSinceRelease=0,this.reset(),this.parent.on("moved",(t=>this.moved(t)))}down(){return this.saved=[],this.x=this.y=null,!1}isActive(){return!(!this.x&&!this.y)}move(){if(this.paused)return!1;const t=this.parent.input.count();return(1===t||t>1&&!this.parent.plugins.get("pinch",!0))&&(this.saved.push({x:this.parent.x,y:this.parent.y,time:performance.now()}),this.saved.length>60&&this.saved.splice(0,30)),!1}moved(t){if(this.saved.length){const i=this.saved[this.saved.length-1];"clamp-x"===t.type?i.x===t.original.x&&(i.x=this.parent.x):"clamp-y"===t.type&&i.y===t.original.y&&(i.y=this.parent.y)}}up(){if(0===this.parent.input.count()&&this.saved.length){const t=performance.now();for(const i of this.saved)if(i.time>=t-100){const e=t-i.time;this.x=(this.parent.x-i.x)/e,this.y=(this.parent.y-i.y)/e,this.percentChangeX=this.percentChangeY=this.options.friction,this.timeSinceRelease=0;break}}return!1}activate(t){void 0!==(t=t||{}).x&&(this.x=t.x,this.percentChangeX=this.options.friction),void 0!==t.y&&(this.y=t.y,this.percentChangeY=this.options.friction)}update(t){if(this.paused)return;const i=this.x||this.y,e=this.timeSinceRelease,s=this.timeSinceRelease+t;if(this.x){const i=this.percentChangeX,n=Math.log(i);this.parent.x+=this.x*f/n*(Math.pow(i,s/f)-Math.pow(i,e/f)),this.x*=Math.pow(this.percentChangeX,t/f)}if(this.y){const i=this.percentChangeY,n=Math.log(i);this.parent.y+=this.y*f/n*(Math.pow(i,s/f)-Math.pow(i,e/f)),this.y*=Math.pow(this.percentChangeY,t/f)}this.timeSinceRelease+=t,this.x&&this.y?Math.abs(this.x)<this.options.minSpeed&&Math.abs(this.y)<this.options.minSpeed&&(this.x=0,this.y=0):(Math.abs(this.x||0)<this.options.minSpeed&&(this.x=0),Math.abs(this.y||0)<this.options.minSpeed&&(this.y=0)),i&&this.parent.emit("moved",{viewport:this.parent,type:"decelerate"})}reset(){this.x=this.y=null}}const W={direction:"all",pressDrag:!0,wheel:!0,wheelScroll:1,reverse:!1,clampWheel:!1,underflow:"center",factor:1,mouseButtons:"all",keyToPress:null,ignoreKeyToPressOnTouch:!1,lineHeight:20};class b extends r{constructor(t,i={}){super(t),this.options=Object.assign({},W,i),this.moved=!1,this.reverse=this.options.reverse?1:-1,this.xDirection=!this.options.direction||"all"===this.options.direction||"x"===this.options.direction,this.yDirection=!this.options.direction||"all"===this.options.direction||"y"===this.options.direction,this.keyIsPressed=!1,this.parseUnderflow(),this.mouseButtons(this.options.mouseButtons),this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){window.addEventListener("keydown",(i=>{t.includes(i.code)&&(this.keyIsPressed=!0)})),window.addEventListener("keyup",(i=>{t.includes(i.code)&&(this.keyIsPressed=!1)}))}mouseButtons(t){this.mouse=t&&"all"!==t?[-1!==t.indexOf("left"),-1!==t.indexOf("middle"),-1!==t.indexOf("right")]:[!0,!0,!0]}parseUnderflow(){const t=this.options.underflow.toLowerCase();"center"===t?(this.underflowX=0,this.underflowY=0):(t.includes("left")?this.underflowX=-1:t.includes("right")?this.underflowX=1:this.underflowX=0,t.includes("top")?this.underflowY=-1:t.includes("bottom")?this.underflowY=1:this.underflowY=0)}checkButtons(t){const i="mouse"===t.data.pointerType,e=this.parent.input.count();return!(!(1===e||e>1&&!this.parent.plugins.get("pinch",!0))||i&&!this.mouse[t.data.button])}checkKeyPress(t){return!this.options.keyToPress||this.keyIsPressed||this.options.ignoreKeyToPressOnTouch&&"touch"===t.data.pointerType}down(t){return!(this.paused||!this.options.pressDrag)&&(this.checkButtons(t)&&this.checkKeyPress(t)?(this.last={x:t.data.global.x,y:t.data.global.y},this.current=t.data.pointerId,!0):(this.last=null,!1))}get active(){return this.moved}move(t){if(this.paused||!this.options.pressDrag)return!1;if(this.last&&this.current===t.data.pointerId){const e=t.data.global.x,s=t.data.global.y,n=this.parent.input.count();if(1===n||n>1&&!this.parent.plugins.get("pinch",!0)){const n=e-this.last.x,h=s-this.last.y;if(this.moved||this.xDirection&&this.parent.input.checkThreshold(n)||this.yDirection&&this.parent.input.checkThreshold(h)){const n={x:e,y:s};return this.xDirection&&(this.parent.x+=(n.x-this.last.x)*this.options.factor),this.yDirection&&(this.parent.y+=(n.y-this.last.y)*this.options.factor),this.last=n,this.moved||this.parent.emit("drag-start",{event:t,screen:new i.Point(this.last.x,this.last.y),world:this.parent.toWorld(new i.Point(this.last.x,this.last.y)),viewport:this.parent}),this.moved=!0,this.parent.emit("moved",{viewport:this.parent,type:"drag"}),!0}}else this.moved=!1}return!1}up(t){if(this.paused)return!1;const e=this.parent.input.touches;if(1===e.length){const t=e[0];return t.last&&(this.last={x:t.last.x,y:t.last.y},this.current=t.id),this.moved=!1,!0}if(this.last&&this.moved){const e=new i.Point(this.last.x,this.last.y);return this.parent.emit("drag-end",{event:t,screen:e,world:this.parent.toWorld(e),viewport:this.parent}),this.last=null,this.moved=!1,!0}return!1}wheel(t){if(this.paused)return!1;if(this.options.wheel){const i=this.parent.plugins.get("wheel",!0);if(!i||!i.options.wheelZoom&&!t.ctrlKey){const i=t.deltaMode?this.options.lineHeight:1;return this.xDirection&&(this.parent.x+=t.deltaX*i*this.options.wheelScroll*this.reverse),this.yDirection&&(this.parent.y+=t.deltaY*i*this.options.wheelScroll*this.reverse),this.options.clampWheel&&this.clamp(),this.parent.emit("wheel-scroll",this.parent),this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.options.passiveWheel||t.preventDefault(),this.parent.options.stopPropagation&&t.stopPropagation(),!0}}return!1}resume(){this.last=null,this.paused=!1}clamp(){const t=this.parent.plugins.get("decelerate",!0)||{};if("y"!==this.options.clampWheel)if(this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:this.parent.x=0;break;case 1:this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}else this.parent.left<0?(this.parent.x=0,t.x=0):this.parent.right>this.parent.worldWidth&&(this.parent.x=-this.parent.worldWidth*this.parent.scale.x+this.parent.screenWidth,t.x=0);if("x"!==this.options.clampWheel)if(this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:this.parent.y=0;break;case 1:this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}else this.parent.top<0&&(this.parent.y=0,t.y=0),this.parent.bottom>this.parent.worldHeight&&(this.parent.y=-this.parent.worldHeight*this.parent.scale.y+this.parent.screenHeight,t.y=0)}}const H={speed:0,acceleration:null,radius:null};class S extends r{constructor(t,i,e={}){super(t),this.target=i,this.options=Object.assign({},H,e),this.velocity={x:0,y:0}}update(t){if(this.paused)return;const i=this.parent.center;let e=this.target.x,s=this.target.y;if(this.options.radius){if(!(Math.sqrt(Math.pow(this.target.y-i.y,2)+Math.pow(this.target.x-i.x,2))>this.options.radius))return;{const t=Math.atan2(this.target.y-i.y,this.target.x-i.x);e=this.target.x-Math.cos(t)*this.options.radius,s=this.target.y-Math.sin(t)*this.options.radius}}const n=e-i.x,h=s-i.y;if(n||h)if(this.options.speed)if(this.options.acceleration){const o=Math.atan2(s-i.y,e-i.x),r=Math.sqrt(Math.pow(n,2)+Math.pow(h,2));if(r){const a=(Math.pow(this.velocity.x,2)+Math.pow(this.velocity.y,2))/(2*this.options.acceleration);this.velocity=r>a?{x:Math.min(this.velocity.x+this.options.acceleration*t,this.options.speed),y:Math.min(this.velocity.y+this.options.acceleration*t,this.options.speed)}:{x:Math.max(this.velocity.x-this.options.acceleration*this.options.speed,0),y:Math.max(this.velocity.y-this.options.acceleration*this.options.speed,0)};const p=Math.cos(o)*this.velocity.x,l=Math.sin(o)*this.velocity.y,c=Math.abs(p)>Math.abs(n)?e:i.x+p,d=Math.abs(l)>Math.abs(h)?s:i.y+l;this.parent.moveCenter(c,d),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}else{const t=Math.atan2(s-i.y,e-i.x),o=Math.cos(t)*this.options.speed,r=Math.sin(t)*this.options.speed,a=Math.abs(o)>Math.abs(n)?e:i.x+o,p=Math.abs(r)>Math.abs(h)?s:i.y+r;this.parent.moveCenter(a,p),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}else this.parent.moveCenter(e,s),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}const M={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};class C extends r{constructor(t,i={}){super(t),this.options=Object.assign({},M,i),this.reverse=this.options.reverse?1:-1,this.radiusSquared="number"==typeof this.options.radius?Math.pow(this.options.radius,2):null,this.resize()}resize(){const t=this.options.distance;null!==t?(this.left=t,this.top=t,this.right=this.parent.worldScreenWidth-t,this.bottom=this.parent.worldScreenHeight-t):this.options.radius||(this.left=this.options.left,this.top=this.options.top,this.right=null===this.options.right?null:this.parent.worldScreenWidth-this.options.right,this.bottom=null===this.options.bottom?null:this.parent.worldScreenHeight-this.options.bottom)}down(){return this.paused||this.options.allowButtons||(this.horizontal=this.vertical=null),!1}move(t){if(this.paused)return!1;if("mouse"!==t.data.pointerType&&1!==t.data.identifier||!this.options.allowButtons&&0!==t.data.buttons)return!1;const i=t.data.global.x,e=t.data.global.y;if(this.radiusSquared){const t=this.parent.toScreen(this.parent.center);if(Math.pow(t.x-i,2)+Math.pow(t.y-e,2)>=this.radiusSquared){const s=Math.atan2(t.y-e,t.x-i);this.options.linear?(this.horizontal=Math.round(Math.cos(s))*this.options.speed*this.reverse*.06,this.vertical=Math.round(Math.sin(s))*this.options.speed*this.reverse*.06):(this.horizontal=Math.cos(s)*this.options.speed*this.reverse*.06,this.vertical=Math.sin(s)*this.options.speed*this.reverse*.06)}else this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=0}else null!==this.left&&i<this.left?this.horizontal=Number(this.reverse)*this.options.speed*.06:null!==this.right&&i>this.right?this.horizontal=-1*this.reverse*this.options.speed*.06:(this.decelerateHorizontal(),this.horizontal=0),null!==this.top&&e<this.top?this.vertical=Number(this.reverse)*this.options.speed*.06:null!==this.bottom&&e>this.bottom?this.vertical=-1*this.reverse*this.options.speed*.06:(this.decelerateVertical(),this.vertical=0);return!1}decelerateHorizontal(){const t=this.parent.plugins.get("decelerate",!0);this.horizontal&&t&&!this.options.noDecelerate&&t.activate({x:this.horizontal*this.options.speed*this.reverse/(1e3/60)})}decelerateVertical(){const t=this.parent.plugins.get("decelerate",!0);this.vertical&&t&&!this.options.noDecelerate&&t.activate({y:this.vertical*this.options.speed*this.reverse/(1e3/60)})}up(){return this.paused||(this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=null),!1}update(){if(!this.paused&&(this.horizontal||this.vertical)){const t=this.parent.center;this.horizontal&&(t.x+=this.horizontal*this.options.speed),this.vertical&&(t.y+=this.vertical*this.options.speed),this.parent.moveCenter(t),this.parent.emit("moved",{viewport:this.parent,type:"mouse-edges"})}}}const z={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class _ extends r{__init(){this.active=!1}__init2(){this.pinching=!1}__init3(){this.moved=!1}constructor(t,i={}){super(t),_.prototype.__init.call(this),_.prototype.__init2.call(this),_.prototype.__init3.call(this),this.options=Object.assign({},z,i)}down(){return this.parent.input.count()>=2&&(this.active=!0,!0)}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}move(t){if(this.paused||!this.active)return!1;const i=t.data.global.x,e=t.data.global.y,s=this.parent.input.touches;if(s.length>=2){const n=s[0],h=s[1],o=n.last&&h.last?Math.sqrt(Math.pow(h.last.x-n.last.x,2)+Math.pow(h.last.y-n.last.y,2)):null;if(n.id===t.data.pointerId?n.last={x:i,y:e,data:t.data}:h.id===t.data.pointerId&&(h.last={x:i,y:e,data:t.data}),o){let t;const i={x:n.last.x+(h.last.x-n.last.x)/2,y:n.last.y+(h.last.y-n.last.y)/2};this.options.center||(t=this.parent.toLocal(i));let e=Math.sqrt(Math.pow(h.last.x-n.last.x,2)+Math.pow(h.last.y-n.last.y,2));e=0===e?e=1e-10:e;const s=(1-o/e)*this.options.percent*(this.isAxisX()?this.parent.scale.x:this.parent.scale.y);this.isAxisX()&&(this.parent.scale.x+=s),this.isAxisY()&&(this.parent.scale.y+=s),this.parent.emit("zoomed",{viewport:this.parent,type:"pinch",center:i});const r=this.parent.plugins.get("clamp-zoom",!0);if(r&&r.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(t);this.parent.x+=(i.x-e.x)*this.options.factor,this.parent.y+=(i.y-e.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})}!this.options.noDrag&&this.lastCenter&&(this.parent.x+=(i.x-this.lastCenter.x)*this.options.factor,this.parent.y+=(i.y-this.lastCenter.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})),this.lastCenter=i,this.moved=!0}else this.pinching||(this.parent.emit("pinch-start",this.parent),this.pinching=!0);return!0}return!1}up(){return!!(this.pinching&&this.parent.input.touches.length<=1)&&(this.active=!1,this.lastCenter=null,this.pinching=!1,this.moved=!1,this.parent.emit("pinch-end",this.parent),!0)}}const P={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class X extends r{constructor(t,i,e,s={}){super(t),this.options=Object.assign({},P,s),this.ease=a(s.ease,"easeInOutSine"),this.x=i,this.y=e,this.options.forceStart&&this.snapStart()}snapStart(){this.percent=0,this.snapping={time:0};const t=this.options.topLeft?this.parent.corner:this.parent.center;this.deltaX=this.x-t.x,this.deltaY=this.y-t.y,this.startX=t.x,this.startY=t.y,this.parent.emit("snap-start",this.parent)}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap"):this.options.interrupt&&(this.snapping=null),!1}up(){if(0===this.parent.input.count()){const t=this.parent.plugins.get("decelerate",!0);t&&(t.x||t.y)&&(t.percentChangeX=t.percentChangeY=this.options.friction)}return!1}update(t){if(!(this.paused||this.options.interrupt&&0!==this.parent.input.count()))if(this.snapping){const i=this.snapping;let e,s,n;i.time+=t;const h=this.startX,o=this.startY,r=this.deltaX,a=this.deltaY;if(i.time>this.options.time)e=!0,s=h+r,n=o+a;else{const t=this.ease(i.time,0,1,this.options.time);s=h+r*t,n=o+a*t}this.options.topLeft?this.parent.moveCorner(s,n):this.parent.moveCenter(s,n),this.parent.emit("moved",{viewport:this.parent,type:"snap"}),e&&(this.options.removeOnComplete&&this.parent.plugins.remove("snap"),this.parent.emit("snap-end",this.parent),this.snapping=null)}else{const t=this.options.topLeft?this.parent.corner:this.parent.center;t.x===this.x&&t.y===this.y||this.snapStart()}}}const k={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class Y extends r{constructor(t,i={}){super(t),this.options=Object.assign({},k,i),this.ease=a(this.options.ease),this.xIndependent=!1,this.yIndependent=!1,this.xScale=0,this.yScale=0,this.options.width>0&&(this.xScale=t.screenWidth/this.options.width,this.xIndependent=!0),this.options.height>0&&(this.yScale=t.screenHeight/this.options.height,this.yIndependent=!0),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale,0===this.options.time?(t.container.scale.x=this.xScale,t.container.scale.y=this.yScale,this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom")):i.forceStart&&this.createSnapping()}createSnapping(){const t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,e=this.parent.screenWidth/this.xScale,s=this.parent.screenHeight/this.yScale;this.snapping={time:0,startX:t,startY:i,deltaX:e-t,deltaY:s-i},this.parent.emit("snap-zoom-start",this.parent)}resize(){this.snapping=null,this.options.width>0&&(this.xScale=this.parent.screenWidth/this.options.width),this.options.height>0&&(this.yScale=this.parent.screenHeight/this.options.height),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap-zoom"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap-zoom"):this.options.interrupt&&(this.snapping=null),!1}update(t){if(this.paused)return;if(this.options.interrupt&&0!==this.parent.input.count())return;let i;if(this.options.center||this.options.noMove||(i=this.parent.center),this.snapping){if(this.snapping){const e=this.snapping;if(e.time+=t,e.time>=this.options.time)this.parent.scale.set(this.xScale,this.yScale),this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom"),this.parent.emit("snap-zoom-end",this.parent),this.snapping=null;else{const t=this.snapping,i=this.ease(t.time,t.startX,t.deltaX,this.options.time),e=this.ease(t.time,t.startY,t.deltaY,this.options.time);this.parent.scale.x=this.parent.screenWidth/i,this.parent.scale.y=this.parent.screenHeight/e}const s=this.parent.plugins.get("clamp-zoom",!0);s&&s.clamp(),this.options.noMove||(this.options.center?this.parent.moveCenter(this.options.center):this.parent.moveCenter(i))}}else this.parent.scale.x===this.xScale&&this.parent.scale.y===this.yScale||this.createSnapping()}resume(){this.snapping=null,super.resume()}}const O={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",trackpadPinch:!1,wheelZoom:!0};class A extends r{constructor(t,i={}){super(t),this.options=Object.assign({},O,i)}down(){return this.options.interrupt&&(this.smoothing=null),!1}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}update(){if(this.smoothing){const t=this.smoothingCenter,i=this.smoothing;let e;this.options.center||(e=this.parent.toLocal(t)),this.isAxisX()&&(this.parent.scale.x+=i.x),this.isAxisY()&&(this.parent.scale.y+=i.y),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const s=this.parent.plugins.get("clamp-zoom",!0);if(s&&s.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(e);this.parent.x+=t.x-i.x,this.parent.y+=t.y-i.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.smoothingCount++,this.smoothingCount>=this.options.smooth&&(this.smoothing=null)}}pinch(t){const i=this.parent.input.getPointerPosition(t),e=-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/200,s=Math.pow(2,(1+this.options.percent)*e);let n;this.options.center||(n=this.parent.toLocal(i)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const h=this.parent.plugins.get("clamp-zoom",!0);if(h&&h.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const t=this.parent.toGlobal(n);this.parent.x+=i.x-t.x,this.parent.y+=i.y-t.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel",{wheel:{dx:t.deltaX,dy:t.deltaY,dz:t.deltaZ},event:t,viewport:this.parent})}wheel(t){if(this.paused)return!1;if(t.ctrlKey&&this.options.trackpadPinch)this.pinch(t);else if(this.options.wheelZoom){const i=this.parent.input.getPointerPosition(t),e=(this.options.reverse?-1:1)*-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/500,s=Math.pow(2,(1+this.options.percent)*e);if(this.options.smooth){const t={x:this.smoothing?this.smoothing.x*(this.options.smooth-this.smoothingCount):0,y:this.smoothing?this.smoothing.y*(this.options.smooth-this.smoothingCount):0};this.smoothing={x:((this.parent.scale.x+t.x)*s-this.parent.scale.x)/this.options.smooth,y:((this.parent.scale.y+t.y)*s-this.parent.scale.y)/this.options.smooth},this.smoothingCount=0,this.smoothingCenter=i}else{let t;this.options.center||(t=this.parent.toLocal(i)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const e=this.parent.plugins.get("clamp-zoom",!0);if(e&&e.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(t);this.parent.x+=i.x-e.x,this.parent.y+=i.y-e.y}}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel",{wheel:{dx:t.deltaX,dy:t.deltaY,dz:t.deltaZ},event:t,viewport:this.parent})}return!this.parent.options.passiveWheel}}class I{constructor(t){this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.interactive=!0,this.viewport.forceHitArea||(this.viewport.hitArea=new i.Rectangle(0,0,this.viewport.worldWidth,this.viewport.worldHeight)),this.viewport.on("pointerdown",this.down,this),this.viewport.on("pointermove",this.move,this),this.viewport.on("pointerup",this.up,this),this.viewport.on("pointerupoutside",this.up,this),this.viewport.on("pointercancel",this.up,this),this.viewport.on("pointerout",this.up,this),this.wheelFunction=t=>this.handleWheel(t),this.viewport.options.divWheel.addEventListener("wheel",this.wheelFunction,{passive:this.viewport.options.passiveWheel}),this.isMouseDown=!1}destroy(){this.viewport.options.divWheel.removeEventListener("wheel",this.wheelFunction)}down(t){if(this.viewport.pause||!this.viewport.worldVisible)return;if("mouse"===t.data.pointerType?this.isMouseDown=!0:this.get(t.data.pointerId)||this.touches.push({id:t.data.pointerId,last:null}),1===this.count()){this.last=t.data.global.clone();const i=this.viewport.plugins.get("decelerate",!0),e=this.viewport.plugins.get("bounce",!0);i&&i.isActive()||e&&e.isActive()?this.clickedAvailable=!1:this.clickedAvailable=!0}else this.clickedAvailable=!1;this.viewport.plugins.down(t)&&this.viewport.options.stopPropagation&&t.stopPropagation()}clear(){this.isMouseDown=!1,this.touches=[],this.last=null}checkThreshold(t){return Math.abs(t)>=this.viewport.threshold}move(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const i=this.viewport.plugins.move(t);if(this.clickedAvailable&&this.last){const i=t.data.global.x-this.last.x,e=t.data.global.y-this.last.y;(this.checkThreshold(i)||this.checkThreshold(e))&&(this.clickedAvailable=!1)}i&&this.viewport.options.stopPropagation&&t.stopPropagation()}up(t){if(this.viewport.pause||!this.viewport.worldVisible)return;"mouse"===t.data.pointerType&&(this.isMouseDown=!1),"mouse"!==t.data.pointerType&&this.remove(t.data.pointerId);const i=this.viewport.plugins.up(t);this.clickedAvailable&&0===this.count()&&this.last&&(this.viewport.emit("clicked",{event:t,screen:this.last,world:this.viewport.toWorld(this.last),viewport:this}),this.clickedAvailable=!1),i&&this.viewport.options.stopPropagation&&t.stopPropagation()}getPointerPosition(t){const e=new i.Point;return this.viewport.options.interaction?this.viewport.options.interaction.mapPositionToPoint(e,t.clientX,t.clientY):(e.x=t.clientX,e.y=t.clientY),e}handleWheel(t){if(this.viewport.pause||!this.viewport.worldVisible)return;if(this.viewport.options.interaction&&this.viewport.options.interaction.interactionDOMElement!==t.target)return;const i=this.viewport.toLocal(this.getPointerPosition(t));if(this.viewport.left<=i.x&&i.x<=this.viewport.right&&this.viewport.top<=i.y&&i.y<=this.viewport.bottom){this.viewport.plugins.wheel(t)&&!this.viewport.options.passiveWheel&&t.preventDefault()}}pause(){this.touches=[],this.isMouseDown=!1}get(t){for(const i of this.touches)if(i.id===t)return i;return null}remove(t){for(let i=0;i<this.touches.length;i++)if(this.touches[i].id===t)return void this.touches.splice(i,1)}count(){return(this.isMouseDown?1:0)+this.touches.length}}function D(t){let i,e=t[0],s=1;for(;s<t.length;){const n=t[s],h=t[s+1];if(s+=2,("optionalAccess"===n||"optionalCall"===n)&&null==e)return;"access"===n||"optionalAccess"===n?(i=e,e=h(e)):"call"!==n&&"optionalCall"!==n||(e=h(((...t)=>e.call(i,...t))),i=void 0)}return e}const T=["drag","pinch","wheel","follow","mouse-edges","decelerate","animate","bounce","snap-zoom","clamp-zoom","snap","clamp"];class L{constructor(t){this.viewport=t,this.list=[],this.plugins={}}add(t,i,e=T.length){this.plugins[t]=i;const s=T.indexOf(t);-1!==s&&T.splice(s,1),T.splice(e,0,t),this.sort()}get(t,i){return i&&D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.paused])?null:this.plugins[t]}update(t){for(const i of this.list)i.update(t)}resize(){for(const t of this.list)t.resize()}reset(){for(const t of this.list)t.reset()}removeAll(){this.plugins={},this.sort()}remove(t){this.plugins[t]&&(delete this.plugins[t],this.viewport.emit(`${t}-remove`),this.sort())}pause(t){D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.pause,"call",t=>t()])}resume(t){D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.resume,"call",t=>t()])}sort(){this.list=[];for(const t of T)this.plugins[t]&&this.list.push(this.plugins[t])}down(t){let i=!1;for(const e of this.list)e.down(t)&&(i=!0);return i}move(t){let i=!1;for(const e of this.viewport.plugins.list)e.move(t)&&(i=!0);return i}up(t){let i=!1;for(const e of this.list)e.up(t)&&(i=!0);return i}wheel(t){let i=!1;for(const e of this.list)e.wheel(t)&&(i=!0);return i}}const V={screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,interaction:null,disableOnContextMenu:!1,ticker:n.Ticker.shared};class j extends s.Container{__init(){this._disableOnContextMenu=t=>t.preventDefault()}constructor(t={}){super(),j.prototype.__init.call(this),this.options=Object.assign({},{divWheel:document.body},V,t),this.screenWidth=this.options.screenWidth,this.screenHeight=this.options.screenHeight,this._worldWidth=this.options.worldWidth,this._worldHeight=this.options.worldHeight,this.forceHitArea=this.options.forceHitArea,this.threshold=this.options.threshold,this.options.divWheel=this.options.divWheel||document.body,this.options.disableOnContextMenu&&this.options.divWheel.addEventListener("contextmenu",this._disableOnContextMenu),this.options.noTicker||(this.tickerFunction=()=>this.update(this.options.ticker.elapsedMS),this.options.ticker.add(this.tickerFunction)),this.input=new I(this),this.plugins=new L(this)}destroy(t){!this.options.noTicker&&this.tickerFunction&&this.options.ticker.remove(this.tickerFunction),this.options.disableOnContextMenu&&this.options.divWheel.removeEventListener("contextmenu",this._disableOnContextMenu),this.input.destroy(),super.destroy(t)}update(t){this.pause||(this.plugins.update(t),this.lastViewport&&(this.lastViewport.x!==this.x||this.lastViewport.y!==this.y?this.moving=!0:this.moving&&(this.emit("moved-end",this),this.moving=!1),this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y?this.zooming=!0:this.zooming&&(this.emit("zoomed-end",this),this.zooming=!1)),this.forceHitArea||(this._hitAreaDefault=new i.Rectangle(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight),this.hitArea=this._hitAreaDefault),this._dirty=this._dirty||!this.lastViewport||this.lastViewport.x!==this.x||this.lastViewport.y!==this.y||this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y,this.lastViewport={x:this.x,y:this.y,scaleX:this.scale.x,scaleY:this.scale.y},this.emit("frame-end",this))}resize(t=window.innerWidth,i=window.innerHeight,e,s){this.screenWidth=t,this.screenHeight=i,void 0!==e&&(this._worldWidth=e),void 0!==s&&(this._worldHeight=s),this.plugins.resize(),this.dirty=!0}get worldWidth(){return this._worldWidth?this._worldWidth:this.width/this.scale.x}set worldWidth(t){this._worldWidth=t,this.plugins.resize()}get worldHeight(){return this._worldHeight?this._worldHeight:this.height/this.scale.y}set worldHeight(t){this._worldHeight=t,this.plugins.resize()}getVisibleBounds(){return new i.Rectangle(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return 2===arguments.length?this.toLocal(new i.Point(t,e)):this.toLocal(t)}toScreen(t,e){return 2===arguments.length?this.toGlobal(new i.Point(t,e)):this.toGlobal(t)}get worldScreenWidth(){return this.screenWidth/this.scale.x}get worldScreenHeight(){return this.screenHeight/this.scale.y}get screenWorldWidth(){return this.worldWidth*this.scale.x}get screenWorldHeight(){return this.worldHeight*this.scale.y}get center(){return new i.Point(this.worldScreenWidth/2-this.x/this.scale.x,this.worldScreenHeight/2-this.y/this.scale.y)}set center(t){this.moveCenter(t)}moveCenter(...t){let i,e;"number"==typeof t[0]?(i=t[0],e=t[1]):(i=t[0].x,e=t[0].y);const s=(this.worldScreenWidth/2-i)*this.scale.x,n=(this.worldScreenHeight/2-e)*this.scale.y;return this.x===s&&this.y===n||(this.position.set(s,n),this.plugins.reset(),this.dirty=!0),this}get corner(){return new i.Point(-this.x/this.scale.x,-this.y/this.scale.y)}set corner(t){this.moveCorner(t)}moveCorner(...t){let i,e;return 1===t.length?(i=-t[0].x*this.scale.x,e=-t[0].y*this.scale.y):(i=-t[0]*this.scale.x,e=-t[1]*this.scale.y),i===this.x&&e===this.y||(this.position.set(i,e),this.plugins.reset(),this.dirty=!0),this}get screenWidthInWorldPixels(){return this.screenWidth/this.scale.x}get screenHeightInWorldPixels(){return this.screenHeight/this.scale.y}findFitWidth(t){return this.screenWidth/t}findFitHeight(t){return this.screenHeight/t}findFit(t,i){const e=this.screenWidth/t,s=this.screenHeight/i;return Math.min(e,s)}findCover(t,i){const e=this.screenWidth/t,s=this.screenHeight/i;return Math.max(e,s)}fitWidth(t=this.worldWidth,i,e=!0,s){let n;i&&(n=this.center),this.scale.x=this.screenWidth/t,e&&(this.scale.y=this.scale.x);const h=this.plugins.get("clamp-zoom",!0);return!s&&h&&h.clamp(),i&&n&&this.moveCenter(n),this}fitHeight(t=this.worldHeight,i,e=!0,s){let n;i&&(n=this.center),this.scale.y=this.screenHeight/t,e&&(this.scale.x=this.scale.y);const h=this.plugins.get("clamp-zoom",!0);return!s&&h&&h.clamp(),i&&n&&this.moveCenter(n),this}fitWorld(t){let i;t&&(i=this.center),this.scale.x=this.screenWidth/this.worldWidth,this.scale.y=this.screenHeight/this.worldHeight,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const e=this.plugins.get("clamp-zoom",!0);return e&&e.clamp(),t&&i&&this.moveCenter(i),this}fit(t,i=this.worldWidth,e=this.worldHeight){let s;t&&(s=this.center),this.scale.x=this.screenWidth/i,this.scale.y=this.screenHeight/e,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const n=this.plugins.get("clamp-zoom",!0);return n&&n.clamp(),t&&s&&this.moveCenter(s),this}setZoom(t,i){let e;i&&(e=this.center),this.scale.set(t);const s=this.plugins.get("clamp-zoom",!0);return s&&s.clamp(),i&&e&&this.moveCenter(e),this}zoomPercent(t,i){return this.setZoom(this.scale.x+this.scale.x*t,i)}zoom(t,i){return this.fitWidth(t+this.worldScreenWidth,i),this}get scaled(){return this.scale.x}set scaled(t){this.setZoom(t,!0)}snapZoom(t){return this.plugins.add("snap-zoom",new Y(this,t)),this}OOB(){return{left:this.left<0,right:this.right>this.worldWidth,top:this.top<0,bottom:this.bottom>this.worldHeight,cornerPoint:new i.Point(this.worldWidth*this.scale.x-this.screenWidth,this.worldHeight*this.scale.y-this.screenHeight)}}get right(){return-this.x/this.scale.x+this.worldScreenWidth}set right(t){this.x=-t*this.scale.x+this.screenWidth,this.plugins.reset()}get left(){return-this.x/this.scale.x}set left(t){this.x=-t*this.scale.x,this.plugins.reset()}get top(){return-this.y/this.scale.y}set top(t){this.y=-t*this.scale.y,this.plugins.reset()}get bottom(){return-this.y/this.scale.y+this.worldScreenHeight}set bottom(t){this.y=-t*this.scale.y+this.screenHeight,this.plugins.reset()}get dirty(){return!!this._dirty}set dirty(t){this._dirty=t}get forceHitArea(){return this._forceHitArea}set forceHitArea(t){t?(this._forceHitArea=t,this.hitArea=t):(this._forceHitArea=null,this.hitArea=new i.Rectangle(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new b(this,t)),this}clamp(t){return this.plugins.add("clamp",new g(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new v(this,t)),this}bounce(t){return this.plugins.add("bounce",new u(this,t)),this}pinch(t){return this.plugins.add("pinch",new _(this,t)),this}snap(t,i,e){return this.plugins.add("snap",new X(this,t,i,e)),this}follow(t,i){return this.plugins.add("follow",new S(this,t,i)),this}wheel(t){return this.plugins.add("wheel",new A(this,t)),this}animate(t){return this.plugins.add("animate",new l(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new y(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new C(this,t)),this}get pause(){return!!this._pause}set pause(t){this._pause=t,this.lastViewport=null,this.moving=!1,this.zooming=!1,t&&this.input.pause()}ensureVisible(t,i,e,s,n){n&&(e>this.worldScreenWidth||s>this.worldScreenHeight)&&(this.fit(!0,e,s),this.emit("zoomed",{viewport:this,type:"ensureVisible"}));let h=!1;t<this.left?(this.left=t,h=!0):t+e>this.right&&(this.right=t+e,h=!0),i<this.top?(this.top=i,h=!0):i+s>this.bottom&&(this.bottom=i+s,h=!0),h&&this.emit("moved",{viewport:this,type:"ensureVisible"})}}t.Animate=l,t.Bounce=u,t.Clamp=g,t.ClampZoom=y,t.Decelerate=v,t.Drag=b,t.Follow=S,t.InputManager=I,t.MouseEdges=C,t.Pinch=_,t.Plugin=r,t.PluginManager=L,t.Snap=X,t.SnapZoom=Y,t.Viewport=j,t.Wheel=A,Object.defineProperty(t,"__esModule",{value:!0})})),"undefined"!=typeof pixi_viewport&&Object.assign(this.PIXI,pixi_viewport); | ||
this.PIXI=this.PIXI||{},function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("@pixi/math"),require("penner"),require("@pixi/display"),require("@pixi/ticker")):"function"==typeof define&&define.amd?define(["exports","@pixi/math","penner","@pixi/display","@pixi/ticker"],i):i((t="undefined"!=typeof globalThis?globalThis:t||self).pixi_viewport={},t.PIXI,t.Penner,t.PIXI,t.PIXI)}(this,(function(t,i,e,s,n){"use strict";function h(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=h(e);class r{constructor(t){this.parent=t,this.paused=!1}destroy(){}down(t){return!1}move(t){return!1}up(t){return!1}wheel(t){return!1}update(t){}resize(){}reset(){}pause(){this.paused=!0}resume(){this.paused=!1}}function a(t,i){return t?"function"==typeof t?t:"string"==typeof t?o.default[t]:void 0:o.default[i]}const p={removeOnInterrupt:!1,ease:"linear",time:1e3};class l extends r{__init(){this.startWidth=null}__init2(){this.startHeight=null}__init3(){this.deltaWidth=null}__init4(){this.deltaHeight=null}__init5(){this.width=null}__init6(){this.height=null}__init7(){this.time=0}constructor(t,i={}){super(t),l.prototype.__init.call(this),l.prototype.__init2.call(this),l.prototype.__init3.call(this),l.prototype.__init4.call(this),l.prototype.__init5.call(this),l.prototype.__init6.call(this),l.prototype.__init7.call(this),this.options=Object.assign({},p,i),this.options.ease=a(this.options.ease),this.setupPosition(),this.setupZoom(),this.time=0}setupPosition(){void 0!==this.options.position?(this.startX=this.parent.center.x,this.startY=this.parent.center.y,this.deltaX=this.options.position.x-this.parent.center.x,this.deltaY=this.options.position.y-this.parent.center.y,this.keepCenter=!1):this.keepCenter=!0}setupZoom(){this.width=null,this.height=null,void 0!==this.options.scale?this.width=this.parent.screenWidth/this.options.scale:void 0!==this.options.scaleX||void 0!==this.options.scaleY?(void 0!==this.options.scaleX&&(this.width=this.parent.screenWidth/this.options.scaleX),void 0!==this.options.scaleY&&(this.height=this.parent.screenHeight/this.options.scaleY)):(void 0!==this.options.width&&(this.width=this.options.width),void 0!==this.options.height&&(this.height=this.options.height)),null!==this.width&&(this.startWidth=this.parent.screenWidthInWorldPixels,this.deltaWidth=this.width-this.startWidth),null!==this.height&&(this.startHeight=this.parent.screenHeightInWorldPixels,this.deltaHeight=this.height-this.startHeight)}down(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("animate"),!1}complete(){this.parent.plugins.remove("animate"),null!==this.width&&this.parent.fitWidth(this.width,this.keepCenter,null===this.height),null!==this.height&&this.parent.fitHeight(this.height,this.keepCenter,null===this.width),this.keepCenter||this.parent.moveCenter(this.options.position),this.parent.emit("animate-end",this.parent),this.options.callbackOnComplete&&this.options.callbackOnComplete(this.parent)}update(t){if(!this.paused)if(this.time+=t,this.time>=this.options.time)this.complete();else{const t=new i.Point(this.parent.scale.x,this.parent.scale.y),e=this.options.ease(this.time,0,1,this.options.time);if(null!==this.width){const t=this.startWidth,i=this.deltaWidth;this.parent.fitWidth(t+i*e,this.keepCenter,null===this.height)}if(null!==this.height){const t=this.startHeight,i=this.deltaHeight;this.parent.fitHeight(t+i*e,this.keepCenter,null===this.width)}if(null===this.width?this.parent.scale.x=this.parent.scale.y:null===this.height&&(this.parent.scale.y=this.parent.scale.x),!this.keepCenter){const t=this.startX,s=this.startY,n=this.deltaX,h=this.deltaY,o=new i.Point(this.parent.x,this.parent.y);this.parent.moveCenter(t+n*e,s+h*e),this.parent.emit("moved",{viewport:this.parent,original:o,type:"animate"})}(this.width||this.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:t,type:"animate"})}}}function c(t){let i,e=t[0],s=1;for(;s<t.length;){const n=t[s],h=t[s+1];if(s+=2,("optionalAccess"===n||"optionalCall"===n)&&null==e)return;"access"===n||"optionalAccess"===n?(i=e,e=h(e)):"call"!==n&&"optionalCall"!==n||(e=h(((...t)=>e.call(i,...t))),i=void 0)}return e}const d={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class u extends r{constructor(t,i={}){super(t),this.options=Object.assign({},d,i),this.ease=a(this.options.ease,"easeInOutSine"),this.options.sides?"all"===this.options.sides?this.top=this.bottom=this.left=this.right=!0:"horizontal"===this.options.sides?(this.right=this.left=!0,this.top=this.bottom=!1):"vertical"===this.options.sides?(this.left=this.right=!1,this.top=this.bottom=!0):(this.top=-1!==this.options.sides.indexOf("top"),this.bottom=-1!==this.options.sides.indexOf("bottom"),this.left=-1!==this.options.sides.indexOf("left"),this.right=-1!==this.options.sides.indexOf("right")):this.left=this.top=this.right=this.bottom=!1;const e=this.options.underflow.toLowerCase();"center"===e?(this.underflowX=0,this.underflowY=0):(this.underflowX=-1!==e.indexOf("left")?-1:-1!==e.indexOf("right")?1:0,this.underflowY=-1!==e.indexOf("top")?-1:-1!==e.indexOf("bottom")?1:0),this.reset()}isActive(){return null!==this.toX||null!==this.toY}down(){return this.toX=this.toY=null,!1}up(){return this.bounce(),!1}update(t){if(!this.paused){if(this.bounce(),this.toX){const i=this.toX;i.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-x"}),i.time>=this.options.time?(this.parent.x=i.end,this.toX=null,this.parent.emit("bounce-x-end",this.parent)):this.parent.x=this.ease(i.time,i.start,i.delta,this.options.time)}if(this.toY){const i=this.toY;i.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-y"}),i.time>=this.options.time?(this.parent.y=i.end,this.toY=null,this.parent.emit("bounce-y-end",this.parent)):this.parent.y=this.ease(i.time,i.start,i.delta,this.options.time)}}}calcUnderflowX(){let t;switch(this.underflowX){case-1:t=0;break;case 1:t=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:t=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}return t}calcUnderflowY(){let t;switch(this.underflowY){case-1:t=0;break;case 1:t=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:t=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}return t}oob(){const t=this.options.bounceBox;if(t){const e=void 0===t.x?0:t.x,s=void 0===t.y?0:t.y,n=void 0===t.width?this.parent.worldWidth:t.width,h=void 0===t.height?this.parent.worldHeight:t.height;return{left:this.parent.left<e,right:this.parent.right>n,top:this.parent.top<s,bottom:this.parent.bottom>h,topLeft:new i.Point(e*this.parent.scale.x,s*this.parent.scale.y),bottomRight:new i.Point(n*this.parent.scale.x-this.parent.screenWidth,h*this.parent.scale.y-this.parent.screenHeight)}}return{left:this.parent.left<0,right:this.parent.right>this.parent.worldWidth,top:this.parent.top<0,bottom:this.parent.bottom>this.parent.worldHeight,topLeft:new i.Point(0,0),bottomRight:new i.Point(this.parent.worldWidth*this.parent.scale.x-this.parent.screenWidth,this.parent.worldHeight*this.parent.scale.y-this.parent.screenHeight)}}bounce(){if(this.paused)return;let t,i=this.parent.plugins.get("decelerate",!0);i&&(i.x||i.y)&&(i.x&&i.percentChangeX===c([i,"access",t=>t.options,"optionalAccess",t=>t.friction])||i.y&&i.percentChangeY===c([i,"access",t=>t.options,"optionalAccess",t=>t.friction]))&&(t=this.oob(),(t.left&&this.left||t.right&&this.right)&&(i.percentChangeX=this.options.friction),(t.top&&this.top||t.bottom&&this.bottom)&&(i.percentChangeY=this.options.friction));const e=this.parent.plugins.get("drag",!0)||{},s=this.parent.plugins.get("pinch",!0)||{};if(i=i||{},!(c([e,"optionalAccess",t=>t.active])||c([s,"optionalAccess",t=>t.active])||this.toX&&this.toY||i.x&&i.y)){t=t||this.oob();const e=t.topLeft,s=t.bottomRight;if(!this.toX&&!i.x){let i=null;t.left&&this.left?i=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-e.x:t.right&&this.right&&(i=this.parent.screenWorldWidth<this.parent.screenWidth?this.calcUnderflowX():-s.x),null!==i&&this.parent.x!==i&&(this.toX={time:0,start:this.parent.x,delta:i-this.parent.x,end:i},this.parent.emit("bounce-x-start",this.parent))}if(!this.toY&&!i.y){let i=null;t.top&&this.top?i=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-e.y:t.bottom&&this.bottom&&(i=this.parent.screenWorldHeight<this.parent.screenHeight?this.calcUnderflowY():-s.y),null!==i&&this.parent.y!==i&&(this.toY={time:0,start:this.parent.y,delta:i-this.parent.y,end:i},this.parent.emit("bounce-y-start",this.parent))}}}reset(){this.toX=this.toY=null,this.bounce()}}const m={left:!1,right:!1,top:!1,bottom:!1,direction:null,underflow:"center"};class g extends r{constructor(t,i={}){super(t),this.options=Object.assign({},m,i),this.options.direction&&(this.options.left="x"===this.options.direction||"all"===this.options.direction||null,this.options.right="x"===this.options.direction||"all"===this.options.direction||null,this.options.top="y"===this.options.direction||"all"===this.options.direction||null,this.options.bottom="y"===this.options.direction||"all"===this.options.direction||null),this.parseUnderflow(),this.last={x:null,y:null,scaleX:null,scaleY:null},this.update()}parseUnderflow(){const t=this.options.underflow.toLowerCase();"none"===t?this.noUnderflow=!0:"center"===t?(this.underflowX=this.underflowY=0,this.noUnderflow=!1):(this.underflowX=-1!==t.indexOf("left")?-1:-1!==t.indexOf("right")?1:0,this.underflowY=-1!==t.indexOf("top")?-1:-1!==t.indexOf("bottom")?1:0,this.noUnderflow=!1)}move(){return this.update(),!1}update(){if(this.paused)return;if(this.parent.x===this.last.x&&this.parent.y===this.last.y&&this.parent.scale.x===this.last.scaleX&&this.parent.scale.y===this.last.scaleY)return;const t={x:this.parent.x,y:this.parent.y},i=this.parent.plugins.decelerate||{};if(null!==this.options.left||null!==this.options.right){let e=!1;if(!this.noUnderflow&&this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:0!==this.parent.x&&(this.parent.x=0,e=!0);break;case 1:this.parent.x!==this.parent.screenWidth-this.parent.screenWorldWidth&&(this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth,e=!0);break;default:this.parent.x!==(this.parent.screenWidth-this.parent.screenWorldWidth)/2&&(this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2,e=!0)}else null!==this.options.left&&this.parent.left<(!0===this.options.left?0:this.options.left)&&(this.parent.x=-(!0===this.options.left?0:this.options.left)*this.parent.scale.x,i.x=0,e=!0),null!==this.options.right&&this.parent.right>(!0===this.options.right?this.parent.worldWidth:this.options.right)&&(this.parent.x=-(!0===this.options.right?this.parent.worldWidth:this.options.right)*this.parent.scale.x+this.parent.screenWidth,i.x=0,e=!0);e&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-x"})}if(null!==this.options.top||null!==this.options.bottom){let e=!1;if(!this.noUnderflow&&this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:0!==this.parent.y&&(this.parent.y=0,e=!0);break;case 1:this.parent.y!==this.parent.screenHeight-this.parent.screenWorldHeight&&(this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight,e=!0);break;default:this.parent.y!==(this.parent.screenHeight-this.parent.screenWorldHeight)/2&&(this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2,e=!0)}else null!==this.options.top&&this.parent.top<(!0===this.options.top?0:this.options.top)&&(this.parent.y=-(!0===this.options.top?0:this.options.top)*this.parent.scale.y,i.y=0,e=!0),null!==this.options.bottom&&this.parent.bottom>(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)&&(this.parent.y=-(!0===this.options.bottom?this.parent.worldHeight:this.options.bottom)*this.parent.scale.y+this.parent.screenHeight,i.y=0,e=!0);e&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-y"})}this.last.x=this.parent.x,this.last.y=this.parent.y,this.last.scaleX=this.parent.scale.x,this.last.scaleY=this.parent.scale.y}reset(){this.update()}}const w={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class y extends r{constructor(t,i={}){super(t),this.options=Object.assign({},w,i),this.clamp()}resize(){this.clamp()}clamp(){if(!this.paused)if(this.options.minWidth||this.options.minHeight||this.options.maxWidth||this.options.maxHeight){let t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight;if(null!==this.options.minWidth&&t<this.options.minWidth){const e=this.parent.scale.x;this.parent.fitWidth(this.options.minWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxWidth&&t>this.options.maxWidth){const e=this.parent.scale.x;this.parent.fitWidth(this.options.maxWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.minHeight&&i<this.options.minHeight){const e=this.parent.scale.y;this.parent.fitHeight(this.options.minHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/e,t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(null!==this.options.maxHeight&&i>this.options.maxHeight){const t=this.parent.scale.y;this.parent.fitHeight(this.options.maxHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/t,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}}else if(this.options.minScale||this.options.maxScale){const t={x:null,y:null},i={x:null,y:null};if("number"==typeof this.options.minScale)t.x=this.options.minScale,t.y=this.options.minScale;else if(null!==this.options.minScale){const i=this.options.minScale;t.x=void 0===i.x?null:i.x,t.y=void 0===i.y?null:i.y}if("number"==typeof this.options.maxScale)i.x=this.options.maxScale,i.y=this.options.maxScale;else if(null!==this.options.maxScale){const t=this.options.maxScale;i.x=void 0===t.x?null:t.x,i.y=void 0===t.y?null:t.y}let e=this.parent.scale.x,s=this.parent.scale.y;null!==t.x&&e<t.x&&(e=t.x),null!==i.x&&e>i.x&&(e=i.x),null!==t.y&&s<t.y&&(s=t.y),null!==i.y&&s>i.y&&(s=i.y),e===this.parent.scale.x&&s===this.parent.scale.y||(this.parent.scale.set(e,s),this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"}))}}reset(){this.clamp()}}const x={friction:.98,bounce:.8,minSpeed:.01},f=16;class v extends r{constructor(t,i={}){super(t),this.options=Object.assign({},x,i),this.saved=[],this.timeSinceRelease=0,this.reset(),this.parent.on("moved",(t=>this.moved(t)))}down(){return this.saved=[],this.x=this.y=null,!1}isActive(){return!(!this.x&&!this.y)}move(){if(this.paused)return!1;const t=this.parent.input.count();return(1===t||t>1&&!this.parent.plugins.get("pinch",!0))&&(this.saved.push({x:this.parent.x,y:this.parent.y,time:performance.now()}),this.saved.length>60&&this.saved.splice(0,30)),!1}moved(t){if(this.saved.length){const i=this.saved[this.saved.length-1];"clamp-x"===t.type?i.x===t.original.x&&(i.x=this.parent.x):"clamp-y"===t.type&&i.y===t.original.y&&(i.y=this.parent.y)}}up(){if(0===this.parent.input.count()&&this.saved.length){const t=performance.now();for(const i of this.saved)if(i.time>=t-100){const e=t-i.time;this.x=(this.parent.x-i.x)/e,this.y=(this.parent.y-i.y)/e,this.percentChangeX=this.percentChangeY=this.options.friction,this.timeSinceRelease=0;break}}return!1}activate(t){void 0!==(t=t||{}).x&&(this.x=t.x,this.percentChangeX=this.options.friction),void 0!==t.y&&(this.y=t.y,this.percentChangeY=this.options.friction)}update(t){if(this.paused)return;const i=this.x||this.y,e=this.timeSinceRelease,s=this.timeSinceRelease+t;if(this.x){const i=this.percentChangeX,n=Math.log(i);this.parent.x+=this.x*f/n*(Math.pow(i,s/f)-Math.pow(i,e/f)),this.x*=Math.pow(this.percentChangeX,t/f)}if(this.y){const i=this.percentChangeY,n=Math.log(i);this.parent.y+=this.y*f/n*(Math.pow(i,s/f)-Math.pow(i,e/f)),this.y*=Math.pow(this.percentChangeY,t/f)}this.timeSinceRelease+=t,this.x&&this.y?Math.abs(this.x)<this.options.minSpeed&&Math.abs(this.y)<this.options.minSpeed&&(this.x=0,this.y=0):(Math.abs(this.x||0)<this.options.minSpeed&&(this.x=0),Math.abs(this.y||0)<this.options.minSpeed&&(this.y=0)),i&&this.parent.emit("moved",{viewport:this.parent,type:"decelerate"})}reset(){this.x=this.y=null}}const W={direction:"all",pressDrag:!0,wheel:!0,wheelScroll:1,reverse:!1,clampWheel:!1,underflow:"center",factor:1,mouseButtons:"all",keyToPress:null,ignoreKeyToPressOnTouch:!1,lineHeight:20};class b extends r{constructor(t,i={}){super(t),this.options=Object.assign({},W,i),this.moved=!1,this.reverse=this.options.reverse?1:-1,this.xDirection=!this.options.direction||"all"===this.options.direction||"x"===this.options.direction,this.yDirection=!this.options.direction||"all"===this.options.direction||"y"===this.options.direction,this.keyIsPressed=!1,this.parseUnderflow(),this.mouseButtons(this.options.mouseButtons),this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){window.addEventListener("keydown",(i=>{t.includes(i.code)&&(this.keyIsPressed=!0)})),window.addEventListener("keyup",(i=>{t.includes(i.code)&&(this.keyIsPressed=!1)}))}mouseButtons(t){this.mouse=t&&"all"!==t?[-1!==t.indexOf("left"),-1!==t.indexOf("middle"),-1!==t.indexOf("right")]:[!0,!0,!0]}parseUnderflow(){const t=this.options.underflow.toLowerCase();"center"===t?(this.underflowX=0,this.underflowY=0):(t.includes("left")?this.underflowX=-1:t.includes("right")?this.underflowX=1:this.underflowX=0,t.includes("top")?this.underflowY=-1:t.includes("bottom")?this.underflowY=1:this.underflowY=0)}checkButtons(t){const i="mouse"===t.data.pointerType,e=this.parent.input.count();return!(!(1===e||e>1&&!this.parent.plugins.get("pinch",!0))||i&&!this.mouse[t.data.button])}checkKeyPress(t){return!this.options.keyToPress||this.keyIsPressed||this.options.ignoreKeyToPressOnTouch&&"touch"===t.data.pointerType}down(t){return!(this.paused||!this.options.pressDrag)&&(this.checkButtons(t)&&this.checkKeyPress(t)?(this.last={x:t.data.global.x,y:t.data.global.y},this.current=t.data.pointerId,!0):(this.last=null,!1))}get active(){return this.moved}move(t){if(this.paused||!this.options.pressDrag)return!1;if(this.last&&this.current===t.data.pointerId){const e=t.data.global.x,s=t.data.global.y,n=this.parent.input.count();if(1===n||n>1&&!this.parent.plugins.get("pinch",!0)){const n=e-this.last.x,h=s-this.last.y;if(this.moved||this.xDirection&&this.parent.input.checkThreshold(n)||this.yDirection&&this.parent.input.checkThreshold(h)){const n={x:e,y:s};return this.xDirection&&(this.parent.x+=(n.x-this.last.x)*this.options.factor),this.yDirection&&(this.parent.y+=(n.y-this.last.y)*this.options.factor),this.last=n,this.moved||this.parent.emit("drag-start",{event:t,screen:new i.Point(this.last.x,this.last.y),world:this.parent.toWorld(new i.Point(this.last.x,this.last.y)),viewport:this.parent}),this.moved=!0,this.parent.emit("moved",{viewport:this.parent,type:"drag"}),!0}}else this.moved=!1}return!1}up(t){if(this.paused)return!1;const e=this.parent.input.touches;if(1===e.length){const t=e[0];return t.last&&(this.last={x:t.last.x,y:t.last.y},this.current=t.id),this.moved=!1,!0}if(this.last&&this.moved){const e=new i.Point(this.last.x,this.last.y);return this.parent.emit("drag-end",{event:t,screen:e,world:this.parent.toWorld(e),viewport:this.parent}),this.last=null,this.moved=!1,!0}return!1}wheel(t){if(this.paused)return!1;if(this.options.wheel){const i=this.parent.plugins.get("wheel",!0);if(!i||!i.options.wheelZoom&&!t.ctrlKey){const i=t.deltaMode?this.options.lineHeight:1;return this.xDirection&&(this.parent.x+=t.deltaX*i*this.options.wheelScroll*this.reverse),this.yDirection&&(this.parent.y+=t.deltaY*i*this.options.wheelScroll*this.reverse),this.options.clampWheel&&this.clamp(),this.parent.emit("wheel-scroll",this.parent),this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.options.passiveWheel||t.preventDefault(),this.parent.options.stopPropagation&&t.stopPropagation(),!0}}return!1}resume(){this.last=null,this.paused=!1}clamp(){const t=this.parent.plugins.get("decelerate",!0)||{};if("y"!==this.options.clampWheel)if(this.parent.screenWorldWidth<this.parent.screenWidth)switch(this.underflowX){case-1:this.parent.x=0;break;case 1:this.parent.x=this.parent.screenWidth-this.parent.screenWorldWidth;break;default:this.parent.x=(this.parent.screenWidth-this.parent.screenWorldWidth)/2}else this.parent.left<0?(this.parent.x=0,t.x=0):this.parent.right>this.parent.worldWidth&&(this.parent.x=-this.parent.worldWidth*this.parent.scale.x+this.parent.screenWidth,t.x=0);if("x"!==this.options.clampWheel)if(this.parent.screenWorldHeight<this.parent.screenHeight)switch(this.underflowY){case-1:this.parent.y=0;break;case 1:this.parent.y=this.parent.screenHeight-this.parent.screenWorldHeight;break;default:this.parent.y=(this.parent.screenHeight-this.parent.screenWorldHeight)/2}else this.parent.top<0&&(this.parent.y=0,t.y=0),this.parent.bottom>this.parent.worldHeight&&(this.parent.y=-this.parent.worldHeight*this.parent.scale.y+this.parent.screenHeight,t.y=0)}}const H={speed:0,acceleration:null,radius:null};class S extends r{constructor(t,i,e={}){super(t),this.target=i,this.options=Object.assign({},H,e),this.velocity={x:0,y:0}}update(t){if(this.paused)return;const i=this.parent.center;let e=this.target.x,s=this.target.y;if(this.options.radius){if(!(Math.sqrt(Math.pow(this.target.y-i.y,2)+Math.pow(this.target.x-i.x,2))>this.options.radius))return;{const t=Math.atan2(this.target.y-i.y,this.target.x-i.x);e=this.target.x-Math.cos(t)*this.options.radius,s=this.target.y-Math.sin(t)*this.options.radius}}const n=e-i.x,h=s-i.y;if(n||h)if(this.options.speed)if(this.options.acceleration){const o=Math.atan2(s-i.y,e-i.x),r=Math.sqrt(Math.pow(n,2)+Math.pow(h,2));if(r){const a=(Math.pow(this.velocity.x,2)+Math.pow(this.velocity.y,2))/(2*this.options.acceleration);this.velocity=r>a?{x:Math.min(this.velocity.x+this.options.acceleration*t,this.options.speed),y:Math.min(this.velocity.y+this.options.acceleration*t,this.options.speed)}:{x:Math.max(this.velocity.x-this.options.acceleration*this.options.speed,0),y:Math.max(this.velocity.y-this.options.acceleration*this.options.speed,0)};const p=Math.cos(o)*this.velocity.x,l=Math.sin(o)*this.velocity.y,c=Math.abs(p)>Math.abs(n)?e:i.x+p,d=Math.abs(l)>Math.abs(h)?s:i.y+l;this.parent.moveCenter(c,d),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}else{const t=Math.atan2(s-i.y,e-i.x),o=Math.cos(t)*this.options.speed,r=Math.sin(t)*this.options.speed,a=Math.abs(o)>Math.abs(n)?e:i.x+o,p=Math.abs(r)>Math.abs(h)?s:i.y+r;this.parent.moveCenter(a,p),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}else this.parent.moveCenter(e,s),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}const M={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};class C extends r{constructor(t,i={}){super(t),this.options=Object.assign({},M,i),this.reverse=this.options.reverse?1:-1,this.radiusSquared="number"==typeof this.options.radius?Math.pow(this.options.radius,2):null,this.resize()}resize(){const t=this.options.distance;null!==t?(this.left=t,this.top=t,this.right=this.parent.worldScreenWidth-t,this.bottom=this.parent.worldScreenHeight-t):this.options.radius||(this.left=this.options.left,this.top=this.options.top,this.right=null===this.options.right?null:this.parent.worldScreenWidth-this.options.right,this.bottom=null===this.options.bottom?null:this.parent.worldScreenHeight-this.options.bottom)}down(){return this.paused||this.options.allowButtons||(this.horizontal=this.vertical=null),!1}move(t){if(this.paused)return!1;if("mouse"!==t.data.pointerType&&1!==t.data.identifier||!this.options.allowButtons&&0!==t.data.buttons)return!1;const i=t.data.global.x,e=t.data.global.y;if(this.radiusSquared){const t=this.parent.toScreen(this.parent.center);if(Math.pow(t.x-i,2)+Math.pow(t.y-e,2)>=this.radiusSquared){const s=Math.atan2(t.y-e,t.x-i);this.options.linear?(this.horizontal=Math.round(Math.cos(s))*this.options.speed*this.reverse*.06,this.vertical=Math.round(Math.sin(s))*this.options.speed*this.reverse*.06):(this.horizontal=Math.cos(s)*this.options.speed*this.reverse*.06,this.vertical=Math.sin(s)*this.options.speed*this.reverse*.06)}else this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=0}else null!==this.left&&i<this.left?this.horizontal=Number(this.reverse)*this.options.speed*.06:null!==this.right&&i>this.right?this.horizontal=-1*this.reverse*this.options.speed*.06:(this.decelerateHorizontal(),this.horizontal=0),null!==this.top&&e<this.top?this.vertical=Number(this.reverse)*this.options.speed*.06:null!==this.bottom&&e>this.bottom?this.vertical=-1*this.reverse*this.options.speed*.06:(this.decelerateVertical(),this.vertical=0);return!1}decelerateHorizontal(){const t=this.parent.plugins.get("decelerate",!0);this.horizontal&&t&&!this.options.noDecelerate&&t.activate({x:this.horizontal*this.options.speed*this.reverse/(1e3/60)})}decelerateVertical(){const t=this.parent.plugins.get("decelerate",!0);this.vertical&&t&&!this.options.noDecelerate&&t.activate({y:this.vertical*this.options.speed*this.reverse/(1e3/60)})}up(){return this.paused||(this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=null),!1}update(){if(!this.paused&&(this.horizontal||this.vertical)){const t=this.parent.center;this.horizontal&&(t.x+=this.horizontal*this.options.speed),this.vertical&&(t.y+=this.vertical*this.options.speed),this.parent.moveCenter(t),this.parent.emit("moved",{viewport:this.parent,type:"mouse-edges"})}}}const P={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class k extends r{__init(){this.active=!1}__init2(){this.pinching=!1}__init3(){this.moved=!1}constructor(t,i={}){super(t),k.prototype.__init.call(this),k.prototype.__init2.call(this),k.prototype.__init3.call(this),this.options=Object.assign({},P,i)}down(){return this.parent.input.count()>=2&&(this.active=!0,!0)}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}move(t){if(this.paused||!this.active)return!1;const i=t.data.global.x,e=t.data.global.y,s=this.parent.input.touches;if(s.length>=2){const n=s[0],h=s[1],o=n.last&&h.last?Math.sqrt(Math.pow(h.last.x-n.last.x,2)+Math.pow(h.last.y-n.last.y,2)):null;if(n.id===t.data.pointerId?n.last={x:i,y:e,data:t.data}:h.id===t.data.pointerId&&(h.last={x:i,y:e,data:t.data}),o){let t;const i={x:n.last.x+(h.last.x-n.last.x)/2,y:n.last.y+(h.last.y-n.last.y)/2};this.options.center||(t=this.parent.toLocal(i));let e=Math.sqrt(Math.pow(h.last.x-n.last.x,2)+Math.pow(h.last.y-n.last.y,2));e=0===e?e=1e-10:e;const s=(1-o/e)*this.options.percent*(this.isAxisX()?this.parent.scale.x:this.parent.scale.y);this.isAxisX()&&(this.parent.scale.x+=s),this.isAxisY()&&(this.parent.scale.y+=s),this.parent.emit("zoomed",{viewport:this.parent,type:"pinch",center:i});const r=this.parent.plugins.get("clamp-zoom",!0);if(r&&r.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(t);this.parent.x+=(i.x-e.x)*this.options.factor,this.parent.y+=(i.y-e.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})}!this.options.noDrag&&this.lastCenter&&(this.parent.x+=(i.x-this.lastCenter.x)*this.options.factor,this.parent.y+=(i.y-this.lastCenter.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})),this.lastCenter=i,this.moved=!0}else this.pinching||(this.parent.emit("pinch-start",this.parent),this.pinching=!0);return!0}return!1}up(){return!!(this.pinching&&this.parent.input.touches.length<=1)&&(this.active=!1,this.lastCenter=null,this.pinching=!1,this.moved=!1,this.parent.emit("pinch-end",this.parent),!0)}}const z={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class _ extends r{constructor(t,i,e,s={}){super(t),this.options=Object.assign({},z,s),this.ease=a(s.ease,"easeInOutSine"),this.x=i,this.y=e,this.options.forceStart&&this.snapStart()}snapStart(){this.percent=0,this.snapping={time:0};const t=this.options.topLeft?this.parent.corner:this.parent.center;this.deltaX=this.x-t.x,this.deltaY=this.y-t.y,this.startX=t.x,this.startY=t.y,this.parent.emit("snap-start",this.parent)}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap"):this.options.interrupt&&(this.snapping=null),!1}up(){if(0===this.parent.input.count()){const t=this.parent.plugins.get("decelerate",!0);t&&(t.x||t.y)&&(t.percentChangeX=t.percentChangeY=this.options.friction)}return!1}update(t){if(!(this.paused||this.options.interrupt&&0!==this.parent.input.count()))if(this.snapping){const i=this.snapping;let e,s,n;i.time+=t;const h=this.startX,o=this.startY,r=this.deltaX,a=this.deltaY;if(i.time>this.options.time)e=!0,s=h+r,n=o+a;else{const t=this.ease(i.time,0,1,this.options.time);s=h+r*t,n=o+a*t}this.options.topLeft?this.parent.moveCorner(s,n):this.parent.moveCenter(s,n),this.parent.emit("moved",{viewport:this.parent,type:"snap"}),e&&(this.options.removeOnComplete&&this.parent.plugins.remove("snap"),this.parent.emit("snap-end",this.parent),this.snapping=null)}else{const t=this.options.topLeft?this.parent.corner:this.parent.center;t.x===this.x&&t.y===this.y||this.snapStart()}}}const X={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class Y extends r{constructor(t,i={}){super(t),this.options=Object.assign({},X,i),this.ease=a(this.options.ease),this.xIndependent=!1,this.yIndependent=!1,this.xScale=0,this.yScale=0,this.options.width>0&&(this.xScale=t.screenWidth/this.options.width,this.xIndependent=!0),this.options.height>0&&(this.yScale=t.screenHeight/this.options.height,this.yIndependent=!0),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale,0===this.options.time?(t.container.scale.x=this.xScale,t.container.scale.y=this.yScale,this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom")):i.forceStart&&this.createSnapping()}createSnapping(){const t=this.parent.worldScreenWidth,i=this.parent.worldScreenHeight,e=this.parent.screenWidth/this.xScale,s=this.parent.screenHeight/this.yScale;this.snapping={time:0,startX:t,startY:i,deltaX:e-t,deltaY:s-i},this.parent.emit("snap-zoom-start",this.parent)}resize(){this.snapping=null,this.options.width>0&&(this.xScale=this.parent.screenWidth/this.options.width),this.options.height>0&&(this.yScale=this.parent.screenHeight/this.options.height),this.xScale=this.xIndependent?this.xScale:this.yScale,this.yScale=this.yIndependent?this.yScale:this.xScale}wheel(){return this.options.removeOnInterrupt&&this.parent.plugins.remove("snap-zoom"),!1}down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap-zoom"):this.options.interrupt&&(this.snapping=null),!1}update(t){if(this.paused)return;if(this.options.interrupt&&0!==this.parent.input.count())return;let i;if(this.options.center||this.options.noMove||(i=this.parent.center),this.snapping){if(this.snapping){const e=this.snapping;if(e.time+=t,e.time>=this.options.time)this.parent.scale.set(this.xScale,this.yScale),this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom"),this.parent.emit("snap-zoom-end",this.parent),this.snapping=null;else{const t=this.snapping,i=this.ease(t.time,t.startX,t.deltaX,this.options.time),e=this.ease(t.time,t.startY,t.deltaY,this.options.time);this.parent.scale.x=this.parent.screenWidth/i,this.parent.scale.y=this.parent.screenHeight/e}const s=this.parent.plugins.get("clamp-zoom",!0);s&&s.clamp(),this.options.noMove||(this.options.center?this.parent.moveCenter(this.options.center):this.parent.moveCenter(i))}}else this.parent.scale.x===this.xScale&&this.parent.scale.y===this.yScale||this.createSnapping()}resume(){this.snapping=null,super.resume()}}const O={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",keyToPress:null,trackpadPinch:!1,wheelZoom:!0};class A extends r{constructor(t,i={}){super(t),this.options=Object.assign({},O,i),this.keyIsPressed=!1,this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){window.addEventListener("keydown",(i=>{t.includes(i.code)&&(this.keyIsPressed=!0)})),window.addEventListener("keyup",(i=>{t.includes(i.code)&&(this.keyIsPressed=!1)}))}checkKeyPress(){return!this.options.keyToPress||this.keyIsPressed}down(){return this.options.interrupt&&(this.smoothing=null),!1}isAxisX(){return["all","x"].includes(this.options.axis)}isAxisY(){return["all","y"].includes(this.options.axis)}update(){if(this.smoothing){const t=this.smoothingCenter,i=this.smoothing;let e;this.options.center||(e=this.parent.toLocal(t)),this.isAxisX()&&(this.parent.scale.x+=i.x),this.isAxisY()&&(this.parent.scale.y+=i.y),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const s=this.parent.plugins.get("clamp-zoom",!0);if(s&&s.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const i=this.parent.toGlobal(e);this.parent.x+=t.x-i.x,this.parent.y+=t.y-i.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.smoothingCount++,this.smoothingCount>=this.options.smooth&&(this.smoothing=null)}}pinch(t){if(this.paused)return;const i=this.parent.input.getPointerPosition(t),e=-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/200,s=Math.pow(2,(1+this.options.percent)*e);let n;this.options.center||(n=this.parent.toLocal(i)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const h=this.parent.plugins.get("clamp-zoom",!0);if(h&&h.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const t=this.parent.toGlobal(n);this.parent.x+=i.x-t.x,this.parent.y+=i.y-t.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel",{wheel:{dx:t.deltaX,dy:t.deltaY,dz:t.deltaZ},event:t,viewport:this.parent})}wheel(t){if(this.paused)return!1;if(!this.checkKeyPress())return!1;if(t.ctrlKey&&this.options.trackpadPinch)this.pinch(t);else if(this.options.wheelZoom){const i=this.parent.input.getPointerPosition(t),e=(this.options.reverse?-1:1)*-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/500,s=Math.pow(2,(1+this.options.percent)*e);if(this.options.smooth){const t={x:this.smoothing?this.smoothing.x*(this.options.smooth-this.smoothingCount):0,y:this.smoothing?this.smoothing.y*(this.options.smooth-this.smoothingCount):0};this.smoothing={x:((this.parent.scale.x+t.x)*s-this.parent.scale.x)/this.options.smooth,y:((this.parent.scale.y+t.y)*s-this.parent.scale.y)/this.options.smooth},this.smoothingCount=0,this.smoothingCenter=i}else{let t;this.options.center||(t=this.parent.toLocal(i)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const e=this.parent.plugins.get("clamp-zoom",!0);if(e&&e.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const e=this.parent.toGlobal(t);this.parent.x+=i.x-e.x,this.parent.y+=i.y-e.y}}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel",{wheel:{dx:t.deltaX,dy:t.deltaY,dz:t.deltaZ},event:t,viewport:this.parent})}return!this.parent.options.passiveWheel}}class I{constructor(t){this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.interactive=!0,this.viewport.forceHitArea||(this.viewport.hitArea=new i.Rectangle(0,0,this.viewport.worldWidth,this.viewport.worldHeight)),this.viewport.on("pointerdown",this.down,this),this.viewport.on("pointermove",this.move,this),this.viewport.on("pointerup",this.up,this),this.viewport.on("pointerupoutside",this.up,this),this.viewport.on("pointercancel",this.up,this),this.viewport.on("pointerout",this.up,this),this.wheelFunction=t=>this.handleWheel(t),this.viewport.options.divWheel.addEventListener("wheel",this.wheelFunction,{passive:this.viewport.options.passiveWheel}),this.isMouseDown=!1}destroy(){this.viewport.options.divWheel.removeEventListener("wheel",this.wheelFunction)}down(t){if(this.viewport.pause||!this.viewport.worldVisible)return;if("mouse"===t.data.pointerType?this.isMouseDown=!0:this.get(t.data.pointerId)||this.touches.push({id:t.data.pointerId,last:null}),1===this.count()){this.last=t.data.global.clone();const i=this.viewport.plugins.get("decelerate",!0),e=this.viewport.plugins.get("bounce",!0);i&&i.isActive()||e&&e.isActive()?this.clickedAvailable=!1:this.clickedAvailable=!0}else this.clickedAvailable=!1;this.viewport.plugins.down(t)&&this.viewport.options.stopPropagation&&t.stopPropagation()}clear(){this.isMouseDown=!1,this.touches=[],this.last=null}checkThreshold(t){return Math.abs(t)>=this.viewport.threshold}move(t){if(this.viewport.pause||!this.viewport.worldVisible)return;const i=this.viewport.plugins.move(t);if(this.clickedAvailable&&this.last){const i=t.data.global.x-this.last.x,e=t.data.global.y-this.last.y;(this.checkThreshold(i)||this.checkThreshold(e))&&(this.clickedAvailable=!1)}i&&this.viewport.options.stopPropagation&&t.stopPropagation()}up(t){if(this.viewport.pause||!this.viewport.worldVisible)return;"mouse"===t.data.pointerType&&(this.isMouseDown=!1),"mouse"!==t.data.pointerType&&this.remove(t.data.pointerId);const i=this.viewport.plugins.up(t);this.clickedAvailable&&0===this.count()&&this.last&&(this.viewport.emit("clicked",{event:t,screen:this.last,world:this.viewport.toWorld(this.last),viewport:this}),this.clickedAvailable=!1),i&&this.viewport.options.stopPropagation&&t.stopPropagation()}getPointerPosition(t){const e=new i.Point;return this.viewport.options.interaction?this.viewport.options.interaction.mapPositionToPoint(e,t.clientX,t.clientY):(e.x=t.clientX,e.y=t.clientY),e}handleWheel(t){if(this.viewport.pause||!this.viewport.worldVisible)return;if(this.viewport.options.interaction&&this.viewport.options.interaction.interactionDOMElement!==t.target)return;const i=this.viewport.toLocal(this.getPointerPosition(t));if(this.viewport.left<=i.x&&i.x<=this.viewport.right&&this.viewport.top<=i.y&&i.y<=this.viewport.bottom){this.viewport.plugins.wheel(t)&&!this.viewport.options.passiveWheel&&t.preventDefault()}}pause(){this.touches=[],this.isMouseDown=!1}get(t){for(const i of this.touches)if(i.id===t)return i;return null}remove(t){for(let i=0;i<this.touches.length;i++)if(this.touches[i].id===t)return void this.touches.splice(i,1)}count(){return(this.isMouseDown?1:0)+this.touches.length}}function D(t){let i,e=t[0],s=1;for(;s<t.length;){const n=t[s],h=t[s+1];if(s+=2,("optionalAccess"===n||"optionalCall"===n)&&null==e)return;"access"===n||"optionalAccess"===n?(i=e,e=h(e)):"call"!==n&&"optionalCall"!==n||(e=h(((...t)=>e.call(i,...t))),i=void 0)}return e}const T=["drag","pinch","wheel","follow","mouse-edges","decelerate","animate","bounce","snap-zoom","clamp-zoom","snap","clamp"];class L{constructor(t){this.viewport=t,this.list=[],this.plugins={}}add(t,i,e=T.length){this.plugins[t]=i;const s=T.indexOf(t);-1!==s&&T.splice(s,1),T.splice(e,0,t),this.sort()}get(t,i){return i&&D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.paused])?null:this.plugins[t]}update(t){for(const i of this.list)i.update(t)}resize(){for(const t of this.list)t.resize()}reset(){for(const t of this.list)t.reset()}removeAll(){this.plugins={},this.sort()}remove(t){this.plugins[t]&&(delete this.plugins[t],this.viewport.emit(`${t}-remove`),this.sort())}pause(t){D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.pause,"call",t=>t()])}resume(t){D([this,"access",t=>t.plugins,"access",i=>i[t],"optionalAccess",t=>t.resume,"call",t=>t()])}sort(){this.list=[];for(const t of T)this.plugins[t]&&this.list.push(this.plugins[t])}down(t){let i=!1;for(const e of this.list)e.down(t)&&(i=!0);return i}move(t){let i=!1;for(const e of this.viewport.plugins.list)e.move(t)&&(i=!0);return i}up(t){let i=!1;for(const e of this.list)e.up(t)&&(i=!0);return i}wheel(t){let i=!1;for(const e of this.list)e.wheel(t)&&(i=!0);return i}}const V={screenWidth:window.innerWidth,screenHeight:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,interaction:null,disableOnContextMenu:!1,ticker:n.Ticker.shared};class j extends s.Container{__init(){this._disableOnContextMenu=t=>t.preventDefault()}constructor(t={}){super(),j.prototype.__init.call(this),this.options=Object.assign({},{divWheel:document.body},V,t),this.screenWidth=this.options.screenWidth,this.screenHeight=this.options.screenHeight,this._worldWidth=this.options.worldWidth,this._worldHeight=this.options.worldHeight,this.forceHitArea=this.options.forceHitArea,this.threshold=this.options.threshold,this.options.divWheel=this.options.divWheel||document.body,this.options.disableOnContextMenu&&this.options.divWheel.addEventListener("contextmenu",this._disableOnContextMenu),this.options.noTicker||(this.tickerFunction=()=>this.update(this.options.ticker.elapsedMS),this.options.ticker.add(this.tickerFunction)),this.input=new I(this),this.plugins=new L(this)}destroy(t){!this.options.noTicker&&this.tickerFunction&&this.options.ticker.remove(this.tickerFunction),this.options.disableOnContextMenu&&this.options.divWheel.removeEventListener("contextmenu",this._disableOnContextMenu),this.input.destroy(),super.destroy(t)}update(t){this.pause||(this.plugins.update(t),this.lastViewport&&(this.lastViewport.x!==this.x||this.lastViewport.y!==this.y?this.moving=!0:this.moving&&(this.emit("moved-end",this),this.moving=!1),this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y?this.zooming=!0:this.zooming&&(this.emit("zoomed-end",this),this.zooming=!1)),this.forceHitArea||(this._hitAreaDefault=new i.Rectangle(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight),this.hitArea=this._hitAreaDefault),this._dirty=this._dirty||!this.lastViewport||this.lastViewport.x!==this.x||this.lastViewport.y!==this.y||this.lastViewport.scaleX!==this.scale.x||this.lastViewport.scaleY!==this.scale.y,this.lastViewport={x:this.x,y:this.y,scaleX:this.scale.x,scaleY:this.scale.y},this.emit("frame-end",this))}resize(t=window.innerWidth,i=window.innerHeight,e,s){this.screenWidth=t,this.screenHeight=i,void 0!==e&&(this._worldWidth=e),void 0!==s&&(this._worldHeight=s),this.plugins.resize(),this.dirty=!0}get worldWidth(){return this._worldWidth?this._worldWidth:this.width/this.scale.x}set worldWidth(t){this._worldWidth=t,this.plugins.resize()}get worldHeight(){return this._worldHeight?this._worldHeight:this.height/this.scale.y}set worldHeight(t){this._worldHeight=t,this.plugins.resize()}getVisibleBounds(){return new i.Rectangle(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return 2===arguments.length?this.toLocal(new i.Point(t,e)):this.toLocal(t)}toScreen(t,e){return 2===arguments.length?this.toGlobal(new i.Point(t,e)):this.toGlobal(t)}get worldScreenWidth(){return this.screenWidth/this.scale.x}get worldScreenHeight(){return this.screenHeight/this.scale.y}get screenWorldWidth(){return this.worldWidth*this.scale.x}get screenWorldHeight(){return this.worldHeight*this.scale.y}get center(){return new i.Point(this.worldScreenWidth/2-this.x/this.scale.x,this.worldScreenHeight/2-this.y/this.scale.y)}set center(t){this.moveCenter(t)}moveCenter(...t){let i,e;"number"==typeof t[0]?(i=t[0],e=t[1]):(i=t[0].x,e=t[0].y);const s=(this.worldScreenWidth/2-i)*this.scale.x,n=(this.worldScreenHeight/2-e)*this.scale.y;return this.x===s&&this.y===n||(this.position.set(s,n),this.plugins.reset(),this.dirty=!0),this}get corner(){return new i.Point(-this.x/this.scale.x,-this.y/this.scale.y)}set corner(t){this.moveCorner(t)}moveCorner(...t){let i,e;return 1===t.length?(i=-t[0].x*this.scale.x,e=-t[0].y*this.scale.y):(i=-t[0]*this.scale.x,e=-t[1]*this.scale.y),i===this.x&&e===this.y||(this.position.set(i,e),this.plugins.reset(),this.dirty=!0),this}get screenWidthInWorldPixels(){return this.screenWidth/this.scale.x}get screenHeightInWorldPixels(){return this.screenHeight/this.scale.y}findFitWidth(t){return this.screenWidth/t}findFitHeight(t){return this.screenHeight/t}findFit(t,i){const e=this.screenWidth/t,s=this.screenHeight/i;return Math.min(e,s)}findCover(t,i){const e=this.screenWidth/t,s=this.screenHeight/i;return Math.max(e,s)}fitWidth(t=this.worldWidth,i,e=!0,s){let n;i&&(n=this.center),this.scale.x=this.screenWidth/t,e&&(this.scale.y=this.scale.x);const h=this.plugins.get("clamp-zoom",!0);return!s&&h&&h.clamp(),i&&n&&this.moveCenter(n),this}fitHeight(t=this.worldHeight,i,e=!0,s){let n;i&&(n=this.center),this.scale.y=this.screenHeight/t,e&&(this.scale.x=this.scale.y);const h=this.plugins.get("clamp-zoom",!0);return!s&&h&&h.clamp(),i&&n&&this.moveCenter(n),this}fitWorld(t){let i;t&&(i=this.center),this.scale.x=this.screenWidth/this.worldWidth,this.scale.y=this.screenHeight/this.worldHeight,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const e=this.plugins.get("clamp-zoom",!0);return e&&e.clamp(),t&&i&&this.moveCenter(i),this}fit(t,i=this.worldWidth,e=this.worldHeight){let s;t&&(s=this.center),this.scale.x=this.screenWidth/i,this.scale.y=this.screenHeight/e,this.scale.x<this.scale.y?this.scale.y=this.scale.x:this.scale.x=this.scale.y;const n=this.plugins.get("clamp-zoom",!0);return n&&n.clamp(),t&&s&&this.moveCenter(s),this}setZoom(t,i){let e;i&&(e=this.center),this.scale.set(t);const s=this.plugins.get("clamp-zoom",!0);return s&&s.clamp(),i&&e&&this.moveCenter(e),this}zoomPercent(t,i){return this.setZoom(this.scale.x+this.scale.x*t,i)}zoom(t,i){return this.fitWidth(t+this.worldScreenWidth,i),this}get scaled(){return this.scale.x}set scaled(t){this.setZoom(t,!0)}snapZoom(t){return this.plugins.add("snap-zoom",new Y(this,t)),this}OOB(){return{left:this.left<0,right:this.right>this.worldWidth,top:this.top<0,bottom:this.bottom>this.worldHeight,cornerPoint:new i.Point(this.worldWidth*this.scale.x-this.screenWidth,this.worldHeight*this.scale.y-this.screenHeight)}}get right(){return-this.x/this.scale.x+this.worldScreenWidth}set right(t){this.x=-t*this.scale.x+this.screenWidth,this.plugins.reset()}get left(){return-this.x/this.scale.x}set left(t){this.x=-t*this.scale.x,this.plugins.reset()}get top(){return-this.y/this.scale.y}set top(t){this.y=-t*this.scale.y,this.plugins.reset()}get bottom(){return-this.y/this.scale.y+this.worldScreenHeight}set bottom(t){this.y=-t*this.scale.y+this.screenHeight,this.plugins.reset()}get dirty(){return!!this._dirty}set dirty(t){this._dirty=t}get forceHitArea(){return this._forceHitArea}set forceHitArea(t){t?(this._forceHitArea=t,this.hitArea=t):(this._forceHitArea=null,this.hitArea=new i.Rectangle(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new b(this,t)),this}clamp(t){return this.plugins.add("clamp",new g(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new v(this,t)),this}bounce(t){return this.plugins.add("bounce",new u(this,t)),this}pinch(t){return this.plugins.add("pinch",new k(this,t)),this}snap(t,i,e){return this.plugins.add("snap",new _(this,t,i,e)),this}follow(t,i){return this.plugins.add("follow",new S(this,t,i)),this}wheel(t){return this.plugins.add("wheel",new A(this,t)),this}animate(t){return this.plugins.add("animate",new l(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new y(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new C(this,t)),this}get pause(){return!!this._pause}set pause(t){this._pause=t,this.lastViewport=null,this.moving=!1,this.zooming=!1,t&&this.input.pause()}ensureVisible(t,i,e,s,n){n&&(e>this.worldScreenWidth||s>this.worldScreenHeight)&&(this.fit(!0,e,s),this.emit("zoomed",{viewport:this,type:"ensureVisible"}));let h=!1;t<this.left?(this.left=t,h=!0):t+e>this.right&&(this.right=t+e,h=!0),i<this.top?(this.top=i,h=!0):i+s>this.bottom&&(this.bottom=i+s,h=!0),h&&this.emit("moved",{viewport:this,type:"ensureVisible"})}}t.Animate=l,t.Bounce=u,t.Clamp=g,t.ClampZoom=y,t.Decelerate=v,t.Drag=b,t.Follow=S,t.InputManager=I,t.MouseEdges=C,t.Pinch=k,t.Plugin=r,t.PluginManager=L,t.Snap=_,t.SnapZoom=Y,t.Viewport=j,t.Wheel=A,Object.defineProperty(t,"__esModule",{value:!0})})),"undefined"!=typeof pixi_viewport&&Object.assign(this.PIXI,pixi_viewport); | ||
//# sourceMappingURL=viewport.min.min.js.map |
@@ -349,2 +349,3 @@ import { Container } from '@pixi/display'; | ||
axis?: 'all' | 'x' | 'y'; | ||
keyToPress?: string[] | null; | ||
trackpadPinch?: boolean; | ||
@@ -583,3 +584,6 @@ wheelZoom?: boolean; | ||
protected smoothingCount?: number; | ||
protected keyIsPressed: boolean; | ||
constructor(parent: Viewport, options?: IWheelOptions); | ||
protected handleKeyPresses(codes: string[]): void; | ||
protected checkKeyPress(): boolean; | ||
down(): boolean; | ||
@@ -586,0 +590,0 @@ protected isAxisX(): boolean; |
{ | ||
"name": "pixi-viewport", | ||
"version": "4.32.0", | ||
"version": "4.33.0", | ||
"description": "A highly configurable viewport/2D camera designed to work with pixi.js. Features include dragging, pinch-to-zoom, mouse wheel zooming, decelerated dragging, follow target, snap to point, snap to zoom, clamping, bouncing on edges, and move on mouse edges.", | ||
@@ -94,3 +94,3 @@ "main": "dist/cjs/viewport.js", | ||
"pixi-ease": "^3.0.7", | ||
"pixi.js": "^6.0.0", | ||
"pixi.js": "^6.1.2", | ||
"raf": "^3.4.1", | ||
@@ -97,0 +97,0 @@ "rollup": "^2.47.0", |
@@ -74,3 +74,3 @@ import { Point, Rectangle } from '@pixi/math'; | ||
*/ | ||
public down(event: InteractionEvent) | ||
public down(event: InteractionEvent): void | ||
{ | ||
@@ -77,0 +77,0 @@ if (this.viewport.pause || !this.viewport.worldVisible) |
@@ -59,2 +59,10 @@ import { Plugin } from './Plugin'; | ||
/** | ||
* Array containing {@link key|https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code} codes of | ||
* keys that can be pressed for the zoom to be triggered, e.g.: ['ShiftLeft', 'ShiftRight'}. | ||
* | ||
* @default null | ||
*/ | ||
keyToPress?: string[] | null; | ||
/** | ||
* pinch the trackpad to zoom | ||
@@ -78,2 +86,3 @@ */ | ||
axis: 'all', | ||
keyToPress: null, | ||
trackpadPinch: false, | ||
@@ -96,2 +105,5 @@ wheelZoom: true, | ||
/** Flags whether the keys required to zoom are pressed currently. */ | ||
protected keyIsPressed: boolean; | ||
/** | ||
@@ -104,4 +116,39 @@ * This is called by {@link Viewport.wheel}. | ||
this.options = Object.assign({}, DEFAULT_WHEEL_OPTIONS, options); | ||
this.keyIsPressed = false; | ||
if (this.options.keyToPress) | ||
{ | ||
this.handleKeyPresses(this.options.keyToPress); | ||
} | ||
} | ||
/** | ||
* Handles keypress events and set the keyIsPressed boolean accordingly | ||
* | ||
* @param {array} codes - key codes that can be used to trigger zoom event | ||
*/ | ||
protected handleKeyPresses(codes: string[]): void | ||
{ | ||
window.addEventListener('keydown', (e) => | ||
{ | ||
if (codes.includes(e.code)) | ||
{ | ||
this.keyIsPressed = true; | ||
} | ||
}); | ||
window.addEventListener('keyup', (e) => | ||
{ | ||
if (codes.includes(e.code)) | ||
{ | ||
this.keyIsPressed = false; | ||
} | ||
}); | ||
} | ||
protected checkKeyPress(): boolean | ||
{ | ||
return !this.options.keyToPress || this.keyIsPressed; | ||
} | ||
public down(): boolean | ||
@@ -170,3 +217,3 @@ { | ||
if (this.smoothingCount as number >= this.options.smooth) | ||
if ((this.smoothingCount as number) >= this.options.smooth) | ||
{ | ||
@@ -180,2 +227,7 @@ this.smoothing = null; | ||
{ | ||
if (this.paused) | ||
{ | ||
return; | ||
} | ||
const point = this.parent.input.getPointerPosition(e); | ||
@@ -229,2 +281,7 @@ const step = -e.deltaY * (e.deltaMode ? this.options.lineHeight : 1) / 200; | ||
if (!this.checkKeyPress()) | ||
{ | ||
return false; | ||
} | ||
if (e.ctrlKey && this.options.trackpadPinch) | ||
@@ -231,0 +288,0 @@ { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1435305
18186