@ray-js/robot-map-sdk 0.0.16-beta.6 → 0.0.16-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -0
- package/dist/index.rjs.js +1 -1
- package/dist-app/assets/index-p0-u2RxE.js +1 -0
- package/dist-app/index.html +1 -1
- package/dist-docs/404.html +2 -2
- package/dist-docs/agents/domain.html +3 -3
- package/dist-docs/agents/issue-tracker.html +3 -3
- package/dist-docs/agents/triage-labels.html +3 -3
- package/dist-docs/assets/{app.ByFtf7S3.js → app.fe7_GzM3.js} +1 -1
- package/dist-docs/assets/chunks/@localSearchIndexroot.DzDjmMRw.js +1 -0
- package/dist-docs/assets/chunks/{BitmapFont.CxzI5juo.js → BitmapFont.Bt2l0bgn.js} +1 -1
- package/dist-docs/assets/chunks/{BufferResource.DHAX0dLK.js → BufferResource.D5JQhxuZ.js} +1 -1
- package/dist-docs/assets/chunks/{CanvasRenderer.D5NS4GmW.js → CanvasRenderer.BrFqgMtf.js} +1 -1
- package/dist-docs/assets/chunks/{RenderTargetSystem.CcMP0blc.js → RenderTargetSystem.C9QurjPY.js} +1 -1
- package/dist-docs/assets/chunks/{VPLocalSearchBox.QeMPtZZ2.js → VPLocalSearchBox.Cg06j_m9.js} +1 -1
- package/dist-docs/assets/chunks/{WebGLRenderer.DjvikWe1.js → WebGLRenderer.B0g4W2sN.js} +1 -1
- package/dist-docs/assets/chunks/{WebGPURenderer.WuGRbgwP.js → WebGPURenderer.DPBWbSBB.js} +1 -1
- package/dist-docs/assets/chunks/{browserAll.BoE1srum.js → browserAll.74_UInap.js} +1 -1
- package/dist-docs/assets/chunks/{index.DF9JqE9W.js → index.DiAoTUAb.js} +4 -4
- package/dist-docs/assets/chunks/theme.BW-xO32x.js +4 -0
- package/dist-docs/assets/chunks/{webworkerAll.C7VOGNTT.js → webworkerAll.BhhkfDFx.js} +1 -1
- package/dist-docs/assets/{guide_getting-started.md.Ciz_rolL.js → guide_getting-started.md.B03id0o2.js} +1 -1
- package/dist-docs/assets/{reference_config.md.B45KsJB6.js → reference_config.md.Dr5HxVZt.js} +11 -3
- package/dist-docs/assets/{reference_config.md.B45KsJB6.lean.js → reference_config.md.Dr5HxVZt.lean.js} +1 -1
- package/dist-docs/guide/advanced-usage.html +3 -3
- package/dist-docs/guide/concepts.html +3 -3
- package/dist-docs/guide/getting-started.html +5 -5
- package/dist-docs/guide/mcp.html +3 -3
- package/dist-docs/hashmap.json +1 -1
- package/dist-docs/index.html +3 -3
- package/dist-docs/plans/2026-03-04-detected-objects-visibility-design.html +3 -3
- package/dist-docs/plans/2026-03-04-show-detected-objects-implementation-plan.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-debug-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-events-console-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-events-console-implementation-plan.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-runtime-controls-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-runtime-controls-implementation-plan.html +3 -3
- package/dist-docs/plans/2026-03-10-testing-rollout-next-steps-plan.html +3 -3
- package/dist-docs/plans/2026-03-11-simulator-logger-dump-implementation-plan.html +3 -3
- package/dist-docs/reference/callbacks.html +3 -3
- package/dist-docs/reference/config.html +14 -6
- package/dist-docs/reference/data.html +3 -3
- package/dist-docs/reference/methods.html +3 -3
- package/dist-docs/reference/runtime.html +3 -3
- package/dist-docs/reference/types.html +3 -3
- package/dist-docs/reference/utils.html +3 -3
- package/dist-docs/simulator/index.html +3 -3
- package/package.json +1 -1
- package/dist-app/assets/index-B1qsN3Md.js +0 -1
- package/dist-docs/assets/chunks/@localSearchIndexroot.CyHa6iJo.js +0 -1
- package/dist-docs/assets/chunks/theme.DjNI0QHl.js +0 -4
- /package/dist-docs/assets/{guide_getting-started.md.Ciz_rolL.lean.js → guide_getting-started.md.B03id0o2.lean.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.
|
|
2
|
-
var Kc=Object.defineProperty;var Qc=(n,t,e)=>t in n?Kc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var f=(n,t,e)=>Qc(n,typeof t!="symbol"?t+"":t,e);import{V as Ae}from"./framework.CBLqO2Q1.js";import{L as xh,u as Sh,m as vh,G as Jc,E as td,d as De,y as ed,Q as id,v as bh,H as sd,R as nd,T as rd,i as br,U as wh,V as od,W as ad,I as hd,X as ld,K as ho,Y as cd,e as dd,w as ud,l as Un,f as pd,a as fd,x as lo,Z as gd,h as md,_ as yd,j as xd,$ as Ch,a0 as Sd,a1 as vd,C as bd,a2 as wd,N as Hn,O as Cd,P as _d,M as co}from"./mapValues.D2X8cRgC.js";import{a as ae,N as qs,i as $e,D as _h,b as uo,M as po,d as Pd,H as Md,e as Td}from"./theme.DjNI0QHl.js";var E=(n=>(n.Application="application",n.WebGLPipes="webgl-pipes",n.WebGLPipesAdaptor="webgl-pipes-adaptor",n.WebGLSystem="webgl-system",n.WebGPUPipes="webgpu-pipes",n.WebGPUPipesAdaptor="webgpu-pipes-adaptor",n.WebGPUSystem="webgpu-system",n.CanvasSystem="canvas-system",n.CanvasPipesAdaptor="canvas-pipes-adaptor",n.CanvasPipes="canvas-pipes",n.Asset="asset",n.LoadParser="load-parser",n.ResolveParser="resolve-parser",n.CacheParser="cache-parser",n.DetectionParser="detection-parser",n.MaskEffect="mask-effect",n.BlendMode="blend-mode",n.TextureSource="texture-source",n.Environment="environment",n.ShapeBuilder="shape-builder",n.Batcher="batcher",n))(E||{});const Vn=n=>{if(typeof n=="function"||typeof n=="object"&&n.extension){if(!n.extension)throw new Error("Extension class must have an extension object");n={...typeof n.extension!="object"?{type:n.extension}:n.extension,ref:n}}if(typeof n=="object")n={...n};else throw new Error("Invalid extension type");return typeof n.type=="string"&&(n.type=[n.type]),n},ji=(n,t)=>Vn(n).priority??t,q={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...n){return n.map(Vn).forEach(t=>{t.type.forEach(e=>{var i,s;return(s=(i=this._removeHandlers)[e])==null?void 0:s.call(i,t)})}),this},add(...n){return n.map(Vn).forEach(t=>{t.type.forEach(e=>{var r,o;const i=this._addHandlers,s=this._queue;i[e]?(o=i[e])==null||o.call(i,t):(s[e]=s[e]||[],(r=s[e])==null||r.push(t))})}),this},handle(n,t,e){var o;const i=this._addHandlers,s=this._removeHandlers;if(i[n]||s[n])throw new Error(`Extension type ${n} already has a handler`);i[n]=t,s[n]=e;const r=this._queue;return r[n]&&((o=r[n])==null||o.forEach(a=>t(a)),delete r[n]),this},handleByMap(n,t){return this.handle(n,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(n,t,e=-1){return this.handle(n,i=>{t.findIndex(r=>r.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((r,o)=>ji(o.value,e)-ji(r.value,e)))},i=>{const s=t.findIndex(r=>r.name===i.name);s!==-1&&t.splice(s,1)})},handleByList(n,t,e=-1){return this.handle(n,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((s,r)=>ji(r,e)-ji(s,e)))},i=>{const s=t.indexOf(i.ref);s!==-1&&t.splice(s,1)})},mixin(n,...t){for(const e of t)Object.defineProperties(n.prototype,Object.getOwnPropertyDescriptors(e))}},Ad={extension:{type:E.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Ae(()=>import("./browserAll.BoE1srum.js"),__vite__mapDeps([0,1,2,3,4]))}},Rd={extension:{type:E.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Ae(()=>import("./webworkerAll.C7VOGNTT.js"),__vite__mapDeps([1,2,3,4]))}};class lt{constructor(t,e,i){this._x=e||0,this._y=i||0,this._observer=t}clone(t){return new lt(t??this._observer,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this._observer._onUpdate(this)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this._observer._onUpdate(this)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._observer._onUpdate(this))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._observer._onUpdate(this))}}var Ph={exports:{}};(function(n){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function r(h,l,c,d,u){if(typeof c!="function")throw new TypeError("The listener must be a function");var p=new s(c,d||h,u),g=e?e+l:l;return h._events[g]?h._events[g].fn?h._events[g]=[h._events[g],p]:h._events[g].push(p):(h._events[g]=p,h._eventsCount++),h}function o(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],c,d;if(this._eventsCount===0)return l;for(d in c=this._events)t.call(c,d)&&l.push(e?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=e?e+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,g=new Array(p);u<p;u++)g[u]=d[u].fn;return g},a.prototype.listenerCount=function(l){var c=e?e+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,g){var y=e?e+l:l;if(!this._events[y])return!1;var m=this._events[y],x=arguments.length,S,v;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),x){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,c),!0;case 3:return m.fn.call(m.context,c,d),!0;case 4:return m.fn.call(m.context,c,d,u),!0;case 5:return m.fn.call(m.context,c,d,u,p),!0;case 6:return m.fn.call(m.context,c,d,u,p,g),!0}for(v=1,S=new Array(x-1);v<x;v++)S[v-1]=arguments[v];m.fn.apply(m.context,S)}else{var b=m.length,P;for(v=0;v<b;v++)switch(m[v].once&&this.removeListener(l,m[v].fn,void 0,!0),x){case 1:m[v].fn.call(m[v].context);break;case 2:m[v].fn.call(m[v].context,c);break;case 3:m[v].fn.call(m[v].context,c,d);break;case 4:m[v].fn.call(m[v].context,c,d,u);break;default:if(!S)for(P=1,S=new Array(x-1);P<x;P++)S[P-1]=arguments[P];m[v].fn.apply(m[v].context,S)}}return!0},a.prototype.on=function(l,c,d){return r(this,l,c,d,!1)},a.prototype.once=function(l,c,d){return r(this,l,c,d,!0)},a.prototype.removeListener=function(l,c,d,u){var p=e?e+l:l;if(!this._events[p])return this;if(!c)return o(this,p),this;var g=this._events[p];if(g.fn)g.fn===c&&(!u||g.once)&&(!d||g.context===d)&&o(this,p);else{for(var y=0,m=[],x=g.length;y<x;y++)(g[y].fn!==c||u&&!g[y].once||d&&g[y].context!==d)&&m.push(g[y]);m.length?this._events[p]=m.length===1?m[0]:m:o(this,p)}return this},a.prototype.removeAllListeners=function(l){var c;return l?(c=e?e+l:l,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,n.exports=a})(Ph);var kd=Ph.exports;const Zt=xh(kd),Ed=Math.PI*2,Id=180/Math.PI,Dd=Math.PI/180;class Q{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new Q(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Ks.x=0,Ks.y=0,Ks}}const Ks=new Q;class U{constructor(t=1,e=0,i=0,s=1,r=0,o=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=o}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,r,o){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=o,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new Q;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new Q;const i=this.a,s=this.b,r=this.c,o=this.d,a=this.tx,h=this.ty,l=1/(i*o+r*-s),c=t.x,d=t.y;return e.x=o*l*c+-r*l*d+(h*r-a*o)*l,e.y=i*l*d+-s*l*c+(-h*i+a*s)*l,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,r=this.c,o=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=r*e-this.d*i,this.d=r*i+this.d*e,this.tx=o*e-this.ty*i,this.ty=o*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,r=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*r,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*r,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*r+this.ty,this}appendFrom(t,e){const i=t.a,s=t.b,r=t.c,o=t.d,a=t.tx,h=t.ty,l=e.a,c=e.b,d=e.c,u=e.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=r*l+o*d,this.d=r*c+o*u,this.tx=a*l+h*d+e.tx,this.ty=a*c+h*u+e.ty,this}setTransform(t,e,i,s,r,o,a,h,l){return this.a=Math.cos(a+l)*r,this.b=Math.sin(a+l)*r,this.c=-Math.sin(a-h)*o,this.d=Math.cos(a-h)*o,this.tx=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,s=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=s*t.a+this.d*t.c,this.d=s*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,r=this.d,o=t.pivot,a=-Math.atan2(-s,r),h=Math.atan2(i,e),l=Math.abs(a+h);return l<1e-5||Math.abs(Ed-l)<1e-5?(t.rotation=h,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=h),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+r*r),t.position.x=this.tx+(o.x*e+o.y*s),t.position.y=this.ty+(o.x*i+o.y*r),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,r=this.tx,o=t*s-e*i;return this.a=s/o,this.b=-e/o,this.c=-i/o,this.d=t/o,this.tx=(i*this.ty-s*r)/o,this.ty=-(t*this.ty-e*r)/o,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new U;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}equals(t){return t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return Bd.identity()}static get shared(){return Fd.identity()}}const Fd=new U,Bd=new U,ve=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],be=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],we=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Ce=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Nn=[],Mh=[],Zi=Math.sign;function zd(){for(let n=0;n<16;n++){const t=[];Nn.push(t);for(let e=0;e<16;e++){const i=Zi(ve[n]*ve[e]+we[n]*be[e]),s=Zi(be[n]*ve[e]+Ce[n]*be[e]),r=Zi(ve[n]*we[e]+we[n]*Ce[e]),o=Zi(be[n]*we[e]+Ce[n]*Ce[e]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===r&&Ce[a]===o){t.push(a);break}}}for(let n=0;n<16;n++){const t=new U;t.set(ve[n],be[n],we[n],Ce[n],0,0),Mh.push(t)}}zd();const X={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:n=>ve[n],uY:n=>be[n],vX:n=>we[n],vY:n=>Ce[n],inv:n=>n&8?n&15:-n&7,add:(n,t)=>Nn[n][t],sub:(n,t)=>Nn[n][X.inv(t)],rotate180:n=>n^4,isVertical:n=>(n&3)===2,byDirection:(n,t)=>Math.abs(n)*2<=Math.abs(t)?t>=0?X.S:X.N:Math.abs(t)*2<=Math.abs(n)?n>0?X.E:X.W:t>0?n>0?X.SE:X.SW:n>0?X.NE:X.NW,matrixAppendRotationInv:(n,t,e=0,i=0,s=0,r=0)=>{const o=Mh[X.inv(t)],a=o.a,h=o.b,l=o.c,c=o.d,d=e-Math.min(0,a*s,l*r,a*s+l*r),u=i-Math.min(0,h*s,c*r,h*s+c*r),p=n.a,g=n.b,y=n.c,m=n.d;n.a=a*p+h*y,n.b=a*g+h*m,n.c=l*p+c*y,n.d=l*g+c*m,n.tx=d*p+u*y+n.tx,n.ty=d*g+u*m+n.ty},transformRectCoords:(n,t,e,i)=>{const{x:s,y:r,width:o,height:a}=n,{x:h,y:l,width:c,height:d}=t;return e===X.E?(i.set(s+h,r+l,o,a),i):e===X.S?i.set(c-r-a+h,s+l,a,o):e===X.W?i.set(c-s-o+h,d-r-a+l,o,a):e===X.N?i.set(r+h,d-s-o+l,a,o):i.set(s+h,r+l,o,a)}},qi=[new Q,new Q,new Q,new Q];class J{constructor(t=0,e=0,i=0,s=0){this.type="rectangle",this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new J(0,0,0,0)}clone(){return new J(this.x,this.y,this.width,this.height)}copyFromBounds(t){return this.x=t.minX,this.y=t.minY,this.width=t.maxX-t.minX,this.height=t.maxY-t.minY,this}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height}strokeContains(t,e,i,s=.5){const{width:r,height:o}=this;if(r<=0||o<=0)return!1;const a=this.x,h=this.y,l=i*(1-s),c=i-l,d=a-l,u=a+r+l,p=h-l,g=h+o+l,y=a+c,m=a+r-c,x=h+c,S=h+o-c;return t>=d&&t<=u&&e>=p&&e<=g&&!(t>y&&t<m&&e>x&&e<S)}intersects(t,e){if(!e){const R=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=R)return!1;const A=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>A}const i=this.left,s=this.right,r=this.top,o=this.bottom;if(s<=i||o<=r)return!1;const a=qi[0].set(t.left,t.top),h=qi[1].set(t.left,t.bottom),l=qi[2].set(t.right,t.top),c=qi[3].set(t.right,t.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(e.a*e.d-e.b*e.c);if(d===0||(e.apply(a,a),e.apply(h,h),e.apply(l,l),e.apply(c,c),Math.max(a.x,h.x,l.x,c.x)<=i||Math.min(a.x,h.x,l.x,c.x)>=s||Math.max(a.y,h.y,l.y,c.y)<=r||Math.min(a.y,h.y,l.y,c.y)>=o))return!1;const u=d*(h.y-a.y),p=d*(a.x-h.x),g=u*i+p*r,y=u*s+p*r,m=u*i+p*o,x=u*s+p*o;if(Math.max(g,y,m,x)<=u*a.x+p*a.y||Math.min(g,y,m,x)>=u*c.x+p*c.y)return!1;const S=d*(a.y-l.y),v=d*(l.x-a.x),b=S*i+v*r,P=S*s+v*r,C=S*i+v*o,_=S*s+v*o;return!(Math.max(b,P,C,_)<=S*a.x+v*a.y||Math.min(b,P,C,_)>=S*c.x+v*c.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),r=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(r-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}scale(t,e=t){return this.x*=t,this.y*=e,this.width*=t,this.height*=e,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),r=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=r-s,this}getBounds(t){return t||(t=new J),t.copyFrom(this),t}containsRect(t){if(this.width<=0||this.height<=0)return!1;const e=t.x,i=t.y,s=t.x+t.width,r=t.y+t.height;return e>=this.x&&e<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&r>=this.y&&r<this.y+this.height}set(t,e,i,s){return this.x=t,this.y=e,this.width=i,this.height=s,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Qs={default:-1};function ct(n="default"){return Qs[n]===void 0&&(Qs[n]=-1),++Qs[n]}const fo=new Set,K="8.0.0",Ld="8.3.4",Ye={quiet:!1,noColor:!1},V=(n,t,e=3)=>{if(Ye.quiet||fo.has(t))return;let i=new Error().stack;const s=`${t}
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.74_UInap.js","assets/chunks/webworkerAll.BhhkfDFx.js","assets/chunks/framework.CBLqO2Q1.js","assets/chunks/mapValues.D2X8cRgC.js","assets/chunks/theme.BW-xO32x.js","assets/chunks/WebGPURenderer.DPBWbSBB.js","assets/chunks/BufferResource.D5JQhxuZ.js","assets/chunks/RenderTargetSystem.C9QurjPY.js","assets/chunks/WebGLRenderer.B0g4W2sN.js","assets/chunks/CanvasRenderer.BrFqgMtf.js","assets/chunks/BitmapFont.Bt2l0bgn.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Kc=Object.defineProperty;var Qc=(n,t,e)=>t in n?Kc(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var f=(n,t,e)=>Qc(n,typeof t!="symbol"?t+"":t,e);import{V as Ae}from"./framework.CBLqO2Q1.js";import{L as xh,u as Sh,m as vh,G as Jc,E as td,d as De,y as ed,Q as id,v as bh,H as sd,R as nd,T as rd,i as br,U as wh,V as od,W as ad,I as hd,X as ld,K as ho,Y as cd,e as dd,w as ud,l as Un,f as pd,a as fd,x as lo,Z as gd,h as md,_ as yd,j as xd,$ as Ch,a0 as Sd,a1 as vd,C as bd,a2 as wd,N as Hn,O as Cd,P as _d,M as co}from"./mapValues.D2X8cRgC.js";import{a as ae,N as qs,i as $e,D as _h,b as uo,M as po,d as Pd,H as Md,e as Td}from"./theme.BW-xO32x.js";var E=(n=>(n.Application="application",n.WebGLPipes="webgl-pipes",n.WebGLPipesAdaptor="webgl-pipes-adaptor",n.WebGLSystem="webgl-system",n.WebGPUPipes="webgpu-pipes",n.WebGPUPipesAdaptor="webgpu-pipes-adaptor",n.WebGPUSystem="webgpu-system",n.CanvasSystem="canvas-system",n.CanvasPipesAdaptor="canvas-pipes-adaptor",n.CanvasPipes="canvas-pipes",n.Asset="asset",n.LoadParser="load-parser",n.ResolveParser="resolve-parser",n.CacheParser="cache-parser",n.DetectionParser="detection-parser",n.MaskEffect="mask-effect",n.BlendMode="blend-mode",n.TextureSource="texture-source",n.Environment="environment",n.ShapeBuilder="shape-builder",n.Batcher="batcher",n))(E||{});const Vn=n=>{if(typeof n=="function"||typeof n=="object"&&n.extension){if(!n.extension)throw new Error("Extension class must have an extension object");n={...typeof n.extension!="object"?{type:n.extension}:n.extension,ref:n}}if(typeof n=="object")n={...n};else throw new Error("Invalid extension type");return typeof n.type=="string"&&(n.type=[n.type]),n},ji=(n,t)=>Vn(n).priority??t,q={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...n){return n.map(Vn).forEach(t=>{t.type.forEach(e=>{var i,s;return(s=(i=this._removeHandlers)[e])==null?void 0:s.call(i,t)})}),this},add(...n){return n.map(Vn).forEach(t=>{t.type.forEach(e=>{var r,o;const i=this._addHandlers,s=this._queue;i[e]?(o=i[e])==null||o.call(i,t):(s[e]=s[e]||[],(r=s[e])==null||r.push(t))})}),this},handle(n,t,e){var o;const i=this._addHandlers,s=this._removeHandlers;if(i[n]||s[n])throw new Error(`Extension type ${n} already has a handler`);i[n]=t,s[n]=e;const r=this._queue;return r[n]&&((o=r[n])==null||o.forEach(a=>t(a)),delete r[n]),this},handleByMap(n,t){return this.handle(n,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(n,t,e=-1){return this.handle(n,i=>{t.findIndex(r=>r.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((r,o)=>ji(o.value,e)-ji(r.value,e)))},i=>{const s=t.findIndex(r=>r.name===i.name);s!==-1&&t.splice(s,1)})},handleByList(n,t,e=-1){return this.handle(n,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((s,r)=>ji(r,e)-ji(s,e)))},i=>{const s=t.indexOf(i.ref);s!==-1&&t.splice(s,1)})},mixin(n,...t){for(const e of t)Object.defineProperties(n.prototype,Object.getOwnPropertyDescriptors(e))}},Ad={extension:{type:E.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Ae(()=>import("./browserAll.74_UInap.js"),__vite__mapDeps([0,1,2,3,4]))}},Rd={extension:{type:E.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Ae(()=>import("./webworkerAll.BhhkfDFx.js"),__vite__mapDeps([1,2,3,4]))}};class lt{constructor(t,e,i){this._x=e||0,this._y=i||0,this._observer=t}clone(t){return new lt(t??this._observer,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this._observer._onUpdate(this)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this._observer._onUpdate(this)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._observer._onUpdate(this))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._observer._onUpdate(this))}}var Ph={exports:{}};(function(n){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function r(h,l,c,d,u){if(typeof c!="function")throw new TypeError("The listener must be a function");var p=new s(c,d||h,u),g=e?e+l:l;return h._events[g]?h._events[g].fn?h._events[g]=[h._events[g],p]:h._events[g].push(p):(h._events[g]=p,h._eventsCount++),h}function o(h,l){--h._eventsCount===0?h._events=new i:delete h._events[l]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],c,d;if(this._eventsCount===0)return l;for(d in c=this._events)t.call(c,d)&&l.push(e?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=e?e+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,g=new Array(p);u<p;u++)g[u]=d[u].fn;return g},a.prototype.listenerCount=function(l){var c=e?e+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,g){var y=e?e+l:l;if(!this._events[y])return!1;var m=this._events[y],x=arguments.length,S,v;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),x){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,c),!0;case 3:return m.fn.call(m.context,c,d),!0;case 4:return m.fn.call(m.context,c,d,u),!0;case 5:return m.fn.call(m.context,c,d,u,p),!0;case 6:return m.fn.call(m.context,c,d,u,p,g),!0}for(v=1,S=new Array(x-1);v<x;v++)S[v-1]=arguments[v];m.fn.apply(m.context,S)}else{var b=m.length,P;for(v=0;v<b;v++)switch(m[v].once&&this.removeListener(l,m[v].fn,void 0,!0),x){case 1:m[v].fn.call(m[v].context);break;case 2:m[v].fn.call(m[v].context,c);break;case 3:m[v].fn.call(m[v].context,c,d);break;case 4:m[v].fn.call(m[v].context,c,d,u);break;default:if(!S)for(P=1,S=new Array(x-1);P<x;P++)S[P-1]=arguments[P];m[v].fn.apply(m[v].context,S)}}return!0},a.prototype.on=function(l,c,d){return r(this,l,c,d,!1)},a.prototype.once=function(l,c,d){return r(this,l,c,d,!0)},a.prototype.removeListener=function(l,c,d,u){var p=e?e+l:l;if(!this._events[p])return this;if(!c)return o(this,p),this;var g=this._events[p];if(g.fn)g.fn===c&&(!u||g.once)&&(!d||g.context===d)&&o(this,p);else{for(var y=0,m=[],x=g.length;y<x;y++)(g[y].fn!==c||u&&!g[y].once||d&&g[y].context!==d)&&m.push(g[y]);m.length?this._events[p]=m.length===1?m[0]:m:o(this,p)}return this},a.prototype.removeAllListeners=function(l){var c;return l?(c=e?e+l:l,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,n.exports=a})(Ph);var kd=Ph.exports;const Zt=xh(kd),Ed=Math.PI*2,Id=180/Math.PI,Dd=Math.PI/180;class Q{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new Q(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Ks.x=0,Ks.y=0,Ks}}const Ks=new Q;class U{constructor(t=1,e=0,i=0,s=1,r=0,o=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=o}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,r,o){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=r,this.ty=o,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new Q;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new Q;const i=this.a,s=this.b,r=this.c,o=this.d,a=this.tx,h=this.ty,l=1/(i*o+r*-s),c=t.x,d=t.y;return e.x=o*l*c+-r*l*d+(h*r-a*o)*l,e.y=i*l*d+-s*l*c+(-h*i+a*s)*l,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,r=this.c,o=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=r*e-this.d*i,this.d=r*i+this.d*e,this.tx=o*e-this.ty*i,this.ty=o*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,r=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*r,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*r,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*r+this.ty,this}appendFrom(t,e){const i=t.a,s=t.b,r=t.c,o=t.d,a=t.tx,h=t.ty,l=e.a,c=e.b,d=e.c,u=e.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=r*l+o*d,this.d=r*c+o*u,this.tx=a*l+h*d+e.tx,this.ty=a*c+h*u+e.ty,this}setTransform(t,e,i,s,r,o,a,h,l){return this.a=Math.cos(a+l)*r,this.b=Math.sin(a+l)*r,this.c=-Math.sin(a-h)*o,this.d=Math.cos(a-h)*o,this.tx=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,s=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=s*t.a+this.d*t.c,this.d=s*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,r=this.d,o=t.pivot,a=-Math.atan2(-s,r),h=Math.atan2(i,e),l=Math.abs(a+h);return l<1e-5||Math.abs(Ed-l)<1e-5?(t.rotation=h,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=h),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+r*r),t.position.x=this.tx+(o.x*e+o.y*s),t.position.y=this.ty+(o.x*i+o.y*r),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,r=this.tx,o=t*s-e*i;return this.a=s/o,this.b=-e/o,this.c=-i/o,this.d=t/o,this.tx=(i*this.ty-s*r)/o,this.ty=-(t*this.ty-e*r)/o,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new U;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}equals(t){return t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return Bd.identity()}static get shared(){return Fd.identity()}}const Fd=new U,Bd=new U,ve=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],be=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],we=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Ce=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Nn=[],Mh=[],Zi=Math.sign;function zd(){for(let n=0;n<16;n++){const t=[];Nn.push(t);for(let e=0;e<16;e++){const i=Zi(ve[n]*ve[e]+we[n]*be[e]),s=Zi(be[n]*ve[e]+Ce[n]*be[e]),r=Zi(ve[n]*we[e]+we[n]*Ce[e]),o=Zi(be[n]*we[e]+Ce[n]*Ce[e]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===r&&Ce[a]===o){t.push(a);break}}}for(let n=0;n<16;n++){const t=new U;t.set(ve[n],be[n],we[n],Ce[n],0,0),Mh.push(t)}}zd();const X={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:n=>ve[n],uY:n=>be[n],vX:n=>we[n],vY:n=>Ce[n],inv:n=>n&8?n&15:-n&7,add:(n,t)=>Nn[n][t],sub:(n,t)=>Nn[n][X.inv(t)],rotate180:n=>n^4,isVertical:n=>(n&3)===2,byDirection:(n,t)=>Math.abs(n)*2<=Math.abs(t)?t>=0?X.S:X.N:Math.abs(t)*2<=Math.abs(n)?n>0?X.E:X.W:t>0?n>0?X.SE:X.SW:n>0?X.NE:X.NW,matrixAppendRotationInv:(n,t,e=0,i=0,s=0,r=0)=>{const o=Mh[X.inv(t)],a=o.a,h=o.b,l=o.c,c=o.d,d=e-Math.min(0,a*s,l*r,a*s+l*r),u=i-Math.min(0,h*s,c*r,h*s+c*r),p=n.a,g=n.b,y=n.c,m=n.d;n.a=a*p+h*y,n.b=a*g+h*m,n.c=l*p+c*y,n.d=l*g+c*m,n.tx=d*p+u*y+n.tx,n.ty=d*g+u*m+n.ty},transformRectCoords:(n,t,e,i)=>{const{x:s,y:r,width:o,height:a}=n,{x:h,y:l,width:c,height:d}=t;return e===X.E?(i.set(s+h,r+l,o,a),i):e===X.S?i.set(c-r-a+h,s+l,a,o):e===X.W?i.set(c-s-o+h,d-r-a+l,o,a):e===X.N?i.set(r+h,d-s-o+l,a,o):i.set(s+h,r+l,o,a)}},qi=[new Q,new Q,new Q,new Q];class J{constructor(t=0,e=0,i=0,s=0){this.type="rectangle",this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new J(0,0,0,0)}clone(){return new J(this.x,this.y,this.width,this.height)}copyFromBounds(t){return this.x=t.minX,this.y=t.minY,this.width=t.maxX-t.minX,this.height=t.maxY-t.minY,this}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height}strokeContains(t,e,i,s=.5){const{width:r,height:o}=this;if(r<=0||o<=0)return!1;const a=this.x,h=this.y,l=i*(1-s),c=i-l,d=a-l,u=a+r+l,p=h-l,g=h+o+l,y=a+c,m=a+r-c,x=h+c,S=h+o-c;return t>=d&&t<=u&&e>=p&&e<=g&&!(t>y&&t<m&&e>x&&e<S)}intersects(t,e){if(!e){const R=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=R)return!1;const A=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>A}const i=this.left,s=this.right,r=this.top,o=this.bottom;if(s<=i||o<=r)return!1;const a=qi[0].set(t.left,t.top),h=qi[1].set(t.left,t.bottom),l=qi[2].set(t.right,t.top),c=qi[3].set(t.right,t.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(e.a*e.d-e.b*e.c);if(d===0||(e.apply(a,a),e.apply(h,h),e.apply(l,l),e.apply(c,c),Math.max(a.x,h.x,l.x,c.x)<=i||Math.min(a.x,h.x,l.x,c.x)>=s||Math.max(a.y,h.y,l.y,c.y)<=r||Math.min(a.y,h.y,l.y,c.y)>=o))return!1;const u=d*(h.y-a.y),p=d*(a.x-h.x),g=u*i+p*r,y=u*s+p*r,m=u*i+p*o,x=u*s+p*o;if(Math.max(g,y,m,x)<=u*a.x+p*a.y||Math.min(g,y,m,x)>=u*c.x+p*c.y)return!1;const S=d*(a.y-l.y),v=d*(l.x-a.x),b=S*i+v*r,P=S*s+v*r,C=S*i+v*o,_=S*s+v*o;return!(Math.max(b,P,C,_)<=S*a.x+v*a.y||Math.min(b,P,C,_)>=S*c.x+v*c.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),r=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(r-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}scale(t,e=t){return this.x*=t,this.y*=e,this.width*=t,this.height*=e,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),r=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=r-s,this}getBounds(t){return t||(t=new J),t.copyFrom(this),t}containsRect(t){if(this.width<=0||this.height<=0)return!1;const e=t.x,i=t.y,s=t.x+t.width,r=t.y+t.height;return e>=this.x&&e<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&r>=this.y&&r<this.y+this.height}set(t,e,i,s){return this.x=t,this.y=e,this.width=i,this.height=s,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Qs={default:-1};function ct(n="default"){return Qs[n]===void 0&&(Qs[n]=-1),++Qs[n]}const fo=new Set,K="8.0.0",Ld="8.3.4",Ye={quiet:!1,noColor:!1},V=(n,t,e=3)=>{if(Ye.quiet||fo.has(t))return;let i=new Error().stack;const s=`${t}
|
|
3
3
|
Deprecated since v${n}`,r=typeof console.groupCollapsed=="function"&&!Ye.noColor;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",s):(i=i.split(`
|
|
4
4
|
`).splice(e).join(`
|
|
5
5
|
`),r?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",s),console.warn(i),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",s),console.warn(i))),fo.add(t)};Object.defineProperties(V,{quiet:{get:()=>Ye.quiet,set:n=>{Ye.quiet=n},enumerable:!0,configurable:!1},noColor:{get:()=>Ye.noColor,set:n=>{Ye.noColor=n},enumerable:!0,configurable:!1}});const Th=()=>{};function Qe(n){return n+=n===0?1:0,--n,n|=n>>>1,n|=n>>>2,n|=n>>>4,n|=n>>>8,n|=n>>>16,n+1}function go(n){return!(n&n-1)&&!!n}function Ah(n){const t={};for(const e in n)n[e]!==void 0&&(t[e]=n[e]);return t}const mo=Object.create(null);function Od(n){const t=mo[n];return t===void 0&&(mo[n]=ct("resource")),t}const Rh=class kh extends Zt{constructor(t={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,t={...kh.defaultOptions,...t},this.addressMode=t.addressMode,this.addressModeU=t.addressModeU??this.addressModeU,this.addressModeV=t.addressModeV??this.addressModeV,this.addressModeW=t.addressModeW??this.addressModeW,this.scaleMode=t.scaleMode,this.magFilter=t.magFilter??this.magFilter,this.minFilter=t.minFilter??this.minFilter,this.mipmapFilter=t.mipmapFilter??this.mipmapFilter,this.lodMinClamp=t.lodMinClamp,this.lodMaxClamp=t.lodMaxClamp,this.compare=t.compare,this.maxAnisotropy=t.maxAnisotropy??1}set addressMode(t){this.addressModeU=t,this.addressModeV=t,this.addressModeW=t}get addressMode(){return this.addressModeU}set wrapMode(t){V(K,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=t}get wrapMode(){return this.addressMode}set scaleMode(t){this.magFilter=t,this.minFilter=t,this.mipmapFilter=t}get scaleMode(){return this.magFilter}set maxAnisotropy(t){this._maxAnisotropy=Math.min(t,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this._sharedResourceId=null,this.emit("change",this)}_generateResourceId(){const t=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=Od(t),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};Rh.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let Je=Rh;const Eh=class Ih extends Zt{constructor(t={}){super(),this.options=t,this._gpuData=Object.create(null),this._gcLastUsed=-1,this.uid=ct("textureSource"),this._resourceType="textureSource",this._resourceId=ct("resource"),this.uploadMethodId="unknown",this._resolution=1,this.pixelWidth=1,this.pixelHeight=1,this.width=1,this.height=1,this.sampleCount=1,this.mipLevelCount=1,this.autoGenerateMipmaps=!1,this.format="rgba8unorm",this.dimension="2d",this.viewDimension="2d",this.arrayLayerCount=1,this.antialias=!1,this._touched=0,this._batchTick=-1,this._textureBindLocation=-1,t={...Ih.defaultOptions,...t},this.label=t.label??"",this.resource=t.resource,this.autoGarbageCollect=t.autoGarbageCollect,this._resolution=t.resolution,t.width?this.pixelWidth=t.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,t.height?this.pixelHeight=t.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=t.format,this.dimension=t.dimensions,this.viewDimension=t.viewDimension??t.dimensions,this.arrayLayerCount=t.arrayLayerCount,this.mipLevelCount=t.mipLevelCount,this.autoGenerateMipmaps=t.autoGenerateMipmaps,this.sampleCount=t.sampleCount,this.antialias=t.antialias,this.alphaMode=t.alphaMode,this.style=new Je(Ah(t)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(t){var e,i;this.style!==t&&((e=this._style)==null||e.off("change",this._onStyleChange,this),this._style=t,(i=this._style)==null||i.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(t){this._style.maxAnisotropy=t}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(t){this._style.addressMode=t}get repeatMode(){return this._style.addressMode}set repeatMode(t){this._style.addressMode=t}get magFilter(){return this._style.magFilter}set magFilter(t){this._style.magFilter=t}get minFilter(){return this._style.minFilter}set minFilter(t){this._style.minFilter=t}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(t){this._style.mipmapFilter=t}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(t){this._style.lodMinClamp=t}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(t){this._style.lodMaxClamp=t}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const t=this._resolution;if(this.resize(this.resourceWidth/t,this.resourceHeight/t))return}this.emit("update",this)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this._style&&(this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){var t,e;this._resourceId=ct("resource"),this.emit("change",this),this.emit("unload",this);for(const i in this._gpuData)(e=(t=this._gpuData[i])==null?void 0:t.destroy)==null||e.call(t);this._gpuData=Object.create(null)}get resourceWidth(){const{resource:t}=this;return t.naturalWidth||t.videoWidth||t.displayWidth||t.width}get resourceHeight(){const{resource:t}=this;return t.naturalHeight||t.videoHeight||t.displayHeight||t.height}get resolution(){return this._resolution}set resolution(t){this._resolution!==t&&(this._resolution=t,this.width=this.pixelWidth/t,this.height=this.pixelHeight/t)}resize(t,e,i){i||(i=this._resolution),t||(t=this.width),e||(e=this.height);const s=Math.round(t*i),r=Math.round(e*i);return this.width=s/i,this.height=r/i,this._resolution=i,this.pixelWidth===s&&this.pixelHeight===r?!1:(this._refreshPOT(),this.pixelWidth=s,this.pixelHeight=r,this.emit("resize",this),this._resourceId=ct("resource"),this.emit("change",this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit("updateMipmaps",this)}set wrapMode(t){this._style.wrapMode=t}get wrapMode(){return this._style.wrapMode}set scaleMode(t){this._style.scaleMode=t}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=go(this.pixelWidth)&&go(this.pixelHeight)}static test(t){throw new Error("Unimplemented")}};Eh.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",dimensions:"2d",viewDimension:"2d",arrayLayerCount:1,mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let zt=Eh;class wr extends zt{constructor(t){const e=t.resource||new Float32Array(t.width*t.height*4);let i=t.format;i||(e instanceof Float32Array?i="rgba32float":e instanceof Int32Array||e instanceof Uint32Array?i="rgba32uint":e instanceof Int16Array||e instanceof Uint16Array?i="rgba16uint":(e instanceof Int8Array,i="bgra8unorm")),super({...t,resource:e,format:i}),this.uploadMethodId="buffer"}static test(t){return t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array}}wr.extension=E.TextureSource;const yo=new U;class Wd{constructor(t,e){this.mapCoord=new U,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof e>"u"?this.clampMargin=t.width<10?0:.5:this.clampMargin=e,this.isSimple=!1,this.texture=t}get texture(){return this._texture}set texture(t){var e;this.texture!==t&&((e=this._texture)==null||e.removeListener("update",this.update,this),this._texture=t,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(t,e){e===void 0&&(e=t);const i=this.mapCoord;for(let s=0;s<t.length;s+=2){const r=t[s],o=t[s+1];e[s]=r*i.a+o*i.c+i.tx,e[s+1]=r*i.b+o*i.d+i.ty}return e}update(){const t=this._texture;this._updateID++;const e=t.uvs;this.mapCoord.set(e.x1-e.x0,e.y1-e.y0,e.x3-e.x0,e.y3-e.y0,e.x0,e.y0);const i=t.orig,s=t.trim;s&&(yo.set(i.width/s.width,0,0,i.height/s.height,-s.x/s.width,-s.y/s.height),this.mapCoord.append(yo));const r=t.source,o=this.uClampFrame,a=this.clampMargin/r._resolution,h=this.clampOffset/r._resolution;return o[0]=(t.frame.x+a+h)/r.width,o[1]=(t.frame.y+a+h)/r.height,o[2]=(t.frame.x+t.frame.width-a+h)/r.width,o[3]=(t.frame.y+t.frame.height-a+h)/r.height,this.uClampOffset[0]=this.clampOffset/r.pixelWidth,this.uClampOffset[1]=this.clampOffset/r.pixelHeight,this.isSimple=t.frame.width===r.width&&t.frame.height===r.height&&t.rotate===0,!0}}class G extends Zt{constructor({source:t,label:e,frame:i,orig:s,trim:r,defaultAnchor:o,defaultBorders:a,rotate:h,dynamic:l}={}){if(super(),this.uid=ct("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new J,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=e,this.source=(t==null?void 0:t.source)??new zt,this.noFrame=!i,i)this.frame.copyFrom(i);else{const{width:c,height:d}=this._source;this.frame.width=c,this.frame.height=d}this.orig=s||this.frame,this.trim=r,this.rotate=h??0,this.defaultAnchor=o,this.defaultBorders=a,this.destroyed=!1,this.dynamic=l||!1,this.updateUvs()}set source(t){this._source&&this._source.off("resize",this.update,this),this._source=t,t.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new Wd(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:t,frame:e}=this,{width:i,height:s}=this._source,r=e.x/i,o=e.y/s,a=e.width/i,h=e.height/s;let l=this.rotate;if(l){const c=a/2,d=h/2,u=r+c,p=o+d;l=X.add(l,X.NW),t.x0=u+c*X.uX(l),t.y0=p+d*X.uY(l),l=X.add(l,2),t.x1=u+c*X.uX(l),t.y1=p+d*X.uY(l),l=X.add(l,2),t.x2=u+c*X.uX(l),t.y2=p+d*X.uY(l),l=X.add(l,2),t.x3=u+c*X.uX(l),t.y3=p+d*X.uY(l)}else t.x0=r,t.y0=o,t.x1=r+a,t.y1=o,t.x2=r+a,t.y2=o+h,t.x3=r,t.y3=o+h}destroy(t=!1){this._source&&(this._source.off("resize",this.update,this),t&&(this._source.destroy(),this._source=null)),this._textureMatrix=null,this.destroyed=!0,this.emit("destroy",this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit("update",this)}get baseTexture(){return V(K,"Texture.baseTexture is now Texture.source"),this._source}}G.EMPTY=new G({label:"EMPTY",source:new zt({label:"EMPTY"})});G.EMPTY.destroy=Th;G.WHITE=new G({source:new wr({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});G.WHITE.destroy=Th;function Dh(n,t,e){const{width:i,height:s}=e.orig,r=e.trim;if(r){const o=r.width,a=r.height;n.minX=r.x-t._x*i,n.maxX=n.minX+o,n.minY=r.y-t._y*s,n.maxY=n.minY+a}else n.minX=-t._x*i,n.maxX=n.minX+i,n.minY=-t._y*s,n.maxY=n.minY+s}const xo=new U;class Ft{constructor(t=1/0,e=1/0,i=-1/0,s=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=xo,this.minX=t,this.minY=e,this.maxX=i,this.maxY=s}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new J);const t=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(t.x=0,t.y=0,t.width=0,t.height=0):t.copyFromBounds(this),t}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=xo,this}set(t,e,i,s){this.minX=t,this.minY=e,this.maxX=i,this.maxY=s}addFrame(t,e,i,s,r){r||(r=this.matrix);const o=r.a,a=r.b,h=r.c,l=r.d,c=r.tx,d=r.ty;let u=this.minX,p=this.minY,g=this.maxX,y=this.maxY,m=o*t+h*e+c,x=a*t+l*e+d;m<u&&(u=m),x<p&&(p=x),m>g&&(g=m),x>y&&(y=x),m=o*i+h*e+c,x=a*i+l*e+d,m<u&&(u=m),x<p&&(p=x),m>g&&(g=m),x>y&&(y=x),m=o*t+h*s+c,x=a*t+l*s+d,m<u&&(u=m),x<p&&(p=x),m>g&&(g=m),x>y&&(y=x),m=o*i+h*s+c,x=a*i+l*s+d,m<u&&(u=m),x<p&&(p=x),m>g&&(g=m),x>y&&(y=x),this.minX=u,this.minY=p,this.maxX=g,this.maxY=y}addRect(t,e){this.addFrame(t.x,t.y,t.x+t.width,t.y+t.height,e)}addBounds(t,e){this.addFrame(t.minX,t.minY,t.maxX,t.maxY,e)}addBoundsMask(t){this.minX=this.minX>t.minX?this.minX:t.minX,this.minY=this.minY>t.minY?this.minY:t.minY,this.maxX=this.maxX<t.maxX?this.maxX:t.maxX,this.maxY=this.maxY<t.maxY?this.maxY:t.maxY}applyMatrix(t){const e=this.minX,i=this.minY,s=this.maxX,r=this.maxY,{a:o,b:a,c:h,d:l,tx:c,ty:d}=t;let u=o*e+h*i+c,p=a*e+l*i+d;this.minX=u,this.minY=p,this.maxX=u,this.maxY=p,u=o*s+h*i+c,p=a*s+l*i+d,this.minX=u<this.minX?u:this.minX,this.minY=p<this.minY?p:this.minY,this.maxX=u>this.maxX?u:this.maxX,this.maxY=p>this.maxY?p:this.maxY,u=o*e+h*r+c,p=a*e+l*r+d,this.minX=u<this.minX?u:this.minX,this.minY=p<this.minY?p:this.minY,this.maxX=u>this.maxX?u:this.maxX,this.maxY=p>this.maxY?p:this.maxY,u=o*s+h*r+c,p=a*s+l*r+d,this.minX=u<this.minX?u:this.minX,this.minY=p<this.minY?p:this.minY,this.maxX=u>this.maxX?u:this.maxX,this.maxY=p>this.maxY?p:this.maxY}fit(t){return this.minX<t.left&&(this.minX=t.left),this.maxX>t.right&&(this.maxX=t.right),this.minY<t.top&&(this.minY=t.top),this.maxY>t.bottom&&(this.maxY=t.bottom),this}fitBounds(t,e,i,s){return this.minX<t&&(this.minX=t),this.maxX>e&&(this.maxX=e),this.minY<i&&(this.minY=i),this.maxY>s&&(this.maxY=s),this}pad(t,e=t){return this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new Ft(this.minX,this.minY,this.maxX,this.maxY)}scale(t,e=t){return this.minX*=t,this.minY*=e,this.maxX*=t,this.maxY*=e,this}get x(){return this.minX}set x(t){const e=this.maxX-this.minX;this.minX=t,this.maxX=t+e}get y(){return this.minY}set y(t){const e=this.maxY-this.minY;this.minY=t,this.maxY=t+e}get width(){return this.maxX-this.minX}set width(t){this.maxX=this.minX+t}get height(){return this.maxY-this.minY}set height(t){this.maxY=this.minY+t}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(t,e,i,s){let r=this.minX,o=this.minY,a=this.maxX,h=this.maxY;s||(s=this.matrix);const l=s.a,c=s.b,d=s.c,u=s.d,p=s.tx,g=s.ty;for(let y=e;y<i;y+=2){const m=t[y],x=t[y+1],S=l*m+d*x+p,v=c*m+u*x+g;r=S<r?S:r,o=v<o?v:o,a=S>a?S:a,h=v>h?v:h}this.minX=r,this.minY=o,this.maxX=a,this.maxY=h}containsPoint(t,e){return this.minX<=t&&this.minY<=e&&this.maxX>=t&&this.maxY>=e}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(t){return this.minX=t.minX,this.minY=t.minY,this.maxX=t.maxX,this.maxY=t.maxY,this}}var Gd={grad:.9,turn:360,rad:360/(2*Math.PI)},qt=function(n){return typeof n=="string"?n.length>0:typeof n=="number"},xt=function(n,t,e){return t===void 0&&(t=0),e===void 0&&(e=Math.pow(10,t)),Math.round(e*n)/e+0},It=function(n,t,e){return t===void 0&&(t=0),e===void 0&&(e=1),n>e?e:n>t?n:t},Fh=function(n){return(n=isFinite(n)?n%360:0)>0?n:n+360},So=function(n){return{r:It(n.r,0,255),g:It(n.g,0,255),b:It(n.b,0,255),a:It(n.a)}},Js=function(n){return{r:xt(n.r),g:xt(n.g),b:xt(n.b),a:xt(n.a,3)}},Ud=/^#([0-9a-f]{3,8})$/i,Ki=function(n){var t=n.toString(16);return t.length<2?"0"+t:t},Bh=function(n){var t=n.r,e=n.g,i=n.b,s=n.a,r=Math.max(t,e,i),o=r-Math.min(t,e,i),a=o?r===t?(e-i)/o:r===e?2+(i-t)/o:4+(t-e)/o:0;return{h:60*(a<0?a+6:a),s:r?o/r*100:0,v:r/255*100,a:s}},zh=function(n){var t=n.h,e=n.s,i=n.v,s=n.a;t=t/360*6,e/=100,i/=100;var r=Math.floor(t),o=i*(1-e),a=i*(1-(t-r)*e),h=i*(1-(1-t+r)*e),l=r%6;return{r:255*[i,a,o,o,h,i][l],g:255*[h,i,i,a,o,o][l],b:255*[o,o,h,i,i,a][l],a:s}},vo=function(n){return{h:Fh(n.h),s:It(n.s,0,100),l:It(n.l,0,100),a:It(n.a)}},bo=function(n){return{h:xt(n.h),s:xt(n.s),l:xt(n.l),a:xt(n.a,3)}},wo=function(n){return zh((e=(t=n).s,{h:t.h,s:(e*=((i=t.l)<50?i:100-i)/100)>0?2*e/(i+e)*100:0,v:i+e,a:t.a}));var t,e,i},Ci=function(n){return{h:(t=Bh(n)).h,s:(s=(200-(e=t.s))*(i=t.v)/100)>0&&s<200?e*i/100/(s<=100?s:200-s)*100:0,l:s/2,a:t.a};var t,e,i,s},Hd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Vd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Nd=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,$d=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,$n={string:[[function(n){var t=Ud.exec(n);return t?(n=t[1]).length<=4?{r:parseInt(n[0]+n[0],16),g:parseInt(n[1]+n[1],16),b:parseInt(n[2]+n[2],16),a:n.length===4?xt(parseInt(n[3]+n[3],16)/255,2):1}:n.length===6||n.length===8?{r:parseInt(n.substr(0,2),16),g:parseInt(n.substr(2,2),16),b:parseInt(n.substr(4,2),16),a:n.length===8?xt(parseInt(n.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(n){var t=Nd.exec(n)||$d.exec(n);return t?t[2]!==t[4]||t[4]!==t[6]?null:So({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(n){var t=Hd.exec(n)||Vd.exec(n);if(!t)return null;var e,i,s=vo({h:(e=t[1],i=t[2],i===void 0&&(i="deg"),Number(e)*(Gd[i]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return wo(s)},"hsl"]],object:[[function(n){var t=n.r,e=n.g,i=n.b,s=n.a,r=s===void 0?1:s;return qt(t)&&qt(e)&&qt(i)?So({r:Number(t),g:Number(e),b:Number(i),a:Number(r)}):null},"rgb"],[function(n){var t=n.h,e=n.s,i=n.l,s=n.a,r=s===void 0?1:s;if(!qt(t)||!qt(e)||!qt(i))return null;var o=vo({h:Number(t),s:Number(e),l:Number(i),a:Number(r)});return wo(o)},"hsl"],[function(n){var t=n.h,e=n.s,i=n.v,s=n.a,r=s===void 0?1:s;if(!qt(t)||!qt(e)||!qt(i))return null;var o=function(a){return{h:Fh(a.h),s:It(a.s,0,100),v:It(a.v,0,100),a:It(a.a)}}({h:Number(t),s:Number(e),v:Number(i),a:Number(r)});return zh(o)},"hsv"]]},Co=function(n,t){for(var e=0;e<t.length;e++){var i=t[e][0](n);if(i)return[i,t[e][1]]}return[null,void 0]},Yd=function(n){return typeof n=="string"?Co(n.trim(),$n.string):typeof n=="object"&&n!==null?Co(n,$n.object):[null,void 0]},tn=function(n,t){var e=Ci(n);return{h:e.h,s:It(e.s+100*t,0,100),l:e.l,a:e.a}},en=function(n){return(299*n.r+587*n.g+114*n.b)/1e3/255},_o=function(n,t){var e=Ci(n);return{h:e.h,s:e.s,l:It(e.l+100*t,0,100),a:e.a}},Yn=function(){function n(t){this.parsed=Yd(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return n.prototype.isValid=function(){return this.parsed!==null},n.prototype.brightness=function(){return xt(en(this.rgba),2)},n.prototype.isDark=function(){return en(this.rgba)<.5},n.prototype.isLight=function(){return en(this.rgba)>=.5},n.prototype.toHex=function(){return t=Js(this.rgba),e=t.r,i=t.g,s=t.b,o=(r=t.a)<1?Ki(xt(255*r)):"","#"+Ki(e)+Ki(i)+Ki(s)+o;var t,e,i,s,r,o},n.prototype.toRgb=function(){return Js(this.rgba)},n.prototype.toRgbString=function(){return t=Js(this.rgba),e=t.r,i=t.g,s=t.b,(r=t.a)<1?"rgba("+e+", "+i+", "+s+", "+r+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,r},n.prototype.toHsl=function(){return bo(Ci(this.rgba))},n.prototype.toHslString=function(){return t=bo(Ci(this.rgba)),e=t.h,i=t.s,s=t.l,(r=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+r+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,r},n.prototype.toHsv=function(){return t=Bh(this.rgba),{h:xt(t.h),s:xt(t.s),v:xt(t.v),a:xt(t.a,3)};var t},n.prototype.invert=function(){return Nt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},n.prototype.saturate=function(t){return t===void 0&&(t=.1),Nt(tn(this.rgba,t))},n.prototype.desaturate=function(t){return t===void 0&&(t=.1),Nt(tn(this.rgba,-t))},n.prototype.grayscale=function(){return Nt(tn(this.rgba,-1))},n.prototype.lighten=function(t){return t===void 0&&(t=.1),Nt(_o(this.rgba,t))},n.prototype.darken=function(t){return t===void 0&&(t=.1),Nt(_o(this.rgba,-t))},n.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},n.prototype.alpha=function(t){return typeof t=="number"?Nt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):xt(this.rgba.a,3);var e},n.prototype.hue=function(t){var e=Ci(this.rgba);return typeof t=="number"?Nt({h:t,s:e.s,l:e.l,a:e.a}):xt(e.h)},n.prototype.isEqual=function(t){return this.toHex()===Nt(t).toHex()},n}(),Nt=function(n){return n instanceof Yn?n:new Yn(n)},Po=[],Xd=function(n){n.forEach(function(t){Po.indexOf(t)<0&&(t(Yn,$n),Po.push(t))})};function jd(n,t){var e={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},i={};for(var s in e)i[e[s]]=s;var r={};n.prototype.toName=function(o){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var a,h,l=i[this.toHex()];if(l)return l;if(o!=null&&o.closest){var c=this.toRgb(),d=1/0,u="black";if(!r.length)for(var p in e)r[p]=new n(e[p]).toRgb();for(var g in e){var y=(a=c,h=r[g],Math.pow(a.r-h.r,2)+Math.pow(a.g-h.g,2)+Math.pow(a.b-h.b,2));y<d&&(d=y,u=g)}return u}},t.string.push([function(o){var a=o.toLowerCase(),h=a==="transparent"?"#0000":e[a];return h?new n(h).toRgb():null},"name"])}Xd([jd]);const ti=class Si{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(t){if(t instanceof Si)this._value=this._cloneSource(t._value),this._int=t._int,this._components.set(t._components);else{if(t===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,t))&&(this._value=this._cloneSource(t),this._normalize(this._value))}}get value(){return this._value}_cloneSource(t){return typeof t=="string"||typeof t=="number"||t instanceof Number||t===null?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):typeof t=="object"&&t!==null?{...t}:t}_isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if(i==="number"||i==="string"||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length!==e.length?!1:t.every((r,o)=>r===e[o]);if(t!==null&&e!==null){const r=Object.keys(t),o=Object.keys(e);return r.length!==o.length?!1:r.every(a=>t[a]===e[a])}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb),t[0]=Math.round(e*255),t[1]=Math.round(i*255),t[2]=Math.round(s*255),t}toArray(t){this._arrayRgba||(this._arrayRgba=[]),t||(t=this._arrayRgba);const[e,i,s,r]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=r,t}toRgbArray(t){this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb);const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toBgrNumber(){const[t,e,i]=this.toUint8RgbArray();return(i<<16)+(e<<8)+t}toLittleEndianNumber(){const t=this._int;return(t>>16)+(t&65280)+((t&255)<<16)}multiply(t){const[e,i,s,r]=Si._temp.setValue(t)._components;return this._components[0]*=e,this._components[1]*=i,this._components[2]*=s,this._components[3]*=r,this._refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this._refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(t===1)return(255<<24)+this._int;if(t===0)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,r=this._int&255;return e&&(i=i*t+.5|0,s=s*t+.5|0,r=r*t+.5|0),(t*255<<24)+(i<<16)+(s<<8)+r}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const e=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-e.length)+e}setAlpha(t){return this._components[3]=this._clamp(t),this}_normalize(t){let e,i,s,r;if((typeof t=="number"||t instanceof Number)&&t>=0&&t<=16777215){const o=t;e=(o>>16&255)/255,i=(o>>8&255)/255,s=(o&255)/255,r=1}else if((Array.isArray(t)||t instanceof Float32Array)&&t.length>=3&&t.length<=4)t=this._clamp(t),[e,i,s,r=1]=t;else if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&t.length>=3&&t.length<=4)t=this._clamp(t,0,255),[e,i,s,r=255]=t,e/=255,i/=255,s/=255,r/=255;else if(typeof t=="string"||typeof t=="object"){if(typeof t=="string"){const a=Si.HEX_PATTERN.exec(t);a&&(t=`#${a[2]}`)}const o=Nt(t);o.isValid()&&({r:e,g:i,b:s,a:r}=o.rgba,e/=255,i/=255,s/=255)}if(e!==void 0)this._components[0]=e,this._components[1]=i,this._components[2]=s,this._components[3]=r,this._refreshInt();else throw new Error(`Unable to convert color ${t}`)}_refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(t*255<<16)+(e*255<<8)+(i*255|0)}_clamp(t,e=0,i=1){return typeof t=="number"?Math.min(Math.max(t,e),i):(t.forEach((s,r)=>{t[r]=Math.min(Math.max(s,e),i)}),t)}static isColorLike(t){return typeof t=="number"||typeof t=="string"||t instanceof Number||t instanceof Si||Array.isArray(t)||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Float32Array||t.r!==void 0&&t.g!==void 0&&t.b!==void 0||t.r!==void 0&&t.g!==void 0&&t.b!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0&&t.a!==void 0}};ti.shared=new ti;ti._temp=new ti;ti.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let nt=ti;const Zd={cullArea:null,cullable:!1,cullableChildren:!0};let sn=0;const Mo=500;function st(...n){sn!==Mo&&(sn++,sn===Mo?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...n))}const Hi={_registeredResources:new Set,register(n){this._registeredResources.add(n)},unregister(n){this._registeredResources.delete(n)},release(){this._registeredResources.forEach(n=>n.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(n){return this._registeredResources.has(n)},reset(){this._registeredResources.clear()}};class qd{constructor(t,e){this._pool=[],this._count=0,this._index=0,this._classType=t,e&&this.prepopulate(e)}prepopulate(t){for(let e=0;e<t;e++)this._pool[this._index++]=new this._classType;this._count+=t}get(t){var i;let e;return this._index>0?e=this._pool[--this._index]:(e=new this._classType,this._count++),(i=e.init)==null||i.call(e,t),e}return(t){var e;(e=t.reset)==null||e.call(t),this._pool[this._index++]=t}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let t=0;t<this._index;t++)this._pool[t].destroy();this._pool.length=0,this._count=0,this._index=0}}class Kd{constructor(){this._poolsByClass=new Map}prepopulate(t,e){this.getPool(t).prepopulate(e)}get(t,e){return this.getPool(t).get(e)}return(t){this.getPool(t.constructor).return(t)}getPool(t){return this._poolsByClass.has(t)||this._poolsByClass.set(t,new qd(t)),this._poolsByClass.get(t)}stats(){const t={};return this._poolsByClass.forEach(e=>{const i=t[e._classType.name]?e._classType.name+e._classType.ID:e._classType.name;t[i]={free:e.totalFree,used:e.totalUsed,size:e.totalSize}}),t}clear(){this._poolsByClass.forEach(t=>t.clear()),this._poolsByClass.clear()}}const At=new Kd;Hi.register(At);const Qd={get isCachedAsTexture(){var n;return!!((n=this.renderGroup)!=null&&n.isCachedAsTexture)},cacheAsTexture(n){typeof n=="boolean"&&n===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(n===!0?{}:n))},updateCacheTexture(){var n;(n=this.renderGroup)==null||n.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(n){V("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(n)}};function Jd(n,t,e){const i=n.length;let s;if(t>=i||e===0)return;e=t+e>i?i-t:e;const r=i-e;for(s=t;s<r;++s)n[s]=n[s+e];n.length=r}const tu={allowChildren:!0,removeChildren(n=0,t){var r;const e=t??this.children.length,i=e-n,s=[];if(i>0&&i<=e){for(let a=e-1;a>=n;a--){const h=this.children[a];h&&(s.push(h),h.parent=null)}Jd(this.children,n,e);const o=this.renderGroup||this.parentRenderGroup;o&&o.removeChildren(s);for(let a=0;a<s.length;++a){const h=s[a];(r=h.parentRenderLayer)==null||r.detach(h),this.emit("childRemoved",h,this,a),s[a].emit("removed",this)}return s.length>0&&this._didViewChangeTick++,s}else if(i===0&&this.children.length===0)return s;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(n){const t=this.getChildAt(n);return this.removeChild(t)},getChildAt(n){if(n<0||n>=this.children.length)throw new Error(`getChildAt: Index (${n}) does not exist.`);return this.children[n]},setChildIndex(n,t){if(t<0||t>=this.children.length)throw new Error(`The index ${t} supplied is out of bounds ${this.children.length}`);this.getChildIndex(n),this.addChildAt(n,t)},getChildIndex(n){const t=this.children.indexOf(n);if(t===-1)throw new Error("The supplied Container must be a child of the caller");return t},addChildAt(n,t){this.allowChildren||V(K,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:e}=this;if(t<0||t>e.length)throw new Error(`${n}addChildAt: The index ${t} supplied is out of bounds ${e.length}`);if(n.parent){const s=n.parent.children.indexOf(n);if(n.parent===this&&s===t)return n;s!==-1&&n.parent.children.splice(s,1)}t===e.length?e.push(n):e.splice(t,0,n),n.parent=this,n.didChange=!0,n._updateFlags=15;const i=this.renderGroup||this.parentRenderGroup;return i&&i.addChild(n),this.sortableChildren&&(this.sortDirty=!0),this.emit("childAdded",n,this,t),n.emit("added",this),n},swapChildren(n,t){if(n===t)return;const e=this.getChildIndex(n),i=this.getChildIndex(t);this.children[e]=t,this.children[i]=n;const s=this.renderGroup||this.parentRenderGroup;s&&(s.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){var n;(n=this.parent)==null||n.removeChild(this)},reparentChild(...n){return n.length===1?this.reparentChildAt(n[0],this.children.length):(n.forEach(t=>this.reparentChildAt(t,this.children.length)),n[0])},reparentChildAt(n,t){if(n.parent===this)return this.setChildIndex(n,t),n;const e=n.worldTransform.clone();n.removeFromParent(),this.addChildAt(n,t);const i=this.worldTransform.clone();return i.invert(),e.prepend(i),n.setFromMatrix(e),n},replaceChild(n,t){n.updateLocalTransform(),this.addChildAt(t,this.getChildIndex(n)),t.setFromMatrix(n.localTransform),t.updateLocalTransform(),this.removeChild(n)}},eu={collectRenderables(n,t,e){this.parentRenderLayer&&this.parentRenderLayer!==e||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(n,t,e):this.renderGroup?t.renderPipes.renderGroup.addRenderGroup(this.renderGroup,n):this.collectRenderablesWithEffects(n,t,e))},collectRenderablesSimple(n,t,e){const i=this.children,s=i.length;for(let r=0;r<s;r++)i[r].collectRenderables(n,t,e)},collectRenderablesWithEffects(n,t,e){const{renderPipes:i}=t;for(let s=0;s<this.effects.length;s++){const r=this.effects[s];i[r.pipe].push(r,this,n)}this.collectRenderablesSimple(n,t,e);for(let s=this.effects.length-1;s>=0;s--){const r=this.effects[s];i[r.pipe].pop(r,this,n)}}};class To{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let t=0;t<this.filters.length;t++)this.filters[t].destroy();this.filters=null,this.filterArea=null}}class iu{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(t=>{this.add({test:t.test,maskClass:t})}))}add(t){this._tests.push(t)}getMaskEffect(t){this._initialized||this.init();for(let e=0;e<this._tests.length;e++){const i=this._tests[e];if(i.test(t))return At.get(i.maskClass,t)}return t}returnMaskEffect(t){At.return(t)}}const Xn=new iu;q.handleByList(E.MaskEffect,Xn._effectClasses);const su={_maskEffect:null,_maskOptions:{inverse:!1},_filterEffect:null,effects:[],_markStructureAsChanged(){const n=this.renderGroup||this.parentRenderGroup;n&&(n.structureDidChange=!0)},addEffect(n){this.effects.indexOf(n)===-1&&(this.effects.push(n),this.effects.sort((e,i)=>e.priority-i.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(n){const t=this.effects.indexOf(n);t!==-1&&(this.effects.splice(t,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(n){const t=this._maskEffect;(t==null?void 0:t.mask)!==n&&(t&&(this.removeEffect(t),Xn.returnMaskEffect(t),this._maskEffect=null),n!=null&&(this._maskEffect=Xn.getMaskEffect(n),this.addEffect(this._maskEffect)))},get mask(){var n;return(n=this._maskEffect)==null?void 0:n.mask},setMask(n){this._maskOptions={...this._maskOptions,...n},n.mask&&(this.mask=n.mask),this._markStructureAsChanged()},set filters(n){var r;!Array.isArray(n)&&n&&(n=[n]);const t=this._filterEffect||(this._filterEffect=new To);n=n;const e=(n==null?void 0:n.length)>0,i=((r=t.filters)==null?void 0:r.length)>0,s=e!==i;n=Array.isArray(n)?n.slice(0):n,t.filters=Object.freeze(n),s&&(e?this.addEffect(t):(this.removeEffect(t),t.filters=n??null))},get filters(){var n;return(n=this._filterEffect)==null?void 0:n.filters},set filterArea(n){this._filterEffect||(this._filterEffect=new To),this._filterEffect.filterArea=n},get filterArea(){var n;return(n=this._filterEffect)==null?void 0:n.filterArea}},nu={label:null,get name(){return V(K,"Container.name property has been removed, use Container.label instead"),this.label},set name(n){V(K,"Container.name property has been removed, use Container.label instead"),this.label=n},getChildByName(n,t=!1){return this.getChildByLabel(n,t)},getChildByLabel(n,t=!1){const e=this.children;for(let i=0;i<e.length;i++){const s=e[i];if(s.label===n||n instanceof RegExp&&n.test(s.label))return s}if(t)for(let i=0;i<e.length;i++){const r=e[i].getChildByLabel(n,!0);if(r)return r}return null},getChildrenByLabel(n,t=!1,e=[]){const i=this.children;for(let s=0;s<i.length;s++){const r=i[s];(r.label===n||n instanceof RegExp&&n.test(r.label))&&e.push(r)}if(t)for(let s=0;s<i.length;s++)i[s].getChildrenByLabel(n,!0,e);return e}},_t=At.getPool(U),ee=At.getPool(Ft),ru=new U,ou={getFastGlobalBounds(n,t){t||(t=new Ft),t.clear(),this._getGlobalBoundsRecursive(!!n,t,this.parentRenderLayer),t.isValid||t.set(0,0,0,0);const e=this.renderGroup||this.parentRenderGroup;return t.applyMatrix(e.worldTransform),t},_getGlobalBoundsRecursive(n,t,e){let i=t;if(n&&this.parentRenderLayer&&this.parentRenderLayer!==e||this.localDisplayStatus!==7||!this.measurable)return;const s=!!this.effects.length;if((this.renderGroup||s)&&(i=ee.get().clear()),this.boundsArea)t.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const o=this.bounds;i.addFrame(o.minX,o.minY,o.maxX,o.maxY,this.groupTransform)}const r=this.children;for(let o=0;o<r.length;o++)r[o]._getGlobalBoundsRecursive(n,i,e)}if(s){let r=!1;const o=this.renderGroup||this.parentRenderGroup;for(let a=0;a<this.effects.length;a++)this.effects[a].addBounds&&(r||(r=!0,i.applyMatrix(o.worldTransform)),this.effects[a].addBounds(i,!0));r&&i.applyMatrix(o.worldTransform.copyTo(ru).invert()),t.addBounds(i),ee.return(i)}else this.renderGroup&&(t.addBounds(i,this.relativeGroupTransform),ee.return(i))}};function Lh(n,t,e){e.clear();let i,s;return n.parent?t?i=n.parent.worldTransform:(s=_t.get().identity(),i=Cr(n,s)):i=U.IDENTITY,Oh(n,e,i,t),s&&_t.return(s),e.isValid||e.set(0,0,0,0),e}function Oh(n,t,e,i){var a,h;if(!n.visible||!n.measurable)return;let s;i?s=n.worldTransform:(n.updateLocalTransform(),s=_t.get(),s.appendFrom(n.localTransform,e));const r=t,o=!!n.effects.length;if(o&&(t=ee.get().clear()),n.boundsArea)t.addRect(n.boundsArea,s);else{const l=n.bounds;l&&!l.isEmpty()&&(t.matrix=s,t.addBounds(l));for(let c=0;c<n.children.length;c++)Oh(n.children[c],t,s,i)}if(o){for(let l=0;l<n.effects.length;l++)(h=(a=n.effects[l]).addBounds)==null||h.call(a,t);r.addBounds(t,U.IDENTITY),ee.return(t)}i||_t.return(s)}function Cr(n,t){const e=n.parent;return e&&(Cr(e,t),e.updateLocalTransform(),t.append(e.localTransform)),t}function _r(n,t){if(n===16777215||!t)return t;if(t===16777215||!n)return n;const e=n>>16&255,i=n>>8&255,s=n&255,r=t>>16&255,o=t>>8&255,a=t&255,h=e*r/255|0,l=i*o/255|0,c=s*a/255|0;return(h<<16)+(l<<8)+c}const Ao=16777215;function Ro(n,t){return n===Ao?t:t===Ao?n:_r(n,t)}function _i(n){return((n&255)<<16)+(n&65280)+(n>>16&255)}const au={getGlobalAlpha(n){if(n)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let t=this.alpha,e=this.parent;for(;e;)t*=e.alpha,e=e.parent;return t},getGlobalTransform(n=new U,t){if(t)return n.copyFrom(this.worldTransform);this.updateLocalTransform();const e=Cr(this,_t.get().identity());return n.appendFrom(this.localTransform,e),_t.return(e),n},getGlobalTint(n){if(n)return this.renderGroup?_i(this.renderGroup.worldColor):this.parentRenderGroup?_i(Ro(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let t=this.localColor,e=this.parent;for(;e;)t=Ro(t,e.localColor),e=e.parent;return _i(t)}};function Wh(n,t,e){return t.clear(),e||(e=U.IDENTITY),Gh(n,t,e,n,!0),t.isValid||t.set(0,0,0,0),t}function Gh(n,t,e,i,s){var h,l;let r;if(s)r=_t.get(),r=e.copyTo(r);else{if(!n.visible||!n.measurable)return;n.updateLocalTransform();const c=n.localTransform;r=_t.get(),r.appendFrom(c,e)}const o=t,a=!!n.effects.length;if(a&&(t=ee.get().clear()),n.boundsArea)t.addRect(n.boundsArea,r);else{n.renderPipeId&&(t.matrix=r,t.addBounds(n.bounds));const c=n.children;for(let d=0;d<c.length;d++)Gh(c[d],t,r,i,!1)}if(a){for(let c=0;c<n.effects.length;c++)(l=(h=n.effects[c]).addLocalBounds)==null||l.call(h,t,i);o.addBounds(t,U.IDENTITY),ee.return(t)}_t.return(r)}function Uh(n,t){const e=n.children;for(let i=0;i<e.length;i++){const s=e[i],r=s.uid,o=(s._didViewChangeTick&65535)<<16|s._didContainerChangeTick&65535,a=t.index;(t.data[a]!==r||t.data[a+1]!==o)&&(t.data[t.index]=r,t.data[t.index+1]=o,t.didChange=!0),t.index=a+2,s.children.length&&Uh(s,t)}return t.didChange}const hu=new U,lu={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(n,t){const e=Math.sign(this.scale.x)||1;t!==0?this.scale.x=n/t*e:this.scale.x=e},_setHeight(n,t){const e=Math.sign(this.scale.y)||1;t!==0?this.scale.y=n/t*e:this.scale.y=e},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Ft});const n=this._localBoundsCacheData;return n.index=1,n.didChange=!1,n.data[0]!==this._didViewChangeTick&&(n.didChange=!0,n.data[0]=this._didViewChangeTick),Uh(this,n),n.didChange&&Wh(this,n.localBounds,hu),n.localBounds},getBounds(n,t){return Lh(this,n,t||new Ft)}},cu={_onRender:null,set onRender(n){const t=this.renderGroup||this.parentRenderGroup;if(!n){this._onRender&&(t==null||t.removeOnRender(this)),this._onRender=null;return}this._onRender||t==null||t.addOnRender(this),this._onRender=n},get onRender(){return this._onRender}},du={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(n){this._zIndex!==n&&(this._zIndex=n,this.depthOfChildModified())},depthOfChildModified(){this.parent&&(this.parent.sortableChildren=!0,this.parent.sortDirty=!0),this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0)},sortChildren(){this.sortDirty&&(this.sortDirty=!1,this.children.sort(uu))}};function uu(n,t){return n._zIndex-t._zIndex}const pu={getGlobalPosition(n=new Q,t=!1){return this.parent?this.parent.toGlobal(this._position,n,t):(n.x=this._position.x,n.y=this._position.y),n},toGlobal(n,t,e=!1){const i=this.getGlobalTransform(_t.get(),e);return t=i.apply(n,t),_t.return(i),t},toLocal(n,t,e,i){t&&(n=t.toGlobal(n,e,i));const s=this.getGlobalTransform(_t.get(),i);return e=s.applyInverse(n,e),_t.return(s),e}};class Pr{constructor(){this.uid=ct("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(t){this.instructions[this.instructionSize++]=t}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let fu=0;class gu{constructor(t){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this.textureStyle=new Je(this.textureOptions)}createTexture(t,e,i){const s=new zt({...this.textureOptions,width:t,height:e,resolution:1,antialias:i,autoGarbageCollect:!1});return new G({source:s,label:`texturePool_${fu++}`})}getOptimalTexture(t,e,i=1,s){let r=Math.ceil(t*i-1e-6),o=Math.ceil(e*i-1e-6);r=Qe(r),o=Qe(o);const a=(r<<17)+(o<<1)+(s?1:0);this._texturePool[a]||(this._texturePool[a]=[]);let h=this._texturePool[a].pop();return h||(h=this.createTexture(r,o,s)),h.source._resolution=i,h.source.width=r/i,h.source.height=o/i,h.source.pixelWidth=r,h.source.pixelHeight=o,h.frame.x=0,h.frame.y=0,h.frame.width=t,h.frame.height=e,h.updateUvs(),this._poolKeyHash[h.uid]=a,h}getSameSizeTexture(t,e=!1){const i=t.source;return this.getOptimalTexture(t.width,t.height,i._resolution,e)}returnTexture(t,e=!1){const i=this._poolKeyHash[t.uid];e&&(t.source.style=this.textureStyle),this._texturePool[i].push(t)}clear(t){if(t=t!==!1,t)for(const e in this._texturePool){const i=this._texturePool[e];if(i)for(let s=0;s<i.length;s++)i[s].destroy(!0)}this._texturePool={}}}const Is=new gu;Hi.register(Is);class mu{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new U,this.worldColorAlpha=4294967295,this.worldColor=16777215,this.worldAlpha=1,this.childrenToUpdate=Object.create(null),this.updateTick=0,this.gcTick=0,this.childrenRenderablesToUpdate={list:[],index:0},this.structureDidChange=!0,this.instructionSet=new Pr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(t){this.root=t,t._onRender&&this.addOnRender(t),t.didChange=!0;const e=t.children;for(let i=0;i<e.length;i++){const s=e[i];s._updateFlags=15,this.addChild(s)}}enableCacheAsTexture(t={}){this.textureOptions=t,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Is.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const t=this._parentCacheAsTextureRenderGroup;t&&!t.textureNeedsUpdate&&t.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const t in this.childrenToUpdate){const e=this.childrenToUpdate[t];e.list.fill(null),e.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(t){t.renderGroupParent&&t.renderGroupParent._removeRenderGroupChild(t),t.renderGroupParent=this,this.renderGroupChildren.push(t)}_removeRenderGroupChild(t){const e=this.renderGroupChildren.indexOf(t);e>-1&&this.renderGroupChildren.splice(e,1),t.renderGroupParent=null}addChild(t){if(this.structureDidChange=!0,t.parentRenderGroup=this,t.updateTick=-1,t.parent===this.root?t.relativeRenderGroupDepth=1:t.relativeRenderGroupDepth=t.parent.relativeRenderGroupDepth+1,t.didChange=!0,this.onChildUpdate(t),t.renderGroup){this.addRenderGroupChild(t.renderGroup);return}t._onRender&&this.addOnRender(t);const e=t.children;for(let i=0;i<e.length;i++)this.addChild(e[i])}removeChild(t){if(this.structureDidChange=!0,t._onRender&&(t.renderGroup||this.removeOnRender(t)),t.parentRenderGroup=null,t.renderGroup){this._removeRenderGroupChild(t.renderGroup);return}const e=t.children;for(let i=0;i<e.length;i++)this.removeChild(e[i])}removeChildren(t){for(let e=0;e<t.length;e++)this.removeChild(t[e])}onChildUpdate(t){let e=this.childrenToUpdate[t.relativeRenderGroupDepth];e||(e=this.childrenToUpdate[t.relativeRenderGroupDepth]={index:0,list:[]}),e.list[e.index++]=t}updateRenderable(t){t.globalDisplayStatus<7||(this.instructionSet.renderPipes[t.renderPipeId].updateRenderable(t),t.didViewUpdate=!1)}onChildViewUpdate(t){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=t}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(t){this._onRenderContainers.push(t)}removeOnRender(t){this._onRenderContainers.splice(this._onRenderContainers.indexOf(t),1)}runOnRender(t){for(let e=0;e<this._onRenderContainers.length;e++)this._onRenderContainers[e]._onRender(t)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet=null}getChildren(t=[]){const e=this.root.children;for(let i=0;i<e.length;i++)this._getChildren(e[i],t);return t}_getChildren(t,e=[]){if(e.push(t),t.renderGroup)return e;const i=t.children;for(let s=0;s<i.length;s++)this._getChildren(i[s],e);return e}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return this._matrixDirty&1?(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new U),this._inverseWorldTransform.copyFrom(this.worldTransform).invert()):this._inverseWorldTransform}get textureOffsetInverseTransform(){return this._matrixDirty&2?(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new U),this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y)):this._textureOffsetInverseTransform}get inverseParentTextureTransform(){if(!(this._matrixDirty&4))return this._inverseParentTextureTransform;this._matrixDirty&=-5;const t=this._parentCacheAsTextureRenderGroup;return t?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new U),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(t.inverseWorldTransform).translate(-t._textureBounds.x,-t._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function yu(n,t,e={}){for(const i in t)!e[i]&&t[i]!==void 0&&(n[i]=t[i])}const nn=new lt(null),Qi=new lt(null),rn=new lt(null,1,1),Ji=new lt(null),ko=1,xu=2,on=4;class W extends Zt{constructor(t={}){var e,i;super(),this.uid=ct("renderable"),this._updateFlags=15,this.renderGroup=null,this.parentRenderGroup=null,this.parentRenderGroupIndex=0,this.didChange=!1,this.didViewUpdate=!1,this.relativeRenderGroupDepth=0,this.children=[],this.parent=null,this.includeInBuild=!0,this.measurable=!0,this.isSimple=!0,this.parentRenderLayer=null,this.updateTick=-1,this.localTransform=new U,this.relativeGroupTransform=new U,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new lt(this,0,0),this._scale=rn,this._pivot=Qi,this._origin=Ji,this._skew=nn,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._rotation=0,this.localColor=16777215,this.localAlpha=1,this.groupAlpha=1,this.groupColor=16777215,this.groupColorAlpha=4294967295,this.localBlendMode="inherit",this.groupBlendMode="normal",this.localDisplayStatus=7,this.globalDisplayStatus=7,this._didContainerChangeTick=0,this._didViewChangeTick=0,this._didLocalTransformChangeId=-1,this.effects=[],yu(this,t,{children:!0,parent:!0,effects:!0}),(e=t.children)==null||e.forEach(s=>this.addChild(s)),(i=t.parent)==null||i.addChild(this)}static mixin(t){V("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),q.mixin(W,t)}set _didChangeId(t){this._didViewChangeTick=t>>12&4095,this._didContainerChangeTick=t&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...t){if(this.allowChildren||V(K,"addChild: Only Containers will be allowed to add children in v8.0.0"),t.length>1){for(let s=0;s<t.length;s++)this.addChild(t[s]);return t[0]}const e=t[0],i=this.renderGroup||this.parentRenderGroup;return e.parent===this?(this.children.splice(this.children.indexOf(e),1),this.children.push(e),i&&(i.structureDidChange=!0),e):(e.parent&&e.parent.removeChild(e),this.children.push(e),this.sortableChildren&&(this.sortDirty=!0),e.parent=this,e.didChange=!0,e._updateFlags=15,i&&i.addChild(e),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this),this._didViewChangeTick++,e._zIndex!==0&&e.depthOfChildModified(),e)}removeChild(...t){if(t.length>1){for(let s=0;s<t.length;s++)this.removeChild(t[s]);return t[0]}const e=t[0],i=this.children.indexOf(e);return i>-1&&(this._didViewChangeTick++,this.children.splice(i,1),this.renderGroup?this.renderGroup.removeChild(e):this.parentRenderGroup&&this.parentRenderGroup.removeChild(e),e.parentRenderLayer&&e.parentRenderLayer.detach(e),e.parent=null,this.emit("childRemoved",e,this,i),e.emit("removed",this)),e}_onUpdate(t){t&&t===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(t){!!this.renderGroup!==t&&(t?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),this.renderGroup=At.get(mu,this),this.groupTransform=U.IDENTITY,t==null||t.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),At.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,t==null||t.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||(this._worldTransform=new U),this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(t){this._position.x=t}get y(){return this._position.y}set y(t){this._position.y=t}get position(){return this._position}set position(t){this._position.copyFrom(t)}get rotation(){return this._rotation}set rotation(t){this._rotation!==t&&(this._rotation=t,this._onUpdate(this._skew))}get angle(){return this.rotation*Id}set angle(t){this.rotation=t*Dd}get pivot(){return this._pivot===Qi&&(this._pivot=new lt(this,0,0)),this._pivot}set pivot(t){this._pivot===Qi&&(this._pivot=new lt(this,0,0),this._origin!==Ji&&st("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._pivot.set(t):this._pivot.copyFrom(t)}get skew(){return this._skew===nn&&(this._skew=new lt(this,0,0)),this._skew}set skew(t){this._skew===nn&&(this._skew=new lt(this,0,0)),this._skew.copyFrom(t)}get scale(){return this._scale===rn&&(this._scale=new lt(this,1,1)),this._scale}set scale(t){this._scale===rn&&(this._scale=new lt(this,0,0)),typeof t=="string"&&(t=parseFloat(t)),typeof t=="number"?this._scale.set(t):this._scale.copyFrom(t)}get origin(){return this._origin===Ji&&(this._origin=new lt(this,0,0)),this._origin}set origin(t){this._origin===Ji&&(this._origin=new lt(this,0,0),this._pivot!==Qi&&st("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._origin.set(t):this._origin.copyFrom(t)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(t){const e=this.getLocalBounds().width;this._setWidth(t,e)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(t){const e=this.getLocalBounds().height;this._setHeight(t,e)}getSize(t){t||(t={});const e=this.getLocalBounds();return t.width=Math.abs(this.scale.x*e.width),t.height=Math.abs(this.scale.y*e.height),t}setSize(t,e){const i=this.getLocalBounds();typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,i.width),e!==void 0&&this._setHeight(e,i.height)}_updateSkew(){const t=this._rotation,e=this._skew;this._cx=Math.cos(t+e._y),this._sx=Math.sin(t+e._y),this._cy=-Math.sin(t-e._x),this._sy=Math.cos(t-e._x)}updateTransform(t){return this.position.set(typeof t.x=="number"?t.x:this.position.x,typeof t.y=="number"?t.y:this.position.y),this.scale.set(typeof t.scaleX=="number"?t.scaleX||1:this.scale.x,typeof t.scaleY=="number"?t.scaleY||1:this.scale.y),this.rotation=typeof t.rotation=="number"?t.rotation:this.rotation,this.skew.set(typeof t.skewX=="number"?t.skewX:this.skew.x,typeof t.skewY=="number"?t.skewY:this.skew.y),this.pivot.set(typeof t.pivotX=="number"?t.pivotX:this.pivot.x,typeof t.pivotY=="number"?t.pivotY:this.pivot.y),this.origin.set(typeof t.originX=="number"?t.originX:this.origin.x,typeof t.originY=="number"?t.originY:this.origin.y),this}setFromMatrix(t){t.decompose(this)}updateLocalTransform(){const t=this._didContainerChangeTick;if(this._didLocalTransformChangeId===t)return;this._didLocalTransformChangeId=t;const e=this.localTransform,i=this._scale,s=this._pivot,r=this._origin,o=this._position,a=i._x,h=i._y,l=s._x,c=s._y,d=-r._x,u=-r._y;e.a=this._cx*a,e.b=this._sx*a,e.c=this._cy*h,e.d=this._sy*h,e.tx=o._x-(l*e.a+c*e.c)+(d*e.a+u*e.c)-d,e.ty=o._y-(l*e.b+c*e.d)+(d*e.b+u*e.d)-u}set alpha(t){t!==this.localAlpha&&(this.localAlpha=t,this._updateFlags|=ko,this._onUpdate())}get alpha(){return this.localAlpha}set tint(t){const i=nt.shared.setValue(t??16777215).toBgrNumber();i!==this.localColor&&(this.localColor=i,this._updateFlags|=ko,this._onUpdate())}get tint(){return _i(this.localColor)}set blendMode(t){this.localBlendMode!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=xu,this.localBlendMode=t,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(t){const e=t?2:0;(this.localDisplayStatus&2)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=on,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(t){const e=t?0:4;(this.localDisplayStatus&4)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=on,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(t){const e=t?1:0;(this.localDisplayStatus&1)!==e&&(this._updateFlags|=on,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(t=!1){var s;if(this.destroyed)return;this.destroyed=!0;let e;if(this.children.length&&(e=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit("destroyed",this),this.removeAllListeners(),(typeof t=="boolean"?t:t==null?void 0:t.children)&&e)for(let r=0;r<e.length;++r)e[r].destroy(t);(s=this.renderGroup)==null||s.destroy(),this.renderGroup=null}}q.mixin(W,tu,ou,pu,cu,lu,su,nu,du,Zd,Qd,au,eu);class oi extends W{constructor(t){super(t),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this._bounds=new Ft(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=t.autoGarbageCollect??!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(t){this._roundPixels=t?1:0}containsPoint(t){const e=this.bounds,{x:i,y:s}=t;return i>=e.minX&&i<=e.maxX&&s>=e.minY&&s<=e.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const t=this.renderGroup||this.parentRenderGroup;t&&t.onChildViewUpdate(this)}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(t){this.unload(),super.destroy(t),this._bounds=null}collectRenderablesSimple(t,e,i){const{renderPipes:s}=e;s.blendMode.pushBlendMode(this,this.groupBlendMode,t);const o=s[this.renderPipeId];o!=null&&o.addRenderable&&o.addRenderable(this,t),this.didViewUpdate=!1;const a=this.children,h=a.length;for(let l=0;l<h;l++)a[l].collectRenderables(t,e,i);s.blendMode.popBlendMode(t)}}class jt extends oi{constructor(t=G.EMPTY){t instanceof G&&(t={texture:t});const{texture:e=G.EMPTY,anchor:i,roundPixels:s,width:r,height:o,...a}=t;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new lt({_onUpdate:()=>{this.onViewUpdate()}}),i?this.anchor=i:e.defaultAnchor&&(this.anchor=e.defaultAnchor),this.texture=e,this.allowChildren=!1,this.roundPixels=s??!1,r!==void 0&&(this.width=r),o!==void 0&&(this.height=o)}static from(t,e=!1){return t instanceof G?new jt(t):new jt(G.from(t,e))}set texture(t){t||(t=G.EMPTY);const e=this._texture;e!==t&&(e&&e.dynamic&&e.off("update",this.onViewUpdate,this),t.dynamic&&t.on("update",this.onViewUpdate,this),this._texture=t,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return Dh(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return V("8.6.1","Sprite.sourceBounds is deprecated, use visualBounds instead."),this.visualBounds}updateBounds(){const t=this._anchor,e=this._texture,i=this._bounds,{width:s,height:r}=e.orig;i.minX=-t._x*s,i.maxX=i.minX+s,i.minY=-t._y*r,i.maxY=i.minY+r}destroy(t=!1){if(super.destroy(t),typeof t=="boolean"?t:t==null?void 0:t.texture){const i=typeof t=="boolean"?t:t==null?void 0:t.textureSource;this._texture.destroy(i)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this._setWidth(t,this._texture.orig.width),this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this._setHeight(t,this._texture.orig.height),this._height=t}getSize(t){return t||(t={}),t.width=Math.abs(this.scale.x)*this._texture.orig.width,t.height=Math.abs(this.scale.y)*this._texture.orig.height,t}setSize(t,e){typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,this._texture.orig.width),e!==void 0&&this._setHeight(e,this._texture.orig.height)}}const Su=new Ft;function Hh(n,t,e){const i=Su;n.measurable=!0,Lh(n,e,i),t.addBoundsMask(i),n.measurable=!1}function Vh(n,t,e){const i=ee.get();n.measurable=!0;const s=_t.get().identity(),r=Nh(n,e,s);Wh(n,i,r),n.measurable=!1,t.addBoundsMask(i),_t.return(s),ee.return(i)}function Nh(n,t,e){return n?(n!==t&&(Nh(n.parent,t,e),n.updateLocalTransform(),e.append(n.localTransform)),e):(st("Mask bounds, renderable is not inside the root container"),e)}class $h{constructor(t){this.priority=0,this.inverse=!1,this.pipe="alphaMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.renderMaskToTexture=!(t instanceof jt),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask=null)}addBounds(t,e){this.inverse||Hh(this.mask,t,e)}addLocalBounds(t,e){Vh(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof jt}}$h.extension=E.MaskEffect;class Yh{constructor(t){this.priority=0,this.pipe="colorMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t}destroy(){}static test(t){return typeof t=="number"}}Yh.extension=E.MaskEffect;class Xh{constructor(t){this.priority=0,this.pipe="stencilMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(t,e){Hh(this.mask,t,e)}addLocalBounds(t,e){Vh(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof W}}Xh.extension=E.MaskEffect;const vu={createCanvas:(n,t)=>{const e=document.createElement("canvas");return e.width=n,e.height=t,e},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(n,t)=>fetch(n,t),parseXML:n=>new DOMParser().parseFromString(n,"text/xml")};let Eo=vu;const $={get(){return Eo},set(n){Eo=n}};class Mr extends zt{constructor(t){t.resource||(t.resource=$.get().createCanvas()),t.width||(t.width=t.resource.width,t.autoDensity||(t.width/=t.resolution)),t.height||(t.height=t.resource.height,t.autoDensity||(t.height/=t.resolution)),super(t),this.uploadMethodId="image",this.autoDensity=t.autoDensity,this.resizeCanvas(),this.transparent=!!t.transparent}resizeCanvas(){this.autoDensity&&"style"in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(t=this.width,e=this.height,i=this._resolution){const s=super.resize(t,e,i);return s&&this.resizeCanvas(),s}static test(t){return globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&t instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}Mr.extension=E.TextureSource;class ei extends zt{constructor(t){super(t),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(t){return globalThis.HTMLImageElement&&t instanceof HTMLImageElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap||globalThis.VideoFrame&&t instanceof VideoFrame}}ei.extension=E.TextureSource;var Fe=(n=>(n[n.INTERACTION=50]="INTERACTION",n[n.HIGH=25]="HIGH",n[n.NORMAL=0]="NORMAL",n[n.LOW=-25]="LOW",n[n.UTILITY=-50]="UTILITY",n))(Fe||{});class an{constructor(t,e=null,i=0,s=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=t,this._context=e,this.priority=i,this._once=s}match(t,e=null){return this._fn===t&&this._context===e}emit(t){this._fn&&(this._context?this._fn.call(this._context,t):this._fn(t));const e=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const jh=class Rt{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new an(null,null,1/0),this.deltaMS=1/Rt.targetFPMS,this.elapsedMS=1/Rt.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=Fe.NORMAL){return this._addListener(new an(t,e,i))}addOnce(t,e,i=Fe.NORMAL){return this._addListener(new an(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(!e)t.connect(i);else{for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i.match(t,e)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let e;if(t>this.lastTime){if(e=this.elapsedMS=t-this.lastTime,e>this._maxElapsedMS&&(e=this._maxElapsedMS),e*=this.speed,this._minElapsedMS){const r=t-this._lastFrame|0;if(r<this._minElapsedMS)return;this._lastFrame=t-r%this._minElapsedMS}this.deltaMS=e,this.deltaTime=this.deltaMS*Rt.targetFPMS;const i=this._head;let s=i.next;for(;s;)s=s.emit(this);i.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){const e=Math.min(this.maxFPS,t),i=Math.min(Math.max(0,e)/1e3,Rt.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(t===0)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!Rt._shared){const t=Rt._shared=new Rt;t.autoStart=!0,t._protected=!0}return Rt._shared}static get system(){if(!Rt._system){const t=Rt._system=new Rt;t.autoStart=!0,t._protected=!0}return Rt._system}};jh.targetFPMS=.06;let mt=jh,hn;async function Zh(){return hn??(hn=(async()=>{var o;const t=$.get().createCanvas(1,1).getContext("webgl");if(!t)return"premultiply-alpha-on-upload";const e=await new Promise(a=>{const h=document.createElement("video");h.onloadeddata=()=>a(h),h.onerror=()=>a(null),h.autoplay=!1,h.crossOrigin="anonymous",h.preload="auto",h.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",h.load()});if(!e)return"premultiply-alpha-on-upload";const i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);const s=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i,0),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.NONE),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e);const r=new Uint8Array(4);return t.readPixels(0,0,1,1,t.RGBA,t.UNSIGNED_BYTE,r),t.deleteFramebuffer(s),t.deleteTexture(i),(o=t.getExtension("WEBGL_lose_context"))==null||o.loseContext(),r[0]<=r[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),hn}const Ds=class qh extends zt{constructor(t){super(t),this.isReady=!1,this.uploadMethodId="video",t={...qh.defaultOptions,...t},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=t.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=t.autoPlay!==!1,this.alphaMode=t.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),t.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const t=mt.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-t)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const t=this.resource,e=this.options;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(e.preload||t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlayThrough),t.addEventListener("error",this._onError,!0)),this.alphaMode=await Zh(),this._load=new Promise((i,s)=>{this.isValid?i(this):(this._resolve=i,this._reject=s,e.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${e.preloadTimeoutMs}ms`))})),t.load())}),this._load}_onError(t){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.resource;return!t.paused&&!t.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this.isValid||this._mediaReady(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlay),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const t=this.resource;this.isValid&&(this.isReady=!0,this.resize(t.videoWidth,t.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const t=this.resource;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlayThrough),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(mt.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(mt.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(mt.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(t){return globalThis.HTMLVideoElement&&t instanceof HTMLVideoElement}};Ds.extension=E.TextureSource;Ds.defaultOptions={...zt.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};Ds.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let Pi=Ds;const Ot=(n,t,e=!1)=>(Array.isArray(n)||(n=[n]),t?n.map(i=>typeof i=="string"||e?t(i):i):n);class bu{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(t){return this._cache.has(t)}get(t){const e=this._cache.get(t);return e||st(`[Assets] Asset id ${t} was not found in the Cache`),e}set(t,e){const i=Ot(t);let s;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.test(e)){s=l.getCacheableAssets(i,e);break}}const r=new Map(Object.entries(s||{}));s||i.forEach(h=>{r.set(h,e)});const o=[...r.keys()],a={cacheKeys:o,keys:i};i.forEach(h=>{this._cacheMap.set(h,a)}),o.forEach(h=>{const l=s?s[h]:e;this._cache.has(h)&&this._cache.get(h)!==l&&st("[Cache] already has key:",h),this._cache.set(h,r.get(h))})}remove(t){if(!this._cacheMap.has(t)){st(`[Assets] Asset id ${t} was not found in the Cache`);return}const e=this._cacheMap.get(t);e.cacheKeys.forEach(s=>{this._cache.delete(s)}),e.keys.forEach(s=>{this._cacheMap.delete(s)})}get parsers(){return this._parsers}}const yt=new bu,jn=[];q.handleByList(E.TextureSource,jn);function Kh(n={}){const t=n&&n.resource,e=t?n.resource:n,i=t?n:{resource:n};for(let s=0;s<jn.length;s++){const r=jn[s];if(r.test(e))return new r(i)}throw new Error(`Could not find a source type for resource: ${i.resource}`)}function wu(n={},t=!1){const e=n&&n.resource,i=e?n.resource:n,s=e?n:{resource:n};if(!t&&yt.has(i))return yt.get(i);const r=new G({source:Kh(s)});return r.on("destroy",()=>{yt.has(i)&&yt.remove(i)}),t||yt.set(i,r),r}function Cu(n,t=!1){return typeof n=="string"?yt.get(n):n instanceof zt?new G({source:n}):wu(n,t)}G.from=Cu;zt.from=Kh;q.add($h,Yh,Xh,Pi,ei,Mr,wr);var ue=(n=>(n[n.Low=0]="Low",n[n.Normal=1]="Normal",n[n.High=2]="High",n))(ue||{});function Lt(n){if(typeof n!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(n)}`)}function ci(n){return n.split("?")[0].split("#")[0]}function _u(n){return n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Pu(n,t,e){return n.replace(new RegExp(_u(t),"g"),e)}function Mu(n,t){let e="",i=0,s=-1,r=0,o=-1;for(let a=0;a<=n.length;++a){if(a<n.length)o=n.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(s===a-1||r===1))if(s!==a-1&&r===2){if(e.length<2||i!==2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){const h=e.lastIndexOf("/");if(h!==e.length-1){h===-1?(e="",i=0):(e=e.slice(0,h),i=e.length-1-e.lastIndexOf("/")),s=a,r=0;continue}}else if(e.length===2||e.length===1){e="",i=0,s=a,r=0;continue}}}else e.length>0?e+=`/${n.slice(s+1,a)}`:e=n.slice(s+1,a),i=a-s-1;s=a,r=0}else o===46&&r!==-1?++r:r=-1}return e}const Mt={toPosix(n){return Pu(n,"\\","/")},isUrl(n){return/^https?:/.test(this.toPosix(n))},isDataUrl(n){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(n)},isBlobUrl(n){return n.startsWith("blob:")},hasProtocol(n){return/^[^/:]+:/.test(this.toPosix(n))},getProtocol(n){Lt(n),n=this.toPosix(n);const t=/^file:\/\/\//.exec(n);if(t)return t[0];const e=/^[^/:]+:\/{0,2}/.exec(n);return e?e[0]:""},toAbsolute(n,t,e){if(Lt(n),this.isDataUrl(n)||this.isBlobUrl(n))return n;const i=ci(this.toPosix(t??$.get().getBaseUrl())),s=ci(this.toPosix(e??this.rootname(i)));return n=this.toPosix(n),n.startsWith("/")?Mt.join(s,n.slice(1)):this.isAbsolute(n)?n:this.join(i,n)},normalize(n){if(Lt(n),n.length===0)return".";if(this.isDataUrl(n)||this.isBlobUrl(n))return n;n=this.toPosix(n);let t="";const e=n.startsWith("/");this.hasProtocol(n)&&(t=this.rootname(n),n=n.slice(t.length));const i=n.endsWith("/");return n=Mu(n),n.length>0&&i&&(n+="/"),e?`/${n}`:t+n},isAbsolute(n){return Lt(n),n=this.toPosix(n),this.hasProtocol(n)?!0:n.startsWith("/")},join(...n){if(n.length===0)return".";let t;for(let e=0;e<n.length;++e){const i=n[e];if(Lt(i),i.length>0)if(t===void 0)t=i;else{const s=n[e-1]??"";this.joinExtensions.includes(this.extname(s).toLowerCase())?t+=`/../${i}`:t+=`/${i}`}}return t===void 0?".":this.normalize(t)},dirname(n){if(Lt(n),n.length===0)return".";n=this.toPosix(n);let t=n.charCodeAt(0);const e=t===47;let i=-1,s=!0;const r=this.getProtocol(n),o=n;n=n.slice(r.length);for(let a=n.length-1;a>=1;--a)if(t=n.charCodeAt(a),t===47){if(!s){i=a;break}}else s=!1;return i===-1?e?"/":this.isUrl(o)?r+n:r:e&&i===1?"//":r+n.slice(0,i)},rootname(n){Lt(n),n=this.toPosix(n);let t="";if(n.startsWith("/")?t="/":t=this.getProtocol(n),this.isUrl(n)){const e=n.indexOf("/",t.length);e!==-1?t=n.slice(0,e):t=n,t.endsWith("/")||(t+="/")}return t},basename(n,t){Lt(n),t&&Lt(t),n=ci(this.toPosix(n));let e=0,i=-1,s=!0,r;if(t!==void 0&&t.length>0&&t.length<=n.length){if(t.length===n.length&&t===n)return"";let o=t.length-1,a=-1;for(r=n.length-1;r>=0;--r){const h=n.charCodeAt(r);if(h===47){if(!s){e=r+1;break}}else a===-1&&(s=!1,a=r+1),o>=0&&(h===t.charCodeAt(o)?--o===-1&&(i=r):(o=-1,i=a))}return e===i?i=a:i===-1&&(i=n.length),n.slice(e,i)}for(r=n.length-1;r>=0;--r)if(n.charCodeAt(r)===47){if(!s){e=r+1;break}}else i===-1&&(s=!1,i=r+1);return i===-1?"":n.slice(e,i)},extname(n){Lt(n),n=ci(this.toPosix(n));let t=-1,e=0,i=-1,s=!0,r=0;for(let o=n.length-1;o>=0;--o){const a=n.charCodeAt(o);if(a===47){if(!s){e=o+1;break}continue}i===-1&&(s=!1,i=o+1),a===46?t===-1?t=o:r!==1&&(r=1):t!==-1&&(r=-1)}return t===-1||i===-1||r===0||r===1&&t===i-1&&t===e+1?"":n.slice(t,i)},parse(n){Lt(n);const t={root:"",dir:"",base:"",ext:"",name:""};if(n.length===0)return t;n=ci(this.toPosix(n));let e=n.charCodeAt(0);const i=this.isAbsolute(n);let s;t.root=this.rootname(n),i||this.hasProtocol(n)?s=1:s=0;let r=-1,o=0,a=-1,h=!0,l=n.length-1,c=0;for(;l>=s;--l){if(e=n.charCodeAt(l),e===47){if(!h){o=l+1;break}continue}a===-1&&(h=!1,a=l+1),e===46?r===-1?r=l:c!==1&&(c=1):r!==-1&&(c=-1)}return r===-1||a===-1||c===0||c===1&&r===a-1&&r===o+1?a!==-1&&(o===0&&i?t.base=t.name=n.slice(1,a):t.base=t.name=n.slice(o,a)):(o===0&&i?(t.name=n.slice(1,r),t.base=n.slice(1,a)):(t.name=n.slice(o,r),t.base=n.slice(o,a)),t.ext=n.slice(r,a)),t.dir=this.dirname(n),t},sep:"/",delimiter:":",joinExtensions:[".html"]};function Qh(n,t,e,i,s){const r=t[e];for(let o=0;o<r.length;o++){const a=r[o];e<t.length-1?Qh(n.replace(i[e],a),t,e+1,i,s):s.push(n.replace(i[e],a))}}function Tu(n){const t=/\{(.*?)\}/g,e=n.match(t),i=[];if(e){const s=[];e.forEach(r=>{const o=r.substring(1,r.length-1).split(",");s.push(o)}),Qh(n,s,0,e,i)}else i.push(n);return i}const bs=n=>!Array.isArray(n);class ai{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(t,e)=>`${t}${this._bundleIdConnector}${e}`,extractAssetIdFromBundle:(t,e)=>e.replace(`${t}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(t){if(this._bundleIdConnector=t.connector??this._bundleIdConnector,this._createBundleAssetId=t.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=t.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...t){t.forEach(e=>{this._preferredOrder.push(e),e.priority||(e.priority=Object.keys(e.params))}),this._resolverHash={}}set basePath(t){this._basePath=t}get basePath(){return this._basePath}set rootPath(t){this._rootPath=t}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(t){if(typeof t=="string")this._defaultSearchParams=t;else{const e=t;this._defaultSearchParams=Object.keys(e).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`).join("&")}}getAlias(t){const{alias:e,src:i}=t;return Ot(e||i,r=>typeof r=="string"?r:Array.isArray(r)?r.map(o=>(o==null?void 0:o.src)??o):r!=null&&r.src?r.src:r,!0)}addManifest(t){this._manifest&&st("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=t,t.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(t,e){const i=[];let s=e;Array.isArray(e)||(s=Object.entries(e).map(([r,o])=>typeof o=="string"||Array.isArray(o)?{alias:r,src:o}:{alias:r,...o})),s.forEach(r=>{const o=r.src,a=r.alias;let h;if(typeof a=="string"){const l=this._createBundleAssetId(t,a);i.push(l),h=[a,l]}else{const l=a.map(c=>this._createBundleAssetId(t,c));i.push(...l),h=[...a,...l]}this.add({...r,alias:h,src:o})}),this._bundles[t]=i}add(t){const e=[];Array.isArray(t)?e.push(...t):e.push(t);let i;i=r=>{this.hasKey(r)&&st(`[Resolver] already has key: ${r} overwriting`)},Ot(e).forEach(r=>{const{src:o}=r;let{data:a,format:h,loadParser:l,parser:c}=r;const d=Ot(o).map(y=>typeof y=="string"?Tu(y):Array.isArray(y)?y:[y]),u=this.getAlias(r);Array.isArray(u)?u.forEach(i):i(u);const p=[],g=y=>{const m=this._parsers.find(x=>x.test(y));return{src:y,...m==null?void 0:m.parse(y)}};d.forEach(y=>{y.forEach(m=>{let x={};if(typeof m!="object"?x=g(m):(a=m.data??a,h=m.format??h,(m.loadParser||m.parser)&&(l=m.loadParser??l,c=m.parser??c),x={...g(m.src),...m}),!u)throw new Error(`[Resolver] alias is undefined for this asset: ${x.src}`);x=this._buildResolvedAsset(x,{aliases:u,data:a,format:h,loadParser:l,parser:c,progressSize:r.progressSize}),p.push(x)})}),u.forEach(y=>{this._assetMap[y]=p})})}resolveBundle(t){const e=bs(t);t=Ot(t);const i={};return t.forEach(s=>{const r=this._bundles[s];if(r){const o=this.resolve(r),a={};for(const h in o){const l=o[h];a[this._extractAssetIdFromBundle(s,h)]=l}i[s]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const s in e)i[s]=e[s].src;return i}return e.src}resolve(t){const e=bs(t);t=Ot(t);const i={};return t.forEach(s=>{if(!this._resolverHash[s])if(this._assetMap[s]){let r=this._assetMap[s];const o=this._getPreferredOrder(r);o==null||o.priority.forEach(a=>{o.params[a].forEach(h=>{const l=r.filter(c=>c[a]?c[a]===h:!1);l.length&&(r=l)})}),this._resolverHash[s]=r[0]}else this._resolverHash[s]=this._buildResolvedAsset({alias:[s],src:s},{});i[s]=this._resolverHash[s]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[e],s=this._preferredOrder.find(r=>r.params.format.includes(i.format));if(s)return s}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}_buildResolvedAsset(t,e){const{aliases:i,data:s,loadParser:r,parser:o,format:a,progressSize:h}=e;return(this._basePath||this._rootPath)&&(t.src=Mt.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...s||{},...t.data},t.loadParser=r??t.loadParser,t.parser=o??t.parser,t.format=a??t.format??Au(t.src),h!==void 0&&(t.progressSize=h),t}}ai.RETINA_PREFIX=/@([0-9\.]+)x/;function Au(n){return n.split(".").pop().split("?").shift().split("#").shift()}const Zn=(n,t)=>{const e=t.split("?")[1];return e&&(n+=`?${e}`),n},Jh=class vi{constructor(t,e){this.linkedSheets=[];let i=t;(t==null?void 0:t.source)instanceof zt&&(i={texture:t,data:e});const{texture:s,data:r,cachePrefix:o=""}=i;this.cachePrefix=o,this._texture=s instanceof G?s:null,this.textureSource=s.source,this.textures={},this.animations={},this.data=r;const a=parseFloat(r.meta.scale);a?(this.resolution=a,s.source.resolution=this.resolution):this.resolution=s.source._resolution,this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}parse(){return new Promise(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=vi.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(t,e=!1){let i=t;const s=e?1/0:vi.BATCH_SIZE;for(;i-t<s&&i<this._frameKeys.length;){const r=this._frameKeys[i],o=this._frames[r],a=o.frame;if(a){let h=null,l=null;const c=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,d=new J(0,0,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution);o.rotated?h=new J(Math.floor(a.x)/this.resolution,Math.floor(a.y)/this.resolution,Math.floor(a.h)/this.resolution,Math.floor(a.w)/this.resolution):h=new J(Math.floor(a.x)/this.resolution,Math.floor(a.y)/this.resolution,Math.floor(a.w)/this.resolution,Math.floor(a.h)/this.resolution),o.trimmed!==!1&&o.spriteSourceSize&&(l=new J(Math.floor(o.spriteSourceSize.x)/this.resolution,Math.floor(o.spriteSourceSize.y)/this.resolution,Math.floor(a.w)/this.resolution,Math.floor(a.h)/this.resolution)),this.textures[r]=new G({source:this.textureSource,frame:h,orig:d,trim:l,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:r.toString()})}i++}}_processAnimations(){const t=this.data.animations||{};for(const e in t){this.animations[e]=[];for(let i=0;i<t[e].length;i++){const s=t[e][i];this.animations[e].push(this.textures[s])}}}_parseComplete(){const t=this._callback;this._callback=null,this._batchIndex=0,t.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*vi.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*vi.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(t=!1){var e;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,t&&((e=this._texture)==null||e.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};Jh.BATCH_SIZE=1e3;let qn=Jh;const Ru=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function tl(n,t,e){const i={};if(n.forEach(s=>{i[s]=t}),Object.keys(t.textures).forEach(s=>{i[`${t.cachePrefix}${s}`]=t.textures[s]}),!e){const s=Mt.dirname(n[0]);t.linkedSheets.forEach((r,o)=>{const a=tl([`${s}/${t.data.meta.related_multi_packs[o]}`],r,!0);Object.assign(i,a)})}return i}const ku={extension:E.Asset,cache:{test:n=>n instanceof qn,getCacheableAssets:(n,t)=>tl(n,t,!1)},resolver:{extension:{type:E.ResolveParser,name:"resolveSpritesheet"},test:n=>{const e=n.split("?")[0].split("."),i=e.pop(),s=e.pop();return i==="json"&&Ru.includes(s)},parse:n=>{var e;const t=n.split(".");return{resolution:parseFloat(((e=ai.RETINA_PREFIX.exec(n))==null?void 0:e[1])??"1"),format:t[t.length-2],src:n}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:E.LoadParser,priority:ue.Normal,name:"spritesheetLoader"},async testParse(n,t){return Mt.extname(t.src).toLowerCase()===".json"&&!!n.frames},async parse(n,t,e){var d,u;const{texture:i,imageFilename:s,textureOptions:r,cachePrefix:o}=(t==null?void 0:t.data)??{};let a=Mt.dirname(t.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let h;if(i instanceof G)h=i;else{const p=Zn(a+(s??n.meta.image),t.src);h=(await e.load([{src:p,data:r}]))[p]}const l=new qn({texture:h.source,data:n,cachePrefix:o});await l.parse();const c=(d=n==null?void 0:n.meta)==null?void 0:d.related_multi_packs;if(Array.isArray(c)){const p=[];for(const y of c){if(typeof y!="string")continue;let m=a+y;(u=t.data)!=null&&u.ignoreMultiPack||(m=Zn(m,t.src),p.push(e.load({src:m,data:{textureOptions:r,ignoreMultiPack:!0}})))}const g=await Promise.all(p);l.linkedSheets=g,g.forEach(y=>{y.linkedSheets=[l].concat(l.linkedSheets.filter(m=>m!==y))})}return l},async unload(n,t,e){await e.unload(n.textureSource._sourceOrigin),n.destroy(!1)}}};q.add(ku);class Eu{constructor(t){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const e=this._canvas.getBoundingClientRect(),i=this._canvas.width,s=this._canvas.height,r=e.width/i*this._renderer.resolution,o=e.height/s*this._renderer.resolution,a=e.left,h=e.top,l=`translate(${a}px, ${h}px) scale(${r}, ${o})`;l!==this._lastTransform&&(this._domElement.style.transform=l,this._lastTransform=l)},this._domElement=t.domElement,this._renderer=t.renderer,!(globalThis.OffscreenCanvas&&this._renderer.canvas instanceof OffscreenCanvas)&&(this._canvas=this._renderer.canvas,this._attachObserver())}get canvas(){return this._canvas}ensureAttached(){!this._domElement.parentNode&&this._canvas.parentNode&&(this._canvas.parentNode.appendChild(this._domElement),this.updateTranslation())}_attachObserver(){"ResizeObserver"in globalThis?(this._observer&&(this._observer.disconnect(),this._observer=null),this._observer=new ResizeObserver(t=>{for(const e of t){if(e.target!==this._canvas)continue;const i=this.canvas.width,s=this.canvas.height,r=e.contentRect.width/i*this._renderer.resolution,o=e.contentRect.height/s*this._renderer.resolution;(this._lastScaleX!==r||this._lastScaleY!==o)&&(this.updateTranslation(),this._lastScaleX=r,this._lastScaleY=o)}}),this._observer.observe(this._canvas)):this._tickerAttached||mt.shared.add(this.updateTranslation,this,Fe.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&mt.shared.remove(this.updateTranslation),this._domElement=null,this._renderer=null,this._canvas=null,this._tickerAttached=!1,this._lastTransform="",this._lastScaleX=null,this._lastScaleY=null}}class Tr{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=Tr.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new Q,this.page=new Q,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,s,r){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}var ln=/iPhone/i,Io=/iPod/i,Do=/iPad/i,Fo=/\biOS-universal(?:.+)Mac\b/i,cn=/\bAndroid(?:.+)Mobile\b/i,Bo=/Android/i,We=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,ts=/Silk/i,Kt=/Windows Phone/i,zo=/\bWindows(?:.+)ARM\b/i,Lo=/BlackBerry/i,Oo=/BB10/i,Wo=/Opera Mini/i,Go=/\b(CriOS|Chrome)(?:.+)Mobile/i,Uo=/Mobile(?:.+)Firefox\b/i,Ho=function(n){return typeof n<"u"&&n.platform==="MacIntel"&&typeof n.maxTouchPoints=="number"&&n.maxTouchPoints>1&&typeof MSStream>"u"};function Iu(n){return function(t){return t.test(n)}}function Vo(n){var t={userAgent:"",platform:"",maxTouchPoints:0};!n&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof n=="string"?t.userAgent=n:n&&n.userAgent&&(t={userAgent:n.userAgent,platform:n.platform,maxTouchPoints:n.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var s=Iu(e),r={apple:{phone:s(ln)&&!s(Kt),ipod:s(Io),tablet:!s(ln)&&(s(Do)||Ho(t))&&!s(Kt),universal:s(Fo),device:(s(ln)||s(Io)||s(Do)||s(Fo)||Ho(t))&&!s(Kt)},amazon:{phone:s(We),tablet:!s(We)&&s(ts),device:s(We)||s(ts)},android:{phone:!s(Kt)&&s(We)||!s(Kt)&&s(cn),tablet:!s(Kt)&&!s(We)&&!s(cn)&&(s(ts)||s(Bo)),device:!s(Kt)&&(s(We)||s(ts)||s(cn)||s(Bo))||s(/\bokhttp\b/i)},windows:{phone:s(Kt),tablet:s(zo),device:s(Kt)||s(zo)},other:{blackberry:s(Lo),blackberry10:s(Oo),opera:s(Wo),firefox:s(Uo),chrome:s(Go),device:s(Lo)||s(Oo)||s(Wo)||s(Uo)||s(Go)},any:!1,phone:!1,tablet:!1};return r.any=r.apple.device||r.android.device||r.windows.device||r.other.device,r.phone=r.apple.phone||r.android.phone||r.windows.phone,r.tablet=r.apple.tablet||r.android.tablet||r.windows.tablet,r}const Du=Vo.default??Vo,Fu=Du(globalThis.navigator),dn=Object.create(null),No=Object.create(null);function Ar(n,t){let e=No[n];return e===void 0&&(dn[t]===void 0&&(dn[t]=1),No[n]=e=dn[t]++),e}let Ge;function el(){return(!Ge||Ge!=null&&Ge.isContextLost())&&(Ge=$.get().createCanvas().getContext("webgl",{})),Ge}let es;function Bu(){if(!es){es="mediump";const n=el();n&&n.getShaderPrecisionFormat&&(es=n.getShaderPrecisionFormat(n.FRAGMENT_SHADER,n.HIGH_FLOAT).precision?"highp":"mediump")}return es}function zu(n,t,e){return t?n:e?(n=n.replace("out vec4 finalColor;",""),`
|
|
@@ -20,7 +20,7 @@ Deprecated since v${n}`,r=typeof console.groupCollapsed=="function"&&!Ye.noColor
|
|
|
20
20
|
`}function Lu(n,t,e){const i=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(n.substring(0,9)!=="precision"){let s=e?t.requestedFragmentPrecision:t.requestedVertexPrecision;return s==="highp"&&i!=="highp"&&(s="mediump"),`precision ${s} float;
|
|
21
21
|
${n}`}else if(i!=="highp"&&n.substring(0,15)==="precision highp")return n.replace("precision highp","precision mediump");return n}function Ou(n,t){return t?`#version 300 es
|
|
22
22
|
${n}`:n}const Wu={},Gu={};function Uu(n,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const i=e?Wu:Gu;return i[t]?(i[t]++,t+=`-${i[t]}`):i[t]=1,n.indexOf("#define SHADER_NAME")!==-1?n:`${`#define SHADER_NAME ${t}`}
|
|
23
|
-
${n}`}function Hu(n,t){return t?n.replace("#version 300 es",""):n}const un={stripVersion:Hu,ensurePrecision:Lu,addProgramDefines:zu,setProgramName:Uu,insertVersion:Ou},di=Object.create(null),il=class Kn{constructor(t){t={...Kn.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:Bu()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let s=t.fragment,r=t.vertex;Object.keys(un).forEach(o=>{const a=i[o];s=un[o](s,a,!0),r=un[o](r,a,!1)}),this.fragment=s,this.vertex=r,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=Ar(`${this.vertex}:${this.fragment}`,"gl-program")}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,di[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return di[e]||(di[e]=new Kn(t),di[e]._cacheKey=e),di[e]}};il.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let ii=il;const $o={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function Vu(n){return $o[n]??$o.float32}const Nu={f32:"float32","vec2<f32>":"float32x2","vec3<f32>":"float32x3","vec4<f32>":"float32x4",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",i32:"sint32","vec2<i32>":"sint32x2","vec3<i32>":"sint32x3","vec4<i32>":"sint32x4",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"},Yo=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function Xo(n,t){let e;for(;(e=Yo.exec(n))!==null;){const i=Nu[e[3]]??"float32";t[e[2]]={location:parseInt(e[1],10),format:i,stride:Vu(i).stride,offset:0,instance:!1,start:0}}Yo.lastIndex=0}function $u(n){return n.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function Yu({source:n,entryPoint:t}){const e={},i=$u(n),s=i.indexOf(`fn ${t}(`);if(s===-1)return e;const r=i.indexOf("->",s);if(r===-1)return e;const o=i.substring(s,r);if(Xo(o,e),Object.keys(e).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const h=a[1],l=new RegExp(`struct\\s+${h}\\s*\\{([^}]+)\\}`,"s"),c=i.match(l);c&&Xo(c[1],e)}}return e}function pn(n){var d,u;const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@group\((\d+)\)/,i=/@binding\((\d+)\)/,s=/var(<[^>]+>)? (\w+)/,r=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,l=(d=n.match(t))==null?void 0:d.map(p=>({group:parseInt(p.match(e)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(r)[1]}));if(!l)return{groups:[],structs:[]};const c=((u=n.match(o))==null?void 0:u.map(p=>{const g=p.match(h)[1],y=p.match(a).reduce((m,x)=>{const[S,v]=x.split(":");return m[S.trim()]=v.trim(),m},{});return y?{name:g,members:y}:null}).filter(({name:p})=>l.some(g=>g.type===p||g.type.includes(`<${p}>`))))??[];return{groups:l,structs:c}}var _e=(n=>(n[n.VERTEX=1]="VERTEX",n[n.FRAGMENT=2]="FRAGMENT",n[n.COMPUTE=4]="COMPUTE",n))(_e||{});function Xu({groups:n}){const t=[];for(let e=0;e<n.length;e++){const i=n[e];t[i.group]||(t[i.group]=[]),i.isUniform?t[i.group].push({binding:i.binding,visibility:_e.VERTEX|_e.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function ju({groups:n}){const t=[];for(let e=0;e<n.length;e++){const i=n[e];t[i.group]||(t[i.group]={}),t[i.group][i.name]=i.binding}return t}function Zu(n,t){const e=new Set,i=new Set,s=[...n.structs,...t.structs].filter(o=>e.has(o.name)?!1:(e.add(o.name),!0)),r=[...n.groups,...t.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:r}}const ui=Object.create(null);class ce{constructor(t){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:i,layout:s,gpuLayout:r,name:o}=t;if(this.name=o,this.fragment=e,this.vertex=i,e.source===i.source){const l=pn(e.source);this.structsAndGroups=l}else{const l=pn(i.source),c=pn(e.source);this.structsAndGroups=Zu(l,c)}this.layout=s??ju(this.structsAndGroups),this.gpuLayout=r??Xu(this.structsAndGroups),this.autoAssignGlobalUniforms=((a=this.layout[0])==null?void 0:a.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((h=this.layout[1])==null?void 0:h.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,i=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=Ar(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=Yu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,ui[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return ui[e]||(ui[e]=new ce(t),ui[e]._cacheKey=e),ui[e]}}const sl=["f32","i32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>"],qu=sl.reduce((n,t)=>(n[t]=!0,n),{});function Ku(n,t){switch(n){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*t);case"vec3<f32>":return new Float32Array(3*t);case"vec4<f32>":return new Float32Array(4*t);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const nl=class rl{constructor(t,e){this._touched=0,this.uid=ct("uniform"),this._resourceType="uniformGroup",this._resourceId=ct("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...rl.defaultOptions,...e},this.uniformStructures=t;const i={};for(const s in t){const r=t[s];if(r.name=s,r.size=r.size??1,!qu[r.type]){const o=r.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,h]=o;throw new Error(`Uniform type ${r.type} is not supported. Use type: '${a}', size: ${h} instead.`)}throw new Error(`Uniform type ${r.type} is not supported. Supported uniform types are: ${sl.join(", ")}`)}r.value??(r.value=Ku(r.type,r.size)),i[s]=r.value}this.uniforms=i,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=Ar(Object.keys(i).map(s=>`${s}-${t[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};nl.defaultOptions={ubo:!1,isStatic:!1};let si=nl;class Mi{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const i in t){const s=t[i];this.setResource(s,e++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const t=[];let e=0;for(const i in this.resources)t[e++]=this.resources[i]._resourceId;this._key=t.join("|")}setResource(t,e){var s,r;const i=this.resources[e];t!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(r=t.on)==null||r.call(t,"change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t,e){const i=this.resources;for(const s in i)i[s]._gcLastUsed=t,i[s]._touched=e}destroy(){var e;const t=this.resources;for(const i in t){const s=t[i];(e=s==null?void 0:s.off)==null||e.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const i in e)e[i]===t&&(e[i]=null)}else this._updateKey()}}var te=(n=>(n[n.WEBGL=1]="WEBGL",n[n.WEBGPU=2]="WEBGPU",n[n.CANVAS=4]="CANVAS",n[n.BOTH=3]="BOTH",n))(te||{});class Be extends Zt{constructor(t){super(),this.uid=ct("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:e,glProgram:i,groups:s,resources:r,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=te.WEBGPU),i&&(o|=te.WEBGL)),this.compatibleRenderers=o;const h={};if(!r&&!s&&(r={}),r&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&s&&a)for(const l in a)for(const c in a[l]){const d=a[l][c];h[d]={group:l,binding:c,name:d}}else if(e&&s&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,h[c.name]=c})}else if(r){s={},a={},e&&e.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let l=0;for(const c in r)h[c]||(s[99]||(s[99]=new Mi,this._ownedBindGroups.push(s[99])),h[c]={group:99,binding:l,name:c},a[99]=a[99]||{},a[99][l]=c,l++);for(const c in r){const d=c;let u=r[c];!u.source&&!u._resourceType&&(u=new si(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new Mi,this._ownedBindGroups.push(s[p.group])),s[p.group].setResource(u,p.binding))}}this.groups=s,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(s,h)}addResource(t,e,i){var s,r;(s=this._uniformBindMap)[e]||(s[e]={}),(r=this._uniformBindMap[e])[i]||(r[i]=t),this.groups[e]||(this.groups[e]=new Mi,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const s in e){const r=e[s];Object.defineProperty(i,r.name,{get(){return t[r.group].getResource(r.binding)},set(o){t[r.group].setResource(o,r.binding)}})}return i}destroy(t=!1){var e,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(s=>{s.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null)}static from(t){const{gpu:e,gl:i,...s}=t;let r,o;return e&&(r=ce.from(e)),i&&(o=ii.from(i)),new Be({gpuProgram:r,glProgram:o,...s})}}const Qu={normal:0,add:1,multiply:2,screen:3,overlay:4,erase:5,"normal-npm":6,"add-npm":7,"screen-npm":8,min:9,max:10},fn=0,gn=1,mn=2,yn=3,xn=4,Sn=5,Qn=class ol{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<fn)}set blend(t){!!(this.data&1<<fn)!==t&&(this.data^=1<<fn)}get offsets(){return!!(this.data&1<<gn)}set offsets(t){!!(this.data&1<<gn)!==t&&(this.data^=1<<gn)}set cullMode(t){if(t==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=t==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<mn)}set culling(t){!!(this.data&1<<mn)!==t&&(this.data^=1<<mn)}get depthTest(){return!!(this.data&1<<yn)}set depthTest(t){!!(this.data&1<<yn)!==t&&(this.data^=1<<yn)}get depthMask(){return!!(this.data&1<<Sn)}set depthMask(t){!!(this.data&1<<Sn)!==t&&(this.data^=1<<Sn)}get clockwiseFrontFace(){return!!(this.data&1<<xn)}set clockwiseFrontFace(t){!!(this.data&1<<xn)!==t&&(this.data^=1<<xn)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=Qu[t]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const t=new ol;return t.depthTest=!1,t.blend=!0,t}};Qn.default2d=Qn.for2d();let Vi=Qn;const al=class Jn extends Be{constructor(t){t={...Jn.defaultOptions,...t},super(t),this.enabled=!0,this._state=Vi.for2d(),this.blendMode=t.blendMode,this.padding=t.padding,typeof t.antialias=="boolean"?this.antialias=t.antialias?"on":"off":this.antialias=t.antialias,this.resolution=t.resolution,this.blendRequired=t.blendRequired,this.clipToViewport=t.clipToViewport,this.addResource("uTexture",0,1),t.blendRequired&&this.addResource("uBackTexture",0,3)}apply(t,e,i,s){t.applyFilter(this,e,i,s)}get blendMode(){return this._state.blendMode}set blendMode(t){this._state.blendMode=t}static from(t){const{gpu:e,gl:i,...s}=t;let r,o;return e&&(r=ce.from(e)),i&&(o=ii.from(i)),new Jn({gpuProgram:r,glProgram:o,...s})}};al.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Ju=al;const tr=[];q.handleByNamedList(E.Environment,tr);async function tp(n){if(!n)for(let t=0;t<tr.length;t++){const e=tr[t];if(e.value.test()){await e.value.load();return}}}let pi;function ep(){if(typeof pi=="boolean")return pi;try{pi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{pi=!1}return pi}function jo(n,t,e=2){const i=t&&t.length,s=i?t[0]*e:n.length;let r=hl(n,0,s,e,!0);const o=[];if(!r||r.next===r.prev)return o;let a,h,l;if(i&&(r=op(n,t,r,e)),n.length>80*e){a=n[0],h=n[1];let c=a,d=h;for(let u=e;u<s;u+=e){const p=n[u],g=n[u+1];p<a&&(a=p),g<h&&(h=g),p>c&&(c=p),g>d&&(d=g)}l=Math.max(c-a,d-h),l=l!==0?32767/l:0}return Fi(r,o,e,a,h,l,0),o}function hl(n,t,e,i,s){let r;if(s===yp(n,t,e,i)>0)for(let o=t;o<e;o+=i)r=Zo(o/i|0,n[o],n[o+1],r);else for(let o=e-i;o>=t;o-=i)r=Zo(o/i|0,n[o],n[o+1],r);return r&&ni(r,r.next)&&(zi(r),r=r.next),r}function ze(n,t){if(!n)return n;t||(t=n);let e=n,i;do if(i=!1,!e.steiner&&(ni(e,e.next)||ot(e.prev,e,e.next)===0)){if(zi(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Fi(n,t,e,i,s,r,o){if(!n)return;!o&&r&&dp(n,i,s,r);let a=n;for(;n.prev!==n.next;){const h=n.prev,l=n.next;if(r?sp(n,i,s,r):ip(n)){t.push(h.i,n.i,l.i),zi(n),n=l.next,a=l.next;continue}if(n=l,n===a){o?o===1?(n=np(ze(n),t),Fi(n,t,e,i,s,r,2)):o===2&&rp(n,t,e,i,s,r):Fi(ze(n),t,e,i,s,r,1);break}}}function ip(n){const t=n.prev,e=n,i=n.next;if(ot(t,e,i)>=0)return!1;const s=t.x,r=e.x,o=i.x,a=t.y,h=e.y,l=i.y,c=Math.min(s,r,o),d=Math.min(a,h,l),u=Math.max(s,r,o),p=Math.max(a,h,l);let g=i.next;for(;g!==t;){if(g.x>=c&&g.x<=u&&g.y>=d&&g.y<=p&&bi(s,a,r,h,o,l,g.x,g.y)&&ot(g.prev,g,g.next)>=0)return!1;g=g.next}return!0}function sp(n,t,e,i){const s=n.prev,r=n,o=n.next;if(ot(s,r,o)>=0)return!1;const a=s.x,h=r.x,l=o.x,c=s.y,d=r.y,u=o.y,p=Math.min(a,h,l),g=Math.min(c,d,u),y=Math.max(a,h,l),m=Math.max(c,d,u),x=er(p,g,t,e,i),S=er(y,m,t,e,i);let v=n.prevZ,b=n.nextZ;for(;v&&v.z>=x&&b&&b.z<=S;){if(v.x>=p&&v.x<=y&&v.y>=g&&v.y<=m&&v!==s&&v!==o&&bi(a,c,h,d,l,u,v.x,v.y)&&ot(v.prev,v,v.next)>=0||(v=v.prevZ,b.x>=p&&b.x<=y&&b.y>=g&&b.y<=m&&b!==s&&b!==o&&bi(a,c,h,d,l,u,b.x,b.y)&&ot(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;v&&v.z>=x;){if(v.x>=p&&v.x<=y&&v.y>=g&&v.y<=m&&v!==s&&v!==o&&bi(a,c,h,d,l,u,v.x,v.y)&&ot(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;b&&b.z<=S;){if(b.x>=p&&b.x<=y&&b.y>=g&&b.y<=m&&b!==s&&b!==o&&bi(a,c,h,d,l,u,b.x,b.y)&&ot(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function np(n,t){let e=n;do{const i=e.prev,s=e.next.next;!ni(i,s)&&cl(i,e,e.next,s)&&Bi(i,s)&&Bi(s,i)&&(t.push(i.i,e.i,s.i),zi(e),zi(e.next),e=n=s),e=e.next}while(e!==n);return ze(e)}function rp(n,t,e,i,s,r){let o=n;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&fp(o,a)){let h=dl(o,a);o=ze(o,o.next),h=ze(h,h.next),Fi(o,t,e,i,s,r,0),Fi(h,t,e,i,s,r,0);return}a=a.next}o=o.next}while(o!==n)}function op(n,t,e,i){const s=[];for(let r=0,o=t.length;r<o;r++){const a=t[r]*i,h=r<o-1?t[r+1]*i:n.length,l=hl(n,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(pp(l))}s.sort(ap);for(let r=0;r<s.length;r++)e=hp(s[r],e);return e}function ap(n,t){let e=n.x-t.x;if(e===0&&(e=n.y-t.y,e===0)){const i=(n.next.y-n.y)/(n.next.x-n.x),s=(t.next.y-t.y)/(t.next.x-t.x);e=i-s}return e}function hp(n,t){const e=lp(n,t);if(!e)return t;const i=dl(e,n);return ze(i,i.next),ze(e,e.next)}function lp(n,t){let e=t;const i=n.x,s=n.y;let r=-1/0,o;if(ni(n,e))return e;do{if(ni(n,e.next))return e.next;if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){const d=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(d<=i&&d>r&&(r=d,o=e.x<e.next.x?e:e.next,d===i))return o}e=e.next}while(e!==t);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;e=o;do{if(i>=e.x&&e.x>=h&&i!==e.x&&ll(s<l?i:r,s,h,l,s<l?r:i,s,e.x,e.y)){const d=Math.abs(s-e.y)/(i-e.x);Bi(e,n)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&cp(o,e)))&&(o=e,c=d)}e=e.next}while(e!==a);return o}function cp(n,t){return ot(n.prev,n,t.prev)<0&&ot(t.next,n,n.next)<0}function dp(n,t,e,i){let s=n;do s.z===0&&(s.z=er(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==n);s.prevZ.nextZ=null,s.prevZ=null,up(s)}function up(n){let t,e=1;do{let i=n,s;n=null;let r=null;for(t=0;i;){t++;let o=i,a=0;for(let l=0;l<e&&(a++,o=o.nextZ,!!o);l++);let h=e;for(;a>0||h>0&&o;)a!==0&&(h===0||!o||i.z<=o.z)?(s=i,i=i.nextZ,a--):(s=o,o=o.nextZ,h--),r?r.nextZ=s:n=s,s.prevZ=r,r=s;i=o}r.nextZ=null,e*=2}while(t>1);return n}function er(n,t,e,i,s){return n=(n-e)*s|0,t=(t-i)*s|0,n=(n|n<<8)&16711935,n=(n|n<<4)&252645135,n=(n|n<<2)&858993459,n=(n|n<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,n|t<<1}function pp(n){let t=n,e=n;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==n);return e}function ll(n,t,e,i,s,r,o,a){return(s-o)*(t-a)>=(n-o)*(r-a)&&(n-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(r-a)>=(s-o)*(i-a)}function bi(n,t,e,i,s,r,o,a){return!(n===o&&t===a)&&ll(n,t,e,i,s,r,o,a)}function fp(n,t){return n.next.i!==t.i&&n.prev.i!==t.i&&!gp(n,t)&&(Bi(n,t)&&Bi(t,n)&&mp(n,t)&&(ot(n.prev,n,t.prev)||ot(n,t.prev,t))||ni(n,t)&&ot(n.prev,n,n.next)>0&&ot(t.prev,t,t.next)>0)}function ot(n,t,e){return(t.y-n.y)*(e.x-t.x)-(t.x-n.x)*(e.y-t.y)}function ni(n,t){return n.x===t.x&&n.y===t.y}function cl(n,t,e,i){const s=ss(ot(n,t,e)),r=ss(ot(n,t,i)),o=ss(ot(e,i,n)),a=ss(ot(e,i,t));return!!(s!==r&&o!==a||s===0&&is(n,e,t)||r===0&&is(n,i,t)||o===0&&is(e,n,i)||a===0&&is(e,t,i))}function is(n,t,e){return t.x<=Math.max(n.x,e.x)&&t.x>=Math.min(n.x,e.x)&&t.y<=Math.max(n.y,e.y)&&t.y>=Math.min(n.y,e.y)}function ss(n){return n>0?1:n<0?-1:0}function gp(n,t){let e=n;do{if(e.i!==n.i&&e.next.i!==n.i&&e.i!==t.i&&e.next.i!==t.i&&cl(e,e.next,n,t))return!0;e=e.next}while(e!==n);return!1}function Bi(n,t){return ot(n.prev,n,n.next)<0?ot(n,t,n.next)>=0&&ot(n,n.prev,t)>=0:ot(n,t,n.prev)<0||ot(n,n.next,t)<0}function mp(n,t){let e=n,i=!1;const s=(n.x+t.x)/2,r=(n.y+t.y)/2;do e.y>r!=e.next.y>r&&e.next.y!==e.y&&s<(e.next.x-e.x)*(r-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==n);return i}function dl(n,t){const e=ir(n.i,n.x,n.y),i=ir(t.i,t.x,t.y),s=n.next,r=t.prev;return n.next=t,t.prev=n,e.next=s,s.prev=e,i.next=e,e.prev=i,r.next=i,i.prev=r,i}function Zo(n,t,e,i){const s=ir(n,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function zi(n){n.next.prev=n.prev,n.prev.next=n.next,n.prevZ&&(n.prevZ.nextZ=n.nextZ),n.nextZ&&(n.nextZ.prevZ=n.prevZ)}function ir(n,t,e){return{i:n,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function yp(n,t,e,i){let s=0;for(let r=t,o=e-i;r<e;r+=i)s+=(n[o]-n[r])*(n[r+1]+n[o+1]),o=r;return s}const xp=jo.default||jo;var ul=(n=>(n[n.NONE=0]="NONE",n[n.COLOR=16384]="COLOR",n[n.STENCIL=1024]="STENCIL",n[n.DEPTH=256]="DEPTH",n[n.COLOR_DEPTH=16640]="COLOR_DEPTH",n[n.COLOR_STENCIL=17408]="COLOR_STENCIL",n[n.DEPTH_STENCIL=1280]="DEPTH_STENCIL",n[n.ALL=17664]="ALL",n))(ul||{});class Sp{constructor(t){this.items=[],this._name=t}emit(t,e,i,s,r,o,a,h){const{name:l,items:c}=this;for(let d=0,u=c.length;d<u;d++)c[d][l](t,e,i,s,r,o,a,h);return this}add(t){return t[this._name]&&(this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return e!==-1&&this.items.splice(e,1),this}contains(t){return this.items.indexOf(t)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const vp=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],pl=class fl extends Zt{constructor(t){super(),this.tick=0,this.uid=ct("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=t.type,this.name=t.name,this.config=t;const e=[...vp,...this.config.runners??[]];this._addRunners(...e),this._unsafeEvalCheck()}async init(t={}){const e=t.skipExtensionImports===!0?!0:t.manageImports===!1;await tp(e),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)t={...this._systemsHash[i].constructor.defaultOptions,...t};t={...fl.defaultOptions,...t},this._roundPixels=t.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(t);this._initOptions=t}render(t,e){this.tick++;let i=t;if(i instanceof W&&(i={container:i},e&&(V(K,"passing a second argument is deprecated, please use render options instead"),i.target=e.renderTexture)),i.target||(i.target=this.view.renderTarget),i.target===this.view.renderTarget&&(this._lastObjectRendered=i.container,i.clearColor??(i.clearColor=this.background.colorRgba),i.clear??(i.clear=this.background.clearBeforeRender)),i.clearColor){const s=Array.isArray(i.clearColor)&&i.clearColor.length===4;i.clearColor=s?i.clearColor:nt.shared.setValue(i.clearColor).toArray()}i.transform||(i.container.updateLocalTransform(),i.transform=i.container.localTransform),i.container.visible&&(i.container.enableRenderGroup(),this.runners.prerender.emit(i),this.runners.renderStart.emit(i),this.runners.render.emit(i),this.runners.renderEnd.emit(i),this.runners.postrender.emit(i))}resize(t,e,i){const s=this.view.resolution;this.view.resize(t,e,i),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),i!==void 0&&i!==s&&this.runners.resolutionChange.emit(i)}clear(t={}){const e=this;t.target||(t.target=e.renderTarget.renderTarget),t.clearColor||(t.clearColor=this.background.colorRgba),t.clear??(t.clear=ul.ALL);const{clear:i,clearColor:s,target:r,mipLevel:o,layer:a}=t;nt.shared.setValue(s??this.background.colorRgba),e.renderTarget.clear(r,i,nt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(t){this.view.resolution=t,this.runners.resolutionChange.emit(t)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...t){t.forEach(e=>{this.runners[e]=new Sp(e)})}_addSystems(t){let e;for(e in t){const i=t[e];this._addSystem(i.value,i.name)}}_addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(t,e){const i=e.reduce((s,r)=>(s[r.name]=r.value,s),{});t.forEach(s=>{const r=s.value,o=s.name,a=i[o];this.renderPipes[o]=new r(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(t=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(t),(t===!0||typeof t=="object"&&t.releaseGlobalResources)&&Hi.release(),Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(t){return this.textureGenerator.generateTexture(t)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!ep())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}resetState(){this.runners.resetState.emit()}};pl.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let gl=pl,ns;function bp(n){return ns!==void 0||(ns=(()=>{var e;const t={stencil:!0,failIfMajorPerformanceCaveat:n??gl.defaultOptions.failIfMajorPerformanceCaveat};try{if(!$.get().getWebGLRenderingContext())return!1;let s=$.get().createCanvas().getContext("webgl",t);const r=!!((e=s==null?void 0:s.getContextAttributes())!=null&&e.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,r}catch{return!1}})()),ns}let rs;async function wp(n={}){return rs!==void 0||(rs=await(async()=>{const t=$.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(n)).requestDevice(),!0}catch{return!1}})()),rs}const qo=["webgl","webgpu","canvas"];async function Cp(n){let t=[];n.preference?(t.push(n.preference),qo.forEach(r=>{r!==n.preference&&t.push(r)})):t=qo.slice();let e,i={};for(let r=0;r<t.length;r++){const o=t[r];if(o==="webgpu"&&await wp()){const{WebGPURenderer:a}=await Ae(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.WuGRbgwP.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));e=a,i={...n,...n.webgpu};break}else if(o==="webgl"&&bp(n.failIfMajorPerformanceCaveat??gl.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await Ae(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.DjvikWe1.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));e=a,i={...n,...n.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await Ae(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.D5NS4GmW.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));e=a,i={...n,...n.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!e)throw new Error("No available renderer for the current environment");const s=new e;return await s.init(i),s}const ml="8.16.0";class yl{static init(){var t;(t=globalThis.__PIXI_APP_INIT__)==null||t.call(globalThis,this,ml)}static destroy(){}}yl.extension=E.Application;class _p{constructor(t){this._renderer=t}init(){var t;(t=globalThis.__PIXI_RENDERER_INIT__)==null||t.call(globalThis,this._renderer,ml)}destroy(){this._renderer=null}}_p.extension={type:[E.WebGLSystem,E.WebGPUSystem],name:"initHook",priority:-10};class xl{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:r}=this._resizeTo;e=s,i=r}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}xl.extension=E.Application;class Sl{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Fe.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?mt.shared:new mt,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}Sl.extension=E.Application;q.add(xl);q.add(Sl);const vl=class sr{constructor(...t){this.stage=new W,t[0]!==void 0&&V(K,"Application constructor options are deprecated, please use Application.init() instead.")}async init(t){t={...t},this.stage||(this.stage=new W),this.renderer=await Cp(t),sr._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(K,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(t=!1,e=!1){const i=sr._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};vl._plugins=[];let bl=vl;q.handleByList(E.Application,bl._plugins);q.add(yl);const vn={test(n){return typeof n=="string"&&n.startsWith("info face=")},parse(n){const t=n.match(/^[a-z]+\s+.+$/gm),e={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in t){const u=t[d].match(/^[a-z]+/gm)[0],p=t[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),g={};for(const y in p){const m=p[y].split("="),x=m[0],S=m[1].replace(/"/gm,""),v=parseFloat(S),b=isNaN(v)?S:v;g[x]=b}e[u].push(g)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=e.info,[r]=e.common,[o]=e.distanceField??[];o&&(i.distanceField={range:parseInt(o.distanceRange,10),type:o.fieldType}),i.fontSize=parseInt(s.size,10),i.fontFamily=s.face,i.lineHeight=parseInt(r.lineHeight,10);const a=e.page;for(let d=0;d<a.length;d++)i.pages.push({id:parseInt(a[d].id,10)||0,file:a[d].file});const h={};i.baseLineOffset=i.lineHeight-parseInt(r.base,10);const l=e.char;for(let d=0;d<l.length;d++){const u=l[d],p=parseInt(u.id,10);let g=u.letter??u.char??String.fromCharCode(p);g==="space"&&(g=" "),h[p]=g,i.chars[g]={id:p,page:parseInt(u.page,10)||0,x:parseInt(u.x,10),y:parseInt(u.y,10),width:parseInt(u.width,10),height:parseInt(u.height,10),xOffset:parseInt(u.xoffset,10),yOffset:parseInt(u.yoffset,10),xAdvance:parseInt(u.xadvance,10),kerning:{}}}const c=e.kerning||[];for(let d=0;d<c.length;d++){const u=parseInt(c[d].first,10),p=parseInt(c[d].second,10),g=parseInt(c[d].amount,10);i.chars[h[p]].kerning[h[u]]=g}return i}},Ko={test(n){const t=n;return typeof t!="string"&&"getElementsByTagName"in t&&t.getElementsByTagName("page").length&&t.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(n){const t={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},e=n.getElementsByTagName("info")[0],i=n.getElementsByTagName("common")[0],s=n.getElementsByTagName("distanceField")[0];s&&(t.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const r=n.getElementsByTagName("page"),o=n.getElementsByTagName("char"),a=n.getElementsByTagName("kerning");t.fontSize=parseInt(e.getAttribute("size"),10),t.fontFamily=e.getAttribute("face"),t.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<r.length;l++)t.pages.push({id:parseInt(r[l].getAttribute("id"),10)||0,file:r[l].getAttribute("file")});const h={};t.baseLineOffset=t.lineHeight-parseInt(i.getAttribute("base"),10);for(let l=0;l<o.length;l++){const c=o[l],d=parseInt(c.getAttribute("id"),10);let u=c.getAttribute("letter")??c.getAttribute("char")??String.fromCharCode(d);u==="space"&&(u=" "),h[d]=u,t.chars[u]={id:d,page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xOffset:parseInt(c.getAttribute("xoffset"),10),yOffset:parseInt(c.getAttribute("yoffset"),10),xAdvance:parseInt(c.getAttribute("xadvance"),10),kerning:{}}}for(let l=0;l<a.length;l++){const c=parseInt(a[l].getAttribute("first"),10),d=parseInt(a[l].getAttribute("second"),10),u=parseInt(a[l].getAttribute("amount"),10);t.chars[h[d]].kerning[h[c]]=u}return t}},Qo={test(n){return typeof n=="string"&&n.match(/<font(\s|>)/)?Ko.test($.get().parseXML(n)):!1},parse(n){return Ko.parse($.get().parseXML(n))}},Pp=[".xml",".fnt"],Mp={extension:{type:E.CacheParser,name:"cacheBitmapFont"},test:n=>!!(n!=null&&n.pages)&&!!(n!=null&&n.chars)&&typeof(n==null?void 0:n.fontFamily)=="string",getCacheableAssets(n,t){const e={};return n.forEach(i=>{e[i]=t,e[`${i}-bitmap`]=t}),e[`${t.fontFamily}-bitmap`]=t,e}},Tp={extension:{type:E.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(n){return Pp.includes(Mt.extname(n).toLowerCase())},async testParse(n){return vn.test(n)||Qo.test(n)},async parse(n,t,e){const i=vn.test(n)?vn.parse(n):Qo.parse(n),{src:s}=t,{pages:r}=i,o=[],a=i.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let u=0;u<r.length;++u){const p=r[u].file;let g=Mt.join(Mt.dirname(s),p);g=Zn(g,s),o.push({src:g,data:a})}const[h,{BitmapFont:l}]=await Promise.all([e.load(o),Ae(()=>import("./BitmapFont.CxzI5juo.js"),__vite__mapDeps([10,2,3,4]))]),c=o.map(u=>h[u.src]);return new l({data:i,textures:c},s)},async load(n,t){return await(await $.get().fetch(n)).text()},async unload(n,t,e){await Promise.all(n.pages.map(i=>e.unload(i.texture.source._sourceOrigin))),n.destroy()}};class Ap{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}const Rp={extension:{type:E.CacheParser,name:"cacheTextureArray"},test:n=>Array.isArray(n)&&n.every(t=>t instanceof G),getCacheableAssets:(n,t)=>{const e={};return n.forEach(i=>{t.forEach((s,r)=>{e[i+(r===0?"":r+1)]=s})}),e}};async function wl(n){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=n});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(n)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const kp={extension:{type:E.DetectionParser,priority:1},test:async()=>wl("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async n=>[...n,"avif"],remove:async n=>n.filter(t=>t!=="avif")},Jo=["png","jpg","jpeg"],Ep={extension:{type:E.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async n=>[...n,...Jo],remove:async n=>n.filter(t=>!Jo.includes(t))},Ip="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function Fs(n){return Ip?!1:document.createElement("video").canPlayType(n)!==""}const Dp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/mp4"),add:async n=>[...n,"mp4","m4v"],remove:async n=>n.filter(t=>t!=="mp4"&&t!=="m4v")},Fp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/ogg"),add:async n=>[...n,"ogv"],remove:async n=>n.filter(t=>t!=="ogv")},Bp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/webm"),add:async n=>[...n,"webm"],remove:async n=>n.filter(t=>t!=="webm")},zp={extension:{type:E.DetectionParser,priority:0},test:async()=>wl("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async n=>[...n,"webp"],remove:async n=>n.filter(t=>t!=="webp")},Cl=class gs{constructor(){this.loadOptions={...gs.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,r=null;if((e.parser||e.loadParser)&&(r=this._parserHash[e.parser||e.loadParser],e.loadParser&&st(`[Assets] "loadParser" is deprecated, use "parser" instead for ${t}`),r||st(`[Assets] specified load parser "${e.parser||e.loadParser}" not found while loading ${t}`)),!r){for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.load&&((o=l.test)!=null&&o.call(l,t,e,this))){r=l;break}}if(!r)return st(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await r.load(t,e,this),i.parser=r;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];l.parse&&l.parse&&await((a=l.testParse)==null?void 0:a.call(l,s,e,this))&&(s=await l.parse(s,e,this)||s,i.parser=l)}return s})(),i}async load(t,e){this._parsersValidated||this._validateParsers();const i=typeof e=="function"?{...gs.defaultOptions,...this.loadOptions,onProgress:e}:{...gs.defaultOptions,...this.loadOptions,...e||{}},{onProgress:s,onError:r,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=bs(t),u=Ot(t,y=>({alias:[y],src:y,data:{}})),p=u.reduce((y,m)=>y+(m.progressSize||1),0),g=u.map(async y=>{const m=Mt.toAbsolute(y.src);c[y.src]||(await this._loadAssetWithRetry(m,y,{onProgress:s,onError:r,strategy:o,retryCount:a,retryDelay:h},c),l+=y.progressSize||1,s&&s(l/p))});return await Promise.all(g),d?c[u[0].src]:c}async unload(t){const i=Ot(t,s=>({alias:[s],src:s})).map(async s=>{var a,h;const r=Mt.toAbsolute(s.src),o=this.promiseCache[r];if(o){const l=await o.promise;delete this.promiseCache[r],await((h=(a=o.parser)==null?void 0:a.unload)==null?void 0:h.call(a,l,s,this))}});await Promise.all(i)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(t=>t.name||t.id).reduce((t,e)=>(!e.name&&!e.id?st("[Assets] parser should have an id"):(t[e.name]||t[e.id])&&st(`[Assets] parser id conflict "${e.id}"`),t[e.name]=e,e.id&&(t[e.id]=e),t),{})}async _loadAssetWithRetry(t,e,i,s){let r=0;const{onError:o,strategy:a,retryCount:h,retryDelay:l}=i,c=d=>new Promise(u=>setTimeout(u,d));for(;;)try{this.promiseCache[t]||(this.promiseCache[t]=this._getLoadPromiseAndParser(t,e)),s[e.src]=await this.promiseCache[t].promise;return}catch(d){delete this.promiseCache[t],delete s[e.src],r++;const u=a!=="retry"||r>h;if(a==="retry"&&!u){o&&o(d,e),await c(l);continue}if(a==="skip"){o&&o(d,e);return}o&&o(d,e);const p=new Error(`[Loader.load] Failed to load ${t}.
|
|
23
|
+
${n}`}function Hu(n,t){return t?n.replace("#version 300 es",""):n}const un={stripVersion:Hu,ensurePrecision:Lu,addProgramDefines:zu,setProgramName:Uu,insertVersion:Ou},di=Object.create(null),il=class Kn{constructor(t){t={...Kn.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:Bu()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let s=t.fragment,r=t.vertex;Object.keys(un).forEach(o=>{const a=i[o];s=un[o](s,a,!0),r=un[o](r,a,!1)}),this.fragment=s,this.vertex=r,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=Ar(`${this.vertex}:${this.fragment}`,"gl-program")}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,di[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return di[e]||(di[e]=new Kn(t),di[e]._cacheKey=e),di[e]}};il.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let ii=il;const $o={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function Vu(n){return $o[n]??$o.float32}const Nu={f32:"float32","vec2<f32>":"float32x2","vec3<f32>":"float32x3","vec4<f32>":"float32x4",vec2f:"float32x2",vec3f:"float32x3",vec4f:"float32x4",i32:"sint32","vec2<i32>":"sint32x2","vec3<i32>":"sint32x3","vec4<i32>":"sint32x4",vec2i:"sint32x2",vec3i:"sint32x3",vec4i:"sint32x4",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",vec2u:"uint32x2",vec3u:"uint32x3",vec4u:"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"},Yo=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function Xo(n,t){let e;for(;(e=Yo.exec(n))!==null;){const i=Nu[e[3]]??"float32";t[e[2]]={location:parseInt(e[1],10),format:i,stride:Vu(i).stride,offset:0,instance:!1,start:0}}Yo.lastIndex=0}function $u(n){return n.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function Yu({source:n,entryPoint:t}){const e={},i=$u(n),s=i.indexOf(`fn ${t}(`);if(s===-1)return e;const r=i.indexOf("->",s);if(r===-1)return e;const o=i.substring(s,r);if(Xo(o,e),Object.keys(e).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const h=a[1],l=new RegExp(`struct\\s+${h}\\s*\\{([^}]+)\\}`,"s"),c=i.match(l);c&&Xo(c[1],e)}}return e}function pn(n){var d,u;const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@group\((\d+)\)/,i=/@binding\((\d+)\)/,s=/var(<[^>]+>)? (\w+)/,r=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,l=(d=n.match(t))==null?void 0:d.map(p=>({group:parseInt(p.match(e)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(r)[1]}));if(!l)return{groups:[],structs:[]};const c=((u=n.match(o))==null?void 0:u.map(p=>{const g=p.match(h)[1],y=p.match(a).reduce((m,x)=>{const[S,v]=x.split(":");return m[S.trim()]=v.trim(),m},{});return y?{name:g,members:y}:null}).filter(({name:p})=>l.some(g=>g.type===p||g.type.includes(`<${p}>`))))??[];return{groups:l,structs:c}}var _e=(n=>(n[n.VERTEX=1]="VERTEX",n[n.FRAGMENT=2]="FRAGMENT",n[n.COMPUTE=4]="COMPUTE",n))(_e||{});function Xu({groups:n}){const t=[];for(let e=0;e<n.length;e++){const i=n[e];t[i.group]||(t[i.group]=[]),i.isUniform?t[i.group].push({binding:i.binding,visibility:_e.VERTEX|_e.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&t[i.group].push({binding:i.binding,visibility:_e.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function ju({groups:n}){const t=[];for(let e=0;e<n.length;e++){const i=n[e];t[i.group]||(t[i.group]={}),t[i.group][i.name]=i.binding}return t}function Zu(n,t){const e=new Set,i=new Set,s=[...n.structs,...t.structs].filter(o=>e.has(o.name)?!1:(e.add(o.name),!0)),r=[...n.groups,...t.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:r}}const ui=Object.create(null);class ce{constructor(t){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:i,layout:s,gpuLayout:r,name:o}=t;if(this.name=o,this.fragment=e,this.vertex=i,e.source===i.source){const l=pn(e.source);this.structsAndGroups=l}else{const l=pn(i.source),c=pn(e.source);this.structsAndGroups=Zu(l,c)}this.layout=s??ju(this.structsAndGroups),this.gpuLayout=r??Xu(this.structsAndGroups),this.autoAssignGlobalUniforms=((a=this.layout[0])==null?void 0:a.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((h=this.layout[1])==null?void 0:h.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,i=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=Ar(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=Yu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,ui[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return ui[e]||(ui[e]=new ce(t),ui[e]._cacheKey=e),ui[e]}}const sl=["f32","i32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>"],qu=sl.reduce((n,t)=>(n[t]=!0,n),{});function Ku(n,t){switch(n){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*t);case"vec3<f32>":return new Float32Array(3*t);case"vec4<f32>":return new Float32Array(4*t);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const nl=class rl{constructor(t,e){this._touched=0,this.uid=ct("uniform"),this._resourceType="uniformGroup",this._resourceId=ct("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...rl.defaultOptions,...e},this.uniformStructures=t;const i={};for(const s in t){const r=t[s];if(r.name=s,r.size=r.size??1,!qu[r.type]){const o=r.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,h]=o;throw new Error(`Uniform type ${r.type} is not supported. Use type: '${a}', size: ${h} instead.`)}throw new Error(`Uniform type ${r.type} is not supported. Supported uniform types are: ${sl.join(", ")}`)}r.value??(r.value=Ku(r.type,r.size)),i[s]=r.value}this.uniforms=i,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=Ar(Object.keys(i).map(s=>`${s}-${t[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};nl.defaultOptions={ubo:!1,isStatic:!1};let si=nl;class Mi{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const i in t){const s=t[i];this.setResource(s,e++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const t=[];let e=0;for(const i in this.resources)t[e++]=this.resources[i]._resourceId;this._key=t.join("|")}setResource(t,e){var s,r;const i=this.resources[e];t!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(r=t.on)==null||r.call(t,"change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t,e){const i=this.resources;for(const s in i)i[s]._gcLastUsed=t,i[s]._touched=e}destroy(){var e;const t=this.resources;for(const i in t){const s=t[i];(e=s==null?void 0:s.off)==null||e.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const i in e)e[i]===t&&(e[i]=null)}else this._updateKey()}}var te=(n=>(n[n.WEBGL=1]="WEBGL",n[n.WEBGPU=2]="WEBGPU",n[n.CANVAS=4]="CANVAS",n[n.BOTH=3]="BOTH",n))(te||{});class Be extends Zt{constructor(t){super(),this.uid=ct("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:e,glProgram:i,groups:s,resources:r,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=te.WEBGPU),i&&(o|=te.WEBGL)),this.compatibleRenderers=o;const h={};if(!r&&!s&&(r={}),r&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&s&&a)for(const l in a)for(const c in a[l]){const d=a[l][c];h[d]={group:l,binding:c,name:d}}else if(e&&s&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,h[c.name]=c})}else if(r){s={},a={},e&&e.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let l=0;for(const c in r)h[c]||(s[99]||(s[99]=new Mi,this._ownedBindGroups.push(s[99])),h[c]={group:99,binding:l,name:c},a[99]=a[99]||{},a[99][l]=c,l++);for(const c in r){const d=c;let u=r[c];!u.source&&!u._resourceType&&(u=new si(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new Mi,this._ownedBindGroups.push(s[p.group])),s[p.group].setResource(u,p.binding))}}this.groups=s,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(s,h)}addResource(t,e,i){var s,r;(s=this._uniformBindMap)[e]||(s[e]={}),(r=this._uniformBindMap[e])[i]||(r[i]=t),this.groups[e]||(this.groups[e]=new Mi,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const s in e){const r=e[s];Object.defineProperty(i,r.name,{get(){return t[r.group].getResource(r.binding)},set(o){t[r.group].setResource(o,r.binding)}})}return i}destroy(t=!1){var e,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(s=>{s.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null)}static from(t){const{gpu:e,gl:i,...s}=t;let r,o;return e&&(r=ce.from(e)),i&&(o=ii.from(i)),new Be({gpuProgram:r,glProgram:o,...s})}}const Qu={normal:0,add:1,multiply:2,screen:3,overlay:4,erase:5,"normal-npm":6,"add-npm":7,"screen-npm":8,min:9,max:10},fn=0,gn=1,mn=2,yn=3,xn=4,Sn=5,Qn=class ol{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<fn)}set blend(t){!!(this.data&1<<fn)!==t&&(this.data^=1<<fn)}get offsets(){return!!(this.data&1<<gn)}set offsets(t){!!(this.data&1<<gn)!==t&&(this.data^=1<<gn)}set cullMode(t){if(t==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=t==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<mn)}set culling(t){!!(this.data&1<<mn)!==t&&(this.data^=1<<mn)}get depthTest(){return!!(this.data&1<<yn)}set depthTest(t){!!(this.data&1<<yn)!==t&&(this.data^=1<<yn)}get depthMask(){return!!(this.data&1<<Sn)}set depthMask(t){!!(this.data&1<<Sn)!==t&&(this.data^=1<<Sn)}get clockwiseFrontFace(){return!!(this.data&1<<xn)}set clockwiseFrontFace(t){!!(this.data&1<<xn)!==t&&(this.data^=1<<xn)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=Qu[t]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const t=new ol;return t.depthTest=!1,t.blend=!0,t}};Qn.default2d=Qn.for2d();let Vi=Qn;const al=class Jn extends Be{constructor(t){t={...Jn.defaultOptions,...t},super(t),this.enabled=!0,this._state=Vi.for2d(),this.blendMode=t.blendMode,this.padding=t.padding,typeof t.antialias=="boolean"?this.antialias=t.antialias?"on":"off":this.antialias=t.antialias,this.resolution=t.resolution,this.blendRequired=t.blendRequired,this.clipToViewport=t.clipToViewport,this.addResource("uTexture",0,1),t.blendRequired&&this.addResource("uBackTexture",0,3)}apply(t,e,i,s){t.applyFilter(this,e,i,s)}get blendMode(){return this._state.blendMode}set blendMode(t){this._state.blendMode=t}static from(t){const{gpu:e,gl:i,...s}=t;let r,o;return e&&(r=ce.from(e)),i&&(o=ii.from(i)),new Jn({gpuProgram:r,glProgram:o,...s})}};al.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Ju=al;const tr=[];q.handleByNamedList(E.Environment,tr);async function tp(n){if(!n)for(let t=0;t<tr.length;t++){const e=tr[t];if(e.value.test()){await e.value.load();return}}}let pi;function ep(){if(typeof pi=="boolean")return pi;try{pi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{pi=!1}return pi}function jo(n,t,e=2){const i=t&&t.length,s=i?t[0]*e:n.length;let r=hl(n,0,s,e,!0);const o=[];if(!r||r.next===r.prev)return o;let a,h,l;if(i&&(r=op(n,t,r,e)),n.length>80*e){a=n[0],h=n[1];let c=a,d=h;for(let u=e;u<s;u+=e){const p=n[u],g=n[u+1];p<a&&(a=p),g<h&&(h=g),p>c&&(c=p),g>d&&(d=g)}l=Math.max(c-a,d-h),l=l!==0?32767/l:0}return Fi(r,o,e,a,h,l,0),o}function hl(n,t,e,i,s){let r;if(s===yp(n,t,e,i)>0)for(let o=t;o<e;o+=i)r=Zo(o/i|0,n[o],n[o+1],r);else for(let o=e-i;o>=t;o-=i)r=Zo(o/i|0,n[o],n[o+1],r);return r&&ni(r,r.next)&&(zi(r),r=r.next),r}function ze(n,t){if(!n)return n;t||(t=n);let e=n,i;do if(i=!1,!e.steiner&&(ni(e,e.next)||ot(e.prev,e,e.next)===0)){if(zi(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Fi(n,t,e,i,s,r,o){if(!n)return;!o&&r&&dp(n,i,s,r);let a=n;for(;n.prev!==n.next;){const h=n.prev,l=n.next;if(r?sp(n,i,s,r):ip(n)){t.push(h.i,n.i,l.i),zi(n),n=l.next,a=l.next;continue}if(n=l,n===a){o?o===1?(n=np(ze(n),t),Fi(n,t,e,i,s,r,2)):o===2&&rp(n,t,e,i,s,r):Fi(ze(n),t,e,i,s,r,1);break}}}function ip(n){const t=n.prev,e=n,i=n.next;if(ot(t,e,i)>=0)return!1;const s=t.x,r=e.x,o=i.x,a=t.y,h=e.y,l=i.y,c=Math.min(s,r,o),d=Math.min(a,h,l),u=Math.max(s,r,o),p=Math.max(a,h,l);let g=i.next;for(;g!==t;){if(g.x>=c&&g.x<=u&&g.y>=d&&g.y<=p&&bi(s,a,r,h,o,l,g.x,g.y)&&ot(g.prev,g,g.next)>=0)return!1;g=g.next}return!0}function sp(n,t,e,i){const s=n.prev,r=n,o=n.next;if(ot(s,r,o)>=0)return!1;const a=s.x,h=r.x,l=o.x,c=s.y,d=r.y,u=o.y,p=Math.min(a,h,l),g=Math.min(c,d,u),y=Math.max(a,h,l),m=Math.max(c,d,u),x=er(p,g,t,e,i),S=er(y,m,t,e,i);let v=n.prevZ,b=n.nextZ;for(;v&&v.z>=x&&b&&b.z<=S;){if(v.x>=p&&v.x<=y&&v.y>=g&&v.y<=m&&v!==s&&v!==o&&bi(a,c,h,d,l,u,v.x,v.y)&&ot(v.prev,v,v.next)>=0||(v=v.prevZ,b.x>=p&&b.x<=y&&b.y>=g&&b.y<=m&&b!==s&&b!==o&&bi(a,c,h,d,l,u,b.x,b.y)&&ot(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;v&&v.z>=x;){if(v.x>=p&&v.x<=y&&v.y>=g&&v.y<=m&&v!==s&&v!==o&&bi(a,c,h,d,l,u,v.x,v.y)&&ot(v.prev,v,v.next)>=0)return!1;v=v.prevZ}for(;b&&b.z<=S;){if(b.x>=p&&b.x<=y&&b.y>=g&&b.y<=m&&b!==s&&b!==o&&bi(a,c,h,d,l,u,b.x,b.y)&&ot(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function np(n,t){let e=n;do{const i=e.prev,s=e.next.next;!ni(i,s)&&cl(i,e,e.next,s)&&Bi(i,s)&&Bi(s,i)&&(t.push(i.i,e.i,s.i),zi(e),zi(e.next),e=n=s),e=e.next}while(e!==n);return ze(e)}function rp(n,t,e,i,s,r){let o=n;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&fp(o,a)){let h=dl(o,a);o=ze(o,o.next),h=ze(h,h.next),Fi(o,t,e,i,s,r,0),Fi(h,t,e,i,s,r,0);return}a=a.next}o=o.next}while(o!==n)}function op(n,t,e,i){const s=[];for(let r=0,o=t.length;r<o;r++){const a=t[r]*i,h=r<o-1?t[r+1]*i:n.length,l=hl(n,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(pp(l))}s.sort(ap);for(let r=0;r<s.length;r++)e=hp(s[r],e);return e}function ap(n,t){let e=n.x-t.x;if(e===0&&(e=n.y-t.y,e===0)){const i=(n.next.y-n.y)/(n.next.x-n.x),s=(t.next.y-t.y)/(t.next.x-t.x);e=i-s}return e}function hp(n,t){const e=lp(n,t);if(!e)return t;const i=dl(e,n);return ze(i,i.next),ze(e,e.next)}function lp(n,t){let e=t;const i=n.x,s=n.y;let r=-1/0,o;if(ni(n,e))return e;do{if(ni(n,e.next))return e.next;if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){const d=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(d<=i&&d>r&&(r=d,o=e.x<e.next.x?e:e.next,d===i))return o}e=e.next}while(e!==t);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;e=o;do{if(i>=e.x&&e.x>=h&&i!==e.x&&ll(s<l?i:r,s,h,l,s<l?r:i,s,e.x,e.y)){const d=Math.abs(s-e.y)/(i-e.x);Bi(e,n)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&cp(o,e)))&&(o=e,c=d)}e=e.next}while(e!==a);return o}function cp(n,t){return ot(n.prev,n,t.prev)<0&&ot(t.next,n,n.next)<0}function dp(n,t,e,i){let s=n;do s.z===0&&(s.z=er(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==n);s.prevZ.nextZ=null,s.prevZ=null,up(s)}function up(n){let t,e=1;do{let i=n,s;n=null;let r=null;for(t=0;i;){t++;let o=i,a=0;for(let l=0;l<e&&(a++,o=o.nextZ,!!o);l++);let h=e;for(;a>0||h>0&&o;)a!==0&&(h===0||!o||i.z<=o.z)?(s=i,i=i.nextZ,a--):(s=o,o=o.nextZ,h--),r?r.nextZ=s:n=s,s.prevZ=r,r=s;i=o}r.nextZ=null,e*=2}while(t>1);return n}function er(n,t,e,i,s){return n=(n-e)*s|0,t=(t-i)*s|0,n=(n|n<<8)&16711935,n=(n|n<<4)&252645135,n=(n|n<<2)&858993459,n=(n|n<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,n|t<<1}function pp(n){let t=n,e=n;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==n);return e}function ll(n,t,e,i,s,r,o,a){return(s-o)*(t-a)>=(n-o)*(r-a)&&(n-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(r-a)>=(s-o)*(i-a)}function bi(n,t,e,i,s,r,o,a){return!(n===o&&t===a)&&ll(n,t,e,i,s,r,o,a)}function fp(n,t){return n.next.i!==t.i&&n.prev.i!==t.i&&!gp(n,t)&&(Bi(n,t)&&Bi(t,n)&&mp(n,t)&&(ot(n.prev,n,t.prev)||ot(n,t.prev,t))||ni(n,t)&&ot(n.prev,n,n.next)>0&&ot(t.prev,t,t.next)>0)}function ot(n,t,e){return(t.y-n.y)*(e.x-t.x)-(t.x-n.x)*(e.y-t.y)}function ni(n,t){return n.x===t.x&&n.y===t.y}function cl(n,t,e,i){const s=ss(ot(n,t,e)),r=ss(ot(n,t,i)),o=ss(ot(e,i,n)),a=ss(ot(e,i,t));return!!(s!==r&&o!==a||s===0&&is(n,e,t)||r===0&&is(n,i,t)||o===0&&is(e,n,i)||a===0&&is(e,t,i))}function is(n,t,e){return t.x<=Math.max(n.x,e.x)&&t.x>=Math.min(n.x,e.x)&&t.y<=Math.max(n.y,e.y)&&t.y>=Math.min(n.y,e.y)}function ss(n){return n>0?1:n<0?-1:0}function gp(n,t){let e=n;do{if(e.i!==n.i&&e.next.i!==n.i&&e.i!==t.i&&e.next.i!==t.i&&cl(e,e.next,n,t))return!0;e=e.next}while(e!==n);return!1}function Bi(n,t){return ot(n.prev,n,n.next)<0?ot(n,t,n.next)>=0&&ot(n,n.prev,t)>=0:ot(n,t,n.prev)<0||ot(n,n.next,t)<0}function mp(n,t){let e=n,i=!1;const s=(n.x+t.x)/2,r=(n.y+t.y)/2;do e.y>r!=e.next.y>r&&e.next.y!==e.y&&s<(e.next.x-e.x)*(r-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==n);return i}function dl(n,t){const e=ir(n.i,n.x,n.y),i=ir(t.i,t.x,t.y),s=n.next,r=t.prev;return n.next=t,t.prev=n,e.next=s,s.prev=e,i.next=e,e.prev=i,r.next=i,i.prev=r,i}function Zo(n,t,e,i){const s=ir(n,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function zi(n){n.next.prev=n.prev,n.prev.next=n.next,n.prevZ&&(n.prevZ.nextZ=n.nextZ),n.nextZ&&(n.nextZ.prevZ=n.prevZ)}function ir(n,t,e){return{i:n,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function yp(n,t,e,i){let s=0;for(let r=t,o=e-i;r<e;r+=i)s+=(n[o]-n[r])*(n[r+1]+n[o+1]),o=r;return s}const xp=jo.default||jo;var ul=(n=>(n[n.NONE=0]="NONE",n[n.COLOR=16384]="COLOR",n[n.STENCIL=1024]="STENCIL",n[n.DEPTH=256]="DEPTH",n[n.COLOR_DEPTH=16640]="COLOR_DEPTH",n[n.COLOR_STENCIL=17408]="COLOR_STENCIL",n[n.DEPTH_STENCIL=1280]="DEPTH_STENCIL",n[n.ALL=17664]="ALL",n))(ul||{});class Sp{constructor(t){this.items=[],this._name=t}emit(t,e,i,s,r,o,a,h){const{name:l,items:c}=this;for(let d=0,u=c.length;d<u;d++)c[d][l](t,e,i,s,r,o,a,h);return this}add(t){return t[this._name]&&(this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return e!==-1&&this.items.splice(e,1),this}contains(t){return this.items.indexOf(t)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const vp=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],pl=class fl extends Zt{constructor(t){super(),this.tick=0,this.uid=ct("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=t.type,this.name=t.name,this.config=t;const e=[...vp,...this.config.runners??[]];this._addRunners(...e),this._unsafeEvalCheck()}async init(t={}){const e=t.skipExtensionImports===!0?!0:t.manageImports===!1;await tp(e),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)t={...this._systemsHash[i].constructor.defaultOptions,...t};t={...fl.defaultOptions,...t},this._roundPixels=t.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(t);this._initOptions=t}render(t,e){this.tick++;let i=t;if(i instanceof W&&(i={container:i},e&&(V(K,"passing a second argument is deprecated, please use render options instead"),i.target=e.renderTexture)),i.target||(i.target=this.view.renderTarget),i.target===this.view.renderTarget&&(this._lastObjectRendered=i.container,i.clearColor??(i.clearColor=this.background.colorRgba),i.clear??(i.clear=this.background.clearBeforeRender)),i.clearColor){const s=Array.isArray(i.clearColor)&&i.clearColor.length===4;i.clearColor=s?i.clearColor:nt.shared.setValue(i.clearColor).toArray()}i.transform||(i.container.updateLocalTransform(),i.transform=i.container.localTransform),i.container.visible&&(i.container.enableRenderGroup(),this.runners.prerender.emit(i),this.runners.renderStart.emit(i),this.runners.render.emit(i),this.runners.renderEnd.emit(i),this.runners.postrender.emit(i))}resize(t,e,i){const s=this.view.resolution;this.view.resize(t,e,i),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),i!==void 0&&i!==s&&this.runners.resolutionChange.emit(i)}clear(t={}){const e=this;t.target||(t.target=e.renderTarget.renderTarget),t.clearColor||(t.clearColor=this.background.colorRgba),t.clear??(t.clear=ul.ALL);const{clear:i,clearColor:s,target:r,mipLevel:o,layer:a}=t;nt.shared.setValue(s??this.background.colorRgba),e.renderTarget.clear(r,i,nt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(t){this.view.resolution=t,this.runners.resolutionChange.emit(t)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...t){t.forEach(e=>{this.runners[e]=new Sp(e)})}_addSystems(t){let e;for(e in t){const i=t[e];this._addSystem(i.value,i.name)}}_addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(t,e){const i=e.reduce((s,r)=>(s[r.name]=r.value,s),{});t.forEach(s=>{const r=s.value,o=s.name,a=i[o];this.renderPipes[o]=new r(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(t=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(t),(t===!0||typeof t=="object"&&t.releaseGlobalResources)&&Hi.release(),Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(t){return this.textureGenerator.generateTexture(t)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!ep())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}resetState(){this.runners.resetState.emit()}};pl.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let gl=pl,ns;function bp(n){return ns!==void 0||(ns=(()=>{var e;const t={stencil:!0,failIfMajorPerformanceCaveat:n??gl.defaultOptions.failIfMajorPerformanceCaveat};try{if(!$.get().getWebGLRenderingContext())return!1;let s=$.get().createCanvas().getContext("webgl",t);const r=!!((e=s==null?void 0:s.getContextAttributes())!=null&&e.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,r}catch{return!1}})()),ns}let rs;async function wp(n={}){return rs!==void 0||(rs=await(async()=>{const t=$.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(n)).requestDevice(),!0}catch{return!1}})()),rs}const qo=["webgl","webgpu","canvas"];async function Cp(n){let t=[];n.preference?(t.push(n.preference),qo.forEach(r=>{r!==n.preference&&t.push(r)})):t=qo.slice();let e,i={};for(let r=0;r<t.length;r++){const o=t[r];if(o==="webgpu"&&await wp()){const{WebGPURenderer:a}=await Ae(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.DPBWbSBB.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));e=a,i={...n,...n.webgpu};break}else if(o==="webgl"&&bp(n.failIfMajorPerformanceCaveat??gl.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await Ae(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.B0g4W2sN.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));e=a,i={...n,...n.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await Ae(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.BrFqgMtf.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));e=a,i={...n,...n.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!e)throw new Error("No available renderer for the current environment");const s=new e;return await s.init(i),s}const ml="8.16.0";class yl{static init(){var t;(t=globalThis.__PIXI_APP_INIT__)==null||t.call(globalThis,this,ml)}static destroy(){}}yl.extension=E.Application;class _p{constructor(t){this._renderer=t}init(){var t;(t=globalThis.__PIXI_RENDERER_INIT__)==null||t.call(globalThis,this._renderer,ml)}destroy(){this._renderer=null}}_p.extension={type:[E.WebGLSystem,E.WebGPUSystem],name:"initHook",priority:-10};class xl{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:r}=this._resizeTo;e=s,i=r}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}xl.extension=E.Application;class Sl{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Fe.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?mt.shared:new mt,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}Sl.extension=E.Application;q.add(xl);q.add(Sl);const vl=class sr{constructor(...t){this.stage=new W,t[0]!==void 0&&V(K,"Application constructor options are deprecated, please use Application.init() instead.")}async init(t){t={...t},this.stage||(this.stage=new W),this.renderer=await Cp(t),sr._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(K,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(t=!1,e=!1){const i=sr._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};vl._plugins=[];let bl=vl;q.handleByList(E.Application,bl._plugins);q.add(yl);const vn={test(n){return typeof n=="string"&&n.startsWith("info face=")},parse(n){const t=n.match(/^[a-z]+\s+.+$/gm),e={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in t){const u=t[d].match(/^[a-z]+/gm)[0],p=t[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),g={};for(const y in p){const m=p[y].split("="),x=m[0],S=m[1].replace(/"/gm,""),v=parseFloat(S),b=isNaN(v)?S:v;g[x]=b}e[u].push(g)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=e.info,[r]=e.common,[o]=e.distanceField??[];o&&(i.distanceField={range:parseInt(o.distanceRange,10),type:o.fieldType}),i.fontSize=parseInt(s.size,10),i.fontFamily=s.face,i.lineHeight=parseInt(r.lineHeight,10);const a=e.page;for(let d=0;d<a.length;d++)i.pages.push({id:parseInt(a[d].id,10)||0,file:a[d].file});const h={};i.baseLineOffset=i.lineHeight-parseInt(r.base,10);const l=e.char;for(let d=0;d<l.length;d++){const u=l[d],p=parseInt(u.id,10);let g=u.letter??u.char??String.fromCharCode(p);g==="space"&&(g=" "),h[p]=g,i.chars[g]={id:p,page:parseInt(u.page,10)||0,x:parseInt(u.x,10),y:parseInt(u.y,10),width:parseInt(u.width,10),height:parseInt(u.height,10),xOffset:parseInt(u.xoffset,10),yOffset:parseInt(u.yoffset,10),xAdvance:parseInt(u.xadvance,10),kerning:{}}}const c=e.kerning||[];for(let d=0;d<c.length;d++){const u=parseInt(c[d].first,10),p=parseInt(c[d].second,10),g=parseInt(c[d].amount,10);i.chars[h[p]].kerning[h[u]]=g}return i}},Ko={test(n){const t=n;return typeof t!="string"&&"getElementsByTagName"in t&&t.getElementsByTagName("page").length&&t.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(n){const t={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},e=n.getElementsByTagName("info")[0],i=n.getElementsByTagName("common")[0],s=n.getElementsByTagName("distanceField")[0];s&&(t.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const r=n.getElementsByTagName("page"),o=n.getElementsByTagName("char"),a=n.getElementsByTagName("kerning");t.fontSize=parseInt(e.getAttribute("size"),10),t.fontFamily=e.getAttribute("face"),t.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<r.length;l++)t.pages.push({id:parseInt(r[l].getAttribute("id"),10)||0,file:r[l].getAttribute("file")});const h={};t.baseLineOffset=t.lineHeight-parseInt(i.getAttribute("base"),10);for(let l=0;l<o.length;l++){const c=o[l],d=parseInt(c.getAttribute("id"),10);let u=c.getAttribute("letter")??c.getAttribute("char")??String.fromCharCode(d);u==="space"&&(u=" "),h[d]=u,t.chars[u]={id:d,page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xOffset:parseInt(c.getAttribute("xoffset"),10),yOffset:parseInt(c.getAttribute("yoffset"),10),xAdvance:parseInt(c.getAttribute("xadvance"),10),kerning:{}}}for(let l=0;l<a.length;l++){const c=parseInt(a[l].getAttribute("first"),10),d=parseInt(a[l].getAttribute("second"),10),u=parseInt(a[l].getAttribute("amount"),10);t.chars[h[d]].kerning[h[c]]=u}return t}},Qo={test(n){return typeof n=="string"&&n.match(/<font(\s|>)/)?Ko.test($.get().parseXML(n)):!1},parse(n){return Ko.parse($.get().parseXML(n))}},Pp=[".xml",".fnt"],Mp={extension:{type:E.CacheParser,name:"cacheBitmapFont"},test:n=>!!(n!=null&&n.pages)&&!!(n!=null&&n.chars)&&typeof(n==null?void 0:n.fontFamily)=="string",getCacheableAssets(n,t){const e={};return n.forEach(i=>{e[i]=t,e[`${i}-bitmap`]=t}),e[`${t.fontFamily}-bitmap`]=t,e}},Tp={extension:{type:E.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(n){return Pp.includes(Mt.extname(n).toLowerCase())},async testParse(n){return vn.test(n)||Qo.test(n)},async parse(n,t,e){const i=vn.test(n)?vn.parse(n):Qo.parse(n),{src:s}=t,{pages:r}=i,o=[],a=i.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let u=0;u<r.length;++u){const p=r[u].file;let g=Mt.join(Mt.dirname(s),p);g=Zn(g,s),o.push({src:g,data:a})}const[h,{BitmapFont:l}]=await Promise.all([e.load(o),Ae(()=>import("./BitmapFont.Bt2l0bgn.js"),__vite__mapDeps([10,2,3,4]))]),c=o.map(u=>h[u.src]);return new l({data:i,textures:c},s)},async load(n,t){return await(await $.get().fetch(n)).text()},async unload(n,t,e){await Promise.all(n.pages.map(i=>e.unload(i.texture.source._sourceOrigin))),n.destroy()}};class Ap{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}const Rp={extension:{type:E.CacheParser,name:"cacheTextureArray"},test:n=>Array.isArray(n)&&n.every(t=>t instanceof G),getCacheableAssets:(n,t)=>{const e={};return n.forEach(i=>{t.forEach((s,r)=>{e[i+(r===0?"":r+1)]=s})}),e}};async function wl(n){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=n});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(n)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const kp={extension:{type:E.DetectionParser,priority:1},test:async()=>wl("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async n=>[...n,"avif"],remove:async n=>n.filter(t=>t!=="avif")},Jo=["png","jpg","jpeg"],Ep={extension:{type:E.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async n=>[...n,...Jo],remove:async n=>n.filter(t=>!Jo.includes(t))},Ip="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function Fs(n){return Ip?!1:document.createElement("video").canPlayType(n)!==""}const Dp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/mp4"),add:async n=>[...n,"mp4","m4v"],remove:async n=>n.filter(t=>t!=="mp4"&&t!=="m4v")},Fp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/ogg"),add:async n=>[...n,"ogv"],remove:async n=>n.filter(t=>t!=="ogv")},Bp={extension:{type:E.DetectionParser,priority:0},test:async()=>Fs("video/webm"),add:async n=>[...n,"webm"],remove:async n=>n.filter(t=>t!=="webm")},zp={extension:{type:E.DetectionParser,priority:0},test:async()=>wl("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async n=>[...n,"webp"],remove:async n=>n.filter(t=>t!=="webp")},Cl=class gs{constructor(){this.loadOptions={...gs.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,r=null;if((e.parser||e.loadParser)&&(r=this._parserHash[e.parser||e.loadParser],e.loadParser&&st(`[Assets] "loadParser" is deprecated, use "parser" instead for ${t}`),r||st(`[Assets] specified load parser "${e.parser||e.loadParser}" not found while loading ${t}`)),!r){for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.load&&((o=l.test)!=null&&o.call(l,t,e,this))){r=l;break}}if(!r)return st(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await r.load(t,e,this),i.parser=r;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];l.parse&&l.parse&&await((a=l.testParse)==null?void 0:a.call(l,s,e,this))&&(s=await l.parse(s,e,this)||s,i.parser=l)}return s})(),i}async load(t,e){this._parsersValidated||this._validateParsers();const i=typeof e=="function"?{...gs.defaultOptions,...this.loadOptions,onProgress:e}:{...gs.defaultOptions,...this.loadOptions,...e||{}},{onProgress:s,onError:r,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=bs(t),u=Ot(t,y=>({alias:[y],src:y,data:{}})),p=u.reduce((y,m)=>y+(m.progressSize||1),0),g=u.map(async y=>{const m=Mt.toAbsolute(y.src);c[y.src]||(await this._loadAssetWithRetry(m,y,{onProgress:s,onError:r,strategy:o,retryCount:a,retryDelay:h},c),l+=y.progressSize||1,s&&s(l/p))});return await Promise.all(g),d?c[u[0].src]:c}async unload(t){const i=Ot(t,s=>({alias:[s],src:s})).map(async s=>{var a,h;const r=Mt.toAbsolute(s.src),o=this.promiseCache[r];if(o){const l=await o.promise;delete this.promiseCache[r],await((h=(a=o.parser)==null?void 0:a.unload)==null?void 0:h.call(a,l,s,this))}});await Promise.all(i)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(t=>t.name||t.id).reduce((t,e)=>(!e.name&&!e.id?st("[Assets] parser should have an id"):(t[e.name]||t[e.id])&&st(`[Assets] parser id conflict "${e.id}"`),t[e.name]=e,e.id&&(t[e.id]=e),t),{})}async _loadAssetWithRetry(t,e,i,s){let r=0;const{onError:o,strategy:a,retryCount:h,retryDelay:l}=i,c=d=>new Promise(u=>setTimeout(u,d));for(;;)try{this.promiseCache[t]||(this.promiseCache[t]=this._getLoadPromiseAndParser(t,e)),s[e.src]=await this.promiseCache[t].promise;return}catch(d){delete this.promiseCache[t],delete s[e.src],r++;const u=a!=="retry"||r>h;if(a==="retry"&&!u){o&&o(d,e),await c(l);continue}if(a==="skip"){o&&o(d,e);return}o&&o(d,e);const p=new Error(`[Loader.load] Failed to load ${t}.
|
|
24
24
|
${d}`);throw d instanceof Error&&d.stack&&(p.stack=d.stack),p}}};Cl.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let Lp=Cl;function pe(n,t){if(Array.isArray(t)){for(const e of t)if(n.startsWith(`data:${e}`))return!0;return!1}return n.startsWith(`data:${t}`)}function hi(n,t){const e=n.split("?")[0],i=Mt.extname(e).toLowerCase();return Array.isArray(t)?t.includes(i):i===t}const Op=".json",Wp="application/json",Gp={extension:{type:E.LoadParser,priority:ue.Low},name:"loadJson",id:"json",test(n){return pe(n,Wp)||hi(n,Op)},async load(n){return await(await $.get().fetch(n)).json()}},Up=".txt",Hp="text/plain",Vp={name:"loadTxt",id:"text",extension:{type:E.LoadParser,priority:ue.Low,name:"loadTxt"},test(n){return pe(n,Hp)||hi(n,Up)},async load(n){return await(await $.get().fetch(n)).text()}},Np=["normal","bold","100","200","300","400","500","600","700","800","900"],$p=[".ttf",".otf",".woff",".woff2"],Yp=["font/ttf","font/otf","font/woff","font/woff2"],Xp=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function jp(n){const t=Mt.extname(n),s=Mt.basename(n,t).replace(/(-|_)/g," ").toLowerCase().split(" ").map(a=>a.charAt(0).toUpperCase()+a.slice(1));let r=s.length>0;for(const a of s)if(!a.match(Xp)){r=!1;break}let o=s.join(" ");return r||(o=`"${o.replace(/[\\"]/g,"\\$&")}"`),o}const Zp=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function qp(n){return Zp.test(n)?n:encodeURI(n)}const Kp={extension:{type:E.LoadParser,priority:ue.Low},name:"loadWebFont",id:"web-font",test(n){return pe(n,Yp)||hi(n,$p)},async load(n,t){var i,s,r;const e=$.get().getFontFaceSet();if(e){const o=[],a=((i=t.data)==null?void 0:i.family)??jp(n),h=((r=(s=t.data)==null?void 0:s.weights)==null?void 0:r.filter(c=>Np.includes(c)))??["normal"],l=t.data??{};for(let c=0;c<h.length;c++){const d=h[c],u=new FontFace(a,`url(${qp(n)})`,{...l,weight:d});await u.load(),e.add(u),o.push(u)}return yt.has(`${a}-and-url`)?yt.get(`${a}-and-url`).entries.push({url:n,faces:o}):yt.set(`${a}-and-url`,{entries:[{url:n,faces:o}]}),o.length===1?o[0]:o}return st("[loadWebFont] FontFace API is not supported. Skipping loading font"),null},unload(n){const t=Array.isArray(n)?n:[n],e=t[0].family,i=yt.get(`${e}-and-url`),s=i.entries.find(r=>r.faces.some(o=>t.indexOf(o)!==-1));s.faces=s.faces.filter(r=>t.indexOf(r)===-1),s.faces.length===0&&(i.entries=i.entries.filter(r=>r!==s)),t.forEach(r=>{$.get().getFontFaceSet().delete(r)}),i.entries.length===0&&yt.remove(`${e}-and-url`)}};var Qp=tf,bn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Jp=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function tf(n){var t=[];return n.replace(Jp,function(e,i,s){var r=i.toLowerCase();for(s=sf(s),r=="m"&&s.length>2&&(t.push([i].concat(s.splice(0,2))),r="l",i=i=="m"?"l":"L");;){if(s.length==bn[r])return s.unshift(i),t.push(s);if(s.length<bn[r])throw new Error("malformed path data");t.push([i].concat(s.splice(0,bn[r])))}}),t}var ef=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function sf(n){var t=n.match(ef);return t?t.map(Number):[]}const nf=xh(Qp);function rf(n,t){const e=nf(n),i=[];let s=null,r=0,o=0;for(let a=0;a<e.length;a++){const h=e[a],l=h[0],c=h;switch(l){case"M":r=c[1],o=c[2],t.moveTo(r,o);break;case"m":r+=c[1],o+=c[2],t.moveTo(r,o);break;case"H":r=c[1],t.lineTo(r,o);break;case"h":r+=c[1],t.lineTo(r,o);break;case"V":o=c[1],t.lineTo(r,o);break;case"v":o+=c[1],t.lineTo(r,o);break;case"L":r=c[1],o=c[2],t.lineTo(r,o);break;case"l":r+=c[1],o+=c[2],t.lineTo(r,o);break;case"C":r=c[5],o=c[6],t.bezierCurveTo(c[1],c[2],c[3],c[4],r,o);break;case"c":t.bezierCurveTo(r+c[1],o+c[2],r+c[3],o+c[4],r+c[5],o+c[6]),r+=c[5],o+=c[6];break;case"S":r=c[3],o=c[4],t.bezierCurveToShort(c[1],c[2],r,o);break;case"s":t.bezierCurveToShort(r+c[1],o+c[2],r+c[3],o+c[4]),r+=c[3],o+=c[4];break;case"Q":r=c[3],o=c[4],t.quadraticCurveTo(c[1],c[2],r,o);break;case"q":t.quadraticCurveTo(r+c[1],o+c[2],r+c[3],o+c[4]),r+=c[3],o+=c[4];break;case"T":r=c[1],o=c[2],t.quadraticCurveToShort(r,o);break;case"t":r+=c[1],o+=c[2],t.quadraticCurveToShort(r,o);break;case"A":r=c[6],o=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],r,o);break;case"a":r+=c[6],o+=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],r,o);break;case"Z":case"z":t.closePath(),i.length>0&&(s=i.pop(),s?(r=s.startX,o=s.startY):(r=0,o=0)),s=null;break;default:st(`Unknown SVG path command: ${l}`)}l!=="Z"&&l!=="z"&&s===null&&(s={startX:r,startY:o},i.push(s))}return t}class Bs{constructor(t=0,e=0,i=0){this.type="circle",this.x=t,this.y=e,this.radius=i}clone(){return new Bs(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-t,r=this.y-e;return s*=s,r*=r,s+r<=i}strokeContains(t,e,i,s=.5){if(this.radius===0)return!1;const r=this.x-t,o=this.y-e,a=this.radius,h=(1-s)*i,l=Math.sqrt(r*r+o*o);return l<=a+h&&l>a-(i-h)}getBounds(t){return t||(t=new J),t.x=this.x-this.radius,t.y=this.y-this.radius,t.width=this.radius*2,t.height=this.radius*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.radius=t.radius,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class Rr{constructor(t=0,e=0,i=0,s=0){this.type="ellipse",this.x=t,this.y=e,this.halfWidth=i,this.halfHeight=s}clone(){return new Rr(this.x,this.y,this.halfWidth,this.halfHeight)}contains(t,e){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let i=(t-this.x)/this.halfWidth,s=(e-this.y)/this.halfHeight;return i*=i,s*=s,i+s<=1}strokeContains(t,e,i,s=.5){const{halfWidth:r,halfHeight:o}=this;if(r<=0||o<=0)return!1;const a=i*(1-s),h=i-a,l=r-h,c=o-h,d=r+a,u=o+a,p=t-this.x,g=e-this.y,y=p*p/(l*l)+g*g/(c*c),m=p*p/(d*d)+g*g/(u*u);return y>1&&m<=1}getBounds(t){return t||(t=new J),t.x=this.x-this.halfWidth,t.y=this.y-this.halfHeight,t.width=this.halfWidth*2,t.height=this.halfHeight*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.halfWidth=t.halfWidth,this.halfHeight=t.halfHeight,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function of(n,t,e,i,s,r){const o=n-e,a=t-i,h=s-e,l=r-i,c=o*h+a*l,d=h*h+l*l;let u=-1;d!==0&&(u=c/d);let p,g;u<0?(p=e,g=i):u>1?(p=s,g=r):(p=e+u*h,g=i+u*l);const y=n-p,m=t-g;return y*y+m*m}let af,hf;class Re{constructor(...t){this.type="polygon";let e=Array.isArray(t[0])?t[0]:t;if(typeof e[0]!="number"){const i=[];for(let s=0,r=e.length;s<r;s++)i.push(e[s].x,e[s].y);e=i}this.points=e,this.closePath=!0}isClockwise(){let t=0;const e=this.points,i=e.length;for(let s=0;s<i;s+=2){const r=e[s],o=e[s+1],a=e[(s+2)%i],h=e[(s+3)%i];t+=(a-r)*(h+o)}return t<0}containsPolygon(t){const e=this.getBounds(af),i=t.getBounds(hf);if(!e.containsRect(i))return!1;const s=t.points;for(let r=0;r<s.length;r+=2){const o=s[r],a=s[r+1];if(!this.contains(o,a))return!1}return!0}clone(){const t=this.points.slice(),e=new Re(t);return e.closePath=this.closePath,e}contains(t,e){let i=!1;const s=this.points.length/2;for(let r=0,o=s-1;r<s;o=r++){const a=this.points[r*2],h=this.points[r*2+1],l=this.points[o*2],c=this.points[o*2+1];h>e!=c>e&&t<(l-a)*((e-h)/(c-h))+a&&(i=!i)}return i}strokeContains(t,e,i,s=.5){const r=i*i,o=r*(1-s),a=r-o,{points:h}=this,l=h.length-(this.closePath?0:2);for(let c=0;c<l;c+=2){const d=h[c],u=h[c+1],p=h[(c+2)%h.length],g=h[(c+3)%h.length],y=of(t,e,d,u,p,g),m=Math.sign((p-d)*(e-u)-(g-u)*(t-d));if(y<=(m<0?a:o))return!0}return!1}getBounds(t){t||(t=new J);const e=this.points;let i=1/0,s=-1/0,r=1/0,o=-1/0;for(let a=0,h=e.length;a<h;a+=2){const l=e[a],c=e[a+1];i=l<i?l:i,s=l>s?l:s,r=c<r?c:r,o=c>o?c:o}return t.x=i,t.width=s-i,t.y=r,t.height=o-r,t}copyFrom(t){return this.points=t.points.slice(),this.closePath=t.closePath,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((t,e)=>`${t}, ${e}`,"")}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return V("8.11.0","Polygon.lastX is deprecated, please use Polygon.lastX instead."),this.points[this.points.length-2]}get y(){return V("8.11.0","Polygon.y is deprecated, please use Polygon.lastY instead."),this.points[this.points.length-1]}get startX(){return this.points[0]}get startY(){return this.points[1]}}const os=(n,t,e,i,s,r,o)=>{const a=n-e,h=t-i,l=Math.sqrt(a*a+h*h);return l>=s-r&&l<=s+o};class kr{constructor(t=0,e=0,i=0,s=0,r=20){this.type="roundedRectangle",this.x=t,this.y=e,this.width=i,this.height=s,this.radius=r}getBounds(t){return t||(t=new J),t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}clone(){return new kr(this.x,this.y,this.width,this.height,this.radius)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(e>=this.y+i&&e<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let s=t-(this.x+i),r=e-(this.y+i);const o=i*i;if(s*s+r*r<=o||(s=t-(this.x+this.width-i),s*s+r*r<=o)||(r=e-(this.y+this.height-i),s*s+r*r<=o)||(s=t-(this.x+i),s*s+r*r<=o))return!0}return!1}strokeContains(t,e,i,s=.5){const{x:r,y:o,width:a,height:h,radius:l}=this,c=i*(1-s),d=i-c,u=r+l,p=o+l,g=a-l*2,y=h-l*2,m=r+a,x=o+h;return(t>=r-c&&t<=r+d||t>=m-d&&t<=m+c)&&e>=p&&e<=p+y||(e>=o-c&&e<=o+d||e>=x-d&&e<=x+c)&&t>=u&&t<=u+g?!0:t<u&&e<p&&os(t,e,u,p,l,d,c)||t>m-l&&e<p&&os(t,e,m-l,p,l,d,c)||t>m-l&&e>x-l&&os(t,e,m-l,x-l,l,d,c)||t<u&&e>x-l&&os(t,e,u,x-l,l,d,c)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const _l={};function lf(n,t,e){let i=2166136261;for(let s=0;s<t;s++)i^=n[s].uid,i=Math.imul(i,16777619),i>>>=0;return _l[i]||cf(n,t,i,e)}function cf(n,t,e,i){const s={};let r=0;for(let a=0;a<i;a++){const h=a<t?n[a]:G.EMPTY.source;s[r++]=h.source,s[r++]=h.style}const o=new Mi(s);return _l[e]=o,o}class ta{constructor(t){typeof t=="number"?this.rawBinaryData=new ArrayBuffer(t):t instanceof Uint8Array?this.rawBinaryData=t.buffer:this.rawBinaryData=t,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}get float64View(){return this._float64Array||(this._float64Array=new Float64Array(this.rawBinaryData)),this._float64Array}get bigUint64View(){return this._bigUint64Array||(this._bigUint64Array=new BigUint64Array(this.rawBinaryData)),this._bigUint64Array}view(t){return this[`${t}View`]}destroy(){this.rawBinaryData=null,this.uint32View=null,this.float32View=null,this.uint16View=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._int32View=null,this._float64Array=null,this._bigUint64Array=null}static sizeOf(t){switch(t){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${t} isn't a valid view type`)}}}function ea(n,t,e,i){if(e??(e=0),i??(i=Math.min(n.byteLength-e,t.byteLength)),!(e&7)&&!(i&7)){const s=i/8;new Float64Array(t,0,s).set(new Float64Array(n,e,s))}else if(!(e&3)&&!(i&3)){const s=i/4;new Float32Array(t,0,s).set(new Float32Array(n,e,s))}else new Uint8Array(t).set(new Uint8Array(n,e,i))}const df={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var uf=(n=>(n[n.DISABLED=0]="DISABLED",n[n.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",n[n.MASK_ACTIVE=2]="MASK_ACTIVE",n[n.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",n[n.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",n[n.NONE=5]="NONE",n))(uf||{});function ws(n,t){return t.alphaMode==="no-premultiply-alpha"&&df[n]||n}const pf=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
|
|
25
25
|
`);function ff(n){let t="";for(let e=0;e<n;++e)e>0&&(t+=`
|
|
26
26
|
else `),e<n-1&&(t+=`if(test == ${e}.0){}`);return t}function gf(n,t){if(n===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const e=t.createShader(t.FRAGMENT_SHADER);try{for(;;){const i=pf.replace(/%forloop%/gi,ff(n));if(t.shaderSource(e,i),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS))n=n/2|0;else break}}finally{t.deleteShader(e)}return n}let Ue=null;function mf(){var t;if(Ue)return Ue;const n=el();return Ue=n.getParameter(n.MAX_TEXTURE_IMAGE_UNITS),Ue=gf(Ue,n),(t=n.getExtension("WEBGL_lose_context"))==null||t.loseContext(),Ue}class yf{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let t=0;t<this.count;t++){const e=this.textures[t];this.textures[t]=null,this.ids[e.uid]=null}this.count=0}}class xf{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new yf,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null,this.elements=null}}const Ti=[];let Cs=0;Hi.register({clear:()=>{if(Ti.length>0)for(const n of Ti)n&&n.destroy();Ti.length=0,Cs=0}});function ia(){return Cs>0?Ti[--Cs]:new xf}function sa(n){n.elements=null,Ti[Cs++]=n}let fi=0;const Pl=class Ml{constructor(t){this.uid=ct("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t={...Ml.defaultOptions,...t},t.maxTextures||(V("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),t.maxTextures=mf());const{maxTextures:e,attributesInitialSize:i,indicesInitialSize:s}=t;this.attributeBuffer=new ta(i*4),this.indexBuffer=new Uint16Array(s),this.maxTextures=e}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let t=0;t<this.batchIndex;t++)sa(this.batches[t]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(t){this._elements[this.elementSize++]=t,t._indexStart=this.indexSize,t._attributeStart=this.attributeSize,t._batcher=this,this.indexSize+=t.indexSize,this.attributeSize+=t.attributeSize*this.vertexSize}checkAndUpdateTexture(t,e){const i=t._batch.textures.ids[e._source.uid];return!i&&i!==0?!1:(t._textureId=i,t.texture=e,!0)}updateElement(t){this.dirty=!0;const e=this.attributeBuffer;t.packAsQuad?this.packQuadAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId):this.packAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId)}break(t){const e=this._elements;if(!e[this.elementStart])return;let i=ia(),s=i.textures;s.clear();const r=e[this.elementStart];let o=ws(r.blendMode,r.texture._source),a=r.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);const h=this.attributeBuffer.float32View,l=this.attributeBuffer.uint32View,c=this.indexBuffer;let d=this._batchIndexSize,u=this._batchIndexStart,p="startBatch",g=[];const y=this.maxTextures;for(let m=this.elementStart;m<this.elementSize;++m){const x=e[m];e[m]=null;const v=x.texture._source,b=ws(x.blendMode,v),P=o!==b||a!==x.topology;if(v._batchTick===fi&&!P){x._textureId=v._textureBindLocation,d+=x.indexSize,x.packAsQuad?(this.packQuadAttributes(x,h,l,x._attributeStart,x._textureId),this.packQuadIndex(c,x._indexStart,x._attributeStart/this.vertexSize)):(this.packAttributes(x,h,l,x._attributeStart,x._textureId),this.packIndex(x,c,x._indexStart,x._attributeStart/this.vertexSize)),x._batch=i,g.push(x);continue}v._batchTick=fi,(s.count>=y||P)&&(this._finishBatch(i,u,d-u,s,o,a,t,p,g),p="renderBatch",u=d,o=b,a=x.topology,i=ia(),s=i.textures,s.clear(),g=[],++fi),x._textureId=v._textureBindLocation=s.count,s.ids[v.uid]=s.count,s.textures[s.count++]=v,x._batch=i,g.push(x),d+=x.indexSize,x.packAsQuad?(this.packQuadAttributes(x,h,l,x._attributeStart,x._textureId),this.packQuadIndex(c,x._indexStart,x._attributeStart/this.vertexSize)):(this.packAttributes(x,h,l,x._attributeStart,x._textureId),this.packIndex(x,c,x._indexStart,x._attributeStart/this.vertexSize))}s.count>0&&(this._finishBatch(i,u,d-u,s,o,a,t,p,g),u=d,++fi),this.elementStart=this.elementSize,this._batchIndexStart=u,this._batchIndexSize=d}_finishBatch(t,e,i,s,r,o,a,h,l){t.gpuBindGroup=null,t.bindGroup=null,t.action=h,t.batcher=this,t.textures=s,t.blendMode=r,t.topology=o,t.start=e,t.size=i,t.elements=l,++fi,this.batches[this.batchIndex++]=t,a.add(t)}finish(t){this.break(t)}ensureAttributeBuffer(t){t*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(t*4)}ensureIndexBuffer(t){t<=this.indexBuffer.length||this._resizeIndexBuffer(t)}_resizeAttributeBuffer(t){const e=Math.max(t,this.attributeBuffer.size*2),i=new ta(e);ea(this.attributeBuffer.rawBinaryData,i.rawBinaryData),this.attributeBuffer=i}_resizeIndexBuffer(t){const e=this.indexBuffer;let i=Math.max(t,e.length*1.5);i+=i%2;const s=i>65535?new Uint32Array(i):new Uint16Array(i);if(s.BYTES_PER_ELEMENT!==e.BYTES_PER_ELEMENT)for(let r=0;r<e.length;r++)s[r]=e[r];else ea(e.buffer,s.buffer);this.indexBuffer=s}packQuadIndex(t,e,i){t[e]=i+0,t[e+1]=i+1,t[e+2]=i+2,t[e+3]=i+0,t[e+4]=i+2,t[e+5]=i+3}packIndex(t,e,i,s){const r=t.indices,o=t.indexSize,a=t.indexOffset,h=t.attributeOffset;for(let l=0;l<o;l++)e[i++]=s+r[l+a]-h}destroy(t={}){var e;if(this.batches!==null){for(let i=0;i<this.batchIndex;i++)sa(this.batches[i]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,t.shader&&((e=this.shader)==null||e.destroy(),this.shader=null);for(let i=0;i<this._elements.length;i++)this._elements[i]&&(this._elements[i]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};Pl.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let Sf=Pl;var ft=(n=>(n[n.MAP_READ=1]="MAP_READ",n[n.MAP_WRITE=2]="MAP_WRITE",n[n.COPY_SRC=4]="COPY_SRC",n[n.COPY_DST=8]="COPY_DST",n[n.INDEX=16]="INDEX",n[n.VERTEX=32]="VERTEX",n[n.UNIFORM=64]="UNIFORM",n[n.STORAGE=128]="STORAGE",n[n.INDIRECT=256]="INDIRECT",n[n.QUERY_RESOLVE=512]="QUERY_RESOLVE",n[n.STATIC=1024]="STATIC",n))(ft||{});class le extends Zt{constructor(t){let{data:e,size:i}=t;const{usage:s,label:r,shrinkToFit:o}=t;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=ct("buffer"),this._resourceType="buffer",this._resourceId=ct("resource"),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,e instanceof Array&&(e=new Float32Array(e)),this._data=e,i??(i=e==null?void 0:e.byteLength);const a=!!e;this.descriptor={size:i,usage:s,mappedAtCreation:a,label:r},this.shrinkToFit=o??!0}get data(){return this._data}set data(t){this.setDataWithSize(t,t.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&ft.STATIC)}set static(t){t?this.descriptor.usage|=ft.STATIC:this.descriptor.usage&=~ft.STATIC}setDataWithSize(t,e,i){if(this._updateID++,this._updateSize=e*t.BYTES_PER_ELEMENT,this._data===t){i&&this.emit("update",this);return}const s=this._data;if(this._data=t,this._dataInt32=null,!s||s.length!==t.length){!this.shrinkToFit&&s&&t.byteLength<s.byteLength?i&&this.emit("update",this):(this.descriptor.size=t.byteLength,this._resourceId=ct("resource"),this.emit("change",this));return}i&&this.emit("update",this)}update(t){this._updateSize=t??this._updateSize,this._updateID++,this.emit("update",this)}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Tl(n,t){if(!(n instanceof le)){let e=t?ft.INDEX:ft.VERTEX;n instanceof Array&&(t?(n=new Uint32Array(n),e=ft.INDEX|ft.COPY_DST):(n=new Float32Array(n),e=ft.VERTEX|ft.COPY_DST)),n=new le({data:n,label:t?"index-mesh-buffer":"vertex-mesh-buffer",usage:e})}return n}function vf(n,t,e){const i=n.getAttribute(t);if(!i)return e.minX=0,e.minY=0,e.maxX=0,e.maxY=0,e;const s=i.buffer.data;let r=1/0,o=1/0,a=-1/0,h=-1/0;const l=s.BYTES_PER_ELEMENT,c=(i.offset||0)/l,d=(i.stride||2*4)/l;for(let u=c;u<s.length;u+=d){const p=s[u],g=s[u+1];p>a&&(a=p),g>h&&(h=g),p<r&&(r=p),g<o&&(o=g)}return e.minX=r,e.minY=o,e.maxX=a,e.maxY=h,e}function bf(n){return(n instanceof le||Array.isArray(n)||n.BYTES_PER_ELEMENT)&&(n={buffer:n}),n.buffer=Tl(n.buffer,!1),n}class Li extends Zt{constructor(t={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=ct("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new Ft,this._boundsDirty=!0;const{attributes:e,indexBuffer:i,topology:s}=t;if(this.buffers=[],this.attributes={},e)for(const r in e)this.addAttribute(r,e[r]);this.instanceCount=t.instanceCount??1,i&&this.addIndex(i),this.topology=s||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(t){return this.attributes[t]}getIndex(){return this.indexBuffer}getBuffer(t){return this.getAttribute(t).buffer}getSize(){for(const t in this.attributes){const e=this.attributes[t];return e.buffer.data.length/(e.stride/4||e.size)}return 0}addAttribute(t,e){const i=bf(e);this.buffers.indexOf(i.buffer)===-1&&(this.buffers.push(i.buffer),i.buffer.on("update",this.onBufferUpdate,this),i.buffer.on("change",this.onBufferUpdate,this)),this.attributes[t]=i}addIndex(t){this.indexBuffer=Tl(t,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,vf(this,"aPosition",this._bounds)):this._bounds}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null)}destroy(t=!1){var e;this.emit("destroy",this),this.removeAllListeners(),t&&this.buffers.forEach(i=>i.destroy()),this.unload(),(e=this.indexBuffer)==null||e.destroy(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const wf=new Float32Array(1),Cf=new Uint32Array(1);class _f extends Li{constructor(){const e=new le({data:wf,label:"attribute-batch-buffer",usage:ft.VERTEX|ft.COPY_DST,shrinkToFit:!1}),i=new le({data:Cf,label:"index-batch-buffer",usage:ft.INDEX|ft.COPY_DST,shrinkToFit:!1}),s=6*4;super({attributes:{aPosition:{buffer:e,format:"float32x2",stride:s,offset:0},aUV:{buffer:e,format:"float32x2",stride:s,offset:2*4},aColor:{buffer:e,format:"unorm8x4",stride:s,offset:4*4},aTextureIdAndRound:{buffer:e,format:"uint16x2",stride:s,offset:5*4}},indexBuffer:i})}}function na(n,t,e){if(n)for(const i in n){const s=i.toLocaleLowerCase(),r=t[s];if(r){let o=n[i];i==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),e&&r.push(`//----${e}----//`),r.push(o)}else st(`${i} placement hook does not exist in shader`)}}const Pf=/\{\{(.*?)\}\}/g;function ra(n){var i;const t={};return(((i=n.match(Pf))==null?void 0:i.map(s=>s.replace(/[{()}]/g,"")))??[]).forEach(s=>{t[s]=[]}),t}function oa(n,t){let e;const i=/@in\s+([^;]+);/g;for(;(e=i.exec(n))!==null;)t.push(e[1])}function aa(n,t,e=!1){const i=[];oa(t,i),n.forEach(a=>{a.header&&oa(a.header,i)});const s=i;e&&s.sort();const r=s.map((a,h)=>` @location(${h}) ${a},`).join(`
|
|
@@ -741,4 +741,4 @@ fn mainFragment(
|
|
|
741
741
|
|
|
742
742
|
return vec4<f32>(color, 1.0);
|
|
743
743
|
}
|
|
744
|
-
`,entryPoint:"main"}})}),l=new za({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(e,i){this.position.set(e,i)}clear(){this.removeChildren()}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class bS{constructor(t){f(this,"heatmap");f(this,"pointsTopLeftOrigin",[]);f(this,"signalGrid",[]);f(this,"cellSize",2);f(this,"maxDistance",14);f(this,"smoothIterations",10);f(this,"heatmapAlpha",.8);f(this,"isHeatmapDrawn",!1);f(this,"loadTimer",null);f(this,"pendingPoints",null);this.appService=t,this.heatmap=new vS(t);const e=t.heatMapConfig;this.cellSize=e.cellSize,this.maxDistance=e.maxDistance,this.smoothIterations=e.smoothIterations,this.heatmapAlpha=e.heatmapAlpha}draw(t){if(t.length===0){this.clear();return}const e=this.appService;if(!e.isMapDrawn){this.pendingPoints=t;return}this.pendingPoints=null;const{minX:i,minY:s}=e.mapManager.mapBounds,r=t.map(o=>({x:+(o.x-i).toFixed(0),y:+(o.y-s).toFixed(0),signal:o.signal}));this.signalGrid=this.calculateInterpolatedSignal(r),this.heatmap.draw(this.signalGrid,this.heatmapAlpha),this.isHeatmapDrawn=!0}clear(){this.pendingPoints=null,this.pointsTopLeftOrigin=[],this.signalGrid=[],this.heatmap.clear(),this.isHeatmapDrawn=!1}onMapLoaded(){this.loadTimer||(this.pendingPoints&&this.draw(this.pendingPoints),this.loadTimer=setTimeout(()=>{this.loadTimer=null},200))}calculateInterpolatedSignal(t){var p;const e=this.appService,i=((p=e.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:r,maxX:o,maxY:a}=e.mapManager.mapBounds;r=r-i.y,s=s-i.x,a=a-i.y,o=o-i.x;const h=Math.ceil((a-r)/this.cellSize),l=Math.ceil((o-s)/this.cellSize),c=Array(h).fill(null).map(()=>Array(l).fill(null));for(let g=0;g<h;g++){const y=r+g*this.cellSize+this.cellSize/2,m=Math.min(this.cellSize,a-(y-this.cellSize/2));for(let x=0;x<l;x++){const S=s+x*this.cellSize+this.cellSize/2,v=Math.min(this.cellSize,o-(S-this.cellSize/2));let b=0,P=!1;for(let C=0;C<t.length;C++){const _=t[C];if(Math.abs(S-_.x)<=v/2&&Math.abs(y-_.y)<=m/2){const R=1-_.signal/7;b=Math.round(Math.max(b,R)*10)/10,P=!0}}c[g][x]={x:S,y,signal:b,hasPoint:P}}}const d=(g,y)=>{if(t.length===0)return 0;let m=0,x=0;for(const S of t){const v=Math.sqrt((g-S.x)**2+(y-S.y)**2);if(v<=this.maxDistance){const b=1/(1+v),P=1-S.signal/7;x+=b*P,m+=b}}return m===0?0:Math.round(x/m*1e3)/1e3},u=(g,y=1)=>{for(let m=0;m<y;m++){const x=g.map(S=>[...S]);for(let S=1;S<h-1;S++)for(let v=1;v<l-1;v++)if(!g[S][v].hasPoint){let b=0,P=0;const C=4;for(let _=-C;_<=C;_++)for(let R=-C;R<=C;R++){if(_===0&&R===0)continue;const M=S+_,A=v+R;if(M>=0&&M<h&&A>=0&&A<l){const I=1/(1+Math.sqrt(_*_+R*R)*.3);b+=g[M][A].signal*I,P+=I}}if(P>0){const _=b/P,R=.6,M=.4;x[S][v].signal=g[S][v].signal*R+_*M,x[S][v].signal>.1&&(x[S][v].signal=Math.max(x[S][v].signal,.2))}}for(let S=0;S<h;S++)for(let v=0;v<l;v++)g[S][v].signal=x[S][v].signal}};for(let g=0;g<h;g++)for(let y=0;y<l;y++){const m=c[g][y];m.hasPoint||(m.signal=d(m.x,m.y))}return u(c,this.smoothIterations),c}updatePositionByOrigin(t,e){this.heatmap.updatePositionByOrigin(t,e)}destroy(){this.heatmap.destroy()}}class Qr extends H{constructor(e,i){super();f(this,"fillOptions");f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handlePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});f(this,"handleDragPointerMove",e=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,e)});f(this,"handleDragPointerUp",()=>{var e,i;this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});this.appService=e,this.fillOptions=i,this.setupInteraction(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}startDragging(e){var s,r;this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},(r=(s=this.fillOptions).onDragStart)==null||r.call(s,e),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}draw(){const{points:e,fillColor:i}=this.fillOptions;if(e.length<3)return;this.clear();const s=e.flatMap(r=>[r.x,r.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(e){this.fillOptions={...this.fillOptions,...e},e.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(e){this.fillOptions.points=e,this.draw()}updateFillColor(e){this.fillOptions.fillColor=e,this.draw()}stopDragging(){var e;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(e){this.fillOptions.enableInteraction=e,e?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class ri extends W{constructor(e,i){super();f(this,"borderOptions");f(this,"solidLine",null);f(this,"dashGraphics",null);f(this,"fillGraphics",null);f(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=e,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:e=[],closePath:i=!1,style:s}=this.borderOptions;e.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(e,s),s.isDashed?this.drawContinuousDashedBorder(e,i,s):this.drawSolidBorder(e,i,s))}drawFill(e,i){if(!(!i.fillColor||e.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length;s++)this.fillGraphics.lineTo(e[s].x,e[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(e,i,s){const r=this.appService;this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy()),this.solidLine=new H;const o=r.getApp().toFixedSize(s.width);this.solidLine.setStrokeStyle({color:s.color,width:o}),this.solidLine.moveTo(e[0].x,e[0].y);for(let a=1;a<e.length;a++)this.solidLine.lineTo(e[a].x,e[a].y);i&&this.solidLine.lineTo(e[0].x,e[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(e,i,s){if(e.length<2)return;if(!s.dashArray||s.dashArray.length!==2||s.dashArray[0]<=0||s.dashArray[1]<=0){w.warn("Invalid dashArray:",s.dashArray);return}const r=this.appService;this.dashGraphics=new H;const o=r.getApp().toFixedSize(s.width);this.dashGraphics.setStrokeStyle({color:s.color,width:o});const a=Math.max(r.getApp().toFixedSize(s.dashArray[0]),1),h=Math.max(r.getApp().toFixedSize(s.dashArray[1]),1),l=i?[...e,e[0]]:e;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(e,i,s,r){if(i.length<2)return;if(s<=0||r<=0){w.warn("Invalid dash parameters:",{dashLength:s,gapLength:r});return}const o=this.calculatePathSegments(i),a=o.reduce((c,d)=>c+d.length,0);if(a===0)return;const h=s+r;let l=0;for(;l<a;){const c=l+s;c<=a?this.drawContinuousDashSegment(e,o,l,c):this.drawContinuousDashSegment(e,o,l,a),l+=h}}calculatePathSegments(e){const i=[];for(let s=0;s<e.length-1;s++){const r=e[s],o=e[s+1],a=o.x-r.x,h=o.y-r.y,l=Math.sqrt(a*a+h*h);i.push({start:r,end:o,length:l})}return i}drawContinuousDashSegment(e,i,s,r){if(s>=r)return;let o=0,a=!1,h=null;for(const l of i){const c=o,d=o+l.length;if(d>s&&c<r){const u=Math.max(s,c),p=Math.min(r,d),g=(u-c)/l.length,y=(p-c)/l.length,m={x:l.start.x+(l.end.x-l.start.x)*g,y:l.start.y+(l.end.y-l.start.y)*g},x={x:l.start.x+(l.end.x-l.start.x)*y,y:l.start.y+(l.end.y-l.start.y)*y};a?h&&Math.sqrt(Math.pow(m.x-h.x,2)+Math.pow(m.y-h.y,2))>.1&&e.lineTo(m.x,m.y):(e.moveTo(m.x,m.y),a=!0),e.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=r)break}}clearBorder(){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy(),this.fillGraphics=null),this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.dashGraphics&&(this.removeChild(this.dashGraphics),this.dashGraphics.destroy(),this.dashGraphics=null)}updateStyle(e){this.borderOptions.style={...this.borderOptions.style,...e},this.drawBorder()}updatePoints(e){this.borderOptions.points=e,this.drawBorder()}setClosePath(e){this.borderOptions.closePath=e,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class Jr{constructor(t){f(this,"id",null);f(this,"layer",null);f(this,"editingState",{});f(this,"idleState",{});f(this,"host",null);f(this,"onHostDestroyed",null);f(this,"detached",!1);this.deps=t}attach(t,e){this.layer&&this.detach(),this.detached=!1,this.host=t,this.id=e.id,this.editingState=e.editingState,this.idleState=e.idleState??{},this.layer=this.deps.editControls.registerEditControl(e.id,e.layerOptions);const i=()=>this.detach();return this.onHostDestroyed=i,t.once("destroyed",i),this.layer}detach(){this.detached||(this.detached=!0,this.host&&this.onHostDestroyed&&this.host.off("destroyed",this.onHostDestroyed),this.onHostDestroyed=null,this.host=null,this.id!=null&&this.deps.editControls.unregisterEditControl(this.id),this.id=null,this.layer=null)}setEditing(t){if(this.id==null){w.warn("[EditableShape] setEditing called before attach; ignoring");return}this.deps.editControls.updateEditState(this.id,t?this.editingState:this.idleState)}applyEditState(t){if(this.id==null){w.warn("[EditableShape] applyEditState called before attach; ignoring");return}this.deps.editControls.updateEditState(this.id,t)}updatePoints(t,e=!0){var i;(i=this.layer)==null||i.updatePoints(t,e)}getLayer(){return this.layer}getMoveButton(){var t;return((t=this.layer)==null?void 0:t.getMoveButton())??null}}class Es extends Os{constructor(e,{text:i,style:s}){super({text:i,style:s});f(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=Pt(this.updateScale.bind(this),20,{leading:!0,trailing:!0}),this.registerScaleListener(),this.updateScale(this.appService.currentScale)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e<=0||this.scale.set(1/e)}setBaseFontSize(e){this.style.fontSize=e}updateText(e){this.text=e}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Gc extends W{constructor(e){super();f(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.updateScale(this.appService.currentScale),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e!==0&&this.scale.set(1/e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Hs extends Gc{constructor(e,i){super(e);f(this,"background");f(this,"icon");f(this,"options");this.appService=e,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Ut(e),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const e=this.appService,i=this.options.config||e.controlsConfig,s=8,r=i.iconWrapperWidth+s*2,o=i.iconWrapperHeight+s*2;this.hitArea=new J(-r/2,-o/2,r,o)}async render(){this.renderBackground(),this.renderIcon()}renderBackground(){const e=this.appService,i=this.options.config||e.controlsConfig;this.background.clear(),this.background.roundRect(-i.iconWrapperWidth/2,-i.iconWrapperHeight/2,i.iconWrapperWidth,i.iconWrapperHeight,i.iconWrapperBorderRadius).fill(this.options.backgroundColor)}async renderIcon(){try{const e=this.appService,i=this.options.config||e.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(e){w.error(`Failed to load icon: ${this.options.iconAlias}`,e)}}destroy(){super.destroy()}}class Uc extends Hs{constructor(e,i){super(e,i);f(this,"isMoving",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handleMovePointerMove",e=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,e)});f(this,"handleMovePointerUp",()=>{var e,i;this.gestureSession=null,this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});this.appService=e}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startMoving(e)}startMoving(e){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(e.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleMovePointerMove),this.gestureSession.onEnd(this.handleMovePointerUp)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var e,i;this.isMoving&&(this.gestureSession?this.gestureSession.cancel():(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e)))}destroy(){this.stopMoving(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Hc extends Hs{constructor(e,i){super(e,i);f(this,"clickHandler",null);this.appService=e}setupEvents(){this.clickHandler=new St(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),super.destroy()}}const wS=10;class CS extends Hs{constructor(e,i){super(e,i);f(this,"isRotating",!1);f(this,"hasRotated",!1);f(this,"rotationCenter",{x:0,y:0});f(this,"downPosition",{x:0,y:0});f(this,"lastAngle",0);f(this,"clickHandler",null);f(this,"gestureSession",null);f(this,"handleRotationPointerMove",e=>{var o,a,h,l;if(!this.isRotating)return;if(!this.hasRotated){const c=e.global.x-this.downPosition.x,d=e.global.y-this.downPosition.y;if(Math.sqrt(c*c+d*d)<=wS)return;this.hasRotated=!0,(a=(o=this.options).onRotationStart)==null||a.call(o,this.rotationCenter)}const i=this.parent.toLocal(e.global),s=Math.atan2(i.y-this.rotationCenter.y,i.x-this.rotationCenter.x),r=s-this.lastAngle;(l=(h=this.options).onRotationMove)==null||l.call(h,r),this.lastAngle=s});f(this,"handleRotationPointerUp",()=>{var e,i;this.gestureSession=null,this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});this.appService=e}setupEvents(){this.options.onClick&&(this.clickHandler=new St(this,{onClick:()=>{var e,i;this.hasRotated||(i=(e=this.options).onClick)==null||i.call(e)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startRotation(e)}startRotation(e){this.isRotating=!0,this.hasRotated=!1,this.downPosition={x:e.global.x,y:e.global.y};const i=this.options.getTargetPoints();this.rotationCenter=Oe(i);const s=this.parent.toLocal(e.global);this.lastAngle=Math.atan2(s.y-this.rotationCenter.y,s.x-this.rotationCenter.x),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleRotationPointerMove),this.gestureSession.onEnd(this.handleRotationPointerUp)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var e,i;this.isRotating&&(this.gestureSession?this.gestureSession.cancel():(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1))}destroy(){var e;this.stopRotation(),this.gestureSession=null,(e=this.clickHandler)==null||e.destroy(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class vs extends Hs{constructor(e,i){super(e,i);f(this,"isScaling",!1);f(this,"initialButtonPosition",null);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handleScalePointerMove",e=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:r})});f(this,"handleScalePointerUp",()=>{var e,i;this.gestureSession=null,this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});this.appService=e}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startScaling(e)}startScaling(e){var i,s,r,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(e.global),"initialButtonPosition"in this.options)this.initialButtonPosition={x:this.position.x,y:this.position.y},(s=(i=this.options).onScaleStart)==null||s.call(i);else{const a=this.options.getTargetPoints(),h=this.options.getButtonIndex();h>=0&&h<a.length&&(this.initialButtonPosition={...a[h]}),(o=(r=this.options).onScaleStart)==null||o.call(r,h)}this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleScalePointerMove),this.gestureSession.onEnd(this.handleScalePointerUp)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var e,i;this.isScaling&&(this.gestureSession?this.gestureSession.cancel():(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e)))}destroy(){this.stopScaling(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}const pt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class _S extends W{constructor(e,i){super();f(this,"config");f(this,"events");f(this,"zonePoints",[]);f(this,"outlinePoints");f(this,"minSize",.1);f(this,"maxSize");f(this,"sizeConstraintPerEdge");f(this,"initialZonePoints",[]);f(this,"scaleCache",null);f(this,"rotationCache",null);f(this,"outlineBorder");f(this,"moveLine");f(this,"sizeText");f(this,"controlButtons");f(this,"deleteButton",null);f(this,"rotateButton",null);f(this,"scaleButton",null);f(this,"moveButton",null);f(this,"horizontalScaleButton",null);f(this,"verticalScaleButton",null);f(this,"horizontalScaleInitialPosition",null);f(this,"verticalScaleInitialPosition",null);f(this,"clickHandler",null);f(this,"throttledUpdateOutline");this.appService=e,this.zonePoints=i.zonePoints,this.config={...i.config,showScaleButton:i.config.showScaleButton!==void 0?i.config.showScaleButton:!0,showRadialScaleButton:i.config.showRadialScaleButton!==void 0?i.config.showRadialScaleButton:!0,showDeleteButton:i.config.showDeleteButton!==void 0?i.config.showDeleteButton:!0,showMoveButton:i.config.showMoveButton!==void 0?i.config.showMoveButton:!0,showRotateButton:i.config.showRotateButton!==void 0?i.config.showRotateButton:!0,rotateMode:i.config.rotateMode??"step",scaleMode:i.config.scaleMode??"free"},this.events=i.events||{},this.minSize=i.minSize??.1,this.maxSize=i.maxSize,this.sizeConstraintPerEdge=i.sizeConstraintPerEdge,this.throttledUpdateOutline=Pt(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.registerScaleListener()}initializeComponents(){this.outlinePoints=this.calculateOutlinePoints(),this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.moveLine.visible=this.config.showMoveButton||!1,this.sizeText=this.createSizeText(),this.addChild(this.sizeText),this.controlButtons=new W,this.addChild(this.controlButtons),this.createControlButtons(),this.setupClickHandler()}createOutlineBorder(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:r,outlineFillColor:o}=this.config;return new ri(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:e,width:i,isDashed:s,dashArray:r,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:r}=this.config,o=this.calculateMoveLinePoints();return new ri(this.appService,{points:o,closePath:!1,style:{color:e,width:i,isDashed:s,dashArray:r}})}createSizeText(){const e=this.calculateSizeText(),i=new Es(this.appService,{text:e,style:{fontSize:this.config.textFontSize,fontFamily:this.config.textFontFamily,fontWeight:this.config.textFontWeight,fill:this.config.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const r=this.calculateSizeTextRotation();return i.rotation=r,i.eventMode="none",i}createDeleteButton(){const e=new Hc(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.config.deleteIconWrapperFillColor??this.config.iconWrapperFillColor,onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return e.position.set(this.outlinePoints[pt.REMOVE].x,this.outlinePoints[pt.REMOVE].y),e}createRotateButton(){const e=this.config.rotateMode==="step",i=new CS(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.config.iconWrapperFillColor,getTargetPoints:()=>this.zonePoints,onRotationStart:s=>{var r,o;this.initializeRotationCache(s),(o=(r=this.events).onRotateStart)==null||o.call(r,s)},onRotationMove:e?void 0:s=>{var o,a;const r=this.handleInternalRotationMove(s);(a=(o=this.events).onRotateMove)==null||a.call(o,r??void 0)},onClick:e?()=>{var o,a,h,l;const s=this.config.stepRotateAngle??Math.PI/2,r=this.onClickRotateButton(s);(a=(o=this.events).onRotateMove)==null||a.call(o,r??void 0),(l=(h=this.events).onClickRotate)==null||l.call(h,r??void 0)}:void 0,onRotationEnd:()=>{var s,r;this.resetRotationState(),(r=(s=this.events).onRotateEnd)==null||r.call(s)}});return i.position.set(this.outlinePoints[pt.ROTATE].x,this.outlinePoints[pt.ROTATE].y),i}onClickRotateButton(e){this.rotationCache||this.initializeRotationCache(this.calculateRotationCenter());const i=this.handleInternalRotationMove(e);return this.resetRotationState(),i}createScaleButton(){const e=new vs(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.config.iconWrapperFillColor,initialButtonPosition:this.outlinePoints[pt.SCALE],onScaleStart:()=>{var i,s;this.initializeScaleCache(),(s=(i=this.events).onScaleStart)==null||s.call(i)},onScaleMove:({deltaX:i,deltaY:s})=>{var o,a;const r=this.handleInternalScaleMove(i,s);(a=(o=this.events).onScaleMove)==null||a.call(o,r??void 0)},onScaleEnd:()=>{var i,s;this.resetScaleState(),this.initialZonePoints=[],(s=(i=this.events).onScaleEnd)==null||s.call(i)}});return e.position.set(this.outlinePoints[pt.SCALE].x,this.outlinePoints[pt.SCALE].y),e}createHorizontalScaleButton(){const[,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),r=new vs(this.appService,{iconAlias:"horizontalScaleIcon",backgroundColor:this.config.iconWrapperFillColor,config:{iconWrapperWidth:18,iconWrapperHeight:18,iconWrapperBorderRadius:18,iconWidth:10,iconHeight:8},initialButtonPosition:s,onScaleStart:()=>{var h,l;const[,o,a]=this.zonePoints;this.horizontalScaleInitialPosition=this.getEdgeCenter(o,a),this.initializeScaleCache(),(l=(h=this.events).onScaleStart)==null||l.call(h)},onScaleMove:({deltaX:o,deltaY:a})=>{var l,c;const h=this.handleInternalHorizontalScaleMove(o,a);(c=(l=this.events).onScaleMoveHorizontal)==null||c.call(l,h??void 0)},onScaleEnd:()=>{var o,a;this.resetScaleState(),this.initialZonePoints=[],this.horizontalScaleInitialPosition=null,(a=(o=this.events).onScaleEnd)==null||a.call(o)}});return r.position.set(s.x,s.y),r}createVerticalScaleButton(){const[,,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),r=new vs(this.appService,{iconAlias:"verticalScaleIcon",backgroundColor:this.config.iconWrapperFillColor,config:{iconWrapperWidth:18,iconWrapperHeight:18,iconWrapperBorderRadius:18,iconWidth:8,iconHeight:10},initialButtonPosition:s,onScaleStart:()=>{var h,l;const[,,o,a]=this.zonePoints;this.verticalScaleInitialPosition=this.getEdgeCenter(o,a),this.initializeScaleCache(),(l=(h=this.events).onScaleStart)==null||l.call(h)},onScaleMove:({deltaX:o,deltaY:a})=>{var l,c;const h=this.handleInternalVerticalScaleMove(o,a);(c=(l=this.events).onScaleMoveVertical)==null||c.call(l,h??void 0)},onScaleEnd:()=>{var o,a;this.resetScaleState(),this.initialZonePoints=[],this.verticalScaleInitialPosition=null,(a=(o=this.events).onScaleEnd)==null||a.call(o)}});return r.position.set(s.x,s.y),r}createMoveButton(){const e=this.calculateMoveButtonPosition(),i=new Uc(this.appService,{iconAlias:"moveIcon",backgroundColor:this.config.iconWrapperFillColor,onMoveStart:()=>{var s,r;return(r=(s=this.events).onMoveStart)==null?void 0:r.call(s)},onMoveMove:s=>{var r,o;return(o=(r=this.events).onMoveMove)==null?void 0:o.call(r,s)},onMoveEnd:()=>{var s,r;return(r=(s=this.events).onMoveEnd)==null?void 0:r.call(s)}});return i.position.set(e.x,e.y),i}createAndAddButton(e,i){return e.visible=i,this.controlButtons.addChild(e),e}createControlButtons(){this.outlinePoints.length<4||(this.deleteButton=this.createAndAddButton(this.createDeleteButton(),this.config.showDeleteButton??!1),this.moveButton=this.createAndAddButton(this.createMoveButton(),this.config.showMoveButton??!1),this.rotateButton=this.createAndAddButton(this.createRotateButton(),this.config.showRotateButton??!1),this.scaleButton=this.createAndAddButton(this.createScaleButton(),this.config.showScaleButton??!1),this.horizontalScaleButton=this.createAndAddButton(this.createHorizontalScaleButton(),this.config.showRadialScaleButton??!1),this.verticalScaleButton=this.createAndAddButton(this.createVerticalScaleButton(),this.config.showRadialScaleButton??!1))}calculateOutlinePoints(){const e=this.zonePoints;if(e.length<4)return e;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return wx(e,s)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),r=e[pt.MOVE],o=e[pt.SCALE],a=e[pt.REMOVE];return Mc(r,o,a,s)}calculateMoveLinePoints(){const e=this.calculateOutlinePoints();if(e.length<4)return[];const i=e[pt.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const e=this.zonePoints;if(e.length<4)return"0m*0m";const[i,s,,r]=e,o=tt(i,s),a=tt(i,r),{coords:h}=this.appService,l=h.toMeters(Bt(o)),c=h.toMeters(Bt(a)),d=h.toDisplayUnit(l),u=h.toDisplayUnit(c),p=this.appService.runtimeSnapshot.unitLabel;return`${d.toFixed(1)}${p}*${u.toFixed(1)}${p}`}getEdgeCenter(e,i){return{x:(e.x+i.x)/2,y:(e.y+i.y)/2}}calculatePerpendicularOffset(e,i,s,r=!1){const o=Dt(bt(i,e)),a=r?{x:-o.y,y:o.x}:{x:o.y,y:-o.x};return{x:a.x*s,y:a.y*s}}calculateSizeTextPosition(){if(this.zonePoints.length<4)return{x:0,y:0};const i=this.calculateOutlinePoints(),[s,r,o,a]=i,{textPosition:h,textOffset:l}=this.config,d=this.appService.getApp().toFixedSize(l);let u,p;switch(h){case"top":u=this.getEdgeCenter(s,r),p=this.calculatePerpendicularOffset(r,s,d);break;case"right":u=this.getEdgeCenter(r,o),p=this.calculatePerpendicularOffset(r,o,d);break;case"bottom":u=this.getEdgeCenter(a,o),p=this.calculatePerpendicularOffset(a,o,d,!0);break;case"left":u=this.getEdgeCenter(s,a),p=this.calculatePerpendicularOffset(a,s,d);break;default:u=this.getEdgeCenter(s,r),p={x:0,y:d};break}return{x:u.x+p.x,y:u.y+p.y}}calculateSizeTextRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[i,s,r,o]=e,{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=r;break;case"bottom":h=r,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return Ss(h,l,c)}calculateHorizontalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(i,s,r)+Math.PI/2}calculateVerticalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,,i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(s,i,r)}updatePoints(e,i=!0){this.zonePoints=e,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlinePoints=e,this.outlineBorder.updatePoints(e)}updateMoveLine(){if(!this.moveLine)return;const e=this.calculateMoveLinePoints();this.moveLine.updatePoints(e)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:e[pt.REMOVE]},{button:this.scaleButton,point:e[pt.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:e[pt.ROTATE]}),this.horizontalScaleButton){const r=e[pt.ROTATE],o=e[pt.SCALE],a=_c(r,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const r=e[pt.SCALE],o=e[pt.MOVE],a=this.getEdgeCenter(r,o);s.push({button:this.verticalScaleButton,point:a})}s.forEach(({button:r,point:o})=>r.position.set(o.x,o.y)),this.horizontalScaleButton&&(this.horizontalScaleButton.rotation=this.calculateHorizontalScaleButtonRotation()),this.verticalScaleButton&&(this.verticalScaleButton.rotation=this.calculateVerticalScaleButtonRotation()),this.scaleButton&&this.scaleButton.visible&&(this.scaleButton.rotation=this.calculateVerticalScaleButtonRotation())}setupClickHandler(){this.clickHandler=new St(this,{onClick:()=>{var e,i;(i=(e=this.events).onClick)==null||i.call(e)},stopPropagation:!1})}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){(this.outlineBorder.visible||this.controlButtons.visible)&&(this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}initializeScaleCache(){if(this.initialZonePoints.length===0&&(this.initialZonePoints=this.zonePoints.map(p=>({...p}))),this.initialZonePoints.length<4)return;const e={...this.initialZonePoints[pt.SCALE]};if(!e)return;const i=pt.REMOVE,{x:s,y:r}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:r},l=bt(h,o),c=bt(h,a),d=Gi(l),u=Gi(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:e})}sizeConstraintPixels(){const{coords:e}=this.appService,i=(r,o)=>({minSizePixels:e.toPixels(ut(r)),maxSizePixels:o!=null?e.toPixels(ut(o)):void 0});if(this.sizeConstraintPerEdge){const{edge1:r,edge2:o}=this.sizeConstraintPerEdge();return{edge1:i(r.min,r.max),edge2:i(o.min,o.max)}}const s=i(this.minSize,this.maxSize);return{edge1:s,edge2:s}}handleInternalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const{edge1:s,edge2:r}=this.sizeConstraintPixels(),{fixedPoint:o,edge1:a,edge2:h,edge1Len:l,edge2Len:c,initialButtonPosition:d}=this.scaleCache,u={x:d.x+e,y:d.y+i},p=bt(o,u);let g=ps(p,a,l,s.minSizePixels,s.maxSizePixels),y=ps(p,h,c,r.minSizePixels,r.maxSizePixels);if(this.config.scaleMode==="ratioLocked"){const m=Math.min(g,y);g=m,y=m}return this.calculatePointsFromScale(o,a,h,g,y)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.horizontalScaleInitialPosition)return null;const{fixedPoint:s,edge1:r,edge2:o,edge1Len:a}=this.scaleCache,{edge1:h}=this.sizeConstraintPixels(),l={x:this.horizontalScaleInitialPosition.x+e,y:this.horizontalScaleInitialPosition.y+i},c=bt(s,l),d=ps(c,r,a,h.minSizePixels,h.maxSizePixels);return this.calculatePointsFromScale(s,r,o,d,1)}handleInternalVerticalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.verticalScaleInitialPosition)return null;const{fixedPoint:s,edge1:r,edge2:o,edge2Len:a}=this.scaleCache,{edge2:h}=this.sizeConstraintPixels(),l={x:this.verticalScaleInitialPosition.x+e,y:this.verticalScaleInitialPosition.y+i},c=bt(s,l),d=1,u=ps(c,o,a,h.minSizePixels,h.maxSizePixels);return this.calculatePointsFromScale(s,r,o,d,u)}calculatePointsFromScale(e,i,s,r,o){const{x:a,y:h}=e;return[e,{x:a+i.x*r,y:h+i.y*r},{x:a+i.x*r+s.x*o,y:h+i.y*r+s.y*o},{x:a+s.x*o,y:h+s.y*o}]}initializeRotationCache(e){this.zonePoints.length<3||(this.rotationCache={rotationCenter:e,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(e){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=e,vx(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:Oe(this.zonePoints)}updateEditState({showRotateButton:e=!1,showScaleButton:i=!1,showRadialScaleButton:s=!1,showDeleteButton:r=!1,showMoveButton:o=!1,showBorder:a=!1,showSizeText:h=!1,borderStyle:l}){this.rotateButton&&(this.rotateButton.visible=e),this.scaleButton&&(this.scaleButton.visible=i),this.horizontalScaleButton&&(this.horizontalScaleButton.visible=s),this.verticalScaleButton&&(this.verticalScaleButton.visible=s),this.deleteButton&&(this.deleteButton.visible=r),this.moveButton&&(this.moveButton.visible=o);const c=e||i||s||r||o;this.controlButtons.visible=c,!c&&this.getOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=a,this.moveLine&&(this.moveLine.visible=o),this.sizeText&&(this.sizeText.visible=h),a&&(this.updateOutlineBorder(),c&&(this.moveLine&&o&&this.updateMoveLine(),this.updateControlButtonsPosition()),h&&this.updateSizeTextPosition()),l&&this.outlineBorder.updateStyle({isDashed:l.isDashed,dashArray:l.dashArray})}getOperationState(){var r,o,a;const e=((r=this.scaleButton)==null?void 0:r.isCurrentlyScaling())||!1,i=((o=this.rotateButton)==null?void 0:o.isCurrentlyRotating())||!1,s=((a=this.moveButton)==null?void 0:a.isCurrentlyMoving())||!1;return{isDragging:!1,isScaling:e,isRotating:i,isMoving:s,hasAnyOperation:e||i||s}}stopAllOperations(){var e,i,s;(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(e,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const r=s[e],o=s[i];return{x:(r.x+o.x)/2,y:(r.y+o.y)/2}}destroy(){var e,i,s,r,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(r=this.scaleButton)==null||r.destroy(),(o=this.moveButton)==null||o.destroy(),(a=this.horizontalScaleButton)==null||a.destroy(),(h=this.verticalScaleButton)==null||h.destroy(),this.deleteButton=null,this.rotateButton=null,this.scaleButton=null,this.moveButton=null,this.horizontalScaleButton=null,this.verticalScaleButton=null,(l=this.outlineBorder)==null||l.destroy(),(c=this.moveLine)==null||c.destroy(),(d=this.sizeText)==null||d.destroy(),(u=this.controlButtons)==null||u.destroy(),super.destroy()}}function PS(n,t,e){return{outlineStrokeColor:String(n.outlineStrokeColor),outlineStrokeWidth:n.outlineStrokeWidth,outlineDashed:n.outlineDashed,outlineDashArray:n.outlineDashArray,outlineFillColor:n.outlineFillColor?String(n.outlineFillColor):void 0,outlineOffset:n.outlineOffset,iconWrapperFillColor:String(n.iconWrapperFillColor),deleteIconWrapperFillColor:"deleteIconWrapperFillColor"in n&&n.deleteIconWrapperFillColor!==void 0?String(n.deleteIconWrapperFillColor):void 0,showRotateButton:(e==null?void 0:e.showRotateButton)??n.showRotateButton,showScaleButton:(e==null?void 0:e.showScaleButton)??!0,showRadialScaleButton:e==null?void 0:e.showRadialScaleButton,showDeleteButton:(e==null?void 0:e.showDeleteButton)??!0,showMoveButton:(e==null?void 0:e.showMoveButton)??!0,rotateMode:e==null?void 0:e.rotateMode,scaleMode:"free",textColor:String(n.textColor),textPosition:n.textPosition,textOffset:n.textOffset,moveButtonOffset:t.moveButtonOffset,textFontSize:t.textFontSize,textFontFamily:t.textFontFamily,textFontWeight:t.textFontWeight}}function Vs(n,t){return{coords:n.coords,editControls:n.editControlManager,getZoneConfig:e=>MS(n,e),controlsConfig:n.getConfig().controls,makeControlFill:e=>new Qr(n,e),makeBorder:e=>new ri(n,e),render:{request:e=>n.getApp().requestRender(e,!0),stop:e=>n.getApp().stopRender(e)},events:t}}function MS(n,t){var i;const e=n.getConfig();if($e(t)){const s=e.controls[t];if(s)return s}else{const s=(i=e.customZoneTypes)==null?void 0:i[t];if(s)return s}return _h.cleanZone}class Ns extends W{constructor(e){super();f(this,"zoneData");f(this,"zoneType");f(this,"zoneConfig");f(this,"controlsConfig");f(this,"zoneEvents");f(this,"deps");f(this,"controlFill");f(this,"zoneBorder");f(this,"editableShape");f(this,"clickHandler",null);f(this,"initialZonePoints",[]);f(this,"dragStartPosition",null);f(this,"editing",!1);f(this,"resolvedMaxSizeCache",null);f(this,"handleDragStart",()=>{this.editing&&(this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.dragStartPosition=this.controlFill.getDragStartPosition(),this.deps.render.request("zone-drag"))});f(this,"handleDragMove",e=>{if(!this.editing||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;this.applyTranslation(s,r)});f(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.dragStartPosition=null,this.deps.render.stop("zone-drag"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleRotationStart",()=>{this.deps.render.request("zone-rotate")});f(this,"handleRotationMove",e=>{e&&(this.zoneData.points=e,this.drawZone(!1))});f(this,"handleScaleStart",()=>{this.deps.render.request("zone-scale")});f(this,"handleScaleMove",e=>{e&&(this.zoneData.points=e,this.drawZone())});f(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.deps.render.request("zone-move")});f(this,"handleMove",e=>{var a;if(!this.editing||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(a=this.editableShape.getMoveButton())==null?void 0:a.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{var e,i;this.initialZonePoints=[],this.deps.render.stop("zone-move"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleTransformEnd",()=>{var e,i;this.initialZonePoints=[],this.deps.render.stop("zone-rotate"),this.deps.render.stop("zone-scale"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.zoneEvents).onRemove)==null||i.call(e,this.zoneData.id)});f(this,"handleClick",()=>{var e,i;this.editing||(i=(e=this.zoneEvents)==null?void 0:e.onClick)==null||i.call(e,this.getZoneData())});const{deps:i,zoneData:s,zoneType:r}=e;this.deps=i,this.zoneType=r,this.zoneEvents=i.events,this.zoneConfig=i.getZoneConfig(r),this.controlsConfig=i.controlsConfig;const o=this.validateZoneShape(s.points);this.zoneData={...s,points:o},this.initializeComponents(),this.createEditControlLayer(),this.setupClickHandler(),this.applyEditing()}getResolvedMaxSize(){const e=this.zoneConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===e)return this.resolvedMaxSizeCache.value;const i=Us(this.zoneConfig.minSize,e,this.zoneType);return this.resolvedMaxSizeCache={key:e,value:i},i}validateZoneShape(e){if(e.length<4)return e;const i=this.getResolvedMaxSize();return this.deps.coords.validateShape(Sc(e),{minSize:ut(this.zoneConfig.minSize),maxSize:i!=null?ut(i):void 0})}initializeComponents(){this.controlFill=this.createControlFill(),this.addChild(this.controlFill),this.zoneBorder=this.createBorder(),this.addChild(this.zoneBorder)}createControlFill(){return this.deps.makeControlFill({points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:this.editing,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(){const e=this.editing?this.zoneConfig.editing:this.zoneConfig.normal;return this.deps.makeBorder({points:this.zoneData.points,closePath:!0,style:{color:this.zoneConfig.strokeColor,width:this.zoneConfig.strokeWidth,isDashed:e.isDashed,dashArray:e.dashArray}})}createEditControlLayer(){const e=PS(this.zoneConfig,this.controlsConfig,{showRotateButton:this.zoneConfig.showRotateButton,showRadialScaleButton:!1,rotateMode:"free"});this.editableShape=new Jr({editControls:this.deps.editControls});const i=this.getResolvedMaxSize(),s={config:e,zonePoints:this.zoneData.points,minSize:this.zoneConfig.minSize,maxSize:i??void 0,contentLayer:ke,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,onRotateEnd:this.handleTransformEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleTransformEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick}};this.editableShape.attach(this,{id:this.zoneData.id,topology:"quad",layerOptions:s,editingState:{showRotateButton:this.zoneConfig.showRotateButton,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,showBorder:!0,showSizeText:!0},idleState:{showRotateButton:!1,showScaleButton:!1,showRadialScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}applyTranslation(e,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawZone()}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new St(this,{onClick:this.handleClick,stopPropagation:!1})}drawZone(e=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.editableShape.updatePoints(i,e))}applyEditing(){this.controlFill.setInteractionEnabled(this.editing),this.updateBorderStyle(this.editing?this.zoneConfig.editing:this.zoneConfig.normal),this.editableShape.setEditing(this.editing),this.zIndex=this.editing?1e3:0}updateBorderStyle(e){this.zoneBorder.updateStyle({isDashed:e.isDashed,dashArray:e.dashArray})}setEditing(e){this.editing!==e&&(this.editing=e,this.applyEditing())}isEditing(){return this.editing}updateZoneData(e){const i=this.validateZoneShape(e.points);this.zoneData={...e,points:i},this.drawZone()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var e,i,s;this.editableShape.detach(),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.zoneBorder)==null||i.destroy(),(s=this.controlFill)==null||s.destroy(),super.destroy()}}class to extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickForbiddenSweepZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"forbiddenSweepZone"})}static create(t,e){return new to(t,{zoneData:e})}}class eo extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickForbiddenMopZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"forbiddenMopZone"})}static create(t,e){return new eo(t,{zoneData:e})}}class io extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveCleanZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateCleanZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickCleanZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"cleanZone"})}static create(t,e){return new io(t,{zoneData:e})}}class Ne extends H{constructor(e,i){super();f(this,"lineOptions");f(this,"strokeContext",null);f(this,"drawDashLine",()=>{const{start:e,end:i,style:s}=this.lineOptions;this.clear(),this.strokeContext&&this.strokeContext.destroy();const r=this.appService;this.strokeContext=new gt;const o=r.getApp().toFixedSize(s.width);this.strokeContext.setStrokeStyle({color:s.color,width:o}),this.drawDashedLineToContext(this.strokeContext,e.x,e.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=e,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(e,i,s,r,o,a,h){const l=r-i,c=o-s,d=Math.sqrt(l*l+c*c);if(d===0)return;const u=this.appService,p=u.getApp().toFixedSize(a),g=u.getApp().toFixedSize(h),y=p+g,m=d/y,x=Math.round(m);if(x===0){e.moveTo(i,s),e.lineTo(r,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let C=0;C<x;C++){const _=C*S,R=_+v;if(_>=d)break;const M=Math.min(R,d),A=i+_*b,T=s+_*P,I=i+M*b,D=s+M*P;e.moveTo(A,T),e.lineTo(I,D)}}updatePoints(e,i){this.lineOptions.start=e,this.lineOptions.end=i,this.drawDashLine()}updateStyle(e){this.lineOptions.style={...this.lineOptions.style,...e},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Yt=class Yt extends W{constructor(e){super();f(this,"wallData");f(this,"wallConfig");f(this,"controlsConfig");f(this,"wallEvents");f(this,"appService");f(this,"wallLine");f(this,"outlineBorder");f(this,"moveLine");f(this,"lengthText");f(this,"controlButtons");f(this,"removeButton",null);f(this,"scaleButton",null);f(this,"moveButton",null);f(this,"initialWallPoints",[]);f(this,"initialButtonPosition",null);f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"resolvedMaxWidthCache",null);f(this,"throttledUpdateOutline");f(this,"throttledHandleScaleChange");f(this,"wallLineClickHandler",null);f(this,"handleRemove",()=>{var e,i;(i=(e=this.wallEvents).onRemove)==null||i.call(e,this.wallData.id)});f(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(e=>({...e}))});f(this,"finalizeOperation",()=>{var e,i;this.initialWallPoints=[],(i=(e=this.wallEvents).onUpdate)==null||i.call(e,this.getWallData())});f(this,"handleScaleStart",()=>{this.initializeOperation();const e=this.calculateOutlinePoints();e.length>Yt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...e[Yt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});f(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});f(this,"handleScaleEnd",()=>{this.finalizeOperation(),this.initialButtonPosition=null,this.appService.getApp().stopRender("virtualwall-scale")});f(this,"handleMoveStart",()=>{this.initializeOperation(),this.appService.getApp().requestRender("virtualwall-move",!0)});f(this,"handleMove",e=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(e.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{this.finalizeOperation(),this.appService.getApp().stopRender("virtualwall-move")});f(this,"handleScaleChange",()=>{this.redrawSolidLine(),this.setupWallLineHitArea()});f(this,"handleWallLinePointerDown",e=>{this.isEditingEnabled()&&(e.stopPropagation(),this.startDragging(e))});f(this,"handleDragPointerMove",e=>{!this.isDragging||!this.dragStartPosition||this.handleMove(e)});f(this,"handleDragPointerUp",()=>{this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.finalizeOperation())});const{appService:i,wallData:s,events:r={}}=e;this.appService=i,this.wallEvents=r,this.wallConfig=this.appService.controlsConfig.virtualWall,this.controlsConfig=this.appService.controlsConfig,this.wallData={...s,points:this.validateAndCorrectWallLength(s.points)},this.throttledHandleScaleChange=Pt(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=Pt(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("antiScale",this.throttledHandleScaleChange),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}getResolvedMaxWidth(){const e=this.wallConfig.maxWidth;if(this.resolvedMaxWidthCache&&this.resolvedMaxWidthCache.key===e)return this.resolvedMaxWidthCache.value;const i=Us(this.wallConfig.minWidth,e,"virtualWall");return this.resolvedMaxWidthCache={key:e,value:i},i}validateAndCorrectWallLength(e){if(e.length<2)return e;const[i,s]=e,{coords:r}=this.appService,o=r.toPixels(ut(this.wallConfig.minWidth)),a=this.getResolvedMaxWidth(),h=a!=null?r.toPixels(ut(a)):void 0,l=tt(i,s),c=l<o,d=h!=null&&l>h;if(!c&&!d)return e;if(l===0)return[i,{x:i.x+o,y:i.y}];const u=Dt(bt(i,s));let p=l;return h!=null&&(p=Math.min(p,h)),p=Math.max(p,o),[i,{x:i.x+u.x*p,y:i.y+u.y*p}]}isEditingEnabled(){return this.appService.runtimeSnapshot.editingVirtualWallIds.includes(this.wallData.id)}updateOutlineForScale(){this.isEditingEnabled()&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition())}initializeComponents(){this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.createWallLine(!1),this.addChild(this.wallLine),this.lengthText=this.createLengthText(),this.addChild(this.lengthText),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.controlButtons=new W,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.createControlButtons()}createWallLine(e=!0){const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:r,editing:o,normal:a}=this.wallConfig,l=this.isEditingEnabled()?o:a;l.isDashed?this.wallLine=new Ne(this.appService,{start:i[0],end:i[1],style:{color:r.toString(),width:s,dashArray:l.dashArray}}):this.wallLine=this.createSolidLine(i[0],i[1],s,r.toString()),e&&this.setupWallLineInteraction()}createLengthText(){const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e),s=new Es(this.appService,{text:i,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.wallConfig.textColor,align:"center"}});s.anchor.set(.5);const r=this.calculateTextPosition();s.position.set(r.x,r.y);const o=this.calculateTextRotation();return s.rotation=o,s.eventMode="none",s}calculateWallLengthInMeters(){const{points:e}=this.wallData;if(e.length<2)return 0;const i=tt(e[0],e[1]);return this.appService.coords.toMeters(Bt(i))}formatLengthText(e){const i=this.appService.coords.toDisplayUnit(ut(e)),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:e}=this.wallData;if(e.length<2)return{x:0,y:0};const[i,s]=e,r=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return _c(i,s,r)}calculateTextRotation(){const{points:e}=this.wallData;if(e.length<2)return 0;const[i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(i,s,r)}getOutlineStyle(){return{color:this.wallConfig.outlineStrokeColor,width:this.wallConfig.outlineStrokeWidth,isDashed:this.wallConfig.outlineDashed,dashArray:this.wallConfig.outlineDashArray,fillColor:this.wallConfig.outlineFillColor}}createOutlineBorder(){const e=this.calculateOutlinePoints();return new ri(this.appService,{points:e,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);return new ri(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(e){const i=e||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),r=bx(i[0],i[1],s);return[r[3],r[2],r[1],r[0]]}calculateMoveLinePoints(e){if(e.length<4)return[];const{MOVE:i}=Yt.BUTTON_INDICES,s=e[i],r=this.calculateMoveButtonPosition();return[s,r]}calculateMoveButtonPosition(){const{moveButtonOffset:e}=this.controlsConfig,i=this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{MOVE:s}=Yt.BUTTON_INDICES,r=i[s],o=i[(s+3)%4],a=i[(s+1)%4],h=this.appService.getApp().toFixedSize(e);return Mc(r,a,o,h)}createControlButtons(){const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Yt.BUTTON_INDICES;this.removeButton=new Hc(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton=new vs(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,getTargetPoints:()=>this.calculateOutlinePoints(),getButtonIndex:()=>s,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[s].x,e[s].y);const r=this.calculateMoveButtonPosition();this.moveButton=new Uc(this.appService,{iconAlias:"moveIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(r.x,r.y),this.controlButtons.addChild(this.removeButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}applyScaleAndRotation(e){if(this.initialWallPoints.length<2)return;const[i,s]=this.initialWallPoints,r=i,o=this.calculateOutlinePoints(this.initialWallPoints);if(o.length<4)return;const a=o[Yt.BUTTON_INDICES.SCALE],l=bt(s,a),c={x:e.x-l.x,y:e.y-l.y},d=bt(r,c),u=tt(r,c),{coords:p}=this.appService,g=p.toPixels(ut(this.wallConfig.minWidth)),y=this.getResolvedMaxWidth(),m=y!=null?p.toPixels(ut(y)):void 0;let x;if(u<g)if(u===0)x={x:r.x+g,y:r.y};else{const S=Dt(d);x={x:r.x+S.x*g,y:r.y+S.y*g}}else if(m!=null&&u>m){const S=Dt(d);x={x:r.x+S.x*m,y:r.y+S.y*m}}else x=c;this.wallData.points=[r,x],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(e,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:e}=this.wallData;e.length<2||(this.wallLine instanceof Ne?this.wallLine.updatePoints(e[0],e[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const e=this.calculateTextPosition();this.lengthText.position.set(e.x,e.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e);const i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Yt.BUTTON_INDICES,r=this.calculateMoveButtonPosition();this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton.position.set(e[s].x,e[s].y),this.moveButton.position.set(r.x,r.y)}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.lengthText&&(this.lengthText.visible=e),e&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=e?1e3:0}createSolidLine(e,i,s,r){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(e.x,e.y),o.lineTo(i.x,i.y),o.stroke({color:r,width:a}),o}updateWallLineStyle(){const e=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:r,lineColor:o}=this.wallConfig,a=e?i:s;this.wallLine instanceof Ne!==a.isDashed?(this.removeChild(this.wallLine),this.wallLine.destroy(),this.createWallLine(!1),this.addChild(this.wallLine)):this.wallLine instanceof Ne?this.wallLine.updateStyle({color:o.toString(),width:r,dashArray:a.dashArray}):this.redrawSolidLine()}redrawSolidLine(){const e=this.appService;if(!this.wallLine||this.wallLine instanceof Ne)return;const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:r}=this.wallConfig,o=e.getApp().toFixedSize(s);this.wallLine.clear(),this.wallLine.setStrokeStyle({color:r.toString(),width:o}).moveTo(i[0].x,i[0].y).lineTo(i[1].x,i[1].y).stroke()}setupWallLineInteraction(){var i;if(!this.wallLine)return;this.setupWallLineHitArea();const e=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),e?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new St(this.wallLine,{onClick:()=>{var s,r;this.appService.gestureController.suppressMapClick(),(r=(s=this.wallEvents)==null?void 0:s.onClick)==null||r.call(s,this.getWallData())},stopPropagation:!1})}startDragging(e){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(e.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:e}=this.wallData;if(e.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),r=Pc(e[0],e[1],s);if(r.length===0)return;const o=new Re(r);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(e){this.wallData={...e,points:this.validateAndCorrectWallLength(e.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var e,i,s,r,o,a,h,l,c,d;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.wallLine&&this.wallLine.off("pointerdown",this.handleWallLinePointerDown),(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,(s=this.wallLine)==null||s.destroy(),(r=this.lengthText)==null||r.destroy(),(o=this.outlineBorder)==null||o.destroy(),(a=this.moveLine)==null||a.destroy(),(h=this.controlButtons)==null||h.destroy(),(l=this.removeButton)==null||l.destroy(),(c=this.scaleButton)==null||c.destroy(),(d=this.moveButton)==null||d.destroy(),this.removeButton=null,this.scaleButton=null,this.moveButton=null,super.destroy()}};f(Yt,"BUTTON_INDICES",{REMOVE:0,SCALE:2,MOVE:3});let yr=Yt;const TS={fontSize:12,fontFamily:"system-ui, -apple-system, sans-serif",fontWeight:"400",color:"#5d68fe",position:"top",offset:-8,editing:{visible:!0},normal:{visible:!0}};class so extends W{constructor(e){super();f(this,"spotData");f(this,"spotConfig");f(this,"controlsConfig");f(this,"spotEvents");f(this,"appService");f(this,"controlFill");f(this,"spotBorder");f(this,"centerIcon");f(this,"sizeText");f(this,"nameText");f(this,"clickHandler",null);f(this,"initialSpotPoint",null);f(this,"dragStartMousePosition",null);f(this,"throttledUpdateScale");f(this,"unsubscribeMapRotation",null);f(this,"handleDragStart",e=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("spot-drag",!0))});f(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartMousePosition.x,r=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,r)});f(this,"handleDragEnd",()=>{var e,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(e=this.spotEvents).onUpdate)==null||i.call(e,this.getSpotData())});const{appService:i,spotData:s,events:r={}}=e;this.appService=i,this.spotData=s,this.spotEvents=r,this.controlsConfig=this.appService.controlsConfig,this.spotConfig=this.appService.controlsConfig.spot,this.position.set(s.point.x,s.point.y),this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.setupClickHandler(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(){this.isEditingEnabled()&&this.sizeText&&this.updateSizeTextPosition(),this.nameText&&this.updateNameTextPosition()}isEditingEnabled(){return this.appService.runtimeSnapshot.editingSpotIds.includes(this.spotData.id)}shouldShowIcon(){return(this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal).showIcon}calculateRectanglePoints(){const{size:e}=this.spotConfig;if(e===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.coords.toPixels(ut(e))/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const e=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(e),this.addChild(this.controlFill),this.spotBorder=this.createBorder(e),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.calculateSpotNameText()&&(this.nameText=this.createNameText(),this.addChild(this.nameText)),this.drawSpot()}createControlFill(e){const i=this.isEditingEnabled();return new Qr(this.appService,{points:e,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(e){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new ri(this.appService,{points:e,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const e=new Ut(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.eventMode="static",this.setupIconDrag(e),e.visible=!1,e}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s}=this.spotConfig;await e.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",r=>{this.applyAntiRotation(r)})),e.visible=this.shouldShowIcon()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupIconDrag(e){let i=null,s=!1;const r=a=>{if(!s||!this.initialSpotPoint||!i)return;const h=this.parent.toLocal(a.global),l=h.x-i.x,c=h.y-i.y;this.applyTranslation(l,c)},o=()=>{var a,h;s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),(h=(a=this.spotEvents).onUpdate)==null||h.call(a,this.getSpotData()))};e.on("pointerdown",a=>{if(!this.isEditingEnabled())return;a.stopPropagation(),s=!0,this.initialSpotPoint={...this.spotData.point},i=this.parent.toLocal(a.global),this.appService.getApp().requestRender("spot-drag",!0);const h=this.appService.gestureController.hijack(a);h.onMove(r),h.onEnd(o)})}createSizeText(){const e=this.calculateSpotSizeText(),i=new Es(this.appService,{text:e,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.spotConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotSizeText(){const{size:e}=this.spotConfig,i=this.appService.coords.toDisplayUnit(ut(e)),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const{textPosition:e,textOffset:i}=this.spotConfig;return this.calculateTextPosition(e,i)}calculateTextPosition(e,i){const s=this.calculateRectanglePoints();if(s.length<4)return{x:0,y:0};const[r,o,a,h]=s,l=this.appService.getApp().toFixedSize(i);let c,d;switch(e){case"top":{c={x:(r.x+o.x)/2,y:(r.y+o.y)/2},d={x:c.x,y:c.y+l};break}case"right":{c={x:(o.x+a.x)/2,y:(o.y+a.y)/2},d={x:c.x+l,y:c.y};break}case"bottom":{c={x:(h.x+a.x)/2,y:(h.y+a.y)/2},d={x:c.x,y:c.y+l};break}case"left":{c={x:(r.x+h.x)/2,y:(r.y+h.y)/2},d={x:c.x-l,y:c.y};break}default:{c={x:(r.x+o.x)/2,y:(r.y+o.y)/2},d={x:c.x,y:c.y+l};break}}return d}getNameLabelConfig(){return this.spotConfig.nameLabel??TS}createNameText(){const e=this.getNameLabelConfig(),i=new Es(this.appService,{text:this.calculateSpotNameText(),style:{fontSize:e.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fill:e.color,align:"center"}});i.anchor.set(.5);const s=this.calculateNameTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotNameText(){var e;return((e=this.spotData.name)==null?void 0:e.trim())??""}calculateNameTextPosition(){const{position:e,offset:i}=this.getNameLabelConfig();return this.calculateTextPosition(e,i)}shouldShowNameText(){if(!this.calculateSpotNameText())return!1;const i=this.isEditingEnabled(),s=this.getNameLabelConfig();return(i?s.editing:s.normal).visible}applyTranslation(e,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+e,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const e=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new St(e,{onClick:()=>{var i,s;this.isEditingEnabled()||(this.appService.gestureController.suppressMapClick(),(s=(i=this.spotEvents)==null?void 0:i.onClick)==null||s.call(i,this.getSpotData()))},stopPropagation:!1}),this.eventMode="static"}drawSpot(){const e=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(e),this.spotBorder&&this.spotBorder.updatePoints(e)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText(),this.nameText&&this.updateNameText()}updateSizeText(){if(!this.sizeText)return;const e=this.calculateSpotSizeText();this.sizeText.updateText(e),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y)}updateNameText(){this.nameText&&(this.nameText.updateText(this.calculateSpotNameText()),this.updateNameTextPosition())}updateNameTextPosition(){if(!this.nameText)return;const e=this.calculateNameTextPosition();this.nameText.position.set(e.x,e.y)}updateEditState(){const e=this.isEditingEnabled(),i=e?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=e&&this.spotConfig.showText),this.nameText&&(this.nameText.visible=this.shouldShowNameText()),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(e),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=e?1e3:0}updateSpotData(e){this.spotData={...e},!this.nameText&&this.calculateSpotNameText()&&(this.nameText=this.createNameText(),this.addChild(this.nameText)),this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var e,i,s,r,o,a;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.centerIcon&&this.spotConfig.size===0&&this.centerIcon.removeAllListeners(),(i=this.controlFill)==null||i.destroy(),(s=this.spotBorder)==null||s.destroy(),(r=this.centerIcon)==null||r.destroy(),(o=this.sizeText)==null||o.destroy(),(a=this.nameText)==null||a.destroy(),super.destroy()}static create(e,i){return new so({appService:e,spotData:i,events:{onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdateSpot)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickSpot)==null||o.call(r,s)}}})}}const AS=16777215;class no extends W{constructor(e){super();f(this,"purifyPointData");f(this,"config");f(this,"events");f(this,"appService");f(this,"icon");f(this,"clickHandler",null);f(this,"initialPoint",null);f(this,"isOutOfBounds",!1);f(this,"lastValidPoint",null);f(this,"unsubscribeMapRotation",null);const{appService:i,purifyPointData:s,events:r={}}=e;this.appService=i,this.purifyPointData=s,this.events=r,this.config=i.controlsConfig.purifyPoint,this.position.set(s.point.x,s.point.y),this.initializeComponents(),this.updateEditState(),this.setupClickHandler()}initializeComponents(){this.icon=new Ut(this.appService),this.icon.eventMode="static",this.icon.position.set(0,0),this.setupDrag(this.icon),this.addChild(this.icon),this.loadIconTexture(this.icon),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",e=>{this.applyAntiRotation(e)})}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s}=this.config;await e.loadTextureAndSetSize("purifyIcon",{width:i,height:i,sizeFixed:s}),!this.destroyed&&(this.applyAntiRotation(this.appService.runtime.mapRotation),e.visible=!0,this.applyOutOfBoundsTint())}isEditingEnabled(){return(this.appService.runtimeSnapshot.editingPurifyPointIds??[]).includes(this.purifyPointData.id)}applyOutOfBoundsTint(){const{outOfBoundsTint:e}=this.config;this.icon.tint=this.isOutOfBounds&&e!==void 0?e:AS}applyAntiRotation(e){this.rotation=-e*Math.PI/180}setupDrag(e){let i=null,s=!1;const r=a=>{if(!s||!this.initialPoint||!i)return;const h=this.parent.toLocal(a.global),l=h.x-i.x,c=h.y-i.y;this.applyTranslation(l,c),this.evaluateRoomBounds()},o=()=>{var a,h;s&&(s=!1,this.initialPoint=null,i=null,this.isOutOfBounds&&this.lastValidPoint&&(this.purifyPointData.point={...this.lastValidPoint},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y)),this.isOutOfBounds=!1,this.lastValidPoint=null,this.applyOutOfBoundsTint(),this.appService.getApp().stopRender("purify-point-drag"),(h=(a=this.events).onUpdate)==null||h.call(a,this.getPurifyPointData()))};e.on("pointerdown",a=>{if(!this.isEditingEnabled())return;a.stopPropagation(),s=!0,this.initialPoint={...this.purifyPointData.point},i=this.parent.toLocal(a.global),this.isOutOfBounds=!1,this.lastValidPoint={...this.purifyPointData.point},this.appService.getApp().requestRender("purify-point-drag",!0);const h=this.appService.gestureController.hijack(a);h.onMove(r),h.onEnd(o)})}applyTranslation(e,i){this.initialPoint&&(this.purifyPointData.point={x:this.initialPoint.x+e,y:this.initialPoint.y+i},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y))}evaluateRoomBounds(){const{roomId:e}=this.purifyPointData;if(e===void 0){this.lastValidPoint={...this.purifyPointData.point};return}const i=this.appService.mapManager.isPointInRoom(this.purifyPointData.point,e);i&&(this.lastValidPoint={...this.purifyPointData.point});const s=!i;s!==this.isOutOfBounds&&(this.isOutOfBounds=s,this.applyOutOfBoundsTint())}setupClickHandler(){this.clickHandler=new St(this.icon,{onClick:()=>{var e,i;this.isEditingEnabled()||(this.appService.gestureController.suppressMapClick(),(i=(e=this.events)==null?void 0:e.onClick)==null||i.call(e,this.getPurifyPointData()))},stopPropagation:!1}),this.eventMode="static"}updateEditState(){this.zIndex=this.isEditingEnabled()?1e3:0}updatePurifyPointData(e){this.purifyPointData={...e},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y),this.updateEditState()}getPurifyPointData(){return{...this.purifyPointData}}refreshDisplay(){this.applyOutOfBoundsTint()}destroy(){var e,i,s;this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.icon)==null||i.removeAllListeners(),(s=this.icon)==null||s.destroy(),super.destroy()}static create(e,i){return new no({appService:e,purifyPointData:i,events:{onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdatePurifyPoint)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickPurifyPoint)==null||o.call(r,s)}}})}}class RS extends Gc{constructor(e){const{appService:i,wayPointData:s,order:r,events:o={}}=e;super(i);f(this,"wayPointData");f(this,"order");f(this,"wayPointConfig");f(this,"controlsConfig");f(this,"wayPointEvents");f(this,"icon");f(this,"orderContainer");f(this,"orderBackground");f(this,"orderText");f(this,"clickHandler",null);f(this,"initialWayPointPoint",null);f(this,"unsubscribeMapRotation",null);this.wayPointData=s,this.order=r,this.wayPointEvents=o,this.controlsConfig=this.appService.controlsConfig,this.wayPointConfig=this.appService.controlsConfig.wayPoint,this.position.set(s.point.x,s.point.y),this.initializeComponents(),this.updateEditState(),this.setupClickHandler()}isEditingEnabled(){return(this.appService.runtimeSnapshot.editingWayPointIds||[]).includes(this.wayPointData.id)}initializeComponents(){this.icon=this.createIcon(),this.addChild(this.icon),this.wayPointConfig.showOrder&&(this.createOrderContainer(),this.addChild(this.orderContainer))}createIcon(){const e=new Ut(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.anchor.set(.5,1),e.eventMode="static",this.setupIconDrag(e),e}async loadIconTexture(e){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:r}=s,o=i?"wayPointActive":"wayPoint";await e.loadTextureAndSetSize(o,{width:r,height:r,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),e.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:r}=i;this.orderContainer=new W,this.orderBackground=new H,this.orderText=new Os({text:this.order.toString(),style:new de({fontSize:r.fontSize,fontFamily:r.fontFamily,fontWeight:r.fontWeight,fill:r.color,align:"center",trim:!0})}),this.orderBackground.clear(),this.orderBackground.circle(0,0,s.size/2),this.orderBackground.fill({color:s.backgroundColor}),this.orderText.anchor.set(.5,.5),this.orderContainer.addChild(this.orderBackground),this.orderContainer.addChild(this.orderText),this.orderContainer.eventMode="none",this.orderContainer.visible=this.wayPointConfig.showOrder,this.updateOrderPosition()}updateOrderPosition(){if(!this.orderContainer)return;const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{offsetX:s,offsetY:r}=i.orderContainer;this.orderContainer.position.set(s,-r)}setupIconDrag(e){let i=null,s=null,r=!1;const o=h=>{if(!(!r||!i||!s)&&this.parent){const l=this.parent.toLocal(h.global),c=l.x-i.x,d=l.y-i.y,u={x:s.x+c,y:s.y+d};this.wayPointData.point=u,this.position.set(u.x,u.y),this.orderContainer&&this.updateOrderPosition()}},a=()=>{var h,l;r&&(r=!1,i=null,s=null,(l=(h=this.wayPointEvents).onUpdate)==null||l.call(h,this.wayPointData))};e.on("pointerdown",h=>{if(this.isEditingEnabled()&&(h.stopPropagation(),s={...this.wayPointData.point},this.parent&&(i=this.parent.toLocal(h.global)),r=!0,this.parent)){const l=this.appService.gestureController.hijack(h);l.onMove(o),l.onEnd(a)}})}setupClickHandler(){this.clickHandler=new St(this.icon,{stopPropagation:!1,onClick:()=>{var e,i;this.appService.gestureController.suppressMapClick(),(i=(e=this.wayPointEvents).onClick)==null||i.call(e,this.wayPointData)}})}updateWayPoint(e){this.wayPointData=e,this.drawWayPoint()}updateOrder(e){this.order=e,this.orderText&&(this.orderText.text=e.toString())}getWayPointData(){return{...this.wayPointData}}drawWayPoint(){this.position.set(this.wayPointData.point.x,this.wayPointData.point.y),this.orderContainer&&this.updateOrderPosition()}updateEditState(){if(this.loadIconTexture(this.icon),this.orderContainer&&this.orderText&&this.orderBackground){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal;this.orderText.style=new de({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor:r}=i.orderContainer;this.orderBackground.clear(),this.orderBackground.circle(0,0,s/2).fill(r),this.orderContainer.visible=this.wayPointConfig.showOrder,this.updateOrderPosition()}}onEditStateChange(){this.updateEditState()}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.icon&&this.icon.removeAllListeners(),super.destroy()}}class uh extends H{constructor(e,i){super();f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"initialPosition");f(this,"gestureSession",null);f(this,"handleDragPointerMove",e=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y,o={x:this.initialPosition.x+s,y:this.initialPosition.y+r};this.position.set(o.x,o.y),(h=(a=this.options).onDragMove)==null||h.call(a,o)});f(this,"handleDragPointerUp",()=>{var i,s;if(this.gestureSession=null,!this.isDragging)return;const e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=e,this.options=i,this.initialPosition={...i.position},this.position.set(i.position.x,i.position.y),this.eventMode="static",this.cursor="pointer",this.setupEvents(),this.draw()}draw(){const e=this.appService,{config:i}=this.options,s=e.getApp().toFixedSize(i.endPointSize),r=e.getApp().toFixedSize(i.endPointStrokeWidth);this.clear(),this.circle(0,0,s/2),this.fill({color:i.endPointColor}),this.stroke({color:i.endPointStrokeColor,width:r}),this.setupHitArea()}setupHitArea(){const e=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),r=e.getApp().toFixedSize(s);this.hitArea=new Bs(0,0,r)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startDragging(e)}startDragging(e){var s,r;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(e.global),this.initialPosition={x:this.x,y:this.y},(r=(s=this.options).onDragStart)==null||r.call(s),i.getApp().requestRender("endpoint-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}updatePosition(e){this.position.set(e.x,e.y),this.initialPosition={...e}}getPosition(){return{x:this.x,y:this.y}}redraw(){this.draw()}destroy(){var e;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class kS extends W{constructor(e){super();f(this,"endPoints");f(this,"dividerConfig");f(this,"dividerEvents");f(this,"roomId");f(this,"appService");f(this,"roomGeometry",null);f(this,"dashLine");f(this,"solidLine",null);f(this,"startEndPoint");f(this,"endEndPoint");f(this,"solidLinePoints",null);f(this,"initialDividerPoints",[]);f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"throttledHandleScaleChange");f(this,"handleEndPointDragStart",()=>{this.initialDividerPoints=this.endPoints.map(e=>({...e})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});f(this,"handleEndPointDragMove",(e,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[e]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});f(this,"handleEndPointDragEnd",()=>{var e,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints())});f(this,"handleDashLinePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});f(this,"handleDragPointerMove",e=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;this.endPoints=this.initialDividerPoints.map(o=>({x:o.x+s,y:o.y+r})),this.updateAllComponents()});f(this,"handleDragPointerUp",()=>{var e,i;this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});f(this,"handleScaleChange",()=>{var e,i;(e=this.startEndPoint)==null||e.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:r,events:o={}}=e;this.appService=i,this.dividerEvents=o,this.roomId=r,this.dividerConfig=this.appService.dividerConfig,this.roomGeometry=this.appService.mapManager.getRoomById(this.roomId)||null,s?this.endPoints=this.validateDividerPoints(s):this.endPoints=this.createDefaultdividerPoints(),this.throttledHandleScaleChange=Pt(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener()}validateDividerPoints(e){if(e.length>=2)return e.slice(0,2);const i=e[0]||{x:0,y:0},s={x:i.x+50,y:i.y};return[i,s]}createDefaultdividerPoints(){if(!this.roomGeometry)return w.warn("Room geometry not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const e=this.appService.getApp().mapState;if(!e)return w.warn("Map state not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const{boundingBox:i}=this.roomGeometry,s=this.appService.getApp().toFixedSize(this.dividerConfig.defaultExtension),r=this.dividerConfig.defaultDirection,o=i.x+i.width/2,a=i.y+i.height/2,h=r==="horizontal"?i.width+2*s:i.height+2*s;return kx(o,a,h,r).map(c=>({x:c.x-e.origin.x,y:c.y-e.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const e=this.endPoints;if(e.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:r}=this.dividerConfig;this.dashLine=new Ne(this.appService,{start:e[0],end:e[1],style:{color:r.toString(),width:i,dashArray:s}})}createEndPoints(){const e=this.endPoints;this.startEndPoint=new uh(this.appService,{position:e[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new uh(this.appService,{position:e[1],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(1,i),onDragEnd:this.handleEndPointDragEnd})}setupDashLineInteraction(){this.dashLine&&(this.setupDashLineHitArea(),this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.dashLine.on("pointerdown",this.handleDashLinePointerDown))}setupDashLineHitArea(){if(!this.dashLine)return;const e=this.endPoints;if(e.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),r=Pc(e[0],e[1],s);if(r.length===0)return;const o=new Re(r);this.dashLine.hitArea=o}startDragging(e){this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialDividerPoints=this.endPoints.map(s=>({...s})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const e=this.endPoints;e.length<2||!this.dashLine||this.dashLine.updatePoints(e[0],e[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(e);this.solidLine.clear(),this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke()}updateEndPoints(){const e=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(e[0]),this.endEndPoint&&this.endEndPoint.updatePosition(e[1])}registerScaleListener(){const{emitter:e}=this.appService;e.on("antiScale",this.throttledHandleScaleChange)}getDividerEndPoints(){return[...this.endPoints]}getEffectiveDividerPoints(){return this.solidLinePoints?[...this.solidLinePoints]:null}calculateAndCreateSolidLine(){if(this.clearSolidLine(),typeof this.roomId!="number"||!this.getRoomGraphics())return;const i=this.calculateLineRoomIntersection();i&&i.length>=2&&(this.solidLinePoints=[i[0],i[i.length-1]],this.createSolidLine())}getRoomGraphics(){const e=this.appService.mapManager.roomFill;return!e||typeof this.roomId!="number"?null:e.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const e=this.endPoints;if(e.length<2||typeof this.roomId!="number")return null;const[i,s]=e,r=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(r||o)return null;const a=ux(i,s),h=[];for(const p of a)this.isPointInRoomFill(p)&&h.push(p);if(h.length===0)return null;const l=h[0],c=h[h.length-1];return tt(l,c)<3?null:Ex(l,c,.5)}isPointInRoomFill(e){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:e.x+i.origin.x,y:e.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(e){e.x-=.5,e.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const r=s.getRasterRoomData(this.roomId);if(!r)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(e.x),h=Math.round(e.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<r.pixelIndices.length;c++)if(r.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(e){const i={x:Math.round(e.x),y:Math.round(e.y)},s=this.appService.getApp().mapState,r=this.appService.mapManager.getRoomById(this.roomId);return!s||!r||!r.outlinePoints?!1:kt(i,r.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:e}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const r={x:i[0].x+s.origin.x,y:i[0].y+s.origin.y},o={x:i[1].x+s.origin.x,y:i[1].y+s.origin.y};return!Rx(r,o,e.x,e.y,e.width,e.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:e}=this.appService.dividerConfig;e&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var e,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.endPoints)}updateComponents(){const e=this.endPoints;e.length>=2&&(this.dashLine.updatePoints(e[0],e[1]),this.startEndPoint.position.set(e[0].x,e[0].y),this.endEndPoint.position.set(e[1].x,e[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(e);this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke(),this.addChildAt(this.solidLine,0)}clearSolidLine(){this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.solidLinePoints=null}updatedividerPoints(e){this.endPoints=this.validateDividerPoints(e),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var e,i,s,r;this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[]),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.dashLine&&this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.clearSolidLine(),(i=this.dashLine)==null||i.destroy(),(s=this.startEndPoint)==null||s.destroy(),(r=this.endEndPoint)==null||r.destroy(),super.destroy()}}const xr=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","purifyPoint","wayPoint","divider"];function ES(n){if(!n||n.length===0)return[...xr];const t=new Set,e=[];for(const i of n)t.has(i)||(t.add(i),e.push(i));for(const i of xr)t.has(i)||e.push(i);return e}class IS{constructor(t){f(this,"zoneMaps",new Map);f(this,"virtualWallMap",new Map);f(this,"spotMap",new Map);f(this,"purifyPointMap",new Map);f(this,"wayPointMap",new Map);f(this,"divider",null);f(this,"controlContainers",new Map);f(this,"unsubscribeFns",[]);f(this,"builtinZoneFactories",{forbiddenSweepZone:t=>to.create(this.appService,t),forbiddenMopZone:t=>eo.create(this.appService,t),cleanZone:t=>io.create(this.appService,t)});this.appService=t,this.initializeControlContainers();const e=O(t.runtime,"editingForbiddenSweepZoneIds",p=>{w.log(`[runtime] editingForbiddenSweepZoneIds: ${p}`);const g=this.zoneMaps.get("forbiddenSweepZone");g&&this.updateZonesEditState("forbiddenSweepZone",g)}),i=O(t.runtime,"editingForbiddenMopZoneIds",p=>{w.log(`[runtime] editingForbiddenMopZoneIds: ${p}`);const g=this.zoneMaps.get("forbiddenMopZone");g&&this.updateZonesEditState("forbiddenMopZone",g)}),s=O(t.runtime,"editingCleanZoneIds",p=>{w.log(`[runtime] editingCleanZoneIds: ${p}`);const g=this.zoneMaps.get("cleanZone");g&&this.updateZonesEditState("cleanZone",g)}),r=O(t.runtime,"editingCustomZoneIds",p=>{w.log(`[runtime] editingCustomZoneIds: ${JSON.stringify(p??{})}`);for(const[g,y]of this.zoneMaps)$e(g)||y.size&&this.updateZonesEditState(g,y)}),o=O(t.runtime,"editingVirtualWallIds",p=>{w.log(`[runtime] editingVirtualWallIds: ${p}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),a=O(t.runtime,"editingSpotIds",p=>{w.log(`[runtime] editingSpotIds: ${p}`),this.updateSpotsEditState(this.spotMap)}),h=O(t.runtime,"editingPurifyPointIds",p=>{w.log(`[runtime] editingPurifyPointIds: ${p}`),this.updatePurifyPointsEditState(this.purifyPointMap)}),l=O(t.runtime,"editingWayPointIds",p=>{w.log(`[runtime] editingWayPointIds: ${p}`),this.updateWayPointsEditState(this.wayPointMap)}),c=O(t.runtime,"dividingRoomId",p=>{w.log(`[runtime] dividingRoomId: ${p}`),this.handleDividingRoomIdChange(p)}),d=O(t.runtime,"unit",p=>{w.log(`[runtime] unit changed: ${p}`),this.handleUnitChange()}),u=O(t.runtime,"unitLabel",p=>{w.log(`[runtime] unitLabel changed: ${p}`),this.handleUnitChange()});this.unsubscribeFns.push(e,i,s,r,o,a,h,l,c,d,u)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const t=this.appService.appContainer.getLayer(ke);if(!t){w.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const e of xr){const i=new W;i.label=`controls:${e}`,this.controlContainers.set(e,i),t.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const t=this.appService.appContainer.getLayer(ke);if(!t)return;ES(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const r=this.controlContainers.get(i);r&&(r.zIndex=s)}),t.sortableChildren=!0,t.sortChildren()}addToControlLayer(t,e){let i=this.controlContainers.get(t);if(!i){const s=this.appService.appContainer.getLayer(ke);if(!s){w.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new W,i.label=`controls:${t}`,this.controlContainers.set(t,i),s.addChild(i),this.applyRenderOrder()}i.addChild(e)}drawForbiddenSweepZones(t){this.drawZonesByType("forbiddenSweepZone",t)}getForbiddenSweepZones(){return this.getZonesDataByType("forbiddenSweepZone")}clearAllForbiddenSweepZones(){this.clearAllZonesByType("forbiddenSweepZone")}drawForbiddenMopZones(t){this.drawZonesByType("forbiddenMopZone",t)}getForbiddenMopZones(){return this.getZonesDataByType("forbiddenMopZone")}clearAllForbiddenMopZones(){this.clearAllZonesByType("forbiddenMopZone")}drawCleanZones(t){this.drawZonesByType("cleanZone",t)}getCleanZones(){return this.getZonesDataByType("cleanZone")}clearAllCleanZones(){this.clearAllZonesByType("cleanZone")}drawVirtualWalls(t){var r;const e=this.appService,i=this.virtualWallMap,s=new Set(t.map(o=>o.id));for(const[o,a]of i)s.has(o)||((r=a.parent)==null||r.removeChild(a),a.destroy(),i.delete(o));t.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new yr({appService:e,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickVirtualWall)==null||d.call(c,l)}}});i.set(o.id,h),this.addToControlLayer("virtualWall",h)}})}getVirtualWalls(){return this.getWallsData(this.virtualWallMap)}clearAllVirtualWalls(){this.clearAllWalls(this.virtualWallMap)}drawSpots(t){const e=this.spotMap;if(!t||t.length===0){this.clearAllSpotsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(r=>r.id));for(const r of i)s.has(r)||this.removeSpot(r,e);t.forEach(r=>{const o=e.get(r.id);o?this.isSpotDataEqual(o.getSpotData(),r)||o.updateSpotData(r):this.addNewSpot(r,e)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}drawPurifyPoints(t){const e=this.purifyPointMap;if(!t||t.length===0){this.clearAllPurifyPointsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(r=>r.id));for(const r of i)s.has(r)||this.removePurifyPoint(r,e);t.forEach(r=>{const o=e.get(r.id);o?this.isPurifyPointDataEqual(o.getPurifyPointData(),r)||o.updatePurifyPointData(r):this.addNewPurifyPoint(r,e)})}getPurifyPoints(){return this.getPurifyPointsData(this.purifyPointMap)}clearAllPurifyPoints(){this.clearAllPurifyPointsInternal(this.purifyPointMap)}getZoneMap(t){let e=this.zoneMaps.get(t);return e||(e=new Map,this.zoneMaps.set(t,e)),e}resolveZoneFactory(t){var s;const e=this.builtinZoneFactories[t];return e||((s=this.appService.getConfig().customZoneTypes)!=null&&s[t]?r=>new Ns({deps:Vs(this.appService,{onRemove:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onRemoveCustomZone)==null?void 0:h.call(a,t,o)},onUpdate:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onUpdateCustomZone)==null?void 0:h.call(a,t,o)},onClick:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onClickCustomZone)==null?void 0:h.call(a,t,o)}}),zoneData:r,zoneType:t}):null)}drawCustomZones(t,e){this.drawZonesByType(t,e)}getCustomZones(t){return this.getZonesDataByType(t)}clearCustomZones(t){this.clearAllZonesByType(t)}drawZonesByType(t,e){const i=this.resolveZoneFactory(t);if(!i){w.warn(`[ControlsManager] Unknown zone type: ${t}`);return}const s=this.getZoneMap(t);this.drawZonesImpl(e,s,i,t)}getZonesDataByType(t){const e=this.zoneMaps.get(t);return e?this.getZonesData(e):[]}clearAllZonesByType(t){const e=this.zoneMaps.get(t);e&&this.clearAllZones(e)}drawZonesImpl(t,e,i,s){if(!t||t.length===0){this.clearAllZones(e);return}const r=new Set(e.keys()),o=new Set(t.map(a=>a.id));for(const a of r)o.has(a)||this.removeZone(a,e);t.forEach(a=>{const h=e.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,e,i,s)})}addNewZone(t,e,i,s){const r=i(t);e.set(t.id,r),this.addToControlLayer(s,r),r.setEditing(this.getEditingZoneIds(String(s)).includes(t.id))}removeZone(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getZonesData(t){const e=[];return t.forEach(i=>{e.push(i.getZoneData())}),e}clearAllZones(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}getEditingZoneIds(t){var i;const e=this.appService.runtimeSnapshot;switch(t){case"forbiddenSweepZone":return e.editingForbiddenSweepZoneIds;case"forbiddenMopZone":return e.editingForbiddenMopZoneIds;case"cleanZone":return e.editingCleanZoneIds;default:return((i=e.editingCustomZoneIds)==null?void 0:i[t])??[]}}updateZonesEditState(t,e){const i=this.getEditingZoneIds(t);e.forEach((s,r)=>{s.setEditing(i.includes(r))})}updateVirtualWallsEditState(t){t.forEach(e=>{e.updateEditingState()})}isZoneDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],r=e.points[i];if(Math.abs(s.x-r.x)>.1||Math.abs(s.y-r.y)>.1)return!1}return!0}getWallsData(t){return Array.from(t.values()).map(e=>e.getWallData())}clearAllWalls(t){for(const e of t.values())e.destroy();t.clear()}isWallDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],r=e.points[i];if(Math.abs(s.x-r.x)>.1||Math.abs(s.y-r.y)>.1)return!1}return!0}addNewSpot(t,e){const i=so.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("spot",i)}removeSpot(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getSpotsData(t){const e=[];return t.forEach(i=>{e.push(i.getSpotData())}),e}clearAllSpotsInternal(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}updateSpotsEditState(t){t.forEach(e=>{e.updateEditState()})}isSpotDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1?!1:t.name===e.name}addNewPurifyPoint(t,e){const i=no.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("purifyPoint",i)}removePurifyPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getPurifyPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getPurifyPointData())}),e}clearAllPurifyPointsInternal(t){t.forEach(e=>{var i;(i=e.parent)==null||i.removeChild(e),e.destroy()}),t.clear()}updatePurifyPointsEditState(t){t.forEach(e=>{e.updateEditState()})}isPurifyPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1?!1:t.name===e.name}drawWayPoints(t){w.log("[ControlsManager] drawWayPoints",t);const e=Array.from(this.wayPointMap.keys()),i=t.map(r=>r.id);e.filter(r=>!i.includes(r)).forEach(r=>{this.removeWayPoint(r,this.wayPointMap)}),t.forEach((r,o)=>{const a=o+1,h=this.wayPointMap.get(r.id);h?(this.isWayPointDataEqual(h.getWayPointData(),r)||h.updateWayPoint(r),h.updateOrder(a)):this.addNewWayPoint(r,a,this.wayPointMap)})}clearAllWayPoints(){w.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(t,e,i){var o,a;const s=this.appService,r=new RS({appService:s,wayPointData:t,order:e,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(t.id,r),this.addToControlLayer("wayPoint",r)}removeWayPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getWayPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getWayPointData())}),e}clearAllWayPointsInternal(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}updateWayPointsEditState(t){t.forEach(e=>{e.onEditStateChange()})}isWayPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(t){if(t==null||t===-1){this.clearDivider();return}if(!this.getRoomGeometry(t)){this.clearDivider();return}this.createDefaultDivider(t)}getRoomGeometry(t){return this.appService.mapManager.getRoomById(t)}createDefaultDivider(t){const e=this.appService;this.clearDivider(),this.divider=new kS({appService:this.appService,roomId:t,events:{onUpdate:i=>{var s,r;(r=(s=e.events)==null?void 0:s.onUpdateDivider)==null||r.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var t;this.divider&&((t=this.divider.parent)==null||t.removeChild(this.divider),this.divider.destroy(),this.divider=null)}getDividerEndPoints(){return this.divider?this.divider.getDividerEndPoints():null}getEffectiveDividerPoints(){return this.divider?this.divider.getEffectiveDividerPoints():null}handleUnitChange(){w.debug("[ControlsManager] Unit changed, refreshing all size texts");for(const t of this.zoneMaps.values())t.forEach(e=>{e.refreshDisplay()});this.virtualWallMap.forEach(t=>{t.refreshDisplay()}),this.spotMap.forEach(t=>{t.refreshDisplay()}),this.purifyPointMap.forEach(t=>{t.refreshDisplay()})}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[];for(const t of this.zoneMaps.keys())this.clearAllZonesByType(t);this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearAllPurifyPoints(),this.clearDivider(),this.controlContainers.forEach(t=>{t.removeFromParent(),t.destroy({children:!0})}),this.controlContainers.clear()}}class DS extends Ut{constructor(e,i){super(e);f(this,"objectData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);this.appService=e,this.objectData=i}async initializeSprite(){const e=this.appService.detectedObjectConfig,i=this.objectData.width||e.width,s=this.objectData.height||e.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(e.anchor.x,e.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",r=>{this.applyAntiRotation(r)}),e.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickDetectedObject)==null||i.call(e,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(e){const i=this.objectData;this.objectData=e;const s=this.appService.detectedObjectConfig;if(i.src!==e.src){const r=e.width||s.width,o=e.height||s.height;await this.loadTextureAndSetSize(e.src,{width:r,height:o})}if(i.width!==e.width||i.height!==e.height){const r=e.width||s.width,o=e.height||s.height;this.setFixedSize(r,o)}this.position.set(e.x,e.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(e){return this.objectData.id===e.id&&this.objectData.src===e.src&&this.objectData.x===e.x&&this.objectData.y===e.y&&this.objectData.width===e.width&&this.objectData.height===e.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class FS{constructor(t){f(this,"detectedObjectMap",new Map);f(this,"unsubscribeShowDetectedObjects",null);this.appService=t,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=O(this.appService.runtime,"showDetectedObjects",e=>{this.applyLayerVisibility(e)})}async drawDetectedObjects(t){if(!t||t.length===0){this.clearAllDetectedObjects();return}const e=new Set(t.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)e.has(s)||this.removeDetectedObject(s);for(const s of t){const r=this.detectedObjectMap.get(s.id);r?r.isSameData(s)||await r.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(je);e&&(e.visible=t)}clearAllDetectedObjects(){const t=this.appService;this.detectedObjectMap.forEach(e=>{t.appContainer.removeFromLayer(je,e),e.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(t){const e=this.appService,i=new DS(this.appService,t);await i.initializeSprite(),this.detectedObjectMap.set(t.id,i),e.appContainer.addToLayer(je,i)}removeDetectedObject(t){const e=this.appService,i=this.detectedObjectMap.get(t);i&&(e.appContainer.removeFromLayer(je,i),i.destroy(),this.detectedObjectMap.delete(t))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var Ie={},Vc={},ne={};Object.defineProperty(ne,"__esModule",{value:!0});ne.loop=ne.conditional=ne.parse=void 0;var BS=function n(t,e){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:i;if(Array.isArray(e))e.forEach(function(o){return n(t,o,i,s)});else if(typeof e=="function")e(t,i,s,n);else{var r=Object.keys(e)[0];Array.isArray(e[r])?(s[r]={},n(t,e[r],i,s[r])):s[r]=e[r](t,i,s,n)}return i};ne.parse=BS;var zS=function(t,e){return function(i,s,r,o){e(i,s,r)&&o(i,t,s,r)}};ne.conditional=zS;var LS=function(t,e){return function(i,s,r,o){for(var a=[],h=i.pos;e(i,s,r);){var l={};if(o(i,t,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};ne.loop=LS;var dt={};Object.defineProperty(dt,"__esModule",{value:!0});dt.readBits=dt.readArray=dt.readUnsigned=dt.readString=dt.peekBytes=dt.readBytes=dt.peekByte=dt.readByte=dt.buildStream=void 0;var OS=function(t){return{data:t,pos:0}};dt.buildStream=OS;var Nc=function(){return function(t){return t.data[t.pos++]}};dt.readByte=Nc;var WS=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+t]}};dt.peekByte=WS;var $s=function(t){return function(e){return e.data.subarray(e.pos,e.pos+=t)}};dt.readBytes=$s;var GS=function(t){return function(e){return e.data.subarray(e.pos,e.pos+t)}};dt.peekBytes=GS;var US=function(t){return function(e){return Array.from($s(t)(e)).map(function(i){return String.fromCharCode(i)}).join("")}};dt.readString=US;var HS=function(t){return function(e){var i=$s(2)(e);return t?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};dt.readUnsigned=HS;var VS=function(t,e){return function(i,s,r){for(var o=typeof e=="function"?e(i,s,r):e,a=$s(t),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};dt.readArray=VS;var NS=function(t,e,i){for(var s=0,r=0;r<i;r++)s+=t[e+r]&&Math.pow(2,i-r-1);return s},$S=function(t){return function(e){for(var i=Nc()(e),s=new Array(8),r=0;r<8;r++)s[7-r]=!!(i&1<<r);return Object.keys(t).reduce(function(o,a){var h=t[a];return h.length?o[a]=NS(s,h.index,h.length):o[a]=s[h.index],o},{})}};dt.readBits=$S;(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var t=ne,e=dt,i={blocks:function(u){for(var p=0,g=[],y=u.data.length,m=0,x=(0,e.readByte)()(u);x!==p&&x;x=(0,e.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;g.push((0,e.readBytes)(S)(u)),m+=S;break}g.push((0,e.readBytes)(x)(u)),m+=x}for(var v=new Uint8Array(m),b=0,P=0;P<g.length;P++)v.set(g[P],b),b+=g[P].length;return v}},s=(0,t.conditional)({gce:[{codes:(0,e.readBytes)(2)},{byteSize:(0,e.readByte)()},{extras:(0,e.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,e.readUnsigned)(!0)},{transparentColorIndex:(0,e.readByte)()},{terminator:(0,e.readByte)()}]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),r=(0,t.conditional)({image:[{code:(0,e.readByte)()},{descriptor:[{left:(0,e.readUnsigned)(!0)},{top:(0,e.readUnsigned)(!0)},{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{lct:(0,e.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,e.readArray)(3,function(d,u,p){return Math.pow(2,p.descriptor.lct.size+1)})},function(d,u,p){return p.descriptor.lct.exists}),{data:[{minCodeSize:(0,e.readByte)()},i]}]},function(d){return(0,e.peekByte)()(d)===44}),o=(0,t.conditional)({text:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{preData:function(u,p,g){return(0,e.readBytes)(g.text.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,t.conditional)({application:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{id:function(u,p,g){return(0,e.readString)(g.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,t.conditional)({comment:[{codes:(0,e.readBytes)(2)},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,e.readString)(3)},{version:(0,e.readString)(3)}]},{lsd:[{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{gct:(0,e.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,e.readByte)()},{pixelAspectRatio:(0,e.readByte)()}]},(0,t.conditional)({gct:(0,e.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,t.loop)([s,a,h,r,o],function(d){var u=(0,e.peekByte)()(d);return u===33||u===44})}],c=l;n.default=c})(Vc);var Ys={};Object.defineProperty(Ys,"__esModule",{value:!0});Ys.deinterlace=void 0;var YS=function(t,e){for(var i=new Array(t.length),s=t.length/e,r=function(u,p){var g=t.slice(p*e,(p+1)*e);i.splice.apply(i,[u*e,e].concat(g))},o=[0,4,2,1],a=[8,8,4,2],h=0,l=0;l<4;l++)for(var c=o[l];c<s;c+=a[l])r(c,h),h++;return i};Ys.deinterlace=YS;var Xs={};Object.defineProperty(Xs,"__esModule",{value:!0});Xs.lzw=void 0;var XS=function(t,e,i){var s=4096,r=-1,o=i,a,h,l,c,d,u,p,C,g,y,P,m,_,R,A,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=t,h=1<<m,d=h+1,a=h+2,p=r,c=m+1,l=(1<<c)-1,g=0;g<h;g++)S[g]=0,v[g]=g;var P,C,_,R,M,A;for(P=C=_=R=M=A=0,y=0;y<o;){if(R===0){if(C<c){P+=e[A]<<C,C+=8,A++;continue}if(g=P&l,P>>=c,C-=c,g>a||g==d)break;if(g==h){c=m+1,l=(1<<c)-1,a=h+2,p=r;continue}if(p==r){b[R++]=v[g],p=g,_=g;continue}for(u=g,g==a&&(b[R++]=_,g=p);g>h;)b[R++]=v[g],g=S[g];_=v[g]&255,b[R++]=_,a<s&&(S[a]=p,v[a]=_,a++,!(a&l)&&a<s&&(c++,l+=a)),p=u}R--,x[M++]=b[R],y++}for(y=M;y<o;y++)x[y]=0;return x};Xs.lzw=XS;Object.defineProperty(Ie,"__esModule",{value:!0});var $c=Ie.decompressFrames=Ie.decompressFrame=Yc=Ie.parseGIF=void 0,jS=JS(Vc),ZS=ne,qS=dt,KS=Ys,QS=Xs;function JS(n){return n&&n.__esModule?n:{default:n}}var tv=function(t){var e=new Uint8Array(t);return(0,ZS.parse)((0,qS.buildStream)(e),jS.default)},Yc=Ie.parseGIF=tv,ev=function(t){for(var e=t.pixels.length,i=new Uint8ClampedArray(e*4),s=0;s<e;s++){var r=s*4,o=t.pixels[s],a=t.colorTable[o]||[0,0,0];i[r]=a[0],i[r+1]=a[1],i[r+2]=a[2],i[r+3]=o!==t.transparentIndex?255:0}return i},Xc=function(t,e,i){if(!t.image){console.warn("gif frame does not have associated image.");return}var s=t.image,r=s.descriptor.width*s.descriptor.height,o=(0,QS.lzw)(s.data.minCodeSize,s.data.blocks,r);s.descriptor.lct.interlaced&&(o=(0,KS.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=e,t.gce&&(a.delay=(t.gce.delay||10)*10,a.disposalType=t.gce.extras.disposal,t.gce.extras.transparentColorGiven&&(a.transparentIndex=t.gce.transparentColorIndex)),i&&(a.patch=ev(a)),a};Ie.decompressFrame=Xc;var iv=function(t,e){return t.frames.filter(function(i){return i.image}).map(function(i){return Xc(i,t.gct,e)})};$c=Ie.decompressFrames=iv;class js{constructor(t){if(!t||!t.length)throw new Error("Invalid frames");const[{texture:{width:e,height:i}}]=t;this.width=e,this.height=i,this.frames=t,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const t of this.textures)t.destroy(!0);for(const t of this.frames)t.texture=null;this.frames.length=0,this.textures.length=0,Object.assign(this,{frames:null,textures:null,width:0,height:0,duration:0,totalFrames:0})}static from(t,e){if(!t||t.byteLength===0)throw new Error("Invalid buffer");const i=S=>{let v=null;for(const b of S.frames)v=b.gce??v,"image"in b&&!("gce"in b)&&(b.gce=v)},s=Yc(t);i(s);const r=$c(s,!0),o=[],a=s.lsd.width,h=s.lsd.height,l=$.get().createCanvas(a,h),c=l.getContext("2d",{willReadFrequently:!0}),d=$.get().createCanvas(),u=d.getContext("2d");let p=0,g=null;const{fps:y=30,...m}=e??{},x=1e3/y;for(let S=0;S<r.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:C,height:_,left:R,top:M}}=r[S];d.width=C,d.height=_,u.clearRect(0,0,C,_);const A=u.createImageData(C,_);A.data.set(P),u.putImageData(A,0,0),v===3&&(g=c.getImageData(0,0,a,h)),c.drawImage(d,R,M);const T=c.getImageData(0,0,a,h);v===2?c.clearRect(0,0,a,h):v===3&&c.putImageData(g,0,0);const I=$.get().createCanvas(T.width,T.height);I.getContext("2d").putImageData(T,0,0),o.push({start:p,end:p+b,texture:new G({source:new Mr({resource:I,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new js(o)}}const sv={extension:E.Asset,detection:{test:async()=>!0,add:async n=>[...n,"gif"],remove:async n=>n.filter(t=>t!=="gif")},loader:{name:"gifLoader",id:"gif",test:n=>Mt.extname(n)===".gif"||n.startsWith("data:image/gif"),load:async(n,t)=>{const i=await(await $.get().fetch(n)).arrayBuffer();return js.from(i,t==null?void 0:t.data)},unload:async n=>{n.destroy()}}},jc=class Sr extends jt{constructor(...t){const e=t[0]instanceof js?{source:t[0]}:t[0],{source:i,fps:s,loop:r,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},Sr.defaultOptions,e);super({texture:G.EMPTY,...u}),this.animationSpeed=1,this.loop=!0,this.duration=0,this.autoPlay=!0,this.dirty=!1,this._currentFrame=0,this._autoUpdate=!1,this._isConnectedToTicker=!1,this._playing=!1,this._currentTime=0,this.onRender=()=>this._updateFrame(),this.texture=i.textures[0],this.duration=i.frames[i.frames.length-1].end,this._source=i,this._playing=!1,this._currentTime=0,this._isConnectedToTicker=!1,Object.assign(this,{fps:s,loop:r,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d}),this.currentFrame=0,a&&this.play()}stop(){this._playing&&(this._playing=!1,this._autoUpdate&&this._isConnectedToTicker&&(mt.shared.remove(this.update,this),this._isConnectedToTicker=!1))}play(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(mt.shared.add(this.update,this,Fe.HIGH),this._isConnectedToTicker=!0),!this.loop&&this.currentFrame===this._source.frames.length-1&&(this._currentTime=0))}get progress(){return this._currentTime/this.duration}get playing(){return this._playing}update(t){var o,a;if(!this._playing)return;const e=this.animationSpeed*t.deltaTime/mt.targetFPMS,i=this._currentTime+e,s=i%this.duration,r=this._source.frames.findIndex(h=>h.start<=s&&h.end>s);i>=this.duration?this.loop?(this._currentTime=s,this._updateFrameIndex(r),(o=this.onLoop)==null||o.call(this)):(this._currentTime=this.duration,this._updateFrameIndex(this.totalFrames-1),(a=this.onComplete)==null||a.call(this),this.stop()):(this._currentTime=s,this._updateFrameIndex(r))}_updateFrame(){this.dirty&&(this.texture=this._source.frames[this._currentFrame].texture,this.dirty=!1)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,!this._autoUpdate&&this._isConnectedToTicker?(mt.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(mt.shared.add(this.update,this),this._isConnectedToTicker=!0))}get currentFrame(){return this._currentFrame}set currentFrame(t){this._updateFrameIndex(t),this._currentTime=this._source.frames[t].start}get source(){return this._source}_updateFrameIndex(t){var e;if(t<0||t>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${t}`);this._currentFrame!==t&&(this._currentFrame=t,this.dirty=!0,(e=this.onFrameChange)==null||e.call(this,t))}get totalFrames(){return this._source.totalFrames}destroy(t=!1){this.stop(),super.destroy(),t&&this._source.destroy();const e=null;this._source=e,this.onComplete=e,this.onFrameChange=e,this.onLoop=e}clone(){const t=new Sr({source:this._source,autoUpdate:this._autoUpdate,loop:this.loop,autoPlay:this.autoPlay,animationSpeed:this.animationSpeed,onComplete:this.onComplete,onFrameChange:this.onFrameChange,onLoop:this.onLoop});return t.dirty=!0,t}};jc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let nv=jc;q.add(sv);class ro extends nv{constructor(e,i){super(i);f(this,"throttledUpdateScale");f(this,"fixedWidth",0);f(this,"fixedHeight",0);f(this,"isFixedSizeSet",!1);f(this,"sizeFixed",!0);f(this,"baselineScale",1);f(this,"basePositionX",0);f(this,"basePositionY",0);f(this,"pixelOffset",null);this.appService=e,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(e){this.sizeFixed=e,this.baselineScale=1,e&&this.isFixedSizeSet?this.applySize():!e&&this.isFixedSizeSet&&this.applySize()}setBasePosition(e,i){this.basePositionX=e,this.basePositionY=i,this.pixelOffset?this.applyPixelOffset():this.position.set(e,i)}setPixelOffset(e){this.pixelOffset=e,e?this.applyPixelOffset():this.position.set(this.basePositionX,this.basePositionY)}applyPixelOffset(){if(this.destroyed||!this.pixelOffset)return;if(!this.sizeFixed){this.position.set(this.basePositionX,this.basePositionY);return}const e=this.appService.currentScale,i=this.appService.appContainer.getMapRotationRadians(),s=$r(this.pixelOffset,e,i);this.position.set(this.basePositionX+s.x,this.basePositionY+s.y)}set width(e){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(e,this.fixedHeight||e)}set height(e){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||e,e)}get width(){return this.fixedWidth||super.width}get height(){return this.fixedHeight||super.height}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applySize(){if(!this.isFixedSizeSet||!this.texture||this.texture.width===0||this.texture.height===0)return;const e=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const r=e/s,o=i/s;super.scale.set(r,o)}else super.scale.set(e/this.baselineScale,i/this.baselineScale)}updateScale(e){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():e!==0&&super.scale.set(1/e),this.applyPixelOffset())}static async createFromSrc(e,i,s){try{const r=await N.load(i),o=new ro(e,{source:r});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(r){throw w.error(`Failed to load GIF "${i}":`,r),r}}draw(e,i){const{x:s,y:r,rotation:o=0}=e;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,r)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ve extends ro{constructor(e,i,s){super(e,{source:i});f(this,"elementData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.elementData=s}async initialize(){this.elementData.sizeFixed!==void 0&&this.setSizeFixed(this.elementData.sizeFixed),this.setFixedSize(this.elementData.width,this.elementData.height);const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.setPixelOffset(this.elementData.pixelOffset??null),this.setBasePosition(this.elementData.x,this.elementData.y),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.elementData.opacity!==void 0&&(this.alpha=this.elementData.opacity),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i),this.applyPixelOffset()}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;if(this.elementData=e,i.src!==e.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height);const s=e.anchor||{x:.5,y:.5},r=i.anchor||{x:.5,y:.5};(s.x!==r.x||s.y!==r.y)&&this.anchor.set(s.x,s.y),this.setPixelOffset(e.pixelOffset??null),this.setBasePosition(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5},r=this.elementData.pixelOffset,o=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y&&((r==null?void 0:r.x)??0)===((o==null?void 0:o.x)??0)&&((r==null?void 0:r.y)??0)===((o==null?void 0:o.y)??0)}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class On extends Ut{constructor(e,i){super(e);f(this,"elementData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.appService=e,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.setPixelOffset(this.elementData.pixelOffset??null),this.setBasePosition(this.elementData.x,this.elementData.y),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.elementData.opacity!==void 0&&(this.alpha=this.elementData.opacity),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i),this.applyPixelOffset()}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.src!==e.src?await this.loadTextureAndSetSize(e.src,{width:e.width,height:e.height,sizeFixed:e.sizeFixed}):(i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height));const s=e.anchor||{x:.5,y:.5},r=i.anchor||{x:.5,y:.5};(s.x!==r.x||s.y!==r.y)&&this.anchor.set(s.x,s.y),this.setPixelOffset(e.pixelOffset??null),this.setBasePosition(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5},r=this.elementData.pixelOffset,o=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y&&((r==null?void 0:r.x)??0)===((o==null?void 0:o.x)??0)&&((r==null?void 0:r.y)??0)===((o==null?void 0:o.y)??0)}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class rv extends dm{constructor(e,i){super(i);f(this,"throttledUpdateScale");f(this,"fixedWidth",0);f(this,"fixedHeight",0);f(this,"isFixedSizeSet",!1);f(this,"userCenterX",0);f(this,"userCenterY",0);f(this,"sizeFixed",!0);f(this,"pixelOffset",null);this.appService=e,this.anchor.set(0,0),this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(e,i){this.userCenterX=e,this.userCenterY=i,this.updatePositionFromCenter()}setPixelOffset(e){this.pixelOffset=e,this.isFixedSizeSet&&this.updatePositionFromCenter()}applyPixelOffset(){this.isFixedSizeSet&&this.updatePositionFromCenter()}setSizeFixed(e){this.sizeFixed=e,this.isFixedSizeSet&&(this.applyFixedSize(),this.updatePositionFromCenter())}getIsFixedSizeSet(){return this.isFixedSizeSet}updatePositionFromCenter(){if(!this.isFixedSizeSet){this.position.set(this.userCenterX,this.userCenterY);return}const i=this.appService.currentScale;let s,r;this.sizeFixed?(s=this.fixedWidth/2/i,r=this.fixedHeight/2/i):(s=this.fixedWidth/2,r=this.fixedHeight/2);let o=this.userCenterX,a=this.userCenterY;if(this.sizeFixed&&this.pixelOffset){const h=this.appService.appContainer.getMapRotationRadians(),l=$r(this.pixelOffset,i,h);o+=l.x,a+=l.y}this.position.set(o-s,a-r)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applyFixedSize(){if(!this.isFixedSizeSet)return;const i=this.appService.currentScale;if(i!==0){if(this.sizeFixed){const s=1/i;this.scale.set(s)}else this.scale.set(1);this.element&&(this.element.style.width=`${this.fixedWidth}px`,this.element.style.height=`${this.fixedHeight}px`)}}updateScale(e){this.isFixedSizeSet&&e!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(e){return super.updateTransform(e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ii extends rv{constructor(e,i){const s=document.createElement("div");Ii.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(e,{element:s});f(this,"elementData");f(this,"domClickHandler",null);f(this,"resizeObserver",null);f(this,"debugMarker",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.elementData=i}async initialize(){this.alpha=0,this.elementData.width&&this.elementData.height?(this.setFixedSize(this.elementData.width,this.elementData.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.waitForElementInsertion()):(this.position.set(this.elementData.x,this.elementData.y),this.setupAutoSize()),this.setPixelOffset(this.elementData.pixelOffset??null),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",e=>{this.applyRotation(e),this.applyPixelOffset()}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupAutoSize(){this.element&&(this.element.style.width="auto",this.element.style.height="auto",this.waitForElementDimensions())}waitForElementInsertion(){if(!this.element)return;const e=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(e))};requestAnimationFrame(e)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e=>{var s;const i=e[0];i&&i.contentRect.width>0&&i.contentRect.height>0&&(this.setFixedSize(i.contentRect.width,i.contentRect.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement(),(s=this.resizeObserver)==null||s.disconnect(),this.resizeObserver=null)}),this.resizeObserver.observe(this.element)):this.pollForElementDimensions())}pollForElementDimensions(){if(!this.element)return;const e=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(e);return}const i=this.element.getBoundingClientRect();i.width>0&&i.height>0?(this.setFixedSize(i.width,i.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement()):requestAnimationFrame(e)};requestAnimationFrame(e)}showElement(){this.alpha=this.elementData.opacity??1,this.element.style.pointerEvents=this.elementData.interactive?"auto":"none",this.interactive=this.elementData.interactive??!1,this.elementData.interactive&&this.element&&(this.element.style.setProperty("-webkit-tap-highlight-color","transparent"),this.element.style.setProperty("-webkit-touch-callout","none")),this.appService.getApp().renderOnceNextFrame()}setupClickHandler(){this.element&&(this.domClickHandler=e=>{e.preventDefault(),e.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.htmlContent!==e.htmlContent&&this.element&&(this.element.innerHTML=e.htmlContent,(!e.width||!e.height)&&this.waitForElementDimensions()),(i.width!==e.width||i.height!==e.height)&&(e.width&&e.height?(this.setFixedSize(e.width,e.height),this.element&&(this.element.style.width=`${e.width}px`,this.element.style.height=`${e.height}px`)):this.setupAutoSize()),this.setPixelOffset(e.pixelOffset??null),e.width&&e.height?this.setCenterPosition(e.x,e.y):this.getIsFixedSizeSet()?this.setCenterPosition(e.x,e.y):this.position.set(e.x,e.y),i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),this.userRotation=e.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=e.opacity??1,e.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(e){const i=this.elementData.pixelOffset,s=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.htmlContent===e.htmlContent&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&((i==null?void 0:i.x)??0)===((s==null?void 0:s.x)??0)&&((i==null?void 0:i.y)??0)===((s==null?void 0:s.y)??0)}static setupDefaultStyles(e,i){const s={position:"relative",boxSizing:"border-box",webkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",background:"transparent",userSelect:"auto",webkitUserSelect:"auto"};i.width&&i.height?(s.width=`${i.width}px`,s.height=`${i.height}px`,s.overflow="hidden"):(s.width=i.width?`${i.width}px`:"auto",s.height=i.height?`${i.height}px`:"auto",s.overflow="visible"),Object.assign(e.style,s),e.style.setProperty("-webkit-tap-highlight-color","transparent"),e.style.setProperty("-webkit-touch-callout","none")}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null),this.debugMarker&&(this.debugMarker.destroy(),this.debugMarker=null),super.destroy()}}class ov{constructor(t){f(this,"customElementsMap",new Map);f(this,"gifTicker",null);f(this,"gifElements",new Set);this.appService=t}async drawCustomElements(t){if(!t||t.length===0){this.clearAllCustomElements();return}const e=new Set(t.map(r=>r.id)),i=Array.from(this.customElementsMap.keys());for(const r of i)e.has(r)||this.removeCustomElement(r);const s=t.map(async r=>{const o=this.customElementsMap.get(r.id);o?this.isSameData(o,r)||(r.type==="gif"&&o.getElementData().src!==r.src?(this.removeCustomElement(r.id),await this.addNewCustomElement(r)):await this.updateElementData(o,r)):await this.addNewCustomElement(r)});await Promise.all(s),this.updateGifTicker()}clearAllCustomElements(){const t=this.appService;this.customElementsMap.forEach(e=>{e instanceof Ve?t.appContainer.removeFromLayer(Ei,e):t.appContainer.removeFromLayer(ki,e),e.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(t){const e=this.appService;let i;switch(t.type){case"image":i=new On(this.appService,t);break;case"gif":{const s=await N.load(t.src);i=new Ve(this.appService,s,t);break}case"html":i=new Ii(this.appService,t);break;default:throw new Error(`Unsupported custom element type: ${t.type}`)}await i.initialize(),this.customElementsMap.set(t.id,i),i instanceof Ve?(e.appContainer.addToLayer(Ei,i),this.gifElements.add(i)):e.appContainer.addToLayer(ki,i)}removeCustomElement(t){const e=this.appService,i=this.customElementsMap.get(t);i&&(i instanceof Ve?(this.gifElements.delete(i),e.appContainer.removeFromLayer(Ei,i)):e.appContainer.removeFromLayer(ki,i),i.destroy(),this.customElementsMap.delete(t))}isSameData(t,e){return t.getElementData().type!==e.type?!1:e.type==="image"&&t instanceof On||e.type==="gif"&&t instanceof Ve||e.type==="html"&&t instanceof Ii?t.isSameData(e):!1}async updateElementData(t,e){if(e.type==="image"&&t instanceof On)await t.updateElementData(e);else if(e.type==="gif"&&t instanceof Ve)await t.updateElementData(e);else if(e.type==="html"&&t instanceof Ii)await t.updateElementData(e);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var t;(t=this.gifTicker)!=null&&t.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new mt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var t;(t=this.gifTicker)!=null&&t.started&&(w.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const t=this.appService;if(this.gifElements.size===0)return;const e=t.getApp();e.renderer.render(e.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class av extends W{constructor(e,i){super();f(this,"roomId");f(this,"roomIndex");f(this,"appService");f(this,"nameText");f(this,"iconSprite",null);f(this,"iconWrapper",null);f(this,"iconBg",null);this.appService=e,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:r}=e.roomConfig,{showRoomType:o}=e.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new de({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Os({text:c,style:l}),this.nameText.anchor.set(.5),o&&i.type!=null&&(r!=null&&r.assets)&&r.assets[i.type]&&this.createIcon(i.type,h),this.addChild(this.nameText),this.layout()}createIcon(e,i){const{type:s}=this.appService.roomConfig,r=s.iconSize||14;this.iconWrapper||(this.iconWrapper=new W,this.addChild(this.iconWrapper)),s.container.visible?(this.iconBg||(this.iconBg=new H,this.iconWrapper.addChild(this.iconBg)),this.drawIconBg(i)):this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite||(this.iconSprite=new Ut(this.appService),this.iconSprite.anchor.set(.5),this.iconWrapper.addChild(this.iconSprite)),this.iconSprite.visible=!0,this.iconSprite.tint=s.container.visible?"#ffffff":i,this.iconSprite.setFixedSize(r,r),this.iconSprite.loadTextureAndSetSize(s.assets[e],{width:r,height:r,sizeFixed:!1}).then(()=>{this.iconSprite&&(this.iconSprite.visible=this.appService.runtime.showRoomType,this.layout())}),s.container&&this.iconSprite.position.set(0,0)}drawIconBg(e){const{type:i}=this.appService.roomConfig;if(!this.iconBg||!i.container.visible)return;const{size:s,borderRadius:r}=i.container;this.iconBg.clear().roundRect(-s/2,-s/2,s,s,r).fill(e)}layout(){if(!this.iconWrapper||!this.iconWrapper.visible){this.nameText.position.set(0,0);return}if(!(this.iconSprite&&this.iconSprite.visible||this.iconBg&&this.iconBg.visible)){this.nameText.position.set(0,0);return}const{gap:i=4,position:s="left"}=this.appService.roomConfig.type,r=this.nameText.width,o=this.iconWrapper.width,h=-(o+i+r)/2;s==="left"?(this.iconWrapper.x=h+o/2,this.nameText.x=h+o+i+r/2):(this.nameText.x=h+r/2,this.iconWrapper.x=h+r+i+o/2),this.iconWrapper.y=0,this.nameText.y=0}updateName(e){this.nameText.text=e,this.layout()}refreshColor(e){const{type:i}=this.appService.roomConfig,s=this.appService.getRoomData(this.roomId),r=(s==null?void 0:s.colorIndex)??this.roomIndex,o=this.getRoomNameColor(r,e);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(e,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:r,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(r)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[e%s.nameInactive.length]:s.name[e%s.name.length];const a=s.nameNormal||s.name;return a[e%a.length]}async updateRoomType(e){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||e==null||!(i!=null&&i.assets)||!i.assets[e])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const r=this.appService.getRoomData(this.roomId),o=(r==null?void 0:r.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(e,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(e){if(this.iconWrapper)this.iconWrapper.visible=e,this.layout();else if(e){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(e){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),this.nameText.destroy({texture:!0,textureSource:!0}),super.destroy(e)}}class hv extends W{constructor(e,i){super();f(this,"background");f(this,"foldedIndicator");f(this,"propertyIcons",new Map);f(this,"orderContainer");f(this,"orderBackground");f(this,"orderText");f(this,"isFolded",!1);f(this,"roomId");f(this,"roomIndex");f(this,"isDestroyed",!1);this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.foldedIndicator=new H,this.foldedIndicator.visible=!1;const{property:r}=s,o=i.colorIndex??i.index,a=this.getIconColor(o);this.initializePropertyIcons(r.displayOrders,a);const h=r.cleanOrder.color==="auto"?s.colors.active[o%s.colors.active.length]:r.cleanOrder.color;this.orderContainer=new W,this.orderBackground=new H,this.orderText=new Os({text:"",style:new de({fontSize:r.cleanOrder.fontSize,fontFamily:r.cleanOrder.fontFamily,fontWeight:r.cleanOrder.fontWeight,fill:h,align:"center",trim:!0})}),this.orderText.anchor.set(.5,.5),this.orderContainer.addChild(this.orderBackground),this.orderContainer.addChild(this.orderText),this.addChild(this.background),this.addChild(this.foldedIndicator),this.propertyIcons.forEach(({sprite:l})=>{this.addChild(l)}),this.addChild(this.orderContainer),this.visible=this.appService.runtimeSnapshot.showRoomProperty}initializePropertyIcons(e,i){const s=["cleanMode","suction","cistern","cleanTimes"];e.forEach(r=>{const o=s.includes(r),a=new Ut(this.appService);a.tint=i,a.anchor.set(0,0),this.propertyIcons.set(r,{fieldName:r,sprite:a,isBuiltin:o})})}async updateProperty(e){this.isDestroyed||this.destroyed||(await this.updateIcons(e),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(e,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return e[i]??null;if(e.customData&&i in e.customData){const r=e.customData[i];return typeof r=="number"?r:null}return null}getAssetAlias(e,i){const s={cleanMode:r=>`cleanMode_${r}`,suction:r=>`fan_${r}`,cistern:r=>`water_${r}`,cleanTimes:r=>`cleanTimes${r}`};return e in s?s[e](i):`custom_${e}_${i}`}shouldShowField(e,i,s){const{showRoomProperty:r}=this.appService.runtimeSnapshot;return!(s===null||!r||i==="cleanTimes"&&s<=0)}getDisplayElements(e){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,r=e.order||0,o=s&&r>0,a=[];return o&&a.push({element:this.orderContainer,show:!0,isOrder:!0,fieldName:"order"}),i.forEach(h=>{const l=this.propertyIcons.get(h);if(!l||!l.sprite)return;const c=this.getFieldValue(e,h);this.shouldShowField(e,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:r}}async updateIcons(e){if(this.isDestroyed||this.destroyed||this.isFolded)return;const{iconWidth:i,iconHeight:s,container:r,cleanOrder:o,iconGap:a}=this.appService.roomConfig.property,{paddingHorizontal:h,paddingVertical:l}=r,{elementsToShow:c,orderValue:d}=this.getDisplayElements(e);this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:g})=>{g.visible=!1});const u=[];if(c.forEach(g=>{if(g.isOrder){this.orderContainer.visible=!0,this.orderText.text=d.toString();const y=e.colorIndex??this.roomIndex,m=this.getIconColor(y);this.orderBackground.clear(),this.orderBackground.setFillStyle({color:m}),this.orderBackground.circle(i/2,s/2,i/2).fill();const x=this.resolveOrderTextColor(y);this.orderText.style.fill=x,this.orderText.position.set(i/2,s/2)}else{const y=this.propertyIcons.get(g.fieldName);if(y&&y.sprite){y.sprite.visible=!0;const m=this.getAssetAlias(g.fieldName,g.value);u.push(y.sprite.loadTextureAndSetSize(m,{width:i,height:s,sizeFixed:!1}))}}}),await Promise.all(u),this.isDestroyed||this.destroyed)return;let p=h;c.forEach((g,y)=>{const{element:m,isOrder:x}=g;!m||!m.position||(m.position.set(p,l),p+=i,y<c.length-1&&(x?p+=o.gapRight:p+=a))})}updateBackground(){if(this.isDestroyed||this.destroyed)return;const e=this.appService.roomConfig,{container:i,foldable:s}=e.property,{borderRadius:r,tailHeight:o,tailWidth:a,backgroundColor:h}=i,l=this.calculateContentWidth(),c=this.calculateContentHeight(),d=Math.min(r,l/2,c/2),u=d*.8,p=Math.max(l-u*2,a*.5),g=Math.min(a,l/2,p);if(this.background.clear(),this.background.setFillStyle({color:h}),s){const y=(l-g)/2,m=c+o;this.background.moveTo(d,0),this.background.lineTo(l-d,0),this.background.arcTo(l,0,l,d,d),this.background.lineTo(l,c-d),this.background.arcTo(l,c,l-d,c,d),this.background.lineTo(y+g,c),this.background.lineTo(y+g/2,m),this.background.lineTo(y,c),this.background.lineTo(d,c),this.background.arcTo(0,c,0,c-d,d),this.background.lineTo(0,d),this.background.arcTo(0,0,d,0,d),this.background.closePath()}else this.background.roundRect(0,0,l,c,d);this.background.fill()}calculateContentWidth(){const{iconWidth:e,container:i,cleanOrder:s,iconGap:r}=this.appService.roomConfig.property,{paddingHorizontal:o}=i,a=this.appService.getRoomData(this.roomId);if(!a)return o*2;const{elementsToShow:h}=this.getDisplayElements(a);let l=o;return h.forEach((c,d)=>{const{isOrder:u}=c;l+=e,d<h.length-1&&(u?l+=s.gapRight:l+=r)}),l+=o,l}calculateContentHeight(){const e=this.appService.roomConfig,{iconHeight:i,container:s}=e.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:e,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(e?s:0)}getTotalWidth(){if(this.isFolded){const{tailWidth:i}=this.appService.roomConfig.property.container,s=this.calculateContentWidth();return Math.min(i,s/2)}return this.calculateContentWidth()}async setFolded(e){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=e,e)this.background.visible=!1,this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:s})=>{s.visible=!1}),this.foldedIndicator.visible=!0,this.updateFoldedIndicator();else{this.background.visible=!0,this.foldedIndicator.visible=!1,this.foldedIndicator.position.set(0,0),this.updateBackground();const s=this.appService.getRoomData(this.roomId);s&&await this.updateIcons(s)}}isFoldedState(){const{foldable:e}=this.appService.roomConfig.property;return e?this.isFolded:!1}updateFoldedIndicator(){const e=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:r}=e.property.container,o=this.calculateContentWidth(),a=Math.min(s,o/2);this.foldedIndicator.clear(),this.foldedIndicator.setFillStyle({color:r}),this.foldedIndicator.poly([0,i,a,i,a/2,0]).fill(),this.foldedIndicator.position.set(0,0)}resolveOrderTextColor(e){const{property:i,colors:s}=this.appService.roomConfig,{enableRoomSelection:r}=this.appService.runtime;if(i.cleanOrder.color==="auto"){const o=r?s.active:s.normal||s.active;return o[e%o.length]}return i.cleanOrder.color}getIconColor(e){const{colors:i}=this.appService.roomConfig,{propertyTheme:s,propertyThemeInactive:r,propertyThemeNormal:o}=i,{enableRoomSelection:a,selectRoomIds:h}=this.appService.runtime;if(a)return!h.includes(this.roomId)&&r?r[e%r.length]:s[e%s.length];const l=o||s;return l[e%l.length]}refreshColor(){const e=this.appService.getRoomData(this.roomId),i=(e==null?void 0:e.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite:r})=>{r.tint=s}),this.orderBackground&&this.orderBackground.visible){const{property:r}=this.appService.roomConfig,o=r.iconWidth,a=r.iconHeight;this.orderBackground.clear(),this.orderBackground.setFillStyle({color:s}),this.orderBackground.circle(o/2,a/2,o/2).fill();const h=this.resolveOrderTextColor(i);this.orderText.style.fill=h}}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.propertyIcons.forEach(({sprite:e})=>{e.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0,context:!0}))}}class lv extends W{constructor(e,i){super();f(this,"background");f(this,"checkmarkIcon");f(this,"bubble");f(this,"roomIndex");f(this,"roomId");this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon:r}}=s;this.checkmarkIcon=new Ut(this.appService);const o=i.colorIndex??i.index;this.checkmarkIcon.tint=r[o%r.length],this.checkmarkIcon.anchor.set(0,0),this.addChild(this.background),this.addChild(this.bubble),this.addChild(this.checkmarkIcon)}async updateIndicator(e){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:r}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=r.includes(e.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(e){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:r}=i;if(e){this.visible=!0,this.checkmarkIcon.visible=!0,await this.checkmarkIcon.loadTextureAndSetSize("checkmark",{width:s,height:r,sizeFixed:!1});const o=i.containerWidth/2,a=i.containerHeight/2;this.checkmarkIcon.position.set(o-s/2,a-r/2)}else this.visible=!1}updateBackground(){const{selectionIndicator:e,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:r,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=e,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],g=a==="auto"?p:a;if(this.checkmarkIcon.tint=i.selectionIndicatorIcon[u%i.selectionIndicatorIcon.length],this.background.clear(),this.bubble.clear(),this.background.setFillStyle({color:p}).roundRect(0,0,s,r,h).fill().setStrokeStyle({color:g,width:o,alignment:0}).stroke(),l>0&&c>0){const y=(s-c)/2;this.bubble.setFillStyle({color:g});const m=r+o;this.bubble.poly([y,m-1,y+c,m-1,y+c/2,m+l]).fill()}}getTotalHeight(){const{selectionIndicator:e}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:r}=e;return i+r+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:e}=this.appService.roomConfig;return e.containerWidth}async refreshColor(){const e=this.appService.getRoomData(this.roomId);e&&await this.updateIndicator(e)}destroy(){var e;(e=this.checkmarkIcon)==null||e.destroy(),super.destroy({children:!0,context:!0})}}class cv extends W{constructor(e,i){super();f(this,"roomId");f(this,"roomName");f(this,"roomProperty",null);f(this,"roomSelectionIndicator",null);f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"targetElasticScale",1);f(this,"currentElasticScale",1);f(this,"isAnimatingScale",!1);f(this,"scaleAnimationBound",null);f(this,"updateScaleBound",null);this.appService=e,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(e.currentScale),this.updateScaleBound=s=>this.updateScale(s),this.appService.emitter.on("antiScale",this.updateScaleBound),this.updateScale(this.appService.currentScale),i.centerPoint&&this.position.set(i.centerPoint.x,i.centerPoint.y),this.roomName=new av(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",s=>{this.applyAntiRotation(s)}),this.clickHandler=new St(this,{onClick:()=>{var s,r;(r=(s=this.appService.events)==null?void 0:s.onClickRoomProperties)==null||r.call(s,i)}})}async initialize(e){await this.createRoomProperty(e),await this.createRoomSelectionIndicator(e),this.updateLayout()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}initializeElasticScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:r}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=r:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:r}=this.appService.roomConfig;if(!i){e!==0&&this.scale.set(1/e);return}if(e===0)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=r:h=1;const c=1/e*h;Math.abs(this.targetElasticScale-h)>.01?(this.targetElasticScale=h,this.startScaleAnimation()):this.scale.set(c)}startScaleAnimation(){this.scaleAnimationBound||(this.scaleAnimationBound=this.animateScale.bind(this)),this.isAnimatingScale||(this.isAnimatingScale=!0,this.appService.getApp().ticker.add(this.scaleAnimationBound))}animateScale(){this.currentElasticScale+=(this.targetElasticScale-this.currentElasticScale)*.3;const r=1/this.appService.currentScale*this.currentElasticScale;this.scale.set(r),Math.abs(this.currentElasticScale-this.targetElasticScale)<.001&&(this.currentElasticScale=this.targetElasticScale,this.isAnimatingScale=!1,this.scaleAnimationBound&&this.appService.getApp().ticker.remove(this.scaleAnimationBound))}shouldShowRoomProperty(){const{showRoomOrder:e,showRoomProperty:i,selectRoomIds:s,enableRoomSelection:r,roomSelectionMode:o}=this.appService.runtimeSnapshot,a=this.appService.getRoomData(this.roomId);if(!a||r&&o==="checkmark"&&s.includes(this.roomId))return!1;const h=e&&(a.order||0)>0;let l=!1;if(i){const{displayOrders:c}=this.appService.roomConfig.property;l=c.some(d=>!!(d==="suction"&&a.suction!=null||d==="cistern"&&a.cistern!=null||d==="cleanMode"&&a.cleanMode!=null||d==="cleanTimes"&&a.cleanTimes>0||a.customData&&d in a.customData&&typeof a.customData[d]=="number"&&a.customData[d]!=null))}return h||l}shouldShowRoomSelectionIndicator(){const{enableRoomSelection:e,roomSelectionMode:i}=this.appService.runtimeSnapshot;return e&&i==="checkmark"}async updateRoomPropertyVisibility(){if(!this.roomProperty)return;if(!this.shouldShowRoomProperty())this.roomProperty.visible=!1;else{this.roomProperty.visible=!0;const i=this.appService.runtimeSnapshot.roomPropertyFoldIds.includes(this.roomId);await this.roomProperty.setFolded(i);const s=this.appService.getRoomData(this.roomId);s&&await this.roomProperty.updateProperty(s)}this.updateLayout()}async updateRoomSelectionIndicatorVisibility(){if(!this.roomSelectionIndicator)return;if(this.shouldShowRoomSelectionIndicator()){const i=this.appService.getRoomData(this.roomId);i&&await this.roomSelectionIndicator.updateIndicator(i)}else this.roomSelectionIndicator.visible=!1;this.updateLayout()}async createRoomProperty(e){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new hv(this.appService,e),await this.roomProperty.updateProperty(e),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(e){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new lv(this.appService,e),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,g;if(this.destroyed)return;const{property:{offsetY:e,offsetX:i},selectionIndicator:{offsetY:s,offsetX:r}}=this.appService.roomConfig,o=((l=this.roomProperty)==null?void 0:l.visible)||!1,a=((c=this.roomName)==null?void 0:c.visible)||!1,h=((d=this.roomSelectionIndicator)==null?void 0:d.visible)||!1;if(o&&this.roomProperty){const y=this.roomProperty.getTotalHeight(),m=this.roomProperty.getTotalWidth();if(this.roomProperty.isFoldedState()){const S=-m/2+i,v=-y/2-e;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-e-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-e)}if(h&&this.roomSelectionIndicator){const y=this.roomSelectionIndicator.getTotalHeight(),m=this.roomSelectionIndicator.getTotalWidth();a&&((p=this.roomName)!=null&&p.position)?(this.roomSelectionIndicator.position.set(-m/2+r,-s-y),this.roomName.position.set(0,0)):this.roomSelectionIndicator.position.set(-m/2+r,-y/2-s)}a&&!o&&!h&&((g=this.roomName)!=null&&g.position)&&this.roomName.position.set(0,0)}updateName(e){this.roomName.updateName(e)}async updateRoomType(e){await this.roomName.updateRoomType(e),this.updateLayout()}updateRoomNameVisibility(e){this.roomName.visible=e,this.updateLayout()}updateRoomTypeVisibility(e){this.roomName.updateRoomTypeVisibility(e),this.updateLayout()}updatePosition(e){this.position.set(e.x,e.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var e,i,s,r;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.isAnimatingScale&&this.scaleAnimationBound&&(this.appService.getApp().ticker.remove(this.scaleAnimationBound),this.isAnimatingScale=!1),this.scaleAnimationBound=null,this.updateScaleBound&&(this.appService.emitter.off("antiScale",this.updateScaleBound),this.updateScaleBound=null),(i=this.roomProperty)==null||i.destroy(),this.roomProperty=null,(s=this.roomSelectionIndicator)==null||s.destroy(),this.roomSelectionIndicator=null,(r=this.roomName)==null||r.destroy(),this.isRenderGroup&&(this.isRenderGroup=!1),super.destroy()}}class dv extends W{constructor(e){super({isRenderGroup:!0});f(this,"floorTypeMap",new Map);f(this,"floorTypeMasks",new Map);f(this,"floorTypeContexts",new Map);f(this,"floorTypeToRooms",new Map);this.appService=e,this.appService.appContainer.addToLayer(qr,this)}async createFloorTypes(e){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(e),r=[];for(const[o,a]of s)r.push(this.createMergedFloorType(o,a));await Promise.all(r)}groupRoomsByFloorType(e){const i=new Map,s=this.appService;return e.forEach((r,o)=>{const a=s.getRoomData(o),h=(a==null?void 0:a.floorType)||0;h>=0&&(i.has(h)||i.set(h,[]),i.get(h).push({roomId:o,graphics:r}))}),i}async createMergedFloorType(e,i){const s=this.appService,{assets:r,opacity:o,scale:a}=s.roomConfig.floorType,h=e%r.length,l=`floorType${h}`;if(!r[h]){w.warn(`No texture asset configured for floorType: ${e}`);return}const c=await N.load(l);if(!c){w.warn(`Floor material texture not found: ${l}`);return}const d=i.map(({graphics:m})=>m.getLocalBounds()),u=Tx(d),p=new Ms({texture:c,width:u.width,height:u.height});p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:g,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=g,this.addChild(p),this.floorTypeMap.set(e,p),this.floorTypeMasks.set(e,g),this.floorTypeContexts.set(e,y),this.floorTypeToRooms.set(e,new Set(i.map(({roomId:m})=>m)))}createMergedMask(e){const i=new W,s=[];return e.forEach(r=>{const o=new H,a=r.context.clone();o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(e=>{try{e.destroy({children:!0})}catch(i){w.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(e=>{try{e.forEach(i=>{try{i.destroy()}catch(s){w.warn("Error destroying cloned graphics context:",s)}})}catch(i){w.warn("Error destroying graphics contexts:",i)}}),this.floorTypeContexts.clear(),this.floorTypeMap.forEach(e=>{try{this.removeChild(e),e.destroy()}catch(i){w.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}const Wn=(n,t)=>n&&t?{x:n.x-t.x,y:n.y-t.y}:null;class uv{constructor(t){f(this,"unsubscribeFns",[]);f(this,"roomInfoContainer",new W);f(this,"roomInfoMap",new Map);f(this,"roomDisplayMap",new Map);f(this,"roomFloorType");this.appService=t,this.roomFloorType=new dv(t),t.appContainer.addToLayer(zc,this.roomInfoContainer);const e=O(t.runtime,"showRoomFloorType",d=>{w.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=O(t.runtime,"showRoomProperty",d=>{w.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=O(t.runtime,"showRoomOrder",d=>{w.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),r=O(t.runtime,"roomPropertyFoldIds",d=>{w.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=O(t.runtime,"showRoomName",d=>{w.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=O(t.runtime,"showRoomType",d=>{w.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=O(t.runtime,"enableRoomSelection",d=>{w.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=O(t.runtime,"selectRoomIds",d=>{w.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=O(t.runtime,"roomSelectionMode",d=>{w.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(e,i,s,r,o,a,h,l,c)}async drawRoomProperty(t){var s;const e=this.appService;this.roomDisplayMap.clear();const i=((s=e.getApp().mapState)==null?void 0:s.origin)??null;return t.forEach((r,o)=>{const a=e.mapManager.getRoomById(r.id),h=(a==null?void 0:a.centerPoint)||null,l={...r,centerPoint:h,relativeCenterPoint:Wn(h,i),index:o,colorIndex:a==null?void 0:a.colorIndex};this.roomDisplayMap.set(r.id,l)}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes(),!0}async updateRoomInfoDisplay(){if(this.roomDisplayMap.size===0){this.appService.mapManager.getAllRooms().length===0&&this.clearRoomInfos();return}const t=Array.from(this.roomDisplayMap.values()).filter(e=>e.centerPoint!==null);this.clearRoomInfos(),await Promise.all(t.map(e=>this.createRoomInfo(e)))}async createRoomInfo(t){const e=new cv(this.appService,t);this.roomInfoContainer.addChild(e),this.roomInfoMap.set(t.id,e),await e.initialize(t)}updateRoomName(t,e){const i=this.roomInfoMap.get(t);i&&i.updateName(e)}async updateRoomType(t,e){const i=this.roomDisplayMap.get(t);i&&(i.type=e);const s=this.roomInfoMap.get(t);s&&await s.updateRoomType(e)}updateRoomPosition(t,e){var r;const i=this.roomDisplayMap.get(t);if(i){i.centerPoint=e;const o=((r=this.appService.getApp().mapState)==null?void 0:r.origin)??null;i.relativeCenterPoint=Wn(e,o)}const s=this.roomInfoMap.get(t);s&&s.updatePosition(e)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const t=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),t.forEach(e=>{try{e.destroy()}catch(i){w.warn(`[RoomManager] Error destroying RoomInfo for room ${e.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(t){return this.roomDisplayMap.get(t)}async refresh(){var i;const t=this.appService;this.roomFloorType.clearFloorTypes();const e=((i=t.getApp().mapState)==null?void 0:i.origin)??null;this.roomDisplayMap.forEach((s,r)=>{const o=t.mapManager.getRoomById(r),a=(o==null?void 0:o.centerPoint)||null;if(s.centerPoint!==a){s.centerPoint=a,s.relativeCenterPoint=Wn(a,e);const l=this.roomInfoMap.get(r);l&&a&&l.updatePosition(a)}const h=o==null?void 0:o.colorIndex;if(s.colorIndex!==h&&h!==void 0){s.colorIndex=h;const l=this.roomInfoMap.get(r);l&&l.refreshColor()}}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes()}async updateAllRoomPropertyVisibility(){this.roomInfoMap.size!==0&&await Promise.all(Array.from(this.roomInfoMap.values()).map(async t=>{try{await t.updateRoomPropertyVisibility()}catch(e){console.warn(`[RoomManager] Failed to update room property visibility for room ${t.roomId}`,e)}}))}updateAllRoomNameVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomNameVisibility(t)})}updateAllRoomTypeVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomTypeVisibility(t)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.refreshColor()})}async updateFloorTypes(){const t=this.appService,e=t.mapManager.roomFill.getRoomGraphicsMap();e.size>0?(await this.roomFloorType.createFloorTypes(e),t.getApp().renderOnceNextFrame()):t.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy()}}var mh,yh;(mh=navigator==null?void 0:navigator.userAgent)!=null&&mh.includes("tuya-ark-ide")||((yh=navigator==null?void 0:navigator.userAgent)==null||yh.includes("miniProgram"));const pv=()=>{var i,s;if(!Fu.any)return!0;const n=navigator.userAgent.toLowerCase(),t=()=>{const r=navigator.deviceMemory;return r?r>=4:!0};let e=!1;if(/iphone|ipad|ipod/.test(n)){const r=(i=n.match(/os (\d+)_/))==null?void 0:i[1];e=(r?parseInt(r):0)>=12}else if(/android/.test(n)){const r=(s=n.match(/android (\d+)/))==null?void 0:s[1];e=(r?parseInt(r):0)>=10}return e&&t()};class fv extends W{constructor(e,i,s){super();f(this,"graphics");f(this,"sprite",null);f(this,"viewportBounds");f(this,"lastConfig",null);f(this,"onImageLoaded");this.label="background",this.viewportBounds=i,this.onImageLoaded=s,this.graphics=new H,this.graphics.label="backgroundGraphics",this.addChild(this.graphics),this.render(e)}async render(e){if(this.lastConfig=e,this.clear(),e.backgroundImage){await this.renderImage(e.backgroundImage,e.backgroundAlpha);return}if(e.backgroundGradient){this.renderGradient(e.backgroundGradient);return}if(e.backgroundColor!==void 0){this.renderSolidColor(e.backgroundColor,e.backgroundAlpha);return}w.warn("[Background] No background configuration provided")}clear(){this.graphics.clear(),this.sprite&&(this.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null)}renderSolidColor(e,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:e,alpha:i}),w.debug("[Background] Rendered solid color background",{color:e,alpha:i})}renderGradient(e){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),e.type==="linear"){const r=e.x0??0,o=e.y0??0,a=e.x1??1,h=e.y1??1,l=new Gt({type:"linear",start:{x:r,y:o},end:{x:a,y:h},colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(l),w.debug("[Background] Rendered linear gradient background",{x0:r,y0:o,x1:a,y1:h,colorStops:e.colorStops.length})}else if(e.type==="radial"){const r=e.cx??.5,o=e.cy??.5,a=e.r??.5,h=new Gt({type:"radial",center:{x:r,y:o},innerRadius:0,outerCenter:{x:r,y:o},outerRadius:a,colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(h),w.debug("[Background] Rendered radial gradient background",{cx:r,cy:o,r:a,colorStops:e.colorStops.length})}}async renderImage(e,i){var s,r,o,a;try{const h=await N.load(e.src);if(!h){w.error("[Background] Failed to load image:",e.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=e.fit||"cover",u=((r=e.position)==null?void 0:r.x)??.5,p=((o=e.position)==null?void 0:o.y)??.5,g=h.width,y=h.height,m=g/y,x=l/c;switch(d){case"fill":this.sprite.width=l,this.sprite.height=c,this.sprite.x=0,this.sprite.y=0;break;case"contain":m>x?(this.sprite.width=l,this.sprite.height=l/m):(this.sprite.height=c,this.sprite.width=c*m),this.sprite.x=(l-this.sprite.width)*u,this.sprite.y=(c-this.sprite.height)*p;break;case"cover":m>x?(this.sprite.height=c,this.sprite.width=c*m):(this.sprite.width=l,this.sprite.height=l/m),this.sprite.x=(l-this.sprite.width)*u,this.sprite.y=(c-this.sprite.height)*p;break;case"none":this.sprite.width=g,this.sprite.height=y,this.sprite.x=(l-g)*u,this.sprite.y=(c-y)*p;break}e.repeat&&w.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),w.debug("[Background] Rendered image background",{src:e.src,fit:d,position:{x:u,y:p},spriteSize:{width:this.sprite.width,height:this.sprite.height}}),this.onImageLoaded&&this.onImageLoaded()}catch(h){w.error("[Background] Error loading background image:",h),(a=this.lastConfig)!=null&&a.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i)}}async update(e){await this.render(e)}async updateViewportBounds(e){this.viewportBounds=e,this.lastConfig&&await this.render(this.lastConfig)}destroy(){this.clear(),super.destroy()}}class gv extends W{constructor(e){super();f(this,"carpetData");f(this,"carpetConfig");f(this,"controlsConfig");f(this,"carpetEvents");f(this,"appService");f(this,"controlFill");f(this,"editableShape");f(this,"clickHandler",null);f(this,"maskContainer",null);f(this,"maskGraphics",null);f(this,"texture",null);f(this,"textureMap",new Map);f(this,"tilingSprite",null);f(this,"initialZonePoints",[]);f(this,"unsubscribeFns",[]);f(this,"resolvedMaxSizeCache",null);f(this,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});f(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(e.global),s=this.controlFill.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});f(this,"handleMove",e=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(h=(a=this.editableShape)==null?void 0:a.getMoveButton())==null?void 0:h.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});f(this,"handleRotationMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleRotationEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleClickRotate",e=>{var i,s;e&&(this.carpetData.points=e,this.drawCarpet()),this.appService.getApp().renderOnce(),(s=(i=this.carpetEvents).onUpdate)==null||s.call(i,this.getCarpetData())});f(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});f(this,"handleScaleMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleMoveHorizontal",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleMoveVertical",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-scale"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.carpetEvents).onRemove)==null||i.call(e,this.carpetData.id)});f(this,"handleClick",()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())});f(this,"handlePointsUpdate",e=>{this.carpetData.points=e,this.drawCarpet()});const{appService:i,carpetData:s,events:r={},textureMap:o}=e;this.appService=i,this.textureMap=o,this.carpetEvents=r,this.controlsConfig=this.getControlsConfig(),this.carpetConfig=this.controlsConfig.carpet,this.processCarpetData(s),this.initializeComponents(),this.createEditControlLayer(),this.setupClickHandler(),this.setupEnableRoomSelectionListener(),this.updateEditState(),this.loadTexture()}getResolvedMaxSize(){const e=this.carpetConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===e)return this.resolvedMaxSizeCache.value;const i=Us(this.carpetConfig.minSize,e,"carpet");return this.resolvedMaxSizeCache={key:e,value:i},i}validateCarpetShape(e){const i=this.getResolvedMaxSize();return this.appService.coords.validateShape(Sc(e),{minSize:ut(this.carpetConfig.minSize),maxSize:i!=null?ut(i):void 0})}processCarpetData(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=this.validateCarpetShape(e.points);this.carpetData={...e,points:s}}else this.carpetData={...e,points:[],shape:e.shape||"rectangle"}}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}isEditingEnabled(){return this.appService.runtimeSnapshot.editingCarpetIds.includes(this.carpetData.id)}isSelected(){return this.appService.runtimeSnapshot.selectedCarpetIds.includes(this.carpetData.id)}shouldShowEditControl(){return this.isEditingEnabled()||this.isSelected()}initializeComponents(){this.maskContainer=this.createMaskContainer(),this.controlFill=this.createControlFill(),this.addChild(this.maskContainer),this.addChild(this.controlFill),this.drawCarpet()}createMaskContainer(){const e=new W;return this.maskGraphics=new H,this.updateMaskShape(),e.addChild(this.maskGraphics),e.mask=this.maskGraphics,e}createControlFill(){const e=this.isEditingEnabled();return new Qr(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:e,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const e=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s=!!e&&!i&&this.carpetConfig.scaleMode==="ratioLocked",r={...In(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...In(this.carpetConfig,["textColor","textPosition","textOffset"]),...In(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!e&&!i&&this.carpetConfig.showRotateButton,showScaleButton:!!e&&!i,showDeleteButton:!!e,showMoveButton:!!e&&!i,showRadialScaleButton:s,iconWrapperFillColor:this.carpetConfig.iconWrapperFillColor,deleteIconWrapperFillColor:this.carpetConfig.deleteIconWrapperFillColor,rotateMode:this.carpetConfig.rotateMode,scaleMode:this.carpetConfig.scaleMode,moveButtonOffset:this.controlsConfig.moveButtonOffset},o=i?this.calculateBoundingRectanglePoints():this.carpetData.points||[];this.editableShape=new Jr({editControls:this.appService.editControlManager});const a=this.getResolvedMaxSize();this.editableShape.attach(this,{id:this.carpetData.id,topology:"quad",layerOptions:{config:r,zonePoints:o,minSize:this.carpetConfig.minSize,maxSize:a??void 0,contentLayer:Ke,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,onClickRotate:this.handleClickRotate,onRotateEnd:this.handleRotationEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleMoveHorizontal:this.handleScaleMoveHorizontal,onScaleMoveVertical:this.handleScaleMoveVertical,onScaleEnd:this.handleScaleEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick,onPointsUpdate:this.handlePointsUpdate}},editingState:{showRotateButton:!i&&this.carpetConfig.showRotateButton,showScaleButton:!i,showDeleteButton:!0,showMoveButton:!i,showBorder:!0,showSizeText:!0,borderStyle:this.carpetConfig.editing,showRadialScaleButton:!i&&this.carpetConfig.scaleMode==="ratioLocked"},idleState:{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new St(this,{onClick:()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const e=O(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(e);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(e){if(e){if(this.eventMode="none",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="none"}}else if(this.eventMode="static",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="static"}}calculateBounds(){const{points:e}=this.carpetData;let i=1/0,s=1/0,r=-1/0,o=-1/0;if(e&&e.length>0)for(const a of e)i=Math.min(i,a.x),s=Math.min(s,a.y),r=Math.max(r,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:r,maxY:o}}calculateBoundingRectanglePoints(){const{points:e}=this.carpetData;if(!e||e.length===0)return[];const{minX:i,minY:s,maxX:r,maxY:o}=Ts(e);return[{x:i,y:s},{x:r,y:s},{x:r,y:o},{x:i,y:o}]}updateMaskShape(){if(!this.maskGraphics)return;this.maskGraphics.clear();const{points:e,shape:i}=this.carpetData;if(!(!e||!Array.isArray(e)||e.length<2)){if(i==="round"){if(e.length<4)return;const r=Oe(e),[o,a,,h]=e,l=tt(o,a),c=tt(o,h),d=Math.atan2(a.y-o.y,a.x-o.x);this.maskGraphics.position.set(r.x,r.y),this.maskGraphics.rotation=d,this.maskGraphics.ellipse(0,0,l/2,c/2)}else{const r=e.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(r),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}loadTexture(){const{opacity:e,scale:i}=this.appService.carpetConfig,{type:s}=this.carpetData;try{this.texture=this.textureMap.get(s)||this.textureMap.get(-1)||null,this.texture&&this.maskContainer&&(this.tilingSprite&&(this.maskContainer.removeChild(this.tilingSprite),this.tilingSprite.destroy(),this.tilingSprite=null),this.createTilingSprite(i,e),this.appService.getApp().renderOnce())}catch(r){console.warn("Failed to load carpet texture:",r)}}createTilingSprite(e,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new Ms({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(e),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const e=this.calculateBounds();this.tilingSprite.position.set(e.minX-50,e.minY-50),this.tilingSprite.width=e.maxX-e.minX+100,this.tilingSprite.height=e.maxY-e.minY+100}applyTranslation(e,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:e}=this.carpetData;if(!(!e||e.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(e),this.editableShape)){const r=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():e;this.editableShape.updatePoints(r)}}updateEditState(){const e=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();this.controlFill.setInteractionEnabled(e),this.editableShape&&(i&&!e?this.editableShape.applyEditState({showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!0,showSizeText:!1,borderStyle:this.carpetConfig.normal}):this.editableShape.setEditing(e)),this.zIndex=s?1e3:0}refreshConfig(){this.controlsConfig=this.getControlsConfig(),this.carpetConfig=this.controlsConfig.carpet,this.resolvedMaxSizeCache=null,this.controlFill.updateFillColor(this.carpetConfig.fillColor),this.editableShape.detach(),this.createEditControlLayer(),this.drawCarpet(),this.updateEditState()}updateCarpetData(e){const s=this.carpetData.type;if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const r=this.validateCarpetShape(e.points);this.carpetData={...e,points:r}}else this.carpetData={...e,points:e.points||[]};s!==this.carpetData.type&&this.loadTexture(),this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var e,i,s,r,o;this.editableShape.detach(),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(e=this.tilingSprite)==null||e.destroy(),(i=this.maskGraphics)==null||i.destroy(),(s=this.maskContainer)==null||s.destroy(),this.tilingSprite=null,this.maskGraphics=null,this.maskContainer=null,this.texture=null,(r=this.controlFill)==null||r.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class mv{constructor(t){f(this,"customCarpetMap",new Map);f(this,"unsubscribeFns",[]);f(this,"textureMap",new Map);f(this,"texturesLoaded",!1);f(this,"texturesLoadingPromise",null);this.appService=t,this.applyLayerVisibility(t.runtime.showCustomCarpets);const e=O(t.runtime,"editingCarpetIds",r=>{w.log(`[runtime] editingCarpetIds: ${r}`),this.updateCarpetsEditState()}),i=O(t.runtime,"selectedCarpetIds",r=>{w.log(`[runtime] selectedCarpetIds: ${r}`),this.updateCarpetsEditState()}),s=O(t.runtime,"showCustomCarpets",r=>{w.log(`[runtime] showCustomCarpets: ${r}`),this.applyLayerVisibility(r)});this.unsubscribeFns.push(e,i,s)}async loadTextures(){if(!this.texturesLoaded){if(this.texturesLoadingPromise)return this.texturesLoadingPromise;this.texturesLoadingPromise=this._loadTextures(),await this.texturesLoadingPromise,this.texturesLoaded=!0,this.texturesLoadingPromise=null}}async _loadTextures(){const t=this.appService,{material:e,src:i}=t.carpetConfig;if(e)for(const s of e){const r=await N.load(s.src);this.textureMap.set(s.type,r)}if(i){const s=await N.load(i);this.textureMap.set(-1,s)}}async drawCustomCarpets(t){if(await this.loadTextures(),!t||t.length===0){this.clearAllCustomCarpets();return}const e=new Set(this.customCarpetMap.keys()),i=new Set(t.map(s=>s.id));for(const s of e)i.has(s)||this.removeCustomCarpet(s);t.forEach(s=>{const r=this.customCarpetMap.get(s.id.toString());r?this.isCarpetDataEqual(r.getCarpetData(),s)||r.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const t=[];return this.customCarpetMap.forEach(e=>{t.push(e.getCarpetData())}),t}getCustomCarpetById(t){return this.customCarpetMap.get(t)}clearAllCustomCarpets(){this.customCarpetMap.forEach((t,e)=>{var s;const i=this.customCarpetMap.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(t){const e=this.appService,i=new gv({appService:e,carpetData:t,textureMap:this.textureMap,events:{onRemove:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onDeleteCustomCarpet)==null||o.call(r,{id:s})},onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdateCustomCarpet)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickCarpet)==null||o.call(r,{id:s.id})}}});this.customCarpetMap.set(t.id.toString(),i),e.appContainer.addToLayer(Ke,i)}removeCustomCarpet(t){const e=this.appService,i=this.customCarpetMap.get(t);i&&(e.appContainer.removeFromLayer(Ke,i),i.destroy(),this.customCarpetMap.delete(t))}updateCarpetsEditState(){this.customCarpetMap.forEach(t=>{t.updateEditState()})}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(Ke);e&&(e.visible=t)}isCarpetDataEqual(t,e){if(t.id!==e.id||t.type!==e.type||t.shape!==e.shape)return!1;const i=t.points||[],s=e.points||[];if(i.length!==s.length)return!1;for(let r=0;r<i.length;r++){const o=i[r],a=s[r];if(Math.abs(o.x-a.x)>.1||Math.abs(o.y-a.y)>.1)return!1}return!0}refreshDisplay(){this.customCarpetMap.forEach(t=>{t.refreshDisplay()})}refreshConfig(){this.customCarpetMap.forEach(t=>{t.refreshConfig()})}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearAllCustomCarpets()}}function yv(n,t){return{coords:n.coords,editControls:n.editControlManager,furnitureConfig:n.furnitureConfig,controlsConfig:n.controlsConfig,gestures:n.gestureController,render:{request:e=>n.getApp().requestRender(e,!0),stop:e=>n.getApp().stopRender(e),once:e=>n.getApp().requestRender(e,!1)},events:t}}const ph="furniture-drag",fh="furniture-scale",gh="furniture-move",Gn="furniture-rotate";class xv extends W{constructor(e){super();f(this,"deps");f(this,"config");f(this,"controlsConfig");f(this,"furnitureEvents");f(this,"data");f(this,"textureAlias");f(this,"sprite");f(this,"editableShape");f(this,"editing",!1);f(this,"clickHandler",null);f(this,"dragStartPosition",null);f(this,"initialPoints",[]);f(this,"isDragging",!1);f(this,"gestureSession",null);f(this,"originalSizeMeters",null);f(this,"resolveSizeConstraintPerEdge",()=>{var o,a;const{minScaleRatio:e,maxScaleRatio:i}=this.config,s=i===1/0||i==null?void 0:i,r=h=>{if(!h||h<=0)return{min:.1,max:void 0};const l=h*(e||0);return{min:l>0?l:.1,max:s!=null?h*s:void 0}};return{edge1:r((o=this.originalSizeMeters)==null?void 0:o.width),edge2:r((a=this.originalSizeMeters)==null?void 0:a.height)}});f(this,"onDragStart",e=>{if(!this.editing||!this.parent||e.target!==this&&e.target!==this.sprite)return;e.stopPropagation();const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(s=>({...s})),this.isDragging=!1,this.gestureSession=this.deps.gestures.hijack(e),this.gestureSession.onMove(this.onDragMove),this.gestureSession.onEnd(this.onDragEnd)});f(this,"onDragMove",e=>{if(!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(r)<3||(this.isDragging||(this.isDragging=!0,this.deps.render.request(ph)),this.data.points=this.initialPoints.map(o=>({x:o.x+s,y:o.y+r})),this.redraw())});f(this,"onDragEnd",()=>{var e,i;this.gestureSession=null,this.dragStartPosition&&(this.isDragging&&((i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData()),this.deps.render.stop(ph)),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});f(this,"handleRotateStart",()=>{this.deps.render.request(Gn)});f(this,"handleRotateMove",e=>{e&&(this.data.points=e,this.redraw())});f(this,"handleTapRotate",e=>{var i,s;e&&(this.data.points=e,this.redraw()),this.captureOriginalSize(),this.deps.render.once(Gn),(s=(i=this.furnitureEvents).onUpdate)==null||s.call(i,this.getData())});f(this,"handleScaleStart",()=>{this.deps.render.request(fh)});f(this,"handleScaleMove",e=>{e&&(this.data.points=e,this.redraw())});f(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(e=>({...e})),this.deps.render.request(gh)});f(this,"handleMove",e=>{var a;if(!this.editing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(e.global),s=(a=this.editableShape.getMoveButton())==null?void 0:a.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.data.points=this.initialPoints.map(h=>({x:h.x+r,y:h.y+o})),this.redraw()});f(this,"handleMoveEnd",()=>{var e,i;this.initialPoints=[],this.deps.render.stop(gh),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});f(this,"handleTransformEnd",()=>{var e,i;this.deps.render.stop(Gn),this.deps.render.stop(fh),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.furnitureEvents).onRemove)==null||i.call(e,this.data.id)});f(this,"handleClick",()=>{var e,i;this.editing||(i=(e=this.furnitureEvents).onClick)==null||i.call(e,this.getData())});const{deps:i,data:s,textureAlias:r}=e;this.deps=i,this.config=i.furnitureConfig,this.controlsConfig=i.controlsConfig,this.furnitureEvents=i.events,this.data={...s,points:s.points.map(o=>({...o}))},this.textureAlias=r,this.captureOriginalSize(),this.createSprite(),this.updateSpriteTransform(),this.createEditControlLayer(),this.eventMode="static",this.cursor="pointer",this.setupInteraction(),this.applyEditing()}captureOriginalSize(){const e=this.data.points;if(e.length<4){this.originalSizeMeters=null;return}const i=tt(e[0],e[1]),s=tt(e[1],e[2]);this.originalSizeMeters={width:this.deps.coords.toMeters(Bt(i)),height:this.deps.coords.toMeters(Bt(s))}}createSprite(){const e=N.get(this.textureAlias);this.sprite=new jt(e),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="passive",this.addChild(this.sprite)}updateSpriteTransform(){const e=this.data.points;if(e.length<4)return;const i=Oe(e),s=e[1].x-e[0].x,r=e[1].y-e[0].y,o=Math.atan2(r,s),a=tt(e[0],e[1]),h=tt(e[1],e[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControlLayer(){const e={outlineStrokeColor:String(this.config.outlineStrokeColor),outlineStrokeWidth:this.config.outlineStrokeWidth,outlineDashed:this.config.outlineDashed,outlineDashArray:this.config.outlineDashArray,outlineFillColor:this.config.outlineFillColor?String(this.config.outlineFillColor):void 0,outlineOffset:this.config.outlineOffset,iconWrapperFillColor:String(this.config.iconWrapperFillColor),showRotateButton:!0,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,rotateMode:"step",stepRotateAngle:this.config.rotateDirection==="ccw"?-Math.PI/2:Math.PI/2,scaleMode:this.config.lockAspectRatio?"ratioLocked":"free",textColor:String(this.config.textColor),textPosition:this.config.textPosition,textOffset:this.config.textOffset,moveButtonOffset:this.controlsConfig.moveButtonOffset,textFontSize:this.controlsConfig.textFontSize,textFontFamily:this.controlsConfig.textFontFamily,textFontWeight:this.controlsConfig.textFontWeight};this.editableShape=new Jr({editControls:this.deps.editControls});const i={config:e,zonePoints:this.data.points,sizeConstraintPerEdge:this.resolveSizeConstraintPerEdge,contentLayer:Te,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotateStart,onRotateMove:this.handleRotateMove,onClickRotate:this.handleTapRotate,onRotateEnd:this.handleTransformEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleTransformEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick}};this.editableShape.attach(this,{id:this.data.id,topology:"quad",layerOptions:i,editingState:{showRotateButton:!0,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,showBorder:!0,showSizeText:this.config.showSizeText},idleState:{showRotateButton:!1,showScaleButton:!1,showRadialScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}setupInteraction(){this.clickHandler=new St(this,{onClick:e=>{!this.isDragging&&((e==null?void 0:e.target)===this||(e==null?void 0:e.target)===this.sprite)&&this.handleClick()}}),this.on("pointerdown",this.onDragStart,this)}redraw(){this.data.points.length<4||(this.updateSpriteTransform(),this.editableShape.updatePoints(this.data.points))}applyEditing(){this.editableShape.setEditing(this.editing),this.zIndex=this.editing?1e3:0}updateEditState(e){this.editing!==e&&(this.editing=e,this.applyEditing())}isEditing(){return this.editing}getData(){return{id:this.data.id,furnitureType:this.data.furnitureType,points:this.data.points.map(e=>({...e}))}}updateData(e){this.data={...e,points:e.points.map(i=>({...i}))},this.captureOriginalSize(),this.data.points.length>=4&&(this.updateSpriteTransform(),this.editableShape.updatePoints(this.data.points))}destroy(){var e,i,s;(e=this.editableShape)==null||e.detach(),(i=this.gestureSession)==null||i.cancel(),this.gestureSession=null,(s=this.clickHandler)==null||s.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class Sv{constructor(t){f(this,"furnitureMap",new Map);f(this,"unsubscribeFns",[]);this.appService=t,this.applyLayerVisibility(t.runtime.showFurnitures);const e=O(t.runtime,"editingFurnitureIds",s=>{w.log(`[runtime] editingFurnitureIds: ${s}`),this.updateEditState()}),i=O(t.runtime,"showFurnitures",s=>{w.log(`[runtime] showFurnitures: ${s}`),this.applyLayerVisibility(s)});this.unsubscribeFns.push(e,i)}async drawFurnitures(t){if(!t||t.length===0){this.clearAll();return}const e=new Set(this.furnitureMap.keys()),i=new Set(t.map(r=>r.id));for(const r of e)i.has(r)||this.removeFurniture(r);const s=[];for(const r of t){const o=this.furnitureMap.get(r.id);o?this.isDataEqual(o.getData(),r)||o.updateData(r):s.push(this.addFurniture(r))}await Promise.all(s)}async addFurniture(t){const e=this.appService;if(!e.furnitureConfig.assets.find(l=>l.type===t.furnitureType)){w.warn(`[FurnitureManager] No asset found for furnitureType: ${t.furnitureType}`);return}const r=`furniture_${t.furnitureType}`;await N.load(r);const o=yv(e,{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveFurniture)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateFurniture)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickFurniture)==null||d.call(c,l)}}),a=new xv({deps:o,data:t,textureAlias:r});this.furnitureMap.set(t.id,a),e.appContainer.addToLayer(Te,a),e.runtime.editingFurnitureIds.includes(t.id)&&(a.updateEditState(!0),this.moveToEditLayer(a))}removeFurniture(t){var i;const e=this.furnitureMap.get(t);e&&((i=e.parent)==null||i.removeChild(e),e.destroy(),this.furnitureMap.delete(t))}clearAll(){var t;for(const[,e]of this.furnitureMap)(t=e.parent)==null||t.removeChild(e),e.destroy();this.furnitureMap.clear()}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(Te);e&&(e.visible=t),this.furnitureMap.forEach(i=>{i.visible=t})}updateEditState(){const t=this.appService.runtime.editingFurnitureIds,{appContainer:e}=this.appService,i=e.getLayer(Te);this.furnitureMap.forEach((s,r)=>{const o=t.includes(r);s.updateEditState(o),o?this.moveToEditLayer(s):s.parent!==i&&this.moveToFurnitureLayer(s)})}moveToEditLayer(t){var e;(e=t.parent)==null||e.removeChild(t),this.appService.appContainer.addToLayer(Ee,t)}moveToFurnitureLayer(t){var e;(e=t.parent)==null||e.removeChild(t),this.appService.appContainer.addToLayer(Te,t)}getFurnitures(){const t=[];return this.furnitureMap.forEach(e=>{t.push(e.getData())}),t}isDataEqual(t,e){if(t.id!==e.id||t.furnitureType!==e.furnitureType||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++)if(Math.abs(t.points[i].x-e.points[i].x)>.1||Math.abs(t.points[i].y-e.points[i].y)>.1)return!1;return!0}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearAll()}}class vv{constructor(t){f(this,"editControlLayers",new Map);this.appService=t}registerEditControl(t,e){const i=this.appService;this.editControlLayers.has(t)&&this.unregisterEditControl(t);const s=new _S(i,e);if(!i.appContainer.addToLayer(Ee,s))throw w.warn(`[EditControlManager] Failed to add edit control layer for id: ${t}`),s.destroy(),new Error(`Failed to register edit control for id: ${t}`);if(this.editControlLayers.set(t,s),e.contentLayer){const o=i.appContainer.getLayer(Ee),a=i.appContainer.getLayer(e.contentLayer);o&&a&&(o.position.x!==a.position.x||o.position.y!==a.position.y)&&w.warn(`[EditControlManager] Edit layer position does not match content layer "${e.contentLayer}" position — edit controls will appear misaligned. Ensure "${e.contentLayer}" is in ORIGIN_TRACKED_LAYERS.`,{edit:o.position,content:a.position})}return s}unregisterEditControl(t){const e=this.editControlLayers.get(t);if(!e)return;this.appService.appContainer.removeFromLayer(Ee,e),e.destroy(),this.editControlLayers.delete(t)}getEditControl(t){return this.editControlLayers.get(t)}updateEditState(t,e){const i=this.editControlLayers.get(t);i&&i.updateEditState(e)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(e=>this.unregisterEditControl(e))}getAllEditControls(){return Array.from(this.editControlLayers.values())}hasEditControl(t){return this.editControlLayers.has(t)}}function fs(n){return n.charAt(0).toUpperCase()+n.slice(1)}const Di=class Di extends bl{constructor(e=po){super();f(this,"mapState",null);f(this,"components",{});f(this,"managers",{});f(this,"config",uo);f(this,"runtime");f(this,"appService");f(this,"coords");f(this,"scaleMin",.5);f(this,"scaleMax",5);f(this,"events",{});f(this,"instanceKey");f(this,"debugInstanceId");f(this,"previousLoggerRuntimeState",null);f(this,"isDestroying",!1);f(this,"hasActiveContextLoss",!1);f(this,"createdAtMs",Date.now());f(this,"lastMapDataAtMs",null);f(this,"lastMapDrawAtMs",null);f(this,"lastPathDataAtMs",null);f(this,"lastVisibilityChangeAtMs",null);f(this,"containerElement");f(this,"onWebGLContextLost",e=>{var r;const i=e;if((r=i.preventDefault)==null||r.call(i),this.hasActiveContextLoss)return;this.hasActiveContextLoss=!0;const s=this.getContextLossDiagnostics(e);w.error("[Pixi] WebGL context lost",s.summary),w.error("[Pixi] WebGL context lost tail",s.recentLifecycleTail),this.recordDebugLifecycleEvent("webglcontextlost",{eventType:e.type,statusMessage:i.statusMessage??null})});f(this,"onWebGLContextRestored",e=>{this.hasActiveContextLoss=!1,w.warn("[Pixi] WebGL context restored, scheduling render",this.getRendererDiagnostics({eventType:e.type})),this.recordDebugLifecycleEvent("webglcontextrestored",{eventType:e.type}),this.renderOnceNextFrame()});f(this,"emitter",Nx());f(this,"tickerState",{renderReasons:new Set,renderTimer:null,lastRequestReason:null,lastStopReason:null});f(this,"customCarpetResolvedMaxSizeCache",null);f(this,"pendingAsyncRender",!1);f(this,"isFirstMapDraw",!0);f(this,"isMapDrawn",!1);f(this,"onVisibilityChange",()=>{var i;this.lastVisibilityChangeAtMs=Date.now(),document.visibilityState==="visible"||(i=this.components.interaction)==null||i.clearTouches()});f(this,"onRendererResize",()=>{var e,i;this.isDestroying||((e=this.components.viewportContainer)==null||e.updateViewport(this.config),(i=this.components.background)==null||i.updateViewportBounds(this.getViewportBounds()),this.renderOnceNextFrame())});this.instanceKey=e,this.debugInstanceId=hh(),this.coords=new nS(()=>{var i;return((i=this.runtime)==null?void 0:i.unit)??"meter"}),this.appService=new Rc(this),globalThis.__PIXI_APP__=this,this.recordDebugLifecycleEvent("app:create",{instanceKey:e})}getRendererDiagnostics(e={}){var r,o,a,h,l,c,d,u,p,g,y;const i=this.containerElement&&"getBoundingClientRect"in this.containerElement&&typeof this.containerElement.getBoundingClientRect=="function"?this.containerElement.getBoundingClientRect():null,s=((r=this.renderer)==null?void 0:r.type)===te.WEBGPU?"webgpu":((o=this.renderer)==null?void 0:o.type)===te.WEBGL?"webgl":"unknown";return{sessionId:zn().getSessionId(),instanceId:this.debugInstanceId,requestedPreference:this.config.global.rendererPreference,rendererType:s,rendererWidth:((a=this.renderer)==null?void 0:a.width)??null,rendererHeight:((h=this.renderer)==null?void 0:h.height)??null,canvasWidth:((l=this.canvas)==null?void 0:l.width)??null,canvasHeight:((c=this.canvas)==null?void 0:c.height)??null,canvasClientWidth:((d=this.canvas)==null?void 0:d.clientWidth)??null,canvasClientHeight:((u=this.canvas)==null?void 0:u.clientHeight)??null,containerWidth:(i==null?void 0:i.width)??null,containerHeight:(i==null?void 0:i.height)??null,mapId:((p=this.mapState)==null?void 0:p.id)??null,mapWidth:((g=this.mapState)==null?void 0:g.width)??null,mapHeight:((y=this.mapState)==null?void 0:y.height)??null,isMapDrawn:this.isMapDrawn,visibilityState:document.visibilityState,...e}}getElapsedMsSince(e){return typeof e=="number"?Math.max(0,Date.now()-e):null}getDeviceDiagnostics(){const e=globalThis.navigator;return{devicePixelRatio:globalThis.devicePixelRatio??null,userAgent:(e==null?void 0:e.userAgent)??null,hardwareConcurrency:(e==null?void 0:e.hardwareConcurrency)??null,deviceMemory:(e==null?void 0:e.deviceMemory)??null,documentWasDiscarded:"wasDiscarded"in document?document.wasDiscarded:null}}getWebGLDiagnostics(){var r;const e=(r=this.renderer)==null?void 0:r.gl;if(!e)return{contextAttributes:null,isContextLost:null,drawingBufferWidth:null,drawingBufferHeight:null,vendor:null,renderer:null,version:null,shadingLanguageVersion:null,maxTextureSize:null,maxRenderbufferSize:null};const i=o=>{if(typeof o!="number"||typeof e.getParameter!="function")return null;try{return e.getParameter(o)??null}catch{return null}},s=typeof e.getExtension=="function"?e.getExtension("WEBGL_debug_renderer_info"):null;return{contextAttributes:typeof e.getContextAttributes=="function"?e.getContextAttributes()??null:null,isContextLost:typeof e.isContextLost=="function"?e.isContextLost():null,drawingBufferWidth:e.drawingBufferWidth??null,drawingBufferHeight:e.drawingBufferHeight??null,vendor:s&&typeof s.UNMASKED_VENDOR_WEBGL=="number"?i(s.UNMASKED_VENDOR_WEBGL):null,renderer:s&&typeof s.UNMASKED_RENDERER_WEBGL=="number"?i(s.UNMASKED_RENDERER_WEBGL):null,version:i(e.VERSION),shadingLanguageVersion:i(e.SHADING_LANGUAGE_VERSION),maxTextureSize:i(e.MAX_TEXTURE_SIZE),maxRenderbufferSize:i(e.MAX_RENDERBUFFER_SIZE)}}getRecentLifecycleTail(){return zn().readCurrentSession().slice(-Di.CONTEXT_LOSS_TAIL_SIZE).map(e=>({seq:e.seq,ts:e.ts,event:e.event,sessionId:e.sessionId,instanceId:e.instanceId??null,visibilityState:e.visibilityState??null,rendererType:e.rendererType??null,mapId:e.mapId??null,detail:e.detail}))}getContextLossDiagnostics(e){const i=e;return{summary:this.getRendererDiagnostics({eventType:e.type,statusMessage:i.statusMessage??null,uptimeMs:this.getElapsedMsSince(this.createdAtMs),timeSinceLastMapDataMs:this.getElapsedMsSince(this.lastMapDataAtMs),timeSinceLastMapDrawMs:this.getElapsedMsSince(this.lastMapDrawAtMs),timeSinceLastPathDataMs:this.getElapsedMsSince(this.lastPathDataAtMs),timeSinceLastVisibilityChangeMs:this.getElapsedMsSince(this.lastVisibilityChangeAtMs),device:this.getDeviceDiagnostics(),webgl:this.getWebGLDiagnostics()}),recentLifecycleTail:this.getRecentLifecycleTail()}}attachRendererDiagnostics(){var e,i;if(((e=this.renderer)==null?void 0:e.type)!==te.WEBGL||typeof((i=this.canvas)==null?void 0:i.addEventListener)!="function"){w.debug("[Pixi] Renderer diagnostics initialized",this.getRendererDiagnostics({contextListeners:!1}));return}this.canvas.addEventListener("webglcontextlost",this.onWebGLContextLost),this.canvas.addEventListener("webglcontextrestored",this.onWebGLContextRestored),w.debug("[Pixi] Renderer diagnostics initialized",this.getRendererDiagnostics({contextListeners:!0}))}detachRendererDiagnostics(){var e;typeof((e=this.canvas)==null?void 0:e.removeEventListener)=="function"&&(this.canvas.removeEventListener("webglcontextlost",this.onWebGLContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onWebGLContextRestored))}getDebugRendererType(){var e,i;return((e=this.renderer)==null?void 0:e.type)===te.WEBGPU?"webgpu":((i=this.renderer)==null?void 0:i.type)===te.WEBGL?"webgl":"unknown"}recordDebugLifecycleEvent(e,i){var s;zn().record({event:e,instanceId:this.debugInstanceId,visibilityState:typeof document<"u"?document.visibilityState:null,rendererType:this.getDebugRendererType(),mapId:((s=this.mapState)==null?void 0:s.id)??null,detail:i})}async initialize(e){const{resizeTo:i,events:s,config:r,runtime:o={},...a}=e;this.config=mr(Na({},uo,r??{},(g,y)=>{if(Array.isArray(y))return y})),this.validateCustomZoneTypes(this.config),this.previousLoggerRuntimeState=nx(),sx({getLoggerConfig:()=>this.config.logger,getLegacyEnabled:()=>this.config.global.enableLogger}),w.log("Applying config",this.config,r),this.runtime=mr(Object.assign({},Pd,o));const h=this.instanceKey===po;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={gcActive:!1,autoStart:!1,sharedTicker:c,eventFeatures:{move:l,globalMove:!1,click:l,wheel:l}},u={resizeTo:h?i:void 0,resolution:this.config.global.resolution,antialias:c?!1:pv(),depth:!c,autoDensity:!0,backgroundColor:0,backgroundAlpha:0,...d,...a},p=this.config.global.rendererPreference;if(p==="webgpu")try{await this.init({...u,preference:"webgpu"})}catch(g){w.warn("[Pixi] WebGPU initialization failed, falling back to WebGL:",g),await this.init({...u,preference:"webgl"})}else await this.init({...u,preference:p});this.attachRendererDiagnostics(),this.recordDebugLifecycleEvent("app:initialized",{isMainInstance:h,isPerformanceMode:c,requestedPreference:p}),w.debug("[Pixi] Renderer initialized",this.getRendererDiagnostics({isMainInstance:h,isPerformanceMode:c})),this.preloadAssets(),this.scaleMax=this.config.interaction.zoomRange.max,this.scaleMin=this.config.interaction.zoomRange.min,this.events=s,this.initializeViewportContainer(),this.initializeInteraction(),this.initializeAppContainer(),this.renderer.on("resize",this.onRendererResize),this.managers.mapManager=new fS(this.appService),this.managers.heatmapManager=new bS(this.appService),this.managers.pathManager=new SS(this.appService),this.managers.controlsManager=new IS(this.appService),this.managers.detectedObjectManager=new FS(this.appService),this.managers.customElementsManager=new ov(this.appService),this.managers.roomsManager=new uv(this.appService),this.managers.customCarpetManager=new mv(this.appService),this.managers.furnitureManager=new Sv(this.appService),this.managers.editControlManager=new vv(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(e){var a,h,l,c,d,u,p;this.lastMapDataAtMs=Date.now(),this.isMapDrawn=!1,w.log("[Map] drawMap",e);const{size:i,resolution:s,origin:r,id:o}=e;((a=this.mapState)==null?void 0:a.id)!==void 0&&this.mapState.id!==o&&this.managers.pathManager.clear(),(r[0]!==((h=this.mapState)==null?void 0:h.origin.x)||r[1]!==((l=this.mapState)==null?void 0:l.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(...r),this.managers.pathManager.updatePositionByOrigin(...r),this.managers.heatmapManager.updatePositionByOrigin(...r)),this.mapState={id:e.id,status:e.status===1,origin:{x:r[0],y:r[1]},charger:{x:e.charger.coordinate[0],y:e.charger.coordinate[1]},chargerDirection:e.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},this.coords.setResolution(s),w.debug("[Map] Structured map state updated",{mapId:o,mapWidth:i[0],mapHeight:i[1],mapResolution:s,mapStatus:e.status===1,originX:r[0],originY:r[1]}),this.isFirstMapDraw&&(this.isFirstMapDraw=!1,(d=(c=this.events)==null?void 0:c.onMapFirstDrawed)==null||d.call(c,this.mapState)),(p=(u=this.events)==null?void 0:u.onMapDrawed)==null||p.call(u,this.mapState),this.emitter.emit("mapStateUpdate",this.mapState),await this.managers.mapManager.drawMap(e),i[0]===0||i[1]===0?(w.warn("[Map] Structured map cleared by incoming data",this.getRendererDiagnostics({mapId:o,mapWidth:i[0],mapHeight:i[1],mapResolution:s,mapStatus:e.status===1,originX:r[0],originY:r[1]})),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.lastMapDrawAtMs=Date.now(),this.managers.heatmapManager.onMapLoaded()),this.emitRoomsDrawed(),this.renderOnce()}async drawRasterMap(e){var a,h,l,c,d,u;this.lastMapDataAtMs=Date.now(),this.isMapDrawn=!1,w.log("[Map] drawRasterMap",e);const{mapHeader:i,mapData:s}=e,{originX:r,originY:o}=i;(r!==((a=this.mapState)==null?void 0:a.origin.x)||o!==((h=this.mapState)==null?void 0:h.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(r,o),this.managers.pathManager.updatePositionByOrigin(r,o),this.managers.heatmapManager.updatePositionByOrigin(r,o)),this.mapState={id:i.id,status:i.mapStable,origin:{x:r,y:o},charger:{x:i.chargeX,y:i.chargeY},chargerDirection:i.chargeDirection??0,resolution:i.mapResolution*100,width:i.mapWidth,height:i.mapHeight,version:i.version,mapType:"raster"},this.coords.setResolution(i.mapResolution*100),w.debug("[Map] Raster map state updated",{mapId:i.id,mapWidth:i.mapWidth,mapHeight:i.mapHeight,mapResolution:i.mapResolution*100,mapStatus:i.mapStable,originX:r,originY:o,version:i.version??null}),this.isFirstMapDraw&&(this.isFirstMapDraw=!1,(c=(l=this.events)==null?void 0:l.onMapFirstDrawed)==null||c.call(l,this.mapState)),(u=(d=this.events)==null?void 0:d.onMapDrawed)==null||u.call(d,this.mapState),this.emitter.emit("mapStateUpdate",this.mapState),await this.managers.mapManager.drawRasterMap(s.parsed,this.mapState),i.mapWidth===0||i.mapHeight===0?(w.warn("[Map] Raster map cleared by incoming data",this.getRendererDiagnostics({mapId:i.id,mapWidth:i.mapWidth,mapHeight:i.mapHeight,mapResolution:i.mapResolution*100,mapStatus:i.mapStable,originX:r,originY:o,version:i.version??null})),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.lastMapDrawAtMs=Date.now(),this.managers.heatmapManager.onMapLoaded()),this.emitRoomsDrawed(),this.renderOnce()}emitRoomsDrawed(){var r,o;const e=(r=this.events)==null?void 0:r.onRoomsDrawed;if(!e)return;const i=((o=this.mapState)==null?void 0:o.origin)??{x:0,y:0},s=this.managers.mapManager.getAllRooms().map(a=>({id:a.id,centerPoint:a.centerPoint,relativeCenterPoint:{x:a.centerPoint.x-i.x,y:a.centerPoint.y-i.y}}));e(s)}drawPath(e){var i,s;this.lastPathDataAtMs=Date.now(),w.log("[Path] drawPath",e),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:e.pathHeader.pathId,type:e.pathHeader.type,direction:e.pathHeader.direction,count:e.pathHeader.count,initFlag:e.pathHeader.initFlag,robotPosition:e.pathPoints[e.pathPoints.length-1]??null}),this.managers.pathManager.draw(e),this.renderOnce()}async drawRoomProperty(e){var i,s;w.log("[Room] drawRoomProperty",e),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,e),await this.managers.roomsManager.drawRoomProperty(e),this.renderOnceNextFrame()}async drawCustomCarpets(e){w.log("[CustomCarpets] drawCustomCarpets",e),await this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawFurnitures(e){w.log("[Furniture] drawFurnitures",e),await this.managers.furnitureManager.drawFurnitures(e),this.renderOnceNextFrame()}drawHeatmap(e){w.log("[Heatmap] drawHeatmap",e),this.managers.heatmapManager.draw(e),this.renderOnce()}drawForbiddenSweepZones(e){w.log("[Controls] drawForbiddenSweepZones",e),this.managers.controlsManager.drawForbiddenSweepZones(e),this.renderOnceNextFrame()}drawForbiddenMopZones(e){w.log("[Controls] drawForbiddenMopZones",e),this.managers.controlsManager.drawForbiddenMopZones(e),this.renderOnceNextFrame()}drawCleanZones(e){w.log("[Controls] drawCleanZones",e),this.managers.controlsManager.drawCleanZones(e),this.renderOnceNextFrame()}drawCustomZones(e,i){if($e(e)){w.warn(`[MapApplication] drawCustomZones: '${e}' is a built-in type; use draw${fs(e)}s() instead`);return}w.log("[Controls] drawCustomZones",e,i),this.managers.controlsManager.drawCustomZones(e,i),this.renderOnceNextFrame()}getCustomZones(e){return $e(e)?(w.warn(`[MapApplication] getCustomZones: '${e}' is a built-in type; use get${fs(e)}s() instead`),[]):this.managers.controlsManager.getCustomZones(e)}clearCustomZones(e){if($e(e)){w.warn(`[MapApplication] clearCustomZones: '${e}' is a built-in type; use clearAll${fs(e)}s() instead`);return}w.log("[Controls] clearCustomZones",e),this.managers.controlsManager.clearCustomZones(e),this.renderOnceNextFrame()}setEditingCustomZones(e,i){if($e(e)){w.warn(`[MapApplication] setEditingCustomZones: '${e}' is a built-in type; use runtime.editing${fs(e)}Ids instead`);return}this.runtime.editingCustomZoneIds={...this.runtime.editingCustomZoneIds??{},[e]:[...i]}}drawVirtualWalls(e){w.log("[Controls] drawVirtualWalls",e),this.managers.controlsManager.drawVirtualWalls(e),this.renderOnceNextFrame()}drawSpots(e){w.log("[Controls] drawSpots",e),this.managers.controlsManager.drawSpots(e),this.renderOnceNextFrame()}drawPurifyPoints(e){w.log("[Controls] drawPurifyPoints",e),this.managers.controlsManager.drawPurifyPoints(e),this.renderOnceNextFrame()}drawWayPoints(e){w.log("[Controls] drawWayPoints",e),this.managers.controlsManager.drawWayPoints(e),this.renderOnceNextFrame()}async drawDetectedObjects(e){w.log("[DetectedObject] drawDetectedObjects",e),await this.managers.detectedObjectManager.drawDetectedObjects(e),this.renderOnceNextFrame()}drawCustomCarpet(e){w.log("[CustomCarpet] drawCustomCarpet",e),this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawCustomElements(e){w.log("[CustomElements] drawCustomElements",e),await this.managers.customElementsManager.drawCustomElements(e),this.renderOnceNextFrame()}getForbiddenSweepZones(){return this.managers.controlsManager.getForbiddenSweepZones()}getForbiddenMopZones(){return this.managers.controlsManager.getForbiddenMopZones()}getCleanZones(){return this.managers.controlsManager.getCleanZones()}getVirtualWalls(){return this.managers.controlsManager.getVirtualWalls()}getSpots(){return this.managers.controlsManager.getSpots()}getPurifyPoints(){return this.managers.controlsManager.getPurifyPoints()}clearAllPurifyPoints(){this.managers.controlsManager.clearAllPurifyPoints(),this.renderOnceNextFrame()}getWayPoints(){return this.managers.controlsManager.getWayPoints()}getEffectiveDividerPoints(){return this.managers.controlsManager.getEffectiveDividerPoints()}getCustomCarpets(){return this.managers.customCarpetManager.getCustomCarpets()}getFurnitures(){return this.managers.furnitureManager.getFurnitures()}getDividerEndPoints(){return this.managers.controlsManager.getDividerEndPoints()}resetPanZoom(){this.components.interaction.setPanZoom()}forceEndGesture(){w.log("[Map] forceEndGesture"),this.components.interaction.forceEndGesture()}fitMapToView(e,i=!1){if(!e||e.minX===e.maxX||e.minY===e.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,r=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(e,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-r*2),g=u*(1-s*2),y=p/l,m=g/c,x=Math.min(y,m),S=this.config.interaction.fitMinScale,v=this.config.interaction.fitMaxScale,b=Math.max(S,Math.min(v,x));this.setScaleBounds(this.config.interaction.zoomRange.min,this.config.interaction.zoomRange.max),b<this.scaleMin&&(this.setScaleBounds(b,this.scaleMax),w.debug("[MapApplication] scaleMin lowered for fit:",{configured:this.config.interaction.zoomRange.min,adjusted:b})),b>this.scaleMax&&(this.setScaleBounds(this.scaleMin,b),w.debug("[MapApplication] scaleMax raised for fit:",{configured:this.config.interaction.zoomRange.max,adjusted:b}));const P=e.minX+(e.maxX-e.minX)/2,C=e.minY+(e.maxY-e.minY)/2,_=this.config.map.autoFitOffset||{x:0,y:0},R=d/2+(_.x||0),M=u/2+(_.y||0),A=Math.cos(a),T=Math.sin(a),I=P*A-C*T,D=P*T+C*A,B=R-I*b,j=M-D*b;w.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:e,rotatedBounds:h,finalScale:b,position:{x:B,y:j}}),this.components.interaction.setPanZoom({targetPosition:{x:B,y:j},targetScale:{x:b,y:b},setCenter:!0,setScale:!0},i)}setScaleBounds(e,i){this.scaleMin=e,this.scaleMax=i,this.components.interaction.scaleMin=e,this.components.interaction.scaleMax=i}validateCustomZoneTypes(e){const i=["minSize","strokeColor","strokeWidth","fillColor","outlineOffset","outlineStrokeColor","outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","iconWrapperFillColor","textColor","textPosition","textOffset","showRotateButton","editing","normal"],s=e.customZoneTypes??{},r=_h.cleanZone;for(const[,o]of Object.entries(s))for(const a of i)o[a]===void 0&&(o[a]=r[a])}calculateRotatedBounds(e,i){if(i===0)return e;const s=(e.minX+e.maxX)/2,r=(e.minY+e.maxY)/2,o=[{x:e.minX-s,y:e.minY-r},{x:e.maxX-s,y:e.minY-r},{x:e.maxX-s,y:e.maxY-r},{x:e.minX-s,y:e.maxY-r}],a=Math.cos(i),h=Math.sin(i),l=o.map(g=>({x:g.x*a-g.y*h,y:g.x*h+g.y*a}));let c=1/0,d=1/0,u=-1/0,p=-1/0;return l.forEach(g=>{c=Math.min(c,g.x),d=Math.min(d,g.y),u=Math.max(u,g.x),p=Math.max(p,g.y)}),{minX:c+s,minY:d+r,maxX:u+s,maxY:p+r}}getViewportBounds(){var e;return((e=this.components.viewportContainer)==null?void 0:e.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(e){Object.assign(this.runtime,e),w.log("[runtime] runtime updated",e),this.renderOnceNextFrame()}updateConfig(e){var s,r,o;Na(this.config,e,(a,h)=>{if(Array.isArray(h))return h}),e.customZoneTypes&&this.validateCustomZoneTypes(this.config),(s=this.managers.controlsManager)==null||s.updateRenderOrder(),((r=e.controls)==null?void 0:r.carpet)!==void 0&&((o=this.managers.customCarpetManager)==null||o.refreshConfig()),w.log("[Config] Configuration updated",e),this.renderOnceNextFrame()}metersToPixels(e){return this.coords.toPixels(ut(e))}pixelsToMeters(e){return this.coords.toMeters(Bt(e))}toFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e/s}fromFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e*s}getViewportCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate center point"),null;const e=this.getViewportBounds(),i=e.x+e.width/2,s=e.y+e.height/2,r=this.components.appContainer,o=r.scale.x,a=r.getMapRotationRadians(),h=i-r.x,l=s-r.y,c=h/o,d=l/o,u=Math.cos(a),p=Math.sin(a),g=c*u+d*p,y=-c*p+d*u,m=g-this.mapState.origin.x,x=y-this.mapState.origin.y;return{x:m,y:x}}getMapCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate map center point"),null;const e=this.managers.mapManager.mapBounds;if(e.minX===1/0||e.minY===1/0||e.maxX===-1/0||e.maxY===-1/0)return w.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(e.minX+e.maxX)/2,s=(e.minY+e.maxY)/2,r=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:r,y:o}}getWallPointsByViewportCenter(e){var g;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:r=0,offsetY:o=0}=e||{},a=this.getViewportCenterPoint()||{x:0,y:0},l=this.coords.toPixels(ut(i))/2,c=((g=this.components.appContainer)==null?void 0:g.getMapRotationRadians())||0,d=Math.cos(c),u=Math.sin(c);let p;return s==="horizontal"?p=[{vx:-l+r,vy:o},{vx:l+r,vy:o}]:p=[{vx:r,vy:-l+o},{vx:r,vy:l+o}],p.map(y=>({x:a.x+y.vx*d+y.vy*u,y:a.y-y.vx*u+y.vy*d}))}getForbiddenSweepZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getForbiddenMopZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getCleanZonePointsByViewportCenter(e){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getSpotPointByViewportCenter(e){const{offsetX:i=0,offsetY:s=0}=e||{},r=this.getViewportCenterPoint()||{x:0,y:0},o=r.x+i,a=r.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(e){const{furnitureType:i=1,offsetX:s=0,offsetY:r=0}=e||{},o=this.config.furniture.assets.find(h=>h.type===i),a=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:a,widthMeters:(o==null?void 0:o.width)??1.8,heightMeters:(o==null?void 0:o.height)??2,applyMapRotation:!0,visualOffsetX:s,visualOffsetY:r})}getResolvedCustomCarpetMaxSize(){const e=this.config.controls.carpet.maxSize;if(this.customCarpetResolvedMaxSizeCache&&this.customCarpetResolvedMaxSizeCache.key===e)return this.customCarpetResolvedMaxSizeCache.value;const i=Us(this.config.controls.carpet.minSize,e,"carpet");return this.customCarpetResolvedMaxSizeCache={key:e,value:i},i}getCustomCarpetPointsByViewportCenter(e){const s=this.config.controls.carpet.minSize,r=this.getResolvedCustomCarpetMaxSize(),{offsetX:o=0,offsetY:a=0}=e||{},h=(g,y)=>{const m=typeof g=="number"&&Number.isFinite(g)?g:y;return r!=null?Math.min(Math.max(m,s),r):Math.max(m,s)},l=(e==null?void 0:e.width)??(e==null?void 0:e.height),c=(e==null?void 0:e.height)??(e==null?void 0:e.width),d=h(l,s),u=h(c,s),p=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:p,widthMeters:d,heightMeters:u,applyMapRotation:!0,visualOffsetX:o,visualOffsetY:a})}getRectPointsByCenter(e){const{center:i,width:s,height:r,applyMapRotation:o=!0}=e;return this.buildRectPoints({center:i,widthMeters:s,heightMeters:r,applyMapRotation:o})}areRoomsAdjacent(e){return!e||e.length===0?(w.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(e)}isPointInAnyRoom(e){return!e||typeof e.x!="number"||typeof e.y!="number"?(w.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(e):(w.warn("[Room] Map state not available"),null)}isPointInRoom(e,i){return!e||typeof e.x!="number"||typeof e.y!="number"?(w.warn("[Room] Invalid point provided"),!1):this.mapState?this.managers.mapManager.isPointInRoom(e,i):(w.warn("[Room] Map state not available"),!1)}isWallIntersectsAnyRoom(e){return!e||e.length!==2||!e[0]||!e[1]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"?(w.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(e):(w.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(e){return!e||e.length!==4||!e[0]||!e[1]||!e[2]||!e[3]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"||typeof e[2].x!="number"||typeof e[2].y!="number"||typeof e[3].x!="number"||typeof e[3].y!="number"?(w.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(e):(w.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(e,i,s){var h,l;if(!e||e.length<1)return w.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(e.length!==1&&e.length!==2&&e.length!==4)return w.warn("[Distance] Invalid points array: must have exactly 1 (point), 2 (wall) or 4 (zone) points"),!1;if(i<=0)return w.warn("[Distance] Invalid threshold: must be greater than 0"),!1;if(!this.mapState)return w.warn("[Distance] Map state not available"),!1;const{checkCharger:r=!0,checkRobot:o=!1}=s||{};if(!r&&!o)return w.warn("[Distance] At least one of checkCharger or checkRobot must be true"),!1;const a=this.coords.toPixels(ut(i));if(r){const c=this.appService.getChargerPosition();if(c){const d=(h=this.mapState)==null?void 0:h.charger.x,u=(l=this.mapState)==null?void 0:l.charger.y;if(d===0&&u===0)return w.warn("[Distance] Charger position not available"),!1;const p=Qa(c,e);if(p<=a)return w.log(`[Distance] Too close to charger: ${p.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else w.warn("[Distance] Charger position not available")}if(o){const c=this.appService.getRobotPosition();if(c){const d=Qa(c,e);if(d<=a)return w.log(`[Distance] Too close to robot: ${d.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else w.warn("[Distance] Robot position not available")}return!1}async snapshot(e){this.render();const{snapshot:i,global:s}=this.config,r=(e==null?void 0:e.backgroundColor)??s.backgroundColor,o=this.components.appContainer,a=o.getSnapshotBounds(),h=Math.floor(a.x),l=Math.floor(a.y),c=Math.ceil(a.x+a.width)-h,d=Math.ceil(a.y+a.height)-l;if(c<=0||d<=0)return w.error("[MapApplication] Snapshot failed: invalid bounds",a),"";const u=i.resolution||window.devicePixelRatio||2,p=Nr.create({width:c,height:d,resolution:u}),g=new H;g.rect(0,0,c,d).fill(r);const y=new U;y.translate(-h,-l);try{return this.renderer.render({container:g,target:p}),this.renderer.render({container:o,target:p,transform:y,clear:!1}),await this.renderer.extract.base64({target:p,format:i.format,quality:i.quality,antialias:i.antialias})}catch(m){return w.error("[MapApplication] Snapshot failed:",m),""}finally{g.destroy(),p.destroy(!0)}}async snapshotByData({map:e,path:i,roomProperties:s,customElements:r,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c,carpets:d},u={},p){const g=`SNAPSHOT_${hh()}`;w.log(`[MapApplication] ${g} snapshot start`);const y=new Di(g);try{if(await y.initialize({config:this.config,runtime:u}),!e)throw new Error("Map data is required");if(e.startsWith("7b22")){const x=Md(e);await y.drawMap(x)}else{const x=Td(e,{pointsStructured:!0});if(x)await y.drawRasterMap(x);else throw new Error("Failed to decode raster map data")}if(i){const{decodePath:x}=await Ae(async()=>{const{decodePath:v}=await import("./theme.DjNI0QHl.js").then(b=>b.f);return{decodePath:v}},__vite__mapDeps([4,2])),S=x(i);y.drawPath(S)}s&&s.length>0&&await y.drawRoomProperty(s),o&&o.length>0&&y.drawForbiddenSweepZones(o),a&&a.length>0&&y.drawForbiddenMopZones(a),h&&h.length>0&&y.drawVirtualWalls(h),d&&d.length>0&&await y.drawCustomCarpets(d),c&&c.length>0&&await y.drawFurnitures(c),l&&l.length>0&&await y.drawDetectedObjects(l),r&&r.length>0&&await y.drawCustomElements(r);const m=await y.snapshot(p);return w.log(`[MapApplication] ${g} snapshot completed successfully`),m}catch(m){throw w.error(`[MapApplication] ${g} snapshot other map failed:`,m),m}finally{w.log(`[MapApplication] ${g} destroy`),y.destroy()}}renderOnce(){w.debug("[Pixi] renderOnce");try{this.render()}catch(e){w.error("[Pixi] renderOnce failed",this.getRendererDiagnostics({error:e}))}}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{w.debug("[Pixi] renderOnceNextFrame");try{this.render()}catch(e){w.error("[Pixi] renderOnceNextFrame failed",this.getRendererDiagnostics({error:e}))}finally{this.pendingAsyncRender=!1}}))}requestRender(e,i=!1){if(this.tickerState.lastRequestReason=e,!i){this.renderOnceNextFrame(),this.emitRenderStateUpdate();return}this.tickerState.renderReasons.add(e),this.ticker.started||(w.debug(`🎬 [Ticker] START: ${e}`),this.ticker.start()),this.emitRenderStateUpdate()}stopRender(e){this.tickerState.lastStopReason=e,this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100),this.emitRenderStateUpdate()}getRenderState(){var i;const e=!!((i=this.ticker)!=null&&i.started);return{continuous:e,fps:e?Math.round(this.ticker.FPS):0,lastRequestReason:this.tickerState.lastRequestReason,lastStopReason:this.tickerState.lastStopReason,activeReasons:[...this.tickerState.renderReasons]}}emitRenderStateUpdate(){this.emitter.emit("renderStateUpdate",this.getRenderState())}destroy(){var e,i,s,r,o,a,h,l,c,d,u,p,g;if(!this.isDestroying){this.isDestroying=!0,w.log("[MapApplication] destroy"),this.recordDebugLifecycleEvent("destroy:start");try{this.tickerState.renderTimer&&(clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=null),this.tickerState.renderReasons.clear(),this.emitter.all.clear(),(e=this.renderer)==null||e.off("resize",this.onRendererResize),document.removeEventListener("visibilitychange",this.onVisibilityChange),(i=this.managers.pathManager)==null||i.destroy(),(s=this.managers.mapManager)==null||s.destroy(),(r=this.managers.controlsManager)==null||r.destroy(),(o=this.managers.furnitureManager)==null||o.destroy(),(a=this.managers.detectedObjectManager)==null||a.destroy(),(h=this.managers.customElementsManager)==null||h.destroy(),(l=this.managers.roomsManager)==null||l.destroy(),(c=this.components.interaction)==null||c.destroy(),(d=this.components.background)==null||d.destroy(),(u=this.components.viewportContainer)==null||u.destroy(),(p=this.components.appContainer)==null||p.destroy(),(g=this.managers.heatmapManager)==null||g.destroy(),this.detachRendererDiagnostics(),rx(this.previousLoggerRuntimeState),this.previousLoggerRuntimeState=null,globalThis.__PIXI_APP__===this&&delete globalThis.__PIXI_APP__,super.destroy({removeView:!0},{children:!0,texture:!0,textureSource:!0,context:!0})}finally{globalThis.__PIXI_APP__===this&&delete globalThis.__PIXI_APP__,this.recordDebugLifecycleEvent("destroy:end")}}}initializeViewportContainer(){this.components.viewportContainer=new oS(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const e=this.getViewportBounds();this.components.background=new fv(this.config.global,e,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Gs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new cS(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Vx(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(e,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&(w.debug("⏸️ [Ticker] STOP"),this.ticker&&(this.ticker.stop(),this.emitRenderStateUpdate()))},i)}generateZonePoints(e,i,s){const r=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:r,widthMeters:e,heightMeters:e,applyMapRotation:!0,visualOffsetX:i,visualOffsetY:s})}buildRectPoints(e){var y;const{center:i,widthMeters:s,heightMeters:r,applyMapRotation:o,visualOffsetX:a=0,visualOffsetY:h=0}=e,l=this.coords.toPixels(ut(s))/2,c=this.coords.toPixels(ut(r))/2,d=o&&((y=this.components.appContainer)==null?void 0:y.getMapRotationRadians())||0,u=Math.cos(d),p=Math.sin(d);return[{vx:-l+a,vy:-c+h},{vx:l+a,vy:-c+h},{vx:l+a,vy:c+h},{vx:-l+a,vy:c+h}].map(m=>({x:i.x+m.vx*u+m.vy*p,y:i.y-m.vx*p+m.vy*u}))}preloadAssets(){const e=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:e}),s.push("robot"),N.add({alias:"chargingStation",src:i}),s.push("chargingStation"),N.add({alias:"deleteIcon",src:this.config.controls.deleteIconSrc}),s.push("deleteIcon"),N.add({alias:"rotateIcon",src:this.config.controls.rotateIconSrc}),s.push("rotateIcon"),N.add({alias:"scaleIcon",src:this.config.controls.scaleIconSrc}),s.push("scaleIcon"),N.add({alias:"moveIcon",src:this.config.controls.moveIconSrc}),s.push("moveIcon"),N.add({alias:"checkmark",src:this.config.room.selectionIndicator.iconSrc}),s.push("checkmark"),N.add({alias:"spotIcon",src:this.config.controls.spot.iconSrc}),s.push("spotIcon"),N.add({alias:"purifyIcon",src:this.config.controls.purifyPoint.iconSrc}),s.push("purifyIcon"),N.add({alias:"wayPoint",src:this.config.controls.wayPoint.normal.iconSrc}),s.push("wayPoint"),N.add({alias:"wayPointActive",src:this.config.controls.wayPoint.editing.iconSrc}),s.push("wayPointActive"),N.add({alias:"horizontalScaleIcon",src:this.config.controls.horizontalScaleIconSrc}),s.push("horizontalScaleIcon"),N.add({alias:"verticalScaleIcon",src:this.config.controls.verticalScaleIconSrc}),s.push("verticalScaleIcon"),this.config.room.property.cleanMode.assets.forEach((r,o)=>{const a=`cleanMode_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.suction.assets.forEach((r,o)=>{const a=`fan_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.cistern.assets.forEach((r,o)=>{const a=`water_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.cleanTimes.assets.forEach((r,o)=>{const a=`cleanTimes${o+1}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.floorType.assets.forEach((r,o)=>{if(!r)return;const a=`floorType${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.customAssets&&Object.entries(this.config.room.property.customAssets).forEach(([r,o])=>{o.forEach((a,h)=>{const l=`custom_${r}_${h}`;N.add({alias:l,src:a}),s.push(l)})}),this.config.furniture.assets.forEach(r=>{const o=`furniture_${r.type}`;N.add({alias:o,src:r.src}),s.push(o)}),N.backgroundLoad(s)}setupMapRotationListener(){this.applyMapRotation(this.runtime.mapRotation),O(this.runtime,"mapRotation",e=>{this.applyMapRotation(e)})}applyMapRotation(e){const i=(e%360+360)%360;w.log(`[MapApplication] Applying map rotation: ${i}°`),this.components.appContainer.setMapRotation(i);const s=this.managers.mapManager.mapBounds;s&&s.minX!==1/0&&s.maxX!==-1/0&&this.fitMapToView(s,!1),this.emitter.emit("mapRotationUpdate",i),this.renderOnce()}};f(Di,"CONTEXT_LOSS_TAIL_SIZE",8);let vr=Di;const Av=Object.freeze(Object.defineProperty({__proto__:null,AppService:Rc,MapApplication:vr},Symbol.toStringTag,{value:"Module"}));export{ea as $,_i as A,le as B,oe as C,_r as D,Zt as E,Tr as F,H as G,bm as H,ei as I,lg as J,zs as K,tg as L,U as M,Gt as N,Ls as O,Q as P,Mr as Q,J as R,uf as S,G as T,Fe as U,$ as V,gl as W,te as X,Vi as Y,lf as Z,li as _,Je as a,Mi as a0,Ar as a1,ul as a2,zt as a3,si as a4,kl as a5,Wf as a6,Vf as a7,Tv as a8,Il as a9,Li as aA,gf as aB,El as aC,Gf as aD,$f as aE,wm as aF,Dl as aG,Yf as aH,pm as aI,Av as aJ,Be as aa,ms as ab,Ju as ac,Wd as ad,ce as ae,ii as af,Xf as ag,At as ah,Lh as ai,Ft as aj,Is as ak,To as al,jt as am,iy as an,mu as ao,Ro as ap,on as aq,ko as ar,xu as as,Wh as at,Nr as au,Gr as av,ml as aw,Hi as ax,_p as ay,Sp as az,cr as b,nt as c,V as d,de as e,dr as f,ls as g,yt as h,X as i,Vu as j,ft as k,Lm as l,ct as m,Fu as n,Eu as o,E as p,mt as q,Jd as r,um as s,Ia as t,ep as u,K as v,st as w,q as x,W as y,it as z};
|
|
744
|
+
`,entryPoint:"main"}})}),l=new za({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(e,i){this.position.set(e,i)}clear(){this.removeChildren()}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class bS{constructor(t){f(this,"heatmap");f(this,"pointsTopLeftOrigin",[]);f(this,"signalGrid",[]);f(this,"cellSize",2);f(this,"maxDistance",14);f(this,"smoothIterations",10);f(this,"heatmapAlpha",.8);f(this,"isHeatmapDrawn",!1);f(this,"loadTimer",null);f(this,"pendingPoints",null);this.appService=t,this.heatmap=new vS(t);const e=t.heatMapConfig;this.cellSize=e.cellSize,this.maxDistance=e.maxDistance,this.smoothIterations=e.smoothIterations,this.heatmapAlpha=e.heatmapAlpha}draw(t){if(t.length===0){this.clear();return}const e=this.appService;if(!e.isMapDrawn){this.pendingPoints=t;return}this.pendingPoints=null;const{minX:i,minY:s}=e.mapManager.mapBounds,r=t.map(o=>({x:+(o.x-i).toFixed(0),y:+(o.y-s).toFixed(0),signal:o.signal}));this.signalGrid=this.calculateInterpolatedSignal(r),this.heatmap.draw(this.signalGrid,this.heatmapAlpha),this.isHeatmapDrawn=!0}clear(){this.pendingPoints=null,this.pointsTopLeftOrigin=[],this.signalGrid=[],this.heatmap.clear(),this.isHeatmapDrawn=!1}onMapLoaded(){this.loadTimer||(this.pendingPoints&&this.draw(this.pendingPoints),this.loadTimer=setTimeout(()=>{this.loadTimer=null},200))}calculateInterpolatedSignal(t){var p;const e=this.appService,i=((p=e.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:r,maxX:o,maxY:a}=e.mapManager.mapBounds;r=r-i.y,s=s-i.x,a=a-i.y,o=o-i.x;const h=Math.ceil((a-r)/this.cellSize),l=Math.ceil((o-s)/this.cellSize),c=Array(h).fill(null).map(()=>Array(l).fill(null));for(let g=0;g<h;g++){const y=r+g*this.cellSize+this.cellSize/2,m=Math.min(this.cellSize,a-(y-this.cellSize/2));for(let x=0;x<l;x++){const S=s+x*this.cellSize+this.cellSize/2,v=Math.min(this.cellSize,o-(S-this.cellSize/2));let b=0,P=!1;for(let C=0;C<t.length;C++){const _=t[C];if(Math.abs(S-_.x)<=v/2&&Math.abs(y-_.y)<=m/2){const R=1-_.signal/7;b=Math.round(Math.max(b,R)*10)/10,P=!0}}c[g][x]={x:S,y,signal:b,hasPoint:P}}}const d=(g,y)=>{if(t.length===0)return 0;let m=0,x=0;for(const S of t){const v=Math.sqrt((g-S.x)**2+(y-S.y)**2);if(v<=this.maxDistance){const b=1/(1+v),P=1-S.signal/7;x+=b*P,m+=b}}return m===0?0:Math.round(x/m*1e3)/1e3},u=(g,y=1)=>{for(let m=0;m<y;m++){const x=g.map(S=>[...S]);for(let S=1;S<h-1;S++)for(let v=1;v<l-1;v++)if(!g[S][v].hasPoint){let b=0,P=0;const C=4;for(let _=-C;_<=C;_++)for(let R=-C;R<=C;R++){if(_===0&&R===0)continue;const M=S+_,A=v+R;if(M>=0&&M<h&&A>=0&&A<l){const I=1/(1+Math.sqrt(_*_+R*R)*.3);b+=g[M][A].signal*I,P+=I}}if(P>0){const _=b/P,R=.6,M=.4;x[S][v].signal=g[S][v].signal*R+_*M,x[S][v].signal>.1&&(x[S][v].signal=Math.max(x[S][v].signal,.2))}}for(let S=0;S<h;S++)for(let v=0;v<l;v++)g[S][v].signal=x[S][v].signal}};for(let g=0;g<h;g++)for(let y=0;y<l;y++){const m=c[g][y];m.hasPoint||(m.signal=d(m.x,m.y))}return u(c,this.smoothIterations),c}updatePositionByOrigin(t,e){this.heatmap.updatePositionByOrigin(t,e)}destroy(){this.heatmap.destroy()}}class Qr extends H{constructor(e,i){super();f(this,"fillOptions");f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handlePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});f(this,"handleDragPointerMove",e=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,e)});f(this,"handleDragPointerUp",()=>{var e,i;this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});this.appService=e,this.fillOptions=i,this.setupInteraction(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}startDragging(e){var s,r;this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},(r=(s=this.fillOptions).onDragStart)==null||r.call(s,e),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}draw(){const{points:e,fillColor:i}=this.fillOptions;if(e.length<3)return;this.clear();const s=e.flatMap(r=>[r.x,r.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(e){this.fillOptions={...this.fillOptions,...e},e.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(e){this.fillOptions.points=e,this.draw()}updateFillColor(e){this.fillOptions.fillColor=e,this.draw()}stopDragging(){var e;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(e){this.fillOptions.enableInteraction=e,e?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class ri extends W{constructor(e,i){super();f(this,"borderOptions");f(this,"solidLine",null);f(this,"dashGraphics",null);f(this,"fillGraphics",null);f(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=e,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:e=[],closePath:i=!1,style:s}=this.borderOptions;e.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(e,s),s.isDashed?this.drawContinuousDashedBorder(e,i,s):this.drawSolidBorder(e,i,s))}drawFill(e,i){if(!(!i.fillColor||e.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length;s++)this.fillGraphics.lineTo(e[s].x,e[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(e,i,s){const r=this.appService;this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy()),this.solidLine=new H;const o=r.getApp().toFixedSize(s.width);this.solidLine.setStrokeStyle({color:s.color,width:o}),this.solidLine.moveTo(e[0].x,e[0].y);for(let a=1;a<e.length;a++)this.solidLine.lineTo(e[a].x,e[a].y);i&&this.solidLine.lineTo(e[0].x,e[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(e,i,s){if(e.length<2)return;if(!s.dashArray||s.dashArray.length!==2||s.dashArray[0]<=0||s.dashArray[1]<=0){w.warn("Invalid dashArray:",s.dashArray);return}const r=this.appService;this.dashGraphics=new H;const o=r.getApp().toFixedSize(s.width);this.dashGraphics.setStrokeStyle({color:s.color,width:o});const a=Math.max(r.getApp().toFixedSize(s.dashArray[0]),1),h=Math.max(r.getApp().toFixedSize(s.dashArray[1]),1),l=i?[...e,e[0]]:e;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(e,i,s,r){if(i.length<2)return;if(s<=0||r<=0){w.warn("Invalid dash parameters:",{dashLength:s,gapLength:r});return}const o=this.calculatePathSegments(i),a=o.reduce((c,d)=>c+d.length,0);if(a===0)return;const h=s+r;let l=0;for(;l<a;){const c=l+s;c<=a?this.drawContinuousDashSegment(e,o,l,c):this.drawContinuousDashSegment(e,o,l,a),l+=h}}calculatePathSegments(e){const i=[];for(let s=0;s<e.length-1;s++){const r=e[s],o=e[s+1],a=o.x-r.x,h=o.y-r.y,l=Math.sqrt(a*a+h*h);i.push({start:r,end:o,length:l})}return i}drawContinuousDashSegment(e,i,s,r){if(s>=r)return;let o=0,a=!1,h=null;for(const l of i){const c=o,d=o+l.length;if(d>s&&c<r){const u=Math.max(s,c),p=Math.min(r,d),g=(u-c)/l.length,y=(p-c)/l.length,m={x:l.start.x+(l.end.x-l.start.x)*g,y:l.start.y+(l.end.y-l.start.y)*g},x={x:l.start.x+(l.end.x-l.start.x)*y,y:l.start.y+(l.end.y-l.start.y)*y};a?h&&Math.sqrt(Math.pow(m.x-h.x,2)+Math.pow(m.y-h.y,2))>.1&&e.lineTo(m.x,m.y):(e.moveTo(m.x,m.y),a=!0),e.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=r)break}}clearBorder(){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy(),this.fillGraphics=null),this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.dashGraphics&&(this.removeChild(this.dashGraphics),this.dashGraphics.destroy(),this.dashGraphics=null)}updateStyle(e){this.borderOptions.style={...this.borderOptions.style,...e},this.drawBorder()}updatePoints(e){this.borderOptions.points=e,this.drawBorder()}setClosePath(e){this.borderOptions.closePath=e,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class Jr{constructor(t){f(this,"id",null);f(this,"layer",null);f(this,"editingState",{});f(this,"idleState",{});f(this,"host",null);f(this,"onHostDestroyed",null);f(this,"detached",!1);this.deps=t}attach(t,e){this.layer&&this.detach(),this.detached=!1,this.host=t,this.id=e.id,this.editingState=e.editingState,this.idleState=e.idleState??{},this.layer=this.deps.editControls.registerEditControl(e.id,e.layerOptions);const i=()=>this.detach();return this.onHostDestroyed=i,t.once("destroyed",i),this.layer}detach(){this.detached||(this.detached=!0,this.host&&this.onHostDestroyed&&this.host.off("destroyed",this.onHostDestroyed),this.onHostDestroyed=null,this.host=null,this.id!=null&&this.deps.editControls.unregisterEditControl(this.id),this.id=null,this.layer=null)}setEditing(t){if(this.id==null){w.warn("[EditableShape] setEditing called before attach; ignoring");return}this.deps.editControls.updateEditState(this.id,t?this.editingState:this.idleState)}applyEditState(t){if(this.id==null){w.warn("[EditableShape] applyEditState called before attach; ignoring");return}this.deps.editControls.updateEditState(this.id,t)}updatePoints(t,e=!0){var i;(i=this.layer)==null||i.updatePoints(t,e)}getLayer(){return this.layer}getMoveButton(){var t;return((t=this.layer)==null?void 0:t.getMoveButton())??null}}class Es extends Os{constructor(e,{text:i,style:s}){super({text:i,style:s});f(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=Pt(this.updateScale.bind(this),20,{leading:!0,trailing:!0}),this.registerScaleListener(),this.updateScale(this.appService.currentScale)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e<=0||this.scale.set(1/e)}setBaseFontSize(e){this.style.fontSize=e}updateText(e){this.text=e}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Gc extends W{constructor(e){super();f(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.updateScale(this.appService.currentScale),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e!==0&&this.scale.set(1/e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Hs extends Gc{constructor(e,i){super(e);f(this,"background");f(this,"icon");f(this,"options");this.appService=e,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Ut(e),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const e=this.appService,i=this.options.config||e.controlsConfig,s=8,r=i.iconWrapperWidth+s*2,o=i.iconWrapperHeight+s*2;this.hitArea=new J(-r/2,-o/2,r,o)}async render(){this.renderBackground(),this.renderIcon()}renderBackground(){const e=this.appService,i=this.options.config||e.controlsConfig;this.background.clear(),this.background.roundRect(-i.iconWrapperWidth/2,-i.iconWrapperHeight/2,i.iconWrapperWidth,i.iconWrapperHeight,i.iconWrapperBorderRadius).fill(this.options.backgroundColor)}async renderIcon(){try{const e=this.appService,i=this.options.config||e.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(e){w.error(`Failed to load icon: ${this.options.iconAlias}`,e)}}destroy(){super.destroy()}}class Uc extends Hs{constructor(e,i){super(e,i);f(this,"isMoving",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handleMovePointerMove",e=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,e)});f(this,"handleMovePointerUp",()=>{var e,i;this.gestureSession=null,this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});this.appService=e}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startMoving(e)}startMoving(e){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(e.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleMovePointerMove),this.gestureSession.onEnd(this.handleMovePointerUp)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var e,i;this.isMoving&&(this.gestureSession?this.gestureSession.cancel():(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e)))}destroy(){this.stopMoving(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Hc extends Hs{constructor(e,i){super(e,i);f(this,"clickHandler",null);this.appService=e}setupEvents(){this.clickHandler=new St(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),super.destroy()}}const wS=10;class CS extends Hs{constructor(e,i){super(e,i);f(this,"isRotating",!1);f(this,"hasRotated",!1);f(this,"rotationCenter",{x:0,y:0});f(this,"downPosition",{x:0,y:0});f(this,"lastAngle",0);f(this,"clickHandler",null);f(this,"gestureSession",null);f(this,"handleRotationPointerMove",e=>{var o,a,h,l;if(!this.isRotating)return;if(!this.hasRotated){const c=e.global.x-this.downPosition.x,d=e.global.y-this.downPosition.y;if(Math.sqrt(c*c+d*d)<=wS)return;this.hasRotated=!0,(a=(o=this.options).onRotationStart)==null||a.call(o,this.rotationCenter)}const i=this.parent.toLocal(e.global),s=Math.atan2(i.y-this.rotationCenter.y,i.x-this.rotationCenter.x),r=s-this.lastAngle;(l=(h=this.options).onRotationMove)==null||l.call(h,r),this.lastAngle=s});f(this,"handleRotationPointerUp",()=>{var e,i;this.gestureSession=null,this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});this.appService=e}setupEvents(){this.options.onClick&&(this.clickHandler=new St(this,{onClick:()=>{var e,i;this.hasRotated||(i=(e=this.options).onClick)==null||i.call(e)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startRotation(e)}startRotation(e){this.isRotating=!0,this.hasRotated=!1,this.downPosition={x:e.global.x,y:e.global.y};const i=this.options.getTargetPoints();this.rotationCenter=Oe(i);const s=this.parent.toLocal(e.global);this.lastAngle=Math.atan2(s.y-this.rotationCenter.y,s.x-this.rotationCenter.x),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleRotationPointerMove),this.gestureSession.onEnd(this.handleRotationPointerUp)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var e,i;this.isRotating&&(this.gestureSession?this.gestureSession.cancel():(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1))}destroy(){var e;this.stopRotation(),this.gestureSession=null,(e=this.clickHandler)==null||e.destroy(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class vs extends Hs{constructor(e,i){super(e,i);f(this,"isScaling",!1);f(this,"initialButtonPosition",null);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"handleScalePointerMove",e=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:r})});f(this,"handleScalePointerUp",()=>{var e,i;this.gestureSession=null,this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});this.appService=e}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startScaling(e)}startScaling(e){var i,s,r,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(e.global),"initialButtonPosition"in this.options)this.initialButtonPosition={x:this.position.x,y:this.position.y},(s=(i=this.options).onScaleStart)==null||s.call(i);else{const a=this.options.getTargetPoints(),h=this.options.getButtonIndex();h>=0&&h<a.length&&(this.initialButtonPosition={...a[h]}),(o=(r=this.options).onScaleStart)==null||o.call(r,h)}this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleScalePointerMove),this.gestureSession.onEnd(this.handleScalePointerUp)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var e,i;this.isScaling&&(this.gestureSession?this.gestureSession.cancel():(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e)))}destroy(){this.stopScaling(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}const pt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class _S extends W{constructor(e,i){super();f(this,"config");f(this,"events");f(this,"zonePoints",[]);f(this,"outlinePoints");f(this,"minSize",.1);f(this,"maxSize");f(this,"sizeConstraintPerEdge");f(this,"initialZonePoints",[]);f(this,"scaleCache",null);f(this,"rotationCache",null);f(this,"outlineBorder");f(this,"moveLine");f(this,"sizeText");f(this,"controlButtons");f(this,"deleteButton",null);f(this,"rotateButton",null);f(this,"scaleButton",null);f(this,"moveButton",null);f(this,"horizontalScaleButton",null);f(this,"verticalScaleButton",null);f(this,"horizontalScaleInitialPosition",null);f(this,"verticalScaleInitialPosition",null);f(this,"clickHandler",null);f(this,"throttledUpdateOutline");this.appService=e,this.zonePoints=i.zonePoints,this.config={...i.config,showScaleButton:i.config.showScaleButton!==void 0?i.config.showScaleButton:!0,showRadialScaleButton:i.config.showRadialScaleButton!==void 0?i.config.showRadialScaleButton:!0,showDeleteButton:i.config.showDeleteButton!==void 0?i.config.showDeleteButton:!0,showMoveButton:i.config.showMoveButton!==void 0?i.config.showMoveButton:!0,showRotateButton:i.config.showRotateButton!==void 0?i.config.showRotateButton:!0,rotateMode:i.config.rotateMode??"step",scaleMode:i.config.scaleMode??"free"},this.events=i.events||{},this.minSize=i.minSize??.1,this.maxSize=i.maxSize,this.sizeConstraintPerEdge=i.sizeConstraintPerEdge,this.throttledUpdateOutline=Pt(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.registerScaleListener()}initializeComponents(){this.outlinePoints=this.calculateOutlinePoints(),this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.moveLine.visible=this.config.showMoveButton||!1,this.sizeText=this.createSizeText(),this.addChild(this.sizeText),this.controlButtons=new W,this.addChild(this.controlButtons),this.createControlButtons(),this.setupClickHandler()}createOutlineBorder(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:r,outlineFillColor:o}=this.config;return new ri(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:e,width:i,isDashed:s,dashArray:r,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:r}=this.config,o=this.calculateMoveLinePoints();return new ri(this.appService,{points:o,closePath:!1,style:{color:e,width:i,isDashed:s,dashArray:r}})}createSizeText(){const e=this.calculateSizeText(),i=new Es(this.appService,{text:e,style:{fontSize:this.config.textFontSize,fontFamily:this.config.textFontFamily,fontWeight:this.config.textFontWeight,fill:this.config.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const r=this.calculateSizeTextRotation();return i.rotation=r,i.eventMode="none",i}createDeleteButton(){const e=new Hc(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.config.deleteIconWrapperFillColor??this.config.iconWrapperFillColor,onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return e.position.set(this.outlinePoints[pt.REMOVE].x,this.outlinePoints[pt.REMOVE].y),e}createRotateButton(){const e=this.config.rotateMode==="step",i=new CS(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.config.iconWrapperFillColor,getTargetPoints:()=>this.zonePoints,onRotationStart:s=>{var r,o;this.initializeRotationCache(s),(o=(r=this.events).onRotateStart)==null||o.call(r,s)},onRotationMove:e?void 0:s=>{var o,a;const r=this.handleInternalRotationMove(s);(a=(o=this.events).onRotateMove)==null||a.call(o,r??void 0)},onClick:e?()=>{var o,a,h,l;const s=this.config.stepRotateAngle??Math.PI/2,r=this.onClickRotateButton(s);(a=(o=this.events).onRotateMove)==null||a.call(o,r??void 0),(l=(h=this.events).onClickRotate)==null||l.call(h,r??void 0)}:void 0,onRotationEnd:()=>{var s,r;this.resetRotationState(),(r=(s=this.events).onRotateEnd)==null||r.call(s)}});return i.position.set(this.outlinePoints[pt.ROTATE].x,this.outlinePoints[pt.ROTATE].y),i}onClickRotateButton(e){this.rotationCache||this.initializeRotationCache(this.calculateRotationCenter());const i=this.handleInternalRotationMove(e);return this.resetRotationState(),i}createScaleButton(){const e=new vs(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.config.iconWrapperFillColor,initialButtonPosition:this.outlinePoints[pt.SCALE],onScaleStart:()=>{var i,s;this.initializeScaleCache(),(s=(i=this.events).onScaleStart)==null||s.call(i)},onScaleMove:({deltaX:i,deltaY:s})=>{var o,a;const r=this.handleInternalScaleMove(i,s);(a=(o=this.events).onScaleMove)==null||a.call(o,r??void 0)},onScaleEnd:()=>{var i,s;this.resetScaleState(),this.initialZonePoints=[],(s=(i=this.events).onScaleEnd)==null||s.call(i)}});return e.position.set(this.outlinePoints[pt.SCALE].x,this.outlinePoints[pt.SCALE].y),e}createHorizontalScaleButton(){const[,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),r=new vs(this.appService,{iconAlias:"horizontalScaleIcon",backgroundColor:this.config.iconWrapperFillColor,config:{iconWrapperWidth:18,iconWrapperHeight:18,iconWrapperBorderRadius:18,iconWidth:10,iconHeight:8},initialButtonPosition:s,onScaleStart:()=>{var h,l;const[,o,a]=this.zonePoints;this.horizontalScaleInitialPosition=this.getEdgeCenter(o,a),this.initializeScaleCache(),(l=(h=this.events).onScaleStart)==null||l.call(h)},onScaleMove:({deltaX:o,deltaY:a})=>{var l,c;const h=this.handleInternalHorizontalScaleMove(o,a);(c=(l=this.events).onScaleMoveHorizontal)==null||c.call(l,h??void 0)},onScaleEnd:()=>{var o,a;this.resetScaleState(),this.initialZonePoints=[],this.horizontalScaleInitialPosition=null,(a=(o=this.events).onScaleEnd)==null||a.call(o)}});return r.position.set(s.x,s.y),r}createVerticalScaleButton(){const[,,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),r=new vs(this.appService,{iconAlias:"verticalScaleIcon",backgroundColor:this.config.iconWrapperFillColor,config:{iconWrapperWidth:18,iconWrapperHeight:18,iconWrapperBorderRadius:18,iconWidth:8,iconHeight:10},initialButtonPosition:s,onScaleStart:()=>{var h,l;const[,,o,a]=this.zonePoints;this.verticalScaleInitialPosition=this.getEdgeCenter(o,a),this.initializeScaleCache(),(l=(h=this.events).onScaleStart)==null||l.call(h)},onScaleMove:({deltaX:o,deltaY:a})=>{var l,c;const h=this.handleInternalVerticalScaleMove(o,a);(c=(l=this.events).onScaleMoveVertical)==null||c.call(l,h??void 0)},onScaleEnd:()=>{var o,a;this.resetScaleState(),this.initialZonePoints=[],this.verticalScaleInitialPosition=null,(a=(o=this.events).onScaleEnd)==null||a.call(o)}});return r.position.set(s.x,s.y),r}createMoveButton(){const e=this.calculateMoveButtonPosition(),i=new Uc(this.appService,{iconAlias:"moveIcon",backgroundColor:this.config.iconWrapperFillColor,onMoveStart:()=>{var s,r;return(r=(s=this.events).onMoveStart)==null?void 0:r.call(s)},onMoveMove:s=>{var r,o;return(o=(r=this.events).onMoveMove)==null?void 0:o.call(r,s)},onMoveEnd:()=>{var s,r;return(r=(s=this.events).onMoveEnd)==null?void 0:r.call(s)}});return i.position.set(e.x,e.y),i}createAndAddButton(e,i){return e.visible=i,this.controlButtons.addChild(e),e}createControlButtons(){this.outlinePoints.length<4||(this.deleteButton=this.createAndAddButton(this.createDeleteButton(),this.config.showDeleteButton??!1),this.moveButton=this.createAndAddButton(this.createMoveButton(),this.config.showMoveButton??!1),this.rotateButton=this.createAndAddButton(this.createRotateButton(),this.config.showRotateButton??!1),this.scaleButton=this.createAndAddButton(this.createScaleButton(),this.config.showScaleButton??!1),this.horizontalScaleButton=this.createAndAddButton(this.createHorizontalScaleButton(),this.config.showRadialScaleButton??!1),this.verticalScaleButton=this.createAndAddButton(this.createVerticalScaleButton(),this.config.showRadialScaleButton??!1))}calculateOutlinePoints(){const e=this.zonePoints;if(e.length<4)return e;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return wx(e,s)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),r=e[pt.MOVE],o=e[pt.SCALE],a=e[pt.REMOVE];return Mc(r,o,a,s)}calculateMoveLinePoints(){const e=this.calculateOutlinePoints();if(e.length<4)return[];const i=e[pt.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const e=this.zonePoints;if(e.length<4)return"0m*0m";const[i,s,,r]=e,o=tt(i,s),a=tt(i,r),{coords:h}=this.appService,l=h.toMeters(Bt(o)),c=h.toMeters(Bt(a)),d=h.toDisplayUnit(l),u=h.toDisplayUnit(c),p=this.appService.runtimeSnapshot.unitLabel;return`${d.toFixed(1)}${p}*${u.toFixed(1)}${p}`}getEdgeCenter(e,i){return{x:(e.x+i.x)/2,y:(e.y+i.y)/2}}calculatePerpendicularOffset(e,i,s,r=!1){const o=Dt(bt(i,e)),a=r?{x:-o.y,y:o.x}:{x:o.y,y:-o.x};return{x:a.x*s,y:a.y*s}}calculateSizeTextPosition(){if(this.zonePoints.length<4)return{x:0,y:0};const i=this.calculateOutlinePoints(),[s,r,o,a]=i,{textPosition:h,textOffset:l}=this.config,d=this.appService.getApp().toFixedSize(l);let u,p;switch(h){case"top":u=this.getEdgeCenter(s,r),p=this.calculatePerpendicularOffset(r,s,d);break;case"right":u=this.getEdgeCenter(r,o),p=this.calculatePerpendicularOffset(r,o,d);break;case"bottom":u=this.getEdgeCenter(a,o),p=this.calculatePerpendicularOffset(a,o,d,!0);break;case"left":u=this.getEdgeCenter(s,a),p=this.calculatePerpendicularOffset(a,s,d);break;default:u=this.getEdgeCenter(s,r),p={x:0,y:d};break}return{x:u.x+p.x,y:u.y+p.y}}calculateSizeTextRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[i,s,r,o]=e,{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=r;break;case"bottom":h=r,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return Ss(h,l,c)}calculateHorizontalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(i,s,r)+Math.PI/2}calculateVerticalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,,i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(s,i,r)}updatePoints(e,i=!0){this.zonePoints=e,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlinePoints=e,this.outlineBorder.updatePoints(e)}updateMoveLine(){if(!this.moveLine)return;const e=this.calculateMoveLinePoints();this.moveLine.updatePoints(e)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:e[pt.REMOVE]},{button:this.scaleButton,point:e[pt.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:e[pt.ROTATE]}),this.horizontalScaleButton){const r=e[pt.ROTATE],o=e[pt.SCALE],a=_c(r,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const r=e[pt.SCALE],o=e[pt.MOVE],a=this.getEdgeCenter(r,o);s.push({button:this.verticalScaleButton,point:a})}s.forEach(({button:r,point:o})=>r.position.set(o.x,o.y)),this.horizontalScaleButton&&(this.horizontalScaleButton.rotation=this.calculateHorizontalScaleButtonRotation()),this.verticalScaleButton&&(this.verticalScaleButton.rotation=this.calculateVerticalScaleButtonRotation()),this.scaleButton&&this.scaleButton.visible&&(this.scaleButton.rotation=this.calculateVerticalScaleButtonRotation())}setupClickHandler(){this.clickHandler=new St(this,{onClick:()=>{var e,i;(i=(e=this.events).onClick)==null||i.call(e)},stopPropagation:!1})}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){(this.outlineBorder.visible||this.controlButtons.visible)&&(this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}initializeScaleCache(){if(this.initialZonePoints.length===0&&(this.initialZonePoints=this.zonePoints.map(p=>({...p}))),this.initialZonePoints.length<4)return;const e={...this.initialZonePoints[pt.SCALE]};if(!e)return;const i=pt.REMOVE,{x:s,y:r}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:r},l=bt(h,o),c=bt(h,a),d=Gi(l),u=Gi(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:e})}sizeConstraintPixels(){const{coords:e}=this.appService,i=(r,o)=>({minSizePixels:e.toPixels(ut(r)),maxSizePixels:o!=null?e.toPixels(ut(o)):void 0});if(this.sizeConstraintPerEdge){const{edge1:r,edge2:o}=this.sizeConstraintPerEdge();return{edge1:i(r.min,r.max),edge2:i(o.min,o.max)}}const s=i(this.minSize,this.maxSize);return{edge1:s,edge2:s}}handleInternalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const{edge1:s,edge2:r}=this.sizeConstraintPixels(),{fixedPoint:o,edge1:a,edge2:h,edge1Len:l,edge2Len:c,initialButtonPosition:d}=this.scaleCache,u={x:d.x+e,y:d.y+i},p=bt(o,u);let g=ps(p,a,l,s.minSizePixels,s.maxSizePixels),y=ps(p,h,c,r.minSizePixels,r.maxSizePixels);if(this.config.scaleMode==="ratioLocked"){const m=Math.min(g,y);g=m,y=m}return this.calculatePointsFromScale(o,a,h,g,y)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.horizontalScaleInitialPosition)return null;const{fixedPoint:s,edge1:r,edge2:o,edge1Len:a}=this.scaleCache,{edge1:h}=this.sizeConstraintPixels(),l={x:this.horizontalScaleInitialPosition.x+e,y:this.horizontalScaleInitialPosition.y+i},c=bt(s,l),d=ps(c,r,a,h.minSizePixels,h.maxSizePixels);return this.calculatePointsFromScale(s,r,o,d,1)}handleInternalVerticalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.verticalScaleInitialPosition)return null;const{fixedPoint:s,edge1:r,edge2:o,edge2Len:a}=this.scaleCache,{edge2:h}=this.sizeConstraintPixels(),l={x:this.verticalScaleInitialPosition.x+e,y:this.verticalScaleInitialPosition.y+i},c=bt(s,l),d=1,u=ps(c,o,a,h.minSizePixels,h.maxSizePixels);return this.calculatePointsFromScale(s,r,o,d,u)}calculatePointsFromScale(e,i,s,r,o){const{x:a,y:h}=e;return[e,{x:a+i.x*r,y:h+i.y*r},{x:a+i.x*r+s.x*o,y:h+i.y*r+s.y*o},{x:a+s.x*o,y:h+s.y*o}]}initializeRotationCache(e){this.zonePoints.length<3||(this.rotationCache={rotationCenter:e,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(e){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=e,vx(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:Oe(this.zonePoints)}updateEditState({showRotateButton:e=!1,showScaleButton:i=!1,showRadialScaleButton:s=!1,showDeleteButton:r=!1,showMoveButton:o=!1,showBorder:a=!1,showSizeText:h=!1,borderStyle:l}){this.rotateButton&&(this.rotateButton.visible=e),this.scaleButton&&(this.scaleButton.visible=i),this.horizontalScaleButton&&(this.horizontalScaleButton.visible=s),this.verticalScaleButton&&(this.verticalScaleButton.visible=s),this.deleteButton&&(this.deleteButton.visible=r),this.moveButton&&(this.moveButton.visible=o);const c=e||i||s||r||o;this.controlButtons.visible=c,!c&&this.getOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=a,this.moveLine&&(this.moveLine.visible=o),this.sizeText&&(this.sizeText.visible=h),a&&(this.updateOutlineBorder(),c&&(this.moveLine&&o&&this.updateMoveLine(),this.updateControlButtonsPosition()),h&&this.updateSizeTextPosition()),l&&this.outlineBorder.updateStyle({isDashed:l.isDashed,dashArray:l.dashArray})}getOperationState(){var r,o,a;const e=((r=this.scaleButton)==null?void 0:r.isCurrentlyScaling())||!1,i=((o=this.rotateButton)==null?void 0:o.isCurrentlyRotating())||!1,s=((a=this.moveButton)==null?void 0:a.isCurrentlyMoving())||!1;return{isDragging:!1,isScaling:e,isRotating:i,isMoving:s,hasAnyOperation:e||i||s}}stopAllOperations(){var e,i,s;(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(e,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const r=s[e],o=s[i];return{x:(r.x+o.x)/2,y:(r.y+o.y)/2}}destroy(){var e,i,s,r,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(r=this.scaleButton)==null||r.destroy(),(o=this.moveButton)==null||o.destroy(),(a=this.horizontalScaleButton)==null||a.destroy(),(h=this.verticalScaleButton)==null||h.destroy(),this.deleteButton=null,this.rotateButton=null,this.scaleButton=null,this.moveButton=null,this.horizontalScaleButton=null,this.verticalScaleButton=null,(l=this.outlineBorder)==null||l.destroy(),(c=this.moveLine)==null||c.destroy(),(d=this.sizeText)==null||d.destroy(),(u=this.controlButtons)==null||u.destroy(),super.destroy()}}function PS(n,t,e){return{outlineStrokeColor:String(n.outlineStrokeColor),outlineStrokeWidth:n.outlineStrokeWidth,outlineDashed:n.outlineDashed,outlineDashArray:n.outlineDashArray,outlineFillColor:n.outlineFillColor?String(n.outlineFillColor):void 0,outlineOffset:n.outlineOffset,iconWrapperFillColor:String(n.iconWrapperFillColor),deleteIconWrapperFillColor:"deleteIconWrapperFillColor"in n&&n.deleteIconWrapperFillColor!==void 0?String(n.deleteIconWrapperFillColor):void 0,showRotateButton:(e==null?void 0:e.showRotateButton)??n.showRotateButton,showScaleButton:(e==null?void 0:e.showScaleButton)??!0,showRadialScaleButton:e==null?void 0:e.showRadialScaleButton,showDeleteButton:(e==null?void 0:e.showDeleteButton)??!0,showMoveButton:(e==null?void 0:e.showMoveButton)??!0,rotateMode:e==null?void 0:e.rotateMode,scaleMode:"free",textColor:String(n.textColor),textPosition:n.textPosition,textOffset:n.textOffset,moveButtonOffset:t.moveButtonOffset,textFontSize:t.textFontSize,textFontFamily:t.textFontFamily,textFontWeight:t.textFontWeight}}function Vs(n,t){return{coords:n.coords,editControls:n.editControlManager,getZoneConfig:e=>MS(n,e),controlsConfig:n.getConfig().controls,makeControlFill:e=>new Qr(n,e),makeBorder:e=>new ri(n,e),render:{request:e=>n.getApp().requestRender(e,!0),stop:e=>n.getApp().stopRender(e)},events:t}}function MS(n,t){var i;const e=n.getConfig();if($e(t)){const s=e.controls[t];if(s)return s}else{const s=(i=e.customZoneTypes)==null?void 0:i[t];if(s)return s}return _h.cleanZone}class Ns extends W{constructor(e){super();f(this,"zoneData");f(this,"zoneType");f(this,"zoneConfig");f(this,"controlsConfig");f(this,"zoneEvents");f(this,"deps");f(this,"controlFill");f(this,"zoneBorder");f(this,"editableShape");f(this,"clickHandler",null);f(this,"initialZonePoints",[]);f(this,"dragStartPosition",null);f(this,"editing",!1);f(this,"resolvedMaxSizeCache",null);f(this,"handleDragStart",()=>{this.editing&&(this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.dragStartPosition=this.controlFill.getDragStartPosition(),this.deps.render.request("zone-drag"))});f(this,"handleDragMove",e=>{if(!this.editing||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;this.applyTranslation(s,r)});f(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.dragStartPosition=null,this.deps.render.stop("zone-drag"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleRotationStart",()=>{this.deps.render.request("zone-rotate")});f(this,"handleRotationMove",e=>{e&&(this.zoneData.points=e,this.drawZone(!1))});f(this,"handleScaleStart",()=>{this.deps.render.request("zone-scale")});f(this,"handleScaleMove",e=>{e&&(this.zoneData.points=e,this.drawZone())});f(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.deps.render.request("zone-move")});f(this,"handleMove",e=>{var a;if(!this.editing||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(a=this.editableShape.getMoveButton())==null?void 0:a.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{var e,i;this.initialZonePoints=[],this.deps.render.stop("zone-move"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleTransformEnd",()=>{var e,i;this.initialZonePoints=[],this.deps.render.stop("zone-rotate"),this.deps.render.stop("zone-scale"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.zoneEvents).onRemove)==null||i.call(e,this.zoneData.id)});f(this,"handleClick",()=>{var e,i;this.editing||(i=(e=this.zoneEvents)==null?void 0:e.onClick)==null||i.call(e,this.getZoneData())});const{deps:i,zoneData:s,zoneType:r}=e;this.deps=i,this.zoneType=r,this.zoneEvents=i.events,this.zoneConfig=i.getZoneConfig(r),this.controlsConfig=i.controlsConfig;const o=this.validateZoneShape(s.points);this.zoneData={...s,points:o},this.initializeComponents(),this.createEditControlLayer(),this.setupClickHandler(),this.applyEditing()}getResolvedMaxSize(){const e=this.zoneConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===e)return this.resolvedMaxSizeCache.value;const i=Us(this.zoneConfig.minSize,e,this.zoneType);return this.resolvedMaxSizeCache={key:e,value:i},i}validateZoneShape(e){if(e.length<4)return e;const i=this.getResolvedMaxSize();return this.deps.coords.validateShape(Sc(e),{minSize:ut(this.zoneConfig.minSize),maxSize:i!=null?ut(i):void 0})}initializeComponents(){this.controlFill=this.createControlFill(),this.addChild(this.controlFill),this.zoneBorder=this.createBorder(),this.addChild(this.zoneBorder)}createControlFill(){return this.deps.makeControlFill({points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:this.editing,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(){const e=this.editing?this.zoneConfig.editing:this.zoneConfig.normal;return this.deps.makeBorder({points:this.zoneData.points,closePath:!0,style:{color:this.zoneConfig.strokeColor,width:this.zoneConfig.strokeWidth,isDashed:e.isDashed,dashArray:e.dashArray}})}createEditControlLayer(){const e=PS(this.zoneConfig,this.controlsConfig,{showRotateButton:this.zoneConfig.showRotateButton,showRadialScaleButton:!1,rotateMode:"free"});this.editableShape=new Jr({editControls:this.deps.editControls});const i=this.getResolvedMaxSize(),s={config:e,zonePoints:this.zoneData.points,minSize:this.zoneConfig.minSize,maxSize:i??void 0,contentLayer:ke,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,onRotateEnd:this.handleTransformEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleTransformEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick}};this.editableShape.attach(this,{id:this.zoneData.id,topology:"quad",layerOptions:s,editingState:{showRotateButton:this.zoneConfig.showRotateButton,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,showBorder:!0,showSizeText:!0},idleState:{showRotateButton:!1,showScaleButton:!1,showRadialScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}applyTranslation(e,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawZone()}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new St(this,{onClick:this.handleClick,stopPropagation:!1})}drawZone(e=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.editableShape.updatePoints(i,e))}applyEditing(){this.controlFill.setInteractionEnabled(this.editing),this.updateBorderStyle(this.editing?this.zoneConfig.editing:this.zoneConfig.normal),this.editableShape.setEditing(this.editing),this.zIndex=this.editing?1e3:0}updateBorderStyle(e){this.zoneBorder.updateStyle({isDashed:e.isDashed,dashArray:e.dashArray})}setEditing(e){this.editing!==e&&(this.editing=e,this.applyEditing())}isEditing(){return this.editing}updateZoneData(e){const i=this.validateZoneShape(e.points);this.zoneData={...e,points:i},this.drawZone()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var e,i,s;this.editableShape.detach(),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.zoneBorder)==null||i.destroy(),(s=this.controlFill)==null||s.destroy(),super.destroy()}}class to extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickForbiddenSweepZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"forbiddenSweepZone"})}static create(t,e){return new to(t,{zoneData:e})}}class eo extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickForbiddenMopZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"forbiddenMopZone"})}static create(t,e){return new eo(t,{zoneData:e})}}class io extends Ns{constructor(t,e){super({deps:Vs(t,{onRemove:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onRemoveCleanZone)==null||r.call(s,i)},onUpdate:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onUpdateCleanZone)==null||r.call(s,i)},onClick:i=>{var s,r;(r=(s=t.events)==null?void 0:s.onClickCleanZone)==null||r.call(s,i)}}),zoneData:e.zoneData,zoneType:"cleanZone"})}static create(t,e){return new io(t,{zoneData:e})}}class Ne extends H{constructor(e,i){super();f(this,"lineOptions");f(this,"strokeContext",null);f(this,"drawDashLine",()=>{const{start:e,end:i,style:s}=this.lineOptions;this.clear(),this.strokeContext&&this.strokeContext.destroy();const r=this.appService;this.strokeContext=new gt;const o=r.getApp().toFixedSize(s.width);this.strokeContext.setStrokeStyle({color:s.color,width:o}),this.drawDashedLineToContext(this.strokeContext,e.x,e.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=e,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(e,i,s,r,o,a,h){const l=r-i,c=o-s,d=Math.sqrt(l*l+c*c);if(d===0)return;const u=this.appService,p=u.getApp().toFixedSize(a),g=u.getApp().toFixedSize(h),y=p+g,m=d/y,x=Math.round(m);if(x===0){e.moveTo(i,s),e.lineTo(r,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let C=0;C<x;C++){const _=C*S,R=_+v;if(_>=d)break;const M=Math.min(R,d),A=i+_*b,T=s+_*P,I=i+M*b,D=s+M*P;e.moveTo(A,T),e.lineTo(I,D)}}updatePoints(e,i){this.lineOptions.start=e,this.lineOptions.end=i,this.drawDashLine()}updateStyle(e){this.lineOptions.style={...this.lineOptions.style,...e},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Yt=class Yt extends W{constructor(e){super();f(this,"wallData");f(this,"wallConfig");f(this,"controlsConfig");f(this,"wallEvents");f(this,"appService");f(this,"wallLine");f(this,"outlineBorder");f(this,"moveLine");f(this,"lengthText");f(this,"controlButtons");f(this,"removeButton",null);f(this,"scaleButton",null);f(this,"moveButton",null);f(this,"initialWallPoints",[]);f(this,"initialButtonPosition",null);f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"resolvedMaxWidthCache",null);f(this,"throttledUpdateOutline");f(this,"throttledHandleScaleChange");f(this,"wallLineClickHandler",null);f(this,"handleRemove",()=>{var e,i;(i=(e=this.wallEvents).onRemove)==null||i.call(e,this.wallData.id)});f(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(e=>({...e}))});f(this,"finalizeOperation",()=>{var e,i;this.initialWallPoints=[],(i=(e=this.wallEvents).onUpdate)==null||i.call(e,this.getWallData())});f(this,"handleScaleStart",()=>{this.initializeOperation();const e=this.calculateOutlinePoints();e.length>Yt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...e[Yt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});f(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});f(this,"handleScaleEnd",()=>{this.finalizeOperation(),this.initialButtonPosition=null,this.appService.getApp().stopRender("virtualwall-scale")});f(this,"handleMoveStart",()=>{this.initializeOperation(),this.appService.getApp().requestRender("virtualwall-move",!0)});f(this,"handleMove",e=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(e.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{this.finalizeOperation(),this.appService.getApp().stopRender("virtualwall-move")});f(this,"handleScaleChange",()=>{this.redrawSolidLine(),this.setupWallLineHitArea()});f(this,"handleWallLinePointerDown",e=>{this.isEditingEnabled()&&(e.stopPropagation(),this.startDragging(e))});f(this,"handleDragPointerMove",e=>{!this.isDragging||!this.dragStartPosition||this.handleMove(e)});f(this,"handleDragPointerUp",()=>{this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.finalizeOperation())});const{appService:i,wallData:s,events:r={}}=e;this.appService=i,this.wallEvents=r,this.wallConfig=this.appService.controlsConfig.virtualWall,this.controlsConfig=this.appService.controlsConfig,this.wallData={...s,points:this.validateAndCorrectWallLength(s.points)},this.throttledHandleScaleChange=Pt(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=Pt(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("antiScale",this.throttledHandleScaleChange),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}getResolvedMaxWidth(){const e=this.wallConfig.maxWidth;if(this.resolvedMaxWidthCache&&this.resolvedMaxWidthCache.key===e)return this.resolvedMaxWidthCache.value;const i=Us(this.wallConfig.minWidth,e,"virtualWall");return this.resolvedMaxWidthCache={key:e,value:i},i}validateAndCorrectWallLength(e){if(e.length<2)return e;const[i,s]=e,{coords:r}=this.appService,o=r.toPixels(ut(this.wallConfig.minWidth)),a=this.getResolvedMaxWidth(),h=a!=null?r.toPixels(ut(a)):void 0,l=tt(i,s),c=l<o,d=h!=null&&l>h;if(!c&&!d)return e;if(l===0)return[i,{x:i.x+o,y:i.y}];const u=Dt(bt(i,s));let p=l;return h!=null&&(p=Math.min(p,h)),p=Math.max(p,o),[i,{x:i.x+u.x*p,y:i.y+u.y*p}]}isEditingEnabled(){return this.appService.runtimeSnapshot.editingVirtualWallIds.includes(this.wallData.id)}updateOutlineForScale(){this.isEditingEnabled()&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition())}initializeComponents(){this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.createWallLine(!1),this.addChild(this.wallLine),this.lengthText=this.createLengthText(),this.addChild(this.lengthText),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.controlButtons=new W,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.createControlButtons()}createWallLine(e=!0){const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:r,editing:o,normal:a}=this.wallConfig,l=this.isEditingEnabled()?o:a;l.isDashed?this.wallLine=new Ne(this.appService,{start:i[0],end:i[1],style:{color:r.toString(),width:s,dashArray:l.dashArray}}):this.wallLine=this.createSolidLine(i[0],i[1],s,r.toString()),e&&this.setupWallLineInteraction()}createLengthText(){const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e),s=new Es(this.appService,{text:i,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.wallConfig.textColor,align:"center"}});s.anchor.set(.5);const r=this.calculateTextPosition();s.position.set(r.x,r.y);const o=this.calculateTextRotation();return s.rotation=o,s.eventMode="none",s}calculateWallLengthInMeters(){const{points:e}=this.wallData;if(e.length<2)return 0;const i=tt(e[0],e[1]);return this.appService.coords.toMeters(Bt(i))}formatLengthText(e){const i=this.appService.coords.toDisplayUnit(ut(e)),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:e}=this.wallData;if(e.length<2)return{x:0,y:0};const[i,s]=e,r=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return _c(i,s,r)}calculateTextRotation(){const{points:e}=this.wallData;if(e.length<2)return 0;const[i,s]=e,r=this.appService.appContainer.getMapRotationRadians();return Ss(i,s,r)}getOutlineStyle(){return{color:this.wallConfig.outlineStrokeColor,width:this.wallConfig.outlineStrokeWidth,isDashed:this.wallConfig.outlineDashed,dashArray:this.wallConfig.outlineDashArray,fillColor:this.wallConfig.outlineFillColor}}createOutlineBorder(){const e=this.calculateOutlinePoints();return new ri(this.appService,{points:e,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);return new ri(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(e){const i=e||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),r=bx(i[0],i[1],s);return[r[3],r[2],r[1],r[0]]}calculateMoveLinePoints(e){if(e.length<4)return[];const{MOVE:i}=Yt.BUTTON_INDICES,s=e[i],r=this.calculateMoveButtonPosition();return[s,r]}calculateMoveButtonPosition(){const{moveButtonOffset:e}=this.controlsConfig,i=this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{MOVE:s}=Yt.BUTTON_INDICES,r=i[s],o=i[(s+3)%4],a=i[(s+1)%4],h=this.appService.getApp().toFixedSize(e);return Mc(r,a,o,h)}createControlButtons(){const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Yt.BUTTON_INDICES;this.removeButton=new Hc(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton=new vs(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,getTargetPoints:()=>this.calculateOutlinePoints(),getButtonIndex:()=>s,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[s].x,e[s].y);const r=this.calculateMoveButtonPosition();this.moveButton=new Uc(this.appService,{iconAlias:"moveIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(r.x,r.y),this.controlButtons.addChild(this.removeButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}applyScaleAndRotation(e){if(this.initialWallPoints.length<2)return;const[i,s]=this.initialWallPoints,r=i,o=this.calculateOutlinePoints(this.initialWallPoints);if(o.length<4)return;const a=o[Yt.BUTTON_INDICES.SCALE],l=bt(s,a),c={x:e.x-l.x,y:e.y-l.y},d=bt(r,c),u=tt(r,c),{coords:p}=this.appService,g=p.toPixels(ut(this.wallConfig.minWidth)),y=this.getResolvedMaxWidth(),m=y!=null?p.toPixels(ut(y)):void 0;let x;if(u<g)if(u===0)x={x:r.x+g,y:r.y};else{const S=Dt(d);x={x:r.x+S.x*g,y:r.y+S.y*g}}else if(m!=null&&u>m){const S=Dt(d);x={x:r.x+S.x*m,y:r.y+S.y*m}}else x=c;this.wallData.points=[r,x],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(e,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:e}=this.wallData;e.length<2||(this.wallLine instanceof Ne?this.wallLine.updatePoints(e[0],e[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const e=this.calculateTextPosition();this.lengthText.position.set(e.x,e.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e);const i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Yt.BUTTON_INDICES,r=this.calculateMoveButtonPosition();this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton.position.set(e[s].x,e[s].y),this.moveButton.position.set(r.x,r.y)}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.lengthText&&(this.lengthText.visible=e),e&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=e?1e3:0}createSolidLine(e,i,s,r){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(e.x,e.y),o.lineTo(i.x,i.y),o.stroke({color:r,width:a}),o}updateWallLineStyle(){const e=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:r,lineColor:o}=this.wallConfig,a=e?i:s;this.wallLine instanceof Ne!==a.isDashed?(this.removeChild(this.wallLine),this.wallLine.destroy(),this.createWallLine(!1),this.addChild(this.wallLine)):this.wallLine instanceof Ne?this.wallLine.updateStyle({color:o.toString(),width:r,dashArray:a.dashArray}):this.redrawSolidLine()}redrawSolidLine(){const e=this.appService;if(!this.wallLine||this.wallLine instanceof Ne)return;const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:r}=this.wallConfig,o=e.getApp().toFixedSize(s);this.wallLine.clear(),this.wallLine.setStrokeStyle({color:r.toString(),width:o}).moveTo(i[0].x,i[0].y).lineTo(i[1].x,i[1].y).stroke()}setupWallLineInteraction(){var i;if(!this.wallLine)return;this.setupWallLineHitArea();const e=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),e?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new St(this.wallLine,{onClick:()=>{var s,r;this.appService.gestureController.suppressMapClick(),(r=(s=this.wallEvents)==null?void 0:s.onClick)==null||r.call(s,this.getWallData())},stopPropagation:!1})}startDragging(e){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(e.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:e}=this.wallData;if(e.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),r=Pc(e[0],e[1],s);if(r.length===0)return;const o=new Re(r);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(e){this.wallData={...e,points:this.validateAndCorrectWallLength(e.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var e,i,s,r,o,a,h,l,c,d;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.wallLine&&this.wallLine.off("pointerdown",this.handleWallLinePointerDown),(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,(s=this.wallLine)==null||s.destroy(),(r=this.lengthText)==null||r.destroy(),(o=this.outlineBorder)==null||o.destroy(),(a=this.moveLine)==null||a.destroy(),(h=this.controlButtons)==null||h.destroy(),(l=this.removeButton)==null||l.destroy(),(c=this.scaleButton)==null||c.destroy(),(d=this.moveButton)==null||d.destroy(),this.removeButton=null,this.scaleButton=null,this.moveButton=null,super.destroy()}};f(Yt,"BUTTON_INDICES",{REMOVE:0,SCALE:2,MOVE:3});let yr=Yt;const TS={fontSize:12,fontFamily:"system-ui, -apple-system, sans-serif",fontWeight:"400",color:"#5d68fe",position:"top",offset:-8,editing:{visible:!0},normal:{visible:!0}};class so extends W{constructor(e){super();f(this,"spotData");f(this,"spotConfig");f(this,"controlsConfig");f(this,"spotEvents");f(this,"appService");f(this,"controlFill");f(this,"spotBorder");f(this,"centerIcon");f(this,"sizeText");f(this,"nameText");f(this,"clickHandler",null);f(this,"initialSpotPoint",null);f(this,"dragStartMousePosition",null);f(this,"throttledUpdateScale");f(this,"unsubscribeMapRotation",null);f(this,"handleDragStart",e=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("spot-drag",!0))});f(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartMousePosition.x,r=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,r)});f(this,"handleDragEnd",()=>{var e,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(e=this.spotEvents).onUpdate)==null||i.call(e,this.getSpotData())});const{appService:i,spotData:s,events:r={}}=e;this.appService=i,this.spotData=s,this.spotEvents=r,this.controlsConfig=this.appService.controlsConfig,this.spotConfig=this.appService.controlsConfig.spot,this.position.set(s.point.x,s.point.y),this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.setupClickHandler(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(){this.isEditingEnabled()&&this.sizeText&&this.updateSizeTextPosition(),this.nameText&&this.updateNameTextPosition()}isEditingEnabled(){return this.appService.runtimeSnapshot.editingSpotIds.includes(this.spotData.id)}shouldShowIcon(){return(this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal).showIcon}calculateRectanglePoints(){const{size:e}=this.spotConfig;if(e===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.coords.toPixels(ut(e))/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const e=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(e),this.addChild(this.controlFill),this.spotBorder=this.createBorder(e),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.calculateSpotNameText()&&(this.nameText=this.createNameText(),this.addChild(this.nameText)),this.drawSpot()}createControlFill(e){const i=this.isEditingEnabled();return new Qr(this.appService,{points:e,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(e){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new ri(this.appService,{points:e,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const e=new Ut(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.eventMode="static",this.setupIconDrag(e),e.visible=!1,e}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s,iconAnchor:r}=this.spotConfig;await e.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),r&&e.anchor.set(r.x,r.y),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",o=>{this.applyAntiRotation(o)})),e.visible=this.shouldShowIcon()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupIconDrag(e){let i=null,s=!1;const r=a=>{if(!s||!this.initialSpotPoint||!i)return;const h=this.parent.toLocal(a.global),l=h.x-i.x,c=h.y-i.y;this.applyTranslation(l,c)},o=()=>{var a,h;s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),(h=(a=this.spotEvents).onUpdate)==null||h.call(a,this.getSpotData()))};e.on("pointerdown",a=>{if(!this.isEditingEnabled())return;a.stopPropagation(),s=!0,this.initialSpotPoint={...this.spotData.point},i=this.parent.toLocal(a.global),this.appService.getApp().requestRender("spot-drag",!0);const h=this.appService.gestureController.hijack(a);h.onMove(r),h.onEnd(o)})}createSizeText(){const e=this.calculateSpotSizeText(),i=new Es(this.appService,{text:e,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.spotConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotSizeText(){const{size:e}=this.spotConfig,i=this.appService.coords.toDisplayUnit(ut(e)),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const{textPosition:e,textOffset:i}=this.spotConfig;return this.calculateTextPosition(e,i)}calculateTextPosition(e,i){const s=this.calculateRectanglePoints();if(s.length<4)return{x:0,y:0};const[r,o,a,h]=s,l=this.appService.getApp().toFixedSize(i);let c,d;switch(e){case"top":{c={x:(r.x+o.x)/2,y:(r.y+o.y)/2},d={x:c.x,y:c.y+l};break}case"right":{c={x:(o.x+a.x)/2,y:(o.y+a.y)/2},d={x:c.x+l,y:c.y};break}case"bottom":{c={x:(h.x+a.x)/2,y:(h.y+a.y)/2},d={x:c.x,y:c.y+l};break}case"left":{c={x:(r.x+h.x)/2,y:(r.y+h.y)/2},d={x:c.x-l,y:c.y};break}default:{c={x:(r.x+o.x)/2,y:(r.y+o.y)/2},d={x:c.x,y:c.y+l};break}}return d}getNameLabelConfig(){return this.spotConfig.nameLabel??TS}createNameText(){const e=this.getNameLabelConfig(),i=new Es(this.appService,{text:this.calculateSpotNameText(),style:{fontSize:e.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fill:e.color,align:"center"}});i.anchor.set(.5);const s=this.calculateNameTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotNameText(){var e;return((e=this.spotData.name)==null?void 0:e.trim())??""}calculateNameTextPosition(){const{position:e,offset:i}=this.getNameLabelConfig();return this.calculateTextPosition(e,i)}shouldShowNameText(){if(!this.calculateSpotNameText())return!1;const i=this.isEditingEnabled(),s=this.getNameLabelConfig();return(i?s.editing:s.normal).visible}applyTranslation(e,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+e,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const e=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new St(e,{onClick:()=>{var i,s;this.isEditingEnabled()||(this.appService.gestureController.suppressMapClick(),(s=(i=this.spotEvents)==null?void 0:i.onClick)==null||s.call(i,this.getSpotData()))},stopPropagation:!1}),this.eventMode="static"}drawSpot(){const e=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(e),this.spotBorder&&this.spotBorder.updatePoints(e)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText(),this.nameText&&this.updateNameText()}updateSizeText(){if(!this.sizeText)return;const e=this.calculateSpotSizeText();this.sizeText.updateText(e),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y)}updateNameText(){this.nameText&&(this.nameText.updateText(this.calculateSpotNameText()),this.updateNameTextPosition())}updateNameTextPosition(){if(!this.nameText)return;const e=this.calculateNameTextPosition();this.nameText.position.set(e.x,e.y)}updateEditState(){const e=this.isEditingEnabled(),i=e?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=e&&this.spotConfig.showText),this.nameText&&(this.nameText.visible=this.shouldShowNameText()),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(e),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=e?1e3:0}updateSpotData(e){this.spotData={...e},!this.nameText&&this.calculateSpotNameText()&&(this.nameText=this.createNameText(),this.addChild(this.nameText)),this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var e,i,s,r,o,a;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.centerIcon&&this.spotConfig.size===0&&this.centerIcon.removeAllListeners(),(i=this.controlFill)==null||i.destroy(),(s=this.spotBorder)==null||s.destroy(),(r=this.centerIcon)==null||r.destroy(),(o=this.sizeText)==null||o.destroy(),(a=this.nameText)==null||a.destroy(),super.destroy()}static create(e,i){return new so({appService:e,spotData:i,events:{onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdateSpot)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickSpot)==null||o.call(r,s)}}})}}const AS=16777215;class no extends W{constructor(e){super();f(this,"purifyPointData");f(this,"config");f(this,"events");f(this,"appService");f(this,"icon");f(this,"clickHandler",null);f(this,"initialPoint",null);f(this,"isOutOfBounds",!1);f(this,"lastValidPoint",null);f(this,"unsubscribeMapRotation",null);const{appService:i,purifyPointData:s,events:r={}}=e;this.appService=i,this.purifyPointData=s,this.events=r,this.config=i.controlsConfig.purifyPoint,this.position.set(s.point.x,s.point.y),this.initializeComponents(),this.updateEditState(),this.setupClickHandler()}initializeComponents(){this.icon=new Ut(this.appService),this.icon.eventMode="static",this.icon.position.set(0,0),this.setupDrag(this.icon),this.addChild(this.icon),this.loadIconTexture(this.icon),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",e=>{this.applyAntiRotation(e)})}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s}=this.config;await e.loadTextureAndSetSize("purifyIcon",{width:i,height:i,sizeFixed:s}),!this.destroyed&&(this.applyAntiRotation(this.appService.runtime.mapRotation),e.visible=!0,this.applyOutOfBoundsTint())}isEditingEnabled(){return(this.appService.runtimeSnapshot.editingPurifyPointIds??[]).includes(this.purifyPointData.id)}applyOutOfBoundsTint(){const{outOfBoundsTint:e}=this.config;this.icon.tint=this.isOutOfBounds&&e!==void 0?e:AS}applyAntiRotation(e){this.rotation=-e*Math.PI/180}setupDrag(e){let i=null,s=!1;const r=a=>{if(!s||!this.initialPoint||!i)return;const h=this.parent.toLocal(a.global),l=h.x-i.x,c=h.y-i.y;this.applyTranslation(l,c),this.evaluateRoomBounds()},o=()=>{var a,h;s&&(s=!1,this.initialPoint=null,i=null,this.isOutOfBounds&&this.lastValidPoint&&(this.purifyPointData.point={...this.lastValidPoint},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y)),this.isOutOfBounds=!1,this.lastValidPoint=null,this.applyOutOfBoundsTint(),this.appService.getApp().stopRender("purify-point-drag"),(h=(a=this.events).onUpdate)==null||h.call(a,this.getPurifyPointData()))};e.on("pointerdown",a=>{if(!this.isEditingEnabled())return;a.stopPropagation(),s=!0,this.initialPoint={...this.purifyPointData.point},i=this.parent.toLocal(a.global),this.isOutOfBounds=!1,this.lastValidPoint={...this.purifyPointData.point},this.appService.getApp().requestRender("purify-point-drag",!0);const h=this.appService.gestureController.hijack(a);h.onMove(r),h.onEnd(o)})}applyTranslation(e,i){this.initialPoint&&(this.purifyPointData.point={x:this.initialPoint.x+e,y:this.initialPoint.y+i},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y))}evaluateRoomBounds(){const{roomId:e}=this.purifyPointData;if(e===void 0){this.lastValidPoint={...this.purifyPointData.point};return}const i=this.appService.mapManager.isPointInRoom(this.purifyPointData.point,e);i&&(this.lastValidPoint={...this.purifyPointData.point});const s=!i;s!==this.isOutOfBounds&&(this.isOutOfBounds=s,this.applyOutOfBoundsTint())}setupClickHandler(){this.clickHandler=new St(this.icon,{onClick:()=>{var e,i;this.isEditingEnabled()||(this.appService.gestureController.suppressMapClick(),(i=(e=this.events)==null?void 0:e.onClick)==null||i.call(e,this.getPurifyPointData()))},stopPropagation:!1}),this.eventMode="static"}updateEditState(){this.zIndex=this.isEditingEnabled()?1e3:0}updatePurifyPointData(e){this.purifyPointData={...e},this.position.set(this.purifyPointData.point.x,this.purifyPointData.point.y),this.updateEditState()}getPurifyPointData(){return{...this.purifyPointData}}refreshDisplay(){this.applyOutOfBoundsTint()}destroy(){var e,i,s;this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.icon)==null||i.removeAllListeners(),(s=this.icon)==null||s.destroy(),super.destroy()}static create(e,i){return new no({appService:e,purifyPointData:i,events:{onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdatePurifyPoint)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickPurifyPoint)==null||o.call(r,s)}}})}}class RS extends Gc{constructor(e){const{appService:i,wayPointData:s,order:r,events:o={}}=e;super(i);f(this,"wayPointData");f(this,"order");f(this,"wayPointConfig");f(this,"controlsConfig");f(this,"wayPointEvents");f(this,"icon");f(this,"orderContainer");f(this,"orderBackground");f(this,"orderText");f(this,"clickHandler",null);f(this,"initialWayPointPoint",null);f(this,"unsubscribeMapRotation",null);this.wayPointData=s,this.order=r,this.wayPointEvents=o,this.controlsConfig=this.appService.controlsConfig,this.wayPointConfig=this.appService.controlsConfig.wayPoint,this.position.set(s.point.x,s.point.y),this.initializeComponents(),this.updateEditState(),this.setupClickHandler()}isEditingEnabled(){return(this.appService.runtimeSnapshot.editingWayPointIds||[]).includes(this.wayPointData.id)}initializeComponents(){this.icon=this.createIcon(),this.addChild(this.icon),this.wayPointConfig.showOrder&&(this.createOrderContainer(),this.addChild(this.orderContainer))}createIcon(){const e=new Ut(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.anchor.set(.5,1),e.eventMode="static",this.setupIconDrag(e),e}async loadIconTexture(e){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:r}=s,o=i?"wayPointActive":"wayPoint";await e.loadTextureAndSetSize(o,{width:r,height:r,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),e.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:r}=i;this.orderContainer=new W,this.orderBackground=new H,this.orderText=new Os({text:this.order.toString(),style:new de({fontSize:r.fontSize,fontFamily:r.fontFamily,fontWeight:r.fontWeight,fill:r.color,align:"center",trim:!0})}),this.orderBackground.clear(),this.orderBackground.circle(0,0,s.size/2),this.orderBackground.fill({color:s.backgroundColor}),this.orderText.anchor.set(.5,.5),this.orderContainer.addChild(this.orderBackground),this.orderContainer.addChild(this.orderText),this.orderContainer.eventMode="none",this.orderContainer.visible=this.wayPointConfig.showOrder,this.updateOrderPosition()}updateOrderPosition(){if(!this.orderContainer)return;const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{offsetX:s,offsetY:r}=i.orderContainer;this.orderContainer.position.set(s,-r)}setupIconDrag(e){let i=null,s=null,r=!1;const o=h=>{if(!(!r||!i||!s)&&this.parent){const l=this.parent.toLocal(h.global),c=l.x-i.x,d=l.y-i.y,u={x:s.x+c,y:s.y+d};this.wayPointData.point=u,this.position.set(u.x,u.y),this.orderContainer&&this.updateOrderPosition()}},a=()=>{var h,l;r&&(r=!1,i=null,s=null,(l=(h=this.wayPointEvents).onUpdate)==null||l.call(h,this.wayPointData))};e.on("pointerdown",h=>{if(this.isEditingEnabled()&&(h.stopPropagation(),s={...this.wayPointData.point},this.parent&&(i=this.parent.toLocal(h.global)),r=!0,this.parent)){const l=this.appService.gestureController.hijack(h);l.onMove(o),l.onEnd(a)}})}setupClickHandler(){this.clickHandler=new St(this.icon,{stopPropagation:!1,onClick:()=>{var e,i;this.appService.gestureController.suppressMapClick(),(i=(e=this.wayPointEvents).onClick)==null||i.call(e,this.wayPointData)}})}updateWayPoint(e){this.wayPointData=e,this.drawWayPoint()}updateOrder(e){this.order=e,this.orderText&&(this.orderText.text=e.toString())}getWayPointData(){return{...this.wayPointData}}drawWayPoint(){this.position.set(this.wayPointData.point.x,this.wayPointData.point.y),this.orderContainer&&this.updateOrderPosition()}updateEditState(){if(this.loadIconTexture(this.icon),this.orderContainer&&this.orderText&&this.orderBackground){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal;this.orderText.style=new de({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor:r}=i.orderContainer;this.orderBackground.clear(),this.orderBackground.circle(0,0,s/2).fill(r),this.orderContainer.visible=this.wayPointConfig.showOrder,this.updateOrderPosition()}}onEditStateChange(){this.updateEditState()}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.icon&&this.icon.removeAllListeners(),super.destroy()}}class uh extends H{constructor(e,i){super();f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"initialPosition");f(this,"gestureSession",null);f(this,"handleDragPointerMove",e=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y,o={x:this.initialPosition.x+s,y:this.initialPosition.y+r};this.position.set(o.x,o.y),(h=(a=this.options).onDragMove)==null||h.call(a,o)});f(this,"handleDragPointerUp",()=>{var i,s;if(this.gestureSession=null,!this.isDragging)return;const e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=e,this.options=i,this.initialPosition={...i.position},this.position.set(i.position.x,i.position.y),this.eventMode="static",this.cursor="pointer",this.setupEvents(),this.draw()}draw(){const e=this.appService,{config:i}=this.options,s=e.getApp().toFixedSize(i.endPointSize),r=e.getApp().toFixedSize(i.endPointStrokeWidth);this.clear(),this.circle(0,0,s/2),this.fill({color:i.endPointColor}),this.stroke({color:i.endPointStrokeColor,width:r}),this.setupHitArea()}setupHitArea(){const e=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),r=e.getApp().toFixedSize(s);this.hitArea=new Bs(0,0,r)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startDragging(e)}startDragging(e){var s,r;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(e.global),this.initialPosition={x:this.x,y:this.y},(r=(s=this.options).onDragStart)==null||r.call(s),i.getApp().requestRender("endpoint-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}updatePosition(e){this.position.set(e.x,e.y),this.initialPosition={...e}}getPosition(){return{x:this.x,y:this.y}}redraw(){this.draw()}destroy(){var e;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.off("pointerdown",this.handlePointerDown),super.destroy()}}class kS extends W{constructor(e){super();f(this,"endPoints");f(this,"dividerConfig");f(this,"dividerEvents");f(this,"roomId");f(this,"appService");f(this,"roomGeometry",null);f(this,"dashLine");f(this,"solidLine",null);f(this,"startEndPoint");f(this,"endEndPoint");f(this,"solidLinePoints",null);f(this,"initialDividerPoints",[]);f(this,"isDragging",!1);f(this,"dragStartPosition",null);f(this,"gestureSession",null);f(this,"throttledHandleScaleChange");f(this,"handleEndPointDragStart",()=>{this.initialDividerPoints=this.endPoints.map(e=>({...e})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});f(this,"handleEndPointDragMove",(e,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[e]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});f(this,"handleEndPointDragEnd",()=>{var e,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints())});f(this,"handleDashLinePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});f(this,"handleDragPointerMove",e=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;this.endPoints=this.initialDividerPoints.map(o=>({x:o.x+s,y:o.y+r})),this.updateAllComponents()});f(this,"handleDragPointerUp",()=>{var e,i;this.gestureSession=null,this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});f(this,"handleScaleChange",()=>{var e,i;(e=this.startEndPoint)==null||e.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:r,events:o={}}=e;this.appService=i,this.dividerEvents=o,this.roomId=r,this.dividerConfig=this.appService.dividerConfig,this.roomGeometry=this.appService.mapManager.getRoomById(this.roomId)||null,s?this.endPoints=this.validateDividerPoints(s):this.endPoints=this.createDefaultdividerPoints(),this.throttledHandleScaleChange=Pt(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener()}validateDividerPoints(e){if(e.length>=2)return e.slice(0,2);const i=e[0]||{x:0,y:0},s={x:i.x+50,y:i.y};return[i,s]}createDefaultdividerPoints(){if(!this.roomGeometry)return w.warn("Room geometry not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const e=this.appService.getApp().mapState;if(!e)return w.warn("Map state not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const{boundingBox:i}=this.roomGeometry,s=this.appService.getApp().toFixedSize(this.dividerConfig.defaultExtension),r=this.dividerConfig.defaultDirection,o=i.x+i.width/2,a=i.y+i.height/2,h=r==="horizontal"?i.width+2*s:i.height+2*s;return kx(o,a,h,r).map(c=>({x:c.x-e.origin.x,y:c.y-e.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const e=this.endPoints;if(e.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:r}=this.dividerConfig;this.dashLine=new Ne(this.appService,{start:e[0],end:e[1],style:{color:r.toString(),width:i,dashArray:s}})}createEndPoints(){const e=this.endPoints;this.startEndPoint=new uh(this.appService,{position:e[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new uh(this.appService,{position:e[1],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(1,i),onDragEnd:this.handleEndPointDragEnd})}setupDashLineInteraction(){this.dashLine&&(this.setupDashLineHitArea(),this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.dashLine.on("pointerdown",this.handleDashLinePointerDown))}setupDashLineHitArea(){if(!this.dashLine)return;const e=this.endPoints;if(e.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),r=Pc(e[0],e[1],s);if(r.length===0)return;const o=new Re(r);this.dashLine.hitArea=o}startDragging(e){this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialDividerPoints=this.endPoints.map(s=>({...s})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-drag",!0),this.gestureSession=this.appService.gestureController.hijack(e),this.gestureSession.onMove(this.handleDragPointerMove),this.gestureSession.onEnd(this.handleDragPointerUp)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const e=this.endPoints;e.length<2||!this.dashLine||this.dashLine.updatePoints(e[0],e[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(e);this.solidLine.clear(),this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke()}updateEndPoints(){const e=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(e[0]),this.endEndPoint&&this.endEndPoint.updatePosition(e[1])}registerScaleListener(){const{emitter:e}=this.appService;e.on("antiScale",this.throttledHandleScaleChange)}getDividerEndPoints(){return[...this.endPoints]}getEffectiveDividerPoints(){return this.solidLinePoints?[...this.solidLinePoints]:null}calculateAndCreateSolidLine(){if(this.clearSolidLine(),typeof this.roomId!="number"||!this.getRoomGraphics())return;const i=this.calculateLineRoomIntersection();i&&i.length>=2&&(this.solidLinePoints=[i[0],i[i.length-1]],this.createSolidLine())}getRoomGraphics(){const e=this.appService.mapManager.roomFill;return!e||typeof this.roomId!="number"?null:e.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const e=this.endPoints;if(e.length<2||typeof this.roomId!="number")return null;const[i,s]=e,r=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(r||o)return null;const a=ux(i,s),h=[];for(const p of a)this.isPointInRoomFill(p)&&h.push(p);if(h.length===0)return null;const l=h[0],c=h[h.length-1];return tt(l,c)<3?null:Ex(l,c,.5)}isPointInRoomFill(e){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:e.x+i.origin.x,y:e.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(e){e.x-=.5,e.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const r=s.getRasterRoomData(this.roomId);if(!r)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(e.x),h=Math.round(e.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<r.pixelIndices.length;c++)if(r.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(e){const i={x:Math.round(e.x),y:Math.round(e.y)},s=this.appService.getApp().mapState,r=this.appService.mapManager.getRoomById(this.roomId);return!s||!r||!r.outlinePoints?!1:kt(i,r.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:e}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const r={x:i[0].x+s.origin.x,y:i[0].y+s.origin.y},o={x:i[1].x+s.origin.x,y:i[1].y+s.origin.y};return!Rx(r,o,e.x,e.y,e.width,e.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:e}=this.appService.dividerConfig;e&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var e,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.endPoints)}updateComponents(){const e=this.endPoints;e.length>=2&&(this.dashLine.updatePoints(e[0],e[1]),this.startEndPoint.position.set(e[0].x,e[0].y),this.endEndPoint.position.set(e[1].x,e[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(e);this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke(),this.addChildAt(this.solidLine,0)}clearSolidLine(){this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.solidLinePoints=null}updatedividerPoints(e){this.endPoints=this.validateDividerPoints(e),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var e,i,s,r;this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[]),(e=this.gestureSession)==null||e.cancel(),this.gestureSession=null,this.dashLine&&this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.clearSolidLine(),(i=this.dashLine)==null||i.destroy(),(s=this.startEndPoint)==null||s.destroy(),(r=this.endEndPoint)==null||r.destroy(),super.destroy()}}const xr=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","purifyPoint","wayPoint","divider"];function ES(n){if(!n||n.length===0)return[...xr];const t=new Set,e=[];for(const i of n)t.has(i)||(t.add(i),e.push(i));for(const i of xr)t.has(i)||e.push(i);return e}class IS{constructor(t){f(this,"zoneMaps",new Map);f(this,"virtualWallMap",new Map);f(this,"spotMap",new Map);f(this,"purifyPointMap",new Map);f(this,"wayPointMap",new Map);f(this,"divider",null);f(this,"controlContainers",new Map);f(this,"unsubscribeFns",[]);f(this,"builtinZoneFactories",{forbiddenSweepZone:t=>to.create(this.appService,t),forbiddenMopZone:t=>eo.create(this.appService,t),cleanZone:t=>io.create(this.appService,t)});this.appService=t,this.initializeControlContainers();const e=O(t.runtime,"editingForbiddenSweepZoneIds",p=>{w.log(`[runtime] editingForbiddenSweepZoneIds: ${p}`);const g=this.zoneMaps.get("forbiddenSweepZone");g&&this.updateZonesEditState("forbiddenSweepZone",g)}),i=O(t.runtime,"editingForbiddenMopZoneIds",p=>{w.log(`[runtime] editingForbiddenMopZoneIds: ${p}`);const g=this.zoneMaps.get("forbiddenMopZone");g&&this.updateZonesEditState("forbiddenMopZone",g)}),s=O(t.runtime,"editingCleanZoneIds",p=>{w.log(`[runtime] editingCleanZoneIds: ${p}`);const g=this.zoneMaps.get("cleanZone");g&&this.updateZonesEditState("cleanZone",g)}),r=O(t.runtime,"editingCustomZoneIds",p=>{w.log(`[runtime] editingCustomZoneIds: ${JSON.stringify(p??{})}`);for(const[g,y]of this.zoneMaps)$e(g)||y.size&&this.updateZonesEditState(g,y)}),o=O(t.runtime,"editingVirtualWallIds",p=>{w.log(`[runtime] editingVirtualWallIds: ${p}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),a=O(t.runtime,"editingSpotIds",p=>{w.log(`[runtime] editingSpotIds: ${p}`),this.updateSpotsEditState(this.spotMap)}),h=O(t.runtime,"editingPurifyPointIds",p=>{w.log(`[runtime] editingPurifyPointIds: ${p}`),this.updatePurifyPointsEditState(this.purifyPointMap)}),l=O(t.runtime,"editingWayPointIds",p=>{w.log(`[runtime] editingWayPointIds: ${p}`),this.updateWayPointsEditState(this.wayPointMap)}),c=O(t.runtime,"dividingRoomId",p=>{w.log(`[runtime] dividingRoomId: ${p}`),this.handleDividingRoomIdChange(p)}),d=O(t.runtime,"unit",p=>{w.log(`[runtime] unit changed: ${p}`),this.handleUnitChange()}),u=O(t.runtime,"unitLabel",p=>{w.log(`[runtime] unitLabel changed: ${p}`),this.handleUnitChange()});this.unsubscribeFns.push(e,i,s,r,o,a,h,l,c,d,u)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const t=this.appService.appContainer.getLayer(ke);if(!t){w.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const e of xr){const i=new W;i.label=`controls:${e}`,this.controlContainers.set(e,i),t.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const t=this.appService.appContainer.getLayer(ke);if(!t)return;ES(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const r=this.controlContainers.get(i);r&&(r.zIndex=s)}),t.sortableChildren=!0,t.sortChildren()}addToControlLayer(t,e){let i=this.controlContainers.get(t);if(!i){const s=this.appService.appContainer.getLayer(ke);if(!s){w.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new W,i.label=`controls:${t}`,this.controlContainers.set(t,i),s.addChild(i),this.applyRenderOrder()}i.addChild(e)}drawForbiddenSweepZones(t){this.drawZonesByType("forbiddenSweepZone",t)}getForbiddenSweepZones(){return this.getZonesDataByType("forbiddenSweepZone")}clearAllForbiddenSweepZones(){this.clearAllZonesByType("forbiddenSweepZone")}drawForbiddenMopZones(t){this.drawZonesByType("forbiddenMopZone",t)}getForbiddenMopZones(){return this.getZonesDataByType("forbiddenMopZone")}clearAllForbiddenMopZones(){this.clearAllZonesByType("forbiddenMopZone")}drawCleanZones(t){this.drawZonesByType("cleanZone",t)}getCleanZones(){return this.getZonesDataByType("cleanZone")}clearAllCleanZones(){this.clearAllZonesByType("cleanZone")}drawVirtualWalls(t){var r;const e=this.appService,i=this.virtualWallMap,s=new Set(t.map(o=>o.id));for(const[o,a]of i)s.has(o)||((r=a.parent)==null||r.removeChild(a),a.destroy(),i.delete(o));t.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new yr({appService:e,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickVirtualWall)==null||d.call(c,l)}}});i.set(o.id,h),this.addToControlLayer("virtualWall",h)}})}getVirtualWalls(){return this.getWallsData(this.virtualWallMap)}clearAllVirtualWalls(){this.clearAllWalls(this.virtualWallMap)}drawSpots(t){const e=this.spotMap;if(!t||t.length===0){this.clearAllSpotsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(r=>r.id));for(const r of i)s.has(r)||this.removeSpot(r,e);t.forEach(r=>{const o=e.get(r.id);o?this.isSpotDataEqual(o.getSpotData(),r)||o.updateSpotData(r):this.addNewSpot(r,e)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}drawPurifyPoints(t){const e=this.purifyPointMap;if(!t||t.length===0){this.clearAllPurifyPointsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(r=>r.id));for(const r of i)s.has(r)||this.removePurifyPoint(r,e);t.forEach(r=>{const o=e.get(r.id);o?this.isPurifyPointDataEqual(o.getPurifyPointData(),r)||o.updatePurifyPointData(r):this.addNewPurifyPoint(r,e)})}getPurifyPoints(){return this.getPurifyPointsData(this.purifyPointMap)}clearAllPurifyPoints(){this.clearAllPurifyPointsInternal(this.purifyPointMap)}getZoneMap(t){let e=this.zoneMaps.get(t);return e||(e=new Map,this.zoneMaps.set(t,e)),e}resolveZoneFactory(t){var s;const e=this.builtinZoneFactories[t];return e||((s=this.appService.getConfig().customZoneTypes)!=null&&s[t]?r=>new Ns({deps:Vs(this.appService,{onRemove:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onRemoveCustomZone)==null?void 0:h.call(a,t,o)},onUpdate:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onUpdateCustomZone)==null?void 0:h.call(a,t,o)},onClick:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onClickCustomZone)==null?void 0:h.call(a,t,o)}}),zoneData:r,zoneType:t}):null)}drawCustomZones(t,e){this.drawZonesByType(t,e)}getCustomZones(t){return this.getZonesDataByType(t)}clearCustomZones(t){this.clearAllZonesByType(t)}drawZonesByType(t,e){const i=this.resolveZoneFactory(t);if(!i){w.warn(`[ControlsManager] Unknown zone type: ${t}`);return}const s=this.getZoneMap(t);this.drawZonesImpl(e,s,i,t)}getZonesDataByType(t){const e=this.zoneMaps.get(t);return e?this.getZonesData(e):[]}clearAllZonesByType(t){const e=this.zoneMaps.get(t);e&&this.clearAllZones(e)}drawZonesImpl(t,e,i,s){if(!t||t.length===0){this.clearAllZones(e);return}const r=new Set(e.keys()),o=new Set(t.map(a=>a.id));for(const a of r)o.has(a)||this.removeZone(a,e);t.forEach(a=>{const h=e.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,e,i,s)})}addNewZone(t,e,i,s){const r=i(t);e.set(t.id,r),this.addToControlLayer(s,r),r.setEditing(this.getEditingZoneIds(String(s)).includes(t.id))}removeZone(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getZonesData(t){const e=[];return t.forEach(i=>{e.push(i.getZoneData())}),e}clearAllZones(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}getEditingZoneIds(t){var i;const e=this.appService.runtimeSnapshot;switch(t){case"forbiddenSweepZone":return e.editingForbiddenSweepZoneIds;case"forbiddenMopZone":return e.editingForbiddenMopZoneIds;case"cleanZone":return e.editingCleanZoneIds;default:return((i=e.editingCustomZoneIds)==null?void 0:i[t])??[]}}updateZonesEditState(t,e){const i=this.getEditingZoneIds(t);e.forEach((s,r)=>{s.setEditing(i.includes(r))})}updateVirtualWallsEditState(t){t.forEach(e=>{e.updateEditingState()})}isZoneDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],r=e.points[i];if(Math.abs(s.x-r.x)>.1||Math.abs(s.y-r.y)>.1)return!1}return!0}getWallsData(t){return Array.from(t.values()).map(e=>e.getWallData())}clearAllWalls(t){for(const e of t.values())e.destroy();t.clear()}isWallDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],r=e.points[i];if(Math.abs(s.x-r.x)>.1||Math.abs(s.y-r.y)>.1)return!1}return!0}addNewSpot(t,e){const i=so.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("spot",i)}removeSpot(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getSpotsData(t){const e=[];return t.forEach(i=>{e.push(i.getSpotData())}),e}clearAllSpotsInternal(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}updateSpotsEditState(t){t.forEach(e=>{e.updateEditState()})}isSpotDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1?!1:t.name===e.name}addNewPurifyPoint(t,e){const i=no.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("purifyPoint",i)}removePurifyPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getPurifyPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getPurifyPointData())}),e}clearAllPurifyPointsInternal(t){t.forEach(e=>{var i;(i=e.parent)==null||i.removeChild(e),e.destroy()}),t.clear()}updatePurifyPointsEditState(t){t.forEach(e=>{e.updateEditState()})}isPurifyPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1?!1:t.name===e.name}drawWayPoints(t){w.log("[ControlsManager] drawWayPoints",t);const e=Array.from(this.wayPointMap.keys()),i=t.map(r=>r.id);e.filter(r=>!i.includes(r)).forEach(r=>{this.removeWayPoint(r,this.wayPointMap)}),t.forEach((r,o)=>{const a=o+1,h=this.wayPointMap.get(r.id);h?(this.isWayPointDataEqual(h.getWayPointData(),r)||h.updateWayPoint(r),h.updateOrder(a)):this.addNewWayPoint(r,a,this.wayPointMap)})}clearAllWayPoints(){w.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(t,e,i){var o,a;const s=this.appService,r=new RS({appService:s,wayPointData:t,order:e,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(t.id,r),this.addToControlLayer("wayPoint",r)}removeWayPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getWayPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getWayPointData())}),e}clearAllWayPointsInternal(t){t.forEach((e,i)=>{var r;const s=t.get(i);s&&((r=s.parent)==null||r.removeChild(s),s.destroy())}),t.clear()}updateWayPointsEditState(t){t.forEach(e=>{e.onEditStateChange()})}isWayPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(t){if(t==null||t===-1){this.clearDivider();return}if(!this.getRoomGeometry(t)){this.clearDivider();return}this.createDefaultDivider(t)}getRoomGeometry(t){return this.appService.mapManager.getRoomById(t)}createDefaultDivider(t){const e=this.appService;this.clearDivider(),this.divider=new kS({appService:this.appService,roomId:t,events:{onUpdate:i=>{var s,r;(r=(s=e.events)==null?void 0:s.onUpdateDivider)==null||r.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var t;this.divider&&((t=this.divider.parent)==null||t.removeChild(this.divider),this.divider.destroy(),this.divider=null)}getDividerEndPoints(){return this.divider?this.divider.getDividerEndPoints():null}getEffectiveDividerPoints(){return this.divider?this.divider.getEffectiveDividerPoints():null}handleUnitChange(){w.debug("[ControlsManager] Unit changed, refreshing all size texts");for(const t of this.zoneMaps.values())t.forEach(e=>{e.refreshDisplay()});this.virtualWallMap.forEach(t=>{t.refreshDisplay()}),this.spotMap.forEach(t=>{t.refreshDisplay()}),this.purifyPointMap.forEach(t=>{t.refreshDisplay()})}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[];for(const t of this.zoneMaps.keys())this.clearAllZonesByType(t);this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearAllPurifyPoints(),this.clearDivider(),this.controlContainers.forEach(t=>{t.removeFromParent(),t.destroy({children:!0})}),this.controlContainers.clear()}}class DS extends Ut{constructor(e,i){super(e);f(this,"objectData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);this.appService=e,this.objectData=i}async initializeSprite(){const e=this.appService.detectedObjectConfig,i=this.objectData.width||e.width,s=this.objectData.height||e.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(e.anchor.x,e.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",r=>{this.applyAntiRotation(r)}),e.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickDetectedObject)==null||i.call(e,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(e){const i=this.objectData;this.objectData=e;const s=this.appService.detectedObjectConfig;if(i.src!==e.src){const r=e.width||s.width,o=e.height||s.height;await this.loadTextureAndSetSize(e.src,{width:r,height:o})}if(i.width!==e.width||i.height!==e.height){const r=e.width||s.width,o=e.height||s.height;this.setFixedSize(r,o)}this.position.set(e.x,e.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(e){return this.objectData.id===e.id&&this.objectData.src===e.src&&this.objectData.x===e.x&&this.objectData.y===e.y&&this.objectData.width===e.width&&this.objectData.height===e.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class FS{constructor(t){f(this,"detectedObjectMap",new Map);f(this,"unsubscribeShowDetectedObjects",null);this.appService=t,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=O(this.appService.runtime,"showDetectedObjects",e=>{this.applyLayerVisibility(e)})}async drawDetectedObjects(t){if(!t||t.length===0){this.clearAllDetectedObjects();return}const e=new Set(t.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)e.has(s)||this.removeDetectedObject(s);for(const s of t){const r=this.detectedObjectMap.get(s.id);r?r.isSameData(s)||await r.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(je);e&&(e.visible=t)}clearAllDetectedObjects(){const t=this.appService;this.detectedObjectMap.forEach(e=>{t.appContainer.removeFromLayer(je,e),e.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(t){const e=this.appService,i=new DS(this.appService,t);await i.initializeSprite(),this.detectedObjectMap.set(t.id,i),e.appContainer.addToLayer(je,i)}removeDetectedObject(t){const e=this.appService,i=this.detectedObjectMap.get(t);i&&(e.appContainer.removeFromLayer(je,i),i.destroy(),this.detectedObjectMap.delete(t))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var Ie={},Vc={},ne={};Object.defineProperty(ne,"__esModule",{value:!0});ne.loop=ne.conditional=ne.parse=void 0;var BS=function n(t,e){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:i;if(Array.isArray(e))e.forEach(function(o){return n(t,o,i,s)});else if(typeof e=="function")e(t,i,s,n);else{var r=Object.keys(e)[0];Array.isArray(e[r])?(s[r]={},n(t,e[r],i,s[r])):s[r]=e[r](t,i,s,n)}return i};ne.parse=BS;var zS=function(t,e){return function(i,s,r,o){e(i,s,r)&&o(i,t,s,r)}};ne.conditional=zS;var LS=function(t,e){return function(i,s,r,o){for(var a=[],h=i.pos;e(i,s,r);){var l={};if(o(i,t,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};ne.loop=LS;var dt={};Object.defineProperty(dt,"__esModule",{value:!0});dt.readBits=dt.readArray=dt.readUnsigned=dt.readString=dt.peekBytes=dt.readBytes=dt.peekByte=dt.readByte=dt.buildStream=void 0;var OS=function(t){return{data:t,pos:0}};dt.buildStream=OS;var Nc=function(){return function(t){return t.data[t.pos++]}};dt.readByte=Nc;var WS=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+t]}};dt.peekByte=WS;var $s=function(t){return function(e){return e.data.subarray(e.pos,e.pos+=t)}};dt.readBytes=$s;var GS=function(t){return function(e){return e.data.subarray(e.pos,e.pos+t)}};dt.peekBytes=GS;var US=function(t){return function(e){return Array.from($s(t)(e)).map(function(i){return String.fromCharCode(i)}).join("")}};dt.readString=US;var HS=function(t){return function(e){var i=$s(2)(e);return t?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};dt.readUnsigned=HS;var VS=function(t,e){return function(i,s,r){for(var o=typeof e=="function"?e(i,s,r):e,a=$s(t),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};dt.readArray=VS;var NS=function(t,e,i){for(var s=0,r=0;r<i;r++)s+=t[e+r]&&Math.pow(2,i-r-1);return s},$S=function(t){return function(e){for(var i=Nc()(e),s=new Array(8),r=0;r<8;r++)s[7-r]=!!(i&1<<r);return Object.keys(t).reduce(function(o,a){var h=t[a];return h.length?o[a]=NS(s,h.index,h.length):o[a]=s[h.index],o},{})}};dt.readBits=$S;(function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var t=ne,e=dt,i={blocks:function(u){for(var p=0,g=[],y=u.data.length,m=0,x=(0,e.readByte)()(u);x!==p&&x;x=(0,e.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;g.push((0,e.readBytes)(S)(u)),m+=S;break}g.push((0,e.readBytes)(x)(u)),m+=x}for(var v=new Uint8Array(m),b=0,P=0;P<g.length;P++)v.set(g[P],b),b+=g[P].length;return v}},s=(0,t.conditional)({gce:[{codes:(0,e.readBytes)(2)},{byteSize:(0,e.readByte)()},{extras:(0,e.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,e.readUnsigned)(!0)},{transparentColorIndex:(0,e.readByte)()},{terminator:(0,e.readByte)()}]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),r=(0,t.conditional)({image:[{code:(0,e.readByte)()},{descriptor:[{left:(0,e.readUnsigned)(!0)},{top:(0,e.readUnsigned)(!0)},{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{lct:(0,e.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,e.readArray)(3,function(d,u,p){return Math.pow(2,p.descriptor.lct.size+1)})},function(d,u,p){return p.descriptor.lct.exists}),{data:[{minCodeSize:(0,e.readByte)()},i]}]},function(d){return(0,e.peekByte)()(d)===44}),o=(0,t.conditional)({text:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{preData:function(u,p,g){return(0,e.readBytes)(g.text.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,t.conditional)({application:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{id:function(u,p,g){return(0,e.readString)(g.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,t.conditional)({comment:[{codes:(0,e.readBytes)(2)},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,e.readString)(3)},{version:(0,e.readString)(3)}]},{lsd:[{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{gct:(0,e.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,e.readByte)()},{pixelAspectRatio:(0,e.readByte)()}]},(0,t.conditional)({gct:(0,e.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,t.loop)([s,a,h,r,o],function(d){var u=(0,e.peekByte)()(d);return u===33||u===44})}],c=l;n.default=c})(Vc);var Ys={};Object.defineProperty(Ys,"__esModule",{value:!0});Ys.deinterlace=void 0;var YS=function(t,e){for(var i=new Array(t.length),s=t.length/e,r=function(u,p){var g=t.slice(p*e,(p+1)*e);i.splice.apply(i,[u*e,e].concat(g))},o=[0,4,2,1],a=[8,8,4,2],h=0,l=0;l<4;l++)for(var c=o[l];c<s;c+=a[l])r(c,h),h++;return i};Ys.deinterlace=YS;var Xs={};Object.defineProperty(Xs,"__esModule",{value:!0});Xs.lzw=void 0;var XS=function(t,e,i){var s=4096,r=-1,o=i,a,h,l,c,d,u,p,C,g,y,P,m,_,R,A,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=t,h=1<<m,d=h+1,a=h+2,p=r,c=m+1,l=(1<<c)-1,g=0;g<h;g++)S[g]=0,v[g]=g;var P,C,_,R,M,A;for(P=C=_=R=M=A=0,y=0;y<o;){if(R===0){if(C<c){P+=e[A]<<C,C+=8,A++;continue}if(g=P&l,P>>=c,C-=c,g>a||g==d)break;if(g==h){c=m+1,l=(1<<c)-1,a=h+2,p=r;continue}if(p==r){b[R++]=v[g],p=g,_=g;continue}for(u=g,g==a&&(b[R++]=_,g=p);g>h;)b[R++]=v[g],g=S[g];_=v[g]&255,b[R++]=_,a<s&&(S[a]=p,v[a]=_,a++,!(a&l)&&a<s&&(c++,l+=a)),p=u}R--,x[M++]=b[R],y++}for(y=M;y<o;y++)x[y]=0;return x};Xs.lzw=XS;Object.defineProperty(Ie,"__esModule",{value:!0});var $c=Ie.decompressFrames=Ie.decompressFrame=Yc=Ie.parseGIF=void 0,jS=JS(Vc),ZS=ne,qS=dt,KS=Ys,QS=Xs;function JS(n){return n&&n.__esModule?n:{default:n}}var tv=function(t){var e=new Uint8Array(t);return(0,ZS.parse)((0,qS.buildStream)(e),jS.default)},Yc=Ie.parseGIF=tv,ev=function(t){for(var e=t.pixels.length,i=new Uint8ClampedArray(e*4),s=0;s<e;s++){var r=s*4,o=t.pixels[s],a=t.colorTable[o]||[0,0,0];i[r]=a[0],i[r+1]=a[1],i[r+2]=a[2],i[r+3]=o!==t.transparentIndex?255:0}return i},Xc=function(t,e,i){if(!t.image){console.warn("gif frame does not have associated image.");return}var s=t.image,r=s.descriptor.width*s.descriptor.height,o=(0,QS.lzw)(s.data.minCodeSize,s.data.blocks,r);s.descriptor.lct.interlaced&&(o=(0,KS.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=e,t.gce&&(a.delay=(t.gce.delay||10)*10,a.disposalType=t.gce.extras.disposal,t.gce.extras.transparentColorGiven&&(a.transparentIndex=t.gce.transparentColorIndex)),i&&(a.patch=ev(a)),a};Ie.decompressFrame=Xc;var iv=function(t,e){return t.frames.filter(function(i){return i.image}).map(function(i){return Xc(i,t.gct,e)})};$c=Ie.decompressFrames=iv;class js{constructor(t){if(!t||!t.length)throw new Error("Invalid frames");const[{texture:{width:e,height:i}}]=t;this.width=e,this.height=i,this.frames=t,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const t of this.textures)t.destroy(!0);for(const t of this.frames)t.texture=null;this.frames.length=0,this.textures.length=0,Object.assign(this,{frames:null,textures:null,width:0,height:0,duration:0,totalFrames:0})}static from(t,e){if(!t||t.byteLength===0)throw new Error("Invalid buffer");const i=S=>{let v=null;for(const b of S.frames)v=b.gce??v,"image"in b&&!("gce"in b)&&(b.gce=v)},s=Yc(t);i(s);const r=$c(s,!0),o=[],a=s.lsd.width,h=s.lsd.height,l=$.get().createCanvas(a,h),c=l.getContext("2d",{willReadFrequently:!0}),d=$.get().createCanvas(),u=d.getContext("2d");let p=0,g=null;const{fps:y=30,...m}=e??{},x=1e3/y;for(let S=0;S<r.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:C,height:_,left:R,top:M}}=r[S];d.width=C,d.height=_,u.clearRect(0,0,C,_);const A=u.createImageData(C,_);A.data.set(P),u.putImageData(A,0,0),v===3&&(g=c.getImageData(0,0,a,h)),c.drawImage(d,R,M);const T=c.getImageData(0,0,a,h);v===2?c.clearRect(0,0,a,h):v===3&&c.putImageData(g,0,0);const I=$.get().createCanvas(T.width,T.height);I.getContext("2d").putImageData(T,0,0),o.push({start:p,end:p+b,texture:new G({source:new Mr({resource:I,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new js(o)}}const sv={extension:E.Asset,detection:{test:async()=>!0,add:async n=>[...n,"gif"],remove:async n=>n.filter(t=>t!=="gif")},loader:{name:"gifLoader",id:"gif",test:n=>Mt.extname(n)===".gif"||n.startsWith("data:image/gif"),load:async(n,t)=>{const i=await(await $.get().fetch(n)).arrayBuffer();return js.from(i,t==null?void 0:t.data)},unload:async n=>{n.destroy()}}},jc=class Sr extends jt{constructor(...t){const e=t[0]instanceof js?{source:t[0]}:t[0],{source:i,fps:s,loop:r,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},Sr.defaultOptions,e);super({texture:G.EMPTY,...u}),this.animationSpeed=1,this.loop=!0,this.duration=0,this.autoPlay=!0,this.dirty=!1,this._currentFrame=0,this._autoUpdate=!1,this._isConnectedToTicker=!1,this._playing=!1,this._currentTime=0,this.onRender=()=>this._updateFrame(),this.texture=i.textures[0],this.duration=i.frames[i.frames.length-1].end,this._source=i,this._playing=!1,this._currentTime=0,this._isConnectedToTicker=!1,Object.assign(this,{fps:s,loop:r,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d}),this.currentFrame=0,a&&this.play()}stop(){this._playing&&(this._playing=!1,this._autoUpdate&&this._isConnectedToTicker&&(mt.shared.remove(this.update,this),this._isConnectedToTicker=!1))}play(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(mt.shared.add(this.update,this,Fe.HIGH),this._isConnectedToTicker=!0),!this.loop&&this.currentFrame===this._source.frames.length-1&&(this._currentTime=0))}get progress(){return this._currentTime/this.duration}get playing(){return this._playing}update(t){var o,a;if(!this._playing)return;const e=this.animationSpeed*t.deltaTime/mt.targetFPMS,i=this._currentTime+e,s=i%this.duration,r=this._source.frames.findIndex(h=>h.start<=s&&h.end>s);i>=this.duration?this.loop?(this._currentTime=s,this._updateFrameIndex(r),(o=this.onLoop)==null||o.call(this)):(this._currentTime=this.duration,this._updateFrameIndex(this.totalFrames-1),(a=this.onComplete)==null||a.call(this),this.stop()):(this._currentTime=s,this._updateFrameIndex(r))}_updateFrame(){this.dirty&&(this.texture=this._source.frames[this._currentFrame].texture,this.dirty=!1)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,!this._autoUpdate&&this._isConnectedToTicker?(mt.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(mt.shared.add(this.update,this),this._isConnectedToTicker=!0))}get currentFrame(){return this._currentFrame}set currentFrame(t){this._updateFrameIndex(t),this._currentTime=this._source.frames[t].start}get source(){return this._source}_updateFrameIndex(t){var e;if(t<0||t>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${t}`);this._currentFrame!==t&&(this._currentFrame=t,this.dirty=!0,(e=this.onFrameChange)==null||e.call(this,t))}get totalFrames(){return this._source.totalFrames}destroy(t=!1){this.stop(),super.destroy(),t&&this._source.destroy();const e=null;this._source=e,this.onComplete=e,this.onFrameChange=e,this.onLoop=e}clone(){const t=new Sr({source:this._source,autoUpdate:this._autoUpdate,loop:this.loop,autoPlay:this.autoPlay,animationSpeed:this.animationSpeed,onComplete:this.onComplete,onFrameChange:this.onFrameChange,onLoop:this.onLoop});return t.dirty=!0,t}};jc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let nv=jc;q.add(sv);class ro extends nv{constructor(e,i){super(i);f(this,"throttledUpdateScale");f(this,"fixedWidth",0);f(this,"fixedHeight",0);f(this,"isFixedSizeSet",!1);f(this,"sizeFixed",!0);f(this,"baselineScale",1);f(this,"basePositionX",0);f(this,"basePositionY",0);f(this,"pixelOffset",null);this.appService=e,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(e){this.sizeFixed=e,this.baselineScale=1,e&&this.isFixedSizeSet?this.applySize():!e&&this.isFixedSizeSet&&this.applySize()}setBasePosition(e,i){this.basePositionX=e,this.basePositionY=i,this.pixelOffset?this.applyPixelOffset():this.position.set(e,i)}setPixelOffset(e){this.pixelOffset=e,e?this.applyPixelOffset():this.position.set(this.basePositionX,this.basePositionY)}applyPixelOffset(){if(this.destroyed||!this.pixelOffset)return;if(!this.sizeFixed){this.position.set(this.basePositionX,this.basePositionY);return}const e=this.appService.currentScale,i=this.appService.appContainer.getMapRotationRadians(),s=$r(this.pixelOffset,e,i);this.position.set(this.basePositionX+s.x,this.basePositionY+s.y)}set width(e){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(e,this.fixedHeight||e)}set height(e){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||e,e)}get width(){return this.fixedWidth||super.width}get height(){return this.fixedHeight||super.height}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applySize(){if(!this.isFixedSizeSet||!this.texture||this.texture.width===0||this.texture.height===0)return;const e=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const r=e/s,o=i/s;super.scale.set(r,o)}else super.scale.set(e/this.baselineScale,i/this.baselineScale)}updateScale(e){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():e!==0&&super.scale.set(1/e),this.applyPixelOffset())}static async createFromSrc(e,i,s){try{const r=await N.load(i),o=new ro(e,{source:r});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(r){throw w.error(`Failed to load GIF "${i}":`,r),r}}draw(e,i){const{x:s,y:r,rotation:o=0}=e;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,r)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ve extends ro{constructor(e,i,s){super(e,{source:i});f(this,"elementData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.elementData=s}async initialize(){this.elementData.sizeFixed!==void 0&&this.setSizeFixed(this.elementData.sizeFixed),this.setFixedSize(this.elementData.width,this.elementData.height);const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.setPixelOffset(this.elementData.pixelOffset??null),this.setBasePosition(this.elementData.x,this.elementData.y),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.elementData.opacity!==void 0&&(this.alpha=this.elementData.opacity),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i),this.applyPixelOffset()}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;if(this.elementData=e,i.src!==e.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height);const s=e.anchor||{x:.5,y:.5},r=i.anchor||{x:.5,y:.5};(s.x!==r.x||s.y!==r.y)&&this.anchor.set(s.x,s.y),this.setPixelOffset(e.pixelOffset??null),this.setBasePosition(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5},r=this.elementData.pixelOffset,o=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y&&((r==null?void 0:r.x)??0)===((o==null?void 0:o.x)??0)&&((r==null?void 0:r.y)??0)===((o==null?void 0:o.y)??0)}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class On extends Ut{constructor(e,i){super(e);f(this,"elementData");f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.appService=e,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.setPixelOffset(this.elementData.pixelOffset??null),this.setBasePosition(this.elementData.x,this.elementData.y),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.elementData.opacity!==void 0&&(this.alpha=this.elementData.opacity),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i),this.applyPixelOffset()}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new St(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.src!==e.src?await this.loadTextureAndSetSize(e.src,{width:e.width,height:e.height,sizeFixed:e.sizeFixed}):(i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height));const s=e.anchor||{x:.5,y:.5},r=i.anchor||{x:.5,y:.5};(s.x!==r.x||s.y!==r.y)&&this.anchor.set(s.x,s.y),this.setPixelOffset(e.pixelOffset??null),this.setBasePosition(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5},r=this.elementData.pixelOffset,o=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y&&((r==null?void 0:r.x)??0)===((o==null?void 0:o.x)??0)&&((r==null?void 0:r.y)??0)===((o==null?void 0:o.y)??0)}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class rv extends dm{constructor(e,i){super(i);f(this,"throttledUpdateScale");f(this,"fixedWidth",0);f(this,"fixedHeight",0);f(this,"isFixedSizeSet",!1);f(this,"userCenterX",0);f(this,"userCenterY",0);f(this,"sizeFixed",!0);f(this,"pixelOffset",null);this.appService=e,this.anchor.set(0,0),this.throttledUpdateScale=Pt(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(e,i){this.userCenterX=e,this.userCenterY=i,this.updatePositionFromCenter()}setPixelOffset(e){this.pixelOffset=e,this.isFixedSizeSet&&this.updatePositionFromCenter()}applyPixelOffset(){this.isFixedSizeSet&&this.updatePositionFromCenter()}setSizeFixed(e){this.sizeFixed=e,this.isFixedSizeSet&&(this.applyFixedSize(),this.updatePositionFromCenter())}getIsFixedSizeSet(){return this.isFixedSizeSet}updatePositionFromCenter(){if(!this.isFixedSizeSet){this.position.set(this.userCenterX,this.userCenterY);return}const i=this.appService.currentScale;let s,r;this.sizeFixed?(s=this.fixedWidth/2/i,r=this.fixedHeight/2/i):(s=this.fixedWidth/2,r=this.fixedHeight/2);let o=this.userCenterX,a=this.userCenterY;if(this.sizeFixed&&this.pixelOffset){const h=this.appService.appContainer.getMapRotationRadians(),l=$r(this.pixelOffset,i,h);o+=l.x,a+=l.y}this.position.set(o-s,a-r)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applyFixedSize(){if(!this.isFixedSizeSet)return;const i=this.appService.currentScale;if(i!==0){if(this.sizeFixed){const s=1/i;this.scale.set(s)}else this.scale.set(1);this.element&&(this.element.style.width=`${this.fixedWidth}px`,this.element.style.height=`${this.fixedHeight}px`)}}updateScale(e){this.isFixedSizeSet&&e!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(e){return super.updateTransform(e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ii extends rv{constructor(e,i){const s=document.createElement("div");Ii.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(e,{element:s});f(this,"elementData");f(this,"domClickHandler",null);f(this,"resizeObserver",null);f(this,"debugMarker",null);f(this,"unsubscribeMapRotation",null);f(this,"userRotation",0);this.elementData=i}async initialize(){this.alpha=0,this.elementData.width&&this.elementData.height?(this.setFixedSize(this.elementData.width,this.elementData.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.waitForElementInsertion()):(this.position.set(this.elementData.x,this.elementData.y),this.setupAutoSize()),this.setPixelOffset(this.elementData.pixelOffset??null),this.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",e=>{this.applyRotation(e),this.applyPixelOffset()}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupAutoSize(){this.element&&(this.element.style.width="auto",this.element.style.height="auto",this.waitForElementDimensions())}waitForElementInsertion(){if(!this.element)return;const e=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(e))};requestAnimationFrame(e)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e=>{var s;const i=e[0];i&&i.contentRect.width>0&&i.contentRect.height>0&&(this.setFixedSize(i.contentRect.width,i.contentRect.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement(),(s=this.resizeObserver)==null||s.disconnect(),this.resizeObserver=null)}),this.resizeObserver.observe(this.element)):this.pollForElementDimensions())}pollForElementDimensions(){if(!this.element)return;const e=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(e);return}const i=this.element.getBoundingClientRect();i.width>0&&i.height>0?(this.setFixedSize(i.width,i.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement()):requestAnimationFrame(e)};requestAnimationFrame(e)}showElement(){this.alpha=this.elementData.opacity??1,this.element.style.pointerEvents=this.elementData.interactive?"auto":"none",this.interactive=this.elementData.interactive??!1,this.elementData.interactive&&this.element&&(this.element.style.setProperty("-webkit-tap-highlight-color","transparent"),this.element.style.setProperty("-webkit-touch-callout","none")),this.appService.getApp().renderOnceNextFrame()}setupClickHandler(){this.element&&(this.domClickHandler=e=>{e.preventDefault(),e.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.htmlContent!==e.htmlContent&&this.element&&(this.element.innerHTML=e.htmlContent,(!e.width||!e.height)&&this.waitForElementDimensions()),(i.width!==e.width||i.height!==e.height)&&(e.width&&e.height?(this.setFixedSize(e.width,e.height),this.element&&(this.element.style.width=`${e.width}px`,this.element.style.height=`${e.height}px`)):this.setupAutoSize()),this.setPixelOffset(e.pixelOffset??null),e.width&&e.height?this.setCenterPosition(e.x,e.y):this.getIsFixedSizeSet()?this.setCenterPosition(e.x,e.y):this.position.set(e.x,e.y),i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),this.userRotation=e.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=e.opacity??1,e.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(e){const i=this.elementData.pixelOffset,s=e.pixelOffset;return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.htmlContent===e.htmlContent&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&((i==null?void 0:i.x)??0)===((s==null?void 0:s.x)??0)&&((i==null?void 0:i.y)??0)===((s==null?void 0:s.y)??0)}static setupDefaultStyles(e,i){const s={position:"relative",boxSizing:"border-box",webkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",background:"transparent",userSelect:"auto",webkitUserSelect:"auto"};i.width&&i.height?(s.width=`${i.width}px`,s.height=`${i.height}px`,s.overflow="hidden"):(s.width=i.width?`${i.width}px`:"auto",s.height=i.height?`${i.height}px`:"auto",s.overflow="visible"),Object.assign(e.style,s),e.style.setProperty("-webkit-tap-highlight-color","transparent"),e.style.setProperty("-webkit-touch-callout","none")}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null),this.debugMarker&&(this.debugMarker.destroy(),this.debugMarker=null),super.destroy()}}class ov{constructor(t){f(this,"customElementsMap",new Map);f(this,"gifTicker",null);f(this,"gifElements",new Set);this.appService=t}async drawCustomElements(t){if(!t||t.length===0){this.clearAllCustomElements();return}const e=new Set(t.map(r=>r.id)),i=Array.from(this.customElementsMap.keys());for(const r of i)e.has(r)||this.removeCustomElement(r);const s=t.map(async r=>{const o=this.customElementsMap.get(r.id);o?this.isSameData(o,r)||(r.type==="gif"&&o.getElementData().src!==r.src?(this.removeCustomElement(r.id),await this.addNewCustomElement(r)):await this.updateElementData(o,r)):await this.addNewCustomElement(r)});await Promise.all(s),this.updateGifTicker()}clearAllCustomElements(){const t=this.appService;this.customElementsMap.forEach(e=>{e instanceof Ve?t.appContainer.removeFromLayer(Ei,e):t.appContainer.removeFromLayer(ki,e),e.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(t){const e=this.appService;let i;switch(t.type){case"image":i=new On(this.appService,t);break;case"gif":{const s=await N.load(t.src);i=new Ve(this.appService,s,t);break}case"html":i=new Ii(this.appService,t);break;default:throw new Error(`Unsupported custom element type: ${t.type}`)}await i.initialize(),this.customElementsMap.set(t.id,i),i instanceof Ve?(e.appContainer.addToLayer(Ei,i),this.gifElements.add(i)):e.appContainer.addToLayer(ki,i)}removeCustomElement(t){const e=this.appService,i=this.customElementsMap.get(t);i&&(i instanceof Ve?(this.gifElements.delete(i),e.appContainer.removeFromLayer(Ei,i)):e.appContainer.removeFromLayer(ki,i),i.destroy(),this.customElementsMap.delete(t))}isSameData(t,e){return t.getElementData().type!==e.type?!1:e.type==="image"&&t instanceof On||e.type==="gif"&&t instanceof Ve||e.type==="html"&&t instanceof Ii?t.isSameData(e):!1}async updateElementData(t,e){if(e.type==="image"&&t instanceof On)await t.updateElementData(e);else if(e.type==="gif"&&t instanceof Ve)await t.updateElementData(e);else if(e.type==="html"&&t instanceof Ii)await t.updateElementData(e);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var t;(t=this.gifTicker)!=null&&t.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new mt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var t;(t=this.gifTicker)!=null&&t.started&&(w.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const t=this.appService;if(this.gifElements.size===0)return;const e=t.getApp();e.renderer.render(e.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class av extends W{constructor(e,i){super();f(this,"roomId");f(this,"roomIndex");f(this,"appService");f(this,"nameText");f(this,"iconSprite",null);f(this,"iconWrapper",null);f(this,"iconBg",null);this.appService=e,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:r}=e.roomConfig,{showRoomType:o}=e.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new de({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Os({text:c,style:l}),this.nameText.anchor.set(.5),o&&i.type!=null&&(r!=null&&r.assets)&&r.assets[i.type]&&this.createIcon(i.type,h),this.addChild(this.nameText),this.layout()}createIcon(e,i){const{type:s}=this.appService.roomConfig,r=s.iconSize||14;this.iconWrapper||(this.iconWrapper=new W,this.addChild(this.iconWrapper)),s.container.visible?(this.iconBg||(this.iconBg=new H,this.iconWrapper.addChild(this.iconBg)),this.drawIconBg(i)):this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite||(this.iconSprite=new Ut(this.appService),this.iconSprite.anchor.set(.5),this.iconWrapper.addChild(this.iconSprite)),this.iconSprite.visible=!0,this.iconSprite.tint=s.container.visible?"#ffffff":i,this.iconSprite.setFixedSize(r,r),this.iconSprite.loadTextureAndSetSize(s.assets[e],{width:r,height:r,sizeFixed:!1}).then(()=>{this.iconSprite&&(this.iconSprite.visible=this.appService.runtime.showRoomType,this.layout())}),s.container&&this.iconSprite.position.set(0,0)}drawIconBg(e){const{type:i}=this.appService.roomConfig;if(!this.iconBg||!i.container.visible)return;const{size:s,borderRadius:r}=i.container;this.iconBg.clear().roundRect(-s/2,-s/2,s,s,r).fill(e)}layout(){if(!this.iconWrapper||!this.iconWrapper.visible){this.nameText.position.set(0,0);return}if(!(this.iconSprite&&this.iconSprite.visible||this.iconBg&&this.iconBg.visible)){this.nameText.position.set(0,0);return}const{gap:i=4,position:s="left"}=this.appService.roomConfig.type,r=this.nameText.width,o=this.iconWrapper.width,h=-(o+i+r)/2;s==="left"?(this.iconWrapper.x=h+o/2,this.nameText.x=h+o+i+r/2):(this.nameText.x=h+r/2,this.iconWrapper.x=h+r+i+o/2),this.iconWrapper.y=0,this.nameText.y=0}updateName(e){this.nameText.text=e,this.layout()}refreshColor(e){const{type:i}=this.appService.roomConfig,s=this.appService.getRoomData(this.roomId),r=(s==null?void 0:s.colorIndex)??this.roomIndex,o=this.getRoomNameColor(r,e);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(e,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:r,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(r)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[e%s.nameInactive.length]:s.name[e%s.name.length];const a=s.nameNormal||s.name;return a[e%a.length]}async updateRoomType(e){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||e==null||!(i!=null&&i.assets)||!i.assets[e])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const r=this.appService.getRoomData(this.roomId),o=(r==null?void 0:r.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(e,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(e){if(this.iconWrapper)this.iconWrapper.visible=e,this.layout();else if(e){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(e){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),this.nameText.destroy({texture:!0,textureSource:!0}),super.destroy(e)}}class hv extends W{constructor(e,i){super();f(this,"background");f(this,"foldedIndicator");f(this,"propertyIcons",new Map);f(this,"orderContainer");f(this,"orderBackground");f(this,"orderText");f(this,"isFolded",!1);f(this,"roomId");f(this,"roomIndex");f(this,"isDestroyed",!1);this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.foldedIndicator=new H,this.foldedIndicator.visible=!1;const{property:r}=s,o=i.colorIndex??i.index,a=this.getIconColor(o);this.initializePropertyIcons(r.displayOrders,a);const h=r.cleanOrder.color==="auto"?s.colors.active[o%s.colors.active.length]:r.cleanOrder.color;this.orderContainer=new W,this.orderBackground=new H,this.orderText=new Os({text:"",style:new de({fontSize:r.cleanOrder.fontSize,fontFamily:r.cleanOrder.fontFamily,fontWeight:r.cleanOrder.fontWeight,fill:h,align:"center",trim:!0})}),this.orderText.anchor.set(.5,.5),this.orderContainer.addChild(this.orderBackground),this.orderContainer.addChild(this.orderText),this.addChild(this.background),this.addChild(this.foldedIndicator),this.propertyIcons.forEach(({sprite:l})=>{this.addChild(l)}),this.addChild(this.orderContainer),this.visible=this.appService.runtimeSnapshot.showRoomProperty}initializePropertyIcons(e,i){const s=["cleanMode","suction","cistern","cleanTimes"];e.forEach(r=>{const o=s.includes(r),a=new Ut(this.appService);a.tint=i,a.anchor.set(0,0),this.propertyIcons.set(r,{fieldName:r,sprite:a,isBuiltin:o})})}async updateProperty(e){this.isDestroyed||this.destroyed||(await this.updateIcons(e),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(e,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return e[i]??null;if(e.customData&&i in e.customData){const r=e.customData[i];return typeof r=="number"?r:null}return null}getAssetAlias(e,i){const s={cleanMode:r=>`cleanMode_${r}`,suction:r=>`fan_${r}`,cistern:r=>`water_${r}`,cleanTimes:r=>`cleanTimes${r}`};return e in s?s[e](i):`custom_${e}_${i}`}shouldShowField(e,i,s){const{showRoomProperty:r}=this.appService.runtimeSnapshot;return!(s===null||!r||i==="cleanTimes"&&s<=0)}getDisplayElements(e){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,r=e.order||0,o=s&&r>0,a=[];return o&&a.push({element:this.orderContainer,show:!0,isOrder:!0,fieldName:"order"}),i.forEach(h=>{const l=this.propertyIcons.get(h);if(!l||!l.sprite)return;const c=this.getFieldValue(e,h);this.shouldShowField(e,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:r}}async updateIcons(e){if(this.isDestroyed||this.destroyed||this.isFolded)return;const{iconWidth:i,iconHeight:s,container:r,cleanOrder:o,iconGap:a}=this.appService.roomConfig.property,{paddingHorizontal:h,paddingVertical:l}=r,{elementsToShow:c,orderValue:d}=this.getDisplayElements(e);this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:g})=>{g.visible=!1});const u=[];if(c.forEach(g=>{if(g.isOrder){this.orderContainer.visible=!0,this.orderText.text=d.toString();const y=e.colorIndex??this.roomIndex,m=this.getIconColor(y);this.orderBackground.clear(),this.orderBackground.setFillStyle({color:m}),this.orderBackground.circle(i/2,s/2,i/2).fill();const x=this.resolveOrderTextColor(y);this.orderText.style.fill=x,this.orderText.position.set(i/2,s/2)}else{const y=this.propertyIcons.get(g.fieldName);if(y&&y.sprite){y.sprite.visible=!0;const m=this.getAssetAlias(g.fieldName,g.value);u.push(y.sprite.loadTextureAndSetSize(m,{width:i,height:s,sizeFixed:!1}))}}}),await Promise.all(u),this.isDestroyed||this.destroyed)return;let p=h;c.forEach((g,y)=>{const{element:m,isOrder:x}=g;!m||!m.position||(m.position.set(p,l),p+=i,y<c.length-1&&(x?p+=o.gapRight:p+=a))})}updateBackground(){if(this.isDestroyed||this.destroyed)return;const e=this.appService.roomConfig,{container:i,foldable:s}=e.property,{borderRadius:r,tailHeight:o,tailWidth:a,backgroundColor:h}=i,l=this.calculateContentWidth(),c=this.calculateContentHeight(),d=Math.min(r,l/2,c/2),u=d*.8,p=Math.max(l-u*2,a*.5),g=Math.min(a,l/2,p);if(this.background.clear(),this.background.setFillStyle({color:h}),s){const y=(l-g)/2,m=c+o;this.background.moveTo(d,0),this.background.lineTo(l-d,0),this.background.arcTo(l,0,l,d,d),this.background.lineTo(l,c-d),this.background.arcTo(l,c,l-d,c,d),this.background.lineTo(y+g,c),this.background.lineTo(y+g/2,m),this.background.lineTo(y,c),this.background.lineTo(d,c),this.background.arcTo(0,c,0,c-d,d),this.background.lineTo(0,d),this.background.arcTo(0,0,d,0,d),this.background.closePath()}else this.background.roundRect(0,0,l,c,d);this.background.fill()}calculateContentWidth(){const{iconWidth:e,container:i,cleanOrder:s,iconGap:r}=this.appService.roomConfig.property,{paddingHorizontal:o}=i,a=this.appService.getRoomData(this.roomId);if(!a)return o*2;const{elementsToShow:h}=this.getDisplayElements(a);let l=o;return h.forEach((c,d)=>{const{isOrder:u}=c;l+=e,d<h.length-1&&(u?l+=s.gapRight:l+=r)}),l+=o,l}calculateContentHeight(){const e=this.appService.roomConfig,{iconHeight:i,container:s}=e.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:e,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(e?s:0)}getTotalWidth(){if(this.isFolded){const{tailWidth:i}=this.appService.roomConfig.property.container,s=this.calculateContentWidth();return Math.min(i,s/2)}return this.calculateContentWidth()}async setFolded(e){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=e,e)this.background.visible=!1,this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:s})=>{s.visible=!1}),this.foldedIndicator.visible=!0,this.updateFoldedIndicator();else{this.background.visible=!0,this.foldedIndicator.visible=!1,this.foldedIndicator.position.set(0,0),this.updateBackground();const s=this.appService.getRoomData(this.roomId);s&&await this.updateIcons(s)}}isFoldedState(){const{foldable:e}=this.appService.roomConfig.property;return e?this.isFolded:!1}updateFoldedIndicator(){const e=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:r}=e.property.container,o=this.calculateContentWidth(),a=Math.min(s,o/2);this.foldedIndicator.clear(),this.foldedIndicator.setFillStyle({color:r}),this.foldedIndicator.poly([0,i,a,i,a/2,0]).fill(),this.foldedIndicator.position.set(0,0)}resolveOrderTextColor(e){const{property:i,colors:s}=this.appService.roomConfig,{enableRoomSelection:r}=this.appService.runtime;if(i.cleanOrder.color==="auto"){const o=r?s.active:s.normal||s.active;return o[e%o.length]}return i.cleanOrder.color}getIconColor(e){const{colors:i}=this.appService.roomConfig,{propertyTheme:s,propertyThemeInactive:r,propertyThemeNormal:o}=i,{enableRoomSelection:a,selectRoomIds:h}=this.appService.runtime;if(a)return!h.includes(this.roomId)&&r?r[e%r.length]:s[e%s.length];const l=o||s;return l[e%l.length]}refreshColor(){const e=this.appService.getRoomData(this.roomId),i=(e==null?void 0:e.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite:r})=>{r.tint=s}),this.orderBackground&&this.orderBackground.visible){const{property:r}=this.appService.roomConfig,o=r.iconWidth,a=r.iconHeight;this.orderBackground.clear(),this.orderBackground.setFillStyle({color:s}),this.orderBackground.circle(o/2,a/2,o/2).fill();const h=this.resolveOrderTextColor(i);this.orderText.style.fill=h}}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.propertyIcons.forEach(({sprite:e})=>{e.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0,context:!0}))}}class lv extends W{constructor(e,i){super();f(this,"background");f(this,"checkmarkIcon");f(this,"bubble");f(this,"roomIndex");f(this,"roomId");this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon:r}}=s;this.checkmarkIcon=new Ut(this.appService);const o=i.colorIndex??i.index;this.checkmarkIcon.tint=r[o%r.length],this.checkmarkIcon.anchor.set(0,0),this.addChild(this.background),this.addChild(this.bubble),this.addChild(this.checkmarkIcon)}async updateIndicator(e){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:r}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=r.includes(e.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(e){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:r}=i;if(e){this.visible=!0,this.checkmarkIcon.visible=!0,await this.checkmarkIcon.loadTextureAndSetSize("checkmark",{width:s,height:r,sizeFixed:!1});const o=i.containerWidth/2,a=i.containerHeight/2;this.checkmarkIcon.position.set(o-s/2,a-r/2)}else this.visible=!1}updateBackground(){const{selectionIndicator:e,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:r,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=e,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],g=a==="auto"?p:a;if(this.checkmarkIcon.tint=i.selectionIndicatorIcon[u%i.selectionIndicatorIcon.length],this.background.clear(),this.bubble.clear(),this.background.setFillStyle({color:p}).roundRect(0,0,s,r,h).fill().setStrokeStyle({color:g,width:o,alignment:0}).stroke(),l>0&&c>0){const y=(s-c)/2;this.bubble.setFillStyle({color:g});const m=r+o;this.bubble.poly([y,m-1,y+c,m-1,y+c/2,m+l]).fill()}}getTotalHeight(){const{selectionIndicator:e}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:r}=e;return i+r+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:e}=this.appService.roomConfig;return e.containerWidth}async refreshColor(){const e=this.appService.getRoomData(this.roomId);e&&await this.updateIndicator(e)}destroy(){var e;(e=this.checkmarkIcon)==null||e.destroy(),super.destroy({children:!0,context:!0})}}class cv extends W{constructor(e,i){super();f(this,"roomId");f(this,"roomName");f(this,"roomProperty",null);f(this,"roomSelectionIndicator",null);f(this,"clickHandler",null);f(this,"unsubscribeMapRotation",null);f(this,"targetElasticScale",1);f(this,"currentElasticScale",1);f(this,"isAnimatingScale",!1);f(this,"scaleAnimationBound",null);f(this,"updateScaleBound",null);this.appService=e,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(e.currentScale),this.updateScaleBound=s=>this.updateScale(s),this.appService.emitter.on("antiScale",this.updateScaleBound),this.updateScale(this.appService.currentScale),i.centerPoint&&this.position.set(i.centerPoint.x,i.centerPoint.y),this.roomName=new av(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=O(this.appService.runtime,"mapRotation",s=>{this.applyAntiRotation(s)}),this.clickHandler=new St(this,{onClick:()=>{var s,r;(r=(s=this.appService.events)==null?void 0:s.onClickRoomProperties)==null||r.call(s,i)}})}async initialize(e){await this.createRoomProperty(e),await this.createRoomSelectionIndicator(e),this.updateLayout()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}initializeElasticScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:r}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=r:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:r}=this.appService.roomConfig;if(!i){e!==0&&this.scale.set(1/e);return}if(e===0)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=r:h=1;const c=1/e*h;Math.abs(this.targetElasticScale-h)>.01?(this.targetElasticScale=h,this.startScaleAnimation()):this.scale.set(c)}startScaleAnimation(){this.scaleAnimationBound||(this.scaleAnimationBound=this.animateScale.bind(this)),this.isAnimatingScale||(this.isAnimatingScale=!0,this.appService.getApp().ticker.add(this.scaleAnimationBound))}animateScale(){this.currentElasticScale+=(this.targetElasticScale-this.currentElasticScale)*.3;const r=1/this.appService.currentScale*this.currentElasticScale;this.scale.set(r),Math.abs(this.currentElasticScale-this.targetElasticScale)<.001&&(this.currentElasticScale=this.targetElasticScale,this.isAnimatingScale=!1,this.scaleAnimationBound&&this.appService.getApp().ticker.remove(this.scaleAnimationBound))}shouldShowRoomProperty(){const{showRoomOrder:e,showRoomProperty:i,selectRoomIds:s,enableRoomSelection:r,roomSelectionMode:o}=this.appService.runtimeSnapshot,a=this.appService.getRoomData(this.roomId);if(!a||r&&o==="checkmark"&&s.includes(this.roomId))return!1;const h=e&&(a.order||0)>0;let l=!1;if(i){const{displayOrders:c}=this.appService.roomConfig.property;l=c.some(d=>!!(d==="suction"&&a.suction!=null||d==="cistern"&&a.cistern!=null||d==="cleanMode"&&a.cleanMode!=null||d==="cleanTimes"&&a.cleanTimes>0||a.customData&&d in a.customData&&typeof a.customData[d]=="number"&&a.customData[d]!=null))}return h||l}shouldShowRoomSelectionIndicator(){const{enableRoomSelection:e,roomSelectionMode:i}=this.appService.runtimeSnapshot;return e&&i==="checkmark"}async updateRoomPropertyVisibility(){if(!this.roomProperty)return;if(!this.shouldShowRoomProperty())this.roomProperty.visible=!1;else{this.roomProperty.visible=!0;const i=this.appService.runtimeSnapshot.roomPropertyFoldIds.includes(this.roomId);await this.roomProperty.setFolded(i);const s=this.appService.getRoomData(this.roomId);s&&await this.roomProperty.updateProperty(s)}this.updateLayout()}async updateRoomSelectionIndicatorVisibility(){if(!this.roomSelectionIndicator)return;if(this.shouldShowRoomSelectionIndicator()){const i=this.appService.getRoomData(this.roomId);i&&await this.roomSelectionIndicator.updateIndicator(i)}else this.roomSelectionIndicator.visible=!1;this.updateLayout()}async createRoomProperty(e){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new hv(this.appService,e),await this.roomProperty.updateProperty(e),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(e){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new lv(this.appService,e),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,g;if(this.destroyed)return;const{property:{offsetY:e,offsetX:i},selectionIndicator:{offsetY:s,offsetX:r}}=this.appService.roomConfig,o=((l=this.roomProperty)==null?void 0:l.visible)||!1,a=((c=this.roomName)==null?void 0:c.visible)||!1,h=((d=this.roomSelectionIndicator)==null?void 0:d.visible)||!1;if(o&&this.roomProperty){const y=this.roomProperty.getTotalHeight(),m=this.roomProperty.getTotalWidth();if(this.roomProperty.isFoldedState()){const S=-m/2+i,v=-y/2-e;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-e-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-e)}if(h&&this.roomSelectionIndicator){const y=this.roomSelectionIndicator.getTotalHeight(),m=this.roomSelectionIndicator.getTotalWidth();a&&((p=this.roomName)!=null&&p.position)?(this.roomSelectionIndicator.position.set(-m/2+r,-s-y),this.roomName.position.set(0,0)):this.roomSelectionIndicator.position.set(-m/2+r,-y/2-s)}a&&!o&&!h&&((g=this.roomName)!=null&&g.position)&&this.roomName.position.set(0,0)}updateName(e){this.roomName.updateName(e)}async updateRoomType(e){await this.roomName.updateRoomType(e),this.updateLayout()}updateRoomNameVisibility(e){this.roomName.visible=e,this.updateLayout()}updateRoomTypeVisibility(e){this.roomName.updateRoomTypeVisibility(e),this.updateLayout()}updatePosition(e){this.position.set(e.x,e.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var e,i,s,r;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.isAnimatingScale&&this.scaleAnimationBound&&(this.appService.getApp().ticker.remove(this.scaleAnimationBound),this.isAnimatingScale=!1),this.scaleAnimationBound=null,this.updateScaleBound&&(this.appService.emitter.off("antiScale",this.updateScaleBound),this.updateScaleBound=null),(i=this.roomProperty)==null||i.destroy(),this.roomProperty=null,(s=this.roomSelectionIndicator)==null||s.destroy(),this.roomSelectionIndicator=null,(r=this.roomName)==null||r.destroy(),this.isRenderGroup&&(this.isRenderGroup=!1),super.destroy()}}class dv extends W{constructor(e){super({isRenderGroup:!0});f(this,"floorTypeMap",new Map);f(this,"floorTypeMasks",new Map);f(this,"floorTypeContexts",new Map);f(this,"floorTypeToRooms",new Map);this.appService=e,this.appService.appContainer.addToLayer(qr,this)}async createFloorTypes(e){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(e),r=[];for(const[o,a]of s)r.push(this.createMergedFloorType(o,a));await Promise.all(r)}groupRoomsByFloorType(e){const i=new Map,s=this.appService;return e.forEach((r,o)=>{const a=s.getRoomData(o),h=(a==null?void 0:a.floorType)||0;h>=0&&(i.has(h)||i.set(h,[]),i.get(h).push({roomId:o,graphics:r}))}),i}async createMergedFloorType(e,i){const s=this.appService,{assets:r,opacity:o,scale:a}=s.roomConfig.floorType,h=e%r.length,l=`floorType${h}`;if(!r[h]){w.warn(`No texture asset configured for floorType: ${e}`);return}const c=await N.load(l);if(!c){w.warn(`Floor material texture not found: ${l}`);return}const d=i.map(({graphics:m})=>m.getLocalBounds()),u=Tx(d),p=new Ms({texture:c,width:u.width,height:u.height});p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:g,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=g,this.addChild(p),this.floorTypeMap.set(e,p),this.floorTypeMasks.set(e,g),this.floorTypeContexts.set(e,y),this.floorTypeToRooms.set(e,new Set(i.map(({roomId:m})=>m)))}createMergedMask(e){const i=new W,s=[];return e.forEach(r=>{const o=new H,a=r.context.clone();o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(e=>{try{e.destroy({children:!0})}catch(i){w.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(e=>{try{e.forEach(i=>{try{i.destroy()}catch(s){w.warn("Error destroying cloned graphics context:",s)}})}catch(i){w.warn("Error destroying graphics contexts:",i)}}),this.floorTypeContexts.clear(),this.floorTypeMap.forEach(e=>{try{this.removeChild(e),e.destroy()}catch(i){w.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}const Wn=(n,t)=>n&&t?{x:n.x-t.x,y:n.y-t.y}:null;class uv{constructor(t){f(this,"unsubscribeFns",[]);f(this,"roomInfoContainer",new W);f(this,"roomInfoMap",new Map);f(this,"roomDisplayMap",new Map);f(this,"roomFloorType");this.appService=t,this.roomFloorType=new dv(t),t.appContainer.addToLayer(zc,this.roomInfoContainer);const e=O(t.runtime,"showRoomFloorType",d=>{w.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=O(t.runtime,"showRoomProperty",d=>{w.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=O(t.runtime,"showRoomOrder",d=>{w.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),r=O(t.runtime,"roomPropertyFoldIds",d=>{w.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=O(t.runtime,"showRoomName",d=>{w.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=O(t.runtime,"showRoomType",d=>{w.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=O(t.runtime,"enableRoomSelection",d=>{w.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=O(t.runtime,"selectRoomIds",d=>{w.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=O(t.runtime,"roomSelectionMode",d=>{w.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(e,i,s,r,o,a,h,l,c)}async drawRoomProperty(t){var s;const e=this.appService;this.roomDisplayMap.clear();const i=((s=e.getApp().mapState)==null?void 0:s.origin)??null;return t.forEach((r,o)=>{const a=e.mapManager.getRoomById(r.id),h=(a==null?void 0:a.centerPoint)||null,l={...r,centerPoint:h,relativeCenterPoint:Wn(h,i),index:o,colorIndex:a==null?void 0:a.colorIndex};this.roomDisplayMap.set(r.id,l)}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes(),!0}async updateRoomInfoDisplay(){if(this.roomDisplayMap.size===0){this.appService.mapManager.getAllRooms().length===0&&this.clearRoomInfos();return}const t=Array.from(this.roomDisplayMap.values()).filter(e=>e.centerPoint!==null);this.clearRoomInfos(),await Promise.all(t.map(e=>this.createRoomInfo(e)))}async createRoomInfo(t){const e=new cv(this.appService,t);this.roomInfoContainer.addChild(e),this.roomInfoMap.set(t.id,e),await e.initialize(t)}updateRoomName(t,e){const i=this.roomInfoMap.get(t);i&&i.updateName(e)}async updateRoomType(t,e){const i=this.roomDisplayMap.get(t);i&&(i.type=e);const s=this.roomInfoMap.get(t);s&&await s.updateRoomType(e)}updateRoomPosition(t,e){var r;const i=this.roomDisplayMap.get(t);if(i){i.centerPoint=e;const o=((r=this.appService.getApp().mapState)==null?void 0:r.origin)??null;i.relativeCenterPoint=Wn(e,o)}const s=this.roomInfoMap.get(t);s&&s.updatePosition(e)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const t=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),t.forEach(e=>{try{e.destroy()}catch(i){w.warn(`[RoomManager] Error destroying RoomInfo for room ${e.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(t){return this.roomDisplayMap.get(t)}async refresh(){var i;const t=this.appService;this.roomFloorType.clearFloorTypes();const e=((i=t.getApp().mapState)==null?void 0:i.origin)??null;this.roomDisplayMap.forEach((s,r)=>{const o=t.mapManager.getRoomById(r),a=(o==null?void 0:o.centerPoint)||null;if(s.centerPoint!==a){s.centerPoint=a,s.relativeCenterPoint=Wn(a,e);const l=this.roomInfoMap.get(r);l&&a&&l.updatePosition(a)}const h=o==null?void 0:o.colorIndex;if(s.colorIndex!==h&&h!==void 0){s.colorIndex=h;const l=this.roomInfoMap.get(r);l&&l.refreshColor()}}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes()}async updateAllRoomPropertyVisibility(){this.roomInfoMap.size!==0&&await Promise.all(Array.from(this.roomInfoMap.values()).map(async t=>{try{await t.updateRoomPropertyVisibility()}catch(e){console.warn(`[RoomManager] Failed to update room property visibility for room ${t.roomId}`,e)}}))}updateAllRoomNameVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomNameVisibility(t)})}updateAllRoomTypeVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomTypeVisibility(t)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.refreshColor()})}async updateFloorTypes(){const t=this.appService,e=t.mapManager.roomFill.getRoomGraphicsMap();e.size>0?(await this.roomFloorType.createFloorTypes(e),t.getApp().renderOnceNextFrame()):t.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy()}}var mh,yh;(mh=navigator==null?void 0:navigator.userAgent)!=null&&mh.includes("tuya-ark-ide")||((yh=navigator==null?void 0:navigator.userAgent)==null||yh.includes("miniProgram"));const pv=()=>{var i,s;if(!Fu.any)return!0;const n=navigator.userAgent.toLowerCase(),t=()=>{const r=navigator.deviceMemory;return r?r>=4:!0};let e=!1;if(/iphone|ipad|ipod/.test(n)){const r=(i=n.match(/os (\d+)_/))==null?void 0:i[1];e=(r?parseInt(r):0)>=12}else if(/android/.test(n)){const r=(s=n.match(/android (\d+)/))==null?void 0:s[1];e=(r?parseInt(r):0)>=10}return e&&t()};class fv extends W{constructor(e,i,s){super();f(this,"graphics");f(this,"sprite",null);f(this,"viewportBounds");f(this,"lastConfig",null);f(this,"onImageLoaded");this.label="background",this.viewportBounds=i,this.onImageLoaded=s,this.graphics=new H,this.graphics.label="backgroundGraphics",this.addChild(this.graphics),this.render(e)}async render(e){if(this.lastConfig=e,this.clear(),e.backgroundImage){await this.renderImage(e.backgroundImage,e.backgroundAlpha);return}if(e.backgroundGradient){this.renderGradient(e.backgroundGradient);return}if(e.backgroundColor!==void 0){this.renderSolidColor(e.backgroundColor,e.backgroundAlpha);return}w.warn("[Background] No background configuration provided")}clear(){this.graphics.clear(),this.sprite&&(this.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null)}renderSolidColor(e,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:e,alpha:i}),w.debug("[Background] Rendered solid color background",{color:e,alpha:i})}renderGradient(e){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),e.type==="linear"){const r=e.x0??0,o=e.y0??0,a=e.x1??1,h=e.y1??1,l=new Gt({type:"linear",start:{x:r,y:o},end:{x:a,y:h},colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(l),w.debug("[Background] Rendered linear gradient background",{x0:r,y0:o,x1:a,y1:h,colorStops:e.colorStops.length})}else if(e.type==="radial"){const r=e.cx??.5,o=e.cy??.5,a=e.r??.5,h=new Gt({type:"radial",center:{x:r,y:o},innerRadius:0,outerCenter:{x:r,y:o},outerRadius:a,colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(h),w.debug("[Background] Rendered radial gradient background",{cx:r,cy:o,r:a,colorStops:e.colorStops.length})}}async renderImage(e,i){var s,r,o,a;try{const h=await N.load(e.src);if(!h){w.error("[Background] Failed to load image:",e.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=e.fit||"cover",u=((r=e.position)==null?void 0:r.x)??.5,p=((o=e.position)==null?void 0:o.y)??.5,g=h.width,y=h.height,m=g/y,x=l/c;switch(d){case"fill":this.sprite.width=l,this.sprite.height=c,this.sprite.x=0,this.sprite.y=0;break;case"contain":m>x?(this.sprite.width=l,this.sprite.height=l/m):(this.sprite.height=c,this.sprite.width=c*m),this.sprite.x=(l-this.sprite.width)*u,this.sprite.y=(c-this.sprite.height)*p;break;case"cover":m>x?(this.sprite.height=c,this.sprite.width=c*m):(this.sprite.width=l,this.sprite.height=l/m),this.sprite.x=(l-this.sprite.width)*u,this.sprite.y=(c-this.sprite.height)*p;break;case"none":this.sprite.width=g,this.sprite.height=y,this.sprite.x=(l-g)*u,this.sprite.y=(c-y)*p;break}e.repeat&&w.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),w.debug("[Background] Rendered image background",{src:e.src,fit:d,position:{x:u,y:p},spriteSize:{width:this.sprite.width,height:this.sprite.height}}),this.onImageLoaded&&this.onImageLoaded()}catch(h){w.error("[Background] Error loading background image:",h),(a=this.lastConfig)!=null&&a.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i)}}async update(e){await this.render(e)}async updateViewportBounds(e){this.viewportBounds=e,this.lastConfig&&await this.render(this.lastConfig)}destroy(){this.clear(),super.destroy()}}class gv extends W{constructor(e){super();f(this,"carpetData");f(this,"carpetConfig");f(this,"controlsConfig");f(this,"carpetEvents");f(this,"appService");f(this,"controlFill");f(this,"editableShape");f(this,"clickHandler",null);f(this,"maskContainer",null);f(this,"maskGraphics",null);f(this,"texture",null);f(this,"textureMap",new Map);f(this,"tilingSprite",null);f(this,"initialZonePoints",[]);f(this,"unsubscribeFns",[]);f(this,"resolvedMaxSizeCache",null);f(this,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});f(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(e.global),s=this.controlFill.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});f(this,"handleMove",e=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(h=(a=this.editableShape)==null?void 0:a.getMoveButton())==null?void 0:h.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.applyTranslation(r,o)});f(this,"handleMoveEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});f(this,"handleRotationMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleRotationEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleClickRotate",e=>{var i,s;e&&(this.carpetData.points=e,this.drawCarpet()),this.appService.getApp().renderOnce(),(s=(i=this.carpetEvents).onUpdate)==null||s.call(i,this.getCarpetData())});f(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});f(this,"handleScaleMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleMoveHorizontal",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleMoveVertical",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});f(this,"handleScaleEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-scale"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.carpetEvents).onRemove)==null||i.call(e,this.carpetData.id)});f(this,"handleClick",()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())});f(this,"handlePointsUpdate",e=>{this.carpetData.points=e,this.drawCarpet()});const{appService:i,carpetData:s,events:r={},textureMap:o}=e;this.appService=i,this.textureMap=o,this.carpetEvents=r,this.controlsConfig=this.getControlsConfig(),this.carpetConfig=this.controlsConfig.carpet,this.processCarpetData(s),this.initializeComponents(),this.createEditControlLayer(),this.setupClickHandler(),this.setupEnableRoomSelectionListener(),this.updateEditState(),this.loadTexture()}getResolvedMaxSize(){const e=this.carpetConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===e)return this.resolvedMaxSizeCache.value;const i=Us(this.carpetConfig.minSize,e,"carpet");return this.resolvedMaxSizeCache={key:e,value:i},i}validateCarpetShape(e){const i=this.getResolvedMaxSize();return this.appService.coords.validateShape(Sc(e),{minSize:ut(this.carpetConfig.minSize),maxSize:i!=null?ut(i):void 0})}processCarpetData(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=this.validateCarpetShape(e.points);this.carpetData={...e,points:s}}else this.carpetData={...e,points:[],shape:e.shape||"rectangle"}}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}isEditingEnabled(){return this.appService.runtimeSnapshot.editingCarpetIds.includes(this.carpetData.id)}isSelected(){return this.appService.runtimeSnapshot.selectedCarpetIds.includes(this.carpetData.id)}shouldShowEditControl(){return this.isEditingEnabled()||this.isSelected()}initializeComponents(){this.maskContainer=this.createMaskContainer(),this.controlFill=this.createControlFill(),this.addChild(this.maskContainer),this.addChild(this.controlFill),this.drawCarpet()}createMaskContainer(){const e=new W;return this.maskGraphics=new H,this.updateMaskShape(),e.addChild(this.maskGraphics),e.mask=this.maskGraphics,e}createControlFill(){const e=this.isEditingEnabled();return new Qr(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:e,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const e=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s=!!e&&!i&&this.carpetConfig.scaleMode==="ratioLocked",r={...In(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...In(this.carpetConfig,["textColor","textPosition","textOffset"]),...In(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!e&&!i&&this.carpetConfig.showRotateButton,showScaleButton:!!e&&!i,showDeleteButton:!!e,showMoveButton:!!e&&!i,showRadialScaleButton:s,iconWrapperFillColor:this.carpetConfig.iconWrapperFillColor,deleteIconWrapperFillColor:this.carpetConfig.deleteIconWrapperFillColor,rotateMode:this.carpetConfig.rotateMode,scaleMode:this.carpetConfig.scaleMode,moveButtonOffset:this.controlsConfig.moveButtonOffset},o=i?this.calculateBoundingRectanglePoints():this.carpetData.points||[];this.editableShape=new Jr({editControls:this.appService.editControlManager});const a=this.getResolvedMaxSize();this.editableShape.attach(this,{id:this.carpetData.id,topology:"quad",layerOptions:{config:r,zonePoints:o,minSize:this.carpetConfig.minSize,maxSize:a??void 0,contentLayer:Ke,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,onClickRotate:this.handleClickRotate,onRotateEnd:this.handleRotationEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleMoveHorizontal:this.handleScaleMoveHorizontal,onScaleMoveVertical:this.handleScaleMoveVertical,onScaleEnd:this.handleScaleEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick,onPointsUpdate:this.handlePointsUpdate}},editingState:{showRotateButton:!i&&this.carpetConfig.showRotateButton,showScaleButton:!i,showDeleteButton:!0,showMoveButton:!i,showBorder:!0,showSizeText:!0,borderStyle:this.carpetConfig.editing,showRadialScaleButton:!i&&this.carpetConfig.scaleMode==="ratioLocked"},idleState:{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new St(this,{onClick:()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const e=O(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(e);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(e){if(e){if(this.eventMode="none",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="none"}}else if(this.eventMode="static",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="static"}}calculateBounds(){const{points:e}=this.carpetData;let i=1/0,s=1/0,r=-1/0,o=-1/0;if(e&&e.length>0)for(const a of e)i=Math.min(i,a.x),s=Math.min(s,a.y),r=Math.max(r,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:r,maxY:o}}calculateBoundingRectanglePoints(){const{points:e}=this.carpetData;if(!e||e.length===0)return[];const{minX:i,minY:s,maxX:r,maxY:o}=Ts(e);return[{x:i,y:s},{x:r,y:s},{x:r,y:o},{x:i,y:o}]}updateMaskShape(){if(!this.maskGraphics)return;this.maskGraphics.clear();const{points:e,shape:i}=this.carpetData;if(!(!e||!Array.isArray(e)||e.length<2)){if(i==="round"){if(e.length<4)return;const r=Oe(e),[o,a,,h]=e,l=tt(o,a),c=tt(o,h),d=Math.atan2(a.y-o.y,a.x-o.x);this.maskGraphics.position.set(r.x,r.y),this.maskGraphics.rotation=d,this.maskGraphics.ellipse(0,0,l/2,c/2)}else{const r=e.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(r),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}loadTexture(){const{opacity:e,scale:i}=this.appService.carpetConfig,{type:s}=this.carpetData;try{this.texture=this.textureMap.get(s)||this.textureMap.get(-1)||null,this.texture&&this.maskContainer&&(this.tilingSprite&&(this.maskContainer.removeChild(this.tilingSprite),this.tilingSprite.destroy(),this.tilingSprite=null),this.createTilingSprite(i,e),this.appService.getApp().renderOnce())}catch(r){console.warn("Failed to load carpet texture:",r)}}createTilingSprite(e,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new Ms({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(e),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const e=this.calculateBounds();this.tilingSprite.position.set(e.minX-50,e.minY-50),this.tilingSprite.width=e.maxX-e.minX+100,this.tilingSprite.height=e.maxY-e.minY+100}applyTranslation(e,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:e}=this.carpetData;if(!(!e||e.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(e),this.editableShape)){const r=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():e;this.editableShape.updatePoints(r)}}updateEditState(){const e=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();this.controlFill.setInteractionEnabled(e),this.editableShape&&(i&&!e?this.editableShape.applyEditState({showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!0,showSizeText:!1,borderStyle:this.carpetConfig.normal}):this.editableShape.setEditing(e)),this.zIndex=s?1e3:0}refreshConfig(){this.controlsConfig=this.getControlsConfig(),this.carpetConfig=this.controlsConfig.carpet,this.resolvedMaxSizeCache=null,this.controlFill.updateFillColor(this.carpetConfig.fillColor),this.editableShape.detach(),this.createEditControlLayer(),this.drawCarpet(),this.updateEditState()}updateCarpetData(e){const s=this.carpetData.type;if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const r=this.validateCarpetShape(e.points);this.carpetData={...e,points:r}}else this.carpetData={...e,points:e.points||[]};s!==this.carpetData.type&&this.loadTexture(),this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var e,i,s,r,o;this.editableShape.detach(),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(e=this.tilingSprite)==null||e.destroy(),(i=this.maskGraphics)==null||i.destroy(),(s=this.maskContainer)==null||s.destroy(),this.tilingSprite=null,this.maskGraphics=null,this.maskContainer=null,this.texture=null,(r=this.controlFill)==null||r.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class mv{constructor(t){f(this,"customCarpetMap",new Map);f(this,"unsubscribeFns",[]);f(this,"textureMap",new Map);f(this,"texturesLoaded",!1);f(this,"texturesLoadingPromise",null);this.appService=t,this.applyLayerVisibility(t.runtime.showCustomCarpets);const e=O(t.runtime,"editingCarpetIds",r=>{w.log(`[runtime] editingCarpetIds: ${r}`),this.updateCarpetsEditState()}),i=O(t.runtime,"selectedCarpetIds",r=>{w.log(`[runtime] selectedCarpetIds: ${r}`),this.updateCarpetsEditState()}),s=O(t.runtime,"showCustomCarpets",r=>{w.log(`[runtime] showCustomCarpets: ${r}`),this.applyLayerVisibility(r)});this.unsubscribeFns.push(e,i,s)}async loadTextures(){if(!this.texturesLoaded){if(this.texturesLoadingPromise)return this.texturesLoadingPromise;this.texturesLoadingPromise=this._loadTextures(),await this.texturesLoadingPromise,this.texturesLoaded=!0,this.texturesLoadingPromise=null}}async _loadTextures(){const t=this.appService,{material:e,src:i}=t.carpetConfig;if(e)for(const s of e){const r=await N.load(s.src);this.textureMap.set(s.type,r)}if(i){const s=await N.load(i);this.textureMap.set(-1,s)}}async drawCustomCarpets(t){if(await this.loadTextures(),!t||t.length===0){this.clearAllCustomCarpets();return}const e=new Set(this.customCarpetMap.keys()),i=new Set(t.map(s=>s.id));for(const s of e)i.has(s)||this.removeCustomCarpet(s);t.forEach(s=>{const r=this.customCarpetMap.get(s.id.toString());r?this.isCarpetDataEqual(r.getCarpetData(),s)||r.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const t=[];return this.customCarpetMap.forEach(e=>{t.push(e.getCarpetData())}),t}getCustomCarpetById(t){return this.customCarpetMap.get(t)}clearAllCustomCarpets(){this.customCarpetMap.forEach((t,e)=>{var s;const i=this.customCarpetMap.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(t){const e=this.appService,i=new gv({appService:e,carpetData:t,textureMap:this.textureMap,events:{onRemove:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onDeleteCustomCarpet)==null||o.call(r,{id:s})},onUpdate:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onUpdateCustomCarpet)==null||o.call(r,s)},onClick:s=>{var r,o;(o=(r=e.events)==null?void 0:r.onClickCarpet)==null||o.call(r,{id:s.id})}}});this.customCarpetMap.set(t.id.toString(),i),e.appContainer.addToLayer(Ke,i)}removeCustomCarpet(t){const e=this.appService,i=this.customCarpetMap.get(t);i&&(e.appContainer.removeFromLayer(Ke,i),i.destroy(),this.customCarpetMap.delete(t))}updateCarpetsEditState(){this.customCarpetMap.forEach(t=>{t.updateEditState()})}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(Ke);e&&(e.visible=t)}isCarpetDataEqual(t,e){if(t.id!==e.id||t.type!==e.type||t.shape!==e.shape)return!1;const i=t.points||[],s=e.points||[];if(i.length!==s.length)return!1;for(let r=0;r<i.length;r++){const o=i[r],a=s[r];if(Math.abs(o.x-a.x)>.1||Math.abs(o.y-a.y)>.1)return!1}return!0}refreshDisplay(){this.customCarpetMap.forEach(t=>{t.refreshDisplay()})}refreshConfig(){this.customCarpetMap.forEach(t=>{t.refreshConfig()})}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearAllCustomCarpets()}}function yv(n,t){return{coords:n.coords,editControls:n.editControlManager,furnitureConfig:n.furnitureConfig,controlsConfig:n.controlsConfig,gestures:n.gestureController,render:{request:e=>n.getApp().requestRender(e,!0),stop:e=>n.getApp().stopRender(e),once:e=>n.getApp().requestRender(e,!1)},events:t}}const ph="furniture-drag",fh="furniture-scale",gh="furniture-move",Gn="furniture-rotate";class xv extends W{constructor(e){super();f(this,"deps");f(this,"config");f(this,"controlsConfig");f(this,"furnitureEvents");f(this,"data");f(this,"textureAlias");f(this,"sprite");f(this,"editableShape");f(this,"editing",!1);f(this,"clickHandler",null);f(this,"dragStartPosition",null);f(this,"initialPoints",[]);f(this,"isDragging",!1);f(this,"gestureSession",null);f(this,"originalSizeMeters",null);f(this,"resolveSizeConstraintPerEdge",()=>{var o,a;const{minScaleRatio:e,maxScaleRatio:i}=this.config,s=i===1/0||i==null?void 0:i,r=h=>{if(!h||h<=0)return{min:.1,max:void 0};const l=h*(e||0);return{min:l>0?l:.1,max:s!=null?h*s:void 0}};return{edge1:r((o=this.originalSizeMeters)==null?void 0:o.width),edge2:r((a=this.originalSizeMeters)==null?void 0:a.height)}});f(this,"onDragStart",e=>{if(!this.editing||!this.parent||e.target!==this&&e.target!==this.sprite)return;e.stopPropagation();const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(s=>({...s})),this.isDragging=!1,this.gestureSession=this.deps.gestures.hijack(e),this.gestureSession.onMove(this.onDragMove),this.gestureSession.onEnd(this.onDragEnd)});f(this,"onDragMove",e=>{if(!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,r=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(r)<3||(this.isDragging||(this.isDragging=!0,this.deps.render.request(ph)),this.data.points=this.initialPoints.map(o=>({x:o.x+s,y:o.y+r})),this.redraw())});f(this,"onDragEnd",()=>{var e,i;this.gestureSession=null,this.dragStartPosition&&(this.isDragging&&((i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData()),this.deps.render.stop(ph)),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});f(this,"handleRotateStart",()=>{this.deps.render.request(Gn)});f(this,"handleRotateMove",e=>{e&&(this.data.points=e,this.redraw())});f(this,"handleTapRotate",e=>{var i,s;e&&(this.data.points=e,this.redraw()),this.captureOriginalSize(),this.deps.render.once(Gn),(s=(i=this.furnitureEvents).onUpdate)==null||s.call(i,this.getData())});f(this,"handleScaleStart",()=>{this.deps.render.request(fh)});f(this,"handleScaleMove",e=>{e&&(this.data.points=e,this.redraw())});f(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(e=>({...e})),this.deps.render.request(gh)});f(this,"handleMove",e=>{var a;if(!this.editing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(e.global),s=(a=this.editableShape.getMoveButton())==null?void 0:a.getDragStartPosition();if(!s)return;const r=i.x-s.x,o=i.y-s.y;this.data.points=this.initialPoints.map(h=>({x:h.x+r,y:h.y+o})),this.redraw()});f(this,"handleMoveEnd",()=>{var e,i;this.initialPoints=[],this.deps.render.stop(gh),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});f(this,"handleTransformEnd",()=>{var e,i;this.deps.render.stop(Gn),this.deps.render.stop(fh),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});f(this,"handleDelete",()=>{var e,i;(i=(e=this.furnitureEvents).onRemove)==null||i.call(e,this.data.id)});f(this,"handleClick",()=>{var e,i;this.editing||(i=(e=this.furnitureEvents).onClick)==null||i.call(e,this.getData())});const{deps:i,data:s,textureAlias:r}=e;this.deps=i,this.config=i.furnitureConfig,this.controlsConfig=i.controlsConfig,this.furnitureEvents=i.events,this.data={...s,points:s.points.map(o=>({...o}))},this.textureAlias=r,this.captureOriginalSize(),this.createSprite(),this.updateSpriteTransform(),this.createEditControlLayer(),this.eventMode="static",this.cursor="pointer",this.setupInteraction(),this.applyEditing()}captureOriginalSize(){const e=this.data.points;if(e.length<4){this.originalSizeMeters=null;return}const i=tt(e[0],e[1]),s=tt(e[1],e[2]);this.originalSizeMeters={width:this.deps.coords.toMeters(Bt(i)),height:this.deps.coords.toMeters(Bt(s))}}createSprite(){const e=N.get(this.textureAlias);this.sprite=new jt(e),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="passive",this.addChild(this.sprite)}updateSpriteTransform(){const e=this.data.points;if(e.length<4)return;const i=Oe(e),s=e[1].x-e[0].x,r=e[1].y-e[0].y,o=Math.atan2(r,s),a=tt(e[0],e[1]),h=tt(e[1],e[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControlLayer(){const e={outlineStrokeColor:String(this.config.outlineStrokeColor),outlineStrokeWidth:this.config.outlineStrokeWidth,outlineDashed:this.config.outlineDashed,outlineDashArray:this.config.outlineDashArray,outlineFillColor:this.config.outlineFillColor?String(this.config.outlineFillColor):void 0,outlineOffset:this.config.outlineOffset,iconWrapperFillColor:String(this.config.iconWrapperFillColor),showRotateButton:!0,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,rotateMode:"step",stepRotateAngle:this.config.rotateDirection==="ccw"?-Math.PI/2:Math.PI/2,scaleMode:this.config.lockAspectRatio?"ratioLocked":"free",textColor:String(this.config.textColor),textPosition:this.config.textPosition,textOffset:this.config.textOffset,moveButtonOffset:this.controlsConfig.moveButtonOffset,textFontSize:this.controlsConfig.textFontSize,textFontFamily:this.controlsConfig.textFontFamily,textFontWeight:this.controlsConfig.textFontWeight};this.editableShape=new Jr({editControls:this.deps.editControls});const i={config:e,zonePoints:this.data.points,sizeConstraintPerEdge:this.resolveSizeConstraintPerEdge,contentLayer:Te,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotateStart,onRotateMove:this.handleRotateMove,onClickRotate:this.handleTapRotate,onRotateEnd:this.handleTransformEnd,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleTransformEnd,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd,onClick:this.handleClick}};this.editableShape.attach(this,{id:this.data.id,topology:"quad",layerOptions:i,editingState:{showRotateButton:!0,showScaleButton:!0,showRadialScaleButton:!1,showDeleteButton:!0,showMoveButton:!0,showBorder:!0,showSizeText:this.config.showSizeText},idleState:{showRotateButton:!1,showScaleButton:!1,showRadialScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1}})}setupInteraction(){this.clickHandler=new St(this,{onClick:e=>{!this.isDragging&&((e==null?void 0:e.target)===this||(e==null?void 0:e.target)===this.sprite)&&this.handleClick()}}),this.on("pointerdown",this.onDragStart,this)}redraw(){this.data.points.length<4||(this.updateSpriteTransform(),this.editableShape.updatePoints(this.data.points))}applyEditing(){this.editableShape.setEditing(this.editing),this.zIndex=this.editing?1e3:0}updateEditState(e){this.editing!==e&&(this.editing=e,this.applyEditing())}isEditing(){return this.editing}getData(){return{id:this.data.id,furnitureType:this.data.furnitureType,points:this.data.points.map(e=>({...e}))}}updateData(e){this.data={...e,points:e.points.map(i=>({...i}))},this.captureOriginalSize(),this.data.points.length>=4&&(this.updateSpriteTransform(),this.editableShape.updatePoints(this.data.points))}destroy(){var e,i,s;(e=this.editableShape)==null||e.detach(),(i=this.gestureSession)==null||i.cancel(),this.gestureSession=null,(s=this.clickHandler)==null||s.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class Sv{constructor(t){f(this,"furnitureMap",new Map);f(this,"unsubscribeFns",[]);this.appService=t,this.applyLayerVisibility(t.runtime.showFurnitures);const e=O(t.runtime,"editingFurnitureIds",s=>{w.log(`[runtime] editingFurnitureIds: ${s}`),this.updateEditState()}),i=O(t.runtime,"showFurnitures",s=>{w.log(`[runtime] showFurnitures: ${s}`),this.applyLayerVisibility(s)});this.unsubscribeFns.push(e,i)}async drawFurnitures(t){if(!t||t.length===0){this.clearAll();return}const e=new Set(this.furnitureMap.keys()),i=new Set(t.map(r=>r.id));for(const r of e)i.has(r)||this.removeFurniture(r);const s=[];for(const r of t){const o=this.furnitureMap.get(r.id);o?this.isDataEqual(o.getData(),r)||o.updateData(r):s.push(this.addFurniture(r))}await Promise.all(s)}async addFurniture(t){const e=this.appService;if(!e.furnitureConfig.assets.find(l=>l.type===t.furnitureType)){w.warn(`[FurnitureManager] No asset found for furnitureType: ${t.furnitureType}`);return}const r=`furniture_${t.furnitureType}`;await N.load(r);const o=yv(e,{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveFurniture)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateFurniture)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickFurniture)==null||d.call(c,l)}}),a=new xv({deps:o,data:t,textureAlias:r});this.furnitureMap.set(t.id,a),e.appContainer.addToLayer(Te,a),e.runtime.editingFurnitureIds.includes(t.id)&&(a.updateEditState(!0),this.moveToEditLayer(a))}removeFurniture(t){var i;const e=this.furnitureMap.get(t);e&&((i=e.parent)==null||i.removeChild(e),e.destroy(),this.furnitureMap.delete(t))}clearAll(){var t;for(const[,e]of this.furnitureMap)(t=e.parent)==null||t.removeChild(e),e.destroy();this.furnitureMap.clear()}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(Te);e&&(e.visible=t),this.furnitureMap.forEach(i=>{i.visible=t})}updateEditState(){const t=this.appService.runtime.editingFurnitureIds,{appContainer:e}=this.appService,i=e.getLayer(Te);this.furnitureMap.forEach((s,r)=>{const o=t.includes(r);s.updateEditState(o),o?this.moveToEditLayer(s):s.parent!==i&&this.moveToFurnitureLayer(s)})}moveToEditLayer(t){var e;(e=t.parent)==null||e.removeChild(t),this.appService.appContainer.addToLayer(Ee,t)}moveToFurnitureLayer(t){var e;(e=t.parent)==null||e.removeChild(t),this.appService.appContainer.addToLayer(Te,t)}getFurnitures(){const t=[];return this.furnitureMap.forEach(e=>{t.push(e.getData())}),t}isDataEqual(t,e){if(t.id!==e.id||t.furnitureType!==e.furnitureType||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++)if(Math.abs(t.points[i].x-e.points[i].x)>.1||Math.abs(t.points[i].y-e.points[i].y)>.1)return!1;return!0}destroy(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.clearAll()}}class vv{constructor(t){f(this,"editControlLayers",new Map);this.appService=t}registerEditControl(t,e){const i=this.appService;this.editControlLayers.has(t)&&this.unregisterEditControl(t);const s=new _S(i,e);if(!i.appContainer.addToLayer(Ee,s))throw w.warn(`[EditControlManager] Failed to add edit control layer for id: ${t}`),s.destroy(),new Error(`Failed to register edit control for id: ${t}`);if(this.editControlLayers.set(t,s),e.contentLayer){const o=i.appContainer.getLayer(Ee),a=i.appContainer.getLayer(e.contentLayer);o&&a&&(o.position.x!==a.position.x||o.position.y!==a.position.y)&&w.warn(`[EditControlManager] Edit layer position does not match content layer "${e.contentLayer}" position — edit controls will appear misaligned. Ensure "${e.contentLayer}" is in ORIGIN_TRACKED_LAYERS.`,{edit:o.position,content:a.position})}return s}unregisterEditControl(t){const e=this.editControlLayers.get(t);if(!e)return;this.appService.appContainer.removeFromLayer(Ee,e),e.destroy(),this.editControlLayers.delete(t)}getEditControl(t){return this.editControlLayers.get(t)}updateEditState(t,e){const i=this.editControlLayers.get(t);i&&i.updateEditState(e)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(e=>this.unregisterEditControl(e))}getAllEditControls(){return Array.from(this.editControlLayers.values())}hasEditControl(t){return this.editControlLayers.has(t)}}function fs(n){return n.charAt(0).toUpperCase()+n.slice(1)}const Di=class Di extends bl{constructor(e=po){super();f(this,"mapState",null);f(this,"components",{});f(this,"managers",{});f(this,"config",uo);f(this,"runtime");f(this,"appService");f(this,"coords");f(this,"scaleMin",.5);f(this,"scaleMax",5);f(this,"events",{});f(this,"instanceKey");f(this,"debugInstanceId");f(this,"previousLoggerRuntimeState",null);f(this,"isDestroying",!1);f(this,"hasActiveContextLoss",!1);f(this,"createdAtMs",Date.now());f(this,"lastMapDataAtMs",null);f(this,"lastMapDrawAtMs",null);f(this,"lastPathDataAtMs",null);f(this,"lastVisibilityChangeAtMs",null);f(this,"containerElement");f(this,"onWebGLContextLost",e=>{var r;const i=e;if((r=i.preventDefault)==null||r.call(i),this.hasActiveContextLoss)return;this.hasActiveContextLoss=!0;const s=this.getContextLossDiagnostics(e);w.error("[Pixi] WebGL context lost",s.summary),w.error("[Pixi] WebGL context lost tail",s.recentLifecycleTail),this.recordDebugLifecycleEvent("webglcontextlost",{eventType:e.type,statusMessage:i.statusMessage??null})});f(this,"onWebGLContextRestored",e=>{this.hasActiveContextLoss=!1,w.warn("[Pixi] WebGL context restored, scheduling render",this.getRendererDiagnostics({eventType:e.type})),this.recordDebugLifecycleEvent("webglcontextrestored",{eventType:e.type}),this.renderOnceNextFrame()});f(this,"emitter",Nx());f(this,"tickerState",{renderReasons:new Set,renderTimer:null,lastRequestReason:null,lastStopReason:null});f(this,"customCarpetResolvedMaxSizeCache",null);f(this,"pendingAsyncRender",!1);f(this,"isFirstMapDraw",!0);f(this,"isMapDrawn",!1);f(this,"onVisibilityChange",()=>{var i;this.lastVisibilityChangeAtMs=Date.now(),document.visibilityState==="visible"||(i=this.components.interaction)==null||i.clearTouches()});f(this,"onRendererResize",()=>{var e,i;this.isDestroying||((e=this.components.viewportContainer)==null||e.updateViewport(this.config),(i=this.components.background)==null||i.updateViewportBounds(this.getViewportBounds()),this.renderOnceNextFrame())});this.instanceKey=e,this.debugInstanceId=hh(),this.coords=new nS(()=>{var i;return((i=this.runtime)==null?void 0:i.unit)??"meter"}),this.appService=new Rc(this),globalThis.__PIXI_APP__=this,this.recordDebugLifecycleEvent("app:create",{instanceKey:e})}getRendererDiagnostics(e={}){var r,o,a,h,l,c,d,u,p,g,y;const i=this.containerElement&&"getBoundingClientRect"in this.containerElement&&typeof this.containerElement.getBoundingClientRect=="function"?this.containerElement.getBoundingClientRect():null,s=((r=this.renderer)==null?void 0:r.type)===te.WEBGPU?"webgpu":((o=this.renderer)==null?void 0:o.type)===te.WEBGL?"webgl":"unknown";return{sessionId:zn().getSessionId(),instanceId:this.debugInstanceId,requestedPreference:this.config.global.rendererPreference,rendererType:s,rendererWidth:((a=this.renderer)==null?void 0:a.width)??null,rendererHeight:((h=this.renderer)==null?void 0:h.height)??null,canvasWidth:((l=this.canvas)==null?void 0:l.width)??null,canvasHeight:((c=this.canvas)==null?void 0:c.height)??null,canvasClientWidth:((d=this.canvas)==null?void 0:d.clientWidth)??null,canvasClientHeight:((u=this.canvas)==null?void 0:u.clientHeight)??null,containerWidth:(i==null?void 0:i.width)??null,containerHeight:(i==null?void 0:i.height)??null,mapId:((p=this.mapState)==null?void 0:p.id)??null,mapWidth:((g=this.mapState)==null?void 0:g.width)??null,mapHeight:((y=this.mapState)==null?void 0:y.height)??null,isMapDrawn:this.isMapDrawn,visibilityState:document.visibilityState,...e}}getElapsedMsSince(e){return typeof e=="number"?Math.max(0,Date.now()-e):null}getDeviceDiagnostics(){const e=globalThis.navigator;return{devicePixelRatio:globalThis.devicePixelRatio??null,userAgent:(e==null?void 0:e.userAgent)??null,hardwareConcurrency:(e==null?void 0:e.hardwareConcurrency)??null,deviceMemory:(e==null?void 0:e.deviceMemory)??null,documentWasDiscarded:"wasDiscarded"in document?document.wasDiscarded:null}}getWebGLDiagnostics(){var r;const e=(r=this.renderer)==null?void 0:r.gl;if(!e)return{contextAttributes:null,isContextLost:null,drawingBufferWidth:null,drawingBufferHeight:null,vendor:null,renderer:null,version:null,shadingLanguageVersion:null,maxTextureSize:null,maxRenderbufferSize:null};const i=o=>{if(typeof o!="number"||typeof e.getParameter!="function")return null;try{return e.getParameter(o)??null}catch{return null}},s=typeof e.getExtension=="function"?e.getExtension("WEBGL_debug_renderer_info"):null;return{contextAttributes:typeof e.getContextAttributes=="function"?e.getContextAttributes()??null:null,isContextLost:typeof e.isContextLost=="function"?e.isContextLost():null,drawingBufferWidth:e.drawingBufferWidth??null,drawingBufferHeight:e.drawingBufferHeight??null,vendor:s&&typeof s.UNMASKED_VENDOR_WEBGL=="number"?i(s.UNMASKED_VENDOR_WEBGL):null,renderer:s&&typeof s.UNMASKED_RENDERER_WEBGL=="number"?i(s.UNMASKED_RENDERER_WEBGL):null,version:i(e.VERSION),shadingLanguageVersion:i(e.SHADING_LANGUAGE_VERSION),maxTextureSize:i(e.MAX_TEXTURE_SIZE),maxRenderbufferSize:i(e.MAX_RENDERBUFFER_SIZE)}}getRecentLifecycleTail(){return zn().readCurrentSession().slice(-Di.CONTEXT_LOSS_TAIL_SIZE).map(e=>({seq:e.seq,ts:e.ts,event:e.event,sessionId:e.sessionId,instanceId:e.instanceId??null,visibilityState:e.visibilityState??null,rendererType:e.rendererType??null,mapId:e.mapId??null,detail:e.detail}))}getContextLossDiagnostics(e){const i=e;return{summary:this.getRendererDiagnostics({eventType:e.type,statusMessage:i.statusMessage??null,uptimeMs:this.getElapsedMsSince(this.createdAtMs),timeSinceLastMapDataMs:this.getElapsedMsSince(this.lastMapDataAtMs),timeSinceLastMapDrawMs:this.getElapsedMsSince(this.lastMapDrawAtMs),timeSinceLastPathDataMs:this.getElapsedMsSince(this.lastPathDataAtMs),timeSinceLastVisibilityChangeMs:this.getElapsedMsSince(this.lastVisibilityChangeAtMs),device:this.getDeviceDiagnostics(),webgl:this.getWebGLDiagnostics()}),recentLifecycleTail:this.getRecentLifecycleTail()}}attachRendererDiagnostics(){var e,i;if(((e=this.renderer)==null?void 0:e.type)!==te.WEBGL||typeof((i=this.canvas)==null?void 0:i.addEventListener)!="function"){w.debug("[Pixi] Renderer diagnostics initialized",this.getRendererDiagnostics({contextListeners:!1}));return}this.canvas.addEventListener("webglcontextlost",this.onWebGLContextLost),this.canvas.addEventListener("webglcontextrestored",this.onWebGLContextRestored),w.debug("[Pixi] Renderer diagnostics initialized",this.getRendererDiagnostics({contextListeners:!0}))}detachRendererDiagnostics(){var e;typeof((e=this.canvas)==null?void 0:e.removeEventListener)=="function"&&(this.canvas.removeEventListener("webglcontextlost",this.onWebGLContextLost),this.canvas.removeEventListener("webglcontextrestored",this.onWebGLContextRestored))}getDebugRendererType(){var e,i;return((e=this.renderer)==null?void 0:e.type)===te.WEBGPU?"webgpu":((i=this.renderer)==null?void 0:i.type)===te.WEBGL?"webgl":"unknown"}recordDebugLifecycleEvent(e,i){var s;zn().record({event:e,instanceId:this.debugInstanceId,visibilityState:typeof document<"u"?document.visibilityState:null,rendererType:this.getDebugRendererType(),mapId:((s=this.mapState)==null?void 0:s.id)??null,detail:i})}async initialize(e){const{resizeTo:i,events:s,config:r,runtime:o={},...a}=e;this.config=mr(Na({},uo,r??{},(g,y)=>{if(Array.isArray(y))return y})),this.validateCustomZoneTypes(this.config),this.previousLoggerRuntimeState=nx(),sx({getLoggerConfig:()=>this.config.logger,getLegacyEnabled:()=>this.config.global.enableLogger}),w.log("Applying config",this.config,r),this.runtime=mr(Object.assign({},Pd,o));const h=this.instanceKey===po;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={gcActive:!1,autoStart:!1,sharedTicker:c,eventFeatures:{move:l,globalMove:!1,click:l,wheel:l}},u={resizeTo:h?i:void 0,resolution:this.config.global.resolution,antialias:c?!1:pv(),depth:!c,autoDensity:!0,backgroundColor:0,backgroundAlpha:0,...d,...a},p=this.config.global.rendererPreference;if(p==="webgpu")try{await this.init({...u,preference:"webgpu"})}catch(g){w.warn("[Pixi] WebGPU initialization failed, falling back to WebGL:",g),await this.init({...u,preference:"webgl"})}else await this.init({...u,preference:p});this.attachRendererDiagnostics(),this.recordDebugLifecycleEvent("app:initialized",{isMainInstance:h,isPerformanceMode:c,requestedPreference:p}),w.debug("[Pixi] Renderer initialized",this.getRendererDiagnostics({isMainInstance:h,isPerformanceMode:c})),this.preloadAssets(),this.scaleMax=this.config.interaction.zoomRange.max,this.scaleMin=this.config.interaction.zoomRange.min,this.events=s,this.initializeViewportContainer(),this.initializeInteraction(),this.initializeAppContainer(),this.renderer.on("resize",this.onRendererResize),this.managers.mapManager=new fS(this.appService),this.managers.heatmapManager=new bS(this.appService),this.managers.pathManager=new SS(this.appService),this.managers.controlsManager=new IS(this.appService),this.managers.detectedObjectManager=new FS(this.appService),this.managers.customElementsManager=new ov(this.appService),this.managers.roomsManager=new uv(this.appService),this.managers.customCarpetManager=new mv(this.appService),this.managers.furnitureManager=new Sv(this.appService),this.managers.editControlManager=new vv(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(e){var a,h,l,c,d,u,p;this.lastMapDataAtMs=Date.now(),this.isMapDrawn=!1,w.log("[Map] drawMap",e);const{size:i,resolution:s,origin:r,id:o}=e;((a=this.mapState)==null?void 0:a.id)!==void 0&&this.mapState.id!==o&&this.managers.pathManager.clear(),(r[0]!==((h=this.mapState)==null?void 0:h.origin.x)||r[1]!==((l=this.mapState)==null?void 0:l.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(...r),this.managers.pathManager.updatePositionByOrigin(...r),this.managers.heatmapManager.updatePositionByOrigin(...r)),this.mapState={id:e.id,status:e.status===1,origin:{x:r[0],y:r[1]},charger:{x:e.charger.coordinate[0],y:e.charger.coordinate[1]},chargerDirection:e.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},this.coords.setResolution(s),w.debug("[Map] Structured map state updated",{mapId:o,mapWidth:i[0],mapHeight:i[1],mapResolution:s,mapStatus:e.status===1,originX:r[0],originY:r[1]}),this.isFirstMapDraw&&(this.isFirstMapDraw=!1,(d=(c=this.events)==null?void 0:c.onMapFirstDrawed)==null||d.call(c,this.mapState)),(p=(u=this.events)==null?void 0:u.onMapDrawed)==null||p.call(u,this.mapState),this.emitter.emit("mapStateUpdate",this.mapState),await this.managers.mapManager.drawMap(e),i[0]===0||i[1]===0?(w.warn("[Map] Structured map cleared by incoming data",this.getRendererDiagnostics({mapId:o,mapWidth:i[0],mapHeight:i[1],mapResolution:s,mapStatus:e.status===1,originX:r[0],originY:r[1]})),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.lastMapDrawAtMs=Date.now(),this.managers.heatmapManager.onMapLoaded()),this.emitRoomsDrawed(),this.renderOnce()}async drawRasterMap(e){var a,h,l,c,d,u;this.lastMapDataAtMs=Date.now(),this.isMapDrawn=!1,w.log("[Map] drawRasterMap",e);const{mapHeader:i,mapData:s}=e,{originX:r,originY:o}=i;(r!==((a=this.mapState)==null?void 0:a.origin.x)||o!==((h=this.mapState)==null?void 0:h.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(r,o),this.managers.pathManager.updatePositionByOrigin(r,o),this.managers.heatmapManager.updatePositionByOrigin(r,o)),this.mapState={id:i.id,status:i.mapStable,origin:{x:r,y:o},charger:{x:i.chargeX,y:i.chargeY},chargerDirection:i.chargeDirection??0,resolution:i.mapResolution*100,width:i.mapWidth,height:i.mapHeight,version:i.version,mapType:"raster"},this.coords.setResolution(i.mapResolution*100),w.debug("[Map] Raster map state updated",{mapId:i.id,mapWidth:i.mapWidth,mapHeight:i.mapHeight,mapResolution:i.mapResolution*100,mapStatus:i.mapStable,originX:r,originY:o,version:i.version??null}),this.isFirstMapDraw&&(this.isFirstMapDraw=!1,(c=(l=this.events)==null?void 0:l.onMapFirstDrawed)==null||c.call(l,this.mapState)),(u=(d=this.events)==null?void 0:d.onMapDrawed)==null||u.call(d,this.mapState),this.emitter.emit("mapStateUpdate",this.mapState),await this.managers.mapManager.drawRasterMap(s.parsed,this.mapState),i.mapWidth===0||i.mapHeight===0?(w.warn("[Map] Raster map cleared by incoming data",this.getRendererDiagnostics({mapId:i.id,mapWidth:i.mapWidth,mapHeight:i.mapHeight,mapResolution:i.mapResolution*100,mapStatus:i.mapStable,originX:r,originY:o,version:i.version??null})),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.lastMapDrawAtMs=Date.now(),this.managers.heatmapManager.onMapLoaded()),this.emitRoomsDrawed(),this.renderOnce()}emitRoomsDrawed(){var r,o;const e=(r=this.events)==null?void 0:r.onRoomsDrawed;if(!e)return;const i=((o=this.mapState)==null?void 0:o.origin)??{x:0,y:0},s=this.managers.mapManager.getAllRooms().map(a=>({id:a.id,centerPoint:a.centerPoint,relativeCenterPoint:{x:a.centerPoint.x-i.x,y:a.centerPoint.y-i.y}}));e(s)}drawPath(e){var i,s;this.lastPathDataAtMs=Date.now(),w.log("[Path] drawPath",e),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:e.pathHeader.pathId,type:e.pathHeader.type,direction:e.pathHeader.direction,count:e.pathHeader.count,initFlag:e.pathHeader.initFlag,robotPosition:e.pathPoints[e.pathPoints.length-1]??null}),this.managers.pathManager.draw(e),this.renderOnce()}async drawRoomProperty(e){var i,s;w.log("[Room] drawRoomProperty",e),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,e),await this.managers.roomsManager.drawRoomProperty(e),this.renderOnceNextFrame()}async drawCustomCarpets(e){w.log("[CustomCarpets] drawCustomCarpets",e),await this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawFurnitures(e){w.log("[Furniture] drawFurnitures",e),await this.managers.furnitureManager.drawFurnitures(e),this.renderOnceNextFrame()}drawHeatmap(e){w.log("[Heatmap] drawHeatmap",e),this.managers.heatmapManager.draw(e),this.renderOnce()}drawForbiddenSweepZones(e){w.log("[Controls] drawForbiddenSweepZones",e),this.managers.controlsManager.drawForbiddenSweepZones(e),this.renderOnceNextFrame()}drawForbiddenMopZones(e){w.log("[Controls] drawForbiddenMopZones",e),this.managers.controlsManager.drawForbiddenMopZones(e),this.renderOnceNextFrame()}drawCleanZones(e){w.log("[Controls] drawCleanZones",e),this.managers.controlsManager.drawCleanZones(e),this.renderOnceNextFrame()}drawCustomZones(e,i){if($e(e)){w.warn(`[MapApplication] drawCustomZones: '${e}' is a built-in type; use draw${fs(e)}s() instead`);return}w.log("[Controls] drawCustomZones",e,i),this.managers.controlsManager.drawCustomZones(e,i),this.renderOnceNextFrame()}getCustomZones(e){return $e(e)?(w.warn(`[MapApplication] getCustomZones: '${e}' is a built-in type; use get${fs(e)}s() instead`),[]):this.managers.controlsManager.getCustomZones(e)}clearCustomZones(e){if($e(e)){w.warn(`[MapApplication] clearCustomZones: '${e}' is a built-in type; use clearAll${fs(e)}s() instead`);return}w.log("[Controls] clearCustomZones",e),this.managers.controlsManager.clearCustomZones(e),this.renderOnceNextFrame()}setEditingCustomZones(e,i){if($e(e)){w.warn(`[MapApplication] setEditingCustomZones: '${e}' is a built-in type; use runtime.editing${fs(e)}Ids instead`);return}this.runtime.editingCustomZoneIds={...this.runtime.editingCustomZoneIds??{},[e]:[...i]}}drawVirtualWalls(e){w.log("[Controls] drawVirtualWalls",e),this.managers.controlsManager.drawVirtualWalls(e),this.renderOnceNextFrame()}drawSpots(e){w.log("[Controls] drawSpots",e),this.managers.controlsManager.drawSpots(e),this.renderOnceNextFrame()}drawPurifyPoints(e){w.log("[Controls] drawPurifyPoints",e),this.managers.controlsManager.drawPurifyPoints(e),this.renderOnceNextFrame()}drawWayPoints(e){w.log("[Controls] drawWayPoints",e),this.managers.controlsManager.drawWayPoints(e),this.renderOnceNextFrame()}async drawDetectedObjects(e){w.log("[DetectedObject] drawDetectedObjects",e),await this.managers.detectedObjectManager.drawDetectedObjects(e),this.renderOnceNextFrame()}drawCustomCarpet(e){w.log("[CustomCarpet] drawCustomCarpet",e),this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawCustomElements(e){w.log("[CustomElements] drawCustomElements",e),await this.managers.customElementsManager.drawCustomElements(e),this.renderOnceNextFrame()}getForbiddenSweepZones(){return this.managers.controlsManager.getForbiddenSweepZones()}getForbiddenMopZones(){return this.managers.controlsManager.getForbiddenMopZones()}getCleanZones(){return this.managers.controlsManager.getCleanZones()}getVirtualWalls(){return this.managers.controlsManager.getVirtualWalls()}getSpots(){return this.managers.controlsManager.getSpots()}getPurifyPoints(){return this.managers.controlsManager.getPurifyPoints()}clearAllPurifyPoints(){this.managers.controlsManager.clearAllPurifyPoints(),this.renderOnceNextFrame()}getWayPoints(){return this.managers.controlsManager.getWayPoints()}getEffectiveDividerPoints(){return this.managers.controlsManager.getEffectiveDividerPoints()}getCustomCarpets(){return this.managers.customCarpetManager.getCustomCarpets()}getFurnitures(){return this.managers.furnitureManager.getFurnitures()}getDividerEndPoints(){return this.managers.controlsManager.getDividerEndPoints()}resetPanZoom(){this.components.interaction.setPanZoom()}forceEndGesture(){w.log("[Map] forceEndGesture"),this.components.interaction.forceEndGesture()}fitMapToView(e,i=!1){if(!e||e.minX===e.maxX||e.minY===e.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,r=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(e,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-r*2),g=u*(1-s*2),y=p/l,m=g/c,x=Math.min(y,m),S=this.config.interaction.fitMinScale,v=this.config.interaction.fitMaxScale,b=Math.max(S,Math.min(v,x));this.setScaleBounds(this.config.interaction.zoomRange.min,this.config.interaction.zoomRange.max),b<this.scaleMin&&(this.setScaleBounds(b,this.scaleMax),w.debug("[MapApplication] scaleMin lowered for fit:",{configured:this.config.interaction.zoomRange.min,adjusted:b})),b>this.scaleMax&&(this.setScaleBounds(this.scaleMin,b),w.debug("[MapApplication] scaleMax raised for fit:",{configured:this.config.interaction.zoomRange.max,adjusted:b}));const P=e.minX+(e.maxX-e.minX)/2,C=e.minY+(e.maxY-e.minY)/2,_=this.config.map.autoFitOffset||{x:0,y:0},R=d/2+(_.x||0),M=u/2+(_.y||0),A=Math.cos(a),T=Math.sin(a),I=P*A-C*T,D=P*T+C*A,B=R-I*b,j=M-D*b;w.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:e,rotatedBounds:h,finalScale:b,position:{x:B,y:j}}),this.components.interaction.setPanZoom({targetPosition:{x:B,y:j},targetScale:{x:b,y:b},setCenter:!0,setScale:!0},i)}setScaleBounds(e,i){this.scaleMin=e,this.scaleMax=i,this.components.interaction.scaleMin=e,this.components.interaction.scaleMax=i}validateCustomZoneTypes(e){const i=["minSize","strokeColor","strokeWidth","fillColor","outlineOffset","outlineStrokeColor","outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","iconWrapperFillColor","textColor","textPosition","textOffset","showRotateButton","editing","normal"],s=e.customZoneTypes??{},r=_h.cleanZone;for(const[,o]of Object.entries(s))for(const a of i)o[a]===void 0&&(o[a]=r[a])}calculateRotatedBounds(e,i){if(i===0)return e;const s=(e.minX+e.maxX)/2,r=(e.minY+e.maxY)/2,o=[{x:e.minX-s,y:e.minY-r},{x:e.maxX-s,y:e.minY-r},{x:e.maxX-s,y:e.maxY-r},{x:e.minX-s,y:e.maxY-r}],a=Math.cos(i),h=Math.sin(i),l=o.map(g=>({x:g.x*a-g.y*h,y:g.x*h+g.y*a}));let c=1/0,d=1/0,u=-1/0,p=-1/0;return l.forEach(g=>{c=Math.min(c,g.x),d=Math.min(d,g.y),u=Math.max(u,g.x),p=Math.max(p,g.y)}),{minX:c+s,minY:d+r,maxX:u+s,maxY:p+r}}getViewportBounds(){var e;return((e=this.components.viewportContainer)==null?void 0:e.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(e){Object.assign(this.runtime,e),w.log("[runtime] runtime updated",e),this.renderOnceNextFrame()}updateConfig(e){var s,r,o;Na(this.config,e,(a,h)=>{if(Array.isArray(h))return h}),e.customZoneTypes&&this.validateCustomZoneTypes(this.config),(s=this.managers.controlsManager)==null||s.updateRenderOrder(),((r=e.controls)==null?void 0:r.carpet)!==void 0&&((o=this.managers.customCarpetManager)==null||o.refreshConfig()),w.log("[Config] Configuration updated",e),this.renderOnceNextFrame()}metersToPixels(e){return this.coords.toPixels(ut(e))}pixelsToMeters(e){return this.coords.toMeters(Bt(e))}toFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e/s}fromFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e*s}getViewportCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate center point"),null;const e=this.getViewportBounds(),i=e.x+e.width/2,s=e.y+e.height/2,r=this.components.appContainer,o=r.scale.x,a=r.getMapRotationRadians(),h=i-r.x,l=s-r.y,c=h/o,d=l/o,u=Math.cos(a),p=Math.sin(a),g=c*u+d*p,y=-c*p+d*u,m=g-this.mapState.origin.x,x=y-this.mapState.origin.y;return{x:m,y:x}}getMapCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate map center point"),null;const e=this.managers.mapManager.mapBounds;if(e.minX===1/0||e.minY===1/0||e.maxX===-1/0||e.maxY===-1/0)return w.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(e.minX+e.maxX)/2,s=(e.minY+e.maxY)/2,r=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:r,y:o}}getWallPointsByViewportCenter(e){var g;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:r=0,offsetY:o=0}=e||{},a=this.getViewportCenterPoint()||{x:0,y:0},l=this.coords.toPixels(ut(i))/2,c=((g=this.components.appContainer)==null?void 0:g.getMapRotationRadians())||0,d=Math.cos(c),u=Math.sin(c);let p;return s==="horizontal"?p=[{vx:-l+r,vy:o},{vx:l+r,vy:o}]:p=[{vx:r,vy:-l+o},{vx:r,vy:l+o}],p.map(y=>({x:a.x+y.vx*d+y.vy*u,y:a.y-y.vx*u+y.vy*d}))}getForbiddenSweepZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getForbiddenMopZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getCleanZonePointsByViewportCenter(e){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:r=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,r,o)}getSpotPointByViewportCenter(e){const{offsetX:i=0,offsetY:s=0}=e||{},r=this.getViewportCenterPoint()||{x:0,y:0},o=r.x+i,a=r.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(e){const{furnitureType:i=1,offsetX:s=0,offsetY:r=0}=e||{},o=this.config.furniture.assets.find(h=>h.type===i),a=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:a,widthMeters:(o==null?void 0:o.width)??1.8,heightMeters:(o==null?void 0:o.height)??2,applyMapRotation:!0,visualOffsetX:s,visualOffsetY:r})}getResolvedCustomCarpetMaxSize(){const e=this.config.controls.carpet.maxSize;if(this.customCarpetResolvedMaxSizeCache&&this.customCarpetResolvedMaxSizeCache.key===e)return this.customCarpetResolvedMaxSizeCache.value;const i=Us(this.config.controls.carpet.minSize,e,"carpet");return this.customCarpetResolvedMaxSizeCache={key:e,value:i},i}getCustomCarpetPointsByViewportCenter(e){const s=this.config.controls.carpet.minSize,r=this.getResolvedCustomCarpetMaxSize(),{offsetX:o=0,offsetY:a=0}=e||{},h=(g,y)=>{const m=typeof g=="number"&&Number.isFinite(g)?g:y;return r!=null?Math.min(Math.max(m,s),r):Math.max(m,s)},l=(e==null?void 0:e.width)??(e==null?void 0:e.height),c=(e==null?void 0:e.height)??(e==null?void 0:e.width),d=h(l,s),u=h(c,s),p=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:p,widthMeters:d,heightMeters:u,applyMapRotation:!0,visualOffsetX:o,visualOffsetY:a})}getRectPointsByCenter(e){const{center:i,width:s,height:r,applyMapRotation:o=!0}=e;return this.buildRectPoints({center:i,widthMeters:s,heightMeters:r,applyMapRotation:o})}areRoomsAdjacent(e){return!e||e.length===0?(w.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(e)}isPointInAnyRoom(e){return!e||typeof e.x!="number"||typeof e.y!="number"?(w.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(e):(w.warn("[Room] Map state not available"),null)}isPointInRoom(e,i){return!e||typeof e.x!="number"||typeof e.y!="number"?(w.warn("[Room] Invalid point provided"),!1):this.mapState?this.managers.mapManager.isPointInRoom(e,i):(w.warn("[Room] Map state not available"),!1)}isWallIntersectsAnyRoom(e){return!e||e.length!==2||!e[0]||!e[1]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"?(w.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(e):(w.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(e){return!e||e.length!==4||!e[0]||!e[1]||!e[2]||!e[3]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"||typeof e[2].x!="number"||typeof e[2].y!="number"||typeof e[3].x!="number"||typeof e[3].y!="number"?(w.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(e):(w.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(e,i,s){var h,l;if(!e||e.length<1)return w.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(e.length!==1&&e.length!==2&&e.length!==4)return w.warn("[Distance] Invalid points array: must have exactly 1 (point), 2 (wall) or 4 (zone) points"),!1;if(i<=0)return w.warn("[Distance] Invalid threshold: must be greater than 0"),!1;if(!this.mapState)return w.warn("[Distance] Map state not available"),!1;const{checkCharger:r=!0,checkRobot:o=!1}=s||{};if(!r&&!o)return w.warn("[Distance] At least one of checkCharger or checkRobot must be true"),!1;const a=this.coords.toPixels(ut(i));if(r){const c=this.appService.getChargerPosition();if(c){const d=(h=this.mapState)==null?void 0:h.charger.x,u=(l=this.mapState)==null?void 0:l.charger.y;if(d===0&&u===0)return w.warn("[Distance] Charger position not available"),!1;const p=Qa(c,e);if(p<=a)return w.log(`[Distance] Too close to charger: ${p.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else w.warn("[Distance] Charger position not available")}if(o){const c=this.appService.getRobotPosition();if(c){const d=Qa(c,e);if(d<=a)return w.log(`[Distance] Too close to robot: ${d.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else w.warn("[Distance] Robot position not available")}return!1}async snapshot(e){this.render();const{snapshot:i,global:s}=this.config,r=(e==null?void 0:e.backgroundColor)??s.backgroundColor,o=this.components.appContainer,a=o.getSnapshotBounds(),h=Math.floor(a.x),l=Math.floor(a.y),c=Math.ceil(a.x+a.width)-h,d=Math.ceil(a.y+a.height)-l;if(c<=0||d<=0)return w.error("[MapApplication] Snapshot failed: invalid bounds",a),"";const u=i.resolution||window.devicePixelRatio||2,p=Nr.create({width:c,height:d,resolution:u}),g=new H;g.rect(0,0,c,d).fill(r);const y=new U;y.translate(-h,-l);try{return this.renderer.render({container:g,target:p}),this.renderer.render({container:o,target:p,transform:y,clear:!1}),await this.renderer.extract.base64({target:p,format:i.format,quality:i.quality,antialias:i.antialias})}catch(m){return w.error("[MapApplication] Snapshot failed:",m),""}finally{g.destroy(),p.destroy(!0)}}async snapshotByData({map:e,path:i,roomProperties:s,customElements:r,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c,carpets:d},u={},p){const g=`SNAPSHOT_${hh()}`;w.log(`[MapApplication] ${g} snapshot start`);const y=new Di(g);try{if(await y.initialize({config:this.config,runtime:u}),!e)throw new Error("Map data is required");if(e.startsWith("7b22")){const x=Md(e);await y.drawMap(x)}else{const x=Td(e,{pointsStructured:!0});if(x)await y.drawRasterMap(x);else throw new Error("Failed to decode raster map data")}if(i){const{decodePath:x}=await Ae(async()=>{const{decodePath:v}=await import("./theme.BW-xO32x.js").then(b=>b.f);return{decodePath:v}},__vite__mapDeps([4,2])),S=x(i);y.drawPath(S)}s&&s.length>0&&await y.drawRoomProperty(s),o&&o.length>0&&y.drawForbiddenSweepZones(o),a&&a.length>0&&y.drawForbiddenMopZones(a),h&&h.length>0&&y.drawVirtualWalls(h),d&&d.length>0&&await y.drawCustomCarpets(d),c&&c.length>0&&await y.drawFurnitures(c),l&&l.length>0&&await y.drawDetectedObjects(l),r&&r.length>0&&await y.drawCustomElements(r);const m=await y.snapshot(p);return w.log(`[MapApplication] ${g} snapshot completed successfully`),m}catch(m){throw w.error(`[MapApplication] ${g} snapshot other map failed:`,m),m}finally{w.log(`[MapApplication] ${g} destroy`),y.destroy()}}renderOnce(){w.debug("[Pixi] renderOnce");try{this.render()}catch(e){w.error("[Pixi] renderOnce failed",this.getRendererDiagnostics({error:e}))}}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{w.debug("[Pixi] renderOnceNextFrame");try{this.render()}catch(e){w.error("[Pixi] renderOnceNextFrame failed",this.getRendererDiagnostics({error:e}))}finally{this.pendingAsyncRender=!1}}))}requestRender(e,i=!1){if(this.tickerState.lastRequestReason=e,!i){this.renderOnceNextFrame(),this.emitRenderStateUpdate();return}this.tickerState.renderReasons.add(e),this.ticker.started||(w.debug(`🎬 [Ticker] START: ${e}`),this.ticker.start()),this.emitRenderStateUpdate()}stopRender(e){this.tickerState.lastStopReason=e,this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100),this.emitRenderStateUpdate()}getRenderState(){var i;const e=!!((i=this.ticker)!=null&&i.started);return{continuous:e,fps:e?Math.round(this.ticker.FPS):0,lastRequestReason:this.tickerState.lastRequestReason,lastStopReason:this.tickerState.lastStopReason,activeReasons:[...this.tickerState.renderReasons]}}emitRenderStateUpdate(){this.emitter.emit("renderStateUpdate",this.getRenderState())}destroy(){var e,i,s,r,o,a,h,l,c,d,u,p,g;if(!this.isDestroying){this.isDestroying=!0,w.log("[MapApplication] destroy"),this.recordDebugLifecycleEvent("destroy:start");try{this.tickerState.renderTimer&&(clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=null),this.tickerState.renderReasons.clear(),this.emitter.all.clear(),(e=this.renderer)==null||e.off("resize",this.onRendererResize),document.removeEventListener("visibilitychange",this.onVisibilityChange),(i=this.managers.pathManager)==null||i.destroy(),(s=this.managers.mapManager)==null||s.destroy(),(r=this.managers.controlsManager)==null||r.destroy(),(o=this.managers.furnitureManager)==null||o.destroy(),(a=this.managers.detectedObjectManager)==null||a.destroy(),(h=this.managers.customElementsManager)==null||h.destroy(),(l=this.managers.roomsManager)==null||l.destroy(),(c=this.components.interaction)==null||c.destroy(),(d=this.components.background)==null||d.destroy(),(u=this.components.viewportContainer)==null||u.destroy(),(p=this.components.appContainer)==null||p.destroy(),(g=this.managers.heatmapManager)==null||g.destroy(),this.detachRendererDiagnostics(),rx(this.previousLoggerRuntimeState),this.previousLoggerRuntimeState=null,globalThis.__PIXI_APP__===this&&delete globalThis.__PIXI_APP__,super.destroy({removeView:!0},{children:!0,texture:!0,textureSource:!0,context:!0})}finally{globalThis.__PIXI_APP__===this&&delete globalThis.__PIXI_APP__,this.recordDebugLifecycleEvent("destroy:end")}}}initializeViewportContainer(){this.components.viewportContainer=new oS(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const e=this.getViewportBounds();this.components.background=new fv(this.config.global,e,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Gs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new cS(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Vx(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(e,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&(w.debug("⏸️ [Ticker] STOP"),this.ticker&&(this.ticker.stop(),this.emitRenderStateUpdate()))},i)}generateZonePoints(e,i,s){const r=this.getViewportCenterPoint()||{x:0,y:0};return this.buildRectPoints({center:r,widthMeters:e,heightMeters:e,applyMapRotation:!0,visualOffsetX:i,visualOffsetY:s})}buildRectPoints(e){var y;const{center:i,widthMeters:s,heightMeters:r,applyMapRotation:o,visualOffsetX:a=0,visualOffsetY:h=0}=e,l=this.coords.toPixels(ut(s))/2,c=this.coords.toPixels(ut(r))/2,d=o&&((y=this.components.appContainer)==null?void 0:y.getMapRotationRadians())||0,u=Math.cos(d),p=Math.sin(d);return[{vx:-l+a,vy:-c+h},{vx:l+a,vy:-c+h},{vx:l+a,vy:c+h},{vx:-l+a,vy:c+h}].map(m=>({x:i.x+m.vx*u+m.vy*p,y:i.y-m.vx*p+m.vy*u}))}preloadAssets(){const e=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:e}),s.push("robot"),N.add({alias:"chargingStation",src:i}),s.push("chargingStation"),N.add({alias:"deleteIcon",src:this.config.controls.deleteIconSrc}),s.push("deleteIcon"),N.add({alias:"rotateIcon",src:this.config.controls.rotateIconSrc}),s.push("rotateIcon"),N.add({alias:"scaleIcon",src:this.config.controls.scaleIconSrc}),s.push("scaleIcon"),N.add({alias:"moveIcon",src:this.config.controls.moveIconSrc}),s.push("moveIcon"),N.add({alias:"checkmark",src:this.config.room.selectionIndicator.iconSrc}),s.push("checkmark"),N.add({alias:"spotIcon",src:this.config.controls.spot.iconSrc}),s.push("spotIcon"),N.add({alias:"purifyIcon",src:this.config.controls.purifyPoint.iconSrc}),s.push("purifyIcon"),N.add({alias:"wayPoint",src:this.config.controls.wayPoint.normal.iconSrc}),s.push("wayPoint"),N.add({alias:"wayPointActive",src:this.config.controls.wayPoint.editing.iconSrc}),s.push("wayPointActive"),N.add({alias:"horizontalScaleIcon",src:this.config.controls.horizontalScaleIconSrc}),s.push("horizontalScaleIcon"),N.add({alias:"verticalScaleIcon",src:this.config.controls.verticalScaleIconSrc}),s.push("verticalScaleIcon"),this.config.room.property.cleanMode.assets.forEach((r,o)=>{const a=`cleanMode_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.suction.assets.forEach((r,o)=>{const a=`fan_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.cistern.assets.forEach((r,o)=>{const a=`water_${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.cleanTimes.assets.forEach((r,o)=>{const a=`cleanTimes${o+1}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.floorType.assets.forEach((r,o)=>{if(!r)return;const a=`floorType${o}`;N.add({alias:a,src:r}),s.push(a)}),this.config.room.property.customAssets&&Object.entries(this.config.room.property.customAssets).forEach(([r,o])=>{o.forEach((a,h)=>{const l=`custom_${r}_${h}`;N.add({alias:l,src:a}),s.push(l)})}),this.config.furniture.assets.forEach(r=>{const o=`furniture_${r.type}`;N.add({alias:o,src:r.src}),s.push(o)}),N.backgroundLoad(s)}setupMapRotationListener(){this.applyMapRotation(this.runtime.mapRotation),O(this.runtime,"mapRotation",e=>{this.applyMapRotation(e)})}applyMapRotation(e){const i=(e%360+360)%360;w.log(`[MapApplication] Applying map rotation: ${i}°`),this.components.appContainer.setMapRotation(i);const s=this.managers.mapManager.mapBounds;s&&s.minX!==1/0&&s.maxX!==-1/0&&this.fitMapToView(s,!1),this.emitter.emit("mapRotationUpdate",i),this.renderOnce()}};f(Di,"CONTEXT_LOSS_TAIL_SIZE",8);let vr=Di;const Av=Object.freeze(Object.defineProperty({__proto__:null,AppService:Rc,MapApplication:vr},Symbol.toStringTag,{value:"Module"}));export{ea as $,_i as A,le as B,oe as C,_r as D,Zt as E,Tr as F,H as G,bm as H,ei as I,lg as J,zs as K,tg as L,U as M,Gt as N,Ls as O,Q as P,Mr as Q,J as R,uf as S,G as T,Fe as U,$ as V,gl as W,te as X,Vi as Y,lf as Z,li as _,Je as a,Mi as a0,Ar as a1,ul as a2,zt as a3,si as a4,kl as a5,Wf as a6,Vf as a7,Tv as a8,Il as a9,Li as aA,gf as aB,El as aC,Gf as aD,$f as aE,wm as aF,Dl as aG,Yf as aH,pm as aI,Av as aJ,Be as aa,ms as ab,Ju as ac,Wd as ad,ce as ae,ii as af,Xf as ag,At as ah,Lh as ai,Ft as aj,Is as ak,To as al,jt as am,iy as an,mu as ao,Ro as ap,on as aq,ko as ar,xu as as,Wh as at,Nr as au,Gr as av,ml as aw,Hi as ax,_p as ay,Sp as az,cr as b,nt as c,V as d,de as e,dr as f,ls as g,yt as h,X as i,Vu as j,ft as k,Lm as l,ct as m,Fu as n,Eu as o,E as p,mt as q,Jd as r,um as s,Ia as t,ep as u,K as v,st as w,q as x,W as y,it as z};
|