@ray-js/robot-map-sdk 0.0.14 → 0.0.15-beta.1

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.
Files changed (42) hide show
  1. package/dist-docs/404.html +2 -2
  2. package/dist-docs/assets/{app.DHRGs5Zc.js → app.DrVvoJqD.js} +1 -1
  3. package/dist-docs/assets/chunks/@localSearchIndexroot.DgCT_aeF.js +1 -0
  4. package/dist-docs/assets/chunks/{BitmapFont.CcysO3pT.js → BitmapFont.BEQi-SuJ.js} +1 -1
  5. package/dist-docs/assets/chunks/{BufferResource.C_MJ8LV7.js → BufferResource.BcXsqdtp.js} +1 -1
  6. package/dist-docs/assets/chunks/{CanvasRenderer.AFx6MHtI.js → CanvasRenderer.D4lorIYk.js} +1 -1
  7. package/dist-docs/assets/chunks/{RenderTargetSystem.DlyLBS5z.js → RenderTargetSystem.Bje_ofsU.js} +1 -1
  8. package/dist-docs/assets/chunks/{VPLocalSearchBox.DeambLpp.js → VPLocalSearchBox.C6RPYXCP.js} +1 -1
  9. package/dist-docs/assets/chunks/{WebGLRenderer.uIm0oBU6.js → WebGLRenderer.DBz0cz4m.js} +1 -1
  10. package/dist-docs/assets/chunks/{WebGPURenderer.KCAyMTek.js → WebGPURenderer.DeayS-qR.js} +1 -1
  11. package/dist-docs/assets/chunks/{browserAll.5RQbY4cm.js → browserAll.DTj5xrRK.js} +1 -1
  12. package/dist-docs/assets/chunks/{index.BLj_eQCu.js → index.B6zCXCHX.js} +4 -4
  13. package/dist-docs/assets/chunks/{theme.DZz2Y3xc.js → theme.C_XzLiDc.js} +3 -3
  14. package/dist-docs/assets/chunks/{webworkerAll.D3-je4ql.js → webworkerAll.CtODZtwG.js} +1 -1
  15. package/dist-docs/assets/{guide_getting-started.md.BxrBbc12.js → guide_getting-started.md.GeenewB7.js} +2 -2
  16. package/dist-docs/assets/guide_getting-started.md.GeenewB7.lean.js +1 -0
  17. package/dist-docs/guide/advanced-usage.html +3 -3
  18. package/dist-docs/guide/concepts.html +3 -3
  19. package/dist-docs/guide/getting-started.html +5 -5
  20. package/dist-docs/guide/mcp.html +3 -3
  21. package/dist-docs/hashmap.json +1 -1
  22. package/dist-docs/index.html +3 -3
  23. package/dist-docs/plans/2026-03-04-detected-objects-visibility-design.html +3 -3
  24. package/dist-docs/plans/2026-03-04-show-detected-objects-implementation-plan.html +3 -3
  25. package/dist-docs/plans/2026-03-10-simulator-debug-design.html +3 -3
  26. package/dist-docs/plans/2026-03-10-simulator-events-console-design.html +3 -3
  27. package/dist-docs/plans/2026-03-10-simulator-events-console-implementation-plan.html +3 -3
  28. package/dist-docs/plans/2026-03-10-simulator-runtime-controls-design.html +3 -3
  29. package/dist-docs/plans/2026-03-10-simulator-runtime-controls-implementation-plan.html +3 -3
  30. package/dist-docs/plans/2026-03-10-testing-rollout-next-steps-plan.html +3 -3
  31. package/dist-docs/plans/2026-03-11-simulator-logger-dump-implementation-plan.html +3 -3
  32. package/dist-docs/reference/callbacks.html +3 -3
  33. package/dist-docs/reference/config.html +3 -3
  34. package/dist-docs/reference/data.html +3 -3
  35. package/dist-docs/reference/methods.html +3 -3
  36. package/dist-docs/reference/runtime.html +3 -3
  37. package/dist-docs/reference/types.html +3 -3
  38. package/dist-docs/reference/utils.html +3 -3
  39. package/dist-docs/simulator/index.html +3 -3
  40. package/package.json +1 -1
  41. package/dist-docs/assets/chunks/@localSearchIndexroot.RPRwAWt3.js +0 -1
  42. package/dist-docs/assets/guide_getting-started.md.BxrBbc12.lean.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.5RQbY4cm.js","assets/chunks/webworkerAll.D3-je4ql.js","assets/chunks/framework.CBLqO2Q1.js","assets/chunks/mapValues.D2X8cRgC.js","assets/chunks/theme.DZz2Y3xc.js","assets/chunks/WebGPURenderer.KCAyMTek.js","assets/chunks/BufferResource.C_MJ8LV7.js","assets/chunks/RenderTargetSystem.DlyLBS5z.js","assets/chunks/WebGLRenderer.uIm0oBU6.js","assets/chunks/CanvasRenderer.AFx6MHtI.js","assets/chunks/BitmapFont.CcysO3pT.js"])))=>i.map(i=>d[i]);
2
- var Tc=Object.defineProperty;var kc=(r,e,t)=>e in r?Tc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var g=(r,e,t)=>kc(r,typeof e!="symbol"?e+"":e,t);import{V as _e}from"./framework.CBLqO2Q1.js";import{L as th,u as eh,m as ih,G as Rc,E as Ec,d as Ee,y as Ic,Q as Bc,v as sh,H as Dc,R as Fc,T as zc,i as cr,U as nh,V as Lc,W as Oc,I as Gc,X as Wc,K as $r,Y as Uc,e as Hc,w as Vc,l as kn,f as Nc,a as jc,x as Qr,Z as Yc,h as Xc,_ as Zc,j as qc,$ as rh,a0 as Kc,a1 as $c,C as Qc,a2 as Jc,N as Rn,O as td,P as ed,M as Jr}from"./mapValues.D2X8cRgC.js";import{N as re,H as id,a as sd}from"./theme.DZz2Y3xc.js";var I=(r=>(r.Application="application",r.WebGLPipes="webgl-pipes",r.WebGLPipesAdaptor="webgl-pipes-adaptor",r.WebGLSystem="webgl-system",r.WebGPUPipes="webgpu-pipes",r.WebGPUPipesAdaptor="webgpu-pipes-adaptor",r.WebGPUSystem="webgpu-system",r.CanvasSystem="canvas-system",r.CanvasPipesAdaptor="canvas-pipes-adaptor",r.CanvasPipes="canvas-pipes",r.Asset="asset",r.LoadParser="load-parser",r.ResolveParser="resolve-parser",r.CacheParser="cache-parser",r.DetectionParser="detection-parser",r.MaskEffect="mask-effect",r.BlendMode="blend-mode",r.TextureSource="texture-source",r.Environment="environment",r.ShapeBuilder="shape-builder",r.Batcher="batcher",r))(I||{});const En=r=>{if(typeof r=="function"||typeof r=="object"&&r.extension){if(!r.extension)throw new Error("Extension class must have an extension object");r={...typeof r.extension!="object"?{type:r.extension}:r.extension,ref:r}}if(typeof r=="object")r={...r};else throw new Error("Invalid extension type");return typeof r.type=="string"&&(r.type=[r.type]),r},qi=(r,e)=>En(r).priority??e,$={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(En).forEach(e=>{e.type.forEach(t=>{var i,s;return(s=(i=this._removeHandlers)[t])==null?void 0:s.call(i,e)})}),this},add(...r){return r.map(En).forEach(e=>{e.type.forEach(t=>{var n,o;const i=this._addHandlers,s=this._queue;i[t]?(o=i[t])==null||o.call(i,e):(s[t]=s[t]||[],(n=s[t])==null||n.push(e))})}),this},handle(r,e,t){var o;const i=this._addHandlers,s=this._removeHandlers;if(i[r]||s[r])throw new Error(`Extension type ${r} already has a handler`);i[r]=e,s[r]=t;const n=this._queue;return n[r]&&((o=n[r])==null||o.forEach(a=>e(a)),delete n[r]),this},handleByMap(r,e){return this.handle(r,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(r,e,t=-1){return this.handle(r,i=>{e.findIndex(n=>n.name===i.name)>=0||(e.push({name:i.name,value:i.ref}),e.sort((n,o)=>qi(o.value,t)-qi(n.value,t)))},i=>{const s=e.findIndex(n=>n.name===i.name);s!==-1&&e.splice(s,1)})},handleByList(r,e,t=-1){return this.handle(r,i=>{e.includes(i.ref)||(e.push(i.ref),e.sort((s,n)=>qi(n,t)-qi(s,t)))},i=>{const s=e.indexOf(i.ref);s!==-1&&e.splice(s,1)})},mixin(r,...e){for(const t of e)Object.defineProperties(r.prototype,Object.getOwnPropertyDescriptors(t))}},nd={extension:{type:I.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await _e(()=>import("./browserAll.5RQbY4cm.js"),__vite__mapDeps([0,1,2,3,4]))}},rd={extension:{type:I.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await _e(()=>import("./webworkerAll.D3-je4ql.js"),__vite__mapDeps([1,2,3,4]))}};class ct{constructor(e,t,i){this._x=t||0,this._y=i||0,this._observer=e}clone(e){return new ct(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.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(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}var oh={exports:{}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function n(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),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=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)e.call(c,d)&&l.push(t?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=t?t+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,f=new Array(p);u<p;u++)f[u]=d[u].fn;return f},a.prototype.listenerCount=function(l){var c=t?t+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,f){var y=t?t+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,f),!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 n(this,l,c,d,!1)},a.prototype.once=function(l,c,d){return n(this,l,c,d,!0)},a.prototype.removeListener=function(l,c,d,u){var p=t?t+l:l;if(!this._events[p])return this;if(!c)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===c&&(!u||f.once)&&(!d||f.context===d)&&o(this,p);else{for(var y=0,m=[],x=f.length;y<x;y++)(f[y].fn!==c||u&&!f[y].once||d&&f[y].context!==d)&&m.push(f[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=t?t+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=t,a.EventEmitter=a,r.exports=a})(oh);var od=oh.exports;const Yt=th(od),ad=Math.PI*2,hd=180/Math.PI,ld=Math.PI/180;class tt{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new tt(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,t=e){return this.x=e,this.y=t,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Vs.x=0,Vs.y=0,Vs}}const Vs=new tt;class U{constructor(e=1,t=0,i=0,s=1,n=0,o=0){this.array=null,this.a=e,this.b=t,this.c=i,this.d=s,this.tx=n,this.ty=o}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,t,i,s,n,o){return this.a=e,this.b=t,this.c=i,this.d=s,this.tx=n,this.ty=o,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const i=t||this.array;return e?(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(e,t){t=t||new tt;const i=e.x,s=e.y;return t.x=this.a*i+this.c*s+this.tx,t.y=this.b*i+this.d*s+this.ty,t}applyInverse(e,t){t=t||new tt;const i=this.a,s=this.b,n=this.c,o=this.d,a=this.tx,h=this.ty,l=1/(i*o+n*-s),c=e.x,d=e.y;return t.x=o*l*c+-n*l*d+(h*n-a*o)*l,t.y=i*l*d+-s*l*c+(-h*i+a*s)*l,t}translate(e,t){return this.tx+=e,this.ty+=t,this}scale(e,t){return this.a*=e,this.d*=t,this.c*=e,this.b*=t,this.tx*=e,this.ty*=t,this}rotate(e){const t=Math.cos(e),i=Math.sin(e),s=this.a,n=this.c,o=this.tx;return this.a=s*t-this.b*i,this.b=s*i+this.b*t,this.c=n*t-this.d*i,this.d=n*i+this.d*t,this.tx=o*t-this.ty*i,this.ty=o*i+this.ty*t,this}append(e){const t=this.a,i=this.b,s=this.c,n=this.d;return this.a=e.a*t+e.b*s,this.b=e.a*i+e.b*n,this.c=e.c*t+e.d*s,this.d=e.c*i+e.d*n,this.tx=e.tx*t+e.ty*s+this.tx,this.ty=e.tx*i+e.ty*n+this.ty,this}appendFrom(e,t){const i=e.a,s=e.b,n=e.c,o=e.d,a=e.tx,h=e.ty,l=t.a,c=t.b,d=t.c,u=t.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=n*l+o*d,this.d=n*c+o*u,this.tx=a*l+h*d+t.tx,this.ty=a*c+h*u+t.ty,this}setTransform(e,t,i,s,n,o,a,h,l){return this.a=Math.cos(a+l)*n,this.b=Math.sin(a+l)*n,this.c=-Math.sin(a-h)*o,this.d=Math.cos(a-h)*o,this.tx=e-(i*this.a+s*this.c),this.ty=t-(i*this.b+s*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const i=this.a,s=this.c;this.a=i*e.a+this.b*e.c,this.b=i*e.b+this.b*e.d,this.c=s*e.a+this.d*e.c,this.d=s*e.b+this.d*e.d}return this.tx=t*e.a+this.ty*e.c+e.tx,this.ty=t*e.b+this.ty*e.d+e.ty,this}decompose(e){const t=this.a,i=this.b,s=this.c,n=this.d,o=e.pivot,a=-Math.atan2(-s,n),h=Math.atan2(i,t),l=Math.abs(a+h);return l<1e-5||Math.abs(ad-l)<1e-5?(e.rotation=h,e.skew.x=e.skew.y=0):(e.rotation=0,e.skew.x=a,e.skew.y=h),e.scale.x=Math.sqrt(t*t+i*i),e.scale.y=Math.sqrt(s*s+n*n),e.position.x=this.tx+(o.x*t+o.y*s),e.position.y=this.ty+(o.x*i+o.y*n),e}invert(){const e=this.a,t=this.b,i=this.c,s=this.d,n=this.tx,o=e*s-t*i;return this.a=s/o,this.b=-t/o,this.c=-i/o,this.d=e/o,this.tx=(i*this.ty-s*n)/o,this.ty=-(e*this.ty-t*n)/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 e=new U;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}equals(e){return e.a===this.a&&e.b===this.b&&e.c===this.c&&e.d===this.d&&e.tx===this.tx&&e.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 dd.identity()}static get shared(){return cd.identity()}}const cd=new U,dd=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],In=[],ah=[],Ki=Math.sign;function ud(){for(let r=0;r<16;r++){const e=[];In.push(e);for(let t=0;t<16;t++){const i=Ki(ve[r]*ve[t]+we[r]*be[t]),s=Ki(be[r]*ve[t]+Ce[r]*be[t]),n=Ki(ve[r]*we[t]+we[r]*Ce[t]),o=Ki(be[r]*we[t]+Ce[r]*Ce[t]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===n&&Ce[a]===o){e.push(a);break}}}for(let r=0;r<16;r++){const e=new U;e.set(ve[r],be[r],we[r],Ce[r],0,0),ah.push(e)}}ud();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:r=>ve[r],uY:r=>be[r],vX:r=>we[r],vY:r=>Ce[r],inv:r=>r&8?r&15:-r&7,add:(r,e)=>In[r][e],sub:(r,e)=>In[r][X.inv(e)],rotate180:r=>r^4,isVertical:r=>(r&3)===2,byDirection:(r,e)=>Math.abs(r)*2<=Math.abs(e)?e>=0?X.S:X.N:Math.abs(e)*2<=Math.abs(r)?r>0?X.E:X.W:e>0?r>0?X.SE:X.SW:r>0?X.NE:X.NW,matrixAppendRotationInv:(r,e,t=0,i=0,s=0,n=0)=>{const o=ah[X.inv(e)],a=o.a,h=o.b,l=o.c,c=o.d,d=t-Math.min(0,a*s,l*n,a*s+l*n),u=i-Math.min(0,h*s,c*n,h*s+c*n),p=r.a,f=r.b,y=r.c,m=r.d;r.a=a*p+h*y,r.b=a*f+h*m,r.c=l*p+c*y,r.d=l*f+c*m,r.tx=d*p+u*y+r.tx,r.ty=d*f+u*m+r.ty},transformRectCoords:(r,e,t,i)=>{const{x:s,y:n,width:o,height:a}=r,{x:h,y:l,width:c,height:d}=e;return t===X.E?(i.set(s+h,n+l,o,a),i):t===X.S?i.set(c-n-a+h,s+l,a,o):t===X.W?i.set(c-s-o+h,d-n-a+l,o,a):t===X.N?i.set(n+h,d-s-o+l,a,o):i.set(s+h,n+l,o,a)}},$i=[new tt,new tt,new tt,new tt];class et{constructor(e=0,t=0,i=0,s=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),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 et(0,0,0,0)}clone(){return new et(this.x,this.y,this.width,this.height)}copyFromBounds(e){return this.x=e.minX,this.y=e.minY,this.width=e.maxX-e.minX,this.height=e.maxY-e.minY,this}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){return this.width<=0||this.height<=0?!1:e>=this.x&&e<this.x+this.width&&t>=this.y&&t<this.y+this.height}strokeContains(e,t,i,s=.5){const{width:n,height:o}=this;if(n<=0||o<=0)return!1;const a=this.x,h=this.y,l=i*(1-s),c=i-l,d=a-l,u=a+n+l,p=h-l,f=h+o+l,y=a+c,m=a+n-c,x=h+c,S=h+o-c;return e>=d&&e<=u&&t>=p&&t<=f&&!(e>y&&e<m&&t>x&&t<S)}intersects(e,t){if(!t){const k=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=k)return!1;const T=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>T}const i=this.left,s=this.right,n=this.top,o=this.bottom;if(s<=i||o<=n)return!1;const a=$i[0].set(e.left,e.top),h=$i[1].set(e.left,e.bottom),l=$i[2].set(e.right,e.top),c=$i[3].set(e.right,e.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(t.a*t.d-t.b*t.c);if(d===0||(t.apply(a,a),t.apply(h,h),t.apply(l,l),t.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)<=n||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),f=u*i+p*n,y=u*s+p*n,m=u*i+p*o,x=u*s+p*o;if(Math.max(f,y,m,x)<=u*a.x+p*a.y||Math.min(f,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*n,P=S*s+v*n,C=S*i+v*o,A=S*s+v*o;return!(Math.max(b,P,C,A)<=S*a.x+v*a.y||Math.min(b,P,C,A)>=S*c.x+v*c.y)}pad(e=0,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}fit(e){const t=Math.max(this.x,e.x),i=Math.min(this.x+this.width,e.x+e.width),s=Math.max(this.y,e.y),n=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(i-t,0),this.y=s,this.height=Math.max(n-s,0),this}ceil(e=1,t=.001){const i=Math.ceil((this.x+this.width-t)*e)/e,s=Math.ceil((this.y+this.height-t)*e)/e;return this.x=Math.floor((this.x+t)*e)/e,this.y=Math.floor((this.y+t)*e)/e,this.width=i-this.x,this.height=s-this.y,this}scale(e,t=e){return this.x*=e,this.y*=t,this.width*=e,this.height*=t,this}enlarge(e){const t=Math.min(this.x,e.x),i=Math.max(this.x+this.width,e.x+e.width),s=Math.min(this.y,e.y),n=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=i-t,this.y=s,this.height=n-s,this}getBounds(e){return e||(e=new et),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,i=e.y,s=e.x+e.width,n=e.y+e.height;return t>=this.x&&t<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&n>=this.y&&n<this.y+this.height}set(e,t,i,s){return this.x=e,this.y=t,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 Ns={default:-1};function dt(r="default"){return Ns[r]===void 0&&(Ns[r]=-1),++Ns[r]}const to=new Set,J="8.0.0",pd="8.3.4",He={quiet:!1,noColor:!1},V=(r,e,t=3)=>{if(He.quiet||to.has(e))return;let i=new Error().stack;const s=`${e}
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.DTj5xrRK.js","assets/chunks/webworkerAll.CtODZtwG.js","assets/chunks/framework.CBLqO2Q1.js","assets/chunks/mapValues.D2X8cRgC.js","assets/chunks/theme.C_XzLiDc.js","assets/chunks/WebGPURenderer.DeayS-qR.js","assets/chunks/BufferResource.BcXsqdtp.js","assets/chunks/RenderTargetSystem.Bje_ofsU.js","assets/chunks/WebGLRenderer.DBz0cz4m.js","assets/chunks/CanvasRenderer.D4lorIYk.js","assets/chunks/BitmapFont.BEQi-SuJ.js"])))=>i.map(i=>d[i]);
2
+ var Tc=Object.defineProperty;var kc=(r,e,t)=>e in r?Tc(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var g=(r,e,t)=>kc(r,typeof e!="symbol"?e+"":e,t);import{V as _e}from"./framework.CBLqO2Q1.js";import{L as th,u as eh,m as ih,G as Rc,E as Ec,d as Ee,y as Ic,Q as Bc,v as sh,H as Dc,R as Fc,T as zc,i as cr,U as nh,V as Lc,W as Oc,I as Gc,X as Wc,K as $r,Y as Uc,e as Hc,w as Vc,l as kn,f as Nc,a as jc,x as Qr,Z as Yc,h as Xc,_ as Zc,j as qc,$ as rh,a0 as Kc,a1 as $c,C as Qc,a2 as Jc,N as Rn,O as td,P as ed,M as Jr}from"./mapValues.D2X8cRgC.js";import{N as re,H as id,a as sd}from"./theme.C_XzLiDc.js";var I=(r=>(r.Application="application",r.WebGLPipes="webgl-pipes",r.WebGLPipesAdaptor="webgl-pipes-adaptor",r.WebGLSystem="webgl-system",r.WebGPUPipes="webgpu-pipes",r.WebGPUPipesAdaptor="webgpu-pipes-adaptor",r.WebGPUSystem="webgpu-system",r.CanvasSystem="canvas-system",r.CanvasPipesAdaptor="canvas-pipes-adaptor",r.CanvasPipes="canvas-pipes",r.Asset="asset",r.LoadParser="load-parser",r.ResolveParser="resolve-parser",r.CacheParser="cache-parser",r.DetectionParser="detection-parser",r.MaskEffect="mask-effect",r.BlendMode="blend-mode",r.TextureSource="texture-source",r.Environment="environment",r.ShapeBuilder="shape-builder",r.Batcher="batcher",r))(I||{});const En=r=>{if(typeof r=="function"||typeof r=="object"&&r.extension){if(!r.extension)throw new Error("Extension class must have an extension object");r={...typeof r.extension!="object"?{type:r.extension}:r.extension,ref:r}}if(typeof r=="object")r={...r};else throw new Error("Invalid extension type");return typeof r.type=="string"&&(r.type=[r.type]),r},qi=(r,e)=>En(r).priority??e,$={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(En).forEach(e=>{e.type.forEach(t=>{var i,s;return(s=(i=this._removeHandlers)[t])==null?void 0:s.call(i,e)})}),this},add(...r){return r.map(En).forEach(e=>{e.type.forEach(t=>{var n,o;const i=this._addHandlers,s=this._queue;i[t]?(o=i[t])==null||o.call(i,e):(s[t]=s[t]||[],(n=s[t])==null||n.push(e))})}),this},handle(r,e,t){var o;const i=this._addHandlers,s=this._removeHandlers;if(i[r]||s[r])throw new Error(`Extension type ${r} already has a handler`);i[r]=e,s[r]=t;const n=this._queue;return n[r]&&((o=n[r])==null||o.forEach(a=>e(a)),delete n[r]),this},handleByMap(r,e){return this.handle(r,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(r,e,t=-1){return this.handle(r,i=>{e.findIndex(n=>n.name===i.name)>=0||(e.push({name:i.name,value:i.ref}),e.sort((n,o)=>qi(o.value,t)-qi(n.value,t)))},i=>{const s=e.findIndex(n=>n.name===i.name);s!==-1&&e.splice(s,1)})},handleByList(r,e,t=-1){return this.handle(r,i=>{e.includes(i.ref)||(e.push(i.ref),e.sort((s,n)=>qi(n,t)-qi(s,t)))},i=>{const s=e.indexOf(i.ref);s!==-1&&e.splice(s,1)})},mixin(r,...e){for(const t of e)Object.defineProperties(r.prototype,Object.getOwnPropertyDescriptors(t))}},nd={extension:{type:I.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await _e(()=>import("./browserAll.DTj5xrRK.js"),__vite__mapDeps([0,1,2,3,4]))}},rd={extension:{type:I.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await _e(()=>import("./webworkerAll.CtODZtwG.js"),__vite__mapDeps([1,2,3,4]))}};class ct{constructor(e,t,i){this._x=t||0,this._y=i||0,this._observer=e}clone(e){return new ct(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.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(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}var oh={exports:{}};(function(r){var e=Object.prototype.hasOwnProperty,t="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(t=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function n(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),f=t?t+l:l;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],p]:h._events[f].push(p):(h._events[f]=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)e.call(c,d)&&l.push(t?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=t?t+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,f=new Array(p);u<p;u++)f[u]=d[u].fn;return f},a.prototype.listenerCount=function(l){var c=t?t+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,f){var y=t?t+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,f),!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 n(this,l,c,d,!1)},a.prototype.once=function(l,c,d){return n(this,l,c,d,!0)},a.prototype.removeListener=function(l,c,d,u){var p=t?t+l:l;if(!this._events[p])return this;if(!c)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===c&&(!u||f.once)&&(!d||f.context===d)&&o(this,p);else{for(var y=0,m=[],x=f.length;y<x;y++)(f[y].fn!==c||u&&!f[y].once||d&&f[y].context!==d)&&m.push(f[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=t?t+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=t,a.EventEmitter=a,r.exports=a})(oh);var od=oh.exports;const Yt=th(od),ad=Math.PI*2,hd=180/Math.PI,ld=Math.PI/180;class tt{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new tt(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,t=e){return this.x=e,this.y=t,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Vs.x=0,Vs.y=0,Vs}}const Vs=new tt;class U{constructor(e=1,t=0,i=0,s=1,n=0,o=0){this.array=null,this.a=e,this.b=t,this.c=i,this.d=s,this.tx=n,this.ty=o}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,t,i,s,n,o){return this.a=e,this.b=t,this.c=i,this.d=s,this.tx=n,this.ty=o,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const i=t||this.array;return e?(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(e,t){t=t||new tt;const i=e.x,s=e.y;return t.x=this.a*i+this.c*s+this.tx,t.y=this.b*i+this.d*s+this.ty,t}applyInverse(e,t){t=t||new tt;const i=this.a,s=this.b,n=this.c,o=this.d,a=this.tx,h=this.ty,l=1/(i*o+n*-s),c=e.x,d=e.y;return t.x=o*l*c+-n*l*d+(h*n-a*o)*l,t.y=i*l*d+-s*l*c+(-h*i+a*s)*l,t}translate(e,t){return this.tx+=e,this.ty+=t,this}scale(e,t){return this.a*=e,this.d*=t,this.c*=e,this.b*=t,this.tx*=e,this.ty*=t,this}rotate(e){const t=Math.cos(e),i=Math.sin(e),s=this.a,n=this.c,o=this.tx;return this.a=s*t-this.b*i,this.b=s*i+this.b*t,this.c=n*t-this.d*i,this.d=n*i+this.d*t,this.tx=o*t-this.ty*i,this.ty=o*i+this.ty*t,this}append(e){const t=this.a,i=this.b,s=this.c,n=this.d;return this.a=e.a*t+e.b*s,this.b=e.a*i+e.b*n,this.c=e.c*t+e.d*s,this.d=e.c*i+e.d*n,this.tx=e.tx*t+e.ty*s+this.tx,this.ty=e.tx*i+e.ty*n+this.ty,this}appendFrom(e,t){const i=e.a,s=e.b,n=e.c,o=e.d,a=e.tx,h=e.ty,l=t.a,c=t.b,d=t.c,u=t.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=n*l+o*d,this.d=n*c+o*u,this.tx=a*l+h*d+t.tx,this.ty=a*c+h*u+t.ty,this}setTransform(e,t,i,s,n,o,a,h,l){return this.a=Math.cos(a+l)*n,this.b=Math.sin(a+l)*n,this.c=-Math.sin(a-h)*o,this.d=Math.cos(a-h)*o,this.tx=e-(i*this.a+s*this.c),this.ty=t-(i*this.b+s*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const i=this.a,s=this.c;this.a=i*e.a+this.b*e.c,this.b=i*e.b+this.b*e.d,this.c=s*e.a+this.d*e.c,this.d=s*e.b+this.d*e.d}return this.tx=t*e.a+this.ty*e.c+e.tx,this.ty=t*e.b+this.ty*e.d+e.ty,this}decompose(e){const t=this.a,i=this.b,s=this.c,n=this.d,o=e.pivot,a=-Math.atan2(-s,n),h=Math.atan2(i,t),l=Math.abs(a+h);return l<1e-5||Math.abs(ad-l)<1e-5?(e.rotation=h,e.skew.x=e.skew.y=0):(e.rotation=0,e.skew.x=a,e.skew.y=h),e.scale.x=Math.sqrt(t*t+i*i),e.scale.y=Math.sqrt(s*s+n*n),e.position.x=this.tx+(o.x*t+o.y*s),e.position.y=this.ty+(o.x*i+o.y*n),e}invert(){const e=this.a,t=this.b,i=this.c,s=this.d,n=this.tx,o=e*s-t*i;return this.a=s/o,this.b=-t/o,this.c=-i/o,this.d=e/o,this.tx=(i*this.ty-s*n)/o,this.ty=-(e*this.ty-t*n)/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 e=new U;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}equals(e){return e.a===this.a&&e.b===this.b&&e.c===this.c&&e.d===this.d&&e.tx===this.tx&&e.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 dd.identity()}static get shared(){return cd.identity()}}const cd=new U,dd=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],In=[],ah=[],Ki=Math.sign;function ud(){for(let r=0;r<16;r++){const e=[];In.push(e);for(let t=0;t<16;t++){const i=Ki(ve[r]*ve[t]+we[r]*be[t]),s=Ki(be[r]*ve[t]+Ce[r]*be[t]),n=Ki(ve[r]*we[t]+we[r]*Ce[t]),o=Ki(be[r]*we[t]+Ce[r]*Ce[t]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===n&&Ce[a]===o){e.push(a);break}}}for(let r=0;r<16;r++){const e=new U;e.set(ve[r],be[r],we[r],Ce[r],0,0),ah.push(e)}}ud();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:r=>ve[r],uY:r=>be[r],vX:r=>we[r],vY:r=>Ce[r],inv:r=>r&8?r&15:-r&7,add:(r,e)=>In[r][e],sub:(r,e)=>In[r][X.inv(e)],rotate180:r=>r^4,isVertical:r=>(r&3)===2,byDirection:(r,e)=>Math.abs(r)*2<=Math.abs(e)?e>=0?X.S:X.N:Math.abs(e)*2<=Math.abs(r)?r>0?X.E:X.W:e>0?r>0?X.SE:X.SW:r>0?X.NE:X.NW,matrixAppendRotationInv:(r,e,t=0,i=0,s=0,n=0)=>{const o=ah[X.inv(e)],a=o.a,h=o.b,l=o.c,c=o.d,d=t-Math.min(0,a*s,l*n,a*s+l*n),u=i-Math.min(0,h*s,c*n,h*s+c*n),p=r.a,f=r.b,y=r.c,m=r.d;r.a=a*p+h*y,r.b=a*f+h*m,r.c=l*p+c*y,r.d=l*f+c*m,r.tx=d*p+u*y+r.tx,r.ty=d*f+u*m+r.ty},transformRectCoords:(r,e,t,i)=>{const{x:s,y:n,width:o,height:a}=r,{x:h,y:l,width:c,height:d}=e;return t===X.E?(i.set(s+h,n+l,o,a),i):t===X.S?i.set(c-n-a+h,s+l,a,o):t===X.W?i.set(c-s-o+h,d-n-a+l,o,a):t===X.N?i.set(n+h,d-s-o+l,a,o):i.set(s+h,n+l,o,a)}},$i=[new tt,new tt,new tt,new tt];class et{constructor(e=0,t=0,i=0,s=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),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 et(0,0,0,0)}clone(){return new et(this.x,this.y,this.width,this.height)}copyFromBounds(e){return this.x=e.minX,this.y=e.minY,this.width=e.maxX-e.minX,this.height=e.maxY-e.minY,this}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){return this.width<=0||this.height<=0?!1:e>=this.x&&e<this.x+this.width&&t>=this.y&&t<this.y+this.height}strokeContains(e,t,i,s=.5){const{width:n,height:o}=this;if(n<=0||o<=0)return!1;const a=this.x,h=this.y,l=i*(1-s),c=i-l,d=a-l,u=a+n+l,p=h-l,f=h+o+l,y=a+c,m=a+n-c,x=h+c,S=h+o-c;return e>=d&&e<=u&&t>=p&&t<=f&&!(e>y&&e<m&&t>x&&t<S)}intersects(e,t){if(!t){const k=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=k)return!1;const T=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>T}const i=this.left,s=this.right,n=this.top,o=this.bottom;if(s<=i||o<=n)return!1;const a=$i[0].set(e.left,e.top),h=$i[1].set(e.left,e.bottom),l=$i[2].set(e.right,e.top),c=$i[3].set(e.right,e.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(t.a*t.d-t.b*t.c);if(d===0||(t.apply(a,a),t.apply(h,h),t.apply(l,l),t.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)<=n||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),f=u*i+p*n,y=u*s+p*n,m=u*i+p*o,x=u*s+p*o;if(Math.max(f,y,m,x)<=u*a.x+p*a.y||Math.min(f,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*n,P=S*s+v*n,C=S*i+v*o,A=S*s+v*o;return!(Math.max(b,P,C,A)<=S*a.x+v*a.y||Math.min(b,P,C,A)>=S*c.x+v*c.y)}pad(e=0,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}fit(e){const t=Math.max(this.x,e.x),i=Math.min(this.x+this.width,e.x+e.width),s=Math.max(this.y,e.y),n=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(i-t,0),this.y=s,this.height=Math.max(n-s,0),this}ceil(e=1,t=.001){const i=Math.ceil((this.x+this.width-t)*e)/e,s=Math.ceil((this.y+this.height-t)*e)/e;return this.x=Math.floor((this.x+t)*e)/e,this.y=Math.floor((this.y+t)*e)/e,this.width=i-this.x,this.height=s-this.y,this}scale(e,t=e){return this.x*=e,this.y*=t,this.width*=e,this.height*=t,this}enlarge(e){const t=Math.min(this.x,e.x),i=Math.max(this.x+this.width,e.x+e.width),s=Math.min(this.y,e.y),n=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=i-t,this.y=s,this.height=n-s,this}getBounds(e){return e||(e=new et),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,i=e.y,s=e.x+e.width,n=e.y+e.height;return t>=this.x&&t<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&n>=this.y&&n<this.y+this.height}set(e,t,i,s){return this.x=e,this.y=t,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 Ns={default:-1};function dt(r="default"){return Ns[r]===void 0&&(Ns[r]=-1),++Ns[r]}const to=new Set,J="8.0.0",pd="8.3.4",He={quiet:!1,noColor:!1},V=(r,e,t=3)=>{if(He.quiet||to.has(e))return;let i=new Error().stack;const s=`${e}
3
3
  Deprecated since v${r}`,n=typeof console.groupCollapsed=="function"&&!He.noColor;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",s):(i=i.split(`
4
4
  `).splice(t).join(`
5
5
  `),n?(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))),to.add(e)};Object.defineProperties(V,{quiet:{get:()=>He.quiet,set:r=>{He.quiet=r},enumerable:!0,configurable:!1},noColor:{get:()=>He.noColor,set:r=>{He.noColor=r},enumerable:!0,configurable:!1}});const hh=()=>{};function Je(r){return r+=r===0?1:0,--r,r|=r>>>1,r|=r>>>2,r|=r>>>4,r|=r>>>8,r|=r>>>16,r+1}function eo(r){return!(r&r-1)&&!!r}function lh(r){const e={};for(const t in r)r[t]!==void 0&&(e[t]=r[t]);return e}const io=Object.create(null);function fd(r){const e=io[r];return e===void 0&&(io[r]=dt("resource")),e}const ch=class dh extends Yt{constructor(e={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,e={...dh.defaultOptions,...e},this.addressMode=e.addressMode,this.addressModeU=e.addressModeU??this.addressModeU,this.addressModeV=e.addressModeV??this.addressModeV,this.addressModeW=e.addressModeW??this.addressModeW,this.scaleMode=e.scaleMode,this.magFilter=e.magFilter??this.magFilter,this.minFilter=e.minFilter??this.minFilter,this.mipmapFilter=e.mipmapFilter??this.mipmapFilter,this.lodMinClamp=e.lodMinClamp,this.lodMaxClamp=e.lodMaxClamp,this.compare=e.compare,this.maxAnisotropy=e.maxAnisotropy??1}set addressMode(e){this.addressModeU=e,this.addressModeV=e,this.addressModeW=e}get addressMode(){return this.addressModeU}set wrapMode(e){V(J,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,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 e=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=fd(e),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};ch.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let ti=ch;const uh=class ph extends Yt{constructor(e={}){super(),this.options=e,this._gpuData=Object.create(null),this._gcLastUsed=-1,this.uid=dt("textureSource"),this._resourceType="textureSource",this._resourceId=dt("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,e={...ph.defaultOptions,...e},this.label=e.label??"",this.resource=e.resource,this.autoGarbageCollect=e.autoGarbageCollect,this._resolution=e.resolution,e.width?this.pixelWidth=e.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,e.height?this.pixelHeight=e.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=e.format,this.dimension=e.dimensions,this.viewDimension=e.viewDimension??e.dimensions,this.arrayLayerCount=e.arrayLayerCount,this.mipLevelCount=e.mipLevelCount,this.autoGenerateMipmaps=e.autoGenerateMipmaps,this.sampleCount=e.sampleCount,this.antialias=e.antialias,this.alphaMode=e.alphaMode,this.style=new ti(lh(e)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(e){var t,i;this.style!==e&&((t=this._style)==null||t.off("change",this._onStyleChange,this),this._style=e,(i=this._style)==null||i.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(e){this._style.maxAnisotropy=e}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(e){this._style.addressMode=e}get repeatMode(){return this._style.addressMode}set repeatMode(e){this._style.addressMode=e}get magFilter(){return this._style.magFilter}set magFilter(e){this._style.magFilter=e}get minFilter(){return this._style.minFilter}set minFilter(e){this._style.minFilter=e}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(e){this._style.mipmapFilter=e}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(e){this._style.lodMinClamp=e}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(e){this._style.lodMaxClamp=e}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const e=this._resolution;if(this.resize(this.resourceWidth/e,this.resourceHeight/e))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 e,t;this._resourceId=dt("resource"),this.emit("change",this),this.emit("unload",this);for(const i in this._gpuData)(t=(e=this._gpuData[i])==null?void 0:e.destroy)==null||t.call(e);this._gpuData=Object.create(null)}get resourceWidth(){const{resource:e}=this;return e.naturalWidth||e.videoWidth||e.displayWidth||e.width}get resourceHeight(){const{resource:e}=this;return e.naturalHeight||e.videoHeight||e.displayHeight||e.height}get resolution(){return this._resolution}set resolution(e){this._resolution!==e&&(this._resolution=e,this.width=this.pixelWidth/e,this.height=this.pixelHeight/e)}resize(e,t,i){i||(i=this._resolution),e||(e=this.width),t||(t=this.height);const s=Math.round(e*i),n=Math.round(t*i);return this.width=s/i,this.height=n/i,this._resolution=i,this.pixelWidth===s&&this.pixelHeight===n?!1:(this._refreshPOT(),this.pixelWidth=s,this.pixelHeight=n,this.emit("resize",this),this._resourceId=dt("resource"),this.emit("change",this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit("updateMipmaps",this)}set wrapMode(e){this._style.wrapMode=e}get wrapMode(){return this._style.wrapMode}set scaleMode(e){this._style.scaleMode=e}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=eo(this.pixelWidth)&&eo(this.pixelHeight)}static test(e){throw new Error("Unimplemented")}};uh.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 Dt=uh;class dr extends Dt{constructor(e){const t=e.resource||new Float32Array(e.width*e.height*4);let i=e.format;i||(t instanceof Float32Array?i="rgba32float":t instanceof Int32Array||t instanceof Uint32Array?i="rgba32uint":t instanceof Int16Array||t instanceof Uint16Array?i="rgba16uint":(t instanceof Int8Array,i="bgra8unorm")),super({...e,resource:t,format:i}),this.uploadMethodId="buffer"}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}dr.extension=I.TextureSource;const so=new U;class gd{constructor(e,t){this.mapCoord=new U,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof t>"u"?this.clampMargin=e.width<10?0:.5:this.clampMargin=t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){var t;this.texture!==e&&((t=this._texture)==null||t.removeListener("update",this.update,this),this._texture=e,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(e,t){t===void 0&&(t=e);const i=this.mapCoord;for(let s=0;s<e.length;s+=2){const n=e[s],o=e[s+1];t[s]=n*i.a+o*i.c+i.tx,t[s+1]=n*i.b+o*i.d+i.ty}return t}update(){const e=this._texture;this._updateID++;const t=e.uvs;this.mapCoord.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0);const i=e.orig,s=e.trim;s&&(so.set(i.width/s.width,0,0,i.height/s.height,-s.x/s.width,-s.y/s.height),this.mapCoord.append(so));const n=e.source,o=this.uClampFrame,a=this.clampMargin/n._resolution,h=this.clampOffset/n._resolution;return o[0]=(e.frame.x+a+h)/n.width,o[1]=(e.frame.y+a+h)/n.height,o[2]=(e.frame.x+e.frame.width-a+h)/n.width,o[3]=(e.frame.y+e.frame.height-a+h)/n.height,this.uClampOffset[0]=this.clampOffset/n.pixelWidth,this.uClampOffset[1]=this.clampOffset/n.pixelHeight,this.isSimple=e.frame.width===n.width&&e.frame.height===n.height&&e.rotate===0,!0}}class G extends Yt{constructor({source:e,label:t,frame:i,orig:s,trim:n,defaultAnchor:o,defaultBorders:a,rotate:h,dynamic:l}={}){if(super(),this.uid=dt("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new et,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=(e==null?void 0:e.source)??new Dt,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=n,this.rotate=h??0,this.defaultAnchor=o,this.defaultBorders=a,this.destroyed=!1,this.dynamic=l||!1,this.updateUvs()}set source(e){this._source&&this._source.off("resize",this.update,this),this._source=e,e.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new gd(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:e,frame:t}=this,{width:i,height:s}=this._source,n=t.x/i,o=t.y/s,a=t.width/i,h=t.height/s;let l=this.rotate;if(l){const c=a/2,d=h/2,u=n+c,p=o+d;l=X.add(l,X.NW),e.x0=u+c*X.uX(l),e.y0=p+d*X.uY(l),l=X.add(l,2),e.x1=u+c*X.uX(l),e.y1=p+d*X.uY(l),l=X.add(l,2),e.x2=u+c*X.uX(l),e.y2=p+d*X.uY(l),l=X.add(l,2),e.x3=u+c*X.uX(l),e.y3=p+d*X.uY(l)}else e.x0=n,e.y0=o,e.x1=n+a,e.y1=o,e.x2=n+a,e.y2=o+h,e.x3=n,e.y3=o+h}destroy(e=!1){this._source&&(this._source.off("resize",this.update,this),e&&(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(J,"Texture.baseTexture is now Texture.source"),this._source}}G.EMPTY=new G({label:"EMPTY",source:new Dt({label:"EMPTY"})});G.EMPTY.destroy=hh;G.WHITE=new G({source:new dr({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});G.WHITE.destroy=hh;function fh(r,e,t){const{width:i,height:s}=t.orig,n=t.trim;if(n){const o=n.width,a=n.height;r.minX=n.x-e._x*i,r.maxX=r.minX+o,r.minY=n.y-e._y*s,r.maxY=r.minY+a}else r.minX=-e._x*i,r.maxX=r.minX+i,r.minY=-e._y*s,r.maxY=r.minY+s}const no=new U;class Bt{constructor(e=1/0,t=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=no,this.minX=e,this.minY=t,this.maxX=i,this.maxY=s}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new et);const e=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(e.x=0,e.y=0,e.width=0,e.height=0):e.copyFromBounds(this),e}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=no,this}set(e,t,i,s){this.minX=e,this.minY=t,this.maxX=i,this.maxY=s}addFrame(e,t,i,s,n){n||(n=this.matrix);const o=n.a,a=n.b,h=n.c,l=n.d,c=n.tx,d=n.ty;let u=this.minX,p=this.minY,f=this.maxX,y=this.maxY,m=o*e+h*t+c,x=a*e+l*t+d;m<u&&(u=m),x<p&&(p=x),m>f&&(f=m),x>y&&(y=x),m=o*i+h*t+c,x=a*i+l*t+d,m<u&&(u=m),x<p&&(p=x),m>f&&(f=m),x>y&&(y=x),m=o*e+h*s+c,x=a*e+l*s+d,m<u&&(u=m),x<p&&(p=x),m>f&&(f=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>f&&(f=m),x>y&&(y=x),this.minX=u,this.minY=p,this.maxX=f,this.maxY=y}addRect(e,t){this.addFrame(e.x,e.y,e.x+e.width,e.y+e.height,t)}addBounds(e,t){this.addFrame(e.minX,e.minY,e.maxX,e.maxY,t)}addBoundsMask(e){this.minX=this.minX>e.minX?this.minX:e.minX,this.minY=this.minY>e.minY?this.minY:e.minY,this.maxX=this.maxX<e.maxX?this.maxX:e.maxX,this.maxY=this.maxY<e.maxY?this.maxY:e.maxY}applyMatrix(e){const t=this.minX,i=this.minY,s=this.maxX,n=this.maxY,{a:o,b:a,c:h,d:l,tx:c,ty:d}=e;let u=o*t+h*i+c,p=a*t+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*t+h*n+c,p=a*t+l*n+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*n+c,p=a*s+l*n+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(e){return this.minX<e.left&&(this.minX=e.left),this.maxX>e.right&&(this.maxX=e.right),this.minY<e.top&&(this.minY=e.top),this.maxY>e.bottom&&(this.maxY=e.bottom),this}fitBounds(e,t,i,s){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<i&&(this.minY=i),this.maxY>s&&(this.maxY=s),this}pad(e,t=e){return this.minX-=e,this.maxX+=e,this.minY-=t,this.maxY+=t,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 Bt(this.minX,this.minY,this.maxX,this.maxY)}scale(e,t=e){return this.minX*=e,this.minY*=t,this.maxX*=e,this.maxY*=t,this}get x(){return this.minX}set x(e){const t=this.maxX-this.minX;this.minX=e,this.maxX=e+t}get y(){return this.minY}set y(e){const t=this.maxY-this.minY;this.minY=e,this.maxY=e+t}get width(){return this.maxX-this.minX}set width(e){this.maxX=this.minX+e}get height(){return this.maxY-this.minY}set height(e){this.maxY=this.minY+e}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(e,t,i,s){let n=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,f=s.ty;for(let y=t;y<i;y+=2){const m=e[y],x=e[y+1],S=l*m+d*x+p,v=c*m+u*x+f;n=S<n?S:n,o=v<o?v:o,a=S>a?S:a,h=v>h?v:h}this.minX=n,this.minY=o,this.maxX=a,this.maxY=h}containsPoint(e,t){return this.minX<=e&&this.minY<=t&&this.maxX>=e&&this.maxY>=t}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(e){return this.minX=e.minX,this.minY=e.minY,this.maxX=e.maxX,this.maxY=e.maxY,this}}var md={grad:.9,turn:360,rad:360/(2*Math.PI)},Zt=function(r){return typeof r=="string"?r.length>0:typeof r=="number"},St=function(r,e,t){return e===void 0&&(e=0),t===void 0&&(t=Math.pow(10,e)),Math.round(t*r)/t+0},It=function(r,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),r>t?t:r>e?r:e},gh=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},ro=function(r){return{r:It(r.r,0,255),g:It(r.g,0,255),b:It(r.b,0,255),a:It(r.a)}},js=function(r){return{r:St(r.r),g:St(r.g),b:St(r.b),a:St(r.a,3)}},yd=/^#([0-9a-f]{3,8})$/i,Qi=function(r){var e=r.toString(16);return e.length<2?"0"+e:e},mh=function(r){var e=r.r,t=r.g,i=r.b,s=r.a,n=Math.max(e,t,i),o=n-Math.min(e,t,i),a=o?n===e?(t-i)/o:n===t?2+(i-e)/o:4+(e-t)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:s}},yh=function(r){var e=r.h,t=r.s,i=r.v,s=r.a;e=e/360*6,t/=100,i/=100;var n=Math.floor(e),o=i*(1-t),a=i*(1-(e-n)*t),h=i*(1-(1-e+n)*t),l=n%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}},oo=function(r){return{h:gh(r.h),s:It(r.s,0,100),l:It(r.l,0,100),a:It(r.a)}},ao=function(r){return{h:St(r.h),s:St(r.s),l:St(r.l),a:St(r.a,3)}},ho=function(r){return yh((t=(e=r).s,{h:e.h,s:(t*=((i=e.l)<50?i:100-i)/100)>0?2*t/(i+t)*100:0,v:i+t,a:e.a}));var e,t,i},Ai=function(r){return{h:(e=mh(r)).h,s:(s=(200-(t=e.s))*(i=e.v)/100)>0&&s<200?t*i/100/(s<=100?s:200-s)*100:0,l:s/2,a:e.a};var e,t,i,s},xd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Sd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,vd=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,bd=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Bn={string:[[function(r){var e=yd.exec(r);return e?(r=e[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:r.length===4?St(parseInt(r[3]+r[3],16)/255,2):1}:r.length===6||r.length===8?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:r.length===8?St(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var e=vd.exec(r)||bd.exec(r);return e?e[2]!==e[4]||e[4]!==e[6]?null:ro({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(r){var e=xd.exec(r)||Sd.exec(r);if(!e)return null;var t,i,s=oo({h:(t=e[1],i=e[2],i===void 0&&(i="deg"),Number(t)*(md[i]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return ho(s)},"hsl"]],object:[[function(r){var e=r.r,t=r.g,i=r.b,s=r.a,n=s===void 0?1:s;return Zt(e)&&Zt(t)&&Zt(i)?ro({r:Number(e),g:Number(t),b:Number(i),a:Number(n)}):null},"rgb"],[function(r){var e=r.h,t=r.s,i=r.l,s=r.a,n=s===void 0?1:s;if(!Zt(e)||!Zt(t)||!Zt(i))return null;var o=oo({h:Number(e),s:Number(t),l:Number(i),a:Number(n)});return ho(o)},"hsl"],[function(r){var e=r.h,t=r.s,i=r.v,s=r.a,n=s===void 0?1:s;if(!Zt(e)||!Zt(t)||!Zt(i))return null;var o=function(a){return{h:gh(a.h),s:It(a.s,0,100),v:It(a.v,0,100),a:It(a.a)}}({h:Number(e),s:Number(t),v:Number(i),a:Number(n)});return yh(o)},"hsv"]]},lo=function(r,e){for(var t=0;t<e.length;t++){var i=e[t][0](r);if(i)return[i,e[t][1]]}return[null,void 0]},wd=function(r){return typeof r=="string"?lo(r.trim(),Bn.string):typeof r=="object"&&r!==null?lo(r,Bn.object):[null,void 0]},Ys=function(r,e){var t=Ai(r);return{h:t.h,s:It(t.s+100*e,0,100),l:t.l,a:t.a}},Xs=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},co=function(r,e){var t=Ai(r);return{h:t.h,s:t.s,l:It(t.l+100*e,0,100),a:t.a}},Dn=function(){function r(e){this.parsed=wd(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return this.parsed!==null},r.prototype.brightness=function(){return St(Xs(this.rgba),2)},r.prototype.isDark=function(){return Xs(this.rgba)<.5},r.prototype.isLight=function(){return Xs(this.rgba)>=.5},r.prototype.toHex=function(){return e=js(this.rgba),t=e.r,i=e.g,s=e.b,o=(n=e.a)<1?Qi(St(255*n)):"","#"+Qi(t)+Qi(i)+Qi(s)+o;var e,t,i,s,n,o},r.prototype.toRgb=function(){return js(this.rgba)},r.prototype.toRgbString=function(){return e=js(this.rgba),t=e.r,i=e.g,s=e.b,(n=e.a)<1?"rgba("+t+", "+i+", "+s+", "+n+")":"rgb("+t+", "+i+", "+s+")";var e,t,i,s,n},r.prototype.toHsl=function(){return ao(Ai(this.rgba))},r.prototype.toHslString=function(){return e=ao(Ai(this.rgba)),t=e.h,i=e.s,s=e.l,(n=e.a)<1?"hsla("+t+", "+i+"%, "+s+"%, "+n+")":"hsl("+t+", "+i+"%, "+s+"%)";var e,t,i,s,n},r.prototype.toHsv=function(){return e=mh(this.rgba),{h:St(e.h),s:St(e.s),v:St(e.v),a:St(e.a,3)};var e},r.prototype.invert=function(){return Ut({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},r.prototype.saturate=function(e){return e===void 0&&(e=.1),Ut(Ys(this.rgba,e))},r.prototype.desaturate=function(e){return e===void 0&&(e=.1),Ut(Ys(this.rgba,-e))},r.prototype.grayscale=function(){return Ut(Ys(this.rgba,-1))},r.prototype.lighten=function(e){return e===void 0&&(e=.1),Ut(co(this.rgba,e))},r.prototype.darken=function(e){return e===void 0&&(e=.1),Ut(co(this.rgba,-e))},r.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},r.prototype.alpha=function(e){return typeof e=="number"?Ut({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):St(this.rgba.a,3);var t},r.prototype.hue=function(e){var t=Ai(this.rgba);return typeof e=="number"?Ut({h:e,s:t.s,l:t.l,a:t.a}):St(t.h)},r.prototype.isEqual=function(e){return this.toHex()===Ut(e).toHex()},r}(),Ut=function(r){return r instanceof Dn?r:new Dn(r)},uo=[],Cd=function(r){r.forEach(function(e){uo.indexOf(e)<0&&(e(Dn,Bn),uo.push(e))})};function Ad(r,e){var t={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 t)i[t[s]]=s;var n={};r.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(!n.length)for(var p in t)n[p]=new r(t[p]).toRgb();for(var f in t){var y=(a=c,h=n[f],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=f)}return u}},e.string.push([function(o){var a=o.toLowerCase(),h=a==="transparent"?"#0000":t[a];return h?new r(h).toRgb():null},"name"])}Cd([Ad]);const ei=class bi{constructor(e=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=e}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(e){return this.value=e,this}set value(e){if(e instanceof bi)this._value=this._cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(e===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,e))&&(this._value=this._cloneSource(e),this._normalize(this._value))}}get value(){return this._value}_cloneSource(e){return typeof e=="string"||typeof e=="number"||e instanceof Number||e===null?e:Array.isArray(e)||ArrayBuffer.isView(e)?e.slice(0):typeof e=="object"&&e!==null?{...e}:e}_isSourceEqual(e,t){const i=typeof e;if(i!==typeof t)return!1;if(i==="number"||i==="string"||e instanceof Number)return e===t;if(Array.isArray(e)&&Array.isArray(t)||ArrayBuffer.isView(e)&&ArrayBuffer.isView(t))return e.length!==t.length?!1:e.every((n,o)=>n===t[o]);if(e!==null&&t!==null){const n=Object.keys(e),o=Object.keys(t);return n.length!==o.length?!1:n.every(a=>e[a]===t[a])}return e===t}toRgba(){const[e,t,i,s]=this._components;return{r:e,g:t,b:i,a:s}}toRgb(){const[e,t,i]=this._components;return{r:e,g:t,b:i}}toRgbaString(){const[e,t,i]=this.toUint8RgbArray();return`rgba(${e},${t},${i},${this.alpha})`}toUint8RgbArray(e){const[t,i,s]=this._components;return this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb),e[0]=Math.round(t*255),e[1]=Math.round(i*255),e[2]=Math.round(s*255),e}toArray(e){this._arrayRgba||(this._arrayRgba=[]),e||(e=this._arrayRgba);const[t,i,s,n]=this._components;return e[0]=t,e[1]=i,e[2]=s,e[3]=n,e}toRgbArray(e){this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb);const[t,i,s]=this._components;return e[0]=t,e[1]=i,e[2]=s,e}toNumber(){return this._int}toBgrNumber(){const[e,t,i]=this.toUint8RgbArray();return(i<<16)+(t<<8)+e}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[t,i,s,n]=bi._temp.setValue(e)._components;return this._components[0]*=t,this._components[1]*=i,this._components[2]*=s,this._components[3]*=n,this._refreshInt(),this._value=null,this}premultiply(e,t=!0){return t&&(this._components[0]*=e,this._components[1]*=e,this._components[2]*=e),this._components[3]=e,this._refreshInt(),this._value=null,this}toPremultiplied(e,t=!0){if(e===1)return(255<<24)+this._int;if(e===0)return t?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,n=this._int&255;return t&&(i=i*e+.5|0,s=s*e+.5|0,n=n*e+.5|0),(e*255<<24)+(i<<16)+(s<<8)+n}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const t=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(e){return this._components[3]=this._clamp(e),this}_normalize(e){let t,i,s,n;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const o=e;t=(o>>16&255)/255,i=(o>>8&255)/255,s=(o&255)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[t,i,s,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[t,i,s,n=255]=e,t/=255,i/=255,s/=255,n/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const a=bi.HEX_PATTERN.exec(e);a&&(e=`#${a[2]}`)}const o=Ut(e);o.isValid()&&({r:t,g:i,b:s,a:n}=o.rgba,t/=255,i/=255,s/=255)}if(t!==void 0)this._components[0]=t,this._components[1]=i,this._components[2]=s,this._components[3]=n,this._refreshInt();else throw new Error(`Unable to convert color ${e}`)}_refreshInt(){this._clamp(this._components);const[e,t,i]=this._components;this._int=(e*255<<16)+(t*255<<8)+(i*255|0)}_clamp(e,t=0,i=1){return typeof e=="number"?Math.min(Math.max(e,t),i):(e.forEach((s,n)=>{e[n]=Math.min(Math.max(s,t),i)}),e)}static isColorLike(e){return typeof e=="number"||typeof e=="string"||e instanceof Number||e instanceof bi||Array.isArray(e)||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Float32Array||e.r!==void 0&&e.g!==void 0&&e.b!==void 0||e.r!==void 0&&e.g!==void 0&&e.b!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0&&e.a!==void 0}};ei.shared=new ei;ei._temp=new ei;ei.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let rt=ei;const Pd={cullArea:null,cullable:!1,cullableChildren:!0};let Zs=0;const po=500;function nt(...r){Zs!==po&&(Zs++,Zs===po?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...r))}const Hi={_registeredResources:new Set,register(r){this._registeredResources.add(r)},unregister(r){this._registeredResources.delete(r)},release(){this._registeredResources.forEach(r=>r.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(r){return this._registeredResources.has(r)},reset(){this._registeredResources.clear()}};class Md{constructor(e,t){this._pool=[],this._count=0,this._index=0,this._classType=e,t&&this.prepopulate(t)}prepopulate(e){for(let t=0;t<e;t++)this._pool[this._index++]=new this._classType;this._count+=e}get(e){var i;let t;return this._index>0?t=this._pool[--this._index]:(t=new this._classType,this._count++),(i=t.init)==null||i.call(t,e),t}return(e){var t;(t=e.reset)==null||t.call(e),this._pool[this._index++]=e}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 e=0;e<this._index;e++)this._pool[e].destroy();this._pool.length=0,this._count=0,this._index=0}}class _d{constructor(){this._poolsByClass=new Map}prepopulate(e,t){this.getPool(e).prepopulate(t)}get(e,t){return this.getPool(e).get(t)}return(e){this.getPool(e.constructor).return(e)}getPool(e){return this._poolsByClass.has(e)||this._poolsByClass.set(e,new Md(e)),this._poolsByClass.get(e)}stats(){const e={};return this._poolsByClass.forEach(t=>{const i=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[i]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}}const _t=new _d;Hi.register(_t);const Td={get isCachedAsTexture(){var r;return!!((r=this.renderGroup)!=null&&r.isCachedAsTexture)},cacheAsTexture(r){typeof r=="boolean"&&r===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(r===!0?{}:r))},updateCacheTexture(){var r;(r=this.renderGroup)==null||r.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(r){V("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(r)}};function kd(r,e,t){const i=r.length;let s;if(e>=i||t===0)return;t=e+t>i?i-e:t;const n=i-t;for(s=e;s<n;++s)r[s]=r[s+t];r.length=n}const Rd={allowChildren:!0,removeChildren(r=0,e){var n;const t=e??this.children.length,i=t-r,s=[];if(i>0&&i<=t){for(let a=t-1;a>=r;a--){const h=this.children[a];h&&(s.push(h),h.parent=null)}kd(this.children,r,t);const o=this.renderGroup||this.parentRenderGroup;o&&o.removeChildren(s);for(let a=0;a<s.length;++a){const h=s[a];(n=h.parentRenderLayer)==null||n.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(r){const e=this.getChildAt(r);return this.removeChild(e)},getChildAt(r){if(r<0||r>=this.children.length)throw new Error(`getChildAt: Index (${r}) does not exist.`);return this.children[r]},setChildIndex(r,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);this.getChildIndex(r),this.addChildAt(r,e)},getChildIndex(r){const e=this.children.indexOf(r);if(e===-1)throw new Error("The supplied Container must be a child of the caller");return e},addChildAt(r,e){this.allowChildren||V(J,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:t}=this;if(e<0||e>t.length)throw new Error(`${r}addChildAt: The index ${e} supplied is out of bounds ${t.length}`);if(r.parent){const s=r.parent.children.indexOf(r);if(r.parent===this&&s===e)return r;s!==-1&&r.parent.children.splice(s,1)}e===t.length?t.push(r):t.splice(e,0,r),r.parent=this,r.didChange=!0,r._updateFlags=15;const i=this.renderGroup||this.parentRenderGroup;return i&&i.addChild(r),this.sortableChildren&&(this.sortDirty=!0),this.emit("childAdded",r,this,e),r.emit("added",this),r},swapChildren(r,e){if(r===e)return;const t=this.getChildIndex(r),i=this.getChildIndex(e);this.children[t]=e,this.children[i]=r;const s=this.renderGroup||this.parentRenderGroup;s&&(s.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){var r;(r=this.parent)==null||r.removeChild(this)},reparentChild(...r){return r.length===1?this.reparentChildAt(r[0],this.children.length):(r.forEach(e=>this.reparentChildAt(e,this.children.length)),r[0])},reparentChildAt(r,e){if(r.parent===this)return this.setChildIndex(r,e),r;const t=r.worldTransform.clone();r.removeFromParent(),this.addChildAt(r,e);const i=this.worldTransform.clone();return i.invert(),t.prepend(i),r.setFromMatrix(t),r},replaceChild(r,e){r.updateLocalTransform(),this.addChildAt(e,this.getChildIndex(r)),e.setFromMatrix(r.localTransform),e.updateLocalTransform(),this.removeChild(r)}},Ed={collectRenderables(r,e,t){this.parentRenderLayer&&this.parentRenderLayer!==t||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(r,e,t):this.renderGroup?e.renderPipes.renderGroup.addRenderGroup(this.renderGroup,r):this.collectRenderablesWithEffects(r,e,t))},collectRenderablesSimple(r,e,t){const i=this.children,s=i.length;for(let n=0;n<s;n++)i[n].collectRenderables(r,e,t)},collectRenderablesWithEffects(r,e,t){const{renderPipes:i}=e;for(let s=0;s<this.effects.length;s++){const n=this.effects[s];i[n.pipe].push(n,this,r)}this.collectRenderablesSimple(r,e,t);for(let s=this.effects.length-1;s>=0;s--){const n=this.effects[s];i[n.pipe].pop(n,this,r)}}};class fo{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let e=0;e<this.filters.length;e++)this.filters[e].destroy();this.filters=null,this.filterArea=null}}class Id{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(e=>{this.add({test:e.test,maskClass:e})}))}add(e){this._tests.push(e)}getMaskEffect(e){this._initialized||this.init();for(let t=0;t<this._tests.length;t++){const i=this._tests[t];if(i.test(e))return _t.get(i.maskClass,e)}return e}returnMaskEffect(e){_t.return(e)}}const Fn=new Id;$.handleByList(I.MaskEffect,Fn._effectClasses);const Bd={_maskEffect:null,_maskOptions:{inverse:!1},_filterEffect:null,effects:[],_markStructureAsChanged(){const r=this.renderGroup||this.parentRenderGroup;r&&(r.structureDidChange=!0)},addEffect(r){this.effects.indexOf(r)===-1&&(this.effects.push(r),this.effects.sort((t,i)=>t.priority-i.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(r){const e=this.effects.indexOf(r);e!==-1&&(this.effects.splice(e,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(r){const e=this._maskEffect;(e==null?void 0:e.mask)!==r&&(e&&(this.removeEffect(e),Fn.returnMaskEffect(e),this._maskEffect=null),r!=null&&(this._maskEffect=Fn.getMaskEffect(r),this.addEffect(this._maskEffect)))},get mask(){var r;return(r=this._maskEffect)==null?void 0:r.mask},setMask(r){this._maskOptions={...this._maskOptions,...r},r.mask&&(this.mask=r.mask),this._markStructureAsChanged()},set filters(r){var n;!Array.isArray(r)&&r&&(r=[r]);const e=this._filterEffect||(this._filterEffect=new fo);r=r;const t=(r==null?void 0:r.length)>0,i=((n=e.filters)==null?void 0:n.length)>0,s=t!==i;r=Array.isArray(r)?r.slice(0):r,e.filters=Object.freeze(r),s&&(t?this.addEffect(e):(this.removeEffect(e),e.filters=r??null))},get filters(){var r;return(r=this._filterEffect)==null?void 0:r.filters},set filterArea(r){this._filterEffect||(this._filterEffect=new fo),this._filterEffect.filterArea=r},get filterArea(){var r;return(r=this._filterEffect)==null?void 0:r.filterArea}},Dd={label:null,get name(){return V(J,"Container.name property has been removed, use Container.label instead"),this.label},set name(r){V(J,"Container.name property has been removed, use Container.label instead"),this.label=r},getChildByName(r,e=!1){return this.getChildByLabel(r,e)},getChildByLabel(r,e=!1){const t=this.children;for(let i=0;i<t.length;i++){const s=t[i];if(s.label===r||r instanceof RegExp&&r.test(s.label))return s}if(e)for(let i=0;i<t.length;i++){const n=t[i].getChildByLabel(r,!0);if(n)return n}return null},getChildrenByLabel(r,e=!1,t=[]){const i=this.children;for(let s=0;s<i.length;s++){const n=i[s];(n.label===r||r instanceof RegExp&&r.test(n.label))&&t.push(n)}if(e)for(let s=0;s<i.length;s++)i[s].getChildrenByLabel(r,!0,t);return t}},Pt=_t.getPool(U),Qt=_t.getPool(Bt),Fd=new U,zd={getFastGlobalBounds(r,e){e||(e=new Bt),e.clear(),this._getGlobalBoundsRecursive(!!r,e,this.parentRenderLayer),e.isValid||e.set(0,0,0,0);const t=this.renderGroup||this.parentRenderGroup;return e.applyMatrix(t.worldTransform),e},_getGlobalBoundsRecursive(r,e,t){let i=e;if(r&&this.parentRenderLayer&&this.parentRenderLayer!==t||this.localDisplayStatus!==7||!this.measurable)return;const s=!!this.effects.length;if((this.renderGroup||s)&&(i=Qt.get().clear()),this.boundsArea)e.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 n=this.children;for(let o=0;o<n.length;o++)n[o]._getGlobalBoundsRecursive(r,i,t)}if(s){let n=!1;const o=this.renderGroup||this.parentRenderGroup;for(let a=0;a<this.effects.length;a++)this.effects[a].addBounds&&(n||(n=!0,i.applyMatrix(o.worldTransform)),this.effects[a].addBounds(i,!0));n&&i.applyMatrix(o.worldTransform.copyTo(Fd).invert()),e.addBounds(i),Qt.return(i)}else this.renderGroup&&(e.addBounds(i,this.relativeGroupTransform),Qt.return(i))}};function xh(r,e,t){t.clear();let i,s;return r.parent?e?i=r.parent.worldTransform:(s=Pt.get().identity(),i=ur(r,s)):i=U.IDENTITY,Sh(r,t,i,e),s&&Pt.return(s),t.isValid||t.set(0,0,0,0),t}function Sh(r,e,t,i){var a,h;if(!r.visible||!r.measurable)return;let s;i?s=r.worldTransform:(r.updateLocalTransform(),s=Pt.get(),s.appendFrom(r.localTransform,t));const n=e,o=!!r.effects.length;if(o&&(e=Qt.get().clear()),r.boundsArea)e.addRect(r.boundsArea,s);else{const l=r.bounds;l&&!l.isEmpty()&&(e.matrix=s,e.addBounds(l));for(let c=0;c<r.children.length;c++)Sh(r.children[c],e,s,i)}if(o){for(let l=0;l<r.effects.length;l++)(h=(a=r.effects[l]).addBounds)==null||h.call(a,e);n.addBounds(e,U.IDENTITY),Qt.return(e)}i||Pt.return(s)}function ur(r,e){const t=r.parent;return t&&(ur(t,e),t.updateLocalTransform(),e.append(t.localTransform)),e}function pr(r,e){if(r===16777215||!e)return e;if(e===16777215||!r)return r;const t=r>>16&255,i=r>>8&255,s=r&255,n=e>>16&255,o=e>>8&255,a=e&255,h=t*n/255|0,l=i*o/255|0,c=s*a/255|0;return(h<<16)+(l<<8)+c}const go=16777215;function mo(r,e){return r===go?e:e===go?r:pr(r,e)}function Pi(r){return((r&255)<<16)+(r&65280)+(r>>16&255)}const Ld={getGlobalAlpha(r){if(r)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let e=this.alpha,t=this.parent;for(;t;)e*=t.alpha,t=t.parent;return e},getGlobalTransform(r=new U,e){if(e)return r.copyFrom(this.worldTransform);this.updateLocalTransform();const t=ur(this,Pt.get().identity());return r.appendFrom(this.localTransform,t),Pt.return(t),r},getGlobalTint(r){if(r)return this.renderGroup?Pi(this.renderGroup.worldColor):this.parentRenderGroup?Pi(mo(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let e=this.localColor,t=this.parent;for(;t;)e=mo(e,t.localColor),t=t.parent;return Pi(e)}};function vh(r,e,t){return e.clear(),t||(t=U.IDENTITY),bh(r,e,t,r,!0),e.isValid||e.set(0,0,0,0),e}function bh(r,e,t,i,s){var h,l;let n;if(s)n=Pt.get(),n=t.copyTo(n);else{if(!r.visible||!r.measurable)return;r.updateLocalTransform();const c=r.localTransform;n=Pt.get(),n.appendFrom(c,t)}const o=e,a=!!r.effects.length;if(a&&(e=Qt.get().clear()),r.boundsArea)e.addRect(r.boundsArea,n);else{r.renderPipeId&&(e.matrix=n,e.addBounds(r.bounds));const c=r.children;for(let d=0;d<c.length;d++)bh(c[d],e,n,i,!1)}if(a){for(let c=0;c<r.effects.length;c++)(l=(h=r.effects[c]).addLocalBounds)==null||l.call(h,e,i);o.addBounds(e,U.IDENTITY),Qt.return(e)}Pt.return(n)}function wh(r,e){const t=r.children;for(let i=0;i<t.length;i++){const s=t[i],n=s.uid,o=(s._didViewChangeTick&65535)<<16|s._didContainerChangeTick&65535,a=e.index;(e.data[a]!==n||e.data[a+1]!==o)&&(e.data[e.index]=n,e.data[e.index+1]=o,e.didChange=!0),e.index=a+2,s.children.length&&wh(s,e)}return e.didChange}const Od=new U,Gd={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(r,e){const t=Math.sign(this.scale.x)||1;e!==0?this.scale.x=r/e*t:this.scale.x=t},_setHeight(r,e){const t=Math.sign(this.scale.y)||1;e!==0?this.scale.y=r/e*t:this.scale.y=t},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Bt});const r=this._localBoundsCacheData;return r.index=1,r.didChange=!1,r.data[0]!==this._didViewChangeTick&&(r.didChange=!0,r.data[0]=this._didViewChangeTick),wh(this,r),r.didChange&&vh(this,r.localBounds,Od),r.localBounds},getBounds(r,e){return xh(this,r,e||new Bt)}},Wd={_onRender:null,set onRender(r){const e=this.renderGroup||this.parentRenderGroup;if(!r){this._onRender&&(e==null||e.removeOnRender(this)),this._onRender=null;return}this._onRender||e==null||e.addOnRender(this),this._onRender=r},get onRender(){return this._onRender}},Ud={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(r){this._zIndex!==r&&(this._zIndex=r,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(Hd))}};function Hd(r,e){return r._zIndex-e._zIndex}const Vd={getGlobalPosition(r=new tt,e=!1){return this.parent?this.parent.toGlobal(this._position,r,e):(r.x=this._position.x,r.y=this._position.y),r},toGlobal(r,e,t=!1){const i=this.getGlobalTransform(Pt.get(),t);return e=i.apply(r,e),Pt.return(i),e},toLocal(r,e,t,i){e&&(r=e.toGlobal(r,t,i));const s=this.getGlobalTransform(Pt.get(),i);return t=s.applyInverse(r,t),Pt.return(s),t}};class fr{constructor(){this.uid=dt("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(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let Nd=0;class jd{constructor(e){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=e||{},this.enableFullScreen=!1,this.textureStyle=new ti(this.textureOptions)}createTexture(e,t,i){const s=new Dt({...this.textureOptions,width:e,height:t,resolution:1,antialias:i,autoGarbageCollect:!1});return new G({source:s,label:`texturePool_${Nd++}`})}getOptimalTexture(e,t,i=1,s){let n=Math.ceil(e*i-1e-6),o=Math.ceil(t*i-1e-6);n=Je(n),o=Je(o);const a=(n<<17)+(o<<1)+(s?1:0);this._texturePool[a]||(this._texturePool[a]=[]);let h=this._texturePool[a].pop();return h||(h=this.createTexture(n,o,s)),h.source._resolution=i,h.source.width=n/i,h.source.height=o/i,h.source.pixelWidth=n,h.source.pixelHeight=o,h.frame.x=0,h.frame.y=0,h.frame.width=e,h.frame.height=t,h.updateUvs(),this._poolKeyHash[h.uid]=a,h}getSameSizeTexture(e,t=!1){const i=e.source;return this.getOptimalTexture(e.width,e.height,i._resolution,t)}returnTexture(e,t=!1){const i=this._poolKeyHash[e.uid];t&&(e.source.style=this.textureStyle),this._texturePool[i].push(e)}clear(e){if(e=e!==!1,e)for(const t in this._texturePool){const i=this._texturePool[t];if(i)for(let s=0;s<i.length;s++)i[s].destroy(!0)}this._texturePool={}}}const _s=new jd;Hi.register(_s);class Yd{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 fr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(e){this.root=e,e._onRender&&this.addOnRender(e),e.didChange=!0;const t=e.children;for(let i=0;i<t.length;i++){const s=t[i];s._updateFlags=15,this.addChild(s)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(_s.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const e in this.childrenToUpdate){const t=this.childrenToUpdate[e];t.list.fill(null),t.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(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){const t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.parent===this.root?e.relativeRenderGroupDepth=1:e.relativeRenderGroupDepth=e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);const t=e.children;for(let i=0;i<t.length;i++)this.addChild(t[i])}removeChild(e){if(this.structureDidChange=!0,e._onRender&&(e.renderGroup||this.removeOnRender(e)),e.parentRenderGroup=null,e.renderGroup){this._removeRenderGroupChild(e.renderGroup);return}const t=e.children;for(let i=0;i<t.length;i++)this.removeChild(t[i])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||(t=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]}),t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.push(e)}removeOnRender(e){this._onRenderContainers.splice(this._onRenderContainers.indexOf(e),1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}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(e=[]){const t=this.root.children;for(let i=0;i<t.length;i++)this._getChildren(t[i],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;const i=e.children;for(let s=0;s<i.length;s++)this._getChildren(i[s],t);return t}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 e=this._parentCacheAsTextureRenderGroup;return e?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new U),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(e.inverseWorldTransform).translate(-e._textureBounds.x,-e._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function Xd(r,e,t={}){for(const i in e)!t[i]&&e[i]!==void 0&&(r[i]=e[i])}const qs=new ct(null),Ji=new ct(null),Ks=new ct(null,1,1),ts=new ct(null),yo=1,Zd=2,$s=4;class L extends Yt{constructor(e={}){var t,i;super(),this.uid=dt("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 ct(this,0,0),this._scale=Ks,this._pivot=Ji,this._origin=ts,this._skew=qs,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=[],Xd(this,e,{children:!0,parent:!0,effects:!0}),(t=e.children)==null||t.forEach(s=>this.addChild(s)),(i=e.parent)==null||i.addChild(this)}static mixin(e){V("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),$.mixin(L,e)}set _didChangeId(e){this._didViewChangeTick=e>>12&4095,this._didContainerChangeTick=e&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...e){if(this.allowChildren||V(J,"addChild: Only Containers will be allowed to add children in v8.0.0"),e.length>1){for(let s=0;s<e.length;s++)this.addChild(e[s]);return e[0]}const t=e[0],i=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),i&&(i.structureDidChange=!0),t):(t.parent&&t.parent.removeChild(t),this.children.push(t),this.sortableChildren&&(this.sortDirty=!0),t.parent=this,t.didChange=!0,t._updateFlags=15,i&&i.addChild(t),this.emit("childAdded",t,this,this.children.length-1),t.emit("added",this),this._didViewChangeTick++,t._zIndex!==0&&t.depthOfChildModified(),t)}removeChild(...e){if(e.length>1){for(let s=0;s<e.length;s++)this.removeChild(e[s]);return e[0]}const t=e[0],i=this.children.indexOf(t);return i>-1&&(this._didViewChangeTick++,this.children.splice(i,1),this.renderGroup?this.renderGroup.removeChild(t):this.parentRenderGroup&&this.parentRenderGroup.removeChild(t),t.parentRenderLayer&&t.parentRenderLayer.detach(t),t.parent=null,this.emit("childRemoved",t,this,i),t.emit("removed",this)),t}_onUpdate(e){e&&e===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(e){!!this.renderGroup!==e&&(e?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const e=this.parentRenderGroup;e==null||e.removeChild(this),this.renderGroup=_t.get(Yd,this),this.groupTransform=U.IDENTITY,e==null||e.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const e=this.parentRenderGroup;e==null||e.removeChild(this),_t.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,e==null||e.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(e){this._position.x=e}get y(){return this._position.y}set y(e){this._position.y=e}get position(){return this._position}set position(e){this._position.copyFrom(e)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._onUpdate(this._skew))}get angle(){return this.rotation*hd}set angle(e){this.rotation=e*ld}get pivot(){return this._pivot===Ji&&(this._pivot=new ct(this,0,0)),this._pivot}set pivot(e){this._pivot===Ji&&(this._pivot=new ct(this,0,0),this._origin!==ts&&nt("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._pivot.set(e):this._pivot.copyFrom(e)}get skew(){return this._skew===qs&&(this._skew=new ct(this,0,0)),this._skew}set skew(e){this._skew===qs&&(this._skew=new ct(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===Ks&&(this._scale=new ct(this,1,1)),this._scale}set scale(e){this._scale===Ks&&(this._scale=new ct(this,0,0)),typeof e=="string"&&(e=parseFloat(e)),typeof e=="number"?this._scale.set(e):this._scale.copyFrom(e)}get origin(){return this._origin===ts&&(this._origin=new ct(this,0,0)),this._origin}set origin(e){this._origin===ts&&(this._origin=new ct(this,0,0),this._pivot!==Ji&&nt("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._origin.set(e):this._origin.copyFrom(e)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(e){const t=this.getLocalBounds().width;this._setWidth(e,t)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(e){const t=this.getLocalBounds().height;this._setHeight(e,t)}getSize(e){e||(e={});const t=this.getLocalBounds();return e.width=Math.abs(this.scale.x*t.width),e.height=Math.abs(this.scale.y*t.height),e}setSize(e,t){const i=this.getLocalBounds();typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,i.width),t!==void 0&&this._setHeight(t,i.height)}_updateSkew(){const e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x=="number"?e.x:this.position.x,typeof e.y=="number"?e.y:this.position.y),this.scale.set(typeof e.scaleX=="number"?e.scaleX||1:this.scale.x,typeof e.scaleY=="number"?e.scaleY||1:this.scale.y),this.rotation=typeof e.rotation=="number"?e.rotation:this.rotation,this.skew.set(typeof e.skewX=="number"?e.skewX:this.skew.x,typeof e.skewY=="number"?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX=="number"?e.pivotX:this.pivot.x,typeof e.pivotY=="number"?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX=="number"?e.originX:this.origin.x,typeof e.originY=="number"?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){const e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;const t=this.localTransform,i=this._scale,s=this._pivot,n=this._origin,o=this._position,a=i._x,h=i._y,l=s._x,c=s._y,d=-n._x,u=-n._y;t.a=this._cx*a,t.b=this._sx*a,t.c=this._cy*h,t.d=this._sy*h,t.tx=o._x-(l*t.a+c*t.c)+(d*t.a+u*t.c)-d,t.ty=o._y-(l*t.b+c*t.d)+(d*t.b+u*t.d)-u}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=yo,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){const i=rt.shared.setValue(e??16777215).toBgrNumber();i!==this.localColor&&(this.localColor=i,this._updateFlags|=yo,this._onUpdate())}get tint(){return Pi(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Zd,this.localBlendMode=e,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(e){const t=e?2:0;(this.localDisplayStatus&2)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=$s,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(e){const t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=$s,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(e){const t=e?1:0;(this.localDisplayStatus&1)!==t&&(this._updateFlags|=$s,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(e=!1){var s;if(this.destroyed)return;this.destroyed=!0;let t;if(this.children.length&&(t=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 e=="boolean"?e:e==null?void 0:e.children)&&t)for(let n=0;n<t.length;++n)t[n].destroy(e);(s=this.renderGroup)==null||s.destroy(),this.renderGroup=null}}$.mixin(L,Rd,zd,Vd,Wd,Gd,Bd,Dd,Ud,Pd,Td,Ld,Ed);class ai extends L{constructor(e){super(e),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 Bt(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=e.autoGarbageCollect??!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(e){this._roundPixels=e?1:0}containsPoint(e){const t=this.bounds,{x:i,y:s}=e;return i>=t.minX&&i<=t.maxX&&s>=t.minY&&s<=t.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const e=this.renderGroup||this.parentRenderGroup;e&&e.onChildViewUpdate(this)}unload(){var e;this.emit("unload",this);for(const t in this._gpuData)(e=this._gpuData[t])==null||e.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(e){this.unload(),super.destroy(e),this._bounds=null}collectRenderablesSimple(e,t,i){const{renderPipes:s}=t;s.blendMode.pushBlendMode(this,this.groupBlendMode,e);const o=s[this.renderPipeId];o!=null&&o.addRenderable&&o.addRenderable(this,e),this.didViewUpdate=!1;const a=this.children,h=a.length;for(let l=0;l<h;l++)a[l].collectRenderables(e,t,i);s.blendMode.popBlendMode(e)}}class jt extends ai{constructor(e=G.EMPTY){e instanceof G&&(e={texture:e});const{texture:t=G.EMPTY,anchor:i,roundPixels:s,width:n,height:o,...a}=e;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new ct({_onUpdate:()=>{this.onViewUpdate()}}),i?this.anchor=i:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=s??!1,n!==void 0&&(this.width=n),o!==void 0&&(this.height=o)}static from(e,t=!1){return e instanceof G?new jt(e):new jt(G.from(e,t))}set texture(e){e||(e=G.EMPTY);const t=this._texture;t!==e&&(t&&t.dynamic&&t.off("update",this.onViewUpdate,this),e.dynamic&&e.on("update",this.onViewUpdate,this),this._texture=e,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 fh(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 e=this._anchor,t=this._texture,i=this._bounds,{width:s,height:n}=t.orig;i.minX=-e._x*s,i.maxX=i.minX+s,i.minY=-e._y*n,i.maxY=i.minY+n}destroy(e=!1){if(super.destroy(e),typeof e=="boolean"?e:e==null?void 0:e.texture){const i=typeof e=="boolean"?e:e==null?void 0:e.textureSource;this._texture.destroy(i)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(e){this._setWidth(e,this._texture.orig.width),this._width=e}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(e){this._setHeight(e,this._texture.orig.height),this._height=e}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this._texture.orig.width,e.height=Math.abs(this.scale.y)*this._texture.orig.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this._texture.orig.width),t!==void 0&&this._setHeight(t,this._texture.orig.height)}}const qd=new Bt;function Ch(r,e,t){const i=qd;r.measurable=!0,xh(r,t,i),e.addBoundsMask(i),r.measurable=!1}function Ah(r,e,t){const i=Qt.get();r.measurable=!0;const s=Pt.get().identity(),n=Ph(r,t,s);vh(r,i,n),r.measurable=!1,e.addBoundsMask(i),Pt.return(s),Qt.return(i)}function Ph(r,e,t){return r?(r!==e&&(Ph(r.parent,e,t),r.updateLocalTransform(),t.append(r.localTransform)),t):(nt("Mask bounds, renderable is not inside the root container"),t)}class Mh{constructor(e){this.priority=0,this.inverse=!1,this.pipe="alphaMask",e!=null&&e.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e 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(e,t){this.inverse||Ch(this.mask,e,t)}addLocalBounds(e,t){Ah(this.mask,e,t)}containsPoint(e,t){const i=this.mask;return t(i,e)}destroy(){this.reset()}static test(e){return e instanceof jt}}Mh.extension=I.MaskEffect;class _h{constructor(e){this.priority=0,this.pipe="colorMask",e!=null&&e.mask&&this.init(e.mask)}init(e){this.mask=e}destroy(){}static test(e){return typeof e=="number"}}_h.extension=I.MaskEffect;class Th{constructor(e){this.priority=0,this.pipe="stencilMask",e!=null&&e.mask&&this.init(e.mask)}init(e){this.mask=e,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(e,t){Ch(this.mask,e,t)}addLocalBounds(e,t){Ah(this.mask,e,t)}containsPoint(e,t){const i=this.mask;return t(i,e)}destroy(){this.reset()}static test(e){return e instanceof L}}Th.extension=I.MaskEffect;const Kd={createCanvas:(r,e)=>{const t=document.createElement("canvas");return t.width=r,t.height=e,t},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,e)=>fetch(r,e),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")};let xo=Kd;const j={get(){return xo},set(r){xo=r}};class gr extends Dt{constructor(e){e.resource||(e.resource=j.get().createCanvas()),e.width||(e.width=e.resource.width,e.autoDensity||(e.width/=e.resolution)),e.height||(e.height=e.resource.height,e.autoDensity||(e.height/=e.resolution)),super(e),this.uploadMethodId="image",this.autoDensity=e.autoDensity,this.resizeCanvas(),this.transparent=!!e.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(e=this.width,t=this.height,i=this._resolution){const s=super.resize(e,t,i);return s&&this.resizeCanvas(),s}static test(e){return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&e instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}gr.extension=I.TextureSource;class ii extends Dt{constructor(e){super(e),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(e){return globalThis.HTMLImageElement&&e instanceof HTMLImageElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||globalThis.VideoFrame&&e instanceof VideoFrame}}ii.extension=I.TextureSource;var Ie=(r=>(r[r.INTERACTION=50]="INTERACTION",r[r.HIGH=25]="HIGH",r[r.NORMAL=0]="NORMAL",r[r.LOW=-25]="LOW",r[r.UTILITY=-50]="UTILITY",r))(Ie||{});class Qs{constructor(e,t=null,i=0,s=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=i,this._once=s}match(e,t=null){return this._fn===e&&this._context===t}emit(e){this._fn&&(this._context?this._fn.call(this._context,e):this._fn(e));const t=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),t}connect(e){this.previous=e,e.next&&(e.next.previous=this),this.next=e.next,e.next=this}destroy(e=!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 t=this.next;return this.next=e?null:t,this.previous=null,t}}const kh=class Tt{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 Qs(null,null,1/0),this.deltaMS=1/Tt.targetFPMS,this.elapsedMS=1/Tt.targetFPMS,this._tick=e=>{this._requestId=null,this.started&&(this.update(e),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(e,t,i=Ie.NORMAL){return this._addListener(new Qs(e,t,i))}addOnce(e,t,i=Ie.NORMAL){return this._addListener(new Qs(e,t,i,!0))}_addListener(e){let t=this._head.next,i=this._head;if(!t)e.connect(i);else{for(;t;){if(e.priority>t.priority){e.connect(i);break}i=t,t=t.next}e.previous||e.connect(i)}return this._startIfPossible(),this}remove(e,t){let i=this._head.next;for(;i;)i.match(e,t)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let e=0,t=this._head;for(;t=t.next;)e++;return e}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let e=this._head.next;for(;e;)e=e.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let t;if(e>this.lastTime){if(t=this.elapsedMS=e-this.lastTime,t>this._maxElapsedMS&&(t=this._maxElapsedMS),t*=this.speed,this._minElapsedMS){const n=e-this._lastFrame|0;if(n<this._minElapsedMS)return;this._lastFrame=e-n%this._minElapsedMS}this.deltaMS=t,this.deltaTime=this.deltaMS*Tt.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=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const t=Math.min(this.maxFPS,e),i=Math.min(Math.max(0,t)/1e3,Tt.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){if(e===0)this._minElapsedMS=0;else{const t=Math.max(this.minFPS,e);this._minElapsedMS=1/(t/1e3)}}static get shared(){if(!Tt._shared){const e=Tt._shared=new Tt;e.autoStart=!0,e._protected=!0}return Tt._shared}static get system(){if(!Tt._system){const e=Tt._system=new Tt;e.autoStart=!0,e._protected=!0}return Tt._system}};kh.targetFPMS=.06;let yt=kh,Js;async function Rh(){return Js??(Js=(async()=>{var o;const e=j.get().createCanvas(1,1).getContext("webgl");if(!e)return"premultiply-alpha-on-upload";const t=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(!t)return"premultiply-alpha-on-upload";const i=e.createTexture();e.bindTexture(e.TEXTURE_2D,i);const s=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,s),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,i,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);const n=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,n),e.deleteFramebuffer(s),e.deleteTexture(i),(o=e.getExtension("WEBGL_lose_context"))==null||o.loseContext(),n[0]<=n[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),Js}const Ts=class Eh extends Dt{constructor(e){super(e),this.isReady=!1,this.uploadMethodId="video",e={...Eh.defaultOptions,...e},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this.alphaMode=e.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),e.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const e=yt.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!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 e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener("play",this._onPlayStart),e.addEventListener("pause",this._onPlayStop),e.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlayThrough),e.addEventListener("error",this._onError,!0)),this.alphaMode=await Rh(),this._load=new Promise((i,s)=>{this.isValid?i(this):(this._resolve=i,this._reject=s,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.resource;return!e.paused&&!e.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 e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.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 e=this.resource;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlayThrough),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(yt.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||(yt.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(yt.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};Ts.extension=I.TextureSource;Ts.defaultOptions={...Dt.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};Ts.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let Mi=Ts;const zt=(r,e,t=!1)=>(Array.isArray(r)||(r=[r]),e?r.map(i=>typeof i=="string"||t?e(i):i):r);class $d{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){const t=this._cache.get(e);return t||nt(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){const i=zt(e);let s;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.test(t)){s=l.getCacheableAssets(i,t);break}}const n=new Map(Object.entries(s||{}));s||i.forEach(h=>{n.set(h,t)});const o=[...n.keys()],a={cacheKeys:o,keys:i};i.forEach(h=>{this._cacheMap.set(h,a)}),o.forEach(h=>{const l=s?s[h]:t;this._cache.has(h)&&this._cache.get(h)!==l&&nt("[Cache] already has key:",h),this._cache.set(h,n.get(h))})}remove(e){if(!this._cacheMap.has(e)){nt(`[Assets] Asset id ${e} was not found in the Cache`);return}const t=this._cacheMap.get(e);t.cacheKeys.forEach(s=>{this._cache.delete(s)}),t.keys.forEach(s=>{this._cacheMap.delete(s)})}get parsers(){return this._parsers}}const xt=new $d,zn=[];$.handleByList(I.TextureSource,zn);function Ih(r={}){const e=r&&r.resource,t=e?r.resource:r,i=e?r:{resource:r};for(let s=0;s<zn.length;s++){const n=zn[s];if(n.test(t))return new n(i)}throw new Error(`Could not find a source type for resource: ${i.resource}`)}function Qd(r={},e=!1){const t=r&&r.resource,i=t?r.resource:r,s=t?r:{resource:r};if(!e&&xt.has(i))return xt.get(i);const n=new G({source:Ih(s)});return n.on("destroy",()=>{xt.has(i)&&xt.remove(i)}),e||xt.set(i,n),n}function Jd(r,e=!1){return typeof r=="string"?xt.get(r):r instanceof Dt?new G({source:r}):Qd(r,e)}G.from=Jd;Dt.from=Ih;$.add(Mh,_h,Th,Mi,ii,gr,dr);var ue=(r=>(r[r.Low=0]="Low",r[r.Normal=1]="Normal",r[r.High=2]="High",r))(ue||{});function Ft(r){if(typeof r!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(r)}`)}function di(r){return r.split("?")[0].split("#")[0]}function tu(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function eu(r,e,t){return r.replace(new RegExp(tu(e),"g"),t)}function iu(r,e){let t="",i=0,s=-1,n=0,o=-1;for(let a=0;a<=r.length;++a){if(a<r.length)o=r.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(s===a-1||n===1))if(s!==a-1&&n===2){if(t.length<2||i!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){const h=t.lastIndexOf("/");if(h!==t.length-1){h===-1?(t="",i=0):(t=t.slice(0,h),i=t.length-1-t.lastIndexOf("/")),s=a,n=0;continue}}else if(t.length===2||t.length===1){t="",i=0,s=a,n=0;continue}}}else t.length>0?t+=`/${r.slice(s+1,a)}`:t=r.slice(s+1,a),i=a-s-1;s=a,n=0}else o===46&&n!==-1?++n:n=-1}return t}const Mt={toPosix(r){return eu(r,"\\","/")},isUrl(r){return/^https?:/.test(this.toPosix(r))},isDataUrl(r){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(r)},isBlobUrl(r){return r.startsWith("blob:")},hasProtocol(r){return/^[^/:]+:/.test(this.toPosix(r))},getProtocol(r){Ft(r),r=this.toPosix(r);const e=/^file:\/\/\//.exec(r);if(e)return e[0];const t=/^[^/:]+:\/{0,2}/.exec(r);return t?t[0]:""},toAbsolute(r,e,t){if(Ft(r),this.isDataUrl(r)||this.isBlobUrl(r))return r;const i=di(this.toPosix(e??j.get().getBaseUrl())),s=di(this.toPosix(t??this.rootname(i)));return r=this.toPosix(r),r.startsWith("/")?Mt.join(s,r.slice(1)):this.isAbsolute(r)?r:this.join(i,r)},normalize(r){if(Ft(r),r.length===0)return".";if(this.isDataUrl(r)||this.isBlobUrl(r))return r;r=this.toPosix(r);let e="";const t=r.startsWith("/");this.hasProtocol(r)&&(e=this.rootname(r),r=r.slice(e.length));const i=r.endsWith("/");return r=iu(r),r.length>0&&i&&(r+="/"),t?`/${r}`:e+r},isAbsolute(r){return Ft(r),r=this.toPosix(r),this.hasProtocol(r)?!0:r.startsWith("/")},join(...r){if(r.length===0)return".";let e;for(let t=0;t<r.length;++t){const i=r[t];if(Ft(i),i.length>0)if(e===void 0)e=i;else{const s=r[t-1]??"";this.joinExtensions.includes(this.extname(s).toLowerCase())?e+=`/../${i}`:e+=`/${i}`}}return e===void 0?".":this.normalize(e)},dirname(r){if(Ft(r),r.length===0)return".";r=this.toPosix(r);let e=r.charCodeAt(0);const t=e===47;let i=-1,s=!0;const n=this.getProtocol(r),o=r;r=r.slice(n.length);for(let a=r.length-1;a>=1;--a)if(e=r.charCodeAt(a),e===47){if(!s){i=a;break}}else s=!1;return i===-1?t?"/":this.isUrl(o)?n+r:n:t&&i===1?"//":n+r.slice(0,i)},rootname(r){Ft(r),r=this.toPosix(r);let e="";if(r.startsWith("/")?e="/":e=this.getProtocol(r),this.isUrl(r)){const t=r.indexOf("/",e.length);t!==-1?e=r.slice(0,t):e=r,e.endsWith("/")||(e+="/")}return e},basename(r,e){Ft(r),e&&Ft(e),r=di(this.toPosix(r));let t=0,i=-1,s=!0,n;if(e!==void 0&&e.length>0&&e.length<=r.length){if(e.length===r.length&&e===r)return"";let o=e.length-1,a=-1;for(n=r.length-1;n>=0;--n){const h=r.charCodeAt(n);if(h===47){if(!s){t=n+1;break}}else a===-1&&(s=!1,a=n+1),o>=0&&(h===e.charCodeAt(o)?--o===-1&&(i=n):(o=-1,i=a))}return t===i?i=a:i===-1&&(i=r.length),r.slice(t,i)}for(n=r.length-1;n>=0;--n)if(r.charCodeAt(n)===47){if(!s){t=n+1;break}}else i===-1&&(s=!1,i=n+1);return i===-1?"":r.slice(t,i)},extname(r){Ft(r),r=di(this.toPosix(r));let e=-1,t=0,i=-1,s=!0,n=0;for(let o=r.length-1;o>=0;--o){const a=r.charCodeAt(o);if(a===47){if(!s){t=o+1;break}continue}i===-1&&(s=!1,i=o+1),a===46?e===-1?e=o:n!==1&&(n=1):e!==-1&&(n=-1)}return e===-1||i===-1||n===0||n===1&&e===i-1&&e===t+1?"":r.slice(e,i)},parse(r){Ft(r);const e={root:"",dir:"",base:"",ext:"",name:""};if(r.length===0)return e;r=di(this.toPosix(r));let t=r.charCodeAt(0);const i=this.isAbsolute(r);let s;e.root=this.rootname(r),i||this.hasProtocol(r)?s=1:s=0;let n=-1,o=0,a=-1,h=!0,l=r.length-1,c=0;for(;l>=s;--l){if(t=r.charCodeAt(l),t===47){if(!h){o=l+1;break}continue}a===-1&&(h=!1,a=l+1),t===46?n===-1?n=l:c!==1&&(c=1):n!==-1&&(c=-1)}return n===-1||a===-1||c===0||c===1&&n===a-1&&n===o+1?a!==-1&&(o===0&&i?e.base=e.name=r.slice(1,a):e.base=e.name=r.slice(o,a)):(o===0&&i?(e.name=r.slice(1,n),e.base=r.slice(1,a)):(e.name=r.slice(o,n),e.base=r.slice(o,a)),e.ext=r.slice(n,a)),e.dir=this.dirname(r),e},sep:"/",delimiter:":",joinExtensions:[".html"]};function Bh(r,e,t,i,s){const n=e[t];for(let o=0;o<n.length;o++){const a=n[o];t<e.length-1?Bh(r.replace(i[t],a),e,t+1,i,s):s.push(r.replace(i[t],a))}}function su(r){const e=/\{(.*?)\}/g,t=r.match(e),i=[];if(t){const s=[];t.forEach(n=>{const o=n.substring(1,n.length-1).split(",");s.push(o)}),Bh(r,s,0,t,i)}else i.push(r);return i}const ms=r=>!Array.isArray(r);class hi{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(e,t)=>`${e}${this._bundleIdConnector}${t}`,extractAssetIdFromBundle:(e,t)=>t.replace(`${e}${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(e){if(this._bundleIdConnector=e.connector??this._bundleIdConnector,this._createBundleAssetId=e.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=e.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...e){e.forEach(t=>{this._preferredOrder.push(t),t.priority||(t.priority=Object.keys(t.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}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(e){if(typeof e=="string")this._defaultSearchParams=e;else{const t=e;this._defaultSearchParams=Object.keys(t).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(t[i])}`).join("&")}}getAlias(e){const{alias:t,src:i}=e;return zt(t||i,n=>typeof n=="string"?n:Array.isArray(n)?n.map(o=>(o==null?void 0:o.src)??o):n!=null&&n.src?n.src:n,!0)}addManifest(e){this._manifest&&nt("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=e,e.bundles.forEach(t=>{this.addBundle(t.name,t.assets)})}addBundle(e,t){const i=[];let s=t;Array.isArray(t)||(s=Object.entries(t).map(([n,o])=>typeof o=="string"||Array.isArray(o)?{alias:n,src:o}:{alias:n,...o})),s.forEach(n=>{const o=n.src,a=n.alias;let h;if(typeof a=="string"){const l=this._createBundleAssetId(e,a);i.push(l),h=[a,l]}else{const l=a.map(c=>this._createBundleAssetId(e,c));i.push(...l),h=[...a,...l]}this.add({...n,alias:h,src:o})}),this._bundles[e]=i}add(e){const t=[];Array.isArray(e)?t.push(...e):t.push(e);let i;i=n=>{this.hasKey(n)&&nt(`[Resolver] already has key: ${n} overwriting`)},zt(t).forEach(n=>{const{src:o}=n;let{data:a,format:h,loadParser:l,parser:c}=n;const d=zt(o).map(y=>typeof y=="string"?su(y):Array.isArray(y)?y:[y]),u=this.getAlias(n);Array.isArray(u)?u.forEach(i):i(u);const p=[],f=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=f(m):(a=m.data??a,h=m.format??h,(m.loadParser||m.parser)&&(l=m.loadParser??l,c=m.parser??c),x={...f(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:n.progressSize}),p.push(x)})}),u.forEach(y=>{this._assetMap[y]=p})})}resolveBundle(e){const t=ms(e);e=zt(e);const i={};return e.forEach(s=>{const n=this._bundles[s];if(n){const o=this.resolve(n),a={};for(const h in o){const l=o[h];a[this._extractAssetIdFromBundle(s,h)]=l}i[s]=a}}),t?i[e[0]]:i}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const i={};for(const s in t)i[s]=t[s].src;return i}return t.src}resolve(e){const t=ms(e);e=zt(e);const i={};return e.forEach(s=>{if(!this._resolverHash[s])if(this._assetMap[s]){let n=this._assetMap[s];const o=this._getPreferredOrder(n);o==null||o.priority.forEach(a=>{o.params[a].forEach(h=>{const l=n.filter(c=>c[a]?c[a]===h:!1);l.length&&(n=l)})}),this._resolverHash[s]=n[0]}else this._resolverHash[s]=this._buildResolvedAsset({alias:[s],src:s},{});i[s]=this._resolverHash[s]}),t?i[e[0]]:i}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const i=e[t],s=this._preferredOrder.find(n=>n.params.format.includes(i.format));if(s)return s}return this._preferredOrder[0]}_appendDefaultSearchParams(e){if(!this._defaultSearchParams)return e;const t=/\?/.test(e)?"&":"?";return`${e}${t}${this._defaultSearchParams}`}_buildResolvedAsset(e,t){const{aliases:i,data:s,loadParser:n,parser:o,format:a,progressSize:h}=t;return(this._basePath||this._rootPath)&&(e.src=Mt.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=i??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...s||{},...e.data},e.loadParser=n??e.loadParser,e.parser=o??e.parser,e.format=a??e.format??nu(e.src),h!==void 0&&(e.progressSize=h),e}}hi.RETINA_PREFIX=/@([0-9\.]+)x/;function nu(r){return r.split(".").pop().split("?").shift().split("#").shift()}const Ln=(r,e)=>{const t=e.split("?")[1];return t&&(r+=`?${t}`),r},Dh=class wi{constructor(e,t){this.linkedSheets=[];let i=e;(e==null?void 0:e.source)instanceof Dt&&(i={texture:e,data:t});const{texture:s,data:n,cachePrefix:o=""}=i;this.cachePrefix=o,this._texture=s instanceof G?s:null,this.textureSource=s.source,this.textures={},this.animations={},this.data=n;const a=parseFloat(n.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(e=>{this._callback=e,this._batchIndex=0,this._frameKeys.length<=wi.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(e,t=!1){let i=e;const s=t?1/0:wi.BATCH_SIZE;for(;i-e<s&&i<this._frameKeys.length;){const n=this._frameKeys[i],o=this._frames[n],a=o.frame;if(a){let h=null,l=null;const c=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,d=new et(0,0,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution);o.rotated?h=new et(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 et(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 et(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[n]=new G({source:this.textureSource,frame:h,orig:d,trim:l,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:n.toString()})}i++}}_processAnimations(){const e=this.data.animations||{};for(const t in e){this.animations[t]=[];for(let i=0;i<e[t].length;i++){const s=e[t][i];this.animations[t].push(this.textures[s])}}}_parseComplete(){const e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*wi.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*wi.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(e=!1){var t;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,e&&((t=this._texture)==null||t.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};Dh.BATCH_SIZE=1e3;let On=Dh;const ru=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function Fh(r,e,t){const i={};if(r.forEach(s=>{i[s]=e}),Object.keys(e.textures).forEach(s=>{i[`${e.cachePrefix}${s}`]=e.textures[s]}),!t){const s=Mt.dirname(r[0]);e.linkedSheets.forEach((n,o)=>{const a=Fh([`${s}/${e.data.meta.related_multi_packs[o]}`],n,!0);Object.assign(i,a)})}return i}const ou={extension:I.Asset,cache:{test:r=>r instanceof On,getCacheableAssets:(r,e)=>Fh(r,e,!1)},resolver:{extension:{type:I.ResolveParser,name:"resolveSpritesheet"},test:r=>{const t=r.split("?")[0].split("."),i=t.pop(),s=t.pop();return i==="json"&&ru.includes(s)},parse:r=>{var t;const e=r.split(".");return{resolution:parseFloat(((t=hi.RETINA_PREFIX.exec(r))==null?void 0:t[1])??"1"),format:e[e.length-2],src:r}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:I.LoadParser,priority:ue.Normal,name:"spritesheetLoader"},async testParse(r,e){return Mt.extname(e.src).toLowerCase()===".json"&&!!r.frames},async parse(r,e,t){var d,u;const{texture:i,imageFilename:s,textureOptions:n,cachePrefix:o}=(e==null?void 0:e.data)??{};let a=Mt.dirname(e.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let h;if(i instanceof G)h=i;else{const p=Ln(a+(s??r.meta.image),e.src);h=(await t.load([{src:p,data:n}]))[p]}const l=new On({texture:h.source,data:r,cachePrefix:o});await l.parse();const c=(d=r==null?void 0:r.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=e.data)!=null&&u.ignoreMultiPack||(m=Ln(m,e.src),p.push(t.load({src:m,data:{textureOptions:n,ignoreMultiPack:!0}})))}const f=await Promise.all(p);l.linkedSheets=f,f.forEach(y=>{y.linkedSheets=[l].concat(l.linkedSheets.filter(m=>m!==y))})}return l},async unload(r,e,t){await t.unload(r.textureSource._sourceOrigin),r.destroy(!1)}}};$.add(ou);class au{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),i=this._canvas.width,s=this._canvas.height,n=t.width/i*this._renderer.resolution,o=t.height/s*this._renderer.resolution,a=t.left,h=t.top,l=`translate(${a}px, ${h}px) scale(${n}, ${o})`;l!==this._lastTransform&&(this._domElement.style.transform=l,this._lastTransform=l)},this._domElement=e.domElement,this._renderer=e.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(e=>{for(const t of e){if(t.target!==this._canvas)continue;const i=this.canvas.width,s=this.canvas.height,n=t.contentRect.width/i*this._renderer.resolution,o=t.contentRect.height/s*this._renderer.resolution;(this._lastScaleX!==n||this._lastScaleY!==o)&&(this.updateTranslation(),this._lastScaleX=n,this._lastScaleY=o)}}),this._observer.observe(this._canvas)):this._tickerAttached||yt.shared.add(this.updateTranslation,this,Ie.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&yt.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 mr{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=mr.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new tt,this.page=new tt,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=e}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(e,t,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,i,s,n){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 tn=/iPhone/i,So=/iPod/i,vo=/iPad/i,bo=/\biOS-universal(?:.+)Mac\b/i,en=/\bAndroid(?:.+)Mobile\b/i,wo=/Android/i,ze=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,es=/Silk/i,qt=/Windows Phone/i,Co=/\bWindows(?:.+)ARM\b/i,Ao=/BlackBerry/i,Po=/BB10/i,Mo=/Opera Mini/i,_o=/\b(CriOS|Chrome)(?:.+)Mobile/i,To=/Mobile(?:.+)Firefox\b/i,ko=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function hu(r){return function(e){return e.test(r)}}function Ro(r){var e={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?e.userAgent=r:r&&r.userAgent&&(e={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var t=e.userAgent,i=t.split("[FBAN");typeof i[1]<"u"&&(t=i[0]),i=t.split("Twitter"),typeof i[1]<"u"&&(t=i[0]);var s=hu(t),n={apple:{phone:s(tn)&&!s(qt),ipod:s(So),tablet:!s(tn)&&(s(vo)||ko(e))&&!s(qt),universal:s(bo),device:(s(tn)||s(So)||s(vo)||s(bo)||ko(e))&&!s(qt)},amazon:{phone:s(ze),tablet:!s(ze)&&s(es),device:s(ze)||s(es)},android:{phone:!s(qt)&&s(ze)||!s(qt)&&s(en),tablet:!s(qt)&&!s(ze)&&!s(en)&&(s(es)||s(wo)),device:!s(qt)&&(s(ze)||s(es)||s(en)||s(wo))||s(/\bokhttp\b/i)},windows:{phone:s(qt),tablet:s(Co),device:s(qt)||s(Co)},other:{blackberry:s(Ao),blackberry10:s(Po),opera:s(Mo),firefox:s(To),chrome:s(_o),device:s(Ao)||s(Po)||s(Mo)||s(To)||s(_o)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const lu=Ro.default??Ro,Gn=lu(globalThis.navigator),sn=Object.create(null),Eo=Object.create(null);function yr(r,e){let t=Eo[r];return t===void 0&&(sn[e]===void 0&&(sn[e]=1),Eo[r]=t=sn[e]++),t}let Le;function zh(){return(!Le||Le!=null&&Le.isContextLost())&&(Le=j.get().createCanvas().getContext("webgl",{})),Le}let is;function cu(){if(!is){is="mediump";const r=zh();r&&r.getShaderPrecisionFormat&&(is=r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision?"highp":"mediump")}return is}function du(r,e,t){return e?r:t?(r=r.replace("out vec4 finalColor;",""),`
@@ -20,7 +20,7 @@ Deprecated since v${r}`,n=typeof console.groupCollapsed=="function"&&!He.noColor
20
20
  `}function uu(r,e,t){const i=t?e.maxSupportedFragmentPrecision:e.maxSupportedVertexPrecision;if(r.substring(0,9)!=="precision"){let s=t?e.requestedFragmentPrecision:e.requestedVertexPrecision;return s==="highp"&&i!=="highp"&&(s="mediump"),`precision ${s} float;
21
21
  ${r}`}else if(i!=="highp"&&r.substring(0,15)==="precision highp")return r.replace("precision highp","precision mediump");return r}function pu(r,e){return e?`#version 300 es
22
22
  ${r}`:r}const fu={},gu={};function mu(r,{name:e="pixi-program"},t=!0){e=e.replace(/\s+/g,"-"),e+=t?"-fragment":"-vertex";const i=t?fu:gu;return i[e]?(i[e]++,e+=`-${i[e]}`):i[e]=1,r.indexOf("#define SHADER_NAME")!==-1?r:`${`#define SHADER_NAME ${e}`}
23
- ${r}`}function yu(r,e){return e?r.replace("#version 300 es",""):r}const nn={stripVersion:yu,ensurePrecision:uu,addProgramDefines:du,setProgramName:mu,insertVersion:pu},ui=Object.create(null),Lh=class Wn{constructor(e){e={...Wn.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:cu()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let s=e.fragment,n=e.vertex;Object.keys(nn).forEach(o=>{const a=i[o];s=nn[o](s,a,!0),n=nn[o](n,a,!1)}),this.fragment=s,this.vertex=n,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=yr(`${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,ui[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return ui[t]||(ui[t]=new Wn(e),ui[t]._cacheKey=t),ui[t]}};Lh.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let si=Lh;const Io={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 xu(r){return Io[r]??Io.float32}const Su={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"},Bo=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function Do(r,e){let t;for(;(t=Bo.exec(r))!==null;){const i=Su[t[3]]??"float32";e[t[2]]={location:parseInt(t[1],10),format:i,stride:xu(i).stride,offset:0,instance:!1,start:0}}Bo.lastIndex=0}function vu(r){return r.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function bu({source:r,entryPoint:e}){const t={},i=vu(r),s=i.indexOf(`fn ${e}(`);if(s===-1)return t;const n=i.indexOf("->",s);if(n===-1)return t;const o=i.substring(s,n);if(Do(o,t),Object.keys(t).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&&Do(c[1],t)}}return t}function rn(r){var d,u;const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,i=/@binding\((\d+)\)/,s=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,l=(d=r.match(e))==null?void 0:d.map(p=>({group:parseInt(p.match(t)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(n)[1]}));if(!l)return{groups:[],structs:[]};const c=((u=r.match(o))==null?void 0:u.map(p=>{const f=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:f,members:y}:null}).filter(({name:p})=>l.some(f=>f.type===p||f.type.includes(`<${p}>`))))??[];return{groups:l,structs:c}}var Ae=(r=>(r[r.VERTEX=1]="VERTEX",r[r.FRAGMENT=2]="FRAGMENT",r[r.COMPUTE=4]="COMPUTE",r))(Ae||{});function wu({groups:r}){const e=[];for(let t=0;t<r.length;t++){const i=r[t];e[i.group]||(e[i.group]=[]),i.isUniform?e[i.group].push({binding:i.binding,visibility:Ae.VERTEX|Ae.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return e}function Cu({groups:r}){const e=[];for(let t=0;t<r.length;t++){const i=r[t];e[i.group]||(e[i.group]={}),e[i.group][i.name]=i.binding}return e}function Au(r,e){const t=new Set,i=new Set,s=[...r.structs,...e.structs].filter(o=>t.has(o.name)?!1:(t.add(o.name),!0)),n=[...r.groups,...e.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:n}}const pi=Object.create(null);class le{constructor(e){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:i,layout:s,gpuLayout:n,name:o}=e;if(this.name=o,this.fragment=t,this.vertex=i,t.source===i.source){const l=rn(t.source);this.structsAndGroups=l}else{const l=rn(i.source),c=rn(t.source);this.structsAndGroups=Au(l,c)}this.layout=s??Cu(this.structsAndGroups),this.gpuLayout=n??wu(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:e,fragment:t}=this,i=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=yr(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=bu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,pi[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return pi[t]||(pi[t]=new le(e),pi[t]._cacheKey=t),pi[t]}}const Oh=["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>"],Pu=Oh.reduce((r,e)=>(r[e]=!0,r),{});function Mu(r,e){switch(r){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*e);case"vec3<f32>":return new Float32Array(3*e);case"vec4<f32>":return new Float32Array(4*e);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 Gh=class Wh{constructor(e,t){this._touched=0,this.uid=dt("uniform"),this._resourceType="uniformGroup",this._resourceId=dt("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...Wh.defaultOptions,...t},this.uniformStructures=e;const i={};for(const s in e){const n=e[s];if(n.name=s,n.size=n.size??1,!Pu[n.type]){const o=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,h]=o;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${a}', size: ${h} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${Oh.join(", ")}`)}n.value??(n.value=Mu(n.type,n.size)),i[s]=n.value}this.uniforms=i,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=yr(Object.keys(i).map(s=>`${s}-${e[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};Gh.defaultOptions={ubo:!1,isStatic:!1};let ni=Gh;class _i{constructor(e){this.resources=Object.create(null),this._dirty=!0;let t=0;for(const i in e){const s=e[i];this.setResource(s,t++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const e=[];let t=0;for(const i in this.resources)e[t++]=this.resources[i]._resourceId;this._key=e.join("|")}setResource(e,t){var s,n;const i=this.resources[t];e!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(n=e.on)==null||n.call(e,"change",this.onResourceChange,this),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e,t){const i=this.resources;for(const s in i)i[s]._gcLastUsed=e,i[s]._touched=t}destroy(){var t;const e=this.resources;for(const i in e){const s=e[i];(t=s==null?void 0:s.off)==null||t.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const i in t)t[i]===e&&(t[i]=null)}else this._updateKey()}}var Fi=(r=>(r[r.WEBGL=1]="WEBGL",r[r.WEBGPU=2]="WEBGPU",r[r.CANVAS=4]="CANVAS",r[r.BOTH=3]="BOTH",r))(Fi||{});class Be extends Yt{constructor(e){super(),this.uid=dt("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:i,groups:s,resources:n,compatibleRenderers:o,groupMap:a}=e;this.gpuProgram=t,this.glProgram=i,o===void 0&&(o=0,t&&(o|=Fi.WEBGPU),i&&(o|=Fi.WEBGL)),this.compatibleRenderers=o;const h={};if(!n&&!s&&(n={}),n&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!t&&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(t&&s&&!a){const l=t.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(n){s={},a={},t&&t.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 n)h[c]||(s[99]||(s[99]=new _i,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 n){const d=c;let u=n[c];!u.source&&!u._resourceType&&(u=new ni(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new _i,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(e,t,i){var s,n;(s=this._uniformBindMap)[t]||(s[t]={}),(n=this._uniformBindMap[t])[i]||(n[i]=e),this.groups[t]||(this.groups[t]=new _i,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const i={};for(const s in t){const n=t[s];Object.defineProperty(i,n.name,{get(){return e[n.group].getResource(n.binding)},set(o){e[n.group].setResource(o,n.binding)}})}return i}destroy(e=!1){var t,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),e&&((t=this.gpuProgram)==null||t.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(e){const{gpu:t,gl:i,...s}=e;let n,o;return t&&(n=le.from(t)),i&&(o=si.from(i)),new Be({gpuProgram:n,glProgram:o,...s})}}const _u={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},on=0,an=1,hn=2,ln=3,cn=4,dn=5,Un=class Uh{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<on)}set blend(e){!!(this.data&1<<on)!==e&&(this.data^=1<<on)}get offsets(){return!!(this.data&1<<an)}set offsets(e){!!(this.data&1<<an)!==e&&(this.data^=1<<an)}set cullMode(e){if(e==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=e==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<hn)}set culling(e){!!(this.data&1<<hn)!==e&&(this.data^=1<<hn)}get depthTest(){return!!(this.data&1<<ln)}set depthTest(e){!!(this.data&1<<ln)!==e&&(this.data^=1<<ln)}get depthMask(){return!!(this.data&1<<dn)}set depthMask(e){!!(this.data&1<<dn)!==e&&(this.data^=1<<dn)}get clockwiseFrontFace(){return!!(this.data&1<<cn)}set clockwiseFrontFace(e){!!(this.data&1<<cn)!==e&&(this.data^=1<<cn)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=_u[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const e=new Uh;return e.depthTest=!1,e.blend=!0,e}};Un.default2d=Un.for2d();let Vi=Un;const Hh=class Hn extends Be{constructor(e){e={...Hn.defaultOptions,...e},super(e),this.enabled=!0,this._state=Vi.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,i,s){e.applyFilter(this,t,i,s)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:i,...s}=e;let n,o;return t&&(n=le.from(t)),i&&(o=si.from(i)),new Hn({gpuProgram:n,glProgram:o,...s})}};Hh.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Tu=Hh;const Vn=[];$.handleByNamedList(I.Environment,Vn);async function ku(r){if(!r)for(let e=0;e<Vn.length;e++){const t=Vn[e];if(t.value.test()){await t.value.load();return}}}let fi;function Ru(){if(typeof fi=="boolean")return fi;try{fi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{fi=!1}return fi}function Fo(r,e,t=2){const i=e&&e.length,s=i?e[0]*t:r.length;let n=Vh(r,0,s,t,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=Fu(r,e,n,t)),r.length>80*t){a=r[0],h=r[1];let c=a,d=h;for(let u=t;u<s;u+=t){const p=r[u],f=r[u+1];p<a&&(a=p),f<h&&(h=f),p>c&&(c=p),f>d&&(d=f)}l=Math.max(c-a,d-h),l=l!==0?32767/l:0}return zi(n,o,t,a,h,l,0),o}function Vh(r,e,t,i,s){let n;if(s===Yu(r,e,t,i)>0)for(let o=e;o<t;o+=i)n=zo(o/i|0,r[o],r[o+1],n);else for(let o=t-i;o>=e;o-=i)n=zo(o/i|0,r[o],r[o+1],n);return n&&ri(n,n.next)&&(Oi(n),n=n.next),n}function De(r,e){if(!r)return r;e||(e=r);let t=r,i;do if(i=!1,!t.steiner&&(ri(t,t.next)||at(t.prev,t,t.next)===0)){if(Oi(t),t=e=t.prev,t===t.next)break;i=!0}else t=t.next;while(i||t!==e);return e}function zi(r,e,t,i,s,n,o){if(!r)return;!o&&n&&Wu(r,i,s,n);let a=r;for(;r.prev!==r.next;){const h=r.prev,l=r.next;if(n?Iu(r,i,s,n):Eu(r)){e.push(h.i,r.i,l.i),Oi(r),r=l.next,a=l.next;continue}if(r=l,r===a){o?o===1?(r=Bu(De(r),e),zi(r,e,t,i,s,n,2)):o===2&&Du(r,e,t,i,s,n):zi(De(r),e,t,i,s,n,1);break}}}function Eu(r){const e=r.prev,t=r,i=r.next;if(at(e,t,i)>=0)return!1;const s=e.x,n=t.x,o=i.x,a=e.y,h=t.y,l=i.y,c=Math.min(s,n,o),d=Math.min(a,h,l),u=Math.max(s,n,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=c&&f.x<=u&&f.y>=d&&f.y<=p&&Ci(s,a,n,h,o,l,f.x,f.y)&&at(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Iu(r,e,t,i){const s=r.prev,n=r,o=r.next;if(at(s,n,o)>=0)return!1;const a=s.x,h=n.x,l=o.x,c=s.y,d=n.y,u=o.y,p=Math.min(a,h,l),f=Math.min(c,d,u),y=Math.max(a,h,l),m=Math.max(c,d,u),x=Nn(p,f,e,t,i),S=Nn(y,m,e,t,i);let v=r.prevZ,b=r.nextZ;for(;v&&v.z>=x&&b&&b.z<=S;){if(v.x>=p&&v.x<=y&&v.y>=f&&v.y<=m&&v!==s&&v!==o&&Ci(a,c,h,d,l,u,v.x,v.y)&&at(v.prev,v,v.next)>=0||(v=v.prevZ,b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==s&&b!==o&&Ci(a,c,h,d,l,u,b.x,b.y)&&at(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>=f&&v.y<=m&&v!==s&&v!==o&&Ci(a,c,h,d,l,u,v.x,v.y)&&at(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>=f&&b.y<=m&&b!==s&&b!==o&&Ci(a,c,h,d,l,u,b.x,b.y)&&at(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Bu(r,e){let t=r;do{const i=t.prev,s=t.next.next;!ri(i,s)&&jh(i,t,t.next,s)&&Li(i,s)&&Li(s,i)&&(e.push(i.i,t.i,s.i),Oi(t),Oi(t.next),t=r=s),t=t.next}while(t!==r);return De(t)}function Du(r,e,t,i,s,n){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Vu(o,a)){let h=Yh(o,a);o=De(o,o.next),h=De(h,h.next),zi(o,e,t,i,s,n,0),zi(h,e,t,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function Fu(r,e,t,i){const s=[];for(let n=0,o=e.length;n<o;n++){const a=e[n]*i,h=n<o-1?e[n+1]*i:r.length,l=Vh(r,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(Hu(l))}s.sort(zu);for(let n=0;n<s.length;n++)t=Lu(s[n],t);return t}function zu(r,e){let t=r.x-e.x;if(t===0&&(t=r.y-e.y,t===0)){const i=(r.next.y-r.y)/(r.next.x-r.x),s=(e.next.y-e.y)/(e.next.x-e.x);t=i-s}return t}function Lu(r,e){const t=Ou(r,e);if(!t)return e;const i=Yh(t,r);return De(i,i.next),De(t,t.next)}function Ou(r,e){let t=e;const i=r.x,s=r.y;let n=-1/0,o;if(ri(r,t))return t;do{if(ri(r,t.next))return t.next;if(s<=t.y&&s>=t.next.y&&t.next.y!==t.y){const d=t.x+(s-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(d<=i&&d>n&&(n=d,o=t.x<t.next.x?t:t.next,d===i))return o}t=t.next}while(t!==e);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;t=o;do{if(i>=t.x&&t.x>=h&&i!==t.x&&Nh(s<l?i:n,s,h,l,s<l?n:i,s,t.x,t.y)){const d=Math.abs(s-t.y)/(i-t.x);Li(t,r)&&(d<c||d===c&&(t.x>o.x||t.x===o.x&&Gu(o,t)))&&(o=t,c=d)}t=t.next}while(t!==a);return o}function Gu(r,e){return at(r.prev,r,e.prev)<0&&at(e.next,r,r.next)<0}function Wu(r,e,t,i){let s=r;do s.z===0&&(s.z=Nn(s.x,s.y,e,t,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,Uu(s)}function Uu(r){let e,t=1;do{let i=r,s;r=null;let n=null;for(e=0;i;){e++;let o=i,a=0;for(let l=0;l<t&&(a++,o=o.nextZ,!!o);l++);let h=t;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--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;i=o}n.nextZ=null,t*=2}while(e>1);return r}function Nn(r,e,t,i,s){return r=(r-t)*s|0,e=(e-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r|e<<1}function Hu(r){let e=r,t=r;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==r);return t}function Nh(r,e,t,i,s,n,o,a){return(s-o)*(e-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(t-o)*(e-a)&&(t-o)*(n-a)>=(s-o)*(i-a)}function Ci(r,e,t,i,s,n,o,a){return!(r===o&&e===a)&&Nh(r,e,t,i,s,n,o,a)}function Vu(r,e){return r.next.i!==e.i&&r.prev.i!==e.i&&!Nu(r,e)&&(Li(r,e)&&Li(e,r)&&ju(r,e)&&(at(r.prev,r,e.prev)||at(r,e.prev,e))||ri(r,e)&&at(r.prev,r,r.next)>0&&at(e.prev,e,e.next)>0)}function at(r,e,t){return(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y)}function ri(r,e){return r.x===e.x&&r.y===e.y}function jh(r,e,t,i){const s=ns(at(r,e,t)),n=ns(at(r,e,i)),o=ns(at(t,i,r)),a=ns(at(t,i,e));return!!(s!==n&&o!==a||s===0&&ss(r,t,e)||n===0&&ss(r,i,e)||o===0&&ss(t,r,i)||a===0&&ss(t,e,i))}function ss(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function ns(r){return r>0?1:r<0?-1:0}function Nu(r,e){let t=r;do{if(t.i!==r.i&&t.next.i!==r.i&&t.i!==e.i&&t.next.i!==e.i&&jh(t,t.next,r,e))return!0;t=t.next}while(t!==r);return!1}function Li(r,e){return at(r.prev,r,r.next)<0?at(r,e,r.next)>=0&&at(r,r.prev,e)>=0:at(r,e,r.prev)<0||at(r,r.next,e)<0}function ju(r,e){let t=r,i=!1;const s=(r.x+e.x)/2,n=(r.y+e.y)/2;do t.y>n!=t.next.y>n&&t.next.y!==t.y&&s<(t.next.x-t.x)*(n-t.y)/(t.next.y-t.y)+t.x&&(i=!i),t=t.next;while(t!==r);return i}function Yh(r,e){const t=jn(r.i,r.x,r.y),i=jn(e.i,e.x,e.y),s=r.next,n=e.prev;return r.next=e,e.prev=r,t.next=s,s.prev=t,i.next=t,t.prev=i,n.next=i,i.prev=n,i}function zo(r,e,t,i){const s=jn(r,e,t);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Oi(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function jn(r,e,t){return{i:r,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Yu(r,e,t,i){let s=0;for(let n=e,o=t-i;n<t;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}const Xu=Fo.default||Fo;var Xh=(r=>(r[r.NONE=0]="NONE",r[r.COLOR=16384]="COLOR",r[r.STENCIL=1024]="STENCIL",r[r.DEPTH=256]="DEPTH",r[r.COLOR_DEPTH=16640]="COLOR_DEPTH",r[r.COLOR_STENCIL=17408]="COLOR_STENCIL",r[r.DEPTH_STENCIL=1280]="DEPTH_STENCIL",r[r.ALL=17664]="ALL",r))(Xh||{});class Zu{constructor(e){this.items=[],this._name=e}emit(e,t,i,s,n,o,a,h){const{name:l,items:c}=this;for(let d=0,u=c.length;d<u;d++)c[d][l](e,t,i,s,n,o,a,h);return this}add(e){return e[this._name]&&(this.remove(e),this.items.push(e)),this}remove(e){const t=this.items.indexOf(e);return t!==-1&&this.items.splice(t,1),this}contains(e){return this.items.indexOf(e)!==-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 qu=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Zh=class qh extends Yt{constructor(e){super(),this.tick=0,this.uid=dt("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=e.type,this.name=e.name,this.config=e;const t=[...qu,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await ku(t),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)e={...this._systemsHash[i].constructor.defaultOptions,...e};e={...qh.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(e);this._initOptions=e}render(e,t){this.tick++;let i=e;if(i instanceof L&&(i={container:i},t&&(V(J,"passing a second argument is deprecated, please use render options instead"),i.target=t.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:rt.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(e,t,i){const s=this.view.resolution;this.view.resize(e,t,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(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=Xh.ALL);const{clear:i,clearColor:s,target:n,mipLevel:o,layer:a}=e;rt.shared.setValue(s??this.background.colorRgba),t.renderTarget.clear(n,i,rt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(e){this.view.resolution=e,this.runners.resolutionChange.emit(e)}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(...e){e.forEach(t=>{this.runners[t]=new Zu(t)})}_addSystems(e){let t;for(t in e){const i=e[t];this._addSystem(i.value,i.name)}}_addSystem(e,t){const i=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=i,this._systemsHash[t]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(e,t){const i=t.reduce((s,n)=>(s[n.name]=n.value,s),{});e.forEach(s=>{const n=s.value,o=s.name,a=i[o];this.renderPipes[o]=new n(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&Hi.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Ru())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()}};Zh.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let Kh=Zh,rs;function Ku(r){return rs!==void 0||(rs=(()=>{var t;const e={stencil:!0,failIfMajorPerformanceCaveat:r??Kh.defaultOptions.failIfMajorPerformanceCaveat};try{if(!j.get().getWebGLRenderingContext())return!1;let s=j.get().createCanvas().getContext("webgl",e);const n=!!((t=s==null?void 0:s.getContextAttributes())!=null&&t.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,n}catch{return!1}})()),rs}let os;async function $u(r={}){return os!==void 0||(os=await(async()=>{const e=j.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(r)).requestDevice(),!0}catch{return!1}})()),os}const Lo=["webgl","webgpu","canvas"];async function Qu(r){let e=[];r.preference?(e.push(r.preference),Lo.forEach(n=>{n!==r.preference&&e.push(n)})):e=Lo.slice();let t,i={};for(let n=0;n<e.length;n++){const o=e[n];if(o==="webgpu"&&await $u()){const{WebGPURenderer:a}=await _e(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.KCAyMTek.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));t=a,i={...r,...r.webgpu};break}else if(o==="webgl"&&Ku(r.failIfMajorPerformanceCaveat??Kh.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await _e(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.uIm0oBU6.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));t=a,i={...r,...r.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await _e(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.AFx6MHtI.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));t=a,i={...r,...r.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!t)throw new Error("No available renderer for the current environment");const s=new t;return await s.init(i),s}const $h="8.16.0";class Qh{static init(){var e;(e=globalThis.__PIXI_APP_INIT__)==null||e.call(globalThis,this,$h)}static destroy(){}}Qh.extension=I.Application;class Ju{constructor(e){this._renderer=e}init(){var e;(e=globalThis.__PIXI_RENDERER_INIT__)==null||e.call(globalThis,this._renderer,$h)}destroy(){this._renderer=null}}Ju.extension={type:[I.WebGLSystem,I.WebGPUSystem],name:"initHook",priority:-10};class Jh{static init(e){Object.defineProperty(this,"resizeTo",{configurable:!0,set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(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 t,i;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:n}=this._resizeTo;t=s,i=n}this.renderer.resize(t,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Jh.extension=I.Application;class tl{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{configurable:!0,set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,Ie.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?yt.shared:new yt,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}tl.extension=I.Application;$.add(Jh);$.add(tl);const el=class Yn{constructor(...e){this.stage=new L,e[0]!==void 0&&V(J,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new L),this.renderer=await Qu(e),Yn._plugins.forEach(t=>{t.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(J,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,t=!1){const i=Yn._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};el._plugins=[];let il=el;$.handleByList(I.Application,il._plugins);$.add(Qh);const un={test(r){return typeof r=="string"&&r.startsWith("info face=")},parse(r){const e=r.match(/^[a-z]+\s+.+$/gm),t={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in e){const u=e[d].match(/^[a-z]+/gm)[0],p=e[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),f={};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;f[x]=b}t[u].push(f)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=t.info,[n]=t.common,[o]=t.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(n.lineHeight,10);const a=t.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(n.base,10);const l=t.char;for(let d=0;d<l.length;d++){const u=l[d],p=parseInt(u.id,10);let f=u.letter??u.char??String.fromCharCode(p);f==="space"&&(f=" "),h[p]=f,i.chars[f]={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=t.kerning||[];for(let d=0;d<c.length;d++){const u=parseInt(c[d].first,10),p=parseInt(c[d].second,10),f=parseInt(c[d].amount,10);i.chars[h[p]].kerning[h[u]]=f}return i}},Oo={test(r){const e=r;return typeof e!="string"&&"getElementsByTagName"in e&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(r){const e={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},t=r.getElementsByTagName("info")[0],i=r.getElementsByTagName("common")[0],s=r.getElementsByTagName("distanceField")[0];s&&(e.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const n=r.getElementsByTagName("page"),o=r.getElementsByTagName("char"),a=r.getElementsByTagName("kerning");e.fontSize=parseInt(t.getAttribute("size"),10),e.fontFamily=t.getAttribute("face"),e.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<n.length;l++)e.pages.push({id:parseInt(n[l].getAttribute("id"),10)||0,file:n[l].getAttribute("file")});const h={};e.baseLineOffset=e.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,e.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);e.chars[h[d]].kerning[h[c]]=u}return e}},Go={test(r){return typeof r=="string"&&r.match(/<font(\s|>)/)?Oo.test(j.get().parseXML(r)):!1},parse(r){return Oo.parse(j.get().parseXML(r))}},tp=[".xml",".fnt"],ep={extension:{type:I.CacheParser,name:"cacheBitmapFont"},test:r=>!!(r!=null&&r.pages)&&!!(r!=null&&r.chars)&&typeof(r==null?void 0:r.fontFamily)=="string",getCacheableAssets(r,e){const t={};return r.forEach(i=>{t[i]=e,t[`${i}-bitmap`]=e}),t[`${e.fontFamily}-bitmap`]=e,t}},ip={extension:{type:I.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(r){return tp.includes(Mt.extname(r).toLowerCase())},async testParse(r){return un.test(r)||Go.test(r)},async parse(r,e,t){const i=un.test(r)?un.parse(r):Go.parse(r),{src:s}=e,{pages:n}=i,o=[],a=i.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let u=0;u<n.length;++u){const p=n[u].file;let f=Mt.join(Mt.dirname(s),p);f=Ln(f,s),o.push({src:f,data:a})}const[h,{BitmapFont:l}]=await Promise.all([t.load(o),_e(()=>import("./BitmapFont.CcysO3pT.js"),__vite__mapDeps([10,2,3,4]))]),c=o.map(u=>h[u.src]);return new l({data:i,textures:c},s)},async load(r,e){return await(await j.get().fetch(r)).text()},async unload(r,e,t){await Promise.all(r.pages.map(i=>t.unload(i.texture.source._sourceOrigin))),r.destroy()}};class sp{constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),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 e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<t;i++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const np={extension:{type:I.CacheParser,name:"cacheTextureArray"},test:r=>Array.isArray(r)&&r.every(e=>e instanceof G),getCacheableAssets:(r,e)=>{const t={};return r.forEach(i=>{e.forEach((s,n)=>{t[i+(n===0?"":n+1)]=s})}),t}};async function sl(r){if("Image"in globalThis)return new Promise(e=>{const t=new Image;t.onload=()=>{e(!0)},t.onerror=()=>{e(!1)},t.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const e=await(await fetch(r)).blob();await createImageBitmap(e)}catch{return!1}return!0}return!1}const rp={extension:{type:I.DetectionParser,priority:1},test:async()=>sl("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(e=>e!=="avif")},Wo=["png","jpg","jpeg"],op={extension:{type:I.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Wo],remove:async r=>r.filter(e=>!Wo.includes(e))},ap="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function ks(r){return ap?!1:document.createElement("video").canPlayType(r)!==""}const hp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(e=>e!=="mp4"&&e!=="m4v")},lp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(e=>e!=="ogv")},cp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(e=>e!=="webm")},dp={extension:{type:I.DetectionParser,priority:0},test:async()=>sl("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(e=>e!=="webp")},nl=class us{constructor(){this.loadOptions={...us.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(e,t,i)=>(this._parsersValidated=!1,e[t]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(e,t){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,n=null;if((t.parser||t.loadParser)&&(n=this._parserHash[t.parser||t.loadParser],t.loadParser&&nt(`[Assets] "loadParser" is deprecated, use "parser" instead for ${e}`),n||nt(`[Assets] specified load parser "${t.parser||t.loadParser}" not found while loading ${e}`)),!n){for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.load&&((o=l.test)!=null&&o.call(l,e,t,this))){n=l;break}}if(!n)return nt(`[Assets] ${e} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await n.load(e,t,this),i.parser=n;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,t,this))&&(s=await l.parse(s,t,this)||s,i.parser=l)}return s})(),i}async load(e,t){this._parsersValidated||this._validateParsers();const i=typeof t=="function"?{...us.defaultOptions,...this.loadOptions,onProgress:t}:{...us.defaultOptions,...this.loadOptions,...t||{}},{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=ms(e),u=zt(e,y=>({alias:[y],src:y,data:{}})),p=u.reduce((y,m)=>y+(m.progressSize||1),0),f=u.map(async y=>{const m=Mt.toAbsolute(y.src);c[y.src]||(await this._loadAssetWithRetry(m,y,{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h},c),l+=y.progressSize||1,s&&s(l/p))});return await Promise.all(f),d?c[u[0].src]:c}async unload(e){const i=zt(e,s=>({alias:[s],src:s})).map(async s=>{var a,h;const n=Mt.toAbsolute(s.src),o=this.promiseCache[n];if(o){const l=await o.promise;delete this.promiseCache[n],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(e=>e.name||e.id).reduce((e,t)=>(!t.name&&!t.id?nt("[Assets] parser should have an id"):(e[t.name]||e[t.id])&&nt(`[Assets] parser id conflict "${t.id}"`),e[t.name]=t,t.id&&(e[t.id]=t),e),{})}async _loadAssetWithRetry(e,t,i,s){let n=0;const{onError:o,strategy:a,retryCount:h,retryDelay:l}=i,c=d=>new Promise(u=>setTimeout(u,d));for(;;)try{this.promiseCache[e]||(this.promiseCache[e]=this._getLoadPromiseAndParser(e,t)),s[t.src]=await this.promiseCache[e].promise;return}catch(d){delete this.promiseCache[e],delete s[t.src],n++;const u=a!=="retry"||n>h;if(a==="retry"&&!u){o&&o(d,t),await c(l);continue}if(a==="skip"){o&&o(d,t);return}o&&o(d,t);const p=new Error(`[Loader.load] Failed to load ${e}.
23
+ ${r}`}function yu(r,e){return e?r.replace("#version 300 es",""):r}const nn={stripVersion:yu,ensurePrecision:uu,addProgramDefines:du,setProgramName:mu,insertVersion:pu},ui=Object.create(null),Lh=class Wn{constructor(e){e={...Wn.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:cu()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let s=e.fragment,n=e.vertex;Object.keys(nn).forEach(o=>{const a=i[o];s=nn[o](s,a,!0),n=nn[o](n,a,!1)}),this.fragment=s,this.vertex=n,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=yr(`${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,ui[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return ui[t]||(ui[t]=new Wn(e),ui[t]._cacheKey=t),ui[t]}};Lh.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let si=Lh;const Io={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 xu(r){return Io[r]??Io.float32}const Su={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"},Bo=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function Do(r,e){let t;for(;(t=Bo.exec(r))!==null;){const i=Su[t[3]]??"float32";e[t[2]]={location:parseInt(t[1],10),format:i,stride:xu(i).stride,offset:0,instance:!1,start:0}}Bo.lastIndex=0}function vu(r){return r.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function bu({source:r,entryPoint:e}){const t={},i=vu(r),s=i.indexOf(`fn ${e}(`);if(s===-1)return t;const n=i.indexOf("->",s);if(n===-1)return t;const o=i.substring(s,n);if(Do(o,t),Object.keys(t).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&&Do(c[1],t)}}return t}function rn(r){var d,u;const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,i=/@binding\((\d+)\)/,s=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,h=/struct\s+(\w+)/,l=(d=r.match(e))==null?void 0:d.map(p=>({group:parseInt(p.match(t)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(n)[1]}));if(!l)return{groups:[],structs:[]};const c=((u=r.match(o))==null?void 0:u.map(p=>{const f=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:f,members:y}:null}).filter(({name:p})=>l.some(f=>f.type===p||f.type.includes(`<${p}>`))))??[];return{groups:l,structs:c}}var Ae=(r=>(r[r.VERTEX=1]="VERTEX",r[r.FRAGMENT=2]="FRAGMENT",r[r.COMPUTE=4]="COMPUTE",r))(Ae||{});function wu({groups:r}){const e=[];for(let t=0;t<r.length;t++){const i=r[t];e[i.group]||(e[i.group]=[]),i.isUniform?e[i.group].push({binding:i.binding,visibility:Ae.VERTEX|Ae.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&e[i.group].push({binding:i.binding,visibility:Ae.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return e}function Cu({groups:r}){const e=[];for(let t=0;t<r.length;t++){const i=r[t];e[i.group]||(e[i.group]={}),e[i.group][i.name]=i.binding}return e}function Au(r,e){const t=new Set,i=new Set,s=[...r.structs,...e.structs].filter(o=>t.has(o.name)?!1:(t.add(o.name),!0)),n=[...r.groups,...e.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:n}}const pi=Object.create(null);class le{constructor(e){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:i,layout:s,gpuLayout:n,name:o}=e;if(this.name=o,this.fragment=t,this.vertex=i,t.source===i.source){const l=rn(t.source);this.structsAndGroups=l}else{const l=rn(i.source),c=rn(t.source);this.structsAndGroups=Au(l,c)}this.layout=s??Cu(this.structsAndGroups),this.gpuLayout=n??wu(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:e,fragment:t}=this,i=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=yr(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=bu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,pi[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return pi[t]||(pi[t]=new le(e),pi[t]._cacheKey=t),pi[t]}}const Oh=["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>"],Pu=Oh.reduce((r,e)=>(r[e]=!0,r),{});function Mu(r,e){switch(r){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*e);case"vec3<f32>":return new Float32Array(3*e);case"vec4<f32>":return new Float32Array(4*e);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 Gh=class Wh{constructor(e,t){this._touched=0,this.uid=dt("uniform"),this._resourceType="uniformGroup",this._resourceId=dt("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...Wh.defaultOptions,...t},this.uniformStructures=e;const i={};for(const s in e){const n=e[s];if(n.name=s,n.size=n.size??1,!Pu[n.type]){const o=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,h]=o;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${a}', size: ${h} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${Oh.join(", ")}`)}n.value??(n.value=Mu(n.type,n.size)),i[s]=n.value}this.uniforms=i,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=yr(Object.keys(i).map(s=>`${s}-${e[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};Gh.defaultOptions={ubo:!1,isStatic:!1};let ni=Gh;class _i{constructor(e){this.resources=Object.create(null),this._dirty=!0;let t=0;for(const i in e){const s=e[i];this.setResource(s,t++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const e=[];let t=0;for(const i in this.resources)e[t++]=this.resources[i]._resourceId;this._key=e.join("|")}setResource(e,t){var s,n;const i=this.resources[t];e!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(n=e.on)==null||n.call(e,"change",this.onResourceChange,this),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e,t){const i=this.resources;for(const s in i)i[s]._gcLastUsed=e,i[s]._touched=t}destroy(){var t;const e=this.resources;for(const i in e){const s=e[i];(t=s==null?void 0:s.off)==null||t.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const i in t)t[i]===e&&(t[i]=null)}else this._updateKey()}}var Fi=(r=>(r[r.WEBGL=1]="WEBGL",r[r.WEBGPU=2]="WEBGPU",r[r.CANVAS=4]="CANVAS",r[r.BOTH=3]="BOTH",r))(Fi||{});class Be extends Yt{constructor(e){super(),this.uid=dt("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:i,groups:s,resources:n,compatibleRenderers:o,groupMap:a}=e;this.gpuProgram=t,this.glProgram=i,o===void 0&&(o=0,t&&(o|=Fi.WEBGPU),i&&(o|=Fi.WEBGL)),this.compatibleRenderers=o;const h={};if(!n&&!s&&(n={}),n&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!t&&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(t&&s&&!a){const l=t.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(n){s={},a={},t&&t.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 n)h[c]||(s[99]||(s[99]=new _i,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 n){const d=c;let u=n[c];!u.source&&!u._resourceType&&(u=new ni(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new _i,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(e,t,i){var s,n;(s=this._uniformBindMap)[t]||(s[t]={}),(n=this._uniformBindMap[t])[i]||(n[i]=e),this.groups[t]||(this.groups[t]=new _i,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const i={};for(const s in t){const n=t[s];Object.defineProperty(i,n.name,{get(){return e[n.group].getResource(n.binding)},set(o){e[n.group].setResource(o,n.binding)}})}return i}destroy(e=!1){var t,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),e&&((t=this.gpuProgram)==null||t.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(e){const{gpu:t,gl:i,...s}=e;let n,o;return t&&(n=le.from(t)),i&&(o=si.from(i)),new Be({gpuProgram:n,glProgram:o,...s})}}const _u={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},on=0,an=1,hn=2,ln=3,cn=4,dn=5,Un=class Uh{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<on)}set blend(e){!!(this.data&1<<on)!==e&&(this.data^=1<<on)}get offsets(){return!!(this.data&1<<an)}set offsets(e){!!(this.data&1<<an)!==e&&(this.data^=1<<an)}set cullMode(e){if(e==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=e==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<hn)}set culling(e){!!(this.data&1<<hn)!==e&&(this.data^=1<<hn)}get depthTest(){return!!(this.data&1<<ln)}set depthTest(e){!!(this.data&1<<ln)!==e&&(this.data^=1<<ln)}get depthMask(){return!!(this.data&1<<dn)}set depthMask(e){!!(this.data&1<<dn)!==e&&(this.data^=1<<dn)}get clockwiseFrontFace(){return!!(this.data&1<<cn)}set clockwiseFrontFace(e){!!(this.data&1<<cn)!==e&&(this.data^=1<<cn)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=_u[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const e=new Uh;return e.depthTest=!1,e.blend=!0,e}};Un.default2d=Un.for2d();let Vi=Un;const Hh=class Hn extends Be{constructor(e){e={...Hn.defaultOptions,...e},super(e),this.enabled=!0,this._state=Vi.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,i,s){e.applyFilter(this,t,i,s)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:i,...s}=e;let n,o;return t&&(n=le.from(t)),i&&(o=si.from(i)),new Hn({gpuProgram:n,glProgram:o,...s})}};Hh.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Tu=Hh;const Vn=[];$.handleByNamedList(I.Environment,Vn);async function ku(r){if(!r)for(let e=0;e<Vn.length;e++){const t=Vn[e];if(t.value.test()){await t.value.load();return}}}let fi;function Ru(){if(typeof fi=="boolean")return fi;try{fi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{fi=!1}return fi}function Fo(r,e,t=2){const i=e&&e.length,s=i?e[0]*t:r.length;let n=Vh(r,0,s,t,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=Fu(r,e,n,t)),r.length>80*t){a=r[0],h=r[1];let c=a,d=h;for(let u=t;u<s;u+=t){const p=r[u],f=r[u+1];p<a&&(a=p),f<h&&(h=f),p>c&&(c=p),f>d&&(d=f)}l=Math.max(c-a,d-h),l=l!==0?32767/l:0}return zi(n,o,t,a,h,l,0),o}function Vh(r,e,t,i,s){let n;if(s===Yu(r,e,t,i)>0)for(let o=e;o<t;o+=i)n=zo(o/i|0,r[o],r[o+1],n);else for(let o=t-i;o>=e;o-=i)n=zo(o/i|0,r[o],r[o+1],n);return n&&ri(n,n.next)&&(Oi(n),n=n.next),n}function De(r,e){if(!r)return r;e||(e=r);let t=r,i;do if(i=!1,!t.steiner&&(ri(t,t.next)||at(t.prev,t,t.next)===0)){if(Oi(t),t=e=t.prev,t===t.next)break;i=!0}else t=t.next;while(i||t!==e);return e}function zi(r,e,t,i,s,n,o){if(!r)return;!o&&n&&Wu(r,i,s,n);let a=r;for(;r.prev!==r.next;){const h=r.prev,l=r.next;if(n?Iu(r,i,s,n):Eu(r)){e.push(h.i,r.i,l.i),Oi(r),r=l.next,a=l.next;continue}if(r=l,r===a){o?o===1?(r=Bu(De(r),e),zi(r,e,t,i,s,n,2)):o===2&&Du(r,e,t,i,s,n):zi(De(r),e,t,i,s,n,1);break}}}function Eu(r){const e=r.prev,t=r,i=r.next;if(at(e,t,i)>=0)return!1;const s=e.x,n=t.x,o=i.x,a=e.y,h=t.y,l=i.y,c=Math.min(s,n,o),d=Math.min(a,h,l),u=Math.max(s,n,o),p=Math.max(a,h,l);let f=i.next;for(;f!==e;){if(f.x>=c&&f.x<=u&&f.y>=d&&f.y<=p&&Ci(s,a,n,h,o,l,f.x,f.y)&&at(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Iu(r,e,t,i){const s=r.prev,n=r,o=r.next;if(at(s,n,o)>=0)return!1;const a=s.x,h=n.x,l=o.x,c=s.y,d=n.y,u=o.y,p=Math.min(a,h,l),f=Math.min(c,d,u),y=Math.max(a,h,l),m=Math.max(c,d,u),x=Nn(p,f,e,t,i),S=Nn(y,m,e,t,i);let v=r.prevZ,b=r.nextZ;for(;v&&v.z>=x&&b&&b.z<=S;){if(v.x>=p&&v.x<=y&&v.y>=f&&v.y<=m&&v!==s&&v!==o&&Ci(a,c,h,d,l,u,v.x,v.y)&&at(v.prev,v,v.next)>=0||(v=v.prevZ,b.x>=p&&b.x<=y&&b.y>=f&&b.y<=m&&b!==s&&b!==o&&Ci(a,c,h,d,l,u,b.x,b.y)&&at(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>=f&&v.y<=m&&v!==s&&v!==o&&Ci(a,c,h,d,l,u,v.x,v.y)&&at(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>=f&&b.y<=m&&b!==s&&b!==o&&Ci(a,c,h,d,l,u,b.x,b.y)&&at(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function Bu(r,e){let t=r;do{const i=t.prev,s=t.next.next;!ri(i,s)&&jh(i,t,t.next,s)&&Li(i,s)&&Li(s,i)&&(e.push(i.i,t.i,s.i),Oi(t),Oi(t.next),t=r=s),t=t.next}while(t!==r);return De(t)}function Du(r,e,t,i,s,n){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Vu(o,a)){let h=Yh(o,a);o=De(o,o.next),h=De(h,h.next),zi(o,e,t,i,s,n,0),zi(h,e,t,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function Fu(r,e,t,i){const s=[];for(let n=0,o=e.length;n<o;n++){const a=e[n]*i,h=n<o-1?e[n+1]*i:r.length,l=Vh(r,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(Hu(l))}s.sort(zu);for(let n=0;n<s.length;n++)t=Lu(s[n],t);return t}function zu(r,e){let t=r.x-e.x;if(t===0&&(t=r.y-e.y,t===0)){const i=(r.next.y-r.y)/(r.next.x-r.x),s=(e.next.y-e.y)/(e.next.x-e.x);t=i-s}return t}function Lu(r,e){const t=Ou(r,e);if(!t)return e;const i=Yh(t,r);return De(i,i.next),De(t,t.next)}function Ou(r,e){let t=e;const i=r.x,s=r.y;let n=-1/0,o;if(ri(r,t))return t;do{if(ri(r,t.next))return t.next;if(s<=t.y&&s>=t.next.y&&t.next.y!==t.y){const d=t.x+(s-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(d<=i&&d>n&&(n=d,o=t.x<t.next.x?t:t.next,d===i))return o}t=t.next}while(t!==e);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;t=o;do{if(i>=t.x&&t.x>=h&&i!==t.x&&Nh(s<l?i:n,s,h,l,s<l?n:i,s,t.x,t.y)){const d=Math.abs(s-t.y)/(i-t.x);Li(t,r)&&(d<c||d===c&&(t.x>o.x||t.x===o.x&&Gu(o,t)))&&(o=t,c=d)}t=t.next}while(t!==a);return o}function Gu(r,e){return at(r.prev,r,e.prev)<0&&at(e.next,r,r.next)<0}function Wu(r,e,t,i){let s=r;do s.z===0&&(s.z=Nn(s.x,s.y,e,t,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,Uu(s)}function Uu(r){let e,t=1;do{let i=r,s;r=null;let n=null;for(e=0;i;){e++;let o=i,a=0;for(let l=0;l<t&&(a++,o=o.nextZ,!!o);l++);let h=t;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--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;i=o}n.nextZ=null,t*=2}while(e>1);return r}function Nn(r,e,t,i,s){return r=(r-t)*s|0,e=(e-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,r|e<<1}function Hu(r){let e=r,t=r;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==r);return t}function Nh(r,e,t,i,s,n,o,a){return(s-o)*(e-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(t-o)*(e-a)&&(t-o)*(n-a)>=(s-o)*(i-a)}function Ci(r,e,t,i,s,n,o,a){return!(r===o&&e===a)&&Nh(r,e,t,i,s,n,o,a)}function Vu(r,e){return r.next.i!==e.i&&r.prev.i!==e.i&&!Nu(r,e)&&(Li(r,e)&&Li(e,r)&&ju(r,e)&&(at(r.prev,r,e.prev)||at(r,e.prev,e))||ri(r,e)&&at(r.prev,r,r.next)>0&&at(e.prev,e,e.next)>0)}function at(r,e,t){return(e.y-r.y)*(t.x-e.x)-(e.x-r.x)*(t.y-e.y)}function ri(r,e){return r.x===e.x&&r.y===e.y}function jh(r,e,t,i){const s=ns(at(r,e,t)),n=ns(at(r,e,i)),o=ns(at(t,i,r)),a=ns(at(t,i,e));return!!(s!==n&&o!==a||s===0&&ss(r,t,e)||n===0&&ss(r,i,e)||o===0&&ss(t,r,i)||a===0&&ss(t,e,i))}function ss(r,e,t){return e.x<=Math.max(r.x,t.x)&&e.x>=Math.min(r.x,t.x)&&e.y<=Math.max(r.y,t.y)&&e.y>=Math.min(r.y,t.y)}function ns(r){return r>0?1:r<0?-1:0}function Nu(r,e){let t=r;do{if(t.i!==r.i&&t.next.i!==r.i&&t.i!==e.i&&t.next.i!==e.i&&jh(t,t.next,r,e))return!0;t=t.next}while(t!==r);return!1}function Li(r,e){return at(r.prev,r,r.next)<0?at(r,e,r.next)>=0&&at(r,r.prev,e)>=0:at(r,e,r.prev)<0||at(r,r.next,e)<0}function ju(r,e){let t=r,i=!1;const s=(r.x+e.x)/2,n=(r.y+e.y)/2;do t.y>n!=t.next.y>n&&t.next.y!==t.y&&s<(t.next.x-t.x)*(n-t.y)/(t.next.y-t.y)+t.x&&(i=!i),t=t.next;while(t!==r);return i}function Yh(r,e){const t=jn(r.i,r.x,r.y),i=jn(e.i,e.x,e.y),s=r.next,n=e.prev;return r.next=e,e.prev=r,t.next=s,s.prev=t,i.next=t,t.prev=i,n.next=i,i.prev=n,i}function zo(r,e,t,i){const s=jn(r,e,t);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Oi(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function jn(r,e,t){return{i:r,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Yu(r,e,t,i){let s=0;for(let n=e,o=t-i;n<t;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}const Xu=Fo.default||Fo;var Xh=(r=>(r[r.NONE=0]="NONE",r[r.COLOR=16384]="COLOR",r[r.STENCIL=1024]="STENCIL",r[r.DEPTH=256]="DEPTH",r[r.COLOR_DEPTH=16640]="COLOR_DEPTH",r[r.COLOR_STENCIL=17408]="COLOR_STENCIL",r[r.DEPTH_STENCIL=1280]="DEPTH_STENCIL",r[r.ALL=17664]="ALL",r))(Xh||{});class Zu{constructor(e){this.items=[],this._name=e}emit(e,t,i,s,n,o,a,h){const{name:l,items:c}=this;for(let d=0,u=c.length;d<u;d++)c[d][l](e,t,i,s,n,o,a,h);return this}add(e){return e[this._name]&&(this.remove(e),this.items.push(e)),this}remove(e){const t=this.items.indexOf(e);return t!==-1&&this.items.splice(t,1),this}contains(e){return this.items.indexOf(e)!==-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 qu=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Zh=class qh extends Yt{constructor(e){super(),this.tick=0,this.uid=dt("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=e.type,this.name=e.name,this.config=e;const t=[...qu,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await ku(t),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)e={...this._systemsHash[i].constructor.defaultOptions,...e};e={...qh.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(e);this._initOptions=e}render(e,t){this.tick++;let i=e;if(i instanceof L&&(i={container:i},t&&(V(J,"passing a second argument is deprecated, please use render options instead"),i.target=t.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:rt.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(e,t,i){const s=this.view.resolution;this.view.resize(e,t,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(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=Xh.ALL);const{clear:i,clearColor:s,target:n,mipLevel:o,layer:a}=e;rt.shared.setValue(s??this.background.colorRgba),t.renderTarget.clear(n,i,rt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(e){this.view.resolution=e,this.runners.resolutionChange.emit(e)}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(...e){e.forEach(t=>{this.runners[t]=new Zu(t)})}_addSystems(e){let t;for(t in e){const i=e[t];this._addSystem(i.value,i.name)}}_addSystem(e,t){const i=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=i,this._systemsHash[t]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(e,t){const i=t.reduce((s,n)=>(s[n.name]=n.value,s),{});e.forEach(s=>{const n=s.value,o=s.name,a=i[o];this.renderPipes[o]=new n(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&Hi.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Ru())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()}};Zh.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let Kh=Zh,rs;function Ku(r){return rs!==void 0||(rs=(()=>{var t;const e={stencil:!0,failIfMajorPerformanceCaveat:r??Kh.defaultOptions.failIfMajorPerformanceCaveat};try{if(!j.get().getWebGLRenderingContext())return!1;let s=j.get().createCanvas().getContext("webgl",e);const n=!!((t=s==null?void 0:s.getContextAttributes())!=null&&t.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,n}catch{return!1}})()),rs}let os;async function $u(r={}){return os!==void 0||(os=await(async()=>{const e=j.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(r)).requestDevice(),!0}catch{return!1}})()),os}const Lo=["webgl","webgpu","canvas"];async function Qu(r){let e=[];r.preference?(e.push(r.preference),Lo.forEach(n=>{n!==r.preference&&e.push(n)})):e=Lo.slice();let t,i={};for(let n=0;n<e.length;n++){const o=e[n];if(o==="webgpu"&&await $u()){const{WebGPURenderer:a}=await _e(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.DeayS-qR.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));t=a,i={...r,...r.webgpu};break}else if(o==="webgl"&&Ku(r.failIfMajorPerformanceCaveat??Kh.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await _e(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.DBz0cz4m.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));t=a,i={...r,...r.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await _e(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.D4lorIYk.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));t=a,i={...r,...r.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!t)throw new Error("No available renderer for the current environment");const s=new t;return await s.init(i),s}const $h="8.16.0";class Qh{static init(){var e;(e=globalThis.__PIXI_APP_INIT__)==null||e.call(globalThis,this,$h)}static destroy(){}}Qh.extension=I.Application;class Ju{constructor(e){this._renderer=e}init(){var e;(e=globalThis.__PIXI_RENDERER_INIT__)==null||e.call(globalThis,this._renderer,$h)}destroy(){this._renderer=null}}Ju.extension={type:[I.WebGLSystem,I.WebGPUSystem],name:"initHook",priority:-10};class Jh{static init(e){Object.defineProperty(this,"resizeTo",{configurable:!0,set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(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 t,i;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:n}=this._resizeTo;t=s,i=n}this.renderer.resize(t,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Jh.extension=I.Application;class tl{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{configurable:!0,set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,Ie.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?yt.shared:new yt,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}tl.extension=I.Application;$.add(Jh);$.add(tl);const el=class Yn{constructor(...e){this.stage=new L,e[0]!==void 0&&V(J,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new L),this.renderer=await Qu(e),Yn._plugins.forEach(t=>{t.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(J,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,t=!1){const i=Yn._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};el._plugins=[];let il=el;$.handleByList(I.Application,il._plugins);$.add(Qh);const un={test(r){return typeof r=="string"&&r.startsWith("info face=")},parse(r){const e=r.match(/^[a-z]+\s+.+$/gm),t={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in e){const u=e[d].match(/^[a-z]+/gm)[0],p=e[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),f={};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;f[x]=b}t[u].push(f)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=t.info,[n]=t.common,[o]=t.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(n.lineHeight,10);const a=t.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(n.base,10);const l=t.char;for(let d=0;d<l.length;d++){const u=l[d],p=parseInt(u.id,10);let f=u.letter??u.char??String.fromCharCode(p);f==="space"&&(f=" "),h[p]=f,i.chars[f]={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=t.kerning||[];for(let d=0;d<c.length;d++){const u=parseInt(c[d].first,10),p=parseInt(c[d].second,10),f=parseInt(c[d].amount,10);i.chars[h[p]].kerning[h[u]]=f}return i}},Oo={test(r){const e=r;return typeof e!="string"&&"getElementsByTagName"in e&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(r){const e={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},t=r.getElementsByTagName("info")[0],i=r.getElementsByTagName("common")[0],s=r.getElementsByTagName("distanceField")[0];s&&(e.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const n=r.getElementsByTagName("page"),o=r.getElementsByTagName("char"),a=r.getElementsByTagName("kerning");e.fontSize=parseInt(t.getAttribute("size"),10),e.fontFamily=t.getAttribute("face"),e.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<n.length;l++)e.pages.push({id:parseInt(n[l].getAttribute("id"),10)||0,file:n[l].getAttribute("file")});const h={};e.baseLineOffset=e.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,e.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);e.chars[h[d]].kerning[h[c]]=u}return e}},Go={test(r){return typeof r=="string"&&r.match(/<font(\s|>)/)?Oo.test(j.get().parseXML(r)):!1},parse(r){return Oo.parse(j.get().parseXML(r))}},tp=[".xml",".fnt"],ep={extension:{type:I.CacheParser,name:"cacheBitmapFont"},test:r=>!!(r!=null&&r.pages)&&!!(r!=null&&r.chars)&&typeof(r==null?void 0:r.fontFamily)=="string",getCacheableAssets(r,e){const t={};return r.forEach(i=>{t[i]=e,t[`${i}-bitmap`]=e}),t[`${e.fontFamily}-bitmap`]=e,t}},ip={extension:{type:I.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(r){return tp.includes(Mt.extname(r).toLowerCase())},async testParse(r){return un.test(r)||Go.test(r)},async parse(r,e,t){const i=un.test(r)?un.parse(r):Go.parse(r),{src:s}=e,{pages:n}=i,o=[],a=i.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let u=0;u<n.length;++u){const p=n[u].file;let f=Mt.join(Mt.dirname(s),p);f=Ln(f,s),o.push({src:f,data:a})}const[h,{BitmapFont:l}]=await Promise.all([t.load(o),_e(()=>import("./BitmapFont.BEQi-SuJ.js"),__vite__mapDeps([10,2,3,4]))]),c=o.map(u=>h[u.src]);return new l({data:i,textures:c},s)},async load(r,e){return await(await j.get().fetch(r)).text()},async unload(r,e,t){await Promise.all(r.pages.map(i=>t.unload(i.texture.source._sourceOrigin))),r.destroy()}};class sp{constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),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 e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<t;i++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const np={extension:{type:I.CacheParser,name:"cacheTextureArray"},test:r=>Array.isArray(r)&&r.every(e=>e instanceof G),getCacheableAssets:(r,e)=>{const t={};return r.forEach(i=>{e.forEach((s,n)=>{t[i+(n===0?"":n+1)]=s})}),t}};async function sl(r){if("Image"in globalThis)return new Promise(e=>{const t=new Image;t.onload=()=>{e(!0)},t.onerror=()=>{e(!1)},t.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const e=await(await fetch(r)).blob();await createImageBitmap(e)}catch{return!1}return!0}return!1}const rp={extension:{type:I.DetectionParser,priority:1},test:async()=>sl("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(e=>e!=="avif")},Wo=["png","jpg","jpeg"],op={extension:{type:I.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Wo],remove:async r=>r.filter(e=>!Wo.includes(e))},ap="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function ks(r){return ap?!1:document.createElement("video").canPlayType(r)!==""}const hp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(e=>e!=="mp4"&&e!=="m4v")},lp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(e=>e!=="ogv")},cp={extension:{type:I.DetectionParser,priority:0},test:async()=>ks("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(e=>e!=="webm")},dp={extension:{type:I.DetectionParser,priority:0},test:async()=>sl("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(e=>e!=="webp")},nl=class us{constructor(){this.loadOptions={...us.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(e,t,i)=>(this._parsersValidated=!1,e[t]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(e,t){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,n=null;if((t.parser||t.loadParser)&&(n=this._parserHash[t.parser||t.loadParser],t.loadParser&&nt(`[Assets] "loadParser" is deprecated, use "parser" instead for ${e}`),n||nt(`[Assets] specified load parser "${t.parser||t.loadParser}" not found while loading ${e}`)),!n){for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.load&&((o=l.test)!=null&&o.call(l,e,t,this))){n=l;break}}if(!n)return nt(`[Assets] ${e} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await n.load(e,t,this),i.parser=n;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,t,this))&&(s=await l.parse(s,t,this)||s,i.parser=l)}return s})(),i}async load(e,t){this._parsersValidated||this._validateParsers();const i=typeof t=="function"?{...us.defaultOptions,...this.loadOptions,onProgress:t}:{...us.defaultOptions,...this.loadOptions,...t||{}},{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=ms(e),u=zt(e,y=>({alias:[y],src:y,data:{}})),p=u.reduce((y,m)=>y+(m.progressSize||1),0),f=u.map(async y=>{const m=Mt.toAbsolute(y.src);c[y.src]||(await this._loadAssetWithRetry(m,y,{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h},c),l+=y.progressSize||1,s&&s(l/p))});return await Promise.all(f),d?c[u[0].src]:c}async unload(e){const i=zt(e,s=>({alias:[s],src:s})).map(async s=>{var a,h;const n=Mt.toAbsolute(s.src),o=this.promiseCache[n];if(o){const l=await o.promise;delete this.promiseCache[n],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(e=>e.name||e.id).reduce((e,t)=>(!t.name&&!t.id?nt("[Assets] parser should have an id"):(e[t.name]||e[t.id])&&nt(`[Assets] parser id conflict "${t.id}"`),e[t.name]=t,t.id&&(e[t.id]=t),e),{})}async _loadAssetWithRetry(e,t,i,s){let n=0;const{onError:o,strategy:a,retryCount:h,retryDelay:l}=i,c=d=>new Promise(u=>setTimeout(u,d));for(;;)try{this.promiseCache[e]||(this.promiseCache[e]=this._getLoadPromiseAndParser(e,t)),s[t.src]=await this.promiseCache[e].promise;return}catch(d){delete this.promiseCache[e],delete s[t.src],n++;const u=a!=="retry"||n>h;if(a==="retry"&&!u){o&&o(d,t),await c(l);continue}if(a==="skip"){o&&o(d,t);return}o&&o(d,t);const p=new Error(`[Loader.load] Failed to load ${e}.
24
24
  ${d}`);throw d instanceof Error&&d.stack&&(p.stack=d.stack),p}}};nl.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let up=nl;function pe(r,e){if(Array.isArray(e)){for(const t of e)if(r.startsWith(`data:${t}`))return!0;return!1}return r.startsWith(`data:${e}`)}function li(r,e){const t=r.split("?")[0],i=Mt.extname(t).toLowerCase();return Array.isArray(e)?e.includes(i):i===e}const pp=".json",fp="application/json",gp={extension:{type:I.LoadParser,priority:ue.Low},name:"loadJson",id:"json",test(r){return pe(r,fp)||li(r,pp)},async load(r){return await(await j.get().fetch(r)).json()}},mp=".txt",yp="text/plain",xp={name:"loadTxt",id:"text",extension:{type:I.LoadParser,priority:ue.Low,name:"loadTxt"},test(r){return pe(r,yp)||li(r,mp)},async load(r){return await(await j.get().fetch(r)).text()}},Sp=["normal","bold","100","200","300","400","500","600","700","800","900"],vp=[".ttf",".otf",".woff",".woff2"],bp=["font/ttf","font/otf","font/woff","font/woff2"],wp=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function Cp(r){const e=Mt.extname(r),s=Mt.basename(r,e).replace(/(-|_)/g," ").toLowerCase().split(" ").map(a=>a.charAt(0).toUpperCase()+a.slice(1));let n=s.length>0;for(const a of s)if(!a.match(wp)){n=!1;break}let o=s.join(" ");return n||(o=`"${o.replace(/[\\"]/g,"\\$&")}"`),o}const Ap=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function Pp(r){return Ap.test(r)?r:encodeURI(r)}const Mp={extension:{type:I.LoadParser,priority:ue.Low},name:"loadWebFont",id:"web-font",test(r){return pe(r,bp)||li(r,vp)},async load(r,e){var i,s,n;const t=j.get().getFontFaceSet();if(t){const o=[],a=((i=e.data)==null?void 0:i.family)??Cp(r),h=((n=(s=e.data)==null?void 0:s.weights)==null?void 0:n.filter(c=>Sp.includes(c)))??["normal"],l=e.data??{};for(let c=0;c<h.length;c++){const d=h[c],u=new FontFace(a,`url(${Pp(r)})`,{...l,weight:d});await u.load(),t.add(u),o.push(u)}return xt.has(`${a}-and-url`)?xt.get(`${a}-and-url`).entries.push({url:r,faces:o}):xt.set(`${a}-and-url`,{entries:[{url:r,faces:o}]}),o.length===1?o[0]:o}return nt("[loadWebFont] FontFace API is not supported. Skipping loading font"),null},unload(r){const e=Array.isArray(r)?r:[r],t=e[0].family,i=xt.get(`${t}-and-url`),s=i.entries.find(n=>n.faces.some(o=>e.indexOf(o)!==-1));s.faces=s.faces.filter(n=>e.indexOf(n)===-1),s.faces.length===0&&(i.entries=i.entries.filter(n=>n!==s)),e.forEach(n=>{j.get().getFontFaceSet().delete(n)}),i.entries.length===0&&xt.remove(`${t}-and-url`)}};var _p=kp,pn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Tp=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function kp(r){var e=[];return r.replace(Tp,function(t,i,s){var n=i.toLowerCase();for(s=Ep(s),n=="m"&&s.length>2&&(e.push([i].concat(s.splice(0,2))),n="l",i=i=="m"?"l":"L");;){if(s.length==pn[n])return s.unshift(i),e.push(s);if(s.length<pn[n])throw new Error("malformed path data");e.push([i].concat(s.splice(0,pn[n])))}}),e}var Rp=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Ep(r){var e=r.match(Rp);return e?e.map(Number):[]}const Ip=th(_p);function Bp(r,e){const t=Ip(r),i=[];let s=null,n=0,o=0;for(let a=0;a<t.length;a++){const h=t[a],l=h[0],c=h;switch(l){case"M":n=c[1],o=c[2],e.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],e.moveTo(n,o);break;case"H":n=c[1],e.lineTo(n,o);break;case"h":n+=c[1],e.lineTo(n,o);break;case"V":o=c[1],e.lineTo(n,o);break;case"v":o+=c[1],e.lineTo(n,o);break;case"L":n=c[1],o=c[2],e.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],e.lineTo(n,o);break;case"C":n=c[5],o=c[6],e.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":e.bezierCurveTo(n+c[1],o+c[2],n+c[3],o+c[4],n+c[5],o+c[6]),n+=c[5],o+=c[6];break;case"S":n=c[3],o=c[4],e.bezierCurveToShort(c[1],c[2],n,o);break;case"s":e.bezierCurveToShort(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"Q":n=c[3],o=c[4],e.quadraticCurveTo(c[1],c[2],n,o);break;case"q":e.quadraticCurveTo(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"T":n=c[1],o=c[2],e.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],e.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":e.closePath(),i.length>0&&(s=i.pop(),s?(n=s.startX,o=s.startY):(n=0,o=0)),s=null;break;default:nt(`Unknown SVG path command: ${l}`)}l!=="Z"&&l!=="z"&&s===null&&(s={startX:n,startY:o},i.push(s))}return e}class Rs{constructor(e=0,t=0,i=0){this.type="circle",this.x=e,this.y=t,this.radius=i}clone(){return new Rs(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-e,n=this.y-t;return s*=s,n*=n,s+n<=i}strokeContains(e,t,i,s=.5){if(this.radius===0)return!1;const n=this.x-e,o=this.y-t,a=this.radius,h=(1-s)*i,l=Math.sqrt(n*n+o*o);return l<=a+h&&l>a-(i-h)}getBounds(e){return e||(e=new et),e.x=this.x-this.radius,e.y=this.y-this.radius,e.width=this.radius*2,e.height=this.radius*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class xr{constructor(e=0,t=0,i=0,s=0){this.type="ellipse",this.x=e,this.y=t,this.halfWidth=i,this.halfHeight=s}clone(){return new xr(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let i=(e-this.x)/this.halfWidth,s=(t-this.y)/this.halfHeight;return i*=i,s*=s,i+s<=1}strokeContains(e,t,i,s=.5){const{halfWidth:n,halfHeight:o}=this;if(n<=0||o<=0)return!1;const a=i*(1-s),h=i-a,l=n-h,c=o-h,d=n+a,u=o+a,p=e-this.x,f=t-this.y,y=p*p/(l*l)+f*f/(c*c),m=p*p/(d*d)+f*f/(u*u);return y>1&&m<=1}getBounds(e){return e||(e=new et),e.x=this.x-this.halfWidth,e.y=this.y-this.halfHeight,e.width=this.halfWidth*2,e.height=this.halfHeight*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.halfWidth=e.halfWidth,this.halfHeight=e.halfHeight,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function Dp(r,e,t,i,s,n){const o=r-t,a=e-i,h=s-t,l=n-i,c=o*h+a*l,d=h*h+l*l;let u=-1;d!==0&&(u=c/d);let p,f;u<0?(p=t,f=i):u>1?(p=s,f=n):(p=t+u*h,f=i+u*l);const y=r-p,m=e-f;return y*y+m*m}let Fp,zp;class Te{constructor(...e){this.type="polygon";let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!="number"){const i=[];for(let s=0,n=t.length;s<n;s++)i.push(t[s].x,t[s].y);t=i}this.points=t,this.closePath=!0}isClockwise(){let e=0;const t=this.points,i=t.length;for(let s=0;s<i;s+=2){const n=t[s],o=t[s+1],a=t[(s+2)%i],h=t[(s+3)%i];e+=(a-n)*(h+o)}return e<0}containsPolygon(e){const t=this.getBounds(Fp),i=e.getBounds(zp);if(!t.containsRect(i))return!1;const s=e.points;for(let n=0;n<s.length;n+=2){const o=s[n],a=s[n+1];if(!this.contains(o,a))return!1}return!0}clone(){const e=this.points.slice(),t=new Te(e);return t.closePath=this.closePath,t}contains(e,t){let i=!1;const s=this.points.length/2;for(let n=0,o=s-1;n<s;o=n++){const a=this.points[n*2],h=this.points[n*2+1],l=this.points[o*2],c=this.points[o*2+1];h>t!=c>t&&e<(l-a)*((t-h)/(c-h))+a&&(i=!i)}return i}strokeContains(e,t,i,s=.5){const n=i*i,o=n*(1-s),a=n-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],f=h[(c+3)%h.length],y=Dp(e,t,d,u,p,f),m=Math.sign((p-d)*(t-u)-(f-u)*(e-d));if(y<=(m<0?a:o))return!0}return!1}getBounds(e){e||(e=new et);const t=this.points;let i=1/0,s=-1/0,n=1/0,o=-1/0;for(let a=0,h=t.length;a<h;a+=2){const l=t[a],c=t[a+1];i=l<i?l:i,s=l>s?l:s,n=c<n?c:n,o=c>o?c:o}return e.x=i,e.width=s-i,e.y=n,e.height=o-n,e}copyFrom(e){return this.points=e.points.slice(),this.closePath=e.closePath,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((e,t)=>`${e}, ${t}`,"")}]`}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 as=(r,e,t,i,s,n,o)=>{const a=r-t,h=e-i,l=Math.sqrt(a*a+h*h);return l>=s-n&&l<=s+o};class Sr{constructor(e=0,t=0,i=0,s=0,n=20){this.type="roundedRectangle",this.x=e,this.y=t,this.width=i,this.height=s,this.radius=n}getBounds(e){return e||(e=new et),e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new Sr(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+i&&t<=this.y+this.height-i||e>=this.x+i&&e<=this.x+this.width-i)return!0;let s=e-(this.x+i),n=t-(this.y+i);const o=i*i;if(s*s+n*n<=o||(s=e-(this.x+this.width-i),s*s+n*n<=o)||(n=t-(this.y+this.height-i),s*s+n*n<=o)||(s=e-(this.x+i),s*s+n*n<=o))return!0}return!1}strokeContains(e,t,i,s=.5){const{x:n,y:o,width:a,height:h,radius:l}=this,c=i*(1-s),d=i-c,u=n+l,p=o+l,f=a-l*2,y=h-l*2,m=n+a,x=o+h;return(e>=n-c&&e<=n+d||e>=m-d&&e<=m+c)&&t>=p&&t<=p+y||(t>=o-c&&t<=o+d||t>=x-d&&t<=x+c)&&e>=u&&e<=u+f?!0:e<u&&t<p&&as(e,t,u,p,l,d,c)||e>m-l&&t<p&&as(e,t,m-l,p,l,d,c)||e>m-l&&t>x-l&&as(e,t,m-l,x-l,l,d,c)||e<u&&t>x-l&&as(e,t,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 rl={};function Lp(r,e,t){let i=2166136261;for(let s=0;s<e;s++)i^=r[s].uid,i=Math.imul(i,16777619),i>>>=0;return rl[i]||Op(r,e,i,t)}function Op(r,e,t,i){const s={};let n=0;for(let a=0;a<i;a++){const h=a<e?r[a]:G.EMPTY.source;s[n++]=h.source,s[n++]=h.style}const o=new _i(s);return rl[t]=o,o}class Uo{constructor(e){typeof e=="number"?this.rawBinaryData=new ArrayBuffer(e):e instanceof Uint8Array?this.rawBinaryData=e.buffer:this.rawBinaryData=e,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(e){return this[`${e}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(e){switch(e){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${e} isn't a valid view type`)}}}function Ho(r,e,t,i){if(t??(t=0),i??(i=Math.min(r.byteLength-t,e.byteLength)),!(t&7)&&!(i&7)){const s=i/8;new Float64Array(e,0,s).set(new Float64Array(r,t,s))}else if(!(t&3)&&!(i&3)){const s=i/4;new Float32Array(e,0,s).set(new Float32Array(r,t,s))}else new Uint8Array(e).set(new Uint8Array(r,t,i))}const Gp={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var Wp=(r=>(r[r.DISABLED=0]="DISABLED",r[r.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",r[r.MASK_ACTIVE=2]="MASK_ACTIVE",r[r.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",r[r.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",r[r.NONE=5]="NONE",r))(Wp||{});function ys(r,e){return e.alphaMode==="no-premultiply-alpha"&&Gp[r]||r}const Up=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
25
25
  `);function Hp(r){let e="";for(let t=0;t<r;++t)t>0&&(e+=`
26
26
  else `),t<r-1&&(e+=`if(test == ${t}.0){}`);return e}function Vp(r,e){if(r===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const t=e.createShader(e.FRAGMENT_SHADER);try{for(;;){const i=Up.replace(/%forloop%/gi,Hp(r));if(e.shaderSource(t,i),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))r=r/2|0;else break}}finally{e.deleteShader(t)}return r}let Oe=null;function Np(){var e;if(Oe)return Oe;const r=zh();return Oe=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),Oe=Vp(Oe,r),(e=r.getExtension("WEBGL_lose_context"))==null||e.loseContext(),Oe}class jp{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let e=0;e<this.count;e++){const t=this.textures[e];this.textures[e]=null,this.ids[t.uid]=null}this.count=0}}class Yp{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new jp,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 xs=0;Hi.register({clear:()=>{if(Ti.length>0)for(const r of Ti)r&&r.destroy();Ti.length=0,xs=0}});function Vo(){return xs>0?Ti[--xs]:new Yp}function No(r){r.elements=null,Ti[xs++]=r}let gi=0;const ol=class al{constructor(e){this.uid=dt("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],e={...al.defaultOptions,...e},e.maxTextures||(V("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),e.maxTextures=Np());const{maxTextures:t,attributesInitialSize:i,indicesInitialSize:s}=e;this.attributeBuffer=new Uo(i*4),this.indexBuffer=new Uint16Array(s),this.maxTextures=t}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)No(this.batches[e]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(e){this._elements[this.elementSize++]=e,e._indexStart=this.indexSize,e._attributeStart=this.attributeSize,e._batcher=this,this.indexSize+=e.indexSize,this.attributeSize+=e.attributeSize*this.vertexSize}checkAndUpdateTexture(e,t){const i=e._batch.textures.ids[t._source.uid];return!i&&i!==0?!1:(e._textureId=i,e.texture=t,!0)}updateElement(e){this.dirty=!0;const t=this.attributeBuffer;e.packAsQuad?this.packQuadAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId):this.packAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId)}break(e){const t=this._elements;if(!t[this.elementStart])return;let i=Vo(),s=i.textures;s.clear();const n=t[this.elementStart];let o=ys(n.blendMode,n.texture._source),a=n.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",f=[];const y=this.maxTextures;for(let m=this.elementStart;m<this.elementSize;++m){const x=t[m];t[m]=null;const v=x.texture._source,b=ys(x.blendMode,v),P=o!==b||a!==x.topology;if(v._batchTick===gi&&!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,f.push(x);continue}v._batchTick=gi,(s.count>=y||P)&&(this._finishBatch(i,u,d-u,s,o,a,e,p,f),p="renderBatch",u=d,o=b,a=x.topology,i=Vo(),s=i.textures,s.clear(),f=[],++gi),x._textureId=v._textureBindLocation=s.count,s.ids[v.uid]=s.count,s.textures[s.count++]=v,x._batch=i,f.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,e,p,f),u=d,++gi),this.elementStart=this.elementSize,this._batchIndexStart=u,this._batchIndexSize=d}_finishBatch(e,t,i,s,n,o,a,h,l){e.gpuBindGroup=null,e.bindGroup=null,e.action=h,e.batcher=this,e.textures=s,e.blendMode=n,e.topology=o,e.start=t,e.size=i,e.elements=l,++gi,this.batches[this.batchIndex++]=e,a.add(e)}finish(e){this.break(e)}ensureAttributeBuffer(e){e*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(e*4)}ensureIndexBuffer(e){e<=this.indexBuffer.length||this._resizeIndexBuffer(e)}_resizeAttributeBuffer(e){const t=Math.max(e,this.attributeBuffer.size*2),i=new Uo(t);Ho(this.attributeBuffer.rawBinaryData,i.rawBinaryData),this.attributeBuffer=i}_resizeIndexBuffer(e){const t=this.indexBuffer;let i=Math.max(e,t.length*1.5);i+=i%2;const s=i>65535?new Uint32Array(i):new Uint16Array(i);if(s.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let n=0;n<t.length;n++)s[n]=t[n];else Ho(t.buffer,s.buffer);this.indexBuffer=s}packQuadIndex(e,t,i){e[t]=i+0,e[t+1]=i+1,e[t+2]=i+2,e[t+3]=i+0,e[t+4]=i+2,e[t+5]=i+3}packIndex(e,t,i,s){const n=e.indices,o=e.indexSize,a=e.indexOffset,h=e.attributeOffset;for(let l=0;l<o;l++)t[i++]=s+n[l+a]-h}destroy(e={}){var t;if(this.batches!==null){for(let i=0;i<this.batchIndex;i++)No(this.batches[i]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,e.shader&&((t=this.shader)==null||t.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}}};ol.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let Xp=ol;var ft=(r=>(r[r.MAP_READ=1]="MAP_READ",r[r.MAP_WRITE=2]="MAP_WRITE",r[r.COPY_SRC=4]="COPY_SRC",r[r.COPY_DST=8]="COPY_DST",r[r.INDEX=16]="INDEX",r[r.VERTEX=32]="VERTEX",r[r.UNIFORM=64]="UNIFORM",r[r.STORAGE=128]="STORAGE",r[r.INDIRECT=256]="INDIRECT",r[r.QUERY_RESOLVE=512]="QUERY_RESOLVE",r[r.STATIC=1024]="STATIC",r))(ft||{});class he extends Yt{constructor(e){let{data:t,size:i}=e;const{usage:s,label:n,shrinkToFit:o}=e;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=dt("buffer"),this._resourceType="buffer",this._resourceId=dt("resource"),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,i??(i=t==null?void 0:t.byteLength);const a=!!t;this.descriptor={size:i,usage:s,mappedAtCreation:a,label:n},this.shrinkToFit=o??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.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(e){e?this.descriptor.usage|=ft.STATIC:this.descriptor.usage&=~ft.STATIC}setDataWithSize(e,t,i){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._data===e){i&&this.emit("update",this);return}const s=this._data;if(this._data=e,this._dataInt32=null,!s||s.length!==e.length){!this.shrinkToFit&&s&&e.byteLength<s.byteLength?i&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=dt("resource"),this.emit("change",this));return}i&&this.emit("update",this)}update(e){this._updateSize=e??this._updateSize,this._updateID++,this.emit("update",this)}unload(){var e;this.emit("unload",this);for(const t in this._gpuData)(e=this._gpuData[t])==null||e.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 hl(r,e){if(!(r instanceof he)){let t=e?ft.INDEX:ft.VERTEX;r instanceof Array&&(e?(r=new Uint32Array(r),t=ft.INDEX|ft.COPY_DST):(r=new Float32Array(r),t=ft.VERTEX|ft.COPY_DST)),r=new he({data:r,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return r}function Zp(r,e,t){const i=r.getAttribute(e);if(!i)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const s=i.buffer.data;let n=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],f=s[u+1];p>a&&(a=p),f>h&&(h=f),p<n&&(n=p),f<o&&(o=f)}return t.minX=n,t.minY=o,t.maxX=a,t.maxY=h,t}function qp(r){return(r instanceof he||Array.isArray(r)||r.BYTES_PER_ELEMENT)&&(r={buffer:r}),r.buffer=hl(r.buffer,!1),r}class Gi extends Yt{constructor(e={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=dt("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new Bt,this._boundsDirty=!0;const{attributes:t,indexBuffer:i,topology:s}=e;if(this.buffers=[],this.attributes={},t)for(const n in t)this.addAttribute(n,t[n]);this.instanceCount=e.instanceCount??1,i&&this.addIndex(i),this.topology=s||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}getSize(){for(const e in this.attributes){const t=this.attributes[e];return t.buffer.data.length/(t.stride/4||t.size)}return 0}addAttribute(e,t){const i=qp(t);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[e]=i}addIndex(e){this.indexBuffer=hl(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,Zp(this,"aPosition",this._bounds)):this._bounds}unload(){var e;this.emit("unload",this);for(const t in this._gpuData)(e=this._gpuData[t])==null||e.destroy();this._gpuData=Object.create(null)}destroy(e=!1){var t;this.emit("destroy",this),this.removeAllListeners(),e&&this.buffers.forEach(i=>i.destroy()),this.unload(),(t=this.indexBuffer)==null||t.destroy(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const Kp=new Float32Array(1),$p=new Uint32Array(1);class Qp extends Gi{constructor(){const t=new he({data:Kp,label:"attribute-batch-buffer",usage:ft.VERTEX|ft.COPY_DST,shrinkToFit:!1}),i=new he({data:$p,label:"index-batch-buffer",usage:ft.INDEX|ft.COPY_DST,shrinkToFit:!1}),s=6*4;super({attributes:{aPosition:{buffer:t,format:"float32x2",stride:s,offset:0},aUV:{buffer:t,format:"float32x2",stride:s,offset:2*4},aColor:{buffer:t,format:"unorm8x4",stride:s,offset:4*4},aTextureIdAndRound:{buffer:t,format:"uint16x2",stride:s,offset:5*4}},indexBuffer:i})}}function jo(r,e,t){if(r)for(const i in r){const s=i.toLocaleLowerCase(),n=e[s];if(n){let o=r[i];i==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),t&&n.push(`//----${t}----//`),n.push(o)}else nt(`${i} placement hook does not exist in shader`)}}const Jp=/\{\{(.*?)\}\}/g;function Yo(r){var i;const e={};return(((i=r.match(Jp))==null?void 0:i.map(s=>s.replace(/[{()}]/g,"")))??[]).forEach(s=>{e[s]=[]}),e}function Xo(r,e){let t;const i=/@in\s+([^;]+);/g;for(;(t=i.exec(r))!==null;)e.push(t[1])}function Zo(r,e,t=!1){const i=[];Xo(e,i),r.forEach(a=>{a.header&&Xo(a.header,i)});const s=i;t&&s.sort();const n=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 Ca({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(t,i){this.position.set(t,i)}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class sS{constructor(e){g(this,"heatmap");g(this,"pointsTopLeftOrigin",[]);g(this,"signalGrid",[]);g(this,"cellSize",2);g(this,"maxDistance",14);g(this,"smoothIterations",10);g(this,"heatmapAlpha",.8);g(this,"isHeatmapDrawn",!1);g(this,"loadTimer",null);g(this,"pendingPoints",null);this.appService=e,this.heatmap=new iS(e);const t=e.heatMapConfig;this.cellSize=t.cellSize,this.maxDistance=t.maxDistance,this.smoothIterations=t.smoothIterations,this.heatmapAlpha=t.heatmapAlpha}draw(e){const t=this.appService;if(!t.isMapDrawn){this.pendingPoints=e;return}this.pendingPoints=null;const{minX:i,minY:s}=t.mapManager.mapBounds,n=e.map(o=>({x:+(o.x-i).toFixed(0),y:+(o.y-s).toFixed(0),signal:o.signal}));this.signalGrid=this.calculateInterpolatedSignal(n),this.heatmap.draw(this.signalGrid,this.heatmapAlpha),this.isHeatmapDrawn=!0}onMapLoaded(){this.loadTimer||(this.pendingPoints&&this.draw(this.pendingPoints),this.loadTimer=setTimeout(()=>{this.loadTimer=null},200))}calculateInterpolatedSignal(e){var p;const t=this.appService,i=((p=t.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:n,maxX:o,maxY:a}=t.mapManager.mapBounds;n=n-i.y,s=s-i.x,a=a-i.y,o=o-i.x;const h=Math.ceil((a-n)/this.cellSize),l=Math.ceil((o-s)/this.cellSize),c=Array(h).fill(null).map(()=>Array(l).fill(null));for(let f=0;f<h;f++){const y=n+f*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<e.length;C++){const A=e[C];if(Math.abs(S-A.x)<=v/2&&Math.abs(y-A.y)<=m/2){const k=1-A.signal/7;b=Math.round(Math.max(b,k)*10)/10,P=!0}}c[f][x]={x:S,y,signal:b,hasPoint:P}}}const d=(f,y)=>{if(e.length===0)return 0;let m=0,x=0;for(const S of e){const v=Math.sqrt((f-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=(f,y=1)=>{for(let m=0;m<y;m++){const x=f.map(S=>[...S]);for(let S=1;S<h-1;S++)for(let v=1;v<l-1;v++)if(!f[S][v].hasPoint){let b=0,P=0;const C=4;for(let A=-C;A<=C;A++)for(let k=-C;k<=C;k++){if(A===0&&k===0)continue;const M=S+A,T=v+k;if(M>=0&&M<h&&T>=0&&T<l){const E=1/(1+Math.sqrt(A*A+k*k)*.3);b+=f[M][T].signal*E,P+=E}}if(P>0){const A=b/P,k=.6,M=.4;x[S][v].signal=f[S][v].signal*k+A*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++)f[S][v].signal=x[S][v].signal}};for(let f=0;f<h;f++)for(let y=0;y<l;y++){const m=c[f][y];m.hasPoint||(m.signal=d(m.x,m.y))}return u(c,this.smoothIterations),c}updatePositionByOrigin(e,t){this.heatmap.updatePositionByOrigin(e,t)}destroy(){this.heatmap.destroy()}}class xc extends L{constructor(t){super();g(this,"throttledUpdateScale");this.appService=t,this.throttledUpdateScale=Ct(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(t){t!==0&&this.scale.set(1/t)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class Ni extends xc{constructor(t,i){super(t);g(this,"background");g(this,"icon");g(this,"options");this.appService=t,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Xt(t),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const t=this.appService,i=this.options.config||t.controlsConfig,s=8,n=i.iconWrapperWidth+s*2,o=i.iconWrapperHeight+s*2;this.hitArea=new et(-n/2,-o/2,n,o)}async render(){this.renderBackground(),this.renderIcon()}renderBackground(){const t=this.appService,i=this.options.config||t.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 t=this.appService,i=this.options.config||t.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(t){w.error(`Failed to load icon: ${this.options.iconAlias}`,t)}}destroy(){super.destroy()}}class Sc extends Ni{constructor(t,i){super(t,i);g(this,"isRotating",!1);g(this,"hasRotated",!1);g(this,"rotationCenter",{x:0,y:0});g(this,"lastAngle",0);g(this,"clickHandler",null);g(this,"handleRotationPointerMove",t=>{var o,a;if(!this.isRotating)return;this.hasRotated=!0;const i=this.parent.toLocal(t.global),s=Math.atan2(i.y-this.rotationCenter.y,i.x-this.rotationCenter.x),n=s-this.lastAngle;(a=(o=this.options).onRotationMove)==null||a.call(o,n),this.lastAngle=s});g(this,"handleRotationPointerUp",()=>{var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)});g(this,"handleRotationCancel",()=>{var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)});this.appService=t,this.setupRotationEventListeners()}setupRotationEventListeners(){const{emitter:t}=this.appService;this.appService.emitter.on("gestureHijackPointerMove",this.handleRotationPointerMove),t.on("gestureHijackPointerUp",this.handleRotationPointerUp),t.on("gestureHijackCancel",this.handleRotationCancel)}cleanupRotationEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleRotationPointerMove),t.off("gestureHijackPointerUp",this.handleRotationPointerUp),t.off("gestureHijackCancel",this.handleRotationCancel)}setupEvents(){this.options.onClick&&(this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.hasRotated||(i=(t=this.options).onClick)==null||i.call(t)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startRotation(t)}startRotation(t){var n,o;this.isRotating=!0,this.hasRotated=!1;const i=this.options.getTargetPoints();this.rotationCenter=de(i);const s=this.parent.toLocal(t.global);this.lastAngle=Math.atan2(s.y-this.rotationCenter.y,s.x-this.rotationCenter.x),(o=(n=this.options).onRotationStart)==null||o.call(n,this.rotationCenter),this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)}destroy(){var t;this.stopRotation(),(t=this.clickHandler)==null||t.destroy(),this.cleanupRotationEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class zs extends Ni{constructor(t,i){super(t,i);g(this,"clickHandler",null);this.appService=t}setupEvents(){this.clickHandler=new vt(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var t;(t=this.clickHandler)==null||t.destroy(),super.destroy()}}class Qe extends Ni{constructor(t,i){super(t,i);g(this,"isScaling",!1);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"handleScalePointerMove",t=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:n})});g(this,"handleScalePointerUp",()=>{var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))});g(this,"handleScaleCancel",()=>{var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))});this.appService=t,this.setupScaleEventListeners()}setupScaleEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleScalePointerMove),t.on("gestureHijackPointerUp",this.handleScalePointerUp),t.on("gestureHijackCancel",this.handleScaleCancel)}cleanupScaleEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleScalePointerMove),t.off("gestureHijackPointerUp",this.handleScalePointerUp),t.off("gestureHijackCancel",this.handleScaleCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startScaling(t)}startScaling(t){var i,s,n,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(t.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=(n=this.options).onScaleStart)==null||o.call(n,h)}this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))}destroy(){this.stopScaling(),this.cleanupScaleEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ls extends Ni{constructor(t,i){super(t,i);g(this,"isMoving",!1);g(this,"dragStartPosition",null);g(this,"handleMovePointerMove",t=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,t)});g(this,"handleMovePointerUp",()=>{var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))});g(this,"handleMoveCancel",()=>{var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))});this.appService=t,this.setupMoveEventListeners()}setupMoveEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleMovePointerMove),t.on("gestureHijackPointerUp",this.handleMovePointerUp),t.on("gestureHijackCancel",this.handleMoveCancel)}cleanupMoveEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleMovePointerMove),t.off("gestureHijackPointerUp",this.handleMovePointerUp),t.off("gestureHijackCancel",this.handleMoveCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startMoving(t)}startMoving(t){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(t.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))}destroy(){this.stopMoving(),this.cleanupMoveEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ur extends H{constructor(t,i){super();g(this,"fillOptions");g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"handlePointerDown",t=>{t.stopPropagation(),this.startDragging(t)});g(this,"handleDragPointerMove",t=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,t)});g(this,"handleDragPointerUp",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(t=this.fillOptions).onDragEnd)==null||i.call(t))});g(this,"handleDragCancel",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(t=this.fillOptions).onDragEnd)==null||i.call(t))});this.appService=t,this.fillOptions=i,this.setupInteraction(),this.setupDragEventListeners(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}startDragging(t){var s,n;this.isDragging=!0;const i=this.parent.toLocal(t.global);this.dragStartPosition={x:i.x,y:i.y},(n=(s=this.fillOptions).onDragStart)==null||n.call(s,t),this.appService.emitter.emit("gestureHijackStart",t)}draw(){const{points:t,fillColor:i}=this.fillOptions;if(t.length<3)return;this.clear();const s=t.flatMap(n=>[n.x,n.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(t){this.fillOptions={...this.fillOptions,...t},t.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(t){this.fillOptions.points=t,this.draw()}updateFillColor(t){this.fillOptions.fillColor=t,this.draw()}stopDragging(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(t){this.fillOptions.enableInteraction=t,t?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}const Hr=(r,e,t)=>{if(e!=null){if(typeof e!="number"||!Number.isFinite(e)||e<=r){w.warn(`[${t}] maxSize (${String(e)}) must be a finite number greater than minSize (${r}); ignoring.`);return}return e}};class Nt extends L{constructor(t,i){super();g(this,"borderOptions");g(this,"solidLine",null);g(this,"dashGraphics",null);g(this,"fillGraphics",null);g(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=t,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:t=[],closePath:i=!1,style:s}=this.borderOptions;t.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(t,s),s.isDashed?this.drawContinuousDashedBorder(t,i,s):this.drawSolidBorder(t,i,s))}drawFill(t,i){if(!(!i.fillColor||t.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(t[0].x,t[0].y);for(let s=1;s<t.length;s++)this.fillGraphics.lineTo(t[s].x,t[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(t,i,s){const n=this.appService;this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy()),this.solidLine=new H;const o=n.getApp().toFixedSize(s.width);this.solidLine.setStrokeStyle({color:s.color,width:o}),this.solidLine.moveTo(t[0].x,t[0].y);for(let a=1;a<t.length;a++)this.solidLine.lineTo(t[a].x,t[a].y);i&&this.solidLine.lineTo(t[0].x,t[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(t,i,s){if(t.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 n=this.appService;this.dashGraphics=new H;const o=n.getApp().toFixedSize(s.width);this.dashGraphics.setStrokeStyle({color:s.color,width:o});const a=Math.max(n.getApp().toFixedSize(s.dashArray[0]),1),h=Math.max(n.getApp().toFixedSize(s.dashArray[1]),1),l=i?[...t,t[0]]:t;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(t,i,s,n){if(i.length<2)return;if(s<=0||n<=0){w.warn("Invalid dash parameters:",{dashLength:s,gapLength:n});return}const o=this.calculatePathSegments(i),a=o.reduce((c,d)=>c+d.length,0);if(a===0)return;const h=s+n;let l=0;for(;l<a;){const c=l+s;c<=a?this.drawContinuousDashSegment(t,o,l,c):this.drawContinuousDashSegment(t,o,l,a),l+=h}}calculatePathSegments(t){const i=[];for(let s=0;s<t.length-1;s++){const n=t[s],o=t[s+1],a=o.x-n.x,h=o.y-n.y,l=Math.sqrt(a*a+h*h);i.push({start:n,end:o,length:l})}return i}drawContinuousDashSegment(t,i,s,n){if(s>=n)return;let o=0,a=!1,h=null;for(const l of i){const c=o,d=o+l.length;if(d>s&&c<n){const u=Math.max(s,c),p=Math.min(n,d),f=(u-c)/l.length,y=(p-c)/l.length,m={x:l.start.x+(l.end.x-l.start.x)*f,y:l.start.y+(l.end.y-l.start.y)*f},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&&t.lineTo(m.x,m.y):(t.moveTo(m.x,m.y),a=!0),t.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=n)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(t){this.borderOptions.style={...this.borderOptions.style,...t},this.drawBorder()}updatePoints(t){this.borderOptions.points=t,this.drawBorder()}setClosePath(t){this.borderOptions.closePath=t,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class ji extends Bs{constructor(t,{text:i,style:s}){super({text:i,style:s});g(this,"throttledUpdateScale");this.appService=t,this.throttledUpdateScale=Ct(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(t){t<=0||this.scale.set(1/t)}setBaseFontSize(t){this.style.fontSize=t}updateText(t){this.text=t}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}const At=class At extends L{constructor(t){super();g(this,"appService");g(this,"zoneData");g(this,"zoneType");g(this,"zoneConfig");g(this,"controlsConfig");g(this,"zoneEvents");g(this,"controlFill");g(this,"zoneBorder");g(this,"outlineBorder");g(this,"moveLine");g(this,"sizeText");g(this,"controlButtons");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"totalRotationAngle",0);g(this,"rotationCenter",null);g(this,"initialZonePoints",[]);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"clickHandler",null);g(this,"resolvedMaxSizeCache",null);g(this,"throttledUpdateOutline");g(this,"handleDragStart",t=>{this.isEditingEnabled()&&(this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.dragStartPosition=this.parent.toLocal(t.global),this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var t,i;this.initialZonePoints=[],this.dragStartPosition=null,this.appService.getApp().stopRender("zone-drag"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleRotationStart",t=>{this.totalRotationAngle=0,this.rotationCenter=t,this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",t=>{this.totalRotationAngle+=t,this.applyRotation(this.totalRotationAngle)});g(this,"handleRotationEnd",()=>{var t,i;this.rotationCenter=null,this.totalRotationAngle=0,this.initialZonePoints=[],this.appService.getApp().stopRender("zone-rotate"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleScaleStart",()=>{this.initialZonePoints=this.zoneData.points.map(i=>({...i}));const t=At.BUTTON_INDICES.SCALE;t<this.zoneData.points.length&&(this.initialButtonPosition={...this.zoneData.points[t]}),this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialZonePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var t,i;this.initialZonePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("zone-scale"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(t=>({...t})),this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",t=>{var a;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(t.global),s=(a=this.moveButton)==null?void 0:a.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleDelete",()=>{var t,i;(i=(t=this.zoneEvents).onRemove)==null||i.call(t,this.zoneData.id)});const{appService:i,zoneData:s,zoneType:n,events:o={}}=t;this.appService=i,this.zoneType=n,this.zoneEvents=o,this.zoneConfig=this.getZoneConfig(),this.controlsConfig=this.getControlsConfig();const a=this.validateAndCorrectZoneSize(s.points),h=Cs(a);this.zoneData={...s,points:h},this.throttledUpdateOutline=Ct(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.createControlButtons(),this.updateEditState(),this.setupClickHandler(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){this.isEditingEnabled()&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}getZoneConfig(){var i;const t=this.appService.getConfig();if(Ne(this.zoneType)){const s=t.controls[this.zoneType];if(s)return s}else{const s=(i=t.customZoneTypes)==null?void 0:i[this.zoneType];if(s)return s}return Ei.cleanZone}getControlsConfig(){const{controls:t}=this.appService.getConfig();return t}validateAndCorrectZoneSize(t){if(t.length<4)return t;const i=this.appService.metersToPixels(this.zoneConfig.minSize),s=this.getResolvedMaxSize(),n=s!=null?this.appService.metersToPixels(s):void 0;return nr(t,i,n)}getResolvedMaxSize(){const t=this.zoneConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===t)return this.resolvedMaxSizeCache.value;const i=Hr(this.zoneConfig.minSize,t,this.zoneType);return this.resolvedMaxSizeCache={key:t,value:i},i}isEditingEnabled(){var s;const t=this.appService.runtimeSnapshot,i=this.zoneData.id;switch(this.zoneType){case"forbiddenSweepZone":return t.editingForbiddenSweepZoneIds.includes(i);case"forbiddenMopZone":return t.editingForbiddenMopZoneIds.includes(i);case"cleanZone":return t.editingCleanZoneIds.includes(i);default:return(((s=t.editingCustomZoneIds)==null?void 0:s[this.zoneType])??[]).includes(i)}}initializeComponents(){this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.controlFill=this.createControlFill(),this.addChild(this.controlFill),this.zoneBorder=this.createBorder(),this.addChild(this.zoneBorder),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.sizeText=this.createSizeText(),this.addChild(this.sizeText),this.controlButtons=new L,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.drawZone()}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;this.deleteButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onClick:this.handleDelete}),this.deleteButton.position.set(t[At.BUTTON_INDICES.REMOVE].x,t[At.BUTTON_INDICES.REMOVE].y),this.zoneConfig.showRotateButton&&(this.rotateButton=new Sc(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,onRotationStart:this.handleRotationStart,onRotationMove:this.handleRotationMove,onRotationEnd:this.handleRotationEnd}),this.rotateButton.position.set(t[At.BUTTON_INDICES.ROTATE].x,t[At.BUTTON_INDICES.ROTATE].y)),this.scaleButton=new Qe(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,getButtonIndex:()=>At.BUTTON_INDICES.SCALE,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(t[At.BUTTON_INDICES.SCALE].x,t[At.BUTTON_INDICES.SCALE].y);const i=this.calculateMoveButtonPosition();this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(i.x,i.y),this.controlButtons.addChild(this.deleteButton),this.rotateButton&&this.controlButtons.addChild(this.rotateButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}createControlFill(){const t=this.isEditingEnabled();return new Ur(this.appService,{points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:t,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(){const i=this.isEditingEnabled()?this.zoneConfig.editing:this.zoneConfig.normal;return new Nt(this.appService,{points:this.zoneData.points,closePath:!0,style:{color:this.zoneConfig.strokeColor,width:this.zoneConfig.strokeWidth,isDashed:i.isDashed,dashArray:i.dashArray}})}createOutlineBorder(){const t=this.calculateOutlinePoints();return new Nt(this.appService,{points:t,closePath:!0,style:{color:this.zoneConfig.outlineStrokeColor,width:this.zoneConfig.outlineStrokeWidth,isDashed:this.zoneConfig.outlineDashed,dashArray:this.zoneConfig.outlineDashArray,fillColor:this.zoneConfig.outlineFillColor}})}createMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);return new Nt(this.appService,{points:i,closePath:!1,style:{color:this.zoneConfig.outlineStrokeColor,width:this.zoneConfig.outlineStrokeWidth,isDashed:this.zoneConfig.outlineDashed,dashArray:this.zoneConfig.outlineDashArray}})}calculateOutlinePoints(){const{points:t}=this.zoneData;if(t.length<4)return t;const i=this.appService.getApp().toFixedSize(this.zoneConfig.outlineOffset);return zr(t,i)}calculateMoveLinePoints(t){if(t.length<4)return[];const i=t[At.BUTTON_INDICES.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}createSizeText(){const t=this.calculateZoneSizeText(),i=new ji(this.appService,{text:t,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.zoneConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}calculateZoneSizeText(){const{points:t}=this.zoneData;if(t.length<4)return"0m*0m";const[i,s,,n]=t,o=Q(i,s),a=Q(i,n),h=this.appService.pixelsToMeters(o),l=this.appService.pixelsToMeters(a),c=this.appService.metersToDisplayUnit(h),d=this.appService.metersToDisplayUnit(l),u=this.appService.runtimeSnapshot.unitLabel;return`${c.toFixed(1)}${u}*${d.toFixed(1)}${u}`}calculateSizeTextPosition(){const{points:t}=this.zoneData;if(t.length<4)return{x:0,y:0};const[i,s,n,o]=t,{textPosition:a,textOffset:h}=this.zoneConfig,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2};const u=gt(K(s,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2};const u=gt(K(s,n)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2};const u=gt(K(o,n)),p={x:-u.y,y:u.x};d={x:p.x*l,y:p.y*l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2};const u=gt(K(o,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}default:c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:0,y:l};break}return{x:c.x+d.x,y:c.y+d.y}}calculateSizeTextRotation(){const{points:t}=this.zoneData;if(t.length<4)return 0;const[i,s,n,o]=t,{textPosition:a}=this.zoneConfig;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}calculateMoveButtonPosition(){const t=this.calculateOutlinePoints();if(t.length<4)return{x:0,y:0};const{controls:i}=this.appService.getConfig(),s=t[At.BUTTON_INDICES.MOVE],n=t[2],o=t[0],a=this.appService.getApp().toFixedSize(i.moveButtonOffset);return Ds(s,n,o,a)}applyTranslation(t,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawZone(),this.updateControlButtonsPosition()}applyRotation(t){!this.rotationCenter||this.initialZonePoints.length===0||(this.zoneData.points=Fr(this.initialZonePoints,this.rotationCenter,t),this.drawZone(!1),this.updateControlButtonsPosition())}applyEdgeBasedScale(t){if(this.initialZonePoints.length<4)return;const{FIXED:i}=At.BUTTON_INDICES,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=K(h,o),c=K(h,a),d=K(h,t),u=ee(l),p=ee(c);if(u===0||p===0)return;const f=this.appService.metersToPixels(this.zoneConfig.minSize),y=this.getResolvedMaxSize(),m=y!=null?this.appService.metersToPixels(y):void 0,[x,S]=[ae(d,l,u,f,m),ae(d,c,p,f,m)];this.zoneData.points=[h,{x:s+l.x*x,y:n+l.y*x},{x:s+l.x*x+c.x*S,y:n+l.y*x+c.y*S},{x:s+c.x*S,y:n+c.y*S}],this.drawZone(),this.updateControlButtonsPosition()}setupClickHandler(){this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.isEditingEnabled()||(i=(t=this.zoneEvents)==null?void 0:t.onClick)==null||i.call(t,this.getZoneData())},stopPropagation:!1})}drawZone(t=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.updateOutlineBorder(),this.updateMoveLine(),this.updateSizeText(t))}updateOutlineBorder(){const t=this.calculateOutlinePoints();this.outlineBorder.updatePoints(t)}updateMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);this.moveLine.updatePoints(i)}updateSizeText(t=!0){if(this.sizeText){if(t){const i=this.calculateZoneSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,ROTATE:s,SCALE:n}=At.BUTTON_INDICES,o=this.calculateMoveButtonPosition(),a=[{button:this.deleteButton,point:t[i]},{button:this.scaleButton,point:t[n]},{button:this.moveButton,point:o}];this.rotateButton&&a.push({button:this.rotateButton,point:t[s]}),a.forEach(({button:h,point:l})=>h.position.set(l.x,l.y))}updateEditState(){const t=this.isEditingEnabled();this.controlButtons.visible=t,!t&&this.getCurrentOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=t,this.moveLine.visible=t,this.sizeText&&(this.sizeText.visible=t),t&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition()),this.controlFill.setInteractionEnabled(t),this.updateBorderStyle(t?this.zoneConfig.editing:this.zoneConfig.normal),this.zIndex=t?1e3:0}updateBorderStyle(t){this.zoneBorder.updateStyle({isDashed:t.isDashed,dashArray:t.dashArray})}getCurrentOperationState(){var o,a,h;const t=this.controlFill.isCurrentlyDragging(),i=((o=this.scaleButton)==null?void 0:o.isCurrentlyScaling())||!1,s=((a=this.rotateButton)==null?void 0:a.isCurrentlyRotating())||!1,n=((h=this.moveButton)==null?void 0:h.isCurrentlyMoving())||!1;return{isDragging:t,isScaling:i,isRotating:s,isMoving:n,hasAnyOperation:t||i||s||n}}stopAllOperations(){var t,i,s;this.controlFill.stopDragging(),(t=this.scaleButton)==null||t.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}stopDragging(){this.controlFill.stopDragging()}stopScaling(){var t;(t=this.scaleButton)==null||t.stopScaling()}stopRotating(){var t;(t=this.rotateButton)==null||t.stopRotation()}stopMoving(){var t;(t=this.moveButton)==null||t.stopMoving()}isCurrentlyDragging(){return this.controlFill.isCurrentlyDragging()}isCurrentlyScaling(){var t;return((t=this.scaleButton)==null?void 0:t.isCurrentlyScaling())||!1}isCurrentlyRotating(){var t;return((t=this.rotateButton)==null?void 0:t.isCurrentlyRotating())||!1}isCurrentlyMoving(){var t;return((t=this.moveButton)==null?void 0:t.isCurrentlyMoving())||!1}updateZoneData(t){const i=this.validateAndCorrectZoneSize(t.points),s=Cs(i);this.zoneData={...t,points:s},this.drawZone(),this.updateControlButtonsPosition(),this.updateEditState()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var t,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(n=this.scaleButton)==null||n.destroy(),(o=this.moveButton)==null||o.destroy(),this.deleteButton=null,this.rotateButton=null,this.scaleButton=null,this.moveButton=null,(a=this.zoneBorder)==null||a.destroy(),(h=this.outlineBorder)==null||h.destroy(),(l=this.moveLine)==null||l.destroy(),(c=this.sizeText)==null||c.destroy(),(d=this.controlFill)==null||d.destroy(),(u=this.controlButtons)==null||u.destroy(),super.destroy()}};g(At,"BUTTON_INDICES",{REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0});let oi=At;class Vr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"forbiddenSweepZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickForbiddenSweepZone)==null||n.call(s,i)}}})}static create(e,t){return new Vr(e,{zoneData:t})}}class Nr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"forbiddenMopZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickForbiddenMopZone)==null||n.call(s,i)}}})}static create(e,t){return new Nr(e,{zoneData:t})}}class jr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"cleanZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveCleanZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateCleanZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickCleanZone)==null||n.call(s,i)}}})}static create(e,t){return new jr(e,{zoneData:t})}}class Ue extends H{constructor(t,i){super();g(this,"lineOptions");g(this,"strokeContext",null);g(this,"drawDashLine",()=>{const{start:t,end:i,style:s}=this.lineOptions;this.clear(),this.strokeContext&&this.strokeContext.destroy();const n=this.appService;this.strokeContext=new mt;const o=n.getApp().toFixedSize(s.width);this.strokeContext.setStrokeStyle({color:s.color,width:o}),this.drawDashedLineToContext(this.strokeContext,t.x,t.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=t,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(t,i,s,n,o,a,h){const l=n-i,c=o-s,d=Math.sqrt(l*l+c*c);if(d===0)return;const u=this.appService,p=u.getApp().toFixedSize(a),f=u.getApp().toFixedSize(h),y=p+f,m=d/y,x=Math.round(m);if(x===0){t.moveTo(i,s),t.lineTo(n,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let C=0;C<x;C++){const A=C*S,k=A+v;if(A>=d)break;const M=Math.min(k,d),T=i+A*b,_=s+A*P,E=i+M*b,B=s+M*P;t.moveTo(T,_),t.lineTo(E,B)}}updatePoints(t,i){this.lineOptions.start=t,this.lineOptions.end=i,this.drawDashLine()}updateStyle(t){this.lineOptions.style={...this.lineOptions.style,...t},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Vt=class Vt extends L{constructor(t){super();g(this,"wallData");g(this,"wallConfig");g(this,"controlsConfig");g(this,"wallEvents");g(this,"appService");g(this,"wallLine");g(this,"outlineBorder");g(this,"moveLine");g(this,"lengthText");g(this,"controlButtons");g(this,"removeButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"initialWallPoints",[]);g(this,"initialButtonPosition",null);g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"resolvedMaxWidthCache",null);g(this,"throttledUpdateOutline");g(this,"throttledHandleScaleChange");g(this,"wallLineClickHandler",null);g(this,"handleRemove",()=>{var t,i;(i=(t=this.wallEvents).onRemove)==null||i.call(t,this.wallData.id)});g(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(t=>({...t}))});g(this,"finalizeOperation",()=>{var t,i;this.initialWallPoints=[],(i=(t=this.wallEvents).onUpdate)==null||i.call(t,this.getWallData())});g(this,"handleScaleStart",()=>{this.initializeOperation();const t=this.calculateOutlinePoints();t.length>Vt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...t[Vt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});g(this,"handleScaleEnd",()=>{this.finalizeOperation(),this.initialButtonPosition=null,this.appService.getApp().stopRender("virtualwall-scale")});g(this,"handleMoveStart",()=>{this.initializeOperation(),this.appService.getApp().requestRender("virtualwall-move",!0)});g(this,"handleMove",t=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(t.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{this.finalizeOperation(),this.appService.getApp().stopRender("virtualwall-move")});g(this,"handleScaleChange",()=>{this.redrawSolidLine(),this.setupWallLineHitArea()});g(this,"handleWallLinePointerDown",t=>{this.isEditingEnabled()&&(t.stopPropagation(),this.startDragging(t))});g(this,"handleDragPointerMove",t=>{!this.isDragging||!this.dragStartPosition||this.handleMove(t)});g(this,"handleDragPointerUp",()=>{this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.finalizeOperation())});g(this,"handleDragCancel",()=>{this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.handleMoveEnd())});const{appService:i,wallData:s,events:n={}}=t;this.appService=i,this.wallEvents=n,this.wallConfig=this.appService.controlsConfig.virtualWall,this.controlsConfig=this.appService.controlsConfig,this.wallData={...s,points:this.validateAndCorrectWallLength(s.points)},this.throttledHandleScaleChange=Ct(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=Ct(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.registerScaleListener(),this.setupDragEventListeners()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("antiScale",this.throttledHandleScaleChange),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}getResolvedMaxWidth(){const t=this.wallConfig.maxWidth;if(this.resolvedMaxWidthCache&&this.resolvedMaxWidthCache.key===t)return this.resolvedMaxWidthCache.value;const i=Hr(this.wallConfig.minWidth,t,"virtualWall");return this.resolvedMaxWidthCache={key:t,value:i},i}validateAndCorrectWallLength(t){if(t.length<2)return t;const[i,s]=t,n=this.appService.metersToPixels(this.wallConfig.minWidth),o=this.getResolvedMaxWidth(),a=o!=null?this.appService.metersToPixels(o):void 0,h=Q(i,s),l=h<n,c=a!=null&&h>a;if(!l&&!c)return t;if(h===0)return[i,{x:i.x+n,y:i.y}];const d=gt(K(i,s));let u=h;return a!=null&&(u=Math.min(u,a)),u=Math.max(u,n),[i,{x:i.x+d.x*u,y:i.y+d.y*u}]}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 L,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.createControlButtons()}createWallLine(t=!0){const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:n,editing:o,normal:a}=this.wallConfig,l=this.isEditingEnabled()?o:a;l.isDashed?this.wallLine=new Ue(this.appService,{start:i[0],end:i[1],style:{color:n.toString(),width:s,dashArray:l.dashArray}}):this.wallLine=this.createSolidLine(i[0],i[1],s,n.toString()),t&&this.setupWallLineInteraction()}createLengthText(){const t=this.calculateWallLengthInMeters(),i=this.formatLengthText(t),s=new ji(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 n=this.calculateTextPosition();s.position.set(n.x,n.y);const o=this.calculateTextRotation();return s.rotation=o,s.eventMode="none",s}calculateWallLengthInMeters(){const{points:t}=this.wallData;if(t.length<2)return 0;const i=Q(t[0],t[1]);return this.appService.pixelsToMeters(i)}formatLengthText(t){const i=this.appService.metersToDisplayUnit(t),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:t}=this.wallData;if(t.length<2)return{x:0,y:0};const[i,s]=t,n=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return nc(i,s,n)}calculateTextRotation(){const{points:t}=this.wallData;if(t.length<2)return 0;const[i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(i,s,n)}getOutlineStyle(){return{color:this.wallConfig.outlineStrokeColor,width:this.wallConfig.outlineStrokeWidth,isDashed:this.wallConfig.outlineDashed,dashArray:this.wallConfig.outlineDashArray,fillColor:this.wallConfig.outlineFillColor}}createOutlineBorder(){const t=this.calculateOutlinePoints();return new Nt(this.appService,{points:t,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);return new Nt(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(t){const i=t||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),n=my(i[0],i[1],s);return[n[3],n[2],n[1],n[0]]}calculateMoveLinePoints(t){if(t.length<4)return[];const{MOVE:i}=Vt.BUTTON_INDICES,s=t[i],n=this.calculateMoveButtonPosition();return[s,n]}calculateMoveButtonPosition(){const{moveButtonOffset:t}=this.controlsConfig,i=this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{MOVE:s}=Vt.BUTTON_INDICES,n=i[s],o=i[(s+3)%4],a=i[(s+1)%4],h=this.appService.getApp().toFixedSize(t);return Ds(n,a,o,h)}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES;this.removeButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(t[i].x,t[i].y),this.scaleButton=new Qe(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(t[s].x,t[s].y);const n=this.calculateMoveButtonPosition();this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(n.x,n.y),this.controlButtons.addChild(this.removeButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}applyScaleAndRotation(t){if(this.initialWallPoints.length<2)return;const[i,s]=this.initialWallPoints,n=i,o=this.calculateOutlinePoints(this.initialWallPoints);if(o.length<4)return;const a=o[Vt.BUTTON_INDICES.SCALE],l=K(s,a),c={x:t.x-l.x,y:t.y-l.y},d=K(n,c),u=Q(n,c),p=this.appService.metersToPixels(this.wallConfig.minWidth),f=this.getResolvedMaxWidth(),y=f!=null?this.appService.metersToPixels(f):void 0;let m;if(u<p)if(u===0)m={x:n.x+p,y:n.y};else{const x=gt(d);m={x:n.x+x.x*p,y:n.y+x.y*p}}else if(y!=null&&u>y){const x=gt(d);m={x:n.x+x.x*y,y:n.y+x.y*y}}else m=c;this.wallData.points=[n,m],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(t,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:t}=this.wallData;t.length<2||(this.wallLine instanceof Ue?this.wallLine.updatePoints(t[0],t[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const t=this.calculateWallLengthInMeters(),i=this.formatLengthText(t);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const t=this.calculateTextPosition();this.lengthText.position.set(t.x,t.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const t=this.calculateOutlinePoints();this.outlineBorder.updatePoints(t);const i=this.calculateMoveLinePoints(t);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES,n=this.calculateMoveButtonPosition();this.removeButton.position.set(t[i].x,t[i].y),this.scaleButton.position.set(t[s].x,t[s].y),this.moveButton.position.set(n.x,n.y)}updateEditState(){const t=this.isEditingEnabled();this.controlButtons.visible=t,this.outlineBorder.visible=t,this.moveLine.visible=t,this.lengthText&&(this.lengthText.visible=t),t&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=t?1e3:0}createSolidLine(t,i,s,n){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(t.x,t.y),o.lineTo(i.x,i.y),o.stroke({color:n,width:a}),o}updateWallLineStyle(){const t=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:n,lineColor:o}=this.wallConfig,a=t?i:s;this.wallLine instanceof Ue!==a.isDashed?(this.removeChild(this.wallLine),this.wallLine.destroy(),this.createWallLine(!1),this.addChild(this.wallLine)):this.wallLine instanceof Ue?this.wallLine.updateStyle({color:o.toString(),width:n,dashArray:a.dashArray}):this.redrawSolidLine()}redrawSolidLine(){const t=this.appService;if(!this.wallLine||this.wallLine instanceof Ue)return;const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:n}=this.wallConfig,o=t.getApp().toFixedSize(s);this.wallLine.clear(),this.wallLine.setStrokeStyle({color:n.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 t=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),t?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new vt(this.wallLine,{onClick:()=>{var s,n;this.appService.emitter.emit("suppressMapClick"),(n=(s=this.wallEvents)==null?void 0:s.onClick)==null||n.call(s,this.getWallData())},stopPropagation:!1})}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}startDragging(t){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(t.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.appService.emitter.emit("gestureHijackStart",t)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:t}=this.wallData;if(t.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),n=rc(t[0],t[1],s);if(n.length===0)return;const o=new Te(n);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(t){this.wallData={...t,points:this.validateAndCorrectWallLength(t.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var t,i,s,n,o,a,h,l,c;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),this.cleanupDragEventListeners(),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),this.wallLine&&this.wallLine.off("pointerdown",this.handleWallLinePointerDown),(t=this.wallLineClickHandler)==null||t.destroy(),this.wallLineClickHandler=null,(i=this.wallLine)==null||i.destroy(),(s=this.lengthText)==null||s.destroy(),(n=this.outlineBorder)==null||n.destroy(),(o=this.moveLine)==null||o.destroy(),(a=this.controlButtons)==null||a.destroy(),(h=this.removeButton)==null||h.destroy(),(l=this.scaleButton)==null||l.destroy(),(c=this.moveButton)==null||c.destroy(),this.removeButton=null,this.scaleButton=null,this.moveButton=null,super.destroy()}};g(Vt,"BUTTON_INDICES",{REMOVE:0,SCALE:2,MOVE:3});let ar=Vt;class Yr extends L{constructor(t){super();g(this,"spotData");g(this,"spotConfig");g(this,"controlsConfig");g(this,"spotEvents");g(this,"appService");g(this,"controlFill");g(this,"spotBorder");g(this,"centerIcon");g(this,"sizeText");g(this,"clickHandler",null);g(this,"initialSpotPoint",null);g(this,"dragStartMousePosition",null);g(this,"throttledUpdateScale");g(this,"unsubscribeMapRotation",null);g(this,"handleDragStart",t=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(t.global),this.appService.getApp().requestRender("spot-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartMousePosition.x,n=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var t,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(t=this.spotEvents).onUpdate)==null||i.call(t,this.getSpotData())});const{appService:i,spotData:s,events:n={}}=t;this.appService=i,this.spotData=s,this.spotEvents=n,this.controlsConfig=this.appService.controlsConfig,this.spotConfig=this.appService.controlsConfig.spot,this.position.set(s.point.x,s.point.y),this.throttledUpdateScale=Ct(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()}isEditingEnabled(){return this.appService.runtimeSnapshot.editingSpotIds.includes(this.spotData.id)}shouldShowIcon(){return(this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal).showIcon}calculateRectanglePoints(){const{size:t}=this.spotConfig;if(t===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.metersToPixels(t)/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const t=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(t),this.addChild(this.controlFill),this.spotBorder=this.createBorder(t),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.drawSpot()}createControlFill(t){const i=this.isEditingEnabled();return new Ur(this.appService,{points:t,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(t){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new Nt(this.appService,{points:t,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const t=new Xt(this.appService);return this.loadIconTexture(t),t.position.set(0,0),t.eventMode="static",this.setupIconDrag(t),t.visible=!1,t}async loadIconTexture(t){const{iconSize:i,iconSizeFixed:s}=this.spotConfig;await t.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)})),t.visible=this.shouldShowIcon()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}setupIconDrag(t){let i=null,s=!1;const n=h=>{if(!s||!this.initialSpotPoint||!i)return;const l=this.parent.toLocal(h.global),c=l.x-i.x,d=l.y-i.y;this.applyTranslation(c,d)},o=()=>{s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),this.appService.emitter.off("gestureHijackPointerMove",n),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.off("gestureHijackCancel",o))},a=()=>{var h,l;s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),(l=(h=this.spotEvents).onUpdate)==null||l.call(h,this.getSpotData()),this.appService.emitter.off("gestureHijackPointerMove",n),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.off("gestureHijackCancel",o))};t.on("pointerdown",h=>{this.isEditingEnabled()&&(h.stopPropagation(),s=!0,this.initialSpotPoint={...this.spotData.point},i=this.parent.toLocal(h.global),this.appService.getApp().requestRender("spot-drag",!0),this.appService.emitter.emit("gestureHijackStart",h),this.appService.emitter.on("gestureHijackPointerMove",n),this.appService.emitter.on("gestureHijackPointerUp",a),this.appService.emitter.on("gestureHijackCancel",o))})}createSizeText(){const t=this.calculateSpotSizeText(),i=new ji(this.appService,{text:t,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:t}=this.spotConfig,i=this.appService.metersToDisplayUnit(t),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const t=this.calculateRectanglePoints();if(t.length<4)return{x:0,y:0};const[i,s,n,o]=t,{textPosition:a,textOffset:h}=this.spotConfig,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:c.x,y:c.y+l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2},d={x:c.x+l,y:c.y};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2},d={x:c.x,y:c.y+l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2},d={x:c.x-l,y:c.y};break}default:{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:c.x,y:c.y+l};break}}return d}applyTranslation(t,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+t,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const t=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new vt(t,{onClick:()=>{var i,s;this.isEditingEnabled()||(this.appService.emitter.emit("suppressMapClick"),(s=(i=this.spotEvents)==null?void 0:i.onClick)==null||s.call(i,this.getSpotData()))},stopPropagation:!1}),this.eventMode="static"}drawSpot(){const t=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(t),this.spotBorder&&this.spotBorder.updatePoints(t)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText()}updateSizeText(){if(!this.sizeText)return;const t=this.calculateSpotSizeText();this.sizeText.updateText(t),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y)}updateEditState(){const t=this.isEditingEnabled(),i=t?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=t&&this.spotConfig.showText),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(t),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=t?1e3:0}updateSpotData(t){this.spotData={...t},this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var t,i,s,n,o;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(t=this.clickHandler)==null||t.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(),(n=this.centerIcon)==null||n.destroy(),(o=this.sizeText)==null||o.destroy(),super.destroy()}static create(t,i){return new Yr({appService:t,spotData:i,events:{onUpdate:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onUpdateSpot)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onClickSpot)==null||o.call(n,s)}}})}}class nS extends xc{constructor(t){const{appService:i,wayPointData:s,order:n,events:o={}}=t;super(i);g(this,"wayPointData");g(this,"order");g(this,"wayPointConfig");g(this,"controlsConfig");g(this,"wayPointEvents");g(this,"icon");g(this,"orderContainer");g(this,"orderBackground");g(this,"orderText");g(this,"clickHandler",null);g(this,"initialWayPointPoint",null);g(this,"unsubscribeMapRotation",null);this.wayPointData=s,this.order=n,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 t=new Xt(this.appService);return this.loadIconTexture(t),t.position.set(0,0),t.anchor.set(.5,1),t.eventMode="static",this.setupIconDrag(t),t}async loadIconTexture(t){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:n}=s,o=i?"wayPointActive":"wayPoint";await t.loadTextureAndSetSize(o,{width:n,height:n,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),t.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:n}=i;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Bs({text:this.order.toString(),style:new ce({fontSize:n.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fill:n.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:n}=i.orderContainer;this.orderContainer.position.set(s,-n)}setupIconDrag(t){let i=null,s=null,n=!1;const o=h=>{if(!(!n||!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;n&&(n=!1,i=null,s=null,(l=(h=this.wayPointEvents).onUpdate)==null||l.call(h,this.wayPointData),this.appService.emitter.off("gestureHijackPointerMove",o),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.emit("gestureHijackCancel"))};t.on("pointerdown",h=>{this.isEditingEnabled()&&(h.stopPropagation(),s={...this.wayPointData.point},this.parent&&(i=this.parent.toLocal(h.global)),n=!0,this.parent&&(this.appService.emitter.emit("gestureHijackStart",h),this.appService.emitter.on("gestureHijackPointerMove",o),this.appService.emitter.on("gestureHijackPointerUp",a)))})}setupClickHandler(){this.clickHandler=new vt(this.icon,{stopPropagation:!1,onClick:()=>{var t,i;this.appService.emitter.emit("suppressMapClick"),(i=(t=this.wayPointEvents).onClick)==null||i.call(t,this.wayPointData)}})}updateWayPoint(t){this.wayPointData=t,this.drawWayPoint()}updateOrder(t){this.order=t,this.orderText&&(this.orderText.text=t.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 ce({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor:n}=i.orderContainer;this.orderBackground.clear(),this.orderBackground.circle(0,0,s/2).fill(n),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 Ka extends H{constructor(t,i){super();g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"initialPosition");g(this,"handleDragPointerMove",t=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y,o={x:this.initialPosition.x+s,y:this.initialPosition.y+n};this.position.set(o.x,o.y),(h=(a=this.options).onDragMove)==null||h.call(a,o)});g(this,"handleDragPointerUp",()=>{var i,s;if(!this.isDragging)return;const t=this.appService;this.isDragging=!1,this.dragStartPosition=null,t.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});g(this,"handleDragCancel",()=>{var i,s;if(!this.isDragging)return;const t=this.appService;this.isDragging=!1,this.dragStartPosition=null,t.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=t,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(),this.setupDragEventListeners()}draw(){const t=this.appService,{config:i}=this.options,s=t.getApp().toFixedSize(i.endPointSize),n=t.getApp().toFixedSize(i.endPointStrokeWidth);this.clear(),this.circle(0,0,s/2),this.fill({color:i.endPointColor}),this.stroke({color:i.endPointStrokeColor,width:n}),this.setupHitArea()}setupHitArea(){const t=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),n=t.getApp().toFixedSize(s);this.hitArea=new Rs(0,0,n)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}handlePointerDown(t){t.stopPropagation(),this.startDragging(t)}startDragging(t){var s,n;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(t.global),this.initialPosition={x:this.x,y:this.y},(n=(s=this.options).onDragStart)==null||n.call(s),i.getApp().requestRender("endpoint-drag",!0),this.appService.emitter.emit("gestureHijackStart",t)}updatePosition(t){this.position.set(t.x,t.y),this.initialPosition={...t}}getPosition(){return{x:this.x,y:this.y}}redraw(){this.draw()}destroy(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class rS extends L{constructor(t){super();g(this,"endPoints");g(this,"dividerConfig");g(this,"dividerEvents");g(this,"roomId");g(this,"appService");g(this,"roomGeometry",null);g(this,"dashLine");g(this,"solidLine",null);g(this,"startEndPoint");g(this,"endEndPoint");g(this,"solidLinePoints",null);g(this,"initialDividerPoints",[]);g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"throttledHandleScaleChange");g(this,"handleEndPointDragStart",()=>{this.initialDividerPoints=this.endPoints.map(t=>({...t})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});g(this,"handleEndPointDragMove",(t,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[t]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});g(this,"handleEndPointDragEnd",()=>{var t,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints())});g(this,"handleDashLinePointerDown",t=>{t.stopPropagation(),this.startDragging(t)});g(this,"handleDragPointerMove",t=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.endPoints=this.initialDividerPoints.map(o=>({x:o.x+s,y:o.y+n})),this.updateAllComponents()});g(this,"handleDragPointerUp",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints()))});g(this,"handleDragCancel",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints()))});g(this,"handleScaleChange",()=>{var t,i;(t=this.startEndPoint)==null||t.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:n,events:o={}}=t;this.appService=i,this.dividerEvents=o,this.roomId=n,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=Ct(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener(),this.setupDragEventListeners()}validateDividerPoints(t){if(t.length>=2)return t.slice(0,2);const i=t[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 t=this.appService.getApp().mapState;if(!t)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),n=this.dividerConfig.defaultDirection,o=i.x+i.width/2,a=i.y+i.height/2,h=n==="horizontal"?i.width+2*s:i.height+2*s;return Ay(o,a,h,n).map(c=>({x:c.x-t.origin.x,y:c.y-t.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const t=this.endPoints;if(t.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:n}=this.dividerConfig;this.dashLine=new Ue(this.appService,{start:t[0],end:t[1],style:{color:n.toString(),width:i,dashArray:s}})}createEndPoints(){const t=this.endPoints;this.startEndPoint=new Ka(this.appService,{position:t[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new Ka(this.appService,{position:t[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 t=this.endPoints;if(t.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),n=rc(t[0],t[1],s);if(n.length===0)return;const o=new Te(n);this.dashLine.hitArea=o}startDragging(t){this.isDragging=!0;const i=this.parent.toLocal(t.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.appService.emitter.emit("gestureHijackStart",t)}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const t=this.endPoints;t.length<2||!this.dashLine||this.dashLine.updatePoints(t[0],t[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:t,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(t);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 t=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(t[0]),this.endEndPoint&&this.endEndPoint.updatePosition(t[1])}registerScaleListener(){const{emitter:t}=this.appService;t.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 t=this.appService.mapManager.roomFill;return!t||typeof this.roomId!="number"?null:t.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const t=this.endPoints;if(t.length<2||typeof this.roomId!="number")return null;const[i,s]=t,n=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(n||o)return null;const a=dy(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 Q(l,c)<3?null:Py(l,c,.5)}isPointInRoomFill(t){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:t.x+i.origin.x,y:t.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(t){t.x-=.5,t.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const n=s.getRasterRoomData(this.roomId);if(!n)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(t.x),h=Math.round(t.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<n.pixelIndices.length;c++)if(n.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(t){const i={x:Math.round(t.x),y:Math.round(t.y)},s=this.appService.getApp().mapState,n=this.appService.mapManager.getRoomById(this.roomId);return!s||!n||!n.outlinePoints?!1:Et(i,n.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:t}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const n={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!Cy(n,o,t.x,t.y,t.width,t.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:t}=this.appService.dividerConfig;t&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var t,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.endPoints)}updateComponents(){const t=this.endPoints;t.length>=2&&(this.dashLine.updatePoints(t[0],t[1]),this.startEndPoint.position.set(t[0].x,t[0].y),this.endEndPoint.position.set(t[1].x,t[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:t,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(t);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(t){this.endPoints=this.validateDividerPoints(t),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var t,i,s;this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.cleanupDragEventListeners(),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[]),this.dashLine&&this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.clearSolidLine(),(t=this.dashLine)==null||t.destroy(),(i=this.startEndPoint)==null||i.destroy(),(s=this.endEndPoint)==null||s.destroy(),super.destroy()}}const hr=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","wayPoint","divider"];function oS(r){if(!r||r.length===0)return[...hr];const e=new Set,t=[];for(const i of r)e.has(i)||(e.add(i),t.push(i));for(const i of hr)e.has(i)||t.push(i);return t}class aS{constructor(e){g(this,"zoneMaps",new Map);g(this,"virtualWallMap",new Map);g(this,"spotMap",new Map);g(this,"wayPointMap",new Map);g(this,"divider",null);g(this,"controlContainers",new Map);g(this,"unsubscribeFns",[]);g(this,"builtinZoneFactories",{forbiddenSweepZone:e=>Vr.create(this.appService,e),forbiddenMopZone:e=>Nr.create(this.appService,e),cleanZone:e=>jr.create(this.appService,e)});this.appService=e,this.initializeControlContainers();const t=W(e.runtime,"editingForbiddenSweepZoneIds",u=>{w.log(`[runtime] editingForbiddenSweepZoneIds: ${u}`);const p=this.zoneMaps.get("forbiddenSweepZone");p&&this.updateZonesEditState(p)}),i=W(e.runtime,"editingForbiddenMopZoneIds",u=>{w.log(`[runtime] editingForbiddenMopZoneIds: ${u}`);const p=this.zoneMaps.get("forbiddenMopZone");p&&this.updateZonesEditState(p)}),s=W(e.runtime,"editingCleanZoneIds",u=>{w.log(`[runtime] editingCleanZoneIds: ${u}`);const p=this.zoneMaps.get("cleanZone");p&&this.updateZonesEditState(p)}),n=W(e.runtime,"editingCustomZoneIds",u=>{w.log(`[runtime] editingCustomZoneIds: ${JSON.stringify(u??{})}`);for(const[p,f]of this.zoneMaps)Ne(p)||f.size&&this.updateZonesEditState(f)}),o=W(e.runtime,"editingVirtualWallIds",u=>{w.log(`[runtime] editingVirtualWallIds: ${u}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),a=W(e.runtime,"editingSpotIds",u=>{w.log(`[runtime] editingSpotIds: ${u}`),this.updateSpotsEditState(this.spotMap)}),h=W(e.runtime,"editingWayPointIds",u=>{w.log(`[runtime] editingWayPointIds: ${u}`),this.updateWayPointsEditState(this.wayPointMap)}),l=W(e.runtime,"dividingRoomId",u=>{w.log(`[runtime] dividingRoomId: ${u}`),this.handleDividingRoomIdChange(u)}),c=W(e.runtime,"unit",u=>{w.log(`[runtime] unit changed: ${u}`),this.handleUnitChange()}),d=W(e.runtime,"unitLabel",u=>{w.log(`[runtime] unitLabel changed: ${u}`),this.handleUnitChange()});this.unsubscribeFns.push(t,i,s,n,o,a,h,l,c,d)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const e=this.appService.appContainer.getLayer(Ke);if(!e){w.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const t of hr){const i=new L;i.label=`controls:${t}`,this.controlContainers.set(t,i),e.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const e=this.appService.appContainer.getLayer(Ke);if(!e)return;oS(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const n=this.controlContainers.get(i);n&&(n.zIndex=s)}),e.sortableChildren=!0,e.sortChildren()}addToControlLayer(e,t){let i=this.controlContainers.get(e);if(!i){const s=this.appService.appContainer.getLayer(Ke);if(!s){w.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new L,i.label=`controls:${e}`,this.controlContainers.set(e,i),s.addChild(i),this.applyRenderOrder()}i.addChild(t)}drawForbiddenSweepZones(e){this.drawZonesByType("forbiddenSweepZone",e)}getForbiddenSweepZones(){return this.getZonesDataByType("forbiddenSweepZone")}clearAllForbiddenSweepZones(){this.clearAllZonesByType("forbiddenSweepZone")}drawForbiddenMopZones(e){this.drawZonesByType("forbiddenMopZone",e)}getForbiddenMopZones(){return this.getZonesDataByType("forbiddenMopZone")}clearAllForbiddenMopZones(){this.clearAllZonesByType("forbiddenMopZone")}drawCleanZones(e){this.drawZonesByType("cleanZone",e)}getCleanZones(){return this.getZonesDataByType("cleanZone")}clearAllCleanZones(){this.clearAllZonesByType("cleanZone")}drawVirtualWalls(e){var n;const t=this.appService,i=this.virtualWallMap,s=new Set(e.map(o=>o.id));for(const[o,a]of i)s.has(o)||((n=a.parent)==null||n.removeChild(a),a.destroy(),i.delete(o));e.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new ar({appService:t,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=t.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=t.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=t.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(e){const t=this.spotMap;if(!e||e.length===0){this.clearAllSpotsInternal(t);return}const i=new Set(t.keys()),s=new Set(e.map(n=>n.id));for(const n of i)s.has(n)||this.removeSpot(n,t);e.forEach(n=>{const o=t.get(n.id);o?this.isSpotDataEqual(o.getSpotData(),n)||o.updateSpotData(n):this.addNewSpot(n,t)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}getZoneMap(e){let t=this.zoneMaps.get(e);return t||(t=new Map,this.zoneMaps.set(e,t)),t}resolveZoneFactory(e){var s;const t=this.builtinZoneFactories[e];return t||((s=this.appService.getConfig().customZoneTypes)!=null&&s[e]?n=>new oi({appService:this.appService,zoneData:n,zoneType:e,events:{onRemove:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onRemoveCustomZone)==null?void 0:h.call(a,e,o)},onUpdate:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onUpdateCustomZone)==null?void 0:h.call(a,e,o)},onClick:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onClickCustomZone)==null?void 0:h.call(a,e,o)}}}):null)}drawCustomZones(e,t){this.drawZonesByType(e,t)}getCustomZones(e){return this.getZonesDataByType(e)}clearCustomZones(e){this.clearAllZonesByType(e)}drawZonesByType(e,t){const i=this.resolveZoneFactory(e);if(!i){w.warn(`[ControlsManager] Unknown zone type: ${e}`);return}const s=this.getZoneMap(e);this.drawZonesImpl(t,s,i,e)}getZonesDataByType(e){const t=this.zoneMaps.get(e);return t?this.getZonesData(t):[]}clearAllZonesByType(e){const t=this.zoneMaps.get(e);t&&this.clearAllZones(t)}drawZonesImpl(e,t,i,s){if(!e||e.length===0){this.clearAllZones(t);return}const n=new Set(t.keys()),o=new Set(e.map(a=>a.id));for(const a of n)o.has(a)||this.removeZone(a,t);e.forEach(a=>{const h=t.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,t,i,s)})}addNewZone(e,t,i,s){const n=i(e);t.set(e.id,n),this.addToControlLayer(s,n)}removeZone(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getZonesData(e){const t=[];return e.forEach(i=>{t.push(i.getZoneData())}),t}clearAllZones(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateZonesEditState(e){e.forEach(t=>{t.updateEditState()})}updateVirtualWallsEditState(e){e.forEach(t=>{t.updateEditingState()})}isZoneDataEqual(e,t){if(e.id!==t.id||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++){const s=e.points[i],n=t.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}getWallsData(e){return Array.from(e.values()).map(t=>t.getWallData())}clearAllWalls(e){for(const t of e.values())t.destroy();e.clear()}isWallDataEqual(e,t){if(e.id!==t.id||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++){const s=e.points[i],n=t.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}addNewSpot(e,t){const i=Yr.create(this.appService,e);t.set(e.id,i),this.addToControlLayer("spot",i)}removeSpot(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getSpotsData(e){const t=[];return e.forEach(i=>{t.push(i.getSpotData())}),t}clearAllSpotsInternal(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateSpotsEditState(e){e.forEach(t=>{t.updateEditState()})}isSpotDataEqual(e,t){if(e.id!==t.id)return!1;const i=e.point,s=t.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}drawWayPoints(e){w.log("[ControlsManager] drawWayPoints",e);const t=Array.from(this.wayPointMap.keys()),i=e.map(n=>n.id);t.filter(n=>!i.includes(n)).forEach(n=>{this.removeWayPoint(n,this.wayPointMap)}),e.forEach((n,o)=>{const a=o+1,h=this.wayPointMap.get(n.id);h?(this.isWayPointDataEqual(h.getWayPointData(),n)||h.updateWayPoint(n),h.updateOrder(a)):this.addNewWayPoint(n,a,this.wayPointMap)})}clearAllWayPoints(){w.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(e,t,i){var o,a;const s=this.appService,n=new nS({appService:s,wayPointData:e,order:t,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(e.id,n),this.addToControlLayer("wayPoint",n)}removeWayPoint(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getWayPointsData(e){const t=[];return e.forEach(i=>{t.push(i.getWayPointData())}),t}clearAllWayPointsInternal(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateWayPointsEditState(e){e.forEach(t=>{t.onEditStateChange()})}isWayPointDataEqual(e,t){if(e.id!==t.id)return!1;const i=e.point,s=t.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(e){if(e==null||e===-1){this.clearDivider();return}if(!this.getRoomGeometry(e)){this.clearDivider();return}this.createDefaultDivider(e)}getRoomGeometry(e){return this.appService.mapManager.getRoomById(e)}createDefaultDivider(e){const t=this.appService;this.clearDivider(),this.divider=new rS({appService:this.appService,roomId:e,events:{onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateDivider)==null||n.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var e;this.divider&&((e=this.divider.parent)==null||e.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 e of this.zoneMaps.values())e.forEach(t=>{t.refreshDisplay()});this.virtualWallMap.forEach(e=>{e.refreshDisplay()}),this.spotMap.forEach(e=>{e.refreshDisplay()})}destroy(){for(const e of this.zoneMaps.keys())this.clearAllZonesByType(e);this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearDivider(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[],this.controlContainers.forEach(e=>{e.removeFromParent(),e.destroy({children:!0})}),this.controlContainers.clear()}}class hS extends Xt{constructor(t,i){super(t);g(this,"objectData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);this.appService=t,this.objectData=i}async initializeSprite(){const t=this.appService.detectedObjectConfig,i=this.objectData.width||t.width,s=this.objectData.height||t.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(t.anchor.x,t.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)}),t.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickDetectedObject)==null||i.call(t,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(t){const i=this.objectData;this.objectData=t;const s=this.appService.detectedObjectConfig;if(i.src!==t.src){const n=t.width||s.width,o=t.height||s.height;await this.loadTextureAndSetSize(t.src,{width:n,height:o})}if(i.width!==t.width||i.height!==t.height){const n=t.width||s.width,o=t.height||s.height;this.setFixedSize(n,o)}this.position.set(t.x,t.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(t){return this.objectData.id===t.id&&this.objectData.src===t.src&&this.objectData.x===t.x&&this.objectData.y===t.y&&this.objectData.width===t.width&&this.objectData.height===t.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class lS{constructor(e){g(this,"detectedObjectMap",new Map);g(this,"unsubscribeShowDetectedObjects",null);this.appService=e,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=W(this.appService.runtime,"showDetectedObjects",t=>{this.applyLayerVisibility(t)})}async drawDetectedObjects(e){if(!e||e.length===0){this.clearAllDetectedObjects();return}const t=new Set(e.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)t.has(s)||this.removeDetectedObject(s);for(const s of e){const n=this.detectedObjectMap.get(s.id);n?n.isSameData(s)||await n.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer(Ye);t&&(t.visible=e)}clearAllDetectedObjects(){const e=this.appService;this.detectedObjectMap.forEach(t=>{e.appContainer.removeFromLayer(Ye,t),t.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(e){const t=this.appService,i=new hS(this.appService,e);await i.initializeSprite(),this.detectedObjectMap.set(e.id,i),t.appContainer.addToLayer(Ye,i)}removeDetectedObject(e){const t=this.appService,i=this.detectedObjectMap.get(e);i&&(t.appContainer.removeFromLayer(Ye,i),i.destroy(),this.detectedObjectMap.delete(e))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var Re={},vc={},te={};Object.defineProperty(te,"__esModule",{value:!0});te.loop=te.conditional=te.parse=void 0;var cS=function r(e,t){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(t))t.forEach(function(o){return r(e,o,i,s)});else if(typeof t=="function")t(e,i,s,r);else{var n=Object.keys(t)[0];Array.isArray(t[n])?(s[n]={},r(e,t[n],i,s[n])):s[n]=t[n](e,i,s,r)}return i};te.parse=cS;var dS=function(e,t){return function(i,s,n,o){t(i,s,n)&&o(i,e,s,n)}};te.conditional=dS;var uS=function(e,t){return function(i,s,n,o){for(var a=[],h=i.pos;t(i,s,n);){var l={};if(o(i,e,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};te.loop=uS;var ut={};Object.defineProperty(ut,"__esModule",{value:!0});ut.readBits=ut.readArray=ut.readUnsigned=ut.readString=ut.peekBytes=ut.readBytes=ut.peekByte=ut.readByte=ut.buildStream=void 0;var pS=function(e){return{data:e,pos:0}};ut.buildStream=pS;var bc=function(){return function(e){return e.data[e.pos++]}};ut.readByte=bc;var fS=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(t){return t.data[t.pos+e]}};ut.peekByte=fS;var Os=function(e){return function(t){return t.data.subarray(t.pos,t.pos+=e)}};ut.readBytes=Os;var gS=function(e){return function(t){return t.data.subarray(t.pos,t.pos+e)}};ut.peekBytes=gS;var mS=function(e){return function(t){return Array.from(Os(e)(t)).map(function(i){return String.fromCharCode(i)}).join("")}};ut.readString=mS;var yS=function(e){return function(t){var i=Os(2)(t);return e?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};ut.readUnsigned=yS;var xS=function(e,t){return function(i,s,n){for(var o=typeof t=="function"?t(i,s,n):t,a=Os(e),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};ut.readArray=xS;var SS=function(e,t,i){for(var s=0,n=0;n<i;n++)s+=e[t+n]&&Math.pow(2,i-n-1);return s},vS=function(e){return function(t){for(var i=bc()(t),s=new Array(8),n=0;n<8;n++)s[7-n]=!!(i&1<<n);return Object.keys(e).reduce(function(o,a){var h=e[a];return h.length?o[a]=SS(s,h.index,h.length):o[a]=s[h.index],o},{})}};ut.readBits=vS;(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var e=te,t=ut,i={blocks:function(u){for(var p=0,f=[],y=u.data.length,m=0,x=(0,t.readByte)()(u);x!==p&&x;x=(0,t.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;f.push((0,t.readBytes)(S)(u)),m+=S;break}f.push((0,t.readBytes)(x)(u)),m+=x}for(var v=new Uint8Array(m),b=0,P=0;P<f.length;P++)v.set(f[P],b),b+=f[P].length;return v}},s=(0,e.conditional)({gce:[{codes:(0,t.readBytes)(2)},{byteSize:(0,t.readByte)()},{extras:(0,t.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,t.readUnsigned)(!0)},{transparentColorIndex:(0,t.readByte)()},{terminator:(0,t.readByte)()}]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),n=(0,e.conditional)({image:[{code:(0,t.readByte)()},{descriptor:[{left:(0,t.readUnsigned)(!0)},{top:(0,t.readUnsigned)(!0)},{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{lct:(0,t.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,e.conditional)({lct:(0,t.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,t.readByte)()},i]}]},function(d){return(0,t.peekByte)()(d)===44}),o=(0,e.conditional)({text:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{preData:function(u,p,f){return(0,t.readBytes)(f.text.blockSize)(u)}},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,e.conditional)({application:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{id:function(u,p,f){return(0,t.readString)(f.blockSize)(u)}},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,e.conditional)({comment:[{codes:(0,t.readBytes)(2)},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,t.readString)(3)},{version:(0,t.readString)(3)}]},{lsd:[{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{gct:(0,t.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,t.readByte)()},{pixelAspectRatio:(0,t.readByte)()}]},(0,e.conditional)({gct:(0,t.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,e.loop)([s,a,h,n,o],function(d){var u=(0,t.peekByte)()(d);return u===33||u===44})}],c=l;r.default=c})(vc);var Gs={};Object.defineProperty(Gs,"__esModule",{value:!0});Gs.deinterlace=void 0;var bS=function(e,t){for(var i=new Array(e.length),s=e.length/t,n=function(u,p){var f=e.slice(p*t,(p+1)*t);i.splice.apply(i,[u*t,t].concat(f))},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])n(c,h),h++;return i};Gs.deinterlace=bS;var Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});Ws.lzw=void 0;var wS=function(e,t,i){var s=4096,n=-1,o=i,a,h,l,c,d,u,p,C,f,y,P,m,A,k,T,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=e,h=1<<m,d=h+1,a=h+2,p=n,c=m+1,l=(1<<c)-1,f=0;f<h;f++)S[f]=0,v[f]=f;var P,C,A,k,M,T;for(P=C=A=k=M=T=0,y=0;y<o;){if(k===0){if(C<c){P+=t[T]<<C,C+=8,T++;continue}if(f=P&l,P>>=c,C-=c,f>a||f==d)break;if(f==h){c=m+1,l=(1<<c)-1,a=h+2,p=n;continue}if(p==n){b[k++]=v[f],p=f,A=f;continue}for(u=f,f==a&&(b[k++]=A,f=p);f>h;)b[k++]=v[f],f=S[f];A=v[f]&255,b[k++]=A,a<s&&(S[a]=p,v[a]=A,a++,!(a&l)&&a<s&&(c++,l+=a)),p=u}k--,x[M++]=b[k],y++}for(y=M;y<o;y++)x[y]=0;return x};Ws.lzw=wS;Object.defineProperty(Re,"__esModule",{value:!0});var wc=Re.decompressFrames=Re.decompressFrame=Cc=Re.parseGIF=void 0,CS=TS(vc),AS=te,PS=ut,MS=Gs,_S=Ws;function TS(r){return r&&r.__esModule?r:{default:r}}var kS=function(e){var t=new Uint8Array(e);return(0,AS.parse)((0,PS.buildStream)(t),CS.default)},Cc=Re.parseGIF=kS,RS=function(e){for(var t=e.pixels.length,i=new Uint8ClampedArray(t*4),s=0;s<t;s++){var n=s*4,o=e.pixels[s],a=e.colorTable[o]||[0,0,0];i[n]=a[0],i[n+1]=a[1],i[n+2]=a[2],i[n+3]=o!==e.transparentIndex?255:0}return i},Ac=function(e,t,i){if(!e.image){console.warn("gif frame does not have associated image.");return}var s=e.image,n=s.descriptor.width*s.descriptor.height,o=(0,_S.lzw)(s.data.minCodeSize,s.data.blocks,n);s.descriptor.lct.interlaced&&(o=(0,MS.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=t,e.gce&&(a.delay=(e.gce.delay||10)*10,a.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(a.transparentIndex=e.gce.transparentColorIndex)),i&&(a.patch=RS(a)),a};Re.decompressFrame=Ac;var ES=function(e,t){return e.frames.filter(function(i){return i.image}).map(function(i){return Ac(i,e.gct,t)})};wc=Re.decompressFrames=ES;class Us{constructor(e){if(!e||!e.length)throw new Error("Invalid frames");const[{texture:{width:t,height:i}}]=e;this.width=t,this.height=i,this.frames=e,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const e of this.textures)e.destroy(!0);for(const e of this.frames)e.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(e,t){if(!e||e.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=Cc(e);i(s);const n=wc(s,!0),o=[],a=s.lsd.width,h=s.lsd.height,l=j.get().createCanvas(a,h),c=l.getContext("2d",{willReadFrequently:!0}),d=j.get().createCanvas(),u=d.getContext("2d");let p=0,f=null;const{fps:y=30,...m}=t??{},x=1e3/y;for(let S=0;S<n.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:C,height:A,left:k,top:M}}=n[S];d.width=C,d.height=A,u.clearRect(0,0,C,A);const T=u.createImageData(C,A);T.data.set(P),u.putImageData(T,0,0),v===3&&(f=c.getImageData(0,0,a,h)),c.drawImage(d,k,M);const _=c.getImageData(0,0,a,h);v===2?c.clearRect(0,0,a,h):v===3&&c.putImageData(f,0,0);const E=j.get().createCanvas(_.width,_.height);E.getContext("2d").putImageData(_,0,0),o.push({start:p,end:p+b,texture:new G({source:new gr({resource:E,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new Us(o)}}const IS={extension:I.Asset,detection:{test:async()=>!0,add:async r=>[...r,"gif"],remove:async r=>r.filter(e=>e!=="gif")},loader:{name:"gifLoader",id:"gif",test:r=>Mt.extname(r)===".gif"||r.startsWith("data:image/gif"),load:async(r,e)=>{const i=await(await j.get().fetch(r)).arrayBuffer();return Us.from(i,e==null?void 0:e.data)},unload:async r=>{r.destroy()}}},Pc=class lr extends jt{constructor(...e){const t=e[0]instanceof Us?{source:e[0]}:e[0],{source:i,fps:s,loop:n,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},lr.defaultOptions,t);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:n,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&&(yt.shared.remove(this.update,this),this._isConnectedToTicker=!1))}play(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(yt.shared.add(this.update,this,Ie.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(e){var o,a;if(!this._playing)return;const t=this.animationSpeed*e.deltaTime/yt.targetFPMS,i=this._currentTime+t,s=i%this.duration,n=this._source.frames.findIndex(h=>h.start<=s&&h.end>s);i>=this.duration?this.loop?(this._currentTime=s,this._updateFrameIndex(n),(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(n))}_updateFrame(){this.dirty&&(this.texture=this._source.frames[this._currentFrame].texture,this.dirty=!1)}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,!this._autoUpdate&&this._isConnectedToTicker?(yt.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(yt.shared.add(this.update,this),this._isConnectedToTicker=!0))}get currentFrame(){return this._currentFrame}set currentFrame(e){this._updateFrameIndex(e),this._currentTime=this._source.frames[e].start}get source(){return this._source}_updateFrameIndex(e){var t;if(e<0||e>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${e}`);this._currentFrame!==e&&(this._currentFrame=e,this.dirty=!0,(t=this.onFrameChange)==null||t.call(this,e))}get totalFrames(){return this._source.totalFrames}destroy(e=!1){this.stop(),super.destroy(),e&&this._source.destroy();const t=null;this._source=t,this.onComplete=t,this.onFrameChange=t,this.onLoop=t}clone(){const e=new lr({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 e.dirty=!0,e}};Pc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let BS=Pc;$.add(IS);class Xr extends BS{constructor(t,i){super(i);g(this,"throttledUpdateScale");g(this,"fixedWidth",0);g(this,"fixedHeight",0);g(this,"isFixedSizeSet",!1);g(this,"sizeFixed",!0);g(this,"baselineScale",1);this.appService=t,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=Ct(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(t,i){this.fixedWidth=t,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(t){this.sizeFixed=t,this.baselineScale=1,t&&this.isFixedSizeSet?this.applySize():!t&&this.isFixedSizeSet&&this.applySize()}set width(t){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(t,this.fixedHeight||t)}set height(t){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||t,t)}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 t=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const n=t/s,o=i/s;super.scale.set(n,o)}else super.scale.set(t/this.baselineScale,i/this.baselineScale)}updateScale(t){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():t!==0&&super.scale.set(1/t))}static async createFromSrc(t,i,s){try{const n=await N.load(i),o=new Xr(t,{source:n});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(n){throw w.error(`Failed to load GIF "${i}":`,n),n}}draw(t,i){const{x:s,y:n,rotation:o=0}=t;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,n)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class We extends Xr{constructor(t,i,s){super(t,{source:i});g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(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 t=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(t.x,t.y),this.position.set(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=W(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;if(this.elementData=t,i.src!==t.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),(i.width!==t.width||i.height!==t.height)&&this.setFixedSize(t.width,t.height);const s=t.anchor||{x:.5,y:.5},n=i.anchor||{x:.5,y:.5};(s.x!==n.x||s.y!==n.y)&&this.anchor.set(s.x,s.y),this.position.set(t.x,t.y),t.rotation!==void 0&&(this.userRotation=t.rotation,this.applyRotation(this.appService.runtime.mapRotation)),t.opacity!==void 0&&(this.alpha=t.opacity),t.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(t){const i=this.elementData.anchor||{x:.5,y:.5},s=t.anchor||{x:.5,y:.5};return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.src===t.src&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class Tn extends Xt{constructor(t,i){super(t);g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"userRotation",0);this.appService=t,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const t=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(t.x,t.y),this.position.set(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=W(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;this.elementData=t,i.src!==t.src?await this.loadTextureAndSetSize(t.src,{width:t.width,height:t.height,sizeFixed:t.sizeFixed}):(i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),(i.width!==t.width||i.height!==t.height)&&this.setFixedSize(t.width,t.height));const s=t.anchor||{x:.5,y:.5},n=i.anchor||{x:.5,y:.5};(s.x!==n.x||s.y!==n.y)&&this.anchor.set(s.x,s.y),this.position.set(t.x,t.y),t.rotation!==void 0&&(this.userRotation=t.rotation,this.applyRotation(this.appService.runtime.mapRotation)),t.opacity!==void 0&&(this.alpha=t.opacity),t.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(t){const i=this.elementData.anchor||{x:.5,y:.5},s=t.anchor||{x:.5,y:.5};return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.src===t.src&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class DS extends Wg{constructor(t,i){super(i);g(this,"throttledUpdateScale");g(this,"fixedWidth",0);g(this,"fixedHeight",0);g(this,"isFixedSizeSet",!1);g(this,"userCenterX",0);g(this,"userCenterY",0);g(this,"sizeFixed",!0);this.appService=t,this.anchor.set(0,0),this.throttledUpdateScale=Ct(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(t,i){this.fixedWidth=t,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(t,i){this.userCenterX=t,this.userCenterY=i,this.updatePositionFromCenter()}setSizeFixed(t){this.sizeFixed=t,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,n;this.sizeFixed?(s=this.fixedWidth/2/i,n=this.fixedHeight/2/i):(s=this.fixedWidth/2,n=this.fixedHeight/2),this.position.set(this.userCenterX-s,this.userCenterY-n)}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(t){this.isFixedSizeSet&&t!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(t){return super.updateTransform(t)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class Di extends DS{constructor(t,i){const s=document.createElement("div");Di.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(t,{element:s});g(this,"elementData");g(this,"domClickHandler",null);g(this,"resizeObserver",null);g(this,"debugMarker",null);g(this,"unsubscribeMapRotation",null);g(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.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",t=>{this.applyRotation(t)}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*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 t=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(t))};requestAnimationFrame(t)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(t=>{var s;const i=t[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 t=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(t);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(t)};requestAnimationFrame(t)}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=t=>{t.preventDefault(),t.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;this.elementData=t,i.htmlContent!==t.htmlContent&&this.element&&(this.element.innerHTML=t.htmlContent,(!t.width||!t.height)&&this.waitForElementDimensions()),(i.width!==t.width||i.height!==t.height)&&(t.width&&t.height?(this.setFixedSize(t.width,t.height),this.element&&(this.element.style.width=`${t.width}px`,this.element.style.height=`${t.height}px`)):this.setupAutoSize()),t.width&&t.height?this.setCenterPosition(t.x,t.y):this.getIsFixedSizeSet()?this.setCenterPosition(t.x,t.y):this.position.set(t.x,t.y),i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),this.userRotation=t.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=t.opacity??1,t.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(t){return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.htmlContent===t.htmlContent&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed}static setupDefaultStyles(t,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(t.style,s),t.style.setProperty("-webkit-tap-highlight-color","transparent"),t.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 FS{constructor(e){g(this,"customElementsMap",new Map);g(this,"gifTicker",null);g(this,"gifElements",new Set);this.appService=e}async drawCustomElements(e){if(!e||e.length===0){this.clearAllCustomElements();return}const t=new Set(e.map(n=>n.id)),i=Array.from(this.customElementsMap.keys());for(const n of i)t.has(n)||this.removeCustomElement(n);const s=e.map(async n=>{const o=this.customElementsMap.get(n.id);o?this.isSameData(o,n)||(n.type==="gif"&&o.getElementData().src!==n.src?(this.removeCustomElement(n.id),await this.addNewCustomElement(n)):await this.updateElementData(o,n)):await this.addNewCustomElement(n)});await Promise.all(s),this.updateGifTicker()}clearAllCustomElements(){const e=this.appService;this.customElementsMap.forEach(t=>{t instanceof We?e.appContainer.removeFromLayer(Bi,t):e.appContainer.removeFromLayer(Ii,t),t.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(e){const t=this.appService;let i;switch(e.type){case"image":i=new Tn(this.appService,e);break;case"gif":{const s=await N.load(e.src);i=new We(this.appService,s,e);break}case"html":i=new Di(this.appService,e);break;default:throw new Error(`Unsupported custom element type: ${e.type}`)}await i.initialize(),this.customElementsMap.set(e.id,i),i instanceof We?(t.appContainer.addToLayer(Bi,i),this.gifElements.add(i)):t.appContainer.addToLayer(Ii,i)}removeCustomElement(e){const t=this.appService,i=this.customElementsMap.get(e);i&&(i instanceof We?(this.gifElements.delete(i),t.appContainer.removeFromLayer(Bi,i)):t.appContainer.removeFromLayer(Ii,i),i.destroy(),this.customElementsMap.delete(e))}isSameData(e,t){return e.getElementData().type!==t.type?!1:t.type==="image"&&e instanceof Tn||t.type==="gif"&&e instanceof We||t.type==="html"&&e instanceof Di?e.isSameData(t):!1}async updateElementData(e,t){if(t.type==="image"&&e instanceof Tn)await e.updateElementData(t);else if(t.type==="gif"&&e instanceof We)await e.updateElementData(t);else if(t.type==="html"&&e instanceof Di)await e.updateElementData(t);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var e;(e=this.gifTicker)!=null&&e.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new yt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var e;(e=this.gifTicker)!=null&&e.started&&(w.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const e=this.appService;if(this.gifElements.size===0)return;const t=e.getApp();t.renderer.render(t.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class zS extends L{constructor(t,i){super();g(this,"roomId");g(this,"roomIndex");g(this,"appService");g(this,"nameText");g(this,"iconSprite",null);g(this,"iconWrapper",null);g(this,"iconBg",null);this.appService=t,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:n}=t.roomConfig,{showRoomType:o}=t.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new ce({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Bs({text:c,style:l}),this.nameText.anchor.set(.5),o&&i.type!=null&&(n!=null&&n.assets)&&n.assets[i.type]&&this.createIcon(i.type,h),this.addChild(this.nameText),this.layout()}createIcon(t,i){const{type:s}=this.appService.roomConfig,n=s.iconSize||14;this.iconWrapper||(this.iconWrapper=new L,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 Xt(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(n,n),this.iconSprite.loadTextureAndSetSize(s.assets[t],{width:n,height:n,sizeFixed:!1}).then(()=>{this.iconSprite&&(this.iconSprite.visible=this.appService.runtime.showRoomType,this.layout())}),s.container&&this.iconSprite.position.set(0,0)}drawIconBg(t){const{type:i}=this.appService.roomConfig;if(!this.iconBg||!i.container.visible)return;const{size:s,borderRadius:n}=i.container;this.iconBg.clear().roundRect(-s/2,-s/2,s,s,n).fill(t)}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,n=this.nameText.width,o=this.iconWrapper.width,h=-(o+i+n)/2;s==="left"?(this.iconWrapper.x=h+o/2,this.nameText.x=h+o+i+n/2):(this.nameText.x=h+n/2,this.iconWrapper.x=h+n+i+o/2),this.iconWrapper.y=0,this.nameText.y=0}updateName(t){this.nameText.text=t,this.layout()}refreshColor(t){const{type:i}=this.appService.roomConfig,s=this.appService.getRoomData(this.roomId),n=(s==null?void 0:s.colorIndex)??this.roomIndex,o=this.getRoomNameColor(n,t);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(t,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:n,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(n)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[t%s.nameInactive.length]:s.name[t%s.name.length];const a=s.nameNormal||s.name;return a[t%a.length]}async updateRoomType(t){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||t==null||!(i!=null&&i.assets)||!i.assets[t])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const n=this.appService.getRoomData(this.roomId),o=(n==null?void 0:n.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(t,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(t){if(this.iconWrapper)this.iconWrapper.visible=t,this.layout();else if(t){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(t){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),super.destroy(t)}}class LS extends L{constructor(t,i){super();g(this,"background");g(this,"foldedIndicator");g(this,"propertyIcons",new Map);g(this,"orderContainer");g(this,"orderBackground");g(this,"orderText");g(this,"isFolded",!1);g(this,"roomId");g(this,"roomIndex");g(this,"isDestroyed",!1);this.appService=t;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:n}=s,o=i.colorIndex??i.index,a=this.getIconColor(o);this.initializePropertyIcons(n.displayOrders,a);const h=n.cleanOrder.color==="auto"?s.colors.active[o%s.colors.active.length]:n.cleanOrder.color;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Bs({text:"",style:new ce({fontSize:n.cleanOrder.fontSize,fontFamily:n.cleanOrder.fontFamily,fontWeight:n.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(t,i){const s=["cleanMode","suction","cistern","cleanTimes"];t.forEach(n=>{const o=s.includes(n),a=new Xt(this.appService);a.tint=i,a.anchor.set(0,0),this.propertyIcons.set(n,{fieldName:n,sprite:a,isBuiltin:o})})}async updateProperty(t){this.isDestroyed||this.destroyed||(await this.updateIcons(t),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(t,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return t[i]??null;if(t.customData&&i in t.customData){const n=t.customData[i];return typeof n=="number"?n:null}return null}getAssetAlias(t,i){const s={cleanMode:n=>`cleanMode_${n}`,suction:n=>`fan_${n}`,cistern:n=>`water_${n}`,cleanTimes:n=>`cleanTimes${n}`};return t in s?s[t](i):`custom_${t}_${i}`}shouldShowField(t,i,s){const{showRoomProperty:n}=this.appService.runtimeSnapshot;return!(s===null||!n||i==="cleanTimes"&&s<=0)}getDisplayElements(t){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,n=t.order||0,o=s&&n>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(t,h);this.shouldShowField(t,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:n}}async updateIcons(t){if(this.isDestroyed||this.destroyed||this.isFolded)return;const{iconWidth:i,iconHeight:s,container:n,cleanOrder:o,iconGap:a}=this.appService.roomConfig.property,{paddingHorizontal:h,paddingVertical:l}=n,{elementsToShow:c,orderValue:d}=this.getDisplayElements(t);this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:f})=>{f.visible=!1});const u=[];if(c.forEach(f=>{if(f.isOrder){this.orderContainer.visible=!0,this.orderText.text=d.toString();const y=t.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(f.fieldName);if(y&&y.sprite){y.sprite.visible=!0;const m=this.getAssetAlias(f.fieldName,f.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((f,y)=>{const{element:m,isOrder:x}=f;!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 t=this.appService.roomConfig,{container:i,foldable:s}=t.property,{borderRadius:n,tailHeight:o,tailWidth:a,backgroundColor:h}=i,l=this.calculateContentWidth(),c=this.calculateContentHeight(),d=Math.min(n,l/2,c/2),u=d*.8,p=Math.max(l-u*2,a*.5),f=Math.min(a,l/2,p);if(this.background.clear(),this.background.setFillStyle({color:h}),s){const y=(l-f)/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+f,c),this.background.lineTo(y+f/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:t,container:i,cleanOrder:s,iconGap:n}=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+=t,d<h.length-1&&(u?l+=s.gapRight:l+=n)}),l+=o,l}calculateContentHeight(){const t=this.appService.roomConfig,{iconHeight:i,container:s}=t.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:t,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(t?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(t){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=t,t)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:t}=this.appService.roomConfig.property;return t?this.isFolded:!1}updateFoldedIndicator(){const t=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:n}=t.property.container,o=this.calculateContentWidth(),a=Math.min(s,o/2);this.foldedIndicator.clear(),this.foldedIndicator.setFillStyle({color:n}),this.foldedIndicator.poly([0,i,a,i,a/2,0]).fill(),this.foldedIndicator.position.set(0,0)}resolveOrderTextColor(t){const{property:i,colors:s}=this.appService.roomConfig,{enableRoomSelection:n}=this.appService.runtime;if(i.cleanOrder.color==="auto"){const o=n?s.active:s.normal||s.active;return o[t%o.length]}return i.cleanOrder.color}getIconColor(t){const{colors:i}=this.appService.roomConfig,{propertyTheme:s,propertyThemeInactive:n,propertyThemeNormal:o}=i,{enableRoomSelection:a,selectRoomIds:h}=this.appService.runtime;if(a)return!h.includes(this.roomId)&&n?n[t%n.length]:s[t%s.length];const l=o||s;return l[t%l.length]}refreshColor(){const t=this.appService.getRoomData(this.roomId),i=(t==null?void 0:t.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite:n})=>{n.tint=s}),this.orderBackground&&this.orderBackground.visible){const{property:n}=this.appService.roomConfig,o=n.iconWidth,a=n.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:t})=>{t.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0}))}}class OS extends L{constructor(t,i){super();g(this,"background");g(this,"checkmarkIcon");g(this,"bubble");g(this,"roomIndex");g(this,"roomId");this.appService=t;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon:n}}=s;this.checkmarkIcon=new Xt(this.appService);const o=i.colorIndex??i.index;this.checkmarkIcon.tint=n[o%n.length],this.checkmarkIcon.anchor.set(0,0),this.addChild(this.background),this.addChild(this.bubble),this.addChild(this.checkmarkIcon)}async updateIndicator(t){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:n}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=n.includes(t.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(t){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:n}=i;if(t){this.visible=!0,this.checkmarkIcon.visible=!0,await this.checkmarkIcon.loadTextureAndSetSize("checkmark",{width:s,height:n,sizeFixed:!1});const o=i.containerWidth/2,a=i.containerHeight/2;this.checkmarkIcon.position.set(o-s/2,a-n/2)}else this.visible=!1}updateBackground(){const{selectionIndicator:t,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:n,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=t,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],f=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,n,h).fill().setStrokeStyle({color:f,width:o,alignment:0}).stroke(),l>0&&c>0){const y=(s-c)/2;this.bubble.setFillStyle({color:f});const m=n+o;this.bubble.poly([y,m-1,y+c,m-1,y+c/2,m+l]).fill()}}getTotalHeight(){const{selectionIndicator:t}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:n}=t;return i+n+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:t}=this.appService.roomConfig;return t.containerWidth}async refreshColor(){const t=this.appService.getRoomData(this.roomId);t&&await this.updateIndicator(t)}destroy(){var t;(t=this.checkmarkIcon)==null||t.destroy(),super.destroy({children:!0})}}class GS extends L{constructor(t,i){super();g(this,"roomId");g(this,"roomName");g(this,"roomProperty",null);g(this,"roomSelectionIndicator",null);g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"targetElasticScale",1);g(this,"currentElasticScale",1);g(this,"isAnimatingScale",!1);g(this,"scaleAnimationBound",null);g(this,"updateScaleBound",null);this.appService=t,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(t.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 zS(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",s=>{this.applyAntiRotation(s)}),this.clickHandler=new vt(this,{onClick:()=>{var s,n;(n=(s=this.appService.events)==null?void 0:s.onClickRoomProperties)==null||n.call(s,i)}})}async initialize(t){await this.createRoomProperty(t),await this.createRoomSelectionIndicator(t),this.updateLayout()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}initializeElasticScale(t){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;t<=o?h=s:t>=a?h=n:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(t){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i){t!==0&&this.scale.set(1/t);return}if(t===0)return;const o=1,a=5;let h;t<=o?h=s:t>=a?h=n:h=1;const c=1/t*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 n=1/this.appService.currentScale*this.currentElasticScale;this.scale.set(n),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:t,showRoomProperty:i,selectRoomIds:s,enableRoomSelection:n,roomSelectionMode:o}=this.appService.runtimeSnapshot,a=this.appService.getRoomData(this.roomId);if(!a||n&&o==="checkmark"&&s.includes(this.roomId))return!1;const h=t&&(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:t,roomSelectionMode:i}=this.appService.runtimeSnapshot;return t&&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(t){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new LS(this.appService,t),await this.roomProperty.updateProperty(t),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(t){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new OS(this.appService,t),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,f;if(this.destroyed)return;const{property:{offsetY:t,offsetX:i},selectionIndicator:{offsetY:s,offsetX:n}}=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-t;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-t-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-t)}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+n,-s-y),this.roomName.position.set(0,0)):this.roomSelectionIndicator.position.set(-m/2+n,-y/2-s)}a&&!o&&!h&&((f=this.roomName)!=null&&f.position)&&this.roomName.position.set(0,0)}updateName(t){this.roomName.updateName(t)}async updateRoomType(t){await this.roomName.updateRoomType(t),this.updateLayout()}updateRoomNameVisibility(t){this.roomName.visible=t,this.updateLayout()}updateRoomTypeVisibility(t){this.roomName.updateRoomTypeVisibility(t),this.updateLayout()}updatePosition(t){this.position.set(t.x,t.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var t,i,s,n;(t=this.clickHandler)==null||t.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,(n=this.roomName)==null||n.destroy(),super.destroy()}}class WS extends L{constructor(t){super({isRenderGroup:!0});g(this,"floorTypeMap",new Map);g(this,"floorTypeMasks",new Map);g(this,"floorTypeContexts",new Map);g(this,"floorTypeToRooms",new Map);this.appService=t,this.appService.appContainer.addToLayer(Gr,this)}async createFloorTypes(t){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(t),n=[];for(const[o,a]of s)n.push(this.createMergedFloorType(o,a));await Promise.all(n)}groupRoomsByFloorType(t){const i=new Map,s=this.appService;return t.forEach((n,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:n}))}),i}async createMergedFloorType(t,i){const s=this.appService,{assets:n,opacity:o,scale:a}=s.roomConfig.floorType,h=t%n.length,l=`floorType${h}`;if(!n[h]){w.warn(`No texture asset configured for floorType: ${t}`);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=by(d),p=new bs({texture:c,width:u.width,height:u.height});p.autoGarbageCollect=!1,p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:f,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=f,this.addChild(p),this.floorTypeMap.set(t,p),this.floorTypeMasks.set(t,f),this.floorTypeContexts.set(t,y),this.floorTypeToRooms.set(t,new Set(i.map(({roomId:m})=>m)))}createMergedMask(t){const i=new L,s=[];return t.forEach(n=>{const o=new H;o.autoGarbageCollect=!1;const a=n.context.clone();a.autoGarbageCollect=!1,o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(t=>{try{t.destroy({children:!0})}catch(i){w.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(t=>{try{t.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(t=>{try{this.removeChild(t),t.destroy()}catch(i){w.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}class US{constructor(e){g(this,"unsubscribeFns",[]);g(this,"roomInfoContainer",new L);g(this,"roomInfoMap",new Map);g(this,"roomDisplayMap",new Map);g(this,"roomFloorType");this.appService=e,this.roomFloorType=new WS(e),e.appContainer.addToLayer(fc,this.roomInfoContainer);const t=W(e.runtime,"showRoomFloorType",d=>{w.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=W(e.runtime,"showRoomProperty",d=>{w.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=W(e.runtime,"showRoomOrder",d=>{w.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),n=W(e.runtime,"roomPropertyFoldIds",d=>{w.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=W(e.runtime,"showRoomName",d=>{w.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=W(e.runtime,"showRoomType",d=>{w.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=W(e.runtime,"enableRoomSelection",d=>{w.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=W(e.runtime,"selectRoomIds",d=>{w.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=W(e.runtime,"roomSelectionMode",d=>{w.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(t,i,s,n,o,a,h,l,c)}async drawRoomProperty(e){const t=this.appService;return this.roomDisplayMap.clear(),e.forEach((i,s)=>{const n=t.mapManager.getRoomById(i.id),o={...i,centerPoint:(n==null?void 0:n.centerPoint)||null,index:s,colorIndex:n==null?void 0:n.colorIndex};this.roomDisplayMap.set(i.id,o)}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes(),!0}async updateRoomInfoDisplay(){if(this.roomDisplayMap.size===0){this.appService.mapManager.getAllRooms().length===0&&this.clearRoomInfos();return}const e=Array.from(this.roomDisplayMap.values()).filter(t=>t.centerPoint!==null);this.clearRoomInfos(),await Promise.all(e.map(t=>this.createRoomInfo(t)))}async createRoomInfo(e){const t=new GS(this.appService,e);this.roomInfoContainer.addChild(t),this.roomInfoMap.set(e.id,t),await t.initialize(e)}updateRoomName(e,t){const i=this.roomInfoMap.get(e);i&&i.updateName(t)}async updateRoomType(e,t){const i=this.roomDisplayMap.get(e);i&&(i.type=t);const s=this.roomInfoMap.get(e);s&&await s.updateRoomType(t)}updateRoomPosition(e,t){const i=this.roomDisplayMap.get(e);i&&(i.centerPoint=t);const s=this.roomInfoMap.get(e);s&&s.updatePosition(t)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const e=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),e.forEach(t=>{try{t.destroy()}catch(i){w.warn(`[RoomManager] Error destroying RoomInfo for room ${t.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(e){return this.roomDisplayMap.get(e)}async refresh(){const e=this.appService;this.roomFloorType.clearFloorTypes(),this.roomDisplayMap.forEach((t,i)=>{const s=e.mapManager.getRoomById(i),n=(s==null?void 0:s.centerPoint)||null;if(t.centerPoint!==n){t.centerPoint=n;const a=this.roomInfoMap.get(i);a&&n&&a.updatePosition(n)}const o=s==null?void 0:s.colorIndex;if(t.colorIndex!==o&&o!==void 0){t.colorIndex=o;const a=this.roomInfoMap.get(i);a&&a.refreshColor()}}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes()}async updateAllRoomPropertyVisibility(){this.roomInfoMap.size!==0&&await Promise.all(Array.from(this.roomInfoMap.values()).map(async e=>{try{await e.updateRoomPropertyVisibility()}catch(t){console.warn(`[RoomManager] Failed to update room property visibility for room ${e.roomId}`,t)}}))}updateAllRoomNameVisibility(e){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomNameVisibility(e)})}updateAllRoomTypeVisibility(e){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomTypeVisibility(e)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.refreshColor()})}async updateFloorTypes(){const e=this.appService,t=e.mapManager.roomFill.getRoomGraphicsMap();t.size>0?(await this.roomFloorType.createFloorTypes(t),e.getApp().renderOnceNextFrame()):e.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}var Qa,Ja;(Qa=navigator==null?void 0:navigator.userAgent)!=null&&Qa.includes("tuya-ark-ide")||((Ja=navigator==null?void 0:navigator.userAgent)==null||Ja.includes("miniProgram"));const HS=()=>{var i,s;if(!Gn.any)return!0;const r=navigator.userAgent.toLowerCase(),e=()=>{const n=navigator.deviceMemory;return n?n>=4:!0};let t=!1;if(/iphone|ipad|ipod/.test(r)){const n=(i=r.match(/os (\d+)_/))==null?void 0:i[1];t=(n?parseInt(n):0)>=12}else if(/android/.test(r)){const n=(s=r.match(/android (\d+)/))==null?void 0:s[1];t=(n?parseInt(n):0)>=10}return t&&e()};class VS extends L{constructor(t,i,s){super();g(this,"graphics");g(this,"sprite",null);g(this,"viewportBounds");g(this,"lastConfig",null);g(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(t)}async render(t){if(this.lastConfig=t,this.clear(),t.backgroundImage){await this.renderImage(t.backgroundImage,t.backgroundAlpha);return}if(t.backgroundGradient){this.renderGradient(t.backgroundGradient);return}if(t.backgroundColor!==void 0){this.renderSolidColor(t.backgroundColor,t.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(t,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:t,alpha:i}),w.debug("[Background] Rendered solid color background",{color:t,alpha:i})}renderGradient(t){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),t.type==="linear"){const n=t.x0??0,o=t.y0??0,a=t.x1??1,h=t.y1??1,l=new Ot({type:"linear",start:{x:n,y:o},end:{x:a,y:h},colorStops:t.colorStops});this.graphics.rect(0,0,i,s).fill(l),w.debug("[Background] Rendered linear gradient background",{x0:n,y0:o,x1:a,y1:h,colorStops:t.colorStops.length})}else if(t.type==="radial"){const n=t.cx??.5,o=t.cy??.5,a=t.r??.5,h=new Ot({type:"radial",center:{x:n,y:o},innerRadius:0,outerCenter:{x:n,y:o},outerRadius:a,colorStops:t.colorStops});this.graphics.rect(0,0,i,s).fill(h),w.debug("[Background] Rendered radial gradient background",{cx:n,cy:o,r:a,colorStops:t.colorStops.length})}}async renderImage(t,i){var s,n,o,a;try{const h=await N.load(t.src);if(!h){w.error("[Background] Failed to load image:",t.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.autoGarbageCollect=!1,this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=t.fit||"cover",u=((n=t.position)==null?void 0:n.x)??.5,p=((o=t.position)==null?void 0:o.y)??.5,f=h.width,y=h.height,m=f/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=f,this.sprite.height=y,this.sprite.x=(l-f)*u,this.sprite.y=(c-y)*p;break}t.repeat&&w.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),w.debug("[Background] Rendered image background",{src:t.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(t){await this.render(t)}destroy(){this.clear(),super.destroy()}}class NS extends L{constructor(t){super();g(this,"carpetData");g(this,"carpetConfig");g(this,"controlsConfig");g(this,"carpetEvents");g(this,"appService");g(this,"controlFill");g(this,"editControlLayer");g(this,"clickHandler",null);g(this,"maskContainer",null);g(this,"maskGraphics",null);g(this,"texture",null);g(this,"textureMap",new Map);g(this,"tilingSprite",null);g(this,"initialZonePoints",[]);g(this,"unsubscribeFns",[]);g(this,"resolvedMaxSizeCache",null);g(this,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(t=>({...t})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(t.global),s=this.controlFill.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleDragEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(t=>({...t})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",t=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(t.global),s=(h=(a=this.editControlLayer)==null?void 0:a.getMoveButton())==null?void 0:h.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleRotationEnd",()=>{var t,i;this.appService.getApp().stopRender("zone-rotate"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleMoveHorizontal",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleMoveVertical",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleEnd",()=>{var t,i;this.appService.getApp().stopRender("zone-scale"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleDelete",()=>{var t,i;(i=(t=this.carpetEvents).onRemove)==null||i.call(t,this.carpetData.id)});g(this,"handleClick",()=>{var t,i;this.isEditingEnabled()||(i=(t=this.carpetEvents)==null?void 0:t.onClick)==null||i.call(t,this.getCarpetData())});g(this,"handlePointsUpdate",t=>{this.carpetData.points=t,this.drawCarpet()});const{appService:i,carpetData:s,events:n={},textureMap:o}=t;this.appService=i,this.textureMap=o,this.carpetEvents=n,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 t=this.carpetConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===t)return this.resolvedMaxSizeCache.value;const i=Hr(this.carpetConfig.minSize,t,"carpet");return this.resolvedMaxSizeCache={key:t,value:i},i}processCarpetData(t){if(t.points&&t.points.length>=2)if(t.shape==="custom")this.carpetData={...t,points:t.points};else{const s=this.getResolvedMaxSize(),n=nr(t.points,this.appService.metersToPixels(this.carpetConfig.minSize),s!=null?this.appService.metersToPixels(s):void 0),o=Cs(n);this.carpetData={...t,points:o}}else this.carpetData={...t,points:[],shape:t.shape||"rectangle"}}getControlsConfig(){const{controls:t}=this.appService.getConfig();return t}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 t=new L;return this.maskGraphics=new H,this.maskGraphics.autoGarbageCollect=!1,this.updateMaskShape(),t.addChild(this.maskGraphics),t.mask=this.maskGraphics,t}createControlFill(){const t=this.isEditingEnabled();return new Ur(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:t,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const t=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s={...An(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...An(this.carpetConfig,["textColor","textPosition","textOffset"]),...An(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!t&&!i&&this.carpetConfig.showRotateButton,showScaleButton:!!t&&!i,showDeleteButton:!!t,showMoveButton:!!t&&!i,showRadialScaleButton:!!t&&!i,iconWrapperFillColor:this.carpetConfig.iconWrapperFillColor,moveButtonOffset:this.controlsConfig.moveButtonOffset},n=i?this.calculateBoundingRectanglePoints():this.carpetData.points||[];this.editControlLayer=this.appService.editControlManager.registerEditControl(this.carpetData.id,{config:s,zonePoints:n,minSize:this.carpetConfig.minSize,maxSize:this.getResolvedMaxSize(),contentLayer:$e,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,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}})}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.isEditingEnabled()||(i=(t=this.carpetEvents)==null?void 0:t.onClick)==null||i.call(t,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const t=W(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(t);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(t){if(t){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:t}=this.carpetData;let i=1/0,s=1/0,n=-1/0,o=-1/0;if(t&&t.length>0)for(const a of t)i=Math.min(i,a.x),s=Math.min(s,a.y),n=Math.max(n,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:n,maxY:o}}calculateBoundingRectanglePoints(){const{points:t}=this.carpetData;if(!t||t.length===0)return[];const{minX:i,minY:s,maxX:n,maxY:o}=ws(t);return[{x:i,y:s},{x:n,y:s},{x:n,y:o},{x:i,y:o}]}updateMaskShape(){if(!this.maskGraphics)return;this.maskGraphics.clear();const{points:t,shape:i}=this.carpetData;if(!(!t||!Array.isArray(t)||t.length<2)){if(i==="round"){if(t.length<4)return;const n=de(t),[o,a,,h]=t,l=Q(o,a),c=Q(o,h),d=Math.atan2(a.y-o.y,a.x-o.x);this.maskGraphics.position.set(n.x,n.y),this.maskGraphics.rotation=d,this.maskGraphics.ellipse(0,0,l/2,c/2)}else{const n=t.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(n),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}loadTexture(){const{opacity:t,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,t),this.appService.getApp().renderOnce())}catch(n){console.warn("Failed to load carpet texture:",n)}}createTilingSprite(t,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new bs({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.autoGarbageCollect=!1,this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(t),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const t=this.calculateBounds();this.tilingSprite.position.set(t.minX-50,t.minY-50),this.tilingSprite.width=t.maxX-t.minX+100,this.tilingSprite.height=t.maxY-t.minY+100}applyTranslation(t,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:t}=this.carpetData;if(!(!t||t.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(t),this.editControlLayer)){const n=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():t;this.editControlLayer.updatePoints(n)}}updateEditState(){const t=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();if(this.controlFill.setInteractionEnabled(t),this.editControlLayer)if(i&&!t)this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!0,showSizeText:!1,borderStyle:this.carpetConfig.normal});else if(t){const n=this.carpetData.shape==="custom";this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!n&&this.carpetConfig.showRotateButton,showScaleButton:!n,showDeleteButton:!0,showMoveButton:!n,showBorder:!0,showSizeText:!0,borderStyle:this.carpetConfig.editing,showRadialScaleButton:!n})}else this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1});this.zIndex=s?1e3:0}updateCarpetData(t){const s=this.carpetData.type;if(t.points&&t.points.length>=2)if(t.shape==="custom")this.carpetData={...t,points:t.points};else{const n=this.getResolvedMaxSize(),o=nr(t.points,this.appService.metersToPixels(this.carpetConfig.minSize),n!=null?this.appService.metersToPixels(n):void 0),a=Cs(o);this.carpetData={...t,points:a}}else this.carpetData={...t,points:t.points||[]};s!==this.carpetData.type&&this.loadTexture(),this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var t,i,s,n,o;this.appService.editControlManager.unregisterEditControl(this.carpetData.id),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(t=this.tilingSprite)==null||t.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,(n=this.controlFill)==null||n.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class jS{constructor(e){g(this,"customCarpetMap",new Map);g(this,"unsubscribeFns",[]);g(this,"textureMap",new Map);g(this,"texturesLoaded",!1);g(this,"texturesLoadingPromise",null);this.appService=e,this.applyLayerVisibility(e.runtime.showCustomCarpets);const t=W(e.runtime,"editingCarpetIds",n=>{w.log(`[runtime] editingCarpetIds: ${n}`),this.updateCarpetsEditState()}),i=W(e.runtime,"selectedCarpetIds",n=>{w.log(`[runtime] selectedCarpetIds: ${n}`),this.updateCarpetsEditState()}),s=W(e.runtime,"showCustomCarpets",n=>{w.log(`[runtime] showCustomCarpets: ${n}`),this.applyLayerVisibility(n)});this.unsubscribeFns.push(t,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 e=this.appService,{material:t,src:i}=e.carpetConfig;if(t)for(const s of t){const n=await N.load(s.src);this.textureMap.set(s.type,n)}if(i){const s=await N.load(i);this.textureMap.set(-1,s)}}async drawCustomCarpets(e){if(await this.loadTextures(),!e||e.length===0){this.clearAllCustomCarpets();return}const t=new Set(this.customCarpetMap.keys()),i=new Set(e.map(s=>s.id));for(const s of t)i.has(s)||this.removeCustomCarpet(s);e.forEach(s=>{const n=this.customCarpetMap.get(s.id.toString());n?this.isCarpetDataEqual(n.getCarpetData(),s)||n.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const e=[];return this.customCarpetMap.forEach(t=>{e.push(t.getCarpetData())}),e}getCustomCarpetById(e){return this.customCarpetMap.get(e)}clearAllCustomCarpets(){this.customCarpetMap.forEach((e,t)=>{var s;const i=this.customCarpetMap.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(e){const t=this.appService,i=new NS({appService:t,carpetData:e,textureMap:this.textureMap,events:{onRemove:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onDeleteCustomCarpet)==null||o.call(n,{id:s})},onUpdate:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onUpdateCustomCarpet)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onClickCarpet)==null||o.call(n,{id:s.id})}}});this.customCarpetMap.set(e.id.toString(),i),t.appContainer.addToLayer($e,i)}removeCustomCarpet(e){const t=this.appService,i=this.customCarpetMap.get(e);i&&(t.appContainer.removeFromLayer($e,i),i.destroy(),this.customCarpetMap.delete(e))}updateCarpetsEditState(){this.customCarpetMap.forEach(e=>{e.updateEditState()})}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer($e);t&&(t.visible=e)}isCarpetDataEqual(e,t){if(e.id!==t.id||e.type!==t.type||e.shape!==t.shape)return!1;const i=e.points||[],s=t.points||[];if(i.length!==s.length)return!1;for(let n=0;n<i.length;n++){const o=i[n],a=s[n];if(Math.abs(o.x-a.x)>.1||Math.abs(o.y-a.y)>.1)return!1}return!0}refreshDisplay(){this.customCarpetMap.forEach(e=>{e.refreshDisplay()})}destroy(){this.clearAllCustomCarpets(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}class YS extends Ni{constructor(e,t){super(e,t),this.cursor="pointer"}setupEvents(){this.on("pointerdown",e=>{e.stopPropagation()}),this.on("pointertap",()=>{var e,t;(t=(e=this.options).onClick)==null||t.call(e)})}destroy(){this.removeAllListeners(),super.destroy()}}const Rt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0};class XS extends L{constructor(t){super();g(this,"appService");g(this,"data");g(this,"furnitureEvents");g(this,"textureAlias");g(this,"sprite");g(this,"controlButtons");g(this,"outlineBorder");g(this,"moveLine");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"sizeText",null);g(this,"isEditing",!1);g(this,"dragStartPosition",null);g(this,"initialPoints",[]);g(this,"clickHandler",null);g(this,"isDragging",!1);g(this,"initialScalePoints",[]);g(this,"initialButtonPosition",null);g(this,"rotationCount",0);g(this,"originalEdgeLengths",null);g(this,"onDragStart",t=>{if(!this.isEditing||!this.parent||t.target!==this&&t.target!==this.sprite)return;t.stopPropagation();const i=this.parent.toLocal(t.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(s=>({...s})),this.isDragging=!1,this.setupDragEventListeners(),this.appService.emitter.emit("gestureHijackStart",t)});g(this,"onDragMove",t=>{if(!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(n)<3||(this.isDragging||(this.isDragging=!0,this.appService.getApp().requestRender("furniture-drag",!0)),this.data.points=this.initialPoints.map(o=>({x:o.x+s,y:o.y+n})),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText())});g(this,"onDragEnd",()=>{var t,i;this.dragStartPosition&&(this.cleanupDragEventListeners(),this.isDragging&&((i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData()),this.appService.getApp().stopRender("furniture-drag")),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});g(this,"onDragCancel",()=>{this.dragStartPosition&&(this.cleanupDragEventListeners(),this.isDragging&&this.appService.getApp().stopRender("furniture-drag"),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});g(this,"handleScaleStart",()=>{this.initialScalePoints=this.data.points.map(i=>({...i}));const t=this.getVisualIndex(Rt.SCALE);t>=0&&t<this.data.points.length&&(this.initialButtonPosition={...this.data.points[t]}),this.appService.getApp().requestRender("furniture-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialScalePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var t,i;this.initialScalePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("furniture-scale"),(i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData())});g(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(t=>({...t})),this.appService.getApp().requestRender("furniture-move",!0)});g(this,"handleMoveMove",t=>{var a;if(!this.isEditing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(t.global),s=(a=this.moveButton)==null?void 0:a.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.data.points=this.initialPoints.map(h=>({x:h.x+n,y:h.y+o})),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText()});g(this,"handleMoveEnd",()=>{var t,i;this.initialPoints=[],this.appService.getApp().stopRender("furniture-move"),(i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData())});const{appService:i,data:s,textureAlias:n,events:o={}}=t;this.appService=i,this.data={...s,points:s.points.map(a=>({...a}))},this.textureAlias=n,this.furnitureEvents=o,this.createSprite(),this.updateSpriteTransform(),this.createEditControls(),this.captureOriginalEdgeLengths(),this.eventMode="static",this.cursor="pointer",this.setupInteraction()}get config(){return this.appService.furnitureConfig}captureOriginalEdgeLengths(){const t=this.data.points;if(t.length<4)return;const i=this.getVisualIndex(Rt.FIXED),s=this.getVisualIndex(1),n=this.getVisualIndex(3);this.originalEdgeLengths={edge1:Q(t[i],t[s]),edge2:Q(t[i],t[n])}}getVisualIndex(t){return(t+4-this.rotationCount)%4}getVisualPoints(){const t=this.data.points;return[t[this.getVisualIndex(0)],t[this.getVisualIndex(1)],t[this.getVisualIndex(2)],t[this.getVisualIndex(3)]]}createSprite(){const t=N.get(this.textureAlias);this.sprite=new jt(t),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="passive",this.addChild(this.sprite)}updateSpriteTransform(){const t=this.data.points;if(t.length<4)return;const i=de(t),s=t[1].x-t[0].x,n=t[1].y-t[0].y,o=Math.atan2(n,s),a=Q(t[0],t[1]),h=Q(t[1],t[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControls(){const t=this.calculateOutlinePoints();this.outlineBorder=new Nt(this.appService,{points:t,closePath:!0,style:{color:this.config.outlineStrokeColor,width:this.config.outlineStrokeWidth,isDashed:this.config.outlineDashed,dashArray:this.config.outlineDashArray,fillColor:this.config.outlineFillColor}}),this.outlineBorder.visible=!1,this.addChild(this.outlineBorder);const i=this.calculateMoveLinePoints(t);this.moveLine=new Nt(this.appService,{points:i,closePath:!1,style:{color:this.config.outlineStrokeColor,width:this.config.outlineStrokeWidth,isDashed:this.config.outlineDashed,dashArray:this.config.outlineDashArray}}),this.moveLine.visible=!1,this.addChild(this.moveLine),this.controlButtons=new L,this.controlButtons.visible=!1,this.addChild(this.controlButtons),this.createControlButtons()}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;const{iconWrapperFillColor:i}=this.config,s=this.getVisualIndex(Rt.REMOVE),n=this.getVisualIndex(Rt.ROTATE),o=this.getVisualIndex(Rt.SCALE);this.deleteButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:i,onClick:()=>{var h,l;return(l=(h=this.furnitureEvents).onRemove)==null?void 0:l.call(h,this.data.id)}}),this.deleteButton.position.set(t[s].x,t[s].y),this.rotateButton=new YS(this.appService,{iconAlias:"rotateIcon",backgroundColor:i,onClick:()=>this.handleTapRotate()}),this.rotateButton.position.set(t[n].x,t[n].y),this.scaleButton=new Qe(this.appService,{iconAlias:"scaleIcon",backgroundColor:i,getTargetPoints:()=>this.data.points,getButtonIndex:()=>this.getVisualIndex(Rt.SCALE),onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(t[o].x,t[o].y);const a=this.calculateMoveButtonPosition(t);this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:i,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMoveMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(a.x,a.y),this.controlButtons.addChild(this.deleteButton),this.controlButtons.addChild(this.rotateButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton),this.config.showSizeText&&(this.sizeText=this.createSizeText(),this.controlButtons.addChild(this.sizeText))}calculateOutlinePoints(){const{points:t}=this.data;if(t.length<4)return t;const i=this.appService.getApp().toFixedSize(this.config.outlineOffset);return zr(t,i)}calculateMoveButtonPosition(t){const i=t??this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{controls:s}=this.appService.getConfig(),n=this.getVisualIndex(Rt.MOVE),o=this.getVisualIndex(2),a=this.getVisualIndex(0),h=this.appService.getApp().toFixedSize(s.moveButtonOffset);return Ds(i[n],i[o],i[a],h)}calculateMoveLinePoints(t,i){if(t.length<4)return[];const s=this.getVisualIndex(Rt.MOVE),n=i??this.calculateMoveButtonPosition(t);return[t[s],n]}createSizeText(){const t=this.calculateSizeTextContent(),i=this.appService.controlsConfig,s=new ji(this.appService,{text:t,style:{fontSize:i.textFontSize,fontFamily:i.textFontFamily,fontWeight:i.textFontWeight,fill:this.config.textColor,align:"center"}});s.anchor.set(.5);const n=this.calculateSizeTextPosition();s.position.set(n.x,n.y);const o=this.calculateSizeTextRotation();return s.rotation=o,s.eventMode="none",s}calculateSizeTextContent(){const{points:t}=this.data;if(t.length<4)return"0m*0m";const[i,s,,n]=this.getVisualPoints(),o=Q(i,s),a=Q(i,n),h=this.rotationCount%2!==0,l=h?a:o,c=h?o:a,d=this.appService.pixelsToMeters(l),u=this.appService.pixelsToMeters(c),p=this.appService.metersToDisplayUnit(d),f=this.appService.metersToDisplayUnit(u),y=this.appService.runtimeSnapshot.unitLabel;return`${p.toFixed(1)}${y}*${f.toFixed(1)}${y}`}calculateSizeTextPosition(){const{points:t}=this.data;if(t.length<4)return{x:0,y:0};const[i,s,n,o]=this.getVisualPoints(),{textPosition:a,textOffset:h}=this.config,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2};const u=gt(K(s,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2};const u=gt(K(s,n)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2};const u=gt(K(o,n)),p={x:-u.y,y:u.x};d={x:p.x*l,y:p.y*l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2};const u=gt(K(o,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}default:c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:0,y:l};break}return{x:c.x+d.x,y:c.y+d.y}}calculateSizeTextRotation(){const{points:t}=this.data;if(t.length<4)return 0;const[i,s,n,o]=this.getVisualPoints(),{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}setupInteraction(){this.clickHandler=new vt(this,{onClick:t=>{var i,s;!this.isDragging&&((t==null?void 0:t.target)===this||(t==null?void 0:t.target)===this.sprite)&&((s=(i=this.furnitureEvents).onClick)==null||s.call(i,this.getData()))}}),this.on("pointerdown",this.onDragStart,this)}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.onDragMove),t.on("gestureHijackPointerUp",this.onDragEnd),t.on("gestureHijackCancel",this.onDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.onDragMove),t.off("gestureHijackPointerUp",this.onDragEnd),t.off("gestureHijackCancel",this.onDragCancel)}handleTapRotate(){var n,o;const t=this.config.rotateDirection!=="ccw",i=t?Math.PI/2:-Math.PI/2,s=de(this.data.points);this.data.points=Fr(this.data.points,s,i),this.rotationCount=(this.rotationCount+(t?1:3))%4,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(),(o=(n=this.furnitureEvents).onUpdate)==null||o.call(n,this.getData())}applyEdgeBasedScale(t){if(this.initialScalePoints.length<4)return;const i=this.getVisualIndex(Rt.FIXED),s=this.getVisualIndex(1),n=this.getVisualIndex(3),{x:o,y:a}=this.initialScalePoints[i],h=this.initialScalePoints[s],l=this.initialScalePoints[n],c={x:o,y:a},d=K(c,h),u=K(c,l),p=K(c,t),f=ee(d),y=ee(u);if(f===0||y===0)return;const{minScaleRatio:m,maxScaleRatio:x}=this.config;let S=ae(p,d,f,0),v=ae(p,u,y,0);if(this.config.lockAspectRatio){const C=Math.min(S,v);S=C,v=C}if(this.originalEdgeLengths){const C=this.rotationCount%2!==0,A=C?this.originalEdgeLengths.edge2:this.originalEdgeLengths.edge1,k=C?this.originalEdgeLengths.edge1:this.originalEdgeLengths.edge2,M=S*f/A,T=v*y/k;let _=Math.max(m,Math.min(x,M)),E=Math.max(m,Math.min(x,T));if(this.config.lockAspectRatio){const B=Math.min(_,E);_=B,E=B}S=_*A/f,v=E*k/y}else if(S=Math.max(m,Math.min(x,S)),v=Math.max(m,Math.min(x,v)),this.config.lockAspectRatio){const C=Math.min(S,v);S=C,v=C}const b=[c,{x:o+d.x*S,y:a+d.y*S},{x:o+d.x*S+u.x*v,y:a+d.y*S+u.y*v},{x:o+u.x*v,y:a+u.y*v}],P=new Array(4);for(let C=0;C<4;C++)P[this.getVisualIndex(C)]=b[C];this.data.points=P,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditControls(){var h;const t=this.calculateOutlinePoints();if(t.length<4)return;this.outlineBorder.updatePoints(t);const i=this.calculateMoveButtonPosition(t),s=this.calculateMoveLinePoints(t,i);if(this.moveLine.updatePoints(s),!this.deleteButton||!this.rotateButton||!this.scaleButton)return;const n=this.getVisualIndex(Rt.REMOVE),o=this.getVisualIndex(Rt.ROTATE),a=this.getVisualIndex(Rt.SCALE);this.deleteButton.position.set(t[n].x,t[n].y),this.rotateButton.position.set(t[o].x,t[o].y),this.scaleButton.position.set(t[a].x,t[a].y),(h=this.moveButton)==null||h.position.set(i.x,i.y)}updateSizeText(t=!1){if(!this.sizeText)return;if(t){const n=this.calculateSizeTextContent();this.sizeText.updateText(n)}const i=this.calculateSizeTextPosition();this.sizeText.position.set(i.x,i.y);const s=this.calculateSizeTextRotation();this.sizeText.rotation=s}getData(){return{id:this.data.id,furnitureType:this.data.furnitureType,points:this.data.points.map(t=>({...t}))}}updateData(t){this.data={...t,points:t.points.map(i=>({...i}))},this.rotationCount=0,this.captureOriginalEdgeLengths(),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditState(t){this.isEditing!==t&&(this.isEditing=t,this.outlineBorder.visible=t,this.moveLine.visible=t,this.controlButtons.visible=t,t&&(this.updateEditControls(),this.updateSizeText(!0)))}destroy(){var t;this.cleanupDragEventListeners(),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class ZS{constructor(e){g(this,"furnitureMap",new Map);g(this,"unsubscribeFns",[]);this.appService=e,this.applyLayerVisibility(e.runtime.showFurnitures);const t=W(e.runtime,"editingFurnitureIds",s=>{w.log(`[runtime] editingFurnitureIds: ${s}`),this.updateEditState()}),i=W(e.runtime,"showFurnitures",s=>{w.log(`[runtime] showFurnitures: ${s}`),this.applyLayerVisibility(s)});this.unsubscribeFns.push(t,i)}async drawFurnitures(e){if(!e||e.length===0){this.clearAll();return}const t=new Set(this.furnitureMap.keys()),i=new Set(e.map(n=>n.id));for(const n of t)i.has(n)||this.removeFurniture(n);const s=[];for(const n of e){const o=this.furnitureMap.get(n.id);o?this.isDataEqual(o.getData(),n)||o.updateData(n):s.push(this.addFurniture(n))}await Promise.all(s)}async addFurniture(e){const t=this.appService;if(!t.furnitureConfig.assets.find(h=>h.type===e.furnitureType)){w.warn(`[FurnitureManager] No asset found for furnitureType: ${e.furnitureType}`);return}const n=`furniture_${e.furnitureType}`;await N.load(n);const o=new XS({appService:t,data:e,textureAlias:n,events:{onRemove:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onRemoveFurniture)==null||c.call(l,h)},onUpdate:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onUpdateFurniture)==null||c.call(l,h)},onClick:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onClickFurniture)==null||c.call(l,h)}}});this.furnitureMap.set(e.id,o),t.appContainer.addToLayer(je,o),t.runtime.editingFurnitureIds.includes(e.id)&&(o.updateEditState(!0),this.moveToEditLayer(o))}removeFurniture(e){var i;const t=this.furnitureMap.get(e);t&&((i=t.parent)==null||i.removeChild(t),t.destroy(),this.furnitureMap.delete(e))}clearAll(){var e;for(const[,t]of this.furnitureMap)(e=t.parent)==null||e.removeChild(t),t.destroy();this.furnitureMap.clear()}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer(je);t&&(t.visible=e),this.furnitureMap.forEach(i=>{i.visible=e})}updateEditState(){const e=this.appService.runtime.editingFurnitureIds,{appContainer:t}=this.appService,i=t.getLayer(je);this.furnitureMap.forEach((s,n)=>{const o=e.includes(n);s.updateEditState(o),o?this.moveToEditLayer(s):s.parent!==i&&this.moveToFurnitureLayer(s)})}moveToEditLayer(e){var t;(t=e.parent)==null||t.removeChild(e),this.appService.appContainer.addToLayer(ke,e)}moveToFurnitureLayer(e){var t;(t=e.parent)==null||t.removeChild(e),this.appService.appContainer.addToLayer(je,e)}getFurnitures(){const e=[];return this.furnitureMap.forEach(t=>{e.push(t.getData())}),e}isDataEqual(e,t){if(e.id!==t.id||e.furnitureType!==t.furnitureType||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++)if(Math.abs(e.points[i].x-t.points[i].x)>.1||Math.abs(e.points[i].y-t.points[i].y)>.1)return!1;return!0}destroy(){this.clearAll(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}const pt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class qS extends L{constructor(t,i){super();g(this,"config");g(this,"events");g(this,"zonePoints",[]);g(this,"outlinePoints");g(this,"minSize",.1);g(this,"maxSize");g(this,"initialZonePoints",[]);g(this,"scaleCache",null);g(this,"rotationCache",null);g(this,"outlineBorder");g(this,"moveLine");g(this,"sizeText");g(this,"controlButtons");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"horizontalScaleButton",null);g(this,"verticalScaleButton",null);g(this,"horizontalScaleInitialPosition",null);g(this,"verticalScaleInitialPosition",null);g(this,"clickHandler",null);g(this,"throttledUpdateOutline");this.appService=t,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},this.events=i.events||{},this.minSize=i.minSize??.1,this.maxSize=i.maxSize,this.throttledUpdateOutline=Ct(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 L,this.addChild(this.controlButtons),this.createControlButtons(),this.setupClickHandler()}createOutlineBorder(){const{outlineStrokeColor:t,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n,outlineFillColor:o}=this.config;return new Nt(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:t,width:i,isDashed:s,dashArray:n,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:t,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n}=this.config,o=this.calculateMoveLinePoints();return new Nt(this.appService,{points:o,closePath:!1,style:{color:t,width:i,isDashed:s,dashArray:n}})}createSizeText(){const t=this.calculateSizeText(),i=new ji(this.appService,{text:t,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 n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}createDeleteButton(){const t=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:"red",onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return t.position.set(this.outlinePoints[pt.REMOVE].x,this.outlinePoints[pt.REMOVE].y),t}createRotateButton(){const t=new Sc(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.config.iconWrapperFillColor,getTargetPoints:()=>this.zonePoints,onRotationStart:i=>{var s,n;this.initializeRotationCache(i),(n=(s=this.events).onRotateStart)==null||n.call(s,i)},onClick:()=>{var n,o;const i=Math.PI/2,s=this.onClickRotateButton(i);(o=(n=this.events).onRotateMove)==null||o.call(n,s??void 0)},onRotationEnd:()=>{var i,s;this.resetRotationState(),(s=(i=this.events).onRotateEnd)==null||s.call(i)}});return t.position.set(this.outlinePoints[pt.ROTATE].x,this.outlinePoints[pt.ROTATE].y),t}onClickRotateButton(t){const i=this.handleInternalRotationMove(t)??[];return this.resetRotationState(),i}createScaleButton(){const t=new Qe(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 n=this.handleInternalScaleMove(i,s);(a=(o=this.events).onScaleMove)==null||a.call(o,n??void 0)},onScaleEnd:()=>{var i,s;this.resetScaleState(),this.initialZonePoints=[],(s=(i=this.events).onScaleEnd)==null||s.call(i)}});return t.position.set(this.outlinePoints[pt.SCALE].x,this.outlinePoints[pt.SCALE].y),t}createHorizontalScaleButton(){const[,t,i]=this.outlinePoints,s=this.getEdgeCenter(t,i),n=new Qe(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 n.position.set(s.x,s.y),n}createVerticalScaleButton(){const[,,t,i]=this.outlinePoints,s=this.getEdgeCenter(t,i),n=new Qe(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 n.position.set(s.x,s.y),n}createMoveButton(){const t=this.calculateMoveButtonPosition(),i=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.config.iconWrapperFillColor,onMoveStart:()=>{var s,n;return(n=(s=this.events).onMoveStart)==null?void 0:n.call(s)},onMoveMove:s=>{var n,o;return(o=(n=this.events).onMoveMove)==null?void 0:o.call(n,s)},onMoveEnd:()=>{var s,n;return(n=(s=this.events).onMoveEnd)==null?void 0:n.call(s)}});return i.position.set(t.x,t.y),i}createAndAddButton(t,i){return t.visible=i,this.controlButtons.addChild(t),t}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),console.log("this.config.showRadialScaleButton",this.config.showRadialScaleButton),this.horizontalScaleButton=this.createAndAddButton(this.createHorizontalScaleButton(),this.config.showRadialScaleButton??!1),this.verticalScaleButton=this.createAndAddButton(this.createVerticalScaleButton(),this.config.showRadialScaleButton??!1))}calculateOutlinePoints(){const t=this.zonePoints;if(t.length<4)return t;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return zr(t,s)}calculateMoveButtonPosition(){const t=this.calculateOutlinePoints();if(t.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),n=t[pt.MOVE],o=t[pt.SCALE],a=t[pt.REMOVE];return Ds(n,o,a,s)}calculateMoveLinePoints(){const t=this.calculateOutlinePoints();if(t.length<4)return[];const i=t[pt.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const t=this.zonePoints;if(t.length<4)return"0m*0m";const[i,s,,n]=t,o=Q(i,s),a=Q(i,n),h=this.appService,l=h.pixelsToMeters(o),c=h.pixelsToMeters(a),d=h.metersToDisplayUnit(l),u=h.metersToDisplayUnit(c),p=h.runtimeSnapshot.unitLabel;return`${d.toFixed(1)}${p}*${u.toFixed(1)}${p}`}getEdgeCenter(t,i){return{x:(t.x+i.x)/2,y:(t.y+i.y)/2}}calculatePerpendicularOffset(t,i,s,n=!1){const o=gt(K(i,t)),a=n?{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,n,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,n),p=this.calculatePerpendicularOffset(n,s,d);break;case"right":u=this.getEdgeCenter(n,o),p=this.calculatePerpendicularOffset(n,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,n),p={x:0,y:d};break}return{x:u.x+p.x,y:u.y+p.y}}calculateSizeTextRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[i,s,n,o]=t,{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}calculateHorizontalScaleButtonRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[,i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(i,s,n)+Math.PI/2}calculateVerticalScaleButtonRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[,,i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(s,i,n)}updatePoints(t,i=!0){this.zonePoints=t,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const t=this.calculateOutlinePoints();this.outlinePoints=t,this.outlineBorder.updatePoints(t)}updateMoveLine(){if(!this.moveLine)return;const t=this.calculateMoveLinePoints();this.moveLine.updatePoints(t)}updateSizeText(t=!0){if(this.sizeText){if(t){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:t[pt.REMOVE]},{button:this.scaleButton,point:t[pt.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:t[pt.ROTATE]}),this.horizontalScaleButton){const n=t[pt.ROTATE],o=t[pt.SCALE],a=nc(n,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const n=t[pt.SCALE],o=t[pt.MOVE],a=this.getEdgeCenter(n,o);s.push({button:this.verticalScaleButton,point:a})}s.forEach(({button:n,point:o})=>n.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 vt(this,{onClick:()=>{var t,i;(i=(t=this.events).onClick)==null||i.call(t)},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 t={...this.initialZonePoints[pt.SCALE]};if(!t)return;const i=pt.REMOVE,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=K(h,o),c=K(h,a),d=ee(l),u=ee(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:t})}handleInternalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const s=this.appService.metersToPixels(this.minSize),n=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,{fixedPoint:o,edge1:a,edge2:h,edge1Len:l,edge2Len:c,initialButtonPosition:d}=this.scaleCache,u={x:d.x+t,y:d.y+i},p=K(o,u),f=ae(p,a,l,s,n),y=ae(p,h,c,s,n);return this.calculatePointsFromScale(o,a,h,f,y)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.horizontalScaleInitialPosition)return null;const{fixedPoint:s,edge1:n,edge2:o,edge1Len:a}=this.scaleCache,h=this.appService.metersToPixels(this.minSize),l=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,c={x:this.horizontalScaleInitialPosition.x+t,y:this.horizontalScaleInitialPosition.y+i},d=K(s,c),u=ae(d,n,a,h,l);return this.calculatePointsFromScale(s,n,o,u,1)}handleInternalVerticalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.verticalScaleInitialPosition)return null;const{fixedPoint:s,edge1:n,edge2:o,edge2Len:a}=this.scaleCache,h=this.appService.metersToPixels(this.minSize),l=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,c={x:this.verticalScaleInitialPosition.x+t,y:this.verticalScaleInitialPosition.y+i},d=K(s,c),u=1,p=ae(d,o,a,h,l);return this.calculatePointsFromScale(s,n,o,u,p)}calculatePointsFromScale(t,i,s,n,o){const{x:a,y:h}=t;return[t,{x:a+i.x*n,y:h+i.y*n},{x:a+i.x*n+s.x*o,y:h+i.y*n+s.y*o},{x:a+s.x*o,y:h+s.y*o}]}initializeRotationCache(t){this.zonePoints.length<3||(this.rotationCache={rotationCenter:t,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(t){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=t,Fr(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:de(this.zonePoints)}updateEditState({showRotateButton:t=!1,showScaleButton:i=!1,showRadialScaleButton:s=!1,showDeleteButton:n=!1,showMoveButton:o=!1,showBorder:a=!1,showSizeText:h=!1,borderStyle:l}){this.rotateButton&&(this.rotateButton.visible=t),this.scaleButton&&(this.scaleButton.visible=i),this.horizontalScaleButton&&(this.horizontalScaleButton.visible=s),this.verticalScaleButton&&(this.verticalScaleButton.visible=s),this.deleteButton&&(this.deleteButton.visible=n),this.moveButton&&(this.moveButton.visible=o);const c=t||i||s||n||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 n,o,a;const t=((n=this.scaleButton)==null?void 0:n.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:t,isRotating:i,isMoving:s,hasAnyOperation:t||i||s}}stopAllOperations(){var t,i,s;(t=this.scaleButton)==null||t.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(t,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const n=s[t],o=s[i];return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}}destroy(){var t,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(n=this.scaleButton)==null||n.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()}}class KS{constructor(e){g(this,"editControlLayers",new Map);this.appService=e}registerEditControl(e,t){const i=this.appService;this.editControlLayers.has(e)&&this.unregisterEditControl(e);const s=new qS(i,t);if(!i.appContainer.addToLayer(ke,s))throw w.warn(`[EditControlManager] Failed to add edit control layer for id: ${e}`),s.destroy(),new Error(`Failed to register edit control for id: ${e}`);if(this.editControlLayers.set(e,s),t.contentLayer){const o=i.appContainer.getLayer(ke),a=i.appContainer.getLayer(t.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 "${t.contentLayer}" position — edit controls will appear misaligned. Ensure "${t.contentLayer}" is in ORIGIN_TRACKED_LAYERS.`,{edit:o.position,content:a.position})}return s}unregisterEditControl(e){const t=this.editControlLayers.get(e);if(!t)return;this.appService.appContainer.removeFromLayer(ke,t),t.destroy(),this.editControlLayers.delete(e)}getEditControl(e){return this.editControlLayers.get(e)}updateEditState(e,t){const i=this.editControlLayers.get(e);i&&i.updateEditState(t)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(t=>this.unregisterEditControl(t))}getAllEditControls(){return Array.from(this.editControlLayers.values())}hasEditControl(e){return this.editControlLayers.has(e)}}const $S=60;function $a(r){return Math.round(r*1e3/$S)}function ds(r){return r.charAt(0).toUpperCase()+r.slice(1)}class Zr extends il{constructor(t=Ya){super();g(this,"mapState",null);g(this,"components",{});g(this,"managers",{});g(this,"config",ja);g(this,"runtime");g(this,"appService");g(this,"scaleMin",.5);g(this,"scaleMax",5);g(this,"events",{});g(this,"instanceKey");g(this,"containerElement");g(this,"emitter",Gx());g(this,"tickerState",{renderReasons:new Set,renderTimer:null});g(this,"pendingAsyncRender",!1);g(this,"isFirstMapDraw",!0);g(this,"isMapDrawn",!1);g(this,"onVisibilityChange",()=>{var i;document.visibilityState==="visible"||(i=this.components.interaction)==null||i.clearTouches()});this.instanceKey=t,this.appService=new ac(this),globalThis.__PIXI_APP__=this}async initialize(t){const{resizeTo:i,events:s,config:n,runtime:o={},...a}=t;this.config=or(Ea({},ja,n??{},(f,y)=>{if(Array.isArray(y))return y})),this.validateCustomZoneTypes(this.config),hy(()=>this.config.global.enableLogger),w.log("Applying config",this.config,n),this.runtime=or(Object.assign({},Ox,o));const h=this.instanceKey===Ya;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={gcActive:!0,gcMaxUnusedTime:$a(c?60:Gn.any?180:3600),gcFrequency:$a(c?10:Gn.any?100:50),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:HS(),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(f){w.warn("[Pixi] WebGPU initialization failed, falling back to WebGL:",f),await this.init({...u,preference:"webgl"})}else await this.init({...u,preference:p});w.log(`[Pixi] Renderer initialized: ${this.renderer.type===Fi.WEBGPU?"WebGPU":"WebGL"} ${this.renderer.type}`),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.managers.mapManager=new Kx(this.appService),this.managers.heatmapManager=new sS(this.appService),this.managers.pathManager=new eS(this.appService),this.managers.controlsManager=new aS(this.appService),this.managers.detectedObjectManager=new lS(this.appService),this.managers.customElementsManager=new FS(this.appService),this.managers.roomsManager=new US(this.appService),this.managers.customCarpetManager=new jS(this.appService),this.managers.furnitureManager=new ZS(this.appService),this.managers.editControlManager=new KS(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(t){var a,h,l,c,d,u,p;this.isMapDrawn=!1,w.log("[Map] drawMap",t);const{size:i,resolution:s,origin:n,id:o}=t;((a=this.mapState)==null?void 0:a.id)!==void 0&&this.mapState.id!==o&&this.managers.pathManager.clear(),(n[0]!==((h=this.mapState)==null?void 0:h.origin.x)||n[1]!==((l=this.mapState)==null?void 0:l.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(...n),this.managers.pathManager.updatePositionByOrigin(...n),this.managers.heatmapManager.updatePositionByOrigin(...n)),this.mapState={id:t.id,status:t.status===1,origin:{x:n[0],y:n[1]},charger:{x:t.charger.coordinate[0],y:t.charger.coordinate[1]},chargerDirection:t.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},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),await this.managers.mapManager.drawMap(t),i[0]===0||i[1]===0?(w.log("[Map] Map cleared, clearing path and room data"),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.managers.heatmapManager.onMapLoaded()),this.renderOnce()}async drawRasterMap(t){var a,h,l,c,d,u;this.isMapDrawn=!1,w.log("[Map] drawRasterMap",t);const{mapHeader:i,mapData:s}=t,{originX:n,originY:o}=i;(n!==((a=this.mapState)==null?void 0:a.origin.x)||o!==((h=this.mapState)==null?void 0:h.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(n,o),this.managers.pathManager.updatePositionByOrigin(n,o),this.managers.heatmapManager.updatePositionByOrigin(n,o)),this.mapState={id:i.id,status:i.mapStable,origin:{x:n,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.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),await this.managers.mapManager.drawRasterMap(s.parsed,this.mapState),i.mapWidth===0||i.mapHeight===0?(w.log("[Map] Map cleared, clearing path and room data"),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.managers.heatmapManager.onMapLoaded()),this.renderOnce()}drawPath(t){var i,s;w.log("[Path] drawPath",t),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:t.pathHeader.pathId,type:t.pathHeader.type,direction:t.pathHeader.direction,count:t.pathHeader.count,initFlag:t.pathHeader.initFlag,robotPosition:t.pathPoints[t.pathPoints.length-1]??null}),this.managers.pathManager.draw(t),this.renderOnce()}async drawRoomProperty(t){var i,s;w.log("[Room] drawRoomProperty",t),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,t),await this.managers.roomsManager.drawRoomProperty(t),this.renderOnceNextFrame()}async drawCustomCarpets(t){w.log("[CustomCarpets] drawCustomCarpets",t),await this.managers.customCarpetManager.drawCustomCarpets(t),this.renderOnceNextFrame()}async drawFurnitures(t){w.log("[Furniture] drawFurnitures",t),await this.managers.furnitureManager.drawFurnitures(t),this.renderOnceNextFrame()}drawHeatmap(t){w.log("[Heatmap] drawHeatmap",t),this.managers.heatmapManager.draw(t),this.renderOnce()}drawForbiddenSweepZones(t){w.log("[Controls] drawForbiddenSweepZones",t),this.managers.controlsManager.drawForbiddenSweepZones(t),this.renderOnceNextFrame()}drawForbiddenMopZones(t){w.log("[Controls] drawForbiddenMopZones",t),this.managers.controlsManager.drawForbiddenMopZones(t),this.renderOnceNextFrame()}drawCleanZones(t){w.log("[Controls] drawCleanZones",t),this.managers.controlsManager.drawCleanZones(t),this.renderOnceNextFrame()}drawCustomZones(t,i){if(Ne(t)){w.warn(`[MapApplication] drawCustomZones: '${t}' is a built-in type; use draw${ds(t)}s() instead`);return}w.log("[Controls] drawCustomZones",t,i),this.managers.controlsManager.drawCustomZones(t,i),this.renderOnceNextFrame()}getCustomZones(t){return Ne(t)?(w.warn(`[MapApplication] getCustomZones: '${t}' is a built-in type; use get${ds(t)}s() instead`),[]):this.managers.controlsManager.getCustomZones(t)}clearCustomZones(t){if(Ne(t)){w.warn(`[MapApplication] clearCustomZones: '${t}' is a built-in type; use clearAll${ds(t)}s() instead`);return}w.log("[Controls] clearCustomZones",t),this.managers.controlsManager.clearCustomZones(t),this.renderOnceNextFrame()}setEditingCustomZones(t,i){if(Ne(t)){w.warn(`[MapApplication] setEditingCustomZones: '${t}' is a built-in type; use runtime.editing${ds(t)}Ids instead`);return}this.runtime.editingCustomZoneIds={...this.runtime.editingCustomZoneIds??{},[t]:[...i]}}drawVirtualWalls(t){w.log("[Controls] drawVirtualWalls",t),this.managers.controlsManager.drawVirtualWalls(t),this.renderOnceNextFrame()}drawSpots(t){w.log("[Controls] drawSpots",t),this.managers.controlsManager.drawSpots(t),this.renderOnceNextFrame()}drawWayPoints(t){w.log("[Controls] drawWayPoints",t),this.managers.controlsManager.drawWayPoints(t),this.renderOnceNextFrame()}async drawDetectedObjects(t){w.log("[DetectedObject] drawDetectedObjects",t),await this.managers.detectedObjectManager.drawDetectedObjects(t),this.renderOnceNextFrame()}drawCustomCarpet(t){w.log("[CustomCarpet] drawCustomCarpet",t),this.managers.customCarpetManager.drawCustomCarpets(t),this.renderOnceNextFrame()}async drawCustomElements(t){w.log("[CustomElements] drawCustomElements",t),await this.managers.customElementsManager.drawCustomElements(t),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()}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(t,i=!1){if(!t||t.minX===t.maxX||t.minY===t.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,n=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(t,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-n*2),f=u*(1-s*2),y=p/l,m=f/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=t.minX+(t.maxX-t.minX)/2,C=t.minY+(t.maxY-t.minY)/2,A=this.config.map.autoFitOffset||{x:0,y:0},k=d/2+(A.x||0),M=u/2+(A.y||0),T=Math.cos(a),_=Math.sin(a),E=P*T-C*_,B=P*_+C*T,F=k-E*b,Z=M-B*b;w.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:t,rotatedBounds:h,finalScale:b,position:{x:F,y:Z}}),this.components.interaction.setPanZoom({targetPosition:{x:F,y:Z},targetScale:{x:b,y:b},setCenter:!0,setScale:!0},i)}setScaleBounds(t,i){this.scaleMin=t,this.scaleMax=i,this.components.interaction.scaleMin=t,this.components.interaction.scaleMax=i}validateCustomZoneTypes(t){const i=["minSize","strokeColor","strokeWidth","fillColor","outlineOffset","outlineStrokeColor","outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","iconWrapperFillColor","textColor","textPosition","textOffset","showRotateButton","editing","normal"],s=t.customZoneTypes??{},n=Ei.cleanZone;for(const[,o]of Object.entries(s))for(const a of i)o[a]===void 0&&(o[a]=n[a])}calculateRotatedBounds(t,i){if(i===0)return t;const s=(t.minX+t.maxX)/2,n=(t.minY+t.maxY)/2,o=[{x:t.minX-s,y:t.minY-n},{x:t.maxX-s,y:t.minY-n},{x:t.maxX-s,y:t.maxY-n},{x:t.minX-s,y:t.maxY-n}],a=Math.cos(i),h=Math.sin(i),l=o.map(f=>({x:f.x*a-f.y*h,y:f.x*h+f.y*a}));let c=1/0,d=1/0,u=-1/0,p=-1/0;return l.forEach(f=>{c=Math.min(c,f.x),d=Math.min(d,f.y),u=Math.max(u,f.x),p=Math.max(p,f.y)}),{minX:c+s,minY:d+n,maxX:u+s,maxY:p+n}}getViewportBounds(){var t;return((t=this.components.viewportContainer)==null?void 0:t.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(t){Object.assign(this.runtime,t),w.log("[runtime] runtime updated",t),this.renderOnceNextFrame()}updateConfig(t){var i;Ea(this.config,t,(s,n)=>{if(Array.isArray(n))return n}),t.customZoneTypes&&this.validateCustomZoneTypes(this.config),(i=this.managers.controlsManager)==null||i.updateRenderOrder(),w.log("[Config] Configuration updated",t),this.renderOnceNextFrame()}metersToPixels(t){var n;if(!((n=this.mapState)!=null&&n.resolution))return w.warn("Map resolution not available, using default resolution (5cm/pixel)"),t*20;const s=1/(this.mapState.resolution/100);return t*s}pixelsToMeters(t){var s;if(!((s=this.mapState)!=null&&s.resolution))return w.warn("Map resolution not available, using default resolution (5cm/pixel)"),t*.05;const i=this.mapState.resolution/100;return t*i}toFixedSize(t,i){const s=i??this.components.appContainer.scale.x;return t/s}fromFixedSize(t,i){const s=i??this.components.appContainer.scale.x;return t*s}getViewportCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate center point"),null;const t=this.getViewportBounds(),i=t.x+t.width/2,s=t.y+t.height/2,n=this.components.appContainer,o=n.scale.x,a=n.getMapRotationRadians(),h=i-n.x,l=s-n.y,c=h/o,d=l/o,u=Math.cos(a),p=Math.sin(a),f=c*u+d*p,y=-c*p+d*u,m=f-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 t=this.managers.mapManager.mapBounds;if(t.minX===1/0||t.minY===1/0||t.maxX===-1/0||t.maxY===-1/0)return w.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(t.minX+t.maxX)/2,s=(t.minY+t.maxY)/2,n=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:n,y:o}}getWallPointsByViewportCenter(t){var f;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:n=0,offsetY:o=0}=t||{},a=this.getViewportCenterPoint()||{x:0,y:0},l=this.metersToPixels(i)/2,c=((f=this.components.appContainer)==null?void 0:f.getMapRotationRadians())||0,d=Math.cos(c),u=Math.sin(c);let p;return s==="horizontal"?p=[{vx:-l+n,vy:o},{vx:l+n,vy:o}]:p=[{vx:n,vy:-l+o},{vx:n,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(t){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getForbiddenMopZonePointsByViewportCenter(t){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getCleanZonePointsByViewportCenter(t){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getSpotPointByViewportCenter(t){const{offsetX:i=0,offsetY:s=0}=t||{},n=this.getViewportCenterPoint()||{x:0,y:0},o=n.x+i,a=n.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(t){var x;const{furnitureType:i=1,offsetX:s=0,offsetY:n=0}=t||{},a=this.config.furniture.assets.find(S=>S.type===i),h=this.metersToPixels((a==null?void 0:a.width)??1.8),l=this.metersToPixels((a==null?void 0:a.height)??2),c=h/2,d=l/2,u=this.getViewportCenterPoint()||{x:0,y:0},p=((x=this.components.appContainer)==null?void 0:x.getMapRotationRadians())||0,f=Math.cos(p),y=Math.sin(p);return[{vx:-c+s,vy:-d+n},{vx:c+s,vy:-d+n},{vx:c+s,vy:d+n},{vx:-c+s,vy:d+n}].map(S=>({x:u.x+S.vx*f+S.vy*y,y:u.y-S.vx*y+S.vy*f}))}areRoomsAdjacent(t){return!t||t.length===0?(w.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(t)}isPointInAnyRoom(t){return!t||typeof t.x!="number"||typeof t.y!="number"?(w.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(t):(w.warn("[Room] Map state not available"),null)}isWallIntersectsAnyRoom(t){return!t||t.length!==2||!t[0]||!t[1]||typeof t[0].x!="number"||typeof t[0].y!="number"||typeof t[1].x!="number"||typeof t[1].y!="number"?(w.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(t):(w.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(t){return!t||t.length!==4||!t[0]||!t[1]||!t[2]||!t[3]||typeof t[0].x!="number"||typeof t[0].y!="number"||typeof t[1].x!="number"||typeof t[1].y!="number"||typeof t[2].x!="number"||typeof t[2].y!="number"||typeof t[3].x!="number"||typeof t[3].y!="number"?(w.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(t):(w.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(t,i,s){var h,l;if(!t||t.length<1)return w.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(t.length!==1&&t.length!==2&&t.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:n=!0,checkRobot:o=!1}=s||{};if(!n&&!o)return w.warn("[Distance] At least one of checkCharger or checkRobot must be true"),!1;const a=this.metersToPixels(i);if(n){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=za(c,t);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=za(c,t);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(t){this.render();const{snapshot:i,global:s}=this.config,n=(t==null?void 0:t.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=Br.create({width:c,height:d,resolution:u}),f=new H;f.rect(0,0,c,d).fill(n);const y=new U;y.translate(-h,-l);try{return this.renderer.render({container:f,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{f.destroy(),p.destroy(!0)}}async snapshotByData({map:t,path:i,roomProperties:s,customElements:n,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c},d={},u){const p=`SNAPSHOT_${Ux()}`;w.log(`[MapApplication] ${p} snapshot start`);const f=new Zr(p);try{if(await f.initialize({config:this.config,runtime:d}),!t)throw new Error("Map data is required");if(t.startsWith("7b22")){const m=id(t);await f.drawMap(m)}else{const m=sd(t,{pointsStructured:!0});if(m)await f.drawRasterMap(m);else throw new Error("Failed to decode raster map data")}if(i){const{decodePath:m}=await _e(async()=>{const{decodePath:S}=await import("./theme.DZz2Y3xc.js").then(v=>v.i);return{decodePath:S}},__vite__mapDeps([4,2])),x=m(i);f.drawPath(x)}s&&s.length>0&&await f.drawRoomProperty(s),o&&o.length>0&&f.drawForbiddenSweepZones(o),a&&a.length>0&&f.drawForbiddenMopZones(a),h&&h.length>0&&f.drawVirtualWalls(h),c&&c.length>0&&await f.drawFurnitures(c),l&&l.length>0&&await f.drawDetectedObjects(l),n&&n.length>0&&await f.drawCustomElements(n);const y=await f.snapshot(u);return w.log(`[MapApplication] ${p} snapshot completed successfully`),y}catch(y){throw w.error(`[MapApplication] ${p} snapshot other map failed:`,y),y}finally{w.log(`[MapApplication] ${p} destroy`),f.destroy()}}renderOnce(){w.log("[Pixi] renderOnce"),this.render()}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{w.log("[Pixi] renderOnceNextFrame"),this.render(),this.pendingAsyncRender=!1}))}requestRender(t,i=!1){if(!i){this.renderOnceNextFrame();return}this.tickerState.renderReasons.add(t),this.ticker.started||(w.debug(`🎬 [Ticker] START: ${t}`),this.ticker.start())}stopRender(t){this.tickerState.renderReasons.delete(t),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100)}destroy(){var t;w.log("[MapApplication] destroy"),this.tickerState.renderTimer&&(clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=null),this.tickerState.renderReasons.clear(),this.emitter.all.clear(),document.removeEventListener("visibilitychange",this.onVisibilityChange),this.managers.pathManager.destroy(),this.managers.mapManager.destroy(),this.managers.controlsManager.destroy(),this.managers.furnitureManager.destroy(),this.managers.detectedObjectManager.destroy(),this.managers.customElementsManager.destroy(),this.managers.roomsManager.destroy(),this.components.interaction.destroy(),(t=this.components.background)==null||t.destroy(),this.components.viewportContainer.destroy(),this.components.appContainer.destroy(),this.managers.heatmapManager.destroy(),super.destroy()}initializeViewportContainer(){this.components.viewportContainer=new Hx(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const t=this.getViewportBounds();this.components.background=new VS(this.config.global,t,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Fs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new Yx(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Ly(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(t,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(t),this.tickerState.renderReasons.size===0&&(w.debug("⏸️ [Ticker] STOP"),this.ticker&&this.ticker.stop())},i)}generateZonePoints(t,i,s){var u;const n=this.getViewportCenterPoint()||{x:0,y:0},a=this.metersToPixels(t)/2,h=((u=this.components.appContainer)==null?void 0:u.getMapRotationRadians())||0,l=Math.cos(h),c=Math.sin(h);return[{vx:-a+i,vy:-a+s},{vx:a+i,vy:-a+s},{vx:a+i,vy:a+s},{vx:-a+i,vy:a+s}].map(p=>({x:n.x+p.vx*l+p.vy*c,y:n.y-p.vx*c+p.vy*l}))}preloadAssets(){const t=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:t}),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:"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((n,o)=>{const a=`cleanMode_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.suction.assets.forEach((n,o)=>{const a=`fan_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.cistern.assets.forEach((n,o)=>{const a=`water_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.cleanTimes.assets.forEach((n,o)=>{const a=`cleanTimes${o+1}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.floorType.assets.forEach((n,o)=>{if(!n)return;const a=`floorType${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.customAssets&&Object.entries(this.config.room.property.customAssets).forEach(([n,o])=>{o.forEach((a,h)=>{const l=`custom_${n}_${h}`;N.add({alias:l,src:a}),s.push(l)})}),this.config.furniture.assets.forEach(n=>{const o=`furniture_${n.type}`;N.add({alias:o,src:n.src}),s.push(o)}),N.backgroundLoad(s)}setupMapRotationListener(){this.applyMapRotation(this.runtime.mapRotation),W(this.runtime,"mapRotation",t=>{this.applyMapRotation(t)})}applyMapRotation(t){const i=(t%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()}}const r0=Object.freeze(Object.defineProperty({__proto__:null,AppService:ac,MapApplication:Zr},Symbol.toStringTag,{value:"Module"}));export{Ho as $,Pi as A,he as B,se as C,pr as D,Yt as E,mr as F,H as G,Kg as H,ii as I,Of as J,Es as K,kf as L,U as M,Ot as N,Is as O,tt as P,gr as Q,et as R,Wp as S,G as T,Ie as U,j as V,Kh as W,Fi as X,Vi as Y,Lp as Z,ci as _,ti as a,_i as a0,yr as a1,Xh as a2,Dt as a3,ni as a4,dl as a5,ff as a6,xf as a7,n0 as a8,pl as a9,Gi as aA,Vp as aB,ul as aC,gf as aD,vf as aE,$g as aF,fl as aG,bf as aH,Hg as aI,r0 as aJ,Be as aa,ps as ab,Tu as ac,gd as ad,le as ae,si as af,wf as ag,_t as ah,xh as ai,Bt as aj,_s as ak,fo as al,jt as am,Em as an,Yd as ao,mo as ap,$s as aq,yo as ar,Zd as as,vh as at,Br as au,kr as av,$h as aw,Hi as ax,Ju as ay,Zu as az,Jn as b,rt as c,V as d,ce as e,tr as f,cs as g,xt as h,X as i,xu as j,ft as k,um as l,dt as m,Gn as n,au as o,I as p,yt as q,kd as r,Ug as s,Sa as t,Ru as u,J as v,nt as w,$ as x,L as y,st as z};
744
+ `,entryPoint:"main"}})}),l=new Ca({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(t,i){this.position.set(t,i)}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class sS{constructor(e){g(this,"heatmap");g(this,"pointsTopLeftOrigin",[]);g(this,"signalGrid",[]);g(this,"cellSize",2);g(this,"maxDistance",14);g(this,"smoothIterations",10);g(this,"heatmapAlpha",.8);g(this,"isHeatmapDrawn",!1);g(this,"loadTimer",null);g(this,"pendingPoints",null);this.appService=e,this.heatmap=new iS(e);const t=e.heatMapConfig;this.cellSize=t.cellSize,this.maxDistance=t.maxDistance,this.smoothIterations=t.smoothIterations,this.heatmapAlpha=t.heatmapAlpha}draw(e){const t=this.appService;if(!t.isMapDrawn){this.pendingPoints=e;return}this.pendingPoints=null;const{minX:i,minY:s}=t.mapManager.mapBounds,n=e.map(o=>({x:+(o.x-i).toFixed(0),y:+(o.y-s).toFixed(0),signal:o.signal}));this.signalGrid=this.calculateInterpolatedSignal(n),this.heatmap.draw(this.signalGrid,this.heatmapAlpha),this.isHeatmapDrawn=!0}onMapLoaded(){this.loadTimer||(this.pendingPoints&&this.draw(this.pendingPoints),this.loadTimer=setTimeout(()=>{this.loadTimer=null},200))}calculateInterpolatedSignal(e){var p;const t=this.appService,i=((p=t.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:n,maxX:o,maxY:a}=t.mapManager.mapBounds;n=n-i.y,s=s-i.x,a=a-i.y,o=o-i.x;const h=Math.ceil((a-n)/this.cellSize),l=Math.ceil((o-s)/this.cellSize),c=Array(h).fill(null).map(()=>Array(l).fill(null));for(let f=0;f<h;f++){const y=n+f*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<e.length;C++){const A=e[C];if(Math.abs(S-A.x)<=v/2&&Math.abs(y-A.y)<=m/2){const k=1-A.signal/7;b=Math.round(Math.max(b,k)*10)/10,P=!0}}c[f][x]={x:S,y,signal:b,hasPoint:P}}}const d=(f,y)=>{if(e.length===0)return 0;let m=0,x=0;for(const S of e){const v=Math.sqrt((f-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=(f,y=1)=>{for(let m=0;m<y;m++){const x=f.map(S=>[...S]);for(let S=1;S<h-1;S++)for(let v=1;v<l-1;v++)if(!f[S][v].hasPoint){let b=0,P=0;const C=4;for(let A=-C;A<=C;A++)for(let k=-C;k<=C;k++){if(A===0&&k===0)continue;const M=S+A,T=v+k;if(M>=0&&M<h&&T>=0&&T<l){const E=1/(1+Math.sqrt(A*A+k*k)*.3);b+=f[M][T].signal*E,P+=E}}if(P>0){const A=b/P,k=.6,M=.4;x[S][v].signal=f[S][v].signal*k+A*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++)f[S][v].signal=x[S][v].signal}};for(let f=0;f<h;f++)for(let y=0;y<l;y++){const m=c[f][y];m.hasPoint||(m.signal=d(m.x,m.y))}return u(c,this.smoothIterations),c}updatePositionByOrigin(e,t){this.heatmap.updatePositionByOrigin(e,t)}destroy(){this.heatmap.destroy()}}class xc extends L{constructor(t){super();g(this,"throttledUpdateScale");this.appService=t,this.throttledUpdateScale=Ct(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(t){t!==0&&this.scale.set(1/t)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class Ni extends xc{constructor(t,i){super(t);g(this,"background");g(this,"icon");g(this,"options");this.appService=t,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Xt(t),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const t=this.appService,i=this.options.config||t.controlsConfig,s=8,n=i.iconWrapperWidth+s*2,o=i.iconWrapperHeight+s*2;this.hitArea=new et(-n/2,-o/2,n,o)}async render(){this.renderBackground(),this.renderIcon()}renderBackground(){const t=this.appService,i=this.options.config||t.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 t=this.appService,i=this.options.config||t.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(t){w.error(`Failed to load icon: ${this.options.iconAlias}`,t)}}destroy(){super.destroy()}}class Sc extends Ni{constructor(t,i){super(t,i);g(this,"isRotating",!1);g(this,"hasRotated",!1);g(this,"rotationCenter",{x:0,y:0});g(this,"lastAngle",0);g(this,"clickHandler",null);g(this,"handleRotationPointerMove",t=>{var o,a;if(!this.isRotating)return;this.hasRotated=!0;const i=this.parent.toLocal(t.global),s=Math.atan2(i.y-this.rotationCenter.y,i.x-this.rotationCenter.x),n=s-this.lastAngle;(a=(o=this.options).onRotationMove)==null||a.call(o,n),this.lastAngle=s});g(this,"handleRotationPointerUp",()=>{var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)});g(this,"handleRotationCancel",()=>{var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)});this.appService=t,this.setupRotationEventListeners()}setupRotationEventListeners(){const{emitter:t}=this.appService;this.appService.emitter.on("gestureHijackPointerMove",this.handleRotationPointerMove),t.on("gestureHijackPointerUp",this.handleRotationPointerUp),t.on("gestureHijackCancel",this.handleRotationCancel)}cleanupRotationEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleRotationPointerMove),t.off("gestureHijackPointerUp",this.handleRotationPointerUp),t.off("gestureHijackCancel",this.handleRotationCancel)}setupEvents(){this.options.onClick&&(this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.hasRotated||(i=(t=this.options).onClick)==null||i.call(t)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startRotation(t)}startRotation(t){var n,o;this.isRotating=!0,this.hasRotated=!1;const i=this.options.getTargetPoints();this.rotationCenter=de(i);const s=this.parent.toLocal(t.global);this.lastAngle=Math.atan2(s.y-this.rotationCenter.y,s.x-this.rotationCenter.x),(o=(n=this.options).onRotationStart)==null||o.call(n,this.rotationCenter),this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var t,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(t=this.options).onRotationEnd)==null||i.call(t)),this.hasRotated=!1)}destroy(){var t;this.stopRotation(),(t=this.clickHandler)==null||t.destroy(),this.cleanupRotationEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class zs extends Ni{constructor(t,i){super(t,i);g(this,"clickHandler",null);this.appService=t}setupEvents(){this.clickHandler=new vt(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var t;(t=this.clickHandler)==null||t.destroy(),super.destroy()}}class Qe extends Ni{constructor(t,i){super(t,i);g(this,"isScaling",!1);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"handleScalePointerMove",t=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:n})});g(this,"handleScalePointerUp",()=>{var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))});g(this,"handleScaleCancel",()=>{var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))});this.appService=t,this.setupScaleEventListeners()}setupScaleEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleScalePointerMove),t.on("gestureHijackPointerUp",this.handleScalePointerUp),t.on("gestureHijackCancel",this.handleScaleCancel)}cleanupScaleEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleScalePointerMove),t.off("gestureHijackPointerUp",this.handleScalePointerUp),t.off("gestureHijackCancel",this.handleScaleCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startScaling(t)}startScaling(t){var i,s,n,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(t.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=(n=this.options).onScaleStart)==null||o.call(n,h)}this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var t,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(t=this.options).onScaleEnd)==null||i.call(t))}destroy(){this.stopScaling(),this.cleanupScaleEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ls extends Ni{constructor(t,i){super(t,i);g(this,"isMoving",!1);g(this,"dragStartPosition",null);g(this,"handleMovePointerMove",t=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,t)});g(this,"handleMovePointerUp",()=>{var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))});g(this,"handleMoveCancel",()=>{var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))});this.appService=t,this.setupMoveEventListeners()}setupMoveEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleMovePointerMove),t.on("gestureHijackPointerUp",this.handleMovePointerUp),t.on("gestureHijackCancel",this.handleMoveCancel)}cleanupMoveEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleMovePointerMove),t.off("gestureHijackPointerUp",this.handleMovePointerUp),t.off("gestureHijackCancel",this.handleMoveCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(t){t.stopPropagation(),this.startMoving(t)}startMoving(t){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(t.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.appService.emitter.emit("gestureHijackStart",t)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var t,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(t=this.options).onMoveEnd)==null||i.call(t))}destroy(){this.stopMoving(),this.cleanupMoveEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ur extends H{constructor(t,i){super();g(this,"fillOptions");g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"handlePointerDown",t=>{t.stopPropagation(),this.startDragging(t)});g(this,"handleDragPointerMove",t=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,t)});g(this,"handleDragPointerUp",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(t=this.fillOptions).onDragEnd)==null||i.call(t))});g(this,"handleDragCancel",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(t=this.fillOptions).onDragEnd)==null||i.call(t))});this.appService=t,this.fillOptions=i,this.setupInteraction(),this.setupDragEventListeners(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}startDragging(t){var s,n;this.isDragging=!0;const i=this.parent.toLocal(t.global);this.dragStartPosition={x:i.x,y:i.y},(n=(s=this.fillOptions).onDragStart)==null||n.call(s,t),this.appService.emitter.emit("gestureHijackStart",t)}draw(){const{points:t,fillColor:i}=this.fillOptions;if(t.length<3)return;this.clear();const s=t.flatMap(n=>[n.x,n.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(t){this.fillOptions={...this.fillOptions,...t},t.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(t){this.fillOptions.points=t,this.draw()}updateFillColor(t){this.fillOptions.fillColor=t,this.draw()}stopDragging(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(t){this.fillOptions.enableInteraction=t,t?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}const Hr=(r,e,t)=>{if(e!=null){if(typeof e!="number"||!Number.isFinite(e)||e<=r){w.warn(`[${t}] maxSize (${String(e)}) must be a finite number greater than minSize (${r}); ignoring.`);return}return e}};class Nt extends L{constructor(t,i){super();g(this,"borderOptions");g(this,"solidLine",null);g(this,"dashGraphics",null);g(this,"fillGraphics",null);g(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=t,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:t=[],closePath:i=!1,style:s}=this.borderOptions;t.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(t,s),s.isDashed?this.drawContinuousDashedBorder(t,i,s):this.drawSolidBorder(t,i,s))}drawFill(t,i){if(!(!i.fillColor||t.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(t[0].x,t[0].y);for(let s=1;s<t.length;s++)this.fillGraphics.lineTo(t[s].x,t[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(t,i,s){const n=this.appService;this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy()),this.solidLine=new H;const o=n.getApp().toFixedSize(s.width);this.solidLine.setStrokeStyle({color:s.color,width:o}),this.solidLine.moveTo(t[0].x,t[0].y);for(let a=1;a<t.length;a++)this.solidLine.lineTo(t[a].x,t[a].y);i&&this.solidLine.lineTo(t[0].x,t[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(t,i,s){if(t.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 n=this.appService;this.dashGraphics=new H;const o=n.getApp().toFixedSize(s.width);this.dashGraphics.setStrokeStyle({color:s.color,width:o});const a=Math.max(n.getApp().toFixedSize(s.dashArray[0]),1),h=Math.max(n.getApp().toFixedSize(s.dashArray[1]),1),l=i?[...t,t[0]]:t;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(t,i,s,n){if(i.length<2)return;if(s<=0||n<=0){w.warn("Invalid dash parameters:",{dashLength:s,gapLength:n});return}const o=this.calculatePathSegments(i),a=o.reduce((c,d)=>c+d.length,0);if(a===0)return;const h=s+n;let l=0;for(;l<a;){const c=l+s;c<=a?this.drawContinuousDashSegment(t,o,l,c):this.drawContinuousDashSegment(t,o,l,a),l+=h}}calculatePathSegments(t){const i=[];for(let s=0;s<t.length-1;s++){const n=t[s],o=t[s+1],a=o.x-n.x,h=o.y-n.y,l=Math.sqrt(a*a+h*h);i.push({start:n,end:o,length:l})}return i}drawContinuousDashSegment(t,i,s,n){if(s>=n)return;let o=0,a=!1,h=null;for(const l of i){const c=o,d=o+l.length;if(d>s&&c<n){const u=Math.max(s,c),p=Math.min(n,d),f=(u-c)/l.length,y=(p-c)/l.length,m={x:l.start.x+(l.end.x-l.start.x)*f,y:l.start.y+(l.end.y-l.start.y)*f},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&&t.lineTo(m.x,m.y):(t.moveTo(m.x,m.y),a=!0),t.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=n)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(t){this.borderOptions.style={...this.borderOptions.style,...t},this.drawBorder()}updatePoints(t){this.borderOptions.points=t,this.drawBorder()}setClosePath(t){this.borderOptions.closePath=t,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class ji extends Bs{constructor(t,{text:i,style:s}){super({text:i,style:s});g(this,"throttledUpdateScale");this.appService=t,this.throttledUpdateScale=Ct(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(t){t<=0||this.scale.set(1/t)}setBaseFontSize(t){this.style.fontSize=t}updateText(t){this.text=t}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}const At=class At extends L{constructor(t){super();g(this,"appService");g(this,"zoneData");g(this,"zoneType");g(this,"zoneConfig");g(this,"controlsConfig");g(this,"zoneEvents");g(this,"controlFill");g(this,"zoneBorder");g(this,"outlineBorder");g(this,"moveLine");g(this,"sizeText");g(this,"controlButtons");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"totalRotationAngle",0);g(this,"rotationCenter",null);g(this,"initialZonePoints",[]);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"clickHandler",null);g(this,"resolvedMaxSizeCache",null);g(this,"throttledUpdateOutline");g(this,"handleDragStart",t=>{this.isEditingEnabled()&&(this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.dragStartPosition=this.parent.toLocal(t.global),this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var t,i;this.initialZonePoints=[],this.dragStartPosition=null,this.appService.getApp().stopRender("zone-drag"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleRotationStart",t=>{this.totalRotationAngle=0,this.rotationCenter=t,this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",t=>{this.totalRotationAngle+=t,this.applyRotation(this.totalRotationAngle)});g(this,"handleRotationEnd",()=>{var t,i;this.rotationCenter=null,this.totalRotationAngle=0,this.initialZonePoints=[],this.appService.getApp().stopRender("zone-rotate"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleScaleStart",()=>{this.initialZonePoints=this.zoneData.points.map(i=>({...i}));const t=At.BUTTON_INDICES.SCALE;t<this.zoneData.points.length&&(this.initialButtonPosition={...this.zoneData.points[t]}),this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialZonePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var t,i;this.initialZonePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("zone-scale"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(t=>({...t})),this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",t=>{var a;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(t.global),s=(a=this.moveButton)==null?void 0:a.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(t=this.zoneEvents).onUpdate)==null||i.call(t,this.getZoneData())});g(this,"handleDelete",()=>{var t,i;(i=(t=this.zoneEvents).onRemove)==null||i.call(t,this.zoneData.id)});const{appService:i,zoneData:s,zoneType:n,events:o={}}=t;this.appService=i,this.zoneType=n,this.zoneEvents=o,this.zoneConfig=this.getZoneConfig(),this.controlsConfig=this.getControlsConfig();const a=this.validateAndCorrectZoneSize(s.points),h=Cs(a);this.zoneData={...s,points:h},this.throttledUpdateOutline=Ct(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.createControlButtons(),this.updateEditState(),this.setupClickHandler(),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){this.isEditingEnabled()&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}getZoneConfig(){var i;const t=this.appService.getConfig();if(Ne(this.zoneType)){const s=t.controls[this.zoneType];if(s)return s}else{const s=(i=t.customZoneTypes)==null?void 0:i[this.zoneType];if(s)return s}return Ei.cleanZone}getControlsConfig(){const{controls:t}=this.appService.getConfig();return t}validateAndCorrectZoneSize(t){if(t.length<4)return t;const i=this.appService.metersToPixels(this.zoneConfig.minSize),s=this.getResolvedMaxSize(),n=s!=null?this.appService.metersToPixels(s):void 0;return nr(t,i,n)}getResolvedMaxSize(){const t=this.zoneConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===t)return this.resolvedMaxSizeCache.value;const i=Hr(this.zoneConfig.minSize,t,this.zoneType);return this.resolvedMaxSizeCache={key:t,value:i},i}isEditingEnabled(){var s;const t=this.appService.runtimeSnapshot,i=this.zoneData.id;switch(this.zoneType){case"forbiddenSweepZone":return t.editingForbiddenSweepZoneIds.includes(i);case"forbiddenMopZone":return t.editingForbiddenMopZoneIds.includes(i);case"cleanZone":return t.editingCleanZoneIds.includes(i);default:return(((s=t.editingCustomZoneIds)==null?void 0:s[this.zoneType])??[]).includes(i)}}initializeComponents(){this.outlineBorder=this.createOutlineBorder(),this.addChild(this.outlineBorder),this.controlFill=this.createControlFill(),this.addChild(this.controlFill),this.zoneBorder=this.createBorder(),this.addChild(this.zoneBorder),this.moveLine=this.createMoveLine(),this.addChild(this.moveLine),this.sizeText=this.createSizeText(),this.addChild(this.sizeText),this.controlButtons=new L,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.drawZone()}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;this.deleteButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onClick:this.handleDelete}),this.deleteButton.position.set(t[At.BUTTON_INDICES.REMOVE].x,t[At.BUTTON_INDICES.REMOVE].y),this.zoneConfig.showRotateButton&&(this.rotateButton=new Sc(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,onRotationStart:this.handleRotationStart,onRotationMove:this.handleRotationMove,onRotationEnd:this.handleRotationEnd}),this.rotateButton.position.set(t[At.BUTTON_INDICES.ROTATE].x,t[At.BUTTON_INDICES.ROTATE].y)),this.scaleButton=new Qe(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,getButtonIndex:()=>At.BUTTON_INDICES.SCALE,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(t[At.BUTTON_INDICES.SCALE].x,t[At.BUTTON_INDICES.SCALE].y);const i=this.calculateMoveButtonPosition();this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(i.x,i.y),this.controlButtons.addChild(this.deleteButton),this.rotateButton&&this.controlButtons.addChild(this.rotateButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}createControlFill(){const t=this.isEditingEnabled();return new Ur(this.appService,{points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:t,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(){const i=this.isEditingEnabled()?this.zoneConfig.editing:this.zoneConfig.normal;return new Nt(this.appService,{points:this.zoneData.points,closePath:!0,style:{color:this.zoneConfig.strokeColor,width:this.zoneConfig.strokeWidth,isDashed:i.isDashed,dashArray:i.dashArray}})}createOutlineBorder(){const t=this.calculateOutlinePoints();return new Nt(this.appService,{points:t,closePath:!0,style:{color:this.zoneConfig.outlineStrokeColor,width:this.zoneConfig.outlineStrokeWidth,isDashed:this.zoneConfig.outlineDashed,dashArray:this.zoneConfig.outlineDashArray,fillColor:this.zoneConfig.outlineFillColor}})}createMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);return new Nt(this.appService,{points:i,closePath:!1,style:{color:this.zoneConfig.outlineStrokeColor,width:this.zoneConfig.outlineStrokeWidth,isDashed:this.zoneConfig.outlineDashed,dashArray:this.zoneConfig.outlineDashArray}})}calculateOutlinePoints(){const{points:t}=this.zoneData;if(t.length<4)return t;const i=this.appService.getApp().toFixedSize(this.zoneConfig.outlineOffset);return zr(t,i)}calculateMoveLinePoints(t){if(t.length<4)return[];const i=t[At.BUTTON_INDICES.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}createSizeText(){const t=this.calculateZoneSizeText(),i=new ji(this.appService,{text:t,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.zoneConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}calculateZoneSizeText(){const{points:t}=this.zoneData;if(t.length<4)return"0m*0m";const[i,s,,n]=t,o=Q(i,s),a=Q(i,n),h=this.appService.pixelsToMeters(o),l=this.appService.pixelsToMeters(a),c=this.appService.metersToDisplayUnit(h),d=this.appService.metersToDisplayUnit(l),u=this.appService.runtimeSnapshot.unitLabel;return`${c.toFixed(1)}${u}*${d.toFixed(1)}${u}`}calculateSizeTextPosition(){const{points:t}=this.zoneData;if(t.length<4)return{x:0,y:0};const[i,s,n,o]=t,{textPosition:a,textOffset:h}=this.zoneConfig,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2};const u=gt(K(s,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2};const u=gt(K(s,n)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2};const u=gt(K(o,n)),p={x:-u.y,y:u.x};d={x:p.x*l,y:p.y*l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2};const u=gt(K(o,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}default:c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:0,y:l};break}return{x:c.x+d.x,y:c.y+d.y}}calculateSizeTextRotation(){const{points:t}=this.zoneData;if(t.length<4)return 0;const[i,s,n,o]=t,{textPosition:a}=this.zoneConfig;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}calculateMoveButtonPosition(){const t=this.calculateOutlinePoints();if(t.length<4)return{x:0,y:0};const{controls:i}=this.appService.getConfig(),s=t[At.BUTTON_INDICES.MOVE],n=t[2],o=t[0],a=this.appService.getApp().toFixedSize(i.moveButtonOffset);return Ds(s,n,o,a)}applyTranslation(t,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawZone(),this.updateControlButtonsPosition()}applyRotation(t){!this.rotationCenter||this.initialZonePoints.length===0||(this.zoneData.points=Fr(this.initialZonePoints,this.rotationCenter,t),this.drawZone(!1),this.updateControlButtonsPosition())}applyEdgeBasedScale(t){if(this.initialZonePoints.length<4)return;const{FIXED:i}=At.BUTTON_INDICES,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=K(h,o),c=K(h,a),d=K(h,t),u=ee(l),p=ee(c);if(u===0||p===0)return;const f=this.appService.metersToPixels(this.zoneConfig.minSize),y=this.getResolvedMaxSize(),m=y!=null?this.appService.metersToPixels(y):void 0,[x,S]=[ae(d,l,u,f,m),ae(d,c,p,f,m)];this.zoneData.points=[h,{x:s+l.x*x,y:n+l.y*x},{x:s+l.x*x+c.x*S,y:n+l.y*x+c.y*S},{x:s+c.x*S,y:n+c.y*S}],this.drawZone(),this.updateControlButtonsPosition()}setupClickHandler(){this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.isEditingEnabled()||(i=(t=this.zoneEvents)==null?void 0:t.onClick)==null||i.call(t,this.getZoneData())},stopPropagation:!1})}drawZone(t=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.updateOutlineBorder(),this.updateMoveLine(),this.updateSizeText(t))}updateOutlineBorder(){const t=this.calculateOutlinePoints();this.outlineBorder.updatePoints(t)}updateMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);this.moveLine.updatePoints(i)}updateSizeText(t=!0){if(this.sizeText){if(t){const i=this.calculateZoneSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,ROTATE:s,SCALE:n}=At.BUTTON_INDICES,o=this.calculateMoveButtonPosition(),a=[{button:this.deleteButton,point:t[i]},{button:this.scaleButton,point:t[n]},{button:this.moveButton,point:o}];this.rotateButton&&a.push({button:this.rotateButton,point:t[s]}),a.forEach(({button:h,point:l})=>h.position.set(l.x,l.y))}updateEditState(){const t=this.isEditingEnabled();this.controlButtons.visible=t,!t&&this.getCurrentOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=t,this.moveLine.visible=t,this.sizeText&&(this.sizeText.visible=t),t&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition()),this.controlFill.setInteractionEnabled(t),this.updateBorderStyle(t?this.zoneConfig.editing:this.zoneConfig.normal),this.zIndex=t?1e3:0}updateBorderStyle(t){this.zoneBorder.updateStyle({isDashed:t.isDashed,dashArray:t.dashArray})}getCurrentOperationState(){var o,a,h;const t=this.controlFill.isCurrentlyDragging(),i=((o=this.scaleButton)==null?void 0:o.isCurrentlyScaling())||!1,s=((a=this.rotateButton)==null?void 0:a.isCurrentlyRotating())||!1,n=((h=this.moveButton)==null?void 0:h.isCurrentlyMoving())||!1;return{isDragging:t,isScaling:i,isRotating:s,isMoving:n,hasAnyOperation:t||i||s||n}}stopAllOperations(){var t,i,s;this.controlFill.stopDragging(),(t=this.scaleButton)==null||t.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}stopDragging(){this.controlFill.stopDragging()}stopScaling(){var t;(t=this.scaleButton)==null||t.stopScaling()}stopRotating(){var t;(t=this.rotateButton)==null||t.stopRotation()}stopMoving(){var t;(t=this.moveButton)==null||t.stopMoving()}isCurrentlyDragging(){return this.controlFill.isCurrentlyDragging()}isCurrentlyScaling(){var t;return((t=this.scaleButton)==null?void 0:t.isCurrentlyScaling())||!1}isCurrentlyRotating(){var t;return((t=this.rotateButton)==null?void 0:t.isCurrentlyRotating())||!1}isCurrentlyMoving(){var t;return((t=this.moveButton)==null?void 0:t.isCurrentlyMoving())||!1}updateZoneData(t){const i=this.validateAndCorrectZoneSize(t.points),s=Cs(i);this.zoneData={...t,points:s},this.drawZone(),this.updateControlButtonsPosition(),this.updateEditState()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var t,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(n=this.scaleButton)==null||n.destroy(),(o=this.moveButton)==null||o.destroy(),this.deleteButton=null,this.rotateButton=null,this.scaleButton=null,this.moveButton=null,(a=this.zoneBorder)==null||a.destroy(),(h=this.outlineBorder)==null||h.destroy(),(l=this.moveLine)==null||l.destroy(),(c=this.sizeText)==null||c.destroy(),(d=this.controlFill)==null||d.destroy(),(u=this.controlButtons)==null||u.destroy(),super.destroy()}};g(At,"BUTTON_INDICES",{REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0});let oi=At;class Vr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"forbiddenSweepZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickForbiddenSweepZone)==null||n.call(s,i)}}})}static create(e,t){return new Vr(e,{zoneData:t})}}class Nr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"forbiddenMopZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickForbiddenMopZone)==null||n.call(s,i)}}})}static create(e,t){return new Nr(e,{zoneData:t})}}class jr extends oi{constructor(e,t){super({appService:e,zoneData:t.zoneData,zoneType:"cleanZone",events:{onRemove:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onRemoveCleanZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateCleanZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onClickCleanZone)==null||n.call(s,i)}}})}static create(e,t){return new jr(e,{zoneData:t})}}class Ue extends H{constructor(t,i){super();g(this,"lineOptions");g(this,"strokeContext",null);g(this,"drawDashLine",()=>{const{start:t,end:i,style:s}=this.lineOptions;this.clear(),this.strokeContext&&this.strokeContext.destroy();const n=this.appService;this.strokeContext=new mt;const o=n.getApp().toFixedSize(s.width);this.strokeContext.setStrokeStyle({color:s.color,width:o}),this.drawDashedLineToContext(this.strokeContext,t.x,t.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=t,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(t,i,s,n,o,a,h){const l=n-i,c=o-s,d=Math.sqrt(l*l+c*c);if(d===0)return;const u=this.appService,p=u.getApp().toFixedSize(a),f=u.getApp().toFixedSize(h),y=p+f,m=d/y,x=Math.round(m);if(x===0){t.moveTo(i,s),t.lineTo(n,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let C=0;C<x;C++){const A=C*S,k=A+v;if(A>=d)break;const M=Math.min(k,d),T=i+A*b,_=s+A*P,E=i+M*b,B=s+M*P;t.moveTo(T,_),t.lineTo(E,B)}}updatePoints(t,i){this.lineOptions.start=t,this.lineOptions.end=i,this.drawDashLine()}updateStyle(t){this.lineOptions.style={...this.lineOptions.style,...t},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Vt=class Vt extends L{constructor(t){super();g(this,"wallData");g(this,"wallConfig");g(this,"controlsConfig");g(this,"wallEvents");g(this,"appService");g(this,"wallLine");g(this,"outlineBorder");g(this,"moveLine");g(this,"lengthText");g(this,"controlButtons");g(this,"removeButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"initialWallPoints",[]);g(this,"initialButtonPosition",null);g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"resolvedMaxWidthCache",null);g(this,"throttledUpdateOutline");g(this,"throttledHandleScaleChange");g(this,"wallLineClickHandler",null);g(this,"handleRemove",()=>{var t,i;(i=(t=this.wallEvents).onRemove)==null||i.call(t,this.wallData.id)});g(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(t=>({...t}))});g(this,"finalizeOperation",()=>{var t,i;this.initialWallPoints=[],(i=(t=this.wallEvents).onUpdate)==null||i.call(t,this.getWallData())});g(this,"handleScaleStart",()=>{this.initializeOperation();const t=this.calculateOutlinePoints();t.length>Vt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...t[Vt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});g(this,"handleScaleEnd",()=>{this.finalizeOperation(),this.initialButtonPosition=null,this.appService.getApp().stopRender("virtualwall-scale")});g(this,"handleMoveStart",()=>{this.initializeOperation(),this.appService.getApp().requestRender("virtualwall-move",!0)});g(this,"handleMove",t=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(t.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{this.finalizeOperation(),this.appService.getApp().stopRender("virtualwall-move")});g(this,"handleScaleChange",()=>{this.redrawSolidLine(),this.setupWallLineHitArea()});g(this,"handleWallLinePointerDown",t=>{this.isEditingEnabled()&&(t.stopPropagation(),this.startDragging(t))});g(this,"handleDragPointerMove",t=>{!this.isDragging||!this.dragStartPosition||this.handleMove(t)});g(this,"handleDragPointerUp",()=>{this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.finalizeOperation())});g(this,"handleDragCancel",()=>{this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.appService.getApp().stopRender("virtualwall-drag"),this.handleMoveEnd())});const{appService:i,wallData:s,events:n={}}=t;this.appService=i,this.wallEvents=n,this.wallConfig=this.appService.controlsConfig.virtualWall,this.controlsConfig=this.appService.controlsConfig,this.wallData={...s,points:this.validateAndCorrectWallLength(s.points)},this.throttledHandleScaleChange=Ct(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=Ct(this.updateOutlineForScale.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.updateEditState(),this.registerScaleListener(),this.setupDragEventListeners()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("antiScale",this.throttledHandleScaleChange),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}getResolvedMaxWidth(){const t=this.wallConfig.maxWidth;if(this.resolvedMaxWidthCache&&this.resolvedMaxWidthCache.key===t)return this.resolvedMaxWidthCache.value;const i=Hr(this.wallConfig.minWidth,t,"virtualWall");return this.resolvedMaxWidthCache={key:t,value:i},i}validateAndCorrectWallLength(t){if(t.length<2)return t;const[i,s]=t,n=this.appService.metersToPixels(this.wallConfig.minWidth),o=this.getResolvedMaxWidth(),a=o!=null?this.appService.metersToPixels(o):void 0,h=Q(i,s),l=h<n,c=a!=null&&h>a;if(!l&&!c)return t;if(h===0)return[i,{x:i.x+n,y:i.y}];const d=gt(K(i,s));let u=h;return a!=null&&(u=Math.min(u,a)),u=Math.max(u,n),[i,{x:i.x+d.x*u,y:i.y+d.y*u}]}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 L,this.controlButtons.visible=this.isEditingEnabled(),this.addChild(this.controlButtons),this.createControlButtons()}createWallLine(t=!0){const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:n,editing:o,normal:a}=this.wallConfig,l=this.isEditingEnabled()?o:a;l.isDashed?this.wallLine=new Ue(this.appService,{start:i[0],end:i[1],style:{color:n.toString(),width:s,dashArray:l.dashArray}}):this.wallLine=this.createSolidLine(i[0],i[1],s,n.toString()),t&&this.setupWallLineInteraction()}createLengthText(){const t=this.calculateWallLengthInMeters(),i=this.formatLengthText(t),s=new ji(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 n=this.calculateTextPosition();s.position.set(n.x,n.y);const o=this.calculateTextRotation();return s.rotation=o,s.eventMode="none",s}calculateWallLengthInMeters(){const{points:t}=this.wallData;if(t.length<2)return 0;const i=Q(t[0],t[1]);return this.appService.pixelsToMeters(i)}formatLengthText(t){const i=this.appService.metersToDisplayUnit(t),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:t}=this.wallData;if(t.length<2)return{x:0,y:0};const[i,s]=t,n=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return nc(i,s,n)}calculateTextRotation(){const{points:t}=this.wallData;if(t.length<2)return 0;const[i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(i,s,n)}getOutlineStyle(){return{color:this.wallConfig.outlineStrokeColor,width:this.wallConfig.outlineStrokeWidth,isDashed:this.wallConfig.outlineDashed,dashArray:this.wallConfig.outlineDashArray,fillColor:this.wallConfig.outlineFillColor}}createOutlineBorder(){const t=this.calculateOutlinePoints();return new Nt(this.appService,{points:t,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const t=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(t);return new Nt(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(t){const i=t||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),n=my(i[0],i[1],s);return[n[3],n[2],n[1],n[0]]}calculateMoveLinePoints(t){if(t.length<4)return[];const{MOVE:i}=Vt.BUTTON_INDICES,s=t[i],n=this.calculateMoveButtonPosition();return[s,n]}calculateMoveButtonPosition(){const{moveButtonOffset:t}=this.controlsConfig,i=this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{MOVE:s}=Vt.BUTTON_INDICES,n=i[s],o=i[(s+3)%4],a=i[(s+1)%4],h=this.appService.getApp().toFixedSize(t);return Ds(n,a,o,h)}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES;this.removeButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(t[i].x,t[i].y),this.scaleButton=new Qe(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(t[s].x,t[s].y);const n=this.calculateMoveButtonPosition();this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(n.x,n.y),this.controlButtons.addChild(this.removeButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton)}applyScaleAndRotation(t){if(this.initialWallPoints.length<2)return;const[i,s]=this.initialWallPoints,n=i,o=this.calculateOutlinePoints(this.initialWallPoints);if(o.length<4)return;const a=o[Vt.BUTTON_INDICES.SCALE],l=K(s,a),c={x:t.x-l.x,y:t.y-l.y},d=K(n,c),u=Q(n,c),p=this.appService.metersToPixels(this.wallConfig.minWidth),f=this.getResolvedMaxWidth(),y=f!=null?this.appService.metersToPixels(f):void 0;let m;if(u<p)if(u===0)m={x:n.x+p,y:n.y};else{const x=gt(d);m={x:n.x+x.x*p,y:n.y+x.y*p}}else if(y!=null&&u>y){const x=gt(d);m={x:n.x+x.x*y,y:n.y+x.y*y}}else m=c;this.wallData.points=[n,m],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(t,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:t}=this.wallData;t.length<2||(this.wallLine instanceof Ue?this.wallLine.updatePoints(t[0],t[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const t=this.calculateWallLengthInMeters(),i=this.formatLengthText(t);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const t=this.calculateTextPosition();this.lengthText.position.set(t.x,t.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const t=this.calculateOutlinePoints();this.outlineBorder.updatePoints(t);const i=this.calculateMoveLinePoints(t);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES,n=this.calculateMoveButtonPosition();this.removeButton.position.set(t[i].x,t[i].y),this.scaleButton.position.set(t[s].x,t[s].y),this.moveButton.position.set(n.x,n.y)}updateEditState(){const t=this.isEditingEnabled();this.controlButtons.visible=t,this.outlineBorder.visible=t,this.moveLine.visible=t,this.lengthText&&(this.lengthText.visible=t),t&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=t?1e3:0}createSolidLine(t,i,s,n){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(t.x,t.y),o.lineTo(i.x,i.y),o.stroke({color:n,width:a}),o}updateWallLineStyle(){const t=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:n,lineColor:o}=this.wallConfig,a=t?i:s;this.wallLine instanceof Ue!==a.isDashed?(this.removeChild(this.wallLine),this.wallLine.destroy(),this.createWallLine(!1),this.addChild(this.wallLine)):this.wallLine instanceof Ue?this.wallLine.updateStyle({color:o.toString(),width:n,dashArray:a.dashArray}):this.redrawSolidLine()}redrawSolidLine(){const t=this.appService;if(!this.wallLine||this.wallLine instanceof Ue)return;const{points:i}=this.wallData;if(i.length<2)return;const{lineWidth:s,lineColor:n}=this.wallConfig,o=t.getApp().toFixedSize(s);this.wallLine.clear(),this.wallLine.setStrokeStyle({color:n.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 t=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),t?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new vt(this.wallLine,{onClick:()=>{var s,n;this.appService.emitter.emit("suppressMapClick"),(n=(s=this.wallEvents)==null?void 0:s.onClick)==null||n.call(s,this.getWallData())},stopPropagation:!1})}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}startDragging(t){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(t.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.appService.emitter.emit("gestureHijackStart",t)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:t}=this.wallData;if(t.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),n=rc(t[0],t[1],s);if(n.length===0)return;const o=new Te(n);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(t){this.wallData={...t,points:this.validateAndCorrectWallLength(t.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var t,i,s,n,o,a,h,l,c;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),this.cleanupDragEventListeners(),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),this.wallLine&&this.wallLine.off("pointerdown",this.handleWallLinePointerDown),(t=this.wallLineClickHandler)==null||t.destroy(),this.wallLineClickHandler=null,(i=this.wallLine)==null||i.destroy(),(s=this.lengthText)==null||s.destroy(),(n=this.outlineBorder)==null||n.destroy(),(o=this.moveLine)==null||o.destroy(),(a=this.controlButtons)==null||a.destroy(),(h=this.removeButton)==null||h.destroy(),(l=this.scaleButton)==null||l.destroy(),(c=this.moveButton)==null||c.destroy(),this.removeButton=null,this.scaleButton=null,this.moveButton=null,super.destroy()}};g(Vt,"BUTTON_INDICES",{REMOVE:0,SCALE:2,MOVE:3});let ar=Vt;class Yr extends L{constructor(t){super();g(this,"spotData");g(this,"spotConfig");g(this,"controlsConfig");g(this,"spotEvents");g(this,"appService");g(this,"controlFill");g(this,"spotBorder");g(this,"centerIcon");g(this,"sizeText");g(this,"clickHandler",null);g(this,"initialSpotPoint",null);g(this,"dragStartMousePosition",null);g(this,"throttledUpdateScale");g(this,"unsubscribeMapRotation",null);g(this,"handleDragStart",t=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(t.global),this.appService.getApp().requestRender("spot-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartMousePosition.x,n=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var t,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(t=this.spotEvents).onUpdate)==null||i.call(t,this.getSpotData())});const{appService:i,spotData:s,events:n={}}=t;this.appService=i,this.spotData=s,this.spotEvents=n,this.controlsConfig=this.appService.controlsConfig,this.spotConfig=this.appService.controlsConfig.spot,this.position.set(s.point.x,s.point.y),this.throttledUpdateScale=Ct(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()}isEditingEnabled(){return this.appService.runtimeSnapshot.editingSpotIds.includes(this.spotData.id)}shouldShowIcon(){return(this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal).showIcon}calculateRectanglePoints(){const{size:t}=this.spotConfig;if(t===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.metersToPixels(t)/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const t=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(t),this.addChild(this.controlFill),this.spotBorder=this.createBorder(t),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.drawSpot()}createControlFill(t){const i=this.isEditingEnabled();return new Ur(this.appService,{points:t,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(t){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new Nt(this.appService,{points:t,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const t=new Xt(this.appService);return this.loadIconTexture(t),t.position.set(0,0),t.eventMode="static",this.setupIconDrag(t),t.visible=!1,t}async loadIconTexture(t){const{iconSize:i,iconSizeFixed:s}=this.spotConfig;await t.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)})),t.visible=this.shouldShowIcon()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}setupIconDrag(t){let i=null,s=!1;const n=h=>{if(!s||!this.initialSpotPoint||!i)return;const l=this.parent.toLocal(h.global),c=l.x-i.x,d=l.y-i.y;this.applyTranslation(c,d)},o=()=>{s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),this.appService.emitter.off("gestureHijackPointerMove",n),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.off("gestureHijackCancel",o))},a=()=>{var h,l;s&&(s=!1,this.initialSpotPoint=null,i=null,this.appService.getApp().stopRender("spot-drag"),(l=(h=this.spotEvents).onUpdate)==null||l.call(h,this.getSpotData()),this.appService.emitter.off("gestureHijackPointerMove",n),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.off("gestureHijackCancel",o))};t.on("pointerdown",h=>{this.isEditingEnabled()&&(h.stopPropagation(),s=!0,this.initialSpotPoint={...this.spotData.point},i=this.parent.toLocal(h.global),this.appService.getApp().requestRender("spot-drag",!0),this.appService.emitter.emit("gestureHijackStart",h),this.appService.emitter.on("gestureHijackPointerMove",n),this.appService.emitter.on("gestureHijackPointerUp",a),this.appService.emitter.on("gestureHijackCancel",o))})}createSizeText(){const t=this.calculateSpotSizeText(),i=new ji(this.appService,{text:t,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:t}=this.spotConfig,i=this.appService.metersToDisplayUnit(t),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const t=this.calculateRectanglePoints();if(t.length<4)return{x:0,y:0};const[i,s,n,o]=t,{textPosition:a,textOffset:h}=this.spotConfig,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:c.x,y:c.y+l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2},d={x:c.x+l,y:c.y};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2},d={x:c.x,y:c.y+l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2},d={x:c.x-l,y:c.y};break}default:{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:c.x,y:c.y+l};break}}return d}applyTranslation(t,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+t,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const t=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new vt(t,{onClick:()=>{var i,s;this.isEditingEnabled()||(this.appService.emitter.emit("suppressMapClick"),(s=(i=this.spotEvents)==null?void 0:i.onClick)==null||s.call(i,this.getSpotData()))},stopPropagation:!1}),this.eventMode="static"}drawSpot(){const t=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(t),this.spotBorder&&this.spotBorder.updatePoints(t)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText()}updateSizeText(){if(!this.sizeText)return;const t=this.calculateSpotSizeText();this.sizeText.updateText(t),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y)}updateEditState(){const t=this.isEditingEnabled(),i=t?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=t&&this.spotConfig.showText),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(t),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=t?1e3:0}updateSpotData(t){this.spotData={...t},this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var t,i,s,n,o;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(t=this.clickHandler)==null||t.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(),(n=this.centerIcon)==null||n.destroy(),(o=this.sizeText)==null||o.destroy(),super.destroy()}static create(t,i){return new Yr({appService:t,spotData:i,events:{onUpdate:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onUpdateSpot)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onClickSpot)==null||o.call(n,s)}}})}}class nS extends xc{constructor(t){const{appService:i,wayPointData:s,order:n,events:o={}}=t;super(i);g(this,"wayPointData");g(this,"order");g(this,"wayPointConfig");g(this,"controlsConfig");g(this,"wayPointEvents");g(this,"icon");g(this,"orderContainer");g(this,"orderBackground");g(this,"orderText");g(this,"clickHandler",null);g(this,"initialWayPointPoint",null);g(this,"unsubscribeMapRotation",null);this.wayPointData=s,this.order=n,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 t=new Xt(this.appService);return this.loadIconTexture(t),t.position.set(0,0),t.anchor.set(.5,1),t.eventMode="static",this.setupIconDrag(t),t}async loadIconTexture(t){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:n}=s,o=i?"wayPointActive":"wayPoint";await t.loadTextureAndSetSize(o,{width:n,height:n,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),t.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:n}=i;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Bs({text:this.order.toString(),style:new ce({fontSize:n.fontSize,fontFamily:n.fontFamily,fontWeight:n.fontWeight,fill:n.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:n}=i.orderContainer;this.orderContainer.position.set(s,-n)}setupIconDrag(t){let i=null,s=null,n=!1;const o=h=>{if(!(!n||!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;n&&(n=!1,i=null,s=null,(l=(h=this.wayPointEvents).onUpdate)==null||l.call(h,this.wayPointData),this.appService.emitter.off("gestureHijackPointerMove",o),this.appService.emitter.off("gestureHijackPointerUp",a),this.appService.emitter.emit("gestureHijackCancel"))};t.on("pointerdown",h=>{this.isEditingEnabled()&&(h.stopPropagation(),s={...this.wayPointData.point},this.parent&&(i=this.parent.toLocal(h.global)),n=!0,this.parent&&(this.appService.emitter.emit("gestureHijackStart",h),this.appService.emitter.on("gestureHijackPointerMove",o),this.appService.emitter.on("gestureHijackPointerUp",a)))})}setupClickHandler(){this.clickHandler=new vt(this.icon,{stopPropagation:!1,onClick:()=>{var t,i;this.appService.emitter.emit("suppressMapClick"),(i=(t=this.wayPointEvents).onClick)==null||i.call(t,this.wayPointData)}})}updateWayPoint(t){this.wayPointData=t,this.drawWayPoint()}updateOrder(t){this.order=t,this.orderText&&(this.orderText.text=t.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 ce({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor:n}=i.orderContainer;this.orderBackground.clear(),this.orderBackground.circle(0,0,s/2).fill(n),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 Ka extends H{constructor(t,i){super();g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"initialPosition");g(this,"handleDragPointerMove",t=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y,o={x:this.initialPosition.x+s,y:this.initialPosition.y+n};this.position.set(o.x,o.y),(h=(a=this.options).onDragMove)==null||h.call(a,o)});g(this,"handleDragPointerUp",()=>{var i,s;if(!this.isDragging)return;const t=this.appService;this.isDragging=!1,this.dragStartPosition=null,t.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});g(this,"handleDragCancel",()=>{var i,s;if(!this.isDragging)return;const t=this.appService;this.isDragging=!1,this.dragStartPosition=null,t.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=t,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(),this.setupDragEventListeners()}draw(){const t=this.appService,{config:i}=this.options,s=t.getApp().toFixedSize(i.endPointSize),n=t.getApp().toFixedSize(i.endPointStrokeWidth);this.clear(),this.circle(0,0,s/2),this.fill({color:i.endPointColor}),this.stroke({color:i.endPointStrokeColor,width:n}),this.setupHitArea()}setupHitArea(){const t=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),n=t.getApp().toFixedSize(s);this.hitArea=new Rs(0,0,n)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}handlePointerDown(t){t.stopPropagation(),this.startDragging(t)}startDragging(t){var s,n;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(t.global),this.initialPosition={x:this.x,y:this.y},(n=(s=this.options).onDragStart)==null||n.call(s),i.getApp().requestRender("endpoint-drag",!0),this.appService.emitter.emit("gestureHijackStart",t)}updatePosition(t){this.position.set(t.x,t.y),this.initialPosition={...t}}getPosition(){return{x:this.x,y:this.y}}redraw(){this.draw()}destroy(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class rS extends L{constructor(t){super();g(this,"endPoints");g(this,"dividerConfig");g(this,"dividerEvents");g(this,"roomId");g(this,"appService");g(this,"roomGeometry",null);g(this,"dashLine");g(this,"solidLine",null);g(this,"startEndPoint");g(this,"endEndPoint");g(this,"solidLinePoints",null);g(this,"initialDividerPoints",[]);g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"throttledHandleScaleChange");g(this,"handleEndPointDragStart",()=>{this.initialDividerPoints=this.endPoints.map(t=>({...t})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});g(this,"handleEndPointDragMove",(t,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[t]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});g(this,"handleEndPointDragEnd",()=>{var t,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints())});g(this,"handleDashLinePointerDown",t=>{t.stopPropagation(),this.startDragging(t)});g(this,"handleDragPointerMove",t=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.endPoints=this.initialDividerPoints.map(o=>({x:o.x+s,y:o.y+n})),this.updateAllComponents()});g(this,"handleDragPointerUp",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints()))});g(this,"handleDragCancel",()=>{var t,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.getDividerEndPoints()))});g(this,"handleScaleChange",()=>{var t,i;(t=this.startEndPoint)==null||t.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:n,events:o={}}=t;this.appService=i,this.dividerEvents=o,this.roomId=n,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=Ct(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener(),this.setupDragEventListeners()}validateDividerPoints(t){if(t.length>=2)return t.slice(0,2);const i=t[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 t=this.appService.getApp().mapState;if(!t)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),n=this.dividerConfig.defaultDirection,o=i.x+i.width/2,a=i.y+i.height/2,h=n==="horizontal"?i.width+2*s:i.height+2*s;return Ay(o,a,h,n).map(c=>({x:c.x-t.origin.x,y:c.y-t.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const t=this.endPoints;if(t.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:n}=this.dividerConfig;this.dashLine=new Ue(this.appService,{start:t[0],end:t[1],style:{color:n.toString(),width:i,dashArray:s}})}createEndPoints(){const t=this.endPoints;this.startEndPoint=new Ka(this.appService,{position:t[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new Ka(this.appService,{position:t[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 t=this.endPoints;if(t.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),n=rc(t[0],t[1],s);if(n.length===0)return;const o=new Te(n);this.dashLine.hitArea=o}startDragging(t){this.isDragging=!0;const i=this.parent.toLocal(t.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.appService.emitter.emit("gestureHijackStart",t)}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.handleDragPointerMove),t.on("gestureHijackPointerUp",this.handleDragPointerUp),t.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.handleDragPointerMove),t.off("gestureHijackPointerUp",this.handleDragPointerUp),t.off("gestureHijackCancel",this.handleDragCancel)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const t=this.endPoints;t.length<2||!this.dashLine||this.dashLine.updatePoints(t[0],t[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:t,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(t);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 t=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(t[0]),this.endEndPoint&&this.endEndPoint.updatePosition(t[1])}registerScaleListener(){const{emitter:t}=this.appService;t.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 t=this.appService.mapManager.roomFill;return!t||typeof this.roomId!="number"?null:t.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const t=this.endPoints;if(t.length<2||typeof this.roomId!="number")return null;const[i,s]=t,n=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(n||o)return null;const a=dy(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 Q(l,c)<3?null:Py(l,c,.5)}isPointInRoomFill(t){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:t.x+i.origin.x,y:t.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(t){t.x-=.5,t.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const n=s.getRasterRoomData(this.roomId);if(!n)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(t.x),h=Math.round(t.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<n.pixelIndices.length;c++)if(n.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(t){const i={x:Math.round(t.x),y:Math.round(t.y)},s=this.appService.getApp().mapState,n=this.appService.mapManager.getRoomById(this.roomId);return!s||!n||!n.outlinePoints?!1:Et(i,n.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:t}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const n={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!Cy(n,o,t.x,t.y,t.width,t.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:t}=this.appService.dividerConfig;t&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var t,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(t=this.dividerEvents).onUpdate)==null||i.call(t,this.endPoints)}updateComponents(){const t=this.endPoints;t.length>=2&&(this.dashLine.updatePoints(t[0],t[1]),this.startEndPoint.position.set(t[0].x,t[0].y),this.endEndPoint.position.set(t[1].x,t[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:t,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(t);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(t){this.endPoints=this.validateDividerPoints(t),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var t,i,s;this.appService.emitter.off("antiScale",this.throttledHandleScaleChange),this.cleanupDragEventListeners(),this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[]),this.dashLine&&this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.clearSolidLine(),(t=this.dashLine)==null||t.destroy(),(i=this.startEndPoint)==null||i.destroy(),(s=this.endEndPoint)==null||s.destroy(),super.destroy()}}const hr=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","wayPoint","divider"];function oS(r){if(!r||r.length===0)return[...hr];const e=new Set,t=[];for(const i of r)e.has(i)||(e.add(i),t.push(i));for(const i of hr)e.has(i)||t.push(i);return t}class aS{constructor(e){g(this,"zoneMaps",new Map);g(this,"virtualWallMap",new Map);g(this,"spotMap",new Map);g(this,"wayPointMap",new Map);g(this,"divider",null);g(this,"controlContainers",new Map);g(this,"unsubscribeFns",[]);g(this,"builtinZoneFactories",{forbiddenSweepZone:e=>Vr.create(this.appService,e),forbiddenMopZone:e=>Nr.create(this.appService,e),cleanZone:e=>jr.create(this.appService,e)});this.appService=e,this.initializeControlContainers();const t=W(e.runtime,"editingForbiddenSweepZoneIds",u=>{w.log(`[runtime] editingForbiddenSweepZoneIds: ${u}`);const p=this.zoneMaps.get("forbiddenSweepZone");p&&this.updateZonesEditState(p)}),i=W(e.runtime,"editingForbiddenMopZoneIds",u=>{w.log(`[runtime] editingForbiddenMopZoneIds: ${u}`);const p=this.zoneMaps.get("forbiddenMopZone");p&&this.updateZonesEditState(p)}),s=W(e.runtime,"editingCleanZoneIds",u=>{w.log(`[runtime] editingCleanZoneIds: ${u}`);const p=this.zoneMaps.get("cleanZone");p&&this.updateZonesEditState(p)}),n=W(e.runtime,"editingCustomZoneIds",u=>{w.log(`[runtime] editingCustomZoneIds: ${JSON.stringify(u??{})}`);for(const[p,f]of this.zoneMaps)Ne(p)||f.size&&this.updateZonesEditState(f)}),o=W(e.runtime,"editingVirtualWallIds",u=>{w.log(`[runtime] editingVirtualWallIds: ${u}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),a=W(e.runtime,"editingSpotIds",u=>{w.log(`[runtime] editingSpotIds: ${u}`),this.updateSpotsEditState(this.spotMap)}),h=W(e.runtime,"editingWayPointIds",u=>{w.log(`[runtime] editingWayPointIds: ${u}`),this.updateWayPointsEditState(this.wayPointMap)}),l=W(e.runtime,"dividingRoomId",u=>{w.log(`[runtime] dividingRoomId: ${u}`),this.handleDividingRoomIdChange(u)}),c=W(e.runtime,"unit",u=>{w.log(`[runtime] unit changed: ${u}`),this.handleUnitChange()}),d=W(e.runtime,"unitLabel",u=>{w.log(`[runtime] unitLabel changed: ${u}`),this.handleUnitChange()});this.unsubscribeFns.push(t,i,s,n,o,a,h,l,c,d)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const e=this.appService.appContainer.getLayer(Ke);if(!e){w.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const t of hr){const i=new L;i.label=`controls:${t}`,this.controlContainers.set(t,i),e.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const e=this.appService.appContainer.getLayer(Ke);if(!e)return;oS(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const n=this.controlContainers.get(i);n&&(n.zIndex=s)}),e.sortableChildren=!0,e.sortChildren()}addToControlLayer(e,t){let i=this.controlContainers.get(e);if(!i){const s=this.appService.appContainer.getLayer(Ke);if(!s){w.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new L,i.label=`controls:${e}`,this.controlContainers.set(e,i),s.addChild(i),this.applyRenderOrder()}i.addChild(t)}drawForbiddenSweepZones(e){this.drawZonesByType("forbiddenSweepZone",e)}getForbiddenSweepZones(){return this.getZonesDataByType("forbiddenSweepZone")}clearAllForbiddenSweepZones(){this.clearAllZonesByType("forbiddenSweepZone")}drawForbiddenMopZones(e){this.drawZonesByType("forbiddenMopZone",e)}getForbiddenMopZones(){return this.getZonesDataByType("forbiddenMopZone")}clearAllForbiddenMopZones(){this.clearAllZonesByType("forbiddenMopZone")}drawCleanZones(e){this.drawZonesByType("cleanZone",e)}getCleanZones(){return this.getZonesDataByType("cleanZone")}clearAllCleanZones(){this.clearAllZonesByType("cleanZone")}drawVirtualWalls(e){var n;const t=this.appService,i=this.virtualWallMap,s=new Set(e.map(o=>o.id));for(const[o,a]of i)s.has(o)||((n=a.parent)==null||n.removeChild(a),a.destroy(),i.delete(o));e.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new ar({appService:t,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=t.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=t.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=t.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(e){const t=this.spotMap;if(!e||e.length===0){this.clearAllSpotsInternal(t);return}const i=new Set(t.keys()),s=new Set(e.map(n=>n.id));for(const n of i)s.has(n)||this.removeSpot(n,t);e.forEach(n=>{const o=t.get(n.id);o?this.isSpotDataEqual(o.getSpotData(),n)||o.updateSpotData(n):this.addNewSpot(n,t)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}getZoneMap(e){let t=this.zoneMaps.get(e);return t||(t=new Map,this.zoneMaps.set(e,t)),t}resolveZoneFactory(e){var s;const t=this.builtinZoneFactories[e];return t||((s=this.appService.getConfig().customZoneTypes)!=null&&s[e]?n=>new oi({appService:this.appService,zoneData:n,zoneType:e,events:{onRemove:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onRemoveCustomZone)==null?void 0:h.call(a,e,o)},onUpdate:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onUpdateCustomZone)==null?void 0:h.call(a,e,o)},onClick:o=>{var a,h;return(h=(a=this.appService.events)==null?void 0:a.onClickCustomZone)==null?void 0:h.call(a,e,o)}}}):null)}drawCustomZones(e,t){this.drawZonesByType(e,t)}getCustomZones(e){return this.getZonesDataByType(e)}clearCustomZones(e){this.clearAllZonesByType(e)}drawZonesByType(e,t){const i=this.resolveZoneFactory(e);if(!i){w.warn(`[ControlsManager] Unknown zone type: ${e}`);return}const s=this.getZoneMap(e);this.drawZonesImpl(t,s,i,e)}getZonesDataByType(e){const t=this.zoneMaps.get(e);return t?this.getZonesData(t):[]}clearAllZonesByType(e){const t=this.zoneMaps.get(e);t&&this.clearAllZones(t)}drawZonesImpl(e,t,i,s){if(!e||e.length===0){this.clearAllZones(t);return}const n=new Set(t.keys()),o=new Set(e.map(a=>a.id));for(const a of n)o.has(a)||this.removeZone(a,t);e.forEach(a=>{const h=t.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,t,i,s)})}addNewZone(e,t,i,s){const n=i(e);t.set(e.id,n),this.addToControlLayer(s,n)}removeZone(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getZonesData(e){const t=[];return e.forEach(i=>{t.push(i.getZoneData())}),t}clearAllZones(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateZonesEditState(e){e.forEach(t=>{t.updateEditState()})}updateVirtualWallsEditState(e){e.forEach(t=>{t.updateEditingState()})}isZoneDataEqual(e,t){if(e.id!==t.id||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++){const s=e.points[i],n=t.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}getWallsData(e){return Array.from(e.values()).map(t=>t.getWallData())}clearAllWalls(e){for(const t of e.values())t.destroy();e.clear()}isWallDataEqual(e,t){if(e.id!==t.id||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++){const s=e.points[i],n=t.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}addNewSpot(e,t){const i=Yr.create(this.appService,e);t.set(e.id,i),this.addToControlLayer("spot",i)}removeSpot(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getSpotsData(e){const t=[];return e.forEach(i=>{t.push(i.getSpotData())}),t}clearAllSpotsInternal(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateSpotsEditState(e){e.forEach(t=>{t.updateEditState()})}isSpotDataEqual(e,t){if(e.id!==t.id)return!1;const i=e.point,s=t.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}drawWayPoints(e){w.log("[ControlsManager] drawWayPoints",e);const t=Array.from(this.wayPointMap.keys()),i=e.map(n=>n.id);t.filter(n=>!i.includes(n)).forEach(n=>{this.removeWayPoint(n,this.wayPointMap)}),e.forEach((n,o)=>{const a=o+1,h=this.wayPointMap.get(n.id);h?(this.isWayPointDataEqual(h.getWayPointData(),n)||h.updateWayPoint(n),h.updateOrder(a)):this.addNewWayPoint(n,a,this.wayPointMap)})}clearAllWayPoints(){w.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(e,t,i){var o,a;const s=this.appService,n=new nS({appService:s,wayPointData:e,order:t,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(e.id,n),this.addToControlLayer("wayPoint",n)}removeWayPoint(e,t){var s;const i=t.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),t.delete(e))}getWayPointsData(e){const t=[];return e.forEach(i=>{t.push(i.getWayPointData())}),t}clearAllWayPointsInternal(e){e.forEach((t,i)=>{var n;const s=e.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),e.clear()}updateWayPointsEditState(e){e.forEach(t=>{t.onEditStateChange()})}isWayPointDataEqual(e,t){if(e.id!==t.id)return!1;const i=e.point,s=t.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(e){if(e==null||e===-1){this.clearDivider();return}if(!this.getRoomGeometry(e)){this.clearDivider();return}this.createDefaultDivider(e)}getRoomGeometry(e){return this.appService.mapManager.getRoomById(e)}createDefaultDivider(e){const t=this.appService;this.clearDivider(),this.divider=new rS({appService:this.appService,roomId:e,events:{onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateDivider)==null||n.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var e;this.divider&&((e=this.divider.parent)==null||e.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 e of this.zoneMaps.values())e.forEach(t=>{t.refreshDisplay()});this.virtualWallMap.forEach(e=>{e.refreshDisplay()}),this.spotMap.forEach(e=>{e.refreshDisplay()})}destroy(){for(const e of this.zoneMaps.keys())this.clearAllZonesByType(e);this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearDivider(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[],this.controlContainers.forEach(e=>{e.removeFromParent(),e.destroy({children:!0})}),this.controlContainers.clear()}}class hS extends Xt{constructor(t,i){super(t);g(this,"objectData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);this.appService=t,this.objectData=i}async initializeSprite(){const t=this.appService.detectedObjectConfig,i=this.objectData.width||t.width,s=this.objectData.height||t.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(t.anchor.x,t.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)}),t.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickDetectedObject)==null||i.call(t,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(t){const i=this.objectData;this.objectData=t;const s=this.appService.detectedObjectConfig;if(i.src!==t.src){const n=t.width||s.width,o=t.height||s.height;await this.loadTextureAndSetSize(t.src,{width:n,height:o})}if(i.width!==t.width||i.height!==t.height){const n=t.width||s.width,o=t.height||s.height;this.setFixedSize(n,o)}this.position.set(t.x,t.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(t){return this.objectData.id===t.id&&this.objectData.src===t.src&&this.objectData.x===t.x&&this.objectData.y===t.y&&this.objectData.width===t.width&&this.objectData.height===t.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class lS{constructor(e){g(this,"detectedObjectMap",new Map);g(this,"unsubscribeShowDetectedObjects",null);this.appService=e,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=W(this.appService.runtime,"showDetectedObjects",t=>{this.applyLayerVisibility(t)})}async drawDetectedObjects(e){if(!e||e.length===0){this.clearAllDetectedObjects();return}const t=new Set(e.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)t.has(s)||this.removeDetectedObject(s);for(const s of e){const n=this.detectedObjectMap.get(s.id);n?n.isSameData(s)||await n.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer(Ye);t&&(t.visible=e)}clearAllDetectedObjects(){const e=this.appService;this.detectedObjectMap.forEach(t=>{e.appContainer.removeFromLayer(Ye,t),t.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(e){const t=this.appService,i=new hS(this.appService,e);await i.initializeSprite(),this.detectedObjectMap.set(e.id,i),t.appContainer.addToLayer(Ye,i)}removeDetectedObject(e){const t=this.appService,i=this.detectedObjectMap.get(e);i&&(t.appContainer.removeFromLayer(Ye,i),i.destroy(),this.detectedObjectMap.delete(e))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var Re={},vc={},te={};Object.defineProperty(te,"__esModule",{value:!0});te.loop=te.conditional=te.parse=void 0;var cS=function r(e,t){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(t))t.forEach(function(o){return r(e,o,i,s)});else if(typeof t=="function")t(e,i,s,r);else{var n=Object.keys(t)[0];Array.isArray(t[n])?(s[n]={},r(e,t[n],i,s[n])):s[n]=t[n](e,i,s,r)}return i};te.parse=cS;var dS=function(e,t){return function(i,s,n,o){t(i,s,n)&&o(i,e,s,n)}};te.conditional=dS;var uS=function(e,t){return function(i,s,n,o){for(var a=[],h=i.pos;t(i,s,n);){var l={};if(o(i,e,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};te.loop=uS;var ut={};Object.defineProperty(ut,"__esModule",{value:!0});ut.readBits=ut.readArray=ut.readUnsigned=ut.readString=ut.peekBytes=ut.readBytes=ut.peekByte=ut.readByte=ut.buildStream=void 0;var pS=function(e){return{data:e,pos:0}};ut.buildStream=pS;var bc=function(){return function(e){return e.data[e.pos++]}};ut.readByte=bc;var fS=function(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(t){return t.data[t.pos+e]}};ut.peekByte=fS;var Os=function(e){return function(t){return t.data.subarray(t.pos,t.pos+=e)}};ut.readBytes=Os;var gS=function(e){return function(t){return t.data.subarray(t.pos,t.pos+e)}};ut.peekBytes=gS;var mS=function(e){return function(t){return Array.from(Os(e)(t)).map(function(i){return String.fromCharCode(i)}).join("")}};ut.readString=mS;var yS=function(e){return function(t){var i=Os(2)(t);return e?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};ut.readUnsigned=yS;var xS=function(e,t){return function(i,s,n){for(var o=typeof t=="function"?t(i,s,n):t,a=Os(e),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};ut.readArray=xS;var SS=function(e,t,i){for(var s=0,n=0;n<i;n++)s+=e[t+n]&&Math.pow(2,i-n-1);return s},vS=function(e){return function(t){for(var i=bc()(t),s=new Array(8),n=0;n<8;n++)s[7-n]=!!(i&1<<n);return Object.keys(e).reduce(function(o,a){var h=e[a];return h.length?o[a]=SS(s,h.index,h.length):o[a]=s[h.index],o},{})}};ut.readBits=vS;(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var e=te,t=ut,i={blocks:function(u){for(var p=0,f=[],y=u.data.length,m=0,x=(0,t.readByte)()(u);x!==p&&x;x=(0,t.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;f.push((0,t.readBytes)(S)(u)),m+=S;break}f.push((0,t.readBytes)(x)(u)),m+=x}for(var v=new Uint8Array(m),b=0,P=0;P<f.length;P++)v.set(f[P],b),b+=f[P].length;return v}},s=(0,e.conditional)({gce:[{codes:(0,t.readBytes)(2)},{byteSize:(0,t.readByte)()},{extras:(0,t.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,t.readUnsigned)(!0)},{transparentColorIndex:(0,t.readByte)()},{terminator:(0,t.readByte)()}]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),n=(0,e.conditional)({image:[{code:(0,t.readByte)()},{descriptor:[{left:(0,t.readUnsigned)(!0)},{top:(0,t.readUnsigned)(!0)},{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{lct:(0,t.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,e.conditional)({lct:(0,t.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,t.readByte)()},i]}]},function(d){return(0,t.peekByte)()(d)===44}),o=(0,e.conditional)({text:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{preData:function(u,p,f){return(0,t.readBytes)(f.text.blockSize)(u)}},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,e.conditional)({application:[{codes:(0,t.readBytes)(2)},{blockSize:(0,t.readByte)()},{id:function(u,p,f){return(0,t.readString)(f.blockSize)(u)}},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,e.conditional)({comment:[{codes:(0,t.readBytes)(2)},i]},function(d){var u=(0,t.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,t.readString)(3)},{version:(0,t.readString)(3)}]},{lsd:[{width:(0,t.readUnsigned)(!0)},{height:(0,t.readUnsigned)(!0)},{gct:(0,t.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,t.readByte)()},{pixelAspectRatio:(0,t.readByte)()}]},(0,e.conditional)({gct:(0,t.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,e.loop)([s,a,h,n,o],function(d){var u=(0,t.peekByte)()(d);return u===33||u===44})}],c=l;r.default=c})(vc);var Gs={};Object.defineProperty(Gs,"__esModule",{value:!0});Gs.deinterlace=void 0;var bS=function(e,t){for(var i=new Array(e.length),s=e.length/t,n=function(u,p){var f=e.slice(p*t,(p+1)*t);i.splice.apply(i,[u*t,t].concat(f))},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])n(c,h),h++;return i};Gs.deinterlace=bS;var Ws={};Object.defineProperty(Ws,"__esModule",{value:!0});Ws.lzw=void 0;var wS=function(e,t,i){var s=4096,n=-1,o=i,a,h,l,c,d,u,p,C,f,y,P,m,A,k,T,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=e,h=1<<m,d=h+1,a=h+2,p=n,c=m+1,l=(1<<c)-1,f=0;f<h;f++)S[f]=0,v[f]=f;var P,C,A,k,M,T;for(P=C=A=k=M=T=0,y=0;y<o;){if(k===0){if(C<c){P+=t[T]<<C,C+=8,T++;continue}if(f=P&l,P>>=c,C-=c,f>a||f==d)break;if(f==h){c=m+1,l=(1<<c)-1,a=h+2,p=n;continue}if(p==n){b[k++]=v[f],p=f,A=f;continue}for(u=f,f==a&&(b[k++]=A,f=p);f>h;)b[k++]=v[f],f=S[f];A=v[f]&255,b[k++]=A,a<s&&(S[a]=p,v[a]=A,a++,!(a&l)&&a<s&&(c++,l+=a)),p=u}k--,x[M++]=b[k],y++}for(y=M;y<o;y++)x[y]=0;return x};Ws.lzw=wS;Object.defineProperty(Re,"__esModule",{value:!0});var wc=Re.decompressFrames=Re.decompressFrame=Cc=Re.parseGIF=void 0,CS=TS(vc),AS=te,PS=ut,MS=Gs,_S=Ws;function TS(r){return r&&r.__esModule?r:{default:r}}var kS=function(e){var t=new Uint8Array(e);return(0,AS.parse)((0,PS.buildStream)(t),CS.default)},Cc=Re.parseGIF=kS,RS=function(e){for(var t=e.pixels.length,i=new Uint8ClampedArray(t*4),s=0;s<t;s++){var n=s*4,o=e.pixels[s],a=e.colorTable[o]||[0,0,0];i[n]=a[0],i[n+1]=a[1],i[n+2]=a[2],i[n+3]=o!==e.transparentIndex?255:0}return i},Ac=function(e,t,i){if(!e.image){console.warn("gif frame does not have associated image.");return}var s=e.image,n=s.descriptor.width*s.descriptor.height,o=(0,_S.lzw)(s.data.minCodeSize,s.data.blocks,n);s.descriptor.lct.interlaced&&(o=(0,MS.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:e.image.descriptor.top,left:e.image.descriptor.left,width:e.image.descriptor.width,height:e.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=t,e.gce&&(a.delay=(e.gce.delay||10)*10,a.disposalType=e.gce.extras.disposal,e.gce.extras.transparentColorGiven&&(a.transparentIndex=e.gce.transparentColorIndex)),i&&(a.patch=RS(a)),a};Re.decompressFrame=Ac;var ES=function(e,t){return e.frames.filter(function(i){return i.image}).map(function(i){return Ac(i,e.gct,t)})};wc=Re.decompressFrames=ES;class Us{constructor(e){if(!e||!e.length)throw new Error("Invalid frames");const[{texture:{width:t,height:i}}]=e;this.width=t,this.height=i,this.frames=e,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const e of this.textures)e.destroy(!0);for(const e of this.frames)e.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(e,t){if(!e||e.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=Cc(e);i(s);const n=wc(s,!0),o=[],a=s.lsd.width,h=s.lsd.height,l=j.get().createCanvas(a,h),c=l.getContext("2d",{willReadFrequently:!0}),d=j.get().createCanvas(),u=d.getContext("2d");let p=0,f=null;const{fps:y=30,...m}=t??{},x=1e3/y;for(let S=0;S<n.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:C,height:A,left:k,top:M}}=n[S];d.width=C,d.height=A,u.clearRect(0,0,C,A);const T=u.createImageData(C,A);T.data.set(P),u.putImageData(T,0,0),v===3&&(f=c.getImageData(0,0,a,h)),c.drawImage(d,k,M);const _=c.getImageData(0,0,a,h);v===2?c.clearRect(0,0,a,h):v===3&&c.putImageData(f,0,0);const E=j.get().createCanvas(_.width,_.height);E.getContext("2d").putImageData(_,0,0),o.push({start:p,end:p+b,texture:new G({source:new gr({resource:E,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new Us(o)}}const IS={extension:I.Asset,detection:{test:async()=>!0,add:async r=>[...r,"gif"],remove:async r=>r.filter(e=>e!=="gif")},loader:{name:"gifLoader",id:"gif",test:r=>Mt.extname(r)===".gif"||r.startsWith("data:image/gif"),load:async(r,e)=>{const i=await(await j.get().fetch(r)).arrayBuffer();return Us.from(i,e==null?void 0:e.data)},unload:async r=>{r.destroy()}}},Pc=class lr extends jt{constructor(...e){const t=e[0]instanceof Us?{source:e[0]}:e[0],{source:i,fps:s,loop:n,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},lr.defaultOptions,t);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:n,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&&(yt.shared.remove(this.update,this),this._isConnectedToTicker=!1))}play(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(yt.shared.add(this.update,this,Ie.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(e){var o,a;if(!this._playing)return;const t=this.animationSpeed*e.deltaTime/yt.targetFPMS,i=this._currentTime+t,s=i%this.duration,n=this._source.frames.findIndex(h=>h.start<=s&&h.end>s);i>=this.duration?this.loop?(this._currentTime=s,this._updateFrameIndex(n),(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(n))}_updateFrame(){this.dirty&&(this.texture=this._source.frames[this._currentFrame].texture,this.dirty=!1)}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,!this._autoUpdate&&this._isConnectedToTicker?(yt.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(yt.shared.add(this.update,this),this._isConnectedToTicker=!0))}get currentFrame(){return this._currentFrame}set currentFrame(e){this._updateFrameIndex(e),this._currentTime=this._source.frames[e].start}get source(){return this._source}_updateFrameIndex(e){var t;if(e<0||e>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${e}`);this._currentFrame!==e&&(this._currentFrame=e,this.dirty=!0,(t=this.onFrameChange)==null||t.call(this,e))}get totalFrames(){return this._source.totalFrames}destroy(e=!1){this.stop(),super.destroy(),e&&this._source.destroy();const t=null;this._source=t,this.onComplete=t,this.onFrameChange=t,this.onLoop=t}clone(){const e=new lr({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 e.dirty=!0,e}};Pc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let BS=Pc;$.add(IS);class Xr extends BS{constructor(t,i){super(i);g(this,"throttledUpdateScale");g(this,"fixedWidth",0);g(this,"fixedHeight",0);g(this,"isFixedSizeSet",!1);g(this,"sizeFixed",!0);g(this,"baselineScale",1);this.appService=t,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=Ct(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(t,i){this.fixedWidth=t,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(t){this.sizeFixed=t,this.baselineScale=1,t&&this.isFixedSizeSet?this.applySize():!t&&this.isFixedSizeSet&&this.applySize()}set width(t){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(t,this.fixedHeight||t)}set height(t){if(this.isFixedSizeSet){w.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||t,t)}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 t=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const n=t/s,o=i/s;super.scale.set(n,o)}else super.scale.set(t/this.baselineScale,i/this.baselineScale)}updateScale(t){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():t!==0&&super.scale.set(1/t))}static async createFromSrc(t,i,s){try{const n=await N.load(i),o=new Xr(t,{source:n});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(n){throw w.error(`Failed to load GIF "${i}":`,n),n}}draw(t,i){const{x:s,y:n,rotation:o=0}=t;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,n)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class We extends Xr{constructor(t,i,s){super(t,{source:i});g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(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 t=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(t.x,t.y),this.position.set(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=W(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;if(this.elementData=t,i.src!==t.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),(i.width!==t.width||i.height!==t.height)&&this.setFixedSize(t.width,t.height);const s=t.anchor||{x:.5,y:.5},n=i.anchor||{x:.5,y:.5};(s.x!==n.x||s.y!==n.y)&&this.anchor.set(s.x,s.y),this.position.set(t.x,t.y),t.rotation!==void 0&&(this.userRotation=t.rotation,this.applyRotation(this.appService.runtime.mapRotation)),t.opacity!==void 0&&(this.alpha=t.opacity),t.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(t){const i=this.elementData.anchor||{x:.5,y:.5},s=t.anchor||{x:.5,y:.5};return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.src===t.src&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class Tn extends Xt{constructor(t,i){super(t);g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"userRotation",0);this.appService=t,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const t=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(t.x,t.y),this.position.set(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=W(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;this.elementData=t,i.src!==t.src?await this.loadTextureAndSetSize(t.src,{width:t.width,height:t.height,sizeFixed:t.sizeFixed}):(i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),(i.width!==t.width||i.height!==t.height)&&this.setFixedSize(t.width,t.height));const s=t.anchor||{x:.5,y:.5},n=i.anchor||{x:.5,y:.5};(s.x!==n.x||s.y!==n.y)&&this.anchor.set(s.x,s.y),this.position.set(t.x,t.y),t.rotation!==void 0&&(this.userRotation=t.rotation,this.applyRotation(this.appService.runtime.mapRotation)),t.opacity!==void 0&&(this.alpha=t.opacity),t.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(t){const i=this.elementData.anchor||{x:.5,y:.5},s=t.anchor||{x:.5,y:.5};return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.src===t.src&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class DS extends Wg{constructor(t,i){super(i);g(this,"throttledUpdateScale");g(this,"fixedWidth",0);g(this,"fixedHeight",0);g(this,"isFixedSizeSet",!1);g(this,"userCenterX",0);g(this,"userCenterY",0);g(this,"sizeFixed",!0);this.appService=t,this.anchor.set(0,0),this.throttledUpdateScale=Ct(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(t,i){this.fixedWidth=t,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(t,i){this.userCenterX=t,this.userCenterY=i,this.updatePositionFromCenter()}setSizeFixed(t){this.sizeFixed=t,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,n;this.sizeFixed?(s=this.fixedWidth/2/i,n=this.fixedHeight/2/i):(s=this.fixedWidth/2,n=this.fixedHeight/2),this.position.set(this.userCenterX-s,this.userCenterY-n)}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(t){this.isFixedSizeSet&&t!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(t){return super.updateTransform(t)}destroy(t){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(t)}}class Di extends DS{constructor(t,i){const s=document.createElement("div");Di.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(t,{element:s});g(this,"elementData");g(this,"domClickHandler",null);g(this,"resizeObserver",null);g(this,"debugMarker",null);g(this,"unsubscribeMapRotation",null);g(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.elementData.rotation!==void 0&&(this.userRotation=this.elementData.rotation),this.applyRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",t=>{this.applyRotation(t)}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(t){const i=-t*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 t=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(t))};requestAnimationFrame(t)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(t=>{var s;const i=t[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 t=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(t);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(t)};requestAnimationFrame(t)}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=t=>{t.preventDefault(),t.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var t,i;(i=(t=this.appService.events)==null?void 0:t.onClickCustomElement)==null||i.call(t,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(t){const i=this.elementData;this.elementData=t,i.htmlContent!==t.htmlContent&&this.element&&(this.element.innerHTML=t.htmlContent,(!t.width||!t.height)&&this.waitForElementDimensions()),(i.width!==t.width||i.height!==t.height)&&(t.width&&t.height?(this.setFixedSize(t.width,t.height),this.element&&(this.element.style.width=`${t.width}px`,this.element.style.height=`${t.height}px`)):this.setupAutoSize()),t.width&&t.height?this.setCenterPosition(t.x,t.y):this.getIsFixedSizeSet()?this.setCenterPosition(t.x,t.y):this.position.set(t.x,t.y),i.sizeFixed!==t.sizeFixed&&t.sizeFixed!==void 0&&this.setSizeFixed(t.sizeFixed),this.userRotation=t.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=t.opacity??1,t.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(t){return this.elementData.id===t.id&&this.elementData.type===t.type&&this.elementData.htmlContent===t.htmlContent&&this.elementData.x===t.x&&this.elementData.y===t.y&&this.elementData.width===t.width&&this.elementData.height===t.height&&this.elementData.rotation===t.rotation&&this.elementData.opacity===t.opacity&&this.elementData.interactive===t.interactive&&this.elementData.sizeFixed===t.sizeFixed}static setupDefaultStyles(t,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(t.style,s),t.style.setProperty("-webkit-tap-highlight-color","transparent"),t.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 FS{constructor(e){g(this,"customElementsMap",new Map);g(this,"gifTicker",null);g(this,"gifElements",new Set);this.appService=e}async drawCustomElements(e){if(!e||e.length===0){this.clearAllCustomElements();return}const t=new Set(e.map(n=>n.id)),i=Array.from(this.customElementsMap.keys());for(const n of i)t.has(n)||this.removeCustomElement(n);const s=e.map(async n=>{const o=this.customElementsMap.get(n.id);o?this.isSameData(o,n)||(n.type==="gif"&&o.getElementData().src!==n.src?(this.removeCustomElement(n.id),await this.addNewCustomElement(n)):await this.updateElementData(o,n)):await this.addNewCustomElement(n)});await Promise.all(s),this.updateGifTicker()}clearAllCustomElements(){const e=this.appService;this.customElementsMap.forEach(t=>{t instanceof We?e.appContainer.removeFromLayer(Bi,t):e.appContainer.removeFromLayer(Ii,t),t.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(e){const t=this.appService;let i;switch(e.type){case"image":i=new Tn(this.appService,e);break;case"gif":{const s=await N.load(e.src);i=new We(this.appService,s,e);break}case"html":i=new Di(this.appService,e);break;default:throw new Error(`Unsupported custom element type: ${e.type}`)}await i.initialize(),this.customElementsMap.set(e.id,i),i instanceof We?(t.appContainer.addToLayer(Bi,i),this.gifElements.add(i)):t.appContainer.addToLayer(Ii,i)}removeCustomElement(e){const t=this.appService,i=this.customElementsMap.get(e);i&&(i instanceof We?(this.gifElements.delete(i),t.appContainer.removeFromLayer(Bi,i)):t.appContainer.removeFromLayer(Ii,i),i.destroy(),this.customElementsMap.delete(e))}isSameData(e,t){return e.getElementData().type!==t.type?!1:t.type==="image"&&e instanceof Tn||t.type==="gif"&&e instanceof We||t.type==="html"&&e instanceof Di?e.isSameData(t):!1}async updateElementData(e,t){if(t.type==="image"&&e instanceof Tn)await e.updateElementData(t);else if(t.type==="gif"&&e instanceof We)await e.updateElementData(t);else if(t.type==="html"&&e instanceof Di)await e.updateElementData(t);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var e;(e=this.gifTicker)!=null&&e.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new yt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var e;(e=this.gifTicker)!=null&&e.started&&(w.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const e=this.appService;if(this.gifElements.size===0)return;const t=e.getApp();t.renderer.render(t.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class zS extends L{constructor(t,i){super();g(this,"roomId");g(this,"roomIndex");g(this,"appService");g(this,"nameText");g(this,"iconSprite",null);g(this,"iconWrapper",null);g(this,"iconBg",null);this.appService=t,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:n}=t.roomConfig,{showRoomType:o}=t.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new ce({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Bs({text:c,style:l}),this.nameText.anchor.set(.5),o&&i.type!=null&&(n!=null&&n.assets)&&n.assets[i.type]&&this.createIcon(i.type,h),this.addChild(this.nameText),this.layout()}createIcon(t,i){const{type:s}=this.appService.roomConfig,n=s.iconSize||14;this.iconWrapper||(this.iconWrapper=new L,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 Xt(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(n,n),this.iconSprite.loadTextureAndSetSize(s.assets[t],{width:n,height:n,sizeFixed:!1}).then(()=>{this.iconSprite&&(this.iconSprite.visible=this.appService.runtime.showRoomType,this.layout())}),s.container&&this.iconSprite.position.set(0,0)}drawIconBg(t){const{type:i}=this.appService.roomConfig;if(!this.iconBg||!i.container.visible)return;const{size:s,borderRadius:n}=i.container;this.iconBg.clear().roundRect(-s/2,-s/2,s,s,n).fill(t)}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,n=this.nameText.width,o=this.iconWrapper.width,h=-(o+i+n)/2;s==="left"?(this.iconWrapper.x=h+o/2,this.nameText.x=h+o+i+n/2):(this.nameText.x=h+n/2,this.iconWrapper.x=h+n+i+o/2),this.iconWrapper.y=0,this.nameText.y=0}updateName(t){this.nameText.text=t,this.layout()}refreshColor(t){const{type:i}=this.appService.roomConfig,s=this.appService.getRoomData(this.roomId),n=(s==null?void 0:s.colorIndex)??this.roomIndex,o=this.getRoomNameColor(n,t);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(t,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:n,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(n)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[t%s.nameInactive.length]:s.name[t%s.name.length];const a=s.nameNormal||s.name;return a[t%a.length]}async updateRoomType(t){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||t==null||!(i!=null&&i.assets)||!i.assets[t])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const n=this.appService.getRoomData(this.roomId),o=(n==null?void 0:n.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(t,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(t){if(this.iconWrapper)this.iconWrapper.visible=t,this.layout();else if(t){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(t){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),super.destroy(t)}}class LS extends L{constructor(t,i){super();g(this,"background");g(this,"foldedIndicator");g(this,"propertyIcons",new Map);g(this,"orderContainer");g(this,"orderBackground");g(this,"orderText");g(this,"isFolded",!1);g(this,"roomId");g(this,"roomIndex");g(this,"isDestroyed",!1);this.appService=t;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:n}=s,o=i.colorIndex??i.index,a=this.getIconColor(o);this.initializePropertyIcons(n.displayOrders,a);const h=n.cleanOrder.color==="auto"?s.colors.active[o%s.colors.active.length]:n.cleanOrder.color;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Bs({text:"",style:new ce({fontSize:n.cleanOrder.fontSize,fontFamily:n.cleanOrder.fontFamily,fontWeight:n.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(t,i){const s=["cleanMode","suction","cistern","cleanTimes"];t.forEach(n=>{const o=s.includes(n),a=new Xt(this.appService);a.tint=i,a.anchor.set(0,0),this.propertyIcons.set(n,{fieldName:n,sprite:a,isBuiltin:o})})}async updateProperty(t){this.isDestroyed||this.destroyed||(await this.updateIcons(t),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(t,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return t[i]??null;if(t.customData&&i in t.customData){const n=t.customData[i];return typeof n=="number"?n:null}return null}getAssetAlias(t,i){const s={cleanMode:n=>`cleanMode_${n}`,suction:n=>`fan_${n}`,cistern:n=>`water_${n}`,cleanTimes:n=>`cleanTimes${n}`};return t in s?s[t](i):`custom_${t}_${i}`}shouldShowField(t,i,s){const{showRoomProperty:n}=this.appService.runtimeSnapshot;return!(s===null||!n||i==="cleanTimes"&&s<=0)}getDisplayElements(t){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,n=t.order||0,o=s&&n>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(t,h);this.shouldShowField(t,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:n}}async updateIcons(t){if(this.isDestroyed||this.destroyed||this.isFolded)return;const{iconWidth:i,iconHeight:s,container:n,cleanOrder:o,iconGap:a}=this.appService.roomConfig.property,{paddingHorizontal:h,paddingVertical:l}=n,{elementsToShow:c,orderValue:d}=this.getDisplayElements(t);this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:f})=>{f.visible=!1});const u=[];if(c.forEach(f=>{if(f.isOrder){this.orderContainer.visible=!0,this.orderText.text=d.toString();const y=t.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(f.fieldName);if(y&&y.sprite){y.sprite.visible=!0;const m=this.getAssetAlias(f.fieldName,f.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((f,y)=>{const{element:m,isOrder:x}=f;!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 t=this.appService.roomConfig,{container:i,foldable:s}=t.property,{borderRadius:n,tailHeight:o,tailWidth:a,backgroundColor:h}=i,l=this.calculateContentWidth(),c=this.calculateContentHeight(),d=Math.min(n,l/2,c/2),u=d*.8,p=Math.max(l-u*2,a*.5),f=Math.min(a,l/2,p);if(this.background.clear(),this.background.setFillStyle({color:h}),s){const y=(l-f)/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+f,c),this.background.lineTo(y+f/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:t,container:i,cleanOrder:s,iconGap:n}=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+=t,d<h.length-1&&(u?l+=s.gapRight:l+=n)}),l+=o,l}calculateContentHeight(){const t=this.appService.roomConfig,{iconHeight:i,container:s}=t.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:t,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(t?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(t){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=t,t)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:t}=this.appService.roomConfig.property;return t?this.isFolded:!1}updateFoldedIndicator(){const t=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:n}=t.property.container,o=this.calculateContentWidth(),a=Math.min(s,o/2);this.foldedIndicator.clear(),this.foldedIndicator.setFillStyle({color:n}),this.foldedIndicator.poly([0,i,a,i,a/2,0]).fill(),this.foldedIndicator.position.set(0,0)}resolveOrderTextColor(t){const{property:i,colors:s}=this.appService.roomConfig,{enableRoomSelection:n}=this.appService.runtime;if(i.cleanOrder.color==="auto"){const o=n?s.active:s.normal||s.active;return o[t%o.length]}return i.cleanOrder.color}getIconColor(t){const{colors:i}=this.appService.roomConfig,{propertyTheme:s,propertyThemeInactive:n,propertyThemeNormal:o}=i,{enableRoomSelection:a,selectRoomIds:h}=this.appService.runtime;if(a)return!h.includes(this.roomId)&&n?n[t%n.length]:s[t%s.length];const l=o||s;return l[t%l.length]}refreshColor(){const t=this.appService.getRoomData(this.roomId),i=(t==null?void 0:t.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite:n})=>{n.tint=s}),this.orderBackground&&this.orderBackground.visible){const{property:n}=this.appService.roomConfig,o=n.iconWidth,a=n.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:t})=>{t.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0}))}}class OS extends L{constructor(t,i){super();g(this,"background");g(this,"checkmarkIcon");g(this,"bubble");g(this,"roomIndex");g(this,"roomId");this.appService=t;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon:n}}=s;this.checkmarkIcon=new Xt(this.appService);const o=i.colorIndex??i.index;this.checkmarkIcon.tint=n[o%n.length],this.checkmarkIcon.anchor.set(0,0),this.addChild(this.background),this.addChild(this.bubble),this.addChild(this.checkmarkIcon)}async updateIndicator(t){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:n}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=n.includes(t.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(t){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:n}=i;if(t){this.visible=!0,this.checkmarkIcon.visible=!0,await this.checkmarkIcon.loadTextureAndSetSize("checkmark",{width:s,height:n,sizeFixed:!1});const o=i.containerWidth/2,a=i.containerHeight/2;this.checkmarkIcon.position.set(o-s/2,a-n/2)}else this.visible=!1}updateBackground(){const{selectionIndicator:t,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:n,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=t,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],f=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,n,h).fill().setStrokeStyle({color:f,width:o,alignment:0}).stroke(),l>0&&c>0){const y=(s-c)/2;this.bubble.setFillStyle({color:f});const m=n+o;this.bubble.poly([y,m-1,y+c,m-1,y+c/2,m+l]).fill()}}getTotalHeight(){const{selectionIndicator:t}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:n}=t;return i+n+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:t}=this.appService.roomConfig;return t.containerWidth}async refreshColor(){const t=this.appService.getRoomData(this.roomId);t&&await this.updateIndicator(t)}destroy(){var t;(t=this.checkmarkIcon)==null||t.destroy(),super.destroy({children:!0})}}class GS extends L{constructor(t,i){super();g(this,"roomId");g(this,"roomName");g(this,"roomProperty",null);g(this,"roomSelectionIndicator",null);g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"targetElasticScale",1);g(this,"currentElasticScale",1);g(this,"isAnimatingScale",!1);g(this,"scaleAnimationBound",null);g(this,"updateScaleBound",null);this.appService=t,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(t.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 zS(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=W(this.appService.runtime,"mapRotation",s=>{this.applyAntiRotation(s)}),this.clickHandler=new vt(this,{onClick:()=>{var s,n;(n=(s=this.appService.events)==null?void 0:s.onClickRoomProperties)==null||n.call(s,i)}})}async initialize(t){await this.createRoomProperty(t),await this.createRoomSelectionIndicator(t),this.updateLayout()}applyAntiRotation(t){const i=-t*Math.PI/180;this.rotation=i}initializeElasticScale(t){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;t<=o?h=s:t>=a?h=n:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(t){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i){t!==0&&this.scale.set(1/t);return}if(t===0)return;const o=1,a=5;let h;t<=o?h=s:t>=a?h=n:h=1;const c=1/t*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 n=1/this.appService.currentScale*this.currentElasticScale;this.scale.set(n),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:t,showRoomProperty:i,selectRoomIds:s,enableRoomSelection:n,roomSelectionMode:o}=this.appService.runtimeSnapshot,a=this.appService.getRoomData(this.roomId);if(!a||n&&o==="checkmark"&&s.includes(this.roomId))return!1;const h=t&&(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:t,roomSelectionMode:i}=this.appService.runtimeSnapshot;return t&&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(t){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new LS(this.appService,t),await this.roomProperty.updateProperty(t),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(t){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new OS(this.appService,t),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,f;if(this.destroyed)return;const{property:{offsetY:t,offsetX:i},selectionIndicator:{offsetY:s,offsetX:n}}=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-t;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-t-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-t)}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+n,-s-y),this.roomName.position.set(0,0)):this.roomSelectionIndicator.position.set(-m/2+n,-y/2-s)}a&&!o&&!h&&((f=this.roomName)!=null&&f.position)&&this.roomName.position.set(0,0)}updateName(t){this.roomName.updateName(t)}async updateRoomType(t){await this.roomName.updateRoomType(t),this.updateLayout()}updateRoomNameVisibility(t){this.roomName.visible=t,this.updateLayout()}updateRoomTypeVisibility(t){this.roomName.updateRoomTypeVisibility(t),this.updateLayout()}updatePosition(t){this.position.set(t.x,t.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var t,i,s,n;(t=this.clickHandler)==null||t.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,(n=this.roomName)==null||n.destroy(),super.destroy()}}class WS extends L{constructor(t){super({isRenderGroup:!0});g(this,"floorTypeMap",new Map);g(this,"floorTypeMasks",new Map);g(this,"floorTypeContexts",new Map);g(this,"floorTypeToRooms",new Map);this.appService=t,this.appService.appContainer.addToLayer(Gr,this)}async createFloorTypes(t){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(t),n=[];for(const[o,a]of s)n.push(this.createMergedFloorType(o,a));await Promise.all(n)}groupRoomsByFloorType(t){const i=new Map,s=this.appService;return t.forEach((n,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:n}))}),i}async createMergedFloorType(t,i){const s=this.appService,{assets:n,opacity:o,scale:a}=s.roomConfig.floorType,h=t%n.length,l=`floorType${h}`;if(!n[h]){w.warn(`No texture asset configured for floorType: ${t}`);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=by(d),p=new bs({texture:c,width:u.width,height:u.height});p.autoGarbageCollect=!1,p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:f,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=f,this.addChild(p),this.floorTypeMap.set(t,p),this.floorTypeMasks.set(t,f),this.floorTypeContexts.set(t,y),this.floorTypeToRooms.set(t,new Set(i.map(({roomId:m})=>m)))}createMergedMask(t){const i=new L,s=[];return t.forEach(n=>{const o=new H;o.autoGarbageCollect=!1;const a=n.context.clone();a.autoGarbageCollect=!1,o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(t=>{try{t.destroy({children:!0})}catch(i){w.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(t=>{try{t.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(t=>{try{this.removeChild(t),t.destroy()}catch(i){w.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}class US{constructor(e){g(this,"unsubscribeFns",[]);g(this,"roomInfoContainer",new L);g(this,"roomInfoMap",new Map);g(this,"roomDisplayMap",new Map);g(this,"roomFloorType");this.appService=e,this.roomFloorType=new WS(e),e.appContainer.addToLayer(fc,this.roomInfoContainer);const t=W(e.runtime,"showRoomFloorType",d=>{w.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=W(e.runtime,"showRoomProperty",d=>{w.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=W(e.runtime,"showRoomOrder",d=>{w.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),n=W(e.runtime,"roomPropertyFoldIds",d=>{w.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=W(e.runtime,"showRoomName",d=>{w.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=W(e.runtime,"showRoomType",d=>{w.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=W(e.runtime,"enableRoomSelection",d=>{w.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=W(e.runtime,"selectRoomIds",d=>{w.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=W(e.runtime,"roomSelectionMode",d=>{w.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(t,i,s,n,o,a,h,l,c)}async drawRoomProperty(e){const t=this.appService;return this.roomDisplayMap.clear(),e.forEach((i,s)=>{const n=t.mapManager.getRoomById(i.id),o={...i,centerPoint:(n==null?void 0:n.centerPoint)||null,index:s,colorIndex:n==null?void 0:n.colorIndex};this.roomDisplayMap.set(i.id,o)}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes(),!0}async updateRoomInfoDisplay(){if(this.roomDisplayMap.size===0){this.appService.mapManager.getAllRooms().length===0&&this.clearRoomInfos();return}const e=Array.from(this.roomDisplayMap.values()).filter(t=>t.centerPoint!==null);this.clearRoomInfos(),await Promise.all(e.map(t=>this.createRoomInfo(t)))}async createRoomInfo(e){const t=new GS(this.appService,e);this.roomInfoContainer.addChild(t),this.roomInfoMap.set(e.id,t),await t.initialize(e)}updateRoomName(e,t){const i=this.roomInfoMap.get(e);i&&i.updateName(t)}async updateRoomType(e,t){const i=this.roomDisplayMap.get(e);i&&(i.type=t);const s=this.roomInfoMap.get(e);s&&await s.updateRoomType(t)}updateRoomPosition(e,t){const i=this.roomDisplayMap.get(e);i&&(i.centerPoint=t);const s=this.roomInfoMap.get(e);s&&s.updatePosition(t)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const e=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),e.forEach(t=>{try{t.destroy()}catch(i){w.warn(`[RoomManager] Error destroying RoomInfo for room ${t.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(e){return this.roomDisplayMap.get(e)}async refresh(){const e=this.appService;this.roomFloorType.clearFloorTypes(),this.roomDisplayMap.forEach((t,i)=>{const s=e.mapManager.getRoomById(i),n=(s==null?void 0:s.centerPoint)||null;if(t.centerPoint!==n){t.centerPoint=n;const a=this.roomInfoMap.get(i);a&&n&&a.updatePosition(n)}const o=s==null?void 0:s.colorIndex;if(t.colorIndex!==o&&o!==void 0){t.colorIndex=o;const a=this.roomInfoMap.get(i);a&&a.refreshColor()}}),await this.updateRoomInfoDisplay(),await this.updateFloorTypes()}async updateAllRoomPropertyVisibility(){this.roomInfoMap.size!==0&&await Promise.all(Array.from(this.roomInfoMap.values()).map(async e=>{try{await e.updateRoomPropertyVisibility()}catch(t){console.warn(`[RoomManager] Failed to update room property visibility for room ${e.roomId}`,t)}}))}updateAllRoomNameVisibility(e){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomNameVisibility(e)})}updateAllRoomTypeVisibility(e){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomTypeVisibility(e)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.refreshColor()})}async updateFloorTypes(){const e=this.appService,t=e.mapManager.roomFill.getRoomGraphicsMap();t.size>0?(await this.roomFloorType.createFloorTypes(t),e.getApp().renderOnceNextFrame()):e.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}var Qa,Ja;(Qa=navigator==null?void 0:navigator.userAgent)!=null&&Qa.includes("tuya-ark-ide")||((Ja=navigator==null?void 0:navigator.userAgent)==null||Ja.includes("miniProgram"));const HS=()=>{var i,s;if(!Gn.any)return!0;const r=navigator.userAgent.toLowerCase(),e=()=>{const n=navigator.deviceMemory;return n?n>=4:!0};let t=!1;if(/iphone|ipad|ipod/.test(r)){const n=(i=r.match(/os (\d+)_/))==null?void 0:i[1];t=(n?parseInt(n):0)>=12}else if(/android/.test(r)){const n=(s=r.match(/android (\d+)/))==null?void 0:s[1];t=(n?parseInt(n):0)>=10}return t&&e()};class VS extends L{constructor(t,i,s){super();g(this,"graphics");g(this,"sprite",null);g(this,"viewportBounds");g(this,"lastConfig",null);g(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(t)}async render(t){if(this.lastConfig=t,this.clear(),t.backgroundImage){await this.renderImage(t.backgroundImage,t.backgroundAlpha);return}if(t.backgroundGradient){this.renderGradient(t.backgroundGradient);return}if(t.backgroundColor!==void 0){this.renderSolidColor(t.backgroundColor,t.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(t,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:t,alpha:i}),w.debug("[Background] Rendered solid color background",{color:t,alpha:i})}renderGradient(t){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),t.type==="linear"){const n=t.x0??0,o=t.y0??0,a=t.x1??1,h=t.y1??1,l=new Ot({type:"linear",start:{x:n,y:o},end:{x:a,y:h},colorStops:t.colorStops});this.graphics.rect(0,0,i,s).fill(l),w.debug("[Background] Rendered linear gradient background",{x0:n,y0:o,x1:a,y1:h,colorStops:t.colorStops.length})}else if(t.type==="radial"){const n=t.cx??.5,o=t.cy??.5,a=t.r??.5,h=new Ot({type:"radial",center:{x:n,y:o},innerRadius:0,outerCenter:{x:n,y:o},outerRadius:a,colorStops:t.colorStops});this.graphics.rect(0,0,i,s).fill(h),w.debug("[Background] Rendered radial gradient background",{cx:n,cy:o,r:a,colorStops:t.colorStops.length})}}async renderImage(t,i){var s,n,o,a;try{const h=await N.load(t.src);if(!h){w.error("[Background] Failed to load image:",t.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.autoGarbageCollect=!1,this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=t.fit||"cover",u=((n=t.position)==null?void 0:n.x)??.5,p=((o=t.position)==null?void 0:o.y)??.5,f=h.width,y=h.height,m=f/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=f,this.sprite.height=y,this.sprite.x=(l-f)*u,this.sprite.y=(c-y)*p;break}t.repeat&&w.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),w.debug("[Background] Rendered image background",{src:t.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(t){await this.render(t)}destroy(){this.clear(),super.destroy()}}class NS extends L{constructor(t){super();g(this,"carpetData");g(this,"carpetConfig");g(this,"controlsConfig");g(this,"carpetEvents");g(this,"appService");g(this,"controlFill");g(this,"editControlLayer");g(this,"clickHandler",null);g(this,"maskContainer",null);g(this,"maskGraphics",null);g(this,"texture",null);g(this,"textureMap",new Map);g(this,"tilingSprite",null);g(this,"initialZonePoints",[]);g(this,"unsubscribeFns",[]);g(this,"resolvedMaxSizeCache",null);g(this,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(t=>({...t})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",t=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(t.global),s=this.controlFill.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleDragEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(t=>({...t})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",t=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(t.global),s=(h=(a=this.editControlLayer)==null?void 0:a.getMoveButton())==null?void 0:h.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleMoveEnd",()=>{var t,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleRotationEnd",()=>{var t,i;this.appService.getApp().stopRender("zone-rotate"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleMoveHorizontal",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleMoveVertical",t=>{t&&(this.carpetData.points=t,this.drawCarpet())});g(this,"handleScaleEnd",()=>{var t,i;this.appService.getApp().stopRender("zone-scale"),(i=(t=this.carpetEvents).onUpdate)==null||i.call(t,this.getCarpetData())});g(this,"handleDelete",()=>{var t,i;(i=(t=this.carpetEvents).onRemove)==null||i.call(t,this.carpetData.id)});g(this,"handleClick",()=>{var t,i;this.isEditingEnabled()||(i=(t=this.carpetEvents)==null?void 0:t.onClick)==null||i.call(t,this.getCarpetData())});g(this,"handlePointsUpdate",t=>{this.carpetData.points=t,this.drawCarpet()});const{appService:i,carpetData:s,events:n={},textureMap:o}=t;this.appService=i,this.textureMap=o,this.carpetEvents=n,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 t=this.carpetConfig.maxSize;if(this.resolvedMaxSizeCache&&this.resolvedMaxSizeCache.key===t)return this.resolvedMaxSizeCache.value;const i=Hr(this.carpetConfig.minSize,t,"carpet");return this.resolvedMaxSizeCache={key:t,value:i},i}processCarpetData(t){if(t.points&&t.points.length>=2)if(t.shape==="custom")this.carpetData={...t,points:t.points};else{const s=this.getResolvedMaxSize(),n=nr(t.points,this.appService.metersToPixels(this.carpetConfig.minSize),s!=null?this.appService.metersToPixels(s):void 0),o=Cs(n);this.carpetData={...t,points:o}}else this.carpetData={...t,points:[],shape:t.shape||"rectangle"}}getControlsConfig(){const{controls:t}=this.appService.getConfig();return t}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 t=new L;return this.maskGraphics=new H,this.maskGraphics.autoGarbageCollect=!1,this.updateMaskShape(),t.addChild(this.maskGraphics),t.mask=this.maskGraphics,t}createControlFill(){const t=this.isEditingEnabled();return new Ur(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:t,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const t=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s={...An(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...An(this.carpetConfig,["textColor","textPosition","textOffset"]),...An(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!t&&!i&&this.carpetConfig.showRotateButton,showScaleButton:!!t&&!i,showDeleteButton:!!t,showMoveButton:!!t&&!i,showRadialScaleButton:!!t&&!i,iconWrapperFillColor:this.carpetConfig.iconWrapperFillColor,moveButtonOffset:this.controlsConfig.moveButtonOffset},n=i?this.calculateBoundingRectanglePoints():this.carpetData.points||[];this.editControlLayer=this.appService.editControlManager.registerEditControl(this.carpetData.id,{config:s,zonePoints:n,minSize:this.carpetConfig.minSize,maxSize:this.getResolvedMaxSize(),contentLayer:$e,events:{onRemove:this.handleDelete,onRotateStart:this.handleRotationStart,onRotateMove:this.handleRotationMove,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}})}setupClickHandler(){this.interactiveChildren=!0,this.clickHandler=new vt(this,{onClick:()=>{var t,i;this.isEditingEnabled()||(i=(t=this.carpetEvents)==null?void 0:t.onClick)==null||i.call(t,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const t=W(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(t);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(t){if(t){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:t}=this.carpetData;let i=1/0,s=1/0,n=-1/0,o=-1/0;if(t&&t.length>0)for(const a of t)i=Math.min(i,a.x),s=Math.min(s,a.y),n=Math.max(n,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:n,maxY:o}}calculateBoundingRectanglePoints(){const{points:t}=this.carpetData;if(!t||t.length===0)return[];const{minX:i,minY:s,maxX:n,maxY:o}=ws(t);return[{x:i,y:s},{x:n,y:s},{x:n,y:o},{x:i,y:o}]}updateMaskShape(){if(!this.maskGraphics)return;this.maskGraphics.clear();const{points:t,shape:i}=this.carpetData;if(!(!t||!Array.isArray(t)||t.length<2)){if(i==="round"){if(t.length<4)return;const n=de(t),[o,a,,h]=t,l=Q(o,a),c=Q(o,h),d=Math.atan2(a.y-o.y,a.x-o.x);this.maskGraphics.position.set(n.x,n.y),this.maskGraphics.rotation=d,this.maskGraphics.ellipse(0,0,l/2,c/2)}else{const n=t.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(n),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}loadTexture(){const{opacity:t,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,t),this.appService.getApp().renderOnce())}catch(n){console.warn("Failed to load carpet texture:",n)}}createTilingSprite(t,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new bs({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.autoGarbageCollect=!1,this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(t),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const t=this.calculateBounds();this.tilingSprite.position.set(t.minX-50,t.minY-50),this.tilingSprite.width=t.maxX-t.minX+100,this.tilingSprite.height=t.maxY-t.minY+100}applyTranslation(t,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+t,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:t}=this.carpetData;if(!(!t||t.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(t),this.editControlLayer)){const n=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():t;this.editControlLayer.updatePoints(n)}}updateEditState(){const t=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();if(this.controlFill.setInteractionEnabled(t),this.editControlLayer)if(i&&!t)this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!0,showSizeText:!1,borderStyle:this.carpetConfig.normal});else if(t){const n=this.carpetData.shape==="custom";this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!n&&this.carpetConfig.showRotateButton,showScaleButton:!n,showDeleteButton:!0,showMoveButton:!n,showBorder:!0,showSizeText:!0,borderStyle:this.carpetConfig.editing,showRadialScaleButton:!n})}else this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!1,showScaleButton:!1,showDeleteButton:!1,showMoveButton:!1,showBorder:!1,showSizeText:!1});this.zIndex=s?1e3:0}updateCarpetData(t){const s=this.carpetData.type;if(t.points&&t.points.length>=2)if(t.shape==="custom")this.carpetData={...t,points:t.points};else{const n=this.getResolvedMaxSize(),o=nr(t.points,this.appService.metersToPixels(this.carpetConfig.minSize),n!=null?this.appService.metersToPixels(n):void 0),a=Cs(o);this.carpetData={...t,points:a}}else this.carpetData={...t,points:t.points||[]};s!==this.carpetData.type&&this.loadTexture(),this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var t,i,s,n,o;this.appService.editControlManager.unregisterEditControl(this.carpetData.id),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(t=this.tilingSprite)==null||t.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,(n=this.controlFill)==null||n.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class jS{constructor(e){g(this,"customCarpetMap",new Map);g(this,"unsubscribeFns",[]);g(this,"textureMap",new Map);g(this,"texturesLoaded",!1);g(this,"texturesLoadingPromise",null);this.appService=e,this.applyLayerVisibility(e.runtime.showCustomCarpets);const t=W(e.runtime,"editingCarpetIds",n=>{w.log(`[runtime] editingCarpetIds: ${n}`),this.updateCarpetsEditState()}),i=W(e.runtime,"selectedCarpetIds",n=>{w.log(`[runtime] selectedCarpetIds: ${n}`),this.updateCarpetsEditState()}),s=W(e.runtime,"showCustomCarpets",n=>{w.log(`[runtime] showCustomCarpets: ${n}`),this.applyLayerVisibility(n)});this.unsubscribeFns.push(t,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 e=this.appService,{material:t,src:i}=e.carpetConfig;if(t)for(const s of t){const n=await N.load(s.src);this.textureMap.set(s.type,n)}if(i){const s=await N.load(i);this.textureMap.set(-1,s)}}async drawCustomCarpets(e){if(await this.loadTextures(),!e||e.length===0){this.clearAllCustomCarpets();return}const t=new Set(this.customCarpetMap.keys()),i=new Set(e.map(s=>s.id));for(const s of t)i.has(s)||this.removeCustomCarpet(s);e.forEach(s=>{const n=this.customCarpetMap.get(s.id.toString());n?this.isCarpetDataEqual(n.getCarpetData(),s)||n.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const e=[];return this.customCarpetMap.forEach(t=>{e.push(t.getCarpetData())}),e}getCustomCarpetById(e){return this.customCarpetMap.get(e)}clearAllCustomCarpets(){this.customCarpetMap.forEach((e,t)=>{var s;const i=this.customCarpetMap.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(e){const t=this.appService,i=new NS({appService:t,carpetData:e,textureMap:this.textureMap,events:{onRemove:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onDeleteCustomCarpet)==null||o.call(n,{id:s})},onUpdate:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onUpdateCustomCarpet)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=t.events)==null?void 0:n.onClickCarpet)==null||o.call(n,{id:s.id})}}});this.customCarpetMap.set(e.id.toString(),i),t.appContainer.addToLayer($e,i)}removeCustomCarpet(e){const t=this.appService,i=this.customCarpetMap.get(e);i&&(t.appContainer.removeFromLayer($e,i),i.destroy(),this.customCarpetMap.delete(e))}updateCarpetsEditState(){this.customCarpetMap.forEach(e=>{e.updateEditState()})}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer($e);t&&(t.visible=e)}isCarpetDataEqual(e,t){if(e.id!==t.id||e.type!==t.type||e.shape!==t.shape)return!1;const i=e.points||[],s=t.points||[];if(i.length!==s.length)return!1;for(let n=0;n<i.length;n++){const o=i[n],a=s[n];if(Math.abs(o.x-a.x)>.1||Math.abs(o.y-a.y)>.1)return!1}return!0}refreshDisplay(){this.customCarpetMap.forEach(e=>{e.refreshDisplay()})}destroy(){this.clearAllCustomCarpets(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}class YS extends Ni{constructor(e,t){super(e,t),this.cursor="pointer"}setupEvents(){this.on("pointerdown",e=>{e.stopPropagation()}),this.on("pointertap",()=>{var e,t;(t=(e=this.options).onClick)==null||t.call(e)})}destroy(){this.removeAllListeners(),super.destroy()}}const Rt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0};class XS extends L{constructor(t){super();g(this,"appService");g(this,"data");g(this,"furnitureEvents");g(this,"textureAlias");g(this,"sprite");g(this,"controlButtons");g(this,"outlineBorder");g(this,"moveLine");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"sizeText",null);g(this,"isEditing",!1);g(this,"dragStartPosition",null);g(this,"initialPoints",[]);g(this,"clickHandler",null);g(this,"isDragging",!1);g(this,"initialScalePoints",[]);g(this,"initialButtonPosition",null);g(this,"rotationCount",0);g(this,"originalEdgeLengths",null);g(this,"onDragStart",t=>{if(!this.isEditing||!this.parent||t.target!==this&&t.target!==this.sprite)return;t.stopPropagation();const i=this.parent.toLocal(t.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(s=>({...s})),this.isDragging=!1,this.setupDragEventListeners(),this.appService.emitter.emit("gestureHijackStart",t)});g(this,"onDragMove",t=>{if(!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(t.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(n)<3||(this.isDragging||(this.isDragging=!0,this.appService.getApp().requestRender("furniture-drag",!0)),this.data.points=this.initialPoints.map(o=>({x:o.x+s,y:o.y+n})),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText())});g(this,"onDragEnd",()=>{var t,i;this.dragStartPosition&&(this.cleanupDragEventListeners(),this.isDragging&&((i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData()),this.appService.getApp().stopRender("furniture-drag")),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});g(this,"onDragCancel",()=>{this.dragStartPosition&&(this.cleanupDragEventListeners(),this.isDragging&&this.appService.getApp().stopRender("furniture-drag"),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1)});g(this,"handleScaleStart",()=>{this.initialScalePoints=this.data.points.map(i=>({...i}));const t=this.getVisualIndex(Rt.SCALE);t>=0&&t<this.data.points.length&&(this.initialButtonPosition={...this.data.points[t]}),this.appService.getApp().requestRender("furniture-scale",!0)});g(this,"handleScaleMove",({deltaX:t,deltaY:i})=>{if(this.initialScalePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+t,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var t,i;this.initialScalePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("furniture-scale"),(i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData())});g(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(t=>({...t})),this.appService.getApp().requestRender("furniture-move",!0)});g(this,"handleMoveMove",t=>{var a;if(!this.isEditing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(t.global),s=(a=this.moveButton)==null?void 0:a.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.data.points=this.initialPoints.map(h=>({x:h.x+n,y:h.y+o})),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText()});g(this,"handleMoveEnd",()=>{var t,i;this.initialPoints=[],this.appService.getApp().stopRender("furniture-move"),(i=(t=this.furnitureEvents).onUpdate)==null||i.call(t,this.getData())});const{appService:i,data:s,textureAlias:n,events:o={}}=t;this.appService=i,this.data={...s,points:s.points.map(a=>({...a}))},this.textureAlias=n,this.furnitureEvents=o,this.createSprite(),this.updateSpriteTransform(),this.createEditControls(),this.captureOriginalEdgeLengths(),this.eventMode="static",this.cursor="pointer",this.setupInteraction()}get config(){return this.appService.furnitureConfig}captureOriginalEdgeLengths(){const t=this.data.points;if(t.length<4)return;const i=this.getVisualIndex(Rt.FIXED),s=this.getVisualIndex(1),n=this.getVisualIndex(3);this.originalEdgeLengths={edge1:Q(t[i],t[s]),edge2:Q(t[i],t[n])}}getVisualIndex(t){return(t+4-this.rotationCount)%4}getVisualPoints(){const t=this.data.points;return[t[this.getVisualIndex(0)],t[this.getVisualIndex(1)],t[this.getVisualIndex(2)],t[this.getVisualIndex(3)]]}createSprite(){const t=N.get(this.textureAlias);this.sprite=new jt(t),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="passive",this.addChild(this.sprite)}updateSpriteTransform(){const t=this.data.points;if(t.length<4)return;const i=de(t),s=t[1].x-t[0].x,n=t[1].y-t[0].y,o=Math.atan2(n,s),a=Q(t[0],t[1]),h=Q(t[1],t[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControls(){const t=this.calculateOutlinePoints();this.outlineBorder=new Nt(this.appService,{points:t,closePath:!0,style:{color:this.config.outlineStrokeColor,width:this.config.outlineStrokeWidth,isDashed:this.config.outlineDashed,dashArray:this.config.outlineDashArray,fillColor:this.config.outlineFillColor}}),this.outlineBorder.visible=!1,this.addChild(this.outlineBorder);const i=this.calculateMoveLinePoints(t);this.moveLine=new Nt(this.appService,{points:i,closePath:!1,style:{color:this.config.outlineStrokeColor,width:this.config.outlineStrokeWidth,isDashed:this.config.outlineDashed,dashArray:this.config.outlineDashArray}}),this.moveLine.visible=!1,this.addChild(this.moveLine),this.controlButtons=new L,this.controlButtons.visible=!1,this.addChild(this.controlButtons),this.createControlButtons()}createControlButtons(){const t=this.calculateOutlinePoints();if(t.length<4)return;const{iconWrapperFillColor:i}=this.config,s=this.getVisualIndex(Rt.REMOVE),n=this.getVisualIndex(Rt.ROTATE),o=this.getVisualIndex(Rt.SCALE);this.deleteButton=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:i,onClick:()=>{var h,l;return(l=(h=this.furnitureEvents).onRemove)==null?void 0:l.call(h,this.data.id)}}),this.deleteButton.position.set(t[s].x,t[s].y),this.rotateButton=new YS(this.appService,{iconAlias:"rotateIcon",backgroundColor:i,onClick:()=>this.handleTapRotate()}),this.rotateButton.position.set(t[n].x,t[n].y),this.scaleButton=new Qe(this.appService,{iconAlias:"scaleIcon",backgroundColor:i,getTargetPoints:()=>this.data.points,getButtonIndex:()=>this.getVisualIndex(Rt.SCALE),onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(t[o].x,t[o].y);const a=this.calculateMoveButtonPosition(t);this.moveButton=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:i,onMoveStart:this.handleMoveStart,onMoveMove:this.handleMoveMove,onMoveEnd:this.handleMoveEnd}),this.moveButton.position.set(a.x,a.y),this.controlButtons.addChild(this.deleteButton),this.controlButtons.addChild(this.rotateButton),this.controlButtons.addChild(this.scaleButton),this.controlButtons.addChild(this.moveButton),this.config.showSizeText&&(this.sizeText=this.createSizeText(),this.controlButtons.addChild(this.sizeText))}calculateOutlinePoints(){const{points:t}=this.data;if(t.length<4)return t;const i=this.appService.getApp().toFixedSize(this.config.outlineOffset);return zr(t,i)}calculateMoveButtonPosition(t){const i=t??this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{controls:s}=this.appService.getConfig(),n=this.getVisualIndex(Rt.MOVE),o=this.getVisualIndex(2),a=this.getVisualIndex(0),h=this.appService.getApp().toFixedSize(s.moveButtonOffset);return Ds(i[n],i[o],i[a],h)}calculateMoveLinePoints(t,i){if(t.length<4)return[];const s=this.getVisualIndex(Rt.MOVE),n=i??this.calculateMoveButtonPosition(t);return[t[s],n]}createSizeText(){const t=this.calculateSizeTextContent(),i=this.appService.controlsConfig,s=new ji(this.appService,{text:t,style:{fontSize:i.textFontSize,fontFamily:i.textFontFamily,fontWeight:i.textFontWeight,fill:this.config.textColor,align:"center"}});s.anchor.set(.5);const n=this.calculateSizeTextPosition();s.position.set(n.x,n.y);const o=this.calculateSizeTextRotation();return s.rotation=o,s.eventMode="none",s}calculateSizeTextContent(){const{points:t}=this.data;if(t.length<4)return"0m*0m";const[i,s,,n]=this.getVisualPoints(),o=Q(i,s),a=Q(i,n),h=this.rotationCount%2!==0,l=h?a:o,c=h?o:a,d=this.appService.pixelsToMeters(l),u=this.appService.pixelsToMeters(c),p=this.appService.metersToDisplayUnit(d),f=this.appService.metersToDisplayUnit(u),y=this.appService.runtimeSnapshot.unitLabel;return`${p.toFixed(1)}${y}*${f.toFixed(1)}${y}`}calculateSizeTextPosition(){const{points:t}=this.data;if(t.length<4)return{x:0,y:0};const[i,s,n,o]=this.getVisualPoints(),{textPosition:a,textOffset:h}=this.config,l=this.appService.getApp().toFixedSize(h);let c,d;switch(a){case"top":{c={x:(i.x+s.x)/2,y:(i.y+s.y)/2};const u=gt(K(s,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"right":{c={x:(s.x+n.x)/2,y:(s.y+n.y)/2};const u=gt(K(s,n)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}case"bottom":{c={x:(o.x+n.x)/2,y:(o.y+n.y)/2};const u=gt(K(o,n)),p={x:-u.y,y:u.x};d={x:p.x*l,y:p.y*l};break}case"left":{c={x:(i.x+o.x)/2,y:(i.y+o.y)/2};const u=gt(K(o,i)),p={x:u.y,y:-u.x};d={x:p.x*l,y:p.y*l};break}default:c={x:(i.x+s.x)/2,y:(i.y+s.y)/2},d={x:0,y:l};break}return{x:c.x+d.x,y:c.y+d.y}}calculateSizeTextRotation(){const{points:t}=this.data;if(t.length<4)return 0;const[i,s,n,o]=this.getVisualPoints(),{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}setupInteraction(){this.clickHandler=new vt(this,{onClick:t=>{var i,s;!this.isDragging&&((t==null?void 0:t.target)===this||(t==null?void 0:t.target)===this.sprite)&&((s=(i=this.furnitureEvents).onClick)==null||s.call(i,this.getData()))}}),this.on("pointerdown",this.onDragStart,this)}setupDragEventListeners(){const{emitter:t}=this.appService;t.on("gestureHijackPointerMove",this.onDragMove),t.on("gestureHijackPointerUp",this.onDragEnd),t.on("gestureHijackCancel",this.onDragCancel)}cleanupDragEventListeners(){const{emitter:t}=this.appService;t.off("gestureHijackPointerMove",this.onDragMove),t.off("gestureHijackPointerUp",this.onDragEnd),t.off("gestureHijackCancel",this.onDragCancel)}handleTapRotate(){var n,o;const t=this.config.rotateDirection!=="ccw",i=t?Math.PI/2:-Math.PI/2,s=de(this.data.points);this.data.points=Fr(this.data.points,s,i),this.rotationCount=(this.rotationCount+(t?1:3))%4,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(),(o=(n=this.furnitureEvents).onUpdate)==null||o.call(n,this.getData())}applyEdgeBasedScale(t){if(this.initialScalePoints.length<4)return;const i=this.getVisualIndex(Rt.FIXED),s=this.getVisualIndex(1),n=this.getVisualIndex(3),{x:o,y:a}=this.initialScalePoints[i],h=this.initialScalePoints[s],l=this.initialScalePoints[n],c={x:o,y:a},d=K(c,h),u=K(c,l),p=K(c,t),f=ee(d),y=ee(u);if(f===0||y===0)return;const{minScaleRatio:m,maxScaleRatio:x}=this.config;let S=ae(p,d,f,0),v=ae(p,u,y,0);if(this.config.lockAspectRatio){const C=Math.min(S,v);S=C,v=C}if(this.originalEdgeLengths){const C=this.rotationCount%2!==0,A=C?this.originalEdgeLengths.edge2:this.originalEdgeLengths.edge1,k=C?this.originalEdgeLengths.edge1:this.originalEdgeLengths.edge2,M=S*f/A,T=v*y/k;let _=Math.max(m,Math.min(x,M)),E=Math.max(m,Math.min(x,T));if(this.config.lockAspectRatio){const B=Math.min(_,E);_=B,E=B}S=_*A/f,v=E*k/y}else if(S=Math.max(m,Math.min(x,S)),v=Math.max(m,Math.min(x,v)),this.config.lockAspectRatio){const C=Math.min(S,v);S=C,v=C}const b=[c,{x:o+d.x*S,y:a+d.y*S},{x:o+d.x*S+u.x*v,y:a+d.y*S+u.y*v},{x:o+u.x*v,y:a+u.y*v}],P=new Array(4);for(let C=0;C<4;C++)P[this.getVisualIndex(C)]=b[C];this.data.points=P,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditControls(){var h;const t=this.calculateOutlinePoints();if(t.length<4)return;this.outlineBorder.updatePoints(t);const i=this.calculateMoveButtonPosition(t),s=this.calculateMoveLinePoints(t,i);if(this.moveLine.updatePoints(s),!this.deleteButton||!this.rotateButton||!this.scaleButton)return;const n=this.getVisualIndex(Rt.REMOVE),o=this.getVisualIndex(Rt.ROTATE),a=this.getVisualIndex(Rt.SCALE);this.deleteButton.position.set(t[n].x,t[n].y),this.rotateButton.position.set(t[o].x,t[o].y),this.scaleButton.position.set(t[a].x,t[a].y),(h=this.moveButton)==null||h.position.set(i.x,i.y)}updateSizeText(t=!1){if(!this.sizeText)return;if(t){const n=this.calculateSizeTextContent();this.sizeText.updateText(n)}const i=this.calculateSizeTextPosition();this.sizeText.position.set(i.x,i.y);const s=this.calculateSizeTextRotation();this.sizeText.rotation=s}getData(){return{id:this.data.id,furnitureType:this.data.furnitureType,points:this.data.points.map(t=>({...t}))}}updateData(t){this.data={...t,points:t.points.map(i=>({...i}))},this.rotationCount=0,this.captureOriginalEdgeLengths(),this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditState(t){this.isEditing!==t&&(this.isEditing=t,this.outlineBorder.visible=t,this.moveLine.visible=t,this.controlButtons.visible=t,t&&(this.updateEditControls(),this.updateSizeText(!0)))}destroy(){var t;this.cleanupDragEventListeners(),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class ZS{constructor(e){g(this,"furnitureMap",new Map);g(this,"unsubscribeFns",[]);this.appService=e,this.applyLayerVisibility(e.runtime.showFurnitures);const t=W(e.runtime,"editingFurnitureIds",s=>{w.log(`[runtime] editingFurnitureIds: ${s}`),this.updateEditState()}),i=W(e.runtime,"showFurnitures",s=>{w.log(`[runtime] showFurnitures: ${s}`),this.applyLayerVisibility(s)});this.unsubscribeFns.push(t,i)}async drawFurnitures(e){if(!e||e.length===0){this.clearAll();return}const t=new Set(this.furnitureMap.keys()),i=new Set(e.map(n=>n.id));for(const n of t)i.has(n)||this.removeFurniture(n);const s=[];for(const n of e){const o=this.furnitureMap.get(n.id);o?this.isDataEqual(o.getData(),n)||o.updateData(n):s.push(this.addFurniture(n))}await Promise.all(s)}async addFurniture(e){const t=this.appService;if(!t.furnitureConfig.assets.find(h=>h.type===e.furnitureType)){w.warn(`[FurnitureManager] No asset found for furnitureType: ${e.furnitureType}`);return}const n=`furniture_${e.furnitureType}`;await N.load(n);const o=new XS({appService:t,data:e,textureAlias:n,events:{onRemove:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onRemoveFurniture)==null||c.call(l,h)},onUpdate:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onUpdateFurniture)==null||c.call(l,h)},onClick:h=>{var l,c;(c=(l=t.events)==null?void 0:l.onClickFurniture)==null||c.call(l,h)}}});this.furnitureMap.set(e.id,o),t.appContainer.addToLayer(je,o),t.runtime.editingFurnitureIds.includes(e.id)&&(o.updateEditState(!0),this.moveToEditLayer(o))}removeFurniture(e){var i;const t=this.furnitureMap.get(e);t&&((i=t.parent)==null||i.removeChild(t),t.destroy(),this.furnitureMap.delete(e))}clearAll(){var e;for(const[,t]of this.furnitureMap)(e=t.parent)==null||e.removeChild(t),t.destroy();this.furnitureMap.clear()}applyLayerVisibility(e){const t=this.appService.appContainer.getLayer(je);t&&(t.visible=e),this.furnitureMap.forEach(i=>{i.visible=e})}updateEditState(){const e=this.appService.runtime.editingFurnitureIds,{appContainer:t}=this.appService,i=t.getLayer(je);this.furnitureMap.forEach((s,n)=>{const o=e.includes(n);s.updateEditState(o),o?this.moveToEditLayer(s):s.parent!==i&&this.moveToFurnitureLayer(s)})}moveToEditLayer(e){var t;(t=e.parent)==null||t.removeChild(e),this.appService.appContainer.addToLayer(ke,e)}moveToFurnitureLayer(e){var t;(t=e.parent)==null||t.removeChild(e),this.appService.appContainer.addToLayer(je,e)}getFurnitures(){const e=[];return this.furnitureMap.forEach(t=>{e.push(t.getData())}),e}isDataEqual(e,t){if(e.id!==t.id||e.furnitureType!==t.furnitureType||e.points.length!==t.points.length)return!1;for(let i=0;i<e.points.length;i++)if(Math.abs(e.points[i].x-t.points[i].x)>.1||Math.abs(e.points[i].y-t.points[i].y)>.1)return!1;return!0}destroy(){this.clearAll(),this.unsubscribeFns.forEach(e=>e()),this.unsubscribeFns=[]}}const pt={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class qS extends L{constructor(t,i){super();g(this,"config");g(this,"events");g(this,"zonePoints",[]);g(this,"outlinePoints");g(this,"minSize",.1);g(this,"maxSize");g(this,"initialZonePoints",[]);g(this,"scaleCache",null);g(this,"rotationCache",null);g(this,"outlineBorder");g(this,"moveLine");g(this,"sizeText");g(this,"controlButtons");g(this,"deleteButton",null);g(this,"rotateButton",null);g(this,"scaleButton",null);g(this,"moveButton",null);g(this,"horizontalScaleButton",null);g(this,"verticalScaleButton",null);g(this,"horizontalScaleInitialPosition",null);g(this,"verticalScaleInitialPosition",null);g(this,"clickHandler",null);g(this,"throttledUpdateOutline");this.appService=t,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},this.events=i.events||{},this.minSize=i.minSize??.1,this.maxSize=i.maxSize,this.throttledUpdateOutline=Ct(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 L,this.addChild(this.controlButtons),this.createControlButtons(),this.setupClickHandler()}createOutlineBorder(){const{outlineStrokeColor:t,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n,outlineFillColor:o}=this.config;return new Nt(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:t,width:i,isDashed:s,dashArray:n,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:t,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n}=this.config,o=this.calculateMoveLinePoints();return new Nt(this.appService,{points:o,closePath:!1,style:{color:t,width:i,isDashed:s,dashArray:n}})}createSizeText(){const t=this.calculateSizeText(),i=new ji(this.appService,{text:t,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 n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}createDeleteButton(){const t=new zs(this.appService,{iconAlias:"deleteIcon",backgroundColor:"red",onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return t.position.set(this.outlinePoints[pt.REMOVE].x,this.outlinePoints[pt.REMOVE].y),t}createRotateButton(){const t=new Sc(this.appService,{iconAlias:"rotateIcon",backgroundColor:this.config.iconWrapperFillColor,getTargetPoints:()=>this.zonePoints,onRotationStart:i=>{var s,n;this.initializeRotationCache(i),(n=(s=this.events).onRotateStart)==null||n.call(s,i)},onClick:()=>{var n,o;const i=Math.PI/2,s=this.onClickRotateButton(i);(o=(n=this.events).onRotateMove)==null||o.call(n,s??void 0)},onRotationEnd:()=>{var i,s;this.resetRotationState(),(s=(i=this.events).onRotateEnd)==null||s.call(i)}});return t.position.set(this.outlinePoints[pt.ROTATE].x,this.outlinePoints[pt.ROTATE].y),t}onClickRotateButton(t){const i=this.handleInternalRotationMove(t)??[];return this.resetRotationState(),i}createScaleButton(){const t=new Qe(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 n=this.handleInternalScaleMove(i,s);(a=(o=this.events).onScaleMove)==null||a.call(o,n??void 0)},onScaleEnd:()=>{var i,s;this.resetScaleState(),this.initialZonePoints=[],(s=(i=this.events).onScaleEnd)==null||s.call(i)}});return t.position.set(this.outlinePoints[pt.SCALE].x,this.outlinePoints[pt.SCALE].y),t}createHorizontalScaleButton(){const[,t,i]=this.outlinePoints,s=this.getEdgeCenter(t,i),n=new Qe(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 n.position.set(s.x,s.y),n}createVerticalScaleButton(){const[,,t,i]=this.outlinePoints,s=this.getEdgeCenter(t,i),n=new Qe(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 n.position.set(s.x,s.y),n}createMoveButton(){const t=this.calculateMoveButtonPosition(),i=new Ls(this.appService,{iconAlias:"moveIcon",backgroundColor:this.config.iconWrapperFillColor,onMoveStart:()=>{var s,n;return(n=(s=this.events).onMoveStart)==null?void 0:n.call(s)},onMoveMove:s=>{var n,o;return(o=(n=this.events).onMoveMove)==null?void 0:o.call(n,s)},onMoveEnd:()=>{var s,n;return(n=(s=this.events).onMoveEnd)==null?void 0:n.call(s)}});return i.position.set(t.x,t.y),i}createAndAddButton(t,i){return t.visible=i,this.controlButtons.addChild(t),t}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),console.log("this.config.showRadialScaleButton",this.config.showRadialScaleButton),this.horizontalScaleButton=this.createAndAddButton(this.createHorizontalScaleButton(),this.config.showRadialScaleButton??!1),this.verticalScaleButton=this.createAndAddButton(this.createVerticalScaleButton(),this.config.showRadialScaleButton??!1))}calculateOutlinePoints(){const t=this.zonePoints;if(t.length<4)return t;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return zr(t,s)}calculateMoveButtonPosition(){const t=this.calculateOutlinePoints();if(t.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),n=t[pt.MOVE],o=t[pt.SCALE],a=t[pt.REMOVE];return Ds(n,o,a,s)}calculateMoveLinePoints(){const t=this.calculateOutlinePoints();if(t.length<4)return[];const i=t[pt.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const t=this.zonePoints;if(t.length<4)return"0m*0m";const[i,s,,n]=t,o=Q(i,s),a=Q(i,n),h=this.appService,l=h.pixelsToMeters(o),c=h.pixelsToMeters(a),d=h.metersToDisplayUnit(l),u=h.metersToDisplayUnit(c),p=h.runtimeSnapshot.unitLabel;return`${d.toFixed(1)}${p}*${u.toFixed(1)}${p}`}getEdgeCenter(t,i){return{x:(t.x+i.x)/2,y:(t.y+i.y)/2}}calculatePerpendicularOffset(t,i,s,n=!1){const o=gt(K(i,t)),a=n?{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,n,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,n),p=this.calculatePerpendicularOffset(n,s,d);break;case"right":u=this.getEdgeCenter(n,o),p=this.calculatePerpendicularOffset(n,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,n),p={x:0,y:d};break}return{x:u.x+p.x,y:u.y+p.y}}calculateSizeTextRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[i,s,n,o]=t,{textPosition:a}=this.config;let h,l;switch(a){case"top":h=i,l=s;break;case"right":h=s,l=n;break;case"bottom":h=n,l=o;break;case"left":h=o,l=i;break;default:h=i,l=s;break}const c=this.appService.appContainer.getMapRotationRadians();return qe(h,l,c)}calculateHorizontalScaleButtonRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[,i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(i,s,n)+Math.PI/2}calculateVerticalScaleButtonRotation(){const t=this.zonePoints;if(t.length<4)return 0;const[,,i,s]=t,n=this.appService.appContainer.getMapRotationRadians();return qe(s,i,n)}updatePoints(t,i=!0){this.zonePoints=t,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const t=this.calculateOutlinePoints();this.outlinePoints=t,this.outlineBorder.updatePoints(t)}updateMoveLine(){if(!this.moveLine)return;const t=this.calculateMoveLinePoints();this.moveLine.updatePoints(t)}updateSizeText(t=!0){if(this.sizeText){if(t){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const t=this.calculateSizeTextPosition();this.sizeText.position.set(t.x,t.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const t=this.calculateOutlinePoints();if(t.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:t[pt.REMOVE]},{button:this.scaleButton,point:t[pt.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:t[pt.ROTATE]}),this.horizontalScaleButton){const n=t[pt.ROTATE],o=t[pt.SCALE],a=nc(n,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const n=t[pt.SCALE],o=t[pt.MOVE],a=this.getEdgeCenter(n,o);s.push({button:this.verticalScaleButton,point:a})}s.forEach(({button:n,point:o})=>n.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 vt(this,{onClick:()=>{var t,i;(i=(t=this.events).onClick)==null||i.call(t)},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 t={...this.initialZonePoints[pt.SCALE]};if(!t)return;const i=pt.REMOVE,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=K(h,o),c=K(h,a),d=ee(l),u=ee(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:t})}handleInternalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const s=this.appService.metersToPixels(this.minSize),n=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,{fixedPoint:o,edge1:a,edge2:h,edge1Len:l,edge2Len:c,initialButtonPosition:d}=this.scaleCache,u={x:d.x+t,y:d.y+i},p=K(o,u),f=ae(p,a,l,s,n),y=ae(p,h,c,s,n);return this.calculatePointsFromScale(o,a,h,f,y)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.horizontalScaleInitialPosition)return null;const{fixedPoint:s,edge1:n,edge2:o,edge1Len:a}=this.scaleCache,h=this.appService.metersToPixels(this.minSize),l=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,c={x:this.horizontalScaleInitialPosition.x+t,y:this.horizontalScaleInitialPosition.y+i},d=K(s,c),u=ae(d,n,a,h,l);return this.calculatePointsFromScale(s,n,o,u,1)}handleInternalVerticalScaleMove(t,i){if(this.initialZonePoints.length!==4||!this.scaleCache||!this.verticalScaleInitialPosition)return null;const{fixedPoint:s,edge1:n,edge2:o,edge2Len:a}=this.scaleCache,h=this.appService.metersToPixels(this.minSize),l=this.maxSize!=null?this.appService.metersToPixels(this.maxSize):void 0,c={x:this.verticalScaleInitialPosition.x+t,y:this.verticalScaleInitialPosition.y+i},d=K(s,c),u=1,p=ae(d,o,a,h,l);return this.calculatePointsFromScale(s,n,o,u,p)}calculatePointsFromScale(t,i,s,n,o){const{x:a,y:h}=t;return[t,{x:a+i.x*n,y:h+i.y*n},{x:a+i.x*n+s.x*o,y:h+i.y*n+s.y*o},{x:a+s.x*o,y:h+s.y*o}]}initializeRotationCache(t){this.zonePoints.length<3||(this.rotationCache={rotationCenter:t,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(t){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=t,Fr(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:de(this.zonePoints)}updateEditState({showRotateButton:t=!1,showScaleButton:i=!1,showRadialScaleButton:s=!1,showDeleteButton:n=!1,showMoveButton:o=!1,showBorder:a=!1,showSizeText:h=!1,borderStyle:l}){this.rotateButton&&(this.rotateButton.visible=t),this.scaleButton&&(this.scaleButton.visible=i),this.horizontalScaleButton&&(this.horizontalScaleButton.visible=s),this.verticalScaleButton&&(this.verticalScaleButton.visible=s),this.deleteButton&&(this.deleteButton.visible=n),this.moveButton&&(this.moveButton.visible=o);const c=t||i||s||n||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 n,o,a;const t=((n=this.scaleButton)==null?void 0:n.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:t,isRotating:i,isMoving:s,hasAnyOperation:t||i||s}}stopAllOperations(){var t,i,s;(t=this.scaleButton)==null||t.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(t,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const n=s[t],o=s[i];return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}}destroy(){var t,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(t=this.clickHandler)==null||t.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(n=this.scaleButton)==null||n.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()}}class KS{constructor(e){g(this,"editControlLayers",new Map);this.appService=e}registerEditControl(e,t){const i=this.appService;this.editControlLayers.has(e)&&this.unregisterEditControl(e);const s=new qS(i,t);if(!i.appContainer.addToLayer(ke,s))throw w.warn(`[EditControlManager] Failed to add edit control layer for id: ${e}`),s.destroy(),new Error(`Failed to register edit control for id: ${e}`);if(this.editControlLayers.set(e,s),t.contentLayer){const o=i.appContainer.getLayer(ke),a=i.appContainer.getLayer(t.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 "${t.contentLayer}" position — edit controls will appear misaligned. Ensure "${t.contentLayer}" is in ORIGIN_TRACKED_LAYERS.`,{edit:o.position,content:a.position})}return s}unregisterEditControl(e){const t=this.editControlLayers.get(e);if(!t)return;this.appService.appContainer.removeFromLayer(ke,t),t.destroy(),this.editControlLayers.delete(e)}getEditControl(e){return this.editControlLayers.get(e)}updateEditState(e,t){const i=this.editControlLayers.get(e);i&&i.updateEditState(t)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(t=>this.unregisterEditControl(t))}getAllEditControls(){return Array.from(this.editControlLayers.values())}hasEditControl(e){return this.editControlLayers.has(e)}}const $S=60;function $a(r){return Math.round(r*1e3/$S)}function ds(r){return r.charAt(0).toUpperCase()+r.slice(1)}class Zr extends il{constructor(t=Ya){super();g(this,"mapState",null);g(this,"components",{});g(this,"managers",{});g(this,"config",ja);g(this,"runtime");g(this,"appService");g(this,"scaleMin",.5);g(this,"scaleMax",5);g(this,"events",{});g(this,"instanceKey");g(this,"containerElement");g(this,"emitter",Gx());g(this,"tickerState",{renderReasons:new Set,renderTimer:null});g(this,"pendingAsyncRender",!1);g(this,"isFirstMapDraw",!0);g(this,"isMapDrawn",!1);g(this,"onVisibilityChange",()=>{var i;document.visibilityState==="visible"||(i=this.components.interaction)==null||i.clearTouches()});this.instanceKey=t,this.appService=new ac(this),globalThis.__PIXI_APP__=this}async initialize(t){const{resizeTo:i,events:s,config:n,runtime:o={},...a}=t;this.config=or(Ea({},ja,n??{},(f,y)=>{if(Array.isArray(y))return y})),this.validateCustomZoneTypes(this.config),hy(()=>this.config.global.enableLogger),w.log("Applying config",this.config,n),this.runtime=or(Object.assign({},Ox,o));const h=this.instanceKey===Ya;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={gcActive:!0,gcMaxUnusedTime:$a(c?60:Gn.any?180:3600),gcFrequency:$a(c?10:Gn.any?100:50),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:HS(),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(f){w.warn("[Pixi] WebGPU initialization failed, falling back to WebGL:",f),await this.init({...u,preference:"webgl"})}else await this.init({...u,preference:p});w.log(`[Pixi] Renderer initialized: ${this.renderer.type===Fi.WEBGPU?"WebGPU":"WebGL"} ${this.renderer.type}`),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.managers.mapManager=new Kx(this.appService),this.managers.heatmapManager=new sS(this.appService),this.managers.pathManager=new eS(this.appService),this.managers.controlsManager=new aS(this.appService),this.managers.detectedObjectManager=new lS(this.appService),this.managers.customElementsManager=new FS(this.appService),this.managers.roomsManager=new US(this.appService),this.managers.customCarpetManager=new jS(this.appService),this.managers.furnitureManager=new ZS(this.appService),this.managers.editControlManager=new KS(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(t){var a,h,l,c,d,u,p;this.isMapDrawn=!1,w.log("[Map] drawMap",t);const{size:i,resolution:s,origin:n,id:o}=t;((a=this.mapState)==null?void 0:a.id)!==void 0&&this.mapState.id!==o&&this.managers.pathManager.clear(),(n[0]!==((h=this.mapState)==null?void 0:h.origin.x)||n[1]!==((l=this.mapState)==null?void 0:l.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(...n),this.managers.pathManager.updatePositionByOrigin(...n),this.managers.heatmapManager.updatePositionByOrigin(...n)),this.mapState={id:t.id,status:t.status===1,origin:{x:n[0],y:n[1]},charger:{x:t.charger.coordinate[0],y:t.charger.coordinate[1]},chargerDirection:t.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},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),await this.managers.mapManager.drawMap(t),i[0]===0||i[1]===0?(w.log("[Map] Map cleared, clearing path and room data"),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.managers.heatmapManager.onMapLoaded()),this.renderOnce()}async drawRasterMap(t){var a,h,l,c,d,u;this.isMapDrawn=!1,w.log("[Map] drawRasterMap",t);const{mapHeader:i,mapData:s}=t,{originX:n,originY:o}=i;(n!==((a=this.mapState)==null?void 0:a.origin.x)||o!==((h=this.mapState)==null?void 0:h.origin.y))&&(this.appService.appContainer.updateOriginTrackedLayers(n,o),this.managers.pathManager.updatePositionByOrigin(n,o),this.managers.heatmapManager.updatePositionByOrigin(n,o)),this.mapState={id:i.id,status:i.mapStable,origin:{x:n,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.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),await this.managers.mapManager.drawRasterMap(s.parsed,this.mapState),i.mapWidth===0||i.mapHeight===0?(w.log("[Map] Map cleared, clearing path and room data"),this.managers.pathManager.clear(),this.managers.roomsManager.clear(),this.isMapDrawn=!1):(this.isMapDrawn=!0,this.managers.heatmapManager.onMapLoaded()),this.renderOnce()}drawPath(t){var i,s;w.log("[Path] drawPath",t),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:t.pathHeader.pathId,type:t.pathHeader.type,direction:t.pathHeader.direction,count:t.pathHeader.count,initFlag:t.pathHeader.initFlag,robotPosition:t.pathPoints[t.pathPoints.length-1]??null}),this.managers.pathManager.draw(t),this.renderOnce()}async drawRoomProperty(t){var i,s;w.log("[Room] drawRoomProperty",t),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,t),await this.managers.roomsManager.drawRoomProperty(t),this.renderOnceNextFrame()}async drawCustomCarpets(t){w.log("[CustomCarpets] drawCustomCarpets",t),await this.managers.customCarpetManager.drawCustomCarpets(t),this.renderOnceNextFrame()}async drawFurnitures(t){w.log("[Furniture] drawFurnitures",t),await this.managers.furnitureManager.drawFurnitures(t),this.renderOnceNextFrame()}drawHeatmap(t){w.log("[Heatmap] drawHeatmap",t),this.managers.heatmapManager.draw(t),this.renderOnce()}drawForbiddenSweepZones(t){w.log("[Controls] drawForbiddenSweepZones",t),this.managers.controlsManager.drawForbiddenSweepZones(t),this.renderOnceNextFrame()}drawForbiddenMopZones(t){w.log("[Controls] drawForbiddenMopZones",t),this.managers.controlsManager.drawForbiddenMopZones(t),this.renderOnceNextFrame()}drawCleanZones(t){w.log("[Controls] drawCleanZones",t),this.managers.controlsManager.drawCleanZones(t),this.renderOnceNextFrame()}drawCustomZones(t,i){if(Ne(t)){w.warn(`[MapApplication] drawCustomZones: '${t}' is a built-in type; use draw${ds(t)}s() instead`);return}w.log("[Controls] drawCustomZones",t,i),this.managers.controlsManager.drawCustomZones(t,i),this.renderOnceNextFrame()}getCustomZones(t){return Ne(t)?(w.warn(`[MapApplication] getCustomZones: '${t}' is a built-in type; use get${ds(t)}s() instead`),[]):this.managers.controlsManager.getCustomZones(t)}clearCustomZones(t){if(Ne(t)){w.warn(`[MapApplication] clearCustomZones: '${t}' is a built-in type; use clearAll${ds(t)}s() instead`);return}w.log("[Controls] clearCustomZones",t),this.managers.controlsManager.clearCustomZones(t),this.renderOnceNextFrame()}setEditingCustomZones(t,i){if(Ne(t)){w.warn(`[MapApplication] setEditingCustomZones: '${t}' is a built-in type; use runtime.editing${ds(t)}Ids instead`);return}this.runtime.editingCustomZoneIds={...this.runtime.editingCustomZoneIds??{},[t]:[...i]}}drawVirtualWalls(t){w.log("[Controls] drawVirtualWalls",t),this.managers.controlsManager.drawVirtualWalls(t),this.renderOnceNextFrame()}drawSpots(t){w.log("[Controls] drawSpots",t),this.managers.controlsManager.drawSpots(t),this.renderOnceNextFrame()}drawWayPoints(t){w.log("[Controls] drawWayPoints",t),this.managers.controlsManager.drawWayPoints(t),this.renderOnceNextFrame()}async drawDetectedObjects(t){w.log("[DetectedObject] drawDetectedObjects",t),await this.managers.detectedObjectManager.drawDetectedObjects(t),this.renderOnceNextFrame()}drawCustomCarpet(t){w.log("[CustomCarpet] drawCustomCarpet",t),this.managers.customCarpetManager.drawCustomCarpets(t),this.renderOnceNextFrame()}async drawCustomElements(t){w.log("[CustomElements] drawCustomElements",t),await this.managers.customElementsManager.drawCustomElements(t),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()}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(t,i=!1){if(!t||t.minX===t.maxX||t.minY===t.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,n=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(t,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-n*2),f=u*(1-s*2),y=p/l,m=f/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=t.minX+(t.maxX-t.minX)/2,C=t.minY+(t.maxY-t.minY)/2,A=this.config.map.autoFitOffset||{x:0,y:0},k=d/2+(A.x||0),M=u/2+(A.y||0),T=Math.cos(a),_=Math.sin(a),E=P*T-C*_,B=P*_+C*T,F=k-E*b,Z=M-B*b;w.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:t,rotatedBounds:h,finalScale:b,position:{x:F,y:Z}}),this.components.interaction.setPanZoom({targetPosition:{x:F,y:Z},targetScale:{x:b,y:b},setCenter:!0,setScale:!0},i)}setScaleBounds(t,i){this.scaleMin=t,this.scaleMax=i,this.components.interaction.scaleMin=t,this.components.interaction.scaleMax=i}validateCustomZoneTypes(t){const i=["minSize","strokeColor","strokeWidth","fillColor","outlineOffset","outlineStrokeColor","outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","iconWrapperFillColor","textColor","textPosition","textOffset","showRotateButton","editing","normal"],s=t.customZoneTypes??{},n=Ei.cleanZone;for(const[,o]of Object.entries(s))for(const a of i)o[a]===void 0&&(o[a]=n[a])}calculateRotatedBounds(t,i){if(i===0)return t;const s=(t.minX+t.maxX)/2,n=(t.minY+t.maxY)/2,o=[{x:t.minX-s,y:t.minY-n},{x:t.maxX-s,y:t.minY-n},{x:t.maxX-s,y:t.maxY-n},{x:t.minX-s,y:t.maxY-n}],a=Math.cos(i),h=Math.sin(i),l=o.map(f=>({x:f.x*a-f.y*h,y:f.x*h+f.y*a}));let c=1/0,d=1/0,u=-1/0,p=-1/0;return l.forEach(f=>{c=Math.min(c,f.x),d=Math.min(d,f.y),u=Math.max(u,f.x),p=Math.max(p,f.y)}),{minX:c+s,minY:d+n,maxX:u+s,maxY:p+n}}getViewportBounds(){var t;return((t=this.components.viewportContainer)==null?void 0:t.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(t){Object.assign(this.runtime,t),w.log("[runtime] runtime updated",t),this.renderOnceNextFrame()}updateConfig(t){var i;Ea(this.config,t,(s,n)=>{if(Array.isArray(n))return n}),t.customZoneTypes&&this.validateCustomZoneTypes(this.config),(i=this.managers.controlsManager)==null||i.updateRenderOrder(),w.log("[Config] Configuration updated",t),this.renderOnceNextFrame()}metersToPixels(t){var n;if(!((n=this.mapState)!=null&&n.resolution))return w.warn("Map resolution not available, using default resolution (5cm/pixel)"),t*20;const s=1/(this.mapState.resolution/100);return t*s}pixelsToMeters(t){var s;if(!((s=this.mapState)!=null&&s.resolution))return w.warn("Map resolution not available, using default resolution (5cm/pixel)"),t*.05;const i=this.mapState.resolution/100;return t*i}toFixedSize(t,i){const s=i??this.components.appContainer.scale.x;return t/s}fromFixedSize(t,i){const s=i??this.components.appContainer.scale.x;return t*s}getViewportCenterPoint(){if(!this.mapState)return w.warn("Map state not available, cannot calculate center point"),null;const t=this.getViewportBounds(),i=t.x+t.width/2,s=t.y+t.height/2,n=this.components.appContainer,o=n.scale.x,a=n.getMapRotationRadians(),h=i-n.x,l=s-n.y,c=h/o,d=l/o,u=Math.cos(a),p=Math.sin(a),f=c*u+d*p,y=-c*p+d*u,m=f-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 t=this.managers.mapManager.mapBounds;if(t.minX===1/0||t.minY===1/0||t.maxX===-1/0||t.maxY===-1/0)return w.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(t.minX+t.maxX)/2,s=(t.minY+t.maxY)/2,n=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:n,y:o}}getWallPointsByViewportCenter(t){var f;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:n=0,offsetY:o=0}=t||{},a=this.getViewportCenterPoint()||{x:0,y:0},l=this.metersToPixels(i)/2,c=((f=this.components.appContainer)==null?void 0:f.getMapRotationRadians())||0,d=Math.cos(c),u=Math.sin(c);let p;return s==="horizontal"?p=[{vx:-l+n,vy:o},{vx:l+n,vy:o}]:p=[{vx:n,vy:-l+o},{vx:n,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(t){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getForbiddenMopZonePointsByViewportCenter(t){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getCleanZonePointsByViewportCenter(t){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=t||{};return this.generateZonePoints(s,n,o)}getSpotPointByViewportCenter(t){const{offsetX:i=0,offsetY:s=0}=t||{},n=this.getViewportCenterPoint()||{x:0,y:0},o=n.x+i,a=n.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(t){var x;const{furnitureType:i=1,offsetX:s=0,offsetY:n=0}=t||{},a=this.config.furniture.assets.find(S=>S.type===i),h=this.metersToPixels((a==null?void 0:a.width)??1.8),l=this.metersToPixels((a==null?void 0:a.height)??2),c=h/2,d=l/2,u=this.getViewportCenterPoint()||{x:0,y:0},p=((x=this.components.appContainer)==null?void 0:x.getMapRotationRadians())||0,f=Math.cos(p),y=Math.sin(p);return[{vx:-c+s,vy:-d+n},{vx:c+s,vy:-d+n},{vx:c+s,vy:d+n},{vx:-c+s,vy:d+n}].map(S=>({x:u.x+S.vx*f+S.vy*y,y:u.y-S.vx*y+S.vy*f}))}areRoomsAdjacent(t){return!t||t.length===0?(w.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(t)}isPointInAnyRoom(t){return!t||typeof t.x!="number"||typeof t.y!="number"?(w.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(t):(w.warn("[Room] Map state not available"),null)}isWallIntersectsAnyRoom(t){return!t||t.length!==2||!t[0]||!t[1]||typeof t[0].x!="number"||typeof t[0].y!="number"||typeof t[1].x!="number"||typeof t[1].y!="number"?(w.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(t):(w.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(t){return!t||t.length!==4||!t[0]||!t[1]||!t[2]||!t[3]||typeof t[0].x!="number"||typeof t[0].y!="number"||typeof t[1].x!="number"||typeof t[1].y!="number"||typeof t[2].x!="number"||typeof t[2].y!="number"||typeof t[3].x!="number"||typeof t[3].y!="number"?(w.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(t):(w.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(t,i,s){var h,l;if(!t||t.length<1)return w.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(t.length!==1&&t.length!==2&&t.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:n=!0,checkRobot:o=!1}=s||{};if(!n&&!o)return w.warn("[Distance] At least one of checkCharger or checkRobot must be true"),!1;const a=this.metersToPixels(i);if(n){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=za(c,t);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=za(c,t);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(t){this.render();const{snapshot:i,global:s}=this.config,n=(t==null?void 0:t.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=Br.create({width:c,height:d,resolution:u}),f=new H;f.rect(0,0,c,d).fill(n);const y=new U;y.translate(-h,-l);try{return this.renderer.render({container:f,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{f.destroy(),p.destroy(!0)}}async snapshotByData({map:t,path:i,roomProperties:s,customElements:n,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c},d={},u){const p=`SNAPSHOT_${Ux()}`;w.log(`[MapApplication] ${p} snapshot start`);const f=new Zr(p);try{if(await f.initialize({config:this.config,runtime:d}),!t)throw new Error("Map data is required");if(t.startsWith("7b22")){const m=id(t);await f.drawMap(m)}else{const m=sd(t,{pointsStructured:!0});if(m)await f.drawRasterMap(m);else throw new Error("Failed to decode raster map data")}if(i){const{decodePath:m}=await _e(async()=>{const{decodePath:S}=await import("./theme.C_XzLiDc.js").then(v=>v.i);return{decodePath:S}},__vite__mapDeps([4,2])),x=m(i);f.drawPath(x)}s&&s.length>0&&await f.drawRoomProperty(s),o&&o.length>0&&f.drawForbiddenSweepZones(o),a&&a.length>0&&f.drawForbiddenMopZones(a),h&&h.length>0&&f.drawVirtualWalls(h),c&&c.length>0&&await f.drawFurnitures(c),l&&l.length>0&&await f.drawDetectedObjects(l),n&&n.length>0&&await f.drawCustomElements(n);const y=await f.snapshot(u);return w.log(`[MapApplication] ${p} snapshot completed successfully`),y}catch(y){throw w.error(`[MapApplication] ${p} snapshot other map failed:`,y),y}finally{w.log(`[MapApplication] ${p} destroy`),f.destroy()}}renderOnce(){w.log("[Pixi] renderOnce"),this.render()}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{w.log("[Pixi] renderOnceNextFrame"),this.render(),this.pendingAsyncRender=!1}))}requestRender(t,i=!1){if(!i){this.renderOnceNextFrame();return}this.tickerState.renderReasons.add(t),this.ticker.started||(w.debug(`🎬 [Ticker] START: ${t}`),this.ticker.start())}stopRender(t){this.tickerState.renderReasons.delete(t),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100)}destroy(){var t;w.log("[MapApplication] destroy"),this.tickerState.renderTimer&&(clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=null),this.tickerState.renderReasons.clear(),this.emitter.all.clear(),document.removeEventListener("visibilitychange",this.onVisibilityChange),this.managers.pathManager.destroy(),this.managers.mapManager.destroy(),this.managers.controlsManager.destroy(),this.managers.furnitureManager.destroy(),this.managers.detectedObjectManager.destroy(),this.managers.customElementsManager.destroy(),this.managers.roomsManager.destroy(),this.components.interaction.destroy(),(t=this.components.background)==null||t.destroy(),this.components.viewportContainer.destroy(),this.components.appContainer.destroy(),this.managers.heatmapManager.destroy(),super.destroy()}initializeViewportContainer(){this.components.viewportContainer=new Hx(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const t=this.getViewportBounds();this.components.background=new VS(this.config.global,t,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Fs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new Yx(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Ly(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(t,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(t),this.tickerState.renderReasons.size===0&&(w.debug("⏸️ [Ticker] STOP"),this.ticker&&this.ticker.stop())},i)}generateZonePoints(t,i,s){var u;const n=this.getViewportCenterPoint()||{x:0,y:0},a=this.metersToPixels(t)/2,h=((u=this.components.appContainer)==null?void 0:u.getMapRotationRadians())||0,l=Math.cos(h),c=Math.sin(h);return[{vx:-a+i,vy:-a+s},{vx:a+i,vy:-a+s},{vx:a+i,vy:a+s},{vx:-a+i,vy:a+s}].map(p=>({x:n.x+p.vx*l+p.vy*c,y:n.y-p.vx*c+p.vy*l}))}preloadAssets(){const t=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:t}),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:"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((n,o)=>{const a=`cleanMode_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.suction.assets.forEach((n,o)=>{const a=`fan_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.cistern.assets.forEach((n,o)=>{const a=`water_${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.cleanTimes.assets.forEach((n,o)=>{const a=`cleanTimes${o+1}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.floorType.assets.forEach((n,o)=>{if(!n)return;const a=`floorType${o}`;N.add({alias:a,src:n}),s.push(a)}),this.config.room.property.customAssets&&Object.entries(this.config.room.property.customAssets).forEach(([n,o])=>{o.forEach((a,h)=>{const l=`custom_${n}_${h}`;N.add({alias:l,src:a}),s.push(l)})}),this.config.furniture.assets.forEach(n=>{const o=`furniture_${n.type}`;N.add({alias:o,src:n.src}),s.push(o)}),N.backgroundLoad(s)}setupMapRotationListener(){this.applyMapRotation(this.runtime.mapRotation),W(this.runtime,"mapRotation",t=>{this.applyMapRotation(t)})}applyMapRotation(t){const i=(t%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()}}const r0=Object.freeze(Object.defineProperty({__proto__:null,AppService:ac,MapApplication:Zr},Symbol.toStringTag,{value:"Module"}));export{Ho as $,Pi as A,he as B,se as C,pr as D,Yt as E,mr as F,H as G,Kg as H,ii as I,Of as J,Es as K,kf as L,U as M,Ot as N,Is as O,tt as P,gr as Q,et as R,Wp as S,G as T,Ie as U,j as V,Kh as W,Fi as X,Vi as Y,Lp as Z,ci as _,ti as a,_i as a0,yr as a1,Xh as a2,Dt as a3,ni as a4,dl as a5,ff as a6,xf as a7,n0 as a8,pl as a9,Gi as aA,Vp as aB,ul as aC,gf as aD,vf as aE,$g as aF,fl as aG,bf as aH,Hg as aI,r0 as aJ,Be as aa,ps as ab,Tu as ac,gd as ad,le as ae,si as af,wf as ag,_t as ah,xh as ai,Bt as aj,_s as ak,fo as al,jt as am,Em as an,Yd as ao,mo as ap,$s as aq,yo as ar,Zd as as,vh as at,Br as au,kr as av,$h as aw,Hi as ax,Ju as ay,Zu as az,Jn as b,rt as c,V as d,ce as e,tr as f,cs as g,xt as h,X as i,xu as j,ft as k,um as l,dt as m,Gn as n,au as o,I as p,yt as q,kd as r,Ug as s,Sa as t,Ru as u,J as v,nt as w,$ as x,L as y,st as z};