@ray-js/robot-map-sdk 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/docs-server.js +198 -14
- package/dist-docs/404.html +2 -2
- package/dist-docs/assets/{app.3-ianRvb.js → app.Bg6Ypeoa.js} +1 -1
- package/dist-docs/assets/chunks/@localSearchIndexroot.Eymr9Nu7.js +1 -0
- package/dist-docs/assets/chunks/{BitmapFont.C8awBCd1.js → BitmapFont.CXuoJus7.js} +1 -1
- package/dist-docs/assets/chunks/{BufferResource.C5TLxka4.js → BufferResource.BGUfVWrF.js} +1 -1
- package/dist-docs/assets/chunks/{CanvasRenderer.DyglCOE2.js → CanvasRenderer.DT-IZ40Y.js} +1 -1
- package/dist-docs/assets/chunks/{RenderTargetSystem._cMCUdmu.js → RenderTargetSystem.xcN9N8yZ.js} +1 -1
- package/dist-docs/assets/chunks/{VPLocalSearchBox.DYzATQt_.js → VPLocalSearchBox.q-ZF5NyL.js} +1 -1
- package/dist-docs/assets/chunks/{WebGLRenderer.C_pauwH4.js → WebGLRenderer.yqwosgOK.js} +1 -1
- package/dist-docs/assets/chunks/{WebGPURenderer.DuRPdsh5.js → WebGPURenderer.CQtWddUJ.js} +1 -1
- package/dist-docs/assets/chunks/{browserAll.BebatlLr.js → browserAll.De-cmVZB.js} +1 -1
- package/dist-docs/assets/chunks/{index.DR0yN-kU.js → index.BXtdqYEZ.js} +4 -4
- package/dist-docs/assets/chunks/{theme.Dn4kNa0x.js → theme.CKxbjNbw.js} +3 -3
- package/dist-docs/assets/chunks/{webworkerAll.BAL0vGum.js → webworkerAll.CrpT5gSi.js} +1 -1
- package/dist-docs/assets/{guide_getting-started.md.DzTPTYGC.js → guide_getting-started.md.D2j6CRj3.js} +1 -1
- package/dist-docs/assets/records_plans_2026-03-11-docs-cli-ui-polish-plan.md.B8oZt_5R.js +1 -0
- package/dist-docs/assets/records_plans_2026-03-11-docs-cli-ui-polish-plan.md.B8oZt_5R.lean.js +1 -0
- package/dist-docs/guide/advanced-usage.html +3 -3
- package/dist-docs/guide/concepts.html +3 -3
- package/dist-docs/guide/getting-started.html +5 -5
- package/dist-docs/guide/mcp.html +3 -3
- package/dist-docs/hashmap.json +1 -1
- package/dist-docs/index.html +3 -3
- package/dist-docs/plans/2026-03-04-detected-objects-visibility-design.html +3 -3
- package/dist-docs/plans/2026-03-04-show-detected-objects-implementation-plan.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-debug-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-events-console-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-events-console-implementation-plan.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-runtime-controls-design.html +3 -3
- package/dist-docs/plans/2026-03-10-simulator-runtime-controls-implementation-plan.html +3 -3
- package/dist-docs/records/bugs/2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.html +3 -3
- package/dist-docs/records/bugs/2026-03-10-events-drawer-toolbar-scroll-bugfix.html +3 -3
- package/dist-docs/records/bugs/2026-03-10-simulator-initial-render-layout-bugfix.html +3 -3
- package/dist-docs/records/bugs/2026-03-10-simulator-wheel-scroll-leak-bugfix.html +3 -3
- package/dist-docs/records/bugs/2026-03-11-docs-server-bin-clean-bugfix.html +3 -3
- package/dist-docs/records/plans/2026-03-02-furniture-feature-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-events-console-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-last-successful-combo-cache-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-map-parsed-view-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-map-playground-refactor-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-playground-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-10-simulator-runtime-controls-plan.html +3 -3
- package/dist-docs/records/plans/2026-03-11-docs-cli-ui-polish-plan.html +25 -0
- package/dist-docs/records/plans/2026-03-11-simulator-src-migration-implementation.html +3 -3
- package/dist-docs/records/plans/2026-03-11-simulator-src-migration-plan.html +3 -3
- package/dist-docs/reference/callbacks.html +3 -3
- package/dist-docs/reference/config.html +3 -3
- package/dist-docs/reference/data.html +3 -3
- package/dist-docs/reference/methods.html +3 -3
- package/dist-docs/reference/runtime.html +3 -3
- package/dist-docs/reference/types.html +3 -3
- package/dist-docs/reference/utils.html +3 -3
- package/dist-docs/simulator/index.html +3 -3
- package/package.json +1 -1
- package/dist-docs/assets/chunks/@localSearchIndexroot.l5uunL9n.js +0 -1
- /package/dist-docs/assets/{guide_getting-started.md.DzTPTYGC.lean.js → guide_getting-started.md.D2j6CRj3.lean.js} +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.
|
|
2
|
-
var Ac=Object.defineProperty;var Cc=(r,t,e)=>t in r?Ac(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var g=(r,t,e)=>Cc(r,typeof t!="symbol"?t+"":t,e);import{V as _e}from"./framework.CBLqO2Q1.js";import{L as qa,u as Ka,m as $a,G as Pc,E as Mc,d as Re,y as _c,Q as Tc,v as Qa,H as kc,R as Rc,T as Ec,i as or,U as Ja,V as Ic,W as Bc,I as Dc,X as Fc,K as Yr,Y as zc,e as Lc,w as Oc,l as _n,f as Gc,a as Wc,x as Xr,Z as Uc,h as Hc,_ as Vc,j as Nc,$ as th,a0 as jc,a1 as Yc,C as Xc,a2 as Zc,N as Tn,O as qc,P as Kc,M as Zr}from"./mapValues.D2X8cRgC.js";import{N as oe,H as $c,a as Qc}from"./theme.Dn4kNa0x.js";var E=(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))(E||{});const kn=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},ji=(r,t)=>kn(r).priority??t,$={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(kn).forEach(t=>{t.type.forEach(e=>{var i,s;return(s=(i=this._removeHandlers)[e])==null?void 0:s.call(i,t)})}),this},add(...r){return r.map(kn).forEach(t=>{t.type.forEach(e=>{var n,o;const i=this._addHandlers,s=this._queue;i[e]?(o=i[e])==null||o.call(i,t):(s[e]=s[e]||[],(n=s[e])==null||n.push(t))})}),this},handle(r,t,e){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]=t,s[r]=e;const n=this._queue;return n[r]&&((o=n[r])==null||o.forEach(a=>t(a)),delete n[r]),this},handleByMap(r,t){return this.handle(r,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(r,t,e=-1){return this.handle(r,i=>{t.findIndex(n=>n.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((n,o)=>ji(o.value,e)-ji(n.value,e)))},i=>{const s=t.findIndex(n=>n.name===i.name);s!==-1&&t.splice(s,1)})},handleByList(r,t,e=-1){return this.handle(r,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((s,n)=>ji(n,e)-ji(s,e)))},i=>{const s=t.indexOf(i.ref);s!==-1&&t.splice(s,1)})},mixin(r,...t){for(const e of t)Object.defineProperties(r.prototype,Object.getOwnPropertyDescriptors(e))}},Jc={extension:{type:E.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await _e(()=>import("./browserAll.BebatlLr.js"),__vite__mapDeps([0,1,2,3,4]))}},td={extension:{type:E.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await _e(()=>import("./webworkerAll.BAL0vGum.js"),__vite__mapDeps([1,2,3,4]))}};class ct{constructor(t,e,i){this._x=e||0,this._y=i||0,this._observer=t}clone(t){return new ct(t??this._observer,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this._observer._onUpdate(this)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this._observer._onUpdate(this)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._observer._onUpdate(this))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._observer._onUpdate(this))}}var eh={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function 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=e?e+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)t.call(c,d)&&l.push(e?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=e?e+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,f=new Array(p);u<p;u++)f[u]=d[u].fn;return f},a.prototype.listenerCount=function(l){var c=e?e+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,f){var y=e?e+l:l;if(!this._events[y])return!1;var m=this._events[y],x=arguments.length,S,v;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),x){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,c),!0;case 3:return m.fn.call(m.context,c,d),!0;case 4:return m.fn.call(m.context,c,d,u),!0;case 5:return m.fn.call(m.context,c,d,u,p),!0;case 6:return m.fn.call(m.context,c,d,u,p,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=e?e+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=e?e+l:l,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(eh);var ed=eh.exports;const Yt=qa(ed),id=Math.PI*2,sd=180/Math.PI,nd=Math.PI/180;class tt{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new tt(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Us.x=0,Us.y=0,Us}}const Us=new tt;class W{constructor(t=1,e=0,i=0,s=1,n=0,o=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=n,this.ty=o}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,n,o){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=n,this.ty=o,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new tt;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new 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=t.x,d=t.y;return e.x=o*l*c+-n*l*d+(h*n-a*o)*l,e.y=i*l*d+-s*l*c+(-h*i+a*s)*l,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,n=this.c,o=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=n*e-this.d*i,this.d=n*i+this.d*e,this.tx=o*e-this.ty*i,this.ty=o*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,n=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*n,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*n,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*n+this.ty,this}appendFrom(t,e){const i=t.a,s=t.b,n=t.c,o=t.d,a=t.tx,h=t.ty,l=e.a,c=e.b,d=e.c,u=e.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=n*l+o*d,this.d=n*c+o*u,this.tx=a*l+h*d+e.tx,this.ty=a*c+h*u+e.ty,this}setTransform(t,e,i,s,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=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,s=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=s*t.a+this.d*t.c,this.d=s*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,n=this.d,o=t.pivot,a=-Math.atan2(-s,n),h=Math.atan2(i,e),l=Math.abs(a+h);return l<1e-5||Math.abs(id-l)<1e-5?(t.rotation=h,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=h),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+n*n),t.position.x=this.tx+(o.x*e+o.y*s),t.position.y=this.ty+(o.x*i+o.y*n),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,n=this.tx,o=t*s-e*i;return this.a=s/o,this.b=-e/o,this.c=-i/o,this.d=t/o,this.tx=(i*this.ty-s*n)/o,this.ty=-(t*this.ty-e*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 t=new W;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}equals(t){return t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return od.identity()}static get shared(){return rd.identity()}}const rd=new W,od=new W,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],Ae=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Rn=[],ih=[],Yi=Math.sign;function ad(){for(let r=0;r<16;r++){const t=[];Rn.push(t);for(let e=0;e<16;e++){const i=Yi(ve[r]*ve[e]+we[r]*be[e]),s=Yi(be[r]*ve[e]+Ae[r]*be[e]),n=Yi(ve[r]*we[e]+we[r]*Ae[e]),o=Yi(be[r]*we[e]+Ae[r]*Ae[e]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===n&&Ae[a]===o){t.push(a);break}}}for(let r=0;r<16;r++){const t=new W;t.set(ve[r],be[r],we[r],Ae[r],0,0),ih.push(t)}}ad();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=>Ae[r],inv:r=>r&8?r&15:-r&7,add:(r,t)=>Rn[r][t],sub:(r,t)=>Rn[r][X.inv(t)],rotate180:r=>r^4,isVertical:r=>(r&3)===2,byDirection:(r,t)=>Math.abs(r)*2<=Math.abs(t)?t>=0?X.S:X.N:Math.abs(t)*2<=Math.abs(r)?r>0?X.E:X.W:t>0?r>0?X.SE:X.SW:r>0?X.NE:X.NW,matrixAppendRotationInv:(r,t,e=0,i=0,s=0,n=0)=>{const o=ih[X.inv(t)],a=o.a,h=o.b,l=o.c,c=o.d,d=e-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,t,e,i)=>{const{x:s,y:n,width:o,height:a}=r,{x:h,y:l,width:c,height:d}=t;return e===X.E?(i.set(s+h,n+l,o,a),i):e===X.S?i.set(c-n-a+h,s+l,a,o):e===X.W?i.set(c-s-o+h,d-n-a+l,o,a):e===X.N?i.set(n+h,d-s-o+l,a,o):i.set(s+h,n+l,o,a)}},Xi=[new tt,new tt,new tt,new tt];class et{constructor(t=0,e=0,i=0,s=0){this.type="rectangle",this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new et(0,0,0,0)}clone(){return new et(this.x,this.y,this.width,this.height)}copyFromBounds(t){return this.x=t.minX,this.y=t.minY,this.width=t.maxX-t.minX,this.height=t.maxY-t.minY,this}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height}strokeContains(t,e,i,s=.5){const{width: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 t>=d&&t<=u&&e>=p&&e<=f&&!(t>y&&t<m&&e>x&&e<S)}intersects(t,e){if(!e){const k=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=k)return!1;const T=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.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=Xi[0].set(t.left,t.top),h=Xi[1].set(t.left,t.bottom),l=Xi[2].set(t.right,t.top),c=Xi[3].set(t.right,t.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(e.a*e.d-e.b*e.c);if(d===0||(e.apply(a,a),e.apply(h,h),e.apply(l,l),e.apply(c,c),Math.max(a.x,h.x,l.x,c.x)<=i||Math.min(a.x,h.x,l.x,c.x)>=s||Math.max(a.y,h.y,l.y,c.y)<=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,w=S*i+v*o,C=S*s+v*o;return!(Math.max(b,P,w,C)<=S*a.x+v*a.y||Math.min(b,P,w,C)>=S*c.x+v*c.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),n=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(n-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}scale(t,e=t){return this.x*=t,this.y*=e,this.width*=t,this.height*=e,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),n=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=n-s,this}getBounds(t){return t||(t=new et),t.copyFrom(this),t}containsRect(t){if(this.width<=0||this.height<=0)return!1;const e=t.x,i=t.y,s=t.x+t.width,n=t.y+t.height;return e>=this.x&&e<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&n>=this.y&&n<this.y+this.height}set(t,e,i,s){return this.x=t,this.y=e,this.width=i,this.height=s,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Hs={default:-1};function dt(r="default"){return Hs[r]===void 0&&(Hs[r]=-1),++Hs[r]}const qr=new Set,J="8.0.0",hd="8.3.4",He={quiet:!1,noColor:!1},V=(r,t,e=3)=>{if(He.quiet||qr.has(t))return;let i=new Error().stack;const s=`${t}
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/chunks/browserAll.De-cmVZB.js","assets/chunks/webworkerAll.CrpT5gSi.js","assets/chunks/framework.CBLqO2Q1.js","assets/chunks/mapValues.D2X8cRgC.js","assets/chunks/theme.CKxbjNbw.js","assets/chunks/WebGPURenderer.CQtWddUJ.js","assets/chunks/BufferResource.BGUfVWrF.js","assets/chunks/RenderTargetSystem.xcN9N8yZ.js","assets/chunks/WebGLRenderer.yqwosgOK.js","assets/chunks/CanvasRenderer.DT-IZ40Y.js","assets/chunks/BitmapFont.CXuoJus7.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Ac=Object.defineProperty;var Cc=(r,t,e)=>t in r?Ac(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var g=(r,t,e)=>Cc(r,typeof t!="symbol"?t+"":t,e);import{V as _e}from"./framework.CBLqO2Q1.js";import{L as qa,u as Ka,m as $a,G as Pc,E as Mc,d as Re,y as _c,Q as Tc,v as Qa,H as kc,R as Rc,T as Ec,i as or,U as Ja,V as Ic,W as Bc,I as Dc,X as Fc,K as Yr,Y as zc,e as Lc,w as Oc,l as _n,f as Gc,a as Wc,x as Xr,Z as Uc,h as Hc,_ as Vc,j as Nc,$ as th,a0 as jc,a1 as Yc,C as Xc,a2 as Zc,N as Tn,O as qc,P as Kc,M as Zr}from"./mapValues.D2X8cRgC.js";import{N as oe,H as $c,a as Qc}from"./theme.CKxbjNbw.js";var E=(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))(E||{});const kn=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},ji=(r,t)=>kn(r).priority??t,$={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...r){return r.map(kn).forEach(t=>{t.type.forEach(e=>{var i,s;return(s=(i=this._removeHandlers)[e])==null?void 0:s.call(i,t)})}),this},add(...r){return r.map(kn).forEach(t=>{t.type.forEach(e=>{var n,o;const i=this._addHandlers,s=this._queue;i[e]?(o=i[e])==null||o.call(i,t):(s[e]=s[e]||[],(n=s[e])==null||n.push(t))})}),this},handle(r,t,e){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]=t,s[r]=e;const n=this._queue;return n[r]&&((o=n[r])==null||o.forEach(a=>t(a)),delete n[r]),this},handleByMap(r,t){return this.handle(r,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(r,t,e=-1){return this.handle(r,i=>{t.findIndex(n=>n.name===i.name)>=0||(t.push({name:i.name,value:i.ref}),t.sort((n,o)=>ji(o.value,e)-ji(n.value,e)))},i=>{const s=t.findIndex(n=>n.name===i.name);s!==-1&&t.splice(s,1)})},handleByList(r,t,e=-1){return this.handle(r,i=>{t.includes(i.ref)||(t.push(i.ref),t.sort((s,n)=>ji(n,e)-ji(s,e)))},i=>{const s=t.indexOf(i.ref);s!==-1&&t.splice(s,1)})},mixin(r,...t){for(const e of t)Object.defineProperties(r.prototype,Object.getOwnPropertyDescriptors(e))}},Jc={extension:{type:E.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await _e(()=>import("./browserAll.De-cmVZB.js"),__vite__mapDeps([0,1,2,3,4]))}},td={extension:{type:E.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await _e(()=>import("./webworkerAll.CrpT5gSi.js"),__vite__mapDeps([1,2,3,4]))}};class ct{constructor(t,e,i){this._x=e||0,this._y=i||0,this._observer=t}clone(t){return new ct(t??this._observer,this._x,this._y)}set(t=0,e=t){return(this._x!==t||this._y!==e)&&(this._x=t,this._y=e,this._observer._onUpdate(this)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this._observer._onUpdate(this)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this._observer._onUpdate(this))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this._observer._onUpdate(this))}}var eh={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(h,l,c){this.fn=h,this.context=l,this.once=c||!1}function 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=e?e+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)t.call(c,d)&&l.push(e?d.slice(1):d);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(c)):l},a.prototype.listeners=function(l){var c=e?e+l:l,d=this._events[c];if(!d)return[];if(d.fn)return[d.fn];for(var u=0,p=d.length,f=new Array(p);u<p;u++)f[u]=d[u].fn;return f},a.prototype.listenerCount=function(l){var c=e?e+l:l,d=this._events[c];return d?d.fn?1:d.length:0},a.prototype.emit=function(l,c,d,u,p,f){var y=e?e+l:l;if(!this._events[y])return!1;var m=this._events[y],x=arguments.length,S,v;if(m.fn){switch(m.once&&this.removeListener(l,m.fn,void 0,!0),x){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,c),!0;case 3:return m.fn.call(m.context,c,d),!0;case 4:return m.fn.call(m.context,c,d,u),!0;case 5:return m.fn.call(m.context,c,d,u,p),!0;case 6:return m.fn.call(m.context,c,d,u,p,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=e?e+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=e?e+l:l,this._events[c]&&o(this,c)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(eh);var ed=eh.exports;const Yt=qa(ed),id=Math.PI*2,sd=180/Math.PI,nd=Math.PI/180;class tt{constructor(t=0,e=0){this.x=0,this.y=0,this.x=t,this.y=e}clone(){return new tt(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,e=t){return this.x=t,this.y=e,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Us.x=0,Us.y=0,Us}}const Us=new tt;class W{constructor(t=1,e=0,i=0,s=1,n=0,o=0){this.array=null,this.a=t,this.b=e,this.c=i,this.d=s,this.tx=n,this.ty=o}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,e,i,s,n,o){return this.a=t,this.b=e,this.c=i,this.d=s,this.tx=n,this.ty=o,this}toArray(t,e){this.array||(this.array=new Float32Array(9));const i=e||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,e){e=e||new tt;const i=t.x,s=t.y;return e.x=this.a*i+this.c*s+this.tx,e.y=this.b*i+this.d*s+this.ty,e}applyInverse(t,e){e=e||new 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=t.x,d=t.y;return e.x=o*l*c+-n*l*d+(h*n-a*o)*l,e.y=i*l*d+-s*l*c+(-h*i+a*s)*l,e}translate(t,e){return this.tx+=t,this.ty+=e,this}scale(t,e){return this.a*=t,this.d*=e,this.c*=t,this.b*=e,this.tx*=t,this.ty*=e,this}rotate(t){const e=Math.cos(t),i=Math.sin(t),s=this.a,n=this.c,o=this.tx;return this.a=s*e-this.b*i,this.b=s*i+this.b*e,this.c=n*e-this.d*i,this.d=n*i+this.d*e,this.tx=o*e-this.ty*i,this.ty=o*i+this.ty*e,this}append(t){const e=this.a,i=this.b,s=this.c,n=this.d;return this.a=t.a*e+t.b*s,this.b=t.a*i+t.b*n,this.c=t.c*e+t.d*s,this.d=t.c*i+t.d*n,this.tx=t.tx*e+t.ty*s+this.tx,this.ty=t.tx*i+t.ty*n+this.ty,this}appendFrom(t,e){const i=t.a,s=t.b,n=t.c,o=t.d,a=t.tx,h=t.ty,l=e.a,c=e.b,d=e.c,u=e.d;return this.a=i*l+s*d,this.b=i*c+s*u,this.c=n*l+o*d,this.d=n*c+o*u,this.tx=a*l+h*d+e.tx,this.ty=a*c+h*u+e.ty,this}setTransform(t,e,i,s,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=t-(i*this.a+s*this.c),this.ty=e-(i*this.b+s*this.d),this}prepend(t){const e=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,s=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=s*t.a+this.d*t.c,this.d=s*t.b+this.d*t.d}return this.tx=e*t.a+this.ty*t.c+t.tx,this.ty=e*t.b+this.ty*t.d+t.ty,this}decompose(t){const e=this.a,i=this.b,s=this.c,n=this.d,o=t.pivot,a=-Math.atan2(-s,n),h=Math.atan2(i,e),l=Math.abs(a+h);return l<1e-5||Math.abs(id-l)<1e-5?(t.rotation=h,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=h),t.scale.x=Math.sqrt(e*e+i*i),t.scale.y=Math.sqrt(s*s+n*n),t.position.x=this.tx+(o.x*e+o.y*s),t.position.y=this.ty+(o.x*i+o.y*n),t}invert(){const t=this.a,e=this.b,i=this.c,s=this.d,n=this.tx,o=t*s-e*i;return this.a=s/o,this.b=-e/o,this.c=-i/o,this.d=t/o,this.tx=(i*this.ty-s*n)/o,this.ty=-(t*this.ty-e*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 t=new W;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}equals(t){return t.a===this.a&&t.b===this.b&&t.c===this.c&&t.d===this.d&&t.tx===this.tx&&t.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return od.identity()}static get shared(){return rd.identity()}}const rd=new W,od=new W,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],Ae=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Rn=[],ih=[],Yi=Math.sign;function ad(){for(let r=0;r<16;r++){const t=[];Rn.push(t);for(let e=0;e<16;e++){const i=Yi(ve[r]*ve[e]+we[r]*be[e]),s=Yi(be[r]*ve[e]+Ae[r]*be[e]),n=Yi(ve[r]*we[e]+we[r]*Ae[e]),o=Yi(be[r]*we[e]+Ae[r]*Ae[e]);for(let a=0;a<16;a++)if(ve[a]===i&&be[a]===s&&we[a]===n&&Ae[a]===o){t.push(a);break}}}for(let r=0;r<16;r++){const t=new W;t.set(ve[r],be[r],we[r],Ae[r],0,0),ih.push(t)}}ad();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=>Ae[r],inv:r=>r&8?r&15:-r&7,add:(r,t)=>Rn[r][t],sub:(r,t)=>Rn[r][X.inv(t)],rotate180:r=>r^4,isVertical:r=>(r&3)===2,byDirection:(r,t)=>Math.abs(r)*2<=Math.abs(t)?t>=0?X.S:X.N:Math.abs(t)*2<=Math.abs(r)?r>0?X.E:X.W:t>0?r>0?X.SE:X.SW:r>0?X.NE:X.NW,matrixAppendRotationInv:(r,t,e=0,i=0,s=0,n=0)=>{const o=ih[X.inv(t)],a=o.a,h=o.b,l=o.c,c=o.d,d=e-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,t,e,i)=>{const{x:s,y:n,width:o,height:a}=r,{x:h,y:l,width:c,height:d}=t;return e===X.E?(i.set(s+h,n+l,o,a),i):e===X.S?i.set(c-n-a+h,s+l,a,o):e===X.W?i.set(c-s-o+h,d-n-a+l,o,a):e===X.N?i.set(n+h,d-s-o+l,a,o):i.set(s+h,n+l,o,a)}},Xi=[new tt,new tt,new tt,new tt];class et{constructor(t=0,e=0,i=0,s=0){this.type="rectangle",this.x=Number(t),this.y=Number(e),this.width=Number(i),this.height=Number(s)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new et(0,0,0,0)}clone(){return new et(this.x,this.y,this.width,this.height)}copyFromBounds(t){return this.x=t.minX,this.y=t.minY,this.width=t.maxX-t.minX,this.height=t.maxY-t.minY,this}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&e>=this.y&&e<this.y+this.height}strokeContains(t,e,i,s=.5){const{width: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 t>=d&&t<=u&&e>=p&&e<=f&&!(t>y&&t<m&&e>x&&e<S)}intersects(t,e){if(!e){const k=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=k)return!1;const T=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.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=Xi[0].set(t.left,t.top),h=Xi[1].set(t.left,t.bottom),l=Xi[2].set(t.right,t.top),c=Xi[3].set(t.right,t.bottom);if(l.x<=a.x||h.y<=a.y)return!1;const d=Math.sign(e.a*e.d-e.b*e.c);if(d===0||(e.apply(a,a),e.apply(h,h),e.apply(l,l),e.apply(c,c),Math.max(a.x,h.x,l.x,c.x)<=i||Math.min(a.x,h.x,l.x,c.x)>=s||Math.max(a.y,h.y,l.y,c.y)<=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,w=S*i+v*o,C=S*s+v*o;return!(Math.max(b,P,w,C)<=S*a.x+v*a.y||Math.min(b,P,w,C)>=S*c.x+v*c.y)}pad(t=0,e=t){return this.x-=t,this.y-=e,this.width+=t*2,this.height+=e*2,this}fit(t){const e=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),n=Math.min(this.y+this.height,t.y+t.height);return this.x=e,this.width=Math.max(i-e,0),this.y=s,this.height=Math.max(n-s,0),this}ceil(t=1,e=.001){const i=Math.ceil((this.x+this.width-e)*t)/t,s=Math.ceil((this.y+this.height-e)*t)/t;return this.x=Math.floor((this.x+e)*t)/t,this.y=Math.floor((this.y+e)*t)/t,this.width=i-this.x,this.height=s-this.y,this}scale(t,e=t){return this.x*=t,this.y*=e,this.width*=t,this.height*=e,this}enlarge(t){const e=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),n=Math.max(this.y+this.height,t.y+t.height);return this.x=e,this.width=i-e,this.y=s,this.height=n-s,this}getBounds(t){return t||(t=new et),t.copyFrom(this),t}containsRect(t){if(this.width<=0||this.height<=0)return!1;const e=t.x,i=t.y,s=t.x+t.width,n=t.y+t.height;return e>=this.x&&e<this.x+this.width&&i>=this.y&&i<this.y+this.height&&s>=this.x&&s<this.x+this.width&&n>=this.y&&n<this.y+this.height}set(t,e,i,s){return this.x=t,this.y=e,this.width=i,this.height=s,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Hs={default:-1};function dt(r="default"){return Hs[r]===void 0&&(Hs[r]=-1),++Hs[r]}const qr=new Set,J="8.0.0",hd="8.3.4",He={quiet:!1,noColor:!1},V=(r,t,e=3)=>{if(He.quiet||qr.has(t))return;let i=new Error().stack;const s=`${t}
|
|
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(e).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))),qr.add(t)};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 sh=()=>{};function qe(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 Kr(r){return!(r&r-1)&&!!r}function nh(r){const t={};for(const e in r)r[e]!==void 0&&(t[e]=r[e]);return t}const $r=Object.create(null);function ld(r){const t=$r[r];return t===void 0&&($r[r]=dt("resource")),t}const rh=class oh extends Yt{constructor(t={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,t={...oh.defaultOptions,...t},this.addressMode=t.addressMode,this.addressModeU=t.addressModeU??this.addressModeU,this.addressModeV=t.addressModeV??this.addressModeV,this.addressModeW=t.addressModeW??this.addressModeW,this.scaleMode=t.scaleMode,this.magFilter=t.magFilter??this.magFilter,this.minFilter=t.minFilter??this.minFilter,this.mipmapFilter=t.mipmapFilter??this.mipmapFilter,this.lodMinClamp=t.lodMinClamp,this.lodMaxClamp=t.lodMaxClamp,this.compare=t.compare,this.maxAnisotropy=t.maxAnisotropy??1}set addressMode(t){this.addressModeU=t,this.addressModeV=t,this.addressModeW=t}get addressMode(){return this.addressModeU}set wrapMode(t){V(J,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=t}get wrapMode(){return this.addressMode}set scaleMode(t){this.magFilter=t,this.minFilter=t,this.mipmapFilter=t}get scaleMode(){return this.magFilter}set maxAnisotropy(t){this._maxAnisotropy=Math.min(t,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this._sharedResourceId=null,this.emit("change",this)}_generateResourceId(){const t=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=ld(t),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};rh.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let Ke=rh;const ah=class hh extends Yt{constructor(t={}){super(),this.options=t,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,t={...hh.defaultOptions,...t},this.label=t.label??"",this.resource=t.resource,this.autoGarbageCollect=t.autoGarbageCollect,this._resolution=t.resolution,t.width?this.pixelWidth=t.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,t.height?this.pixelHeight=t.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=t.format,this.dimension=t.dimensions,this.viewDimension=t.viewDimension??t.dimensions,this.arrayLayerCount=t.arrayLayerCount,this.mipLevelCount=t.mipLevelCount,this.autoGenerateMipmaps=t.autoGenerateMipmaps,this.sampleCount=t.sampleCount,this.antialias=t.antialias,this.alphaMode=t.alphaMode,this.style=new Ke(nh(t)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(t){var e,i;this.style!==t&&((e=this._style)==null||e.off("change",this._onStyleChange,this),this._style=t,(i=this._style)==null||i.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(t){this._style.maxAnisotropy=t}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(t){this._style.addressMode=t}get repeatMode(){return this._style.addressMode}set repeatMode(t){this._style.addressMode=t}get magFilter(){return this._style.magFilter}set magFilter(t){this._style.magFilter=t}get minFilter(){return this._style.minFilter}set minFilter(t){this._style.minFilter=t}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(t){this._style.mipmapFilter=t}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(t){this._style.lodMinClamp=t}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(t){this._style.lodMaxClamp=t}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const t=this._resolution;if(this.resize(this.resourceWidth/t,this.resourceHeight/t))return}this.emit("update",this)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this._style&&(this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){var t,e;this._resourceId=dt("resource"),this.emit("change",this),this.emit("unload",this);for(const i in this._gpuData)(e=(t=this._gpuData[i])==null?void 0:t.destroy)==null||e.call(t);this._gpuData=Object.create(null)}get resourceWidth(){const{resource:t}=this;return t.naturalWidth||t.videoWidth||t.displayWidth||t.width}get resourceHeight(){const{resource:t}=this;return t.naturalHeight||t.videoHeight||t.displayHeight||t.height}get resolution(){return this._resolution}set resolution(t){this._resolution!==t&&(this._resolution=t,this.width=this.pixelWidth/t,this.height=this.pixelHeight/t)}resize(t,e,i){i||(i=this._resolution),t||(t=this.width),e||(e=this.height);const s=Math.round(t*i),n=Math.round(e*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(t){this._style.wrapMode=t}get wrapMode(){return this._style.wrapMode}set scaleMode(t){this._style.scaleMode=t}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=Kr(this.pixelWidth)&&Kr(this.pixelHeight)}static test(t){throw new Error("Unimplemented")}};ah.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 Bt=ah;class ar extends Bt{constructor(t){const e=t.resource||new Float32Array(t.width*t.height*4);let i=t.format;i||(e instanceof Float32Array?i="rgba32float":e instanceof Int32Array||e instanceof Uint32Array?i="rgba32uint":e instanceof Int16Array||e instanceof Uint16Array?i="rgba16uint":(e instanceof Int8Array,i="bgra8unorm")),super({...t,resource:e,format:i}),this.uploadMethodId="buffer"}static test(t){return t instanceof Int8Array||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array}}ar.extension=E.TextureSource;const Qr=new W;class cd{constructor(t,e){this.mapCoord=new W,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof e>"u"?this.clampMargin=t.width<10?0:.5:this.clampMargin=e,this.isSimple=!1,this.texture=t}get texture(){return this._texture}set texture(t){var e;this.texture!==t&&((e=this._texture)==null||e.removeListener("update",this.update,this),this._texture=t,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(t,e){e===void 0&&(e=t);const i=this.mapCoord;for(let s=0;s<t.length;s+=2){const n=t[s],o=t[s+1];e[s]=n*i.a+o*i.c+i.tx,e[s+1]=n*i.b+o*i.d+i.ty}return e}update(){const t=this._texture;this._updateID++;const e=t.uvs;this.mapCoord.set(e.x1-e.x0,e.y1-e.y0,e.x3-e.x0,e.y3-e.y0,e.x0,e.y0);const i=t.orig,s=t.trim;s&&(Qr.set(i.width/s.width,0,0,i.height/s.height,-s.x/s.width,-s.y/s.height),this.mapCoord.append(Qr));const n=t.source,o=this.uClampFrame,a=this.clampMargin/n._resolution,h=this.clampOffset/n._resolution;return o[0]=(t.frame.x+a+h)/n.width,o[1]=(t.frame.y+a+h)/n.height,o[2]=(t.frame.x+t.frame.width-a+h)/n.width,o[3]=(t.frame.y+t.frame.height-a+h)/n.height,this.uClampOffset[0]=this.clampOffset/n.pixelWidth,this.uClampOffset[1]=this.clampOffset/n.pixelHeight,this.isSimple=t.frame.width===n.width&&t.frame.height===n.height&&t.rotate===0,!0}}class G extends Yt{constructor({source:t,label:e,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=e,this.source=(t==null?void 0:t.source)??new Bt,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(t){this._source&&this._source.off("resize",this.update,this),this._source=t,t.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new cd(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:t,frame:e}=this,{width:i,height:s}=this._source,n=e.x/i,o=e.y/s,a=e.width/i,h=e.height/s;let l=this.rotate;if(l){const c=a/2,d=h/2,u=n+c,p=o+d;l=X.add(l,X.NW),t.x0=u+c*X.uX(l),t.y0=p+d*X.uY(l),l=X.add(l,2),t.x1=u+c*X.uX(l),t.y1=p+d*X.uY(l),l=X.add(l,2),t.x2=u+c*X.uX(l),t.y2=p+d*X.uY(l),l=X.add(l,2),t.x3=u+c*X.uX(l),t.y3=p+d*X.uY(l)}else t.x0=n,t.y0=o,t.x1=n+a,t.y1=o,t.x2=n+a,t.y2=o+h,t.x3=n,t.y3=o+h}destroy(t=!1){this._source&&(this._source.off("resize",this.update,this),t&&(this._source.destroy(),this._source=null)),this._textureMatrix=null,this.destroyed=!0,this.emit("destroy",this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit("update",this)}get baseTexture(){return V(J,"Texture.baseTexture is now Texture.source"),this._source}}G.EMPTY=new G({label:"EMPTY",source:new Bt({label:"EMPTY"})});G.EMPTY.destroy=sh;G.WHITE=new G({source:new ar({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});G.WHITE.destroy=sh;function lh(r,t,e){const{width:i,height:s}=e.orig,n=e.trim;if(n){const o=n.width,a=n.height;r.minX=n.x-t._x*i,r.maxX=r.minX+o,r.minY=n.y-t._y*s,r.maxY=r.minY+a}else r.minX=-t._x*i,r.maxX=r.minX+i,r.minY=-t._y*s,r.maxY=r.minY+s}const Jr=new W;class It{constructor(t=1/0,e=1/0,i=-1/0,s=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Jr,this.minX=t,this.minY=e,this.maxX=i,this.maxY=s}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new et);const t=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(t.x=0,t.y=0,t.width=0,t.height=0):t.copyFromBounds(this),t}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Jr,this}set(t,e,i,s){this.minX=t,this.minY=e,this.maxX=i,this.maxY=s}addFrame(t,e,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*t+h*e+c,x=a*t+l*e+d;m<u&&(u=m),x<p&&(p=x),m>f&&(f=m),x>y&&(y=x),m=o*i+h*e+c,x=a*i+l*e+d,m<u&&(u=m),x<p&&(p=x),m>f&&(f=m),x>y&&(y=x),m=o*t+h*s+c,x=a*t+l*s+d,m<u&&(u=m),x<p&&(p=x),m>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(t,e){this.addFrame(t.x,t.y,t.x+t.width,t.y+t.height,e)}addBounds(t,e){this.addFrame(t.minX,t.minY,t.maxX,t.maxY,e)}addBoundsMask(t){this.minX=this.minX>t.minX?this.minX:t.minX,this.minY=this.minY>t.minY?this.minY:t.minY,this.maxX=this.maxX<t.maxX?this.maxX:t.maxX,this.maxY=this.maxY<t.maxY?this.maxY:t.maxY}applyMatrix(t){const e=this.minX,i=this.minY,s=this.maxX,n=this.maxY,{a:o,b:a,c:h,d:l,tx:c,ty:d}=t;let u=o*e+h*i+c,p=a*e+l*i+d;this.minX=u,this.minY=p,this.maxX=u,this.maxY=p,u=o*s+h*i+c,p=a*s+l*i+d,this.minX=u<this.minX?u:this.minX,this.minY=p<this.minY?p:this.minY,this.maxX=u>this.maxX?u:this.maxX,this.maxY=p>this.maxY?p:this.maxY,u=o*e+h*n+c,p=a*e+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(t){return this.minX<t.left&&(this.minX=t.left),this.maxX>t.right&&(this.maxX=t.right),this.minY<t.top&&(this.minY=t.top),this.maxY>t.bottom&&(this.maxY=t.bottom),this}fitBounds(t,e,i,s){return this.minX<t&&(this.minX=t),this.maxX>e&&(this.maxX=e),this.minY<i&&(this.minY=i),this.maxY>s&&(this.maxY=s),this}pad(t,e=t){return this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new It(this.minX,this.minY,this.maxX,this.maxY)}scale(t,e=t){return this.minX*=t,this.minY*=e,this.maxX*=t,this.maxY*=e,this}get x(){return this.minX}set x(t){const e=this.maxX-this.minX;this.minX=t,this.maxX=t+e}get y(){return this.minY}set y(t){const e=this.maxY-this.minY;this.minY=t,this.maxY=t+e}get width(){return this.maxX-this.minX}set width(t){this.maxX=this.minX+t}get height(){return this.maxY-this.minY}set height(t){this.maxY=this.minY+t}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(t,e,i,s){let 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=e;y<i;y+=2){const m=t[y],x=t[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(t,e){return this.minX<=t&&this.minY<=e&&this.maxX>=t&&this.maxY>=e}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(t){return this.minX=t.minX,this.minY=t.minY,this.maxX=t.maxX,this.maxY=t.maxY,this}}var dd={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,t,e){return t===void 0&&(t=0),e===void 0&&(e=Math.pow(10,t)),Math.round(e*r)/e+0},Et=function(r,t,e){return t===void 0&&(t=0),e===void 0&&(e=1),r>e?e:r>t?r:t},ch=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},to=function(r){return{r:Et(r.r,0,255),g:Et(r.g,0,255),b:Et(r.b,0,255),a:Et(r.a)}},Vs=function(r){return{r:St(r.r),g:St(r.g),b:St(r.b),a:St(r.a,3)}},ud=/^#([0-9a-f]{3,8})$/i,Zi=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},dh=function(r){var t=r.r,e=r.g,i=r.b,s=r.a,n=Math.max(t,e,i),o=n-Math.min(t,e,i),a=o?n===t?(e-i)/o:n===e?2+(i-t)/o:4+(t-e)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:s}},uh=function(r){var t=r.h,e=r.s,i=r.v,s=r.a;t=t/360*6,e/=100,i/=100;var n=Math.floor(t),o=i*(1-e),a=i*(1-(t-n)*e),h=i*(1-(1-t+n)*e),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}},eo=function(r){return{h:ch(r.h),s:Et(r.s,0,100),l:Et(r.l,0,100),a:Et(r.a)}},io=function(r){return{h:St(r.h),s:St(r.s),l:St(r.l),a:St(r.a,3)}},so=function(r){return uh((e=(t=r).s,{h:t.h,s:(e*=((i=t.l)<50?i:100-i)/100)>0?2*e/(i+e)*100:0,v:i+e,a:t.a}));var t,e,i},bi=function(r){return{h:(t=dh(r)).h,s:(s=(200-(e=t.s))*(i=t.v)/100)>0&&s<200?e*i/100/(s<=100?s:200-s)*100:0,l:s/2,a:t.a};var t,e,i,s},pd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,fd=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,gd=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,md=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,En={string:[[function(r){var t=ud.exec(r);return t?(r=t[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 t=gd.exec(r)||md.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:to({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(r){var t=pd.exec(r)||fd.exec(r);if(!t)return null;var e,i,s=eo({h:(e=t[1],i=t[2],i===void 0&&(i="deg"),Number(e)*(dd[i]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return so(s)},"hsl"]],object:[[function(r){var t=r.r,e=r.g,i=r.b,s=r.a,n=s===void 0?1:s;return Zt(t)&&Zt(e)&&Zt(i)?to({r:Number(t),g:Number(e),b:Number(i),a:Number(n)}):null},"rgb"],[function(r){var t=r.h,e=r.s,i=r.l,s=r.a,n=s===void 0?1:s;if(!Zt(t)||!Zt(e)||!Zt(i))return null;var o=eo({h:Number(t),s:Number(e),l:Number(i),a:Number(n)});return so(o)},"hsl"],[function(r){var t=r.h,e=r.s,i=r.v,s=r.a,n=s===void 0?1:s;if(!Zt(t)||!Zt(e)||!Zt(i))return null;var o=function(a){return{h:ch(a.h),s:Et(a.s,0,100),v:Et(a.v,0,100),a:Et(a.a)}}({h:Number(t),s:Number(e),v:Number(i),a:Number(n)});return uh(o)},"hsv"]]},no=function(r,t){for(var e=0;e<t.length;e++){var i=t[e][0](r);if(i)return[i,t[e][1]]}return[null,void 0]},yd=function(r){return typeof r=="string"?no(r.trim(),En.string):typeof r=="object"&&r!==null?no(r,En.object):[null,void 0]},Ns=function(r,t){var e=bi(r);return{h:e.h,s:Et(e.s+100*t,0,100),l:e.l,a:e.a}},js=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},ro=function(r,t){var e=bi(r);return{h:e.h,s:e.s,l:Et(e.l+100*t,0,100),a:e.a}},In=function(){function r(t){this.parsed=yd(t)[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(js(this.rgba),2)},r.prototype.isDark=function(){return js(this.rgba)<.5},r.prototype.isLight=function(){return js(this.rgba)>=.5},r.prototype.toHex=function(){return t=Vs(this.rgba),e=t.r,i=t.g,s=t.b,o=(n=t.a)<1?Zi(St(255*n)):"","#"+Zi(e)+Zi(i)+Zi(s)+o;var t,e,i,s,n,o},r.prototype.toRgb=function(){return Vs(this.rgba)},r.prototype.toRgbString=function(){return t=Vs(this.rgba),e=t.r,i=t.g,s=t.b,(n=t.a)<1?"rgba("+e+", "+i+", "+s+", "+n+")":"rgb("+e+", "+i+", "+s+")";var t,e,i,s,n},r.prototype.toHsl=function(){return io(bi(this.rgba))},r.prototype.toHslString=function(){return t=io(bi(this.rgba)),e=t.h,i=t.s,s=t.l,(n=t.a)<1?"hsla("+e+", "+i+"%, "+s+"%, "+n+")":"hsl("+e+", "+i+"%, "+s+"%)";var t,e,i,s,n},r.prototype.toHsv=function(){return t=dh(this.rgba),{h:St(t.h),s:St(t.s),v:St(t.v),a:St(t.a,3)};var t},r.prototype.invert=function(){return Ut({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},r.prototype.saturate=function(t){return t===void 0&&(t=.1),Ut(Ns(this.rgba,t))},r.prototype.desaturate=function(t){return t===void 0&&(t=.1),Ut(Ns(this.rgba,-t))},r.prototype.grayscale=function(){return Ut(Ns(this.rgba,-1))},r.prototype.lighten=function(t){return t===void 0&&(t=.1),Ut(ro(this.rgba,t))},r.prototype.darken=function(t){return t===void 0&&(t=.1),Ut(ro(this.rgba,-t))},r.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},r.prototype.alpha=function(t){return typeof t=="number"?Ut({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):St(this.rgba.a,3);var e},r.prototype.hue=function(t){var e=bi(this.rgba);return typeof t=="number"?Ut({h:t,s:e.s,l:e.l,a:e.a}):St(e.h)},r.prototype.isEqual=function(t){return this.toHex()===Ut(t).toHex()},r}(),Ut=function(r){return r instanceof In?r:new In(r)},oo=[],xd=function(r){r.forEach(function(t){oo.indexOf(t)<0&&(t(In,En),oo.push(t))})};function Sd(r,t){var e={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},i={};for(var s in e)i[e[s]]=s;var 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 e)n[p]=new r(e[p]).toRgb();for(var f in e){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}},t.string.push([function(o){var a=o.toLowerCase(),h=a==="transparent"?"#0000":e[a];return h?new r(h).toRgb():null},"name"])}xd([Sd]);const $e=class mi{constructor(t=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=t}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(t){return this.value=t,this}set value(t){if(t instanceof mi)this._value=this._cloneSource(t._value),this._int=t._int,this._components.set(t._components);else{if(t===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,t))&&(this._value=this._cloneSource(t),this._normalize(this._value))}}get value(){return this._value}_cloneSource(t){return typeof t=="string"||typeof t=="number"||t instanceof Number||t===null?t:Array.isArray(t)||ArrayBuffer.isView(t)?t.slice(0):typeof t=="object"&&t!==null?{...t}:t}_isSourceEqual(t,e){const i=typeof t;if(i!==typeof e)return!1;if(i==="number"||i==="string"||t instanceof Number)return t===e;if(Array.isArray(t)&&Array.isArray(e)||ArrayBuffer.isView(t)&&ArrayBuffer.isView(e))return t.length!==e.length?!1:t.every((n,o)=>n===e[o]);if(t!==null&&e!==null){const n=Object.keys(t),o=Object.keys(e);return n.length!==o.length?!1:n.every(a=>t[a]===e[a])}return t===e}toRgba(){const[t,e,i,s]=this._components;return{r:t,g:e,b:i,a:s}}toRgb(){const[t,e,i]=this._components;return{r:t,g:e,b:i}}toRgbaString(){const[t,e,i]=this.toUint8RgbArray();return`rgba(${t},${e},${i},${this.alpha})`}toUint8RgbArray(t){const[e,i,s]=this._components;return this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb),t[0]=Math.round(e*255),t[1]=Math.round(i*255),t[2]=Math.round(s*255),t}toArray(t){this._arrayRgba||(this._arrayRgba=[]),t||(t=this._arrayRgba);const[e,i,s,n]=this._components;return t[0]=e,t[1]=i,t[2]=s,t[3]=n,t}toRgbArray(t){this._arrayRgb||(this._arrayRgb=[]),t||(t=this._arrayRgb);const[e,i,s]=this._components;return t[0]=e,t[1]=i,t[2]=s,t}toNumber(){return this._int}toBgrNumber(){const[t,e,i]=this.toUint8RgbArray();return(i<<16)+(e<<8)+t}toLittleEndianNumber(){const t=this._int;return(t>>16)+(t&65280)+((t&255)<<16)}multiply(t){const[e,i,s,n]=mi._temp.setValue(t)._components;return this._components[0]*=e,this._components[1]*=i,this._components[2]*=s,this._components[3]*=n,this._refreshInt(),this._value=null,this}premultiply(t,e=!0){return e&&(this._components[0]*=t,this._components[1]*=t,this._components[2]*=t),this._components[3]=t,this._refreshInt(),this._value=null,this}toPremultiplied(t,e=!0){if(t===1)return(255<<24)+this._int;if(t===0)return e?0:this._int;let i=this._int>>16&255,s=this._int>>8&255,n=this._int&255;return e&&(i=i*t+.5|0,s=s*t+.5|0,n=n*t+.5|0),(t*255<<24)+(i<<16)+(s<<8)+n}toHex(){const t=this._int.toString(16);return`#${"000000".substring(0,6-t.length)+t}`}toHexa(){const e=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-e.length)+e}setAlpha(t){return this._components[3]=this._clamp(t),this}_normalize(t){let e,i,s,n;if((typeof t=="number"||t instanceof Number)&&t>=0&&t<=16777215){const o=t;e=(o>>16&255)/255,i=(o>>8&255)/255,s=(o&255)/255,n=1}else if((Array.isArray(t)||t instanceof Float32Array)&&t.length>=3&&t.length<=4)t=this._clamp(t),[e,i,s,n=1]=t;else if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&t.length>=3&&t.length<=4)t=this._clamp(t,0,255),[e,i,s,n=255]=t,e/=255,i/=255,s/=255,n/=255;else if(typeof t=="string"||typeof t=="object"){if(typeof t=="string"){const a=mi.HEX_PATTERN.exec(t);a&&(t=`#${a[2]}`)}const o=Ut(t);o.isValid()&&({r:e,g:i,b:s,a:n}=o.rgba,e/=255,i/=255,s/=255)}if(e!==void 0)this._components[0]=e,this._components[1]=i,this._components[2]=s,this._components[3]=n,this._refreshInt();else throw new Error(`Unable to convert color ${t}`)}_refreshInt(){this._clamp(this._components);const[t,e,i]=this._components;this._int=(t*255<<16)+(e*255<<8)+(i*255|0)}_clamp(t,e=0,i=1){return typeof t=="number"?Math.min(Math.max(t,e),i):(t.forEach((s,n)=>{t[n]=Math.min(Math.max(s,e),i)}),t)}static isColorLike(t){return typeof t=="number"||typeof t=="string"||t instanceof Number||t instanceof mi||Array.isArray(t)||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Float32Array||t.r!==void 0&&t.g!==void 0&&t.b!==void 0||t.r!==void 0&&t.g!==void 0&&t.b!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0&&t.a!==void 0}};$e.shared=new $e;$e._temp=new $e;$e.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let rt=$e;const vd={cullArea:null,cullable:!1,cullableChildren:!0};let Ys=0;const ao=500;function nt(...r){Ys!==ao&&(Ys++,Ys===ao?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...r))}const Oi={_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 bd{constructor(t,e){this._pool=[],this._count=0,this._index=0,this._classType=t,e&&this.prepopulate(e)}prepopulate(t){for(let e=0;e<t;e++)this._pool[this._index++]=new this._classType;this._count+=t}get(t){var i;let e;return this._index>0?e=this._pool[--this._index]:(e=new this._classType,this._count++),(i=e.init)==null||i.call(e,t),e}return(t){var e;(e=t.reset)==null||e.call(t),this._pool[this._index++]=t}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let t=0;t<this._index;t++)this._pool[t].destroy();this._pool.length=0,this._count=0,this._index=0}}class wd{constructor(){this._poolsByClass=new Map}prepopulate(t,e){this.getPool(t).prepopulate(e)}get(t,e){return this.getPool(t).get(e)}return(t){this.getPool(t.constructor).return(t)}getPool(t){return this._poolsByClass.has(t)||this._poolsByClass.set(t,new bd(t)),this._poolsByClass.get(t)}stats(){const t={};return this._poolsByClass.forEach(e=>{const i=t[e._classType.name]?e._classType.name+e._classType.ID:e._classType.name;t[i]={free:e.totalFree,used:e.totalUsed,size:e.totalSize}}),t}clear(){this._poolsByClass.forEach(t=>t.clear()),this._poolsByClass.clear()}}const _t=new wd;Oi.register(_t);const Ad={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 Cd(r,t,e){const i=r.length;let s;if(t>=i||e===0)return;e=t+e>i?i-t:e;const n=i-e;for(s=t;s<n;++s)r[s]=r[s+e];r.length=n}const Pd={allowChildren:!0,removeChildren(r=0,t){var n;const e=t??this.children.length,i=e-r,s=[];if(i>0&&i<=e){for(let a=e-1;a>=r;a--){const h=this.children[a];h&&(s.push(h),h.parent=null)}Cd(this.children,r,e);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 t=this.getChildAt(r);return this.removeChild(t)},getChildAt(r){if(r<0||r>=this.children.length)throw new Error(`getChildAt: Index (${r}) does not exist.`);return this.children[r]},setChildIndex(r,t){if(t<0||t>=this.children.length)throw new Error(`The index ${t} supplied is out of bounds ${this.children.length}`);this.getChildIndex(r),this.addChildAt(r,t)},getChildIndex(r){const t=this.children.indexOf(r);if(t===-1)throw new Error("The supplied Container must be a child of the caller");return t},addChildAt(r,t){this.allowChildren||V(J,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:e}=this;if(t<0||t>e.length)throw new Error(`${r}addChildAt: The index ${t} supplied is out of bounds ${e.length}`);if(r.parent){const s=r.parent.children.indexOf(r);if(r.parent===this&&s===t)return r;s!==-1&&r.parent.children.splice(s,1)}t===e.length?e.push(r):e.splice(t,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,t),r.emit("added",this),r},swapChildren(r,t){if(r===t)return;const e=this.getChildIndex(r),i=this.getChildIndex(t);this.children[e]=t,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(t=>this.reparentChildAt(t,this.children.length)),r[0])},reparentChildAt(r,t){if(r.parent===this)return this.setChildIndex(r,t),r;const e=r.worldTransform.clone();r.removeFromParent(),this.addChildAt(r,t);const i=this.worldTransform.clone();return i.invert(),e.prepend(i),r.setFromMatrix(e),r},replaceChild(r,t){r.updateLocalTransform(),this.addChildAt(t,this.getChildIndex(r)),t.setFromMatrix(r.localTransform),t.updateLocalTransform(),this.removeChild(r)}},Md={collectRenderables(r,t,e){this.parentRenderLayer&&this.parentRenderLayer!==e||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(r,t,e):this.renderGroup?t.renderPipes.renderGroup.addRenderGroup(this.renderGroup,r):this.collectRenderablesWithEffects(r,t,e))},collectRenderablesSimple(r,t,e){const i=this.children,s=i.length;for(let n=0;n<s;n++)i[n].collectRenderables(r,t,e)},collectRenderablesWithEffects(r,t,e){const{renderPipes:i}=t;for(let s=0;s<this.effects.length;s++){const n=this.effects[s];i[n.pipe].push(n,this,r)}this.collectRenderablesSimple(r,t,e);for(let s=this.effects.length-1;s>=0;s--){const n=this.effects[s];i[n.pipe].pop(n,this,r)}}};class ho{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let t=0;t<this.filters.length;t++)this.filters[t].destroy();this.filters=null,this.filterArea=null}}class _d{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(t=>{this.add({test:t.test,maskClass:t})}))}add(t){this._tests.push(t)}getMaskEffect(t){this._initialized||this.init();for(let e=0;e<this._tests.length;e++){const i=this._tests[e];if(i.test(t))return _t.get(i.maskClass,t)}return t}returnMaskEffect(t){_t.return(t)}}const Bn=new _d;$.handleByList(E.MaskEffect,Bn._effectClasses);const Td={_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((e,i)=>e.priority-i.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(r){const t=this.effects.indexOf(r);t!==-1&&(this.effects.splice(t,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(r){const t=this._maskEffect;(t==null?void 0:t.mask)!==r&&(t&&(this.removeEffect(t),Bn.returnMaskEffect(t),this._maskEffect=null),r!=null&&(this._maskEffect=Bn.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 t=this._filterEffect||(this._filterEffect=new ho);r=r;const e=(r==null?void 0:r.length)>0,i=((n=t.filters)==null?void 0:n.length)>0,s=e!==i;r=Array.isArray(r)?r.slice(0):r,t.filters=Object.freeze(r),s&&(e?this.addEffect(t):(this.removeEffect(t),t.filters=r??null))},get filters(){var r;return(r=this._filterEffect)==null?void 0:r.filters},set filterArea(r){this._filterEffect||(this._filterEffect=new ho),this._filterEffect.filterArea=r},get filterArea(){var r;return(r=this._filterEffect)==null?void 0:r.filterArea}},kd={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,t=!1){return this.getChildByLabel(r,t)},getChildByLabel(r,t=!1){const e=this.children;for(let i=0;i<e.length;i++){const s=e[i];if(s.label===r||r instanceof RegExp&&r.test(s.label))return s}if(t)for(let i=0;i<e.length;i++){const n=e[i].getChildByLabel(r,!0);if(n)return n}return null},getChildrenByLabel(r,t=!1,e=[]){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))&&e.push(n)}if(t)for(let s=0;s<i.length;s++)i[s].getChildrenByLabel(r,!0,e);return e}},Pt=_t.getPool(W),Qt=_t.getPool(It),Rd=new W,Ed={getFastGlobalBounds(r,t){t||(t=new It),t.clear(),this._getGlobalBoundsRecursive(!!r,t,this.parentRenderLayer),t.isValid||t.set(0,0,0,0);const e=this.renderGroup||this.parentRenderGroup;return t.applyMatrix(e.worldTransform),t},_getGlobalBoundsRecursive(r,t,e){let i=t;if(r&&this.parentRenderLayer&&this.parentRenderLayer!==e||this.localDisplayStatus!==7||!this.measurable)return;const s=!!this.effects.length;if((this.renderGroup||s)&&(i=Qt.get().clear()),this.boundsArea)t.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const o=this.bounds;i.addFrame(o.minX,o.minY,o.maxX,o.maxY,this.groupTransform)}const n=this.children;for(let o=0;o<n.length;o++)n[o]._getGlobalBoundsRecursive(r,i,e)}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(Rd).invert()),t.addBounds(i),Qt.return(i)}else this.renderGroup&&(t.addBounds(i,this.relativeGroupTransform),Qt.return(i))}};function ph(r,t,e){e.clear();let i,s;return r.parent?t?i=r.parent.worldTransform:(s=Pt.get().identity(),i=hr(r,s)):i=W.IDENTITY,fh(r,e,i,t),s&&Pt.return(s),e.isValid||e.set(0,0,0,0),e}function fh(r,t,e,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,e));const n=t,o=!!r.effects.length;if(o&&(t=Qt.get().clear()),r.boundsArea)t.addRect(r.boundsArea,s);else{const l=r.bounds;l&&!l.isEmpty()&&(t.matrix=s,t.addBounds(l));for(let c=0;c<r.children.length;c++)fh(r.children[c],t,s,i)}if(o){for(let l=0;l<r.effects.length;l++)(h=(a=r.effects[l]).addBounds)==null||h.call(a,t);n.addBounds(t,W.IDENTITY),Qt.return(t)}i||Pt.return(s)}function hr(r,t){const e=r.parent;return e&&(hr(e,t),e.updateLocalTransform(),t.append(e.localTransform)),t}function lr(r,t){if(r===16777215||!t)return t;if(t===16777215||!r)return r;const e=r>>16&255,i=r>>8&255,s=r&255,n=t>>16&255,o=t>>8&255,a=t&255,h=e*n/255|0,l=i*o/255|0,c=s*a/255|0;return(h<<16)+(l<<8)+c}const lo=16777215;function co(r,t){return r===lo?t:t===lo?r:lr(r,t)}function wi(r){return((r&255)<<16)+(r&65280)+(r>>16&255)}const Id={getGlobalAlpha(r){if(r)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let t=this.alpha,e=this.parent;for(;e;)t*=e.alpha,e=e.parent;return t},getGlobalTransform(r=new W,t){if(t)return r.copyFrom(this.worldTransform);this.updateLocalTransform();const e=hr(this,Pt.get().identity());return r.appendFrom(this.localTransform,e),Pt.return(e),r},getGlobalTint(r){if(r)return this.renderGroup?wi(this.renderGroup.worldColor):this.parentRenderGroup?wi(co(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let t=this.localColor,e=this.parent;for(;e;)t=co(t,e.localColor),e=e.parent;return wi(t)}};function gh(r,t,e){return t.clear(),e||(e=W.IDENTITY),mh(r,t,e,r,!0),t.isValid||t.set(0,0,0,0),t}function mh(r,t,e,i,s){var h,l;let n;if(s)n=Pt.get(),n=e.copyTo(n);else{if(!r.visible||!r.measurable)return;r.updateLocalTransform();const c=r.localTransform;n=Pt.get(),n.appendFrom(c,e)}const o=t,a=!!r.effects.length;if(a&&(t=Qt.get().clear()),r.boundsArea)t.addRect(r.boundsArea,n);else{r.renderPipeId&&(t.matrix=n,t.addBounds(r.bounds));const c=r.children;for(let d=0;d<c.length;d++)mh(c[d],t,n,i,!1)}if(a){for(let c=0;c<r.effects.length;c++)(l=(h=r.effects[c]).addLocalBounds)==null||l.call(h,t,i);o.addBounds(t,W.IDENTITY),Qt.return(t)}Pt.return(n)}function yh(r,t){const e=r.children;for(let i=0;i<e.length;i++){const s=e[i],n=s.uid,o=(s._didViewChangeTick&65535)<<16|s._didContainerChangeTick&65535,a=t.index;(t.data[a]!==n||t.data[a+1]!==o)&&(t.data[t.index]=n,t.data[t.index+1]=o,t.didChange=!0),t.index=a+2,s.children.length&&yh(s,t)}return t.didChange}const Bd=new W,Dd={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(r,t){const e=Math.sign(this.scale.x)||1;t!==0?this.scale.x=r/t*e:this.scale.x=e},_setHeight(r,t){const e=Math.sign(this.scale.y)||1;t!==0?this.scale.y=r/t*e:this.scale.y=e},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new It});const r=this._localBoundsCacheData;return r.index=1,r.didChange=!1,r.data[0]!==this._didViewChangeTick&&(r.didChange=!0,r.data[0]=this._didViewChangeTick),yh(this,r),r.didChange&&gh(this,r.localBounds,Bd),r.localBounds},getBounds(r,t){return ph(this,r,t||new It)}},Fd={_onRender:null,set onRender(r){const t=this.renderGroup||this.parentRenderGroup;if(!r){this._onRender&&(t==null||t.removeOnRender(this)),this._onRender=null;return}this._onRender||t==null||t.addOnRender(this),this._onRender=r},get onRender(){return this._onRender}},zd={_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(Ld))}};function Ld(r,t){return r._zIndex-t._zIndex}const Od={getGlobalPosition(r=new tt,t=!1){return this.parent?this.parent.toGlobal(this._position,r,t):(r.x=this._position.x,r.y=this._position.y),r},toGlobal(r,t,e=!1){const i=this.getGlobalTransform(Pt.get(),e);return t=i.apply(r,t),Pt.return(i),t},toLocal(r,t,e,i){t&&(r=t.toGlobal(r,e,i));const s=this.getGlobalTransform(Pt.get(),i);return e=s.applyInverse(r,e),Pt.return(s),e}};class cr{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(t){this.instructions[this.instructionSize++]=t}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let Gd=0;class Wd{constructor(t){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=t||{},this.enableFullScreen=!1,this.textureStyle=new Ke(this.textureOptions)}createTexture(t,e,i){const s=new Bt({...this.textureOptions,width:t,height:e,resolution:1,antialias:i,autoGarbageCollect:!1});return new G({source:s,label:`texturePool_${Gd++}`})}getOptimalTexture(t,e,i=1,s){let n=Math.ceil(t*i-1e-6),o=Math.ceil(e*i-1e-6);n=qe(n),o=qe(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=t,h.frame.height=e,h.updateUvs(),this._poolKeyHash[h.uid]=a,h}getSameSizeTexture(t,e=!1){const i=t.source;return this.getOptimalTexture(t.width,t.height,i._resolution,e)}returnTexture(t,e=!1){const i=this._poolKeyHash[t.uid];e&&(t.source.style=this.textureStyle),this._texturePool[i].push(t)}clear(t){if(t=t!==!1,t)for(const e in this._texturePool){const i=this._texturePool[e];if(i)for(let s=0;s<i.length;s++)i[s].destroy(!0)}this._texturePool={}}}const Ps=new Wd;Oi.register(Ps);class Ud{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new W,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 cr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(t){this.root=t,t._onRender&&this.addOnRender(t),t.didChange=!0;const e=t.children;for(let i=0;i<e.length;i++){const s=e[i];s._updateFlags=15,this.addChild(s)}}enableCacheAsTexture(t={}){this.textureOptions=t,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Ps.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const t=this._parentCacheAsTextureRenderGroup;t&&!t.textureNeedsUpdate&&t.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const t in this.childrenToUpdate){const e=this.childrenToUpdate[t];e.list.fill(null),e.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(t){t.renderGroupParent&&t.renderGroupParent._removeRenderGroupChild(t),t.renderGroupParent=this,this.renderGroupChildren.push(t)}_removeRenderGroupChild(t){const e=this.renderGroupChildren.indexOf(t);e>-1&&this.renderGroupChildren.splice(e,1),t.renderGroupParent=null}addChild(t){if(this.structureDidChange=!0,t.parentRenderGroup=this,t.updateTick=-1,t.parent===this.root?t.relativeRenderGroupDepth=1:t.relativeRenderGroupDepth=t.parent.relativeRenderGroupDepth+1,t.didChange=!0,this.onChildUpdate(t),t.renderGroup){this.addRenderGroupChild(t.renderGroup);return}t._onRender&&this.addOnRender(t);const e=t.children;for(let i=0;i<e.length;i++)this.addChild(e[i])}removeChild(t){if(this.structureDidChange=!0,t._onRender&&(t.renderGroup||this.removeOnRender(t)),t.parentRenderGroup=null,t.renderGroup){this._removeRenderGroupChild(t.renderGroup);return}const e=t.children;for(let i=0;i<e.length;i++)this.removeChild(e[i])}removeChildren(t){for(let e=0;e<t.length;e++)this.removeChild(t[e])}onChildUpdate(t){let e=this.childrenToUpdate[t.relativeRenderGroupDepth];e||(e=this.childrenToUpdate[t.relativeRenderGroupDepth]={index:0,list:[]}),e.list[e.index++]=t}updateRenderable(t){t.globalDisplayStatus<7||(this.instructionSet.renderPipes[t.renderPipeId].updateRenderable(t),t.didViewUpdate=!1)}onChildViewUpdate(t){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=t}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(t){this._onRenderContainers.push(t)}removeOnRender(t){this._onRenderContainers.splice(this._onRenderContainers.indexOf(t),1)}runOnRender(t){for(let e=0;e<this._onRenderContainers.length;e++)this._onRenderContainers[e]._onRender(t)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet=null}getChildren(t=[]){const e=this.root.children;for(let i=0;i<e.length;i++)this._getChildren(e[i],t);return t}_getChildren(t,e=[]){if(e.push(t),t.renderGroup)return e;const i=t.children;for(let s=0;s<i.length;s++)this._getChildren(i[s],e);return e}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return this._matrixDirty&1?(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new W),this._inverseWorldTransform.copyFrom(this.worldTransform).invert()):this._inverseWorldTransform}get textureOffsetInverseTransform(){return this._matrixDirty&2?(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new W),this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y)):this._textureOffsetInverseTransform}get inverseParentTextureTransform(){if(!(this._matrixDirty&4))return this._inverseParentTextureTransform;this._matrixDirty&=-5;const t=this._parentCacheAsTextureRenderGroup;return t?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new W),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(t.inverseWorldTransform).translate(-t._textureBounds.x,-t._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function Hd(r,t,e={}){for(const i in t)!e[i]&&t[i]!==void 0&&(r[i]=t[i])}const Xs=new ct(null),qi=new ct(null),Zs=new ct(null,1,1),Ki=new ct(null),uo=1,Vd=2,qs=4;class L extends Yt{constructor(t={}){var e,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 W,this.relativeGroupTransform=new W,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new ct(this,0,0),this._scale=Zs,this._pivot=qi,this._origin=Ki,this._skew=Xs,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=[],Hd(this,t,{children:!0,parent:!0,effects:!0}),(e=t.children)==null||e.forEach(s=>this.addChild(s)),(i=t.parent)==null||i.addChild(this)}static mixin(t){V("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),$.mixin(L,t)}set _didChangeId(t){this._didViewChangeTick=t>>12&4095,this._didContainerChangeTick=t&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...t){if(this.allowChildren||V(J,"addChild: Only Containers will be allowed to add children in v8.0.0"),t.length>1){for(let s=0;s<t.length;s++)this.addChild(t[s]);return t[0]}const e=t[0],i=this.renderGroup||this.parentRenderGroup;return e.parent===this?(this.children.splice(this.children.indexOf(e),1),this.children.push(e),i&&(i.structureDidChange=!0),e):(e.parent&&e.parent.removeChild(e),this.children.push(e),this.sortableChildren&&(this.sortDirty=!0),e.parent=this,e.didChange=!0,e._updateFlags=15,i&&i.addChild(e),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this),this._didViewChangeTick++,e._zIndex!==0&&e.depthOfChildModified(),e)}removeChild(...t){if(t.length>1){for(let s=0;s<t.length;s++)this.removeChild(t[s]);return t[0]}const e=t[0],i=this.children.indexOf(e);return i>-1&&(this._didViewChangeTick++,this.children.splice(i,1),this.renderGroup?this.renderGroup.removeChild(e):this.parentRenderGroup&&this.parentRenderGroup.removeChild(e),e.parentRenderLayer&&e.parentRenderLayer.detach(e),e.parent=null,this.emit("childRemoved",e,this,i),e.emit("removed",this)),e}_onUpdate(t){t&&t===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(t){!!this.renderGroup!==t&&(t?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),this.renderGroup=_t.get(Ud,this),this.groupTransform=W.IDENTITY,t==null||t.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const t=this.parentRenderGroup;t==null||t.removeChild(this),_t.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,t==null||t.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||(this._worldTransform=new W),this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(t){this._position.x=t}get y(){return this._position.y}set y(t){this._position.y=t}get position(){return this._position}set position(t){this._position.copyFrom(t)}get rotation(){return this._rotation}set rotation(t){this._rotation!==t&&(this._rotation=t,this._onUpdate(this._skew))}get angle(){return this.rotation*sd}set angle(t){this.rotation=t*nd}get pivot(){return this._pivot===qi&&(this._pivot=new ct(this,0,0)),this._pivot}set pivot(t){this._pivot===qi&&(this._pivot=new ct(this,0,0),this._origin!==Ki&&nt("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._pivot.set(t):this._pivot.copyFrom(t)}get skew(){return this._skew===Xs&&(this._skew=new ct(this,0,0)),this._skew}set skew(t){this._skew===Xs&&(this._skew=new ct(this,0,0)),this._skew.copyFrom(t)}get scale(){return this._scale===Zs&&(this._scale=new ct(this,1,1)),this._scale}set scale(t){this._scale===Zs&&(this._scale=new ct(this,0,0)),typeof t=="string"&&(t=parseFloat(t)),typeof t=="number"?this._scale.set(t):this._scale.copyFrom(t)}get origin(){return this._origin===Ki&&(this._origin=new ct(this,0,0)),this._origin}set origin(t){this._origin===Ki&&(this._origin=new ct(this,0,0),this._pivot!==qi&&nt("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof t=="number"?this._origin.set(t):this._origin.copyFrom(t)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(t){const e=this.getLocalBounds().width;this._setWidth(t,e)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(t){const e=this.getLocalBounds().height;this._setHeight(t,e)}getSize(t){t||(t={});const e=this.getLocalBounds();return t.width=Math.abs(this.scale.x*e.width),t.height=Math.abs(this.scale.y*e.height),t}setSize(t,e){const i=this.getLocalBounds();typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,i.width),e!==void 0&&this._setHeight(e,i.height)}_updateSkew(){const t=this._rotation,e=this._skew;this._cx=Math.cos(t+e._y),this._sx=Math.sin(t+e._y),this._cy=-Math.sin(t-e._x),this._sy=Math.cos(t-e._x)}updateTransform(t){return this.position.set(typeof t.x=="number"?t.x:this.position.x,typeof t.y=="number"?t.y:this.position.y),this.scale.set(typeof t.scaleX=="number"?t.scaleX||1:this.scale.x,typeof t.scaleY=="number"?t.scaleY||1:this.scale.y),this.rotation=typeof t.rotation=="number"?t.rotation:this.rotation,this.skew.set(typeof t.skewX=="number"?t.skewX:this.skew.x,typeof t.skewY=="number"?t.skewY:this.skew.y),this.pivot.set(typeof t.pivotX=="number"?t.pivotX:this.pivot.x,typeof t.pivotY=="number"?t.pivotY:this.pivot.y),this.origin.set(typeof t.originX=="number"?t.originX:this.origin.x,typeof t.originY=="number"?t.originY:this.origin.y),this}setFromMatrix(t){t.decompose(this)}updateLocalTransform(){const t=this._didContainerChangeTick;if(this._didLocalTransformChangeId===t)return;this._didLocalTransformChangeId=t;const e=this.localTransform,i=this._scale,s=this._pivot,n=this._origin,o=this._position,a=i._x,h=i._y,l=s._x,c=s._y,d=-n._x,u=-n._y;e.a=this._cx*a,e.b=this._sx*a,e.c=this._cy*h,e.d=this._sy*h,e.tx=o._x-(l*e.a+c*e.c)+(d*e.a+u*e.c)-d,e.ty=o._y-(l*e.b+c*e.d)+(d*e.b+u*e.d)-u}set alpha(t){t!==this.localAlpha&&(this.localAlpha=t,this._updateFlags|=uo,this._onUpdate())}get alpha(){return this.localAlpha}set tint(t){const i=rt.shared.setValue(t??16777215).toBgrNumber();i!==this.localColor&&(this.localColor=i,this._updateFlags|=uo,this._onUpdate())}get tint(){return wi(this.localColor)}set blendMode(t){this.localBlendMode!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Vd,this.localBlendMode=t,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(t){const e=t?2:0;(this.localDisplayStatus&2)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=qs,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(t){const e=t?0:4;(this.localDisplayStatus&4)!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=qs,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(t){const e=t?1:0;(this.localDisplayStatus&1)!==e&&(this._updateFlags|=qs,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(t=!1){var s;if(this.destroyed)return;this.destroyed=!0;let e;if(this.children.length&&(e=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit("destroyed",this),this.removeAllListeners(),(typeof t=="boolean"?t:t==null?void 0:t.children)&&e)for(let n=0;n<e.length;++n)e[n].destroy(t);(s=this.renderGroup)==null||s.destroy(),this.renderGroup=null}}$.mixin(L,Pd,Ed,Od,Fd,Dd,Td,kd,zd,vd,Ad,Id,Md);class ii extends L{constructor(t){super(t),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this._bounds=new It(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=t.autoGarbageCollect??!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(t){this._roundPixels=t?1:0}containsPoint(t){const e=this.bounds,{x:i,y:s}=t;return i>=e.minX&&i<=e.maxX&&s>=e.minY&&s<=e.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const t=this.renderGroup||this.parentRenderGroup;t&&t.onChildViewUpdate(this)}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(t){this.unload(),super.destroy(t),this._bounds=null}collectRenderablesSimple(t,e,i){const{renderPipes:s}=e;s.blendMode.pushBlendMode(this,this.groupBlendMode,t);const o=s[this.renderPipeId];o!=null&&o.addRenderable&&o.addRenderable(this,t),this.didViewUpdate=!1;const a=this.children,h=a.length;for(let l=0;l<h;l++)a[l].collectRenderables(t,e,i);s.blendMode.popBlendMode(t)}}class jt extends ii{constructor(t=G.EMPTY){t instanceof G&&(t={texture:t});const{texture:e=G.EMPTY,anchor:i,roundPixels:s,width:n,height:o,...a}=t;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new ct({_onUpdate:()=>{this.onViewUpdate()}}),i?this.anchor=i:e.defaultAnchor&&(this.anchor=e.defaultAnchor),this.texture=e,this.allowChildren=!1,this.roundPixels=s??!1,n!==void 0&&(this.width=n),o!==void 0&&(this.height=o)}static from(t,e=!1){return t instanceof G?new jt(t):new jt(G.from(t,e))}set texture(t){t||(t=G.EMPTY);const e=this._texture;e!==t&&(e&&e.dynamic&&e.off("update",this.onViewUpdate,this),t.dynamic&&t.on("update",this.onViewUpdate,this),this._texture=t,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return lh(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return V("8.6.1","Sprite.sourceBounds is deprecated, use visualBounds instead."),this.visualBounds}updateBounds(){const t=this._anchor,e=this._texture,i=this._bounds,{width:s,height:n}=e.orig;i.minX=-t._x*s,i.maxX=i.minX+s,i.minY=-t._y*n,i.maxY=i.minY+n}destroy(t=!1){if(super.destroy(t),typeof t=="boolean"?t:t==null?void 0:t.texture){const i=typeof t=="boolean"?t:t==null?void 0:t.textureSource;this._texture.destroy(i)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this._setWidth(t,this._texture.orig.width),this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this._setHeight(t,this._texture.orig.height),this._height=t}getSize(t){return t||(t={}),t.width=Math.abs(this.scale.x)*this._texture.orig.width,t.height=Math.abs(this.scale.y)*this._texture.orig.height,t}setSize(t,e){typeof t=="object"?(e=t.height??t.width,t=t.width):e??(e=t),t!==void 0&&this._setWidth(t,this._texture.orig.width),e!==void 0&&this._setHeight(e,this._texture.orig.height)}}const Nd=new It;function xh(r,t,e){const i=Nd;r.measurable=!0,ph(r,e,i),t.addBoundsMask(i),r.measurable=!1}function Sh(r,t,e){const i=Qt.get();r.measurable=!0;const s=Pt.get().identity(),n=vh(r,e,s);gh(r,i,n),r.measurable=!1,t.addBoundsMask(i),Pt.return(s),Qt.return(i)}function vh(r,t,e){return r?(r!==t&&(vh(r.parent,t,e),r.updateLocalTransform(),e.append(r.localTransform)),e):(nt("Mask bounds, renderable is not inside the root container"),e)}class bh{constructor(t){this.priority=0,this.inverse=!1,this.pipe="alphaMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.renderMaskToTexture=!(t instanceof jt),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask=null)}addBounds(t,e){this.inverse||xh(this.mask,t,e)}addLocalBounds(t,e){Sh(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof jt}}bh.extension=E.MaskEffect;class wh{constructor(t){this.priority=0,this.pipe="colorMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t}destroy(){}static test(t){return typeof t=="number"}}wh.extension=E.MaskEffect;class Ah{constructor(t){this.priority=0,this.pipe="stencilMask",t!=null&&t.mask&&this.init(t.mask)}init(t){this.mask=t,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(t,e){xh(this.mask,t,e)}addLocalBounds(t,e){Sh(this.mask,t,e)}containsPoint(t,e){const i=this.mask;return e(i,t)}destroy(){this.reset()}static test(t){return t instanceof L}}Ah.extension=E.MaskEffect;const jd={createCanvas:(r,t)=>{const e=document.createElement("canvas");return e.width=r,e.height=t,e},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,t)=>fetch(r,t),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")};let po=jd;const j={get(){return po},set(r){po=r}};class dr extends Bt{constructor(t){t.resource||(t.resource=j.get().createCanvas()),t.width||(t.width=t.resource.width,t.autoDensity||(t.width/=t.resolution)),t.height||(t.height=t.resource.height,t.autoDensity||(t.height/=t.resolution)),super(t),this.uploadMethodId="image",this.autoDensity=t.autoDensity,this.resizeCanvas(),this.transparent=!!t.transparent}resizeCanvas(){this.autoDensity&&"style"in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(t=this.width,e=this.height,i=this._resolution){const s=super.resize(t,e,i);return s&&this.resizeCanvas(),s}static test(t){return globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&t instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}dr.extension=E.TextureSource;class Qe extends Bt{constructor(t){super(t),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(t){return globalThis.HTMLImageElement&&t instanceof HTMLImageElement||typeof ImageBitmap<"u"&&t instanceof ImageBitmap||globalThis.VideoFrame&&t instanceof VideoFrame}}Qe.extension=E.TextureSource;var Ee=(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))(Ee||{});class Ks{constructor(t,e=null,i=0,s=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=t,this._context=e,this.priority=i,this._once=s}match(t,e=null){return this._fn===t&&this._context===e}emit(t){this._fn&&(this._context?this._fn.call(this._context,t):this._fn(t));const e=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const Ch=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 Ks(null,null,1/0),this.deltaMS=1/Tt.targetFPMS,this.elapsedMS=1/Tt.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=Ee.NORMAL){return this._addListener(new Ks(t,e,i))}addOnce(t,e,i=Ee.NORMAL){return this._addListener(new Ks(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(!e)t.connect(i);else{for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i.match(t,e)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let e;if(t>this.lastTime){if(e=this.elapsedMS=t-this.lastTime,e>this._maxElapsedMS&&(e=this._maxElapsedMS),e*=this.speed,this._minElapsedMS){const n=t-this._lastFrame|0;if(n<this._minElapsedMS)return;this._lastFrame=t-n%this._minElapsedMS}this.deltaMS=e,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=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){const e=Math.min(this.maxFPS,t),i=Math.min(Math.max(0,e)/1e3,Tt.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(t===0)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!Tt._shared){const t=Tt._shared=new Tt;t.autoStart=!0,t._protected=!0}return Tt._shared}static get system(){if(!Tt._system){const t=Tt._system=new Tt;t.autoStart=!0,t._protected=!0}return Tt._system}};Ch.targetFPMS=.06;let yt=Ch,$s;async function Ph(){return $s??($s=(async()=>{var o;const t=j.get().createCanvas(1,1).getContext("webgl");if(!t)return"premultiply-alpha-on-upload";const e=await new Promise(a=>{const h=document.createElement("video");h.onloadeddata=()=>a(h),h.onerror=()=>a(null),h.autoplay=!1,h.crossOrigin="anonymous",h.preload="auto",h.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",h.load()});if(!e)return"premultiply-alpha-on-upload";const i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);const s=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,i,0),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.pixelStorei(t.UNPACK_COLORSPACE_CONVERSION_WEBGL,t.NONE),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e);const n=new Uint8Array(4);return t.readPixels(0,0,1,1,t.RGBA,t.UNSIGNED_BYTE,n),t.deleteFramebuffer(s),t.deleteTexture(i),(o=t.getExtension("WEBGL_lose_context"))==null||o.loseContext(),n[0]<=n[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),$s}const Ms=class Mh extends Bt{constructor(t){super(t),this.isReady=!1,this.uploadMethodId="video",t={...Mh.defaultOptions,...t},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=t.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=t.autoPlay!==!1,this.alphaMode=t.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),t.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const t=yt.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-t)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const t=this.resource,e=this.options;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(e.preload||t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlayThrough),t.addEventListener("error",this._onError,!0)),this.alphaMode=await Ph(),this._load=new Promise((i,s)=>{this.isValid?i(this):(this._resolve=i,this._reject=s,e.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${e.preloadTimeoutMs}ms`))})),t.load())}),this._load}_onError(t){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.resource;return!t.paused&&!t.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this.isValid||this._mediaReady(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlay),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const t=this.resource;this.isValid&&(this.isReady=!0,this.resize(t.videoWidth,t.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const t=this.resource;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlayThrough),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(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(t){return globalThis.HTMLVideoElement&&t instanceof HTMLVideoElement}};Ms.extension=E.TextureSource;Ms.defaultOptions={...Bt.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};Ms.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let Ai=Ms;const zt=(r,t,e=!1)=>(Array.isArray(r)||(r=[r]),t?r.map(i=>typeof i=="string"||e?t(i):i):r);class Yd{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(t){return this._cache.has(t)}get(t){const e=this._cache.get(t);return e||nt(`[Assets] Asset id ${t} was not found in the Cache`),e}set(t,e){const i=zt(t);let s;for(let h=0;h<this.parsers.length;h++){const l=this.parsers[h];if(l.test(e)){s=l.getCacheableAssets(i,e);break}}const n=new Map(Object.entries(s||{}));s||i.forEach(h=>{n.set(h,e)});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]:e;this._cache.has(h)&&this._cache.get(h)!==l&&nt("[Cache] already has key:",h),this._cache.set(h,n.get(h))})}remove(t){if(!this._cacheMap.has(t)){nt(`[Assets] Asset id ${t} was not found in the Cache`);return}const e=this._cacheMap.get(t);e.cacheKeys.forEach(s=>{this._cache.delete(s)}),e.keys.forEach(s=>{this._cacheMap.delete(s)})}get parsers(){return this._parsers}}const xt=new Yd,Dn=[];$.handleByList(E.TextureSource,Dn);function _h(r={}){const t=r&&r.resource,e=t?r.resource:r,i=t?r:{resource:r};for(let s=0;s<Dn.length;s++){const n=Dn[s];if(n.test(e))return new n(i)}throw new Error(`Could not find a source type for resource: ${i.resource}`)}function Xd(r={},t=!1){const e=r&&r.resource,i=e?r.resource:r,s=e?r:{resource:r};if(!t&&xt.has(i))return xt.get(i);const n=new G({source:_h(s)});return n.on("destroy",()=>{xt.has(i)&&xt.remove(i)}),t||xt.set(i,n),n}function Zd(r,t=!1){return typeof r=="string"?xt.get(r):r instanceof Bt?new G({source:r}):Xd(r,t)}G.from=Zd;Bt.from=_h;$.add(bh,wh,Ah,Ai,Qe,dr,ar);var ue=(r=>(r[r.Low=0]="Low",r[r.Normal=1]="Normal",r[r.High=2]="High",r))(ue||{});function Dt(r){if(typeof r!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(r)}`)}function oi(r){return r.split("?")[0].split("#")[0]}function qd(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Kd(r,t,e){return r.replace(new RegExp(qd(t),"g"),e)}function $d(r,t){let e="",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(e.length<2||i!==2||e.charCodeAt(e.length-1)!==46||e.charCodeAt(e.length-2)!==46){if(e.length>2){const h=e.lastIndexOf("/");if(h!==e.length-1){h===-1?(e="",i=0):(e=e.slice(0,h),i=e.length-1-e.lastIndexOf("/")),s=a,n=0;continue}}else if(e.length===2||e.length===1){e="",i=0,s=a,n=0;continue}}}else e.length>0?e+=`/${r.slice(s+1,a)}`:e=r.slice(s+1,a),i=a-s-1;s=a,n=0}else o===46&&n!==-1?++n:n=-1}return e}const Mt={toPosix(r){return Kd(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){Dt(r),r=this.toPosix(r);const t=/^file:\/\/\//.exec(r);if(t)return t[0];const e=/^[^/:]+:\/{0,2}/.exec(r);return e?e[0]:""},toAbsolute(r,t,e){if(Dt(r),this.isDataUrl(r)||this.isBlobUrl(r))return r;const i=oi(this.toPosix(t??j.get().getBaseUrl())),s=oi(this.toPosix(e??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(Dt(r),r.length===0)return".";if(this.isDataUrl(r)||this.isBlobUrl(r))return r;r=this.toPosix(r);let t="";const e=r.startsWith("/");this.hasProtocol(r)&&(t=this.rootname(r),r=r.slice(t.length));const i=r.endsWith("/");return r=$d(r),r.length>0&&i&&(r+="/"),e?`/${r}`:t+r},isAbsolute(r){return Dt(r),r=this.toPosix(r),this.hasProtocol(r)?!0:r.startsWith("/")},join(...r){if(r.length===0)return".";let t;for(let e=0;e<r.length;++e){const i=r[e];if(Dt(i),i.length>0)if(t===void 0)t=i;else{const s=r[e-1]??"";this.joinExtensions.includes(this.extname(s).toLowerCase())?t+=`/../${i}`:t+=`/${i}`}}return t===void 0?".":this.normalize(t)},dirname(r){if(Dt(r),r.length===0)return".";r=this.toPosix(r);let t=r.charCodeAt(0);const e=t===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(t=r.charCodeAt(a),t===47){if(!s){i=a;break}}else s=!1;return i===-1?e?"/":this.isUrl(o)?n+r:n:e&&i===1?"//":n+r.slice(0,i)},rootname(r){Dt(r),r=this.toPosix(r);let t="";if(r.startsWith("/")?t="/":t=this.getProtocol(r),this.isUrl(r)){const e=r.indexOf("/",t.length);e!==-1?t=r.slice(0,e):t=r,t.endsWith("/")||(t+="/")}return t},basename(r,t){Dt(r),t&&Dt(t),r=oi(this.toPosix(r));let e=0,i=-1,s=!0,n;if(t!==void 0&&t.length>0&&t.length<=r.length){if(t.length===r.length&&t===r)return"";let o=t.length-1,a=-1;for(n=r.length-1;n>=0;--n){const h=r.charCodeAt(n);if(h===47){if(!s){e=n+1;break}}else a===-1&&(s=!1,a=n+1),o>=0&&(h===t.charCodeAt(o)?--o===-1&&(i=n):(o=-1,i=a))}return e===i?i=a:i===-1&&(i=r.length),r.slice(e,i)}for(n=r.length-1;n>=0;--n)if(r.charCodeAt(n)===47){if(!s){e=n+1;break}}else i===-1&&(s=!1,i=n+1);return i===-1?"":r.slice(e,i)},extname(r){Dt(r),r=oi(this.toPosix(r));let t=-1,e=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){e=o+1;break}continue}i===-1&&(s=!1,i=o+1),a===46?t===-1?t=o:n!==1&&(n=1):t!==-1&&(n=-1)}return t===-1||i===-1||n===0||n===1&&t===i-1&&t===e+1?"":r.slice(t,i)},parse(r){Dt(r);const t={root:"",dir:"",base:"",ext:"",name:""};if(r.length===0)return t;r=oi(this.toPosix(r));let e=r.charCodeAt(0);const i=this.isAbsolute(r);let s;t.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(e=r.charCodeAt(l),e===47){if(!h){o=l+1;break}continue}a===-1&&(h=!1,a=l+1),e===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?t.base=t.name=r.slice(1,a):t.base=t.name=r.slice(o,a)):(o===0&&i?(t.name=r.slice(1,n),t.base=r.slice(1,a)):(t.name=r.slice(o,n),t.base=r.slice(o,a)),t.ext=r.slice(n,a)),t.dir=this.dirname(r),t},sep:"/",delimiter:":",joinExtensions:[".html"]};function Th(r,t,e,i,s){const n=t[e];for(let o=0;o<n.length;o++){const a=n[o];e<t.length-1?Th(r.replace(i[e],a),t,e+1,i,s):s.push(r.replace(i[e],a))}}function Qd(r){const t=/\{(.*?)\}/g,e=r.match(t),i=[];if(e){const s=[];e.forEach(n=>{const o=n.substring(1,n.length-1).split(",");s.push(o)}),Th(r,s,0,e,i)}else i.push(r);return i}const fs=r=>!Array.isArray(r);class si{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(t,e)=>`${t}${this._bundleIdConnector}${e}`,extractAssetIdFromBundle:(t,e)=>e.replace(`${t}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(t){if(this._bundleIdConnector=t.connector??this._bundleIdConnector,this._createBundleAssetId=t.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=t.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...t){t.forEach(e=>{this._preferredOrder.push(e),e.priority||(e.priority=Object.keys(e.params))}),this._resolverHash={}}set basePath(t){this._basePath=t}get basePath(){return this._basePath}set rootPath(t){this._rootPath=t}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(t){if(typeof t=="string")this._defaultSearchParams=t;else{const e=t;this._defaultSearchParams=Object.keys(e).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`).join("&")}}getAlias(t){const{alias:e,src:i}=t;return zt(e||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(t){this._manifest&&nt("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=t,t.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(t,e){const i=[];let s=e;Array.isArray(e)||(s=Object.entries(e).map(([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(t,a);i.push(l),h=[a,l]}else{const l=a.map(c=>this._createBundleAssetId(t,c));i.push(...l),h=[...a,...l]}this.add({...n,alias:h,src:o})}),this._bundles[t]=i}add(t){const e=[];Array.isArray(t)?e.push(...t):e.push(t);let i;i=n=>{this.hasKey(n)&&nt(`[Resolver] already has key: ${n} overwriting`)},zt(e).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"?Qd(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(t){const e=fs(t);t=zt(t);const i={};return t.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}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const s in e)i[s]=e[s].src;return i}return e.src}resolve(t){const e=fs(t);t=zt(t);const i={};return t.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]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[e],s=this._preferredOrder.find(n=>n.params.format.includes(i.format));if(s)return s}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}_buildResolvedAsset(t,e){const{aliases:i,data:s,loadParser:n,parser:o,format:a,progressSize:h}=e;return(this._basePath||this._rootPath)&&(t.src=Mt.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...s||{},...t.data},t.loadParser=n??t.loadParser,t.parser=o??t.parser,t.format=a??t.format??Jd(t.src),h!==void 0&&(t.progressSize=h),t}}si.RETINA_PREFIX=/@([0-9\.]+)x/;function Jd(r){return r.split(".").pop().split("?").shift().split("#").shift()}const Fn=(r,t)=>{const e=t.split("?")[1];return e&&(r+=`?${e}`),r},kh=class yi{constructor(t,e){this.linkedSheets=[];let i=t;(t==null?void 0:t.source)instanceof Bt&&(i={texture:t,data:e});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(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=yi.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(t,e=!1){let i=t;const s=e?1/0:yi.BATCH_SIZE;for(;i-t<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 t=this.data.animations||{};for(const e in t){this.animations[e]=[];for(let i=0;i<t[e].length;i++){const s=t[e][i];this.animations[e].push(this.textures[s])}}}_parseComplete(){const t=this._callback;this._callback=null,this._batchIndex=0,t.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*yi.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*yi.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(t=!1){var e;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,t&&((e=this._texture)==null||e.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};kh.BATCH_SIZE=1e3;let zn=kh;const tu=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function Rh(r,t,e){const i={};if(r.forEach(s=>{i[s]=t}),Object.keys(t.textures).forEach(s=>{i[`${t.cachePrefix}${s}`]=t.textures[s]}),!e){const s=Mt.dirname(r[0]);t.linkedSheets.forEach((n,o)=>{const a=Rh([`${s}/${t.data.meta.related_multi_packs[o]}`],n,!0);Object.assign(i,a)})}return i}const eu={extension:E.Asset,cache:{test:r=>r instanceof zn,getCacheableAssets:(r,t)=>Rh(r,t,!1)},resolver:{extension:{type:E.ResolveParser,name:"resolveSpritesheet"},test:r=>{const e=r.split("?")[0].split("."),i=e.pop(),s=e.pop();return i==="json"&&tu.includes(s)},parse:r=>{var e;const t=r.split(".");return{resolution:parseFloat(((e=si.RETINA_PREFIX.exec(r))==null?void 0:e[1])??"1"),format:t[t.length-2],src:r}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:E.LoadParser,priority:ue.Normal,name:"spritesheetLoader"},async testParse(r,t){return Mt.extname(t.src).toLowerCase()===".json"&&!!r.frames},async parse(r,t,e){var d,u;const{texture:i,imageFilename:s,textureOptions:n,cachePrefix:o}=(t==null?void 0:t.data)??{};let a=Mt.dirname(t.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let h;if(i instanceof G)h=i;else{const p=Fn(a+(s??r.meta.image),t.src);h=(await e.load([{src:p,data:n}]))[p]}const l=new zn({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=t.data)!=null&&u.ignoreMultiPack||(m=Fn(m,t.src),p.push(e.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,t,e){await e.unload(r.textureSource._sourceOrigin),r.destroy(!1)}}};$.add(eu);class iu{constructor(t){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const e=this._canvas.getBoundingClientRect(),i=this._canvas.width,s=this._canvas.height,n=e.width/i*this._renderer.resolution,o=e.height/s*this._renderer.resolution,a=e.left,h=e.top,l=`translate(${a}px, ${h}px) scale(${n}, ${o})`;l!==this._lastTransform&&(this._domElement.style.transform=l,this._lastTransform=l)},this._domElement=t.domElement,this._renderer=t.renderer,!(globalThis.OffscreenCanvas&&this._renderer.canvas instanceof OffscreenCanvas)&&(this._canvas=this._renderer.canvas,this._attachObserver())}get canvas(){return this._canvas}ensureAttached(){!this._domElement.parentNode&&this._canvas.parentNode&&(this._canvas.parentNode.appendChild(this._domElement),this.updateTranslation())}_attachObserver(){"ResizeObserver"in globalThis?(this._observer&&(this._observer.disconnect(),this._observer=null),this._observer=new ResizeObserver(t=>{for(const e of t){if(e.target!==this._canvas)continue;const i=this.canvas.width,s=this.canvas.height,n=e.contentRect.width/i*this._renderer.resolution,o=e.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,Ee.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 ur{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=ur.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=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,s,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 Qs=/iPhone/i,fo=/iPod/i,go=/iPad/i,mo=/\biOS-universal(?:.+)Mac\b/i,Js=/\bAndroid(?:.+)Mobile\b/i,yo=/Android/i,Fe=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,$i=/Silk/i,qt=/Windows Phone/i,xo=/\bWindows(?:.+)ARM\b/i,So=/BlackBerry/i,vo=/BB10/i,bo=/Opera Mini/i,wo=/\b(CriOS|Chrome)(?:.+)Mobile/i,Ao=/Mobile(?:.+)Firefox\b/i,Co=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function su(r){return function(t){return t.test(r)}}function Po(r){var t={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?t.userAgent=r:r&&r.userAgent&&(t={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var s=su(e),n={apple:{phone:s(Qs)&&!s(qt),ipod:s(fo),tablet:!s(Qs)&&(s(go)||Co(t))&&!s(qt),universal:s(mo),device:(s(Qs)||s(fo)||s(go)||s(mo)||Co(t))&&!s(qt)},amazon:{phone:s(Fe),tablet:!s(Fe)&&s($i),device:s(Fe)||s($i)},android:{phone:!s(qt)&&s(Fe)||!s(qt)&&s(Js),tablet:!s(qt)&&!s(Fe)&&!s(Js)&&(s($i)||s(yo)),device:!s(qt)&&(s(Fe)||s($i)||s(Js)||s(yo))||s(/\bokhttp\b/i)},windows:{phone:s(qt),tablet:s(xo),device:s(qt)||s(xo)},other:{blackberry:s(So),blackberry10:s(vo),opera:s(bo),firefox:s(Ao),chrome:s(wo),device:s(So)||s(vo)||s(bo)||s(Ao)||s(wo)},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 nu=Po.default??Po,Ln=nu(globalThis.navigator),tn=Object.create(null),Mo=Object.create(null);function pr(r,t){let e=Mo[r];return e===void 0&&(tn[t]===void 0&&(tn[t]=1),Mo[r]=e=tn[t]++),e}let ze;function Eh(){return(!ze||ze!=null&&ze.isContextLost())&&(ze=j.get().createCanvas().getContext("webgl",{})),ze}let Qi;function ru(){if(!Qi){Qi="mediump";const r=Eh();r&&r.getShaderPrecisionFormat&&(Qi=r.getShaderPrecisionFormat(r.FRAGMENT_SHADER,r.HIGH_FLOAT).precision?"highp":"mediump")}return Qi}function ou(r,t,e){return t?r:e?(r=r.replace("out vec4 finalColor;",""),`
|
|
@@ -20,7 +20,7 @@ Deprecated since v${r}`,n=typeof console.groupCollapsed=="function"&&!He.noColor
|
|
|
20
20
|
`}function au(r,t,e){const i=e?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(r.substring(0,9)!=="precision"){let s=e?t.requestedFragmentPrecision:t.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 hu(r,t){return t?`#version 300 es
|
|
22
22
|
${r}`:r}const lu={},cu={};function du(r,{name:t="pixi-program"},e=!0){t=t.replace(/\s+/g,"-"),t+=e?"-fragment":"-vertex";const i=e?lu:cu;return i[t]?(i[t]++,t+=`-${i[t]}`):i[t]=1,r.indexOf("#define SHADER_NAME")!==-1?r:`${`#define SHADER_NAME ${t}`}
|
|
23
|
-
${r}`}function uu(r,t){return t?r.replace("#version 300 es",""):r}const en={stripVersion:uu,ensurePrecision:au,addProgramDefines:ou,setProgramName:du,insertVersion:hu},ai=Object.create(null),Ih=class On{constructor(t){t={...On.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:ru()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let s=t.fragment,n=t.vertex;Object.keys(en).forEach(o=>{const a=i[o];s=en[o](s,a,!0),n=en[o](n,a,!1)}),this.fragment=s,this.vertex=n,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=pr(`${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,ai[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return ai[e]||(ai[e]=new On(t),ai[e]._cacheKey=e),ai[e]}};Ih.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let Je=Ih;const _o={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function pu(r){return _o[r]??_o.float32}const fu={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"},To=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function ko(r,t){let e;for(;(e=To.exec(r))!==null;){const i=fu[e[3]]??"float32";t[e[2]]={location:parseInt(e[1],10),format:i,stride:pu(i).stride,offset:0,instance:!1,start:0}}To.lastIndex=0}function gu(r){return r.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function mu({source:r,entryPoint:t}){const e={},i=gu(r),s=i.indexOf(`fn ${t}(`);if(s===-1)return e;const n=i.indexOf("->",s);if(n===-1)return e;const o=i.substring(s,n);if(ko(o,e),Object.keys(e).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const h=a[1],l=new RegExp(`struct\\s+${h}\\s*\\{([^}]+)\\}`,"s"),c=i.match(l);c&&ko(c[1],e)}}return e}function sn(r){var d,u;const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@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(t))==null?void 0:d.map(p=>({group:parseInt(p.match(e)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(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 Ce=(r=>(r[r.VERTEX=1]="VERTEX",r[r.FRAGMENT=2]="FRAGMENT",r[r.COMPUTE=4]="COMPUTE",r))(Ce||{});function yu({groups:r}){const t=[];for(let e=0;e<r.length;e++){const i=r[e];t[i.group]||(t[i.group]=[]),i.isUniform?t[i.group].push({binding:i.binding,visibility:Ce.VERTEX|Ce.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function xu({groups:r}){const t=[];for(let e=0;e<r.length;e++){const i=r[e];t[i.group]||(t[i.group]={}),t[i.group][i.name]=i.binding}return t}function Su(r,t){const e=new Set,i=new Set,s=[...r.structs,...t.structs].filter(o=>e.has(o.name)?!1:(e.add(o.name),!0)),n=[...r.groups,...t.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:n}}const hi=Object.create(null);class ce{constructor(t){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:i,layout:s,gpuLayout:n,name:o}=t;if(this.name=o,this.fragment=e,this.vertex=i,e.source===i.source){const l=sn(e.source);this.structsAndGroups=l}else{const l=sn(i.source),c=sn(e.source);this.structsAndGroups=Su(l,c)}this.layout=s??xu(this.structsAndGroups),this.gpuLayout=n??yu(this.structsAndGroups),this.autoAssignGlobalUniforms=((a=this.layout[0])==null?void 0:a.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((h=this.layout[1])==null?void 0:h.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,i=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=pr(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=mu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,hi[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return hi[e]||(hi[e]=new ce(t),hi[e]._cacheKey=e),hi[e]}}const Bh=["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>"],vu=Bh.reduce((r,t)=>(r[t]=!0,r),{});function bu(r,t){switch(r){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*t);case"vec3<f32>":return new Float32Array(3*t);case"vec4<f32>":return new Float32Array(4*t);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const Dh=class Fh{constructor(t,e){this._touched=0,this.uid=dt("uniform"),this._resourceType="uniformGroup",this._resourceId=dt("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...Fh.defaultOptions,...e},this.uniformStructures=t;const i={};for(const s in t){const n=t[s];if(n.name=s,n.size=n.size??1,!vu[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: ${Bh.join(", ")}`)}n.value??(n.value=bu(n.type,n.size)),i[s]=n.value}this.uniforms=i,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=pr(Object.keys(i).map(s=>`${s}-${t[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};Dh.defaultOptions={ubo:!1,isStatic:!1};let ti=Dh;class Ci{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const i in t){const s=t[i];this.setResource(s,e++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const t=[];let e=0;for(const i in this.resources)t[e++]=this.resources[i]._resourceId;this._key=t.join("|")}setResource(t,e){var s,n;const i=this.resources[e];t!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(n=t.on)==null||n.call(t,"change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t,e){const i=this.resources;for(const s in i)i[s]._gcLastUsed=t,i[s]._touched=e}destroy(){var e;const t=this.resources;for(const i in t){const s=t[i];(e=s==null?void 0:s.off)==null||e.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const i in e)e[i]===t&&(e[i]=null)}else this._updateKey()}}var Ri=(r=>(r[r.WEBGL=1]="WEBGL",r[r.WEBGPU=2]="WEBGPU",r[r.CANVAS=4]="CANVAS",r[r.BOTH=3]="BOTH",r))(Ri||{});class Ie extends Yt{constructor(t){super(),this.uid=dt("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:e,glProgram:i,groups:s,resources:n,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=Ri.WEBGPU),i&&(o|=Ri.WEBGL)),this.compatibleRenderers=o;const h={};if(!n&&!s&&(n={}),n&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&s&&a)for(const l in a)for(const c in a[l]){const d=a[l][c];h[d]={group:l,binding:c,name:d}}else if(e&&s&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,h[c.name]=c})}else if(n){s={},a={},e&&e.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let l=0;for(const c in n)h[c]||(s[99]||(s[99]=new Ci,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 ti(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new Ci,this._ownedBindGroups.push(s[p.group])),s[p.group].setResource(u,p.binding))}}this.groups=s,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(s,h)}addResource(t,e,i){var s,n;(s=this._uniformBindMap)[e]||(s[e]={}),(n=this._uniformBindMap[e])[i]||(n[i]=t),this.groups[e]||(this.groups[e]=new Ci,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const s in e){const n=e[s];Object.defineProperty(i,n.name,{get(){return t[n.group].getResource(n.binding)},set(o){t[n.group].setResource(o,n.binding)}})}return i}destroy(t=!1){var e,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(s=>{s.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null)}static from(t){const{gpu:e,gl:i,...s}=t;let n,o;return e&&(n=ce.from(e)),i&&(o=Je.from(i)),new Ie({gpuProgram:n,glProgram:o,...s})}}const wu={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},nn=0,rn=1,on=2,an=3,hn=4,ln=5,Gn=class zh{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<nn)}set blend(t){!!(this.data&1<<nn)!==t&&(this.data^=1<<nn)}get offsets(){return!!(this.data&1<<rn)}set offsets(t){!!(this.data&1<<rn)!==t&&(this.data^=1<<rn)}set cullMode(t){if(t==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=t==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<on)}set culling(t){!!(this.data&1<<on)!==t&&(this.data^=1<<on)}get depthTest(){return!!(this.data&1<<an)}set depthTest(t){!!(this.data&1<<an)!==t&&(this.data^=1<<an)}get depthMask(){return!!(this.data&1<<ln)}set depthMask(t){!!(this.data&1<<ln)!==t&&(this.data^=1<<ln)}get clockwiseFrontFace(){return!!(this.data&1<<hn)}set clockwiseFrontFace(t){!!(this.data&1<<hn)!==t&&(this.data^=1<<hn)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=wu[t]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const t=new zh;return t.depthTest=!1,t.blend=!0,t}};Gn.default2d=Gn.for2d();let Gi=Gn;const Lh=class Wn extends Ie{constructor(t){t={...Wn.defaultOptions,...t},super(t),this.enabled=!0,this._state=Gi.for2d(),this.blendMode=t.blendMode,this.padding=t.padding,typeof t.antialias=="boolean"?this.antialias=t.antialias?"on":"off":this.antialias=t.antialias,this.resolution=t.resolution,this.blendRequired=t.blendRequired,this.clipToViewport=t.clipToViewport,this.addResource("uTexture",0,1),t.blendRequired&&this.addResource("uBackTexture",0,3)}apply(t,e,i,s){t.applyFilter(this,e,i,s)}get blendMode(){return this._state.blendMode}set blendMode(t){this._state.blendMode=t}static from(t){const{gpu:e,gl:i,...s}=t;let n,o;return e&&(n=ce.from(e)),i&&(o=Je.from(i)),new Wn({gpuProgram:n,glProgram:o,...s})}};Lh.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Au=Lh;const Un=[];$.handleByNamedList(E.Environment,Un);async function Cu(r){if(!r)for(let t=0;t<Un.length;t++){const e=Un[t];if(e.value.test()){await e.value.load();return}}}let li;function Pu(){if(typeof li=="boolean")return li;try{li=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{li=!1}return li}function Ro(r,t,e=2){const i=t&&t.length,s=i?t[0]*e:r.length;let n=Oh(r,0,s,e,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=Ru(r,t,n,e)),r.length>80*e){a=r[0],h=r[1];let c=a,d=h;for(let u=e;u<s;u+=e){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 Ei(n,o,e,a,h,l,0),o}function Oh(r,t,e,i,s){let n;if(s===Uu(r,t,e,i)>0)for(let o=t;o<e;o+=i)n=Eo(o/i|0,r[o],r[o+1],n);else for(let o=e-i;o>=t;o-=i)n=Eo(o/i|0,r[o],r[o+1],n);return n&&ei(n,n.next)&&(Bi(n),n=n.next),n}function Be(r,t){if(!r)return r;t||(t=r);let e=r,i;do if(i=!1,!e.steiner&&(ei(e,e.next)||at(e.prev,e,e.next)===0)){if(Bi(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Ei(r,t,e,i,s,n,o){if(!r)return;!o&&n&&Fu(r,i,s,n);let a=r;for(;r.prev!==r.next;){const h=r.prev,l=r.next;if(n?_u(r,i,s,n):Mu(r)){t.push(h.i,r.i,l.i),Bi(r),r=l.next,a=l.next;continue}if(r=l,r===a){o?o===1?(r=Tu(Be(r),t),Ei(r,t,e,i,s,n,2)):o===2&&ku(r,t,e,i,s,n):Ei(Be(r),t,e,i,s,n,1);break}}}function Mu(r){const t=r.prev,e=r,i=r.next;if(at(t,e,i)>=0)return!1;const s=t.x,n=e.x,o=i.x,a=t.y,h=e.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!==t;){if(f.x>=c&&f.x<=u&&f.y>=d&&f.y<=p&&xi(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 _u(r,t,e,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=Hn(p,f,t,e,i),S=Hn(y,m,t,e,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&&xi(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&&xi(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&&xi(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&&xi(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 Tu(r,t){let e=r;do{const i=e.prev,s=e.next.next;!ei(i,s)&&Wh(i,e,e.next,s)&&Ii(i,s)&&Ii(s,i)&&(t.push(i.i,e.i,s.i),Bi(e),Bi(e.next),e=r=s),e=e.next}while(e!==r);return Be(e)}function ku(r,t,e,i,s,n){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Ou(o,a)){let h=Uh(o,a);o=Be(o,o.next),h=Be(h,h.next),Ei(o,t,e,i,s,n,0),Ei(h,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function Ru(r,t,e,i){const s=[];for(let n=0,o=t.length;n<o;n++){const a=t[n]*i,h=n<o-1?t[n+1]*i:r.length,l=Oh(r,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(Lu(l))}s.sort(Eu);for(let n=0;n<s.length;n++)e=Iu(s[n],e);return e}function Eu(r,t){let e=r.x-t.x;if(e===0&&(e=r.y-t.y,e===0)){const i=(r.next.y-r.y)/(r.next.x-r.x),s=(t.next.y-t.y)/(t.next.x-t.x);e=i-s}return e}function Iu(r,t){const e=Bu(r,t);if(!e)return t;const i=Uh(e,r);return Be(i,i.next),Be(e,e.next)}function Bu(r,t){let e=t;const i=r.x,s=r.y;let n=-1/0,o;if(ei(r,e))return e;do{if(ei(r,e.next))return e.next;if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){const d=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(d<=i&&d>n&&(n=d,o=e.x<e.next.x?e:e.next,d===i))return o}e=e.next}while(e!==t);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;e=o;do{if(i>=e.x&&e.x>=h&&i!==e.x&&Gh(s<l?i:n,s,h,l,s<l?n:i,s,e.x,e.y)){const d=Math.abs(s-e.y)/(i-e.x);Ii(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&Du(o,e)))&&(o=e,c=d)}e=e.next}while(e!==a);return o}function Du(r,t){return at(r.prev,r,t.prev)<0&&at(t.next,r,r.next)<0}function Fu(r,t,e,i){let s=r;do s.z===0&&(s.z=Hn(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,zu(s)}function zu(r){let t,e=1;do{let i=r,s;r=null;let n=null;for(t=0;i;){t++;let o=i,a=0;for(let l=0;l<e&&(a++,o=o.nextZ,!!o);l++);let h=e;for(;a>0||h>0&&o;)a!==0&&(h===0||!o||i.z<=o.z)?(s=i,i=i.nextZ,a--):(s=o,o=o.nextZ,h--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;i=o}n.nextZ=null,e*=2}while(t>1);return r}function Hn(r,t,e,i,s){return r=(r-e)*s|0,t=(t-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function Lu(r){let t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function Gh(r,t,e,i,s,n,o,a){return(s-o)*(t-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(s-o)*(i-a)}function xi(r,t,e,i,s,n,o,a){return!(r===o&&t===a)&&Gh(r,t,e,i,s,n,o,a)}function Ou(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!Gu(r,t)&&(Ii(r,t)&&Ii(t,r)&&Wu(r,t)&&(at(r.prev,r,t.prev)||at(r,t.prev,t))||ei(r,t)&&at(r.prev,r,r.next)>0&&at(t.prev,t,t.next)>0)}function at(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function ei(r,t){return r.x===t.x&&r.y===t.y}function Wh(r,t,e,i){const s=ts(at(r,t,e)),n=ts(at(r,t,i)),o=ts(at(e,i,r)),a=ts(at(e,i,t));return!!(s!==n&&o!==a||s===0&&Ji(r,e,t)||n===0&&Ji(r,i,t)||o===0&&Ji(e,r,i)||a===0&&Ji(e,t,i))}function Ji(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function ts(r){return r>0?1:r<0?-1:0}function Gu(r,t){let e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&Wh(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Ii(r,t){return at(r.prev,r,r.next)<0?at(r,t,r.next)>=0&&at(r,r.prev,t)>=0:at(r,t,r.prev)<0||at(r,r.next,t)<0}function Wu(r,t){let e=r,i=!1;const s=(r.x+t.x)/2,n=(r.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Uh(r,t){const e=Vn(r.i,r.x,r.y),i=Vn(t.i,t.x,t.y),s=r.next,n=t.prev;return r.next=t,t.prev=r,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function Eo(r,t,e,i){const s=Vn(r,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Bi(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 Vn(r,t,e){return{i:r,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Uu(r,t,e,i){let s=0;for(let n=t,o=e-i;n<e;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}const Hu=Ro.default||Ro;var Hh=(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))(Hh||{});class Vu{constructor(t){this.items=[],this._name=t}emit(t,e,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](t,e,i,s,n,o,a,h);return this}add(t){return t[this._name]&&(this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return e!==-1&&this.items.splice(e,1),this}contains(t){return this.items.indexOf(t)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const Nu=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Vh=class Nh extends Yt{constructor(t){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=t.type,this.name=t.name,this.config=t;const e=[...Nu,...this.config.runners??[]];this._addRunners(...e),this._unsafeEvalCheck()}async init(t={}){const e=t.skipExtensionImports===!0?!0:t.manageImports===!1;await Cu(e),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)t={...this._systemsHash[i].constructor.defaultOptions,...t};t={...Nh.defaultOptions,...t},this._roundPixels=t.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(t);this._initOptions=t}render(t,e){this.tick++;let i=t;if(i instanceof L&&(i={container:i},e&&(V(J,"passing a second argument is deprecated, please use render options instead"),i.target=e.renderTexture)),i.target||(i.target=this.view.renderTarget),i.target===this.view.renderTarget&&(this._lastObjectRendered=i.container,i.clearColor??(i.clearColor=this.background.colorRgba),i.clear??(i.clear=this.background.clearBeforeRender)),i.clearColor){const s=Array.isArray(i.clearColor)&&i.clearColor.length===4;i.clearColor=s?i.clearColor: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(t,e,i){const s=this.view.resolution;this.view.resize(t,e,i),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),i!==void 0&&i!==s&&this.runners.resolutionChange.emit(i)}clear(t={}){const e=this;t.target||(t.target=e.renderTarget.renderTarget),t.clearColor||(t.clearColor=this.background.colorRgba),t.clear??(t.clear=Hh.ALL);const{clear:i,clearColor:s,target:n,mipLevel:o,layer:a}=t;rt.shared.setValue(s??this.background.colorRgba),e.renderTarget.clear(n,i,rt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(t){this.view.resolution=t,this.runners.resolutionChange.emit(t)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...t){t.forEach(e=>{this.runners[e]=new Vu(e)})}_addSystems(t){let e;for(e in t){const i=t[e];this._addSystem(i.value,i.name)}}_addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(t,e){const i=e.reduce((s,n)=>(s[n.name]=n.value,s),{});t.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(t=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(t),(t===!0||typeof t=="object"&&t.releaseGlobalResources)&&Oi.release(),Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(t){return this.textureGenerator.generateTexture(t)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Pu())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()}};Vh.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let jh=Vh,es;function ju(r){return es!==void 0||(es=(()=>{var e;const t={stencil:!0,failIfMajorPerformanceCaveat:r??jh.defaultOptions.failIfMajorPerformanceCaveat};try{if(!j.get().getWebGLRenderingContext())return!1;let s=j.get().createCanvas().getContext("webgl",t);const n=!!((e=s==null?void 0:s.getContextAttributes())!=null&&e.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,n}catch{return!1}})()),es}let is;async function Yu(r={}){return is!==void 0||(is=await(async()=>{const t=j.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(r)).requestDevice(),!0}catch{return!1}})()),is}const Io=["webgl","webgpu","canvas"];async function Xu(r){let t=[];r.preference?(t.push(r.preference),Io.forEach(n=>{n!==r.preference&&t.push(n)})):t=Io.slice();let e,i={};for(let n=0;n<t.length;n++){const o=t[n];if(o==="webgpu"&&await Yu()){const{WebGPURenderer:a}=await _e(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.DuRPdsh5.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));e=a,i={...r,...r.webgpu};break}else if(o==="webgl"&&ju(r.failIfMajorPerformanceCaveat??jh.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await _e(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.C_pauwH4.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));e=a,i={...r,...r.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await _e(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.DyglCOE2.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));e=a,i={...r,...r.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!e)throw new Error("No available renderer for the current environment");const s=new e;return await s.init(i),s}const Yh="8.16.0";class Xh{static init(){var t;(t=globalThis.__PIXI_APP_INIT__)==null||t.call(globalThis,this,Yh)}static destroy(){}}Xh.extension=E.Application;class Zu{constructor(t){this._renderer=t}init(){var t;(t=globalThis.__PIXI_RENDERER_INIT__)==null||t.call(globalThis,this._renderer,Yh)}destroy(){this._renderer=null}}Zu.extension={type:[E.WebGLSystem,E.WebGPUSystem],name:"initHook",priority:-10};class Zh{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:n}=this._resizeTo;e=s,i=n}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Zh.extension=E.Application;class qh{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Ee.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?yt.shared:new yt,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}qh.extension=E.Application;$.add(Zh);$.add(qh);const Kh=class Nn{constructor(...t){this.stage=new L,t[0]!==void 0&&V(J,"Application constructor options are deprecated, please use Application.init() instead.")}async init(t){t={...t},this.stage||(this.stage=new L),this.renderer=await Xu(t),Nn._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(J,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(t=!1,e=!1){const i=Nn._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};Kh._plugins=[];let $h=Kh;$.handleByList(E.Application,$h._plugins);$.add(Xh);const cn={test(r){return typeof r=="string"&&r.startsWith("info face=")},parse(r){const t=r.match(/^[a-z]+\s+.+$/gm),e={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in t){const u=t[d].match(/^[a-z]+/gm)[0],p=t[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),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}e[u].push(f)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=e.info,[n]=e.common,[o]=e.distanceField??[];o&&(i.distanceField={range:parseInt(o.distanceRange,10),type:o.fieldType}),i.fontSize=parseInt(s.size,10),i.fontFamily=s.face,i.lineHeight=parseInt(n.lineHeight,10);const a=e.page;for(let d=0;d<a.length;d++)i.pages.push({id:parseInt(a[d].id,10)||0,file:a[d].file});const h={};i.baseLineOffset=i.lineHeight-parseInt(n.base,10);const l=e.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=e.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}},Bo={test(r){const t=r;return typeof t!="string"&&"getElementsByTagName"in t&&t.getElementsByTagName("page").length&&t.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(r){const t={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},e=r.getElementsByTagName("info")[0],i=r.getElementsByTagName("common")[0],s=r.getElementsByTagName("distanceField")[0];s&&(t.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const n=r.getElementsByTagName("page"),o=r.getElementsByTagName("char"),a=r.getElementsByTagName("kerning");t.fontSize=parseInt(e.getAttribute("size"),10),t.fontFamily=e.getAttribute("face"),t.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<n.length;l++)t.pages.push({id:parseInt(n[l].getAttribute("id"),10)||0,file:n[l].getAttribute("file")});const h={};t.baseLineOffset=t.lineHeight-parseInt(i.getAttribute("base"),10);for(let l=0;l<o.length;l++){const c=o[l],d=parseInt(c.getAttribute("id"),10);let u=c.getAttribute("letter")??c.getAttribute("char")??String.fromCharCode(d);u==="space"&&(u=" "),h[d]=u,t.chars[u]={id:d,page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xOffset:parseInt(c.getAttribute("xoffset"),10),yOffset:parseInt(c.getAttribute("yoffset"),10),xAdvance:parseInt(c.getAttribute("xadvance"),10),kerning:{}}}for(let l=0;l<a.length;l++){const c=parseInt(a[l].getAttribute("first"),10),d=parseInt(a[l].getAttribute("second"),10),u=parseInt(a[l].getAttribute("amount"),10);t.chars[h[d]].kerning[h[c]]=u}return t}},Do={test(r){return typeof r=="string"&&r.match(/<font(\s|>)/)?Bo.test(j.get().parseXML(r)):!1},parse(r){return Bo.parse(j.get().parseXML(r))}},qu=[".xml",".fnt"],Ku={extension:{type:E.CacheParser,name:"cacheBitmapFont"},test:r=>!!(r!=null&&r.pages)&&!!(r!=null&&r.chars)&&typeof(r==null?void 0:r.fontFamily)=="string",getCacheableAssets(r,t){const e={};return r.forEach(i=>{e[i]=t,e[`${i}-bitmap`]=t}),e[`${t.fontFamily}-bitmap`]=t,e}},$u={extension:{type:E.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(r){return qu.includes(Mt.extname(r).toLowerCase())},async testParse(r){return cn.test(r)||Do.test(r)},async parse(r,t,e){const i=cn.test(r)?cn.parse(r):Do.parse(r),{src:s}=t,{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=Fn(f,s),o.push({src:f,data:a})}const[h,{BitmapFont:l}]=await Promise.all([e.load(o),_e(()=>import("./BitmapFont.C8awBCd1.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,t){return await(await j.get().fetch(r)).text()},async unload(r,t,e){await Promise.all(r.pages.map(i=>e.unload(i.texture.source._sourceOrigin))),r.destroy()}};class Qu{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}const Ju={extension:{type:E.CacheParser,name:"cacheTextureArray"},test:r=>Array.isArray(r)&&r.every(t=>t instanceof G),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((s,n)=>{e[i+(n===0?"":n+1)]=s})}),e}};async function Qh(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const tp={extension:{type:E.DetectionParser,priority:1},test:async()=>Qh("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")},Fo=["png","jpg","jpeg"],ep={extension:{type:E.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Fo],remove:async r=>r.filter(t=>!Fo.includes(t))},ip="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function _s(r){return ip?!1:document.createElement("video").canPlayType(r)!==""}const sp={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")},np={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")},rp={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")},op={extension:{type:E.DetectionParser,priority:0},test:async()=>Qh("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")},Jh=class as{constructor(){this.loadOptions={...as.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,n=null;if((e.parser||e.loadParser)&&(n=this._parserHash[e.parser||e.loadParser],e.loadParser&&nt(`[Assets] "loadParser" is deprecated, use "parser" instead for ${t}`),n||nt(`[Assets] specified load parser "${e.parser||e.loadParser}" not found while loading ${t}`)),!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,t,e,this))){n=l;break}}if(!n)return nt(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await n.load(t,e,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,e,this))&&(s=await l.parse(s,e,this)||s,i.parser=l)}return s})(),i}async load(t,e){this._parsersValidated||this._validateParsers();const i=typeof e=="function"?{...as.defaultOptions,...this.loadOptions,onProgress:e}:{...as.defaultOptions,...this.loadOptions,...e||{}},{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=fs(t),u=zt(t,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(t){const i=zt(t,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(t=>t.name||t.id).reduce((t,e)=>(!e.name&&!e.id?nt("[Assets] parser should have an id"):(t[e.name]||t[e.id])&&nt(`[Assets] parser id conflict "${e.id}"`),t[e.name]=e,e.id&&(t[e.id]=e),t),{})}async _loadAssetWithRetry(t,e,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[t]||(this.promiseCache[t]=this._getLoadPromiseAndParser(t,e)),s[e.src]=await this.promiseCache[t].promise;return}catch(d){delete this.promiseCache[t],delete s[e.src],n++;const u=a!=="retry"||n>h;if(a==="retry"&&!u){o&&o(d,e),await c(l);continue}if(a==="skip"){o&&o(d,e);return}o&&o(d,e);const p=new Error(`[Loader.load] Failed to load ${t}.
|
|
23
|
+
${r}`}function uu(r,t){return t?r.replace("#version 300 es",""):r}const en={stripVersion:uu,ensurePrecision:au,addProgramDefines:ou,setProgramName:du,insertVersion:hu},ai=Object.create(null),Ih=class On{constructor(t){t={...On.defaultOptions,...t};const e=t.fragment.indexOf("#version 300 es")!==-1,i={stripVersion:e,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:ru()},setProgramName:{name:t.name},addProgramDefines:e,insertVersion:e};let s=t.fragment,n=t.vertex;Object.keys(en).forEach(o=>{const a=i[o];s=en[o](s,a,!0),n=en[o](n,a,!1)}),this.fragment=s,this.vertex=n,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=pr(`${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,ai[this._cacheKey]=null}static from(t){const e=`${t.vertex}:${t.fragment}`;return ai[e]||(ai[e]=new On(t),ai[e]._cacheKey=e),ai[e]}};Ih.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let Je=Ih;const _o={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function pu(r){return _o[r]??_o.float32}const fu={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"},To=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function ko(r,t){let e;for(;(e=To.exec(r))!==null;){const i=fu[e[3]]??"float32";t[e[2]]={location:parseInt(e[1],10),format:i,stride:pu(i).stride,offset:0,instance:!1,start:0}}To.lastIndex=0}function gu(r){return r.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function mu({source:r,entryPoint:t}){const e={},i=gu(r),s=i.indexOf(`fn ${t}(`);if(s===-1)return e;const n=i.indexOf("->",s);if(n===-1)return e;const o=i.substring(s,n);if(ko(o,e),Object.keys(e).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const h=a[1],l=new RegExp(`struct\\s+${h}\\s*\\{([^}]+)\\}`,"s"),c=i.match(l);c&&ko(c[1],e)}}return e}function sn(r){var d,u;const t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,e=/@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(t))==null?void 0:d.map(p=>({group:parseInt(p.match(e)[1],10),binding:parseInt(p.match(i)[1],10),name:p.match(s)[2],isUniform:p.match(s)[1]==="<uniform>",type:p.match(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 Ce=(r=>(r[r.VERTEX=1]="VERTEX",r[r.FRAGMENT=2]="FRAGMENT",r[r.COMPUTE=4]="COMPUTE",r))(Ce||{});function yu({groups:r}){const t=[];for(let e=0;e<r.length;e++){const i=r[e];t[i.group]||(t[i.group]=[]),i.isUniform?t[i.group].push({binding:i.binding,visibility:Ce.VERTEX|Ce.FRAGMENT,buffer:{type:"uniform"}}):i.type==="sampler"?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,sampler:{type:"filtering"}}):i.type==="texture_2d"||i.type.startsWith("texture_2d<")?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}}):i.type==="texture_2d_array"||i.type.startsWith("texture_2d_array<")?t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d-array",multisampled:!1}}):(i.type==="texture_cube"||i.type.startsWith("texture_cube<"))&&t[i.group].push({binding:i.binding,visibility:Ce.FRAGMENT,texture:{sampleType:"float",viewDimension:"cube",multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function xu({groups:r}){const t=[];for(let e=0;e<r.length;e++){const i=r[e];t[i.group]||(t[i.group]={}),t[i.group][i.name]=i.binding}return t}function Su(r,t){const e=new Set,i=new Set,s=[...r.structs,...t.structs].filter(o=>e.has(o.name)?!1:(e.add(o.name),!0)),n=[...r.groups,...t.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return i.has(a)?!1:(i.add(a),!0)});return{structs:s,groups:n}}const hi=Object.create(null);class ce{constructor(t){var a,h;this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:e,vertex:i,layout:s,gpuLayout:n,name:o}=t;if(this.name=o,this.fragment=e,this.vertex=i,e.source===i.source){const l=sn(e.source);this.structsAndGroups=l}else{const l=sn(i.source),c=sn(e.source);this.structsAndGroups=Su(l,c)}this.layout=s??xu(this.structsAndGroups),this.gpuLayout=n??yu(this.structsAndGroups),this.autoAssignGlobalUniforms=((a=this.layout[0])==null?void 0:a.globalUniforms)!==void 0,this.autoAssignLocalUniforms=((h=this.layout[1])==null?void 0:h.localUniforms)!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:t,fragment:e}=this,i=t.source+e.source+t.entryPoint+e.entryPoint;this._layoutKey=pr(i,"program")}get attributeData(){return this._attributeData??(this._attributeData=mu(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,hi[this._cacheKey]=null}static from(t){const e=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return hi[e]||(hi[e]=new ce(t),hi[e]._cacheKey=e),hi[e]}}const Bh=["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>"],vu=Bh.reduce((r,t)=>(r[t]=!0,r),{});function bu(r,t){switch(r){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*t);case"vec3<f32>":return new Float32Array(3*t);case"vec4<f32>":return new Float32Array(4*t);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const Dh=class Fh{constructor(t,e){this._touched=0,this.uid=dt("uniform"),this._resourceType="uniformGroup",this._resourceId=dt("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,e={...Fh.defaultOptions,...e},this.uniformStructures=t;const i={};for(const s in t){const n=t[s];if(n.name=s,n.size=n.size??1,!vu[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: ${Bh.join(", ")}`)}n.value??(n.value=bu(n.type,n.size)),i[s]=n.value}this.uniforms=i,this._dirtyId=1,this.ubo=e.ubo,this.isStatic=e.isStatic,this._signature=pr(Object.keys(i).map(s=>`${s}-${t[s].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};Dh.defaultOptions={ubo:!1,isStatic:!1};let ti=Dh;class Ci{constructor(t){this.resources=Object.create(null),this._dirty=!0;let e=0;for(const i in t){const s=t[i];this.setResource(s,e++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const t=[];let e=0;for(const i in this.resources)t[e++]=this.resources[i]._resourceId;this._key=t.join("|")}setResource(t,e){var s,n;const i=this.resources[e];t!==i&&(i&&((s=i.off)==null||s.call(i,"change",this.onResourceChange,this)),(n=t.on)==null||n.call(t,"change",this.onResourceChange,this),this.resources[e]=t,this._dirty=!0)}getResource(t){return this.resources[t]}_touch(t,e){const i=this.resources;for(const s in i)i[s]._gcLastUsed=t,i[s]._touched=e}destroy(){var e;const t=this.resources;for(const i in t){const s=t[i];(e=s==null?void 0:s.off)==null||e.call(s,"change",this.onResourceChange,this)}this.resources=null}onResourceChange(t){if(this._dirty=!0,t.destroyed){const e=this.resources;for(const i in e)e[i]===t&&(e[i]=null)}else this._updateKey()}}var Ri=(r=>(r[r.WEBGL=1]="WEBGL",r[r.WEBGPU=2]="WEBGPU",r[r.CANVAS=4]="CANVAS",r[r.BOTH=3]="BOTH",r))(Ri||{});class Ie extends Yt{constructor(t){super(),this.uid=dt("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:e,glProgram:i,groups:s,resources:n,compatibleRenderers:o,groupMap:a}=t;this.gpuProgram=e,this.glProgram=i,o===void 0&&(o=0,e&&(o|=Ri.WEBGPU),i&&(o|=Ri.WEBGL)),this.compatibleRenderers=o;const h={};if(!n&&!s&&(n={}),n&&s)throw new Error("[Shader] Cannot have both resources and groups");if(!e&&s&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!e&&s&&a)for(const l in a)for(const c in a[l]){const d=a[l][c];h[d]={group:l,binding:c,name:d}}else if(e&&s&&!a){const l=e.structsAndGroups.groups;a={},l.forEach(c=>{a[c.group]=a[c.group]||{},a[c.group][c.binding]=c.name,h[c.name]=c})}else if(n){s={},a={},e&&e.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let l=0;for(const c in n)h[c]||(s[99]||(s[99]=new Ci,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 ti(u));const p=h[d];p&&(s[p.group]||(s[p.group]=new Ci,this._ownedBindGroups.push(s[p.group])),s[p.group].setResource(u,p.binding))}}this.groups=s,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(s,h)}addResource(t,e,i){var s,n;(s=this._uniformBindMap)[e]||(s[e]={}),(n=this._uniformBindMap[e])[i]||(n[i]=t),this.groups[e]||(this.groups[e]=new Ci,this._ownedBindGroups.push(this.groups[e]))}_buildResourceAccessor(t,e){const i={};for(const s in e){const n=e[s];Object.defineProperty(i,n.name,{get(){return t[n.group].getResource(n.binding)},set(o){t[n.group].setResource(o,n.binding)}})}return i}destroy(t=!1){var e,i;this._destroyed||(this._destroyed=!0,this.emit("destroy",this),t&&((e=this.gpuProgram)==null||e.destroy(),(i=this.glProgram)==null||i.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(s=>{s.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null)}static from(t){const{gpu:e,gl:i,...s}=t;let n,o;return e&&(n=ce.from(e)),i&&(o=Je.from(i)),new Ie({gpuProgram:n,glProgram:o,...s})}}const wu={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},nn=0,rn=1,on=2,an=3,hn=4,ln=5,Gn=class zh{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<nn)}set blend(t){!!(this.data&1<<nn)!==t&&(this.data^=1<<nn)}get offsets(){return!!(this.data&1<<rn)}set offsets(t){!!(this.data&1<<rn)!==t&&(this.data^=1<<rn)}set cullMode(t){if(t==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=t==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<on)}set culling(t){!!(this.data&1<<on)!==t&&(this.data^=1<<on)}get depthTest(){return!!(this.data&1<<an)}set depthTest(t){!!(this.data&1<<an)!==t&&(this.data^=1<<an)}get depthMask(){return!!(this.data&1<<ln)}set depthMask(t){!!(this.data&1<<ln)!==t&&(this.data^=1<<ln)}get clockwiseFrontFace(){return!!(this.data&1<<hn)}set clockwiseFrontFace(t){!!(this.data&1<<hn)!==t&&(this.data^=1<<hn)}get blendMode(){return this._blendMode}set blendMode(t){this.blend=t!=="none",this._blendMode=t,this._blendModeId=wu[t]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(t){this.offsets=!!t,this._polygonOffset=t}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const t=new zh;return t.depthTest=!1,t.blend=!0,t}};Gn.default2d=Gn.for2d();let Gi=Gn;const Lh=class Wn extends Ie{constructor(t){t={...Wn.defaultOptions,...t},super(t),this.enabled=!0,this._state=Gi.for2d(),this.blendMode=t.blendMode,this.padding=t.padding,typeof t.antialias=="boolean"?this.antialias=t.antialias?"on":"off":this.antialias=t.antialias,this.resolution=t.resolution,this.blendRequired=t.blendRequired,this.clipToViewport=t.clipToViewport,this.addResource("uTexture",0,1),t.blendRequired&&this.addResource("uBackTexture",0,3)}apply(t,e,i,s){t.applyFilter(this,e,i,s)}get blendMode(){return this._state.blendMode}set blendMode(t){this._state.blendMode=t}static from(t){const{gpu:e,gl:i,...s}=t;let n,o;return e&&(n=ce.from(e)),i&&(o=Je.from(i)),new Wn({gpuProgram:n,glProgram:o,...s})}};Lh.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Au=Lh;const Un=[];$.handleByNamedList(E.Environment,Un);async function Cu(r){if(!r)for(let t=0;t<Un.length;t++){const e=Un[t];if(e.value.test()){await e.value.load();return}}}let li;function Pu(){if(typeof li=="boolean")return li;try{li=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{li=!1}return li}function Ro(r,t,e=2){const i=t&&t.length,s=i?t[0]*e:r.length;let n=Oh(r,0,s,e,!0);const o=[];if(!n||n.next===n.prev)return o;let a,h,l;if(i&&(n=Ru(r,t,n,e)),r.length>80*e){a=r[0],h=r[1];let c=a,d=h;for(let u=e;u<s;u+=e){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 Ei(n,o,e,a,h,l,0),o}function Oh(r,t,e,i,s){let n;if(s===Uu(r,t,e,i)>0)for(let o=t;o<e;o+=i)n=Eo(o/i|0,r[o],r[o+1],n);else for(let o=e-i;o>=t;o-=i)n=Eo(o/i|0,r[o],r[o+1],n);return n&&ei(n,n.next)&&(Bi(n),n=n.next),n}function Be(r,t){if(!r)return r;t||(t=r);let e=r,i;do if(i=!1,!e.steiner&&(ei(e,e.next)||at(e.prev,e,e.next)===0)){if(Bi(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Ei(r,t,e,i,s,n,o){if(!r)return;!o&&n&&Fu(r,i,s,n);let a=r;for(;r.prev!==r.next;){const h=r.prev,l=r.next;if(n?_u(r,i,s,n):Mu(r)){t.push(h.i,r.i,l.i),Bi(r),r=l.next,a=l.next;continue}if(r=l,r===a){o?o===1?(r=Tu(Be(r),t),Ei(r,t,e,i,s,n,2)):o===2&&ku(r,t,e,i,s,n):Ei(Be(r),t,e,i,s,n,1);break}}}function Mu(r){const t=r.prev,e=r,i=r.next;if(at(t,e,i)>=0)return!1;const s=t.x,n=e.x,o=i.x,a=t.y,h=e.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!==t;){if(f.x>=c&&f.x<=u&&f.y>=d&&f.y<=p&&xi(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 _u(r,t,e,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=Hn(p,f,t,e,i),S=Hn(y,m,t,e,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&&xi(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&&xi(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&&xi(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&&xi(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 Tu(r,t){let e=r;do{const i=e.prev,s=e.next.next;!ei(i,s)&&Wh(i,e,e.next,s)&&Ii(i,s)&&Ii(s,i)&&(t.push(i.i,e.i,s.i),Bi(e),Bi(e.next),e=r=s),e=e.next}while(e!==r);return Be(e)}function ku(r,t,e,i,s,n){let o=r;do{let a=o.next.next;for(;a!==o.prev;){if(o.i!==a.i&&Ou(o,a)){let h=Uh(o,a);o=Be(o,o.next),h=Be(h,h.next),Ei(o,t,e,i,s,n,0),Ei(h,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function Ru(r,t,e,i){const s=[];for(let n=0,o=t.length;n<o;n++){const a=t[n]*i,h=n<o-1?t[n+1]*i:r.length,l=Oh(r,a,h,i,!1);l===l.next&&(l.steiner=!0),s.push(Lu(l))}s.sort(Eu);for(let n=0;n<s.length;n++)e=Iu(s[n],e);return e}function Eu(r,t){let e=r.x-t.x;if(e===0&&(e=r.y-t.y,e===0)){const i=(r.next.y-r.y)/(r.next.x-r.x),s=(t.next.y-t.y)/(t.next.x-t.x);e=i-s}return e}function Iu(r,t){const e=Bu(r,t);if(!e)return t;const i=Uh(e,r);return Be(i,i.next),Be(e,e.next)}function Bu(r,t){let e=t;const i=r.x,s=r.y;let n=-1/0,o;if(ei(r,e))return e;do{if(ei(r,e.next))return e.next;if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){const d=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(d<=i&&d>n&&(n=d,o=e.x<e.next.x?e:e.next,d===i))return o}e=e.next}while(e!==t);if(!o)return null;const a=o,h=o.x,l=o.y;let c=1/0;e=o;do{if(i>=e.x&&e.x>=h&&i!==e.x&&Gh(s<l?i:n,s,h,l,s<l?n:i,s,e.x,e.y)){const d=Math.abs(s-e.y)/(i-e.x);Ii(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&Du(o,e)))&&(o=e,c=d)}e=e.next}while(e!==a);return o}function Du(r,t){return at(r.prev,r,t.prev)<0&&at(t.next,r,r.next)<0}function Fu(r,t,e,i){let s=r;do s.z===0&&(s.z=Hn(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,zu(s)}function zu(r){let t,e=1;do{let i=r,s;r=null;let n=null;for(t=0;i;){t++;let o=i,a=0;for(let l=0;l<e&&(a++,o=o.nextZ,!!o);l++);let h=e;for(;a>0||h>0&&o;)a!==0&&(h===0||!o||i.z<=o.z)?(s=i,i=i.nextZ,a--):(s=o,o=o.nextZ,h--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;i=o}n.nextZ=null,e*=2}while(t>1);return r}function Hn(r,t,e,i,s){return r=(r-e)*s|0,t=(t-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function Lu(r){let t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function Gh(r,t,e,i,s,n,o,a){return(s-o)*(t-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(s-o)*(i-a)}function xi(r,t,e,i,s,n,o,a){return!(r===o&&t===a)&&Gh(r,t,e,i,s,n,o,a)}function Ou(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!Gu(r,t)&&(Ii(r,t)&&Ii(t,r)&&Wu(r,t)&&(at(r.prev,r,t.prev)||at(r,t.prev,t))||ei(r,t)&&at(r.prev,r,r.next)>0&&at(t.prev,t,t.next)>0)}function at(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function ei(r,t){return r.x===t.x&&r.y===t.y}function Wh(r,t,e,i){const s=ts(at(r,t,e)),n=ts(at(r,t,i)),o=ts(at(e,i,r)),a=ts(at(e,i,t));return!!(s!==n&&o!==a||s===0&&Ji(r,e,t)||n===0&&Ji(r,i,t)||o===0&&Ji(e,r,i)||a===0&&Ji(e,t,i))}function Ji(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function ts(r){return r>0?1:r<0?-1:0}function Gu(r,t){let e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&Wh(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Ii(r,t){return at(r.prev,r,r.next)<0?at(r,t,r.next)>=0&&at(r,r.prev,t)>=0:at(r,t,r.prev)<0||at(r,r.next,t)<0}function Wu(r,t){let e=r,i=!1;const s=(r.x+t.x)/2,n=(r.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Uh(r,t){const e=Vn(r.i,r.x,r.y),i=Vn(t.i,t.x,t.y),s=r.next,n=t.prev;return r.next=t,t.prev=r,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function Eo(r,t,e,i){const s=Vn(r,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Bi(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 Vn(r,t,e){return{i:r,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Uu(r,t,e,i){let s=0;for(let n=t,o=e-i;n<e;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}const Hu=Ro.default||Ro;var Hh=(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))(Hh||{});class Vu{constructor(t){this.items=[],this._name=t}emit(t,e,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](t,e,i,s,n,o,a,h);return this}add(t){return t[this._name]&&(this.remove(t),this.items.push(t)),this}remove(t){const e=this.items.indexOf(t);return e!==-1&&this.items.splice(e,1),this}contains(t){return this.items.indexOf(t)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const Nu=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Vh=class Nh extends Yt{constructor(t){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=t.type,this.name=t.name,this.config=t;const e=[...Nu,...this.config.runners??[]];this._addRunners(...e),this._unsafeEvalCheck()}async init(t={}){const e=t.skipExtensionImports===!0?!0:t.manageImports===!1;await Cu(e),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const i in this._systemsHash)t={...this._systemsHash[i].constructor.defaultOptions,...t};t={...Nh.defaultOptions,...t},this._roundPixels=t.roundPixels?1:0;for(let i=0;i<this.runners.init.items.length;i++)await this.runners.init.items[i].init(t);this._initOptions=t}render(t,e){this.tick++;let i=t;if(i instanceof L&&(i={container:i},e&&(V(J,"passing a second argument is deprecated, please use render options instead"),i.target=e.renderTexture)),i.target||(i.target=this.view.renderTarget),i.target===this.view.renderTarget&&(this._lastObjectRendered=i.container,i.clearColor??(i.clearColor=this.background.colorRgba),i.clear??(i.clear=this.background.clearBeforeRender)),i.clearColor){const s=Array.isArray(i.clearColor)&&i.clearColor.length===4;i.clearColor=s?i.clearColor: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(t,e,i){const s=this.view.resolution;this.view.resize(t,e,i),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),i!==void 0&&i!==s&&this.runners.resolutionChange.emit(i)}clear(t={}){const e=this;t.target||(t.target=e.renderTarget.renderTarget),t.clearColor||(t.clearColor=this.background.colorRgba),t.clear??(t.clear=Hh.ALL);const{clear:i,clearColor:s,target:n,mipLevel:o,layer:a}=t;rt.shared.setValue(s??this.background.colorRgba),e.renderTarget.clear(n,i,rt.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(t){this.view.resolution=t,this.runners.resolutionChange.emit(t)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...t){t.forEach(e=>{this.runners[e]=new Vu(e)})}_addSystems(t){let e;for(e in t){const i=t[e];this._addSystem(i.value,i.name)}}_addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const s in this.runners)this.runners[s].add(i);return this}_addPipes(t,e){const i=e.reduce((s,n)=>(s[n.name]=n.value,s),{});t.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(t=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(t),(t===!0||typeof t=="object"&&t.releaseGlobalResources)&&Oi.release(),Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(t){return this.textureGenerator.generateTexture(t)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Pu())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()}};Vh.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let jh=Vh,es;function ju(r){return es!==void 0||(es=(()=>{var e;const t={stencil:!0,failIfMajorPerformanceCaveat:r??jh.defaultOptions.failIfMajorPerformanceCaveat};try{if(!j.get().getWebGLRenderingContext())return!1;let s=j.get().createCanvas().getContext("webgl",t);const n=!!((e=s==null?void 0:s.getContextAttributes())!=null&&e.stencil);if(s){const o=s.getExtension("WEBGL_lose_context");o&&o.loseContext()}return s=null,n}catch{return!1}})()),es}let is;async function Yu(r={}){return is!==void 0||(is=await(async()=>{const t=j.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(r)).requestDevice(),!0}catch{return!1}})()),is}const Io=["webgl","webgpu","canvas"];async function Xu(r){let t=[];r.preference?(t.push(r.preference),Io.forEach(n=>{n!==r.preference&&t.push(n)})):t=Io.slice();let e,i={};for(let n=0;n<t.length;n++){const o=t[n];if(o==="webgpu"&&await Yu()){const{WebGPURenderer:a}=await _e(async()=>{const{WebGPURenderer:h}=await import("./WebGPURenderer.CQtWddUJ.js");return{WebGPURenderer:h}},__vite__mapDeps([5,6,7,2,3,4]));e=a,i={...r,...r.webgpu};break}else if(o==="webgl"&&ju(r.failIfMajorPerformanceCaveat??jh.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await _e(async()=>{const{WebGLRenderer:h}=await import("./WebGLRenderer.yqwosgOK.js");return{WebGLRenderer:h}},__vite__mapDeps([8,6,7,2,3,4]));e=a,i={...r,...r.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await _e(async()=>{const{CanvasRenderer:h}=await import("./CanvasRenderer.DT-IZ40Y.js");return{CanvasRenderer:h}},__vite__mapDeps([9,7,2,3,4]));e=a,i={...r,...r.canvasOptions};break}}if(delete i.webgpu,delete i.webgl,delete i.canvasOptions,!e)throw new Error("No available renderer for the current environment");const s=new e;return await s.init(i),s}const Yh="8.16.0";class Xh{static init(){var t;(t=globalThis.__PIXI_APP_INIT__)==null||t.call(globalThis,this,Yh)}static destroy(){}}Xh.extension=E.Application;class Zu{constructor(t){this._renderer=t}init(){var t;(t=globalThis.__PIXI_RENDERER_INIT__)==null||t.call(globalThis,this._renderer,Yh)}destroy(){this._renderer=null}}Zu.extension={type:[E.WebGLSystem,E.WebGPUSystem],name:"initHook",priority:-10};class Zh{static init(t){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:s,clientHeight:n}=this._resizeTo;e=s,i=n}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}Zh.extension=E.Application;class qh{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{configurable:!0,set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Ee.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?yt.shared:new yt,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}qh.extension=E.Application;$.add(Zh);$.add(qh);const Kh=class Nn{constructor(...t){this.stage=new L,t[0]!==void 0&&V(J,"Application constructor options are deprecated, please use Application.init() instead.")}async init(t){t={...t},this.stage||(this.stage=new L),this.renderer=await Xu(t),Nn._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return V(J,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(t=!1,e=!1){const i=Nn._plugins.slice(0);i.reverse(),i.forEach(s=>{s.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};Kh._plugins=[];let $h=Kh;$.handleByList(E.Application,$h._plugins);$.add(Xh);const cn={test(r){return typeof r=="string"&&r.startsWith("info face=")},parse(r){const t=r.match(/^[a-z]+\s+.+$/gm),e={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const d in t){const u=t[d].match(/^[a-z]+/gm)[0],p=t[d].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),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}e[u].push(f)}const i={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[s]=e.info,[n]=e.common,[o]=e.distanceField??[];o&&(i.distanceField={range:parseInt(o.distanceRange,10),type:o.fieldType}),i.fontSize=parseInt(s.size,10),i.fontFamily=s.face,i.lineHeight=parseInt(n.lineHeight,10);const a=e.page;for(let d=0;d<a.length;d++)i.pages.push({id:parseInt(a[d].id,10)||0,file:a[d].file});const h={};i.baseLineOffset=i.lineHeight-parseInt(n.base,10);const l=e.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=e.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}},Bo={test(r){const t=r;return typeof t!="string"&&"getElementsByTagName"in t&&t.getElementsByTagName("page").length&&t.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(r){const t={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},e=r.getElementsByTagName("info")[0],i=r.getElementsByTagName("common")[0],s=r.getElementsByTagName("distanceField")[0];s&&(t.distanceField={type:s.getAttribute("fieldType"),range:parseInt(s.getAttribute("distanceRange"),10)});const n=r.getElementsByTagName("page"),o=r.getElementsByTagName("char"),a=r.getElementsByTagName("kerning");t.fontSize=parseInt(e.getAttribute("size"),10),t.fontFamily=e.getAttribute("face"),t.lineHeight=parseInt(i.getAttribute("lineHeight"),10);for(let l=0;l<n.length;l++)t.pages.push({id:parseInt(n[l].getAttribute("id"),10)||0,file:n[l].getAttribute("file")});const h={};t.baseLineOffset=t.lineHeight-parseInt(i.getAttribute("base"),10);for(let l=0;l<o.length;l++){const c=o[l],d=parseInt(c.getAttribute("id"),10);let u=c.getAttribute("letter")??c.getAttribute("char")??String.fromCharCode(d);u==="space"&&(u=" "),h[d]=u,t.chars[u]={id:d,page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xOffset:parseInt(c.getAttribute("xoffset"),10),yOffset:parseInt(c.getAttribute("yoffset"),10),xAdvance:parseInt(c.getAttribute("xadvance"),10),kerning:{}}}for(let l=0;l<a.length;l++){const c=parseInt(a[l].getAttribute("first"),10),d=parseInt(a[l].getAttribute("second"),10),u=parseInt(a[l].getAttribute("amount"),10);t.chars[h[d]].kerning[h[c]]=u}return t}},Do={test(r){return typeof r=="string"&&r.match(/<font(\s|>)/)?Bo.test(j.get().parseXML(r)):!1},parse(r){return Bo.parse(j.get().parseXML(r))}},qu=[".xml",".fnt"],Ku={extension:{type:E.CacheParser,name:"cacheBitmapFont"},test:r=>!!(r!=null&&r.pages)&&!!(r!=null&&r.chars)&&typeof(r==null?void 0:r.fontFamily)=="string",getCacheableAssets(r,t){const e={};return r.forEach(i=>{e[i]=t,e[`${i}-bitmap`]=t}),e[`${t.fontFamily}-bitmap`]=t,e}},$u={extension:{type:E.LoadParser,priority:ue.Normal},name:"loadBitmapFont",id:"bitmap-font",test(r){return qu.includes(Mt.extname(r).toLowerCase())},async testParse(r){return cn.test(r)||Do.test(r)},async parse(r,t,e){const i=cn.test(r)?cn.parse(r):Do.parse(r),{src:s}=t,{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=Fn(f,s),o.push({src:f,data:a})}const[h,{BitmapFont:l}]=await Promise.all([e.load(o),_e(()=>import("./BitmapFont.CXuoJus7.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,t){return await(await j.get().fetch(r)).text()},async unload(r,t,e){await Promise.all(r.pages.map(i=>e.unload(i.texture.source._sourceOrigin))),r.destroy()}};class Qu{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}const Ju={extension:{type:E.CacheParser,name:"cacheTextureArray"},test:r=>Array.isArray(r)&&r.every(t=>t instanceof G),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((s,n)=>{e[i+(n===0?"":n+1)]=s})}),e}};async function Qh(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const tp={extension:{type:E.DetectionParser,priority:1},test:async()=>Qh("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")},Fo=["png","jpg","jpeg"],ep={extension:{type:E.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Fo],remove:async r=>r.filter(t=>!Fo.includes(t))},ip="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function _s(r){return ip?!1:document.createElement("video").canPlayType(r)!==""}const sp={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")},np={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")},rp={extension:{type:E.DetectionParser,priority:0},test:async()=>_s("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")},op={extension:{type:E.DetectionParser,priority:0},test:async()=>Qh("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")},Jh=class as{constructor(){this.loadOptions={...as.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let s=null,n=null;if((e.parser||e.loadParser)&&(n=this._parserHash[e.parser||e.loadParser],e.loadParser&&nt(`[Assets] "loadParser" is deprecated, use "parser" instead for ${t}`),n||nt(`[Assets] specified load parser "${e.parser||e.loadParser}" not found while loading ${t}`)),!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,t,e,this))){n=l;break}}if(!n)return nt(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}s=await n.load(t,e,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,e,this))&&(s=await l.parse(s,e,this)||s,i.parser=l)}return s})(),i}async load(t,e){this._parsersValidated||this._validateParsers();const i=typeof e=="function"?{...as.defaultOptions,...this.loadOptions,onProgress:e}:{...as.defaultOptions,...this.loadOptions,...e||{}},{onProgress:s,onError:n,strategy:o,retryCount:a,retryDelay:h}=i;let l=0;const c={},d=fs(t),u=zt(t,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(t){const i=zt(t,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(t=>t.name||t.id).reduce((t,e)=>(!e.name&&!e.id?nt("[Assets] parser should have an id"):(t[e.name]||t[e.id])&&nt(`[Assets] parser id conflict "${e.id}"`),t[e.name]=e,e.id&&(t[e.id]=e),t),{})}async _loadAssetWithRetry(t,e,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[t]||(this.promiseCache[t]=this._getLoadPromiseAndParser(t,e)),s[e.src]=await this.promiseCache[t].promise;return}catch(d){delete this.promiseCache[t],delete s[e.src],n++;const u=a!=="retry"||n>h;if(a==="retry"&&!u){o&&o(d,e),await c(l);continue}if(a==="skip"){o&&o(d,e);return}o&&o(d,e);const p=new Error(`[Loader.load] Failed to load ${t}.
|
|
24
24
|
${d}`);throw d instanceof Error&&d.stack&&(p.stack=d.stack),p}}};Jh.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let ap=Jh;function pe(r,t){if(Array.isArray(t)){for(const e of t)if(r.startsWith(`data:${e}`))return!0;return!1}return r.startsWith(`data:${t}`)}function ni(r,t){const e=r.split("?")[0],i=Mt.extname(e).toLowerCase();return Array.isArray(t)?t.includes(i):i===t}const hp=".json",lp="application/json",cp={extension:{type:E.LoadParser,priority:ue.Low},name:"loadJson",id:"json",test(r){return pe(r,lp)||ni(r,hp)},async load(r){return await(await j.get().fetch(r)).json()}},dp=".txt",up="text/plain",pp={name:"loadTxt",id:"text",extension:{type:E.LoadParser,priority:ue.Low,name:"loadTxt"},test(r){return pe(r,up)||ni(r,dp)},async load(r){return await(await j.get().fetch(r)).text()}},fp=["normal","bold","100","200","300","400","500","600","700","800","900"],gp=[".ttf",".otf",".woff",".woff2"],mp=["font/ttf","font/otf","font/woff","font/woff2"],yp=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function xp(r){const t=Mt.extname(r),s=Mt.basename(r,t).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(yp)){n=!1;break}let o=s.join(" ");return n||(o=`"${o.replace(/[\\"]/g,"\\$&")}"`),o}const Sp=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function vp(r){return Sp.test(r)?r:encodeURI(r)}const bp={extension:{type:E.LoadParser,priority:ue.Low},name:"loadWebFont",id:"web-font",test(r){return pe(r,mp)||ni(r,gp)},async load(r,t){var i,s,n;const e=j.get().getFontFaceSet();if(e){const o=[],a=((i=t.data)==null?void 0:i.family)??xp(r),h=((n=(s=t.data)==null?void 0:s.weights)==null?void 0:n.filter(c=>fp.includes(c)))??["normal"],l=t.data??{};for(let c=0;c<h.length;c++){const d=h[c],u=new FontFace(a,`url(${vp(r)})`,{...l,weight:d});await u.load(),e.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 t=Array.isArray(r)?r:[r],e=t[0].family,i=xt.get(`${e}-and-url`),s=i.entries.find(n=>n.faces.some(o=>t.indexOf(o)!==-1));s.faces=s.faces.filter(n=>t.indexOf(n)===-1),s.faces.length===0&&(i.entries=i.entries.filter(n=>n!==s)),t.forEach(n=>{j.get().getFontFaceSet().delete(n)}),i.entries.length===0&&xt.remove(`${e}-and-url`)}};var wp=Cp,dn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},Ap=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function Cp(r){var t=[];return r.replace(Ap,function(e,i,s){var n=i.toLowerCase();for(s=Mp(s),n=="m"&&s.length>2&&(t.push([i].concat(s.splice(0,2))),n="l",i=i=="m"?"l":"L");;){if(s.length==dn[n])return s.unshift(i),t.push(s);if(s.length<dn[n])throw new Error("malformed path data");t.push([i].concat(s.splice(0,dn[n])))}}),t}var Pp=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function Mp(r){var t=r.match(Pp);return t?t.map(Number):[]}const _p=qa(wp);function Tp(r,t){const e=_p(r),i=[];let s=null,n=0,o=0;for(let a=0;a<e.length;a++){const h=e[a],l=h[0],c=h;switch(l){case"M":n=c[1],o=c[2],t.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],t.moveTo(n,o);break;case"H":n=c[1],t.lineTo(n,o);break;case"h":n+=c[1],t.lineTo(n,o);break;case"V":o=c[1],t.lineTo(n,o);break;case"v":o+=c[1],t.lineTo(n,o);break;case"L":n=c[1],o=c[2],t.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],t.lineTo(n,o);break;case"C":n=c[5],o=c[6],t.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":t.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],t.bezierCurveToShort(c[1],c[2],n,o);break;case"s":t.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],t.quadraticCurveTo(c[1],c[2],n,o);break;case"q":t.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],t.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],t.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],t.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":t.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 t}class Ts{constructor(t=0,e=0,i=0){this.type="circle",this.x=t,this.y=e,this.radius=i}clone(){return new Ts(this.x,this.y,this.radius)}contains(t,e){if(this.radius<=0)return!1;const i=this.radius*this.radius;let s=this.x-t,n=this.y-e;return s*=s,n*=n,s+n<=i}strokeContains(t,e,i,s=.5){if(this.radius===0)return!1;const n=this.x-t,o=this.y-e,a=this.radius,h=(1-s)*i,l=Math.sqrt(n*n+o*o);return l<=a+h&&l>a-(i-h)}getBounds(t){return t||(t=new et),t.x=this.x-this.radius,t.y=this.y-this.radius,t.width=this.radius*2,t.height=this.radius*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.radius=t.radius,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class fr{constructor(t=0,e=0,i=0,s=0){this.type="ellipse",this.x=t,this.y=e,this.halfWidth=i,this.halfHeight=s}clone(){return new fr(this.x,this.y,this.halfWidth,this.halfHeight)}contains(t,e){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let i=(t-this.x)/this.halfWidth,s=(e-this.y)/this.halfHeight;return i*=i,s*=s,i+s<=1}strokeContains(t,e,i,s=.5){const{halfWidth: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=t-this.x,f=e-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(t){return t||(t=new et),t.x=this.x-this.halfWidth,t.y=this.y-this.halfHeight,t.width=this.halfWidth*2,t.height=this.halfHeight*2,t}copyFrom(t){return this.x=t.x,this.y=t.y,this.halfWidth=t.halfWidth,this.halfHeight=t.halfHeight,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function kp(r,t,e,i,s,n){const o=r-e,a=t-i,h=s-e,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=e,f=i):u>1?(p=s,f=n):(p=e+u*h,f=i+u*l);const y=r-p,m=t-f;return y*y+m*m}let Rp,Ep;class Te{constructor(...t){this.type="polygon";let e=Array.isArray(t[0])?t[0]:t;if(typeof e[0]!="number"){const i=[];for(let s=0,n=e.length;s<n;s++)i.push(e[s].x,e[s].y);e=i}this.points=e,this.closePath=!0}isClockwise(){let t=0;const e=this.points,i=e.length;for(let s=0;s<i;s+=2){const n=e[s],o=e[s+1],a=e[(s+2)%i],h=e[(s+3)%i];t+=(a-n)*(h+o)}return t<0}containsPolygon(t){const e=this.getBounds(Rp),i=t.getBounds(Ep);if(!e.containsRect(i))return!1;const s=t.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 t=this.points.slice(),e=new Te(t);return e.closePath=this.closePath,e}contains(t,e){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>e!=c>e&&t<(l-a)*((e-h)/(c-h))+a&&(i=!i)}return i}strokeContains(t,e,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=kp(t,e,d,u,p,f),m=Math.sign((p-d)*(e-u)-(f-u)*(t-d));if(y<=(m<0?a:o))return!0}return!1}getBounds(t){t||(t=new et);const e=this.points;let i=1/0,s=-1/0,n=1/0,o=-1/0;for(let a=0,h=e.length;a<h;a+=2){const l=e[a],c=e[a+1];i=l<i?l:i,s=l>s?l:s,n=c<n?c:n,o=c>o?c:o}return t.x=i,t.width=s-i,t.y=n,t.height=o-n,t}copyFrom(t){return this.points=t.points.slice(),this.closePath=t.closePath,this}copyTo(t){return t.copyFrom(this),t}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((t,e)=>`${t}, ${e}`,"")}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return V("8.11.0","Polygon.lastX is deprecated, please use Polygon.lastX instead."),this.points[this.points.length-2]}get y(){return V("8.11.0","Polygon.y is deprecated, please use Polygon.lastY instead."),this.points[this.points.length-1]}get startX(){return this.points[0]}get startY(){return this.points[1]}}const ss=(r,t,e,i,s,n,o)=>{const a=r-e,h=t-i,l=Math.sqrt(a*a+h*h);return l>=s-n&&l<=s+o};class gr{constructor(t=0,e=0,i=0,s=0,n=20){this.type="roundedRectangle",this.x=t,this.y=e,this.width=i,this.height=s,this.radius=n}getBounds(t){return t||(t=new et),t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}clone(){return new gr(this.x,this.y,this.width,this.height,this.radius)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.copyFrom(this),t}contains(t,e){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&e>=this.y&&e<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(e>=this.y+i&&e<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let s=t-(this.x+i),n=e-(this.y+i);const o=i*i;if(s*s+n*n<=o||(s=t-(this.x+this.width-i),s*s+n*n<=o)||(n=e-(this.y+this.height-i),s*s+n*n<=o)||(s=t-(this.x+i),s*s+n*n<=o))return!0}return!1}strokeContains(t,e,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(t>=n-c&&t<=n+d||t>=m-d&&t<=m+c)&&e>=p&&e<=p+y||(e>=o-c&&e<=o+d||e>=x-d&&e<=x+c)&&t>=u&&t<=u+f?!0:t<u&&e<p&&ss(t,e,u,p,l,d,c)||t>m-l&&e<p&&ss(t,e,m-l,p,l,d,c)||t>m-l&&e>x-l&&ss(t,e,m-l,x-l,l,d,c)||t<u&&e>x-l&&ss(t,e,u,x-l,l,d,c)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const tl={};function Ip(r,t,e){let i=2166136261;for(let s=0;s<t;s++)i^=r[s].uid,i=Math.imul(i,16777619),i>>>=0;return tl[i]||Bp(r,t,i,e)}function Bp(r,t,e,i){const s={};let n=0;for(let a=0;a<i;a++){const h=a<t?r[a]:G.EMPTY.source;s[n++]=h.source,s[n++]=h.style}const o=new Ci(s);return tl[e]=o,o}class zo{constructor(t){typeof t=="number"?this.rawBinaryData=new ArrayBuffer(t):t instanceof Uint8Array?this.rawBinaryData=t.buffer:this.rawBinaryData=t,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}get float64View(){return this._float64Array||(this._float64Array=new Float64Array(this.rawBinaryData)),this._float64Array}get bigUint64View(){return this._bigUint64Array||(this._bigUint64Array=new BigUint64Array(this.rawBinaryData)),this._bigUint64Array}view(t){return this[`${t}View`]}destroy(){this.rawBinaryData=null,this.uint32View=null,this.float32View=null,this.uint16View=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._int32View=null,this._float64Array=null,this._bigUint64Array=null}static sizeOf(t){switch(t){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${t} isn't a valid view type`)}}}function Lo(r,t,e,i){if(e??(e=0),i??(i=Math.min(r.byteLength-e,t.byteLength)),!(e&7)&&!(i&7)){const s=i/8;new Float64Array(t,0,s).set(new Float64Array(r,e,s))}else if(!(e&3)&&!(i&3)){const s=i/4;new Float32Array(t,0,s).set(new Float32Array(r,e,s))}else new Uint8Array(t).set(new Uint8Array(r,e,i))}const Dp={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var Fp=(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))(Fp||{});function gs(r,t){return t.alphaMode==="no-premultiply-alpha"&&Dp[r]||r}const zp=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
|
|
25
25
|
`);function Lp(r){let t="";for(let e=0;e<r;++e)e>0&&(t+=`
|
|
26
26
|
else `),e<r-1&&(t+=`if(test == ${e}.0){}`);return t}function Op(r,t){if(r===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const e=t.createShader(t.FRAGMENT_SHADER);try{for(;;){const i=zp.replace(/%forloop%/gi,Lp(r));if(t.shaderSource(e,i),t.compileShader(e),!t.getShaderParameter(e,t.COMPILE_STATUS))r=r/2|0;else break}}finally{t.deleteShader(e)}return r}let Le=null;function Gp(){var t;if(Le)return Le;const r=Eh();return Le=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),Le=Op(Le,r),(t=r.getExtension("WEBGL_lose_context"))==null||t.loseContext(),Le}class Wp{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let t=0;t<this.count;t++){const e=this.textures[t];this.textures[t]=null,this.ids[e.uid]=null}this.count=0}}class Up{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new Wp,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 Pi=[];let ms=0;Oi.register({clear:()=>{if(Pi.length>0)for(const r of Pi)r&&r.destroy();Pi.length=0,ms=0}});function Oo(){return ms>0?Pi[--ms]:new Up}function Go(r){r.elements=null,Pi[ms++]=r}let ci=0;const el=class il{constructor(t){this.uid=dt("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t={...il.defaultOptions,...t},t.maxTextures||(V("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),t.maxTextures=Gp());const{maxTextures:e,attributesInitialSize:i,indicesInitialSize:s}=t;this.attributeBuffer=new zo(i*4),this.indexBuffer=new Uint16Array(s),this.maxTextures=e}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let t=0;t<this.batchIndex;t++)Go(this.batches[t]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(t){this._elements[this.elementSize++]=t,t._indexStart=this.indexSize,t._attributeStart=this.attributeSize,t._batcher=this,this.indexSize+=t.indexSize,this.attributeSize+=t.attributeSize*this.vertexSize}checkAndUpdateTexture(t,e){const i=t._batch.textures.ids[e._source.uid];return!i&&i!==0?!1:(t._textureId=i,t.texture=e,!0)}updateElement(t){this.dirty=!0;const e=this.attributeBuffer;t.packAsQuad?this.packQuadAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId):this.packAttributes(t,e.float32View,e.uint32View,t._attributeStart,t._textureId)}break(t){const e=this._elements;if(!e[this.elementStart])return;let i=Oo(),s=i.textures;s.clear();const n=e[this.elementStart];let o=gs(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=e[m];e[m]=null;const v=x.texture._source,b=gs(x.blendMode,v),P=o!==b||a!==x.topology;if(v._batchTick===ci&&!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=ci,(s.count>=y||P)&&(this._finishBatch(i,u,d-u,s,o,a,t,p,f),p="renderBatch",u=d,o=b,a=x.topology,i=Oo(),s=i.textures,s.clear(),f=[],++ci),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,t,p,f),u=d,++ci),this.elementStart=this.elementSize,this._batchIndexStart=u,this._batchIndexSize=d}_finishBatch(t,e,i,s,n,o,a,h,l){t.gpuBindGroup=null,t.bindGroup=null,t.action=h,t.batcher=this,t.textures=s,t.blendMode=n,t.topology=o,t.start=e,t.size=i,t.elements=l,++ci,this.batches[this.batchIndex++]=t,a.add(t)}finish(t){this.break(t)}ensureAttributeBuffer(t){t*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(t*4)}ensureIndexBuffer(t){t<=this.indexBuffer.length||this._resizeIndexBuffer(t)}_resizeAttributeBuffer(t){const e=Math.max(t,this.attributeBuffer.size*2),i=new zo(e);Lo(this.attributeBuffer.rawBinaryData,i.rawBinaryData),this.attributeBuffer=i}_resizeIndexBuffer(t){const e=this.indexBuffer;let i=Math.max(t,e.length*1.5);i+=i%2;const s=i>65535?new Uint32Array(i):new Uint16Array(i);if(s.BYTES_PER_ELEMENT!==e.BYTES_PER_ELEMENT)for(let n=0;n<e.length;n++)s[n]=e[n];else Lo(e.buffer,s.buffer);this.indexBuffer=s}packQuadIndex(t,e,i){t[e]=i+0,t[e+1]=i+1,t[e+2]=i+2,t[e+3]=i+0,t[e+4]=i+2,t[e+5]=i+3}packIndex(t,e,i,s){const n=t.indices,o=t.indexSize,a=t.indexOffset,h=t.attributeOffset;for(let l=0;l<o;l++)e[i++]=s+n[l+a]-h}destroy(t={}){var e;if(this.batches!==null){for(let i=0;i<this.batchIndex;i++)Go(this.batches[i]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,t.shader&&((e=this.shader)==null||e.destroy(),this.shader=null);for(let i=0;i<this._elements.length;i++)this._elements[i]&&(this._elements[i]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};el.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let Hp=el;var gt=(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))(gt||{});class le extends Yt{constructor(t){let{data:e,size:i}=t;const{usage:s,label:n,shrinkToFit:o}=t;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,e instanceof Array&&(e=new Float32Array(e)),this._data=e,i??(i=e==null?void 0:e.byteLength);const a=!!e;this.descriptor={size:i,usage:s,mappedAtCreation:a,label:n},this.shrinkToFit=o??!0}get data(){return this._data}set data(t){this.setDataWithSize(t,t.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage>.STATIC)}set static(t){t?this.descriptor.usage|=gt.STATIC:this.descriptor.usage&=~gt.STATIC}setDataWithSize(t,e,i){if(this._updateID++,this._updateSize=e*t.BYTES_PER_ELEMENT,this._data===t){i&&this.emit("update",this);return}const s=this._data;if(this._data=t,this._dataInt32=null,!s||s.length!==t.length){!this.shrinkToFit&&s&&t.byteLength<s.byteLength?i&&this.emit("update",this):(this.descriptor.size=t.byteLength,this._resourceId=dt("resource"),this.emit("change",this));return}i&&this.emit("update",this)}update(t){this._updateSize=t??this._updateSize,this._updateID++,this.emit("update",this)}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function sl(r,t){if(!(r instanceof le)){let e=t?gt.INDEX:gt.VERTEX;r instanceof Array&&(t?(r=new Uint32Array(r),e=gt.INDEX|gt.COPY_DST):(r=new Float32Array(r),e=gt.VERTEX|gt.COPY_DST)),r=new le({data:r,label:t?"index-mesh-buffer":"vertex-mesh-buffer",usage:e})}return r}function Vp(r,t,e){const i=r.getAttribute(t);if(!i)return e.minX=0,e.minY=0,e.maxX=0,e.maxY=0,e;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 e.minX=n,e.minY=o,e.maxX=a,e.maxY=h,e}function Np(r){return(r instanceof le||Array.isArray(r)||r.BYTES_PER_ELEMENT)&&(r={buffer:r}),r.buffer=sl(r.buffer,!1),r}class Di extends Yt{constructor(t={}){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 It,this._boundsDirty=!0;const{attributes:e,indexBuffer:i,topology:s}=t;if(this.buffers=[],this.attributes={},e)for(const n in e)this.addAttribute(n,e[n]);this.instanceCount=t.instanceCount??1,i&&this.addIndex(i),this.topology=s||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(t){return this.attributes[t]}getIndex(){return this.indexBuffer}getBuffer(t){return this.getAttribute(t).buffer}getSize(){for(const t in this.attributes){const e=this.attributes[t];return e.buffer.data.length/(e.stride/4||e.size)}return 0}addAttribute(t,e){const i=Np(e);this.buffers.indexOf(i.buffer)===-1&&(this.buffers.push(i.buffer),i.buffer.on("update",this.onBufferUpdate,this),i.buffer.on("change",this.onBufferUpdate,this)),this.attributes[t]=i}addIndex(t){this.indexBuffer=sl(t,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,Vp(this,"aPosition",this._bounds)):this._bounds}unload(){var t;this.emit("unload",this);for(const e in this._gpuData)(t=this._gpuData[e])==null||t.destroy();this._gpuData=Object.create(null)}destroy(t=!1){var e;this.emit("destroy",this),this.removeAllListeners(),t&&this.buffers.forEach(i=>i.destroy()),this.unload(),(e=this.indexBuffer)==null||e.destroy(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const jp=new Float32Array(1),Yp=new Uint32Array(1);class Xp extends Di{constructor(){const e=new le({data:jp,label:"attribute-batch-buffer",usage:gt.VERTEX|gt.COPY_DST,shrinkToFit:!1}),i=new le({data:Yp,label:"index-batch-buffer",usage:gt.INDEX|gt.COPY_DST,shrinkToFit:!1}),s=6*4;super({attributes:{aPosition:{buffer:e,format:"float32x2",stride:s,offset:0},aUV:{buffer:e,format:"float32x2",stride:s,offset:2*4},aColor:{buffer:e,format:"unorm8x4",stride:s,offset:4*4},aTextureIdAndRound:{buffer:e,format:"uint16x2",stride:s,offset:5*4}},indexBuffer:i})}}function Wo(r,t,e){if(r)for(const i in r){const s=i.toLocaleLowerCase(),n=t[s];if(n){let o=r[i];i==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),e&&n.push(`//----${e}----//`),n.push(o)}else nt(`${i} placement hook does not exist in shader`)}}const Zp=/\{\{(.*?)\}\}/g;function Uo(r){var i;const t={};return(((i=r.match(Zp))==null?void 0:i.map(s=>s.replace(/[{()}]/g,"")))??[]).forEach(s=>{t[s]=[]}),t}function Ho(r,t){let e;const i=/@in\s+([^;]+);/g;for(;(e=i.exec(r))!==null;)t.push(e[1])}function Vo(r,t,e=!1){const i=[];Ho(t,i),r.forEach(a=>{a.header&&Ho(a.header,i)});const s=i;e&&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 xa({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(e,i){this.position.set(e,i)}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class Kx{constructor(t){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=t,this.heatmap=new qx(t);const e=t.heatMapConfig;this.cellSize=e.cellSize,this.maxDistance=e.maxDistance,this.smoothIterations=e.smoothIterations,this.heatmapAlpha=e.heatmapAlpha}draw(t){const e=this.appService;if(!e.isMapDrawn){this.pendingPoints=t;return}this.pendingPoints=null;const{minX:i,minY:s}=e.mapManager.mapBounds,n=t.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(t){var p;const e=this.appService,i=((p=e.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:n,maxX:o,maxY:a}=e.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 w=0;w<t.length;w++){const C=t[w];if(Math.abs(S-C.x)<=v/2&&Math.abs(y-C.y)<=m/2){const k=1-C.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(t.length===0)return 0;let m=0,x=0;for(const S of t){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 w=4;for(let C=-w;C<=w;C++)for(let k=-w;k<=w;k++){if(C===0&&k===0)continue;const M=S+C,T=v+k;if(M>=0&&M<h&&T>=0&&T<l){const I=1/(1+Math.sqrt(C*C+k*k)*.3);b+=f[M][T].signal*I,P+=I}}if(P>0){const C=b/P,k=.6,M=.4;x[S][v].signal=f[S][v].signal*k+C*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(t,e){this.heatmap.updatePositionByOrigin(t,e)}destroy(){this.heatmap.destroy()}}class pc extends L{constructor(e){super();g(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.updateScale(this.appService.currentScale),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e!==0&&this.scale.set(1/e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Wi extends pc{constructor(e,i){super(e);g(this,"background");g(this,"icon");g(this,"options");this.appService=e,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Xt(e),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const e=this.appService,i=this.options.config||e.controlsConfig,s=8,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 e=this.appService,i=this.options.config||e.controlsConfig;this.background.clear(),this.background.roundRect(-i.iconWrapperWidth/2,-i.iconWrapperHeight/2,i.iconWrapperWidth,i.iconWrapperHeight,i.iconWrapperBorderRadius).fill(this.options.backgroundColor)}async renderIcon(){try{const e=this.appService,i=this.options.config||e.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(e){A.error(`Failed to load icon: ${this.options.iconAlias}`,e)}}destroy(){super.destroy()}}class fc extends Wi{constructor(e,i){super(e,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",e=>{var o,a;if(!this.isRotating)return;this.hasRotated=!0;const i=this.parent.toLocal(e.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 e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});g(this,"handleRotationCancel",()=>{var e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});this.appService=e,this.setupRotationEventListeners()}setupRotationEventListeners(){const{emitter:e}=this.appService;this.appService.emitter.on("gestureHijackPointerMove",this.handleRotationPointerMove),e.on("gestureHijackPointerUp",this.handleRotationPointerUp),e.on("gestureHijackCancel",this.handleRotationCancel)}cleanupRotationEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleRotationPointerMove),e.off("gestureHijackPointerUp",this.handleRotationPointerUp),e.off("gestureHijackCancel",this.handleRotationCancel)}setupEvents(){this.options.onClick&&(this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.hasRotated||(i=(e=this.options).onClick)==null||i.call(e)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startRotation(e)}startRotation(e){var n,o;this.isRotating=!0,this.hasRotated=!1;const i=this.options.getTargetPoints();this.rotationCenter=ee(i);const s=this.parent.toLocal(e.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",e)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)}destroy(){var e;this.stopRotation(),(e=this.clickHandler)==null||e.destroy(),this.cleanupRotationEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ds extends Wi{constructor(e,i){super(e,i);g(this,"clickHandler",null);this.appService=e}setupEvents(){this.clickHandler=new vt(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),super.destroy()}}class Ze extends Wi{constructor(e,i){super(e,i);g(this,"isScaling",!1);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"handleScalePointerMove",e=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:n})});g(this,"handleScalePointerUp",()=>{var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});g(this,"handleScaleCancel",()=>{var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});this.appService=e,this.setupScaleEventListeners()}setupScaleEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleScalePointerMove),e.on("gestureHijackPointerUp",this.handleScalePointerUp),e.on("gestureHijackCancel",this.handleScaleCancel)}cleanupScaleEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleScalePointerMove),e.off("gestureHijackPointerUp",this.handleScalePointerUp),e.off("gestureHijackCancel",this.handleScaleCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startScaling(e)}startScaling(e){var i,s,n,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(e.global),"initialButtonPosition"in this.options)this.initialButtonPosition={x:this.position.x,y:this.position.y},(s=(i=this.options).onScaleStart)==null||s.call(i);else{const a=this.options.getTargetPoints(),h=this.options.getButtonIndex();h>=0&&h<a.length&&(this.initialButtonPosition={...a[h]}),(o=(n=this.options).onScaleStart)==null||o.call(n,h)}this.appService.emitter.emit("gestureHijackStart",e)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))}destroy(){this.stopScaling(),this.cleanupScaleEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Fs extends Wi{constructor(e,i){super(e,i);g(this,"isMoving",!1);g(this,"dragStartPosition",null);g(this,"handleMovePointerMove",e=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,e)});g(this,"handleMovePointerUp",()=>{var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});g(this,"handleMoveCancel",()=>{var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});this.appService=e,this.setupMoveEventListeners()}setupMoveEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleMovePointerMove),e.on("gestureHijackPointerUp",this.handleMovePointerUp),e.on("gestureHijackCancel",this.handleMoveCancel)}cleanupMoveEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleMovePointerMove),e.off("gestureHijackPointerUp",this.handleMovePointerUp),e.off("gestureHijackCancel",this.handleMoveCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startMoving(e)}startMoving(e){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(e.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.appService.emitter.emit("gestureHijackStart",e)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))}destroy(){this.stopMoving(),this.cleanupMoveEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Lr extends H{constructor(e,i){super();g(this,"fillOptions");g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"handlePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});g(this,"handleDragPointerMove",e=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,e)});g(this,"handleDragPointerUp",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});g(this,"handleDragCancel",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});this.appService=e,this.fillOptions=i,this.setupInteraction(),this.setupDragEventListeners(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}startDragging(e){var s,n;this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},(n=(s=this.fillOptions).onDragStart)==null||n.call(s,e),this.appService.emitter.emit("gestureHijackStart",e)}draw(){const{points:e,fillColor:i}=this.fillOptions;if(e.length<3)return;this.clear();const s=e.flatMap(n=>[n.x,n.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(e){this.fillOptions={...this.fillOptions,...e},e.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(e){this.fillOptions.points=e,this.draw()}updateFillColor(e){this.fillOptions.fillColor=e,this.draw()}stopDragging(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(e){this.fillOptions.enableInteraction=e,e?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Nt extends L{constructor(e,i){super();g(this,"borderOptions");g(this,"solidLine",null);g(this,"dashGraphics",null);g(this,"fillGraphics",null);g(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=e,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:e=[],closePath:i=!1,style:s}=this.borderOptions;e.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(e,s),s.isDashed?this.drawContinuousDashedBorder(e,i,s):this.drawSolidBorder(e,i,s))}drawFill(e,i){if(!(!i.fillColor||e.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length;s++)this.fillGraphics.lineTo(e[s].x,e[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(e,i,s){const 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(e[0].x,e[0].y);for(let a=1;a<e.length;a++)this.solidLine.lineTo(e[a].x,e[a].y);i&&this.solidLine.lineTo(e[0].x,e[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(e,i,s){if(e.length<2)return;if(!s.dashArray||s.dashArray.length!==2||s.dashArray[0]<=0||s.dashArray[1]<=0){A.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?[...e,e[0]]:e;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(e,i,s,n){if(i.length<2)return;if(s<=0||n<=0){A.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(e,o,l,c):this.drawContinuousDashSegment(e,o,l,a),l+=h}}calculatePathSegments(e){const i=[];for(let s=0;s<e.length-1;s++){const n=e[s],o=e[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(e,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&&e.lineTo(m.x,m.y):(e.moveTo(m.x,m.y),a=!0),e.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=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(e){this.borderOptions.style={...this.borderOptions.style,...e},this.drawBorder()}updatePoints(e){this.borderOptions.points=e,this.drawBorder()}setClosePath(e){this.borderOptions.closePath=e,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class Ui extends Es{constructor(e,{text:i,style:s}){super({text:i,style:s});g(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=At(this.updateScale.bind(this),20,{leading:!0,trailing:!0}),this.registerScaleListener(),this.updateScale(this.appService.currentScale)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e<=0||this.scale.set(1/e)}setBaseFontSize(e){this.style.fontSize=e}updateText(e){this.text=e}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}const Ct=class Ct extends L{constructor(e){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,"throttledUpdateOutline");g(this,"handleDragStart",e=>{this.isEditingEnabled()&&(this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.dragStartPosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.dragStartPosition=null,this.appService.getApp().stopRender("zone-drag"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleRotationStart",e=>{this.totalRotationAngle=0,this.rotationCenter=e,this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",e=>{this.totalRotationAngle+=e,this.applyRotation(this.totalRotationAngle)});g(this,"handleRotationEnd",()=>{var e,i;this.rotationCenter=null,this.totalRotationAngle=0,this.initialZonePoints=[],this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleScaleStart",()=>{this.initialZonePoints=this.zoneData.points.map(i=>({...i}));const e=Ct.BUTTON_INDICES.SCALE;e<this.zoneData.points.length&&(this.initialButtonPosition={...this.zoneData.points[e]}),this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialZonePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var e,i;this.initialZonePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("zone-scale"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",e=>{var a;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.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 e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleDelete",()=>{var e,i;(i=(e=this.zoneEvents).onRemove)==null||i.call(e,this.zoneData.id)});const{appService:i,zoneData:s,zoneType:n,events:o={}}=e;this.appService=i,this.zoneType=n,this.zoneEvents=o,this.zoneConfig=this.getZoneConfig(),this.controlsConfig=this.getControlsConfig();const a=this.validateAndCorrectZoneSize(s.points),h=bs(a);this.zoneData={...s,points:h},this.throttledUpdateOutline=At(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(){const{controls:e}=this.appService.getConfig();return e[this.zoneType]}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}validateAndCorrectZoneSize(e){if(e.length<4)return e;const i=this.appService.metersToPixels(this.zoneConfig.minSize),[s,n,,o]=e,a=Q(s,n),h=Q(s,o);if(a>=i&&h>=i)return e;const l=ee(e),c=pt(q(s,n)),d=pt(q(s,o)),u=Math.max(a,i),p=Math.max(h,i),f=u/2,y=p/2;return[{x:l.x-c.x*f-d.x*y,y:l.y-c.y*f-d.y*y},{x:l.x+c.x*f-d.x*y,y:l.y+c.y*f-d.y*y},{x:l.x+c.x*f+d.x*y,y:l.y+c.y*f+d.y*y},{x:l.x-c.x*f+d.x*y,y:l.y-c.y*f+d.y*y}]}getEditingIdsKey(){switch(this.zoneType){case"forbiddenSweepZone":return"editingForbiddenSweepZoneIds";case"forbiddenMopZone":return"editingForbiddenMopZoneIds";case"cleanZone":return"editingCleanZoneIds";default:return"editingForbiddenSweepZoneIds"}}isEditingEnabled(){const e=this.getEditingIdsKey();return this.appService.runtimeSnapshot[e].includes(this.zoneData.id)}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 e=this.calculateOutlinePoints();if(e.length<4)return;this.deleteButton=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onClick:this.handleDelete}),this.deleteButton.position.set(e[Ct.BUTTON_INDICES.REMOVE].x,e[Ct.BUTTON_INDICES.REMOVE].y),this.zoneConfig.showRotateButton&&(this.rotateButton=new fc(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(e[Ct.BUTTON_INDICES.ROTATE].x,e[Ct.BUTTON_INDICES.ROTATE].y)),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,getButtonIndex:()=>Ct.BUTTON_INDICES.SCALE,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[Ct.BUTTON_INDICES.SCALE].x,e[Ct.BUTTON_INDICES.SCALE].y);const i=this.calculateMoveButtonPosition();this.moveButton=new Fs(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 e=this.isEditingEnabled();return new Lr(this.appService,{points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:e,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 e=this.calculateOutlinePoints();return new Nt(this.appService,{points:e,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 e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);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:e}=this.zoneData;if(e.length<4)return e;const i=this.appService.getApp().toFixedSize(this.zoneConfig.outlineOffset);return Ir(e,i)}calculateMoveLinePoints(e){if(e.length<4)return[];const i=e[Ct.BUTTON_INDICES.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}createSizeText(){const e=this.calculateZoneSizeText(),i=new Ui(this.appService,{text:e,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:e}=this.zoneData;if(e.length<4)return"0m*0m";const[i,s,,n]=e,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:e}=this.zoneData;if(e.length<4)return{x:0,y:0};const[i,s,n,o]=e,{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=pt(q(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=pt(q(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=pt(q(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=pt(q(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:e}=this.zoneData;if(e.length<4)return 0;const[i,s,n,o]=e,{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 Xe(h,l,c)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const{controls:i}=this.appService.getConfig(),s=e[Ct.BUTTON_INDICES.MOVE],n=e[2],o=e[0],a=this.appService.getApp().toFixedSize(i.moveButtonOffset);return Is(s,n,o,a)}applyTranslation(e,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawZone(),this.updateControlButtonsPosition()}applyRotation(e){!this.rotationCenter||this.initialZonePoints.length===0||(this.zoneData.points=Er(this.initialZonePoints,this.rotationCenter,e),this.drawZone(!1),this.updateControlButtonsPosition())}applyEdgeBasedScale(e){if(this.initialZonePoints.length<4)return;const{FIXED:i}=Ct.BUTTON_INDICES,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=q(h,o),c=q(h,a),d=q(h,e),u=ie(l),p=ie(c);if(u===0||p===0)return;const f=this.appService.metersToPixels(this.zoneConfig.minSize),[y,m]=[he(d,l,u,f),he(d,c,p,f)];this.zoneData.points=[h,{x:s+l.x*y,y:n+l.y*y},{x:s+l.x*y+c.x*m,y:n+l.y*y+c.y*m},{x:s+c.x*m,y:n+c.y*m}],this.drawZone(),this.updateControlButtonsPosition()}setupClickHandler(){this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.isEditingEnabled()||(i=(e=this.zoneEvents)==null?void 0:e.onClick)==null||i.call(e,this.getZoneData())},stopPropagation:!1})}drawZone(e=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.updateOutlineBorder(),this.updateMoveLine(),this.updateSizeText(e))}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e)}updateMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateZoneSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,ROTATE:s,SCALE:n}=Ct.BUTTON_INDICES,o=this.calculateMoveButtonPosition(),a=[{button:this.deleteButton,point:e[i]},{button:this.scaleButton,point:e[n]},{button:this.moveButton,point:o}];this.rotateButton&&a.push({button:this.rotateButton,point:e[s]}),a.forEach(({button:h,point:l})=>h.position.set(l.x,l.y))}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,!e&&this.getCurrentOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=e,this.moveLine.visible=e,this.sizeText&&(this.sizeText.visible=e),e&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition()),this.controlFill.setInteractionEnabled(e),this.updateBorderStyle(e?this.zoneConfig.editing:this.zoneConfig.normal),this.zIndex=e?1e3:0}updateBorderStyle(e){this.zoneBorder.updateStyle({isDashed:e.isDashed,dashArray:e.dashArray})}getCurrentOperationState(){var o,a,h;const e=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:e,isScaling:i,isRotating:s,isMoving:n,hasAnyOperation:e||i||s||n}}stopAllOperations(){var e,i,s;this.controlFill.stopDragging(),(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}stopDragging(){this.controlFill.stopDragging()}stopScaling(){var e;(e=this.scaleButton)==null||e.stopScaling()}stopRotating(){var e;(e=this.rotateButton)==null||e.stopRotation()}stopMoving(){var e;(e=this.moveButton)==null||e.stopMoving()}isCurrentlyDragging(){return this.controlFill.isCurrentlyDragging()}isCurrentlyScaling(){var e;return((e=this.scaleButton)==null?void 0:e.isCurrentlyScaling())||!1}isCurrentlyRotating(){var e;return((e=this.rotateButton)==null?void 0:e.isCurrentlyRotating())||!1}isCurrentlyMoving(){var e;return((e=this.moveButton)==null?void 0:e.isCurrentlyMoving())||!1}updateZoneData(e){const i=this.validateAndCorrectZoneSize(e.points),s=bs(i);this.zoneData={...e,points:s},this.drawZone(),this.updateControlButtonsPosition(),this.updateEditState()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var e,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(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(Ct,"BUTTON_INDICES",{REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0});let Li=Ct;class Or extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"forbiddenSweepZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickForbiddenSweepZone)==null||n.call(s,i)}}})}static create(t,e){return new Or(t,{zoneData:e})}}class Gr extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"forbiddenMopZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickForbiddenMopZone)==null||n.call(s,i)}}})}static create(t,e){return new Gr(t,{zoneData:e})}}class Wr extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"cleanZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveCleanZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateCleanZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickCleanZone)==null||n.call(s,i)}}})}static create(t,e){return new Wr(t,{zoneData:e})}}class Ue extends H{constructor(e,i){super();g(this,"lineOptions");g(this,"strokeContext",null);g(this,"drawDashLine",()=>{const{start:e,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,e.x,e.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=e,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(e,i,s,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){e.moveTo(i,s),e.lineTo(n,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let w=0;w<x;w++){const C=w*S,k=C+v;if(C>=d)break;const M=Math.min(k,d),T=i+C*b,_=s+C*P,I=i+M*b,B=s+M*P;e.moveTo(T,_),e.lineTo(I,B)}}updatePoints(e,i){this.lineOptions.start=e,this.lineOptions.end=i,this.drawDashLine()}updateStyle(e){this.lineOptions.style={...this.lineOptions.style,...e},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Vt=class Vt extends L{constructor(e){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,"throttledUpdateOutline");g(this,"throttledHandleScaleChange");g(this,"wallLineClickHandler",null);g(this,"handleRemove",()=>{var e,i;(i=(e=this.wallEvents).onRemove)==null||i.call(e,this.wallData.id)});g(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(e=>({...e}))});g(this,"finalizeOperation",()=>{var e,i;this.initialWallPoints=[],(i=(e=this.wallEvents).onUpdate)==null||i.call(e,this.getWallData())});g(this,"handleScaleStart",()=>{this.initializeOperation();const e=this.calculateOutlinePoints();e.length>Vt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...e[Vt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});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",e=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(e.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const 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",e=>{this.isEditingEnabled()&&(e.stopPropagation(),this.startDragging(e))});g(this,"handleDragPointerMove",e=>{!this.isDragging||!this.dragStartPosition||this.handleMove(e)});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={}}=e;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=At(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=At(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)}validateAndCorrectWallLength(e){if(e.length<2)return e;const[i,s]=e,n=this.appService.metersToPixels(this.wallConfig.minWidth),o=Q(i,s);if(o>=n)return e;if(o===0)return[i,{x:i.x+n,y:i.y}];const a=pt(q(i,s));return[i,{x:i.x+a.x*n,y:i.y+a.y*n}]}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(e=!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()),e&&this.setupWallLineInteraction()}createLengthText(){const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e),s=new Ui(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:e}=this.wallData;if(e.length<2)return 0;const i=Q(e[0],e[1]);return this.appService.pixelsToMeters(i)}formatLengthText(e){const i=this.appService.metersToDisplayUnit(e),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:e}=this.wallData;if(e.length<2)return{x:0,y:0};const[i,s]=e,n=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return Jl(i,s,n)}calculateTextRotation(){const{points:e}=this.wallData;if(e.length<2)return 0;const[i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(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 e=this.calculateOutlinePoints();return new Nt(this.appService,{points:e,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);return new Nt(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(e){const i=e||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),n=dy(i[0],i[1],s);return[n[3],n[2],n[1],n[0]]}calculateMoveLinePoints(e){if(e.length<4)return[];const{MOVE:i}=Vt.BUTTON_INDICES,s=e[i],n=this.calculateMoveButtonPosition();return[s,n]}calculateMoveButtonPosition(){const{moveButtonOffset:e}=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(e);return Is(n,a,o,h)}createControlButtons(){const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES;this.removeButton=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,getTargetPoints:()=>this.calculateOutlinePoints(),getButtonIndex:()=>s,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[s].x,e[s].y);const n=this.calculateMoveButtonPosition();this.moveButton=new Fs(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(e){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=q(s,a),c={x:e.x-l.x,y:e.y-l.y},d=q(n,c),u=Q(n,c),p=this.appService.metersToPixels(this.wallConfig.minWidth);let f;if(u<p)if(u===0)f={x:n.x+p,y:n.y};else{const y=pt(d);f={x:n.x+y.x*p,y:n.y+y.y*p}}else f=c;this.wallData.points=[n,f],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(e,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:e}=this.wallData;e.length<2||(this.wallLine instanceof Ue?this.wallLine.updatePoints(e[0],e[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const e=this.calculateTextPosition();this.lengthText.position.set(e.x,e.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e);const i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES,n=this.calculateMoveButtonPosition();this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton.position.set(e[s].x,e[s].y),this.moveButton.position.set(n.x,n.y)}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.lengthText&&(this.lengthText.visible=e),e&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=e?1e3:0}createSolidLine(e,i,s,n){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(e.x,e.y),o.lineTo(i.x,i.y),o.stroke({color:n,width:a}),o}updateWallLineStyle(){const e=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:n,lineColor:o}=this.wallConfig,a=e?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 e=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=e.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 e=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),e?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new 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:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}startDragging(e){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(e.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.appService.emitter.emit("gestureHijackStart",e)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:e}=this.wallData;if(e.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),n=tc(e[0],e[1],s);if(n.length===0)return;const o=new Te(n);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(e){this.wallData={...e,points:this.validateAndCorrectWallLength(e.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var e,i,s,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),(e=this.wallLineClickHandler)==null||e.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 nr=Vt;class Ur extends L{constructor(e){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",e=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("spot-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartMousePosition.x,n=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var e,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(e=this.spotEvents).onUpdate)==null||i.call(e,this.getSpotData())});const{appService:i,spotData:s,events:n={}}=e;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=At(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:e}=this.spotConfig;if(e===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.metersToPixels(e)/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const e=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(e),this.addChild(this.controlFill),this.spotBorder=this.createBorder(e),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.drawSpot()}createControlFill(e){const i=this.isEditingEnabled();return new Lr(this.appService,{points:e,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(e){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new Nt(this.appService,{points:e,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const e=new Xt(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.eventMode="static",this.setupIconDrag(e),e.visible=!1,e}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s}=this.spotConfig;await e.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)})),e.visible=this.shouldShowIcon()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupIconDrag(e){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))};e.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 e=this.calculateSpotSizeText(),i=new Ui(this.appService,{text:e,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.spotConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotSizeText(){const{size:e}=this.spotConfig,i=this.appService.metersToDisplayUnit(e),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const e=this.calculateRectanglePoints();if(e.length<4)return{x:0,y:0};const[i,s,n,o]=e,{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(e,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+e,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const e=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new vt(e,{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 e=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(e),this.spotBorder&&this.spotBorder.updatePoints(e)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText()}updateSizeText(){if(!this.sizeText)return;const e=this.calculateSpotSizeText();this.sizeText.updateText(e),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y)}updateEditState(){const e=this.isEditingEnabled(),i=e?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=e&&this.spotConfig.showText),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(e),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=e?1e3:0}updateSpotData(e){this.spotData={...e},this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var e,i,s,n,o;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.centerIcon&&this.spotConfig.size===0&&this.centerIcon.removeAllListeners(),(i=this.controlFill)==null||i.destroy(),(s=this.spotBorder)==null||s.destroy(),(n=this.centerIcon)==null||n.destroy(),(o=this.sizeText)==null||o.destroy(),super.destroy()}static create(e,i){return new Ur({appService:e,spotData:i,events:{onUpdate:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onUpdateSpot)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onClickSpot)==null||o.call(n,s)}}})}}class $x extends pc{constructor(e){const{appService:i,wayPointData:s,order:n,events:o={}}=e;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 e=new Xt(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.anchor.set(.5,1),e.eventMode="static",this.setupIconDrag(e),e}async loadIconTexture(e){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:n}=s,o=i?"wayPointActive":"wayPoint";await e.loadTextureAndSetSize(o,{width:n,height:n,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),e.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:n}=i;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Es({text:this.order.toString(),style:new de({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(e){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"))};e.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 e,i;this.appService.emitter.emit("suppressMapClick"),(i=(e=this.wayPointEvents).onClick)==null||i.call(e,this.wayPointData)}})}updateWayPoint(e){this.wayPointData=e,this.drawWayPoint()}updateOrder(e){this.order=e,this.orderText&&(this.orderText.text=e.toString())}getWayPointData(){return{...this.wayPointData}}drawWayPoint(){this.position.set(this.wayPointData.point.x,this.wayPointData.point.y),this.orderContainer&&this.updateOrderPosition()}updateEditState(){if(this.loadIconTexture(this.icon),this.orderContainer&&this.orderText&&this.orderBackground){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal;this.orderText.style=new de({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor: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 Ya extends H{constructor(e,i){super();g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"initialPosition");g(this,"handleDragPointerMove",e=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,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 e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});g(this,"handleDragCancel",()=>{var i,s;if(!this.isDragging)return;const e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=e,this.options=i,this.initialPosition={...i.position},this.position.set(i.position.x,i.position.y),this.eventMode="static",this.cursor="pointer",this.setupEvents(),this.draw(),this.setupDragEventListeners()}draw(){const e=this.appService,{config:i}=this.options,s=e.getApp().toFixedSize(i.endPointSize),n=e.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 e=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),n=e.getApp().toFixedSize(s);this.hitArea=new Ts(0,0,n)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}handlePointerDown(e){e.stopPropagation(),this.startDragging(e)}startDragging(e){var s,n;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(e.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",e)}updatePosition(e){this.position.set(e.x,e.y),this.initialPosition={...e}}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 Qx extends L{constructor(e){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(e=>({...e})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});g(this,"handleEndPointDragMove",(e,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[e]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});g(this,"handleEndPointDragEnd",()=>{var e,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints())});g(this,"handleDashLinePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});g(this,"handleDragPointerMove",e=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,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 e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});g(this,"handleDragCancel",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});g(this,"handleScaleChange",()=>{var e,i;(e=this.startEndPoint)==null||e.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:n,events:o={}}=e;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=At(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener(),this.setupDragEventListeners()}validateDividerPoints(e){if(e.length>=2)return e.slice(0,2);const i=e[0]||{x:0,y:0},s={x:i.x+50,y:i.y};return[i,s]}createDefaultdividerPoints(){if(!this.roomGeometry)return A.warn("Room geometry not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const e=this.appService.getApp().mapState;if(!e)return A.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 Sy(o,a,h,n).map(c=>({x:c.x-e.origin.x,y:c.y-e.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const e=this.endPoints;if(e.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:n}=this.dividerConfig;this.dashLine=new Ue(this.appService,{start:e[0],end:e[1],style:{color:n.toString(),width:i,dashArray:s}})}createEndPoints(){const e=this.endPoints;this.startEndPoint=new Ya(this.appService,{position:e[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new Ya(this.appService,{position:e[1],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(1,i),onDragEnd:this.handleEndPointDragEnd})}setupDashLineInteraction(){this.dashLine&&(this.setupDashLineHitArea(),this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.dashLine.on("pointerdown",this.handleDashLinePointerDown))}setupDashLineHitArea(){if(!this.dashLine)return;const e=this.endPoints;if(e.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),n=tc(e[0],e[1],s);if(n.length===0)return;const o=new Te(n);this.dashLine.hitArea=o}startDragging(e){this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialDividerPoints=this.endPoints.map(s=>({...s})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-drag",!0),this.appService.emitter.emit("gestureHijackStart",e)}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const e=this.endPoints;e.length<2||!this.dashLine||this.dashLine.updatePoints(e[0],e[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(e);this.solidLine.clear(),this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke()}updateEndPoints(){const e=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(e[0]),this.endEndPoint&&this.endEndPoint.updatePosition(e[1])}registerScaleListener(){const{emitter:e}=this.appService;e.on("antiScale",this.throttledHandleScaleChange)}getDividerEndPoints(){return[...this.endPoints]}getEffectiveDividerPoints(){return this.solidLinePoints?[...this.solidLinePoints]:null}calculateAndCreateSolidLine(){if(this.clearSolidLine(),typeof this.roomId!="number"||!this.getRoomGraphics())return;const i=this.calculateLineRoomIntersection();i&&i.length>=2&&(this.solidLinePoints=[i[0],i[i.length-1]],this.createSolidLine())}getRoomGraphics(){const e=this.appService.mapManager.roomFill;return!e||typeof this.roomId!="number"?null:e.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const e=this.endPoints;if(e.length<2||typeof this.roomId!="number")return null;const[i,s]=e,n=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(n||o)return null;const a=oy(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:vy(l,c,.5)}isPointInRoomFill(e){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:e.x+i.origin.x,y:e.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(e){e.x-=.5,e.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const n=s.getRasterRoomData(this.roomId);if(!n)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(e.x),h=Math.round(e.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<n.pixelIndices.length;c++)if(n.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(e){const i={x:Math.round(e.x),y:Math.round(e.y)},s=this.appService.getApp().mapState,n=this.appService.mapManager.getRoomById(this.roomId);return!s||!n||!n.outlinePoints?!1:Rt(i,n.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:e}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const 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!xy(n,o,e.x,e.y,e.width,e.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:e}=this.appService.dividerConfig;e&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var e,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.endPoints)}updateComponents(){const e=this.endPoints;e.length>=2&&(this.dashLine.updatePoints(e[0],e[1]),this.startEndPoint.position.set(e[0].x,e[0].y),this.endEndPoint.position.set(e[1].x,e[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(e);this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke(),this.addChildAt(this.solidLine,0)}clearSolidLine(){this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.solidLinePoints=null}updatedividerPoints(e){this.endPoints=this.validateDividerPoints(e),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var e,i,s;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(),(e=this.dashLine)==null||e.destroy(),(i=this.startEndPoint)==null||i.destroy(),(s=this.endEndPoint)==null||s.destroy(),super.destroy()}}const ps=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","wayPoint","divider"];function Jx(r){if(!r||r.length===0)return[...ps];const t=new Set,e=[];for(const i of r){if(!ps.includes(i)){A.warn(`[ControlsManager] Unknown control render order item: ${i}`);continue}t.has(i)||(t.add(i),e.push(i))}for(const i of ps)t.has(i)||e.push(i);return e}class t0{constructor(t){g(this,"forbiddenSweepZoneMap",new Map);g(this,"forbiddenMopZoneMap",new Map);g(this,"cleanZoneMap",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",[]);this.appService=t,this.initializeControlContainers();const e=U(t.runtime,"editingForbiddenSweepZoneIds",d=>{A.log(`[runtime] editingForbiddenSweepZoneIds: ${d}`),this.updateZonesEditState(this.forbiddenSweepZoneMap)}),i=U(t.runtime,"editingForbiddenMopZoneIds",d=>{A.log(`[runtime] editingForbiddenMopZoneIds: ${d}`),this.updateZonesEditState(this.forbiddenMopZoneMap)}),s=U(t.runtime,"editingCleanZoneIds",d=>{A.log(`[runtime] editingCleanZoneIds: ${d}`),this.updateZonesEditState(this.cleanZoneMap)}),n=U(t.runtime,"editingVirtualWallIds",d=>{A.log(`[runtime] editingVirtualWallIds: ${d}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),o=U(t.runtime,"editingSpotIds",d=>{A.log(`[runtime] editingSpotIds: ${d}`),this.updateSpotsEditState(this.spotMap)}),a=U(t.runtime,"editingWayPointIds",d=>{A.log(`[runtime] editingWayPointIds: ${d}`),this.updateWayPointsEditState(this.wayPointMap)}),h=U(t.runtime,"dividingRoomId",d=>{A.log(`[runtime] dividingRoomId: ${d}`),this.handleDividingRoomIdChange(d)}),l=U(t.runtime,"unit",d=>{A.log(`[runtime] unit changed: ${d}`),this.handleUnitChange()}),c=U(t.runtime,"unitLabel",d=>{A.log(`[runtime] unitLabel changed: ${d}`),this.handleUnitChange()});this.unsubscribeFns.push(e,i,s,n,o,a,h,l,c)}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(Ne);s&&s.position.set(t,e)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const t=this.appService.appContainer.getLayer(Ne);if(!t){A.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const e of ps){const i=new L;i.label=`controls:${e}`,this.controlContainers.set(e,i),t.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const t=this.appService.appContainer.getLayer(Ne);if(!t)return;Jx(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const n=this.controlContainers.get(i);n&&(n.zIndex=s)}),t.sortableChildren=!0,t.sortChildren()}addToControlLayer(t,e){let i=this.controlContainers.get(t);if(!i){const s=this.appService.appContainer.getLayer(Ne);if(!s){A.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new L,i.label=`controls:${t}`,this.controlContainers.set(t,i),s.addChild(i),this.applyRenderOrder()}i.addChild(e)}drawForbiddenSweepZones(t){this.drawZones(t,this.forbiddenSweepZoneMap,e=>Or.create(this.appService,e),"forbiddenSweepZone")}getForbiddenSweepZones(){return this.getZonesData(this.forbiddenSweepZoneMap)}clearAllForbiddenSweepZones(){this.clearAllZones(this.forbiddenSweepZoneMap)}drawForbiddenMopZones(t){this.drawZones(t,this.forbiddenMopZoneMap,e=>Gr.create(this.appService,e),"forbiddenMopZone")}getForbiddenMopZones(){return this.getZonesData(this.forbiddenMopZoneMap)}clearAllForbiddenMopZones(){this.clearAllZones(this.forbiddenMopZoneMap)}drawCleanZones(t){this.drawZones(t,this.cleanZoneMap,e=>Wr.create(this.appService,e),"cleanZone")}getCleanZones(){return this.getZonesData(this.cleanZoneMap)}clearAllCleanZones(){this.clearAllZones(this.cleanZoneMap)}drawVirtualWalls(t){var n;const e=this.appService,i=this.virtualWallMap,s=new Set(t.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));t.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new nr({appService:e,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickVirtualWall)==null||d.call(c,l)}}});i.set(o.id,h),this.addToControlLayer("virtualWall",h)}})}getVirtualWalls(){return this.getWallsData(this.virtualWallMap)}clearAllVirtualWalls(){this.clearAllWalls(this.virtualWallMap)}drawSpots(t){const e=this.spotMap;if(!t||t.length===0){this.clearAllSpotsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(n=>n.id));for(const n of i)s.has(n)||this.removeSpot(n,e);t.forEach(n=>{const o=e.get(n.id);o?this.isSpotDataEqual(o.getSpotData(),n)||o.updateSpotData(n):this.addNewSpot(n,e)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}drawZones(t,e,i,s){if(!t||t.length===0){this.clearAllZones(e);return}const n=new Set(e.keys()),o=new Set(t.map(a=>a.id));for(const a of n)o.has(a)||this.removeZone(a,e);t.forEach(a=>{const h=e.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,e,i,s)})}addNewZone(t,e,i,s){const n=i(t);e.set(t.id,n),this.addToControlLayer(s,n)}removeZone(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getZonesData(t){const e=[];return t.forEach(i=>{e.push(i.getZoneData())}),e}clearAllZones(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateZonesEditState(t){t.forEach(e=>{e.updateEditState()})}updateVirtualWallsEditState(t){t.forEach(e=>{e.updateEditingState()})}isZoneDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],n=e.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}getWallsData(t){return Array.from(t.values()).map(e=>e.getWallData())}clearAllWalls(t){for(const e of t.values())e.destroy();t.clear()}isWallDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],n=e.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}addNewSpot(t,e){const i=Ur.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("spot",i)}removeSpot(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getSpotsData(t){const e=[];return t.forEach(i=>{e.push(i.getSpotData())}),e}clearAllSpotsInternal(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateSpotsEditState(t){t.forEach(e=>{e.updateEditState()})}isSpotDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}drawWayPoints(t){A.log("[ControlsManager] drawWayPoints",t);const e=Array.from(this.wayPointMap.keys()),i=t.map(n=>n.id);e.filter(n=>!i.includes(n)).forEach(n=>{this.removeWayPoint(n,this.wayPointMap)}),t.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(){A.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(t,e,i){var o,a;const s=this.appService,n=new $x({appService:s,wayPointData:t,order:e,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(t.id,n),this.addToControlLayer("wayPoint",n)}removeWayPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getWayPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getWayPointData())}),e}clearAllWayPointsInternal(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateWayPointsEditState(t){t.forEach(e=>{e.onEditStateChange()})}isWayPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(t){if(t==null||t===-1){this.clearDivider();return}if(!this.getRoomGeometry(t)){this.clearDivider();return}this.createDefaultDivider(t)}getRoomGeometry(t){return this.appService.mapManager.getRoomById(t)}createDefaultDivider(t){const e=this.appService;this.clearDivider(),this.divider=new Qx({appService:this.appService,roomId:t,events:{onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateDivider)==null||n.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var t;this.divider&&((t=this.divider.parent)==null||t.removeChild(this.divider),this.divider.destroy(),this.divider=null)}getDividerEndPoints(){return this.divider?this.divider.getDividerEndPoints():null}getEffectiveDividerPoints(){return this.divider?this.divider.getEffectiveDividerPoints():null}handleUnitChange(){A.debug("[ControlsManager] Unit changed, refreshing all size texts"),this.forbiddenSweepZoneMap.forEach(t=>{t.refreshDisplay()}),this.forbiddenMopZoneMap.forEach(t=>{t.refreshDisplay()}),this.cleanZoneMap.forEach(t=>{t.refreshDisplay()}),this.virtualWallMap.forEach(t=>{t.refreshDisplay()}),this.spotMap.forEach(t=>{t.refreshDisplay()})}destroy(){this.clearAllForbiddenSweepZones(),this.clearAllForbiddenMopZones(),this.clearAllCleanZones(),this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearDivider(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.controlContainers.forEach(t=>{t.removeFromParent(),t.destroy({children:!0})}),this.controlContainers.clear()}}class e0 extends Xt{constructor(e,i){super(e);g(this,"objectData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);this.appService=e,this.objectData=i}async initializeSprite(){const e=this.appService.detectedObjectConfig,i=this.objectData.width||e.width,s=this.objectData.height||e.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(e.anchor.x,e.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)}),e.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickDetectedObject)==null||i.call(e,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(e){const i=this.objectData;this.objectData=e;const s=this.appService.detectedObjectConfig;if(i.src!==e.src){const n=e.width||s.width,o=e.height||s.height;await this.loadTextureAndSetSize(e.src,{width:n,height:o})}if(i.width!==e.width||i.height!==e.height){const n=e.width||s.width,o=e.height||s.height;this.setFixedSize(n,o)}this.position.set(e.x,e.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(e){return this.objectData.id===e.id&&this.objectData.src===e.src&&this.objectData.x===e.x&&this.objectData.y===e.y&&this.objectData.width===e.width&&this.objectData.height===e.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class i0{constructor(t){g(this,"detectedObjectMap",new Map);g(this,"unsubscribeShowDetectedObjects",null);this.appService=t,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=U(this.appService.runtime,"showDetectedObjects",e=>{this.applyLayerVisibility(e)})}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(We);s&&s.position.set(t,e)}async drawDetectedObjects(t){if(!t||t.length===0){this.clearAllDetectedObjects();return}const e=new Set(t.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)e.has(s)||this.removeDetectedObject(s);for(const s of t){const n=this.detectedObjectMap.get(s.id);n?n.isSameData(s)||await n.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(We);e&&(e.visible=t)}clearAllDetectedObjects(){const t=this.appService;this.detectedObjectMap.forEach(e=>{t.appContainer.removeFromLayer(We,e),e.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(t){const e=this.appService,i=new e0(this.appService,t);await i.initializeSprite(),this.detectedObjectMap.set(t.id,i),e.appContainer.addToLayer(We,i)}removeDetectedObject(t){const e=this.appService,i=this.detectedObjectMap.get(t);i&&(e.appContainer.removeFromLayer(We,i),i.destroy(),this.detectedObjectMap.delete(t))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var ke={},gc={},te={};Object.defineProperty(te,"__esModule",{value:!0});te.loop=te.conditional=te.parse=void 0;var s0=function r(t,e){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:i;if(Array.isArray(e))e.forEach(function(o){return r(t,o,i,s)});else if(typeof e=="function")e(t,i,s,r);else{var n=Object.keys(e)[0];Array.isArray(e[n])?(s[n]={},r(t,e[n],i,s[n])):s[n]=e[n](t,i,s,r)}return i};te.parse=s0;var n0=function(t,e){return function(i,s,n,o){e(i,s,n)&&o(i,t,s,n)}};te.conditional=n0;var r0=function(t,e){return function(i,s,n,o){for(var a=[],h=i.pos;e(i,s,n);){var l={};if(o(i,t,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};te.loop=r0;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 o0=function(t){return{data:t,pos:0}};ut.buildStream=o0;var mc=function(){return function(t){return t.data[t.pos++]}};ut.readByte=mc;var a0=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+t]}};ut.peekByte=a0;var zs=function(t){return function(e){return e.data.subarray(e.pos,e.pos+=t)}};ut.readBytes=zs;var h0=function(t){return function(e){return e.data.subarray(e.pos,e.pos+t)}};ut.peekBytes=h0;var l0=function(t){return function(e){return Array.from(zs(t)(e)).map(function(i){return String.fromCharCode(i)}).join("")}};ut.readString=l0;var c0=function(t){return function(e){var i=zs(2)(e);return t?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};ut.readUnsigned=c0;var d0=function(t,e){return function(i,s,n){for(var o=typeof e=="function"?e(i,s,n):e,a=zs(t),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};ut.readArray=d0;var u0=function(t,e,i){for(var s=0,n=0;n<i;n++)s+=t[e+n]&&Math.pow(2,i-n-1);return s},p0=function(t){return function(e){for(var i=mc()(e),s=new Array(8),n=0;n<8;n++)s[7-n]=!!(i&1<<n);return Object.keys(t).reduce(function(o,a){var h=t[a];return h.length?o[a]=u0(s,h.index,h.length):o[a]=s[h.index],o},{})}};ut.readBits=p0;(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var t=te,e=ut,i={blocks:function(u){for(var p=0,f=[],y=u.data.length,m=0,x=(0,e.readByte)()(u);x!==p&&x;x=(0,e.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;f.push((0,e.readBytes)(S)(u)),m+=S;break}f.push((0,e.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,t.conditional)({gce:[{codes:(0,e.readBytes)(2)},{byteSize:(0,e.readByte)()},{extras:(0,e.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,e.readUnsigned)(!0)},{transparentColorIndex:(0,e.readByte)()},{terminator:(0,e.readByte)()}]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),n=(0,t.conditional)({image:[{code:(0,e.readByte)()},{descriptor:[{left:(0,e.readUnsigned)(!0)},{top:(0,e.readUnsigned)(!0)},{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{lct:(0,e.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,e.readArray)(3,function(d,u,p){return Math.pow(2,p.descriptor.lct.size+1)})},function(d,u,p){return p.descriptor.lct.exists}),{data:[{minCodeSize:(0,e.readByte)()},i]}]},function(d){return(0,e.peekByte)()(d)===44}),o=(0,t.conditional)({text:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{preData:function(u,p,f){return(0,e.readBytes)(f.text.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,t.conditional)({application:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{id:function(u,p,f){return(0,e.readString)(f.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,t.conditional)({comment:[{codes:(0,e.readBytes)(2)},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,e.readString)(3)},{version:(0,e.readString)(3)}]},{lsd:[{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{gct:(0,e.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,e.readByte)()},{pixelAspectRatio:(0,e.readByte)()}]},(0,t.conditional)({gct:(0,e.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,t.loop)([s,a,h,n,o],function(d){var u=(0,e.peekByte)()(d);return u===33||u===44})}],c=l;r.default=c})(gc);var Ls={};Object.defineProperty(Ls,"__esModule",{value:!0});Ls.deinterlace=void 0;var f0=function(t,e){for(var i=new Array(t.length),s=t.length/e,n=function(u,p){var f=t.slice(p*e,(p+1)*e);i.splice.apply(i,[u*e,e].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};Ls.deinterlace=f0;var Os={};Object.defineProperty(Os,"__esModule",{value:!0});Os.lzw=void 0;var g0=function(t,e,i){var s=4096,n=-1,o=i,a,h,l,c,d,u,p,w,f,y,P,m,C,k,T,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=t,h=1<<m,d=h+1,a=h+2,p=n,c=m+1,l=(1<<c)-1,f=0;f<h;f++)S[f]=0,v[f]=f;var P,w,C,k,M,T;for(P=w=C=k=M=T=0,y=0;y<o;){if(k===0){if(w<c){P+=e[T]<<w,w+=8,T++;continue}if(f=P&l,P>>=c,w-=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,C=f;continue}for(u=f,f==a&&(b[k++]=C,f=p);f>h;)b[k++]=v[f],f=S[f];C=v[f]&255,b[k++]=C,a<s&&(S[a]=p,v[a]=C,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};Os.lzw=g0;Object.defineProperty(ke,"__esModule",{value:!0});var yc=ke.decompressFrames=ke.decompressFrame=xc=ke.parseGIF=void 0,m0=b0(gc),y0=te,x0=ut,S0=Ls,v0=Os;function b0(r){return r&&r.__esModule?r:{default:r}}var w0=function(t){var e=new Uint8Array(t);return(0,y0.parse)((0,x0.buildStream)(e),m0.default)},xc=ke.parseGIF=w0,A0=function(t){for(var e=t.pixels.length,i=new Uint8ClampedArray(e*4),s=0;s<e;s++){var n=s*4,o=t.pixels[s],a=t.colorTable[o]||[0,0,0];i[n]=a[0],i[n+1]=a[1],i[n+2]=a[2],i[n+3]=o!==t.transparentIndex?255:0}return i},Sc=function(t,e,i){if(!t.image){console.warn("gif frame does not have associated image.");return}var s=t.image,n=s.descriptor.width*s.descriptor.height,o=(0,v0.lzw)(s.data.minCodeSize,s.data.blocks,n);s.descriptor.lct.interlaced&&(o=(0,S0.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=e,t.gce&&(a.delay=(t.gce.delay||10)*10,a.disposalType=t.gce.extras.disposal,t.gce.extras.transparentColorGiven&&(a.transparentIndex=t.gce.transparentColorIndex)),i&&(a.patch=A0(a)),a};ke.decompressFrame=Sc;var C0=function(t,e){return t.frames.filter(function(i){return i.image}).map(function(i){return Sc(i,t.gct,e)})};yc=ke.decompressFrames=C0;class Gs{constructor(t){if(!t||!t.length)throw new Error("Invalid frames");const[{texture:{width:e,height:i}}]=t;this.width=e,this.height=i,this.frames=t,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const t of this.textures)t.destroy(!0);for(const t of this.frames)t.texture=null;this.frames.length=0,this.textures.length=0,Object.assign(this,{frames:null,textures:null,width:0,height:0,duration:0,totalFrames:0})}static from(t,e){if(!t||t.byteLength===0)throw new Error("Invalid buffer");const i=S=>{let v=null;for(const b of S.frames)v=b.gce??v,"image"in b&&!("gce"in b)&&(b.gce=v)},s=xc(t);i(s);const n=yc(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}=e??{},x=1e3/y;for(let S=0;S<n.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:w,height:C,left:k,top:M}}=n[S];d.width=w,d.height=C,u.clearRect(0,0,w,C);const T=u.createImageData(w,C);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 I=j.get().createCanvas(_.width,_.height);I.getContext("2d").putImageData(_,0,0),o.push({start:p,end:p+b,texture:new G({source:new dr({resource:I,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new Gs(o)}}const P0={extension:E.Asset,detection:{test:async()=>!0,add:async r=>[...r,"gif"],remove:async r=>r.filter(t=>t!=="gif")},loader:{name:"gifLoader",id:"gif",test:r=>Mt.extname(r)===".gif"||r.startsWith("data:image/gif"),load:async(r,t)=>{const i=await(await j.get().fetch(r)).arrayBuffer();return Gs.from(i,t==null?void 0:t.data)},unload:async r=>{r.destroy()}}},vc=class rr extends jt{constructor(...t){const e=t[0]instanceof Gs?{source:t[0]}:t[0],{source:i,fps:s,loop:n,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},rr.defaultOptions,e);super({texture:G.EMPTY,...u}),this.animationSpeed=1,this.loop=!0,this.duration=0,this.autoPlay=!0,this.dirty=!1,this._currentFrame=0,this._autoUpdate=!1,this._isConnectedToTicker=!1,this._playing=!1,this._currentTime=0,this.onRender=()=>this._updateFrame(),this.texture=i.textures[0],this.duration=i.frames[i.frames.length-1].end,this._source=i,this._playing=!1,this._currentTime=0,this._isConnectedToTicker=!1,Object.assign(this,{fps:s,loop: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,Ee.HIGH),this._isConnectedToTicker=!0),!this.loop&&this.currentFrame===this._source.frames.length-1&&(this._currentTime=0))}get progress(){return this._currentTime/this.duration}get playing(){return this._playing}update(t){var o,a;if(!this._playing)return;const e=this.animationSpeed*t.deltaTime/yt.targetFPMS,i=this._currentTime+e,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(t){t!==this._autoUpdate&&(this._autoUpdate=t,!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(t){this._updateFrameIndex(t),this._currentTime=this._source.frames[t].start}get source(){return this._source}_updateFrameIndex(t){var e;if(t<0||t>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${t}`);this._currentFrame!==t&&(this._currentFrame=t,this.dirty=!0,(e=this.onFrameChange)==null||e.call(this,t))}get totalFrames(){return this._source.totalFrames}destroy(t=!1){this.stop(),super.destroy(),t&&this._source.destroy();const e=null;this._source=e,this.onComplete=e,this.onFrameChange=e,this.onLoop=e}clone(){const t=new rr({source:this._source,autoUpdate:this._autoUpdate,loop:this.loop,autoPlay:this.autoPlay,animationSpeed:this.animationSpeed,onComplete:this.onComplete,onFrameChange:this.onFrameChange,onLoop:this.onLoop});return t.dirty=!0,t}};vc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let M0=vc;$.add(P0);class Hr extends M0{constructor(e,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=e,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(e){this.sizeFixed=e,this.baselineScale=1,e&&this.isFixedSizeSet?this.applySize():!e&&this.isFixedSizeSet&&this.applySize()}set width(e){if(this.isFixedSizeSet){A.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(e,this.fixedHeight||e)}set height(e){if(this.isFixedSizeSet){A.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||e,e)}get width(){return this.fixedWidth||super.width}get height(){return this.fixedHeight||super.height}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applySize(){if(!this.isFixedSizeSet||!this.texture||this.texture.width===0||this.texture.height===0)return;const e=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const n=e/s,o=i/s;super.scale.set(n,o)}else super.scale.set(e/this.baselineScale,i/this.baselineScale)}updateScale(e){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():e!==0&&super.scale.set(1/e))}static async createFromSrc(e,i,s){try{const n=await N.load(i),o=new Hr(e,{source:n});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(n){throw A.error(`Failed to load GIF "${i}":`,n),n}}draw(e,i){const{x:s,y:n,rotation:o=0}=e;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,n)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ge extends Hr{constructor(e,i,s){super(e,{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 e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.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=U(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;if(this.elementData=e,i.src!==e.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height);const s=e.anchor||{x:.5,y:.5},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(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5};return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class Mn extends Xt{constructor(e,i){super(e);g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"userRotation",0);this.appService=e,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.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=U(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.src!==e.src?await this.loadTextureAndSetSize(e.src,{width:e.width,height:e.height,sizeFixed:e.sizeFixed}):(i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height));const s=e.anchor||{x:.5,y:.5},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(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5};return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class _0 extends Fg{constructor(e,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=e,this.anchor.set(0,0),this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(e,i){this.userCenterX=e,this.userCenterY=i,this.updatePositionFromCenter()}setSizeFixed(e){this.sizeFixed=e,this.isFixedSizeSet&&(this.applyFixedSize(),this.updatePositionFromCenter())}getIsFixedSizeSet(){return this.isFixedSizeSet}updatePositionFromCenter(){if(!this.isFixedSizeSet){this.position.set(this.userCenterX,this.userCenterY);return}const i=this.appService.currentScale;let s,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(e){this.isFixedSizeSet&&e!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(e){return super.updateTransform(e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class ki extends _0{constructor(e,i){const s=document.createElement("div");ki.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(e,{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=U(this.appService.runtime,"mapRotation",e=>{this.applyRotation(e)}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupAutoSize(){this.element&&(this.element.style.width="auto",this.element.style.height="auto",this.waitForElementDimensions())}waitForElementInsertion(){if(!this.element)return;const e=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(e))};requestAnimationFrame(e)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e=>{var s;const i=e[0];i&&i.contentRect.width>0&&i.contentRect.height>0&&(this.setFixedSize(i.contentRect.width,i.contentRect.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement(),(s=this.resizeObserver)==null||s.disconnect(),this.resizeObserver=null)}),this.resizeObserver.observe(this.element)):this.pollForElementDimensions())}pollForElementDimensions(){if(!this.element)return;const e=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(e);return}const i=this.element.getBoundingClientRect();i.width>0&&i.height>0?(this.setFixedSize(i.width,i.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement()):requestAnimationFrame(e)};requestAnimationFrame(e)}showElement(){this.alpha=this.elementData.opacity??1,this.element.style.pointerEvents=this.elementData.interactive?"auto":"none",this.interactive=this.elementData.interactive??!1,this.elementData.interactive&&this.element&&(this.element.style.setProperty("-webkit-tap-highlight-color","transparent"),this.element.style.setProperty("-webkit-touch-callout","none")),this.appService.getApp().renderOnceNextFrame()}setupClickHandler(){this.element&&(this.domClickHandler=e=>{e.preventDefault(),e.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.htmlContent!==e.htmlContent&&this.element&&(this.element.innerHTML=e.htmlContent,(!e.width||!e.height)&&this.waitForElementDimensions()),(i.width!==e.width||i.height!==e.height)&&(e.width&&e.height?(this.setFixedSize(e.width,e.height),this.element&&(this.element.style.width=`${e.width}px`,this.element.style.height=`${e.height}px`)):this.setupAutoSize()),e.width&&e.height?this.setCenterPosition(e.x,e.y):this.getIsFixedSizeSet()?this.setCenterPosition(e.x,e.y):this.position.set(e.x,e.y),i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),this.userRotation=e.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=e.opacity??1,e.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(e){return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.htmlContent===e.htmlContent&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed}static setupDefaultStyles(e,i){const s={position:"relative",boxSizing:"border-box",webkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",background:"transparent",userSelect:"auto",webkitUserSelect:"auto"};i.width&&i.height?(s.width=`${i.width}px`,s.height=`${i.height}px`,s.overflow="hidden"):(s.width=i.width?`${i.width}px`:"auto",s.height=i.height?`${i.height}px`:"auto",s.overflow="visible"),Object.assign(e.style,s),e.style.setProperty("-webkit-tap-highlight-color","transparent"),e.style.setProperty("-webkit-touch-callout","none")}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null),this.debugMarker&&(this.debugMarker.destroy(),this.debugMarker=null),super.destroy()}}class T0{constructor(t){g(this,"customElementsMap",new Map);g(this,"gifTicker",null);g(this,"gifElements",new Set);this.appService=t}updatePositionByOrigin(t,e){const i=this.appService,s=i.appContainer.getLayer(Si),n=i.appContainer.getLayer(vi);s&&s.position.set(t,e),n&&n.position.set(t,e)}async drawCustomElements(t){if(!t||t.length===0){this.clearAllCustomElements();return}const e=new Set(t.map(n=>n.id)),i=Array.from(this.customElementsMap.keys());for(const n of i)e.has(n)||this.removeCustomElement(n);const s=t.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 t=this.appService;this.customElementsMap.forEach(e=>{e instanceof Ge?t.appContainer.removeFromLayer(vi,e):t.appContainer.removeFromLayer(Si,e),e.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(t){const e=this.appService;let i;switch(t.type){case"image":i=new Mn(this.appService,t);break;case"gif":{const s=await N.load(t.src);i=new Ge(this.appService,s,t);break}case"html":i=new ki(this.appService,t);break;default:throw new Error(`Unsupported custom element type: ${t.type}`)}await i.initialize(),this.customElementsMap.set(t.id,i),i instanceof Ge?(e.appContainer.addToLayer(vi,i),this.gifElements.add(i)):e.appContainer.addToLayer(Si,i)}removeCustomElement(t){const e=this.appService,i=this.customElementsMap.get(t);i&&(i instanceof Ge?(this.gifElements.delete(i),e.appContainer.removeFromLayer(vi,i)):e.appContainer.removeFromLayer(Si,i),i.destroy(),this.customElementsMap.delete(t))}isSameData(t,e){return t.getElementData().type!==e.type?!1:e.type==="image"&&t instanceof Mn||e.type==="gif"&&t instanceof Ge||e.type==="html"&&t instanceof ki?t.isSameData(e):!1}async updateElementData(t,e){if(e.type==="image"&&t instanceof Mn)await t.updateElementData(e);else if(e.type==="gif"&&t instanceof Ge)await t.updateElementData(e);else if(e.type==="html"&&t instanceof ki)await t.updateElementData(e);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var t;(t=this.gifTicker)!=null&&t.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new yt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var t;(t=this.gifTicker)!=null&&t.started&&(A.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const t=this.appService;if(this.gifElements.size===0)return;const e=t.getApp();e.renderer.render(e.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class k0 extends L{constructor(e,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=e,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:n}=e.roomConfig,{showRoomType:o}=e.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new de({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Es({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(e,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[e],{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(e){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(e)}layout(){if(!this.iconWrapper||!this.iconWrapper.visible){this.nameText.position.set(0,0);return}if(!(this.iconSprite&&this.iconSprite.visible||this.iconBg&&this.iconBg.visible)){this.nameText.position.set(0,0);return}const{gap:i=4,position:s="left"}=this.appService.roomConfig.type,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(e){this.nameText.text=e,this.layout()}refreshColor(e){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,e);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(e,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:n,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(n)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[e%s.nameInactive.length]:s.name[e%s.name.length];const a=s.nameNormal||s.name;return a[e%a.length]}async updateRoomType(e){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||e==null||!(i!=null&&i.assets)||!i.assets[e])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const n=this.appService.getRoomData(this.roomId),o=(n==null?void 0:n.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(e,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(e){if(this.iconWrapper)this.iconWrapper.visible=e,this.layout();else if(e){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(e){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),super.destroy(e)}}class R0 extends L{constructor(e,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=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.foldedIndicator=new H,this.foldedIndicator.visible=!1;const{property: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 Es({text:"",style:new de({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(e,i){const s=["cleanMode","suction","cistern","cleanTimes"];e.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(e){this.isDestroyed||this.destroyed||(await this.updateIcons(e),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(e,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return e[i]??null;if(e.customData&&i in e.customData){const n=e.customData[i];return typeof n=="number"?n:null}return null}getAssetAlias(e,i){const s={cleanMode:n=>`cleanMode_${n}`,suction:n=>`fan_${n}`,cistern:n=>`water_${n}`,cleanTimes:n=>`cleanTimes${n}`};return e in s?s[e](i):`custom_${e}_${i}`}shouldShowField(e,i,s){const{showRoomProperty:n}=this.appService.runtimeSnapshot;return!(s===null||!n||i==="cleanTimes"&&s<=0)}getDisplayElements(e){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,n=e.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(e,h);this.shouldShowField(e,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:n}}async updateIcons(e){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(e);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=e.colorIndex??this.roomIndex,m=this.getIconColor(y);this.orderBackground.clear(),this.orderBackground.setFillStyle({color:m}),this.orderBackground.circle(i/2,s/2,i/2).fill();const x=this.resolveOrderTextColor(y);this.orderText.style.fill=x,this.orderText.position.set(i/2,s/2)}else{const y=this.propertyIcons.get(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 e=this.appService.roomConfig,{container:i,foldable:s}=e.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:e,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+=e,d<h.length-1&&(u?l+=s.gapRight:l+=n)}),l+=o,l}calculateContentHeight(){const e=this.appService.roomConfig,{iconHeight:i,container:s}=e.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:e,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(e?s:0)}getTotalWidth(){if(this.isFolded){const{tailWidth:i}=this.appService.roomConfig.property.container,s=this.calculateContentWidth();return Math.min(i,s/2)}return this.calculateContentWidth()}async setFolded(e){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=e,e)this.background.visible=!1,this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:s})=>{s.visible=!1}),this.foldedIndicator.visible=!0,this.updateFoldedIndicator();else{this.background.visible=!0,this.foldedIndicator.visible=!1,this.foldedIndicator.position.set(0,0),this.updateBackground();const s=this.appService.getRoomData(this.roomId);s&&await this.updateIcons(s)}}isFoldedState(){const{foldable:e}=this.appService.roomConfig.property;return e?this.isFolded:!1}updateFoldedIndicator(){const e=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:n}=e.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(e){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[e%o.length]}return i.cleanOrder.color}getIconColor(e){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[e%n.length]:s[e%s.length];const l=o||s;return l[e%l.length]}refreshColor(){const e=this.appService.getRoomData(this.roomId),i=(e==null?void 0:e.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite: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:e})=>{e.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0}))}}class E0 extends L{constructor(e,i){super();g(this,"background");g(this,"checkmarkIcon");g(this,"bubble");g(this,"roomIndex");g(this,"roomId");this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon: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(e){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:n}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=n.includes(e.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(e){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:n}=i;if(e){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:e,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:n,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=e,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],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:e}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:n}=e;return i+n+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:e}=this.appService.roomConfig;return e.containerWidth}async refreshColor(){const e=this.appService.getRoomData(this.roomId);e&&await this.updateIndicator(e)}destroy(){var e;(e=this.checkmarkIcon)==null||e.destroy(),super.destroy({children:!0})}}class I0 extends L{constructor(e,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=e,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(e.currentScale),this.updateScaleBound=s=>this.updateScale(s),this.appService.emitter.on("antiScale",this.updateScaleBound),this.updateScale(this.appService.currentScale),i.centerPoint&&this.position.set(i.centerPoint.x,i.centerPoint.y),this.roomName=new k0(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=U(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(e){await this.createRoomProperty(e),await this.createRoomSelectionIndicator(e),this.updateLayout()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}initializeElasticScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=n:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i){e!==0&&this.scale.set(1/e);return}if(e===0)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=n:h=1;const c=1/e*h;Math.abs(this.targetElasticScale-h)>.01?(this.targetElasticScale=h,this.startScaleAnimation()):this.scale.set(c)}startScaleAnimation(){this.scaleAnimationBound||(this.scaleAnimationBound=this.animateScale.bind(this)),this.isAnimatingScale||(this.isAnimatingScale=!0,this.appService.getApp().ticker.add(this.scaleAnimationBound))}animateScale(){this.currentElasticScale+=(this.targetElasticScale-this.currentElasticScale)*.3;const 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:e,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=e&&(a.order||0)>0;let l=!1;if(i){const{displayOrders:c}=this.appService.roomConfig.property;l=c.some(d=>!!(d==="suction"&&a.suction!=null||d==="cistern"&&a.cistern!=null||d==="cleanMode"&&a.cleanMode!=null||d==="cleanTimes"&&a.cleanTimes>0||a.customData&&d in a.customData&&typeof a.customData[d]=="number"&&a.customData[d]!=null))}return h||l}shouldShowRoomSelectionIndicator(){const{enableRoomSelection:e,roomSelectionMode:i}=this.appService.runtimeSnapshot;return e&&i==="checkmark"}async updateRoomPropertyVisibility(){if(!this.roomProperty)return;if(!this.shouldShowRoomProperty())this.roomProperty.visible=!1;else{this.roomProperty.visible=!0;const i=this.appService.runtimeSnapshot.roomPropertyFoldIds.includes(this.roomId);await this.roomProperty.setFolded(i);const s=this.appService.getRoomData(this.roomId);s&&await this.roomProperty.updateProperty(s)}this.updateLayout()}async updateRoomSelectionIndicatorVisibility(){if(!this.roomSelectionIndicator)return;if(this.shouldShowRoomSelectionIndicator()){const i=this.appService.getRoomData(this.roomId);i&&await this.roomSelectionIndicator.updateIndicator(i)}else this.roomSelectionIndicator.visible=!1;this.updateLayout()}async createRoomProperty(e){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new R0(this.appService,e),await this.roomProperty.updateProperty(e),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(e){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new E0(this.appService,e),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,f;if(this.destroyed)return;const{property:{offsetY:e,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-e;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-e-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-e)}if(h&&this.roomSelectionIndicator){const y=this.roomSelectionIndicator.getTotalHeight(),m=this.roomSelectionIndicator.getTotalWidth();a&&((p=this.roomName)!=null&&p.position)?(this.roomSelectionIndicator.position.set(-m/2+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(e){this.roomName.updateName(e)}async updateRoomType(e){await this.roomName.updateRoomType(e),this.updateLayout()}updateRoomNameVisibility(e){this.roomName.visible=e,this.updateLayout()}updateRoomTypeVisibility(e){this.roomName.updateRoomTypeVisibility(e),this.updateLayout()}updatePosition(e){this.position.set(e.x,e.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var e,i,s,n;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.isAnimatingScale&&this.scaleAnimationBound&&(this.appService.getApp().ticker.remove(this.scaleAnimationBound),this.isAnimatingScale=!1),this.scaleAnimationBound=null,this.updateScaleBound&&(this.appService.emitter.off("antiScale",this.updateScaleBound),this.updateScaleBound=null),(i=this.roomProperty)==null||i.destroy(),this.roomProperty=null,(s=this.roomSelectionIndicator)==null||s.destroy(),this.roomSelectionIndicator=null,(n=this.roomName)==null||n.destroy(),super.destroy()}}class B0 extends L{constructor(e){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=e,this.appService.appContainer.addToLayer(Fr,this)}async createFloorTypes(e){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(e),n=[];for(const[o,a]of s)n.push(this.createMergedFloorType(o,a));await Promise.all(n)}groupRoomsByFloorType(e){const i=new Map,s=this.appService;return e.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(e,i){const s=this.appService,{assets:n,opacity:o,scale:a}=s.roomConfig.floorType,h=e%n.length,l=`floorType${h}`;if(!n[h]){A.warn(`No texture asset configured for floorType: ${e}`);return}const c=await N.load(l);if(!c){A.warn(`Floor material texture not found: ${l}`);return}const d=i.map(({graphics:m})=>m.getLocalBounds()),u=my(d),p=new Ss({texture:c,width:u.width,height:u.height});p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:f,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=f,this.addChild(p),this.floorTypeMap.set(e,p),this.floorTypeMasks.set(e,f),this.floorTypeContexts.set(e,y),this.floorTypeToRooms.set(e,new Set(i.map(({roomId:m})=>m)))}createMergedMask(e){const i=new L,s=[];return e.forEach(n=>{const o=new H,a=n.context.clone();o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(e=>{try{e.destroy({children:!0})}catch(i){A.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(e=>{try{e.forEach(i=>{try{i.destroy()}catch(s){A.warn("Error destroying cloned graphics context:",s)}})}catch(i){A.warn("Error destroying graphics contexts:",i)}}),this.floorTypeContexts.clear(),this.floorTypeMap.forEach(e=>{try{this.removeChild(e),e.destroy()}catch(i){A.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}class D0{constructor(t){g(this,"unsubscribeFns",[]);g(this,"roomInfoContainer",new L);g(this,"roomInfoMap",new Map);g(this,"roomDisplayMap",new Map);g(this,"roomFloorType");this.appService=t,this.roomFloorType=new B0(t),t.appContainer.addToLayer(lc,this.roomInfoContainer);const e=U(t.runtime,"showRoomFloorType",d=>{A.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=U(t.runtime,"showRoomProperty",d=>{A.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=U(t.runtime,"showRoomOrder",d=>{A.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),n=U(t.runtime,"roomPropertyFoldIds",d=>{A.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=U(t.runtime,"showRoomName",d=>{A.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=U(t.runtime,"showRoomType",d=>{A.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=U(t.runtime,"enableRoomSelection",d=>{A.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=U(t.runtime,"selectRoomIds",d=>{A.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=U(t.runtime,"roomSelectionMode",d=>{A.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(e,i,s,n,o,a,h,l,c)}async drawRoomProperty(t){const e=this.appService;return this.roomDisplayMap.clear(),t.forEach((i,s)=>{const n=e.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 t=Array.from(this.roomDisplayMap.values()).filter(e=>e.centerPoint!==null);this.clearRoomInfos(),await Promise.all(t.map(e=>this.createRoomInfo(e)))}async createRoomInfo(t){const e=new I0(this.appService,t);this.roomInfoContainer.addChild(e),this.roomInfoMap.set(t.id,e),await e.initialize(t)}updateRoomName(t,e){const i=this.roomInfoMap.get(t);i&&i.updateName(e)}async updateRoomType(t,e){const i=this.roomDisplayMap.get(t);i&&(i.type=e);const s=this.roomInfoMap.get(t);s&&await s.updateRoomType(e)}updateRoomPosition(t,e){const i=this.roomDisplayMap.get(t);i&&(i.centerPoint=e);const s=this.roomInfoMap.get(t);s&&s.updatePosition(e)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const t=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),t.forEach(e=>{try{e.destroy()}catch(i){A.warn(`[RoomManager] Error destroying RoomInfo for room ${e.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(t){return this.roomDisplayMap.get(t)}async refresh(){const t=this.appService;this.roomFloorType.clearFloorTypes(),this.roomDisplayMap.forEach((e,i)=>{const s=t.mapManager.getRoomById(i),n=(s==null?void 0:s.centerPoint)||null;if(e.centerPoint!==n){e.centerPoint=n;const a=this.roomInfoMap.get(i);a&&n&&a.updatePosition(n)}const o=s==null?void 0:s.colorIndex;if(e.colorIndex!==o&&o!==void 0){e.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 t=>{try{await t.updateRoomPropertyVisibility()}catch(e){console.warn(`[RoomManager] Failed to update room property visibility for room ${t.roomId}`,e)}}))}updateAllRoomNameVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomNameVisibility(t)})}updateAllRoomTypeVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomTypeVisibility(t)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.refreshColor()})}async updateFloorTypes(){const t=this.appService,e=t.mapManager.roomFill.getRoomGraphicsMap();e.size>0?(await this.roomFloorType.createFloorTypes(e),t.getApp().renderOnceNextFrame()):t.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}var Xa,Za;(Xa=navigator==null?void 0:navigator.userAgent)!=null&&Xa.includes("tuya-ark-ide")||((Za=navigator==null?void 0:navigator.userAgent)==null||Za.includes("miniProgram"));const F0=()=>{var i,s;if(!Ln.any)return!0;const r=navigator.userAgent.toLowerCase(),t=()=>{const n=navigator.deviceMemory;return n?n>=4:!0};let e=!1;if(/iphone|ipad|ipod/.test(r)){const n=(i=r.match(/os (\d+)_/))==null?void 0:i[1];e=(n?parseInt(n):0)>=12}else if(/android/.test(r)){const n=(s=r.match(/android (\d+)/))==null?void 0:s[1];e=(n?parseInt(n):0)>=10}return e&&t()};class z0 extends L{constructor(e,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(e)}async render(e){if(this.lastConfig=e,this.clear(),e.backgroundImage){await this.renderImage(e.backgroundImage,e.backgroundAlpha);return}if(e.backgroundGradient){this.renderGradient(e.backgroundGradient);return}if(e.backgroundColor!==void 0){this.renderSolidColor(e.backgroundColor,e.backgroundAlpha);return}A.warn("[Background] No background configuration provided")}clear(){this.graphics.clear(),this.sprite&&(this.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null)}renderSolidColor(e,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:e,alpha:i}),A.debug("[Background] Rendered solid color background",{color:e,alpha:i})}renderGradient(e){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),e.type==="linear"){const n=e.x0??0,o=e.y0??0,a=e.x1??1,h=e.y1??1,l=new Ot({type:"linear",start:{x:n,y:o},end:{x:a,y:h},colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(l),A.debug("[Background] Rendered linear gradient background",{x0:n,y0:o,x1:a,y1:h,colorStops:e.colorStops.length})}else if(e.type==="radial"){const n=e.cx??.5,o=e.cy??.5,a=e.r??.5,h=new Ot({type:"radial",center:{x:n,y:o},innerRadius:0,outerCenter:{x:n,y:o},outerRadius:a,colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(h),A.debug("[Background] Rendered radial gradient background",{cx:n,cy:o,r:a,colorStops:e.colorStops.length})}}async renderImage(e,i){var s,n,o,a;try{const h=await N.load(e.src);if(!h){A.error("[Background] Failed to load image:",e.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=e.fit||"cover",u=((n=e.position)==null?void 0:n.x)??.5,p=((o=e.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}e.repeat&&A.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),A.debug("[Background] Rendered image background",{src:e.src,fit:d,position:{x:u,y:p},spriteSize:{width:this.sprite.width,height:this.sprite.height}}),this.onImageLoaded&&this.onImageLoaded()}catch(h){A.error("[Background] Error loading background image:",h),(a=this.lastConfig)!=null&&a.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i)}}async update(e){await this.render(e)}destroy(){this.clear(),super.destroy()}}class L0 extends L{constructor(e){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,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(e.global),s=this.controlFill.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",e=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(h=(a=this.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 e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleRotationEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleMoveHorizontal",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleMoveVertical",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-scale"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleDelete",()=>{var e,i;(i=(e=this.carpetEvents).onRemove)==null||i.call(e,this.carpetData.id)});g(this,"handleClick",()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())});g(this,"handlePointsUpdate",e=>{this.carpetData.points=e,this.drawCarpet()});const{appService:i,carpetData:s,events:n={},textureMap:o}=e;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()}processCarpetData(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=Ia(e.points,this.appService.metersToPixels(this.carpetConfig.minSize)),n=bs(s);this.carpetData={...e,points:n}}else this.carpetData={...e,points:[],shape:e.shape||"rectangle"}}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}isEditingEnabled(){return this.appService.runtimeSnapshot.editingCarpetIds.includes(this.carpetData.id)}isSelected(){return this.appService.runtimeSnapshot.selectedCarpetIds.includes(this.carpetData.id)}shouldShowEditControl(){return this.isEditingEnabled()||this.isSelected()}initializeComponents(){this.maskContainer=this.createMaskContainer(),this.controlFill=this.createControlFill(),this.addChild(this.maskContainer),this.addChild(this.controlFill),this.drawCarpet()}createMaskContainer(){const e=new L;return this.maskGraphics=new H,this.updateMaskShape(),e.addChild(this.maskGraphics),e.mask=this.maskGraphics,e}createControlFill(){const e=this.isEditingEnabled();return new Lr(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:e,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const e=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s={...wn(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...wn(this.carpetConfig,["textColor","textPosition","textOffset"]),...wn(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!e&&!i,showScaleButton:!!e&&!i,showDeleteButton:!!e,showMoveButton:!!e&&!i,showRadialScaleButton:!!e&&!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,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 e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const e=U(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(e);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(e){if(e){if(this.eventMode="none",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="none"}}else if(this.eventMode="static",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="static"}}calculateBounds(){const{points:e}=this.carpetData;let i=1/0,s=1/0,n=-1/0,o=-1/0;if(e&&e.length>0)for(const a of e)i=Math.min(i,a.x),s=Math.min(s,a.y),n=Math.max(n,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:n,maxY:o}}calculateBoundingRectanglePoints(){const{points:e}=this.carpetData;if(!e||e.length===0)return[];const{minX:i,minY:s,maxX:n,maxY:o}=vs(e);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:e,shape:i}=this.carpetData;if(!(!e||!Array.isArray(e)||e.length<2)){if(i==="round"){if(e.length<4)return;const n=ee(e),[o,a,,h]=e,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=e.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(n),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}async loadTexture(){const{opacity:e,scale:i}=this.appService.carpetConfig,{type:s}=this.carpetData;try{this.texture=this.textureMap.get(s)||this.textureMap.get(-1)||null,this.texture&&this.maskContainer&&(this.createTilingSprite(i,e),this.appService.getApp().renderOnce())}catch(n){console.warn("Failed to load carpet texture:",n)}}createTilingSprite(e,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new Ss({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(e),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const e=this.calculateBounds();this.tilingSprite.position.set(e.minX-50,e.minY-50),this.tilingSprite.width=e.maxX-e.minX+100,this.tilingSprite.height=e.maxY-e.minY+100}applyTranslation(e,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:e}=this.carpetData;if(!(!e||e.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(e),this.editControlLayer)){const n=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():e;this.editControlLayer.updatePoints(n)}}updateEditState(){const e=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();if(this.controlFill.setInteractionEnabled(e),this.editControlLayer)if(i&&!e)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(e){const n=this.carpetData.shape==="custom";this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!n,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(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=Ia(e.points,this.appService.metersToPixels(this.carpetConfig.minSize)),n=bs(s);this.carpetData={...e,points:n}}else this.carpetData={...e,points:e.points||[]};this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var e,i,s,n,o;this.appService.editControlManager.unregisterEditControl(this.carpetData.id),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(e=this.tilingSprite)==null||e.destroy(),(i=this.maskGraphics)==null||i.destroy(),(s=this.maskContainer)==null||s.destroy(),this.tilingSprite=null,this.maskGraphics=null,this.maskContainer=null,this.texture=null,(n=this.controlFill)==null||n.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class O0{constructor(t){g(this,"customCarpetMap",new Map);g(this,"unsubscribeFns",[]);g(this,"textureMap",new Map);g(this,"texturesLoaded",!1);g(this,"texturesLoadingPromise",null);this.appService=t;const e=U(t.runtime,"editingCarpetIds",s=>{A.log(`[runtime] editingCarpetIds: ${s}`),this.updateCarpetsEditState()}),i=U(t.runtime,"selectedCarpetIds",s=>{A.log(`[runtime] selectedCarpetIds: ${s}`),this.updateCarpetsEditState()});this.unsubscribeFns.push(e,i)}async loadTextures(){if(!this.texturesLoaded){if(this.texturesLoadingPromise)return this.texturesLoadingPromise;this.texturesLoadingPromise=this._loadTextures(),await this.texturesLoadingPromise,this.texturesLoaded=!0,this.texturesLoadingPromise=null}}async _loadTextures(){const t=this.appService,{material:e,src:i}=t.carpetConfig;if(e)for(const s of e){const 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)}}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(us);s&&s.position.set(t,e)}async drawCustomCarpets(t){if(await this.loadTextures(),!t||t.length===0){this.clearAllCustomCarpets();return}const e=new Set(this.customCarpetMap.keys()),i=new Set(t.map(s=>s.id));for(const s of e)i.has(s)||this.removeCustomCarpet(s);t.forEach(s=>{const n=this.customCarpetMap.get(s.id.toString());n?this.isCarpetDataEqual(n.getCarpetData(),s)||n.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const t=[];return this.customCarpetMap.forEach(e=>{t.push(e.getCarpetData())}),t}getCustomCarpetById(t){return this.customCarpetMap.get(t)}clearAllCustomCarpets(){this.customCarpetMap.forEach((t,e)=>{var s;const i=this.customCarpetMap.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(t){const e=this.appService,i=new L0({appService:e,carpetData:t,textureMap:this.textureMap,events:{onRemove:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onDeleteCustomCarpet)==null||o.call(n,{id:s})},onUpdate:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onUpdateCustomCarpet)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onClickCarpet)==null||o.call(n,{id:s.id})}}});this.customCarpetMap.set(t.id.toString(),i),e.appContainer.addToLayer(us,i)}removeCustomCarpet(t){const e=this.appService,i=this.customCarpetMap.get(t);i&&(e.appContainer.removeFromLayer(us,i),i.destroy(),this.customCarpetMap.delete(t))}updateCarpetsEditState(){this.customCarpetMap.forEach(t=>{t.updateEditState()})}isCarpetDataEqual(t,e){if(t.id!==e.id||t.type!==e.type||t.shape!==e.shape)return!1;const i=t.points||[],s=e.points||[];if(i.length!==s.length)return!1;for(let 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(t=>{t.refreshDisplay()})}destroy(){this.clearAllCustomCarpets(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}class G0 extends Wi{constructor(t,e){super(t,e),this.cursor="pointer"}setupEvents(){this.on("pointertap",()=>{var t,e;(e=(t=this.options).onClick)==null||e.call(t)})}destroy(){this.removeAllListeners(),super.destroy()}}const Ft={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0};class W0 extends L{constructor(e){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,"onDragStart",e=>{var s,n;if(!this.isEditing||!this.parent||e.target!==this)return;(n=(s=this.appService.events)==null?void 0:s.onGestureStart)==null||n.call(s),this.appService.getApp().requestRender("furniture-drag",!0);const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(o=>({...o})),this.isDragging=!1});g(this,"onDragMove",e=>{if(!this.isEditing||!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(n)<3||(this.isDragging=!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 e,i,s,n;!this.isEditing||!this.dragStartPosition||(this.isDragging&&((i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1,this.appService.getApp().stopRender("furniture-drag"),(n=(s=this.appService.events)==null?void 0:s.onGestureEnd)==null||n.call(s))});g(this,"handleScaleStart",()=>{this.initialScalePoints=this.data.points.map(i=>({...i}));const e=this.getVisualIndex(Ft.SCALE);e>=0&&e<this.data.points.length&&(this.initialButtonPosition={...this.data.points[e]}),this.appService.getApp().requestRender("furniture-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialScalePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var e,i;this.initialScalePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("furniture-scale"),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});g(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(e=>({...e})),this.appService.getApp().requestRender("furniture-move",!0)});g(this,"handleMoveMove",e=>{var a;if(!this.isEditing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(e.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 e,i;this.initialPoints=[],this.appService.getApp().stopRender("furniture-move"),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});const{appService:i,data:s,textureAlias:n,events:o={}}=e;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.eventMode="static",this.cursor="pointer",this.setupInteraction()}get config(){return this.appService.furnitureConfig}getVisualIndex(e){return(e+4-this.rotationCount)%4}getVisualPoints(){const e=this.data.points;return[e[this.getVisualIndex(0)],e[this.getVisualIndex(1)],e[this.getVisualIndex(2)],e[this.getVisualIndex(3)]]}createSprite(){const e=N.get(this.textureAlias);this.sprite=new jt(e),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="none",this.addChild(this.sprite)}updateSpriteTransform(){const e=this.data.points;if(e.length<4)return;const i=ee(e),s=e[1].x-e[0].x,n=e[1].y-e[0].y,o=Math.atan2(n,s),a=Q(e[0],e[1]),h=Q(e[1],e[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControls(){const e=this.calculateOutlinePoints();this.outlineBorder=new Nt(this.appService,{points:e,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(e);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 e=this.calculateOutlinePoints();if(e.length<4)return;const{iconWrapperFillColor:i}=this.config,s=this.getVisualIndex(Ft.REMOVE),n=this.getVisualIndex(Ft.ROTATE),o=this.getVisualIndex(Ft.SCALE);this.deleteButton=new Ds(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(e[s].x,e[s].y),this.rotateButton=new G0(this.appService,{iconAlias:"rotateIcon",backgroundColor:i,onClick:()=>this.handleTapRotate()}),this.rotateButton.position.set(e[n].x,e[n].y),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:i,getTargetPoints:()=>this.data.points,getButtonIndex:()=>this.getVisualIndex(Ft.SCALE),onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[o].x,e[o].y);const a=this.calculateMoveButtonPosition(e);this.moveButton=new Fs(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:e}=this.data;if(e.length<4)return e;const i=this.appService.getApp().toFixedSize(this.config.outlineOffset);return Ir(e,i)}calculateMoveButtonPosition(e){const i=e??this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{controls:s}=this.appService.getConfig(),n=this.getVisualIndex(Ft.MOVE),o=this.getVisualIndex(2),a=this.getVisualIndex(0),h=this.appService.getApp().toFixedSize(s.moveButtonOffset);return Is(i[n],i[o],i[a],h)}calculateMoveLinePoints(e,i){if(e.length<4)return[];const s=this.getVisualIndex(Ft.MOVE),n=i??this.calculateMoveButtonPosition(e);return[e[s],n]}createSizeText(){const e=this.calculateSizeTextContent(),i=this.appService.controlsConfig,s=new Ui(this.appService,{text:e,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:e}=this.data;if(e.length<4)return"0m*0m";const[i,s,,n]=this.getVisualPoints(),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:e}=this.data;if(e.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=pt(q(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=pt(q(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=pt(q(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=pt(q(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:e}=this.data;if(e.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 Xe(h,l,c)}setupInteraction(){this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.isDragging||(i=(e=this.furnitureEvents).onClick)==null||i.call(e,this.getData())}}),this.on("pointerdown",this.onDragStart,this),this.on("pointermove",this.onDragMove,this),this.on("pointerup",this.onDragEnd,this),this.on("pointerupoutside",this.onDragEnd,this)}handleTapRotate(){var n,o;const e=this.config.rotateDirection!=="ccw",i=e?Math.PI/2:-Math.PI/2,s=ee(this.data.points);this.data.points=Er(this.data.points,s,i),this.rotationCount=(this.rotationCount+(e?1:3))%4,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(),(o=(n=this.furnitureEvents).onUpdate)==null||o.call(n,this.getData())}applyEdgeBasedScale(e){if(this.initialScalePoints.length<4)return;const i=this.getVisualIndex(Ft.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=q(c,h),u=q(c,l),p=q(c,e),f=ie(d),y=ie(u);if(f===0||y===0)return;const{minScaleRatio:m,maxScaleRatio:x}=this.config;let S=he(p,d,f,0),v=he(p,u,y,0);S=Math.max(m,Math.min(x,S)),v=Math.max(m,Math.min(x,v));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 w=0;w<4;w++)P[this.getVisualIndex(w)]=b[w];this.data.points=P,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditControls(){var h;const e=this.calculateOutlinePoints();if(e.length<4)return;this.outlineBorder.updatePoints(e);const i=this.calculateMoveButtonPosition(e),s=this.calculateMoveLinePoints(e,i);if(this.moveLine.updatePoints(s),!this.deleteButton||!this.rotateButton||!this.scaleButton)return;const n=this.getVisualIndex(Ft.REMOVE),o=this.getVisualIndex(Ft.ROTATE),a=this.getVisualIndex(Ft.SCALE);this.deleteButton.position.set(e[n].x,e[n].y),this.rotateButton.position.set(e[o].x,e[o].y),this.scaleButton.position.set(e[a].x,e[a].y),(h=this.moveButton)==null||h.position.set(i.x,i.y)}updateSizeText(e=!1){if(!this.sizeText)return;if(e){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(e=>({...e}))}}updateData(e){this.data={...e,points:e.points.map(i=>({...i}))},this.rotationCount=0,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditState(e){this.isEditing!==e&&(this.isEditing=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.controlButtons.visible=e)}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class U0{constructor(t){g(this,"furnitureMap",new Map);g(this,"unsubscribeFns",[]);this.appService=t;const e=U(t.runtime,"editingFurnitureIds",i=>{A.log(`[runtime] editingFurnitureIds: ${i}`),this.updateEditState()});this.unsubscribeFns.push(e)}updatePositionByOrigin(t,e){const i=this.appService.appContainer.getLayer(ds);i&&i.position.set(t,e)}async drawFurnitures(t){if(!t||t.length===0){this.clearAll();return}const e=new Set(this.furnitureMap.keys()),i=new Set(t.map(n=>n.id));for(const n of e)i.has(n)||this.removeFurniture(n);const s=[];for(const n of t){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(t){const e=this.appService;if(!e.furnitureConfig.assets.find(h=>h.type===t.furnitureType)){A.warn(`[FurnitureManager] No asset found for furnitureType: ${t.furnitureType}`);return}const n=`furniture_${t.furnitureType}`;await N.load(n);const o=new W0({appService:e,data:t,textureAlias:n,events:{onRemove:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onRemoveFurniture)==null||c.call(l,h)},onUpdate:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onUpdateFurniture)==null||c.call(l,h)},onClick:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onClickFurniture)==null||c.call(l,h)}}});this.furnitureMap.set(t.id,o),e.appContainer.addToLayer(ds,o),e.runtime.editingFurnitureIds.includes(t.id)&&o.updateEditState(!0)}removeFurniture(t){const e=this.furnitureMap.get(t);e&&(this.appService.appContainer.removeFromLayer(ds,e),e.destroy(),this.furnitureMap.delete(t))}clearAll(){var t;for(const[,e]of this.furnitureMap)(t=e.parent)==null||t.removeChild(e),e.destroy();this.furnitureMap.clear()}updateEditState(){const t=this.appService.runtime.editingFurnitureIds;this.furnitureMap.forEach((e,i)=>{e.updateEditState(t.includes(i))})}isDataEqual(t,e){if(t.id!==e.id||t.furnitureType!==e.furnitureType||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++)if(Math.abs(t.points[i].x-e.points[i].x)>.1||Math.abs(t.points[i].y-e.points[i].y)>.1)return!1;return!0}destroy(){this.clearAll(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}const ft={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class H0 extends L{constructor(e,i){super();g(this,"config");g(this,"events");g(this,"zonePoints",[]);g(this,"outlinePoints");g(this,"minSize",.1);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=e,this.zonePoints=i.zonePoints,this.config={...i.config,showScaleButton:i.config.showScaleButton!==void 0?i.config.showScaleButton:!0,showRadialScaleButton:i.config.showRadialScaleButton!==void 0?i.config.showRadialScaleButton:!0,showDeleteButton:i.config.showDeleteButton!==void 0?i.config.showDeleteButton:!0,showMoveButton:i.config.showMoveButton!==void 0?i.config.showMoveButton:!0,showRotateButton:i.config.showRotateButton!==void 0?i.config.showRotateButton:!0},this.events=i.events||{},this.minSize=i.minSize??.1,this.throttledUpdateOutline=At(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:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n,outlineFillColor:o}=this.config;return new Nt(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:e,width:i,isDashed:s,dashArray:n,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n}=this.config,o=this.calculateMoveLinePoints();return new Nt(this.appService,{points:o,closePath:!1,style:{color:e,width:i,isDashed:s,dashArray:n}})}createSizeText(){const e=this.calculateSizeText(),i=new Ui(this.appService,{text:e,style:{fontSize:this.config.textFontSize,fontFamily:this.config.textFontFamily,fontWeight:this.config.textFontWeight,fill:this.config.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}createDeleteButton(){const e=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:"red",onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return e.position.set(this.outlinePoints[ft.REMOVE].x,this.outlinePoints[ft.REMOVE].y),e}createRotateButton(){const e=new fc(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 e.position.set(this.outlinePoints[ft.ROTATE].x,this.outlinePoints[ft.ROTATE].y),e}onClickRotateButton(e){const i=this.handleInternalRotationMove(e)??[];return this.resetRotationState(),i}createScaleButton(){const e=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.config.iconWrapperFillColor,initialButtonPosition:this.outlinePoints[ft.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 e.position.set(this.outlinePoints[ft.SCALE].x,this.outlinePoints[ft.SCALE].y),e}createHorizontalScaleButton(){const[,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),n=new Ze(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[,,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),n=new Ze(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 e=this.calculateMoveButtonPosition(),i=new Fs(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(e.x,e.y),i}createAndAddButton(e,i){return e.visible=i,this.controlButtons.addChild(e),e}createControlButtons(){this.outlinePoints.length<4||(this.deleteButton=this.createAndAddButton(this.createDeleteButton(),this.config.showDeleteButton??!1),this.moveButton=this.createAndAddButton(this.createMoveButton(),this.config.showMoveButton??!1),this.rotateButton=this.createAndAddButton(this.createRotateButton(),this.config.showRotateButton??!1),this.scaleButton=this.createAndAddButton(this.createScaleButton(),this.config.showScaleButton??!1),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 e=this.zonePoints;if(e.length<4)return e;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return Ir(e,s)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),n=e[ft.MOVE],o=e[ft.SCALE],a=e[ft.REMOVE];return Is(n,o,a,s)}calculateMoveLinePoints(){const e=this.calculateOutlinePoints();if(e.length<4)return[];const i=e[ft.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const e=this.zonePoints;if(e.length<4)return"0m*0m";const[i,s,,n]=e,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(e,i){return{x:(e.x+i.x)/2,y:(e.y+i.y)/2}}calculatePerpendicularOffset(e,i,s,n=!1){const o=pt(q(i,e)),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 e=this.zonePoints;if(e.length<4)return 0;const[i,s,n,o]=e,{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 Xe(h,l,c)}calculateHorizontalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(i,s,n)+Math.PI/2}calculateVerticalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,,i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(s,i,n)}updatePoints(e,i=!0){this.zonePoints=e,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlinePoints=e,this.outlineBorder.updatePoints(e)}updateMoveLine(){if(!this.moveLine)return;const e=this.calculateMoveLinePoints();this.moveLine.updatePoints(e)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:e[ft.REMOVE]},{button:this.scaleButton,point:e[ft.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:e[ft.ROTATE]}),this.horizontalScaleButton){const n=e[ft.ROTATE],o=e[ft.SCALE],a=Jl(n,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const n=e[ft.SCALE],o=e[ft.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 e,i;(i=(e=this.events).onClick)==null||i.call(e)},stopPropagation:!1})}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){(this.outlineBorder.visible||this.controlButtons.visible)&&(this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}initializeScaleCache(){if(this.initialZonePoints.length===0&&(this.initialZonePoints=this.zonePoints.map(p=>({...p}))),this.initialZonePoints.length<4)return;const e={...this.initialZonePoints[ft.SCALE]};if(!e)return;const i=ft.REMOVE,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=q(h,o),c=q(h,a),d=ie(l),u=ie(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:e})}handleInternalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const s=this.appService.metersToPixels(this.minSize),{fixedPoint:n,edge1:o,edge2:a,edge1Len:h,edge2Len:l,initialButtonPosition:c}=this.scaleCache,d={x:c.x+e,y:c.y+i},u=q(n,d),p=he(u,o,h,s),f=he(u,a,l,s);return this.calculatePointsFromScale(n,o,a,p,f)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(e,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={x:this.horizontalScaleInitialPosition.x+e,y:this.horizontalScaleInitialPosition.y+i},c=q(s,l),d=he(c,n,a,h);return this.calculatePointsFromScale(s,n,o,d,1)}handleInternalVerticalScaleMove(e,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={x:this.verticalScaleInitialPosition.x+e,y:this.verticalScaleInitialPosition.y+i},c=q(s,l),d=1,u=he(c,o,a,h);return this.calculatePointsFromScale(s,n,o,d,u)}calculatePointsFromScale(e,i,s,n,o){const{x:a,y:h}=e;return[e,{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(e){this.zonePoints.length<3||(this.rotationCache={rotationCenter:e,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(e){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=e,Er(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:ee(this.zonePoints)}updateEditState({showRotateButton:e=!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=e),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=e||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 e=((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:e,isRotating:i,isMoving:s,hasAnyOperation:e||i||s}}stopAllOperations(){var e,i,s;(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(e,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const n=s[e],o=s[i];return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}}destroy(){var e,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(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 V0{constructor(t){g(this,"editControlLayers",new Map);this.appService=t}registerEditControl(t,e){const i=this.appService;this.editControlLayers.has(t)&&this.unregisterEditControl(t);const s=new H0(i,e);if(!i.appContainer.addToLayer(Ti,s))throw A.warn(`[EditControlManager] Failed to add edit control layer for id: ${t}`),s.destroy(),new Error(`Failed to register edit control for id: ${t}`);return this.editControlLayers.set(t,s),s}unregisterEditControl(t){const e=this.editControlLayers.get(t);if(!e)return;this.appService.appContainer.removeFromLayer(Ti,e),e.destroy(),this.editControlLayers.delete(t)}getEditControl(t){return this.editControlLayers.get(t)}updateEditState(t,e){const i=this.editControlLayers.get(t);i&&i.updateEditState(e)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(e=>this.unregisterEditControl(e))}getAllEditControls(){return Array.from(this.editControlLayers.values())}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(Ti);s&&s.position.set(t,e)}hasEditControl(t){return this.editControlLayers.has(t)}}class Vr extends $h{constructor(e=Ha){super();g(this,"mapState",null);g(this,"components",{});g(this,"managers",{});g(this,"config",Ua);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",Bx());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=e,this.appService=new ic(this),globalThis.__PIXI_APP__=this}async initialize(e){const{resizeTo:i,events:s,config:n,runtime:o={},...a}=e;this.config=sr(_a({},Ua,n??{})),sy(()=>this.config.global.enableLogger),A.log("Applying config",this.config,n),this.runtime=sr(Object.assign({},Ix,o));const h=this.instanceKey===Ha;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={textureGCMaxIdle:c?60:Ln.any?180:3600,textureGCCheckCountMax:c?10:Ln.any?100:50,autoStart:!1,sharedTicker:c,eventFeatures:{move:l,globalMove:!1,click:l,wheel:l}};await this.init({resizeTo:h?i:void 0,preference:"webgpu",resolution:this.config.global.resolution,antialias:c?!1:F0(),depth:!c,autoDensity:!0,backgroundColor:0,backgroundAlpha:0,...d,...a}),A.log(`[Pixi] Renderer initialized: ${this.renderer.type===Ri.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 Vx(this.appService),this.managers.heatmapManager=new Kx(this.appService),this.managers.pathManager=new Zx(this.appService),this.managers.controlsManager=new t0(this.appService),this.managers.detectedObjectManager=new i0(this.appService),this.managers.customElementsManager=new T0(this.appService),this.managers.roomsManager=new D0(this.appService),this.managers.customCarpetManager=new O0(this.appService),this.managers.furnitureManager=new U0(this.appService),this.managers.editControlManager=new V0(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(e){var a,h,l,c,d,u,p;this.isMapDrawn=!1,A.log("[Map] drawMap",e);const{size:i,resolution:s,origin:n,id:o}=e;((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.managers.pathManager.updatePositionByOrigin(...n),this.managers.controlsManager.updatePositionByOrigin(...n),this.managers.detectedObjectManager.updatePositionByOrigin(...n),this.managers.customElementsManager.updatePositionByOrigin(...n),this.managers.customCarpetManager.updatePositionByOrigin(...n),this.managers.furnitureManager.updatePositionByOrigin(...n),this.managers.editControlManager.updatePositionByOrigin(...n),this.managers.heatmapManager.updatePositionByOrigin(...n)),this.mapState={id:e.id,status:e.status===1,origin:{x:n[0],y:n[1]},charger:{x:e.charger.coordinate[0],y:e.charger.coordinate[1]},chargerDirection:e.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},this.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(e),i[0]===0||i[1]===0?(A.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(e){var a,h,l,c,d,u;this.isMapDrawn=!1,A.log("[Map] drawRasterMap",e);const{mapHeader:i,mapData:s}=e,{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.managers.pathManager.updatePositionByOrigin(n,o),this.managers.controlsManager.updatePositionByOrigin(n,o),this.managers.editControlManager.updatePositionByOrigin(n,o),this.managers.furnitureManager.updatePositionByOrigin(n,o),this.managers.detectedObjectManager.updatePositionByOrigin(n,o),this.managers.customElementsManager.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?(A.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(e){var i,s;A.log("[Path] drawPath",e),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:e.pathHeader.pathId,type:e.pathHeader.type,direction:e.pathHeader.direction,count:e.pathHeader.count,initFlag:e.pathHeader.initFlag,robotPosition:e.pathPoints[e.pathPoints.length-1]??null}),this.managers.pathManager.draw(e),this.renderOnce()}async drawRoomProperty(e){var i,s;A.log("[Room] drawRoomProperty",e),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,e),await this.managers.roomsManager.drawRoomProperty(e),this.renderOnceNextFrame()}async drawCustomCarpets(e){A.log("[CustomCarpets] drawCustomCarpets",e),await this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawFurnitures(e){A.log("[Furniture] drawFurnitures",e),await this.managers.furnitureManager.drawFurnitures(e),this.renderOnceNextFrame()}drawHeatmap(e){A.log("[Heatmap] drawHeatmap",e),this.managers.heatmapManager.draw(e),this.renderOnce()}drawForbiddenSweepZones(e){A.log("[Controls] drawForbiddenSweepZones",e),this.managers.controlsManager.drawForbiddenSweepZones(e),this.renderOnceNextFrame()}drawForbiddenMopZones(e){A.log("[Controls] drawForbiddenMopZones",e),this.managers.controlsManager.drawForbiddenMopZones(e),this.renderOnceNextFrame()}drawCleanZones(e){A.log("[Controls] drawCleanZones",e),this.managers.controlsManager.drawCleanZones(e),this.renderOnceNextFrame()}drawVirtualWalls(e){A.log("[Controls] drawVirtualWalls",e),this.managers.controlsManager.drawVirtualWalls(e),this.renderOnceNextFrame()}drawSpots(e){A.log("[Controls] drawSpots",e),this.managers.controlsManager.drawSpots(e),this.renderOnceNextFrame()}drawWayPoints(e){A.log("[Controls] drawWayPoints",e),this.managers.controlsManager.drawWayPoints(e),this.renderOnceNextFrame()}async drawDetectedObjects(e){A.log("[DetectedObject] drawDetectedObjects",e),await this.managers.detectedObjectManager.drawDetectedObjects(e),this.renderOnceNextFrame()}drawCustomCarpet(e){A.log("[CustomCarpet] drawCustomCarpet",e),this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawCustomElements(e){A.log("[CustomElements] drawCustomElements",e),await this.managers.customElementsManager.drawCustomElements(e),this.renderOnceNextFrame()}getForbiddenSweepZones(){return this.managers.controlsManager.getForbiddenSweepZones()}getForbiddenMopZones(){return this.managers.controlsManager.getForbiddenMopZones()}getCleanZones(){return this.managers.controlsManager.getCleanZones()}getVirtualWalls(){return this.managers.controlsManager.getVirtualWalls()}getSpots(){return this.managers.controlsManager.getSpots()}getWayPoints(){return this.managers.controlsManager.getWayPoints()}getEffectiveDividerPoints(){return this.managers.controlsManager.getEffectiveDividerPoints()}getCustomCarpets(){return this.managers.customCarpetManager.getCustomCarpets()}getDividerEndPoints(){return this.managers.controlsManager.getDividerEndPoints()}resetPanZoom(){this.components.interaction.setPanZoom()}forceEndGesture(){A.log("[Map] forceEndGesture"),this.components.interaction.forceEndGesture()}fitMapToView(e,i=!1){if(!e||e.minX===e.maxX||e.minY===e.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,n=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(e,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-n*2),f=u*(1-s*2),y=p/l,m=f/c,x=Math.min(y,m),S=Math.max(this.config.interaction.fitMinScale,this.scaleMin),v=Math.min(this.config.interaction.fitMaxScale,this.scaleMax),b=Math.max(S,Math.min(v,x)),P=e.minX+(e.maxX-e.minX)/2,w=e.minY+(e.maxY-e.minY)/2,C=this.config.map.autoFitOffset||{x:0,y:0},k=d/2+(C.x||0),M=u/2+(C.y||0),T=Math.cos(a),_=Math.sin(a),I=P*T-w*_,B=P*_+w*T,F=k-I*b,Z=M-B*b;A.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:e,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)}calculateRotatedBounds(e,i){if(i===0)return e;const s=(e.minX+e.maxX)/2,n=(e.minY+e.maxY)/2,o=[{x:e.minX-s,y:e.minY-n},{x:e.maxX-s,y:e.minY-n},{x:e.maxX-s,y:e.maxY-n},{x:e.minX-s,y:e.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 e;return((e=this.components.viewportContainer)==null?void 0:e.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(e){Object.assign(this.runtime,e),A.log("[runtime] runtime updated",e),this.renderOnceNextFrame()}updateConfig(e){var i;_a(this.config,e),(i=this.managers.controlsManager)==null||i.updateRenderOrder(),A.log("[Config] Configuration updated",e),this.renderOnceNextFrame()}metersToPixels(e){var n;if(!((n=this.mapState)!=null&&n.resolution))return A.warn("Map resolution not available, using default resolution (5cm/pixel)"),e*20;const s=1/(this.mapState.resolution/100);return e*s}pixelsToMeters(e){var s;if(!((s=this.mapState)!=null&&s.resolution))return A.warn("Map resolution not available, using default resolution (5cm/pixel)"),e*.05;const i=this.mapState.resolution/100;return e*i}toFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e/s}fromFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e*s}getViewportCenterPoint(){if(!this.mapState)return A.warn("Map state not available, cannot calculate center point"),null;const e=this.getViewportBounds(),i=e.x+e.width/2,s=e.y+e.height/2,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 A.warn("Map state not available, cannot calculate map center point"),null;const e=this.managers.mapManager.mapBounds;if(e.minX===1/0||e.minY===1/0||e.maxX===-1/0||e.maxY===-1/0)return A.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(e.minX+e.maxX)/2,s=(e.minY+e.maxY)/2,n=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:n,y:o}}getWallPointsByViewportCenter(e){var f;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:n=0,offsetY:o=0}=e||{},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(e){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getForbiddenMopZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getCleanZonePointsByViewportCenter(e){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getSpotPointByViewportCenter(e){const{offsetX:i=0,offsetY:s=0}=e||{},n=this.getViewportCenterPoint()||{x:0,y:0},o=n.x+i,a=n.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(e){var x;const{furnitureType:i=1,offsetX:s=0,offsetY:n=0}=e||{},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(e){return!e||e.length===0?(A.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(e)}isPointInAnyRoom(e){return!e||typeof e.x!="number"||typeof e.y!="number"?(A.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(e):(A.warn("[Room] Map state not available"),null)}isWallIntersectsAnyRoom(e){return!e||e.length!==2||!e[0]||!e[1]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"?(A.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(e):(A.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(e){return!e||e.length!==4||!e[0]||!e[1]||!e[2]||!e[3]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"||typeof e[2].x!="number"||typeof e[2].y!="number"||typeof e[3].x!="number"||typeof e[3].y!="number"?(A.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(e):(A.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(e,i,s){var h,l;if(!e||e.length<1)return A.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(e.length!==1&&e.length!==2&&e.length!==4)return A.warn("[Distance] Invalid points array: must have exactly 1 (point), 2 (wall) or 4 (zone) points"),!1;if(i<=0)return A.warn("[Distance] Invalid threshold: must be greater than 0"),!1;if(!this.mapState)return A.warn("[Distance] Map state not available"),!1;const{checkCharger:n=!0,checkRobot:o=!1}=s||{};if(!n&&!o)return A.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 A.warn("[Distance] Charger position not available"),!1;const p=Ea(c,e);if(p<=a)return A.log(`[Distance] Too close to charger: ${p.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else A.warn("[Distance] Charger position not available")}if(o){const c=this.appService.getRobotPosition();if(c){const d=Ea(c,e);if(d<=a)return A.log(`[Distance] Too close to robot: ${d.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else A.warn("[Distance] Robot position not available")}return!1}async snapshot(e){this.render();const{snapshot:i,global:s}=this.config,n=(e==null?void 0:e.backgroundColor)??s.backgroundColor,o=this.components.appContainer,a=o.getSnapshotBounds(),h=Math.floor(a.x),l=Math.floor(a.y),c=Math.ceil(a.x+a.width)-h,d=Math.ceil(a.y+a.height)-l;if(c<=0||d<=0)return A.error("[MapApplication] Snapshot failed: invalid bounds",a),"";const u=i.resolution||window.devicePixelRatio||2,p=kr.create({width:c,height:d,resolution:u}),f=new H;f.rect(0,0,c,d).fill(n);const y=new W;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 A.error("[MapApplication] Snapshot failed:",m),""}finally{f.destroy(),p.destroy(!0)}}async snapshotByData({map:e,path:i,roomProperties:s,customElements:n,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c},d={},u){const p=`SNAPSHOT_${Fx()}`;A.log(`[MapApplication] ${p} snapshot start`);const f=new Vr(p);try{if(await f.initialize({config:this.config,runtime:d}),!e)throw new Error("Map data is required");if(e.startsWith("7b22")){const m=$c(e);await f.drawMap(m)}else{const m=Qc(e,{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.Dn4kNa0x.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 A.log(`[MapApplication] ${p} snapshot completed successfully`),y}catch(y){throw A.error(`[MapApplication] ${p} snapshot other map failed:`,y),y}finally{A.log(`[MapApplication] ${p} destroy`),f.destroy()}}renderOnce(){A.log("[Pixi] renderOnce"),this.render()}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{A.log("[Pixi] renderOnceNextFrame"),this.render(),this.pendingAsyncRender=!1}))}requestRender(e,i=!1){if(!i){this.renderOnceNextFrame();return}this.tickerState.renderReasons.add(e),this.ticker.started||(A.debug(`🎬 [Ticker] START: ${e}`),this.ticker.start())}stopRender(e){this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100)}destroy(){var e;A.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(),(e=this.components.background)==null||e.destroy(),this.components.viewportContainer.destroy(),this.components.appContainer.destroy(),this.managers.heatmapManager.destroy(),super.destroy()}initializeViewportContainer(){this.components.viewportContainer=new zx(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const e=this.getViewportBounds();this.components.background=new z0(this.config.global,e,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Bs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new Gx(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Iy(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(e,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&(A.debug("⏸️ [Ticker] STOP"),this.ticker&&this.ticker.stop())},i)}generateZonePoints(e,i,s){var u;const n=this.getViewportCenterPoint()||{x:0,y:0},a=this.metersToPixels(e)/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 e=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:e}),s.push("robot"),N.add({alias:"chargingStation",src:i}),s.push("chargingStation"),N.add({alias:"deleteIcon",src:this.config.controls.deleteIconSrc}),s.push("deleteIcon"),N.add({alias:"rotateIcon",src:this.config.controls.rotateIconSrc}),s.push("rotateIcon"),N.add({alias:"scaleIcon",src:this.config.controls.scaleIconSrc}),s.push("scaleIcon"),N.add({alias:"moveIcon",src:this.config.controls.moveIconSrc}),s.push("moveIcon"),N.add({alias:"checkmark",src:this.config.room.selectionIndicator.iconSrc}),s.push("checkmark"),N.add({alias:"spotIcon",src:this.config.controls.spot.iconSrc}),s.push("spotIcon"),N.add({alias:"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),U(this.runtime,"mapRotation",e=>{this.applyMapRotation(e)})}applyMapRotation(e){const i=(e%360+360)%360;A.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 $0=Object.freeze(Object.defineProperty({__proto__:null,AppService:ic,MapApplication:Vr},Symbol.toStringTag,{value:"Module"}));export{Lo as $,wi as A,le as B,ne as C,lr as D,Yt as E,ur as F,H as G,jg as H,Qe as I,Bf as J,ks as K,Cf as L,W as M,Ot as N,Rs as O,tt as P,dr as Q,et as R,Fp as S,G as T,Ee as U,j as V,jh as W,Ri as X,Gi as Y,Ip as Z,ri as _,Ke as a,Ci as a0,pr as a1,Hh as a2,Bt as a3,ti as a4,ol as a5,lf as a6,pf as a7,K0 as a8,hl as a9,Di as aA,Op as aB,al as aC,cf as aD,gf as aE,Yg as aF,ll as aG,mf as aH,Lg as aI,$0 as aJ,Ie as aa,hs as ab,Au as ac,cd as ad,ce as ae,Je as af,yf as ag,_t as ah,ph as ai,It as aj,Ps as ak,ho as al,jt as am,Mm as an,Ud as ao,co as ap,qs as aq,uo as ar,Vd as as,gh as at,kr as au,Pr as av,Yh as aw,Oi as ax,Zu as ay,Vu as az,$n as b,rt as c,V as d,de as e,Qn as f,os as g,xt as h,X as i,pu as j,gt as k,am as l,dt as m,Ln as n,iu as o,E as p,yt as q,Cd as r,zg as s,fa as t,Pu as u,J as v,nt as w,$ as x,L as y,st as z};
|
|
744
|
+
`,entryPoint:"main"}})}),l=new xa({geometry:a,shader:h});return l.alpha=.8,l}updatePositionByOrigin(e,i){this.position.set(e,i)}destroy(){this.removeChildren(),this.cacheAsTexture(!1)}}class Kx{constructor(t){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=t,this.heatmap=new qx(t);const e=t.heatMapConfig;this.cellSize=e.cellSize,this.maxDistance=e.maxDistance,this.smoothIterations=e.smoothIterations,this.heatmapAlpha=e.heatmapAlpha}draw(t){const e=this.appService;if(!e.isMapDrawn){this.pendingPoints=t;return}this.pendingPoints=null;const{minX:i,minY:s}=e.mapManager.mapBounds,n=t.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(t){var p;const e=this.appService,i=((p=e.mapState)==null?void 0:p.origin)||{x:0,y:0};let{minX:s,minY:n,maxX:o,maxY:a}=e.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 w=0;w<t.length;w++){const C=t[w];if(Math.abs(S-C.x)<=v/2&&Math.abs(y-C.y)<=m/2){const k=1-C.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(t.length===0)return 0;let m=0,x=0;for(const S of t){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 w=4;for(let C=-w;C<=w;C++)for(let k=-w;k<=w;k++){if(C===0&&k===0)continue;const M=S+C,T=v+k;if(M>=0&&M<h&&T>=0&&T<l){const I=1/(1+Math.sqrt(C*C+k*k)*.3);b+=f[M][T].signal*I,P+=I}}if(P>0){const C=b/P,k=.6,M=.4;x[S][v].signal=f[S][v].signal*k+C*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(t,e){this.heatmap.updatePositionByOrigin(t,e)}destroy(){this.heatmap.destroy()}}class pc extends L{constructor(e){super();g(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.updateScale(this.appService.currentScale),this.registerScaleListener()}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e!==0&&this.scale.set(1/e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Wi extends pc{constructor(e,i){super(e);g(this,"background");g(this,"icon");g(this,"options");this.appService=e,this.options=i,this.background=new H,this.addChild(this.background),this.icon=new Xt(e),this.addChild(this.icon),this.eventMode="static",this.render(),this.setupHitArea(),this.setupEvents()}setupHitArea(){const e=this.appService,i=this.options.config||e.controlsConfig,s=8,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 e=this.appService,i=this.options.config||e.controlsConfig;this.background.clear(),this.background.roundRect(-i.iconWrapperWidth/2,-i.iconWrapperHeight/2,i.iconWrapperWidth,i.iconWrapperHeight,i.iconWrapperBorderRadius).fill(this.options.backgroundColor)}async renderIcon(){try{const e=this.appService,i=this.options.config||e.controlsConfig;await this.icon.loadTextureAndSetSize(this.options.iconAlias,{width:i.iconWidth,height:i.iconHeight,sizeFixed:!1}),this.icon.visible=!0}catch(e){A.error(`Failed to load icon: ${this.options.iconAlias}`,e)}}destroy(){super.destroy()}}class fc extends Wi{constructor(e,i){super(e,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",e=>{var o,a;if(!this.isRotating)return;this.hasRotated=!0;const i=this.parent.toLocal(e.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 e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});g(this,"handleRotationCancel",()=>{var e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)});this.appService=e,this.setupRotationEventListeners()}setupRotationEventListeners(){const{emitter:e}=this.appService;this.appService.emitter.on("gestureHijackPointerMove",this.handleRotationPointerMove),e.on("gestureHijackPointerUp",this.handleRotationPointerUp),e.on("gestureHijackCancel",this.handleRotationCancel)}cleanupRotationEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleRotationPointerMove),e.off("gestureHijackPointerUp",this.handleRotationPointerUp),e.off("gestureHijackCancel",this.handleRotationCancel)}setupEvents(){this.options.onClick&&(this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.hasRotated||(i=(e=this.options).onClick)==null||i.call(e)},stopPropagation:!1})),this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startRotation(e)}startRotation(e){var n,o;this.isRotating=!0,this.hasRotated=!1;const i=this.options.getTargetPoints();this.rotationCenter=ee(i);const s=this.parent.toLocal(e.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",e)}isCurrentlyRotating(){return this.isRotating}stopRotation(){var e,i;this.isRotating&&(this.isRotating=!1,this.hasRotated&&((i=(e=this.options).onRotationEnd)==null||i.call(e)),this.hasRotated=!1)}destroy(){var e;this.stopRotation(),(e=this.clickHandler)==null||e.destroy(),this.cleanupRotationEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Ds extends Wi{constructor(e,i){super(e,i);g(this,"clickHandler",null);this.appService=e}setupEvents(){this.clickHandler=new vt(this,{onClick:this.options.onClick,stopPropagation:!0})}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),super.destroy()}}class Ze extends Wi{constructor(e,i){super(e,i);g(this,"isScaling",!1);g(this,"initialButtonPosition",null);g(this,"dragStartPosition",null);g(this,"handleScalePointerMove",e=>{var o,a;if(!this.isScaling||!this.initialButtonPosition||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;(a=(o=this.options).onScaleMove)==null||a.call(o,{deltaX:s,deltaY:n})});g(this,"handleScalePointerUp",()=>{var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});g(this,"handleScaleCancel",()=>{var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))});this.appService=e,this.setupScaleEventListeners()}setupScaleEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleScalePointerMove),e.on("gestureHijackPointerUp",this.handleScalePointerUp),e.on("gestureHijackCancel",this.handleScaleCancel)}cleanupScaleEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleScalePointerMove),e.off("gestureHijackPointerUp",this.handleScalePointerUp),e.off("gestureHijackCancel",this.handleScaleCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startScaling(e)}startScaling(e){var i,s,n,o;if(this.isScaling=!0,this.dragStartPosition=this.parent.toLocal(e.global),"initialButtonPosition"in this.options)this.initialButtonPosition={x:this.position.x,y:this.position.y},(s=(i=this.options).onScaleStart)==null||s.call(i);else{const a=this.options.getTargetPoints(),h=this.options.getButtonIndex();h>=0&&h<a.length&&(this.initialButtonPosition={...a[h]}),(o=(n=this.options).onScaleStart)==null||o.call(n,h)}this.appService.emitter.emit("gestureHijackStart",e)}isCurrentlyScaling(){return this.isScaling}stopScaling(){var e,i;this.isScaling&&(this.isScaling=!1,this.initialButtonPosition=null,this.dragStartPosition=null,(i=(e=this.options).onScaleEnd)==null||i.call(e))}destroy(){this.stopScaling(),this.cleanupScaleEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Fs extends Wi{constructor(e,i){super(e,i);g(this,"isMoving",!1);g(this,"dragStartPosition",null);g(this,"handleMovePointerMove",e=>{var i,s;!this.isMoving||!this.dragStartPosition||(s=(i=this.options).onMoveMove)==null||s.call(i,e)});g(this,"handleMovePointerUp",()=>{var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});g(this,"handleMoveCancel",()=>{var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))});this.appService=e,this.setupMoveEventListeners()}setupMoveEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleMovePointerMove),e.on("gestureHijackPointerUp",this.handleMovePointerUp),e.on("gestureHijackCancel",this.handleMoveCancel)}cleanupMoveEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleMovePointerMove),e.off("gestureHijackPointerUp",this.handleMovePointerUp),e.off("gestureHijackCancel",this.handleMoveCancel)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}handlePointerDown(e){e.stopPropagation(),this.startMoving(e)}startMoving(e){var i,s;this.isMoving=!0,this.dragStartPosition=this.parent.toLocal(e.global),(s=(i=this.options).onMoveStart)==null||s.call(i),this.appService.emitter.emit("gestureHijackStart",e)}isCurrentlyMoving(){return this.isMoving}getDragStartPosition(){return this.dragStartPosition?{...this.dragStartPosition}:null}stopMoving(){var e,i;this.isMoving&&(this.isMoving=!1,this.dragStartPosition=null,(i=(e=this.options).onMoveEnd)==null||i.call(e))}destroy(){this.stopMoving(),this.cleanupMoveEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Lr extends H{constructor(e,i){super();g(this,"fillOptions");g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"handlePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});g(this,"handleDragPointerMove",e=>{var i,s;!this.isDragging||!this.dragStartPosition||(s=(i=this.fillOptions).onDragMove)==null||s.call(i,e)});g(this,"handleDragPointerUp",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});g(this,"handleDragCancel",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,(i=(e=this.fillOptions).onDragEnd)==null||i.call(e))});this.appService=e,this.fillOptions=i,this.setupInteraction(),this.setupDragEventListeners(),this.draw()}setupInteraction(){this.fillOptions.enableInteraction&&(this.eventMode="static",this.on("pointerdown",this.handlePointerDown))}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}startDragging(e){var s,n;this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},(n=(s=this.fillOptions).onDragStart)==null||n.call(s,e),this.appService.emitter.emit("gestureHijackStart",e)}draw(){const{points:e,fillColor:i}=this.fillOptions;if(e.length<3)return;this.clear();const s=e.flatMap(n=>[n.x,n.y]);this.setFillStyle({color:i}).poly(s).fill()}getDragStartPosition(){return this.dragStartPosition}updateOptions(e){this.fillOptions={...this.fillOptions,...e},e.enableInteraction!==void 0&&(this.off("pointerdown",this.handlePointerDown),this.setupInteraction()),this.draw()}updatePoints(e){this.fillOptions.points=e,this.draw()}updateFillColor(e){this.fillOptions.fillColor=e,this.draw()}stopDragging(){this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null)}isCurrentlyDragging(){return this.isDragging}setInteractionEnabled(e){this.fillOptions.enableInteraction=e,e?(this.eventMode="static",this.on("pointerdown",this.handlePointerDown)):(this.eventMode="auto",this.off("pointerdown",this.handlePointerDown),this.isDragging&&this.stopDragging())}destroy(){this.stopDragging(),this.cleanupDragEventListeners(),this.off("pointerdown",this.handlePointerDown),super.destroy()}}class Nt extends L{constructor(e,i){super();g(this,"borderOptions");g(this,"solidLine",null);g(this,"dashGraphics",null);g(this,"fillGraphics",null);g(this,"handleAntiScale",()=>{this.drawBorder()});this.appService=e,this.borderOptions={...i},this.drawBorder(),this.setupAntiScaleListener(),this.eventMode="none"}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.handleAntiScale)}drawBorder(){const{points:e=[],closePath:i=!1,style:s}=this.borderOptions;e.length<2||(this.clearBorder(),s.fillColor!==void 0&&i&&this.drawFill(e,s),s.isDashed?this.drawContinuousDashedBorder(e,i,s):this.drawSolidBorder(e,i,s))}drawFill(e,i){if(!(!i.fillColor||e.length<3)){this.fillGraphics&&(this.removeChild(this.fillGraphics),this.fillGraphics.destroy()),this.fillGraphics=new H,this.fillGraphics.setFillStyle({color:i.fillColor}),this.fillGraphics.moveTo(e[0].x,e[0].y);for(let s=1;s<e.length;s++)this.fillGraphics.lineTo(e[s].x,e[s].y);this.fillGraphics.closePath(),this.fillGraphics.fill(),this.addChild(this.fillGraphics)}}drawSolidBorder(e,i,s){const 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(e[0].x,e[0].y);for(let a=1;a<e.length;a++)this.solidLine.lineTo(e[a].x,e[a].y);i&&this.solidLine.lineTo(e[0].x,e[0].y),this.solidLine.stroke(),this.addChild(this.solidLine)}drawContinuousDashedBorder(e,i,s){if(e.length<2)return;if(!s.dashArray||s.dashArray.length!==2||s.dashArray[0]<=0||s.dashArray[1]<=0){A.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?[...e,e[0]]:e;this.drawContinuousPathDashes(this.dashGraphics,l,a,h),this.dashGraphics.stroke(),this.addChild(this.dashGraphics)}drawContinuousPathDashes(e,i,s,n){if(i.length<2)return;if(s<=0||n<=0){A.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(e,o,l,c):this.drawContinuousDashSegment(e,o,l,a),l+=h}}calculatePathSegments(e){const i=[];for(let s=0;s<e.length-1;s++){const n=e[s],o=e[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(e,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&&e.lineTo(m.x,m.y):(e.moveTo(m.x,m.y),a=!0),e.lineTo(x.x,x.y),h=x}if(o+=l.length,o>=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(e){this.borderOptions.style={...this.borderOptions.style,...e},this.drawBorder()}updatePoints(e){this.borderOptions.points=e,this.drawBorder()}setClosePath(e){this.borderOptions.closePath=e,this.drawBorder()}getOptions(){return{...this.borderOptions}}destroy(){this.appService.emitter.off("antiScale",this.handleAntiScale),this.clearBorder(),super.destroy()}}class Ui extends Es{constructor(e,{text:i,style:s}){super({text:i,style:s});g(this,"throttledUpdateScale");this.appService=e,this.throttledUpdateScale=At(this.updateScale.bind(this),20,{leading:!0,trailing:!0}),this.registerScaleListener(),this.updateScale(this.appService.currentScale)}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}updateScale(e){e<=0||this.scale.set(1/e)}setBaseFontSize(e){this.style.fontSize=e}updateText(e){this.text=e}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}const Ct=class Ct extends L{constructor(e){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,"throttledUpdateOutline");g(this,"handleDragStart",e=>{this.isEditingEnabled()&&(this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.dragStartPosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.dragStartPosition=null,this.appService.getApp().stopRender("zone-drag"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleRotationStart",e=>{this.totalRotationAngle=0,this.rotationCenter=e,this.initialZonePoints=this.zoneData.points.map(i=>({...i})),this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",e=>{this.totalRotationAngle+=e,this.applyRotation(this.totalRotationAngle)});g(this,"handleRotationEnd",()=>{var e,i;this.rotationCenter=null,this.totalRotationAngle=0,this.initialZonePoints=[],this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleScaleStart",()=>{this.initialZonePoints=this.zoneData.points.map(i=>({...i}));const e=Ct.BUTTON_INDICES.SCALE;e<this.zoneData.points.length&&(this.initialButtonPosition={...this.zoneData.points[e]}),this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialZonePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var e,i;this.initialZonePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("zone-scale"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleMoveStart",()=>{this.initialZonePoints=this.zoneData.points.map(e=>({...e})),this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",e=>{var a;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.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 e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.zoneEvents).onUpdate)==null||i.call(e,this.getZoneData())});g(this,"handleDelete",()=>{var e,i;(i=(e=this.zoneEvents).onRemove)==null||i.call(e,this.zoneData.id)});const{appService:i,zoneData:s,zoneType:n,events:o={}}=e;this.appService=i,this.zoneType=n,this.zoneEvents=o,this.zoneConfig=this.getZoneConfig(),this.controlsConfig=this.getControlsConfig();const a=this.validateAndCorrectZoneSize(s.points),h=bs(a);this.zoneData={...s,points:h},this.throttledUpdateOutline=At(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(){const{controls:e}=this.appService.getConfig();return e[this.zoneType]}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}validateAndCorrectZoneSize(e){if(e.length<4)return e;const i=this.appService.metersToPixels(this.zoneConfig.minSize),[s,n,,o]=e,a=Q(s,n),h=Q(s,o);if(a>=i&&h>=i)return e;const l=ee(e),c=pt(q(s,n)),d=pt(q(s,o)),u=Math.max(a,i),p=Math.max(h,i),f=u/2,y=p/2;return[{x:l.x-c.x*f-d.x*y,y:l.y-c.y*f-d.y*y},{x:l.x+c.x*f-d.x*y,y:l.y+c.y*f-d.y*y},{x:l.x+c.x*f+d.x*y,y:l.y+c.y*f+d.y*y},{x:l.x-c.x*f+d.x*y,y:l.y-c.y*f+d.y*y}]}getEditingIdsKey(){switch(this.zoneType){case"forbiddenSweepZone":return"editingForbiddenSweepZoneIds";case"forbiddenMopZone":return"editingForbiddenMopZoneIds";case"cleanZone":return"editingCleanZoneIds";default:return"editingForbiddenSweepZoneIds"}}isEditingEnabled(){const e=this.getEditingIdsKey();return this.appService.runtimeSnapshot[e].includes(this.zoneData.id)}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 e=this.calculateOutlinePoints();if(e.length<4)return;this.deleteButton=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,onClick:this.handleDelete}),this.deleteButton.position.set(e[Ct.BUTTON_INDICES.REMOVE].x,e[Ct.BUTTON_INDICES.REMOVE].y),this.zoneConfig.showRotateButton&&(this.rotateButton=new fc(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(e[Ct.BUTTON_INDICES.ROTATE].x,e[Ct.BUTTON_INDICES.ROTATE].y)),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.zoneConfig.iconWrapperFillColor,getTargetPoints:()=>this.zoneData.points,getButtonIndex:()=>Ct.BUTTON_INDICES.SCALE,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[Ct.BUTTON_INDICES.SCALE].x,e[Ct.BUTTON_INDICES.SCALE].y);const i=this.calculateMoveButtonPosition();this.moveButton=new Fs(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 e=this.isEditingEnabled();return new Lr(this.appService,{points:this.zoneData.points,fillColor:this.zoneConfig.fillColor,enableInteraction:e,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 e=this.calculateOutlinePoints();return new Nt(this.appService,{points:e,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 e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);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:e}=this.zoneData;if(e.length<4)return e;const i=this.appService.getApp().toFixedSize(this.zoneConfig.outlineOffset);return Ir(e,i)}calculateMoveLinePoints(e){if(e.length<4)return[];const i=e[Ct.BUTTON_INDICES.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}createSizeText(){const e=this.calculateZoneSizeText(),i=new Ui(this.appService,{text:e,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:e}=this.zoneData;if(e.length<4)return"0m*0m";const[i,s,,n]=e,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:e}=this.zoneData;if(e.length<4)return{x:0,y:0};const[i,s,n,o]=e,{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=pt(q(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=pt(q(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=pt(q(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=pt(q(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:e}=this.zoneData;if(e.length<4)return 0;const[i,s,n,o]=e,{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 Xe(h,l,c)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const{controls:i}=this.appService.getConfig(),s=e[Ct.BUTTON_INDICES.MOVE],n=e[2],o=e[0],a=this.appService.getApp().toFixedSize(i.moveButtonOffset);return Is(s,n,o,a)}applyTranslation(e,i){this.zoneData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawZone(),this.updateControlButtonsPosition()}applyRotation(e){!this.rotationCenter||this.initialZonePoints.length===0||(this.zoneData.points=Er(this.initialZonePoints,this.rotationCenter,e),this.drawZone(!1),this.updateControlButtonsPosition())}applyEdgeBasedScale(e){if(this.initialZonePoints.length<4)return;const{FIXED:i}=Ct.BUTTON_INDICES,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=q(h,o),c=q(h,a),d=q(h,e),u=ie(l),p=ie(c);if(u===0||p===0)return;const f=this.appService.metersToPixels(this.zoneConfig.minSize),[y,m]=[he(d,l,u,f),he(d,c,p,f)];this.zoneData.points=[h,{x:s+l.x*y,y:n+l.y*y},{x:s+l.x*y+c.x*m,y:n+l.y*y+c.y*m},{x:s+c.x*m,y:n+c.y*m}],this.drawZone(),this.updateControlButtonsPosition()}setupClickHandler(){this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.isEditingEnabled()||(i=(e=this.zoneEvents)==null?void 0:e.onClick)==null||i.call(e,this.getZoneData())},stopPropagation:!1})}drawZone(e=!0){const{points:i}=this.zoneData;i.length<4||(this.controlFill.updatePoints(i),this.zoneBorder.updatePoints(i),this.updateOutlineBorder(),this.updateMoveLine(),this.updateSizeText(e))}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e)}updateMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateZoneSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,ROTATE:s,SCALE:n}=Ct.BUTTON_INDICES,o=this.calculateMoveButtonPosition(),a=[{button:this.deleteButton,point:e[i]},{button:this.scaleButton,point:e[n]},{button:this.moveButton,point:o}];this.rotateButton&&a.push({button:this.rotateButton,point:e[s]}),a.forEach(({button:h,point:l})=>h.position.set(l.x,l.y))}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,!e&&this.getCurrentOperationState().hasAnyOperation&&this.stopAllOperations(),this.outlineBorder.visible=e,this.moveLine.visible=e,this.sizeText&&(this.sizeText.visible=e),e&&(this.updateOutlineBorder(),this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition()),this.controlFill.setInteractionEnabled(e),this.updateBorderStyle(e?this.zoneConfig.editing:this.zoneConfig.normal),this.zIndex=e?1e3:0}updateBorderStyle(e){this.zoneBorder.updateStyle({isDashed:e.isDashed,dashArray:e.dashArray})}getCurrentOperationState(){var o,a,h;const e=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:e,isScaling:i,isRotating:s,isMoving:n,hasAnyOperation:e||i||s||n}}stopAllOperations(){var e,i,s;this.controlFill.stopDragging(),(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}stopDragging(){this.controlFill.stopDragging()}stopScaling(){var e;(e=this.scaleButton)==null||e.stopScaling()}stopRotating(){var e;(e=this.rotateButton)==null||e.stopRotation()}stopMoving(){var e;(e=this.moveButton)==null||e.stopMoving()}isCurrentlyDragging(){return this.controlFill.isCurrentlyDragging()}isCurrentlyScaling(){var e;return((e=this.scaleButton)==null?void 0:e.isCurrentlyScaling())||!1}isCurrentlyRotating(){var e;return((e=this.rotateButton)==null?void 0:e.isCurrentlyRotating())||!1}isCurrentlyMoving(){var e;return((e=this.moveButton)==null?void 0:e.isCurrentlyMoving())||!1}updateZoneData(e){const i=this.validateAndCorrectZoneSize(e.points),s=bs(i);this.zoneData={...e,points:s},this.drawZone(),this.updateControlButtonsPosition(),this.updateEditState()}getZoneData(){return{...this.zoneData}}refreshDisplay(){this.drawZone()}destroy(){var e,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(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(Ct,"BUTTON_INDICES",{REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0});let Li=Ct;class Or extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"forbiddenSweepZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveForbiddenSweepZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateForbiddenSweepZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickForbiddenSweepZone)==null||n.call(s,i)}}})}static create(t,e){return new Or(t,{zoneData:e})}}class Gr extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"forbiddenMopZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveForbiddenMopZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateForbiddenMopZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickForbiddenMopZone)==null||n.call(s,i)}}})}static create(t,e){return new Gr(t,{zoneData:e})}}class Wr extends Li{constructor(t,e){super({appService:t,zoneData:e.zoneData,zoneType:"cleanZone",events:{onRemove:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onRemoveCleanZone)==null||n.call(s,i)},onUpdate:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onUpdateCleanZone)==null||n.call(s,i)},onClick:i=>{var s,n;(n=(s=t.events)==null?void 0:s.onClickCleanZone)==null||n.call(s,i)}}})}static create(t,e){return new Wr(t,{zoneData:e})}}class Ue extends H{constructor(e,i){super();g(this,"lineOptions");g(this,"strokeContext",null);g(this,"drawDashLine",()=>{const{start:e,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,e.x,e.y,i.x,i.y,s.dashArray[0],s.dashArray[1]),this.strokeContext.stroke(),this.context=this.strokeContext});this.appService=e,this.lineOptions={...i},this.eventMode="static",this.drawDashLine(),this.setupAntiScaleListener()}setupAntiScaleListener(){this.appService.emitter.on("antiScale",this.drawDashLine)}drawDashedLineToContext(e,i,s,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){e.moveTo(i,s),e.lineTo(n,o);return}const S=d/x,v=S*(p/y),b=l/d,P=c/d;for(let w=0;w<x;w++){const C=w*S,k=C+v;if(C>=d)break;const M=Math.min(k,d),T=i+C*b,_=s+C*P,I=i+M*b,B=s+M*P;e.moveTo(T,_),e.lineTo(I,B)}}updatePoints(e,i){this.lineOptions.start=e,this.lineOptions.end=i,this.drawDashLine()}updateStyle(e){this.lineOptions.style={...this.lineOptions.style,...e},this.drawDashLine()}getOptions(){return{...this.lineOptions}}destroy(){this.appService.emitter.off("antiScale",this.drawDashLine),this.strokeContext&&this.strokeContext.destroy(),super.destroy()}}const Vt=class Vt extends L{constructor(e){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,"throttledUpdateOutline");g(this,"throttledHandleScaleChange");g(this,"wallLineClickHandler",null);g(this,"handleRemove",()=>{var e,i;(i=(e=this.wallEvents).onRemove)==null||i.call(e,this.wallData.id)});g(this,"initializeOperation",()=>{this.initialWallPoints=this.wallData.points.map(e=>({...e}))});g(this,"finalizeOperation",()=>{var e,i;this.initialWallPoints=[],(i=(e=this.wallEvents).onUpdate)==null||i.call(e,this.getWallData())});g(this,"handleScaleStart",()=>{this.initializeOperation();const e=this.calculateOutlinePoints();e.length>Vt.BUTTON_INDICES.SCALE&&(this.initialButtonPosition={...e[Vt.BUTTON_INDICES.SCALE]}),this.appService.getApp().requestRender("virtualwall-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialWallPoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyScaleAndRotation(s)});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",e=>{var a;if(this.initialWallPoints.length===0)return;const i=this.parent.toLocal(e.global),s=this.getDragStartPosition()||((a=this.moveButton)==null?void 0:a.getDragStartPosition());if(!s)return;const 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",e=>{this.isEditingEnabled()&&(e.stopPropagation(),this.startDragging(e))});g(this,"handleDragPointerMove",e=>{!this.isDragging||!this.dragStartPosition||this.handleMove(e)});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={}}=e;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=At(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.throttledUpdateOutline=At(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)}validateAndCorrectWallLength(e){if(e.length<2)return e;const[i,s]=e,n=this.appService.metersToPixels(this.wallConfig.minWidth),o=Q(i,s);if(o>=n)return e;if(o===0)return[i,{x:i.x+n,y:i.y}];const a=pt(q(i,s));return[i,{x:i.x+a.x*n,y:i.y+a.y*n}]}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(e=!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()),e&&this.setupWallLineInteraction()}createLengthText(){const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e),s=new Ui(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:e}=this.wallData;if(e.length<2)return 0;const i=Q(e[0],e[1]);return this.appService.pixelsToMeters(i)}formatLengthText(e){const i=this.appService.metersToDisplayUnit(e),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}`}calculateTextPosition(){const{points:e}=this.wallData;if(e.length<2)return{x:0,y:0};const[i,s]=e,n=this.appService.getApp().toFixedSize(this.wallConfig.textOffset);return Jl(i,s,n)}calculateTextRotation(){const{points:e}=this.wallData;if(e.length<2)return 0;const[i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(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 e=this.calculateOutlinePoints();return new Nt(this.appService,{points:e,closePath:!0,style:this.getOutlineStyle()})}createMoveLine(){const e=this.calculateOutlinePoints(),i=this.calculateMoveLinePoints(e);return new Nt(this.appService,{points:i,closePath:!1,style:this.getOutlineStyle()})}calculateOutlinePoints(e){const i=e||this.wallData.points;if(i.length<2)return i;const s=this.appService.getApp().toFixedSize(this.wallConfig.outlineOffset),n=dy(i[0],i[1],s);return[n[3],n[2],n[1],n[0]]}calculateMoveLinePoints(e){if(e.length<4)return[];const{MOVE:i}=Vt.BUTTON_INDICES,s=e[i],n=this.calculateMoveButtonPosition();return[s,n]}calculateMoveButtonPosition(){const{moveButtonOffset:e}=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(e);return Is(n,a,o,h)}createControlButtons(){const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES;this.removeButton=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,onClick:this.handleRemove}),this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.wallConfig.iconWrapperFillColor,getTargetPoints:()=>this.calculateOutlinePoints(),getButtonIndex:()=>s,onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[s].x,e[s].y);const n=this.calculateMoveButtonPosition();this.moveButton=new Fs(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(e){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=q(s,a),c={x:e.x-l.x,y:e.y-l.y},d=q(n,c),u=Q(n,c),p=this.appService.metersToPixels(this.wallConfig.minWidth);let f;if(u<p)if(u===0)f={x:n.x+p,y:n.y};else{const y=pt(d);f={x:n.x+y.x*p,y:n.y+y.y*p}}else f=c;this.wallData.points=[n,f],this.drawVirtualWall(),this.updateControlButtonsPosition()}applyTranslation(e,i){this.wallData.points=this.initialWallPoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawVirtualWall(),this.updateControlButtonsPosition()}drawVirtualWall(){this.updateWallLine(),this.updateLengthText(),this.updateOutlineComponents()}updateWallLine(){const{points:e}=this.wallData;e.length<2||(this.wallLine instanceof Ue?this.wallLine.updatePoints(e[0],e[1]):this.redrawSolidLine(),this.setupWallLineHitArea())}updateLengthText(){if(!this.lengthText)return;const e=this.calculateWallLengthInMeters(),i=this.formatLengthText(e);this.lengthText.updateText(i),this.updateLengthTextPosition()}updateLengthTextPosition(){if(!this.lengthText)return;const e=this.calculateTextPosition();this.lengthText.position.set(e.x,e.y);const i=this.calculateTextRotation();this.lengthText.rotation=i}updateOutlineComponents(){const e=this.calculateOutlinePoints();this.outlineBorder.updatePoints(e);const i=this.calculateMoveLinePoints(e);this.moveLine.updatePoints(i)}updateControlButtonsPosition(){if(!this.removeButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const{REMOVE:i,SCALE:s}=Vt.BUTTON_INDICES,n=this.calculateMoveButtonPosition();this.removeButton.position.set(e[i].x,e[i].y),this.scaleButton.position.set(e[s].x,e[s].y),this.moveButton.position.set(n.x,n.y)}updateEditState(){const e=this.isEditingEnabled();this.controlButtons.visible=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.lengthText&&(this.lengthText.visible=e),e&&(this.updateOutlineComponents(),this.updateControlButtonsPosition(),this.updateLengthTextPosition()),this.updateWallLineStyle(),this.setupWallLineInteraction(),this.zIndex=e?1e3:0}createSolidLine(e,i,s,n){const o=new H;o.eventMode="static";const a=this.appService.getApp().toFixedSize(s);return o.moveTo(e.x,e.y),o.lineTo(i.x,i.y),o.stroke({color:n,width:a}),o}updateWallLineStyle(){const e=this.isEditingEnabled(),{editing:i,normal:s,lineWidth:n,lineColor:o}=this.wallConfig,a=e?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 e=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=e.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 e=this.isEditingEnabled();(i=this.wallLineClickHandler)==null||i.destroy(),this.wallLineClickHandler=null,this.wallLine.off("pointerdown",this.handleWallLinePointerDown),e?this.wallLine.on("pointerdown",this.handleWallLinePointerDown):this.wallLineClickHandler=new 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:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}startDragging(e){const i=this.appService;this.isDragging=!0;const s=this.parent.toLocal(e.global);this.dragStartPosition={x:s.x,y:s.y},this.initializeOperation(),i.getApp().requestRender("virtualwall-drag",!0),this.appService.emitter.emit("gestureHijackStart",e)}getDragStartPosition(){return this.dragStartPosition}setupWallLineHitArea(){if(!this.wallLine)return;const{points:e}=this.wallData;if(e.length<2)return;const{hitAreaThickness:i}=this.wallConfig,s=this.appService.getApp().toFixedSize(i),n=tc(e[0],e[1],s);if(n.length===0)return;const o=new Te(n);this.wallLine.hitArea=o}getWallData(){return{...this.wallData}}updateWallData(e){this.wallData={...e,points:this.validateAndCorrectWallLength(e.points)},this.drawVirtualWall(),this.updateControlButtonsPosition()}updateEditingState(){this.updateEditState()}refreshDisplay(){this.drawVirtualWall()}destroy(){var e,i,s,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),(e=this.wallLineClickHandler)==null||e.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 nr=Vt;class Ur extends L{constructor(e){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",e=>{this.isEditingEnabled()&&(this.initialSpotPoint={...this.spotData.point},this.dragStartMousePosition=this.parent.toLocal(e.global),this.appService.getApp().requestRender("spot-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||!this.initialSpotPoint||!this.dragStartMousePosition||!this.controlFill)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartMousePosition.x,n=i.y-this.dragStartMousePosition.y;this.applyTranslation(s,n)});g(this,"handleDragEnd",()=>{var e,i;this.initialSpotPoint=null,this.dragStartMousePosition=null,this.appService.getApp().stopRender("spot-drag"),(i=(e=this.spotEvents).onUpdate)==null||i.call(e,this.getSpotData())});const{appService:i,spotData:s,events:n={}}=e;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=At(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:e}=this.spotConfig;if(e===0)return[{x:0,y:0},{x:0,y:0},{x:0,y:0},{x:0,y:0}];const s=this.appService.metersToPixels(e)/2;return[{x:-s,y:-s},{x:s,y:-s},{x:s,y:s},{x:-s,y:s}]}initializeComponents(){const e=this.calculateRectanglePoints();this.spotConfig.size>0&&(this.controlFill=this.createControlFill(e),this.addChild(this.controlFill),this.spotBorder=this.createBorder(e),this.addChild(this.spotBorder)),this.centerIcon=this.createCenterIcon(),this.addChild(this.centerIcon),this.spotConfig.showText&&(this.sizeText=this.createSizeText(),this.addChild(this.sizeText)),this.drawSpot()}createControlFill(e){const i=this.isEditingEnabled();return new Lr(this.appService,{points:e,fillColor:this.spotConfig.fillColor,enableInteraction:i,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createBorder(e){const s=this.isEditingEnabled()?this.spotConfig.editing:this.spotConfig.normal;return new Nt(this.appService,{points:e,closePath:!0,style:{color:this.spotConfig.strokeColor,width:this.spotConfig.strokeWidth,isDashed:s.isDashed,dashArray:s.dashArray}})}createCenterIcon(){const e=new Xt(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.eventMode="static",this.setupIconDrag(e),e.visible=!1,e}async loadIconTexture(e){const{iconSize:i,iconSizeFixed:s}=this.spotConfig;await e.loadTextureAndSetSize("spotIcon",{width:i,height:i,sizeFixed:s}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)})),e.visible=this.shouldShowIcon()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupIconDrag(e){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))};e.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 e=this.calculateSpotSizeText(),i=new Ui(this.appService,{text:e,style:{fontSize:this.controlsConfig.textFontSize,fontFamily:this.controlsConfig.textFontFamily,fontWeight:this.controlsConfig.textFontWeight,fill:this.spotConfig.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();return i.position.set(s.x,s.y),i.eventMode="none",i}calculateSpotSizeText(){const{size:e}=this.spotConfig,i=this.appService.metersToDisplayUnit(e),s=this.appService.runtimeSnapshot.unitLabel;return`${i.toFixed(1)}${s}*${i.toFixed(1)}${s}`}calculateSizeTextPosition(){const e=this.calculateRectanglePoints();if(e.length<4)return{x:0,y:0};const[i,s,n,o]=e,{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(e,i){this.initialSpotPoint&&(this.spotData.point={x:this.initialSpotPoint.x+e,y:this.initialSpotPoint.y+i},this.drawSpot())}setupClickHandler(){const e=this.spotConfig.size>0?this:this.centerIcon;this.clickHandler=new vt(e,{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 e=this.calculateRectanglePoints();this.position.set(this.spotData.point.x,this.spotData.point.y),this.spotConfig.size>0&&(this.controlFill&&this.controlFill.updatePoints(e),this.spotBorder&&this.spotBorder.updatePoints(e)),this.spotConfig.showText&&this.sizeText&&this.updateSizeText()}updateSizeText(){if(!this.sizeText)return;const e=this.calculateSpotSizeText();this.sizeText.updateText(e),this.updateSizeTextPosition()}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y)}updateEditState(){const e=this.isEditingEnabled(),i=e?this.spotConfig.editing:this.spotConfig.normal;this.sizeText&&(this.sizeText.visible=e&&this.spotConfig.showText),this.centerIcon&&(this.centerIcon.visible=this.shouldShowIcon()),this.controlFill&&(this.controlFill.setInteractionEnabled(e),this.controlFill.visible=i.showFrame),this.spotBorder&&(this.spotBorder.updateStyle({isDashed:i.isDashed,dashArray:i.dashArray}),this.spotBorder.visible=i.showFrame),this.zIndex=e?1e3:0}updateSpotData(e){this.spotData={...e},this.drawSpot(),this.updateEditState()}getSpotData(){return{...this.spotData}}refreshDisplay(){this.drawSpot()}destroy(){var e,i,s,n,o;this.appService.emitter.off("antiScale",this.throttledUpdateScale),this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.centerIcon&&this.spotConfig.size===0&&this.centerIcon.removeAllListeners(),(i=this.controlFill)==null||i.destroy(),(s=this.spotBorder)==null||s.destroy(),(n=this.centerIcon)==null||n.destroy(),(o=this.sizeText)==null||o.destroy(),super.destroy()}static create(e,i){return new Ur({appService:e,spotData:i,events:{onUpdate:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onUpdateSpot)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onClickSpot)==null||o.call(n,s)}}})}}class $x extends pc{constructor(e){const{appService:i,wayPointData:s,order:n,events:o={}}=e;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 e=new Xt(this.appService);return this.loadIconTexture(e),e.position.set(0,0),e.anchor.set(.5,1),e.eventMode="static",this.setupIconDrag(e),e}async loadIconTexture(e){const i=this.isEditingEnabled(),s=i?this.wayPointConfig.editing:this.wayPointConfig.normal,{iconSize:n}=s,o=i?"wayPointActive":"wayPoint";await e.loadTextureAndSetSize(o,{width:n,height:n,sizeFixed:!1}),this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation||(this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",a=>{this.applyAntiRotation(a)})),e.visible=!0,this.orderContainer&&this.updateOrderPosition()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}createOrderContainer(){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal,{orderContainer:s,orderText:n}=i;this.orderContainer=new L,this.orderBackground=new H,this.orderText=new Es({text:this.order.toString(),style:new de({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(e){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"))};e.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 e,i;this.appService.emitter.emit("suppressMapClick"),(i=(e=this.wayPointEvents).onClick)==null||i.call(e,this.wayPointData)}})}updateWayPoint(e){this.wayPointData=e,this.drawWayPoint()}updateOrder(e){this.order=e,this.orderText&&(this.orderText.text=e.toString())}getWayPointData(){return{...this.wayPointData}}drawWayPoint(){this.position.set(this.wayPointData.point.x,this.wayPointData.point.y),this.orderContainer&&this.updateOrderPosition()}updateEditState(){if(this.loadIconTexture(this.icon),this.orderContainer&&this.orderText&&this.orderBackground){const i=this.isEditingEnabled()?this.wayPointConfig.editing:this.wayPointConfig.normal;this.orderText.style=new de({fontSize:i.orderText.fontSize,fontFamily:i.orderText.fontFamily,fontWeight:i.orderText.fontWeight,fill:i.orderText.color,align:"center",trim:!0});const{size:s,backgroundColor: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 Ya extends H{constructor(e,i){super();g(this,"isDragging",!1);g(this,"dragStartPosition",null);g(this,"initialPosition");g(this,"handleDragPointerMove",e=>{var a,h;if(!this.isDragging||!this.dragStartPosition)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,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 e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});g(this,"handleDragCancel",()=>{var i,s;if(!this.isDragging)return;const e=this.appService;this.isDragging=!1,this.dragStartPosition=null,e.getApp().stopRender("endpoint-drag"),(s=(i=this.options).onDragEnd)==null||s.call(i)});this.appService=e,this.options=i,this.initialPosition={...i.position},this.position.set(i.position.x,i.position.y),this.eventMode="static",this.cursor="pointer",this.setupEvents(),this.draw(),this.setupDragEventListeners()}draw(){const e=this.appService,{config:i}=this.options,s=e.getApp().toFixedSize(i.endPointSize),n=e.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 e=this.appService,{config:i}=this.options,s=Math.max(i.endPointSize/2+10,20),n=e.getApp().toFixedSize(s);this.hitArea=new Ts(0,0,n)}setupEvents(){this.on("pointerdown",this.handlePointerDown.bind(this))}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}handlePointerDown(e){e.stopPropagation(),this.startDragging(e)}startDragging(e){var s,n;const i=this.appService;this.isDragging=!0,this.dragStartPosition=this.parent.toLocal(e.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",e)}updatePosition(e){this.position.set(e.x,e.y),this.initialPosition={...e}}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 Qx extends L{constructor(e){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(e=>({...e})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-endpoint-drag",!0)});g(this,"handleEndPointDragMove",(e,i)=>{this.initialDividerPoints.length!==0&&(this.endPoints[e]=i,this.updateDashLine(),this.updateSolidLine(),this.setupDashLineHitArea())});g(this,"handleEndPointDragEnd",()=>{var e,i;this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-endpoint-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints())});g(this,"handleDashLinePointerDown",e=>{e.stopPropagation(),this.startDragging(e)});g(this,"handleDragPointerMove",e=>{if(!this.isDragging||!this.dragStartPosition||this.initialDividerPoints.length===0)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,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 e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});g(this,"handleDragCancel",()=>{var e,i;this.isDragging&&(this.isDragging=!1,this.dragStartPosition=null,this.initialDividerPoints=[],this.appService.getApp().stopRender("divider-drag"),this.calculateAndCreateSolidLine(),this.checkAndResetIfOutOfRoom(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.getDividerEndPoints()))});g(this,"handleScaleChange",()=>{var e,i;(e=this.startEndPoint)==null||e.redraw(),(i=this.endEndPoint)==null||i.redraw(),this.updateSolidLine(),this.setupDashLineHitArea()});const{appService:i,endPoints:s,roomId:n,events:o={}}=e;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=At(this.handleScaleChange.bind(this),30,{leading:!0,trailing:!0}),this.initializeComponents(),this.calculateAndCreateSolidLine(),this.registerScaleListener(),this.setupDragEventListeners()}validateDividerPoints(e){if(e.length>=2)return e.slice(0,2);const i=e[0]||{x:0,y:0},s={x:i.x+50,y:i.y};return[i,s]}createDefaultdividerPoints(){if(!this.roomGeometry)return A.warn("Room geometry not available, creating fallback divider"),[{x:0,y:0},{x:100,y:0}];const e=this.appService.getApp().mapState;if(!e)return A.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 Sy(o,a,h,n).map(c=>({x:c.x-e.origin.x,y:c.y-e.origin.y}))}initializeComponents(){this.createDashLine(),this.addChild(this.dashLine),this.createEndPoints(),this.addChild(this.startEndPoint),this.addChild(this.endEndPoint),this.setupDashLineInteraction()}createDashLine(){const e=this.endPoints;if(e.length<2)return;const{dashLineWidth:i,dashLineDashArray:s,lineColor:n}=this.dividerConfig;this.dashLine=new Ue(this.appService,{start:e[0],end:e[1],style:{color:n.toString(),width:i,dashArray:s}})}createEndPoints(){const e=this.endPoints;this.startEndPoint=new Ya(this.appService,{position:e[0],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(0,i),onDragEnd:this.handleEndPointDragEnd}),this.endEndPoint=new Ya(this.appService,{position:e[1],config:this.dividerConfig,onDragStart:this.handleEndPointDragStart,onDragMove:i=>this.handleEndPointDragMove(1,i),onDragEnd:this.handleEndPointDragEnd})}setupDashLineInteraction(){this.dashLine&&(this.setupDashLineHitArea(),this.dashLine.off("pointerdown",this.handleDashLinePointerDown),this.dashLine.on("pointerdown",this.handleDashLinePointerDown))}setupDashLineHitArea(){if(!this.dashLine)return;const e=this.endPoints;if(e.length<2)return;const{hitAreaThickness:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(i),n=tc(e[0],e[1],s);if(n.length===0)return;const o=new Te(n);this.dashLine.hitArea=o}startDragging(e){this.isDragging=!0;const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialDividerPoints=this.endPoints.map(s=>({...s})),this.clearSolidLine(),this.appService.getApp().requestRender("divider-drag",!0),this.appService.emitter.emit("gestureHijackStart",e)}setupDragEventListeners(){const{emitter:e}=this.appService;e.on("gestureHijackPointerMove",this.handleDragPointerMove),e.on("gestureHijackPointerUp",this.handleDragPointerUp),e.on("gestureHijackCancel",this.handleDragCancel)}cleanupDragEventListeners(){const{emitter:e}=this.appService;e.off("gestureHijackPointerMove",this.handleDragPointerMove),e.off("gestureHijackPointerUp",this.handleDragPointerUp),e.off("gestureHijackCancel",this.handleDragCancel)}updateAllComponents(){this.updateDashLine(),this.updateSolidLine(),this.updateEndPoints(),this.setupDashLineHitArea()}updateDashLine(){const e=this.endPoints;e.length<2||!this.dashLine||this.dashLine.updatePoints(e[0],e[1])}updateSolidLine(){if(!this.solidLine||!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig,s=this.appService.getApp().toFixedSize(e);this.solidLine.clear(),this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke()}updateEndPoints(){const e=this.endPoints;this.startEndPoint&&this.startEndPoint.updatePosition(e[0]),this.endEndPoint&&this.endEndPoint.updatePosition(e[1])}registerScaleListener(){const{emitter:e}=this.appService;e.on("antiScale",this.throttledHandleScaleChange)}getDividerEndPoints(){return[...this.endPoints]}getEffectiveDividerPoints(){return this.solidLinePoints?[...this.solidLinePoints]:null}calculateAndCreateSolidLine(){if(this.clearSolidLine(),typeof this.roomId!="number"||!this.getRoomGraphics())return;const i=this.calculateLineRoomIntersection();i&&i.length>=2&&(this.solidLinePoints=[i[0],i[i.length-1]],this.createSolidLine())}getRoomGraphics(){const e=this.appService.mapManager.roomFill;return!e||typeof this.roomId!="number"?null:e.getRoomGraphicsMap().get(this.roomId)||null}calculateLineRoomIntersection(){const e=this.endPoints;if(e.length<2||typeof this.roomId!="number")return null;const[i,s]=e,n=this.isPointInRoomFill(i),o=this.isPointInRoomFill(s);if(n||o)return null;const a=oy(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:vy(l,c,.5)}isPointInRoomFill(e){if(typeof this.roomId!="number")return!1;const i=this.appService.getApp().mapState;if(!i)return!1;const s={x:e.x+i.origin.x,y:e.y+i.origin.y};return i.mapType==="raster"?this.isPointInRasterRoomFill(s):this.isPointInStructuredRoomFill(s)}isPointInRasterRoomFill(e){e.x-=.5,e.y-=.5;const i=this.appService.getApp().mapState,s=this.appService.mapManager.roomFill;if(!i||!s)return!1;const n=s.getRasterRoomData(this.roomId);if(!n)return!1;const o=s.getMapWidth();if(o===0)return!1;const a=Math.round(e.x),h=Math.round(e.y);if(a<0||h<0||a>=o)return!1;const l=h*o+a;for(let c=0;c<n.pixelIndices.length;c++)if(n.pixelIndices[c]===l)return!0;return!1}isPointInStructuredRoomFill(e){const i={x:Math.round(e.x),y:Math.round(e.y)},s=this.appService.getApp().mapState,n=this.appService.mapManager.getRoomById(this.roomId);return!s||!n||!n.outlinePoints?!1:Rt(i,n.outlinePoints,!0)}isDividerCompletelyOutOfRoom(){if(!this.roomGeometry)return!1;const{boundingBox:e}=this.roomGeometry,i=this.endPoints;if(i.length<2)return!1;const s=this.appService.getApp().mapState;if(!s)return!1;const 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!xy(n,o,e.x,e.y,e.width,e.height)}checkAndResetIfOutOfRoom(){const{resetDividerWhenOutOfRoom:e}=this.appService.dividerConfig;e&&this.isDividerCompletelyOutOfRoom()&&this.resetToDefaultState()}resetToDefaultState(){var e,i;this.endPoints=this.createDefaultdividerPoints(),this.calculateAndCreateSolidLine(),this.updateComponents(),(i=(e=this.dividerEvents).onUpdate)==null||i.call(e,this.endPoints)}updateComponents(){const e=this.endPoints;e.length>=2&&(this.dashLine.updatePoints(e[0],e[1]),this.startEndPoint.position.set(e[0].x,e[0].y),this.endEndPoint.position.set(e[1].x,e[1].y),this.setupDashLineInteraction())}createSolidLine(){if(!this.solidLinePoints)return;const{solidLineWidth:e,lineColor:i}=this.dividerConfig;this.solidLine=new H,this.solidLine.eventMode="none";const s=this.appService.getApp().toFixedSize(e);this.solidLine.setStrokeStyle({color:i.toString(),width:s}).moveTo(this.solidLinePoints[0].x,this.solidLinePoints[0].y).lineTo(this.solidLinePoints[1].x,this.solidLinePoints[1].y).stroke(),this.addChildAt(this.solidLine,0)}clearSolidLine(){this.solidLine&&(this.removeChild(this.solidLine),this.solidLine.destroy(),this.solidLine=null),this.solidLinePoints=null}updatedividerPoints(e){this.endPoints=this.validateDividerPoints(e),this.updateAllComponents(),this.calculateAndCreateSolidLine()}destroy(){var e,i,s;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(),(e=this.dashLine)==null||e.destroy(),(i=this.startEndPoint)==null||i.destroy(),(s=this.endEndPoint)==null||s.destroy(),super.destroy()}}const ps=["forbiddenSweepZone","forbiddenMopZone","cleanZone","virtualWall","spot","wayPoint","divider"];function Jx(r){if(!r||r.length===0)return[...ps];const t=new Set,e=[];for(const i of r){if(!ps.includes(i)){A.warn(`[ControlsManager] Unknown control render order item: ${i}`);continue}t.has(i)||(t.add(i),e.push(i))}for(const i of ps)t.has(i)||e.push(i);return e}class t0{constructor(t){g(this,"forbiddenSweepZoneMap",new Map);g(this,"forbiddenMopZoneMap",new Map);g(this,"cleanZoneMap",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",[]);this.appService=t,this.initializeControlContainers();const e=U(t.runtime,"editingForbiddenSweepZoneIds",d=>{A.log(`[runtime] editingForbiddenSweepZoneIds: ${d}`),this.updateZonesEditState(this.forbiddenSweepZoneMap)}),i=U(t.runtime,"editingForbiddenMopZoneIds",d=>{A.log(`[runtime] editingForbiddenMopZoneIds: ${d}`),this.updateZonesEditState(this.forbiddenMopZoneMap)}),s=U(t.runtime,"editingCleanZoneIds",d=>{A.log(`[runtime] editingCleanZoneIds: ${d}`),this.updateZonesEditState(this.cleanZoneMap)}),n=U(t.runtime,"editingVirtualWallIds",d=>{A.log(`[runtime] editingVirtualWallIds: ${d}`),this.updateVirtualWallsEditState(this.virtualWallMap)}),o=U(t.runtime,"editingSpotIds",d=>{A.log(`[runtime] editingSpotIds: ${d}`),this.updateSpotsEditState(this.spotMap)}),a=U(t.runtime,"editingWayPointIds",d=>{A.log(`[runtime] editingWayPointIds: ${d}`),this.updateWayPointsEditState(this.wayPointMap)}),h=U(t.runtime,"dividingRoomId",d=>{A.log(`[runtime] dividingRoomId: ${d}`),this.handleDividingRoomIdChange(d)}),l=U(t.runtime,"unit",d=>{A.log(`[runtime] unit changed: ${d}`),this.handleUnitChange()}),c=U(t.runtime,"unitLabel",d=>{A.log(`[runtime] unitLabel changed: ${d}`),this.handleUnitChange()});this.unsubscribeFns.push(e,i,s,n,o,a,h,l,c)}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(Ne);s&&s.position.set(t,e)}updateRenderOrder(){this.applyRenderOrder()}initializeControlContainers(){const t=this.appService.appContainer.getLayer(Ne);if(!t){A.warn("[ControlsManager] LAYER_CONTROLS not found during init");return}for(const e of ps){const i=new L;i.label=`controls:${e}`,this.controlContainers.set(e,i),t.addChild(i)}this.applyRenderOrder()}applyRenderOrder(){const t=this.appService.appContainer.getLayer(Ne);if(!t)return;Jx(this.appService.getConfig().controls.renderOrder).forEach((i,s)=>{const n=this.controlContainers.get(i);n&&(n.zIndex=s)}),t.sortableChildren=!0,t.sortChildren()}addToControlLayer(t,e){let i=this.controlContainers.get(t);if(!i){const s=this.appService.appContainer.getLayer(Ne);if(!s){A.warn("[ControlsManager] LAYER_CONTROLS not found");return}i=new L,i.label=`controls:${t}`,this.controlContainers.set(t,i),s.addChild(i),this.applyRenderOrder()}i.addChild(e)}drawForbiddenSweepZones(t){this.drawZones(t,this.forbiddenSweepZoneMap,e=>Or.create(this.appService,e),"forbiddenSweepZone")}getForbiddenSweepZones(){return this.getZonesData(this.forbiddenSweepZoneMap)}clearAllForbiddenSweepZones(){this.clearAllZones(this.forbiddenSweepZoneMap)}drawForbiddenMopZones(t){this.drawZones(t,this.forbiddenMopZoneMap,e=>Gr.create(this.appService,e),"forbiddenMopZone")}getForbiddenMopZones(){return this.getZonesData(this.forbiddenMopZoneMap)}clearAllForbiddenMopZones(){this.clearAllZones(this.forbiddenMopZoneMap)}drawCleanZones(t){this.drawZones(t,this.cleanZoneMap,e=>Wr.create(this.appService,e),"cleanZone")}getCleanZones(){return this.getZonesData(this.cleanZoneMap)}clearAllCleanZones(){this.clearAllZones(this.cleanZoneMap)}drawVirtualWalls(t){var n;const e=this.appService,i=this.virtualWallMap,s=new Set(t.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));t.forEach(o=>{const a=i.get(o.id);if(a)this.isWallDataEqual(a.getWallData(),o)||a.updateWallData(o);else{const h=new nr({appService:e,wallData:o,events:{onRemove:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onRemoveVirtualWall)==null||d.call(c,l)},onUpdate:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onUpdateVirtualWall)==null||d.call(c,l)},onClick:l=>{var c,d;(d=(c=e.events)==null?void 0:c.onClickVirtualWall)==null||d.call(c,l)}}});i.set(o.id,h),this.addToControlLayer("virtualWall",h)}})}getVirtualWalls(){return this.getWallsData(this.virtualWallMap)}clearAllVirtualWalls(){this.clearAllWalls(this.virtualWallMap)}drawSpots(t){const e=this.spotMap;if(!t||t.length===0){this.clearAllSpotsInternal(e);return}const i=new Set(e.keys()),s=new Set(t.map(n=>n.id));for(const n of i)s.has(n)||this.removeSpot(n,e);t.forEach(n=>{const o=e.get(n.id);o?this.isSpotDataEqual(o.getSpotData(),n)||o.updateSpotData(n):this.addNewSpot(n,e)})}getSpots(){return this.getSpotsData(this.spotMap)}clearAllSpots(){this.clearAllSpotsInternal(this.spotMap)}drawZones(t,e,i,s){if(!t||t.length===0){this.clearAllZones(e);return}const n=new Set(e.keys()),o=new Set(t.map(a=>a.id));for(const a of n)o.has(a)||this.removeZone(a,e);t.forEach(a=>{const h=e.get(a.id);h?this.isZoneDataEqual(h.getZoneData(),a)||h.updateZoneData(a):this.addNewZone(a,e,i,s)})}addNewZone(t,e,i,s){const n=i(t);e.set(t.id,n),this.addToControlLayer(s,n)}removeZone(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getZonesData(t){const e=[];return t.forEach(i=>{e.push(i.getZoneData())}),e}clearAllZones(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateZonesEditState(t){t.forEach(e=>{e.updateEditState()})}updateVirtualWallsEditState(t){t.forEach(e=>{e.updateEditingState()})}isZoneDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],n=e.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}getWallsData(t){return Array.from(t.values()).map(e=>e.getWallData())}clearAllWalls(t){for(const e of t.values())e.destroy();t.clear()}isWallDataEqual(t,e){if(t.id!==e.id||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++){const s=t.points[i],n=e.points[i];if(Math.abs(s.x-n.x)>.1||Math.abs(s.y-n.y)>.1)return!1}return!0}addNewSpot(t,e){const i=Ur.create(this.appService,t);e.set(t.id,i),this.addToControlLayer("spot",i)}removeSpot(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getSpotsData(t){const e=[];return t.forEach(i=>{e.push(i.getSpotData())}),e}clearAllSpotsInternal(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateSpotsEditState(t){t.forEach(e=>{e.updateEditState()})}isSpotDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}drawWayPoints(t){A.log("[ControlsManager] drawWayPoints",t);const e=Array.from(this.wayPointMap.keys()),i=t.map(n=>n.id);e.filter(n=>!i.includes(n)).forEach(n=>{this.removeWayPoint(n,this.wayPointMap)}),t.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(){A.log("[ControlsManager] clearAllWayPoints"),this.clearAllWayPointsInternal(this.wayPointMap)}getWayPoints(){return this.getWayPointsData(this.wayPointMap)}addNewWayPoint(t,e,i){var o,a;const s=this.appService,n=new $x({appService:s,wayPointData:t,order:e,events:{onUpdate:(o=s.events)==null?void 0:o.onUpdateWayPoint,onClick:(a=s.events)==null?void 0:a.onClickWayPoint}});i.set(t.id,n),this.addToControlLayer("wayPoint",n)}removeWayPoint(t,e){var s;const i=e.get(t);i&&((s=i.parent)==null||s.removeChild(i),i.destroy(),e.delete(t))}getWayPointsData(t){const e=[];return t.forEach(i=>{e.push(i.getWayPointData())}),e}clearAllWayPointsInternal(t){t.forEach((e,i)=>{var n;const s=t.get(i);s&&((n=s.parent)==null||n.removeChild(s),s.destroy())}),t.clear()}updateWayPointsEditState(t){t.forEach(e=>{e.onEditStateChange()})}isWayPointDataEqual(t,e){if(t.id!==e.id)return!1;const i=t.point,s=e.point;return!(Math.abs(i.x-s.x)>.1||Math.abs(i.y-s.y)>.1)}handleDividingRoomIdChange(t){if(t==null||t===-1){this.clearDivider();return}if(!this.getRoomGeometry(t)){this.clearDivider();return}this.createDefaultDivider(t)}getRoomGeometry(t){return this.appService.mapManager.getRoomById(t)}createDefaultDivider(t){const e=this.appService;this.clearDivider(),this.divider=new Qx({appService:this.appService,roomId:t,events:{onUpdate:i=>{var s,n;(n=(s=e.events)==null?void 0:s.onUpdateDivider)==null||n.call(s,i)}}}),this.addToControlLayer("divider",this.divider)}clearDivider(){var t;this.divider&&((t=this.divider.parent)==null||t.removeChild(this.divider),this.divider.destroy(),this.divider=null)}getDividerEndPoints(){return this.divider?this.divider.getDividerEndPoints():null}getEffectiveDividerPoints(){return this.divider?this.divider.getEffectiveDividerPoints():null}handleUnitChange(){A.debug("[ControlsManager] Unit changed, refreshing all size texts"),this.forbiddenSweepZoneMap.forEach(t=>{t.refreshDisplay()}),this.forbiddenMopZoneMap.forEach(t=>{t.refreshDisplay()}),this.cleanZoneMap.forEach(t=>{t.refreshDisplay()}),this.virtualWallMap.forEach(t=>{t.refreshDisplay()}),this.spotMap.forEach(t=>{t.refreshDisplay()})}destroy(){this.clearAllForbiddenSweepZones(),this.clearAllForbiddenMopZones(),this.clearAllCleanZones(),this.clearAllVirtualWalls(),this.clearAllSpots(),this.clearDivider(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[],this.controlContainers.forEach(t=>{t.removeFromParent(),t.destroy({children:!0})}),this.controlContainers.clear()}}class e0 extends Xt{constructor(e,i){super(e);g(this,"objectData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);this.appService=e,this.objectData=i}async initializeSprite(){const e=this.appService.detectedObjectConfig,i=this.objectData.width||e.width,s=this.objectData.height||e.height;await this.loadTextureAndSetSize(this.objectData.src,{width:i,height:s}),this.anchor.set(e.anchor.x,e.anchor.y),this.position.set(this.objectData.x,this.objectData.y),this.visible=!0,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=U(this.appService.runtime,"mapRotation",n=>{this.applyAntiRotation(n)}),e.interactive?this.setupClickHandler():this.eventMode="none"}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickDetectedObject)==null||i.call(e,this.getObjectData())}getObjectData(){return{...this.objectData}}async updateObjectData(e){const i=this.objectData;this.objectData=e;const s=this.appService.detectedObjectConfig;if(i.src!==e.src){const n=e.width||s.width,o=e.height||s.height;await this.loadTextureAndSetSize(e.src,{width:n,height:o})}if(i.width!==e.width||i.height!==e.height){const n=e.width||s.width,o=e.height||s.height;this.setFixedSize(n,o)}this.position.set(e.x,e.y),s.interactive?this.clickHandler||this.setupClickHandler():this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null)}isSameData(e){return this.objectData.id===e.id&&this.objectData.src===e.src&&this.objectData.x===e.x&&this.objectData.y===e.y&&this.objectData.width===e.width&&this.objectData.height===e.height}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class i0{constructor(t){g(this,"detectedObjectMap",new Map);g(this,"unsubscribeShowDetectedObjects",null);this.appService=t,this.applyLayerVisibility(this.appService.runtime.showDetectedObjects),this.unsubscribeShowDetectedObjects=U(this.appService.runtime,"showDetectedObjects",e=>{this.applyLayerVisibility(e)})}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(We);s&&s.position.set(t,e)}async drawDetectedObjects(t){if(!t||t.length===0){this.clearAllDetectedObjects();return}const e=new Set(t.map(s=>s.id)),i=Array.from(this.detectedObjectMap.keys());for(const s of i)e.has(s)||this.removeDetectedObject(s);for(const s of t){const n=this.detectedObjectMap.get(s.id);n?n.isSameData(s)||await n.updateObjectData(s):await this.addNewDetectedObject(s)}}applyLayerVisibility(t){const e=this.appService.appContainer.getLayer(We);e&&(e.visible=t)}clearAllDetectedObjects(){const t=this.appService;this.detectedObjectMap.forEach(e=>{t.appContainer.removeFromLayer(We,e),e.destroy()}),this.detectedObjectMap.clear()}async addNewDetectedObject(t){const e=this.appService,i=new e0(this.appService,t);await i.initializeSprite(),this.detectedObjectMap.set(t.id,i),e.appContainer.addToLayer(We,i)}removeDetectedObject(t){const e=this.appService,i=this.detectedObjectMap.get(t);i&&(e.appContainer.removeFromLayer(We,i),i.destroy(),this.detectedObjectMap.delete(t))}destroy(){this.unsubscribeShowDetectedObjects&&(this.unsubscribeShowDetectedObjects(),this.unsubscribeShowDetectedObjects=null),this.clearAllDetectedObjects()}}var ke={},gc={},te={};Object.defineProperty(te,"__esModule",{value:!0});te.loop=te.conditional=te.parse=void 0;var s0=function r(t,e){var i=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},s=arguments.length>3&&arguments[3]!==void 0?arguments[3]:i;if(Array.isArray(e))e.forEach(function(o){return r(t,o,i,s)});else if(typeof e=="function")e(t,i,s,r);else{var n=Object.keys(e)[0];Array.isArray(e[n])?(s[n]={},r(t,e[n],i,s[n])):s[n]=e[n](t,i,s,r)}return i};te.parse=s0;var n0=function(t,e){return function(i,s,n,o){e(i,s,n)&&o(i,t,s,n)}};te.conditional=n0;var r0=function(t,e){return function(i,s,n,o){for(var a=[],h=i.pos;e(i,s,n);){var l={};if(o(i,t,s,l),i.pos===h)break;h=i.pos,a.push(l)}return a}};te.loop=r0;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 o0=function(t){return{data:t,pos:0}};ut.buildStream=o0;var mc=function(){return function(t){return t.data[t.pos++]}};ut.readByte=mc;var a0=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+t]}};ut.peekByte=a0;var zs=function(t){return function(e){return e.data.subarray(e.pos,e.pos+=t)}};ut.readBytes=zs;var h0=function(t){return function(e){return e.data.subarray(e.pos,e.pos+t)}};ut.peekBytes=h0;var l0=function(t){return function(e){return Array.from(zs(t)(e)).map(function(i){return String.fromCharCode(i)}).join("")}};ut.readString=l0;var c0=function(t){return function(e){var i=zs(2)(e);return t?(i[1]<<8)+i[0]:(i[0]<<8)+i[1]}};ut.readUnsigned=c0;var d0=function(t,e){return function(i,s,n){for(var o=typeof e=="function"?e(i,s,n):e,a=zs(t),h=new Array(o),l=0;l<o;l++)h[l]=a(i);return h}};ut.readArray=d0;var u0=function(t,e,i){for(var s=0,n=0;n<i;n++)s+=t[e+n]&&Math.pow(2,i-n-1);return s},p0=function(t){return function(e){for(var i=mc()(e),s=new Array(8),n=0;n<8;n++)s[7-n]=!!(i&1<<n);return Object.keys(t).reduce(function(o,a){var h=t[a];return h.length?o[a]=u0(s,h.index,h.length):o[a]=s[h.index],o},{})}};ut.readBits=p0;(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var t=te,e=ut,i={blocks:function(u){for(var p=0,f=[],y=u.data.length,m=0,x=(0,e.readByte)()(u);x!==p&&x;x=(0,e.readByte)()(u)){if(u.pos+x>=y){var S=y-u.pos;f.push((0,e.readBytes)(S)(u)),m+=S;break}f.push((0,e.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,t.conditional)({gce:[{codes:(0,e.readBytes)(2)},{byteSize:(0,e.readByte)()},{extras:(0,e.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,e.readUnsigned)(!0)},{transparentColorIndex:(0,e.readByte)()},{terminator:(0,e.readByte)()}]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===249}),n=(0,t.conditional)({image:[{code:(0,e.readByte)()},{descriptor:[{left:(0,e.readUnsigned)(!0)},{top:(0,e.readUnsigned)(!0)},{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{lct:(0,e.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,e.readArray)(3,function(d,u,p){return Math.pow(2,p.descriptor.lct.size+1)})},function(d,u,p){return p.descriptor.lct.exists}),{data:[{minCodeSize:(0,e.readByte)()},i]}]},function(d){return(0,e.peekByte)()(d)===44}),o=(0,t.conditional)({text:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{preData:function(u,p,f){return(0,e.readBytes)(f.text.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===1}),a=(0,t.conditional)({application:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{id:function(u,p,f){return(0,e.readString)(f.blockSize)(u)}},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===255}),h=(0,t.conditional)({comment:[{codes:(0,e.readBytes)(2)},i]},function(d){var u=(0,e.peekBytes)(2)(d);return u[0]===33&&u[1]===254}),l=[{header:[{signature:(0,e.readString)(3)},{version:(0,e.readString)(3)}]},{lsd:[{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{gct:(0,e.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,e.readByte)()},{pixelAspectRatio:(0,e.readByte)()}]},(0,t.conditional)({gct:(0,e.readArray)(3,function(d,u){return Math.pow(2,u.lsd.gct.size+1)})},function(d,u){return u.lsd.gct.exists}),{frames:(0,t.loop)([s,a,h,n,o],function(d){var u=(0,e.peekByte)()(d);return u===33||u===44})}],c=l;r.default=c})(gc);var Ls={};Object.defineProperty(Ls,"__esModule",{value:!0});Ls.deinterlace=void 0;var f0=function(t,e){for(var i=new Array(t.length),s=t.length/e,n=function(u,p){var f=t.slice(p*e,(p+1)*e);i.splice.apply(i,[u*e,e].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};Ls.deinterlace=f0;var Os={};Object.defineProperty(Os,"__esModule",{value:!0});Os.lzw=void 0;var g0=function(t,e,i){var s=4096,n=-1,o=i,a,h,l,c,d,u,p,w,f,y,P,m,C,k,T,M,x=new Array(i),S=new Array(s),v=new Array(s),b=new Array(s+1);for(m=t,h=1<<m,d=h+1,a=h+2,p=n,c=m+1,l=(1<<c)-1,f=0;f<h;f++)S[f]=0,v[f]=f;var P,w,C,k,M,T;for(P=w=C=k=M=T=0,y=0;y<o;){if(k===0){if(w<c){P+=e[T]<<w,w+=8,T++;continue}if(f=P&l,P>>=c,w-=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,C=f;continue}for(u=f,f==a&&(b[k++]=C,f=p);f>h;)b[k++]=v[f],f=S[f];C=v[f]&255,b[k++]=C,a<s&&(S[a]=p,v[a]=C,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};Os.lzw=g0;Object.defineProperty(ke,"__esModule",{value:!0});var yc=ke.decompressFrames=ke.decompressFrame=xc=ke.parseGIF=void 0,m0=b0(gc),y0=te,x0=ut,S0=Ls,v0=Os;function b0(r){return r&&r.__esModule?r:{default:r}}var w0=function(t){var e=new Uint8Array(t);return(0,y0.parse)((0,x0.buildStream)(e),m0.default)},xc=ke.parseGIF=w0,A0=function(t){for(var e=t.pixels.length,i=new Uint8ClampedArray(e*4),s=0;s<e;s++){var n=s*4,o=t.pixels[s],a=t.colorTable[o]||[0,0,0];i[n]=a[0],i[n+1]=a[1],i[n+2]=a[2],i[n+3]=o!==t.transparentIndex?255:0}return i},Sc=function(t,e,i){if(!t.image){console.warn("gif frame does not have associated image.");return}var s=t.image,n=s.descriptor.width*s.descriptor.height,o=(0,v0.lzw)(s.data.minCodeSize,s.data.blocks,n);s.descriptor.lct.interlaced&&(o=(0,S0.deinterlace)(o,s.descriptor.width));var a={pixels:o,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height}};return s.descriptor.lct&&s.descriptor.lct.exists?a.colorTable=s.lct:a.colorTable=e,t.gce&&(a.delay=(t.gce.delay||10)*10,a.disposalType=t.gce.extras.disposal,t.gce.extras.transparentColorGiven&&(a.transparentIndex=t.gce.transparentColorIndex)),i&&(a.patch=A0(a)),a};ke.decompressFrame=Sc;var C0=function(t,e){return t.frames.filter(function(i){return i.image}).map(function(i){return Sc(i,t.gct,e)})};yc=ke.decompressFrames=C0;class Gs{constructor(t){if(!t||!t.length)throw new Error("Invalid frames");const[{texture:{width:e,height:i}}]=t;this.width=e,this.height=i,this.frames=t,this.textures=this.frames.map(s=>s.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const t of this.textures)t.destroy(!0);for(const t of this.frames)t.texture=null;this.frames.length=0,this.textures.length=0,Object.assign(this,{frames:null,textures:null,width:0,height:0,duration:0,totalFrames:0})}static from(t,e){if(!t||t.byteLength===0)throw new Error("Invalid buffer");const i=S=>{let v=null;for(const b of S.frames)v=b.gce??v,"image"in b&&!("gce"in b)&&(b.gce=v)},s=xc(t);i(s);const n=yc(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}=e??{},x=1e3/y;for(let S=0;S<n.length;S++){const{disposalType:v=2,delay:b=x,patch:P,dims:{width:w,height:C,left:k,top:M}}=n[S];d.width=w,d.height=C,u.clearRect(0,0,w,C);const T=u.createImageData(w,C);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 I=j.get().createCanvas(_.width,_.height);I.getContext("2d").putImageData(_,0,0),o.push({start:p,end:p+b,texture:new G({source:new dr({resource:I,...m})})}),p+=b}return l.width=l.height=0,d.width=d.height=0,new Gs(o)}}const P0={extension:E.Asset,detection:{test:async()=>!0,add:async r=>[...r,"gif"],remove:async r=>r.filter(t=>t!=="gif")},loader:{name:"gifLoader",id:"gif",test:r=>Mt.extname(r)===".gif"||r.startsWith("data:image/gif"),load:async(r,t)=>{const i=await(await j.get().fetch(r)).arrayBuffer();return Gs.from(i,t==null?void 0:t.data)},unload:async r=>{r.destroy()}}},vc=class rr extends jt{constructor(...t){const e=t[0]instanceof Gs?{source:t[0]}:t[0],{source:i,fps:s,loop:n,animationSpeed:o,autoPlay:a,autoUpdate:h,onComplete:l,onFrameChange:c,onLoop:d,...u}=Object.assign({},rr.defaultOptions,e);super({texture:G.EMPTY,...u}),this.animationSpeed=1,this.loop=!0,this.duration=0,this.autoPlay=!0,this.dirty=!1,this._currentFrame=0,this._autoUpdate=!1,this._isConnectedToTicker=!1,this._playing=!1,this._currentTime=0,this.onRender=()=>this._updateFrame(),this.texture=i.textures[0],this.duration=i.frames[i.frames.length-1].end,this._source=i,this._playing=!1,this._currentTime=0,this._isConnectedToTicker=!1,Object.assign(this,{fps:s,loop: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,Ee.HIGH),this._isConnectedToTicker=!0),!this.loop&&this.currentFrame===this._source.frames.length-1&&(this._currentTime=0))}get progress(){return this._currentTime/this.duration}get playing(){return this._playing}update(t){var o,a;if(!this._playing)return;const e=this.animationSpeed*t.deltaTime/yt.targetFPMS,i=this._currentTime+e,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(t){t!==this._autoUpdate&&(this._autoUpdate=t,!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(t){this._updateFrameIndex(t),this._currentTime=this._source.frames[t].start}get source(){return this._source}_updateFrameIndex(t){var e;if(t<0||t>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${t}`);this._currentFrame!==t&&(this._currentFrame=t,this.dirty=!0,(e=this.onFrameChange)==null||e.call(this,t))}get totalFrames(){return this._source.totalFrames}destroy(t=!1){this.stop(),super.destroy(),t&&this._source.destroy();const e=null;this._source=e,this.onComplete=e,this.onFrameChange=e,this.onLoop=e}clone(){const t=new rr({source:this._source,autoUpdate:this._autoUpdate,loop:this.loop,autoPlay:this.autoPlay,animationSpeed:this.animationSpeed,onComplete:this.onComplete,onFrameChange:this.onFrameChange,onLoop:this.onLoop});return t.dirty=!0,t}};vc.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let M0=vc;$.add(P0);class Hr extends M0{constructor(e,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=e,this.anchor.set(.5),this.visible=!1,this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applySize()}setSizeFixed(e){this.sizeFixed=e,this.baselineScale=1,e&&this.isFixedSizeSet?this.applySize():!e&&this.isFixedSizeSet&&this.applySize()}set width(e){if(this.isFixedSizeSet){A.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置宽度");return}this.setFixedSize(e,this.fixedHeight||e)}set height(e){if(this.isFixedSizeSet){A.warn("EnhancedGifSprite: 使用 setFixedSize() 方法来设置高度");return}this.setFixedSize(this.fixedWidth||e,e)}get width(){return this.fixedWidth||super.width}get height(){return this.fixedHeight||super.height}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateScale)}applySize(){if(!this.isFixedSizeSet||!this.texture||this.texture.width===0||this.texture.height===0)return;const e=this.fixedWidth/this.texture.width,i=this.fixedHeight/this.texture.height;if(this.sizeFixed){const s=this.appService.currentScale;if(s===0)return;const n=e/s,o=i/s;super.scale.set(n,o)}else super.scale.set(e/this.baselineScale,i/this.baselineScale)}updateScale(e){this.sizeFixed&&(this.isFixedSizeSet?this.applySize():e!==0&&super.scale.set(1/e))}static async createFromSrc(e,i,s){try{const n=await N.load(i),o=new Hr(e,{source:n});return s.sizeFixed!==void 0&&o.setSizeFixed(s.sizeFixed),o.setFixedSize(s.width,s.height),o}catch(n){throw A.error(`Failed to load GIF "${i}":`,n),n}}draw(e,i){const{x:s,y:n,rotation:o=0}=e;i&&!this.visible?this.visible=i():!i&&!this.visible&&(this.visible=!0),this.rotation=o,this.position.set(s,n)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class Ge extends Hr{constructor(e,i,s){super(e,{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 e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.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=U(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;if(this.elementData=e,i.src!==e.src)throw new Error("GIF source change requires recreation of instance");i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height);const s=e.anchor||{x:.5,y:.5},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(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5};return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class Mn extends Xt{constructor(e,i){super(e);g(this,"elementData");g(this,"clickHandler",null);g(this,"unsubscribeMapRotation",null);g(this,"userRotation",0);this.appService=e,this.elementData=i}async initialize(){await this.loadTextureAndSetSize(this.elementData.src,{width:this.elementData.width,height:this.elementData.height,sizeFixed:this.elementData.sizeFixed});const e=this.elementData.anchor||{x:.5,y:.5};this.anchor.set(e.x,e.y),this.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=U(this.appService.runtime,"mapRotation",i=>{this.applyRotation(i)}),this.visible=!0,this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupClickHandler(){this.clickHandler&&this.clickHandler.destroy(),this.clickHandler=new vt(this,{onClick:()=>this.handleClick(),stopPropagation:!1})}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.src!==e.src?await this.loadTextureAndSetSize(e.src,{width:e.width,height:e.height,sizeFixed:e.sizeFixed}):(i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),(i.width!==e.width||i.height!==e.height)&&this.setFixedSize(e.width,e.height));const s=e.anchor||{x:.5,y:.5},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(e.x,e.y),e.rotation!==void 0&&(this.userRotation=e.rotation,this.applyRotation(this.appService.runtime.mapRotation)),e.opacity!==void 0&&(this.alpha=e.opacity),e.interactive?this.clickHandler||this.setupClickHandler():(this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),this.eventMode="none")}isSameData(e){const i=this.elementData.anchor||{x:.5,y:.5},s=e.anchor||{x:.5,y:.5};return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.src===e.src&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed&&i.x===s.x&&i.y===s.y}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.clickHandler&&(this.clickHandler.destroy(),this.clickHandler=null),super.destroy()}}class _0 extends Fg{constructor(e,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=e,this.anchor.set(0,0),this.throttledUpdateScale=At(this.updateScale.bind(this),30,{leading:!0,trailing:!0}),this.registerScaleListener()}setFixedSize(e,i){this.fixedWidth=e,this.fixedHeight=i,this.isFixedSizeSet=!0,this.applyFixedSize(),this.updatePositionFromCenter()}setCenterPosition(e,i){this.userCenterX=e,this.userCenterY=i,this.updatePositionFromCenter()}setSizeFixed(e){this.sizeFixed=e,this.isFixedSizeSet&&(this.applyFixedSize(),this.updatePositionFromCenter())}getIsFixedSizeSet(){return this.isFixedSizeSet}updatePositionFromCenter(){if(!this.isFixedSizeSet){this.position.set(this.userCenterX,this.userCenterY);return}const i=this.appService.currentScale;let s,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(e){this.isFixedSizeSet&&e!==0&&(this.applyFixedSize(),this.updatePositionFromCenter())}updateTransform(e){return super.updateTransform(e)}destroy(e){this.appService.emitter.off("antiScale",this.throttledUpdateScale),super.destroy(e)}}class ki extends _0{constructor(e,i){const s=document.createElement("div");ki.setupDefaultStyles(s,i),s.innerHTML=i.htmlContent;super(e,{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=U(this.appService.runtime,"mapRotation",e=>{this.applyRotation(e)}),this.elementData.interactive?this.setupClickHandler():this.eventMode="none"}applyRotation(e){const i=-e*Math.PI/180;this.rotation=this.userRotation+i}setupAutoSize(){this.element&&(this.element.style.width="auto",this.element.style.height="auto",this.waitForElementDimensions())}waitForElementInsertion(){if(!this.element)return;const e=()=>{this.element&&(this.element.isConnected?this.showElement():requestAnimationFrame(e))};requestAnimationFrame(e)}waitForElementDimensions(){this.element&&(typeof ResizeObserver<"u"?(this.resizeObserver=new ResizeObserver(e=>{var s;const i=e[0];i&&i.contentRect.width>0&&i.contentRect.height>0&&(this.setFixedSize(i.contentRect.width,i.contentRect.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement(),(s=this.resizeObserver)==null||s.disconnect(),this.resizeObserver=null)}),this.resizeObserver.observe(this.element)):this.pollForElementDimensions())}pollForElementDimensions(){if(!this.element)return;const e=()=>{if(!this.element)return;if(!this.element.isConnected){requestAnimationFrame(e);return}const i=this.element.getBoundingClientRect();i.width>0&&i.height>0?(this.setFixedSize(i.width,i.height),this.setCenterPosition(this.elementData.x,this.elementData.y),this.setSizeFixed(this.elementData.sizeFixed??!0),this.alpha===0&&this.showElement()):requestAnimationFrame(e)};requestAnimationFrame(e)}showElement(){this.alpha=this.elementData.opacity??1,this.element.style.pointerEvents=this.elementData.interactive?"auto":"none",this.interactive=this.elementData.interactive??!1,this.elementData.interactive&&this.element&&(this.element.style.setProperty("-webkit-tap-highlight-color","transparent"),this.element.style.setProperty("-webkit-touch-callout","none")),this.appService.getApp().renderOnceNextFrame()}setupClickHandler(){this.element&&(this.domClickHandler=e=>{e.preventDefault(),e.stopPropagation(),this.handleClick()},this.element.addEventListener("click",this.domClickHandler))}handleClick(){var e,i;(i=(e=this.appService.events)==null?void 0:e.onClickCustomElement)==null||i.call(e,this.getElementData())}getElementData(){return{...this.elementData}}async updateElementData(e){const i=this.elementData;this.elementData=e,i.htmlContent!==e.htmlContent&&this.element&&(this.element.innerHTML=e.htmlContent,(!e.width||!e.height)&&this.waitForElementDimensions()),(i.width!==e.width||i.height!==e.height)&&(e.width&&e.height?(this.setFixedSize(e.width,e.height),this.element&&(this.element.style.width=`${e.width}px`,this.element.style.height=`${e.height}px`)):this.setupAutoSize()),e.width&&e.height?this.setCenterPosition(e.x,e.y):this.getIsFixedSizeSet()?this.setCenterPosition(e.x,e.y):this.position.set(e.x,e.y),i.sizeFixed!==e.sizeFixed&&e.sizeFixed!==void 0&&this.setSizeFixed(e.sizeFixed),this.userRotation=e.rotation??0,this.applyRotation(this.appService.runtime.mapRotation),this.alpha=e.opacity??1,e.interactive?this.domClickHandler||this.setupClickHandler():(this.eventMode="none",this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null))}isSameData(e){return this.elementData.id===e.id&&this.elementData.type===e.type&&this.elementData.htmlContent===e.htmlContent&&this.elementData.x===e.x&&this.elementData.y===e.y&&this.elementData.width===e.width&&this.elementData.height===e.height&&this.elementData.rotation===e.rotation&&this.elementData.opacity===e.opacity&&this.elementData.interactive===e.interactive&&this.elementData.sizeFixed===e.sizeFixed}static setupDefaultStyles(e,i){const s={position:"relative",boxSizing:"border-box",webkitFontSmoothing:"antialiased",textRendering:"optimizeLegibility",background:"transparent",userSelect:"auto",webkitUserSelect:"auto"};i.width&&i.height?(s.width=`${i.width}px`,s.height=`${i.height}px`,s.overflow="hidden"):(s.width=i.width?`${i.width}px`:"auto",s.height=i.height?`${i.height}px`:"auto",s.overflow="visible"),Object.assign(e.style,s),e.style.setProperty("-webkit-tap-highlight-color","transparent"),e.style.setProperty("-webkit-touch-callout","none")}destroy(){this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.domClickHandler&&this.element&&(this.element.removeEventListener("click",this.domClickHandler),this.domClickHandler=null),this.debugMarker&&(this.debugMarker.destroy(),this.debugMarker=null),super.destroy()}}class T0{constructor(t){g(this,"customElementsMap",new Map);g(this,"gifTicker",null);g(this,"gifElements",new Set);this.appService=t}updatePositionByOrigin(t,e){const i=this.appService,s=i.appContainer.getLayer(Si),n=i.appContainer.getLayer(vi);s&&s.position.set(t,e),n&&n.position.set(t,e)}async drawCustomElements(t){if(!t||t.length===0){this.clearAllCustomElements();return}const e=new Set(t.map(n=>n.id)),i=Array.from(this.customElementsMap.keys());for(const n of i)e.has(n)||this.removeCustomElement(n);const s=t.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 t=this.appService;this.customElementsMap.forEach(e=>{e instanceof Ge?t.appContainer.removeFromLayer(vi,e):t.appContainer.removeFromLayer(Si,e),e.destroy()}),this.customElementsMap.clear(),this.gifElements.clear(),this.stopGifTicker()}async addNewCustomElement(t){const e=this.appService;let i;switch(t.type){case"image":i=new Mn(this.appService,t);break;case"gif":{const s=await N.load(t.src);i=new Ge(this.appService,s,t);break}case"html":i=new ki(this.appService,t);break;default:throw new Error(`Unsupported custom element type: ${t.type}`)}await i.initialize(),this.customElementsMap.set(t.id,i),i instanceof Ge?(e.appContainer.addToLayer(vi,i),this.gifElements.add(i)):e.appContainer.addToLayer(Si,i)}removeCustomElement(t){const e=this.appService,i=this.customElementsMap.get(t);i&&(i instanceof Ge?(this.gifElements.delete(i),e.appContainer.removeFromLayer(vi,i)):e.appContainer.removeFromLayer(Si,i),i.destroy(),this.customElementsMap.delete(t))}isSameData(t,e){return t.getElementData().type!==e.type?!1:e.type==="image"&&t instanceof Mn||e.type==="gif"&&t instanceof Ge||e.type==="html"&&t instanceof ki?t.isSameData(e):!1}async updateElementData(t,e){if(e.type==="image"&&t instanceof Mn)await t.updateElementData(e);else if(e.type==="gif"&&t instanceof Ge)await t.updateElementData(e);else if(e.type==="html"&&t instanceof ki)await t.updateElementData(e);else throw new Error("Element type mismatch during update")}updateGifTicker(){this.gifElements.size>0?this.startGifTicker():this.stopGifTicker()}startGifTicker(){var t;(t=this.gifTicker)!=null&&t.started||(this.gifTicker?this.gifTicker.maxFPS=1:(this.gifTicker=new yt,this.gifTicker.maxFPS=1,this.gifTicker.add(()=>{this.renderGifContainer()})),this.gifTicker.start())}stopGifTicker(){var t;(t=this.gifTicker)!=null&&t.started&&(A.log("⏸️ [GifTicker] 停止 GIF 专用渲染"),this.gifTicker.stop())}renderGifContainer(){const t=this.appService;if(this.gifElements.size===0)return;const e=t.getApp();e.renderer.render(e.stage)}destroy(){this.stopGifTicker(),this.gifTicker&&(this.gifTicker.destroy(),this.gifTicker=null),this.clearAllCustomElements()}}class k0 extends L{constructor(e,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=e,this.roomId=i.id,this.roomIndex=i.index;const{nameLabel:s,type:n}=e.roomConfig,{showRoomType:o}=e.runtime,a=i.colorIndex??i.index,h=this.getRoomNameColor(a),l=new de({fontSize:s.fontSize,fontFamily:s.fontFamily,fontWeight:s.fontWeight,fill:h,align:"center"}),c=i.name||"Unknown";this.nameText=new Es({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(e,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[e],{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(e){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(e)}layout(){if(!this.iconWrapper||!this.iconWrapper.visible){this.nameText.position.set(0,0);return}if(!(this.iconSprite&&this.iconSprite.visible||this.iconBg&&this.iconBg.visible)){this.nameText.position.set(0,0);return}const{gap:i=4,position:s="left"}=this.appService.roomConfig.type,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(e){this.nameText.text=e,this.layout()}refreshColor(e){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,e);this.nameText.style.fill=o,this.iconBg&&this.drawIconBg(o),this.iconSprite&&(this.iconSprite.tint=i.container.visible?"#ffffff":o)}getRoomNameColor(e,i){const{colors:s}=this.appService.roomConfig,{enableRoomSelection:n,selectRoomIds:o}=this.appService.runtime;if(i)return i;if(n)return!o.includes(this.roomId)&&s.nameInactive?s.nameInactive[e%s.nameInactive.length]:s.name[e%s.name.length];const a=s.nameNormal||s.name;return a[e%a.length]}async updateRoomType(e){const{type:i}=this.appService.roomConfig;if(!this.appService.runtime.showRoomType||e==null||!(i!=null&&i.assets)||!i.assets[e])this.iconWrapper&&(this.iconWrapper.visible=!1);else{const n=this.appService.getRoomData(this.roomId),o=(n==null?void 0:n.colorIndex)??this.roomIndex,a=this.getRoomNameColor(o);this.createIcon(e,a),this.iconWrapper&&(this.iconWrapper.visible=!0)}this.layout()}updateRoomTypeVisibility(e){if(this.iconWrapper)this.iconWrapper.visible=e,this.layout();else if(e){const i=this.appService.getRoomData(this.roomId);i&&this.updateRoomType(i.type??null)}}destroy(e){this.iconBg&&(this.iconBg.destroy(),this.iconBg=null),this.iconSprite&&(this.iconSprite.destroy(),this.iconSprite=null),this.iconWrapper&&(this.iconWrapper.destroy(),this.iconWrapper=null),super.destroy(e)}}class R0 extends L{constructor(e,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=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.foldedIndicator=new H,this.foldedIndicator.visible=!1;const{property: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 Es({text:"",style:new de({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(e,i){const s=["cleanMode","suction","cistern","cleanTimes"];e.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(e){this.isDestroyed||this.destroyed||(await this.updateIcons(e),!(this.isDestroyed||this.destroyed)&&this.updateBackground())}getFieldValue(e,i){if(["cleanMode","suction","cistern","cleanTimes"].includes(i))return e[i]??null;if(e.customData&&i in e.customData){const n=e.customData[i];return typeof n=="number"?n:null}return null}getAssetAlias(e,i){const s={cleanMode:n=>`cleanMode_${n}`,suction:n=>`fan_${n}`,cistern:n=>`water_${n}`,cleanTimes:n=>`cleanTimes${n}`};return e in s?s[e](i):`custom_${e}_${i}`}shouldShowField(e,i,s){const{showRoomProperty:n}=this.appService.runtimeSnapshot;return!(s===null||!n||i==="cleanTimes"&&s<=0)}getDisplayElements(e){const{displayOrders:i}=this.appService.roomConfig.property,{showRoomOrder:s}=this.appService.runtimeSnapshot,n=e.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(e,h);this.shouldShowField(e,h,c)&&c!==null&&a.push({element:l.sprite,show:!0,isOrder:!1,fieldName:h,value:c})}),{elementsToShow:a,orderValue:n}}async updateIcons(e){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(e);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=e.colorIndex??this.roomIndex,m=this.getIconColor(y);this.orderBackground.clear(),this.orderBackground.setFillStyle({color:m}),this.orderBackground.circle(i/2,s/2,i/2).fill();const x=this.resolveOrderTextColor(y);this.orderText.style.fill=x,this.orderText.position.set(i/2,s/2)}else{const y=this.propertyIcons.get(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 e=this.appService.roomConfig,{container:i,foldable:s}=e.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:e,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+=e,d<h.length-1&&(u?l+=s.gapRight:l+=n)}),l+=o,l}calculateContentHeight(){const e=this.appService.roomConfig,{iconHeight:i,container:s}=e.property;return s.paddingVertical+i+s.paddingVertical}getTotalHeight(){const{foldable:e,container:i}=this.appService.roomConfig.property,{tailHeight:s}=i;return this.isFolded?s:this.calculateContentHeight()+(e?s:0)}getTotalWidth(){if(this.isFolded){const{tailWidth:i}=this.appService.roomConfig.property.container,s=this.calculateContentWidth();return Math.min(i,s/2)}return this.calculateContentWidth()}async setFolded(e){const{foldable:i}=this.appService.roomConfig.property;if(i)if(this.isFolded=e,e)this.background.visible=!1,this.orderContainer.visible=!1,this.propertyIcons.forEach(({sprite:s})=>{s.visible=!1}),this.foldedIndicator.visible=!0,this.updateFoldedIndicator();else{this.background.visible=!0,this.foldedIndicator.visible=!1,this.foldedIndicator.position.set(0,0),this.updateBackground();const s=this.appService.getRoomData(this.roomId);s&&await this.updateIcons(s)}}isFoldedState(){const{foldable:e}=this.appService.roomConfig.property;return e?this.isFolded:!1}updateFoldedIndicator(){const e=this.appService.roomConfig,{tailHeight:i,tailWidth:s,backgroundColor:n}=e.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(e){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[e%o.length]}return i.cleanOrder.color}getIconColor(e){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[e%n.length]:s[e%s.length];const l=o||s;return l[e%l.length]}refreshColor(){const e=this.appService.getRoomData(this.roomId),i=(e==null?void 0:e.colorIndex)??this.roomIndex,s=this.getIconColor(i);if(this.propertyIcons.forEach(({sprite: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:e})=>{e.destroy()}),this.propertyIcons.clear(),super.destroy({children:!0}))}}class E0 extends L{constructor(e,i){super();g(this,"background");g(this,"checkmarkIcon");g(this,"bubble");g(this,"roomIndex");g(this,"roomId");this.appService=e;const s=this.appService.roomConfig;this.roomId=i.id,this.roomIndex=i.index,this.background=new H,this.bubble=new H;const{colors:{selectionIndicatorIcon: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(e){const{roomSelectionMode:i,enableRoomSelection:s,selectRoomIds:n}=this.appService.runtimeSnapshot;if(!s||i!=="checkmark"){this.visible=!1;return}const o=n.includes(e.id);await this.showCheckmarkMode(o),this.updateBackground()}async showCheckmarkMode(e){const{selectionIndicator:i}=this.appService.roomConfig,{iconWidth:s,iconHeight:n}=i;if(e){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:e,colors:i}=this.appService.roomConfig,{containerWidth:s,containerHeight:n,strokeWidth:o,strokeColor:a,borderRadius:h,tailHeight:l,tailWidth:c}=e,d=this.appService.getRoomData(this.roomId),u=(d==null?void 0:d.colorIndex)??this.roomIndex,p=i.selectionIndicatorBackground[u%i.selectionIndicatorBackground.length],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:e}=this.appService.roomConfig,{containerHeight:i,tailHeight:s,strokeWidth:n}=e;return i+n+(s>0?s:0)}getTotalWidth(){const{selectionIndicator:e}=this.appService.roomConfig;return e.containerWidth}async refreshColor(){const e=this.appService.getRoomData(this.roomId);e&&await this.updateIndicator(e)}destroy(){var e;(e=this.checkmarkIcon)==null||e.destroy(),super.destroy({children:!0})}}class I0 extends L{constructor(e,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=e,this.enableRenderGroup(),this.roomId=i.id,this.initializeElasticScale(e.currentScale),this.updateScaleBound=s=>this.updateScale(s),this.appService.emitter.on("antiScale",this.updateScaleBound),this.updateScale(this.appService.currentScale),i.centerPoint&&this.position.set(i.centerPoint.x,i.centerPoint.y),this.roomName=new k0(this.appService,i),this.roomName.visible=this.appService.runtimeSnapshot.showRoomName,this.applyAntiRotation(this.appService.runtime.mapRotation),this.unsubscribeMapRotation=U(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(e){await this.createRoomProperty(e),await this.createRoomSelectionIndicator(e),this.updateLayout()}applyAntiRotation(e){const i=-e*Math.PI/180;this.rotation=i}initializeElasticScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=n:h=1,this.targetElasticScale=h,this.currentElasticScale=h}updateScale(e){const{enableElasticScale:i,elasticMinScale:s,elasticMaxScale:n}=this.appService.roomConfig;if(!i){e!==0&&this.scale.set(1/e);return}if(e===0)return;const o=1,a=5;let h;e<=o?h=s:e>=a?h=n:h=1;const c=1/e*h;Math.abs(this.targetElasticScale-h)>.01?(this.targetElasticScale=h,this.startScaleAnimation()):this.scale.set(c)}startScaleAnimation(){this.scaleAnimationBound||(this.scaleAnimationBound=this.animateScale.bind(this)),this.isAnimatingScale||(this.isAnimatingScale=!0,this.appService.getApp().ticker.add(this.scaleAnimationBound))}animateScale(){this.currentElasticScale+=(this.targetElasticScale-this.currentElasticScale)*.3;const 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:e,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=e&&(a.order||0)>0;let l=!1;if(i){const{displayOrders:c}=this.appService.roomConfig.property;l=c.some(d=>!!(d==="suction"&&a.suction!=null||d==="cistern"&&a.cistern!=null||d==="cleanMode"&&a.cleanMode!=null||d==="cleanTimes"&&a.cleanTimes>0||a.customData&&d in a.customData&&typeof a.customData[d]=="number"&&a.customData[d]!=null))}return h||l}shouldShowRoomSelectionIndicator(){const{enableRoomSelection:e,roomSelectionMode:i}=this.appService.runtimeSnapshot;return e&&i==="checkmark"}async updateRoomPropertyVisibility(){if(!this.roomProperty)return;if(!this.shouldShowRoomProperty())this.roomProperty.visible=!1;else{this.roomProperty.visible=!0;const i=this.appService.runtimeSnapshot.roomPropertyFoldIds.includes(this.roomId);await this.roomProperty.setFolded(i);const s=this.appService.getRoomData(this.roomId);s&&await this.roomProperty.updateProperty(s)}this.updateLayout()}async updateRoomSelectionIndicatorVisibility(){if(!this.roomSelectionIndicator)return;if(this.shouldShowRoomSelectionIndicator()){const i=this.appService.getRoomData(this.roomId);i&&await this.roomSelectionIndicator.updateIndicator(i)}else this.roomSelectionIndicator.visible=!1;this.updateLayout()}async createRoomProperty(e){this.roomProperty&&(this.removeChild(this.roomProperty),this.roomProperty.destroy()),this.roomProperty=new R0(this.appService,e),await this.roomProperty.updateProperty(e),this.addChild(this.roomProperty),this.addChild(this.roomName),await this.updateRoomPropertyVisibility(),this.updateLayout()}async createRoomSelectionIndicator(e){this.roomSelectionIndicator&&(this.removeChild(this.roomSelectionIndicator),this.roomSelectionIndicator.destroy()),this.roomSelectionIndicator=new E0(this.appService,e),await this.updateRoomSelectionIndicatorVisibility(),this.addChild(this.roomSelectionIndicator)}updateLayout(){var l,c,d,u,p,f;if(this.destroyed)return;const{property:{offsetY:e,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-e;this.roomProperty.position.set(S,v)}else a&&((u=this.roomName)!=null&&u.position)?(this.roomProperty.position.set(-m/2+i,-e-y),this.roomName.position.set(0,0)):this.roomProperty.position.set(-m/2+i,-y/2-e)}if(h&&this.roomSelectionIndicator){const y=this.roomSelectionIndicator.getTotalHeight(),m=this.roomSelectionIndicator.getTotalWidth();a&&((p=this.roomName)!=null&&p.position)?(this.roomSelectionIndicator.position.set(-m/2+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(e){this.roomName.updateName(e)}async updateRoomType(e){await this.roomName.updateRoomType(e),this.updateLayout()}updateRoomNameVisibility(e){this.roomName.visible=e,this.updateLayout()}updateRoomTypeVisibility(e){this.roomName.updateRoomTypeVisibility(e),this.updateLayout()}updatePosition(e){this.position.set(e.x,e.y)}async refreshColor(){this.roomName&&this.roomName.refreshColor(),this.roomProperty&&this.roomProperty.refreshColor(),this.roomSelectionIndicator&&await this.roomSelectionIndicator.refreshColor()}destroy(){var e,i,s,n;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,this.unsubscribeMapRotation&&(this.unsubscribeMapRotation(),this.unsubscribeMapRotation=null),this.isAnimatingScale&&this.scaleAnimationBound&&(this.appService.getApp().ticker.remove(this.scaleAnimationBound),this.isAnimatingScale=!1),this.scaleAnimationBound=null,this.updateScaleBound&&(this.appService.emitter.off("antiScale",this.updateScaleBound),this.updateScaleBound=null),(i=this.roomProperty)==null||i.destroy(),this.roomProperty=null,(s=this.roomSelectionIndicator)==null||s.destroy(),this.roomSelectionIndicator=null,(n=this.roomName)==null||n.destroy(),super.destroy()}}class B0 extends L{constructor(e){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=e,this.appService.appContainer.addToLayer(Fr,this)}async createFloorTypes(e){if(!this.appService.runtimeSnapshot.showRoomFloorType)return;this.clearFloorTypes();const s=this.groupRoomsByFloorType(e),n=[];for(const[o,a]of s)n.push(this.createMergedFloorType(o,a));await Promise.all(n)}groupRoomsByFloorType(e){const i=new Map,s=this.appService;return e.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(e,i){const s=this.appService,{assets:n,opacity:o,scale:a}=s.roomConfig.floorType,h=e%n.length,l=`floorType${h}`;if(!n[h]){A.warn(`No texture asset configured for floorType: ${e}`);return}const c=await N.load(l);if(!c){A.warn(`Floor material texture not found: ${l}`);return}const d=i.map(({graphics:m})=>m.getLocalBounds()),u=my(d),p=new Ss({texture:c,width:u.width,height:u.height});p.x=u.x,p.y=u.y,p.alpha=o,p.tileScale.set(a);const{maskContainer:f,contexts:y}=this.createMergedMask(i.map(({graphics:m})=>m));p.mask=f,this.addChild(p),this.floorTypeMap.set(e,p),this.floorTypeMasks.set(e,f),this.floorTypeContexts.set(e,y),this.floorTypeToRooms.set(e,new Set(i.map(({roomId:m})=>m)))}createMergedMask(e){const i=new L,s=[];return e.forEach(n=>{const o=new H,a=n.context.clone();o.context=a,s.push(a),i.addChild(o)}),{maskContainer:i,contexts:s}}clearFloorTypes(){this.floorTypeMasks.forEach(e=>{try{e.destroy({children:!0})}catch(i){A.warn("Error destroying floor mask:",i)}}),this.floorTypeMasks.clear(),this.floorTypeContexts.forEach(e=>{try{e.forEach(i=>{try{i.destroy()}catch(s){A.warn("Error destroying cloned graphics context:",s)}})}catch(i){A.warn("Error destroying graphics contexts:",i)}}),this.floorTypeContexts.clear(),this.floorTypeMap.forEach(e=>{try{this.removeChild(e),e.destroy()}catch(i){A.warn("Error destroying floor material:",i)}}),this.floorTypeMap.clear(),this.floorTypeToRooms.clear()}destroy(){this.clearFloorTypes(),super.destroy()}}class D0{constructor(t){g(this,"unsubscribeFns",[]);g(this,"roomInfoContainer",new L);g(this,"roomInfoMap",new Map);g(this,"roomDisplayMap",new Map);g(this,"roomFloorType");this.appService=t,this.roomFloorType=new B0(t),t.appContainer.addToLayer(lc,this.roomInfoContainer);const e=U(t.runtime,"showRoomFloorType",d=>{A.log(`[runtime] showRoomFloorType: ${d}`),d?this.updateFloorTypes():this.roomFloorType.clearFloorTypes()}),i=U(t.runtime,"showRoomProperty",d=>{A.log(`[runtime] showRoomProperty: ${d}`),this.updateAllRoomPropertyVisibility()}),s=U(t.runtime,"showRoomOrder",d=>{A.log(`[runtime] showRoomOrder: ${d}`),this.updateAllRoomPropertyVisibility()}),n=U(t.runtime,"roomPropertyFoldIds",d=>{A.log(`[runtime] roomPropertyFoldIds: ${d}`),this.updateAllRoomPropertyVisibility()}),o=U(t.runtime,"showRoomName",d=>{A.log(`[runtime] showRoomName: ${d}`),this.updateAllRoomNameVisibility(d)}),a=U(t.runtime,"showRoomType",d=>{A.log(`[runtime] showRoomType: ${d}`),this.updateAllRoomTypeVisibility(d)}),h=U(t.runtime,"enableRoomSelection",d=>{A.log(`[runtime] enableRoomSelection: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),l=U(t.runtime,"selectRoomIds",d=>{A.log(`[runtime] selectRoomIds: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()}),c=U(t.runtime,"roomSelectionMode",d=>{A.log(`[runtime] roomSelectionMode: ${d}`),this.updateAllRoomPropertyVisibility(),this.updateAllRoomSelectionIndicatorVisibility(),this.refreshAllRoomColors()});this.unsubscribeFns.push(e,i,s,n,o,a,h,l,c)}async drawRoomProperty(t){const e=this.appService;return this.roomDisplayMap.clear(),t.forEach((i,s)=>{const n=e.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 t=Array.from(this.roomDisplayMap.values()).filter(e=>e.centerPoint!==null);this.clearRoomInfos(),await Promise.all(t.map(e=>this.createRoomInfo(e)))}async createRoomInfo(t){const e=new I0(this.appService,t);this.roomInfoContainer.addChild(e),this.roomInfoMap.set(t.id,e),await e.initialize(t)}updateRoomName(t,e){const i=this.roomInfoMap.get(t);i&&i.updateName(e)}async updateRoomType(t,e){const i=this.roomDisplayMap.get(t);i&&(i.type=e);const s=this.roomInfoMap.get(t);s&&await s.updateRoomType(e)}updateRoomPosition(t,e){const i=this.roomDisplayMap.get(t);i&&(i.centerPoint=e);const s=this.roomInfoMap.get(t);s&&s.updatePosition(e)}clearRoomInfos(){if(this.roomInfoMap.size===0)return;const t=Array.from(this.roomInfoMap.values());this.roomInfoContainer.removeChildren(),t.forEach(e=>{try{e.destroy()}catch(i){A.warn(`[RoomManager] Error destroying RoomInfo for room ${e.roomId}:`,i)}}),this.roomInfoMap.clear()}getRoomPropertyById(t){return this.roomDisplayMap.get(t)}async refresh(){const t=this.appService;this.roomFloorType.clearFloorTypes(),this.roomDisplayMap.forEach((e,i)=>{const s=t.mapManager.getRoomById(i),n=(s==null?void 0:s.centerPoint)||null;if(e.centerPoint!==n){e.centerPoint=n;const a=this.roomInfoMap.get(i);a&&n&&a.updatePosition(n)}const o=s==null?void 0:s.colorIndex;if(e.colorIndex!==o&&o!==void 0){e.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 t=>{try{await t.updateRoomPropertyVisibility()}catch(e){console.warn(`[RoomManager] Failed to update room property visibility for room ${t.roomId}`,e)}}))}updateAllRoomNameVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomNameVisibility(t)})}updateAllRoomTypeVisibility(t){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(e=>{e.updateRoomTypeVisibility(t)})}updateAllRoomSelectionIndicatorVisibility(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.updateRoomSelectionIndicatorVisibility()})}refreshAllRoomColors(){this.roomInfoMap.size!==0&&this.roomInfoMap.forEach(t=>{t.refreshColor()})}async updateFloorTypes(){const t=this.appService,e=t.mapManager.roomFill.getRoomGraphicsMap();e.size>0?(await this.roomFloorType.createFloorTypes(e),t.getApp().renderOnceNextFrame()):t.mapManager.getAllRooms().length===0&&this.roomFloorType.clearFloorTypes()}clear(){this.clearRoomInfos(),this.roomInfoContainer.removeChildren(),this.roomInfoMap.clear(),this.roomDisplayMap.clear(),this.roomFloorType.clearFloorTypes()}destroy(){this.clearRoomInfos(),this.roomInfoContainer.destroy(),this.roomFloorType.destroy(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}var Xa,Za;(Xa=navigator==null?void 0:navigator.userAgent)!=null&&Xa.includes("tuya-ark-ide")||((Za=navigator==null?void 0:navigator.userAgent)==null||Za.includes("miniProgram"));const F0=()=>{var i,s;if(!Ln.any)return!0;const r=navigator.userAgent.toLowerCase(),t=()=>{const n=navigator.deviceMemory;return n?n>=4:!0};let e=!1;if(/iphone|ipad|ipod/.test(r)){const n=(i=r.match(/os (\d+)_/))==null?void 0:i[1];e=(n?parseInt(n):0)>=12}else if(/android/.test(r)){const n=(s=r.match(/android (\d+)/))==null?void 0:s[1];e=(n?parseInt(n):0)>=10}return e&&t()};class z0 extends L{constructor(e,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(e)}async render(e){if(this.lastConfig=e,this.clear(),e.backgroundImage){await this.renderImage(e.backgroundImage,e.backgroundAlpha);return}if(e.backgroundGradient){this.renderGradient(e.backgroundGradient);return}if(e.backgroundColor!==void 0){this.renderSolidColor(e.backgroundColor,e.backgroundAlpha);return}A.warn("[Background] No background configuration provided")}clear(){this.graphics.clear(),this.sprite&&(this.removeChild(this.sprite),this.sprite.destroy(),this.sprite=null)}renderSolidColor(e,i){this.graphics.clear(),this.graphics.rect(0,0,this.viewportBounds.width,this.viewportBounds.height).fill({color:e,alpha:i}),A.debug("[Background] Rendered solid color background",{color:e,alpha:i})}renderGradient(e){const{width:i,height:s}=this.viewportBounds;if(this.graphics.clear(),e.type==="linear"){const n=e.x0??0,o=e.y0??0,a=e.x1??1,h=e.y1??1,l=new Ot({type:"linear",start:{x:n,y:o},end:{x:a,y:h},colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(l),A.debug("[Background] Rendered linear gradient background",{x0:n,y0:o,x1:a,y1:h,colorStops:e.colorStops.length})}else if(e.type==="radial"){const n=e.cx??.5,o=e.cy??.5,a=e.r??.5,h=new Ot({type:"radial",center:{x:n,y:o},innerRadius:0,outerCenter:{x:n,y:o},outerRadius:a,colorStops:e.colorStops});this.graphics.rect(0,0,i,s).fill(h),A.debug("[Background] Rendered radial gradient background",{cx:n,cy:o,r:a,colorStops:e.colorStops.length})}}async renderImage(e,i){var s,n,o,a;try{const h=await N.load(e.src);if(!h){A.error("[Background] Failed to load image:",e.src),(s=this.lastConfig)!=null&&s.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i);return}this.sprite=new jt(h),this.sprite.label="backgroundSprite",this.sprite.alpha=i;const{width:l,height:c}=this.viewportBounds,d=e.fit||"cover",u=((n=e.position)==null?void 0:n.x)??.5,p=((o=e.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}e.repeat&&A.warn("[Background] Repeat mode not yet implemented"),this.addChild(this.sprite),A.debug("[Background] Rendered image background",{src:e.src,fit:d,position:{x:u,y:p},spriteSize:{width:this.sprite.width,height:this.sprite.height}}),this.onImageLoaded&&this.onImageLoaded()}catch(h){A.error("[Background] Error loading background image:",h),(a=this.lastConfig)!=null&&a.backgroundColor&&this.renderSolidColor(this.lastConfig.backgroundColor,i)}}async update(e){await this.render(e)}destroy(){this.clear(),super.destroy()}}class L0 extends L{constructor(e){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,"handleDragStart",()=>{this.isEditingEnabled()&&(this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-drag",!0))});g(this,"handleDragMove",e=>{if(!this.isEditingEnabled()||this.initialZonePoints.length===0||this.carpetData.shape==="custom")return;const i=this.parent.toLocal(e.global),s=this.controlFill.getDragStartPosition();if(!s)return;const n=i.x-s.x,o=i.y-s.y;this.applyTranslation(n,o)});g(this,"handleDragEnd",()=>{var e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-drag"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleMoveStart",()=>{this.carpetData.points&&this.carpetData.points.length>0?this.initialZonePoints=this.carpetData.points.map(e=>({...e})):this.initialZonePoints=[],this.appService.getApp().requestRender("zone-move",!0)});g(this,"handleMove",e=>{var a,h;if(!this.isEditingEnabled()||this.initialZonePoints.length===0)return;const i=this.parent.toLocal(e.global),s=(h=(a=this.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 e,i;this.initialZonePoints=[],this.appService.getApp().stopRender("zone-move"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleRotationStart",()=>{this.appService.getApp().requestRender("zone-rotate",!0)});g(this,"handleRotationMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleRotationEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-rotate"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleScaleStart",()=>{this.appService.getApp().requestRender("zone-scale",!0)});g(this,"handleScaleMove",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleMoveHorizontal",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleMoveVertical",e=>{e&&(this.carpetData.points=e,this.drawCarpet())});g(this,"handleScaleEnd",()=>{var e,i;this.appService.getApp().stopRender("zone-scale"),(i=(e=this.carpetEvents).onUpdate)==null||i.call(e,this.getCarpetData())});g(this,"handleDelete",()=>{var e,i;(i=(e=this.carpetEvents).onRemove)==null||i.call(e,this.carpetData.id)});g(this,"handleClick",()=>{var e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())});g(this,"handlePointsUpdate",e=>{this.carpetData.points=e,this.drawCarpet()});const{appService:i,carpetData:s,events:n={},textureMap:o}=e;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()}processCarpetData(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=Ia(e.points,this.appService.metersToPixels(this.carpetConfig.minSize)),n=bs(s);this.carpetData={...e,points:n}}else this.carpetData={...e,points:[],shape:e.shape||"rectangle"}}getControlsConfig(){const{controls:e}=this.appService.getConfig();return e}isEditingEnabled(){return this.appService.runtimeSnapshot.editingCarpetIds.includes(this.carpetData.id)}isSelected(){return this.appService.runtimeSnapshot.selectedCarpetIds.includes(this.carpetData.id)}shouldShowEditControl(){return this.isEditingEnabled()||this.isSelected()}initializeComponents(){this.maskContainer=this.createMaskContainer(),this.controlFill=this.createControlFill(),this.addChild(this.maskContainer),this.addChild(this.controlFill),this.drawCarpet()}createMaskContainer(){const e=new L;return this.maskGraphics=new H,this.updateMaskShape(),e.addChild(this.maskGraphics),e.mask=this.maskGraphics,e}createControlFill(){const e=this.isEditingEnabled();return new Lr(this.appService,{points:this.carpetData.points||[],fillColor:this.carpetConfig.fillColor,enableInteraction:e,onDragStart:this.handleDragStart,onDragMove:this.handleDragMove,onDragEnd:this.handleDragEnd})}createEditControlLayer(){const e=this.isEditingEnabled(),i=this.carpetData.shape==="custom",s={...wn(this.carpetConfig,["outlineStrokeWidth","outlineDashed","outlineDashArray","outlineFillColor","outlineOffset","outlineStrokeColor"]),...wn(this.carpetConfig,["textColor","textPosition","textOffset"]),...wn(this.controlsConfig,["textFontSize","textFontFamily","textFontWeight"]),showRotateButton:!!e&&!i,showScaleButton:!!e&&!i,showDeleteButton:!!e,showMoveButton:!!e&&!i,showRadialScaleButton:!!e&&!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,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 e,i;this.isEditingEnabled()||(i=(e=this.carpetEvents)==null?void 0:e.onClick)==null||i.call(e,this.getCarpetData())},stopPropagation:!1})}setupEnableRoomSelectionListener(){const e=U(this.appService.runtime,"enableRoomSelection",s=>{this.updateClickHandlerState(s)});this.unsubscribeFns.push(e);const i=this.appService.runtimeSnapshot.enableRoomSelection;this.updateClickHandlerState(i)}isRoomSelectionEnabled(){return this.appService.runtimeSnapshot.enableRoomSelection}updateClickHandlerState(e){if(e){if(this.eventMode="none",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="none"}}else if(this.eventMode="static",this.clickHandler){const i=this.clickHandler.getTarget();i.eventMode="static"}}calculateBounds(){const{points:e}=this.carpetData;let i=1/0,s=1/0,n=-1/0,o=-1/0;if(e&&e.length>0)for(const a of e)i=Math.min(i,a.x),s=Math.min(s,a.y),n=Math.max(n,a.x),o=Math.max(o,a.y);return{minX:i,minY:s,maxX:n,maxY:o}}calculateBoundingRectanglePoints(){const{points:e}=this.carpetData;if(!e||e.length===0)return[];const{minX:i,minY:s,maxX:n,maxY:o}=vs(e);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:e,shape:i}=this.carpetData;if(!(!e||!Array.isArray(e)||e.length<2)){if(i==="round"){if(e.length<4)return;const n=ee(e),[o,a,,h]=e,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=e.flatMap(o=>[o.x,o.y]);this.maskGraphics.poly(n),this.maskGraphics.position.set(0,0),this.maskGraphics.rotation=0}this.maskGraphics.fill(16777215)}}async loadTexture(){const{opacity:e,scale:i}=this.appService.carpetConfig,{type:s}=this.carpetData;try{this.texture=this.textureMap.get(s)||this.textureMap.get(-1)||null,this.texture&&this.maskContainer&&(this.createTilingSprite(i,e),this.appService.getApp().renderOnce())}catch(n){console.warn("Failed to load carpet texture:",n)}}createTilingSprite(e,i){if(!this.texture||!this.maskContainer)return;const s=this.calculateBounds();this.tilingSprite=new Ss({texture:this.texture,width:s.maxX-s.minX+100,height:s.maxY-s.minY+100}),this.tilingSprite.position.set(s.minX-50,s.minY-50),this.tilingSprite.tileScale.set(e),this.tilingSprite.alpha=i,this.maskContainer.addChild(this.tilingSprite)}updateTilingSprite(){if(!this.tilingSprite)return;const e=this.calculateBounds();this.tilingSprite.position.set(e.minX-50,e.minY-50),this.tilingSprite.width=e.maxX-e.minX+100,this.tilingSprite.height=e.maxY-e.minY+100}applyTranslation(e,i){this.carpetData.points=this.initialZonePoints.map(s=>({x:s.x+e,y:s.y+i})),this.drawCarpet()}drawCarpet(){const{points:e}=this.carpetData;if(!(!e||e.length<2)&&(this.updateMaskShape(),this.updateTilingSprite(),this.controlFill.updatePoints(e),this.editControlLayer)){const n=this.carpetData.shape==="custom"?this.calculateBoundingRectanglePoints():e;this.editControlLayer.updatePoints(n)}}updateEditState(){const e=this.isEditingEnabled(),i=this.isSelected(),s=this.shouldShowEditControl();if(this.controlFill.setInteractionEnabled(e),this.editControlLayer)if(i&&!e)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(e){const n=this.carpetData.shape==="custom";this.appService.editControlManager.updateEditState(this.carpetData.id,{showRotateButton:!n,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(e){if(e.points&&e.points.length>=2)if(e.shape==="custom")this.carpetData={...e,points:e.points};else{const s=Ia(e.points,this.appService.metersToPixels(this.carpetConfig.minSize)),n=bs(s);this.carpetData={...e,points:n}}else this.carpetData={...e,points:e.points||[]};this.drawCarpet(),this.updateEditState()}getCarpetData(){return{...this.carpetData}}refreshDisplay(){this.drawCarpet()}destroy(){var e,i,s,n,o;this.appService.editControlManager.unregisterEditControl(this.carpetData.id),this.unsubscribeFns.forEach(a=>a()),this.unsubscribeFns=[],(e=this.tilingSprite)==null||e.destroy(),(i=this.maskGraphics)==null||i.destroy(),(s=this.maskContainer)==null||s.destroy(),this.tilingSprite=null,this.maskGraphics=null,this.maskContainer=null,this.texture=null,(n=this.controlFill)==null||n.destroy(),(o=this.clickHandler)==null||o.destroy(),super.destroy()}}class O0{constructor(t){g(this,"customCarpetMap",new Map);g(this,"unsubscribeFns",[]);g(this,"textureMap",new Map);g(this,"texturesLoaded",!1);g(this,"texturesLoadingPromise",null);this.appService=t;const e=U(t.runtime,"editingCarpetIds",s=>{A.log(`[runtime] editingCarpetIds: ${s}`),this.updateCarpetsEditState()}),i=U(t.runtime,"selectedCarpetIds",s=>{A.log(`[runtime] selectedCarpetIds: ${s}`),this.updateCarpetsEditState()});this.unsubscribeFns.push(e,i)}async loadTextures(){if(!this.texturesLoaded){if(this.texturesLoadingPromise)return this.texturesLoadingPromise;this.texturesLoadingPromise=this._loadTextures(),await this.texturesLoadingPromise,this.texturesLoaded=!0,this.texturesLoadingPromise=null}}async _loadTextures(){const t=this.appService,{material:e,src:i}=t.carpetConfig;if(e)for(const s of e){const 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)}}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(us);s&&s.position.set(t,e)}async drawCustomCarpets(t){if(await this.loadTextures(),!t||t.length===0){this.clearAllCustomCarpets();return}const e=new Set(this.customCarpetMap.keys()),i=new Set(t.map(s=>s.id));for(const s of e)i.has(s)||this.removeCustomCarpet(s);t.forEach(s=>{const n=this.customCarpetMap.get(s.id.toString());n?this.isCarpetDataEqual(n.getCarpetData(),s)||n.updateCarpetData(s):this.addNewCustomCarpet(s)})}getCustomCarpets(){const t=[];return this.customCarpetMap.forEach(e=>{t.push(e.getCarpetData())}),t}getCustomCarpetById(t){return this.customCarpetMap.get(t)}clearAllCustomCarpets(){this.customCarpetMap.forEach((t,e)=>{var s;const i=this.customCarpetMap.get(e);i&&((s=i.parent)==null||s.removeChild(i),i.destroy())}),this.customCarpetMap.clear()}addNewCustomCarpet(t){const e=this.appService,i=new L0({appService:e,carpetData:t,textureMap:this.textureMap,events:{onRemove:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onDeleteCustomCarpet)==null||o.call(n,{id:s})},onUpdate:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onUpdateCustomCarpet)==null||o.call(n,s)},onClick:s=>{var n,o;(o=(n=e.events)==null?void 0:n.onClickCarpet)==null||o.call(n,{id:s.id})}}});this.customCarpetMap.set(t.id.toString(),i),e.appContainer.addToLayer(us,i)}removeCustomCarpet(t){const e=this.appService,i=this.customCarpetMap.get(t);i&&(e.appContainer.removeFromLayer(us,i),i.destroy(),this.customCarpetMap.delete(t))}updateCarpetsEditState(){this.customCarpetMap.forEach(t=>{t.updateEditState()})}isCarpetDataEqual(t,e){if(t.id!==e.id||t.type!==e.type||t.shape!==e.shape)return!1;const i=t.points||[],s=e.points||[];if(i.length!==s.length)return!1;for(let 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(t=>{t.refreshDisplay()})}destroy(){this.clearAllCustomCarpets(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}class G0 extends Wi{constructor(t,e){super(t,e),this.cursor="pointer"}setupEvents(){this.on("pointertap",()=>{var t,e;(e=(t=this.options).onClick)==null||e.call(t)})}destroy(){this.removeAllListeners(),super.destroy()}}const Ft={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3,FIXED:0};class W0 extends L{constructor(e){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,"onDragStart",e=>{var s,n;if(!this.isEditing||!this.parent||e.target!==this)return;(n=(s=this.appService.events)==null?void 0:s.onGestureStart)==null||n.call(s),this.appService.getApp().requestRender("furniture-drag",!0);const i=this.parent.toLocal(e.global);this.dragStartPosition={x:i.x,y:i.y},this.initialPoints=this.data.points.map(o=>({...o})),this.isDragging=!1});g(this,"onDragMove",e=>{if(!this.isEditing||!this.dragStartPosition||!this.parent)return;const i=this.parent.toLocal(e.global),s=i.x-this.dragStartPosition.x,n=i.y-this.dragStartPosition.y;!this.isDragging&&Math.abs(s)+Math.abs(n)<3||(this.isDragging=!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 e,i,s,n;!this.isEditing||!this.dragStartPosition||(this.isDragging&&((i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())),this.dragStartPosition=null,this.initialPoints=[],this.isDragging=!1,this.appService.getApp().stopRender("furniture-drag"),(n=(s=this.appService.events)==null?void 0:s.onGestureEnd)==null||n.call(s))});g(this,"handleScaleStart",()=>{this.initialScalePoints=this.data.points.map(i=>({...i}));const e=this.getVisualIndex(Ft.SCALE);e>=0&&e<this.data.points.length&&(this.initialButtonPosition={...this.data.points[e]}),this.appService.getApp().requestRender("furniture-scale",!0)});g(this,"handleScaleMove",({deltaX:e,deltaY:i})=>{if(this.initialScalePoints.length===0||!this.initialButtonPosition)return;const s={x:this.initialButtonPosition.x+e,y:this.initialButtonPosition.y+i};this.applyEdgeBasedScale(s)});g(this,"handleScaleEnd",()=>{var e,i;this.initialScalePoints=[],this.initialButtonPosition=null,this.appService.getApp().stopRender("furniture-scale"),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});g(this,"handleMoveStart",()=>{this.initialPoints=this.data.points.map(e=>({...e})),this.appService.getApp().requestRender("furniture-move",!0)});g(this,"handleMoveMove",e=>{var a;if(!this.isEditing||this.initialPoints.length===0||!this.parent)return;const i=this.parent.toLocal(e.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 e,i;this.initialPoints=[],this.appService.getApp().stopRender("furniture-move"),(i=(e=this.furnitureEvents).onUpdate)==null||i.call(e,this.getData())});const{appService:i,data:s,textureAlias:n,events:o={}}=e;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.eventMode="static",this.cursor="pointer",this.setupInteraction()}get config(){return this.appService.furnitureConfig}getVisualIndex(e){return(e+4-this.rotationCount)%4}getVisualPoints(){const e=this.data.points;return[e[this.getVisualIndex(0)],e[this.getVisualIndex(1)],e[this.getVisualIndex(2)],e[this.getVisualIndex(3)]]}createSprite(){const e=N.get(this.textureAlias);this.sprite=new jt(e),this.sprite.anchor.set(.5),this.sprite.alpha=this.config.opacity,this.sprite.eventMode="none",this.addChild(this.sprite)}updateSpriteTransform(){const e=this.data.points;if(e.length<4)return;const i=ee(e),s=e[1].x-e[0].x,n=e[1].y-e[0].y,o=Math.atan2(n,s),a=Q(e[0],e[1]),h=Q(e[1],e[2]);this.sprite.position.set(i.x,i.y),this.sprite.rotation=o,this.sprite.width=a,this.sprite.height=h}createEditControls(){const e=this.calculateOutlinePoints();this.outlineBorder=new Nt(this.appService,{points:e,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(e);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 e=this.calculateOutlinePoints();if(e.length<4)return;const{iconWrapperFillColor:i}=this.config,s=this.getVisualIndex(Ft.REMOVE),n=this.getVisualIndex(Ft.ROTATE),o=this.getVisualIndex(Ft.SCALE);this.deleteButton=new Ds(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(e[s].x,e[s].y),this.rotateButton=new G0(this.appService,{iconAlias:"rotateIcon",backgroundColor:i,onClick:()=>this.handleTapRotate()}),this.rotateButton.position.set(e[n].x,e[n].y),this.scaleButton=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:i,getTargetPoints:()=>this.data.points,getButtonIndex:()=>this.getVisualIndex(Ft.SCALE),onScaleStart:this.handleScaleStart,onScaleMove:this.handleScaleMove,onScaleEnd:this.handleScaleEnd}),this.scaleButton.position.set(e[o].x,e[o].y);const a=this.calculateMoveButtonPosition(e);this.moveButton=new Fs(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:e}=this.data;if(e.length<4)return e;const i=this.appService.getApp().toFixedSize(this.config.outlineOffset);return Ir(e,i)}calculateMoveButtonPosition(e){const i=e??this.calculateOutlinePoints();if(i.length<4)return{x:0,y:0};const{controls:s}=this.appService.getConfig(),n=this.getVisualIndex(Ft.MOVE),o=this.getVisualIndex(2),a=this.getVisualIndex(0),h=this.appService.getApp().toFixedSize(s.moveButtonOffset);return Is(i[n],i[o],i[a],h)}calculateMoveLinePoints(e,i){if(e.length<4)return[];const s=this.getVisualIndex(Ft.MOVE),n=i??this.calculateMoveButtonPosition(e);return[e[s],n]}createSizeText(){const e=this.calculateSizeTextContent(),i=this.appService.controlsConfig,s=new Ui(this.appService,{text:e,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:e}=this.data;if(e.length<4)return"0m*0m";const[i,s,,n]=this.getVisualPoints(),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:e}=this.data;if(e.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=pt(q(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=pt(q(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=pt(q(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=pt(q(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:e}=this.data;if(e.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 Xe(h,l,c)}setupInteraction(){this.clickHandler=new vt(this,{onClick:()=>{var e,i;this.isDragging||(i=(e=this.furnitureEvents).onClick)==null||i.call(e,this.getData())}}),this.on("pointerdown",this.onDragStart,this),this.on("pointermove",this.onDragMove,this),this.on("pointerup",this.onDragEnd,this),this.on("pointerupoutside",this.onDragEnd,this)}handleTapRotate(){var n,o;const e=this.config.rotateDirection!=="ccw",i=e?Math.PI/2:-Math.PI/2,s=ee(this.data.points);this.data.points=Er(this.data.points,s,i),this.rotationCount=(this.rotationCount+(e?1:3))%4,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(),(o=(n=this.furnitureEvents).onUpdate)==null||o.call(n,this.getData())}applyEdgeBasedScale(e){if(this.initialScalePoints.length<4)return;const i=this.getVisualIndex(Ft.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=q(c,h),u=q(c,l),p=q(c,e),f=ie(d),y=ie(u);if(f===0||y===0)return;const{minScaleRatio:m,maxScaleRatio:x}=this.config;let S=he(p,d,f,0),v=he(p,u,y,0);S=Math.max(m,Math.min(x,S)),v=Math.max(m,Math.min(x,v));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 w=0;w<4;w++)P[this.getVisualIndex(w)]=b[w];this.data.points=P,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditControls(){var h;const e=this.calculateOutlinePoints();if(e.length<4)return;this.outlineBorder.updatePoints(e);const i=this.calculateMoveButtonPosition(e),s=this.calculateMoveLinePoints(e,i);if(this.moveLine.updatePoints(s),!this.deleteButton||!this.rotateButton||!this.scaleButton)return;const n=this.getVisualIndex(Ft.REMOVE),o=this.getVisualIndex(Ft.ROTATE),a=this.getVisualIndex(Ft.SCALE);this.deleteButton.position.set(e[n].x,e[n].y),this.rotateButton.position.set(e[o].x,e[o].y),this.scaleButton.position.set(e[a].x,e[a].y),(h=this.moveButton)==null||h.position.set(i.x,i.y)}updateSizeText(e=!1){if(!this.sizeText)return;if(e){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(e=>({...e}))}}updateData(e){this.data={...e,points:e.points.map(i=>({...i}))},this.rotationCount=0,this.updateSpriteTransform(),this.updateEditControls(),this.updateSizeText(!0)}updateEditState(e){this.isEditing!==e&&(this.isEditing=e,this.outlineBorder.visible=e,this.moveLine.visible=e,this.controlButtons.visible=e)}destroy(){var e;(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,super.destroy({children:!0})}}class U0{constructor(t){g(this,"furnitureMap",new Map);g(this,"unsubscribeFns",[]);this.appService=t;const e=U(t.runtime,"editingFurnitureIds",i=>{A.log(`[runtime] editingFurnitureIds: ${i}`),this.updateEditState()});this.unsubscribeFns.push(e)}updatePositionByOrigin(t,e){const i=this.appService.appContainer.getLayer(ds);i&&i.position.set(t,e)}async drawFurnitures(t){if(!t||t.length===0){this.clearAll();return}const e=new Set(this.furnitureMap.keys()),i=new Set(t.map(n=>n.id));for(const n of e)i.has(n)||this.removeFurniture(n);const s=[];for(const n of t){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(t){const e=this.appService;if(!e.furnitureConfig.assets.find(h=>h.type===t.furnitureType)){A.warn(`[FurnitureManager] No asset found for furnitureType: ${t.furnitureType}`);return}const n=`furniture_${t.furnitureType}`;await N.load(n);const o=new W0({appService:e,data:t,textureAlias:n,events:{onRemove:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onRemoveFurniture)==null||c.call(l,h)},onUpdate:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onUpdateFurniture)==null||c.call(l,h)},onClick:h=>{var l,c;(c=(l=e.events)==null?void 0:l.onClickFurniture)==null||c.call(l,h)}}});this.furnitureMap.set(t.id,o),e.appContainer.addToLayer(ds,o),e.runtime.editingFurnitureIds.includes(t.id)&&o.updateEditState(!0)}removeFurniture(t){const e=this.furnitureMap.get(t);e&&(this.appService.appContainer.removeFromLayer(ds,e),e.destroy(),this.furnitureMap.delete(t))}clearAll(){var t;for(const[,e]of this.furnitureMap)(t=e.parent)==null||t.removeChild(e),e.destroy();this.furnitureMap.clear()}updateEditState(){const t=this.appService.runtime.editingFurnitureIds;this.furnitureMap.forEach((e,i)=>{e.updateEditState(t.includes(i))})}isDataEqual(t,e){if(t.id!==e.id||t.furnitureType!==e.furnitureType||t.points.length!==e.points.length)return!1;for(let i=0;i<t.points.length;i++)if(Math.abs(t.points[i].x-e.points[i].x)>.1||Math.abs(t.points[i].y-e.points[i].y)>.1)return!1;return!0}destroy(){this.clearAll(),this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}}const ft={REMOVE:0,ROTATE:1,SCALE:2,MOVE:3};class H0 extends L{constructor(e,i){super();g(this,"config");g(this,"events");g(this,"zonePoints",[]);g(this,"outlinePoints");g(this,"minSize",.1);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=e,this.zonePoints=i.zonePoints,this.config={...i.config,showScaleButton:i.config.showScaleButton!==void 0?i.config.showScaleButton:!0,showRadialScaleButton:i.config.showRadialScaleButton!==void 0?i.config.showRadialScaleButton:!0,showDeleteButton:i.config.showDeleteButton!==void 0?i.config.showDeleteButton:!0,showMoveButton:i.config.showMoveButton!==void 0?i.config.showMoveButton:!0,showRotateButton:i.config.showRotateButton!==void 0?i.config.showRotateButton:!0},this.events=i.events||{},this.minSize=i.minSize??.1,this.throttledUpdateOutline=At(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:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n,outlineFillColor:o}=this.config;return new Nt(this.appService,{points:this.outlinePoints,closePath:!0,style:{color:e,width:i,isDashed:s,dashArray:n,fillColor:o}})}createMoveLine(){const{outlineStrokeColor:e,outlineStrokeWidth:i,outlineDashed:s,outlineDashArray:n}=this.config,o=this.calculateMoveLinePoints();return new Nt(this.appService,{points:o,closePath:!1,style:{color:e,width:i,isDashed:s,dashArray:n}})}createSizeText(){const e=this.calculateSizeText(),i=new Ui(this.appService,{text:e,style:{fontSize:this.config.textFontSize,fontFamily:this.config.textFontFamily,fontWeight:this.config.textFontWeight,fill:this.config.textColor,align:"center"}});i.anchor.set(.5);const s=this.calculateSizeTextPosition();i.position.set(s.x,s.y);const n=this.calculateSizeTextRotation();return i.rotation=n,i.eventMode="none",i}createDeleteButton(){const e=new Ds(this.appService,{iconAlias:"deleteIcon",backgroundColor:"red",onClick:()=>{var i,s;return(s=(i=this.events).onRemove)==null?void 0:s.call(i)}});return e.position.set(this.outlinePoints[ft.REMOVE].x,this.outlinePoints[ft.REMOVE].y),e}createRotateButton(){const e=new fc(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 e.position.set(this.outlinePoints[ft.ROTATE].x,this.outlinePoints[ft.ROTATE].y),e}onClickRotateButton(e){const i=this.handleInternalRotationMove(e)??[];return this.resetRotationState(),i}createScaleButton(){const e=new Ze(this.appService,{iconAlias:"scaleIcon",backgroundColor:this.config.iconWrapperFillColor,initialButtonPosition:this.outlinePoints[ft.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 e.position.set(this.outlinePoints[ft.SCALE].x,this.outlinePoints[ft.SCALE].y),e}createHorizontalScaleButton(){const[,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),n=new Ze(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[,,e,i]=this.outlinePoints,s=this.getEdgeCenter(e,i),n=new Ze(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 e=this.calculateMoveButtonPosition(),i=new Fs(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(e.x,e.y),i}createAndAddButton(e,i){return e.visible=i,this.controlButtons.addChild(e),e}createControlButtons(){this.outlinePoints.length<4||(this.deleteButton=this.createAndAddButton(this.createDeleteButton(),this.config.showDeleteButton??!1),this.moveButton=this.createAndAddButton(this.createMoveButton(),this.config.showMoveButton??!1),this.rotateButton=this.createAndAddButton(this.createRotateButton(),this.config.showRotateButton??!1),this.scaleButton=this.createAndAddButton(this.createScaleButton(),this.config.showScaleButton??!1),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 e=this.zonePoints;if(e.length<4)return e;const s=this.appService.getApp().toFixedSize(this.config.outlineOffset);return Ir(e,s)}calculateMoveButtonPosition(){const e=this.calculateOutlinePoints();if(e.length<4)return{x:0,y:0};const s=this.appService.getApp().toFixedSize(this.config.moveButtonOffset),n=e[ft.MOVE],o=e[ft.SCALE],a=e[ft.REMOVE];return Is(n,o,a,s)}calculateMoveLinePoints(){const e=this.calculateOutlinePoints();if(e.length<4)return[];const i=e[ft.MOVE],s=this.calculateMoveButtonPosition();return[i,s]}calculateSizeText(){const e=this.zonePoints;if(e.length<4)return"0m*0m";const[i,s,,n]=e,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(e,i){return{x:(e.x+i.x)/2,y:(e.y+i.y)/2}}calculatePerpendicularOffset(e,i,s,n=!1){const o=pt(q(i,e)),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 e=this.zonePoints;if(e.length<4)return 0;const[i,s,n,o]=e,{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 Xe(h,l,c)}calculateHorizontalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(i,s,n)+Math.PI/2}calculateVerticalScaleButtonRotation(){const e=this.zonePoints;if(e.length<4)return 0;const[,,i,s]=e,n=this.appService.appContainer.getMapRotationRadians();return Xe(s,i,n)}updatePoints(e,i=!0){this.zonePoints=e,this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeText(i)}updateOutlineBorder(){const e=this.calculateOutlinePoints();this.outlinePoints=e,this.outlineBorder.updatePoints(e)}updateMoveLine(){if(!this.moveLine)return;const e=this.calculateMoveLinePoints();this.moveLine.updatePoints(e)}updateSizeText(e=!0){if(this.sizeText){if(e){const i=this.calculateSizeText();this.sizeText.updateText(i)}this.updateSizeTextPosition()}}updateSizeTextPosition(){if(!this.sizeText)return;const e=this.calculateSizeTextPosition();this.sizeText.position.set(e.x,e.y);const i=this.calculateSizeTextRotation();this.sizeText.rotation=i}updateControlButtonsPosition(){if(!this.deleteButton||!this.scaleButton||!this.moveButton)return;const e=this.calculateOutlinePoints();if(e.length<4)return;const i=this.calculateMoveButtonPosition(),s=[{button:this.deleteButton,point:e[ft.REMOVE]},{button:this.scaleButton,point:e[ft.SCALE]},{button:this.moveButton,point:i}];if(this.rotateButton&&s.push({button:this.rotateButton,point:e[ft.ROTATE]}),this.horizontalScaleButton){const n=e[ft.ROTATE],o=e[ft.SCALE],a=Jl(n,o,0);s.push({button:this.horizontalScaleButton,point:a})}if(this.verticalScaleButton){const n=e[ft.SCALE],o=e[ft.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 e,i;(i=(e=this.events).onClick)==null||i.call(e)},stopPropagation:!1})}registerScaleListener(){this.appService.emitter.on("antiScale",this.throttledUpdateOutline),this.appService.emitter.on("mapRotationUpdate",this.throttledUpdateOutline)}updateOutlineForScale(){(this.outlineBorder.visible||this.controlButtons.visible)&&(this.updateOutlineBorder(),this.moveLine&&this.updateMoveLine(),this.updateControlButtonsPosition(),this.updateSizeTextPosition())}initializeScaleCache(){if(this.initialZonePoints.length===0&&(this.initialZonePoints=this.zonePoints.map(p=>({...p}))),this.initialZonePoints.length<4)return;const e={...this.initialZonePoints[ft.SCALE]};if(!e)return;const i=ft.REMOVE,{x:s,y:n}=this.initialZonePoints[i],[,o,,a]=this.initialZonePoints,h={x:s,y:n},l=q(h,o),c=q(h,a),d=ie(l),u=ie(c);d===0||u===0||(this.scaleCache={fixedPoint:h,edge1:l,edge2:c,edge1Len:d,edge2Len:u,initialButtonPosition:e})}handleInternalScaleMove(e,i){if(this.initialZonePoints.length!==4||!this.scaleCache)return null;const s=this.appService.metersToPixels(this.minSize),{fixedPoint:n,edge1:o,edge2:a,edge1Len:h,edge2Len:l,initialButtonPosition:c}=this.scaleCache,d={x:c.x+e,y:c.y+i},u=q(n,d),p=he(u,o,h,s),f=he(u,a,l,s);return this.calculatePointsFromScale(n,o,a,p,f)}resetScaleState(){this.scaleCache=null}handleInternalHorizontalScaleMove(e,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={x:this.horizontalScaleInitialPosition.x+e,y:this.horizontalScaleInitialPosition.y+i},c=q(s,l),d=he(c,n,a,h);return this.calculatePointsFromScale(s,n,o,d,1)}handleInternalVerticalScaleMove(e,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={x:this.verticalScaleInitialPosition.x+e,y:this.verticalScaleInitialPosition.y+i},c=q(s,l),d=1,u=he(c,o,a,h);return this.calculatePointsFromScale(s,n,o,d,u)}calculatePointsFromScale(e,i,s,n,o){const{x:a,y:h}=e;return[e,{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(e){this.zonePoints.length<3||(this.rotationCache={rotationCenter:e,initialPoints:this.zonePoints.map(i=>({...i})),totalAngle:0})}handleInternalRotationMove(e){if(!this.rotationCache||this.rotationCache.initialPoints.length<3)return null;const{rotationCenter:i,initialPoints:s}=this.rotationCache;return this.rotationCache.totalAngle+=e,Er(s,i,this.rotationCache.totalAngle)}resetRotationState(){this.rotationCache=null}calculateRotationCenter(){return this.zonePoints.length===0?{x:0,y:0}:ee(this.zonePoints)}updateEditState({showRotateButton:e=!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=e),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=e||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 e=((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:e,isRotating:i,isMoving:s,hasAnyOperation:e||i||s}}stopAllOperations(){var e,i,s;(e=this.scaleButton)==null||e.stopScaling(),(i=this.rotateButton)==null||i.stopRotation(),(s=this.moveButton)==null||s.stopMoving()}getControlButtonsContainer(){return this.controlButtons}getMoveButton(){return this.moveButton}calculateEdgeMidpoint(e,i){const s=this.calculateOutlinePoints();if(s.length<4)return{x:0,y:0};const n=s[e],o=s[i];return{x:(n.x+o.x)/2,y:(n.y+o.y)/2}}destroy(){var e,i,s,n,o,a,h,l,c,d,u;this.appService.emitter.off("antiScale",this.throttledUpdateOutline),this.appService.emitter.off("mapRotationUpdate",this.throttledUpdateOutline),(e=this.clickHandler)==null||e.destroy(),this.clickHandler=null,(i=this.deleteButton)==null||i.destroy(),(s=this.rotateButton)==null||s.destroy(),(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 V0{constructor(t){g(this,"editControlLayers",new Map);this.appService=t}registerEditControl(t,e){const i=this.appService;this.editControlLayers.has(t)&&this.unregisterEditControl(t);const s=new H0(i,e);if(!i.appContainer.addToLayer(Ti,s))throw A.warn(`[EditControlManager] Failed to add edit control layer for id: ${t}`),s.destroy(),new Error(`Failed to register edit control for id: ${t}`);return this.editControlLayers.set(t,s),s}unregisterEditControl(t){const e=this.editControlLayers.get(t);if(!e)return;this.appService.appContainer.removeFromLayer(Ti,e),e.destroy(),this.editControlLayers.delete(t)}getEditControl(t){return this.editControlLayers.get(t)}updateEditState(t,e){const i=this.editControlLayers.get(t);i&&i.updateEditState(e)}clearAll(){Array.from(this.editControlLayers.keys()).forEach(e=>this.unregisterEditControl(e))}getAllEditControls(){return Array.from(this.editControlLayers.values())}updatePositionByOrigin(t,e){const s=this.appService.appContainer.getLayer(Ti);s&&s.position.set(t,e)}hasEditControl(t){return this.editControlLayers.has(t)}}class Vr extends $h{constructor(e=Ha){super();g(this,"mapState",null);g(this,"components",{});g(this,"managers",{});g(this,"config",Ua);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",Bx());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=e,this.appService=new ic(this),globalThis.__PIXI_APP__=this}async initialize(e){const{resizeTo:i,events:s,config:n,runtime:o={},...a}=e;this.config=sr(_a({},Ua,n??{})),sy(()=>this.config.global.enableLogger),A.log("Applying config",this.config,n),this.runtime=sr(Object.assign({},Ix,o));const h=this.instanceKey===Ha;this.containerElement=i;const l=h&&this.config.interaction.enable,c=this.config.global.performanceMode||!h,d={textureGCMaxIdle:c?60:Ln.any?180:3600,textureGCCheckCountMax:c?10:Ln.any?100:50,autoStart:!1,sharedTicker:c,eventFeatures:{move:l,globalMove:!1,click:l,wheel:l}};await this.init({resizeTo:h?i:void 0,preference:"webgpu",resolution:this.config.global.resolution,antialias:c?!1:F0(),depth:!c,autoDensity:!0,backgroundColor:0,backgroundAlpha:0,...d,...a}),A.log(`[Pixi] Renderer initialized: ${this.renderer.type===Ri.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 Vx(this.appService),this.managers.heatmapManager=new Kx(this.appService),this.managers.pathManager=new Zx(this.appService),this.managers.controlsManager=new t0(this.appService),this.managers.detectedObjectManager=new i0(this.appService),this.managers.customElementsManager=new T0(this.appService),this.managers.roomsManager=new D0(this.appService),this.managers.customCarpetManager=new O0(this.appService),this.managers.furnitureManager=new U0(this.appService),this.managers.editControlManager=new V0(this.appService),this.setupMapRotationListener(),document.addEventListener("visibilitychange",this.onVisibilityChange)}async drawMap(e){var a,h,l,c,d,u,p;this.isMapDrawn=!1,A.log("[Map] drawMap",e);const{size:i,resolution:s,origin:n,id:o}=e;((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.managers.pathManager.updatePositionByOrigin(...n),this.managers.controlsManager.updatePositionByOrigin(...n),this.managers.detectedObjectManager.updatePositionByOrigin(...n),this.managers.customElementsManager.updatePositionByOrigin(...n),this.managers.customCarpetManager.updatePositionByOrigin(...n),this.managers.furnitureManager.updatePositionByOrigin(...n),this.managers.editControlManager.updatePositionByOrigin(...n),this.managers.heatmapManager.updatePositionByOrigin(...n)),this.mapState={id:e.id,status:e.status===1,origin:{x:n[0],y:n[1]},charger:{x:e.charger.coordinate[0],y:e.charger.coordinate[1]},chargerDirection:e.charger.angle??0,resolution:s,width:i[0],height:i[1],mapType:"structured"},this.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(e),i[0]===0||i[1]===0?(A.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(e){var a,h,l,c,d,u;this.isMapDrawn=!1,A.log("[Map] drawRasterMap",e);const{mapHeader:i,mapData:s}=e,{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.managers.pathManager.updatePositionByOrigin(n,o),this.managers.controlsManager.updatePositionByOrigin(n,o),this.managers.editControlManager.updatePositionByOrigin(n,o),this.managers.furnitureManager.updatePositionByOrigin(n,o),this.managers.detectedObjectManager.updatePositionByOrigin(n,o),this.managers.customElementsManager.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?(A.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(e){var i,s;A.log("[Path] drawPath",e),(s=(i=this.events)==null?void 0:i.onPathDrawed)==null||s.call(i,{id:e.pathHeader.pathId,type:e.pathHeader.type,direction:e.pathHeader.direction,count:e.pathHeader.count,initFlag:e.pathHeader.initFlag,robotPosition:e.pathPoints[e.pathPoints.length-1]??null}),this.managers.pathManager.draw(e),this.renderOnce()}async drawRoomProperty(e){var i,s;A.log("[Room] drawRoomProperty",e),(s=(i=this.events)==null?void 0:i.onRoomPropertiesDrawed)==null||s.call(i,e),await this.managers.roomsManager.drawRoomProperty(e),this.renderOnceNextFrame()}async drawCustomCarpets(e){A.log("[CustomCarpets] drawCustomCarpets",e),await this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawFurnitures(e){A.log("[Furniture] drawFurnitures",e),await this.managers.furnitureManager.drawFurnitures(e),this.renderOnceNextFrame()}drawHeatmap(e){A.log("[Heatmap] drawHeatmap",e),this.managers.heatmapManager.draw(e),this.renderOnce()}drawForbiddenSweepZones(e){A.log("[Controls] drawForbiddenSweepZones",e),this.managers.controlsManager.drawForbiddenSweepZones(e),this.renderOnceNextFrame()}drawForbiddenMopZones(e){A.log("[Controls] drawForbiddenMopZones",e),this.managers.controlsManager.drawForbiddenMopZones(e),this.renderOnceNextFrame()}drawCleanZones(e){A.log("[Controls] drawCleanZones",e),this.managers.controlsManager.drawCleanZones(e),this.renderOnceNextFrame()}drawVirtualWalls(e){A.log("[Controls] drawVirtualWalls",e),this.managers.controlsManager.drawVirtualWalls(e),this.renderOnceNextFrame()}drawSpots(e){A.log("[Controls] drawSpots",e),this.managers.controlsManager.drawSpots(e),this.renderOnceNextFrame()}drawWayPoints(e){A.log("[Controls] drawWayPoints",e),this.managers.controlsManager.drawWayPoints(e),this.renderOnceNextFrame()}async drawDetectedObjects(e){A.log("[DetectedObject] drawDetectedObjects",e),await this.managers.detectedObjectManager.drawDetectedObjects(e),this.renderOnceNextFrame()}drawCustomCarpet(e){A.log("[CustomCarpet] drawCustomCarpet",e),this.managers.customCarpetManager.drawCustomCarpets(e),this.renderOnceNextFrame()}async drawCustomElements(e){A.log("[CustomElements] drawCustomElements",e),await this.managers.customElementsManager.drawCustomElements(e),this.renderOnceNextFrame()}getForbiddenSweepZones(){return this.managers.controlsManager.getForbiddenSweepZones()}getForbiddenMopZones(){return this.managers.controlsManager.getForbiddenMopZones()}getCleanZones(){return this.managers.controlsManager.getCleanZones()}getVirtualWalls(){return this.managers.controlsManager.getVirtualWalls()}getSpots(){return this.managers.controlsManager.getSpots()}getWayPoints(){return this.managers.controlsManager.getWayPoints()}getEffectiveDividerPoints(){return this.managers.controlsManager.getEffectiveDividerPoints()}getCustomCarpets(){return this.managers.customCarpetManager.getCustomCarpets()}getDividerEndPoints(){return this.managers.controlsManager.getDividerEndPoints()}resetPanZoom(){this.components.interaction.setPanZoom()}forceEndGesture(){A.log("[Map] forceEndGesture"),this.components.interaction.forceEndGesture()}fitMapToView(e,i=!1){if(!e||e.minX===e.maxX||e.minY===e.maxY)return;const s=this.config.map.autoPaddingVerticalPercent,n=this.config.map.autoPaddingHorizontalPercent,o=this.getViewportBounds(),a=this.components.appContainer.getMapRotationRadians(),h=this.calculateRotatedBounds(e,a),l=h.maxX-h.minX,c=h.maxY-h.minY,d=o.width,u=o.height,p=d*(1-n*2),f=u*(1-s*2),y=p/l,m=f/c,x=Math.min(y,m),S=Math.max(this.config.interaction.fitMinScale,this.scaleMin),v=Math.min(this.config.interaction.fitMaxScale,this.scaleMax),b=Math.max(S,Math.min(v,x)),P=e.minX+(e.maxX-e.minX)/2,w=e.minY+(e.maxY-e.minY)/2,C=this.config.map.autoFitOffset||{x:0,y:0},k=d/2+(C.x||0),M=u/2+(C.y||0),T=Math.cos(a),_=Math.sin(a),I=P*T-w*_,B=P*_+w*T,F=k-I*b,Z=M-B*b;A.debug("[MapApplication] fitMapToView calculated:",{rotation:this.components.appContainer.getMapRotation(),originalBounds:e,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)}calculateRotatedBounds(e,i){if(i===0)return e;const s=(e.minX+e.maxX)/2,n=(e.minY+e.maxY)/2,o=[{x:e.minX-s,y:e.minY-n},{x:e.maxX-s,y:e.minY-n},{x:e.maxX-s,y:e.maxY-n},{x:e.minX-s,y:e.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 e;return((e=this.components.viewportContainer)==null?void 0:e.getViewportBounds())||{x:0,y:0,width:this.renderer.width,height:this.renderer.height}}updateRuntime(e){Object.assign(this.runtime,e),A.log("[runtime] runtime updated",e),this.renderOnceNextFrame()}updateConfig(e){var i;_a(this.config,e),(i=this.managers.controlsManager)==null||i.updateRenderOrder(),A.log("[Config] Configuration updated",e),this.renderOnceNextFrame()}metersToPixels(e){var n;if(!((n=this.mapState)!=null&&n.resolution))return A.warn("Map resolution not available, using default resolution (5cm/pixel)"),e*20;const s=1/(this.mapState.resolution/100);return e*s}pixelsToMeters(e){var s;if(!((s=this.mapState)!=null&&s.resolution))return A.warn("Map resolution not available, using default resolution (5cm/pixel)"),e*.05;const i=this.mapState.resolution/100;return e*i}toFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e/s}fromFixedSize(e,i){const s=i??this.components.appContainer.scale.x;return e*s}getViewportCenterPoint(){if(!this.mapState)return A.warn("Map state not available, cannot calculate center point"),null;const e=this.getViewportBounds(),i=e.x+e.width/2,s=e.y+e.height/2,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 A.warn("Map state not available, cannot calculate map center point"),null;const e=this.managers.mapManager.mapBounds;if(e.minX===1/0||e.minY===1/0||e.maxX===-1/0||e.maxY===-1/0)return A.warn("Invalid map bounds, cannot calculate map center point"),null;const i=(e.minX+e.maxX)/2,s=(e.minY+e.maxY)/2,n=i-this.mapState.origin.x,o=s-this.mapState.origin.y;return{x:n,y:o}}getWallPointsByViewportCenter(e){var f;const{width:i=this.config.controls.virtualWall.minWidth,direction:s="horizontal",offsetX:n=0,offsetY:o=0}=e||{},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(e){const i=this.config.controls.forbiddenSweepZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getForbiddenMopZonePointsByViewportCenter(e){const i=this.config.controls.forbiddenMopZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getCleanZonePointsByViewportCenter(e){const i=this.config.controls.cleanZone,{size:s=i.minSize,offsetX:n=0,offsetY:o=0}=e||{};return this.generateZonePoints(s,n,o)}getSpotPointByViewportCenter(e){const{offsetX:i=0,offsetY:s=0}=e||{},n=this.getViewportCenterPoint()||{x:0,y:0},o=n.x+i,a=n.y+s;return{x:o,y:a}}getFurniturePointsByViewportCenter(e){var x;const{furnitureType:i=1,offsetX:s=0,offsetY:n=0}=e||{},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(e){return!e||e.length===0?(A.warn("[Room] No room IDs provided"),!1):this.managers.mapManager.areRoomsAdjacent(e)}isPointInAnyRoom(e){return!e||typeof e.x!="number"||typeof e.y!="number"?(A.warn("[Room] Invalid point provided"),null):this.mapState?this.managers.mapManager.isPointInAnyRoom(e):(A.warn("[Room] Map state not available"),null)}isWallIntersectsAnyRoom(e){return!e||e.length!==2||!e[0]||!e[1]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"?(A.warn("[Room] Invalid wall points provided"),!1):this.mapState?this.managers.mapManager.isWallIntersectsAnyRoom(e):(A.warn("[Room] Map state not available"),!1)}isZoneIntersectsAnyRoom(e){return!e||e.length!==4||!e[0]||!e[1]||!e[2]||!e[3]||typeof e[0].x!="number"||typeof e[0].y!="number"||typeof e[1].x!="number"||typeof e[1].y!="number"||typeof e[2].x!="number"||typeof e[2].y!="number"||typeof e[3].x!="number"||typeof e[3].y!="number"?(A.warn("[Room] Invalid zone points provided"),!1):this.mapState?this.managers.mapManager.isZoneIntersectsAnyRoom(e):(A.warn("[Room] Map state not available"),!1)}isNearChargerOrRobot(e,i,s){var h,l;if(!e||e.length<1)return A.warn("[Distance] Invalid points array: must have at least 1 point"),!1;if(e.length!==1&&e.length!==2&&e.length!==4)return A.warn("[Distance] Invalid points array: must have exactly 1 (point), 2 (wall) or 4 (zone) points"),!1;if(i<=0)return A.warn("[Distance] Invalid threshold: must be greater than 0"),!1;if(!this.mapState)return A.warn("[Distance] Map state not available"),!1;const{checkCharger:n=!0,checkRobot:o=!1}=s||{};if(!n&&!o)return A.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 A.warn("[Distance] Charger position not available"),!1;const p=Ea(c,e);if(p<=a)return A.log(`[Distance] Too close to charger: ${p.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else A.warn("[Distance] Charger position not available")}if(o){const c=this.appService.getRobotPosition();if(c){const d=Ea(c,e);if(d<=a)return A.log(`[Distance] Too close to robot: ${d.toFixed(2)} pixels (threshold: ${a.toFixed(2)} pixels)`),!0}else A.warn("[Distance] Robot position not available")}return!1}async snapshot(e){this.render();const{snapshot:i,global:s}=this.config,n=(e==null?void 0:e.backgroundColor)??s.backgroundColor,o=this.components.appContainer,a=o.getSnapshotBounds(),h=Math.floor(a.x),l=Math.floor(a.y),c=Math.ceil(a.x+a.width)-h,d=Math.ceil(a.y+a.height)-l;if(c<=0||d<=0)return A.error("[MapApplication] Snapshot failed: invalid bounds",a),"";const u=i.resolution||window.devicePixelRatio||2,p=kr.create({width:c,height:d,resolution:u}),f=new H;f.rect(0,0,c,d).fill(n);const y=new W;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 A.error("[MapApplication] Snapshot failed:",m),""}finally{f.destroy(),p.destroy(!0)}}async snapshotByData({map:e,path:i,roomProperties:s,customElements:n,forbiddenSweepZones:o,forbiddenMopZones:a,virtualWalls:h,detectedObjects:l,furnitures:c},d={},u){const p=`SNAPSHOT_${Fx()}`;A.log(`[MapApplication] ${p} snapshot start`);const f=new Vr(p);try{if(await f.initialize({config:this.config,runtime:d}),!e)throw new Error("Map data is required");if(e.startsWith("7b22")){const m=$c(e);await f.drawMap(m)}else{const m=Qc(e,{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.CKxbjNbw.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 A.log(`[MapApplication] ${p} snapshot completed successfully`),y}catch(y){throw A.error(`[MapApplication] ${p} snapshot other map failed:`,y),y}finally{A.log(`[MapApplication] ${p} destroy`),f.destroy()}}renderOnce(){A.log("[Pixi] renderOnce"),this.render()}renderOnceNextFrame(){this.pendingAsyncRender||(this.pendingAsyncRender=!0,requestAnimationFrame(()=>{A.log("[Pixi] renderOnceNextFrame"),this.render(),this.pendingAsyncRender=!1}))}requestRender(e,i=!1){if(!i){this.renderOnceNextFrame();return}this.tickerState.renderReasons.add(e),this.ticker.started||(A.debug(`🎬 [Ticker] START: ${e}`),this.ticker.start())}stopRender(e){this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&this.scheduleStopRender("final",100)}destroy(){var e;A.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(),(e=this.components.background)==null||e.destroy(),this.components.viewportContainer.destroy(),this.components.appContainer.destroy(),this.managers.heatmapManager.destroy(),super.destroy()}initializeViewportContainer(){this.components.viewportContainer=new zx(this.config,this.containerElement),this.stage.addChild(this.components.viewportContainer);const e=this.getViewportBounds();this.components.background=new z0(this.config.global,e,()=>{this.renderOnceNextFrame()}),this.components.viewportContainer.addChild(this.components.background),this.components.viewportContainer.setChildIndex(this.components.background,0),Bs(this.config.global,()=>{var i;(i=this.components.background)==null||i.update(this.config.global)})}initializeAppContainer(){this.components.appContainer=new Gx(this.appService),this.components.interaction.addChild(this.components.appContainer)}initializeInteraction(){this.components.interaction=new Iy(this.appService),this.components.viewportContainer.addChild(this.components.interaction)}scheduleStopRender(e,i){this.tickerState.renderTimer&&clearTimeout(this.tickerState.renderTimer),this.tickerState.renderTimer=setTimeout(()=>{this.tickerState.renderReasons.delete(e),this.tickerState.renderReasons.size===0&&(A.debug("⏸️ [Ticker] STOP"),this.ticker&&this.ticker.stop())},i)}generateZonePoints(e,i,s){var u;const n=this.getViewportCenterPoint()||{x:0,y:0},a=this.metersToPixels(e)/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 e=this.config.robot.icon.src,i=this.config.chargingStation.icon.src,s=[];N.add({alias:"robot",src:e}),s.push("robot"),N.add({alias:"chargingStation",src:i}),s.push("chargingStation"),N.add({alias:"deleteIcon",src:this.config.controls.deleteIconSrc}),s.push("deleteIcon"),N.add({alias:"rotateIcon",src:this.config.controls.rotateIconSrc}),s.push("rotateIcon"),N.add({alias:"scaleIcon",src:this.config.controls.scaleIconSrc}),s.push("scaleIcon"),N.add({alias:"moveIcon",src:this.config.controls.moveIconSrc}),s.push("moveIcon"),N.add({alias:"checkmark",src:this.config.room.selectionIndicator.iconSrc}),s.push("checkmark"),N.add({alias:"spotIcon",src:this.config.controls.spot.iconSrc}),s.push("spotIcon"),N.add({alias:"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),U(this.runtime,"mapRotation",e=>{this.applyMapRotation(e)})}applyMapRotation(e){const i=(e%360+360)%360;A.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 $0=Object.freeze(Object.defineProperty({__proto__:null,AppService:ic,MapApplication:Vr},Symbol.toStringTag,{value:"Module"}));export{Lo as $,wi as A,le as B,ne as C,lr as D,Yt as E,ur as F,H as G,jg as H,Qe as I,Bf as J,ks as K,Cf as L,W as M,Ot as N,Rs as O,tt as P,dr as Q,et as R,Fp as S,G as T,Ee as U,j as V,jh as W,Ri as X,Gi as Y,Ip as Z,ri as _,Ke as a,Ci as a0,pr as a1,Hh as a2,Bt as a3,ti as a4,ol as a5,lf as a6,pf as a7,K0 as a8,hl as a9,Di as aA,Op as aB,al as aC,cf as aD,gf as aE,Yg as aF,ll as aG,mf as aH,Lg as aI,$0 as aJ,Ie as aa,hs as ab,Au as ac,cd as ad,ce as ae,Je as af,yf as ag,_t as ah,ph as ai,It as aj,Ps as ak,ho as al,jt as am,Mm as an,Ud as ao,co as ap,qs as aq,uo as ar,Vd as as,gh as at,kr as au,Pr as av,Yh as aw,Oi as ax,Zu as ay,Vu as az,$n as b,rt as c,V as d,de as e,Qn as f,os as g,xt as h,X as i,pu as j,gt as k,am as l,dt as m,Ln as n,iu as o,E as p,yt as q,Cd as r,zg as s,fa as t,Pu as u,J as v,nt as w,$ as x,L as y,st as z};
|