(function(u,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("pixi.js")):typeof define=="function"&&define.amd?define(["exports","pixi.js"],c):(u=typeof globalThis<"u"?globalThis:u||self,c(u.pixi_viewport={},u.pixi_js))})(this,function(u,c){"use strict";class d{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}}var E=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function D(l){return l&&l.__esModule&&Object.prototype.hasOwnProperty.call(l,"default")?l.default:l}var v={exports:{}};(function(l,t){(function(){var e,n;n=function(i){return l.exports=i},e={linear:function(i,s,h,o){return h*i/o+s},easeInQuad:function(i,s,h,o){return h*(i/=o)*i+s},easeOutQuad:function(i,s,h,o){return-h*(i/=o)*(i-2)+s},easeInOutQuad:function(i,s,h,o){return(i/=o/2)<1?h/2*i*i+s:-h/2*(--i*(i-2)-1)+s},easeInCubic:function(i,s,h,o){return h*(i/=o)*i*i+s},easeOutCubic:function(i,s,h,o){return h*((i=i/o-1)*i*i+1)+s},easeInOutCubic:function(i,s,h,o){return(i/=o/2)<1?h/2*i*i*i+s:h/2*((i-=2)*i*i+2)+s},easeInQuart:function(i,s,h,o){return h*(i/=o)*i*i*i+s},easeOutQuart:function(i,s,h,o){return-h*((i=i/o-1)*i*i*i-1)+s},easeInOutQuart:function(i,s,h,o){return(i/=o/2)<1?h/2*i*i*i*i+s:-h/2*((i-=2)*i*i*i-2)+s},easeInQuint:function(i,s,h,o){return h*(i/=o)*i*i*i*i+s},easeOutQuint:function(i,s,h,o){return h*((i=i/o-1)*i*i*i*i+1)+s},easeInOutQuint:function(i,s,h,o){return(i/=o/2)<1?h/2*i*i*i*i*i+s:h/2*((i-=2)*i*i*i*i+2)+s},easeInSine:function(i,s,h,o){return-h*Math.cos(i/o*(Math.PI/2))+h+s},easeOutSine:function(i,s,h,o){return h*Math.sin(i/o*(Math.PI/2))+s},easeInOutSine:function(i,s,h,o){return-h/2*(Math.cos(Math.PI*i/o)-1)+s},easeInExpo:function(i,s,h,o){return i===0?s:h*Math.pow(2,10*(i/o-1))+s},easeOutExpo:function(i,s,h,o){return i===o?s+h:h*(-Math.pow(2,-10*i/o)+1)+s},easeInOutExpo:function(i,s,h,o){return(i/=o/2)<1?h/2*Math.pow(2,10*(i-1))+s:h/2*(-Math.pow(2,-10*--i)+2)+s},easeInCirc:function(i,s,h,o){return-h*(Math.sqrt(1-(i/=o)*i)-1)+s},easeOutCirc:function(i,s,h,o){return h*Math.sqrt(1-(i=i/o-1)*i)+s},easeInOutCirc:function(i,s,h,o){return(i/=o/2)<1?-h/2*(Math.sqrt(1-i*i)-1)+s:h/2*(Math.sqrt(1-(i-=2)*i)+1)+s},easeInElastic:function(i,s,h,o){var r,a,p;return p=1.70158,a=0,r=h,i===0||(i/=o),a||(a=o*.3),r=this.options.time){const n=this.parent.width,i=this.parent.height;this.complete(),(n!==this.parent.width||i!==this.parent.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}else{const n=this.options.ease(this.time,0,1,this.options.time);if(this.width!==null){const i=this.startWidth,s=this.deltaWidth;this.parent.fitWidth(i+s*n,this.keepCenter,this.height===null)}if(this.height!==null){const i=this.startHeight,s=this.deltaHeight;this.parent.fitHeight(i+s*n,this.keepCenter,this.width===null)}if(this.width===null?this.parent.scale.x=this.parent.scale.y:this.height===null&&(this.parent.scale.y=this.parent.scale.x),!this.keepCenter){const i=this.startX,s=this.startY,h=this.deltaX,o=this.deltaY,r=new c.Point(this.parent.x,this.parent.y);this.parent.moveCenter(i+h*n,s+o*n),this.parent.emit("moved",{viewport:this.parent,original:r,type:"animate"})}(this.width||this.height)&&this.parent.emit("zoomed",{viewport:this.parent,original:e,type:"animate"})}}}const U={sides:"all",friction:.5,time:150,ease:"easeInOutSine",underflow:"center",bounceBox:null};class H extends d{constructor(t,e={}){super(t),this.options=Object.assign({},U,e),this.ease=w(this.options.ease,"easeInOutSine"),this.options.sides?this.options.sides==="all"?this.top=this.bottom=this.left=this.right=!0:this.options.sides==="horizontal"?(this.right=this.left=!0,this.top=this.bottom=!1):this.options.sides==="vertical"?(this.left=this.right=!1,this.top=this.bottom=!0):(this.top=this.options.sides.indexOf("top")!==-1,this.bottom=this.options.sides.indexOf("bottom")!==-1,this.left=this.options.sides.indexOf("left")!==-1,this.right=this.options.sides.indexOf("right")!==-1):this.left=this.top=this.right=this.bottom=!1;const n=this.options.underflow.toLowerCase();n==="center"?(this.underflowX=0,this.underflowY=0):(this.underflowX=n.indexOf("left")!==-1?-1:n.indexOf("right")!==-1?1:0,this.underflowY=n.indexOf("top")!==-1?-1:n.indexOf("bottom")!==-1?1:0),this.reset()}isActive(){return this.toX!==null||this.toY!==null}async down(){return this.toX=this.toY=null,!1}up(){return this.bounce(),!1}update(t){if(!this.paused){if(this.bounce(),this.toX){const e=this.toX;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-x"}),e.time>=this.options.time?(this.parent.x=e.end,this.toX=null,this.parent.emit("bounce-x-end",this.parent)):this.parent.x=this.ease(e.time,e.start,e.delta,this.options.time)}if(this.toY){const e=this.toY;e.time+=t,this.parent.emit("moved",{viewport:this.parent,type:"bounce-y"}),e.time>=this.options.time?(this.parent.y=e.end,this.toY=null,this.parent.emit("bounce-y-end",this.parent)):this.parent.y=this.ease(e.time,e.start,e.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=typeof t.x>"u"?0:t.x,n=typeof t.y>"u"?0:t.y,i=typeof t.width>"u"?this.parent.worldWidth:t.width,s=typeof t.height>"u"?this.parent.worldHeight:t.height;return{left:this.parent.lefti,top:this.parent.tops,topLeft:new c.Point(e*this.parent.scale.x,n*this.parent.scale.y),bottomRight:new c.Point(i*this.parent.scale.x-this.parent.screenWidth,s*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 c.Point(0,0),bottomRight:new c.Point(this.parent.worldWidth*this.parent.scale.x-this.parent.screenWidth,this.parent.worldHeight*this.parent.scale.y-this.parent.screenHeight)}}bounce(){var s,h;if(this.paused)return;let t,e=this.parent.plugins.get("decelerate",!0);e&&(e.x||e.y)&&(e.x&&e.percentChangeX===((s=e.options)==null?void 0:s.friction)||e.y&&e.percentChangeY===((h=e.options)==null?void 0:h.friction))&&(t=this.oob(),(t.left&&this.left||t.right&&this.right)&&(e.percentChangeX=this.options.friction),(t.top&&this.top||t.bottom&&this.bottom)&&(e.percentChangeY=this.options.friction));const n=this.parent.plugins.get("drag",!0)||{},i=this.parent.plugins.get("pinch",!0)||{};if(e=e||{},!(n!=null&&n.active)&&!(i!=null&&i.active)&&(!this.toX||!this.toY)&&(!e.x||!e.y)){t=t||this.oob();const o=t.topLeft,r=t.bottomRight;if(!this.toX&&!e.x){let a=null;t.left&&this.left?a=this.parent.screenWorldWidth(this.options.right===!0?this.parent.worldWidth:this.options.right)&&(this.parent.x=-(this.options.right===!0?this.parent.worldWidth:this.options.right)*this.parent.scale.x+this.parent.screenWidth,e.x=0,n=!0);n&&this.parent.emit("moved",{viewport:this.parent,original:t,type:"clamp-x"})}if(this.options.top!==null||this.options.bottom!==null){let n=!1;if(!this.noUnderflow&&this.parent.screenWorldHeight(this.options.bottom===!0?this.parent.worldHeight:this.options.bottom)&&(this.parent.y=-(this.options.bottom===!0?this.parent.worldHeight:this.options.bottom)*this.parent.scale.y+this.parent.screenHeight,e.y=0,n=!0);n&&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 B={minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,minScale:null,maxScale:null};class M extends d{constructor(t,e={}){super(t),this.options=Object.assign({},B,e),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,e=this.parent.worldScreenHeight;if(this.options.minWidth!==null&&tthis.options.maxWidth){const n=this.parent.scale.x;this.parent.fitWidth(this.options.maxWidth,!1,!1,!0),this.parent.scale.y*=this.parent.scale.x/n,t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}if(this.options.minHeight!==null&&ethis.options.maxHeight){const n=this.parent.scale.y;this.parent.fitHeight(this.options.maxHeight,!1,!1,!0),this.parent.scale.x*=this.parent.scale.y/n,this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"})}}else if(this.options.minScale||this.options.maxScale){const t={x:null,y:null},e={x:null,y:null};if(typeof this.options.minScale=="number")t.x=this.options.minScale,t.y=this.options.minScale;else if(this.options.minScale!==null){const s=this.options.minScale;t.x=typeof s.x>"u"?null:s.x,t.y=typeof s.y>"u"?null:s.y}if(typeof this.options.maxScale=="number")e.x=this.options.maxScale,e.y=this.options.maxScale;else if(this.options.maxScale!==null){const s=this.options.maxScale;e.x=typeof s.x>"u"?null:s.x,e.y=typeof s.y>"u"?null:s.y}let n=this.parent.scale.x,i=this.parent.scale.y;t.x!==null&&ne.x&&(n=e.x),t.y!==null&&ie.y&&(i=e.y),(n!==this.parent.scale.x||i!==this.parent.scale.y)&&(this.parent.scale.set(n,i),this.parent.emit("zoomed",{viewport:this.parent,type:"clamp-zoom"}))}}}reset(){this.clamp()}}const V={friction:.98,bounce:.8,minSpeed:.01},f=16;class P extends d{constructor(t,e={}){super(t),this.options=Object.assign({},V,e),this.saved=[],this.timeSinceRelease=0,this.reset(),this.parent.on("moved",n=>this.handleMoved(n))}async 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(t===1||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}handleMoved(t){if(this.saved.length){const e=this.saved[this.saved.length-1];t.type==="clamp-x"&&t.original?e.x===t.original.x&&(e.x=this.parent.x):t.type==="clamp-y"&&t.original&&e.y===t.original.y&&(e.y=this.parent.y)}}up(){if(this.parent.input.count()===0&&this.saved.length){const t=performance.now();for(const e of this.saved)if(e.time>=t-100){const n=t-e.time;this.x=(this.parent.x-e.x)/n,this.y=(this.parent.y-e.y)/n,this.percentChangeX=this.percentChangeY=this.options.friction,this.timeSinceRelease=0;break}}return!1}activate(t){t=t||{},typeof t.x<"u"&&(this.x=t.x,this.percentChangeX=this.options.friction),typeof t.y<"u"&&(this.y=t.y,this.percentChangeY=this.options.friction)}update(t){if(this.paused)return;const e=this.x||this.y,n=this.timeSinceRelease,i=this.timeSinceRelease+t;if(this.x){const s=this.percentChangeX,h=Math.log(s);this.parent.x+=this.x*f/h*(Math.pow(s,i/f)-Math.pow(s,n/f)),this.x*=Math.pow(this.percentChangeX,t/f)}if(this.y){const s=this.percentChangeY,h=Math.log(s);this.parent.y+=this.y*f/h*(Math.pow(s,i/f)-Math.pow(s,n/f)),this.y*=Math.pow(this.percentChangeY,t/f)}this.timeSinceRelease+=t,this.x&&this.y?Math.abs(this.x){t.includes(i.code)&&(this.keyIsPressed=!0)},n=i=>{t.includes(i.code)&&(this.keyIsPressed=!1)};this.addWindowEventHandler("keyup",n),this.addWindowEventHandler("keydown",e)}addWindowEventHandler(t,e){typeof window>"u"||(window.addEventListener(t,e),this.windowEventHandlers.push({event:t,handler:e}))}destroy(){typeof window>"u"||this.windowEventHandlers.forEach(({event:t,handler:e})=>{window.removeEventListener(t,e)})}mouseButtons(t){!t||t==="all"?this.mouse=[!0,!0,!0]:this.mouse=[t.indexOf("left")!==-1,t.indexOf("middle")!==-1,t.indexOf("right")!==-1]}parseUnderflow(){const t=this.options.underflow.toLowerCase();t==="center"?(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 e=t.pointerType==="mouse",n=this.parent.input.count();return!!((n===1||n>1&&!this.parent.plugins.get("pinch",!0))&&(!e||this.mouse[t.button]))}checkKeyPress(t){return!this.options.keyToPress||this.keyIsPressed||this.options.ignoreKeyToPressOnTouch&&t.data.pointerType==="touch"}async down(t){return this.paused||!this.options.pressDrag?!1:this.checkButtons(t)&&this.checkKeyPress(t)?(this.last={x:t.global.x,y:t.global.y},this.current=t.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.global.x,n=t.global.y,i=this.parent.input.count();if(i===1||i>1&&!this.parent.plugins.get("pinch",!0)){const s=e-this.last.x,h=n-this.last.y;if(this.moved||this.xDirection&&this.parent.input.checkThreshold(s)||this.yDirection&&this.parent.input.checkThreshold(h)){const o={x:e,y:n};return this.xDirection&&(this.parent.x+=(o.x-this.last.x)*this.options.factor),this.yDirection&&(this.parent.y+=(o.y-this.last.y)*this.options.factor),this.last=o,this.moved||this.parent.emit("drag-start",{event:t,screen:new c.Point(this.last.x,this.last.y),world:this.parent.toWorld(new c.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(e.length===1){const n=e[0];return n.last&&(this.last={x:n.last.x,y:n.last.y},this.current=n.id),this.moved=!1,!0}else if(this.last&&this.moved){const n=new c.Point(this.last.x,this.last.y);return this.parent.emit("drag-end",{event:t,screen:n,world:this.parent.toWorld(n),viewport:this.parent}),this.last=null,this.moved=!1,!0}return!1}wheel(t){if(this.paused)return!1;if(this.options.wheel){const e=this.parent.plugins.get("wheel",!0);if(!e||!e.options.wheelZoom&&!t.ctrlKey){const n=t.deltaMode?this.options.lineHeight:1,i=[t.deltaX,t.deltaY],[s,h]=this.options.wheelSwapAxes?i.reverse():i;return this.xDirection&&(this.parent.x+=s*n*this.options.wheelScroll*this.reverse),this.yDirection&&(this.parent.y+=h*n*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(this.options.clampWheel!=="y")if(this.parent.screenWorldWidththis.parent.worldWidth&&(this.parent.x=-this.parent.worldWidth*this.parent.scale.x+this.parent.screenWidth,t.x=0);if(this.options.clampWheel!=="x")if(this.parent.screenWorldHeightthis.parent.worldHeight&&(this.parent.y=-this.parent.worldHeight*this.parent.scale.y+this.parent.screenHeight,t.y=0)}}const N={speed:0,acceleration:null,radius:null};class C extends d{constructor(t,e,n={}){super(t),this.target=e,this.options=Object.assign({},N,n),this.velocity={x:0,y:0}}update(t){if(this.paused)return;const e=this.parent.center;let n=this.target.x,i=this.target.y;if(this.options.radius)if(Math.sqrt(Math.pow(this.target.y-e.y,2)+Math.pow(this.target.x-e.x,2))>this.options.radius){const r=Math.atan2(this.target.y-e.y,this.target.x-e.x);n=this.target.x-Math.cos(r)*this.options.radius,i=this.target.y-Math.sin(r)*this.options.radius}else return;const s=n-e.x,h=i-e.y;if(s||h)if(this.options.speed)if(this.options.acceleration){const o=Math.atan2(i-e.y,n-e.x),r=Math.sqrt(Math.pow(s,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);r>a?this.velocity={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))}:this.velocity={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,g=Math.sin(o)*this.velocity.y,y=Math.abs(p)>Math.abs(s)?n:e.x+p,x=Math.abs(g)>Math.abs(h)?i:e.y+g;this.parent.moveCenter(y,x),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}else{const o=Math.atan2(i-e.y,n-e.x),r=Math.cos(o)*this.options.speed,a=Math.sin(o)*this.options.speed,p=Math.abs(r)>Math.abs(s)?n:e.x+r,g=Math.abs(a)>Math.abs(h)?i:e.y+a;this.parent.moveCenter(p,g),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}else this.parent.moveCenter(n,i),this.parent.emit("moved",{viewport:this.parent,type:"follow"})}}const R={radius:null,distance:null,top:null,bottom:null,left:null,right:null,speed:8,reverse:!1,noDecelerate:!1,linear:!1,allowButtons:!1};class I extends d{constructor(t,e={}){super(t),this.options=Object.assign({},R,e),this.reverse=this.options.reverse?1:-1,this.radiusSquared=typeof this.options.radius=="number"?Math.pow(this.options.radius,2):null,this.resize()}resize(){const t=this.options.distance;t!==null?(this.left=t,this.top=t,this.right=this.parent.screenWidth-t,this.bottom=this.parent.screenHeight-t):this.options.radius||(this.left=this.options.left,this.top=this.options.top,this.right=this.options.right===null?null:this.parent.screenWidth-this.options.right,this.bottom=this.options.bottom===null?null:this.parent.screenHeight-this.options.bottom)}async down(){return this.paused||this.options.allowButtons||(this.horizontal=this.vertical=null),!1}move(t){if(this.paused||t.pointerType!=="mouse"&&t.pointerId!==1||!this.options.allowButtons&&t.buttons!==0)return!1;const e=t.global.x,n=t.global.y;if(this.radiusSquared){const i=this.parent.toScreen(this.parent.center);if(Math.pow(i.x-e,2)+Math.pow(i.y-n,2)>=this.radiusSquared){const h=Math.atan2(i.y-n,i.x-e);this.options.linear?(this.horizontal=Math.round(Math.cos(h))*this.options.speed*this.reverse*(60/1e3),this.vertical=Math.round(Math.sin(h))*this.options.speed*this.reverse*(60/1e3)):(this.horizontal=Math.cos(h)*this.options.speed*this.reverse*(60/1e3),this.vertical=Math.sin(h)*this.options.speed*this.reverse*(60/1e3))}else this.horizontal&&this.decelerateHorizontal(),this.vertical&&this.decelerateVertical(),this.horizontal=this.vertical=0}else this.left!==null&&ethis.right?this.horizontal=-1*this.reverse*this.options.speed*(60/1e3):(this.decelerateHorizontal(),this.horizontal=0),this.top!==null&&nthis.bottom?this.vertical=-1*this.reverse*this.options.speed*(60/1e3):(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 q={noDrag:!1,percent:1,center:null,factor:1,axis:"all"};class k extends d{constructor(t,e={}){super(t),this.active=!1,this.pinching=!1,this.moved=!1,this.options=Object.assign({},q,e)}async down(){return this.parent.input.count()>=2?(this.active=!0,!0):!1}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 e=t.global.x,n=t.global.y,i=this.parent.input.touches;if(i.length>=2){const s=i[0],h=i[1],o=s.last&&h.last?Math.sqrt(Math.pow(h.last.x-s.last.x,2)+Math.pow(h.last.y-s.last.y,2)):null;if(s.id===t.pointerId?s.last={x:e,y:n,data:t}:h.id===t.pointerId&&(h.last={x:e,y:n,data:t}),o){let r;const a=new c.Point(s.last.x+(h.last.x-s.last.x)/2,s.last.y+(h.last.y-s.last.y)/2);this.options.center||(r=this.parent.toLocal(a));let p=Math.sqrt(Math.pow(h.last.x-s.last.x,2)+Math.pow(h.last.y-s.last.y,2));p=p===0?p=1e-10:p;const g=(1-o/p)*this.options.percent*(this.isAxisX()?this.parent.scale.x:this.parent.scale.y);this.isAxisX()&&(this.parent.scale.x+=g),this.isAxisY()&&(this.parent.scale.y+=g),this.parent.emit("zoomed",{viewport:this.parent,type:"pinch",center:a});const y=this.parent.plugins.get("clamp-zoom",!0);if(y&&y.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const x=this.parent.toGlobal(r);this.parent.x+=(a.x-x.x)*this.options.factor,this.parent.y+=(a.y-x.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})}!this.options.noDrag&&this.lastCenter&&(this.parent.x+=(a.x-this.lastCenter.x)*this.options.factor,this.parent.y+=(a.y-this.lastCenter.y)*this.options.factor,this.parent.emit("moved",{viewport:this.parent,type:"pinch"})),this.lastCenter=a,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):!1}}const K={topLeft:!1,friction:.8,time:1e3,ease:"easeInOutSine",interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1};class Y extends d{constructor(t,e,n,i={}){super(t),this.options=Object.assign({},K,i),this.ease=w(i.ease,"easeInOutSine"),this.x=e,this.y=n,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}async down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap"):this.options.interrupt&&(this.snapping=null),!1}up(){if(this.parent.input.count()===0){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&&this.parent.input.count()!==0))if(this.snapping){const e=this.snapping;e.time+=t;let n,i,s;const h=this.startX,o=this.startY,r=this.deltaX,a=this.deltaY;if(e.time>this.options.time)n=!0,i=h+r,s=o+a;else{const p=this.ease(e.time,0,1,this.options.time);i=h+r*p,s=o+a*p}this.options.topLeft?this.parent.moveCorner(i,s):this.parent.moveCenter(i,s),this.parent.emit("moved",{viewport:this.parent,type:"snap"}),n&&(this.options.removeOnComplete&&this.parent.plugins.remove("snap"),this.parent.emit("snap-end",this.parent),this.snapping=null)}else{const e=this.options.topLeft?this.parent.corner:this.parent.center;(e.x!==this.x||e.y!==this.y)&&this.snapStart()}}}const G={width:0,height:0,time:1e3,ease:"easeInOutSine",center:null,interrupt:!0,removeOnComplete:!1,removeOnInterrupt:!1,forceStart:!1,noMove:!1};class X extends d{constructor(t,e={}){super(t),this.options=Object.assign({},G,e),this.ease=w(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,this.options.time===0?(t.container.scale.x=this.xScale,t.container.scale.y=this.yScale,this.options.removeOnComplete&&this.parent.plugins.remove("snap-zoom")):e.forceStart&&this.createSnapping()}createSnapping(){const t=this.parent.worldScreenWidth,e=this.parent.worldScreenHeight,n=this.parent.screenWidth/this.xScale,i=this.parent.screenHeight/this.yScale;this.snapping={time:0,startX:t,startY:e,deltaX:n-t,deltaY:i-e},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}async down(){return this.options.removeOnInterrupt?this.parent.plugins.remove("snap-zoom"):this.options.interrupt&&(this.snapping=null),!1}update(t){if(this.paused||this.options.interrupt&&this.parent.input.count()!==0)return;let e;if(!this.options.center&&!this.options.noMove&&(e=this.parent.center),!this.snapping)(this.parent.scale.x!==this.xScale||this.parent.scale.y!==this.yScale)&&this.createSnapping();else if(this.snapping){const n=this.snapping;if(n.time+=t,n.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 s=this.snapping,h=this.ease(s.time,s.startX,s.deltaX,this.options.time),o=this.ease(s.time,s.startY,s.deltaY,this.options.time);this.parent.scale.x=this.parent.screenWidth/h,this.parent.scale.y=this.parent.screenHeight/o}const i=this.parent.plugins.get("clamp-zoom",!0);i&&i.clamp(),this.options.noMove||(this.options.center?this.parent.moveCenter(this.options.center):this.parent.moveCenter(e))}}resume(){this.snapping=null,super.resume()}}const Q={percent:.1,smooth:!1,interrupt:!0,reverse:!1,center:null,lineHeight:20,axis:"all",keyToPress:null,trackpadPinch:!1,wheelZoom:!0};class z extends d{constructor(t,e={}){super(t),this.options=Object.assign({},Q,e),this.keyIsPressed=!1,this.options.keyToPress&&this.handleKeyPresses(this.options.keyToPress)}handleKeyPresses(t){typeof window>"u"||(window.addEventListener("keydown",e=>{t.includes(e.code)&&(this.keyIsPressed=!0)}),window.addEventListener("keyup",e=>{t.includes(e.code)&&(this.keyIsPressed=!1)}))}checkKeyPress(){return!this.options.keyToPress||this.keyIsPressed}async 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,e=this.smoothing;let n;this.options.center||(n=this.parent.toLocal(t)),this.isAxisX()&&(this.parent.scale.x+=e.x),this.isAxisY()&&(this.parent.scale.y+=e.y),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const i=this.parent.plugins.get("clamp-zoom",!0);if(i&&i.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const s=this.parent.toGlobal(n);this.parent.x+=t.x-s.x,this.parent.y+=t.y-s.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 e=this.parent.input.getPointerPosition(t),n=-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/200,i=Math.pow(2,(1+this.options.percent)*n);let s;this.options.center||(s=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=i),this.isAxisY()&&(this.parent.scale.y*=i),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 o=this.parent.toGlobal(s);this.parent.x+=e.x-o.x,this.parent.y+=e.y-o.y}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}wheel(t){if(this.paused||!this.checkKeyPress())return!1;if(t.ctrlKey&&this.options.trackpadPinch)this.pinch(t);else if(this.options.wheelZoom){const e=this.parent.input.getPointerPosition(t),i=(this.options.reverse?-1:1)*-t.deltaY*(t.deltaMode?this.options.lineHeight:1)/500,s=Math.pow(2,(1+this.options.percent)*i);if(this.options.smooth){const h={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+h.x)*s-this.parent.scale.x)/this.options.smooth,y:((this.parent.scale.y+h.y)*s-this.parent.scale.y)/this.options.smooth},this.smoothingCount=0,this.smoothingCenter=e}else{let h;this.options.center||(h=this.parent.toLocal(e)),this.isAxisX()&&(this.parent.scale.x*=s),this.isAxisY()&&(this.parent.scale.y*=s),this.parent.emit("zoomed",{viewport:this.parent,type:"wheel"});const o=this.parent.plugins.get("clamp-zoom",!0);if(o&&o.clamp(),this.options.center)this.parent.moveCenter(this.options.center);else{const r=this.parent.toGlobal(h);this.parent.x+=e.x-r.x,this.parent.y+=e.y-r.y}}this.parent.emit("moved",{viewport:this.parent,type:"wheel"}),this.parent.emit("wheel-start",{event:t,viewport:this.parent})}return!this.parent.options.passiveWheel}}class A{constructor(t){this.viewport=t,this.touches=[],this.addListeners()}addListeners(){this.viewport.eventMode="static",this.viewport.forceHitArea||(this.viewport.hitArea=new c.Rectangle(0,0,this.viewport.worldWidth,this.viewport.worldHeight)),this.viewport.on("pointerdown",this.down,this),this.viewport.options.allowPreserveDragOutside?this.viewport.on("globalpointermove",this.move,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.options.allowPreserveDragOutside||this.viewport.on("pointerleave",this.up,this),this.wheelFunction=t=>this.handleWheel(t),this.viewport.options.events.domElement.addEventListener("wheel",this.wheelFunction,{passive:this.viewport.options.passiveWheel}),this.isMouseDown=!1}destroy(){var t;(t=this.viewport.options.events.domElement)==null||t.removeEventListener("wheel",this.wheelFunction)}async down(t){if(this.viewport.pause||!this.viewport.visible)return;if(t.pointerType==="mouse"?this.isMouseDown=!0:this.get(t.pointerId)||this.touches.push({id:t.pointerId,last:null}),this.count()===1){this.last=t.global.clone();const n=this.viewport.plugins.get("decelerate",!0),i=this.viewport.plugins.get("bounce",!0);(!n||!n.isActive())&&(!i||!i.isActive())?this.clickedAvailable=!0:this.clickedAvailable=!1}else this.clickedAvailable=!1;await 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.visible)return;const e=this.viewport.plugins.move(t);if(this.clickedAvailable&&this.last){const n=t.global.x-this.last.x,i=t.global.y-this.last.y;(this.checkThreshold(n)||this.checkThreshold(i))&&(this.clickedAvailable=!1)}e&&this.viewport.options.stopPropagation&&t.stopPropagation()}up(t){if(this.viewport.pause||!this.viewport.visible)return;t.pointerType==="mouse"&&(this.isMouseDown=!1),t.pointerType!=="mouse"&&this.remove(t.pointerId);const e=this.viewport.plugins.up(t);this.clickedAvailable&&this.count()===0&&this.last&&(this.viewport.emit("clicked",{event:t,screen:this.last,world:this.viewport.toWorld(this.last),viewport:this.viewport}),this.clickedAvailable=!1),e&&this.viewport.options.stopPropagation&&t.stopPropagation()}getPointerPosition(t){const e=new c.Point;return this.viewport.options.events.mapPositionToPoint(e,t.clientX,t.clientY),e}handleWheel(t){if(this.viewport.pause||!this.viewport.visible)return;const e=this.viewport.toLocal(this.getPointerPosition(t));this.viewport.left<=e.x&&e.x<=this.viewport.right&&this.viewport.top<=e.y&&e.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 e of this.touches)if(e.id===t)return e;return null}remove(t){for(let e=0;e{t.destroy()}),this.plugins={},this.sort()}remove(t){var e;this.plugins[t]&&((e=this.plugins[t])==null||e.destroy(),delete this.plugins[t],this.viewport.emit("plugin-remove",t),this.sort())}pause(t){var e;(e=this.plugins[t])==null||e.pause()}resume(t){var e;(e=this.plugins[t])==null||e.resume()}sort(){this.list=[];for(const t of m)this.plugins[t]&&this.list.push(this.plugins[t])}async down(t){let e=!1;for(const n of this.list)await n.down(t)&&(e=!0);return e}move(t){let e=!1;for(const n of this.viewport.plugins.list)n.move(t)&&(e=!0);return e}up(t){let e=!1;for(const n of this.list)n.up(t)&&(e=!0);return e}wheel(t){let e=!1;for(const n of this.list)n.wheel(t)&&(e=!0);return e}}const J={screenWidth:typeof window>"u"?0:window.innerWidth,screenHeight:typeof window>"u"?0:window.innerHeight,worldWidth:null,worldHeight:null,threshold:5,passiveWheel:!0,stopPropagation:!1,forceHitArea:null,noTicker:!1,disableOnContextMenu:!1,ticker:c.Ticker.shared,allowPreserveDragOutside:!1};class $ extends c.Container{constructor(t){super(),this._disableOnContextMenu=e=>e.preventDefault(),this.options={...J,...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.disableOnContextMenu&&this.options.events.domElement.addEventListener("contextmenu",this._disableOnContextMenu),this.options.noTicker||(this.tickerFunction=()=>this.update(this.options.ticker.elapsedMS),this.options.ticker.add(this.tickerFunction)),this.input=new A(this),this.plugins=new T(this)}destroy(t){var e;!this.options.noTicker&&this.tickerFunction&&this.options.ticker.remove(this.tickerFunction),this.options.disableOnContextMenu&&((e=this.options.events.domElement)==null||e.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 c.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=typeof window>"u"?0:window.innerWidth,e=typeof window>"u"?0:window.innerHeight,n,i){this.screenWidth=t,this.screenHeight=e,typeof n<"u"&&(this._worldWidth=n),typeof i<"u"&&(this._worldHeight=i),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 c.Rectangle(this.left,this.top,this.worldScreenWidth,this.worldScreenHeight)}toWorld(t,e){return arguments.length===2?this.toLocal(new c.Point(t,e)):this.toLocal(t)}toScreen(t,e){return arguments.length===2?this.toGlobal(new c.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 c.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 e,n;typeof t[0]=="number"?(e=t[0],n=t[1]):(e=t[0].x,n=t[0].y);const i=(this.worldScreenWidth/2-e)*this.scale.x,s=(this.worldScreenHeight/2-n)*this.scale.y;return(this.x!==i||this.y!==s)&&(this.position.set(i,s),this.plugins.reset(),this.dirty=!0),this}get corner(){return new c.Point(-this.x/this.scale.x,-this.y/this.scale.y)}set corner(t){this.moveCorner(t)}moveCorner(...t){let e,n;return t.length===1?(e=-t[0].x*this.scale.x,n=-t[0].y*this.scale.y):(e=-t[0]*this.scale.x,n=-t[1]*this.scale.y),(e!==this.x||n!==this.y)&&(this.position.set(e,n),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,e){const n=this.screenWidth/t,i=this.screenHeight/e;return Math.min(n,i)}findCover(t,e){const n=this.screenWidth/t,i=this.screenHeight/e;return Math.max(n,i)}fitWidth(t=this.worldWidth,e,n=!0,i){let s;e&&(s=this.center),this.scale.x=this.screenWidth/t,n&&(this.scale.y=this.scale.x);const h=this.plugins.get("clamp-zoom",!0);return!i&&h&&h.clamp(),e&&s&&this.moveCenter(s),this}fitHeight(t=this.worldHeight,e,n=!0,i){let s;e&&(s=this.center),this.scale.y=this.screenHeight/t,n&&(this.scale.x=this.scale.y);const h=this.plugins.get("clamp-zoom",!0);return!i&&h&&h.clamp(),e&&s&&this.moveCenter(s),this}fitWorld(t){let e;t&&(e=this.center),this.scale.x=this.screenWidth/this.worldWidth,this.scale.y=this.screenHeight/this.worldHeight,this.scale.xthis.worldWidth,top:this.top<0,bottom:this.bottom>this.worldHeight,cornerPoint:new c.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 c.Rectangle(0,0,this.worldWidth,this.worldHeight))}drag(t){return this.plugins.add("drag",new O(this,t)),this}clamp(t){return this.plugins.add("clamp",new S(this,t)),this}decelerate(t){return this.plugins.add("decelerate",new P(this,t)),this}bounce(t){return this.plugins.add("bounce",new H(this,t)),this}pinch(t){return this.plugins.add("pinch",new k(this,t)),this}snap(t,e,n){return this.plugins.add("snap",new Y(this,t,e,n)),this}follow(t,e){return this.plugins.add("follow",new C(this,t,e)),this}wheel(t){return this.plugins.add("wheel",new z(this,t)),this}animate(t){return this.plugins.add("animate",new b(this,t)),this}clampZoom(t){return this.plugins.add("clamp-zoom",new M(this,t)),this}mouseEdges(t){return this.plugins.add("mouse-edges",new I(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,e,n,i,s){s&&(n>this.worldScreenWidth||i>this.worldScreenHeight)&&(this.fit(!0,n,i),this.emit("zoomed",{viewport:this,type:"ensureVisible"}));let h=!1;tthis.right&&(this.right=t+n,h=!0),ethis.bottom&&(this.bottom=e+i,h=!0),h&&this.emit("moved",{viewport:this,type:"ensureVisible"})}}u.Animate=b,u.Bounce=H,u.Clamp=S,u.ClampZoom=M,u.Decelerate=P,u.Drag=O,u.Follow=C,u.InputManager=A,u.MouseEdges=I,u.Pinch=k,u.Plugin=d,u.PluginManager=T,u.Snap=Y,u.SnapZoom=X,u.Viewport=$,u.Wheel=z,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});