agent-theatre 1.2.2 → 1.2.3

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.
@@ -1,8 +1,8 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browserAll-DpEOVFXE.js","assets/webworkerAll-BIhfsOqG.js"])))=>i.map(i=>d[i]);
2
- (function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const n of r)if(n.type==="childList")for(const o of n.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(r){const n={};return r.integrity&&(n.integrity=r.integrity),r.referrerPolicy&&(n.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?n.credentials="include":r.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function s(r){if(r.ep)return;r.ep=!0;const n=t(r);fetch(r.href,n)}})();const Fg="modulepreload",Og=function(i){return"/"+i},yh={},St=function(e,t,s){let r=Promise.resolve();if(t&&t.length>0){let o=function(h){return Promise.all(h.map(c=>Promise.resolve(c).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),l=a?.nonce||a?.getAttribute("nonce");r=o(t.map(h=>{if(h=Og(h),h in yh)return;yh[h]=!0;const c=h.endsWith(".css"),u=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${u}`))return;const d=document.createElement("link");if(d.rel=c?"stylesheet":Fg,c||(d.as="script"),d.crossOrigin="",d.href=h,l&&d.setAttribute("nonce",l),document.head.appendChild(d),c)return new Promise((f,p)=>{d.addEventListener("load",f),d.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${h}`)))})}))}function n(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return r.then(o=>{for(const a of o||[])a.status==="rejected"&&n(a.reason);return e().catch(n)})};var S=(i=>(i.Application="application",i.WebGLPipes="webgl-pipes",i.WebGLPipesAdaptor="webgl-pipes-adaptor",i.WebGLSystem="webgl-system",i.WebGLLoader="webgl-loader",i.WebGPUPipes="webgpu-pipes",i.WebGPUPipesAdaptor="webgpu-pipes-adaptor",i.WebGPUSystem="webgpu-system",i.WebGPULoader="webgpu-loader",i.CanvasSystem="canvas-system",i.CanvasPipesAdaptor="canvas-pipes-adaptor",i.CanvasPipes="canvas-pipes",i.CanvasLoader="canvas-loader",i.Asset="asset",i.LoadParser="load-parser",i.ResolveParser="resolve-parser",i.CacheParser="cache-parser",i.DetectionParser="detection-parser",i.MaskEffect="mask-effect",i.BlendMode="blend-mode",i.TextureSource="texture-source",i.TextureUploaderWebGL="texture-uploader-webgl",i.TextureUploaderWebGPU="texture-uploader-webgpu",i.Environment="environment",i.ShapeBuilder="shape-builder",i.Batcher="batcher",i))(S||{});const Ln=i=>{if(typeof i=="function"||typeof i=="object"&&i.extension){if(!i.extension)throw new Error("Extension class must have an extension object");i={...typeof i.extension!="object"?{type:i.extension}:i.extension,ref:i}}if(typeof i=="object")i={...i};else throw new Error("Invalid extension type");return typeof i.type=="string"&&(i.type=[i.type]),i},Ks=(i,e)=>Ln(i).priority??e,q={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...i){return i.map(Ln).forEach(e=>{e.type.forEach(t=>this._removeHandlers[t]?.(e))}),this},add(...i){return i.map(Ln).forEach(e=>{e.type.forEach(t=>{const s=this._addHandlers,r=this._queue;s[t]?s[t]?.(e):(r[t]=r[t]||[],r[t]?.push(e))})}),this},handle(i,e,t){const s=this._addHandlers,r=this._removeHandlers;if(s[i]||r[i])throw new Error(`Extension type ${i} already has a handler`);s[i]=e,r[i]=t;const n=this._queue;return n[i]&&(n[i]?.forEach(o=>e(o)),delete n[i]),this},handleByMap(i,e){return this.handle(i,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(i,e,t=-1){return this.handle(i,s=>{e.findIndex(n=>n.name===s.name)>=0||(e.push({name:s.name,value:s.ref}),e.sort((n,o)=>Ks(o.value,t)-Ks(n.value,t)))},s=>{const r=e.findIndex(n=>n.name===s.name);r!==-1&&e.splice(r,1)})},handleByList(i,e,t=-1){return this.handle(i,s=>{e.includes(s.ref)||(e.push(s.ref),e.sort((r,n)=>Ks(n,t)-Ks(r,t)))},s=>{const r=e.indexOf(s.ref);r!==-1&&e.splice(r,1)})},mixin(i,...e){for(const t of e)Object.defineProperties(i.prototype,Object.getOwnPropertyDescriptors(t))}},gu={extension:{type:S.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await St(()=>import("./browserAll-DpEOVFXE.js"),__vite__mapDeps([0,1]))}},_u={extension:{type:S.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await St(()=>import("./webworkerAll-BIhfsOqG.js"),[])}};class Ce{constructor(e,t,s){this._x=t||0,this._y=s||0,this._observer=e}clone(e){return new Ce(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}function Lg(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Qr={exports:{}},xh;function Ug(){return xh||(xh=1,(function(i){var e=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function r(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function n(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new r(c,u||l,d),p=t?t+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new s:delete l._events[h]}function a(){this._events=new s,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)e.call(c,u)&&h.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=t?t+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},a.prototype.listenerCount=function(h){var c=t?t+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,f,p){var g=t?t+h:h;if(!this._events[g])return!1;var m=this._events[g],_=arguments.length,y,x;if(m.fn){switch(m.once&&this.removeListener(h,m.fn,void 0,!0),_){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,u),!0;case 4:return m.fn.call(m.context,c,u,d),!0;case 5:return m.fn.call(m.context,c,u,d,f),!0;case 6:return m.fn.call(m.context,c,u,d,f,p),!0}for(x=1,y=new Array(_-1);x<_;x++)y[x-1]=arguments[x];m.fn.apply(m.context,y)}else{var b=m.length,v;for(x=0;x<b;x++)switch(m[x].once&&this.removeListener(h,m[x].fn,void 0,!0),_){case 1:m[x].fn.call(m[x].context);break;case 2:m[x].fn.call(m[x].context,c);break;case 3:m[x].fn.call(m[x].context,c,u);break;case 4:m[x].fn.call(m[x].context,c,u,d);break;default:if(!y)for(v=1,y=new Array(_-1);v<_;v++)y[v-1]=arguments[v];m[x].fn.apply(m[x].context,y)}}return!0},a.prototype.on=function(h,c,u){return n(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return n(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var f=t?t+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var g=0,m=[],_=p.length;g<_;g++)(p[g].fn!==c||d&&!p[g].once||u&&p[g].context!==u)&&m.push(p[g]);m.length?this._events[f]=m.length===1?m[0]:m:o(this,f)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=t?t+h:h,this._events[c]&&o(this,c)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,i.exports=a})(Qr)),Qr.exports}var Ng=Ug();const Re=Lg(Ng),yu=Math.PI*2,xu=180/Math.PI,bu=Math.PI/180;class he{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new he(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,t=e){return this.x=e,this.y=t,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return Jr.x=0,Jr.y=0,Jr}}const Jr=new he;class U{constructor(e=1,t=0,s=0,r=1,n=0,o=0){this.array=null,this.a=e,this.b=t,this.c=s,this.d=r,this.tx=n,this.ty=o}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,t,s,r,n,o){return this.a=e,this.b=t,this.c=s,this.d=r,this.tx=n,this.ty=o,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const s=t||this.array;return e?(s[0]=this.a,s[1]=this.b,s[2]=0,s[3]=this.c,s[4]=this.d,s[5]=0,s[6]=this.tx,s[7]=this.ty,s[8]=1):(s[0]=this.a,s[1]=this.c,s[2]=this.tx,s[3]=this.b,s[4]=this.d,s[5]=this.ty,s[6]=0,s[7]=0,s[8]=1),s}apply(e,t){t=t||new he;const s=e.x,r=e.y;return t.x=this.a*s+this.c*r+this.tx,t.y=this.b*s+this.d*r+this.ty,t}applyInverse(e,t){t=t||new he;const s=this.a,r=this.b,n=this.c,o=this.d,a=this.tx,l=this.ty,h=1/(s*o+n*-r),c=e.x,u=e.y;return t.x=o*h*c+-n*h*u+(l*n-a*o)*h,t.y=s*h*u+-r*h*c+(-l*s+a*r)*h,t}translate(e,t){return this.tx+=e,this.ty+=t,this}scale(e,t){return this.a*=e,this.d*=t,this.c*=e,this.b*=t,this.tx*=e,this.ty*=t,this}rotate(e){const t=Math.cos(e),s=Math.sin(e),r=this.a,n=this.c,o=this.tx;return this.a=r*t-this.b*s,this.b=r*s+this.b*t,this.c=n*t-this.d*s,this.d=n*s+this.d*t,this.tx=o*t-this.ty*s,this.ty=o*s+this.ty*t,this}append(e){const t=this.a,s=this.b,r=this.c,n=this.d;return this.a=e.a*t+e.b*r,this.b=e.a*s+e.b*n,this.c=e.c*t+e.d*r,this.d=e.c*s+e.d*n,this.tx=e.tx*t+e.ty*r+this.tx,this.ty=e.tx*s+e.ty*n+this.ty,this}appendFrom(e,t){const s=e.a,r=e.b,n=e.c,o=e.d,a=e.tx,l=e.ty,h=t.a,c=t.b,u=t.c,d=t.d;return this.a=s*h+r*u,this.b=s*c+r*d,this.c=n*h+o*u,this.d=n*c+o*d,this.tx=a*h+l*u+t.tx,this.ty=a*c+l*d+t.ty,this}setTransform(e,t,s,r,n,o,a,l,h){return this.a=Math.cos(a+h)*n,this.b=Math.sin(a+h)*n,this.c=-Math.sin(a-l)*o,this.d=Math.cos(a-l)*o,this.tx=e-(s*this.a+r*this.c),this.ty=t-(s*this.b+r*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const s=this.a,r=this.c;this.a=s*e.a+this.b*e.c,this.b=s*e.b+this.b*e.d,this.c=r*e.a+this.d*e.c,this.d=r*e.b+this.d*e.d}return this.tx=t*e.a+this.ty*e.c+e.tx,this.ty=t*e.b+this.ty*e.d+e.ty,this}decompose(e){const t=this.a,s=this.b,r=this.c,n=this.d,o=e.pivot,a=-Math.atan2(-r,n),l=Math.atan2(s,t),h=Math.abs(a+l);let c=Math.sqrt(t*t+s*s);return h<1e-5||Math.abs(yu-h)<1e-5?(e.rotation=l,e.skew.x=e.skew.y=0):Math.abs(Math.PI-h)<1e-5?(e.rotation=l-Math.PI,e.skew.x=e.skew.y=0,c=-c):(e.rotation=0,e.skew.x=a,e.skew.y=l),e.scale.x=c,e.scale.y=Math.sqrt(r*r+n*n),e.position.x=this.tx+(o.x*t+o.y*r),e.position.y=this.ty+(o.x*s+o.y*n),e}invert(){const e=this.a,t=this.b,s=this.c,r=this.d,n=this.tx,o=e*r-t*s;return this.a=r/o,this.b=-t/o,this.c=-s/o,this.d=e/o,this.tx=(s*this.ty-r*n)/o,this.ty=-(e*this.ty-t*n)/o,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const e=new U;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}equals(e){return e.a===this.a&&e.b===this.b&&e.c===this.c&&e.d===this.d&&e.tx===this.tx&&e.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return zg.identity()}static get shared(){return Hg.identity()}}const Hg=new U,zg=new U,Ht=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],zt=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Wt=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],$t=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Un=[],vu=[],Ci=Math.sign;function Wg(){for(let i=0;i<16;i++){const e=[];Un.push(e);for(let t=0;t<16;t++){const s=Ci(Ht[i]*Ht[t]+Wt[i]*zt[t]),r=Ci(zt[i]*Ht[t]+$t[i]*zt[t]),n=Ci(Ht[i]*Wt[t]+Wt[i]*$t[t]),o=Ci(zt[i]*Wt[t]+$t[i]*$t[t]);for(let a=0;a<16;a++)if(Ht[a]===s&&zt[a]===r&&Wt[a]===n&&$t[a]===o){e.push(a);break}}}for(let i=0;i<16;i++){const e=new U;e.set(Ht[i],zt[i],Wt[i],$t[i],0,0),vu.push(e)}}Wg();const Z={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:i=>Ht[i],uY:i=>zt[i],vX:i=>Wt[i],vY:i=>$t[i],inv:i=>i&8?i&15:-i&7,add:(i,e)=>Un[i][e],sub:(i,e)=>Un[i][Z.inv(e)],rotate180:i=>i^4,isVertical:i=>(i&3)===2,byDirection:(i,e)=>Math.abs(i)*2<=Math.abs(e)?e>=0?Z.S:Z.N:Math.abs(e)*2<=Math.abs(i)?i>0?Z.E:Z.W:e>0?i>0?Z.SE:Z.SW:i>0?Z.NE:Z.NW,matrixAppendRotationInv:(i,e,t=0,s=0,r=0,n=0)=>{const o=vu[Z.inv(e)],a=o.a,l=o.b,h=o.c,c=o.d,u=t-Math.min(0,a*r,h*n,a*r+h*n),d=s-Math.min(0,l*r,c*n,l*r+c*n),f=i.a,p=i.b,g=i.c,m=i.d;i.a=a*f+l*g,i.b=a*p+l*m,i.c=h*f+c*g,i.d=h*p+c*m,i.tx=u*f+d*g+i.tx,i.ty=u*p+d*m+i.ty},transformRectCoords:(i,e,t,s)=>{const{x:r,y:n,width:o,height:a}=i,{x:l,y:h,width:c,height:u}=e;return t===Z.E?(s.set(r+l,n+h,o,a),s):t===Z.S?s.set(c-n-a+l,r+h,a,o):t===Z.W?s.set(c-r-o+l,u-n-a+h,o,a):t===Z.N?s.set(n+l,u-r-o+h,a,o):s.set(r+l,n+h,o,a)}},Mi=[new he,new he,new he,new he];class te{constructor(e=0,t=0,s=0,r=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),this.width=Number(s),this.height=Number(r)}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 te(0,0,0,0)}clone(){return new te(this.x,this.y,this.width,this.height)}copyFromBounds(e){return this.x=e.minX,this.y=e.minY,this.width=e.maxX-e.minX,this.height=e.maxY-e.minY,this}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){return this.width<=0||this.height<=0?!1:e>=this.x&&e<this.x+this.width&&t>=this.y&&t<this.y+this.height}strokeContains(e,t,s,r=.5){const{width:n,height:o}=this;if(n<=0||o<=0)return!1;const a=this.x,l=this.y,h=s*(1-r),c=s-h,u=a-h,d=a+n+h,f=l-h,p=l+o+h,g=a+c,m=a+n-c,_=l+c,y=l+o-c;return e>=u&&e<=d&&t>=f&&t<=p&&!(e>g&&e<m&&t>_&&t<y)}intersects(e,t){if(!t){const k=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=k)return!1;const A=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>A}const s=this.left,r=this.right,n=this.top,o=this.bottom;if(r<=s||o<=n)return!1;const a=Mi[0].set(e.left,e.top),l=Mi[1].set(e.left,e.bottom),h=Mi[2].set(e.right,e.top),c=Mi[3].set(e.right,e.bottom);if(h.x<=a.x||l.y<=a.y)return!1;const u=Math.sign(t.a*t.d-t.b*t.c);if(u===0||(t.apply(a,a),t.apply(l,l),t.apply(h,h),t.apply(c,c),Math.max(a.x,l.x,h.x,c.x)<=s||Math.min(a.x,l.x,h.x,c.x)>=r||Math.max(a.y,l.y,h.y,c.y)<=n||Math.min(a.y,l.y,h.y,c.y)>=o))return!1;const d=u*(l.y-a.y),f=u*(a.x-l.x),p=d*s+f*n,g=d*r+f*n,m=d*s+f*o,_=d*r+f*o;if(Math.max(p,g,m,_)<=d*a.x+f*a.y||Math.min(p,g,m,_)>=d*c.x+f*c.y)return!1;const y=u*(a.y-h.y),x=u*(h.x-a.x),b=y*s+x*n,v=y*r+x*n,w=y*s+x*o,T=y*r+x*o;return!(Math.max(b,v,w,T)<=y*a.x+x*a.y||Math.min(b,v,w,T)>=y*c.x+x*c.y)}pad(e=0,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}fit(e){const t=Math.max(this.x,e.x),s=Math.min(this.x+this.width,e.x+e.width),r=Math.max(this.y,e.y),n=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(s-t,0),this.y=r,this.height=Math.max(n-r,0),this}ceil(e=1,t=.001){const s=Math.ceil((this.x+this.width-t)*e)/e,r=Math.ceil((this.y+this.height-t)*e)/e;return this.x=Math.floor((this.x+t)*e)/e,this.y=Math.floor((this.y+t)*e)/e,this.width=s-this.x,this.height=r-this.y,this}scale(e,t=e){return this.x*=e,this.y*=t,this.width*=e,this.height*=t,this}enlarge(e){const t=Math.min(this.x,e.x),s=Math.max(this.x+this.width,e.x+e.width),r=Math.min(this.y,e.y),n=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=s-t,this.y=r,this.height=n-r,this}getBounds(e){return e||(e=new te),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,s=e.y,r=e.x+e.width,n=e.y+e.height;return t>=this.x&&t<this.x+this.width&&s>=this.y&&s<this.y+this.height&&r>=this.x&&r<=this.x+this.width&&n>=this.y&&n<=this.y+this.height}set(e,t,s,r){return this.x=e,this.y=t,this.width=s,this.height=r,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const en={default:-1};function oe(i="default"){return en[i]===void 0&&(en[i]=-1),++en[i]}const bh=new Set,ue="8.0.0",wu="8.3.4",ht="8.21.0",Tu="8.22.0",vs={quiet:!1,noColor:!1},H=((i,e,t=3)=>{if(vs.quiet||bh.has(e))return;let s=new Error().stack;const r=`${e}
3
- Deprecated since v${i}`,n=typeof console.groupCollapsed=="function"&&!vs.noColor;typeof s>"u"?console.warn("PixiJS Deprecation Warning: ",r):(s=s.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/browserAll-KVarB43M.js","assets/webworkerAll-DDiRRkEz.js"])))=>i.map(i=>d[i]);
2
+ (function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const n of r)if(n.type==="childList")for(const o of n.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function t(r){const n={};return r.integrity&&(n.integrity=r.integrity),r.referrerPolicy&&(n.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?n.credentials="include":r.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function s(r){if(r.ep)return;r.ep=!0;const n=t(r);fetch(r.href,n)}})();const Hg="modulepreload",Wg=function(i){return"/"+i},bh={},kt=function(e,t,s){let r=Promise.resolve();if(t&&t.length>0){let o=function(h){return Promise.all(h.map(c=>Promise.resolve(c).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};document.getElementsByTagName("link");const a=document.querySelector("meta[property=csp-nonce]"),l=a?.nonce||a?.getAttribute("nonce");r=o(t.map(h=>{if(h=Wg(h),h in bh)return;bh[h]=!0;const c=h.endsWith(".css"),u=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${u}`))return;const d=document.createElement("link");if(d.rel=c?"stylesheet":Hg,c||(d.as="script"),d.crossOrigin="",d.href=h,l&&d.setAttribute("nonce",l),document.head.appendChild(d),c)return new Promise((f,p)=>{d.addEventListener("load",f),d.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${h}`)))})}))}function n(o){const a=new Event("vite:preloadError",{cancelable:!0});if(a.payload=o,window.dispatchEvent(a),!a.defaultPrevented)throw o}return r.then(o=>{for(const a of o||[])a.status==="rejected"&&n(a.reason);return e().catch(n)})};var S=(i=>(i.Application="application",i.WebGLPipes="webgl-pipes",i.WebGLPipesAdaptor="webgl-pipes-adaptor",i.WebGLSystem="webgl-system",i.WebGLLoader="webgl-loader",i.WebGPUPipes="webgpu-pipes",i.WebGPUPipesAdaptor="webgpu-pipes-adaptor",i.WebGPUSystem="webgpu-system",i.WebGPULoader="webgpu-loader",i.CanvasSystem="canvas-system",i.CanvasPipesAdaptor="canvas-pipes-adaptor",i.CanvasPipes="canvas-pipes",i.CanvasLoader="canvas-loader",i.Asset="asset",i.LoadParser="load-parser",i.ResolveParser="resolve-parser",i.CacheParser="cache-parser",i.DetectionParser="detection-parser",i.MaskEffect="mask-effect",i.BlendMode="blend-mode",i.TextureSource="texture-source",i.TextureUploaderWebGL="texture-uploader-webgl",i.TextureUploaderWebGPU="texture-uploader-webgpu",i.Environment="environment",i.ShapeBuilder="shape-builder",i.Batcher="batcher",i))(S||{});const Vn=i=>{if(typeof i=="function"||typeof i=="object"&&i.extension){if(!i.extension)throw new Error("Extension class must have an extension object");i={...typeof i.extension!="object"?{type:i.extension}:i.extension,ref:i}}if(typeof i=="object")i={...i};else throw new Error("Invalid extension type");return typeof i.type=="string"&&(i.type=[i.type]),i},Qs=(i,e)=>Vn(i).priority??e,q={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...i){return i.map(Vn).forEach(e=>{e.type.forEach(t=>this._removeHandlers[t]?.(e))}),this},add(...i){return i.map(Vn).forEach(e=>{e.type.forEach(t=>{const s=this._addHandlers,r=this._queue;s[t]?s[t]?.(e):(r[t]=r[t]||[],r[t]?.push(e))})}),this},handle(i,e,t){const s=this._addHandlers,r=this._removeHandlers;if(s[i]||r[i])throw new Error(`Extension type ${i} already has a handler`);s[i]=e,r[i]=t;const n=this._queue;return n[i]&&(n[i]?.forEach(o=>e(o)),delete n[i]),this},handleByMap(i,e){return this.handle(i,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(i,e,t=-1){return this.handle(i,s=>{e.findIndex(n=>n.name===s.name)>=0||(e.push({name:s.name,value:s.ref}),e.sort((n,o)=>Qs(o.value,t)-Qs(n.value,t)))},s=>{const r=e.findIndex(n=>n.name===s.name);r!==-1&&e.splice(r,1)})},handleByList(i,e,t=-1){return this.handle(i,s=>{e.includes(s.ref)||(e.push(s.ref),e.sort((r,n)=>Qs(n,t)-Qs(r,t)))},s=>{const r=e.indexOf(s.ref);r!==-1&&e.splice(r,1)})},mixin(i,...e){for(const t of e)Object.defineProperties(i.prototype,Object.getOwnPropertyDescriptors(t))}},bu={extension:{type:S.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await kt(()=>import("./browserAll-KVarB43M.js"),__vite__mapDeps([0,1]))}},vu={extension:{type:S.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await kt(()=>import("./webworkerAll-DDiRRkEz.js"),[])}};class Ce{constructor(e,t,s){this._x=t||0,this._y=s||0,this._observer=e}clone(e){return new Ce(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}function $g(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var on={exports:{}},vh;function Vg(){return vh||(vh=1,(function(i){var e=Object.prototype.hasOwnProperty,t="~";function s(){}Object.create&&(s.prototype=Object.create(null),new s().__proto__||(t=!1));function r(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function n(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new r(c,u||l,d),p=t?t+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new s:delete l._events[h]}function a(){this._events=new s,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)e.call(c,u)&&h.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=t?t+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},a.prototype.listenerCount=function(h){var c=t?t+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,f,p){var g=t?t+h:h;if(!this._events[g])return!1;var m=this._events[g],_=arguments.length,y,x;if(m.fn){switch(m.once&&this.removeListener(h,m.fn,void 0,!0),_){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,u),!0;case 4:return m.fn.call(m.context,c,u,d),!0;case 5:return m.fn.call(m.context,c,u,d,f),!0;case 6:return m.fn.call(m.context,c,u,d,f,p),!0}for(x=1,y=new Array(_-1);x<_;x++)y[x-1]=arguments[x];m.fn.apply(m.context,y)}else{var b=m.length,v;for(x=0;x<b;x++)switch(m[x].once&&this.removeListener(h,m[x].fn,void 0,!0),_){case 1:m[x].fn.call(m[x].context);break;case 2:m[x].fn.call(m[x].context,c);break;case 3:m[x].fn.call(m[x].context,c,u);break;case 4:m[x].fn.call(m[x].context,c,u,d);break;default:if(!y)for(v=1,y=new Array(_-1);v<_;v++)y[v-1]=arguments[v];m[x].fn.apply(m[x].context,y)}}return!0},a.prototype.on=function(h,c,u){return n(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return n(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var f=t?t+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var g=0,m=[],_=p.length;g<_;g++)(p[g].fn!==c||d&&!p[g].once||u&&p[g].context!==u)&&m.push(p[g]);m.length?this._events[f]=m.length===1?m[0]:m:o(this,f)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=t?t+h:h,this._events[c]&&o(this,c)):(this._events=new s,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,i.exports=a})(on)),on.exports}var jg=Vg();const Re=$g(jg),wu=Math.PI*2,Tu=180/Math.PI,Su=Math.PI/180;class ce{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new ce(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,t=e){return this.x=e,this.y=t,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return an.x=0,an.y=0,an}}const an=new ce;class U{constructor(e=1,t=0,s=0,r=1,n=0,o=0){this.array=null,this.a=e,this.b=t,this.c=s,this.d=r,this.tx=n,this.ty=o}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,t,s,r,n,o){return this.a=e,this.b=t,this.c=s,this.d=r,this.tx=n,this.ty=o,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const s=t||this.array;return e?(s[0]=this.a,s[1]=this.b,s[2]=0,s[3]=this.c,s[4]=this.d,s[5]=0,s[6]=this.tx,s[7]=this.ty,s[8]=1):(s[0]=this.a,s[1]=this.c,s[2]=this.tx,s[3]=this.b,s[4]=this.d,s[5]=this.ty,s[6]=0,s[7]=0,s[8]=1),s}apply(e,t){t=t||new ce;const s=e.x,r=e.y;return t.x=this.a*s+this.c*r+this.tx,t.y=this.b*s+this.d*r+this.ty,t}applyInverse(e,t){t=t||new ce;const s=this.a,r=this.b,n=this.c,o=this.d,a=this.tx,l=this.ty,h=1/(s*o+n*-r),c=e.x,u=e.y;return t.x=o*h*c+-n*h*u+(l*n-a*o)*h,t.y=s*h*u+-r*h*c+(-l*s+a*r)*h,t}translate(e,t){return this.tx+=e,this.ty+=t,this}scale(e,t){return this.a*=e,this.d*=t,this.c*=e,this.b*=t,this.tx*=e,this.ty*=t,this}rotate(e){const t=Math.cos(e),s=Math.sin(e),r=this.a,n=this.c,o=this.tx;return this.a=r*t-this.b*s,this.b=r*s+this.b*t,this.c=n*t-this.d*s,this.d=n*s+this.d*t,this.tx=o*t-this.ty*s,this.ty=o*s+this.ty*t,this}append(e){const t=this.a,s=this.b,r=this.c,n=this.d;return this.a=e.a*t+e.b*r,this.b=e.a*s+e.b*n,this.c=e.c*t+e.d*r,this.d=e.c*s+e.d*n,this.tx=e.tx*t+e.ty*r+this.tx,this.ty=e.tx*s+e.ty*n+this.ty,this}appendFrom(e,t){const s=e.a,r=e.b,n=e.c,o=e.d,a=e.tx,l=e.ty,h=t.a,c=t.b,u=t.c,d=t.d;return this.a=s*h+r*u,this.b=s*c+r*d,this.c=n*h+o*u,this.d=n*c+o*d,this.tx=a*h+l*u+t.tx,this.ty=a*c+l*d+t.ty,this}setTransform(e,t,s,r,n,o,a,l,h){return this.a=Math.cos(a+h)*n,this.b=Math.sin(a+h)*n,this.c=-Math.sin(a-l)*o,this.d=Math.cos(a-l)*o,this.tx=e-(s*this.a+r*this.c),this.ty=t-(s*this.b+r*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const s=this.a,r=this.c;this.a=s*e.a+this.b*e.c,this.b=s*e.b+this.b*e.d,this.c=r*e.a+this.d*e.c,this.d=r*e.b+this.d*e.d}return this.tx=t*e.a+this.ty*e.c+e.tx,this.ty=t*e.b+this.ty*e.d+e.ty,this}decompose(e){const t=this.a,s=this.b,r=this.c,n=this.d,o=e.pivot,a=-Math.atan2(-r,n),l=Math.atan2(s,t),h=Math.abs(a+l);let c=Math.sqrt(t*t+s*s);return h<1e-5||Math.abs(wu-h)<1e-5?(e.rotation=l,e.skew.x=e.skew.y=0):Math.abs(Math.PI-h)<1e-5?(e.rotation=l-Math.PI,e.skew.x=e.skew.y=0,c=-c):(e.rotation=0,e.skew.x=a,e.skew.y=l),e.scale.x=c,e.scale.y=Math.sqrt(r*r+n*n),e.position.x=this.tx+(o.x*t+o.y*r),e.position.y=this.ty+(o.x*s+o.y*n),e}invert(){const e=this.a,t=this.b,s=this.c,r=this.d,n=this.tx,o=e*r-t*s;return this.a=r/o,this.b=-t/o,this.c=-s/o,this.d=e/o,this.tx=(s*this.ty-r*n)/o,this.ty=-(e*this.ty-t*n)/o,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const e=new U;return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}equals(e){return e.a===this.a&&e.b===this.b&&e.c===this.c&&e.d===this.d&&e.tx===this.tx&&e.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return qg.identity()}static get shared(){return Xg.identity()}}const Xg=new U,qg=new U,Wt=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],$t=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Vt=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],jt=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],jn=[],Cu=[],Ei=Math.sign;function Yg(){for(let i=0;i<16;i++){const e=[];jn.push(e);for(let t=0;t<16;t++){const s=Ei(Wt[i]*Wt[t]+Vt[i]*$t[t]),r=Ei($t[i]*Wt[t]+jt[i]*$t[t]),n=Ei(Wt[i]*Vt[t]+Vt[i]*jt[t]),o=Ei($t[i]*Vt[t]+jt[i]*jt[t]);for(let a=0;a<16;a++)if(Wt[a]===s&&$t[a]===r&&Vt[a]===n&&jt[a]===o){e.push(a);break}}}for(let i=0;i<16;i++){const e=new U;e.set(Wt[i],$t[i],Vt[i],jt[i],0,0),Cu.push(e)}}Yg();const Z={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:i=>Wt[i],uY:i=>$t[i],vX:i=>Vt[i],vY:i=>jt[i],inv:i=>i&8?i&15:-i&7,add:(i,e)=>jn[i][e],sub:(i,e)=>jn[i][Z.inv(e)],rotate180:i=>i^4,isVertical:i=>(i&3)===2,byDirection:(i,e)=>Math.abs(i)*2<=Math.abs(e)?e>=0?Z.S:Z.N:Math.abs(e)*2<=Math.abs(i)?i>0?Z.E:Z.W:e>0?i>0?Z.SE:Z.SW:i>0?Z.NE:Z.NW,matrixAppendRotationInv:(i,e,t=0,s=0,r=0,n=0)=>{const o=Cu[Z.inv(e)],a=o.a,l=o.b,h=o.c,c=o.d,u=t-Math.min(0,a*r,h*n,a*r+h*n),d=s-Math.min(0,l*r,c*n,l*r+c*n),f=i.a,p=i.b,g=i.c,m=i.d;i.a=a*f+l*g,i.b=a*p+l*m,i.c=h*f+c*g,i.d=h*p+c*m,i.tx=u*f+d*g+i.tx,i.ty=u*p+d*m+i.ty},transformRectCoords:(i,e,t,s)=>{const{x:r,y:n,width:o,height:a}=i,{x:l,y:h,width:c,height:u}=e;return t===Z.E?(s.set(r+l,n+h,o,a),s):t===Z.S?s.set(c-n-a+l,r+h,a,o):t===Z.W?s.set(c-r-o+l,u-n-a+h,o,a):t===Z.N?s.set(n+l,u-r-o+h,a,o):s.set(r+l,n+h,o,a)}},Pi=[new ce,new ce,new ce,new ce];class te{constructor(e=0,t=0,s=0,r=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),this.width=Number(s),this.height=Number(r)}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 te(0,0,0,0)}clone(){return new te(this.x,this.y,this.width,this.height)}copyFromBounds(e){return this.x=e.minX,this.y=e.minY,this.width=e.maxX-e.minX,this.height=e.maxY-e.minY,this}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){return this.width<=0||this.height<=0?!1:e>=this.x&&e<this.x+this.width&&t>=this.y&&t<this.y+this.height}strokeContains(e,t,s,r=.5){const{width:n,height:o}=this;if(n<=0||o<=0)return!1;const a=this.x,l=this.y,h=s*(1-r),c=s-h,u=a-h,d=a+n+h,f=l-h,p=l+o+h,g=a+c,m=a+n-c,_=l+c,y=l+o-c;return e>=u&&e<=d&&t>=f&&t<=p&&!(e>g&&e<m&&t>_&&t<y)}intersects(e,t){if(!t){const k=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=k)return!1;const A=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>A}const s=this.left,r=this.right,n=this.top,o=this.bottom;if(r<=s||o<=n)return!1;const a=Pi[0].set(e.left,e.top),l=Pi[1].set(e.left,e.bottom),h=Pi[2].set(e.right,e.top),c=Pi[3].set(e.right,e.bottom);if(h.x<=a.x||l.y<=a.y)return!1;const u=Math.sign(t.a*t.d-t.b*t.c);if(u===0||(t.apply(a,a),t.apply(l,l),t.apply(h,h),t.apply(c,c),Math.max(a.x,l.x,h.x,c.x)<=s||Math.min(a.x,l.x,h.x,c.x)>=r||Math.max(a.y,l.y,h.y,c.y)<=n||Math.min(a.y,l.y,h.y,c.y)>=o))return!1;const d=u*(l.y-a.y),f=u*(a.x-l.x),p=d*s+f*n,g=d*r+f*n,m=d*s+f*o,_=d*r+f*o;if(Math.max(p,g,m,_)<=d*a.x+f*a.y||Math.min(p,g,m,_)>=d*c.x+f*c.y)return!1;const y=u*(a.y-h.y),x=u*(h.x-a.x),b=y*s+x*n,v=y*r+x*n,w=y*s+x*o,T=y*r+x*o;return!(Math.max(b,v,w,T)<=y*a.x+x*a.y||Math.min(b,v,w,T)>=y*c.x+x*c.y)}pad(e=0,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}fit(e){const t=Math.max(this.x,e.x),s=Math.min(this.x+this.width,e.x+e.width),r=Math.max(this.y,e.y),n=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(s-t,0),this.y=r,this.height=Math.max(n-r,0),this}ceil(e=1,t=.001){const s=Math.ceil((this.x+this.width-t)*e)/e,r=Math.ceil((this.y+this.height-t)*e)/e;return this.x=Math.floor((this.x+t)*e)/e,this.y=Math.floor((this.y+t)*e)/e,this.width=s-this.x,this.height=r-this.y,this}scale(e,t=e){return this.x*=e,this.y*=t,this.width*=e,this.height*=t,this}enlarge(e){const t=Math.min(this.x,e.x),s=Math.max(this.x+this.width,e.x+e.width),r=Math.min(this.y,e.y),n=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=s-t,this.y=r,this.height=n-r,this}getBounds(e){return e||(e=new te),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,s=e.y,r=e.x+e.width,n=e.y+e.height;return t>=this.x&&t<this.x+this.width&&s>=this.y&&s<this.y+this.height&&r>=this.x&&r<=this.x+this.width&&n>=this.y&&n<=this.y+this.height}set(e,t,s,r){return this.x=e,this.y=t,this.width=s,this.height=r,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const ln={default:-1};function oe(i="default"){return ln[i]===void 0&&(ln[i]=-1),++ln[i]}const wh=new Set,de="8.0.0",Mu="8.3.4",ut="8.21.0",ku="8.22.0",Cs={quiet:!1,noColor:!1},z=((i,e,t=3)=>{if(Cs.quiet||wh.has(e))return;let s=new Error().stack;const r=`${e}
3
+ Deprecated since v${i}`,n=typeof console.groupCollapsed=="function"&&!Cs.noColor;typeof s>"u"?console.warn("PixiJS Deprecation Warning: ",r):(s=s.split(`
4
4
  `).splice(t).join(`
5
- `),n?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",r),console.warn(s),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",r),console.warn(s))),bh.add(e)});Object.defineProperties(H,{quiet:{get:()=>vs.quiet,set:i=>{vs.quiet=i},enumerable:!0,configurable:!1},noColor:{get:()=>vs.noColor,set:i=>{vs.noColor=i},enumerable:!0,configurable:!1}});const Oo=()=>{};function ir(i){return i.endsWith("int")}function es(i){return i+=i===0?1:0,--i,i|=i>>>1,i|=i>>>2,i|=i>>>4,i|=i>>>8,i|=i>>>16,i+1}function ts(i){return!(i&i-1)&&!!i}function Lo(i){const e={};for(const t in i)i[t]!==void 0&&(e[t]=i[t]);return e}const vh=Object.create(null);function $g(i){const e=vh[i];return e===void 0&&(vh[i]=oe("resource")),e}const Su=class Cu extends Re{constructor(e={}){super(),this._resourceType="textureSampler",this._maxAnisotropy=1,this.destroyed=!1,e={...Cu.defaultOptions,...e},this.addressMode=e.addressMode,this.addressModeU=e.addressModeU??this.addressModeU,this.addressModeV=e.addressModeV??this.addressModeV,this.addressModeW=e.addressModeW??this.addressModeW,this.scaleMode=e.scaleMode,this.magFilter=e.magFilter??this.magFilter,this.minFilter=e.minFilter??this.minFilter,this.mipmapFilter=e.mipmapFilter??this.mipmapFilter,this.lodMinClamp=e.lodMinClamp,this.lodMaxClamp=e.lodMaxClamp,this.compare=e.compare,this.maxAnisotropy=e.maxAnisotropy??1}set addressMode(e){this.addressModeU=e,this.addressModeV=e,this.addressModeW=e}get addressMode(){return this.addressModeU}set wrapMode(e){H(ue,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this._sharedResourceId=null,this.emit("change",this)}_generateResourceId(){const e=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=$g(e),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};Su.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let Dt=Su;const Mu=class ku extends Re{constructor(e={}){super(),this.options=e,this._gpuData=Object.create(null),this._gcLastUsed=-1,this.uid=oe("textureSource"),this._resourceType="textureSource",this._resourceId=oe("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.depth=1,this._ownsStyle=!1,this.antialias=!1,this.transient=!1,this.storage=!1,this._batchTick=-1,this._textureBindLocation=-1;const t=e;e={...ku.defaultOptions,...e};const s=Vg(e),r=s==="3d"||s==="1d"?s:"2d";jg(t,s,r),this.label=e.label??"",this.resource=e.resource,this.autoGarbageCollect=e.autoGarbageCollect,this._resolution=e.resolution,e.width?this.pixelWidth=e.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,e.height?this.pixelHeight=e.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=e.format,this.dimension=r,this.viewDimension=s,this.arrayLayerCount=e.arrayLayerCount,this.depth=r==="3d"?e.depth??1:1,this.mipLevelCount=e.mipLevelCount,this.autoGenerateMipmaps=e.autoGenerateMipmaps,this.sampleCount=e.sampleCount,this.antialias=r==="3d"?!1:e.antialias,this.transient=e.transient??!1,this.storage=e.storage??!1,this.alphaMode=e.alphaMode,this.style=new Dt(Lo(e)),this._ownsStyle=!0,this.destroyed=!1,this._refreshPOT()}get depthOrArrayLayers(){return this.dimension==="3d"?this.depth:this.arrayLayerCount||1}get source(){return this}get style(){return this._style}set style(e){this.style!==e&&(this._ownsStyle=!1,this._style?.off("change",this._onStyleChange,this),this._style=e,this._style?.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(e){this._style.maxAnisotropy=e}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(e){this._style.addressMode=e}get repeatMode(){return this._style.addressMode}set repeatMode(e){this._style.addressMode=e}get magFilter(){return this._style.magFilter}set magFilter(e){this._style.magFilter=e}get minFilter(){return this._style.minFilter}set minFilter(e){this._style.minFilter=e}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(e){this._style.mipmapFilter=e}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(e){this._style.lodMinClamp=e}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(e){this._style.lodMaxClamp=e}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const e=this._resolution;if(this.resize(this.resourceWidth/e,this.resourceHeight/e))return}this.emit("update",this)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this._style&&(this._ownsStyle&&this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=oe("resource"),this.emit("change",this),this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy?.();this._gpuData=Object.create(null)}get resourceWidth(){const{resource:e}=this;return e.naturalWidth||e.videoWidth||e.displayWidth||e.width}get resourceHeight(){const{resource:e}=this;return e.naturalHeight||e.videoHeight||e.displayHeight||e.height}get resolution(){return this._resolution}set resolution(e){this._resolution!==e&&(this._resolution=e,this.width=this.pixelWidth/e,this.height=this.pixelHeight/e)}resize(e,t,s){s||(s=this._resolution),e||(e=this.width),t||(t=this.height);const r=Math.round(e*s),n=Math.round(t*s);return this.width=r/s,this.height=n/s,this._resolution=s,this.pixelWidth===r&&this.pixelHeight===n?!1:(this._refreshPOT(),this.pixelWidth=r,this.pixelHeight=n,this.emit("resize",this),this._resourceId=oe("resource"),this.emit("change",this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit("updateMipmaps",this)}set wrapMode(e){this._style.wrapMode=e}get wrapMode(){return this._style.wrapMode}set scaleMode(e){this._style.scaleMode=e}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=ts(this.pixelWidth)&&ts(this.pixelHeight)}static test(e){throw new Error("Unimplemented")}};Mu.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",arrayLayerCount:1,mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let de=Mu;function Vg(i){return i.viewDimension?i.viewDimension:i.depth?"3d":i.arrayLayerCount>1?"2d-array":"2d"}function jg(i,e,t){if(i.depth!==void 0&&typeof i.depth!="number")throw new Error(`[TextureSource] depth is a 3D texture's depth in texels, but got ${i.depth}. For a depth buffer, use the depth option of a RenderTarget or the renderer.`);if(i.depth&&i.arrayLayerCount>1)throw new Error("[TextureSource] depth and arrayLayerCount can't be combined: use depth for a 3D texture or arrayLayerCount for a 2D array.");if(i.depth&&e!=="3d")throw new Error(`[TextureSource] depth makes a 3D texture, but viewDimension is '${e}'. Use arrayLayerCount for layered textures.`);if(e==="3d"&&i.arrayLayerCount>1)throw new Error("[TextureSource] a 3D texture takes depth, not arrayLayerCount.");if(i.dimensions&&i.dimensions!==t)throw new Error(`[TextureSource] dimensions '${i.dimensions}' doesn't match viewDimension '${e}'. Leave dimensions out; it is derived from the view.`);if(i.dimensions&&H(Tu,"TextureSource dimensions is derived from viewDimension and depth; leave it out."),t==="3d"&&i.antialias)throw new Error("[TextureSource] a 3D texture can't be antialiased: WebGPU has no multisampled 3D textures.")}class gr extends de{constructor(e){const t=e.depth??e.arrayLayerCount??1,s=e.resource||new Float32Array(e.width*e.height*t*4);let r=e.format;r||(s instanceof Float32Array?r="rgba32float":s instanceof Int32Array||s instanceof Uint32Array?r="rgba32uint":s instanceof Int16Array||s instanceof Uint16Array?r="rgba16uint":(s instanceof Int8Array,r="bgra8unorm"));const n=ir(r)||t>1;super({...n&&{alphaMode:"no-premultiply-alpha"},...e,resource:s,format:r}),this.uploadMethodId="buffer",this._updateStart=0,this._updateEnd=1/0}update(e=0,t=1/0){if((e>0||t<1/0)&&this.depthOrArrayLayers>1)throw new Error("[BufferImageSource] a 3D texture or 2D array uploads whole: call update() with no range.");this._updateStart=e,this._updateEnd=t,super.update(),this._updateStart=0,this._updateEnd=1/0}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}gr.extension=S.TextureSource;const wh=new U;class Uo{constructor(e,t){this.mapCoord=new U,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._updateID=0,this.clampOffset=0,typeof t>"u"?this.clampMargin=e.width<10?0:.5:this.clampMargin=t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture?.removeListener("update",this.update,this),this._texture=e,this._texture.addListener("update",this.update,this)),this.update()}destroy(){this._texture?.removeListener("update",this.update,this),this._texture=null}multiplyUvs(e,t){t===void 0&&(t=e);const s=this.mapCoord;for(let r=0;r<e.length;r+=2){const n=e[r],o=e[r+1];t[r]=n*s.a+o*s.c+s.tx,t[r+1]=n*s.b+o*s.d+s.ty}return t}update(){const e=this._texture;this._updateID++;const t=e.uvs;this.mapCoord.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0);const s=e.orig,r=e.trim;r&&(wh.set(s.width/r.width,0,0,s.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(wh));const n=e.source,o=this.uClampFrame,a=this.clampMargin/n._resolution,l=this.clampOffset/n._resolution;return o[0]=(e.frame.x+a+l)/n.width,o[1]=(e.frame.y+a+l)/n.height,o[2]=(e.frame.x+e.frame.width-a+l)/n.width,o[3]=(e.frame.y+e.frame.height-a+l)/n.height,this.uClampOffset[0]=this.clampOffset/n.pixelWidth,this.uClampOffset[1]=this.clampOffset/n.pixelHeight,this.isSimple=e.frame.width===n.width&&e.frame.height===n.height&&e.rotate===0,!0}}class W extends Re{constructor({source:e,label:t,frame:s,orig:r,trim:n,defaultAnchor:o,defaultBorders:a,rotate:l,dynamic:h}={}){if(super(),this.uid=oe("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new te,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=e?.source??new de,this.noFrame=!s,s)this.frame.copyFrom(s);else{const{width:c,height:u}=this._source;this.frame.width=c,this.frame.height=u}this.orig=r||this.frame,this.trim=n,this.rotate=l??0,this.defaultAnchor=o,this.defaultBorders=a,this.destroyed=!1,this.dynamic=h||!1,this.updateUvs()}set source(e){this._source&&this._source.off("resize",this.update,this),this._source=e,e.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new Uo(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:e,frame:t}=this,{width:s,height:r}=this._source,n=t.x/s,o=t.y/r,a=t.width/s,l=t.height/r;let h=this.rotate;if(h){const c=a/2,u=l/2,d=n+c,f=o+u;h=Z.add(h,Z.NW),e.x0=d+c*Z.uX(h),e.y0=f+u*Z.uY(h),h=Z.add(h,2),e.x1=d+c*Z.uX(h),e.y1=f+u*Z.uY(h),h=Z.add(h,2),e.x2=d+c*Z.uX(h),e.y2=f+u*Z.uY(h),h=Z.add(h,2),e.x3=d+c*Z.uX(h),e.y3=f+u*Z.uY(h)}else e.x0=n,e.y0=o,e.x1=n+a,e.y1=o,e.x2=n+a,e.y2=o+l,e.x3=n,e.y3=o+l}destroy(e=!1){this._source&&(this._source.off("resize",this.update,this),e&&(this._source.destroy(),this._source=null)),this._textureMatrix=null,this.destroyed=!0,this.emit("destroy",this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit("update",this)}get baseTexture(){return H(ue,"Texture.baseTexture is now Texture.source"),this._source}}W.EMPTY=new W({label:"EMPTY",source:new de({label:"EMPTY"})});W.EMPTY.destroy=Oo;W.WHITE=new W({source:new gr({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});W.WHITE.destroy=Oo;function No(i,e,t){const{width:s,height:r}=t.orig,n=t.trim;if(n){const o=n.width,a=n.height;i.minX=n.x-e._x*s,i.maxX=i.minX+o,i.minY=n.y-e._y*r,i.maxY=i.minY+a}else i.minX=-e._x*s,i.maxX=i.minX+s,i.minY=-e._y*r,i.maxY=i.minY+r}const Th=new U;class Ee{constructor(e=1/0,t=1/0,s=-1/0,r=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Th,this.minX=e,this.minY=t,this.maxX=s,this.maxY=r}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new te);const e=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(e.x=0,e.y=0,e.width=0,e.height=0):e.copyFromBounds(this),e}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Th,this}set(e,t,s,r){this.minX=e,this.minY=t,this.maxX=s,this.maxY=r}addFrame(e,t,s,r,n){n||(n=this.matrix);const o=n.a,a=n.b,l=n.c,h=n.d,c=n.tx,u=n.ty;let d=this.minX,f=this.minY,p=this.maxX,g=this.maxY,m=o*e+l*t+c,_=a*e+h*t+u;m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*s+l*t+c,_=a*s+h*t+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*e+l*r+c,_=a*e+h*r+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*s+l*r+c,_=a*s+h*r+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),this.minX=d,this.minY=f,this.maxX=p,this.maxY=g}addRect(e,t){this.addFrame(e.x,e.y,e.x+e.width,e.y+e.height,t)}addBounds(e,t){this.addFrame(e.minX,e.minY,e.maxX,e.maxY,t)}addBoundsMask(e){this.minX=this.minX>e.minX?this.minX:e.minX,this.minY=this.minY>e.minY?this.minY:e.minY,this.maxX=this.maxX<e.maxX?this.maxX:e.maxX,this.maxY=this.maxY<e.maxY?this.maxY:e.maxY}applyMatrix(e){const t=this.minX,s=this.minY,r=this.maxX,n=this.maxY,{a:o,b:a,c:l,d:h,tx:c,ty:u}=e;let d=o*t+l*s+c,f=a*t+h*s+u;this.minX=d,this.minY=f,this.maxX=d,this.maxY=f,d=o*r+l*s+c,f=a*r+h*s+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=o*t+l*n+c,f=a*t+h*n+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=o*r+l*n+c,f=a*r+h*n+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY}fit(e){return this.minX<e.left&&(this.minX=e.left),this.maxX>e.right&&(this.maxX=e.right),this.minY<e.top&&(this.minY=e.top),this.maxY>e.bottom&&(this.maxY=e.bottom),this}fitBounds(e,t,s,r){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<s&&(this.minY=s),this.maxY>r&&(this.maxY=r),this}pad(e,t=e){return this.minX-=e,this.maxX+=e,this.minY-=t,this.maxY+=t,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new Ee(this.minX,this.minY,this.maxX,this.maxY)}scale(e,t=e){return this.minX*=e,this.minY*=t,this.maxX*=e,this.maxY*=t,this}get x(){return this.minX}set x(e){const t=this.maxX-this.minX;this.minX=e,this.maxX=e+t}get y(){return this.minY}set y(e){const t=this.maxY-this.minY;this.minY=e,this.maxY=e+t}get width(){return this.maxX-this.minX}set width(e){this.maxX=this.minX+e}get height(){return this.maxY-this.minY}set height(e){this.maxY=this.minY+e}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(e,t,s,r){let n=this.minX,o=this.minY,a=this.maxX,l=this.maxY;r||(r=this.matrix);const h=r.a,c=r.b,u=r.c,d=r.d,f=r.tx,p=r.ty;for(let g=t;g<s;g+=2){const m=e[g],_=e[g+1],y=h*m+u*_+f,x=c*m+d*_+p;n=y<n?y:n,o=x<o?x:o,a=y>a?y:a,l=x>l?x:l}this.minX=n,this.minY=o,this.maxX=a,this.maxY=l}containsPoint(e,t){return this.minX<=e&&this.minY<=t&&this.maxX>=e&&this.maxY>=t}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(e){return this.minX=e.minX,this.minY=e.minY,this.maxX=e.maxX,this.maxY=e.maxY,this}}var Xg={grad:.9,turn:360,rad:360/(2*Math.PI)},_t=function(i){return typeof i=="string"?i.length>0:typeof i=="number"},Me=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=Math.pow(10,e)),Math.round(t*i)/t+0},Ye=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),i>t?t:i>e?i:e},Eu=function(i){return(i=isFinite(i)?i%360:0)>0?i:i+360},Sh=function(i){return{r:Ye(i.r,0,255),g:Ye(i.g,0,255),b:Ye(i.b,0,255),a:Ye(i.a)}},tn=function(i){return{r:Me(i.r),g:Me(i.g),b:Me(i.b),a:Me(i.a,3)}},qg=/^#([0-9a-f]{3,8})$/i,ki=function(i){var e=i.toString(16);return e.length<2?"0"+e:e},Pu=function(i){var e=i.r,t=i.g,s=i.b,r=i.a,n=Math.max(e,t,s),o=n-Math.min(e,t,s),a=o?n===e?(t-s)/o:n===t?2+(s-e)/o:4+(e-t)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},Au=function(i){var e=i.h,t=i.s,s=i.v,r=i.a;e=e/360*6,t/=100,s/=100;var n=Math.floor(e),o=s*(1-t),a=s*(1-(e-n)*t),l=s*(1-(1-e+n)*t),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},Ch=function(i){return{h:Eu(i.h),s:Ye(i.s,0,100),l:Ye(i.l,0,100),a:Ye(i.a)}},Mh=function(i){return{h:Me(i.h),s:Me(i.s),l:Me(i.l),a:Me(i.a,3)}},kh=function(i){return Au((t=(e=i).s,{h:e.h,s:(t*=((s=e.l)<50?s:100-s)/100)>0?2*t/(s+t)*100:0,v:s+t,a:e.a}));var e,t,s},ei=function(i){return{h:(e=Pu(i)).h,s:(r=(200-(t=e.s))*(s=e.v)/100)>0&&r<200?t*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,t,s,r},Yg=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Kg=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Zg=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Qg=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Nn={string:[[function(i){var e=qg.exec(i);return e?(i=e[1]).length<=4?{r:parseInt(i[0]+i[0],16),g:parseInt(i[1]+i[1],16),b:parseInt(i[2]+i[2],16),a:i.length===4?Me(parseInt(i[3]+i[3],16)/255,2):1}:i.length===6||i.length===8?{r:parseInt(i.substr(0,2),16),g:parseInt(i.substr(2,2),16),b:parseInt(i.substr(4,2),16),a:i.length===8?Me(parseInt(i.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(i){var e=Zg.exec(i)||Qg.exec(i);return e?e[2]!==e[4]||e[4]!==e[6]?null:Sh({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(i){var e=Yg.exec(i)||Kg.exec(i);if(!e)return null;var t,s,r=Ch({h:(t=e[1],s=e[2],s===void 0&&(s="deg"),Number(t)*(Xg[s]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return kh(r)},"hsl"]],object:[[function(i){var e=i.r,t=i.g,s=i.b,r=i.a,n=r===void 0?1:r;return _t(e)&&_t(t)&&_t(s)?Sh({r:Number(e),g:Number(t),b:Number(s),a:Number(n)}):null},"rgb"],[function(i){var e=i.h,t=i.s,s=i.l,r=i.a,n=r===void 0?1:r;if(!_t(e)||!_t(t)||!_t(s))return null;var o=Ch({h:Number(e),s:Number(t),l:Number(s),a:Number(n)});return kh(o)},"hsl"],[function(i){var e=i.h,t=i.s,s=i.v,r=i.a,n=r===void 0?1:r;if(!_t(e)||!_t(t)||!_t(s))return null;var o=(function(a){return{h:Eu(a.h),s:Ye(a.s,0,100),v:Ye(a.v,0,100),a:Ye(a.a)}})({h:Number(e),s:Number(t),v:Number(s),a:Number(n)});return Au(o)},"hsv"]]},Eh=function(i,e){for(var t=0;t<e.length;t++){var s=e[t][0](i);if(s)return[s,e[t][1]]}return[null,void 0]},Jg=function(i){return typeof i=="string"?Eh(i.trim(),Nn.string):typeof i=="object"&&i!==null?Eh(i,Nn.object):[null,void 0]},sn=function(i,e){var t=ei(i);return{h:t.h,s:Ye(t.s+100*e,0,100),l:t.l,a:t.a}},rn=function(i){return(299*i.r+587*i.g+114*i.b)/1e3/255},Ph=function(i,e){var t=ei(i);return{h:t.h,s:t.s,l:Ye(t.l+100*e,0,100),a:t.a}},Hn=(function(){function i(e){this.parsed=Jg(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return i.prototype.isValid=function(){return this.parsed!==null},i.prototype.brightness=function(){return Me(rn(this.rgba),2)},i.prototype.isDark=function(){return rn(this.rgba)<.5},i.prototype.isLight=function(){return rn(this.rgba)>=.5},i.prototype.toHex=function(){return e=tn(this.rgba),t=e.r,s=e.g,r=e.b,o=(n=e.a)<1?ki(Me(255*n)):"","#"+ki(t)+ki(s)+ki(r)+o;var e,t,s,r,n,o},i.prototype.toRgb=function(){return tn(this.rgba)},i.prototype.toRgbString=function(){return e=tn(this.rgba),t=e.r,s=e.g,r=e.b,(n=e.a)<1?"rgba("+t+", "+s+", "+r+", "+n+")":"rgb("+t+", "+s+", "+r+")";var e,t,s,r,n},i.prototype.toHsl=function(){return Mh(ei(this.rgba))},i.prototype.toHslString=function(){return e=Mh(ei(this.rgba)),t=e.h,s=e.s,r=e.l,(n=e.a)<1?"hsla("+t+", "+s+"%, "+r+"%, "+n+")":"hsl("+t+", "+s+"%, "+r+"%)";var e,t,s,r,n},i.prototype.toHsv=function(){return e=Pu(this.rgba),{h:Me(e.h),s:Me(e.s),v:Me(e.v),a:Me(e.a,3)};var e},i.prototype.invert=function(){return ot({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},i.prototype.saturate=function(e){return e===void 0&&(e=.1),ot(sn(this.rgba,e))},i.prototype.desaturate=function(e){return e===void 0&&(e=.1),ot(sn(this.rgba,-e))},i.prototype.grayscale=function(){return ot(sn(this.rgba,-1))},i.prototype.lighten=function(e){return e===void 0&&(e=.1),ot(Ph(this.rgba,e))},i.prototype.darken=function(e){return e===void 0&&(e=.1),ot(Ph(this.rgba,-e))},i.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},i.prototype.alpha=function(e){return typeof e=="number"?ot({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):Me(this.rgba.a,3);var t},i.prototype.hue=function(e){var t=ei(this.rgba);return typeof e=="number"?ot({h:e,s:t.s,l:t.l,a:t.a}):Me(t.h)},i.prototype.isEqual=function(e){return this.toHex()===ot(e).toHex()},i})(),ot=function(i){return i instanceof Hn?i:new Hn(i)},Ah=[],e_=function(i){i.forEach(function(e){Ah.indexOf(e)<0&&(e(Hn,Nn),Ah.push(e))})};function t_(i,e){var t={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in t)s[t[r]]=r;var n={};i.prototype.toName=function(o){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var a,l,h=s[this.toHex()];if(h)return h;if(o?.closest){var c=this.toRgb(),u=1/0,d="black";if(!n.length)for(var f in t)n[f]=new i(t[f]).toRgb();for(var p in t){var g=(a=c,l=n[p],Math.pow(a.r-l.r,2)+Math.pow(a.g-l.g,2)+Math.pow(a.b-l.b,2));g<u&&(u=g,d=p)}return d}},e.string.push([function(o){var a=o.toLowerCase(),l=a==="transparent"?"#0000":t[a];return l?new i(l).toRgb():null},"name"])}e_([t_]);const Cs=class Zs{constructor(e=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=e}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(e){return this.value=e,this}set value(e){if(e instanceof Zs)this._value=this._cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(e===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,e))&&(this._value=this._cloneSource(e),this._normalize(this._value))}}get value(){return this._value}_cloneSource(e){return typeof e=="string"||typeof e=="number"||e instanceof Number||e===null?e:Array.isArray(e)||ArrayBuffer.isView(e)?e.slice(0):typeof e=="object"&&e!==null?{...e}:e}_isSourceEqual(e,t){const s=typeof e;if(s!==typeof t)return!1;if(s==="number"||s==="string"||e instanceof Number)return e===t;if(Array.isArray(e)&&Array.isArray(t)||ArrayBuffer.isView(e)&&ArrayBuffer.isView(t))return e.length!==t.length?!1:e.every((n,o)=>n===t[o]);if(e!==null&&t!==null){const n=Object.keys(e),o=Object.keys(t);return n.length!==o.length?!1:n.every(a=>e[a]===t[a])}return e===t}toRgba(){const[e,t,s,r]=this._components;return{r:e,g:t,b:s,a:r}}toRgb(){const[e,t,s]=this._components;return{r:e,g:t,b:s}}toRgbaString(){const[e,t,s]=this.toUint8RgbArray();return`rgba(${e},${t},${s},${this.alpha})`}toUint8RgbArray(e){const[t,s,r]=this._components;return this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb),e[0]=Math.round(t*255),e[1]=Math.round(s*255),e[2]=Math.round(r*255),e}toArray(e){this._arrayRgba||(this._arrayRgba=[]),e||(e=this._arrayRgba);const[t,s,r,n]=this._components;return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}toRgbArray(e){this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb);const[t,s,r]=this._components;return e[0]=t,e[1]=s,e[2]=r,e}toNumber(){return this._int}toBgrNumber(){const[e,t,s]=this.toUint8RgbArray();return(s<<16)+(t<<8)+e}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[t,s,r,n]=Zs._temp.setValue(e)._components;return this._components[0]*=t,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this._refreshInt(),this._value=null,this}premultiply(e,t=!0){return t&&(this._components[0]*=e,this._components[1]*=e,this._components[2]*=e),this._components[3]=e,this._refreshInt(),this._value=null,this}toPremultiplied(e,t=!0){if(e===1)return(255<<24)+this._int;if(e===0)return t?0:this._int;let s=this._int>>16&255,r=this._int>>8&255,n=this._int&255;return t&&(s=s*e+.5|0,r=r*e+.5|0,n=n*e+.5|0),(e*255<<24)+(s<<16)+(r<<8)+n}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const t=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(e){return this._components[3]=this._clamp(e),this._value=null,this}_normalize(e){let t,s,r,n;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const o=e;t=(o>>16&255)/255,s=(o>>8&255)/255,r=(o&255)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[t,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[t,s,r,n=255]=e,t/=255,s/=255,r/=255,n/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const a=Zs.HEX_PATTERN.exec(e);a&&(e=`#${a[2]}`)}const o=ot(e);o.isValid()&&({r:t,g:s,b:r,a:n}=o.rgba,t/=255,s/=255,r/=255)}if(t!==void 0)this._components[0]=t,this._components[1]=s,this._components[2]=r,this._components[3]=n,this._refreshInt();else throw new Error(`Unable to convert color ${e}`)}_refreshInt(){this._clamp(this._components);const[e,t,s]=this._components;this._int=(e*255<<16)+(t*255<<8)+(s*255|0)}_clamp(e,t=0,s=1){return typeof e=="number"?Math.min(Math.max(e,t),s):(e.forEach((r,n)=>{e[n]=Math.min(Math.max(r,t),s)}),e)}static isColorLike(e){return typeof e=="number"||typeof e=="string"||e instanceof Number||e instanceof Zs||Array.isArray(e)||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Float32Array||e.r!==void 0&&e.g!==void 0&&e.b!==void 0||e.r!==void 0&&e.g!==void 0&&e.b!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0&&e.a!==void 0}};Cs.shared=new Cs;Cs._temp=new Cs;Cs.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let ae=Cs;const Ru={cullArea:null,cullable:!1,cullableChildren:!0};let nn=0;const Rh=500;function z(...i){nn!==Rh&&(nn++,nn===Rh?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...i))}const as={_registeredResources:new Set,register(i){this._registeredResources.add(i)},unregister(i){this._registeredResources.delete(i)},release(){this._registeredResources.forEach(i=>i.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(i){return this._registeredResources.has(i)},reset(){this._registeredResources.clear()}};class Bu{constructor(e,t){this._pool=[],this._count=0,this._index=0,this._classType=e,t&&this.prepopulate(t)}prepopulate(e){for(let t=0;t<e;t++)this._pool[this._index++]=new this._classType;this._count+=e}get(e){let t;return this._index>0?t=this._pool[--this._index]:(t=new this._classType,this._count++),t.init?.(e),t}return(e){e.reset?.(),this._pool[this._index++]=e}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let e=0;e<this._index;e++)this._pool[e].destroy();this._pool.length=0,this._count=0,this._index=0}}class Iu{constructor(){this._poolsByClass=new Map}prepopulate(e,t){this.getPool(e).prepopulate(t)}get(e,t){return this.getPool(e).get(t)}return(e){this.getPool(e.constructor).return(e)}getPool(e){return this._poolsByClass.has(e)||this._poolsByClass.set(e,new Bu(e)),this._poolsByClass.get(e)}stats(){const e={};return this._poolsByClass.forEach(t=>{const s=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[s]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}}const Se=new Iu;as.register(Se);const Gu={get isCachedAsTexture(){return!!this.renderGroup?.isCachedAsTexture},cacheAsTexture(i){typeof i=="boolean"&&i===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(i===!0?{}:i))},updateCacheTexture(){this.renderGroup?.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(i){H("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(i)}};function Ho(i,e,t){const s=i.length;let r;if(e>=s||t===0)return;t=e+t>s?s-e:t;const n=s-t;for(r=e;r<n;++r)i[r]=i[r+t];i.length=n}const Du={allowChildren:!0,removeChildren(i=0,e){const t=e??this.children.length,s=t-i,r=[];if(s>0&&s<=t){for(let o=t-1;o>=i;o--){const a=this.children[o];a&&(r.push(a),a.parent=null)}Ho(this.children,i,t);const n=this.renderGroup||this.parentRenderGroup;n&&n.removeChildren(r);for(let o=0;o<r.length;++o){const a=r[o];a.parentRenderLayer?.detach(a),this.emit("childRemoved",a,this,o),r[o].emit("removed",this)}return r.length>0&&this._didViewChangeTick++,r}else if(s===0&&this.children.length===0)return r;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(i){const e=this.getChildAt(i);return this.removeChild(e)},getChildAt(i){if(i<0||i>=this.children.length)throw new Error(`getChildAt: Index (${i}) does not exist.`);return this.children[i]},setChildIndex(i,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);this.getChildIndex(i),this.addChildAt(i,e)},getChildIndex(i){const e=this.children.indexOf(i);if(e===-1)throw new Error("The supplied Container must be a child of the caller");return e},addChildAt(i,e){this.allowChildren||H(ue,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:t}=this;if(e<0||e>t.length)throw new Error(`${i}addChildAt: The index ${e} supplied is out of bounds ${t.length}`);const s=i.parent===this;if(i.parent){const n=i.parent.children.indexOf(i);if(s){if(n===e)return i;i.parent.children.splice(n,1)}else i.removeFromParent()}e===t.length?t.push(i):t.splice(e,0,i);const r=this.renderGroup||this.parentRenderGroup;return this.sortableChildren&&(this.sortDirty=!0),s?(r&&(r.structureDidChange=!0),i):(i.parent=this,i.didChange=!0,i._updateFlags=15,r&&r.addChild(i),this.emit("childAdded",i,this,e),i.emit("added",this),i)},swapChildren(i,e){if(i===e)return;const t=this.getChildIndex(i),s=this.getChildIndex(e);this.children[t]=e,this.children[s]=i;const r=this.renderGroup||this.parentRenderGroup;r&&(r.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){this.parent?.removeChild(this)},reparentChild(...i){return i.length===1?this.reparentChildAt(i[0],this.children.length):(i.forEach(e=>this.reparentChildAt(e,this.children.length)),i[0])},reparentChildAt(i,e){if(i.parent===this)return this.setChildIndex(i,e),i;const t=i.worldTransform.clone();i.removeFromParent(),this.addChildAt(i,e);const s=this.worldTransform.clone();return s.invert(),t.prepend(s),i.setFromMatrix(t),i},replaceChild(i,e){i.updateLocalTransform(),this.addChildAt(e,this.getChildIndex(i)),e.setFromMatrix(i.localTransform),e.updateLocalTransform(),this.removeChild(i)}},Fu={collectRenderables(i,e,t){this.parentRenderLayer&&this.parentRenderLayer!==t||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(i,e,t):this.renderGroup?e.renderPipes.renderGroup.addRenderGroup(this.renderGroup,i):this.collectRenderablesWithEffects(i,e,t))},collectRenderablesSimple(i,e,t){const s=this.children,r=s.length;for(let n=0;n<r;n++)s[n].collectRenderables(i,e,t)},collectRenderablesWithEffects(i,e,t){const{renderPipes:s}=e;for(let r=0;r<this.effects.length;r++){const n=this.effects[r];s[n.pipe].push(n,this,i)}this.collectRenderablesSimple(i,e,t);for(let r=this.effects.length-1;r>=0;r--){const n=this.effects[r];s[n.pipe].pop(n,this,i)}}};class hi{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let e=0;e<this.filters.length;e++)this.filters[e].destroy();this.filters=null,this.filterArea=null}}class Ou{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(e=>{this.add({test:e.test,maskClass:e})}))}add(e){this._tests.push(e)}getMaskEffect(e){this._initialized||this.init();for(let t=0;t<this._tests.length;t++){const s=this._tests[t];if(s.test(e))return Se.get(s.maskClass,e)}return e}returnMaskEffect(e){Se.return(e)}}const rr=new Ou;q.handleByList(S.MaskEffect,rr._effectClasses);const Lu={_maskEffect:null,_maskOptions:{inverse:!1,channel:"red"},_filterEffect:null,effects:[],_markStructureAsChanged(){const i=this.renderGroup||this.parentRenderGroup;i&&(i.structureDidChange=!0)},addEffect(i){this.effects.indexOf(i)===-1&&(this.effects.push(i),this.effects.sort((t,s)=>t.priority-s.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(i){const e=this.effects.indexOf(i);e!==-1&&(this.effects.splice(e,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(i){const e=this._maskEffect;e?.mask!==i&&(e&&(this.removeEffect(e),rr.returnMaskEffect(e),this._maskEffect=null),i!=null&&(this._maskEffect=rr.getMaskEffect(i),this.addEffect(this._maskEffect)))},get mask(){return this._maskEffect?.mask},setMask(i){this._maskOptions={...this._maskOptions,...i},i.mask&&(this.mask=i.mask),this._markStructureAsChanged()},set filters(i){!Array.isArray(i)&&i&&(i=[i]);const e=this._filterEffect||(this._filterEffect=new hi);i=i;const t=i?.length>0,s=e.filters?.length>0,r=t!==s;i=Array.isArray(i)?i.slice(0):i,e.filters=Object.freeze(i),r&&(t?this.addEffect(e):(this.removeEffect(e),e.filters=i??null))},get filters(){return this._filterEffect?.filters},set filterArea(i){this._filterEffect||(this._filterEffect=new hi),this._filterEffect.filterArea=i},get filterArea(){return this._filterEffect?.filterArea}},Uu={label:null,get name(){return H(ue,"Container.name property has been removed, use Container.label instead"),this.label},set name(i){H(ue,"Container.name property has been removed, use Container.label instead"),this.label=i},getChildByName(i,e=!1){return this.getChildByLabel(i,e)},getChildByLabel(i,e=!1){const t=this.children;for(let s=0;s<t.length;s++){const r=t[s];if(r.label===i||i instanceof RegExp&&i.test(r.label))return r}if(e)for(let s=0;s<t.length;s++){const n=t[s].getChildByLabel(i,!0);if(n)return n}return null},getChildrenByLabel(i,e=!1,t=[]){const s=this.children;for(let r=0;r<s.length;r++){const n=s[r];(n.label===i||i instanceof RegExp&&i.test(n.label))&&t.push(n)}if(e)for(let r=0;r<s.length;r++)s[r].getChildrenByLabel(i,!0,t);return t}},Ae=Se.getPool(U),ut=Se.getPool(Ee),s_=new U,Nu={getFastGlobalBounds(i,e){e||(e=new Ee),e.clear(),this._getGlobalBoundsRecursive(!!i,e,this.parentRenderLayer),e.isValid||e.set(0,0,0,0);const t=this.renderGroup||this.parentRenderGroup;return e.applyMatrix(t.worldTransform),e},_getGlobalBoundsRecursive(i,e,t){let s=e;if(i&&this.parentRenderLayer&&this.parentRenderLayer!==t||this.localDisplayStatus!==7||!this.measurable)return;const r=!!this.effects.length;if((this.renderGroup||r)&&(s=ut.get().clear()),this.boundsArea)e.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const o=this.bounds;s.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(i,s,t)}if(r){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,s.applyMatrix(o.worldTransform)),this.effects[a].addBounds(s,!0));n&&s.applyMatrix(o.worldTransform.copyTo(s_).invert()),e.addBounds(s),ut.return(s)}else this.renderGroup&&(e.addBounds(s,this.relativeGroupTransform),ut.return(s))}};function _r(i,e,t){t.clear();let s,r;return i.parent?e?s=i.parent.worldTransform:(r=Ae.get().identity(),s=yr(i,r)):s=U.IDENTITY,Hu(i,t,s,e),r&&Ae.return(r),t.isValid||t.set(0,0,0,0),t}function Hu(i,e,t,s){if(!i.visible||!i.measurable)return;let r;s?r=i.worldTransform:(i.updateLocalTransform(),r=Ae.get(),r.appendFrom(i.localTransform,t));const n=e,o=!!i.effects.length;if(o&&(e=ut.get().clear()),i.boundsArea)e.addRect(i.boundsArea,r);else{const a=i.bounds;a&&!a.isEmpty()&&(e.matrix=r,e.addBounds(a));for(let l=0;l<i.children.length;l++)Hu(i.children[l],e,r,s)}if(o){for(let a=0;a<i.effects.length;a++)i.effects[a].addBounds?.(e);n.addBounds(e,U.IDENTITY),ut.return(e)}s||Ae.return(r)}function yr(i,e){const t=i.parent;return t&&(yr(t,e),t.updateLocalTransform(),e.append(t.localTransform)),e}function Kt(i,e){if(i===16777215||!e)return e;if(e===16777215||!i)return i;const t=i>>16&255,s=i>>8&255,r=i&255,n=e>>16&255,o=e>>8&255,a=e&255,l=t*n/255|0,h=s*o/255|0,c=r*a/255|0;return(l<<16)+(h<<8)+c}const Bh=16777215;function ci(i,e){return i===Bh?e:e===Bh?i:Kt(i,e)}function Zt(i){return((i&255)<<16)+(i&65280)+(i>>16&255)}const zu={getGlobalAlpha(i){if(i)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let e=this.alpha,t=this.parent;for(;t;)e*=t.alpha,t=t.parent;return e},getGlobalTransform(i=new U,e){if(e)return i.copyFrom(this.worldTransform);this.updateLocalTransform();const t=yr(this,Ae.get().identity());return i.appendFrom(this.localTransform,t),Ae.return(t),i},getGlobalTint(i){if(i)return this.renderGroup?Zt(this.renderGroup.worldColor):this.parentRenderGroup?Zt(ci(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let e=this.localColor,t=this.parent;for(;t;)e=ci(e,t.localColor),t=t.parent;return Zt(e)}};function xr(i,e,t){return e.clear(),t||(t=U.IDENTITY),Wu(i,e,t,i,!0),e.isValid||e.set(0,0,0,0),e}function Wu(i,e,t,s,r){let n;if(r)n=Ae.get(),n=t.copyTo(n);else{if(!i.visible||!i.measurable)return;i.updateLocalTransform();const l=i.localTransform;n=Ae.get(),n.appendFrom(l,t)}const o=e,a=!!i.effects.length;if(a&&(e=ut.get().clear()),i.boundsArea)e.addRect(i.boundsArea,n);else{i.renderPipeId&&(e.matrix=n,e.addBounds(i.bounds));const l=i.children;for(let h=0;h<l.length;h++)Wu(l[h],e,n,s,!1)}if(a){for(let l=0;l<i.effects.length;l++)i.effects[l].addLocalBounds?.(e,s);o.addBounds(e,U.IDENTITY),ut.return(e)}Ae.return(n)}function zo(i,e){const t=i.children;for(let s=0;s<t.length;s++){const r=t[s],n=r.uid,o=(r._didViewChangeTick&65535)<<16|r._didContainerChangeTick&65535,a=e.index;(e.data[a]!==n||e.data[a+1]!==o)&&(e.data[e.index]=n,e.data[e.index+1]=o,e.didChange=!0),e.index=a+2,r.children.length&&zo(r,e)}return e.didChange}const i_=new U,$u={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(i,e){const t=Math.sign(this.scale.x)||1;e!==0?this.scale.x=i/e*t:this.scale.x=t},_setHeight(i,e){const t=Math.sign(this.scale.y)||1;e!==0?this.scale.y=i/e*t:this.scale.y=t},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Ee});const i=this._localBoundsCacheData;return i.index=1,i.didChange=!1,i.data[0]!==this._didViewChangeTick&&(i.didChange=!0,i.data[0]=this._didViewChangeTick),zo(this,i),i.didChange&&xr(this,i.localBounds,i_),i.localBounds},getBounds(i,e){return _r(this,i,e||new Ee)}},Vu={_onRender:null,set onRender(i){const e=this.renderGroup||this.parentRenderGroup;if(!i){this._onRender&&e?.removeOnRender(this),this._onRender=null;return}this._onRender||e?.addOnRender(this),this._onRender=i},get onRender(){return this._onRender}},ju={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(i){this._zIndex!==i&&(this._zIndex=i,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(r_))}};function r_(i,e){return i._zIndex-e._zIndex}const Xu={getGlobalPosition(i=new he,e=!1){return this.parent?this.parent.toGlobal(this._position,i,e):(i.x=this._position.x,i.y=this._position.y),i},toGlobal(i,e,t=!1){const s=this.getGlobalTransform(Ae.get(),t);return e=s.apply(i,e),Ae.return(s),e},toLocal(i,e,t,s){e&&(i=e.toGlobal(i,t,s));const r=this.getGlobalTransform(Ae.get(),s);return t=r.applyInverse(i,t),Ae.return(r),t}};class br{constructor(){this.uid=oe("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){if(this.renderPipes)for(const e in this.renderPipes)this.renderPipes[e].destroyInstructionSet?.(this);this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}class Wo{constructor(){this._screenSizes=new Map,this._widths=[],this._heights=[]}get size(){return this._screenSizes.size}set(e,t,s){const r=this._screenSizes.get(e);return r&&r.pixelWidth===t&&r.pixelHeight===s?!1:(this._screenSizes.set(e,{pixelWidth:t,pixelHeight:s}),this._update(),!0)}remove(e){return this._screenSizes.delete(e)?(this._update(),!0):!1}getFittingWidth(e){return this._getFittingAxis(e,this._widths)}getFittingHeight(e){return this._getFittingAxis(e,this._heights)}hasWidth(e){return this._widths.includes(e)}hasHeight(e){return this._heights.includes(e)}_getFittingAxis(e,t){for(let s=0;s<t.length;s++){const r=t[s];if(r>=e)return r}}_update(){this._widths=[...this._screenSizes.values()].map(e=>e.pixelWidth).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>e-t),this._heights=[...this._screenSizes.values()].map(e=>e.pixelHeight).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>e-t)}}let n_=0;const on=32767,o_=4294967296,a_=8589934592,Ih=Object.create(null);let l_=0;function h_(i){const e=Ih[i];return e!==void 0?e:Ih[i]=l_++}function c_(i,e,t,s,r,n){return(i<<17)+(e<<2)+((s?1:0)<<1)+(t?1:0)+(n==="nearest"?1:0)*o_+h_(r)*a_}class qu{constructor(e){this._buckets=new Map,this._poolKey=Object.create(null),this._poolStyle=Object.create(null),this._screens=new Wo,this._enableFullScreen=!1,this.textureOptions=e||{}}get textureStyle(){return H(ht,"TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead."),this._textureStyle||(this._textureStyle=new Dt(this.textureOptions)),this._textureStyle}set textureStyle(e){H(ht,"TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead."),this._textureStyle=e}get enableFullScreen(){return H(ht,"TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize."),this._enableFullScreen}set enableFullScreen(e){H(ht,"TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize."),this._enableFullScreen=e}createTexture(...e){let t=e[0];typeof t=="number"&&(H(ht,"TexturePool.createTexture params are now an options object. See params: { width, height, antialias, autoGenerateMipmaps }"),t={width:t,height:e[1],antialias:e[2]??!1,autoGenerateMipmaps:e[3]??!1});const s=t.format??this.textureOptions.format??de.defaultOptions.format,r=t.scaleMode??this.textureOptions.scaleMode??Dt.defaultOptions.scaleMode,n=new de({...this.textureOptions,width:t.width,height:t.height,resolution:1,antialias:t.antialias??!1,autoGarbageCollect:!1,autoGenerateMipmaps:t.autoGenerateMipmaps??!1,format:s,scaleMode:r});return new W({source:n,label:`texturePool_${n_++}`})}getOptimalTexture(...e){let t=e[0];typeof t=="number"&&(H(ht,"TexturePool.getOptimalTexture params are now an options object. See params: { width, height, resolution, antialias, autoGenerateMipmaps }"),t={width:t,height:e[1],resolution:e[2]??1,antialias:e[3]??!1,autoGenerateMipmaps:e[4]??!1});const s=t.width,r=t.height,n=t.resolution??1,o=t.antialias??!1,a=t.autoGenerateMipmaps??!1,l=t.format??this.textureOptions.format??de.defaultOptions.format,h=t.scaleMode??this.textureOptions.scaleMode??Dt.defaultOptions.scaleMode,{width:c,height:u}=this.getOptimalSize(s,r,n);(c>on||u>on)&&z(`TexturePool: ${c}x${u} is larger than the ${on}px pool key limit, textures of this size may be pooled together`);const d=c_(c,u,o,a,l,h);let f=this._buckets.get(d);f||(f=[],this._buckets.set(d,f));let p=f.pop();return p||(p=this.createTexture({width:c,height:u,antialias:o,autoGenerateMipmaps:a,format:l,scaleMode:h}),this._poolStyle[p.uid]=p.source.style),p.source._resolution=n,p.source.width=c/n,p.source.height=u/n,p.source.pixelWidth=c,p.source.pixelHeight=u,p.frame.x=0,p.frame.y=0,p.frame.width=s,p.frame.height=r,p.updateUvs(),this._poolKey[p.uid]=d,p}getOptimalSize(e,t,s=1){const r=Math.ceil(e*s-1e-6),n=Math.ceil(t*s-1e-6),o=es(r),a=this._screens.getFittingWidth(r),l=es(n),h=this._screens.getFittingHeight(n);return{width:a!==void 0?Math.min(a,o):o,height:h!==void 0?Math.min(h,l):l}}getSameSizeTexture(e,t=!1){const s=e.source;return this.getOptimalTexture({width:e.width,height:e.height,resolution:s._resolution,antialias:t})}returnTexture(e,t=!1){const s=e.uid,r=this._poolKey[s];if(r===void 0){z("TexturePool: returnTexture was passed a texture that did not come from this pool, ignoring it");return}const n=this._poolStyle[s];t&&e.source.style!==n&&(e.source.style=n);const o=this._buckets.get(r);if(!o){delete this._poolKey[s],delete this._poolStyle[s],e.destroy(!0);return}o.push(e)}setScreenSize(e,t,s){this._screens.set(e,t,s)&&this._pruneScreenTextures()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenTextures()}_pruneScreenTextures(){for(const[e,t]of this._buckets){const s=e>>>0,r=s>>>17,n=s>>>2&32767;(ts(r)||this._screens.hasWidth(r))&&(ts(n)||this._screens.hasHeight(n))||(this._dropTextures(t,!0),this._buckets.delete(e))}}_dropTextures(e,t){for(let s=0;s<e.length;s++){const r=e[s];delete this._poolKey[r.uid],delete this._poolStyle[r.uid],t&&r.destroy(!0)}}clear(e){for(const t of this._buckets.values())this._dropTextures(t,e!==!1);this._buckets.clear()}}const Te=new qu;as.register(Te);class nr{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new U,this.worldColorAlpha=4294967295,this.worldColor=16777215,this.worldAlpha=1,this.childrenToUpdate=Object.create(null),this.updateTick=0,this.gcTick=0,this.childrenRenderablesToUpdate={list:[],index:0},this.structureDidChange=!0,this.instructionSet=new br,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(e){this.root=e,e._onRender&&this.addOnRender(e),e.didChange=!0;const t=e.children;for(let s=0;s<t.length;s++){const r=t[s];r._updateFlags=15,this.addChild(r)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Te.returnTexture(this.texture),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const e in this.childrenToUpdate){const t=this.childrenToUpdate[e];t.list.fill(null),t.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){const t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.parent===this.root?e.relativeRenderGroupDepth=1:e.relativeRenderGroupDepth=e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);const t=e.children;for(let s=0;s<t.length;s++)this.addChild(t[s])}removeChild(e){if(this.structureDidChange=!0,e._onRender&&(e.renderGroup||this.removeOnRender(e)),e.parentRenderGroup=null,e.renderGroup){this._removeRenderGroupChild(e.renderGroup);return}const t=e.children;for(let s=0;s<t.length;s++)this.removeChild(t[s])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||(t=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]}),t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.indexOf(e)===-1&&this._onRenderContainers.push(e)}removeOnRender(e){const t=this._onRenderContainers.indexOf(e);t!==-1&&this._onRenderContainers.splice(t,1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet?.destroy(),this.instructionSet=null}getChildren(e=[]){const t=this.root.children;for(let s=0;s<t.length;s++)this._getChildren(t[s],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;const s=e.children;for(let r=0;r<s.length;r++)this._getChildren(s[r],t);return t}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return(this._matrixDirty&1)===0?this._inverseWorldTransform:(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new U),this._inverseWorldTransform.copyFrom(this.worldTransform).invert())}get textureOffsetInverseTransform(){return(this._matrixDirty&2)===0?this._textureOffsetInverseTransform:(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new U),this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y))}get inverseParentTextureTransform(){if((this._matrixDirty&4)===0)return this._inverseParentTextureTransform;this._matrixDirty&=-5;const e=this._parentCacheAsTextureRenderGroup;return e?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new U),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(e.inverseWorldTransform).translate(-e._textureBounds.x,-e._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function Yu(i,e,t={}){for(const s in e)!t[s]&&e[s]!==void 0&&(i[s]=e[s])}const an=new Ce(null),Ei=new Ce(null),ln=new Ce(null,1,1),Pi=new Ce(null),ui=1,vr=2,ws=4;class _e extends Re{constructor(e={}){super(),this.uid=oe("renderable"),this._updateFlags=15,this.renderGroup=null,this.parentRenderGroup=null,this.parentRenderGroupIndex=0,this.didChange=!1,this.didViewUpdate=!1,this.relativeRenderGroupDepth=0,this.children=[],this.parent=null,this.includeInBuild=!0,this.measurable=!0,this.isSimple=!0,this.parentRenderLayer=null,this.updateTick=-1,this.localTransform=new U,this.relativeGroupTransform=new U,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new Ce(this,0,0),this._scale=ln,this._pivot=Ei,this._origin=Pi,this._skew=an,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._rotation=0,this.localColor=16777215,this.localAlpha=1,this.groupAlpha=1,this.groupColor=16777215,this.groupColorAlpha=4294967295,this.localBlendMode="inherit",this.groupBlendMode="normal",this.localDisplayStatus=7,this.globalDisplayStatus=7,this._didContainerChangeTick=0,this._didViewChangeTick=0,this._didLocalTransformChangeId=-1,this.effects=[],Yu(this,e,{children:!0,parent:!0,effects:!0}),e.children?.forEach(t=>this.addChild(t)),e.parent?.addChild(this)}static mixin(e){H("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),q.mixin(_e,e)}set _didChangeId(e){this._didViewChangeTick=e>>12&4095,this._didContainerChangeTick=e&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...e){if(this.allowChildren||H(ue,"addChild: Only Containers will be allowed to add children in v8.0.0"),e.length>1){for(let r=0;r<e.length;r++)this.addChild(e[r]);return e[0]}const t=e[0],s=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),s&&(s.structureDidChange=!0),t):(t.parent&&t.parent.removeChild(t),this.children.push(t),this.sortableChildren&&(this.sortDirty=!0),t.parent=this,t.didChange=!0,t._updateFlags=15,s&&s.addChild(t),this.emit("childAdded",t,this,this.children.length-1),t.emit("added",this),this._didViewChangeTick++,t._zIndex!==0&&t.depthOfChildModified(),t)}removeChild(...e){if(e.length>1){for(let r=0;r<e.length;r++)this.removeChild(e[r]);return e[0]}const t=e[0],s=this.children.indexOf(t);return s>-1&&(this._didViewChangeTick++,this.children.splice(s,1),this.renderGroup?this.renderGroup.removeChild(t):this.parentRenderGroup&&this.parentRenderGroup.removeChild(t),t.parentRenderLayer&&t.parentRenderLayer.detach(t),t.parent=null,this.emit("childRemoved",t,this,s),t.emit("removed",this)),t}_onUpdate(e){e&&e===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(e){!!this.renderGroup!==e&&(e?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),this.renderGroup=Se.get(nr,this),this.groupTransform=U.IDENTITY,e?.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),Se.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,e?.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||(this._worldTransform=new U),this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(e){this._position.x=e}get y(){return this._position.y}set y(e){this._position.y=e}get position(){return this._position}set position(e){this._position.copyFrom(e)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._onUpdate(this._skew))}get angle(){return this.rotation*xu}set angle(e){this.rotation=e*bu}get pivot(){return this._pivot===Ei&&(this._pivot=new Ce(this,0,0)),this._pivot}set pivot(e){this._pivot===Ei&&(this._pivot=new Ce(this,0,0),this._origin!==Pi&&z("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._pivot.set(e):this._pivot.copyFrom(e)}get skew(){return this._skew===an&&(this._skew=new Ce(this,0,0)),this._skew}set skew(e){this._skew===an&&(this._skew=new Ce(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===ln&&(this._scale=new Ce(this,1,1)),this._scale}set scale(e){this._scale===ln&&(this._scale=new Ce(this,0,0)),typeof e=="string"&&(e=parseFloat(e)),typeof e=="number"?this._scale.set(e):this._scale.copyFrom(e)}get origin(){return this._origin===Pi&&(this._origin=new Ce(this,0,0)),this._origin}set origin(e){this._origin===Pi&&(this._origin=new Ce(this,0,0),this._pivot!==Ei&&z("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._origin.set(e):this._origin.copyFrom(e)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(e){const t=this.getLocalBounds().width;this._setWidth(e,t)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(e){const t=this.getLocalBounds().height;this._setHeight(e,t)}getSize(e){e||(e={});const t=this.getLocalBounds();return e.width=Math.abs(this.scale.x*t.width),e.height=Math.abs(this.scale.y*t.height),e}setSize(e,t){const s=this.getLocalBounds();typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,s.width),t!==void 0&&this._setHeight(t,s.height)}_updateSkew(){const e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x=="number"?e.x:this.position.x,typeof e.y=="number"?e.y:this.position.y),this.scale.set(typeof e.scaleX=="number"?e.scaleX:this.scale.x,typeof e.scaleY=="number"?e.scaleY:this.scale.y),this.rotation=typeof e.rotation=="number"?e.rotation:this.rotation,this.skew.set(typeof e.skewX=="number"?e.skewX:this.skew.x,typeof e.skewY=="number"?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX=="number"?e.pivotX:this.pivot.x,typeof e.pivotY=="number"?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX=="number"?e.originX:this.origin.x,typeof e.originY=="number"?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){const e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;const t=this.localTransform,s=this._scale,r=this._pivot,n=this._origin,o=this._position,a=s._x,l=s._y,h=r._x,c=r._y,u=-n._x,d=-n._y;t.a=this._cx*a,t.b=this._sx*a,t.c=this._cy*l,t.d=this._sy*l,t.tx=o._x-(h*t.a+c*t.c)+(u*t.a+d*t.c)-u,t.ty=o._y-(h*t.b+c*t.d)+(u*t.b+d*t.d)-d}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=ui,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){const s=ae.shared.setValue(e??16777215).toBgrNumber();s!==this.localColor&&(this.localColor=s,this._updateFlags|=ui,this._onUpdate())}get tint(){return Zt(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=vr,this.localBlendMode=e,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(e){const t=e?2:0;(this.localDisplayStatus&2)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=ws,this.localDisplayStatus^=2,this._onUpdate(),this.emit("visibleChanged",e))}get culled(){return!(this.localDisplayStatus&4)}set culled(e){const t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=ws,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(e){const t=e?1:0;(this.localDisplayStatus&1)!==t&&(this._updateFlags|=ws,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(e=!1){if(this.destroyed)return;this.destroyed=!0;let t;if(this.children.length&&(t=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit("destroyed",this),this.removeAllListeners(),(typeof e=="boolean"?e:e?.children)&&t)for(let r=0;r<t.length;++r)t[r].destroy(e);this.renderGroup?.destroy(),this.renderGroup=null}}q.mixin(_e,Du,Nu,Xu,Vu,$u,Lu,Uu,ju,Ru,Gu,zu,Fu);class wr extends _e{constructor(e){super(e),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this._bounds=new Ee(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=e.autoGarbageCollect??!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(e){this._roundPixels=e?1:0}containsPoint(e){const t=this.bounds,{x:s,y:r}=e;return s>=t.minX&&s<=t.maxX&&r>=t.minY&&r<=t.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const e=this.renderGroup||this.parentRenderGroup;e&&e.onChildViewUpdate(this)}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(e){this.unload(),super.destroy(e),this._bounds=null}collectRenderablesSimple(e,t,s){const{renderPipes:r}=t;r.blendMode.pushBlendMode(this,this.groupBlendMode,e);const o=r[this.renderPipeId];o?.addRenderable&&o.addRenderable(this,e),this.didViewUpdate=!1;const a=this.children,l=a.length;for(let h=0;h<l;h++)a[h].collectRenderables(e,t,s);r.blendMode.popBlendMode(e)}}class ss extends wr{constructor(e=W.EMPTY){e instanceof W&&(e={texture:e});const{texture:t=W.EMPTY,anchor:s,roundPixels:r,width:n,height:o,...a}=e;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new Ce({_onUpdate:()=>{this.onViewUpdate()}}),s?this.anchor=s:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=r??!1,n!==void 0&&(this.width=n),o!==void 0&&(this.height=o)}static from(e,t=!1){return e instanceof W?new ss(e):new ss(W.from(e,t))}set texture(e){e||(e=W.EMPTY);const t=this._texture;t!==e&&(t&&t.dynamic&&t.off("update",this.onViewUpdate,this),e.dynamic&&e.on("update",this.onViewUpdate,this),this._texture=e,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return No(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return H("8.6.1","Sprite.sourceBounds is deprecated, use visualBounds instead."),this.visualBounds}updateBounds(){const e=this._anchor,t=this._texture,s=this._bounds,{width:r,height:n}=t.orig;s.minX=-e._x*r,s.maxX=s.minX+r,s.minY=-e._y*n,s.maxY=s.minY+n}destroy(e=!1){if(super.destroy(e),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._texture.destroy(s)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(e){this._setWidth(e,this._texture.orig.width),this._width=e}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(e){this._setHeight(e,this._texture.orig.height),this._height=e}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this._texture.orig.width,e.height=Math.abs(this.scale.y)*this._texture.orig.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this._texture.orig.width),t!==void 0&&this._setHeight(t,this._texture.orig.height)}}const u_=new Ee;function $o(i,e,t){const s=u_;i.measurable=!0,_r(i,t,s),e.addBoundsMask(s),i.measurable=!1}function Vo(i,e,t){const s=ut.get();i.measurable=!0;const r=Ae.get().identity(),n=Ku(i,t,r);xr(i,s,n),i.measurable=!1,e.addBoundsMask(s),Ae.return(r),ut.return(s)}function Ku(i,e,t){return i?(i!==e&&(Ku(i.parent,e,t),i.updateLocalTransform(),t.append(i.localTransform)),t):(z("Mask bounds, renderable is not inside the root container"),t)}class jo{constructor(e){this.priority=0,this.inverse=!1,this.channel="red",this.pipe="alphaMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e instanceof ss),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask=null)}addBounds(e,t){this.inverse||$o(this.mask,e,t)}addLocalBounds(e,t){Vo(this.mask,e,t)}containsPoint(e,t){const s=this.mask;return t(s,e)}destroy(){this.reset()}static test(e){return e instanceof ss}}jo.extension=S.MaskEffect;class Xo{constructor(e){this.priority=0,this.pipe="colorMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e}destroy(){}static test(e){return typeof e=="number"}}Xo.extension=S.MaskEffect;class qo{constructor(e){this.priority=0,this.pipe="stencilMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(e,t){$o(this.mask,e,t)}addLocalBounds(e,t){Vo(this.mask,e,t)}containsPoint(e,t){const s=this.mask;return t(s,e)}destroy(){this.reset()}static test(e){return e instanceof _e}}qo.extension=S.MaskEffect;const Zu={createCanvas:(i,e)=>{const t=document.createElement("canvas");return t.width=i,t.height=e,t},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(i,e)=>fetch(i,e),parseXML:i=>new DOMParser().parseFromString(i,"text/xml")};let Gh=Zu;const ee={get(){return Gh},set(i){Gh=i}};class Ve extends de{constructor(e){e.resource||(e.resource=ee.get().createCanvas()),e.width||(e.width=e.resource.width,e.autoDensity||(e.width/=e.resolution)),e.height||(e.height=e.resource.height,e.autoDensity||(e.height/=e.resolution)),super(e),this.uploadMethodId="image",this.autoDensity=e.autoDensity,this.resizeCanvas(),this.transparent=!!e.transparent}resizeCanvas(){this.autoDensity&&"style"in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(e=this.width,t=this.height,s=this._resolution){const r=super.resize(e,t,s);return r&&this.resizeCanvas(),r}static test(e){return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&e instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}Ve.extension=S.TextureSource;class di extends de{constructor(e){super(e),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(e){return globalThis.HTMLImageElement&&e instanceof HTMLImageElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||globalThis.VideoFrame&&e instanceof VideoFrame}}di.extension=S.TextureSource;var is=(i=>(i[i.INTERACTION=50]="INTERACTION",i[i.HIGH=25]="HIGH",i[i.NORMAL=0]="NORMAL",i[i.LOW=-25]="LOW",i[i.UTILITY=-50]="UTILITY",i))(is||{});class qi{constructor(e,t=null,s=0,r=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=s,this._once=r}match(e,t=null){return this._fn===e&&this._context===t}emit(e){this._fn&&(this._context?this._fn.call(this._context,e):this._fn(e));const t=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),t}connect(e){this.previous=e,e.next&&(e.next.previous=this),this.next=e.next,e.next=this}destroy(e=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const t=this.next;return this.next=e?null:t,this.previous=null,t}}const Qu=class Ne{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 qi(null,null,1/0),this.deltaMS=1/Ne.targetFPMS,this.elapsedMS=1/Ne.targetFPMS,this._tick=e=>{this._requestId=null,this.started&&(this.update(e),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(e,t,s=is.NORMAL){return this._addListener(new qi(e,t,s))}addOnce(e,t,s=is.NORMAL){return this._addListener(new qi(e,t,s,!0))}_addListener(e){let t=this._head.next,s=this._head;if(!t)e.connect(s);else{for(;t;){if(e.priority>t.priority){e.connect(s);break}s=t,t=t.next}e.previous||e.connect(s)}return this._startIfPossible(),this}remove(e,t){let s=this._head.next;for(;s;)s.match(e,t)?s=s.destroy():s=s.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let e=0,t=this._head;for(;t=t.next;)e++;return e}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let e=this._head.next;for(;e;)e=e.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let t;if(e>this.lastTime){if(t=this.elapsedMS=e-this.lastTime,t>this._maxElapsedMS&&(t=this._maxElapsedMS),t*=this.speed,this._minElapsedMS){const n=e-this._lastFrame|0;if(n<this._minElapsedMS)return;this._lastFrame=e-n%this._minElapsedMS}this.deltaMS=t,this.deltaTime=this.deltaMS*Ne.targetFPMS;const s=this._head;let r=s.next;for(;r;)r=r.emit(this);s.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const t=Math.min(Math.max(0,e)/1e3,Ne.targetFPMS);this._maxElapsedMS=1/t,this._minElapsedMS&&e>this.maxFPS&&(this.maxFPS=e)}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){e===0?this._minElapsedMS=0:(e<this.minFPS&&(this.minFPS=e),this._minElapsedMS=1/(e/1e3))}static get shared(){if(!Ne._shared){const e=Ne._shared=new Ne;e.autoStart=!0,e._protected=!0}return Ne._shared}static get system(){if(!Ne._system){const e=Ne._system=new Ne;e.autoStart=!0,e._protected=!0}return Ne._system}};Qu.targetFPMS=.06;let We=Qu,hn;async function Ju(){return hn??(hn=(async()=>{const e=ee.get().createCanvas(1,1).getContext("webgl");if(!e)return"premultiply-alpha-on-upload";const t=await new Promise(o=>{const a=document.createElement("video");a.onloadeddata=()=>o(a),a.onerror=()=>o(null),a.autoplay=!1,a.crossOrigin="anonymous",a.preload="auto",a.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",a.load()});if(!t)return"premultiply-alpha-on-upload";const s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s);const r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);const n=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,n),e.deleteFramebuffer(r),e.deleteTexture(s),e.getExtension("WEBGL_lose_context")?.loseContext(),n[0]<=n[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),hn}const Tr=class ed extends de{constructor(e){super(e),this.isReady=!1,this.uploadMethodId="video",e={...ed.defaultOptions,...e},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this.alphaMode=e.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),this._onLoadedMetadata=this._onLoadedMetadata.bind(this),e.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const e=We.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener("play",this._onPlayStart),e.addEventListener("pause",this._onPlayStop),e.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlayThrough),e.addEventListener("error",this._onError,!0)),this.isValid||e.addEventListener("loadedmetadata",this._onLoadedMetadata),this.alphaMode=await Ju(),this._load=new Promise((s,r)=>{this.isValid?s(this):(this._resolve=s,this._reject=r,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.resource;return!e.paused&&!e.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onLoadedMetadata(){this.isValid&&this._mediaReady()}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlayThrough),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&this.isValid&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const e=this.resource;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlayThrough),e.removeEventListener("loadedmetadata",this._onLoadedMetadata),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(We.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||(We.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(We.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};Tr.extension=S.TextureSource;Tr.defaultOptions={...de.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};Tr.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let td=Tr;const Xt=(i,e,t=!1)=>(Array.isArray(i)||(i=[i]),e?i.map(s=>typeof s=="string"||t?e(s):s):i);class d_{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){const t=this._cache.get(e);return t||z(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){const s=Xt(e);let r;for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];if(h.test(t)){r=h.getCacheableAssets(s,t);break}}const n=new Map(Object.entries(r||{}));r||s.forEach(l=>{n.set(l,t)});const o=[...n.keys()],a={cacheKeys:o,keys:s};s.forEach(l=>{this._cacheMap.set(l,a)}),o.forEach(l=>{const h=r?r[l]:t;this._cache.has(l)&&this._cache.get(l)!==h&&z("[Cache] already has key:",l),this._cache.set(l,n.get(l))})}remove(e){if(!this._cacheMap.has(e)){z(`[Assets] Asset id ${e} was not found in the Cache`);return}const t=this._cacheMap.get(e);t.cacheKeys.forEach(r=>{this._cache.delete(r)}),t.keys.forEach(r=>{this._cacheMap.delete(r)})}get parsers(){return this._parsers}}const qt=new d_,zn=[];q.handleByList(S.TextureSource,zn);function sd(i={}){const e=i&&i.resource,t=e?i.resource:i,s=e?i:{resource:i};for(let r=0;r<zn.length;r++){const n=zn[r];if(n.test(t))return new n(s)}throw new Error(`Could not find a source type for resource: ${s.resource}`)}function id(i={},e=!1){const t=i&&i.resource,s=t?i.resource:i,r=t?i:{resource:i};if(!e&&qt.has(s))return qt.get(s);const n=new W({source:sd(r)});return n.on("destroy",()=>{qt.has(s)&&qt.remove(s)}),e||qt.set(s,n),n}function rd(i,e=!1){return typeof i=="string"?qt.get(i):i instanceof de?new W({source:i}):id(i,e)}W.from=rd;de.from=sd;q.add(jo,Xo,qo,td,di,Ve,gr);var Yo=(i=>(i[i.Low=0]="Low",i[i.Normal=1]="Normal",i[i.High=2]="High",i))(Yo||{});function et(i){if(typeof i!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(i)}`)}function Ns(i){return i.split("?")[0].split("#")[0]}function f_(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p_(i,e,t){return i.replace(new RegExp(f_(e),"g"),t)}function m_(i,e){let t="",s=0,r=-1,n=0,o=-1;for(let a=0;a<=i.length;++a){if(a<i.length)o=i.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(r===a-1||n===1))if(r!==a-1&&n===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){const l=t.lastIndexOf("/");if(l!==t.length-1){l===-1?(t="",s=0):(t=t.slice(0,l),s=t.length-1-t.lastIndexOf("/")),r=a,n=0;continue}}else if(t.length===2||t.length===1){t="",s=0,r=a,n=0;continue}}}else t.length>0?t+=`/${i.slice(r+1,a)}`:t=i.slice(r+1,a),s=a-r-1;r=a,n=0}else o===46&&n!==-1?++n:n=-1}return t}const Ms={toPosix(i){return p_(i,"\\","/")},isUrl(i){return/^https?:/.test(this.toPosix(i))},isDataUrl(i){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(i)},isBlobUrl(i){return i.startsWith("blob:")},hasProtocol(i){return/^[^/:]+:/.test(this.toPosix(i))},getProtocol(i){et(i),i=this.toPosix(i);const e=/^file:\/\/\//.exec(i);if(e)return e[0];const t=/^[^/:]+:\/{0,2}/.exec(i);return t?t[0]:""},toAbsolute(i,e,t){if(et(i),this.isDataUrl(i)||this.isBlobUrl(i))return i;const s=Ns(this.toPosix(e??ee.get().getBaseUrl())),r=Ns(this.toPosix(t??this.rootname(s)));return i=this.toPosix(i),i.startsWith("/")?Ms.join(r,i.slice(1)):this.isAbsolute(i)?i:this.join(s,i)},normalize(i){if(et(i),i.length===0)return".";if(this.isDataUrl(i)||this.isBlobUrl(i))return i;i=this.toPosix(i);let e="";const t=i.startsWith("/");this.hasProtocol(i)&&(e=this.rootname(i),i=i.slice(e.length));const s=i.endsWith("/");return i=m_(i),i.length>0&&s&&(i+="/"),t?`/${i}`:e+i},isAbsolute(i){return et(i),i=this.toPosix(i),this.hasProtocol(i)?!0:i.startsWith("/")},join(...i){if(i.length===0)return".";let e;for(let t=0;t<i.length;++t){const s=i[t];if(et(s),s.length>0)if(e===void 0)e=s;else{const r=i[t-1]??"";this.joinExtensions.includes(this.extname(r).toLowerCase())?e+=`/../${s}`:e+=`/${s}`}}return e===void 0?".":this.normalize(e)},dirname(i){if(et(i),i.length===0)return".";i=this.toPosix(i);let e=i.charCodeAt(0);const t=e===47;let s=-1,r=!0;const n=this.getProtocol(i),o=i;i=i.slice(n.length);for(let a=i.length-1;a>=1;--a)if(e=i.charCodeAt(a),e===47){if(!r){s=a;break}}else r=!1;return s===-1?t?"/":this.isUrl(o)?n+i:n:t&&s===1?"//":n+i.slice(0,s)},rootname(i){et(i),i=this.toPosix(i);let e="";if(i.startsWith("/")?e="/":e=this.getProtocol(i),this.isUrl(i)){const t=i.indexOf("/",e.length);t!==-1?e=i.slice(0,t):e=i,e.endsWith("/")||(e+="/")}return e},basename(i,e){et(i),e&&et(e),i=Ns(this.toPosix(i));let t=0,s=-1,r=!0,n;if(e!==void 0&&e.length>0&&e.length<=i.length){if(e.length===i.length&&e===i)return"";let o=e.length-1,a=-1;for(n=i.length-1;n>=0;--n){const l=i.charCodeAt(n);if(l===47){if(!r){t=n+1;break}}else a===-1&&(r=!1,a=n+1),o>=0&&(l===e.charCodeAt(o)?--o===-1&&(s=n):(o=-1,s=a))}return t===s?s=a:s===-1&&(s=i.length),i.slice(t,s)}for(n=i.length-1;n>=0;--n)if(i.charCodeAt(n)===47){if(!r){t=n+1;break}}else s===-1&&(r=!1,s=n+1);return s===-1?"":i.slice(t,s)},extname(i){et(i),i=Ns(this.toPosix(i));let e=-1,t=0,s=-1,r=!0,n=0;for(let o=i.length-1;o>=0;--o){const a=i.charCodeAt(o);if(a===47){if(!r){t=o+1;break}continue}s===-1&&(r=!1,s=o+1),a===46?e===-1?e=o:n!==1&&(n=1):e!==-1&&(n=-1)}return e===-1||s===-1||n===0||n===1&&e===s-1&&e===t+1?"":i.slice(e,s)},parse(i){et(i);const e={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return e;i=Ns(this.toPosix(i));let t=i.charCodeAt(0);const s=this.isAbsolute(i);let r;e.root=this.rootname(i),s||this.hasProtocol(i)?r=1:r=0;let n=-1,o=0,a=-1,l=!0,h=i.length-1,c=0;for(;h>=r;--h){if(t=i.charCodeAt(h),t===47){if(!l){o=h+1;break}continue}a===-1&&(l=!1,a=h+1),t===46?n===-1?n=h: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&&s?e.base=e.name=i.slice(1,a):e.base=e.name=i.slice(o,a)):(o===0&&s?(e.name=i.slice(1,n),e.base=i.slice(1,a)):(e.name=i.slice(o,n),e.base=i.slice(o,a)),e.ext=i.slice(n,a)),e.dir=this.dirname(i),e},sep:"/",delimiter:":",joinExtensions:[".html"]};function nd(i,e,t,s,r){const n=e[t];for(let o=0;o<n.length;o++){const a=n[o];t<e.length-1?nd(i.replace(s[t],a),e,t+1,s,r):r.push(i.replace(s[t],a))}}function od(i){const e=/\{(.*?)\}/g,t=i.match(e),s=[];if(t){const r=[];t.forEach(n=>{const o=n.substring(1,n.length-1).split(",");r.push(o)}),nd(i,r,0,t,s)}else s.push(i);return s}const Wn=i=>!Array.isArray(i);class Ko{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(e,t)=>`${e}${this._bundleIdConnector}${t}`,extractAssetIdFromBundle:(e,t)=>t.replace(`${e}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(e){if(this._bundleIdConnector=e.connector??this._bundleIdConnector,this._createBundleAssetId=e.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=e.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...e){e.forEach(t=>{this._preferredOrder.push(t),t.priority||(t.priority=Object.keys(t.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(e){if(typeof e=="string")this._defaultSearchParams=e;else{const t=e;this._defaultSearchParams=Object.keys(t).map(s=>`${encodeURIComponent(s)}=${encodeURIComponent(t[s])}`).join("&")}}getAlias(e){const{alias:t,src:s}=e;return Xt(t||s,n=>typeof n=="string"?n:Array.isArray(n)?n.map(o=>o?.src??o):n?.src?n.src:n,!0)}removeAlias(e,t){this._assetMap[e]&&(t&&t!==this._resolverHash[e]||(delete this._resolverHash[e],delete this._assetMap[e]))}addManifest(e){this._manifest&&z("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=e,e.bundles.forEach(t=>{this.addBundle(t.name,t.assets)})}addBundle(e,t){const s=[];let r=t;Array.isArray(t)||(r=Object.entries(t).map(([n,o])=>typeof o=="string"||Array.isArray(o)?{alias:n,src:o}:{alias:n,...o})),r.forEach(n=>{const o=n.src,a=n.alias;let l;if(typeof a=="string"){const h=this._createBundleAssetId(e,a);s.push(h),l=[a,h]}else{const h=a.map(c=>this._createBundleAssetId(e,c));s.push(...h),l=[...a,...h]}this.add({...n,alias:l,src:o})}),this._bundles[e]=s}add(e){const t=[];Array.isArray(e)?t.push(...e):t.push(e);let s;s=n=>{this.hasKey(n)&&z(`[Resolver] already has key: ${n} overwriting`)},Xt(t).forEach(n=>{const{src:o}=n;let{data:a,format:l,loadParser:h,parser:c}=n;const u=Xt(o).map(g=>typeof g=="string"?od(g):Array.isArray(g)?g:[g]),d=this.getAlias(n);Array.isArray(d)?d.forEach(s):s(d);const f=[],p=g=>{const m=this._parsers.find(_=>_.test(g));return{src:g,...m?.parse(g)}};u.forEach(g=>{g.forEach(m=>{let _={};if(typeof m!="object"?_=p(m):(a=m.data??a,l=m.format??l,(m.loadParser||m.parser)&&(h=m.loadParser??h,c=m.parser??c),_={...p(m.src),...m}),!d)throw new Error(`[Resolver] alias is undefined for this asset: ${_.src}`);_=this._buildResolvedAsset(_,{aliases:d,data:a,format:l,loadParser:h,parser:c,progressSize:n.progressSize}),f.push(_)})}),d.forEach(g=>{this._assetMap[g]=f})})}resolveBundle(e){const t=Wn(e);e=Xt(e);const s={};return e.forEach(r=>{const n=this._bundles[r];if(n){const o=this.resolve(n),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(r,l)]=h}s[r]=a}}),t?s[e[0]]:s}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const s={};for(const r in t)s[r]=t[r].src;return s}return t.src}resolve(e){const t=Wn(e);e=Xt(e);const s={};return e.forEach(r=>{if(!this._resolverHash[r])if(this._assetMap[r]){let n=this._assetMap[r];const o=this._getPreferredOrder(n);o?.priority.forEach(a=>{o.params[a].forEach(l=>{const h=n.filter(c=>c[a]?c[a]===l:!1);h.length&&(n=h)})}),this._resolverHash[r]=n[0]}else this._resolverHash[r]=this._buildResolvedAsset({alias:[r],src:r},{});s[r]=this._resolverHash[r]}),t?s[e[0]]:s}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const s=e[t],r=this._preferredOrder.find(n=>n.params.format.includes(s.format));if(r)return r}return this._preferredOrder[0]}_appendDefaultSearchParams(e){if(!this._defaultSearchParams)return e;const t=/\?/.test(e)?"&":"?";return`${e}${t}${this._defaultSearchParams}`}_buildResolvedAsset(e,t){const{aliases:s,data:r,loadParser:n,parser:o,format:a,progressSize:l}=t;return(this._basePath||this._rootPath)&&(e.src=Ms.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=s??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...r||{},...e.data},e.loadParser=n??e.loadParser,e.parser=o??e.parser,e.format=a??e.format??ad(e.src),l!==void 0&&(e.progressSize=l),e}}Ko.RETINA_PREFIX=/@([0-9\.]+)x/;function ad(i){return i.split(".").pop().split("?").shift().split("#").shift()}const $n=(i,e)=>{const t=e.split("?")[1];return t&&(i+=`?${t}`),i},ld=class Qs{constructor(e,t){this.linkedSheets=[];let s=e;e?.source instanceof de&&(s={texture:e,data:t});const{texture:r,data:n,cachePrefix:o=""}=s;this.cachePrefix=o,this._texture=r instanceof W?r:null,this.textureSource=r.source,this.textures={},this.animations={},this.data=n;const a=parseFloat(n.meta.scale);a?(this.resolution=a,r.source.resolution=this.resolution):this.resolution=r.source._resolution,this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}parse(){return new Promise(e=>{this._callback=e,this._batchIndex=0,this._frameKeys.length<=Qs.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(e,t=!1){let s=e;const r=t?1/0:Qs.BATCH_SIZE;for(;s-e<r&&s<this._frameKeys.length;){const n=this._frameKeys[s],o=this._frames[n],a=o.frame;if(a){let l=null,h=null;const c=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,u=new te(0,0,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution);o.rotated?l=new te(Math.floor(a.x)/this.resolution,Math.floor(a.y)/this.resolution,Math.floor(a.h)/this.resolution,Math.floor(a.w)/this.resolution):l=new te(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&&(h=new te(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 W({source:this.textureSource,frame:l,orig:u,trim:h,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:n.toString()})}s++}}_processAnimations(){const e=this.data.animations||{};for(const t in e){this.animations[t]=[];for(let s=0;s<e[t].length;s++){const r=e[t][s];this.animations[t].push(this.textures[r])}}}_parseComplete(){const e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*Qs.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*Qs.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(e=!1){for(const t in this.textures)this.textures[t].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,e&&(this._texture?.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};ld.BATCH_SIZE=1e3;let Vn=ld;const g_=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function hd(i,e,t){const s={};if(i.forEach(r=>{s[r]=e}),Object.keys(e.textures).forEach(r=>{s[`${e.cachePrefix}${r}`]=e.textures[r]}),!t){const r=Ms.dirname(i[0]);e.linkedSheets.forEach((n,o)=>{const a=hd([`${r}/${e.data.meta.related_multi_packs[o]}`],n,!0);Object.assign(s,a)})}return s}const cd={extension:S.Asset,cache:{test:i=>i instanceof Vn,getCacheableAssets:(i,e)=>hd(i,e,!1)},resolver:{extension:{type:S.ResolveParser,name:"resolveSpritesheet"},test:i=>{const t=i.split("?")[0].split("."),s=t.pop(),r=t.pop();return s==="json"&&g_.includes(r)},parse:i=>{const e=i.split(".");return{resolution:parseFloat(Ko.RETINA_PREFIX.exec(i)?.[1]??"1"),format:e[e.length-2],src:i}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:S.LoadParser,priority:Yo.Normal,name:"spritesheetLoader"},async testParse(i,e){return Ms.extname(e.src).toLowerCase()===".json"&&!!i.frames},async parse(i,e,t){const{texture:s,imageFilename:r,textureOptions:n,cachePrefix:o}=e?.data??{};let a=Ms.dirname(e.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let l;if(s instanceof W)l=s;else{const u=$n(a+(r??i.meta.image),e.src);l=(await t.load([{src:u,data:n}]))[u]}const h=new Vn({texture:l.source,data:i,cachePrefix:o});await h.parse();const c=i?.meta?.related_multi_packs;if(Array.isArray(c)){const u=[];for(const f of c){if(typeof f!="string")continue;let p=a+f;e.data?.ignoreMultiPack||(p=$n(p,e.src),u.push(t.load({src:p,data:{textureOptions:n,ignoreMultiPack:!0}})))}const d=await Promise.all(u);h.linkedSheets=d,d.forEach(f=>{f.linkedSheets=[h].concat(h.linkedSheets.filter(p=>p!==f))})}return h},async unload(i,e,t){await t.unload(i.textureSource._sourceOrigin),i.destroy(!1)}}};q.add(cd);class Zo{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),s=this._canvas.width,r=this._canvas.height,n=t.width/s*this._renderer.resolution,o=t.height/r*this._renderer.resolution,a=t.left,l=t.top,h=`translate(${a}px, ${l}px) scale(${n}, ${o})`;h!==this._lastTransform&&(this._domElement.style.transform=h,this._lastTransform=h)},this._domElement=e.domElement,this._renderer=e.renderer,!(globalThis.OffscreenCanvas&&this._renderer.canvas instanceof OffscreenCanvas)&&(this._canvas=this._renderer.canvas,this._attachObserver())}get canvas(){return this._canvas}ensureAttached(){!this._domElement.parentNode&&this._canvas.parentNode&&(this._canvas.parentNode.appendChild(this._domElement),this.updateTranslation())}_attachObserver(){"ResizeObserver"in globalThis?(this._observer&&(this._observer.disconnect(),this._observer=null),this._observer=new ResizeObserver(e=>{for(const t of e){if(t.target!==this._canvas)continue;const s=this.canvas.width,r=this.canvas.height,n=t.contentRect.width/s*this._renderer.resolution,o=t.contentRect.height/r*this._renderer.resolution;(this._lastScaleX!==n||this._lastScaleY!==o)&&(this.updateTranslation(),this._lastScaleX=n,this._lastScaleY=o)}}),this._observer.observe(this._canvas)):this._tickerAttached||We.shared.add(this.updateTranslation,this,is.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&We.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 Gs{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=Gs.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new he,this.page=new he,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=e}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(e,t,s){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,s,r,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 cn=/iPhone/i,Dh=/iPod/i,Fh=/iPad/i,Oh=/\biOS-universal(?:.+)Mac\b/i,un=/\bAndroid(?:.+)Mobile\b/i,Lh=/Android/i,cs=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ai=/Silk/i,yt=/Windows Phone/i,Uh=/\bWindows(?:.+)ARM\b/i,Nh=/BlackBerry/i,Hh=/BB10/i,zh=/Opera Mini/i,Wh=/\b(CriOS|Chrome)(?:.+)Mobile/i,$h=/Mobile(?:.+)Firefox\b/i,Vh=function(i){return typeof i<"u"&&i.platform==="MacIntel"&&typeof i.maxTouchPoints=="number"&&i.maxTouchPoints>1&&typeof MSStream>"u"};function __(i){return function(e){return e.test(i)}}function jh(i){var e={userAgent:"",platform:"",maxTouchPoints:0};!i&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof i=="string"?e.userAgent=i:i&&i.userAgent&&(e={userAgent:i.userAgent,platform:i.platform,maxTouchPoints:i.maxTouchPoints||0});var t=e.userAgent,s=t.split("[FBAN");typeof s[1]<"u"&&(t=s[0]),s=t.split("Twitter"),typeof s[1]<"u"&&(t=s[0]);var r=__(t),n={apple:{phone:r(cn)&&!r(yt),ipod:r(Dh),tablet:!r(cn)&&(r(Fh)||Vh(e))&&!r(yt),universal:r(Oh),device:(r(cn)||r(Dh)||r(Fh)||r(Oh)||Vh(e))&&!r(yt)},amazon:{phone:r(cs),tablet:!r(cs)&&r(Ai),device:r(cs)||r(Ai)},android:{phone:!r(yt)&&r(cs)||!r(yt)&&r(un),tablet:!r(yt)&&!r(cs)&&!r(un)&&(r(Ai)||r(Lh)),device:!r(yt)&&(r(cs)||r(Ai)||r(un)||r(Lh))||r(/\bokhttp\b/i)},windows:{phone:r(yt),tablet:r(Uh),device:r(yt)||r(Uh)},other:{blackberry:r(Nh),blackberry10:r(Hh),opera:r(zh),firefox:r($h),chrome:r(Wh),device:r(Nh)||r(Hh)||r(zh)||r($h)||r(Wh)},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 y_=jh.default??jh,ud=y_(globalThis.navigator),x_=9,Xh=100,b_=0,v_=0,qh=2,Yh=1,w_=-1e3,T_=-1e3,S_=2,Qo=class dd{constructor(e,t=ud){this._mobileInfo=t,this.debug=!1,this._activateOnTab=!0,this._deactivateOnMouseMove=!0,this._isActive=!1,this._isMobileAccessibility=!1,this._div=null,this._pools={},this._renderId=0,this._children=[],this._androidUpdateCount=0,this._androidUpdateFrequency=500,this._isRunningTests=!1,this._boundOnKeyDown=this._onKeyDown.bind(this),this._boundOnMouseMove=this._onMouseMove.bind(this),this._hookDiv=null,(t.tablet||t.phone)&&this._createTouchHook(),this._renderer=e}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}get hookDiv(){return this._hookDiv}get div(){return this._div}_createTouchHook(){const e=document.createElement("button");e.style.width=`${Yh}px`,e.style.height=`${Yh}px`,e.style.position="absolute",e.style.top=`${w_}px`,e.style.left=`${T_}px`,e.style.zIndex=S_.toString(),e.style.backgroundColor="#FF0000",e.title="select to enable accessibility for this content",e.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this._activate(),this._destroyTouchHook()}),document.body.appendChild(e),this._hookDiv=e}_destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}_activate(){if(this._isActive)return;this._isActive=!0,this._div||(this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.top=`${b_}px`,this._div.style.left=`${v_}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=qh.toString(),this._canvasObserver=new Zo({domElement:this._div,renderer:this._renderer})),this._deactivateOnMouseMove&&globalThis.document.addEventListener("mousemove",this._boundOnMouseMove,!0);const e=this._renderer.view.canvas;if(e.parentNode)this._canvasObserver.ensureAttached(),this._initAccessibilitySetup();else{const t=new MutationObserver(()=>{e.parentNode&&(t.disconnect(),this._canvasObserver.ensureAttached(),this._initAccessibilitySetup())});t.observe(document.body,{childList:!0,subtree:!0})}}_initAccessibilitySetup(){this._renderer.runners.postrender.add(this),this._renderer.lastObjectRendered&&this._updateAccessibleObjects(this._renderer.lastObjectRendered)}_deactivate(){if(!(!this._isActive||this._isMobileAccessibility)){this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._renderer.runners.postrender.remove(this);for(const e of this._children)e._accessibleDiv?.parentNode&&(e._accessibleDiv.parentNode.removeChild(e._accessibleDiv),e._accessibleDiv=null),e._accessibleActive=!1;for(const e in this._pools)this._pools[e].forEach(s=>{s.parentNode&&s.parentNode.removeChild(s)}),delete this._pools[e];this._div?.parentNode&&this._div.parentNode.removeChild(this._div),this._pools={},this._children=[]}}_updateAccessibleObjects(e){if(!e.visible||!e.accessibleChildren)return;e.accessible&&(e._accessibleActive||this._addChild(e),e._renderId=this._renderId);const t=e.children;if(t)for(let s=0;s<t.length;s++)this._updateAccessibleObjects(t[s])}init(e){const s={accessibilityOptions:{...dd.defaultOptions,...e?.accessibilityOptions||{}}};this.debug=s.accessibilityOptions.debug,this._activateOnTab=s.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=s.accessibilityOptions.deactivateOnMouseMove,this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),s.accessibilityOptions.enabledByDefault&&this._activate(),this._renderer.runners.postrender.remove(this)}postrender(){const e=performance.now();if(this._mobileInfo.android.device&&e<this._androidUpdateCount||(this._androidUpdateCount=e+this._androidUpdateFrequency,(!this._renderer.renderingToScreen||!this._renderer.view.canvas)&&!this._isRunningTests))return;const t=new Set;if(this._renderer.lastObjectRendered){this._updateAccessibleObjects(this._renderer.lastObjectRendered);for(const s of this._children)s._renderId===this._renderId&&t.add(this._children.indexOf(s))}for(let s=this._children.length-1;s>=0;s--){const r=this._children[s];t.has(s)||(r._accessibleDiv&&r._accessibleDiv.parentNode&&(r._accessibleDiv.parentNode.removeChild(r._accessibleDiv),this._getPool(r.accessibleType).push(r._accessibleDiv),r._accessibleDiv=null),r._accessibleActive=!1,Ho(this._children,s,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let s=0;s<this._children.length;s++){const r=this._children[s];if(!r._accessibleActive||!r._accessibleDiv)continue;const n=r._accessibleDiv,o=r.hitArea||r.getBounds().rectangle;if(r.hitArea){const a=r.worldTransform;n.style.left=`${a.tx+o.x*a.a}px`,n.style.top=`${a.ty+o.y*a.d}px`,n.style.width=`${o.width*a.a}px`,n.style.height=`${o.height*a.d}px`}else this._capHitArea(o),n.style.left=`${o.x}px`,n.style.top=`${o.y}px`,n.style.width=`${o.width}px`,n.style.height=`${o.height}px`}this._renderId++}_updateDebugHTML(e){e.innerHTML=`type: ${e.type}</br> title : ${e.title}</br> tabIndex: ${e.tabIndex}`}_capHitArea(e){e.x<0&&(e.width+=e.x,e.x=0),e.y<0&&(e.height+=e.y,e.y=0);const{width:t,height:s}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>s&&(e.height=s-e.y)}_addChild(e){let s=this._getPool(e.accessibleType).pop();s?(s.innerHTML="",s.removeAttribute("title"),s.removeAttribute("aria-label"),s.tabIndex=0):(e.accessibleType==="button"?(s=document.createElement("button"),this.debug||(s.style.color="transparent")):(s=document.createElement(e.accessibleType),s.style.cssText=`
5
+ `),n?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",r),console.warn(s),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",r),console.warn(s))),wh.add(e)});Object.defineProperties(z,{quiet:{get:()=>Cs.quiet,set:i=>{Cs.quiet=i},enumerable:!0,configurable:!1},noColor:{get:()=>Cs.noColor,set:i=>{Cs.noColor=i},enumerable:!0,configurable:!1}});const $o=()=>{};function or(i){return i.endsWith("int")}function is(i){return i+=i===0?1:0,--i,i|=i>>>1,i|=i>>>2,i|=i>>>4,i|=i>>>8,i|=i>>>16,i+1}function rs(i){return!(i&i-1)&&!!i}function Vo(i){const e={};for(const t in i)i[t]!==void 0&&(e[t]=i[t]);return e}const Th=Object.create(null);function Kg(i){const e=Th[i];return e===void 0&&(Th[i]=oe("resource")),e}const Eu=class Pu extends Re{constructor(e={}){super(),this._resourceType="textureSampler",this._maxAnisotropy=1,this.destroyed=!1,e={...Pu.defaultOptions,...e},this.addressMode=e.addressMode,this.addressModeU=e.addressModeU??this.addressModeU,this.addressModeV=e.addressModeV??this.addressModeV,this.addressModeW=e.addressModeW??this.addressModeW,this.scaleMode=e.scaleMode,this.magFilter=e.magFilter??this.magFilter,this.minFilter=e.minFilter??this.minFilter,this.mipmapFilter=e.mipmapFilter??this.mipmapFilter,this.lodMinClamp=e.lodMinClamp,this.lodMaxClamp=e.lodMaxClamp,this.compare=e.compare,this.maxAnisotropy=e.maxAnisotropy??1}set addressMode(e){this.addressModeU=e,this.addressModeV=e,this.addressModeW=e}get addressMode(){return this.addressModeU}set wrapMode(e){z(de,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this._sharedResourceId=null,this.emit("change",this)}_generateResourceId(){const e=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=Kg(e),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};Eu.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let Ot=Eu;const Au=class Ru extends Re{constructor(e={}){super(),this.options=e,this._gpuData=Object.create(null),this._gcLastUsed=-1,this.uid=oe("textureSource"),this._resourceType="textureSource",this._resourceId=oe("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.depth=1,this._ownsStyle=!1,this.antialias=!1,this.transient=!1,this.storage=!1,this._batchTick=-1,this._textureBindLocation=-1;const t=e;e={...Ru.defaultOptions,...e};const s=Zg(e),r=s==="3d"||s==="1d"?s:"2d";Qg(t,s,r),this.label=e.label??"",this.resource=e.resource,this.autoGarbageCollect=e.autoGarbageCollect,this._resolution=e.resolution,e.width?this.pixelWidth=e.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,e.height?this.pixelHeight=e.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=e.format,this.dimension=r,this.viewDimension=s,this.arrayLayerCount=e.arrayLayerCount,this.depth=r==="3d"?e.depth??1:1,this.mipLevelCount=e.mipLevelCount,this.autoGenerateMipmaps=e.autoGenerateMipmaps,this.sampleCount=e.sampleCount,this.antialias=r==="3d"?!1:e.antialias,this.transient=e.transient??!1,this.storage=e.storage??!1,this.alphaMode=e.alphaMode,this.style=new Ot(Vo(e)),this._ownsStyle=!0,this.destroyed=!1,this._refreshPOT()}get depthOrArrayLayers(){return this.dimension==="3d"?this.depth:this.arrayLayerCount||1}get source(){return this}get style(){return this._style}set style(e){this.style!==e&&(this._ownsStyle=!1,this._style?.off("change",this._onStyleChange,this),this._style=e,this._style?.on("change",this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(e){this._style.maxAnisotropy=e}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(e){this._style.addressMode=e}get repeatMode(){return this._style.addressMode}set repeatMode(e){this._style.addressMode=e}get magFilter(){return this._style.magFilter}set magFilter(e){this._style.magFilter=e}get minFilter(){return this._style.minFilter}set minFilter(e){this._style.minFilter=e}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(e){this._style.mipmapFilter=e}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(e){this._style.lodMinClamp=e}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(e){this._style.lodMaxClamp=e}_onStyleChange(){this.emit("styleChange",this)}update(){if(this.resource){const e=this._resolution;if(this.resize(this.resourceWidth/e,this.resourceHeight/e))return}this.emit("update",this)}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this._style&&(this._ownsStyle&&this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=oe("resource"),this.emit("change",this),this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy?.();this._gpuData=Object.create(null)}get resourceWidth(){const{resource:e}=this;return e.naturalWidth||e.videoWidth||e.displayWidth||e.width}get resourceHeight(){const{resource:e}=this;return e.naturalHeight||e.videoHeight||e.displayHeight||e.height}get resolution(){return this._resolution}set resolution(e){this._resolution!==e&&(this._resolution=e,this.width=this.pixelWidth/e,this.height=this.pixelHeight/e)}resize(e,t,s){s||(s=this._resolution),e||(e=this.width),t||(t=this.height);const r=Math.round(e*s),n=Math.round(t*s);return this.width=r/s,this.height=n/s,this._resolution=s,this.pixelWidth===r&&this.pixelHeight===n?!1:(this._refreshPOT(),this.pixelWidth=r,this.pixelHeight=n,this.emit("resize",this),this._resourceId=oe("resource"),this.emit("change",this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit("updateMipmaps",this)}set wrapMode(e){this._style.wrapMode=e}get wrapMode(){return this._style.wrapMode}set scaleMode(e){this._style.scaleMode=e}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=rs(this.pixelWidth)&&rs(this.pixelHeight)}static test(e){throw new Error("Unimplemented")}};Au.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",arrayLayerCount:1,mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let ue=Au;function Zg(i){return i.viewDimension?i.viewDimension:i.depth?"3d":i.arrayLayerCount>1?"2d-array":"2d"}function Qg(i,e,t){if(i.depth!==void 0&&typeof i.depth!="number")throw new Error(`[TextureSource] depth is a 3D texture's depth in texels, but got ${i.depth}. For a depth buffer, use the depth option of a RenderTarget or the renderer.`);if(i.depth&&i.arrayLayerCount>1)throw new Error("[TextureSource] depth and arrayLayerCount can't be combined: use depth for a 3D texture or arrayLayerCount for a 2D array.");if(i.depth&&e!=="3d")throw new Error(`[TextureSource] depth makes a 3D texture, but viewDimension is '${e}'. Use arrayLayerCount for layered textures.`);if(e==="3d"&&i.arrayLayerCount>1)throw new Error("[TextureSource] a 3D texture takes depth, not arrayLayerCount.");if(i.dimensions&&i.dimensions!==t)throw new Error(`[TextureSource] dimensions '${i.dimensions}' doesn't match viewDimension '${e}'. Leave dimensions out; it is derived from the view.`);if(i.dimensions&&z(ku,"TextureSource dimensions is derived from viewDimension and depth; leave it out."),t==="3d"&&i.antialias)throw new Error("[TextureSource] a 3D texture can't be antialiased: WebGPU has no multisampled 3D textures.")}class xr extends ue{constructor(e){const t=e.depth??e.arrayLayerCount??1,s=e.resource||new Float32Array(e.width*e.height*t*4);let r=e.format;r||(s instanceof Float32Array?r="rgba32float":s instanceof Int32Array||s instanceof Uint32Array?r="rgba32uint":s instanceof Int16Array||s instanceof Uint16Array?r="rgba16uint":(s instanceof Int8Array,r="bgra8unorm"));const n=or(r)||t>1;super({...n&&{alphaMode:"no-premultiply-alpha"},...e,resource:s,format:r}),this.uploadMethodId="buffer",this._updateStart=0,this._updateEnd=1/0}update(e=0,t=1/0){if((e>0||t<1/0)&&this.depthOrArrayLayers>1)throw new Error("[BufferImageSource] a 3D texture or 2D array uploads whole: call update() with no range.");this._updateStart=e,this._updateEnd=t,super.update(),this._updateStart=0,this._updateEnd=1/0}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}xr.extension=S.TextureSource;const Sh=new U;class jo{constructor(e,t){this.mapCoord=new U,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._updateID=0,this.clampOffset=0,typeof t>"u"?this.clampMargin=e.width<10?0:.5:this.clampMargin=t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture?.removeListener("update",this.update,this),this._texture=e,this._texture.addListener("update",this.update,this)),this.update()}destroy(){this._texture?.removeListener("update",this.update,this),this._texture=null}multiplyUvs(e,t){t===void 0&&(t=e);const s=this.mapCoord;for(let r=0;r<e.length;r+=2){const n=e[r],o=e[r+1];t[r]=n*s.a+o*s.c+s.tx,t[r+1]=n*s.b+o*s.d+s.ty}return t}update(){const e=this._texture;this._updateID++;const t=e.uvs;this.mapCoord.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0);const s=e.orig,r=e.trim;r&&(Sh.set(s.width/r.width,0,0,s.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(Sh));const n=e.source,o=this.uClampFrame,a=this.clampMargin/n._resolution,l=this.clampOffset/n._resolution;return o[0]=(e.frame.x+a+l)/n.width,o[1]=(e.frame.y+a+l)/n.height,o[2]=(e.frame.x+e.frame.width-a+l)/n.width,o[3]=(e.frame.y+e.frame.height-a+l)/n.height,this.uClampOffset[0]=this.clampOffset/n.pixelWidth,this.uClampOffset[1]=this.clampOffset/n.pixelHeight,this.isSimple=e.frame.width===n.width&&e.frame.height===n.height&&e.rotate===0,!0}}class W extends Re{constructor({source:e,label:t,frame:s,orig:r,trim:n,defaultAnchor:o,defaultBorders:a,rotate:l,dynamic:h}={}){if(super(),this.uid=oe("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new te,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=e?.source??new ue,this.noFrame=!s,s)this.frame.copyFrom(s);else{const{width:c,height:u}=this._source;this.frame.width=c,this.frame.height=u}this.orig=r||this.frame,this.trim=n,this.rotate=l??0,this.defaultAnchor=o,this.defaultBorders=a,this.destroyed=!1,this.dynamic=h||!1,this.updateUvs()}set source(e){this._source&&this._source.off("resize",this.update,this),this._source=e,e.on("resize",this.update,this),this.emit("update",this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||(this._textureMatrix=new jo(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:e,frame:t}=this,{width:s,height:r}=this._source,n=t.x/s,o=t.y/r,a=t.width/s,l=t.height/r;let h=this.rotate;if(h){const c=a/2,u=l/2,d=n+c,f=o+u;h=Z.add(h,Z.NW),e.x0=d+c*Z.uX(h),e.y0=f+u*Z.uY(h),h=Z.add(h,2),e.x1=d+c*Z.uX(h),e.y1=f+u*Z.uY(h),h=Z.add(h,2),e.x2=d+c*Z.uX(h),e.y2=f+u*Z.uY(h),h=Z.add(h,2),e.x3=d+c*Z.uX(h),e.y3=f+u*Z.uY(h)}else e.x0=n,e.y0=o,e.x1=n+a,e.y1=o,e.x2=n+a,e.y2=o+l,e.x3=n,e.y3=o+l}destroy(e=!1){this._source&&(this._source.off("resize",this.update,this),e&&(this._source.destroy(),this._source=null)),this._textureMatrix=null,this.destroyed=!0,this.emit("destroy",this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit("update",this)}get baseTexture(){return z(de,"Texture.baseTexture is now Texture.source"),this._source}}W.EMPTY=new W({label:"EMPTY",source:new ue({label:"EMPTY"})});W.EMPTY.destroy=$o;W.WHITE=new W({source:new xr({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"});W.WHITE.destroy=$o;function Xo(i,e,t){const{width:s,height:r}=t.orig,n=t.trim;if(n){const o=n.width,a=n.height;i.minX=n.x-e._x*s,i.maxX=i.minX+o,i.minY=n.y-e._y*r,i.maxY=i.minY+a}else i.minX=-e._x*s,i.maxX=i.minX+s,i.minY=-e._y*r,i.maxY=i.minY+r}const Ch=new U;class Ee{constructor(e=1/0,t=1/0,s=-1/0,r=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Ch,this.minX=e,this.minY=t,this.maxX=s,this.maxY=r}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new te);const e=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(e.x=0,e.y=0,e.width=0,e.height=0):e.copyFromBounds(this),e}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=Ch,this}set(e,t,s,r){this.minX=e,this.minY=t,this.maxX=s,this.maxY=r}addFrame(e,t,s,r,n){n||(n=this.matrix);const o=n.a,a=n.b,l=n.c,h=n.d,c=n.tx,u=n.ty;let d=this.minX,f=this.minY,p=this.maxX,g=this.maxY,m=o*e+l*t+c,_=a*e+h*t+u;m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*s+l*t+c,_=a*s+h*t+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*e+l*r+c,_=a*e+h*r+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),m=o*s+l*r+c,_=a*s+h*r+u,m<d&&(d=m),_<f&&(f=_),m>p&&(p=m),_>g&&(g=_),this.minX=d,this.minY=f,this.maxX=p,this.maxY=g}addRect(e,t){this.addFrame(e.x,e.y,e.x+e.width,e.y+e.height,t)}addBounds(e,t){this.addFrame(e.minX,e.minY,e.maxX,e.maxY,t)}addBoundsMask(e){this.minX=this.minX>e.minX?this.minX:e.minX,this.minY=this.minY>e.minY?this.minY:e.minY,this.maxX=this.maxX<e.maxX?this.maxX:e.maxX,this.maxY=this.maxY<e.maxY?this.maxY:e.maxY}applyMatrix(e){const t=this.minX,s=this.minY,r=this.maxX,n=this.maxY,{a:o,b:a,c:l,d:h,tx:c,ty:u}=e;let d=o*t+l*s+c,f=a*t+h*s+u;this.minX=d,this.minY=f,this.maxX=d,this.maxY=f,d=o*r+l*s+c,f=a*r+h*s+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=o*t+l*n+c,f=a*t+h*n+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=o*r+l*n+c,f=a*r+h*n+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY}fit(e){return this.minX<e.left&&(this.minX=e.left),this.maxX>e.right&&(this.maxX=e.right),this.minY<e.top&&(this.minY=e.top),this.maxY>e.bottom&&(this.maxY=e.bottom),this}fitBounds(e,t,s,r){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<s&&(this.minY=s),this.maxY>r&&(this.maxY=r),this}pad(e,t=e){return this.minX-=e,this.maxX+=e,this.minY-=t,this.maxY+=t,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new Ee(this.minX,this.minY,this.maxX,this.maxY)}scale(e,t=e){return this.minX*=e,this.minY*=t,this.maxX*=e,this.maxY*=t,this}get x(){return this.minX}set x(e){const t=this.maxX-this.minX;this.minX=e,this.maxX=e+t}get y(){return this.minY}set y(e){const t=this.maxY-this.minY;this.minY=e,this.maxY=e+t}get width(){return this.maxX-this.minX}set width(e){this.maxX=this.minX+e}get height(){return this.maxY-this.minY}set height(e){this.maxY=this.minY+e}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(e,t,s,r){let n=this.minX,o=this.minY,a=this.maxX,l=this.maxY;r||(r=this.matrix);const h=r.a,c=r.b,u=r.c,d=r.d,f=r.tx,p=r.ty;for(let g=t;g<s;g+=2){const m=e[g],_=e[g+1],y=h*m+u*_+f,x=c*m+d*_+p;n=y<n?y:n,o=x<o?x:o,a=y>a?y:a,l=x>l?x:l}this.minX=n,this.minY=o,this.maxX=a,this.maxY=l}containsPoint(e,t){return this.minX<=e&&this.minY<=t&&this.maxX>=e&&this.maxY>=t}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(e){return this.minX=e.minX,this.minY=e.minY,this.maxX=e.maxX,this.maxY=e.maxY,this}}var Jg={grad:.9,turn:360,rad:360/(2*Math.PI)},bt=function(i){return typeof i=="string"?i.length>0:typeof i=="number"},Me=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=Math.pow(10,e)),Math.round(t*i)/t+0},Ye=function(i,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),i>t?t:i>e?i:e},Bu=function(i){return(i=isFinite(i)?i%360:0)>0?i:i+360},Mh=function(i){return{r:Ye(i.r,0,255),g:Ye(i.g,0,255),b:Ye(i.b,0,255),a:Ye(i.a)}},hn=function(i){return{r:Me(i.r),g:Me(i.g),b:Me(i.b),a:Me(i.a,3)}},e_=/^#([0-9a-f]{3,8})$/i,Ai=function(i){var e=i.toString(16);return e.length<2?"0"+e:e},Iu=function(i){var e=i.r,t=i.g,s=i.b,r=i.a,n=Math.max(e,t,s),o=n-Math.min(e,t,s),a=o?n===e?(t-s)/o:n===t?2+(s-e)/o:4+(e-t)/o:0;return{h:60*(a<0?a+6:a),s:n?o/n*100:0,v:n/255*100,a:r}},Gu=function(i){var e=i.h,t=i.s,s=i.v,r=i.a;e=e/360*6,t/=100,s/=100;var n=Math.floor(e),o=s*(1-t),a=s*(1-(e-n)*t),l=s*(1-(1-e+n)*t),h=n%6;return{r:255*[s,a,o,o,l,s][h],g:255*[l,s,s,a,o,o][h],b:255*[o,o,l,s,s,a][h],a:r}},kh=function(i){return{h:Bu(i.h),s:Ye(i.s,0,100),l:Ye(i.l,0,100),a:Ye(i.a)}},Eh=function(i){return{h:Me(i.h),s:Me(i.s),l:Me(i.l),a:Me(i.a,3)}},Ph=function(i){return Gu((t=(e=i).s,{h:e.h,s:(t*=((s=e.l)<50?s:100-s)/100)>0?2*t/(s+t)*100:0,v:s+t,a:e.a}));var e,t,s},si=function(i){return{h:(e=Iu(i)).h,s:(r=(200-(t=e.s))*(s=e.v)/100)>0&&r<200?t*s/100/(r<=100?r:200-r)*100:0,l:r/2,a:e.a};var e,t,s,r},t_=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,s_=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,i_=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,r_=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Xn={string:[[function(i){var e=e_.exec(i);return e?(i=e[1]).length<=4?{r:parseInt(i[0]+i[0],16),g:parseInt(i[1]+i[1],16),b:parseInt(i[2]+i[2],16),a:i.length===4?Me(parseInt(i[3]+i[3],16)/255,2):1}:i.length===6||i.length===8?{r:parseInt(i.substr(0,2),16),g:parseInt(i.substr(2,2),16),b:parseInt(i.substr(4,2),16),a:i.length===8?Me(parseInt(i.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(i){var e=i_.exec(i)||r_.exec(i);return e?e[2]!==e[4]||e[4]!==e[6]?null:Mh({r:Number(e[1])/(e[2]?100/255:1),g:Number(e[3])/(e[4]?100/255:1),b:Number(e[5])/(e[6]?100/255:1),a:e[7]===void 0?1:Number(e[7])/(e[8]?100:1)}):null},"rgb"],[function(i){var e=t_.exec(i)||s_.exec(i);if(!e)return null;var t,s,r=kh({h:(t=e[1],s=e[2],s===void 0&&(s="deg"),Number(t)*(Jg[s]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return Ph(r)},"hsl"]],object:[[function(i){var e=i.r,t=i.g,s=i.b,r=i.a,n=r===void 0?1:r;return bt(e)&&bt(t)&&bt(s)?Mh({r:Number(e),g:Number(t),b:Number(s),a:Number(n)}):null},"rgb"],[function(i){var e=i.h,t=i.s,s=i.l,r=i.a,n=r===void 0?1:r;if(!bt(e)||!bt(t)||!bt(s))return null;var o=kh({h:Number(e),s:Number(t),l:Number(s),a:Number(n)});return Ph(o)},"hsl"],[function(i){var e=i.h,t=i.s,s=i.v,r=i.a,n=r===void 0?1:r;if(!bt(e)||!bt(t)||!bt(s))return null;var o=(function(a){return{h:Bu(a.h),s:Ye(a.s,0,100),v:Ye(a.v,0,100),a:Ye(a.a)}})({h:Number(e),s:Number(t),v:Number(s),a:Number(n)});return Gu(o)},"hsv"]]},Ah=function(i,e){for(var t=0;t<e.length;t++){var s=e[t][0](i);if(s)return[s,e[t][1]]}return[null,void 0]},n_=function(i){return typeof i=="string"?Ah(i.trim(),Xn.string):typeof i=="object"&&i!==null?Ah(i,Xn.object):[null,void 0]},cn=function(i,e){var t=si(i);return{h:t.h,s:Ye(t.s+100*e,0,100),l:t.l,a:t.a}},un=function(i){return(299*i.r+587*i.g+114*i.b)/1e3/255},Rh=function(i,e){var t=si(i);return{h:t.h,s:t.s,l:Ye(t.l+100*e,0,100),a:t.a}},qn=(function(){function i(e){this.parsed=n_(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return i.prototype.isValid=function(){return this.parsed!==null},i.prototype.brightness=function(){return Me(un(this.rgba),2)},i.prototype.isDark=function(){return un(this.rgba)<.5},i.prototype.isLight=function(){return un(this.rgba)>=.5},i.prototype.toHex=function(){return e=hn(this.rgba),t=e.r,s=e.g,r=e.b,o=(n=e.a)<1?Ai(Me(255*n)):"","#"+Ai(t)+Ai(s)+Ai(r)+o;var e,t,s,r,n,o},i.prototype.toRgb=function(){return hn(this.rgba)},i.prototype.toRgbString=function(){return e=hn(this.rgba),t=e.r,s=e.g,r=e.b,(n=e.a)<1?"rgba("+t+", "+s+", "+r+", "+n+")":"rgb("+t+", "+s+", "+r+")";var e,t,s,r,n},i.prototype.toHsl=function(){return Eh(si(this.rgba))},i.prototype.toHslString=function(){return e=Eh(si(this.rgba)),t=e.h,s=e.s,r=e.l,(n=e.a)<1?"hsla("+t+", "+s+"%, "+r+"%, "+n+")":"hsl("+t+", "+s+"%, "+r+"%)";var e,t,s,r,n},i.prototype.toHsv=function(){return e=Iu(this.rgba),{h:Me(e.h),s:Me(e.s),v:Me(e.v),a:Me(e.a,3)};var e},i.prototype.invert=function(){return lt({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},i.prototype.saturate=function(e){return e===void 0&&(e=.1),lt(cn(this.rgba,e))},i.prototype.desaturate=function(e){return e===void 0&&(e=.1),lt(cn(this.rgba,-e))},i.prototype.grayscale=function(){return lt(cn(this.rgba,-1))},i.prototype.lighten=function(e){return e===void 0&&(e=.1),lt(Rh(this.rgba,e))},i.prototype.darken=function(e){return e===void 0&&(e=.1),lt(Rh(this.rgba,-e))},i.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},i.prototype.alpha=function(e){return typeof e=="number"?lt({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):Me(this.rgba.a,3);var t},i.prototype.hue=function(e){var t=si(this.rgba);return typeof e=="number"?lt({h:e,s:t.s,l:t.l,a:t.a}):Me(t.h)},i.prototype.isEqual=function(e){return this.toHex()===lt(e).toHex()},i})(),lt=function(i){return i instanceof qn?i:new qn(i)},Bh=[],o_=function(i){i.forEach(function(e){Bh.indexOf(e)<0&&(e(qn,Xn),Bh.push(e))})};function a_(i,e){var t={white:"#ffffff",bisque:"#ffe4c4",blue:"#0000ff",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",antiquewhite:"#faebd7",aqua:"#00ffff",azure:"#f0ffff",whitesmoke:"#f5f5f5",papayawhip:"#ffefd5",plum:"#dda0dd",blanchedalmond:"#ffebcd",black:"#000000",gold:"#ffd700",goldenrod:"#daa520",gainsboro:"#dcdcdc",cornsilk:"#fff8dc",cornflowerblue:"#6495ed",burlywood:"#deb887",aquamarine:"#7fffd4",beige:"#f5f5dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkkhaki:"#bdb76b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",peachpuff:"#ffdab9",darkmagenta:"#8b008b",darkred:"#8b0000",darkorchid:"#9932cc",darkorange:"#ff8c00",darkslateblue:"#483d8b",gray:"#808080",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",deeppink:"#ff1493",deepskyblue:"#00bfff",wheat:"#f5deb3",firebrick:"#b22222",floralwhite:"#fffaf0",ghostwhite:"#f8f8ff",darkviolet:"#9400d3",magenta:"#ff00ff",green:"#008000",dodgerblue:"#1e90ff",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",blueviolet:"#8a2be2",forestgreen:"#228b22",lawngreen:"#7cfc00",indianred:"#cd5c5c",indigo:"#4b0082",fuchsia:"#ff00ff",brown:"#a52a2a",maroon:"#800000",mediumblue:"#0000cd",lightcoral:"#f08080",darkturquoise:"#00ced1",lightcyan:"#e0ffff",ivory:"#fffff0",lightyellow:"#ffffe0",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",linen:"#faf0e6",mediumaquamarine:"#66cdaa",lemonchiffon:"#fffacd",lime:"#00ff00",khaki:"#f0e68c",mediumseagreen:"#3cb371",limegreen:"#32cd32",mediumspringgreen:"#00fa9a",lightskyblue:"#87cefa",lightblue:"#add8e6",midnightblue:"#191970",lightpink:"#ffb6c1",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",mintcream:"#f5fffa",lightslategray:"#778899",lightslategrey:"#778899",navajowhite:"#ffdead",navy:"#000080",mediumvioletred:"#c71585",powderblue:"#b0e0e6",palegoldenrod:"#eee8aa",oldlace:"#fdf5e6",paleturquoise:"#afeeee",mediumturquoise:"#48d1cc",mediumorchid:"#ba55d3",rebeccapurple:"#663399",lightsteelblue:"#b0c4de",mediumslateblue:"#7b68ee",thistle:"#d8bfd8",tan:"#d2b48c",orchid:"#da70d6",mediumpurple:"#9370db",purple:"#800080",pink:"#ffc0cb",skyblue:"#87ceeb",springgreen:"#00ff7f",palegreen:"#98fb98",red:"#ff0000",yellow:"#ffff00",slateblue:"#6a5acd",lavenderblush:"#fff0f5",peru:"#cd853f",palevioletred:"#db7093",violet:"#ee82ee",teal:"#008080",slategray:"#708090",slategrey:"#708090",aliceblue:"#f0f8ff",darkseagreen:"#8fbc8f",darkolivegreen:"#556b2f",greenyellow:"#adff2f",seagreen:"#2e8b57",seashell:"#fff5ee",tomato:"#ff6347",silver:"#c0c0c0",sienna:"#a0522d",lavender:"#e6e6fa",lightgreen:"#90ee90",orange:"#ffa500",orangered:"#ff4500",steelblue:"#4682b4",royalblue:"#4169e1",turquoise:"#40e0d0",yellowgreen:"#9acd32",salmon:"#fa8072",saddlebrown:"#8b4513",sandybrown:"#f4a460",rosybrown:"#bc8f8f",darksalmon:"#e9967a",lightgoldenrodyellow:"#fafad2",snow:"#fffafa",lightgrey:"#d3d3d3",lightgray:"#d3d3d3",dimgray:"#696969",dimgrey:"#696969",olivedrab:"#6b8e23",olive:"#808000"},s={};for(var r in t)s[t[r]]=r;var n={};i.prototype.toName=function(o){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var a,l,h=s[this.toHex()];if(h)return h;if(o?.closest){var c=this.toRgb(),u=1/0,d="black";if(!n.length)for(var f in t)n[f]=new i(t[f]).toRgb();for(var p in t){var g=(a=c,l=n[p],Math.pow(a.r-l.r,2)+Math.pow(a.g-l.g,2)+Math.pow(a.b-l.b,2));g<u&&(u=g,d=p)}return d}},e.string.push([function(o){var a=o.toLowerCase(),l=a==="transparent"?"#0000":t[a];return l?new i(l).toRgb():null},"name"])}o_([a_]);const Ps=class Js{constructor(e=16777215){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=16777215,this.value=e}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(e){return this.value=e,this}set value(e){if(e instanceof Js)this._value=this._cloneSource(e._value),this._int=e._int,this._components.set(e._components);else{if(e===null)throw new Error("Cannot set Color#value to null");(this._value===null||!this._isSourceEqual(this._value,e))&&(this._value=this._cloneSource(e),this._normalize(this._value))}}get value(){return this._value}_cloneSource(e){return typeof e=="string"||typeof e=="number"||e instanceof Number||e===null?e:Array.isArray(e)||ArrayBuffer.isView(e)?e.slice(0):typeof e=="object"&&e!==null?{...e}:e}_isSourceEqual(e,t){const s=typeof e;if(s!==typeof t)return!1;if(s==="number"||s==="string"||e instanceof Number)return e===t;if(Array.isArray(e)&&Array.isArray(t)||ArrayBuffer.isView(e)&&ArrayBuffer.isView(t))return e.length!==t.length?!1:e.every((n,o)=>n===t[o]);if(e!==null&&t!==null){const n=Object.keys(e),o=Object.keys(t);return n.length!==o.length?!1:n.every(a=>e[a]===t[a])}return e===t}toRgba(){const[e,t,s,r]=this._components;return{r:e,g:t,b:s,a:r}}toRgb(){const[e,t,s]=this._components;return{r:e,g:t,b:s}}toRgbaString(){const[e,t,s]=this.toUint8RgbArray();return`rgba(${e},${t},${s},${this.alpha})`}toUint8RgbArray(e){const[t,s,r]=this._components;return this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb),e[0]=Math.round(t*255),e[1]=Math.round(s*255),e[2]=Math.round(r*255),e}toArray(e){this._arrayRgba||(this._arrayRgba=[]),e||(e=this._arrayRgba);const[t,s,r,n]=this._components;return e[0]=t,e[1]=s,e[2]=r,e[3]=n,e}toRgbArray(e){this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb);const[t,s,r]=this._components;return e[0]=t,e[1]=s,e[2]=r,e}toNumber(){return this._int}toBgrNumber(){const[e,t,s]=this.toUint8RgbArray();return(s<<16)+(t<<8)+e}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[t,s,r,n]=Js._temp.setValue(e)._components;return this._components[0]*=t,this._components[1]*=s,this._components[2]*=r,this._components[3]*=n,this._refreshInt(),this._value=null,this}premultiply(e,t=!0){return t&&(this._components[0]*=e,this._components[1]*=e,this._components[2]*=e),this._components[3]=e,this._refreshInt(),this._value=null,this}toPremultiplied(e,t=!0){if(e===1)return(255<<24)+this._int;if(e===0)return t?0:this._int;let s=this._int>>16&255,r=this._int>>8&255,n=this._int&255;return t&&(s=s*e+.5|0,r=r*e+.5|0,n=n*e+.5|0),(e*255<<24)+(s<<16)+(r<<8)+n}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const t=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(e){return this._components[3]=this._clamp(e),this._value=null,this}_normalize(e){let t,s,r,n;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const o=e;t=(o>>16&255)/255,s=(o>>8&255)/255,r=(o&255)/255,n=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[t,s,r,n=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[t,s,r,n=255]=e,t/=255,s/=255,r/=255,n/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const a=Js.HEX_PATTERN.exec(e);a&&(e=`#${a[2]}`)}const o=lt(e);o.isValid()&&({r:t,g:s,b:r,a:n}=o.rgba,t/=255,s/=255,r/=255)}if(t!==void 0)this._components[0]=t,this._components[1]=s,this._components[2]=r,this._components[3]=n,this._refreshInt();else throw new Error(`Unable to convert color ${e}`)}_refreshInt(){this._clamp(this._components);const[e,t,s]=this._components;this._int=(e*255<<16)+(t*255<<8)+(s*255|0)}_clamp(e,t=0,s=1){return typeof e=="number"?Math.min(Math.max(e,t),s):(e.forEach((r,n)=>{e[n]=Math.min(Math.max(r,t),s)}),e)}static isColorLike(e){return typeof e=="number"||typeof e=="string"||e instanceof Number||e instanceof Js||Array.isArray(e)||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Float32Array||e.r!==void 0&&e.g!==void 0&&e.b!==void 0||e.r!==void 0&&e.g!==void 0&&e.b!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0||e.h!==void 0&&e.s!==void 0&&e.l!==void 0&&e.a!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0||e.h!==void 0&&e.s!==void 0&&e.v!==void 0&&e.a!==void 0}};Ps.shared=new Ps;Ps._temp=new Ps;Ps.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let le=Ps;const Du={cullArea:null,cullable:!1,cullableChildren:!0};let dn=0;const Ih=500;function H(...i){dn!==Ih&&(dn++,dn===Ih?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...i))}const cs={_registeredResources:new Set,register(i){this._registeredResources.add(i)},unregister(i){this._registeredResources.delete(i)},release(){this._registeredResources.forEach(i=>i.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(i){return this._registeredResources.has(i)},reset(){this._registeredResources.clear()}};class Fu{constructor(e,t){this._pool=[],this._count=0,this._index=0,this._classType=e,t&&this.prepopulate(t)}prepopulate(e){for(let t=0;t<e;t++)this._pool[this._index++]=new this._classType;this._count+=e}get(e){let t;return this._index>0?t=this._pool[--this._index]:(t=new this._classType,this._count++),t.init?.(e),t}return(e){e.reset?.(),this._pool[this._index++]=e}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let e=0;e<this._index;e++)this._pool[e].destroy();this._pool.length=0,this._count=0,this._index=0}}class Ou{constructor(){this._poolsByClass=new Map}prepopulate(e,t){this.getPool(e).prepopulate(t)}get(e,t){return this.getPool(e).get(t)}return(e){this.getPool(e.constructor).return(e)}getPool(e){return this._poolsByClass.has(e)||this._poolsByClass.set(e,new Fu(e)),this._poolsByClass.get(e)}stats(){const e={};return this._poolsByClass.forEach(t=>{const s=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[s]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}}const Se=new Ou;cs.register(Se);const Lu={get isCachedAsTexture(){return!!this.renderGroup?.isCachedAsTexture},cacheAsTexture(i){typeof i=="boolean"&&i===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(i===!0?{}:i))},updateCacheTexture(){this.renderGroup?.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(i){z("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(i)}};function qo(i,e,t){const s=i.length;let r;if(e>=s||t===0)return;t=e+t>s?s-e:t;const n=s-t;for(r=e;r<n;++r)i[r]=i[r+t];i.length=n}const Uu={allowChildren:!0,removeChildren(i=0,e){const t=e??this.children.length,s=t-i,r=[];if(s>0&&s<=t){for(let o=t-1;o>=i;o--){const a=this.children[o];a&&(r.push(a),a.parent=null)}qo(this.children,i,t);const n=this.renderGroup||this.parentRenderGroup;n&&n.removeChildren(r);for(let o=0;o<r.length;++o){const a=r[o];a.parentRenderLayer?.detach(a),this.emit("childRemoved",a,this,o),r[o].emit("removed",this)}return r.length>0&&this._didViewChangeTick++,r}else if(s===0&&this.children.length===0)return r;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(i){const e=this.getChildAt(i);return this.removeChild(e)},getChildAt(i){if(i<0||i>=this.children.length)throw new Error(`getChildAt: Index (${i}) does not exist.`);return this.children[i]},setChildIndex(i,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);this.getChildIndex(i),this.addChildAt(i,e)},getChildIndex(i){const e=this.children.indexOf(i);if(e===-1)throw new Error("The supplied Container must be a child of the caller");return e},addChildAt(i,e){this.allowChildren||z(de,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:t}=this;if(e<0||e>t.length)throw new Error(`${i}addChildAt: The index ${e} supplied is out of bounds ${t.length}`);const s=i.parent===this;if(i.parent){const n=i.parent.children.indexOf(i);if(s){if(n===e)return i;i.parent.children.splice(n,1)}else i.removeFromParent()}e===t.length?t.push(i):t.splice(e,0,i);const r=this.renderGroup||this.parentRenderGroup;return this.sortableChildren&&(this.sortDirty=!0),s?(r&&(r.structureDidChange=!0),i):(i.parent=this,i.didChange=!0,i._updateFlags=15,r&&r.addChild(i),this.emit("childAdded",i,this,e),i.emit("added",this),i)},swapChildren(i,e){if(i===e)return;const t=this.getChildIndex(i),s=this.getChildIndex(e);this.children[t]=e,this.children[s]=i;const r=this.renderGroup||this.parentRenderGroup;r&&(r.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){this.parent?.removeChild(this)},reparentChild(...i){return i.length===1?this.reparentChildAt(i[0],this.children.length):(i.forEach(e=>this.reparentChildAt(e,this.children.length)),i[0])},reparentChildAt(i,e){if(i.parent===this)return this.setChildIndex(i,e),i;const t=i.worldTransform.clone();i.removeFromParent(),this.addChildAt(i,e);const s=this.worldTransform.clone();return s.invert(),t.prepend(s),i.setFromMatrix(t),i},replaceChild(i,e){i.updateLocalTransform(),this.addChildAt(e,this.getChildIndex(i)),e.setFromMatrix(i.localTransform),e.updateLocalTransform(),this.removeChild(i)}},Nu={collectRenderables(i,e,t){this.parentRenderLayer&&this.parentRenderLayer!==t||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(i,e,t):this.renderGroup?e.renderPipes.renderGroup.addRenderGroup(this.renderGroup,i):this.collectRenderablesWithEffects(i,e,t))},collectRenderablesSimple(i,e,t){const s=this.children,r=s.length;for(let n=0;n<r;n++)s[n].collectRenderables(i,e,t)},collectRenderablesWithEffects(i,e,t){const{renderPipes:s}=e;for(let r=0;r<this.effects.length;r++){const n=this.effects[r];s[n.pipe].push(n,this,i)}this.collectRenderablesSimple(i,e,t);for(let r=this.effects.length-1;r>=0;r--){const n=this.effects[r];s[n.pipe].pop(n,this,i)}}};class ci{constructor(){this.pipe="filter",this.priority=1}destroy(){for(let e=0;e<this.filters.length;e++)this.filters[e].destroy();this.filters=null,this.filterArea=null}}class zu{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(e=>{this.add({test:e.test,maskClass:e})}))}add(e){this._tests.push(e)}getMaskEffect(e){this._initialized||this.init();for(let t=0;t<this._tests.length;t++){const s=this._tests[t];if(s.test(e))return Se.get(s.maskClass,e)}return e}returnMaskEffect(e){Se.return(e)}}const ar=new zu;q.handleByList(S.MaskEffect,ar._effectClasses);const Hu={_maskEffect:null,_maskOptions:{inverse:!1,channel:"red"},_filterEffect:null,effects:[],_markStructureAsChanged(){const i=this.renderGroup||this.parentRenderGroup;i&&(i.structureDidChange=!0)},addEffect(i){this.effects.indexOf(i)===-1&&(this.effects.push(i),this.effects.sort((t,s)=>t.priority-s.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(i){const e=this.effects.indexOf(i);e!==-1&&(this.effects.splice(e,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(i){const e=this._maskEffect;e?.mask!==i&&(e&&(this.removeEffect(e),ar.returnMaskEffect(e),this._maskEffect=null),i!=null&&(this._maskEffect=ar.getMaskEffect(i),this.addEffect(this._maskEffect)))},get mask(){return this._maskEffect?.mask},setMask(i){this._maskOptions={...this._maskOptions,...i},i.mask&&(this.mask=i.mask),this._markStructureAsChanged()},set filters(i){!Array.isArray(i)&&i&&(i=[i]);const e=this._filterEffect||(this._filterEffect=new ci);i=i;const t=i?.length>0,s=e.filters?.length>0,r=t!==s;i=Array.isArray(i)?i.slice(0):i,e.filters=Object.freeze(i),r&&(t?this.addEffect(e):(this.removeEffect(e),e.filters=i??null))},get filters(){return this._filterEffect?.filters},set filterArea(i){this._filterEffect||(this._filterEffect=new ci),this._filterEffect.filterArea=i},get filterArea(){return this._filterEffect?.filterArea}},Wu={label:null,get name(){return z(de,"Container.name property has been removed, use Container.label instead"),this.label},set name(i){z(de,"Container.name property has been removed, use Container.label instead"),this.label=i},getChildByName(i,e=!1){return this.getChildByLabel(i,e)},getChildByLabel(i,e=!1){const t=this.children;for(let s=0;s<t.length;s++){const r=t[s];if(r.label===i||i instanceof RegExp&&i.test(r.label))return r}if(e)for(let s=0;s<t.length;s++){const n=t[s].getChildByLabel(i,!0);if(n)return n}return null},getChildrenByLabel(i,e=!1,t=[]){const s=this.children;for(let r=0;r<s.length;r++){const n=s[r];(n.label===i||i instanceof RegExp&&i.test(n.label))&&t.push(n)}if(e)for(let r=0;r<s.length;r++)s[r].getChildrenByLabel(i,!0,t);return t}},Ae=Se.getPool(U),ft=Se.getPool(Ee),l_=new U,$u={getFastGlobalBounds(i,e){e||(e=new Ee),e.clear(),this._getGlobalBoundsRecursive(!!i,e,this.parentRenderLayer),e.isValid||e.set(0,0,0,0);const t=this.renderGroup||this.parentRenderGroup;return e.applyMatrix(t.worldTransform),e},_getGlobalBoundsRecursive(i,e,t){let s=e;if(i&&this.parentRenderLayer&&this.parentRenderLayer!==t||this.localDisplayStatus!==7||!this.measurable)return;const r=!!this.effects.length;if((this.renderGroup||r)&&(s=ft.get().clear()),this.boundsArea)e.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const o=this.bounds;s.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(i,s,t)}if(r){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,s.applyMatrix(o.worldTransform)),this.effects[a].addBounds(s,!0));n&&s.applyMatrix(o.worldTransform.copyTo(l_).invert()),e.addBounds(s),ft.return(s)}else this.renderGroup&&(e.addBounds(s,this.relativeGroupTransform),ft.return(s))}};function br(i,e,t){t.clear();let s,r;return i.parent?e?s=i.parent.worldTransform:(r=Ae.get().identity(),s=vr(i,r)):s=U.IDENTITY,Vu(i,t,s,e),r&&Ae.return(r),t.isValid||t.set(0,0,0,0),t}function Vu(i,e,t,s){if(!i.visible||!i.measurable)return;let r;s?r=i.worldTransform:(i.updateLocalTransform(),r=Ae.get(),r.appendFrom(i.localTransform,t));const n=e,o=!!i.effects.length;if(o&&(e=ft.get().clear()),i.boundsArea)e.addRect(i.boundsArea,r);else{const a=i.bounds;a&&!a.isEmpty()&&(e.matrix=r,e.addBounds(a));for(let l=0;l<i.children.length;l++)Vu(i.children[l],e,r,s)}if(o){for(let a=0;a<i.effects.length;a++)i.effects[a].addBounds?.(e);n.addBounds(e,U.IDENTITY),ft.return(e)}s||Ae.return(r)}function vr(i,e){const t=i.parent;return t&&(vr(t,e),t.updateLocalTransform(),e.append(t.localTransform)),e}function es(i,e){if(i===16777215||!e)return e;if(e===16777215||!i)return i;const t=i>>16&255,s=i>>8&255,r=i&255,n=e>>16&255,o=e>>8&255,a=e&255,l=t*n/255|0,h=s*o/255|0,c=r*a/255|0;return(l<<16)+(h<<8)+c}const Gh=16777215;function ui(i,e){return i===Gh?e:e===Gh?i:es(i,e)}function ts(i){return((i&255)<<16)+(i&65280)+(i>>16&255)}const ju={getGlobalAlpha(i){if(i)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let e=this.alpha,t=this.parent;for(;t;)e*=t.alpha,t=t.parent;return e},getGlobalTransform(i=new U,e){if(e)return i.copyFrom(this.worldTransform);this.updateLocalTransform();const t=vr(this,Ae.get().identity());return i.appendFrom(this.localTransform,t),Ae.return(t),i},getGlobalTint(i){if(i)return this.renderGroup?ts(this.renderGroup.worldColor):this.parentRenderGroup?ts(ui(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let e=this.localColor,t=this.parent;for(;t;)e=ui(e,t.localColor),t=t.parent;return ts(e)}};function wr(i,e,t){return e.clear(),t||(t=U.IDENTITY),Xu(i,e,t,i,!0),e.isValid||e.set(0,0,0,0),e}function Xu(i,e,t,s,r){let n;if(r)n=Ae.get(),n=t.copyTo(n);else{if(!i.visible||!i.measurable)return;i.updateLocalTransform();const l=i.localTransform;n=Ae.get(),n.appendFrom(l,t)}const o=e,a=!!i.effects.length;if(a&&(e=ft.get().clear()),i.boundsArea)e.addRect(i.boundsArea,n);else{i.renderPipeId&&(e.matrix=n,e.addBounds(i.bounds));const l=i.children;for(let h=0;h<l.length;h++)Xu(l[h],e,n,s,!1)}if(a){for(let l=0;l<i.effects.length;l++)i.effects[l].addLocalBounds?.(e,s);o.addBounds(e,U.IDENTITY),ft.return(e)}Ae.return(n)}function Yo(i,e){const t=i.children;for(let s=0;s<t.length;s++){const r=t[s],n=r.uid,o=(r._didViewChangeTick&65535)<<16|r._didContainerChangeTick&65535,a=e.index;(e.data[a]!==n||e.data[a+1]!==o)&&(e.data[e.index]=n,e.data[e.index+1]=o,e.didChange=!0),e.index=a+2,r.children.length&&Yo(r,e)}return e.didChange}const h_=new U,qu={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(i,e){const t=Math.sign(this.scale.x)||1;e!==0?this.scale.x=i/e*t:this.scale.x=t},_setHeight(i,e){const t=Math.sign(this.scale.y)||1;e!==0?this.scale.y=i/e*t:this.scale.y=t},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Ee});const i=this._localBoundsCacheData;return i.index=1,i.didChange=!1,i.data[0]!==this._didViewChangeTick&&(i.didChange=!0,i.data[0]=this._didViewChangeTick),Yo(this,i),i.didChange&&wr(this,i.localBounds,h_),i.localBounds},getBounds(i,e){return br(this,i,e||new Ee)}},Yu={_onRender:null,set onRender(i){const e=this.renderGroup||this.parentRenderGroup;if(!i){this._onRender&&e?.removeOnRender(this),this._onRender=null;return}this._onRender||e?.addOnRender(this),this._onRender=i},get onRender(){return this._onRender}},Ku={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(i){this._zIndex!==i&&(this._zIndex=i,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(c_))}};function c_(i,e){return i._zIndex-e._zIndex}const Zu={getGlobalPosition(i=new ce,e=!1){return this.parent?this.parent.toGlobal(this._position,i,e):(i.x=this._position.x,i.y=this._position.y),i},toGlobal(i,e,t=!1){const s=this.getGlobalTransform(Ae.get(),t);return e=s.apply(i,e),Ae.return(s),e},toLocal(i,e,t,s){e&&(i=e.toGlobal(i,t,s));const r=this.getGlobalTransform(Ae.get(),s);return t=r.applyInverse(i,t),Ae.return(r),t}};class Tr{constructor(){this.uid=oe("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){if(this.renderPipes)for(const e in this.renderPipes)this.renderPipes[e].destroyInstructionSet?.(this);this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}class Ko{constructor(){this._screenSizes=new Map,this._widths=[],this._heights=[]}get size(){return this._screenSizes.size}set(e,t,s){const r=this._screenSizes.get(e);return r&&r.pixelWidth===t&&r.pixelHeight===s?!1:(this._screenSizes.set(e,{pixelWidth:t,pixelHeight:s}),this._update(),!0)}remove(e){return this._screenSizes.delete(e)?(this._update(),!0):!1}getFittingWidth(e){return this._getFittingAxis(e,this._widths)}getFittingHeight(e){return this._getFittingAxis(e,this._heights)}hasWidth(e){return this._widths.includes(e)}hasHeight(e){return this._heights.includes(e)}_getFittingAxis(e,t){for(let s=0;s<t.length;s++){const r=t[s];if(r>=e)return r}}_update(){this._widths=[...this._screenSizes.values()].map(e=>e.pixelWidth).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>e-t),this._heights=[...this._screenSizes.values()].map(e=>e.pixelHeight).filter((e,t,s)=>s.indexOf(e)===t).sort((e,t)=>e-t)}}let u_=0;const fn=32767,d_=4294967296,f_=8589934592,Dh=Object.create(null);let p_=0;function m_(i){const e=Dh[i];return e!==void 0?e:Dh[i]=p_++}function g_(i,e,t,s,r,n){return(i<<17)+(e<<2)+((s?1:0)<<1)+(t?1:0)+(n==="nearest"?1:0)*d_+m_(r)*f_}class Qu{constructor(e){this._buckets=new Map,this._poolKey=Object.create(null),this._poolStyle=Object.create(null),this._screens=new Ko,this._enableFullScreen=!1,this.textureOptions=e||{}}get textureStyle(){return z(ut,"TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead."),this._textureStyle||(this._textureStyle=new Ot(this.textureOptions)),this._textureStyle}set textureStyle(e){z(ut,"TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead."),this._textureStyle=e}get enableFullScreen(){return z(ut,"TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize."),this._enableFullScreen}set enableFullScreen(e){z(ut,"TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize."),this._enableFullScreen=e}createTexture(...e){let t=e[0];typeof t=="number"&&(z(ut,"TexturePool.createTexture params are now an options object. See params: { width, height, antialias, autoGenerateMipmaps }"),t={width:t,height:e[1],antialias:e[2]??!1,autoGenerateMipmaps:e[3]??!1});const s=t.format??this.textureOptions.format??ue.defaultOptions.format,r=t.scaleMode??this.textureOptions.scaleMode??Ot.defaultOptions.scaleMode,n=new ue({...this.textureOptions,width:t.width,height:t.height,resolution:1,antialias:t.antialias??!1,autoGarbageCollect:!1,autoGenerateMipmaps:t.autoGenerateMipmaps??!1,format:s,scaleMode:r});return new W({source:n,label:`texturePool_${u_++}`})}getOptimalTexture(...e){let t=e[0];typeof t=="number"&&(z(ut,"TexturePool.getOptimalTexture params are now an options object. See params: { width, height, resolution, antialias, autoGenerateMipmaps }"),t={width:t,height:e[1],resolution:e[2]??1,antialias:e[3]??!1,autoGenerateMipmaps:e[4]??!1});const s=t.width,r=t.height,n=t.resolution??1,o=t.antialias??!1,a=t.autoGenerateMipmaps??!1,l=t.format??this.textureOptions.format??ue.defaultOptions.format,h=t.scaleMode??this.textureOptions.scaleMode??Ot.defaultOptions.scaleMode,{width:c,height:u}=this.getOptimalSize(s,r,n);(c>fn||u>fn)&&H(`TexturePool: ${c}x${u} is larger than the ${fn}px pool key limit, textures of this size may be pooled together`);const d=g_(c,u,o,a,l,h);let f=this._buckets.get(d);f||(f=[],this._buckets.set(d,f));let p=f.pop();return p||(p=this.createTexture({width:c,height:u,antialias:o,autoGenerateMipmaps:a,format:l,scaleMode:h}),this._poolStyle[p.uid]=p.source.style),p.source._resolution=n,p.source.width=c/n,p.source.height=u/n,p.source.pixelWidth=c,p.source.pixelHeight=u,p.frame.x=0,p.frame.y=0,p.frame.width=s,p.frame.height=r,p.updateUvs(),this._poolKey[p.uid]=d,p}getOptimalSize(e,t,s=1){const r=Math.ceil(e*s-1e-6),n=Math.ceil(t*s-1e-6),o=is(r),a=this._screens.getFittingWidth(r),l=is(n),h=this._screens.getFittingHeight(n);return{width:a!==void 0?Math.min(a,o):o,height:h!==void 0?Math.min(h,l):l}}getSameSizeTexture(e,t=!1){const s=e.source;return this.getOptimalTexture({width:e.width,height:e.height,resolution:s._resolution,antialias:t})}returnTexture(e,t=!1){const s=e.uid,r=this._poolKey[s];if(r===void 0){H("TexturePool: returnTexture was passed a texture that did not come from this pool, ignoring it");return}const n=this._poolStyle[s];t&&e.source.style!==n&&(e.source.style=n);const o=this._buckets.get(r);if(!o){delete this._poolKey[s],delete this._poolStyle[s],e.destroy(!0);return}o.push(e)}setScreenSize(e,t,s){this._screens.set(e,t,s)&&this._pruneScreenTextures()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenTextures()}_pruneScreenTextures(){for(const[e,t]of this._buckets){const s=e>>>0,r=s>>>17,n=s>>>2&32767;(rs(r)||this._screens.hasWidth(r))&&(rs(n)||this._screens.hasHeight(n))||(this._dropTextures(t,!0),this._buckets.delete(e))}}_dropTextures(e,t){for(let s=0;s<e.length;s++){const r=e[s];delete this._poolKey[r.uid],delete this._poolStyle[r.uid],t&&r.destroy(!0)}}clear(e){for(const t of this._buckets.values())this._dropTextures(t,e!==!1);this._buckets.clear()}}const Te=new Qu;cs.register(Te);class lr{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new U,this.worldColorAlpha=4294967295,this.worldColor=16777215,this.worldAlpha=1,this.childrenToUpdate=Object.create(null),this.updateTick=0,this.gcTick=0,this.childrenRenderablesToUpdate={list:[],index:0},this.structureDidChange=!0,this.instructionSet=new Tr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(e){this.root=e,e._onRender&&this.addOnRender(e),e.didChange=!0;const t=e.children;for(let s=0;s<t.length;s++){const r=t[s];r._updateFlags=15,this.addChild(r)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Te.returnTexture(this.texture),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const e in this.childrenToUpdate){const t=this.childrenToUpdate[e];t.list.fill(null),t.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){const t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.parent===this.root?e.relativeRenderGroupDepth=1:e.relativeRenderGroupDepth=e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);const t=e.children;for(let s=0;s<t.length;s++)this.addChild(t[s])}removeChild(e){if(this.structureDidChange=!0,e._onRender&&(e.renderGroup||this.removeOnRender(e)),e.parentRenderGroup=null,e.renderGroup){this._removeRenderGroupChild(e.renderGroup);return}const t=e.children;for(let s=0;s<t.length;s++)this.removeChild(t[s])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||(t=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]}),t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.indexOf(e)===-1&&this._onRenderContainers.push(e)}removeOnRender(e){const t=this._onRenderContainers.indexOf(e);t!==-1&&this._onRenderContainers.splice(t,1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet?.destroy(),this.instructionSet=null}getChildren(e=[]){const t=this.root.children;for(let s=0;s<t.length;s++)this._getChildren(t[s],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;const s=e.children;for(let r=0;r<s.length;r++)this._getChildren(s[r],t);return t}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return(this._matrixDirty&1)===0?this._inverseWorldTransform:(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new U),this._inverseWorldTransform.copyFrom(this.worldTransform).invert())}get textureOffsetInverseTransform(){return(this._matrixDirty&2)===0?this._textureOffsetInverseTransform:(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new U),this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y))}get inverseParentTextureTransform(){if((this._matrixDirty&4)===0)return this._inverseParentTextureTransform;this._matrixDirty&=-5;const e=this._parentCacheAsTextureRenderGroup;return e?(this._inverseParentTextureTransform||(this._inverseParentTextureTransform=new U),this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(e.inverseWorldTransform).translate(-e._textureBounds.x,-e._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}}function Ju(i,e,t={}){for(const s in e)!t[s]&&e[s]!==void 0&&(i[s]=e[s])}const pn=new Ce(null),Ri=new Ce(null),mn=new Ce(null,1,1),Bi=new Ce(null),di=1,Sr=2,Ms=4;class _e extends Re{constructor(e={}){super(),this.uid=oe("renderable"),this._updateFlags=15,this.renderGroup=null,this.parentRenderGroup=null,this.parentRenderGroupIndex=0,this.didChange=!1,this.didViewUpdate=!1,this.relativeRenderGroupDepth=0,this.children=[],this.parent=null,this.includeInBuild=!0,this.measurable=!0,this.isSimple=!0,this.parentRenderLayer=null,this.updateTick=-1,this.localTransform=new U,this.relativeGroupTransform=new U,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new Ce(this,0,0),this._scale=mn,this._pivot=Ri,this._origin=Bi,this._skew=pn,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=[],Ju(this,e,{children:!0,parent:!0,effects:!0}),e.children?.forEach(t=>this.addChild(t)),e.parent?.addChild(this)}static mixin(e){z("8.8.0","Container.mixin is deprecated, please use extensions.mixin instead."),q.mixin(_e,e)}set _didChangeId(e){this._didViewChangeTick=e>>12&4095,this._didContainerChangeTick=e&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...e){if(this.allowChildren||z(de,"addChild: Only Containers will be allowed to add children in v8.0.0"),e.length>1){for(let r=0;r<e.length;r++)this.addChild(e[r]);return e[0]}const t=e[0],s=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),s&&(s.structureDidChange=!0),t):(t.parent&&t.parent.removeChild(t),this.children.push(t),this.sortableChildren&&(this.sortDirty=!0),t.parent=this,t.didChange=!0,t._updateFlags=15,s&&s.addChild(t),this.emit("childAdded",t,this,this.children.length-1),t.emit("added",this),this._didViewChangeTick++,t._zIndex!==0&&t.depthOfChildModified(),t)}removeChild(...e){if(e.length>1){for(let r=0;r<e.length;r++)this.removeChild(e[r]);return e[0]}const t=e[0],s=this.children.indexOf(t);return s>-1&&(this._didViewChangeTick++,this.children.splice(s,1),this.renderGroup?this.renderGroup.removeChild(t):this.parentRenderGroup&&this.parentRenderGroup.removeChild(t),t.parentRenderLayer&&t.parentRenderLayer.detach(t),t.parent=null,this.emit("childRemoved",t,this,s),t.emit("removed",this)),t}_onUpdate(e){e&&e===this._skew&&this._updateSkew(),this._didContainerChangeTick++,!this.didChange&&(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(e){!!this.renderGroup!==e&&(e?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),this.renderGroup=Se.get(lr,this),this.groupTransform=U.IDENTITY,e?.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),Se.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,e?.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||(this._worldTransform=new U),this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(e){this._position.x=e}get y(){return this._position.y}set y(e){this._position.y=e}get position(){return this._position}set position(e){this._position.copyFrom(e)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._onUpdate(this._skew))}get angle(){return this.rotation*Tu}set angle(e){this.rotation=e*Su}get pivot(){return this._pivot===Ri&&(this._pivot=new Ce(this,0,0)),this._pivot}set pivot(e){this._pivot===Ri&&(this._pivot=new Ce(this,0,0),this._origin!==Bi&&H("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._pivot.set(e):this._pivot.copyFrom(e)}get skew(){return this._skew===pn&&(this._skew=new Ce(this,0,0)),this._skew}set skew(e){this._skew===pn&&(this._skew=new Ce(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===mn&&(this._scale=new Ce(this,1,1)),this._scale}set scale(e){this._scale===mn&&(this._scale=new Ce(this,0,0)),typeof e=="string"&&(e=parseFloat(e)),typeof e=="number"?this._scale.set(e):this._scale.copyFrom(e)}get origin(){return this._origin===Bi&&(this._origin=new Ce(this,0,0)),this._origin}set origin(e){this._origin===Bi&&(this._origin=new Ce(this,0,0),this._pivot!==Ri&&H("Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.")),typeof e=="number"?this._origin.set(e):this._origin.copyFrom(e)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(e){const t=this.getLocalBounds().width;this._setWidth(e,t)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(e){const t=this.getLocalBounds().height;this._setHeight(e,t)}getSize(e){e||(e={});const t=this.getLocalBounds();return e.width=Math.abs(this.scale.x*t.width),e.height=Math.abs(this.scale.y*t.height),e}setSize(e,t){const s=this.getLocalBounds();typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,s.width),t!==void 0&&this._setHeight(t,s.height)}_updateSkew(){const e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x=="number"?e.x:this.position.x,typeof e.y=="number"?e.y:this.position.y),this.scale.set(typeof e.scaleX=="number"?e.scaleX:this.scale.x,typeof e.scaleY=="number"?e.scaleY:this.scale.y),this.rotation=typeof e.rotation=="number"?e.rotation:this.rotation,this.skew.set(typeof e.skewX=="number"?e.skewX:this.skew.x,typeof e.skewY=="number"?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX=="number"?e.pivotX:this.pivot.x,typeof e.pivotY=="number"?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX=="number"?e.originX:this.origin.x,typeof e.originY=="number"?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){const e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;const t=this.localTransform,s=this._scale,r=this._pivot,n=this._origin,o=this._position,a=s._x,l=s._y,h=r._x,c=r._y,u=-n._x,d=-n._y;t.a=this._cx*a,t.b=this._sx*a,t.c=this._cy*l,t.d=this._sy*l,t.tx=o._x-(h*t.a+c*t.c)+(u*t.a+d*t.c)-u,t.ty=o._y-(h*t.b+c*t.d)+(u*t.b+d*t.d)-d}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=di,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){const s=le.shared.setValue(e??16777215).toBgrNumber();s!==this.localColor&&(this.localColor=s,this._updateFlags|=di,this._onUpdate())}get tint(){return ts(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Sr,this.localBlendMode=e,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(e){const t=e?2:0;(this.localDisplayStatus&2)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Ms,this.localDisplayStatus^=2,this._onUpdate(),this.emit("visibleChanged",e))}get culled(){return!(this.localDisplayStatus&4)}set culled(e){const t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Ms,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(e){const t=e?1:0;(this.localDisplayStatus&1)!==t&&(this._updateFlags|=Ms,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(e=!1){if(this.destroyed)return;this.destroyed=!0;let t;if(this.children.length&&(t=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit("destroyed",this),this.removeAllListeners(),(typeof e=="boolean"?e:e?.children)&&t)for(let r=0;r<t.length;++r)t[r].destroy(e);this.renderGroup?.destroy(),this.renderGroup=null}}q.mixin(_e,Uu,$u,Zu,Yu,qu,Hu,Wu,Ku,Du,Lu,ju,Nu);class Cr extends _e{constructor(e){super(e),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this._bounds=new Ee(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=e.autoGarbageCollect??!0}get bounds(){return this._boundsDirty?(this.updateBounds(),this._boundsDirty=!1,this._bounds):this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(e){this._roundPixels=e?1:0}containsPoint(e){const t=this.bounds,{x:s,y:r}=e;return s>=t.minX&&s<=t.maxX&&r>=t.minY&&r<=t.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;const e=this.renderGroup||this.parentRenderGroup;e&&e.onChildViewUpdate(this)}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(e){this.unload(),super.destroy(e),this._bounds=null}collectRenderablesSimple(e,t,s){const{renderPipes:r}=t;r.blendMode.pushBlendMode(this,this.groupBlendMode,e);const o=r[this.renderPipeId];o?.addRenderable&&o.addRenderable(this,e),this.didViewUpdate=!1;const a=this.children,l=a.length;for(let h=0;h<l;h++)a[h].collectRenderables(e,t,s);r.blendMode.popBlendMode(e)}}class ns extends Cr{constructor(e=W.EMPTY){e instanceof W&&(e={texture:e});const{texture:t=W.EMPTY,anchor:s,roundPixels:r,width:n,height:o,...a}=e;super({label:"Sprite",...a}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new Ce({_onUpdate:()=>{this.onViewUpdate()}}),s?this.anchor=s:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=r??!1,n!==void 0&&(this.width=n),o!==void 0&&(this.height=o)}static from(e,t=!1){return e instanceof W?new ns(e):new ns(W.from(e,t))}set texture(e){e||(e=W.EMPTY);const t=this._texture;t!==e&&(t&&t.dynamic&&t.off("update",this.onViewUpdate,this),e.dynamic&&e.on("update",this.onViewUpdate,this),this._texture=e,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return Xo(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return z("8.6.1","Sprite.sourceBounds is deprecated, use visualBounds instead."),this.visualBounds}updateBounds(){const e=this._anchor,t=this._texture,s=this._bounds,{width:r,height:n}=t.orig;s.minX=-e._x*r,s.maxX=s.minX+r,s.minY=-e._y*n,s.maxY=s.minY+n}destroy(e=!1){if(super.destroy(e),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._texture.destroy(s)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(e){this._setWidth(e,this._texture.orig.width),this._width=e}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(e){this._setHeight(e,this._texture.orig.height),this._height=e}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this._texture.orig.width,e.height=Math.abs(this.scale.y)*this._texture.orig.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this._texture.orig.width),t!==void 0&&this._setHeight(t,this._texture.orig.height)}}const __=new Ee;function Zo(i,e,t){const s=__;i.measurable=!0,br(i,t,s),e.addBoundsMask(s),i.measurable=!1}function Qo(i,e,t){const s=ft.get();i.measurable=!0;const r=Ae.get().identity(),n=ed(i,t,r);wr(i,s,n),i.measurable=!1,e.addBoundsMask(s),Ae.return(r),ft.return(s)}function ed(i,e,t){return i?(i!==e&&(ed(i.parent,e,t),i.updateLocalTransform(),t.append(i.localTransform)),t):(H("Mask bounds, renderable is not inside the root container"),t)}class Jo{constructor(e){this.priority=0,this.inverse=!1,this.channel="red",this.pipe="alphaMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e instanceof ns),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask=null)}addBounds(e,t){this.inverse||Zo(this.mask,e,t)}addLocalBounds(e,t){Qo(this.mask,e,t)}containsPoint(e,t){const s=this.mask;return t(s,e)}destroy(){this.reset()}static test(e){return e instanceof ns}}Jo.extension=S.MaskEffect;class ea{constructor(e){this.priority=0,this.pipe="colorMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e}destroy(){}static test(e){return typeof e=="number"}}ea.extension=S.MaskEffect;class ta{constructor(e){this.priority=0,this.pipe="stencilMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(e,t){Zo(this.mask,e,t)}addLocalBounds(e,t){Qo(this.mask,e,t)}containsPoint(e,t){const s=this.mask;return t(s,e)}destroy(){this.reset()}static test(e){return e instanceof _e}}ta.extension=S.MaskEffect;const td={createCanvas:(i,e)=>{const t=document.createElement("canvas");return t.width=i,t.height=e,t},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(i,e)=>fetch(i,e),parseXML:i=>new DOMParser().parseFromString(i,"text/xml")};let Fh=td;const ee={get(){return Fh},set(i){Fh=i}};class Ve extends ue{constructor(e){e.resource||(e.resource=ee.get().createCanvas()),e.width||(e.width=e.resource.width,e.autoDensity||(e.width/=e.resolution)),e.height||(e.height=e.resource.height,e.autoDensity||(e.height/=e.resolution)),super(e),this.uploadMethodId="image",this.autoDensity=e.autoDensity,this.resizeCanvas(),this.transparent=!!e.transparent}resizeCanvas(){this.autoDensity&&"style"in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(e=this.width,t=this.height,s=this._resolution){const r=super.resize(e,t,s);return r&&this.resizeCanvas(),r}static test(e){return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&e instanceof OffscreenCanvas}get context2D(){return this._context2D||(this._context2D=this.resource.getContext("2d"))}}Ve.extension=S.TextureSource;class fi extends ue{constructor(e){super(e),this.uploadMethodId="image",this.autoGarbageCollect=!0}static test(e){return globalThis.HTMLImageElement&&e instanceof HTMLImageElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||globalThis.VideoFrame&&e instanceof VideoFrame}}fi.extension=S.TextureSource;var os=(i=>(i[i.INTERACTION=50]="INTERACTION",i[i.HIGH=25]="HIGH",i[i.NORMAL=0]="NORMAL",i[i.LOW=-25]="LOW",i[i.UTILITY=-50]="UTILITY",i))(os||{});class Zi{constructor(e,t=null,s=0,r=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=s,this._once=r}match(e,t=null){return this._fn===e&&this._context===t}emit(e){this._fn&&(this._context?this._fn.call(this._context,e):this._fn(e));const t=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),t}connect(e){this.previous=e,e.next&&(e.next.previous=this),this.next=e.next,e.next=this}destroy(e=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const t=this.next;return this.next=e?null:t,this.previous=null,t}}const sd=class Ne{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 Zi(null,null,1/0),this.deltaMS=1/Ne.targetFPMS,this.elapsedMS=1/Ne.targetFPMS,this._tick=e=>{this._requestId=null,this.started&&(this.update(e),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(e,t,s=os.NORMAL){return this._addListener(new Zi(e,t,s))}addOnce(e,t,s=os.NORMAL){return this._addListener(new Zi(e,t,s,!0))}_addListener(e){let t=this._head.next,s=this._head;if(!t)e.connect(s);else{for(;t;){if(e.priority>t.priority){e.connect(s);break}s=t,t=t.next}e.previous||e.connect(s)}return this._startIfPossible(),this}remove(e,t){let s=this._head.next;for(;s;)s.match(e,t)?s=s.destroy():s=s.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let e=0,t=this._head;for(;t=t.next;)e++;return e}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let e=this._head.next;for(;e;)e=e.destroy(!0);this._head.destroy(),this._head=null}}update(e=performance.now()){let t;if(e>this.lastTime){if(t=this.elapsedMS=e-this.lastTime,t>this._maxElapsedMS&&(t=this._maxElapsedMS),t*=this.speed,this._minElapsedMS){const n=e-this._lastFrame|0;if(n<this._minElapsedMS)return;this._lastFrame=e-n%this._minElapsedMS}this.deltaMS=t,this.deltaTime=this.deltaMS*Ne.targetFPMS;const s=this._head;let r=s.next;for(;r;)r=r.emit(this);s.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const t=Math.min(Math.max(0,e)/1e3,Ne.targetFPMS);this._maxElapsedMS=1/t,this._minElapsedMS&&e>this.maxFPS&&(this.maxFPS=e)}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){e===0?this._minElapsedMS=0:(e<this.minFPS&&(this.minFPS=e),this._minElapsedMS=1/(e/1e3))}static get shared(){if(!Ne._shared){const e=Ne._shared=new Ne;e.autoStart=!0,e._protected=!0}return Ne._shared}static get system(){if(!Ne._system){const e=Ne._system=new Ne;e.autoStart=!0,e._protected=!0}return Ne._system}};sd.targetFPMS=.06;let We=sd,gn;async function id(){return gn??(gn=(async()=>{const e=ee.get().createCanvas(1,1).getContext("webgl");if(!e)return"premultiply-alpha-on-upload";const t=await new Promise(o=>{const a=document.createElement("video");a.onloadeddata=()=>o(a),a.onerror=()=>o(null),a.autoplay=!1,a.crossOrigin="anonymous",a.preload="auto",a.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",a.load()});if(!t)return"premultiply-alpha-on-upload";const s=e.createTexture();e.bindTexture(e.TEXTURE_2D,s);const r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,s,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);const n=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,n),e.deleteFramebuffer(r),e.deleteTexture(s),e.getExtension("WEBGL_lose_context")?.loseContext(),n[0]<=n[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),gn}const Mr=class rd extends ue{constructor(e){super(e),this.isReady=!1,this.uploadMethodId="video",e={...rd.defaultOptions,...e},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this.alphaMode=e.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),this._onLoadedMetadata=this._onLoadedMetadata.bind(this),e.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const e=We.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener("play",this._onPlayStart),e.addEventListener("pause",this._onPlayStop),e.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlayThrough),e.addEventListener("error",this._onError,!0)),this.isValid||e.addEventListener("loadedmetadata",this._onLoadedMetadata),this.alphaMode=await id(),this._load=new Promise((s,r)=>{this.isValid?s(this):(this._resolve=s,this._reject=r,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.resource;return!e.paused&&!e.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onLoadedMetadata(){this.isValid&&this._mediaReady()}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlayThrough),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&this.isValid&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const e=this.resource;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlayThrough),e.removeEventListener("loadedmetadata",this._onLoadedMetadata),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(We.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||(We.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(We.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};Mr.extension=S.TextureSource;Mr.defaultOptions={...ue.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1};Mr.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let nd=Mr;const Yt=(i,e,t=!1)=>(Array.isArray(i)||(i=[i]),e?i.map(s=>typeof s=="string"||t?e(s):s):i);class y_{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){const t=this._cache.get(e);return t||H(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){const s=Yt(e);let r;for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];if(h.test(t)){r=h.getCacheableAssets(s,t);break}}const n=new Map(Object.entries(r||{}));r||s.forEach(l=>{n.set(l,t)});const o=[...n.keys()],a={cacheKeys:o,keys:s};s.forEach(l=>{this._cacheMap.set(l,a)}),o.forEach(l=>{const h=r?r[l]:t;this._cache.has(l)&&this._cache.get(l)!==h&&H("[Cache] already has key:",l),this._cache.set(l,n.get(l))})}remove(e){if(!this._cacheMap.has(e)){H(`[Assets] Asset id ${e} was not found in the Cache`);return}const t=this._cacheMap.get(e);t.cacheKeys.forEach(r=>{this._cache.delete(r)}),t.keys.forEach(r=>{this._cacheMap.delete(r)})}get parsers(){return this._parsers}}const Kt=new y_,Yn=[];q.handleByList(S.TextureSource,Yn);function od(i={}){const e=i&&i.resource,t=e?i.resource:i,s=e?i:{resource:i};for(let r=0;r<Yn.length;r++){const n=Yn[r];if(n.test(t))return new n(s)}throw new Error(`Could not find a source type for resource: ${s.resource}`)}function ad(i={},e=!1){const t=i&&i.resource,s=t?i.resource:i,r=t?i:{resource:i};if(!e&&Kt.has(s))return Kt.get(s);const n=new W({source:od(r)});return n.on("destroy",()=>{Kt.has(s)&&Kt.remove(s)}),e||Kt.set(s,n),n}function ld(i,e=!1){return typeof i=="string"?Kt.get(i):i instanceof ue?new W({source:i}):ad(i,e)}W.from=ld;ue.from=od;q.add(Jo,ea,ta,nd,fi,Ve,xr);var sa=(i=>(i[i.Low=0]="Low",i[i.Normal=1]="Normal",i[i.High=2]="High",i))(sa||{});function tt(i){if(typeof i!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(i)}`)}function Hs(i){return i.split("?")[0].split("#")[0]}function x_(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function b_(i,e,t){return i.replace(new RegExp(x_(e),"g"),t)}function v_(i,e){let t="",s=0,r=-1,n=0,o=-1;for(let a=0;a<=i.length;++a){if(a<i.length)o=i.charCodeAt(a);else{if(o===47)break;o=47}if(o===47){if(!(r===a-1||n===1))if(r!==a-1&&n===2){if(t.length<2||s!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){const l=t.lastIndexOf("/");if(l!==t.length-1){l===-1?(t="",s=0):(t=t.slice(0,l),s=t.length-1-t.lastIndexOf("/")),r=a,n=0;continue}}else if(t.length===2||t.length===1){t="",s=0,r=a,n=0;continue}}}else t.length>0?t+=`/${i.slice(r+1,a)}`:t=i.slice(r+1,a),s=a-r-1;r=a,n=0}else o===46&&n!==-1?++n:n=-1}return t}const As={toPosix(i){return b_(i,"\\","/")},isUrl(i){return/^https?:/.test(this.toPosix(i))},isDataUrl(i){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(i)},isBlobUrl(i){return i.startsWith("blob:")},hasProtocol(i){return/^[^/:]+:/.test(this.toPosix(i))},getProtocol(i){tt(i),i=this.toPosix(i);const e=/^file:\/\/\//.exec(i);if(e)return e[0];const t=/^[^/:]+:\/{0,2}/.exec(i);return t?t[0]:""},toAbsolute(i,e,t){if(tt(i),this.isDataUrl(i)||this.isBlobUrl(i))return i;const s=Hs(this.toPosix(e??ee.get().getBaseUrl())),r=Hs(this.toPosix(t??this.rootname(s)));return i=this.toPosix(i),i.startsWith("/")?As.join(r,i.slice(1)):this.isAbsolute(i)?i:this.join(s,i)},normalize(i){if(tt(i),i.length===0)return".";if(this.isDataUrl(i)||this.isBlobUrl(i))return i;i=this.toPosix(i);let e="";const t=i.startsWith("/");this.hasProtocol(i)&&(e=this.rootname(i),i=i.slice(e.length));const s=i.endsWith("/");return i=v_(i),i.length>0&&s&&(i+="/"),t?`/${i}`:e+i},isAbsolute(i){return tt(i),i=this.toPosix(i),this.hasProtocol(i)?!0:i.startsWith("/")},join(...i){if(i.length===0)return".";let e;for(let t=0;t<i.length;++t){const s=i[t];if(tt(s),s.length>0)if(e===void 0)e=s;else{const r=i[t-1]??"";this.joinExtensions.includes(this.extname(r).toLowerCase())?e+=`/../${s}`:e+=`/${s}`}}return e===void 0?".":this.normalize(e)},dirname(i){if(tt(i),i.length===0)return".";i=this.toPosix(i);let e=i.charCodeAt(0);const t=e===47;let s=-1,r=!0;const n=this.getProtocol(i),o=i;i=i.slice(n.length);for(let a=i.length-1;a>=1;--a)if(e=i.charCodeAt(a),e===47){if(!r){s=a;break}}else r=!1;return s===-1?t?"/":this.isUrl(o)?n+i:n:t&&s===1?"//":n+i.slice(0,s)},rootname(i){tt(i),i=this.toPosix(i);let e="";if(i.startsWith("/")?e="/":e=this.getProtocol(i),this.isUrl(i)){const t=i.indexOf("/",e.length);t!==-1?e=i.slice(0,t):e=i,e.endsWith("/")||(e+="/")}return e},basename(i,e){tt(i),e&&tt(e),i=Hs(this.toPosix(i));let t=0,s=-1,r=!0,n;if(e!==void 0&&e.length>0&&e.length<=i.length){if(e.length===i.length&&e===i)return"";let o=e.length-1,a=-1;for(n=i.length-1;n>=0;--n){const l=i.charCodeAt(n);if(l===47){if(!r){t=n+1;break}}else a===-1&&(r=!1,a=n+1),o>=0&&(l===e.charCodeAt(o)?--o===-1&&(s=n):(o=-1,s=a))}return t===s?s=a:s===-1&&(s=i.length),i.slice(t,s)}for(n=i.length-1;n>=0;--n)if(i.charCodeAt(n)===47){if(!r){t=n+1;break}}else s===-1&&(r=!1,s=n+1);return s===-1?"":i.slice(t,s)},extname(i){tt(i),i=Hs(this.toPosix(i));let e=-1,t=0,s=-1,r=!0,n=0;for(let o=i.length-1;o>=0;--o){const a=i.charCodeAt(o);if(a===47){if(!r){t=o+1;break}continue}s===-1&&(r=!1,s=o+1),a===46?e===-1?e=o:n!==1&&(n=1):e!==-1&&(n=-1)}return e===-1||s===-1||n===0||n===1&&e===s-1&&e===t+1?"":i.slice(e,s)},parse(i){tt(i);const e={root:"",dir:"",base:"",ext:"",name:""};if(i.length===0)return e;i=Hs(this.toPosix(i));let t=i.charCodeAt(0);const s=this.isAbsolute(i);let r;e.root=this.rootname(i),s||this.hasProtocol(i)?r=1:r=0;let n=-1,o=0,a=-1,l=!0,h=i.length-1,c=0;for(;h>=r;--h){if(t=i.charCodeAt(h),t===47){if(!l){o=h+1;break}continue}a===-1&&(l=!1,a=h+1),t===46?n===-1?n=h: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&&s?e.base=e.name=i.slice(1,a):e.base=e.name=i.slice(o,a)):(o===0&&s?(e.name=i.slice(1,n),e.base=i.slice(1,a)):(e.name=i.slice(o,n),e.base=i.slice(o,a)),e.ext=i.slice(n,a)),e.dir=this.dirname(i),e},sep:"/",delimiter:":",joinExtensions:[".html"]};function hd(i,e,t,s,r){const n=e[t];for(let o=0;o<n.length;o++){const a=n[o];t<e.length-1?hd(i.replace(s[t],a),e,t+1,s,r):r.push(i.replace(s[t],a))}}function cd(i){const e=/\{(.*?)\}/g,t=i.match(e),s=[];if(t){const r=[];t.forEach(n=>{const o=n.substring(1,n.length-1).split(",");r.push(o)}),hd(i,r,0,t,s)}else s.push(i);return s}const Kn=i=>!Array.isArray(i);class ia{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(e,t)=>`${e}${this._bundleIdConnector}${t}`,extractAssetIdFromBundle:(e,t)=>t.replace(`${e}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(e){if(this._bundleIdConnector=e.connector??this._bundleIdConnector,this._createBundleAssetId=e.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=e.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...e){e.forEach(t=>{this._preferredOrder.push(t),t.priority||(t.priority=Object.keys(t.params))}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(e){if(typeof e=="string")this._defaultSearchParams=e;else{const t=e;this._defaultSearchParams=Object.keys(t).map(s=>`${encodeURIComponent(s)}=${encodeURIComponent(t[s])}`).join("&")}}getAlias(e){const{alias:t,src:s}=e;return Yt(t||s,n=>typeof n=="string"?n:Array.isArray(n)?n.map(o=>o?.src??o):n?.src?n.src:n,!0)}removeAlias(e,t){this._assetMap[e]&&(t&&t!==this._resolverHash[e]||(delete this._resolverHash[e],delete this._assetMap[e]))}addManifest(e){this._manifest&&H("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=e,e.bundles.forEach(t=>{this.addBundle(t.name,t.assets)})}addBundle(e,t){const s=[];let r=t;Array.isArray(t)||(r=Object.entries(t).map(([n,o])=>typeof o=="string"||Array.isArray(o)?{alias:n,src:o}:{alias:n,...o})),r.forEach(n=>{const o=n.src,a=n.alias;let l;if(typeof a=="string"){const h=this._createBundleAssetId(e,a);s.push(h),l=[a,h]}else{const h=a.map(c=>this._createBundleAssetId(e,c));s.push(...h),l=[...a,...h]}this.add({...n,alias:l,src:o})}),this._bundles[e]=s}add(e){const t=[];Array.isArray(e)?t.push(...e):t.push(e);let s;s=n=>{this.hasKey(n)&&H(`[Resolver] already has key: ${n} overwriting`)},Yt(t).forEach(n=>{const{src:o}=n;let{data:a,format:l,loadParser:h,parser:c}=n;const u=Yt(o).map(g=>typeof g=="string"?cd(g):Array.isArray(g)?g:[g]),d=this.getAlias(n);Array.isArray(d)?d.forEach(s):s(d);const f=[],p=g=>{const m=this._parsers.find(_=>_.test(g));return{src:g,...m?.parse(g)}};u.forEach(g=>{g.forEach(m=>{let _={};if(typeof m!="object"?_=p(m):(a=m.data??a,l=m.format??l,(m.loadParser||m.parser)&&(h=m.loadParser??h,c=m.parser??c),_={...p(m.src),...m}),!d)throw new Error(`[Resolver] alias is undefined for this asset: ${_.src}`);_=this._buildResolvedAsset(_,{aliases:d,data:a,format:l,loadParser:h,parser:c,progressSize:n.progressSize}),f.push(_)})}),d.forEach(g=>{this._assetMap[g]=f})})}resolveBundle(e){const t=Kn(e);e=Yt(e);const s={};return e.forEach(r=>{const n=this._bundles[r];if(n){const o=this.resolve(n),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(r,l)]=h}s[r]=a}}),t?s[e[0]]:s}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const s={};for(const r in t)s[r]=t[r].src;return s}return t.src}resolve(e){const t=Kn(e);e=Yt(e);const s={};return e.forEach(r=>{if(!this._resolverHash[r])if(this._assetMap[r]){let n=this._assetMap[r];const o=this._getPreferredOrder(n);o?.priority.forEach(a=>{o.params[a].forEach(l=>{const h=n.filter(c=>c[a]?c[a]===l:!1);h.length&&(n=h)})}),this._resolverHash[r]=n[0]}else this._resolverHash[r]=this._buildResolvedAsset({alias:[r],src:r},{});s[r]=this._resolverHash[r]}),t?s[e[0]]:s}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const s=e[t],r=this._preferredOrder.find(n=>n.params.format.includes(s.format));if(r)return r}return this._preferredOrder[0]}_appendDefaultSearchParams(e){if(!this._defaultSearchParams)return e;const t=/\?/.test(e)?"&":"?";return`${e}${t}${this._defaultSearchParams}`}_buildResolvedAsset(e,t){const{aliases:s,data:r,loadParser:n,parser:o,format:a,progressSize:l}=t;return(this._basePath||this._rootPath)&&(e.src=As.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=s??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...r||{},...e.data},e.loadParser=n??e.loadParser,e.parser=o??e.parser,e.format=a??e.format??ud(e.src),l!==void 0&&(e.progressSize=l),e}}ia.RETINA_PREFIX=/@([0-9\.]+)x/;function ud(i){return i.split(".").pop().split("?").shift().split("#").shift()}const Zn=(i,e)=>{const t=e.split("?")[1];return t&&(i+=`?${t}`),i},dd=class ei{constructor(e,t){this.linkedSheets=[];let s=e;e?.source instanceof ue&&(s={texture:e,data:t});const{texture:r,data:n,cachePrefix:o=""}=s;this.cachePrefix=o,this._texture=r instanceof W?r:null,this.textureSource=r.source,this.textures={},this.animations={},this.data=n;const a=parseFloat(n.meta.scale);a?(this.resolution=a,r.source.resolution=this.resolution):this.resolution=r.source._resolution,this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}parse(){return new Promise(e=>{this._callback=e,this._batchIndex=0,this._frameKeys.length<=ei.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(e,t=!1){let s=e;const r=t?1/0:ei.BATCH_SIZE;for(;s-e<r&&s<this._frameKeys.length;){const n=this._frameKeys[s],o=this._frames[n],a=o.frame;if(a){let l=null,h=null;const c=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,u=new te(0,0,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution);o.rotated?l=new te(Math.floor(a.x)/this.resolution,Math.floor(a.y)/this.resolution,Math.floor(a.h)/this.resolution,Math.floor(a.w)/this.resolution):l=new te(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&&(h=new te(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 W({source:this.textureSource,frame:l,orig:u,trim:h,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:n.toString()})}s++}}_processAnimations(){const e=this.data.animations||{};for(const t in e){this.animations[t]=[];for(let s=0;s<e[t].length;s++){const r=e[t][s];this.animations[t].push(this.textures[r])}}}_parseComplete(){const e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*ei.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*ei.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(e=!1){for(const t in this.textures)this.textures[t].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,e&&(this._texture?.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};dd.BATCH_SIZE=1e3;let Qn=dd;const w_=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function fd(i,e,t){const s={};if(i.forEach(r=>{s[r]=e}),Object.keys(e.textures).forEach(r=>{s[`${e.cachePrefix}${r}`]=e.textures[r]}),!t){const r=As.dirname(i[0]);e.linkedSheets.forEach((n,o)=>{const a=fd([`${r}/${e.data.meta.related_multi_packs[o]}`],n,!0);Object.assign(s,a)})}return s}const pd={extension:S.Asset,cache:{test:i=>i instanceof Qn,getCacheableAssets:(i,e)=>fd(i,e,!1)},resolver:{extension:{type:S.ResolveParser,name:"resolveSpritesheet"},test:i=>{const t=i.split("?")[0].split("."),s=t.pop(),r=t.pop();return s==="json"&&w_.includes(r)},parse:i=>{const e=i.split(".");return{resolution:parseFloat(ia.RETINA_PREFIX.exec(i)?.[1]??"1"),format:e[e.length-2],src:i}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:S.LoadParser,priority:sa.Normal,name:"spritesheetLoader"},async testParse(i,e){return As.extname(e.src).toLowerCase()===".json"&&!!i.frames},async parse(i,e,t){const{texture:s,imageFilename:r,textureOptions:n,cachePrefix:o}=e?.data??{};let a=As.dirname(e.src);a&&a.lastIndexOf("/")!==a.length-1&&(a+="/");let l;if(s instanceof W)l=s;else{const u=Zn(a+(r??i.meta.image),e.src);l=(await t.load([{src:u,data:n}]))[u]}const h=new Qn({texture:l.source,data:i,cachePrefix:o});await h.parse();const c=i?.meta?.related_multi_packs;if(Array.isArray(c)){const u=[];for(const f of c){if(typeof f!="string")continue;let p=a+f;e.data?.ignoreMultiPack||(p=Zn(p,e.src),u.push(t.load({src:p,data:{textureOptions:n,ignoreMultiPack:!0}})))}const d=await Promise.all(u);h.linkedSheets=d,d.forEach(f=>{f.linkedSheets=[h].concat(h.linkedSheets.filter(p=>p!==f))})}return h},async unload(i,e,t){await t.unload(i.textureSource._sourceOrigin),i.destroy(!1)}}};q.add(pd);class ra{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),s=this._canvas.width,r=this._canvas.height,n=t.width/s*this._renderer.resolution,o=t.height/r*this._renderer.resolution,a=t.left,l=t.top,h=`translate(${a}px, ${l}px) scale(${n}, ${o})`;h!==this._lastTransform&&(this._domElement.style.transform=h,this._lastTransform=h)},this._domElement=e.domElement,this._renderer=e.renderer,!(globalThis.OffscreenCanvas&&this._renderer.canvas instanceof OffscreenCanvas)&&(this._canvas=this._renderer.canvas,this._attachObserver())}get canvas(){return this._canvas}ensureAttached(){!this._domElement.parentNode&&this._canvas.parentNode&&(this._canvas.parentNode.appendChild(this._domElement),this.updateTranslation())}_attachObserver(){"ResizeObserver"in globalThis?(this._observer&&(this._observer.disconnect(),this._observer=null),this._observer=new ResizeObserver(e=>{for(const t of e){if(t.target!==this._canvas)continue;const s=this.canvas.width,r=this.canvas.height,n=t.contentRect.width/s*this._renderer.resolution,o=t.contentRect.height/r*this._renderer.resolution;(this._lastScaleX!==n||this._lastScaleY!==o)&&(this.updateTranslation(),this._lastScaleX=n,this._lastScaleY=o)}}),this._observer.observe(this._canvas)):this._tickerAttached||We.shared.add(this.updateTranslation,this,os.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&We.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 Os{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=Os.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new ce,this.page=new ce,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=e}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(e,t,s){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,s,r,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 _n=/iPhone/i,Oh=/iPod/i,Lh=/iPad/i,Uh=/\biOS-universal(?:.+)Mac\b/i,yn=/\bAndroid(?:.+)Mobile\b/i,Nh=/Android/i,ps=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ii=/Silk/i,vt=/Windows Phone/i,zh=/\bWindows(?:.+)ARM\b/i,Hh=/BlackBerry/i,Wh=/BB10/i,$h=/Opera Mini/i,Vh=/\b(CriOS|Chrome)(?:.+)Mobile/i,jh=/Mobile(?:.+)Firefox\b/i,Xh=function(i){return typeof i<"u"&&i.platform==="MacIntel"&&typeof i.maxTouchPoints=="number"&&i.maxTouchPoints>1&&typeof MSStream>"u"};function T_(i){return function(e){return e.test(i)}}function qh(i){var e={userAgent:"",platform:"",maxTouchPoints:0};!i&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof i=="string"?e.userAgent=i:i&&i.userAgent&&(e={userAgent:i.userAgent,platform:i.platform,maxTouchPoints:i.maxTouchPoints||0});var t=e.userAgent,s=t.split("[FBAN");typeof s[1]<"u"&&(t=s[0]),s=t.split("Twitter"),typeof s[1]<"u"&&(t=s[0]);var r=T_(t),n={apple:{phone:r(_n)&&!r(vt),ipod:r(Oh),tablet:!r(_n)&&(r(Lh)||Xh(e))&&!r(vt),universal:r(Uh),device:(r(_n)||r(Oh)||r(Lh)||r(Uh)||Xh(e))&&!r(vt)},amazon:{phone:r(ps),tablet:!r(ps)&&r(Ii),device:r(ps)||r(Ii)},android:{phone:!r(vt)&&r(ps)||!r(vt)&&r(yn),tablet:!r(vt)&&!r(ps)&&!r(yn)&&(r(Ii)||r(Nh)),device:!r(vt)&&(r(ps)||r(Ii)||r(yn)||r(Nh))||r(/\bokhttp\b/i)},windows:{phone:r(vt),tablet:r(zh),device:r(vt)||r(zh)},other:{blackberry:r(Hh),blackberry10:r(Wh),opera:r($h),firefox:r(jh),chrome:r(Vh),device:r(Hh)||r(Wh)||r($h)||r(jh)||r(Vh)},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 S_=qh.default??qh,md=S_(globalThis.navigator),C_=9,Yh=100,M_=0,k_=0,Kh=2,Zh=1,E_=-1e3,P_=-1e3,A_=2,na=class gd{constructor(e,t=md){this._mobileInfo=t,this.debug=!1,this._activateOnTab=!0,this._deactivateOnMouseMove=!0,this._isActive=!1,this._isMobileAccessibility=!1,this._div=null,this._pools={},this._renderId=0,this._children=[],this._androidUpdateCount=0,this._androidUpdateFrequency=500,this._isRunningTests=!1,this._boundOnKeyDown=this._onKeyDown.bind(this),this._boundOnMouseMove=this._onMouseMove.bind(this),this._hookDiv=null,(t.tablet||t.phone)&&this._createTouchHook(),this._renderer=e}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}get hookDiv(){return this._hookDiv}get div(){return this._div}_createTouchHook(){const e=document.createElement("button");e.style.width=`${Zh}px`,e.style.height=`${Zh}px`,e.style.position="absolute",e.style.top=`${E_}px`,e.style.left=`${P_}px`,e.style.zIndex=A_.toString(),e.style.backgroundColor="#FF0000",e.title="select to enable accessibility for this content",e.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this._activate(),this._destroyTouchHook()}),document.body.appendChild(e),this._hookDiv=e}_destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}_activate(){if(this._isActive)return;this._isActive=!0,this._div||(this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.top=`${M_}px`,this._div.style.left=`${k_}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=Kh.toString(),this._canvasObserver=new ra({domElement:this._div,renderer:this._renderer})),this._deactivateOnMouseMove&&globalThis.document.addEventListener("mousemove",this._boundOnMouseMove,!0);const e=this._renderer.view.canvas;if(e.parentNode)this._canvasObserver.ensureAttached(),this._initAccessibilitySetup();else{const t=new MutationObserver(()=>{e.parentNode&&(t.disconnect(),this._canvasObserver.ensureAttached(),this._initAccessibilitySetup())});t.observe(document.body,{childList:!0,subtree:!0})}}_initAccessibilitySetup(){this._renderer.runners.postrender.add(this),this._renderer.lastObjectRendered&&this._updateAccessibleObjects(this._renderer.lastObjectRendered)}_deactivate(){if(!(!this._isActive||this._isMobileAccessibility)){this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._renderer.runners.postrender.remove(this);for(const e of this._children)e._accessibleDiv?.parentNode&&(e._accessibleDiv.parentNode.removeChild(e._accessibleDiv),e._accessibleDiv=null),e._accessibleActive=!1;for(const e in this._pools)this._pools[e].forEach(s=>{s.parentNode&&s.parentNode.removeChild(s)}),delete this._pools[e];this._div?.parentNode&&this._div.parentNode.removeChild(this._div),this._pools={},this._children=[]}}_updateAccessibleObjects(e){if(!e.visible||!e.accessibleChildren)return;e.accessible&&(e._accessibleActive||this._addChild(e),e._renderId=this._renderId);const t=e.children;if(t)for(let s=0;s<t.length;s++)this._updateAccessibleObjects(t[s])}init(e){const s={accessibilityOptions:{...gd.defaultOptions,...e?.accessibilityOptions||{}}};this.debug=s.accessibilityOptions.debug,this._activateOnTab=s.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=s.accessibilityOptions.deactivateOnMouseMove,this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),s.accessibilityOptions.enabledByDefault&&this._activate(),this._renderer.runners.postrender.remove(this)}postrender(){const e=performance.now();if(this._mobileInfo.android.device&&e<this._androidUpdateCount||(this._androidUpdateCount=e+this._androidUpdateFrequency,(!this._renderer.renderingToScreen||!this._renderer.view.canvas)&&!this._isRunningTests))return;const t=new Set;if(this._renderer.lastObjectRendered){this._updateAccessibleObjects(this._renderer.lastObjectRendered);for(const s of this._children)s._renderId===this._renderId&&t.add(this._children.indexOf(s))}for(let s=this._children.length-1;s>=0;s--){const r=this._children[s];t.has(s)||(r._accessibleDiv&&r._accessibleDiv.parentNode&&(r._accessibleDiv.parentNode.removeChild(r._accessibleDiv),this._getPool(r.accessibleType).push(r._accessibleDiv),r._accessibleDiv=null),r._accessibleActive=!1,qo(this._children,s,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let s=0;s<this._children.length;s++){const r=this._children[s];if(!r._accessibleActive||!r._accessibleDiv)continue;const n=r._accessibleDiv,o=r.hitArea||r.getBounds().rectangle;if(r.hitArea){const a=r.worldTransform;n.style.left=`${a.tx+o.x*a.a}px`,n.style.top=`${a.ty+o.y*a.d}px`,n.style.width=`${o.width*a.a}px`,n.style.height=`${o.height*a.d}px`}else this._capHitArea(o),n.style.left=`${o.x}px`,n.style.top=`${o.y}px`,n.style.width=`${o.width}px`,n.style.height=`${o.height}px`}this._renderId++}_updateDebugHTML(e){e.innerHTML=`type: ${e.type}</br> title : ${e.title}</br> tabIndex: ${e.tabIndex}`}_capHitArea(e){e.x<0&&(e.width+=e.x,e.x=0),e.y<0&&(e.height+=e.y,e.y=0);const{width:t,height:s}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>s&&(e.height=s-e.y)}_addChild(e){let s=this._getPool(e.accessibleType).pop();s?(s.innerHTML="",s.removeAttribute("title"),s.removeAttribute("aria-label"),s.tabIndex=0):(e.accessibleType==="button"?(s=document.createElement("button"),this.debug||(s.style.color="transparent")):(s=document.createElement(e.accessibleType),s.style.cssText=`
6
6
  color: transparent;
7
7
  pointer-events: none;
8
8
  padding: 0;
@@ -15,7 +15,7 @@ Deprecated since v${i}`,n=typeof console.groupCollapsed=="function"&&!vs.noColor
15
15
  -webkit-user-select: none;
16
16
  -moz-user-select: none;
17
17
  -ms-user-select: none;
18
- `),s.style.width=`${Xh}px`,s.style.height=`${Xh}px`,s.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",s.style.position="absolute",s.style.zIndex=qh.toString(),s.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?s.setAttribute("aria-live","off"):s.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?s.setAttribute("aria-relevant","additions"):s.setAttribute("aria-relevant","text"),s.addEventListener("click",this._onClick.bind(this)),s.addEventListener("focus",this._onFocus.bind(this)),s.addEventListener("focusout",this._onFocusOut.bind(this))),s.style.pointerEvents=e.accessiblePointerEvents,s.type=e.accessibleType,e.accessibleText&&(s.innerText=e.accessibleText),e.accessibleTitle&&e.accessibleTitle!==null?s.title=e.accessibleTitle:(!e.accessibleHint||e.accessibleHint===null)&&(s.title=`container ${e.tabIndex}`),e.accessibleHint&&e.accessibleHint!==null&&s.setAttribute("aria-label",e.accessibleHint),e.interactive?s.tabIndex=e.tabIndex:s.tabIndex=0,this.debug&&this._updateDebugHTML(s),e._accessibleActive=!0,e._accessibleDiv=s,s.container=e,this._children.push(e),this._div.appendChild(e._accessibleDiv)}_dispatchEvent(e,t){const{container:s}=e.target,r=this._renderer.events.rootBoundary,n=Object.assign(new Gs(r),{target:s});r.rootTarget=this._renderer.lastObjectRendered,t.forEach(o=>r.dispatchEvent(n,o))}_onClick(e){this._dispatchEvent(e,["click","pointertap","tap"])}_onFocus(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","assertive"),this._dispatchEvent(e,["mouseover"])}_onFocusOut(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","polite"),this._dispatchEvent(e,["mouseout"])}_onKeyDown(e){e.keyCode!==x_||!this._activateOnTab||this._activate()}_onMouseMove(e){e.movementX===0&&e.movementY===0||this._deactivate()}destroy(){this._deactivate(),this._destroyTouchHook(),this._canvasObserver?.destroy(),this._canvasObserver=null,this._div=null,this._pools=null,this._children=null,this._renderer=null,this._hookDiv=null,globalThis.removeEventListener("keydown",this._boundOnKeyDown),this._boundOnKeyDown=null,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._boundOnMouseMove=null}setAccessibilityEnabled(e){e?this._activate():this._deactivate()}_getPool(e){return this._pools[e]||(this._pools[e]=[]),this._pools[e]}};Qo.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"accessibility"};Qo.defaultOptions={enabledByDefault:!1,debug:!1,activateOnTab:!0,deactivateOnMouseMove:!0};let C_=Qo;const M_={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,accessibleType:"button",accessibleText:null,accessiblePointerEvents:"auto",accessibleChildren:!0,_accessibleActive:!1,_accessibleDiv:null,_renderId:-1},dn=Object.create(null),Kh=Object.create(null);function rs(i,e){let t=Kh[i];return t===void 0&&(dn[e]===void 0&&(dn[e]=1),Kh[i]=t=dn[e]++),t}let Ri;function Jo(){return(!Ri||Ri?.isContextLost())&&(Ri=ee.get().createCanvas().getContext("webgl",{})),Ri}let Bi;function fd(){if(!Bi){Bi="mediump";const i=Jo();i&&i.getShaderPrecisionFormat&&(Bi=i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision?"highp":"mediump")}return Bi}function pd(i,e,t){return e?i:t?(i=i.replace("out vec4 finalColor;",""),`
18
+ `),s.style.width=`${Yh}px`,s.style.height=`${Yh}px`,s.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",s.style.position="absolute",s.style.zIndex=Kh.toString(),s.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?s.setAttribute("aria-live","off"):s.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?s.setAttribute("aria-relevant","additions"):s.setAttribute("aria-relevant","text"),s.addEventListener("click",this._onClick.bind(this)),s.addEventListener("focus",this._onFocus.bind(this)),s.addEventListener("focusout",this._onFocusOut.bind(this))),s.style.pointerEvents=e.accessiblePointerEvents,s.type=e.accessibleType,e.accessibleText&&(s.innerText=e.accessibleText),e.accessibleTitle&&e.accessibleTitle!==null?s.title=e.accessibleTitle:(!e.accessibleHint||e.accessibleHint===null)&&(s.title=`container ${e.tabIndex}`),e.accessibleHint&&e.accessibleHint!==null&&s.setAttribute("aria-label",e.accessibleHint),e.interactive?s.tabIndex=e.tabIndex:s.tabIndex=0,this.debug&&this._updateDebugHTML(s),e._accessibleActive=!0,e._accessibleDiv=s,s.container=e,this._children.push(e),this._div.appendChild(e._accessibleDiv)}_dispatchEvent(e,t){const{container:s}=e.target,r=this._renderer.events.rootBoundary,n=Object.assign(new Os(r),{target:s});r.rootTarget=this._renderer.lastObjectRendered,t.forEach(o=>r.dispatchEvent(n,o))}_onClick(e){this._dispatchEvent(e,["click","pointertap","tap"])}_onFocus(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","assertive"),this._dispatchEvent(e,["mouseover"])}_onFocusOut(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","polite"),this._dispatchEvent(e,["mouseout"])}_onKeyDown(e){e.keyCode!==C_||!this._activateOnTab||this._activate()}_onMouseMove(e){e.movementX===0&&e.movementY===0||this._deactivate()}destroy(){this._deactivate(),this._destroyTouchHook(),this._canvasObserver?.destroy(),this._canvasObserver=null,this._div=null,this._pools=null,this._children=null,this._renderer=null,this._hookDiv=null,globalThis.removeEventListener("keydown",this._boundOnKeyDown),this._boundOnKeyDown=null,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._boundOnMouseMove=null}setAccessibilityEnabled(e){e?this._activate():this._deactivate()}_getPool(e){return this._pools[e]||(this._pools[e]=[]),this._pools[e]}};na.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"accessibility"};na.defaultOptions={enabledByDefault:!1,debug:!1,activateOnTab:!0,deactivateOnMouseMove:!0};let R_=na;const B_={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,accessibleType:"button",accessibleText:null,accessiblePointerEvents:"auto",accessibleChildren:!0,_accessibleActive:!1,_accessibleDiv:null,_renderId:-1},xn=Object.create(null),Qh=Object.create(null);function as(i,e){let t=Qh[i];return t===void 0&&(xn[e]===void 0&&(xn[e]=1),Qh[i]=t=xn[e]++),t}let Gi;function oa(){return(!Gi||Gi?.isContextLost())&&(Gi=ee.get().createCanvas().getContext("webgl",{})),Gi}let Di;function _d(){if(!Di){Di="mediump";const i=oa();i&&i.getShaderPrecisionFormat&&(Di=i.getShaderPrecisionFormat(i.FRAGMENT_SHADER,i.HIGH_FLOAT).precision?"highp":"mediump")}return Di}function yd(i,e,t){return e?i:t?(i=i.replace("out vec4 finalColor;",""),`
19
19
 
20
20
  #ifdef GL_ES // This checks if it is WebGL1
21
21
  #define in varying
@@ -30,30 +30,30 @@ Deprecated since v${i}`,n=typeof console.groupCollapsed=="function"&&!vs.noColor
30
30
  #define out varying
31
31
  #endif
32
32
  ${i}
33
- `}const k_=/\buniform\s+([iu]?sampler\w+)/g,E_=/\bprecision\s+\w+\s+([iu]?sampler\w+)\s*;/g,P_={sampler2D:"lowp",samplerCube:"lowp"};function md(i,e,t){const s=t?e.maxSupportedFragmentPrecision:e.maxSupportedVertexPrecision;if(i.substring(0,9)!=="precision"){let n=t?e.requestedFragmentPrecision:e.requestedVertexPrecision;n==="highp"&&s!=="highp"&&(n="mediump"),i=`precision ${n} float;
34
- ${i}`}else s!=="highp"&&i.substring(0,15)==="precision highp"&&(i=i.replace("precision highp","precision mediump"));const r=e.maxSupportedFragmentPrecision==="highp"?"highp":"mediump";return A_(i,r)}function A_(i,e){const t=new Set;let s="";for(const[,r]of i.matchAll(E_))t.add(r);for(const[,r]of i.matchAll(k_))t.has(r)||(t.add(r),s+=`precision ${P_[r]??e} ${r};
35
- `);return s+i}function gd(i,e){return e?`#version 300 es
36
- ${i}`:i}const R_={},B_={};function _d(i,{name:e="pixi-program"},t=!0){e=e.replace(/\s+/g,"-"),e+=t?"-fragment":"-vertex";const s=t?R_:B_;return s[e]?(s[e]++,e+=`-${s[e]}`):s[e]=1,i.indexOf("#define SHADER_NAME")!==-1?i:`${`#define SHADER_NAME ${e}`}
37
- ${i}`}function yd(i,e){return e?i.replace("#version 300 es",""):i}const fn={stripVersion:yd,ensurePrecision:md,addProgramDefines:pd,setProgramName:_d,insertVersion:gd},Hs=Object.create(null),xd=class jn{constructor(e){e={...jn.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,s={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:fd()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let r=e.fragment,n=e.vertex;Object.keys(fn).forEach(o=>{const a=s[o];r=fn[o](r,a,!0),n=fn[o](n,a,!1)}),this.fragment=r,this.vertex=n,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=rs(`${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,Hs[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return Hs[t]||(Hs[t]=new jn(e),Hs[t]._cacheKey=t),Hs[t]}};xd.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let ls=xd;const Zh={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 ks(i){return Zh[i]??Zh.float32}const I_={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"},Qh=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function Jh(i,e){let t;for(;(t=Qh.exec(i))!==null;){const s=I_[t[3]]??"float32";e[t[2]]={location:parseInt(t[1],10),format:s,stride:ks(s).stride,offset:0,instance:!1,start:0}}Qh.lastIndex=0}function G_(i){return i.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function bd({source:i,entryPoint:e}){const t={},s=G_(i),r=s.indexOf(`fn ${e}(`);if(r===-1)return t;const n=s.indexOf("->",r);if(n===-1)return t;const o=s.substring(r,n);if(Jh(o,t),Object.keys(t).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const l=a[1],h=new RegExp(`struct\\s+${l}\\s*\\{([^}]+)\\}`,"s"),c=s.match(h);c&&Jh(c[1],t)}}return t}function Yi(i){const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,s=/@binding\((\d+)\)/,r=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,l=/struct\s+(\w+)/,h=i.match(e)?.map(u=>{const d=u.match(r),f=d?.[1]??"";let p;return f==="<uniform>"?p="uniform":f.startsWith("<storage")&&(p="storage"),{group:parseInt(u.match(t)[1],10),binding:parseInt(u.match(s)[1],10),name:d[2],accessMode:p,type:u.match(n)[1]}});if(!h)return{groups:[],structs:[]};const c=i.match(o)?.map(u=>{const d=u.match(l)[1],f=u.match(a).reduce((p,g)=>{const[m,_]=g.split(":");return p[m.trim()]=_.trim(),p},{});return f?{name:d,members:f}:null}).filter(({name:u})=>h.some(d=>d.type===u||d.type.includes(`<${u}>`)))??[];return{groups:h,structs:c}}var fe=(i=>(i[i.VERTEX=1]="VERTEX",i[i.FRAGMENT=2]="FRAGMENT",i[i.COMPUTE=4]="COMPUTE",i))(fe||{});function Ii(i){return i.endsWith("<u32>")?"uint":i.endsWith("<i32>")?"sint":"float"}function vd({groups:i}){const e=[];for(let t=0;t<i.length;t++){const s=i[t];e[s.group]||(e[s.group]=[]),s.accessMode==="uniform"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,buffer:{type:"uniform"}}):s.accessMode==="storage"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,buffer:{type:"read-only-storage"}}):s.type==="sampler"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,sampler:{type:"filtering"}}):s.type==="sampler_comparison"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,sampler:{type:"comparison"}}):s.type==="texture_2d"||s.type.startsWith("texture_2d<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Ii(s.type),viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d_array"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d-array",multisampled:!1}}):s.type==="texture_2d_array"||s.type.startsWith("texture_2d_array<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Ii(s.type),viewDimension:"2d-array",multisampled:!1}}):s.type==="texture_3d"||s.type.startsWith("texture_3d<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Ii(s.type),viewDimension:"3d",multisampled:!1}}):(s.type==="texture_cube"||s.type.startsWith("texture_cube<"))&&e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Ii(s.type),viewDimension:"cube",multisampled:!1}})}for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return e}function wd({groups:i}){const e=[];for(let t=0;t<i.length;t++){const s=i[t];e[s.group]||(e[s.group]={}),e[s.group][s.name]=s.binding}return e}function Td(i,e){const t=new Set,s=new Set,r=[...i.structs,...e.structs].filter(o=>t.has(o.name)?!1:(t.add(o.name),!0)),n=[...i.groups,...e.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return s.has(a)?!1:(s.add(a),!0)});return{structs:r,groups:n}}const zs=Object.create(null);class Ft{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:s,layout:r,gpuLayout:n,name:o}=e;if(this.name=o,this.fragment=t,this.vertex=s,t.source===s.source){const a=Yi(t.source);this.structsAndGroups=a}else{const a=Yi(s.source),l=Yi(t.source);this.structsAndGroups=Td(a,l)}this.layout=r??wd(this.structsAndGroups),this.gpuLayout=n??vd(this.structsAndGroups),this.autoAssignGlobalUniforms=this.layout[0]?.globalUniforms!==void 0,this.autoAssignLocalUniforms=this.layout[1]?.localUniforms!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:e,fragment:t}=this,s=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=rs(s,"program")}get attributeData(){return this._attributeData??(this._attributeData=bd(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,zs[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return zs[t]||(zs[t]=new Ft(e),zs[t]._cacheKey=t),zs[t]}}const ea=["f32","i32","u32","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>","vec2<u32>","vec3<u32>","vec4<u32>"],Sd=ea.reduce((i,e)=>(i[e]=!0,i),{});function Cd(i,e){switch(i){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*e);case"vec3<f32>":return new Float32Array(3*e);case"vec4<f32>":return new Float32Array(4*e);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const Md=class kd extends Re{constructor(e,t){super(),this.uid=oe("uniform"),this._resourceType="uniformGroup",this._resourceId=oe("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...kd.defaultOptions,...t},this.uniformStructures=e;const s={};for(const r in e){const n=e[r];if(n.name=r,n.size=n.size??1,!Sd[n.type]){const o=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,l]=o;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${a}', size: ${l} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${ea.join(", ")}`)}n.value??(n.value=Cd(n.type,n.size)),s[r]=n.value}this.uniforms=s,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=rs(Object.keys(s).map(r=>`${r}-${e[r].type}`).join("-"),"uniform-group")}get buffer(){return this._buffer}set buffer(e){this._buffer!==e&&(this._buffer?.off("change",this.onBufferChange,this),this._buffer=e,e?.on("change",this.onBufferChange,this))}get _gcLastUsed(){return this._buffer?._gcLastUsed??-1}set _gcLastUsed(e){this._buffer&&(this._buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=oe("resource"),this.emit("change",this)}update(){this._dirtyId++}};Md.defaultOptions={ubo:!1,isStatic:!1};let rt=Md;class Mt{constructor(e){this.resources=Object.create(null),this._resourceKeysValue=null,this._dirty=!0;let t=0;for(const s in e){const r=e[s];this.setResource(r,t++)}}get _resourceKeys(){return this._resourceKeysValue??(this._resourceKeysValue=Object.keys(this.resources).map(Number)),this._resourceKeysValue}get _key(){if(this._dirty){this._dirty=!1;const e=[];let t=0;for(const s in this.resources)e[t++]=this.resources[s]?this.resources[s]._resourceId:-1;this._keyValue=e.join("|")}return this._keyValue}setResource(e,t){const s=this.resources[t];e!==s&&(s&&s.off?.("change",this.onResourceChange,this),e.on?.("change",this.onResourceChange,this),s===void 0&&(this._resourceKeysValue=null),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e){const t=this.resources,s=this._resourceKeys;for(let r=0;r<s.length;r++){const n=t[s[r]];n&&(n._gcLastUsed=e)}}destroy(){const e=this.resources;for(const t in e)e[t]?.off?.("change",this.onResourceChange,this);this.resources=null,this._resourceKeysValue=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const s in t)t[s]===e&&(t[s]=null);z(`[BindGroup] a '${e._resourceType}' was destroyed while still bound to a shader. Remove it from the shader before destroying it.`)}}}var Ke=(i=>(i[i.WEBGL=1]="WEBGL",i[i.WEBGPU=2]="WEBGPU",i[i.CANVAS=4]="CANVAS",i[i.BOTH=3]="BOTH",i))(Ke||{});class Es{constructor(e){this.data={...e};const t=Object.keys(e).sort().map(s=>`${s}:${e[s]}`).join("|");this.id=rs(t,"shader-overrides")}static from(e){return e instanceof Es?e:new Es(e)}}class ft extends Re{constructor(e){super(),this.uid=oe("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:s,groups:r,resources:n,compatibleRenderers:o,groupMap:a,overrides:l}=e;this._overrides=l?Es.from(l):null,this.gpuProgram=t,this.glProgram=s,o===void 0&&(o=0,t&&(o|=Ke.WEBGPU),s&&(o|=Ke.WEBGL)),this.compatibleRenderers=o;const h={};if(a)for(const c in a)for(const u in a[c]){const d=a[c][u];h[d]={group:c,binding:u,name:d}}if(!n&&!r&&(n={}),n&&r)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&r&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(t&&r&&!a){const c=t.structsAndGroups.groups;a={},c.forEach(u=>{a[u.group]=a[u.group]||{},a[u.group][u.binding]=u.name,h[u.name]=u})}else if(n){r={},a||(a={}),t&&t.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let c=0;for(const u in n)h[u]||(t&&!s&&z(`[Shader] the resource '${u}' matches no binding in the WGSL source — is the name correct?`),r[99]||(r[99]=new Mt,this._ownedBindGroups.push(r[99])),h[u]={group:99,binding:c,name:u},a[99]=a[99]||{},a[99][c]=u,c++);for(const u in n){const d=u;let f=n[u];!f.source&&!f._resourceType&&(f=new rt(f));const p=h[d];p&&(r[p.group]||(r[p.group]=new Mt,this._ownedBindGroups.push(r[p.group])),r[p.group].setResource(f,p.binding))}}this.groups=r,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(r,h)}addResource(e,t,s){var r,n;(r=this._uniformBindMap)[t]||(r[t]={}),(n=this._uniformBindMap[t])[s]||(n[s]=e),this.groups[t]||(this.groups[t]=new Mt,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const s={};for(const r in t){const n=t[r];Object.defineProperty(s,n.name,{get(){return e[n.group].getResource(n.binding)},set(o){e[n.group].setResource(o,n.binding)}})}return s}destroy(e=!1){this._destroyed||(this._destroyed=!0,this.emit("destroy",this),e&&(this.gpuProgram?.destroy(),this.glProgram?.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(t=>{t.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null,this._overrides=null)}static from(e){const{gpu:t,gl:s,...r}=e;let n,o;return t&&(n=Ft.from(t)),s&&(o=ls.from(s)),new ft({gpuProgram:n,glProgram:o,...r})}}const D_={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},ta={BLEND:0,OFFSET:1,CULLING:2,DEPTH_TEST:3,WINDING:4,DEPTH_MASK:5},{BLEND:pn,OFFSET:mn,CULLING:gn,DEPTH_TEST:_n,WINDING:yn,DEPTH_MASK:xn}=ta,Xn=class Ed{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<pn)}set blend(e){!!(this.data&1<<pn)!==e&&(this.data^=1<<pn)}get offsets(){return!!(this.data&1<<mn)}set offsets(e){!!(this.data&1<<mn)!==e&&(this.data^=1<<mn)}set cullMode(e){if(e==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=e==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<gn)}set culling(e){!!(this.data&1<<gn)!==e&&(this.data^=1<<gn)}get depthTest(){return!!(this.data&1<<_n)}set depthTest(e){!!(this.data&1<<_n)!==e&&(this.data^=1<<_n)}get depthMask(){return!!(this.data&1<<xn)}set depthMask(e){!!(this.data&1<<xn)!==e&&(this.data^=1<<xn)}get clockwiseFrontFace(){return!!(this.data&1<<yn)}set clockwiseFrontFace(e){!!(this.data&1<<yn)!==e&&(this.data^=1<<yn)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=D_[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const e=new Ed;return e.depthTest=!1,e.depthMask=!1,e.blend=!0,e}};Xn.default2d=Xn.for2d();let pt=Xn;const Pd=class qn extends ft{constructor(e){e={...qn.defaultOptions,...e},super(e),this.enabled=!0,this._state=pt.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,s,r){e.applyFilter(this,t,s,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:s,...r}=e;let n,o;return t&&(n=Ft.from(t)),s&&(o=ls.from(s)),new qn({gpuProgram:n,glProgram:o,...r})}};Pd.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let sa=Pd;const Yn=[];q.handleByNamedList(S.Environment,Yn);async function Ad(i){if(!i)for(let e=0;e<Yn.length;e++){const t=Yn[e];if(t.value.test()){await t.value.load();return}}}let Ws;function ia(){if(typeof Ws=="boolean")return Ws;try{Ws=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{Ws=!1}return Ws}const fi=new Set;let Kn=!1;function ec(i,e,t=2){const s=e&&e.length,r=s?e[0]*t:i.length;fi.size&&fi.clear();let n=Rd(i,0,r,t,!0);const o=[];if(!n||n.next===n.prev)return o;let a=0,l=0,h=0;if(s&&(n=N_(i,e,n,t)),i.length>80*t){a=i[0],l=i[1];let c=a,u=l;for(let d=t;d<r;d+=t){const f=i[d],p=i[d+1];f<a&&(a=f),p<l&&(l=p),f>c&&(c=f),p>u&&(u=p)}h=Math.max(c-a,u-l),h=h!==0?32767/h:0}return Zn(n,o,a,l,h),o}function Rd(i,e,t,s,r){let n=null;if(r===J_(i,e,t,s)>0)for(let o=e;o<t;o+=s)n=ic(o/s|0,i[o],i[o+1],n);else for(let o=t-s;o>=e;o-=s)n=ic(o/s|0,i[o],i[o+1],n);return n&&pi(n,n.next)&&(gi(n),n=n.next),n}function ns(i,e=i){const t=e===i;let s=i,r;do r=!1,s!==s.next&&(fi.size===0||!fi.has(s))&&(pi(s,s.next)||xe(s.prev,s,s.next)===0)?((t||s===e)&&(e=s.prev),Kn=!0,gi(s),s=s.prev,r=!0):(t||s!==e)&&(s=s.next,r=!t);while(r||s!==e);return e}function Zn(i,e,t,s,r){r&&X_(i,t,s,r);let n=i,o=!1;for(;i.prev!==i.next;){const a=i.prev,l=i.next;if(xe(a,i,l)<0&&(r?O_(i,t,s,r):F_(i))){e.push(a.i,i.i,l.i),gi(i),i=l,n=l;continue}if(i=l,i===n){if(Kn=!1,i=ns(i),Kn){n=i;continue}if(!o){i=L_(i,e),n=i,o=!0;continue}U_(i,e,t,s,r);break}}}function F_(i){const e=i.prev,t=i,s=i.next,r=e.x,n=t.x,o=s.x,a=e.y,l=t.y,h=s.y,c=Math.min(r,n,o),u=Math.min(a,l,h),d=Math.max(r,n,o),f=Math.max(a,l,h);let p=s.next;for(;p!==e;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&!(r===p.x&&a===p.y)&&ar(r,a,n,l,o,h,p.x,p.y)&&xe(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function O_(i,e,t,s){const r=i.prev,n=i,o=i.next,a=r.x,l=n.x,h=o.x,c=r.y,u=n.y,d=o.y,f=Math.min(a,l,h),p=Math.min(c,u,d),g=Math.max(a,l,h),m=Math.max(c,u,d),_=to(f,p,e,t,s),y=to(g,m,e,t,s);let x=i.prevZ;for(;x&&x.z>=_;){if(x.x>=f&&x.x<=g&&x.y>=p&&x.y<=m&&x!==o&&!(a===x.x&&c===x.y)&&ar(a,c,l,u,h,d,x.x,x.y)&&xe(x.prev,x,x.next)>=0)return!1;x=x.prevZ}let b=i.nextZ;for(;b&&b.z<=y;){if(b.x>=f&&b.x<=g&&b.y>=p&&b.y<=m&&b!==o&&!(a===b.x&&c===b.y)&&ar(a,c,l,u,h,d,b.x,b.y)&&xe(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function L_(i,e){let t=i,s=!1;do{const r=t.prev,n=t.next.next;Gd(r,t,t.next,n,!1)&&mi(r,n)&&mi(n,r)&&(e.push(r.i,t.i,n.i),gi(t),gi(t.next),t=i=n,s=!0),t=t.next}while(t!==i);return s?ns(t):t}function U_(i,e,t,s,r){let n=i;do{let o=n.next.next;for(;o!==n.prev;){if(n.i!==o.i&&K_(n,o)){let a=Dd(n,o);n=ns(n,n.next),a=ns(a,a.next),Zn(n,e,t,s,r),Zn(a,e,t,s,r);return}o=o.next}n=n.next}while(n!==i)}let Qn=!1;function N_(i,e,t,s){const r=[];for(let n=0,o=e.length;n<o;n++){const a=e[n]*s,l=n<o-1?e[n+1]*s:i.length,h=Rd(i,a,l,s,!1);h===h.next&&fi.add(h),r.push(Y_(h))}r.sort(H_),W_(i.length/s,e.length),Id(t,t),Qn=!0;for(let n=0;n<r.length;n++)t=z_(r[n],t);return Qn=!1,ns(t)}function H_(i,e){return i.x-e.x||i.y-e.y||(i.next.y-i.y)/(i.next.x-i.x)-(e.next.y-e.y)/(e.next.x-e.x)}function z_(i,e){const t=V_(i,e);if(!t)return e;const s=Dd(t,i),r=s.next;return Id(t,r.next),ns(s,s.next),ns(t,t.next)}const Bd=16;let pe=new Float64Array(0),or=0;const Jn=[],eo=[];function W_(i,e){const t=Math.ceil((i+2*e)/Bd)+e+2;pe.length<t*4&&(pe=new Float64Array(t*4)),or=0}function Id(i,e){let t=i;do{const s=or++;Jn[s]=t;let r=t.x,n=t.y,o=t.x,a=t.y,l=0;do{const c=t.next;t.z=s,c.x<r&&(r=c.x),c.x>o&&(o=c.x),c.y<n&&(n=c.y),c.y>a&&(a=c.y),t=c}while(++l<Bd&&t!==e);eo[s]=t;const h=s*4;pe[h]=r,pe[h+1]=n,pe[h+2]=o,pe[h+3]=a}while(t!==e)}function $_(i,e){const t=i.z*4;e.x<pe[t]&&(pe[t]=e.x),e.y<pe[t+1]&&(pe[t+1]=e.y),e.x>pe[t+2]&&(pe[t+2]=e.x),e.y>pe[t+3]&&(pe[t+3]=e.y)}function tc(i){let e=eo[i];for(;e.prev.next!==e;)e=e.next;return eo[i]=e,e}function sc(i){let e=Jn[i];for(;e.prev.next!==e;)e=e.next;return Jn[i]=e,e}function V_(i,e){let t=e;const s=i.x,r=i.y;let n=-1/0,o;if(pi(i,t))return t;for(let d=0,f=0;d<or;d++,f+=4){if(r<pe[f+1]||r>pe[f+3]||pe[f]>s||pe[f+2]<=n)continue;const p=tc(d);t=sc(d);do{if(t.prev.next===t){if(pi(i,t.next))return t.next;if(r<=t.y&&r>=t.next.y&&t.next.y!==t.y){const g=t.x+(r-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(g<=s&&g>n&&(n=g,o=t.x<t.next.x?t:t.next,g===s))return o}}t=t.next}while(t!==p)}if(!o)return null;const a=o.x,l=o.y,h=Math.min(r,l),c=Math.max(r,l);let u=1/0;for(let d=0,f=0;d<or;d++,f+=4){if(pe[f+2]<a||pe[f]>s||pe[f+3]<h||pe[f+1]>c)continue;const p=tc(d);t=sc(d);do{if(t.prev.next===t&&s>=t.x&&t.x>=a&&s!==t.x&&ar(r<l?s:n,r,a,l,r<l?n:s,r,t.x,t.y)){const g=Math.abs(r-t.y)/(s-t.x);(mi(t,i)||t.y===r&&t.next.y===r&&t.next.x>s)&&(g<u||g===u&&(t.x>o.x||t.x===o.x&&j_(o,t)))&&(o=t,u=g)}t=t.next}while(t!==p)}return o}function j_(i,e){return xe(i.prev,i,e.prev)<0&&xe(e.next,i,i.next)<0}const He=[];let ys=[],Lt=new Uint32Array(0),$s=new Uint32Array(0);const Vs=new Uint32Array(256);function X_(i,e,t,s){let r=i,n=0;do r.z=to(r.x,r.y,e,t,s),He[n++]=r,r=r.next;while(r!==i);q_(n);let o=null;for(let a=0;a<n;a++){const l=He[a];l.prevZ=o,o&&(o.nextZ=l),o=l}o.nextZ=null,He.fill(null,0,n),ys.fill(null,0,n)}function q_(i){if(i<=32){for(let e=1;e<i;e++){const t=He[e],s=t.z;let r=e-1;for(;r>=0&&He[r].z>s;)He[r+1]=He[r],r--;He[r+1]=t}return}Lt.length<i&&(Lt=new Uint32Array(i),$s=new Uint32Array(i),ys=new Array(i));for(let e=0;e<i;e++)Lt[e]=He[e].z;Gi(i,He,Lt,ys,$s,0),Gi(i,ys,$s,He,Lt,8),Gi(i,He,Lt,ys,$s,16),Gi(i,ys,$s,He,Lt,24)}function Gi(i,e,t,s,r,n){Vs.fill(0);for(let a=0;a<i;a++)Vs[t[a]>>>n&255]++;let o=0;for(let a=0;a<256;a++){const l=Vs[a];Vs[a]=o,o+=l}for(let a=0;a<i;a++){const l=t[a],h=Vs[l>>>n&255]++;s[h]=e[a],r[h]=l}}function to(i,e,t,s,r){return i=(i-t)*r|0,e=(e-s)*r|0,i=(i|i<<8)&16711935,i=(i|i<<4)&252645135,i=(i|i<<2)&858993459,i=(i|i<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,i|e<<1}function Y_(i){let e=i,t=i;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==i);return t}function ar(i,e,t,s,r,n,o,a){return(r-o)*(e-a)>=(i-o)*(n-a)&&(i-o)*(s-a)>=(t-o)*(e-a)&&(t-o)*(n-a)>=(r-o)*(s-a)}function K_(i,e){const t=pi(i,e)&&xe(i.prev,i,i.next)>0&&xe(e.prev,e,e.next)>0;return i.next.i!==e.i&&(t||mi(i,e)&&mi(e,i)&&(xe(i.prev,i,e.prev)!==0||xe(i,e.prev,e)!==0))&&!Z_(i,e)&&(t||Q_(i,e))}function xe(i,e,t){return(e.y-i.y)*(t.x-e.x)-(e.x-i.x)*(t.y-e.y)}function pi(i,e){return i.x===e.x&&i.y===e.y}function Gd(i,e,t,s,r=!0){const n=xe(i,e,t),o=xe(i,e,s),a=xe(t,s,i),l=xe(t,s,e);return(n>0&&o<0||n<0&&o>0)&&(a>0&&l<0||a<0&&l>0)?!0:r?!!(n===0&&Di(i,t,e)||o===0&&Di(i,s,e)||a===0&&Di(t,i,s)||l===0&&Di(t,e,s)):!1}function Di(i,e,t){return e.x<=Math.max(i.x,t.x)&&e.x>=Math.min(i.x,t.x)&&e.y<=Math.max(i.y,t.y)&&e.y>=Math.min(i.y,t.y)}function Z_(i,e){const t=Math.min(i.x,e.x),s=Math.max(i.x,e.x),r=Math.min(i.y,e.y),n=Math.max(i.y,e.y);let o=i;do{const a=o.next;if(o.x>s&&a.x>s||o.x<t&&a.x<t||o.y>n&&a.y>n||o.y<r&&a.y<r){o=a;continue}if(o.i!==i.i&&a.i!==i.i&&o.i!==e.i&&a.i!==e.i&&Gd(o,a,i,e))return!0;o=a}while(o!==i);return!1}function mi(i,e){return xe(i.prev,i,i.next)<0?xe(i,e,i.next)>=0&&xe(i,i.prev,e)>=0:xe(i,e,i.prev)<0||xe(i,i.next,e)<0}function Q_(i,e){let t=i,s=!1;const r=(i.x+e.x)/2,n=(i.y+e.y)/2;do{const o=t.next;t.y>n!=o.y>n&&r<(o.x-t.x)*(n-t.y)/(o.y-t.y)+t.x&&(s=!s),t=o}while(t!==i);return s}function Dd(i,e){const t=so(i.i,i.x,i.y),s=so(e.i,e.x,e.y),r=i.next,n=e.prev;return i.next=e,e.prev=i,t.next=r,r.prev=t,s.next=t,t.prev=s,n.next=s,s.prev=n,s}function ic(i,e,t,s){const r=so(i,e,t);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function gi(i){i.next.prev=i.prev,i.prev.next=i.next,i.prevZ&&(i.prevZ.nextZ=i.nextZ),i.nextZ&&(i.nextZ.prevZ=i.prevZ),Qn&&$_(i.prev,i.next)}function so(i,e,t){return{i,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function J_(i,e,t,s){let r=0;for(let n=e,o=t-s;n<t;n+=s)r+=(i[o]-i[n])*(i[n+1]+i[o+1]),o=n;return r}const Fd=ec.default||ec;var ye=(i=>(i[i.NONE=0]="NONE",i[i.COLOR=16384]="COLOR",i[i.STENCIL=1024]="STENCIL",i[i.DEPTH=256]="DEPTH",i[i.COLOR_DEPTH=16640]="COLOR_DEPTH",i[i.COLOR_STENCIL=17408]="COLOR_STENCIL",i[i.DEPTH_STENCIL=1280]="DEPTH_STENCIL",i[i.ALL=17664]="ALL",i))(ye||{});class ra{constructor(e){this.items=[],this._name=e}emit(e,t,s,r,n,o,a,l){const{name:h,items:c}=this;for(let u=0,d=c.length;u<d;u++)c[u][h](e,t,s,r,n,o,a,l);return this}add(e){return e[this._name]&&(this.remove(e),this.items.push(e)),this}remove(e){const t=this.items.indexOf(e);return t!==-1&&this.items.splice(t,1),this}contains(e){return this.items.indexOf(e)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const e0=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Od=class Ld extends Re{constructor(e){super(),this.tick=0,this.uid=oe("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=e.type,this.name=e.name,this.config=e;const t=[...e0,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await Ad(t),!t&&this.config.loaders&&await Promise.all(this.config.loaders.map(s=>s.value.load())),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const s in this._systemsHash)e={...this._systemsHash[s].constructor.defaultOptions,...e};e={...Ld.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let s=0;s<this.runners.init.items.length;s++)await this.runners.init.items[s].init(e);this._initOptions=e}render(e,t){this.tick++;let s=e;if(s instanceof _e&&(s={container:s},t&&(H(ue,"passing a second argument is deprecated, please use render options instead"),s.target=t.renderTexture)),s.target||(s.target=this.view.renderTarget),s.target===this.view.renderTarget&&(this._lastObjectRendered=s.container,s.clearColor??(s.clearColor=this.background.colorRgba),s.clear??(s.clear=this.background.clearBeforeRender)),s.clearColor){const r=Array.isArray(s.clearColor)&&s.clearColor.length===4;s.clearColor=r?s.clearColor:ae.shared.setValue(s.clearColor).toArray()}s.transform||(s.container.updateLocalTransform(),s.transform=s.container.localTransform),s.container.visible&&(s.container.enableRenderGroup(),this.runners.prerender.emit(s),this.runners.renderStart.emit(s),this.runners.render.emit(s),this.runners.renderEnd.emit(s),this.runners.postrender.emit(s))}resize(e,t,s){const r=this.view.resolution;this.view.resize(e,t,s),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),s!==void 0&&s!==r&&this.runners.resolutionChange.emit(s)}clear(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=ye.ALL);const{clear:s,clearColor:r,target:n,mipLevel:o,layer:a}=e;ae.shared.setValue(r??this.background.colorRgba),t.renderTarget.clear(n,s,ae.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(e){this.view.resolution=e,this.runners.resolutionChange.emit(e)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...e){e.forEach(t=>{this.runners[t]=new ra(t)})}_addSystems(e){let t;for(t in e){const s=e[t];this._addSystem(s.value,s.name)}}_addSystem(e,t){const s=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=s,this._systemsHash[t]=s;for(const r in this.runners)this.runners[r].add(s);return this}_addPipes(e,t){const s=t.reduce((r,n)=>(r[n.name]=n.value,r),{});e.forEach(r=>{const n=r.value,o=r.name,a=s[o];this.renderPipes[o]=new n(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&as.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null,this.removeAllListeners()}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!ia())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()}};Od.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let Ds=Od,Fi;function Ud(i){return Fi!==void 0||(Fi=(()=>{const e={stencil:!0,failIfMajorPerformanceCaveat:i??Ds.defaultOptions.failIfMajorPerformanceCaveat};try{if(!ee.get().getWebGLRenderingContext())return!1;let s=ee.get().createCanvas().getContext("webgl",e);const r=!!s?.getContextAttributes()?.stencil;if(s){const n=s.getExtension("WEBGL_lose_context");n&&n.loseContext()}return s=null,r}catch{return!1}})()),Fi}let Oi;async function Nd(i={}){return Oi!==void 0||(Oi=await(async()=>{const e=ee.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(i)).requestDevice(),!0}catch{return!1}})()),Oi}const rc=["webgl","webgpu","canvas"];async function Hd(i){let e=[];i.preference?Array.isArray(i.preference)?e=i.preference.slice():(e.push(i.preference),rc.forEach(n=>{n!==i.preference&&e.push(n)})):e=rc.slice();let t,s={};for(let n=0;n<e.length;n++){const o=e[n];if(o==="webgpu"&&await Nd()){const{WebGPURenderer:a}=await St(async()=>{const{WebGPURenderer:l}=await Promise.resolve().then(()=>vx);return{WebGPURenderer:l}},void 0);t=a,s={...i,...i.webgpu};break}else if(o==="webgl"&&Ud(i.failIfMajorPerformanceCaveat??Ds.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await St(async()=>{const{WebGLRenderer:l}=await Promise.resolve().then(()=>nx);return{WebGLRenderer:l}},void 0);t=a,s={...i,...i.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await St(async()=>{const{CanvasRenderer:l}=await Promise.resolve().then(()=>Hy);return{CanvasRenderer:l}},void 0);t=a,s={...i,...i.canvasOptions};break}}if(delete s.webgpu,delete s.webgl,delete s.canvasOptions,!t)throw new Error("No available renderer for the current environment");const r=new t;return await r.init(s),r}const _i="8.22.0";class na{static init(){globalThis.__PIXI_APP_INIT__?.(this,_i)}static destroy(){}}na.extension=S.Application;class oa{constructor(e){this._renderer=e}init(){globalThis.__PIXI_RENDERER_INIT__?.(this._renderer,_i)}destroy(){this._renderer=null}}oa.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"initHook",priority:-10};class aa{static init(e){Object.defineProperty(this,"resizeTo",{configurable:!0,set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let t,s;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,s=globalThis.innerHeight;else{const{clientWidth:r,clientHeight:n}=this._resizeTo;t=r,s=n}this.renderer.resize(t,s),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}aa.extension=S.Application;class la{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{configurable:!0,set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,is.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?We.shared:new We,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}la.extension=S.Application;q.add(aa);q.add(la);const zd=class io{constructor(...e){this.stage=new _e,e[0]!==void 0&&H(ue,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new _e),this.renderer=await Hd(e),io._plugins.forEach(t=>{t.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return H(ue,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}get domContainerRoot(){return this.renderer.renderPipes.dom?._domElement}destroy(e=!1,t=!1){const s=io._plugins.slice(0);s.reverse(),s.forEach(r=>{r.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};zd._plugins=[];let ha=zd;q.handleByList(S.Application,ha._plugins);q.add(na);const bn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},t0=/([astvzqmhlc])([^astvzqmhlc]*)/gi,s0=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function i0(i){const e=[];return i.replace(t0,(t,s,r)=>{let n=s.toLowerCase(),o=s;const a=r0(r);for(n==="m"&&a.length>2&&(e.push([o,...a.splice(0,2)]),n="l",o=o==="m"?"l":"L");;){if(a.length===bn[n])return e.push([o,...a]),"";if(a.length<bn[n])throw new Error("malformed path data");e.push([o,...a.splice(0,bn[n])])}}),e}function r0(i){const e=i.match(s0);return e?e.map(Number):[]}function Wd(i,e){const t=i0(i),s=[];let r=null,n=0,o=0;for(let a=0;a<t.length;a++){const l=t[a],h=l[0],c=l;switch(h){case"M":n=c[1],o=c[2],e.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],e.moveTo(n,o);break;case"H":n=c[1],e.lineTo(n,o);break;case"h":n+=c[1],e.lineTo(n,o);break;case"V":o=c[1],e.lineTo(n,o);break;case"v":o+=c[1],e.lineTo(n,o);break;case"L":n=c[1],o=c[2],e.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],e.lineTo(n,o);break;case"C":n=c[5],o=c[6],e.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":e.bezierCurveTo(n+c[1],o+c[2],n+c[3],o+c[4],n+c[5],o+c[6]),n+=c[5],o+=c[6];break;case"S":n=c[3],o=c[4],e.bezierCurveToShort(c[1],c[2],n,o);break;case"s":e.bezierCurveToShort(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"Q":n=c[3],o=c[4],e.quadraticCurveTo(c[1],c[2],n,o);break;case"q":e.quadraticCurveTo(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"T":n=c[1],o=c[2],e.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],e.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":e.closePath(),s.length>0&&(r=s.pop(),r?(n=r.startX,o=r.startY):(n=0,o=0)),r=null;break;default:z(`Unknown SVG path command: ${h}`)}h!=="Z"&&h!=="z"&&r===null&&(r={startX:n,startY:o},s.push(r))}return e}class Sr{constructor(e=0,t=0,s=0){this.type="circle",this.x=e,this.y=t,this.radius=s}clone(){return new Sr(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;const s=this.radius*this.radius;let r=this.x-e,n=this.y-t;return r*=r,n*=n,r+n<=s}strokeContains(e,t,s,r=.5){if(this.radius===0)return!1;const n=this.x-e,o=this.y-t,a=this.radius,l=(1-r)*s,h=Math.sqrt(n*n+o*o);return h<=a+l&&h>a-(s-l)}getBounds(e){return e||(e=new te),e.x=this.x-this.radius,e.y=this.y-this.radius,e.width=this.radius*2,e.height=this.radius*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class Cr{constructor(e=0,t=0,s=0,r=0){this.type="ellipse",this.x=e,this.y=t,this.halfWidth=s,this.halfHeight=r}clone(){return new Cr(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let s=(e-this.x)/this.halfWidth,r=(t-this.y)/this.halfHeight;return s*=s,r*=r,s+r<=1}strokeContains(e,t,s,r=.5){const{halfWidth:n,halfHeight:o}=this;if(n<=0||o<=0)return!1;const a=s*(1-r),l=s-a,h=n-l,c=o-l,u=n+a,d=o+a,f=e-this.x,p=t-this.y;return f*f/(u*u)+p*p/(d*d)>1?!1:h<=0||c<=0?!0:f*f/(h*h)+p*p/(c*c)>1}getBounds(e){return e||(e=new te),e.x=this.x-this.halfWidth,e.y=this.y-this.halfHeight,e.width=this.halfWidth*2,e.height=this.halfHeight*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.halfWidth=e.halfWidth,this.halfHeight=e.halfHeight,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function ca(i){const e=i.length;if(e<6)return 1;let t=0;for(let s=0,r=i[e-2],n=i[e-1];s<e;s+=2){const o=i[s],a=i[s+1];t+=(o-r)*(a+n),r=o,n=a}return t<0?-1:1}function $d(i,e,t,s,r,n){const o=i-t,a=e-s,l=r-t,h=n-s,c=o*l+a*h,u=l*l+h*h;let d=-1;u!==0&&(d=c/u);let f,p;d<0?(f=t,p=s):d>1?(f=r,p=n):(f=t+d*l,p=s+d*h);const g=i-f,m=e-p;return g*g+m*m}let n0,o0;class Ts{constructor(...e){this.type="polygon";let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!="number"){const s=[];for(let r=0,n=t.length;r<n;r++)s.push(t[r].x,t[r].y);t=s}this.points=t,this.closePath=!0}isClockwise(){let e=0;const t=this.points,s=t.length;for(let r=0;r<s;r+=2){const n=t[r],o=t[r+1],a=t[(r+2)%s],l=t[(r+3)%s];e+=(a-n)*(l+o)}return e<0}containsPolygon(e){const t=this.getBounds(n0),s=e.getBounds(o0);if(!t.containsRect(s))return!1;const r=e.points;for(let n=0;n<r.length;n+=2){const o=r[n],a=r[n+1];if(!this.contains(o,a))return!1}return!0}clone(){const e=this.points.slice(),t=new Ts(e);return t.closePath=this.closePath,t}contains(e,t){let s=!1;const r=this.points.length/2;for(let n=0,o=r-1;n<r;o=n++){const a=this.points[n*2],l=this.points[n*2+1],h=this.points[o*2],c=this.points[o*2+1];l>t!=c>t&&e<(h-a)*((t-l)/(c-l))+a&&(s=!s)}return s}strokeContains(e,t,s,r=.5){const{points:n}=this,o=r===.5?r:(r-.5)*ca(n)+.5,a=s*o,l=s-a,h=a*a,c=l*l,u=n.length-(this.closePath?0:2);for(let d=0;d<u;d+=2){const f=n[d],p=n[d+1],g=n[(d+2)%n.length],m=n[(d+3)%n.length],_=$d(e,t,f,p,g,m),y=Math.sign((g-f)*(t-p)-(m-p)*(e-f));if(_<=(y<0?h:c))return!0}return!1}getBounds(e){e||(e=new te);const t=this.points;let s=1/0,r=-1/0,n=1/0,o=-1/0;for(let a=0,l=t.length;a<l;a+=2){const h=t[a],c=t[a+1];s=h<s?h:s,r=h>r?h:r,n=c<n?c:n,o=c>o?c:o}return e.x=s,e.width=r-s,e.y=n,e.height=o-n,e}copyFrom(e){return this.points=e.points.slice(),this.closePath=e.closePath,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((e,t)=>`${e}, ${t}`,"")}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return H("8.11.0","Polygon.lastX is deprecated, please use Polygon.lastX instead."),this.points[this.points.length-2]}get y(){return H("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 Li=(i,e,t,s,r,n,o)=>{const a=i-t,l=e-s,h=Math.sqrt(a*a+l*l);return h>=r-n&&h<=r+o};class Mr{constructor(e=0,t=0,s=0,r=0,n=20){this.type="roundedRectangle",this.x=e,this.y=t,this.width=s,this.height=r,this.radius=n}getBounds(e){return e||(e=new te),e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new Mr(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){const s=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+s&&t<=this.y+this.height-s||e>=this.x+s&&e<=this.x+this.width-s)return!0;let r=e-(this.x+s),n=t-(this.y+s);const o=s*s;if(r*r+n*n<=o||(r=e-(this.x+this.width-s),r*r+n*n<=o)||(n=t-(this.y+this.height-s),r*r+n*n<=o)||(r=e-(this.x+s),r*r+n*n<=o))return!0}return!1}strokeContains(e,t,s,r=.5){const{x:n,y:o,width:a,height:l,radius:h}=this,c=s*(1-r),u=s-c,d=n+h,f=o+h,p=a-h*2,g=l-h*2,m=n+a,_=o+l;return(e>=n-c&&e<=n+u||e>=m-u&&e<=m+c)&&t>=f&&t<=f+g||(t>=o-c&&t<=o+u||t>=_-u&&t<=_+c)&&e>=d&&e<=d+p?!0:e<d&&t<f&&Li(e,t,d,f,h,u,c)||e>m-h&&t<f&&Li(e,t,m-h,f,h,u,c)||e>m-h&&t>_-h&&Li(e,t,m-h,_-h,h,u,c)||e<d&&t>_-h&&Li(e,t,d,_-h,h,u,c)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const Vd={};function kr(i,e,t){let s=2166136261;for(let r=0;r<e;r++)s^=i[r].uid,s=Math.imul(s,16777619),s>>>=0;return Vd[s]||a0(i,e,s,t)}function a0(i,e,t,s){const r={};let n=0;for(let a=0;a<s;a++){const l=a<e?i[a]:W.EMPTY.source;r[n++]=l.source,r[n++]=l.style}const o=new Mt(r);return Vd[t]=o,o}class ro{constructor(e){typeof e=="number"?this.rawBinaryData=new ArrayBuffer(e):e instanceof Uint8Array?this.rawBinaryData=e.buffer:this.rawBinaryData=e,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}get float64View(){return this._float64Array||(this._float64Array=new Float64Array(this.rawBinaryData)),this._float64Array}get bigUint64View(){return this._bigUint64Array||(this._bigUint64Array=new BigUint64Array(this.rawBinaryData)),this._bigUint64Array}view(e){return this[`${e}View`]}destroy(){this.rawBinaryData=null,this.uint32View=null,this.float32View=null,this.uint16View=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._int32View=null,this._float64Array=null,this._bigUint64Array=null}static sizeOf(e){switch(e){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${e} isn't a valid view type`)}}}function lr(i,e,t,s){if(t??(t=0),s??(s=Math.min(i.byteLength-t,e.byteLength)),!(t&7)&&!(s&7)){const r=s/8;new Float64Array(e,0,r).set(new Float64Array(i,t,r))}else if(!(t&3)&&!(s&3)){const r=s/4;new Float32Array(e,0,r).set(new Float32Array(i,t,r))}else new Uint8Array(e).set(new Uint8Array(i,t,s))}const jd={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var me=(i=>(i[i.DISABLED=0]="DISABLED",i[i.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",i[i.MASK_ACTIVE=2]="MASK_ACTIVE",i[i.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",i[i.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",i[i.NONE=5]="NONE",i))(me||{});function no(i,e){return e.alphaMode==="no-premultiply-alpha"&&jd[i]||i}const l0=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
38
- `);function h0(i){let e="";for(let t=0;t<i;++t)t>0&&(e+=`
39
- else `),t<i-1&&(e+=`if(test == ${t}.0){}`);return e}function ua(i,e){if(i===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const t=e.createShader(e.FRAGMENT_SHADER);try{for(;;){const s=l0.replace(/%forloop%/gi,h0(i));if(e.shaderSource(t,s),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))i=i/2|0;else break}}finally{e.deleteShader(t)}return i}let us=null;function Xd(){if(us)return us;const i=Jo();return us=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),us=ua(us,i),i.getExtension("WEBGL_lose_context")?.loseContext(),us}class qd{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let e=0;e<this.count;e++){const t=this.textures[e];this.textures[e]=null,this.ids[t.uid]=null}this.count=0}}class Yd{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new qd,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null,this.elements=null}}const ti=[];let hr=0;as.register({clear:()=>{if(ti.length>0)for(const i of ti)i&&i.destroy();ti.length=0,hr=0}});function nc(){return hr>0?ti[--hr]:new Yd}function oc(i){i.elements=null,ti[hr++]=i}let js=0;const Kd=class Zd{constructor(e){this.uid=oe("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],e={...Zd.defaultOptions,...e},e.maxTextures||(H("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),e.maxTextures=Xd());const{maxTextures:t,attributesInitialSize:s,indicesInitialSize:r}=e;this.attributeBuffer=new ro(s*4),this.indexBuffer=new Uint16Array(r),this.maxTextures=t}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)oc(this.batches[e]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(e){this._elements[this.elementSize++]=e,e._indexStart=this.indexSize,e._attributeStart=this.attributeSize,e._batcher=this,this.indexSize+=e.indexSize,this.attributeSize+=e.attributeSize*this.vertexSize}checkAndUpdateTexture(e,t){const s=e._batch.textures.ids[t._source.uid];return!s&&s!==0?!1:(e._textureId=s,e.texture=t,!0)}updateElement(e){this.dirty=!0;const t=this.attributeBuffer;e.packAsQuad?this.packQuadAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId):this.packAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId)}break(e){const t=this._elements;if(!t[this.elementStart])return;let s=nc(),r=s.textures;r.clear();const n=t[this.elementStart];let o=no(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 l=this.attributeBuffer.float32View,h=this.attributeBuffer.uint32View,c=this.indexBuffer;let u=this._batchIndexSize,d=this._batchIndexStart,f="startBatch",p=[];const g=this.maxTextures;for(let m=this.elementStart;m<this.elementSize;++m){const _=t[m];t[m]=null;const x=_.texture._source,b=no(_.blendMode,x),v=o!==b||a!==_.topology;if(x._batchTick===js&&!v){_._textureId=x._textureBindLocation,u+=_.indexSize,_.packAsQuad?(this.packQuadAttributes(_,l,h,_._attributeStart,_._textureId),this.packQuadIndex(c,_._indexStart,_._attributeStart/this.vertexSize)):(this.packAttributes(_,l,h,_._attributeStart,_._textureId),this.packIndex(_,c,_._indexStart,_._attributeStart/this.vertexSize)),_._batch=s,p.push(_);continue}x._batchTick=js,(r.count>=g||v)&&(this._finishBatch(s,d,u-d,r,o,a,e,f,p),f="renderBatch",d=u,o=b,a=_.topology,s=nc(),r=s.textures,r.clear(),p=[],++js),_._textureId=x._textureBindLocation=r.count,r.ids[x.uid]=r.count,r.textures[r.count++]=x,_._batch=s,p.push(_),u+=_.indexSize,_.packAsQuad?(this.packQuadAttributes(_,l,h,_._attributeStart,_._textureId),this.packQuadIndex(c,_._indexStart,_._attributeStart/this.vertexSize)):(this.packAttributes(_,l,h,_._attributeStart,_._textureId),this.packIndex(_,c,_._indexStart,_._attributeStart/this.vertexSize))}r.count>0&&(this._finishBatch(s,d,u-d,r,o,a,e,f,p),d=u,++js),this.elementStart=this.elementSize,this._batchIndexStart=d,this._batchIndexSize=u}_finishBatch(e,t,s,r,n,o,a,l,h){e.gpuBindGroup=null,e.bindGroup=null,e.action=l,e.batcher=this,e.textures=r,e.blendMode=n,e.topology=o,e.start=t,e.size=s,e.elements=h,++js,this.batches[this.batchIndex++]=e,a.add(e)}finish(e){this.break(e)}ensureAttributeBuffer(e){e*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(e*4)}ensureIndexBuffer(e){e<=this.indexBuffer.length||this._resizeIndexBuffer(e)}_resizeAttributeBuffer(e){const t=Math.max(e,this.attributeBuffer.size*2),s=new ro(t);lr(this.attributeBuffer.rawBinaryData,s.rawBinaryData),this.attributeBuffer=s}_resizeIndexBuffer(e){const t=this.indexBuffer;let s=Math.max(e,t.length*1.5);s+=s%2;const r=s>65535?new Uint32Array(s):new Uint16Array(s);if(r.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let n=0;n<t.length;n++)r[n]=t[n];else lr(t.buffer,r.buffer);this.indexBuffer=r}packQuadIndex(e,t,s){e[t]=s+0,e[t+1]=s+1,e[t+2]=s+2,e[t+3]=s+0,e[t+4]=s+2,e[t+5]=s+3}packIndex(e,t,s,r){const n=e.indices,o=e.indexSize,a=e.indexOffset,l=e.attributeOffset;for(let h=0;h<o;h++)t[s++]=r+n[h+a]-l}destroy(e={}){if(this.batches!==null){for(let t=0;t<this.batchIndex;t++)oc(this.batches[t]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,e.shader&&(this.shader?.destroy(),this.shader=null);for(let t=0;t<this._elements.length;t++)this._elements[t]&&(this._elements[t]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};Kd.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let Qd=Kd;var ce=(i=>(i[i.MAP_READ=1]="MAP_READ",i[i.MAP_WRITE=2]="MAP_WRITE",i[i.COPY_SRC=4]="COPY_SRC",i[i.COPY_DST=8]="COPY_DST",i[i.INDEX=16]="INDEX",i[i.VERTEX=32]="VERTEX",i[i.UNIFORM=64]="UNIFORM",i[i.STORAGE=128]="STORAGE",i[i.INDIRECT=256]="INDIRECT",i[i.QUERY_RESOLVE=512]="QUERY_RESOLVE",i[i.STATIC=1024]="STATIC",i))(ce||{});class kt extends Re{constructor(e){let{data:t,size:s}=e;const{usage:r,label:n,shrinkToFit:o}=e;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=oe("buffer"),this._resourceType="buffer",this._resourceId=oe("resource"),this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,s??(s=t?.byteLength);const a=!!t;this.descriptor={size:s,usage:r,mappedAtCreation:a,label:n},this.shrinkToFit=o??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&ce.STATIC)}set static(e){e?this.descriptor.usage|=ce.STATIC:this.descriptor.usage&=~ce.STATIC}setDataWithSize(e,t,s){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===e){s&&this.emit("update",this);return}const r=this._data;if(this._data=e,this._dataInt32=null,!r||r.length!==e.length){!this.shrinkToFit&&r&&e.byteLength<r.byteLength?s&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=oe("resource"),this.emit("change",this));return}s&&this.emit("update",this)}update(e,t){this._updateSize=e??this._updateSize,this._updateOffset=t||0,this._updateID++,this.emit("update",this)}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=oe("resource"),this.emit("change",this))}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function da(i,e){if(!(i instanceof kt)){let t=e?ce.INDEX:ce.VERTEX;i instanceof Array&&(e?(i=new Uint32Array(i),t=ce.INDEX|ce.COPY_DST):(i=new Float32Array(i),t=ce.VERTEX|ce.COPY_DST)),i=new kt({data:i,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return i}function Jd(i,e,t){const s=i.getAttribute(e);if(!s)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const r=s.buffer.data;let n=1/0,o=1/0,a=-1/0,l=-1/0;const h=r.BYTES_PER_ELEMENT,c=(s.offset||0)/h,u=(s.stride||8)/h;for(let d=c;d<r.length;d+=u){const f=r[d],p=r[d+1];f>a&&(a=f),p>l&&(l=p),f<n&&(n=f),p<o&&(o=p)}return t.minX=n,t.minY=o,t.maxX=a,t.maxY=l,t}function c0(i){return(i instanceof kt||Array.isArray(i)||i.BYTES_PER_ELEMENT)&&(i={buffer:i}),i.buffer=da(i.buffer,!1),i}class Er extends Re{constructor(e={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=oe("geometry"),this._layoutKey=0,this.instanceCount=1,this.indexCount=0,this._bounds=new Ee,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;const{attributes:t,indexBuffer:s,topology:r}=e;if(this.buffers=[],this.attributes={},t)for(const n in t)this.addAttribute(n,t[n]);this.instanceCount=e.instanceCount??1,this.indexCount=e.indexCount??0,s&&this.addIndex(s),this.topology=r||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;const e=this.attributes;for(const t in e){const s=e[t];if(s.instance)continue;const r=s.buffer;return this._vertexCount=r.data.length/(s.stride/4||s.size),this._vertexCount}return this._vertexCount=0,0}getSize(){return H("8.20.0","Geometry.getSize is deprecated, please use Geometry.vertexCount instead."),this.vertexCount}addAttribute(e,t){const s=c0(t);this.buffers.indexOf(s.buffer)===-1&&(this.buffers.push(s.buffer),s.buffer.on("update",this.onBufferUpdate,this),s.buffer.on("change",this.onBufferUpdate,this)),this.attributes[e]=s,this._vertexCountDirty=!0}addIndex(e){this.indexBuffer=da(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,Jd(this,"aPosition",this._bounds)):this._bounds}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){this.emit("destroy",this);for(const t of this.buffers)t.off("update",this.onBufferUpdate,this),t.off("change",this.onBufferUpdate,this),e&&t.destroy();this.unload(),this.removeAllListeners(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const u0=new Float32Array(1),d0=new Uint32Array(1);class ef extends Er{constructor(){const t=new kt({data:u0,label:"attribute-batch-buffer",usage:ce.VERTEX|ce.COPY_DST,shrinkToFit:!1}),s=new kt({data:d0,label:"index-batch-buffer",usage:ce.INDEX|ce.COPY_DST,shrinkToFit:!1}),r=24;super({attributes:{aPosition:{buffer:t,format:"float32x2",stride:r,offset:0},aUV:{buffer:t,format:"float32x2",stride:r,offset:8},aColor:{buffer:t,format:"unorm8x4",stride:r,offset:16},aTextureIdAndRound:{buffer:t,format:"uint16x2",stride:r,offset:20}},indexBuffer:s})}}function oo(i,e,t){if(i)for(const s in i){const r=s.toLocaleLowerCase(),n=e[r];if(n){let o=i[s];s==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),t&&n.push(`//----${t}----//`),n.push(o)}else z(`${s} placement hook does not exist in shader`)}}const f0=/\{\{(.*?)\}\}/g;function ao(i){const e={};return(i.match(f0)?.map(s=>s.replace(/[{()}]/g,""))??[]).forEach(s=>{e[s]=[]}),e}function ac(i,e){let t;const s=/@in\s+([^;]+);/g;for(;(t=s.exec(i))!==null;)e.push(t[1])}function lo(i,e,t=!1){const s=[];ac(e,s),i.forEach(a=>{a.header&&ac(a.header,s)});const r=s;t&&r.sort();const n=r.map((a,l)=>` @location(${l}) ${a},`).join(`
33
+ `}const I_=/\buniform\s+([iu]?sampler\w+)/g,G_=/\bprecision\s+\w+\s+([iu]?sampler\w+)\s*;/g,D_={sampler2D:"lowp",samplerCube:"lowp"};function xd(i,e,t){const s=t?e.maxSupportedFragmentPrecision:e.maxSupportedVertexPrecision;if(i.substring(0,9)!=="precision"){let n=t?e.requestedFragmentPrecision:e.requestedVertexPrecision;n==="highp"&&s!=="highp"&&(n="mediump"),i=`precision ${n} float;
34
+ ${i}`}else s!=="highp"&&i.substring(0,15)==="precision highp"&&(i=i.replace("precision highp","precision mediump"));const r=e.maxSupportedFragmentPrecision==="highp"?"highp":"mediump";return F_(i,r)}function F_(i,e){const t=new Set;let s="";for(const[,r]of i.matchAll(G_))t.add(r);for(const[,r]of i.matchAll(I_))t.has(r)||(t.add(r),s+=`precision ${D_[r]??e} ${r};
35
+ `);return s+i}function bd(i,e){return e?`#version 300 es
36
+ ${i}`:i}const O_={},L_={};function vd(i,{name:e="pixi-program"},t=!0){e=e.replace(/\s+/g,"-"),e+=t?"-fragment":"-vertex";const s=t?O_:L_;return s[e]?(s[e]++,e+=`-${s[e]}`):s[e]=1,i.indexOf("#define SHADER_NAME")!==-1?i:`${`#define SHADER_NAME ${e}`}
37
+ ${i}`}function wd(i,e){return e?i.replace("#version 300 es",""):i}const bn={stripVersion:wd,ensurePrecision:xd,addProgramDefines:yd,setProgramName:vd,insertVersion:bd},Ws=Object.create(null),Td=class Jn{constructor(e){e={...Jn.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,s={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:_d()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let r=e.fragment,n=e.vertex;Object.keys(bn).forEach(o=>{const a=s[o];r=bn[o](r,a,!0),n=bn[o](n,a,!1)}),this.fragment=r,this.vertex=n,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=as(`${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,Ws[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return Ws[t]||(Ws[t]=new Jn(e),Ws[t]._cacheKey=t),Ws[t]}};Td.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let us=Td;const Jh={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 mt(i){return Jh[i]??Jh.float32}const U_={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"},ec=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function tc(i,e){let t;for(;(t=ec.exec(i))!==null;){const s=U_[t[3]]??"float32";e[t[2]]={location:parseInt(t[1],10),format:s,stride:mt(s).stride,offset:0,instance:!1,start:0}}ec.lastIndex=0}function N_(i){return i.replace(/\/\/.*$/gm,"").replace(/\/\*[\s\S]*?\*\//g,"")}function Sd({source:i,entryPoint:e}){const t={},s=N_(i),r=s.indexOf(`fn ${e}(`);if(r===-1)return t;const n=s.indexOf("->",r);if(n===-1)return t;const o=s.substring(r,n);if(tc(o,t),Object.keys(t).length===0){const a=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(a){const l=a[1],h=new RegExp(`struct\\s+${l}\\s*\\{([^}]+)\\}`,"s"),c=s.match(h);c&&tc(c[1],t)}}return t}function Qi(i){const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,s=/@binding\((\d+)\)/,r=/var(<[^>]+>)? (\w+)/,n=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,a=/(\w+)\s*:\s*([\w\<\>]+)/g,l=/struct\s+(\w+)/,h=i.match(e)?.map(u=>{const d=u.match(r),f=d?.[1]??"";let p;return f==="<uniform>"?p="uniform":f.startsWith("<storage")&&(p="storage"),{group:parseInt(u.match(t)[1],10),binding:parseInt(u.match(s)[1],10),name:d[2],accessMode:p,type:u.match(n)[1]}});if(!h)return{groups:[],structs:[]};const c=i.match(o)?.map(u=>{const d=u.match(l)[1],f=u.match(a).reduce((p,g)=>{const[m,_]=g.split(":");return p[m.trim()]=_.trim(),p},{});return f?{name:d,members:f}:null}).filter(({name:u})=>h.some(d=>d.type===u||d.type.includes(`<${u}>`)))??[];return{groups:h,structs:c}}var fe=(i=>(i[i.VERTEX=1]="VERTEX",i[i.FRAGMENT=2]="FRAGMENT",i[i.COMPUTE=4]="COMPUTE",i))(fe||{});function Fi(i){return i.endsWith("<u32>")?"uint":i.endsWith("<i32>")?"sint":"float"}function Cd({groups:i}){const e=[];for(let t=0;t<i.length;t++){const s=i[t];e[s.group]||(e[s.group]=[]),s.accessMode==="uniform"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,buffer:{type:"uniform"}}):s.accessMode==="storage"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,buffer:{type:"read-only-storage"}}):s.type==="sampler"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,sampler:{type:"filtering"}}):s.type==="sampler_comparison"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,sampler:{type:"comparison"}}):s.type==="texture_2d"||s.type.startsWith("texture_2d<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Fi(s.type),viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d",multisampled:!1}}):s.type==="texture_depth_2d_array"?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:"depth",viewDimension:"2d-array",multisampled:!1}}):s.type==="texture_2d_array"||s.type.startsWith("texture_2d_array<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Fi(s.type),viewDimension:"2d-array",multisampled:!1}}):s.type==="texture_3d"||s.type.startsWith("texture_3d<")?e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Fi(s.type),viewDimension:"3d",multisampled:!1}}):(s.type==="texture_cube"||s.type.startsWith("texture_cube<"))&&e[s.group].push({binding:s.binding,visibility:fe.VERTEX|fe.FRAGMENT,texture:{sampleType:Fi(s.type),viewDimension:"cube",multisampled:!1}})}for(let t=0;t<e.length;t++)e[t]||(e[t]=[]);return e}function Md({groups:i}){const e=[];for(let t=0;t<i.length;t++){const s=i[t];e[s.group]||(e[s.group]={}),e[s.group][s.name]=s.binding}return e}function kd(i,e){const t=new Set,s=new Set,r=[...i.structs,...e.structs].filter(o=>t.has(o.name)?!1:(t.add(o.name),!0)),n=[...i.groups,...e.groups].filter(o=>{const a=`${o.name}-${o.binding}`;return s.has(a)?!1:(s.add(a),!0)});return{structs:r,groups:n}}const $s=Object.create(null);class Lt{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:s,layout:r,gpuLayout:n,name:o}=e;if(this.name=o,this.fragment=t,this.vertex=s,t.source===s.source){const a=Qi(t.source);this.structsAndGroups=a}else{const a=Qi(s.source),l=Qi(t.source);this.structsAndGroups=kd(a,l)}this.layout=r??Md(this.structsAndGroups),this.gpuLayout=n??Cd(this.structsAndGroups),this.autoAssignGlobalUniforms=this.layout[0]?.globalUniforms!==void 0,this.autoAssignLocalUniforms=this.layout[1]?.localUniforms!==void 0,this._generateProgramKey()}_generateProgramKey(){const{vertex:e,fragment:t}=this,s=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=as(s,"program")}get attributeData(){return this._attributeData??(this._attributeData=Sd(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,$s[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return $s[t]||($s[t]=new Lt(e),$s[t]._cacheKey=t),$s[t]}}const aa=["f32","i32","u32","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>","vec2<u32>","vec3<u32>","vec4<u32>"],Ed=aa.reduce((i,e)=>(i[e]=!0,i),{});function Pd(i,e){switch(i){case"f32":return 0;case"vec2<f32>":return new Float32Array(2*e);case"vec3<f32>":return new Float32Array(3*e);case"vec4<f32>":return new Float32Array(4*e);case"mat2x2<f32>":return new Float32Array([1,0,0,1]);case"mat3x3<f32>":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4x4<f32>":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}const Ad=class Rd extends Re{constructor(e,t){super(),this.uid=oe("uniform"),this._resourceType="uniformGroup",this._resourceId=oe("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...Rd.defaultOptions,...t},this.uniformStructures=e;const s={};for(const r in e){const n=e[r];if(n.name=r,n.size=n.size??1,!Ed[n.type]){const o=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(o){const[,a,l]=o;throw new Error(`Uniform type ${n.type} is not supported. Use type: '${a}', size: ${l} instead.`)}throw new Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${aa.join(", ")}`)}n.value??(n.value=Pd(n.type,n.size)),s[r]=n.value}this.uniforms=s,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=as(Object.keys(s).map(r=>`${r}-${e[r].type}`).join("-"),"uniform-group")}get buffer(){return this._buffer}set buffer(e){this._buffer!==e&&(this._buffer?.off("change",this.onBufferChange,this),this._buffer=e,e?.on("change",this.onBufferChange,this))}get _gcLastUsed(){return this._buffer?._gcLastUsed??-1}set _gcLastUsed(e){this._buffer&&(this._buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=oe("resource"),this.emit("change",this)}update(){this._dirtyId++}};Ad.defaultOptions={ubo:!1,isStatic:!1};let Ze=Ad;class Pt{constructor(e){this.resources=Object.create(null),this._resourceKeysValue=null,this._dirty=!0;let t=0;for(const s in e){const r=e[s];this.setResource(r,t++)}}get _resourceKeys(){return this._resourceKeysValue??(this._resourceKeysValue=Object.keys(this.resources).map(Number)),this._resourceKeysValue}get _key(){if(this._dirty){this._dirty=!1;const e=[];let t=0;for(const s in this.resources)e[t++]=this.resources[s]?this.resources[s]._resourceId:-1;this._keyValue=e.join("|")}return this._keyValue}setResource(e,t){const s=this.resources[t];e!==s&&(s&&s.off?.("change",this.onResourceChange,this),e.on?.("change",this.onResourceChange,this),s===void 0&&(this._resourceKeysValue=null),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e){const t=this.resources,s=this._resourceKeys;for(let r=0;r<s.length;r++){const n=t[s[r]];n&&(n._gcLastUsed=e)}}destroy(){const e=this.resources;for(const t in e)e[t]?.off?.("change",this.onResourceChange,this);this.resources=null,this._resourceKeysValue=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const s in t)t[s]===e&&(t[s]=null);H(`[BindGroup] a '${e._resourceType}' was destroyed while still bound to a shader. Remove it from the shader before destroying it.`)}}}var Ke=(i=>(i[i.WEBGL=1]="WEBGL",i[i.WEBGPU=2]="WEBGPU",i[i.CANVAS=4]="CANVAS",i[i.BOTH=3]="BOTH",i))(Ke||{});class Rs{constructor(e){this.data={...e};const t=Object.keys(e).sort().map(s=>`${s}:${e[s]}`).join("|");this.id=as(t,"shader-overrides")}static from(e){return e instanceof Rs?e:new Rs(e)}}class gt extends Re{constructor(e){super(),this.uid=oe("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:s,groups:r,resources:n,compatibleRenderers:o,groupMap:a,overrides:l}=e;this._overrides=l?Rs.from(l):null,this.gpuProgram=t,this.glProgram=s,o===void 0&&(o=0,t&&(o|=Ke.WEBGPU),s&&(o|=Ke.WEBGL)),this.compatibleRenderers=o;const h={};if(a)for(const c in a)for(const u in a[c]){const d=a[c][u];h[d]={group:c,binding:u,name:d}}if(!n&&!r&&(n={}),n&&r)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&r&&!a)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(t&&r&&!a){const c=t.structsAndGroups.groups;a={},c.forEach(u=>{a[u.group]=a[u.group]||{},a[u.group][u.binding]=u.name,h[u.name]=u})}else if(n){r={},a||(a={}),t&&t.structsAndGroups.groups.forEach(d=>{a[d.group]=a[d.group]||{},a[d.group][d.binding]=d.name,h[d.name]=d});let c=0;for(const u in n)h[u]||(t&&!s&&H(`[Shader] the resource '${u}' matches no binding in the WGSL source — is the name correct?`),r[99]||(r[99]=new Pt,this._ownedBindGroups.push(r[99])),h[u]={group:99,binding:c,name:u},a[99]=a[99]||{},a[99][c]=u,c++);for(const u in n){const d=u;let f=n[u];!f.source&&!f._resourceType&&(f=new Ze(f));const p=h[d];p&&(r[p.group]||(r[p.group]=new Pt,this._ownedBindGroups.push(r[p.group])),r[p.group].setResource(f,p.binding))}}this.groups=r,this._uniformBindMap=a,this.resources=this._buildResourceAccessor(r,h)}addResource(e,t,s){var r,n;(r=this._uniformBindMap)[t]||(r[t]={}),(n=this._uniformBindMap[t])[s]||(n[s]=e),this.groups[t]||(this.groups[t]=new Pt,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const s={};for(const r in t){const n=t[r];Object.defineProperty(s,n.name,{get(){return e[n.group].getResource(n.binding)},set(o){e[n.group].setResource(o,n.binding)}})}return s}destroy(e=!1){this._destroyed||(this._destroyed=!0,this.emit("destroy",this),e&&(this.gpuProgram?.destroy(),this.glProgram?.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(t=>{t.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null,this._overrides=null)}static from(e){const{gpu:t,gl:s,...r}=e;let n,o;return t&&(n=Lt.from(t)),s&&(o=us.from(s)),new gt({gpuProgram:n,glProgram:o,...r})}}const z_={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},la={BLEND:0,OFFSET:1,CULLING:2,DEPTH_TEST:3,WINDING:4,DEPTH_MASK:5},{BLEND:vn,OFFSET:wn,CULLING:Tn,DEPTH_TEST:Sn,WINDING:Cn,DEPTH_MASK:Mn}=la,eo=class Bd{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<vn)}set blend(e){!!(this.data&1<<vn)!==e&&(this.data^=1<<vn)}get offsets(){return!!(this.data&1<<wn)}set offsets(e){!!(this.data&1<<wn)!==e&&(this.data^=1<<wn)}set cullMode(e){if(e==="none"){this.culling=!1;return}this.culling=!0,this.clockwiseFrontFace=e==="front"}get cullMode(){return this.culling?this.clockwiseFrontFace?"front":"back":"none"}get culling(){return!!(this.data&1<<Tn)}set culling(e){!!(this.data&1<<Tn)!==e&&(this.data^=1<<Tn)}get depthTest(){return!!(this.data&1<<Sn)}set depthTest(e){!!(this.data&1<<Sn)!==e&&(this.data^=1<<Sn)}get depthMask(){return!!(this.data&1<<Mn)}set depthMask(e){!!(this.data&1<<Mn)!==e&&(this.data^=1<<Mn)}get clockwiseFrontFace(){return!!(this.data&1<<Cn)}set clockwiseFrontFace(e){!!(this.data&1<<Cn)!==e&&(this.data^=1<<Cn)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=z_[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){const e=new Bd;return e.depthTest=!1,e.depthMask=!1,e.blend=!0,e}};eo.default2d=eo.for2d();let _t=eo;const Id=class to extends gt{constructor(e){e={...to.defaultOptions,...e},super(e),this.enabled=!0,this._state=_t.for2d(),this.blendMode=e.blendMode,this.padding=e.padding,typeof e.antialias=="boolean"?this.antialias=e.antialias?"on":"off":this.antialias=e.antialias,this.resolution=e.resolution,this.blendRequired=e.blendRequired,this.clipToViewport=e.clipToViewport,this.addResource("uTexture",0,1),e.blendRequired&&this.addResource("uBackTexture",0,3)}apply(e,t,s,r){e.applyFilter(this,t,s,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:s,...r}=e;let n,o;return t&&(n=Lt.from(t)),s&&(o=us.from(s)),new to({gpuProgram:n,glProgram:o,...r})}};Id.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let ha=Id;const so=[];q.handleByNamedList(S.Environment,so);async function Gd(i){if(!i)for(let e=0;e<so.length;e++){const t=so[e];if(t.value.test()){await t.value.load();return}}}let Vs;function ca(){if(typeof Vs=="boolean")return Vs;try{Vs=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{Vs=!1}return Vs}const pi=new Set;let io=!1;function sc(i,e,t=2){const s=e&&e.length,r=s?e[0]*t:i.length;pi.size&&pi.clear();let n=Dd(i,0,r,t,!0);const o=[];if(!n||n.next===n.prev)return o;let a=0,l=0,h=0;if(s&&(n=j_(i,e,n,t)),i.length>80*t){a=i[0],l=i[1];let c=a,u=l;for(let d=t;d<r;d+=t){const f=i[d],p=i[d+1];f<a&&(a=f),p<l&&(l=p),f>c&&(c=f),p>u&&(u=p)}h=Math.max(c-a,u-l),h=h!==0?32767/h:0}return ro(n,o,a,l,h),o}function Dd(i,e,t,s,r){let n=null;if(r===n0(i,e,t,s)>0)for(let o=e;o<t;o+=s)n=nc(o/s|0,i[o],i[o+1],n);else for(let o=t-s;o>=e;o-=s)n=nc(o/s|0,i[o],i[o+1],n);return n&&mi(n,n.next)&&(_i(n),n=n.next),n}function ls(i,e=i){const t=e===i;let s=i,r;do r=!1,s!==s.next&&(pi.size===0||!pi.has(s))&&(mi(s,s.next)||xe(s.prev,s,s.next)===0)?((t||s===e)&&(e=s.prev),io=!0,_i(s),s=s.prev,r=!0):(t||s!==e)&&(s=s.next,r=!t);while(r||s!==e);return e}function ro(i,e,t,s,r){r&&J_(i,t,s,r);let n=i,o=!1;for(;i.prev!==i.next;){const a=i.prev,l=i.next;if(xe(a,i,l)<0&&(r?W_(i,t,s,r):H_(i))){e.push(a.i,i.i,l.i),_i(i),i=l,n=l;continue}if(i=l,i===n){if(io=!1,i=ls(i),io){n=i;continue}if(!o){i=$_(i,e),n=i,o=!0;continue}V_(i,e,t,s,r);break}}}function H_(i){const e=i.prev,t=i,s=i.next,r=e.x,n=t.x,o=s.x,a=e.y,l=t.y,h=s.y,c=Math.min(r,n,o),u=Math.min(a,l,h),d=Math.max(r,n,o),f=Math.max(a,l,h);let p=s.next;for(;p!==e;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&!(r===p.x&&a===p.y)&&cr(r,a,n,l,o,h,p.x,p.y)&&xe(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function W_(i,e,t,s){const r=i.prev,n=i,o=i.next,a=r.x,l=n.x,h=o.x,c=r.y,u=n.y,d=o.y,f=Math.min(a,l,h),p=Math.min(c,u,d),g=Math.max(a,l,h),m=Math.max(c,u,d),_=lo(f,p,e,t,s),y=lo(g,m,e,t,s);let x=i.prevZ;for(;x&&x.z>=_;){if(x.x>=f&&x.x<=g&&x.y>=p&&x.y<=m&&x!==o&&!(a===x.x&&c===x.y)&&cr(a,c,l,u,h,d,x.x,x.y)&&xe(x.prev,x,x.next)>=0)return!1;x=x.prevZ}let b=i.nextZ;for(;b&&b.z<=y;){if(b.x>=f&&b.x<=g&&b.y>=p&&b.y<=m&&b!==o&&!(a===b.x&&c===b.y)&&cr(a,c,l,u,h,d,b.x,b.y)&&xe(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function $_(i,e){let t=i,s=!1;do{const r=t.prev,n=t.next.next;Ld(r,t,t.next,n,!1)&&gi(r,n)&&gi(n,r)&&(e.push(r.i,t.i,n.i),_i(t),_i(t.next),t=i=n,s=!0),t=t.next}while(t!==i);return s?ls(t):t}function V_(i,e,t,s,r){let n=i;do{let o=n.next.next;for(;o!==n.prev;){if(n.i!==o.i&&s0(n,o)){let a=Ud(n,o);n=ls(n,n.next),a=ls(a,a.next),ro(n,e,t,s,r),ro(a,e,t,s,r);return}o=o.next}n=n.next}while(n!==i)}let no=!1;function j_(i,e,t,s){const r=[];for(let n=0,o=e.length;n<o;n++){const a=e[n]*s,l=n<o-1?e[n+1]*s:i.length,h=Dd(i,a,l,s,!1);h===h.next&&pi.add(h),r.push(t0(h))}r.sort(X_),Y_(i.length/s,e.length),Od(t,t),no=!0;for(let n=0;n<r.length;n++)t=q_(r[n],t);return no=!1,ls(t)}function X_(i,e){return i.x-e.x||i.y-e.y||(i.next.y-i.y)/(i.next.x-i.x)-(e.next.y-e.y)/(e.next.x-e.x)}function q_(i,e){const t=Z_(i,e);if(!t)return e;const s=Ud(t,i),r=s.next;return Od(t,r.next),ls(s,s.next),ls(t,t.next)}const Fd=16;let pe=new Float64Array(0),hr=0;const oo=[],ao=[];function Y_(i,e){const t=Math.ceil((i+2*e)/Fd)+e+2;pe.length<t*4&&(pe=new Float64Array(t*4)),hr=0}function Od(i,e){let t=i;do{const s=hr++;oo[s]=t;let r=t.x,n=t.y,o=t.x,a=t.y,l=0;do{const c=t.next;t.z=s,c.x<r&&(r=c.x),c.x>o&&(o=c.x),c.y<n&&(n=c.y),c.y>a&&(a=c.y),t=c}while(++l<Fd&&t!==e);ao[s]=t;const h=s*4;pe[h]=r,pe[h+1]=n,pe[h+2]=o,pe[h+3]=a}while(t!==e)}function K_(i,e){const t=i.z*4;e.x<pe[t]&&(pe[t]=e.x),e.y<pe[t+1]&&(pe[t+1]=e.y),e.x>pe[t+2]&&(pe[t+2]=e.x),e.y>pe[t+3]&&(pe[t+3]=e.y)}function ic(i){let e=ao[i];for(;e.prev.next!==e;)e=e.next;return ao[i]=e,e}function rc(i){let e=oo[i];for(;e.prev.next!==e;)e=e.next;return oo[i]=e,e}function Z_(i,e){let t=e;const s=i.x,r=i.y;let n=-1/0,o;if(mi(i,t))return t;for(let d=0,f=0;d<hr;d++,f+=4){if(r<pe[f+1]||r>pe[f+3]||pe[f]>s||pe[f+2]<=n)continue;const p=ic(d);t=rc(d);do{if(t.prev.next===t){if(mi(i,t.next))return t.next;if(r<=t.y&&r>=t.next.y&&t.next.y!==t.y){const g=t.x+(r-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(g<=s&&g>n&&(n=g,o=t.x<t.next.x?t:t.next,g===s))return o}}t=t.next}while(t!==p)}if(!o)return null;const a=o.x,l=o.y,h=Math.min(r,l),c=Math.max(r,l);let u=1/0;for(let d=0,f=0;d<hr;d++,f+=4){if(pe[f+2]<a||pe[f]>s||pe[f+3]<h||pe[f+1]>c)continue;const p=ic(d);t=rc(d);do{if(t.prev.next===t&&s>=t.x&&t.x>=a&&s!==t.x&&cr(r<l?s:n,r,a,l,r<l?n:s,r,t.x,t.y)){const g=Math.abs(r-t.y)/(s-t.x);(gi(t,i)||t.y===r&&t.next.y===r&&t.next.x>s)&&(g<u||g===u&&(t.x>o.x||t.x===o.x&&Q_(o,t)))&&(o=t,u=g)}t=t.next}while(t!==p)}return o}function Q_(i,e){return xe(i.prev,i,e.prev)<0&&xe(e.next,i,i.next)<0}const ze=[];let ws=[],Nt=new Uint32Array(0),js=new Uint32Array(0);const Xs=new Uint32Array(256);function J_(i,e,t,s){let r=i,n=0;do r.z=lo(r.x,r.y,e,t,s),ze[n++]=r,r=r.next;while(r!==i);e0(n);let o=null;for(let a=0;a<n;a++){const l=ze[a];l.prevZ=o,o&&(o.nextZ=l),o=l}o.nextZ=null,ze.fill(null,0,n),ws.fill(null,0,n)}function e0(i){if(i<=32){for(let e=1;e<i;e++){const t=ze[e],s=t.z;let r=e-1;for(;r>=0&&ze[r].z>s;)ze[r+1]=ze[r],r--;ze[r+1]=t}return}Nt.length<i&&(Nt=new Uint32Array(i),js=new Uint32Array(i),ws=new Array(i));for(let e=0;e<i;e++)Nt[e]=ze[e].z;Oi(i,ze,Nt,ws,js,0),Oi(i,ws,js,ze,Nt,8),Oi(i,ze,Nt,ws,js,16),Oi(i,ws,js,ze,Nt,24)}function Oi(i,e,t,s,r,n){Xs.fill(0);for(let a=0;a<i;a++)Xs[t[a]>>>n&255]++;let o=0;for(let a=0;a<256;a++){const l=Xs[a];Xs[a]=o,o+=l}for(let a=0;a<i;a++){const l=t[a],h=Xs[l>>>n&255]++;s[h]=e[a],r[h]=l}}function lo(i,e,t,s,r){return i=(i-t)*r|0,e=(e-s)*r|0,i=(i|i<<8)&16711935,i=(i|i<<4)&252645135,i=(i|i<<2)&858993459,i=(i|i<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,i|e<<1}function t0(i){let e=i,t=i;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==i);return t}function cr(i,e,t,s,r,n,o,a){return(r-o)*(e-a)>=(i-o)*(n-a)&&(i-o)*(s-a)>=(t-o)*(e-a)&&(t-o)*(n-a)>=(r-o)*(s-a)}function s0(i,e){const t=mi(i,e)&&xe(i.prev,i,i.next)>0&&xe(e.prev,e,e.next)>0;return i.next.i!==e.i&&(t||gi(i,e)&&gi(e,i)&&(xe(i.prev,i,e.prev)!==0||xe(i,e.prev,e)!==0))&&!i0(i,e)&&(t||r0(i,e))}function xe(i,e,t){return(e.y-i.y)*(t.x-e.x)-(e.x-i.x)*(t.y-e.y)}function mi(i,e){return i.x===e.x&&i.y===e.y}function Ld(i,e,t,s,r=!0){const n=xe(i,e,t),o=xe(i,e,s),a=xe(t,s,i),l=xe(t,s,e);return(n>0&&o<0||n<0&&o>0)&&(a>0&&l<0||a<0&&l>0)?!0:r?!!(n===0&&Li(i,t,e)||o===0&&Li(i,s,e)||a===0&&Li(t,i,s)||l===0&&Li(t,e,s)):!1}function Li(i,e,t){return e.x<=Math.max(i.x,t.x)&&e.x>=Math.min(i.x,t.x)&&e.y<=Math.max(i.y,t.y)&&e.y>=Math.min(i.y,t.y)}function i0(i,e){const t=Math.min(i.x,e.x),s=Math.max(i.x,e.x),r=Math.min(i.y,e.y),n=Math.max(i.y,e.y);let o=i;do{const a=o.next;if(o.x>s&&a.x>s||o.x<t&&a.x<t||o.y>n&&a.y>n||o.y<r&&a.y<r){o=a;continue}if(o.i!==i.i&&a.i!==i.i&&o.i!==e.i&&a.i!==e.i&&Ld(o,a,i,e))return!0;o=a}while(o!==i);return!1}function gi(i,e){return xe(i.prev,i,i.next)<0?xe(i,e,i.next)>=0&&xe(i,i.prev,e)>=0:xe(i,e,i.prev)<0||xe(i,i.next,e)<0}function r0(i,e){let t=i,s=!1;const r=(i.x+e.x)/2,n=(i.y+e.y)/2;do{const o=t.next;t.y>n!=o.y>n&&r<(o.x-t.x)*(n-t.y)/(o.y-t.y)+t.x&&(s=!s),t=o}while(t!==i);return s}function Ud(i,e){const t=ho(i.i,i.x,i.y),s=ho(e.i,e.x,e.y),r=i.next,n=e.prev;return i.next=e,e.prev=i,t.next=r,r.prev=t,s.next=t,t.prev=s,n.next=s,s.prev=n,s}function nc(i,e,t,s){const r=ho(i,e,t);return s?(r.next=s.next,r.prev=s,s.next.prev=r,s.next=r):(r.prev=r,r.next=r),r}function _i(i){i.next.prev=i.prev,i.prev.next=i.next,i.prevZ&&(i.prevZ.nextZ=i.nextZ),i.nextZ&&(i.nextZ.prevZ=i.prevZ),no&&K_(i.prev,i.next)}function ho(i,e,t){return{i,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function n0(i,e,t,s){let r=0;for(let n=e,o=t-s;n<t;n+=s)r+=(i[o]-i[n])*(i[n+1]+i[o+1]),o=n;return r}const Nd=sc.default||sc;var ye=(i=>(i[i.NONE=0]="NONE",i[i.COLOR=16384]="COLOR",i[i.STENCIL=1024]="STENCIL",i[i.DEPTH=256]="DEPTH",i[i.COLOR_DEPTH=16640]="COLOR_DEPTH",i[i.COLOR_STENCIL=17408]="COLOR_STENCIL",i[i.DEPTH_STENCIL=1280]="DEPTH_STENCIL",i[i.ALL=17664]="ALL",i))(ye||{});class ua{constructor(e){this.items=[],this._name=e}emit(e,t,s,r,n,o,a,l){const{name:h,items:c}=this;for(let u=0,d=c.length;u<d;u++)c[u][h](e,t,s,r,n,o,a,l);return this}add(e){return e[this._name]&&(this.remove(e),this.items.push(e)),this}remove(e){const t=this.items.indexOf(e);return t!==-1&&this.items.splice(t,1),this}contains(e){return this.items.indexOf(e)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}}const o0=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],zd=class Hd extends Re{constructor(e){super(),this.tick=0,this.uid=oe("renderer"),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=e.type,this.name=e.name,this.config=e;const t=[...o0,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await Gd(t),!t&&this.config.loaders&&await Promise.all(this.config.loaders.map(s=>s.value.load())),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const s in this._systemsHash)e={...this._systemsHash[s].constructor.defaultOptions,...e};e={...Hd.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let s=0;s<this.runners.init.items.length;s++)await this.runners.init.items[s].init(e);this._initOptions=e}render(e,t){this.tick++;let s=e;if(s instanceof _e&&(s={container:s},t&&(z(de,"passing a second argument is deprecated, please use render options instead"),s.target=t.renderTexture)),s.target||(s.target=this.view.renderTarget),s.target===this.view.renderTarget&&(this._lastObjectRendered=s.container,s.clearColor??(s.clearColor=this.background.colorRgba),s.clear??(s.clear=this.background.clearBeforeRender)),s.clearColor){const r=Array.isArray(s.clearColor)&&s.clearColor.length===4;s.clearColor=r?s.clearColor:le.shared.setValue(s.clearColor).toArray()}s.transform||(s.container.updateLocalTransform(),s.transform=s.container.localTransform),s.container.visible&&(s.container.enableRenderGroup(),this.runners.prerender.emit(s),this.runners.renderStart.emit(s),this.runners.render.emit(s),this.runners.renderEnd.emit(s),this.runners.postrender.emit(s))}resize(e,t,s){const r=this.view.resolution;this.view.resize(e,t,s),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),s!==void 0&&s!==r&&this.runners.resolutionChange.emit(s)}clear(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=ye.ALL);const{clear:s,clearColor:r,target:n,mipLevel:o,layer:a}=e;le.shared.setValue(r??this.background.colorRgba),t.renderTarget.clear(n,s,le.shared.toArray(),o??0,a??0)}get resolution(){return this.view.resolution}set resolution(e){this.view.resolution=e,this.runners.resolutionChange.emit(e)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...e){e.forEach(t=>{this.runners[t]=new ua(t)})}_addSystems(e){let t;for(t in e){const s=e[t];this._addSystem(s.value,s.name)}}_addSystem(e,t){const s=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=s,this._systemsHash[t]=s;for(const r in this.runners)this.runners[r].add(s);return this}_addPipes(e,t){const s=t.reduce((r,n)=>(r[n.name]=n.value,r),{});e.forEach(r=>{const n=r.value,o=r.name,a=s[o];this.renderPipes[o]=new n(this,a?new a:null),this.runners.destroy.add(this.renderPipes[o])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&cs.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null,this.removeAllListeners()}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!ca())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()}};zd.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let ds=zd,Ui;function Wd(i){return Ui!==void 0||(Ui=(()=>{const e={stencil:!0,failIfMajorPerformanceCaveat:i??ds.defaultOptions.failIfMajorPerformanceCaveat};try{if(!ee.get().getWebGLRenderingContext())return!1;let s=ee.get().createCanvas().getContext("webgl",e);const r=!!s?.getContextAttributes()?.stencil;if(s){const n=s.getExtension("WEBGL_lose_context");n&&n.loseContext()}return s=null,r}catch{return!1}})()),Ui}let Ni;async function $d(i={}){return Ni!==void 0||(Ni=await(async()=>{const e=ee.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(i)).requestDevice(),!0}catch{return!1}})()),Ni}const oc=["webgl","webgpu","canvas"];async function Vd(i){let e=[];i.preference?Array.isArray(i.preference)?e=i.preference.slice():(e.push(i.preference),oc.forEach(n=>{n!==i.preference&&e.push(n)})):e=oc.slice();let t,s={};for(let n=0;n<e.length;n++){const o=e[n];if(o==="webgpu"&&await $d()){const{WebGPURenderer:a}=await kt(async()=>{const{WebGPURenderer:l}=await Promise.resolve().then(()=>kx);return{WebGPURenderer:l}},void 0);t=a,s={...i,...i.webgpu};break}else if(o==="webgl"&&Wd(i.failIfMajorPerformanceCaveat??ds.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:a}=await kt(async()=>{const{WebGLRenderer:l}=await Promise.resolve().then(()=>ux);return{WebGLRenderer:l}},void 0);t=a,s={...i,...i.webgl};break}else if(o==="canvas"){const{CanvasRenderer:a}=await kt(async()=>{const{CanvasRenderer:l}=await Promise.resolve().then(()=>Xy);return{CanvasRenderer:l}},void 0);t=a,s={...i,...i.canvasOptions};break}}if(delete s.webgpu,delete s.webgl,delete s.canvasOptions,!t)throw new Error("No available renderer for the current environment");const r=new t;return await r.init(s),r}const yi="8.22.0";class da{static init(){globalThis.__PIXI_APP_INIT__?.(this,yi)}static destroy(){}}da.extension=S.Application;class fa{constructor(e){this._renderer=e}init(){globalThis.__PIXI_RENDERER_INIT__?.(this._renderer,yi)}destroy(){this._renderer=null}}fa.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"initHook",priority:-10};class pa{static init(e){Object.defineProperty(this,"resizeTo",{configurable:!0,set(t){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=t,t&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let t,s;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,s=globalThis.innerHeight;else{const{clientWidth:r,clientHeight:n}=this._resizeTo;t=r,s=n}this.renderer.resize(t,s),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}pa.extension=S.Application;class ma{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{configurable:!0,set(t){this._ticker&&this._ticker.remove(this.render,this),this._ticker=t,t&&t.add(this.render,this,os.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?We.shared:new We,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}ma.extension=S.Application;q.add(pa);q.add(ma);const jd=class co{constructor(...e){this.stage=new _e,e[0]!==void 0&&z(de,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new _e),this.renderer=await Vd(e),co._plugins.forEach(t=>{t.init.call(this,e)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return z(de,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}get domContainerRoot(){return this.renderer.renderPipes.dom?._domElement}destroy(e=!1,t=!1){const s=co._plugins.slice(0);s.reverse(),s.forEach(r=>{r.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};jd._plugins=[];let ga=jd;q.handleByList(S.Application,ga._plugins);q.add(da);const kn={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},a0=/([astvzqmhlc])([^astvzqmhlc]*)/gi,l0=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function h0(i){const e=[];return i.replace(a0,(t,s,r)=>{let n=s.toLowerCase(),o=s;const a=c0(r);for(n==="m"&&a.length>2&&(e.push([o,...a.splice(0,2)]),n="l",o=o==="m"?"l":"L");;){if(a.length===kn[n])return e.push([o,...a]),"";if(a.length<kn[n])throw new Error("malformed path data");e.push([o,...a.splice(0,kn[n])])}}),e}function c0(i){const e=i.match(l0);return e?e.map(Number):[]}function Xd(i,e){const t=h0(i),s=[];let r=null,n=0,o=0;for(let a=0;a<t.length;a++){const l=t[a],h=l[0],c=l;switch(h){case"M":n=c[1],o=c[2],e.moveTo(n,o);break;case"m":n+=c[1],o+=c[2],e.moveTo(n,o);break;case"H":n=c[1],e.lineTo(n,o);break;case"h":n+=c[1],e.lineTo(n,o);break;case"V":o=c[1],e.lineTo(n,o);break;case"v":o+=c[1],e.lineTo(n,o);break;case"L":n=c[1],o=c[2],e.lineTo(n,o);break;case"l":n+=c[1],o+=c[2],e.lineTo(n,o);break;case"C":n=c[5],o=c[6],e.bezierCurveTo(c[1],c[2],c[3],c[4],n,o);break;case"c":e.bezierCurveTo(n+c[1],o+c[2],n+c[3],o+c[4],n+c[5],o+c[6]),n+=c[5],o+=c[6];break;case"S":n=c[3],o=c[4],e.bezierCurveToShort(c[1],c[2],n,o);break;case"s":e.bezierCurveToShort(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"Q":n=c[3],o=c[4],e.quadraticCurveTo(c[1],c[2],n,o);break;case"q":e.quadraticCurveTo(n+c[1],o+c[2],n+c[3],o+c[4]),n+=c[3],o+=c[4];break;case"T":n=c[1],o=c[2],e.quadraticCurveToShort(n,o);break;case"t":n+=c[1],o+=c[2],e.quadraticCurveToShort(n,o);break;case"A":n=c[6],o=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"a":n+=c[6],o+=c[7],e.arcToSvg(c[1],c[2],c[3],c[4],c[5],n,o);break;case"Z":case"z":e.closePath(),s.length>0&&(r=s.pop(),r?(n=r.startX,o=r.startY):(n=0,o=0)),r=null;break;default:H(`Unknown SVG path command: ${h}`)}h!=="Z"&&h!=="z"&&r===null&&(r={startX:n,startY:o},s.push(r))}return e}class kr{constructor(e=0,t=0,s=0){this.type="circle",this.x=e,this.y=t,this.radius=s}clone(){return new kr(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;const s=this.radius*this.radius;let r=this.x-e,n=this.y-t;return r*=r,n*=n,r+n<=s}strokeContains(e,t,s,r=.5){if(this.radius===0)return!1;const n=this.x-e,o=this.y-t,a=this.radius,l=(1-r)*s,h=Math.sqrt(n*n+o*o);return h<=a+l&&h>a-(s-l)}getBounds(e){return e||(e=new te),e.x=this.x-this.radius,e.y=this.y-this.radius,e.width=this.radius*2,e.height=this.radius*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}}class Er{constructor(e=0,t=0,s=0,r=0){this.type="ellipse",this.x=e,this.y=t,this.halfWidth=s,this.halfHeight=r}clone(){return new Er(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let s=(e-this.x)/this.halfWidth,r=(t-this.y)/this.halfHeight;return s*=s,r*=r,s+r<=1}strokeContains(e,t,s,r=.5){const{halfWidth:n,halfHeight:o}=this;if(n<=0||o<=0)return!1;const a=s*(1-r),l=s-a,h=n-l,c=o-l,u=n+a,d=o+a,f=e-this.x,p=t-this.y;return f*f/(u*u)+p*p/(d*d)>1?!1:h<=0||c<=0?!0:f*f/(h*h)+p*p/(c*c)>1}getBounds(e){return e||(e=new te),e.x=this.x-this.halfWidth,e.y=this.y-this.halfHeight,e.width=this.halfWidth*2,e.height=this.halfHeight*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.halfWidth=e.halfWidth,this.halfHeight=e.halfHeight,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}}function _a(i){const e=i.length;if(e<6)return 1;let t=0;for(let s=0,r=i[e-2],n=i[e-1];s<e;s+=2){const o=i[s],a=i[s+1];t+=(o-r)*(a+n),r=o,n=a}return t<0?-1:1}function qd(i,e,t,s,r,n){const o=i-t,a=e-s,l=r-t,h=n-s,c=o*l+a*h,u=l*l+h*h;let d=-1;u!==0&&(d=c/u);let f,p;d<0?(f=t,p=s):d>1?(f=r,p=n):(f=t+d*l,p=s+d*h);const g=i-f,m=e-p;return g*g+m*m}let u0,d0;class ks{constructor(...e){this.type="polygon";let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!="number"){const s=[];for(let r=0,n=t.length;r<n;r++)s.push(t[r].x,t[r].y);t=s}this.points=t,this.closePath=!0}isClockwise(){let e=0;const t=this.points,s=t.length;for(let r=0;r<s;r+=2){const n=t[r],o=t[r+1],a=t[(r+2)%s],l=t[(r+3)%s];e+=(a-n)*(l+o)}return e<0}containsPolygon(e){const t=this.getBounds(u0),s=e.getBounds(d0);if(!t.containsRect(s))return!1;const r=e.points;for(let n=0;n<r.length;n+=2){const o=r[n],a=r[n+1];if(!this.contains(o,a))return!1}return!0}clone(){const e=this.points.slice(),t=new ks(e);return t.closePath=this.closePath,t}contains(e,t){let s=!1;const r=this.points.length/2;for(let n=0,o=r-1;n<r;o=n++){const a=this.points[n*2],l=this.points[n*2+1],h=this.points[o*2],c=this.points[o*2+1];l>t!=c>t&&e<(h-a)*((t-l)/(c-l))+a&&(s=!s)}return s}strokeContains(e,t,s,r=.5){const{points:n}=this,o=r===.5?r:(r-.5)*_a(n)+.5,a=s*o,l=s-a,h=a*a,c=l*l,u=n.length-(this.closePath?0:2);for(let d=0;d<u;d+=2){const f=n[d],p=n[d+1],g=n[(d+2)%n.length],m=n[(d+3)%n.length],_=qd(e,t,f,p,g,m),y=Math.sign((g-f)*(t-p)-(m-p)*(e-f));if(_<=(y<0?h:c))return!0}return!1}getBounds(e){e||(e=new te);const t=this.points;let s=1/0,r=-1/0,n=1/0,o=-1/0;for(let a=0,l=t.length;a<l;a+=2){const h=t[a],c=t[a+1];s=h<s?h:s,r=h>r?h:r,n=c<n?c:n,o=c>o?c:o}return e.x=s,e.width=r-s,e.y=n,e.height=o-n,e}copyFrom(e){return this.points=e.points.slice(),this.closePath=e.closePath,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((e,t)=>`${e}, ${t}`,"")}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return z("8.11.0","Polygon.lastX is deprecated, please use Polygon.lastX instead."),this.points[this.points.length-2]}get y(){return z("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 zi=(i,e,t,s,r,n,o)=>{const a=i-t,l=e-s,h=Math.sqrt(a*a+l*l);return h>=r-n&&h<=r+o};class Pr{constructor(e=0,t=0,s=0,r=0,n=20){this.type="roundedRectangle",this.x=e,this.y=t,this.width=s,this.height=r,this.radius=n}getBounds(e){return e||(e=new te),e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new Pr(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){const s=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+s&&t<=this.y+this.height-s||e>=this.x+s&&e<=this.x+this.width-s)return!0;let r=e-(this.x+s),n=t-(this.y+s);const o=s*s;if(r*r+n*n<=o||(r=e-(this.x+this.width-s),r*r+n*n<=o)||(n=t-(this.y+this.height-s),r*r+n*n<=o)||(r=e-(this.x+s),r*r+n*n<=o))return!0}return!1}strokeContains(e,t,s,r=.5){const{x:n,y:o,width:a,height:l,radius:h}=this,c=s*(1-r),u=s-c,d=n+h,f=o+h,p=a-h*2,g=l-h*2,m=n+a,_=o+l;return(e>=n-c&&e<=n+u||e>=m-u&&e<=m+c)&&t>=f&&t<=f+g||(t>=o-c&&t<=o+u||t>=_-u&&t<=_+c)&&e>=d&&e<=d+p?!0:e<d&&t<f&&zi(e,t,d,f,h,u,c)||e>m-h&&t<f&&zi(e,t,m-h,f,h,u,c)||e>m-h&&t>_-h&&zi(e,t,m-h,_-h,h,u,c)||e<d&&t>_-h&&zi(e,t,d,_-h,h,u,c)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const Yd={};function Ar(i,e,t){let s=2166136261;for(let r=0;r<e;r++)s^=i[r].uid,s=Math.imul(s,16777619),s>>>=0;return Yd[s]||f0(i,e,s,t)}function f0(i,e,t,s){const r={};let n=0;for(let a=0;a<s;a++){const l=a<e?i[a]:W.EMPTY.source;r[n++]=l.source,r[n++]=l.style}const o=new Pt(r);return Yd[t]=o,o}class Zt{constructor(e){typeof e=="number"?this.rawBinaryData=new ArrayBuffer(e):e instanceof Uint8Array?this.rawBinaryData=e.buffer:this.rawBinaryData=e,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||(this._int8View=new Int8Array(this.rawBinaryData)),this._int8View}get uint8View(){return this._uint8View||(this._uint8View=new Uint8Array(this.rawBinaryData)),this._uint8View}get int16View(){return this._int16View||(this._int16View=new Int16Array(this.rawBinaryData)),this._int16View}get int32View(){return this._int32View||(this._int32View=new Int32Array(this.rawBinaryData)),this._int32View}get float64View(){return this._float64Array||(this._float64Array=new Float64Array(this.rawBinaryData)),this._float64Array}get bigUint64View(){return this._bigUint64Array||(this._bigUint64Array=new BigUint64Array(this.rawBinaryData)),this._bigUint64Array}view(e){return this[`${e}View`]}destroy(){this.rawBinaryData=null,this.uint32View=null,this.float32View=null,this.uint16View=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._int32View=null,this._float64Array=null,this._bigUint64Array=null}static sizeOf(e){switch(e){case"int8":case"uint8":return 1;case"int16":case"uint16":return 2;case"int32":case"uint32":case"float32":return 4;default:throw new Error(`${e} isn't a valid view type`)}}}function ur(i,e,t,s){if(t??(t=0),s??(s=Math.min(i.byteLength-t,e.byteLength)),!(t&7)&&!(s&7)){const r=s/8;new Float64Array(e,0,r).set(new Float64Array(i,t,r))}else if(!(t&3)&&!(s&3)){const r=s/4;new Float32Array(e,0,r).set(new Float32Array(i,t,r))}else new Uint8Array(e).set(new Uint8Array(i,t,s))}const Kd={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var me=(i=>(i[i.DISABLED=0]="DISABLED",i[i.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",i[i.MASK_ACTIVE=2]="MASK_ACTIVE",i[i.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",i[i.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",i[i.NONE=5]="NONE",i))(me||{});function uo(i,e){return e.alphaMode==="no-premultiply-alpha"&&Kd[i]||i}const p0=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
38
+ `);function m0(i){let e="";for(let t=0;t<i;++t)t>0&&(e+=`
39
+ else `),t<i-1&&(e+=`if(test == ${t}.0){}`);return e}function ya(i,e){if(i===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const t=e.createShader(e.FRAGMENT_SHADER);try{for(;;){const s=p0.replace(/%forloop%/gi,m0(i));if(e.shaderSource(t,s),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))i=i/2|0;else break}}finally{e.deleteShader(t)}return i}let ms=null;function Zd(){if(ms)return ms;const i=oa();return ms=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),ms=ya(ms,i),i.getExtension("WEBGL_lose_context")?.loseContext(),ms}class Qd{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let e=0;e<this.count;e++){const t=this.textures[e];this.textures[e]=null,this.ids[t.uid]=null}this.count=0}}class Jd{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new Qd,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 ii=[];let dr=0;cs.register({clear:()=>{if(ii.length>0)for(const i of ii)i&&i.destroy();ii.length=0,dr=0}});function ac(){return dr>0?ii[--dr]:new Jd}function lc(i){i.elements=null,ii[dr++]=i}let qs=0;const ef=class tf{constructor(e){this.uid=oe("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],e={...tf.defaultOptions,...e},e.maxTextures||(z("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),e.maxTextures=Zd());const{maxTextures:t,attributesInitialSize:s,indicesInitialSize:r}=e;this.attributeBuffer=new Zt(s*4),this.indexBuffer=new Uint16Array(r),this.maxTextures=t}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)lc(this.batches[e]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(e){this._elements[this.elementSize++]=e,e._indexStart=this.indexSize,e._attributeStart=this.attributeSize,e._batcher=this,this.indexSize+=e.indexSize,this.attributeSize+=e.attributeSize*this.vertexSize}checkAndUpdateTexture(e,t){const s=e._batch.textures.ids[t._source.uid];return!s&&s!==0?!1:(e._textureId=s,e.texture=t,!0)}updateElement(e){this.dirty=!0;const t=this.attributeBuffer;e.packAsQuad?this.packQuadAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId):this.packAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId)}break(e){const t=this._elements;if(!t[this.elementStart])return;let s=ac(),r=s.textures;r.clear();const n=t[this.elementStart];let o=uo(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 l=this.attributeBuffer.float32View,h=this.attributeBuffer.uint32View,c=this.indexBuffer;let u=this._batchIndexSize,d=this._batchIndexStart,f="startBatch",p=[];const g=this.maxTextures;for(let m=this.elementStart;m<this.elementSize;++m){const _=t[m];t[m]=null;const x=_.texture._source,b=uo(_.blendMode,x),v=o!==b||a!==_.topology;if(x._batchTick===qs&&!v){_._textureId=x._textureBindLocation,u+=_.indexSize,_.packAsQuad?(this.packQuadAttributes(_,l,h,_._attributeStart,_._textureId),this.packQuadIndex(c,_._indexStart,_._attributeStart/this.vertexSize)):(this.packAttributes(_,l,h,_._attributeStart,_._textureId),this.packIndex(_,c,_._indexStart,_._attributeStart/this.vertexSize)),_._batch=s,p.push(_);continue}x._batchTick=qs,(r.count>=g||v)&&(this._finishBatch(s,d,u-d,r,o,a,e,f,p),f="renderBatch",d=u,o=b,a=_.topology,s=ac(),r=s.textures,r.clear(),p=[],++qs),_._textureId=x._textureBindLocation=r.count,r.ids[x.uid]=r.count,r.textures[r.count++]=x,_._batch=s,p.push(_),u+=_.indexSize,_.packAsQuad?(this.packQuadAttributes(_,l,h,_._attributeStart,_._textureId),this.packQuadIndex(c,_._indexStart,_._attributeStart/this.vertexSize)):(this.packAttributes(_,l,h,_._attributeStart,_._textureId),this.packIndex(_,c,_._indexStart,_._attributeStart/this.vertexSize))}r.count>0&&(this._finishBatch(s,d,u-d,r,o,a,e,f,p),d=u,++qs),this.elementStart=this.elementSize,this._batchIndexStart=d,this._batchIndexSize=u}_finishBatch(e,t,s,r,n,o,a,l,h){e.gpuBindGroup=null,e.bindGroup=null,e.action=l,e.batcher=this,e.textures=r,e.blendMode=n,e.topology=o,e.start=t,e.size=s,e.elements=h,++qs,this.batches[this.batchIndex++]=e,a.add(e)}finish(e){this.break(e)}ensureAttributeBuffer(e){e*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(e*4)}ensureIndexBuffer(e){e<=this.indexBuffer.length||this._resizeIndexBuffer(e)}_resizeAttributeBuffer(e){const t=Math.max(e,this.attributeBuffer.size*2),s=new Zt(t);ur(this.attributeBuffer.rawBinaryData,s.rawBinaryData),this.attributeBuffer=s}_resizeIndexBuffer(e){const t=this.indexBuffer;let s=Math.max(e,t.length*1.5);s+=s%2;const r=s>65535?new Uint32Array(s):new Uint16Array(s);if(r.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let n=0;n<t.length;n++)r[n]=t[n];else ur(t.buffer,r.buffer);this.indexBuffer=r}packQuadIndex(e,t,s){e[t]=s+0,e[t+1]=s+1,e[t+2]=s+2,e[t+3]=s+0,e[t+4]=s+2,e[t+5]=s+3}packIndex(e,t,s,r){const n=e.indices,o=e.indexSize,a=e.indexOffset,l=e.attributeOffset;for(let h=0;h<o;h++)t[s++]=r+n[h+a]-l}destroy(e={}){if(this.batches!==null){for(let t=0;t<this.batchIndex;t++)lc(this.batches[t]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,e.shader&&(this.shader?.destroy(),this.shader=null);for(let t=0;t<this._elements.length;t++)this._elements[t]&&(this._elements[t]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};ef.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let sf=ef;var ae=(i=>(i[i.MAP_READ=1]="MAP_READ",i[i.MAP_WRITE=2]="MAP_WRITE",i[i.COPY_SRC=4]="COPY_SRC",i[i.COPY_DST=8]="COPY_DST",i[i.INDEX=16]="INDEX",i[i.VERTEX=32]="VERTEX",i[i.UNIFORM=64]="UNIFORM",i[i.STORAGE=128]="STORAGE",i[i.INDIRECT=256]="INDIRECT",i[i.QUERY_RESOLVE=512]="QUERY_RESOLVE",i[i.STATIC=1024]="STATIC",i))(ae||{});class ot extends Re{constructor(e){let{data:t,size:s}=e;const{usage:r,label:n,shrinkToFit:o}=e;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=oe("buffer"),this._resourceType="buffer",this._resourceId=oe("resource"),this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,s??(s=t?.byteLength);const a=!!t;this.descriptor={size:s,usage:r,mappedAtCreation:a,label:n},this.shrinkToFit=o??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.length,!0)}get dataInt32(){return this._dataInt32||(this._dataInt32=new Int32Array(this.data.buffer)),this._dataInt32}get static(){return!!(this.descriptor.usage&ae.STATIC)}set static(e){e?this.descriptor.usage|=ae.STATIC:this.descriptor.usage&=~ae.STATIC}setDataWithSize(e,t,s){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===e){s&&this.emit("update",this);return}const r=this._data;if(this._data=e,this._dataInt32=null,!r||r.length!==e.length){!this.shrinkToFit&&r&&e.byteLength<r.byteLength?s&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=oe("resource"),this.emit("change",this));return}s&&this.emit("update",this)}update(e,t){this._updateSize=e??this._updateSize,this._updateOffset=t||0,this._updateID++,this.emit("update",this)}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=oe("resource"),this.emit("change",this))}destroy(){this.destroyed=!0,this.unload(),this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function xa(i,e){if(!(i instanceof ot)){let t=e?ae.INDEX:ae.VERTEX;i instanceof Array&&(e?(i=new Uint32Array(i),t=ae.INDEX|ae.COPY_DST):(i=new Float32Array(i),t=ae.VERTEX|ae.COPY_DST)),i=new ot({data:i,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return i}function rf(i,e,t){const s=i.getAttribute(e);if(!s)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const r=s.buffer.data;let n=1/0,o=1/0,a=-1/0,l=-1/0;const h=r.BYTES_PER_ELEMENT,c=(s.offset||0)/h,u=(s.stride||8)/h;for(let d=c;d<r.length;d+=u){const f=r[d],p=r[d+1];f>a&&(a=f),p>l&&(l=p),f<n&&(n=f),p<o&&(o=p)}return t.minX=n,t.minY=o,t.maxX=a,t.maxY=l,t}function g0(i){return(i instanceof ot||Array.isArray(i)||i.BYTES_PER_ELEMENT)&&(i={buffer:i}),i.buffer=xa(i.buffer,!1),i}class Si extends Re{constructor(e={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=oe("geometry"),this._layoutKey=0,this.instanceCount=1,this.indexCount=0,this._bounds=new Ee,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;const{attributes:t,indexBuffer:s,topology:r}=e;if(this.buffers=[],this.attributes={},t)for(const n in t)this.addAttribute(n,t[n]);this.instanceCount=e.instanceCount??1,this.indexCount=e.indexCount??0,s&&this.addIndex(s),this.topology=r||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;const e=this.attributes;for(const t in e){const s=e[t];if(s.instance)continue;const r=s.buffer;return this._vertexCount=r.data.length/(s.stride/4||s.size),this._vertexCount}return this._vertexCount=0,0}getSize(){return z("8.20.0","Geometry.getSize is deprecated, please use Geometry.vertexCount instead."),this.vertexCount}addAttribute(e,t){const s=g0(t);this.buffers.indexOf(s.buffer)===-1&&(this.buffers.push(s.buffer),s.buffer.on("update",this.onBufferUpdate,this),s.buffer.on("change",this.onBufferUpdate,this)),this.attributes[e]=s,this._vertexCountDirty=!0}addIndex(e){this.indexBuffer=xa(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,rf(this,"aPosition",this._bounds)):this._bounds}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){this.emit("destroy",this);for(const t of this.buffers)t.off("update",this.onBufferUpdate,this),t.off("change",this.onBufferUpdate,this),e&&t.destroy();this.unload(),this.removeAllListeners(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const _0=new Float32Array(1),y0=new Uint32Array(1);class nf extends Si{constructor(){const t=new ot({data:_0,label:"attribute-batch-buffer",usage:ae.VERTEX|ae.COPY_DST,shrinkToFit:!1}),s=new ot({data:y0,label:"index-batch-buffer",usage:ae.INDEX|ae.COPY_DST,shrinkToFit:!1}),r=24;super({attributes:{aPosition:{buffer:t,format:"float32x2",stride:r,offset:0},aUV:{buffer:t,format:"float32x2",stride:r,offset:8},aColor:{buffer:t,format:"unorm8x4",stride:r,offset:16},aTextureIdAndRound:{buffer:t,format:"uint16x2",stride:r,offset:20}},indexBuffer:s})}}function fo(i,e,t){if(i)for(const s in i){const r=s.toLocaleLowerCase(),n=e[r];if(n){let o=i[s];s==="header"&&(o=o.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),t&&n.push(`//----${t}----//`),n.push(o)}else H(`${s} placement hook does not exist in shader`)}}const x0=/\{\{(.*?)\}\}/g;function po(i){const e={};return(i.match(x0)?.map(s=>s.replace(/[{()}]/g,""))??[]).forEach(s=>{e[s]=[]}),e}function hc(i,e){let t;const s=/@in\s+([^;]+);/g;for(;(t=s.exec(i))!==null;)e.push(t[1])}function mo(i,e,t=!1){const s=[];hc(e,s),i.forEach(a=>{a.header&&hc(a.header,s)});const r=s;t&&r.sort();const n=r.map((a,l)=>` @location(${l}) ${a},`).join(`
40
40
  `);let o=e.replace(/@in\s+[^;]+;\s*/g,"");return o=o.replace("{{in}}",`
41
41
  ${n}
42
- `),o}function lc(i,e){let t;const s=/@out\s+([^;]+);/g;for(;(t=s.exec(i))!==null;)e.push(t[1])}function p0(i){const t=/\b(\w+)\s*:/g.exec(i);return t?t[1]:""}function m0(i){const e=/@.*?\s+/g;return i.replace(e,"")}function tf(i,e){const t=[];lc(e,t),i.forEach(l=>{l.header&&lc(l.header,t)});let s=0;const r=t.sort().map(l=>l.indexOf("builtin")>-1?l:`@location(${s++}) ${l}`).join(`,
43
- `),n=t.sort().map(l=>` var ${m0(l)};`).join(`
42
+ `),o}function cc(i,e){let t;const s=/@out\s+([^;]+);/g;for(;(t=s.exec(i))!==null;)e.push(t[1])}function b0(i){const t=/\b(\w+)\s*:/g.exec(i);return t?t[1]:""}function v0(i){const e=/@.*?\s+/g;return i.replace(e,"")}function of(i,e){const t=[];cc(e,t),i.forEach(l=>{l.header&&cc(l.header,t)});let s=0;const r=t.sort().map(l=>l.indexOf("builtin")>-1?l:`@location(${s++}) ${l}`).join(`,
43
+ `),n=t.sort().map(l=>` var ${v0(l)};`).join(`
44
44
  `),o=`return VSOutput(
45
- ${t.sort().map(l=>` ${p0(l)}`).join(`,
45
+ ${t.sort().map(l=>` ${b0(l)}`).join(`,
46
46
  `)});`;let a=e.replace(/@out\s+[^;]+;\s*/g,"");return a=a.replace("{{struct}}",`
47
47
  ${r}
48
48
  `),a=a.replace("{{start}}",`
49
49
  ${n}
50
50
  `),a=a.replace("{{return}}",`
51
51
  ${o}
52
- `),a}function ho(i,e){let t=i;for(const s in e){const r=e[s];r.join(`
52
+ `),a}function go(i,e){let t=i;for(const s in e){const r=e[s];r.join(`
53
53
  `).length?t=t.replace(`{{${s}}}`,`//-----${s} START-----//
54
54
  ${r.join(`
55
55
  `)}
56
- //----${s} FINISH----//`):t=t.replace(`{{${s}}}`,"")}return t}const It=Object.create(null),vn=new Map;let g0=0;function sf({template:i,bits:e}){const t=nf(i,e);if(It[t])return It[t];const{vertex:s,fragment:r}=_0(i,e);return It[t]=of(s,r,e),It[t]}function rf({template:i,bits:e}){const t=nf(i,e);return It[t]||(It[t]=of(i.vertex,i.fragment,e)),It[t]}function _0(i,e){const t=e.map(o=>o.vertex).filter(o=>!!o),s=e.map(o=>o.fragment).filter(o=>!!o);let r=lo(t,i.vertex,!0);r=tf(t,r);const n=lo(s,i.fragment,!0);return{vertex:r,fragment:n}}function nf(i,e){return e.map(t=>(vn.has(t)||vn.set(t,g0++),vn.get(t))).sort((t,s)=>t-s).join("-")+i.vertex+i.fragment}function of(i,e,t){const s=ao(i),r=ao(e);return t.forEach(n=>{oo(n.vertex,s,n.name),oo(n.fragment,r,n.name)}),{vertex:ho(i,s),fragment:ho(e,r)}}const af=`
56
+ //----${s} FINISH----//`):t=t.replace(`{{${s}}}`,"")}return t}const Dt=Object.create(null),En=new Map;let w0=0;function af({template:i,bits:e}){const t=hf(i,e);if(Dt[t])return Dt[t];const{vertex:s,fragment:r}=T0(i,e);return Dt[t]=cf(s,r,e),Dt[t]}function lf({template:i,bits:e}){const t=hf(i,e);return Dt[t]||(Dt[t]=cf(i.vertex,i.fragment,e)),Dt[t]}function T0(i,e){const t=e.map(o=>o.vertex).filter(o=>!!o),s=e.map(o=>o.fragment).filter(o=>!!o);let r=mo(t,i.vertex,!0);r=of(t,r);const n=mo(s,i.fragment,!0);return{vertex:r,fragment:n}}function hf(i,e){return e.map(t=>(En.has(t)||En.set(t,w0++),En.get(t))).sort((t,s)=>t-s).join("-")+i.vertex+i.fragment}function cf(i,e,t){const s=po(i),r=po(e);return t.forEach(n=>{fo(n.vertex,s,n.name),fo(n.fragment,r,n.name)}),{vertex:go(i,s),fragment:go(e,r)}}const uf=`
57
57
  @in aPosition: vec2<f32>;
58
58
  @in aUV: vec2<f32>;
59
59
 
@@ -97,7 +97,7 @@ ${r.join(`
97
97
 
98
98
  {{return}}
99
99
  };
100
- `,lf=`
100
+ `,df=`
101
101
  @in vUV : vec2<f32>;
102
102
  @in vColor : vec4<f32>;
103
103
 
@@ -120,7 +120,7 @@ ${r.join(`
120
120
 
121
121
  return finalColor;
122
122
  };
123
- `,hf=`
123
+ `,ff=`
124
124
  in vec2 aPosition;
125
125
  in vec2 aUV;
126
126
 
@@ -156,7 +156,7 @@ ${r.join(`
156
156
 
157
157
  {{end}}
158
158
  }
159
- `,cf=`
159
+ `,pf=`
160
160
 
161
161
  in vec4 vColor;
162
162
  in vec2 vUV;
@@ -177,7 +177,7 @@ ${r.join(`
177
177
 
178
178
  {{end}}
179
179
  }
180
- `,uf={name:"global-uniforms-bit",vertex:{header:`
180
+ `,mf={name:"global-uniforms-bit",vertex:{header:`
181
181
  struct GlobalUniforms {
182
182
  uProjectionMatrix:mat3x3<f32>,
183
183
  uWorldTransformMatrix:mat3x3<f32>,
@@ -186,22 +186,22 @@ ${r.join(`
186
186
  }
187
187
 
188
188
  @group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
189
- `}},df={name:"global-uniforms-bit",vertex:{header:`
189
+ `}},gf={name:"global-uniforms-bit",vertex:{header:`
190
190
  uniform mat3 uProjectionMatrix;
191
191
  uniform mat3 uWorldTransformMatrix;
192
192
  uniform vec4 uWorldColorAlpha;
193
193
  uniform vec2 uResolution;
194
- `}};function Pr({bits:i,name:e}){const t=sf({template:{fragment:lf,vertex:af},bits:[uf,...i]});return Ft.from({name:e,vertex:{source:t.vertex,entryPoint:"main"},fragment:{source:t.fragment,entryPoint:"main"}})}function Ar({bits:i,name:e}){return new ls({name:e,...rf({template:{vertex:hf,fragment:cf},bits:[df,...i]})})}const fa={name:"color-bit",vertex:{header:`
194
+ `}};function Rr({bits:i,name:e}){const t=af({template:{fragment:df,vertex:uf},bits:[mf,...i]});return Lt.from({name:e,vertex:{source:t.vertex,entryPoint:"main"},fragment:{source:t.fragment,entryPoint:"main"}})}function Br({bits:i,name:e}){return new us({name:e,...lf({template:{vertex:ff,fragment:pf},bits:[gf,...i]})})}const ba={name:"color-bit",vertex:{header:`
195
195
  @in aColor: vec4<f32>;
196
196
  `,main:`
197
197
  vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
198
- `}},pa={name:"color-bit",vertex:{header:`
198
+ `}},va={name:"color-bit",vertex:{header:`
199
199
  in vec4 aColor;
200
200
  `,main:`
201
201
  vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
202
- `}},wn={};function y0(i){const e=[];if(i===1)e.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"),e.push("@group(1) @binding(1) var textureSampler1: sampler;");else{let t=0;for(let s=0;s<i;s++)e.push(`@group(1) @binding(${t++}) var textureSource${s+1}: texture_2d<f32>;`),e.push(`@group(1) @binding(${t++}) var textureSampler${s+1}: sampler;`)}return e.join(`
203
- `)}function x0(i){const e=[];if(i===1)e.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");else{e.push("switch vTextureId {");for(let t=0;t<i;t++)t===i-1?e.push(" default:{"):e.push(` case ${t}:{`),e.push(` outColor = textureSampleGrad(textureSource${t+1}, textureSampler${t+1}, vUV, uvDx, uvDy);`),e.push(" break;}");e.push("}")}return e.join(`
204
- `)}function ma(i){return wn[i]||(wn[i]={name:"texture-batch-bit",vertex:{header:`
202
+ `}},Pn={};function S0(i){const e=[];if(i===1)e.push("@group(1) @binding(0) var textureSource1: texture_2d<f32>;"),e.push("@group(1) @binding(1) var textureSampler1: sampler;");else{let t=0;for(let s=0;s<i;s++)e.push(`@group(1) @binding(${t++}) var textureSource${s+1}: texture_2d<f32>;`),e.push(`@group(1) @binding(${t++}) var textureSampler${s+1}: sampler;`)}return e.join(`
203
+ `)}function C0(i){const e=[];if(i===1)e.push("outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);");else{e.push("switch vTextureId {");for(let t=0;t<i;t++)t===i-1?e.push(" default:{"):e.push(` case ${t}:{`),e.push(` outColor = textureSampleGrad(textureSource${t+1}, textureSampler${t+1}, vUV, uvDx, uvDy);`),e.push(" break;}");e.push("}")}return e.join(`
204
+ `)}function wa(i){return Pn[i]||(Pn[i]={name:"texture-batch-bit",vertex:{header:`
205
205
  @in aTextureIdAndRound: vec2<u32>;
206
206
  @out @interpolate(flat) vTextureId : u32;
207
207
  `,main:`
@@ -214,14 +214,14 @@ ${r.join(`
214
214
  `},fragment:{header:`
215
215
  @in @interpolate(flat) vTextureId: u32;
216
216
 
217
- ${y0(i)}
217
+ ${S0(i)}
218
218
  `,main:`
219
219
  var uvDx = dpdx(vUV);
220
220
  var uvDy = dpdy(vUV);
221
221
 
222
- ${x0(i)}
223
- `}}),wn[i]}const Tn={};function b0(i){const e=[];for(let t=0;t<i;t++)t>0&&e.push("else"),t<i-1&&e.push(`if(vTextureId < ${t}.5)`),e.push("{"),e.push(` outColor = texture(uTextures[${t}], vUV);`),e.push("}");return e.join(`
224
- `)}function ga(i){return Tn[i]||(Tn[i]={name:"texture-batch-bit",vertex:{header:`
222
+ ${C0(i)}
223
+ `}}),Pn[i]}const An={};function M0(i){const e=[];for(let t=0;t<i;t++)t>0&&e.push("else"),t<i-1&&e.push(`if(vTextureId < ${t}.5)`),e.push("{"),e.push(` outColor = texture(uTextures[${t}], vUV);`),e.push("}");return e.join(`
224
+ `)}function Ta(i){return An[i]||(An[i]={name:"texture-batch-bit",vertex:{header:`
225
225
  in vec2 aTextureIdAndRound;
226
226
  out float vTextureId;
227
227
 
@@ -239,18 +239,18 @@ ${r.join(`
239
239
 
240
240
  `,main:`
241
241
 
242
- ${b0(i)}
243
- `}}),Tn[i]}const Rr={name:"round-pixels-bit",vertex:{header:`
242
+ ${M0(i)}
243
+ `}}),An[i]}const Ir={name:"round-pixels-bit",vertex:{header:`
244
244
  fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
245
245
  {
246
246
  return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
247
247
  }
248
- `}},Br={name:"round-pixels-bit",vertex:{header:`
248
+ `}},Gr={name:"round-pixels-bit",vertex:{header:`
249
249
  vec2 roundPixels(vec2 position, vec2 targetSize)
250
250
  {
251
251
  return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
252
252
  }
253
- `}},hc={};function _a(i){let e=hc[i];if(e)return e;const t=new Int32Array(i);for(let s=0;s<i;s++)t[s]=s;return e=hc[i]=new rt({uTextures:{value:t,type:"i32",size:i}},{isStatic:!0}),e}class co extends ft{constructor(e){const t=Ar({name:"batch",bits:[pa,ga(e),Br]}),s=Pr({name:"batch",bits:[fa,ma(e),Rr]});super({glProgram:t,gpuProgram:s,resources:{batchSamplers:_a(e)}}),this.maxTextures=e}}let Xs=null;const ff=class pf extends Qd{constructor(e){super(e),this.geometry=new ef,this.name=pf.extension.name,this.vertexSize=6,Xs??(Xs=new co(e.maxTextures)),this.shader=Xs}packAttributes(e,t,s,r,n){const o=n<<16|e.roundPixels&65535,a=e.transform,l=a.a,h=a.b,c=a.c,u=a.d,d=a.tx,f=a.ty,{positions:p,uvs:g}=e,m=e.color,_=e.attributeOffset,y=_+e.attributeSize;for(let x=_;x<y;x++){const b=x*2,v=p[b],w=p[b+1];t[r++]=l*v+c*w+d,t[r++]=u*w+h*v+f,t[r++]=g[b],t[r++]=g[b+1],s[r++]=m,s[r++]=o}}packQuadAttributes(e,t,s,r,n){const o=e.texture,a=e.transform,l=a.a,h=a.b,c=a.c,u=a.d,d=a.tx,f=a.ty,p=e.bounds,g=p.maxX,m=p.minX,_=p.maxY,y=p.minY,x=o.uvs,b=e.color,v=n<<16|e.roundPixels&65535;t[r+0]=l*m+c*y+d,t[r+1]=u*y+h*m+f,t[r+2]=x.x0,t[r+3]=x.y0,s[r+4]=b,s[r+5]=v,t[r+6]=l*g+c*y+d,t[r+7]=u*y+h*g+f,t[r+8]=x.x1,t[r+9]=x.y1,s[r+10]=b,s[r+11]=v,t[r+12]=l*g+c*_+d,t[r+13]=u*_+h*g+f,t[r+14]=x.x2,t[r+15]=x.y2,s[r+16]=b,s[r+17]=v,t[r+18]=l*m+c*_+d,t[r+19]=u*_+h*m+f,t[r+20]=x.x3,t[r+21]=x.y3,s[r+22]=b,s[r+23]=v}_updateMaxTextures(e){this.shader.maxTextures!==e&&(Xs=new co(e),this.shader=Xs)}destroy(){this.shader=null,super.destroy()}};ff.extension={type:[S.Batcher],name:"default"};let Ir=ff;class nt{constructor(e){this.items=Object.create(null);const{renderer:t,type:s,onUnload:r,priority:n,name:o}=e;this._renderer=t,t.gc.addResourceHash(this,"items",s,n??0),this._onUnload=r,this.name=o}add(e){return this.items[e.uid]?!1:(this.items[e.uid]=e,e.once("unload",this.remove,this),e._gcLastUsed=this._renderer.gc.now,!0)}remove(e,...t){if(!this.items[e.uid])return;const s=e._gpuData[this._renderer.uid];s&&(this._onUnload?.(e,...t),e.off("unload",this.remove,this),s.destroy(),e._gpuData[this._renderer.uid]=null,this.items[e.uid]=null)}removeAll(...e){Object.values(this.items).forEach(t=>t&&this.remove(t,...e))}destroy(...e){this.removeAll(...e),this.items=Object.create(null),this._renderer=null,this._onUnload=null}}function mf(i,e,t,s,r,n,o,a=null){let l=0;t*=e,r*=n;const h=a.a,c=a.b,u=a.c,d=a.d,f=a.tx,p=a.ty;for(;l<o;){const g=i[t],m=i[t+1];s[r]=h*g+u*m+f,s[r+1]=c*g+d*m+p,r+=n,t+=e,l++}}function gf(i,e,t,s){let r=0;for(e*=t;r<s;)i[e]=0,i[e+1]=0,e+=t,r++}function ya(i,e,t,s,r){const n=e.a,o=e.b,a=e.c,l=e.d,h=e.tx,c=e.ty;t||(t=0),s||(s=2),r||(r=i.length/s-t);let u=t*s;for(let d=0;d<r;d++){const f=i[u],p=i[u+1];i[u]=n*f+a*p+h,i[u+1]=o*f+l*p+c,u+=s}}const v0=new U;class Gr{constructor(){this.packAsQuad=!1,this.batcherName="default",this.topology="triangle-list",this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:"normal"}get color(){const e=this.baseColor,t=e>>16|e&65280|(e&255)<<16,s=this.renderable;return s?Kt(t,s.groupColor)+(this.alpha*s.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||v0}copyTo(e){e.indexOffset=this.indexOffset,e.indexSize=this.indexSize,e.attributeOffset=this.attributeOffset,e.attributeSize=this.attributeSize,e.baseColor=this.baseColor,e.alpha=this.alpha,e.texture=this.texture,e.geometryData=this.geometryData,e.topology=this.topology}reset(){this.applyTransform=!0,this.renderable=null,this.topology="triangle-list"}destroy(){this.renderable=null,this.texture=null,this.geometryData=null,this._batcher=null,this._batch=null}}const Ps={extension:{type:S.ShapeBuilder,name:"circle"},build(i,e){let t,s,r,n,o,a;if(i.type==="circle"){const b=i;if(o=a=b.radius,o<=0)return!1;t=b.x,s=b.y,r=n=0}else if(i.type==="ellipse"){const b=i;if(o=b.halfWidth,a=b.halfHeight,o<=0||a<=0)return!1;t=b.x,s=b.y,r=n=0}else{const b=i,v=b.width/2,w=b.height/2;t=b.x+v,s=b.y+w,o=a=Math.max(0,Math.min(b.radius,Math.min(v,w))),r=v-o,n=w-a}if(r<0||n<0)return!1;const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(r?4:0)+(n?4:0);if(h===0)return!1;if(l===0)return e[0]=e[6]=t+r,e[1]=e[3]=s+n,e[2]=e[4]=t-r,e[5]=e[7]=s-n,!0;let c=0,u=l*4+(r?2:0)+2,d=u,f=h,p=r+o,g=n,m=t+p,_=t-p,y=s+g;if(e[c++]=m,e[c++]=y,e[--u]=y,e[--u]=_,n){const b=s-g;e[d++]=_,e[d++]=b,e[--f]=b,e[--f]=m}for(let b=1;b<l;b++){const v=Math.PI/2*(b/l),w=r+Math.cos(v)*o,T=n+Math.sin(v)*a,k=t+w,E=t-w,A=s+T,M=s-T;e[c++]=k,e[c++]=A,e[--u]=A,e[--u]=E,e[d++]=E,e[d++]=M,e[--f]=M,e[--f]=k}p=r,g=n+a,m=t+p,_=t-p,y=s+g;const x=s-g;return e[c++]=m,e[c++]=y,e[--f]=x,e[--f]=m,r&&(e[c++]=_,e[c++]=y,e[--f]=x,e[--f]=_),!0},triangulate(i,e,t,s,r,n){if(i.length===0)return;let o=0,a=0;for(let c=0;c<i.length;c+=2)o+=i[c],a+=i[c+1];o/=i.length/2,a/=i.length/2;let l=s;e[l*t]=o,e[l*t+1]=a;const h=l++;for(let c=0;c<i.length;c+=2)e[l*t]=i[c],e[l*t+1]=i[c+1],c>0&&(r[n++]=l,r[n++]=h,r[n++]=l-1),l++;r[n++]=h+1,r[n++]=h,r[n++]=l-1}},_f={...Ps,extension:{...Ps.extension,name:"ellipse"}},yf={...Ps,extension:{...Ps.extension,name:"roundedRectangle"}},xa=1e-4,uo=1e-4;function cc(i,e,t,s,r,n,o,a){const l=i-t*r,h=e-s*r,c=i+t*n,u=e+s*n;let d,f;o?(d=s,f=-t):(d=-s,f=t);const p=l+d,g=h+f,m=c+d,_=u+f;return a.push(p,g),a.push(m,_),2}function Ut(i,e,t,s,r,n,o,a){const l=t-i,h=s-e;let c=Math.atan2(l,h),u=Math.atan2(r-i,n-e);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),g=Math.sqrt(l*l+h*h),m=(15*p*Math.sqrt(g)/Math.PI>>0)+1,_=f/m;if(d+=_,a){o.push(i,e),o.push(t,s);for(let y=1,x=d;y<m;y++,x+=_)o.push(i,e),o.push(i+Math.sin(x)*g,e+Math.cos(x)*g);o.push(i,e),o.push(r,n)}else{o.push(t,s),o.push(i,e);for(let y=1,x=d;y<m;y++,x+=_)o.push(i+Math.sin(x)*g,e+Math.cos(x)*g),o.push(i,e);o.push(r,n),o.push(i,e)}return m*2}function Dr(i,e,t,s,r,n){const o=xa;if(i.length===0)return;const a=e;let l=a.alignment;if(e.alignment!==.5){let R=ca(i);l=(l-.5)*R+.5}const h=new he(i[0],i[1]),c=new he(i[i.length-2],i[i.length-1]),u=s,d=Math.abs(h.x-c.x)<o&&Math.abs(h.y-c.y)<o;if(u){i=i.slice(),d&&(i.pop(),i.pop(),c.set(i[i.length-2],i[i.length-1]));const R=(h.x+c.x)*.5,L=(c.y+h.y)*.5;i.unshift(R,L),i.push(R,L)}const f=r,p=i.length/2;let g=i.length;const m=f.length/2,_=a.width/2,y=_*_,x=a.miterLimit*a.miterLimit;let b=i[0],v=i[1],w=i[2],T=i[3],k=0,E=0,A=-(v-T),M=b-w,B=0,G=0,O=Math.sqrt(A*A+M*M);A/=O,M/=O,A*=_,M*=_;const I=l,P=(1-I)*2,C=I*2;u||(a.cap==="round"?g+=Ut(b-A*(P-C)*.5,v-M*(P-C)*.5,b-A*P,v-M*P,b+A*C,v+M*C,f,!0)+2:a.cap==="square"&&(g+=cc(b,v,A,M,P,C,!0,f))),f.push(b-A*P,v-M*P),f.push(b+A*C,v+M*C);for(let R=1;R<p-1;++R){b=i[(R-1)*2],v=i[(R-1)*2+1],w=i[R*2],T=i[R*2+1],k=i[(R+1)*2],E=i[(R+1)*2+1],A=-(v-T),M=b-w,O=Math.sqrt(A*A+M*M),A/=O,M/=O,A*=_,M*=_,B=-(T-E),G=w-k,O=Math.sqrt(B*B+G*G),B/=O,G/=O,B*=_,G*=_;const L=w-b,N=v-T,se=w-k,Q=E-T,re=L*se+N*Q,j=N*se-Q*L,Ze=j<0;if(Math.abs(j)<.001*Math.abs(re)){f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),re>=0&&(a.join==="round"?g+=Ut(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+4:g+=2,f.push(w-B*C,T-G*C),f.push(w+B*P,T+G*P));continue}const Si=(-A+b)*(-M+T)-(-A+w)*(-M+v),Os=(-B+k)*(-G+T)-(-B+w)*(-G+E),Ls=(L*Os-se*Si)/j,mt=(Q*Si-N*Os)/j,Ot=(Ls-w)*(Ls-w)+(mt-T)*(mt-T),Qe=w+(Ls-w)*P,Oe=T+(mt-T)*P,Le=w-(Ls-w)*C,Je=T-(mt-T)*C,Rt=Math.min(L*L+N*N,se*se+Q*Q),gt=Ze?P:C,Us=Rt+gt*gt*y;Ot<=Us?a.join==="bevel"||Ot/y>x?(Ze?(f.push(Qe,Oe),f.push(w+A*C,T+M*C),f.push(Qe,Oe),f.push(w+B*C,T+G*C)):(f.push(w-A*P,T-M*P),f.push(Le,Je),f.push(w-B*P,T-G*P),f.push(Le,Je)),g+=2):a.join==="round"?Ze?(f.push(Qe,Oe),f.push(w+A*C,T+M*C),g+=Ut(w,T,w+A*C,T+M*C,w+B*C,T+G*C,f,!0)+4,f.push(Qe,Oe),f.push(w+B*C,T+G*C)):(f.push(w-A*P,T-M*P),f.push(Le,Je),g+=Ut(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+4,f.push(w-B*P,T-G*P),f.push(Le,Je)):(f.push(Qe,Oe),f.push(Le,Je)):(f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),a.join==="round"?Ze?g+=Ut(w,T,w+A*C,T+M*C,w+B*C,T+G*C,f,!0)+2:g+=Ut(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+2:a.join==="miter"&&Ot/y<=x&&(Ze?(f.push(Le,Je),f.push(Le,Je)):(f.push(Qe,Oe),f.push(Qe,Oe)),g+=2),f.push(w-B*P,T-G*P),f.push(w+B*C,T+G*C),g+=2)}b=i[(p-2)*2],v=i[(p-2)*2+1],w=i[(p-1)*2],T=i[(p-1)*2+1],A=-(v-T),M=b-w,O=Math.sqrt(A*A+M*M),A/=O,M/=O,A*=_,M*=_,f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),u||(a.cap==="round"?g+=Ut(w-A*(P-C)*.5,T-M*(P-C)*.5,w-A*P,T-M*P,w+A*C,T+M*C,f,!1)+2:a.cap==="square"&&(g+=cc(w,T,A,M,P,C,!1,f)));const D=uo*uo;for(let R=m;R<g+m-2;++R)b=f[R*2],v=f[R*2+1],w=f[(R+1)*2],T=f[(R+1)*2+1],k=f[(R+2)*2],E=f[(R+2)*2+1],!(Math.abs(b*(T-E)+w*(E-v)+k*(v-T))<D)&&n.push(R,R+1,R+2)}function xf(i,e,t,s){const r=xa;if(i.length===0)return;const n=i[0],o=i[1],a=i[i.length-2],l=i[i.length-1],h=e||Math.abs(n-a)<r&&Math.abs(o-l)<r,c=t,u=i.length/2,d=c.length/2;for(let f=0;f<u;f++)c.push(i[f*2]),c.push(i[f*2+1]);for(let f=0;f<u-1;f++)s.push(d+f,d+f+1);h&&s.push(d+u-1,d)}function ba(i,e,t,s,r,n,o){const a=Fd(i,e,2);if(!a)return;for(let h=0;h<a.length;h+=3)n[o++]=a[h]+r,n[o++]=a[h+1]+r,n[o++]=a[h+2]+r;let l=r*s;for(let h=0;h<i.length;h+=2)t[l]=i[h],t[l+1]=i[h+1],l+=s}const w0=[],bf={extension:{type:S.ShapeBuilder,name:"polygon"},build(i,e){for(let t=0;t<i.points.length;t++)e[t]=i.points[t];return!0},triangulate(i,e,t,s,r,n){ba(i,w0,e,t,s,r,n)}},vf={extension:{type:S.ShapeBuilder,name:"rectangle"},build(i,e){const t=i,s=t.x,r=t.y,n=t.width,o=t.height;return n>0&&o>0?(e[0]=s,e[1]=r,e[2]=s+n,e[3]=r,e[4]=s+n,e[5]=r+o,e[6]=s,e[7]=r+o,!0):!1},triangulate(i,e,t,s,r,n){let o=0;s*=t,e[s+o]=i[0],e[s+o+1]=i[1],o+=t,e[s+o]=i[2],e[s+o+1]=i[3],o+=t,e[s+o]=i[6],e[s+o+1]=i[7],o+=t,e[s+o]=i[4],e[s+o+1]=i[5],o+=t;const a=s/t;r[n++]=a,r[n++]=a+1,r[n++]=a+2,r[n++]=a+1,r[n++]=a+3,r[n++]=a+2}},wf={extension:{type:S.ShapeBuilder,name:"triangle"},build(i,e){return e[0]=i.x,e[1]=i.y,e[2]=i.x2,e[3]=i.y2,e[4]=i.x3,e[5]=i.y3,!0},triangulate(i,e,t,s,r,n){let o=0;s*=t,e[s+o]=i[0],e[s+o+1]=i[1],o+=t,e[s+o]=i[2],e[s+o+1]=i[3],o+=t,e[s+o]=i[4],e[s+o+1]=i[5];const a=s/t;r[n++]=a,r[n++]=a+1,r[n++]=a+2}},uc=[{offset:0,color:"white"},{offset:1,color:"black"}],va=class fo{constructor(...e){this.uid=oe("fillGradient"),this._tick=0,this.type="linear",this.colorStops=[];let t=T0(e);t={...t.type==="radial"?fo.defaultRadialOptions:fo.defaultLinearOptions,...Lo(t)},this._textureSize=t.textureSize,this._wrapMode=t.wrapMode,t.type==="radial"?(this.center=t.center,this.outerCenter=t.outerCenter??this.center,this.innerRadius=t.innerRadius,this.outerRadius=t.outerRadius,this.scale=t.scale,this.rotation=t.rotation):(this.start=t.start,this.end=t.end),this.textureSpace=t.textureSpace,this.type=t.type,t.colorStops.forEach(r=>{this.addColorStop(r.offset,r.color)})}addColorStop(e,t){return this.colorStops.push({offset:e,color:ae.shared.setValue(t).toHexa()}),this}buildLinearGradient(){if(this.texture)return;let{x:e,y:t}=this.start,{x:s,y:r}=this.end,n=s-e,o=r-t;const a=n<0||o<0;if(this._wrapMode==="clamp-to-edge"){if(n<0){const m=e;e=s,s=m,n*=-1}if(o<0){const m=t;t=r,r=m,o*=-1}}const l=this.colorStops.length?this.colorStops:uc,h=this._textureSize,{canvas:c,context:u}=fc(h,1),d=a?u.createLinearGradient(this._textureSize,0,0,0):u.createLinearGradient(0,0,this._textureSize,0);dc(d,l),u.fillStyle=d,u.fillRect(0,0,h,1),this.texture=new W({source:new di({resource:c,addressMode:this._wrapMode})});const f=Math.sqrt(n*n+o*o),p=Math.atan2(o,n),g=new U;g.scale(f/h,1),g.rotate(p),g.translate(e,t),this.textureSpace==="local"&&g.scale(h,h),this.transform=g}buildGradient(){this.texture||this._tick++,this.type==="linear"?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;const e=this.colorStops.length?this.colorStops:uc,t=this._textureSize,{canvas:s,context:r}=fc(t,t),{x:n,y:o}=this.center,{x:a,y:l}=this.outerCenter,h=this.innerRadius,c=this.outerRadius,u=a-c,d=l-c,f=t/(c*2),p=(n-u)*f,g=(o-d)*f,m=r.createRadialGradient(p,g,h*f,(a-u)*f,(l-d)*f,c*f);dc(m,e),r.fillStyle=e[e.length-1].color,r.fillRect(0,0,t,t),r.fillStyle=m,r.translate(p,g),r.rotate(this.rotation),r.scale(1,this.scale),r.translate(-p,-g),r.fillRect(0,0,t,t),this.texture=new W({source:new di({resource:s,addressMode:this._wrapMode})});const _=new U;this.textureSpace==="local"?_.scale(2*c,2*c):_.scale(1/f,1/f),_.translate(u,d),this.transform=_}destroy(){this.texture?.destroy(!0),this.texture=null,this.transform=null,this.colorStops=[],this.start=null,this.end=null,this.center=null,this.outerCenter=null}get styleKey(){return`fill-gradient-${this.uid}-${this._tick}`}};va.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:"local",type:"linear",textureSize:256,wrapMode:"clamp-to-edge"};va.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,rotation:0,textureSpace:"local",type:"radial",textureSize:256,wrapMode:"clamp-to-edge"};let je=va;function dc(i,e){for(let t=0;t<e.length;t++){const s=e[t];i.addColorStop(s.offset,s.color)}}function fc(i,e){const t=ee.get().createCanvas(i,e),s=t.getContext("2d");return{canvas:t,context:s}}function T0(i){let e=i[0]??{};return(typeof e=="number"||i[1])&&(H("8.5.2","use options object instead"),e={type:"linear",start:{x:i[0],y:i[1]},end:{x:i[2],y:i[3]},textureSpace:i[4],textureSize:i[5]??je.defaultLinearOptions.textureSize}),e}const S0=new U,C0=new te,M0=new U;function wa(i,e,t,s){const r=e.matrix?i.copyFrom(e.matrix).invert():i.identity();if(e.textureSpace==="local"){const o=t.getBounds(C0);e.width&&o.pad(e.width);const{x:a,y:l}=o,h=1/o.width,c=1/o.height,u=-a*h,d=-l*c,f=r.a,p=r.b,g=r.c,m=r.d;r.a*=h,r.b*=h,r.c*=c,r.d*=c,r.tx=u*f+d*g+r.tx,r.ty=u*p+d*m+r.ty}else if(e.texture.rotate){const{uvs:o,orig:a}=e.texture;r.scale(1/a.width,1/a.height),r.prepend(M0.set(o.x1-o.x0,o.y1-o.y0,o.x3-o.x0,o.y3-o.y0,o.x0,o.y0))}else r.translate(e.texture.frame.x,e.texture.frame.y),r.scale(1/e.texture.source.width,1/e.texture.source.height);const n=e.texture.source.style;return!(e.fill instanceof je)&&n.addressMode==="clamp-to-edge"&&(n.addressMode="repeat",n.update()),s&&r.append(S0.copyFrom(s).invert()),r}const hs={};q.handleByMap(S.ShapeBuilder,hs);q.add(vf,bf,wf,Ps,_f,yf);const k0=new te,E0=new U;function Tf(i,e){const{geometryData:t,batches:s}=e;s.length=0,t.indices.length=0,t.vertices.length=0,t.uvs.length=0;for(let r=0;r<i.instructions.length;r++){const n=i.instructions[r];if(n.action==="texture")P0(n.data,s,t);else if(n.action==="fill"||n.action==="stroke"){const o=n.action==="stroke",a=n.data.path.shapePath,l=n.data.style,h=n.data.hole;o&&h&&pc(h.shapePath,l,!0,s,t),h&&(a.shapePrimitives[a.shapePrimitives.length-1].holes=h.shapePath.shapePrimitives),pc(a,l,o,s,t)}}}function P0(i,e,t){const s=[],r=hs.rectangle,n=k0;n.x=i.dx,n.y=i.dy,n.width=i.dw,n.height=i.dh;const o=i.transform;if(!r.build(n,s))return;const{vertices:a,uvs:l,indices:h}=t,c=h.length,u=a.length/2;o&&ya(s,o),r.triangulate(s,a,2,u,h,c);const d=i.image,f=d.uvs;l.push(f.x0,f.y0,f.x1,f.y1,f.x3,f.y3,f.x2,f.y2);const p=Se.get(Gr);p.indexOffset=c,p.indexSize=h.length-c,p.attributeOffset=u,p.attributeSize=a.length/2-u,p.baseColor=i.style,p.alpha=i.alpha,p.texture=d,p.geometryData=t,e.push(p)}function pc(i,e,t,s,r){const{vertices:n,uvs:o,indices:a}=r;i.shapePrimitives.forEach(({shape:l,transform:h,holes:c})=>{const u=[],d=hs[l.type];if(!d.build(l,u))return;const f=a.length,p=n.length/2;let g="triangle-list";if(h&&ya(u,h),t){const x=l.closePath??!0,b=e;b.pixelLine?(xf(u,x,n,a),g="line-list"):Dr(u,b,!1,x,n,a)}else if(c){const x=[],b=u.slice();A0(c).forEach(w=>{x.push(b.length/2),b.push(...w)}),ba(b,x,n,2,p,a,f)}else d.triangulate(u,n,2,p,a,f);const m=o.length/2,_=e.texture;if(_!==W.WHITE){const x=wa(E0,e,l,h);mf(n,2,p,o,m,2,n.length/2-p,x)}else gf(o,m,2,n.length/2-p);const y=Se.get(Gr);y.indexOffset=f,y.indexSize=a.length-f,y.attributeOffset=p,y.attributeSize=n.length/2-p,y.baseColor=e.color,y.alpha=e.alpha,y.texture=_,y.geometryData=r,y.topology=g,s.push(y)})}function A0(i){const e=[];for(let t=0;t<i.length;t++){const s=i[t].shape,r=[];hs[s.type].build(s,r)&&e.push(r)}return e}class Sf{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}reset(){this.batches&&this.batches.forEach(e=>{Se.return(e)}),this.graphicsData&&Se.return(this.graphicsData),this.isBatchable=!1,this.context=null,this.batches.length=0,this.geometryData.indices.length=0,this.geometryData.vertices.length=0,this.geometryData.uvs.length=0,this.graphicsData=null}destroy(){this.reset(),this.batches=null,this.geometryData=null}}class Cf{constructor(){this.instructions=new br}init(e){const t=e.maxTextures;this.batcher?this.batcher._updateMaxTextures(t):this.batcher=new Ir({maxTextures:t}),this.instructions.reset()}get geometry(){return H(wu,"GraphicsContextRenderData#geometry is deprecated, please use batcher.geometry instead."),this.batcher.geometry}destroy(){this.batcher.destroy(),this.instructions.destroy(),this.batcher=null,this.instructions=null}}const Ta=class po{constructor(e){this._renderer=e,this._managedContexts=new nt({renderer:e,type:"resource",name:"graphicsContext"})}init(e){po.defaultOptions.bezierSmoothness=e?.bezierSmoothness??po.defaultOptions.bezierSmoothness}getContextRenderData(e){return e._gpuData[this._renderer.uid].graphicsData||this._initContextRenderData(e)}updateGpuContext(e){const t=!!e._gpuData[this._renderer.uid],s=e._gpuData[this._renderer.uid]||this._initContext(e);if(e.dirty||!t){t&&s.reset(),Tf(e,s);const r=e.batchMode;e.customShader||r==="no-batch"?s.isBatchable=!1:r==="auto"?s.isBatchable=s.geometryData.vertices.length<400:s.isBatchable=!0,e.dirty=!1}return s}getGpuContext(e){return e._gpuData[this._renderer.uid]||this._initContext(e)}_initContextRenderData(e){const t=Se.get(Cf,{maxTextures:this._renderer.limits.maxBatchableTextures}),s=e._gpuData[this._renderer.uid],{batches:r,geometryData:n}=s;s.graphicsData=t;const o=n.vertices.length,a=n.indices.length;for(let u=0;u<r.length;u++)r[u].applyTransform=!1;const l=t.batcher;l.ensureAttributeBuffer(o),l.ensureIndexBuffer(a),l.begin();for(let u=0;u<r.length;u++){const d=r[u];l.add(d)}l.finish(t.instructions);const h=l.geometry;h.indexBuffer.setDataWithSize(l.indexBuffer,l.indexSize,!0),h.buffers[0].setDataWithSize(l.attributeBuffer.float32View,l.attributeSize,!0);const c=l.batches;for(let u=0;u<l.batchIndex;u++){const d=c[u];d.bindGroup=kr(d.textures.textures,d.textures.count,this._renderer.limits.maxBatchableTextures)}return t}_initContext(e){const t=new Sf;return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};Ta.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"graphicsContext"};Ta.defaultOptions={bezierSmoothness:.5};let Fr=Ta;const R0=8,Ui=11920929e-14,B0=1;function Sa(i,e,t,s,r,n,o,a,l,h){const u=Math.min(.99,Math.max(0,h??Fr.defaultOptions.bezierSmoothness));let d=(B0-u)/1;return d*=d,I0(e,t,s,r,n,o,a,l,i,d),i}function I0(i,e,t,s,r,n,o,a,l,h){mo(i,e,t,s,r,n,o,a,l,h,0),l.push(o,a)}function mo(i,e,t,s,r,n,o,a,l,h,c){if(c>R0)return;const u=(i+t)/2,d=(e+s)/2,f=(t+r)/2,p=(s+n)/2,g=(r+o)/2,m=(n+a)/2,_=(u+f)/2,y=(d+p)/2,x=(f+g)/2,b=(p+m)/2,v=(_+x)/2,w=(y+b)/2;if(c>0){let T=o-i,k=a-e;const E=Math.abs((t-o)*k-(s-a)*T),A=Math.abs((r-o)*k-(n-a)*T);if(E>Ui&&A>Ui){if((E+A)*(E+A)<=h*(T*T+k*k)){l.push(v,w);return}}else if(E>Ui){if(E*E<=h*(T*T+k*k)){l.push(v,w);return}}else if(A>Ui){if(A*A<=h*(T*T+k*k)){l.push(v,w);return}}else if(T=v-(i+o)/2,k=w-(e+a)/2,T*T+k*k<=h){l.push(v,w);return}}mo(i,e,u,d,_,y,v,w,l,h,c+1),mo(v,w,x,b,g,m,o,a,l,h,c+1)}const G0=8,D0=11920929e-14,F0=1;function Mf(i,e,t,s,r,n,o,a){const h=Math.min(.99,Math.max(0,a??Fr.defaultOptions.bezierSmoothness));let c=(F0-h)/1;return c*=c,O0(e,t,s,r,n,o,i,c),i}function O0(i,e,t,s,r,n,o,a){go(o,i,e,t,s,r,n,a,0),o.push(r,n)}function go(i,e,t,s,r,n,o,a,l){if(l>G0)return;const h=(e+s)/2,c=(t+r)/2,u=(s+n)/2,d=(r+o)/2,f=(h+u)/2,p=(c+d)/2;let g=n-e,m=o-t;const _=Math.abs((s-n)*m-(r-o)*g);if(_>D0){if(_*_<=a*(g*g+m*m)){i.push(f,p);return}}else if(g=f-(e+n)/2,m=p-(t+o)/2,g*g+m*m<=a){i.push(f,p);return}go(i,e,t,h,c,f,p,a,l+1),go(i,f,p,u,d,n,o,a,l+1)}function Ca(i,e,t,s,r,n,o,a){let l=Math.abs(r-n);(!o&&r>n||o&&n>r)&&(l=2*Math.PI-l),a||(a=Math.max(6,Math.floor(6*Math.pow(s,1/3)*(l/Math.PI)))),a=Math.max(a,3);let h=l/a,c=r;h*=o?-1:1;for(let u=0;u<a+1;u++){const d=Math.cos(c),f=Math.sin(c),p=e+d*s,g=t+f*s;i.push(p,g),c+=h}}function kf(i,e,t,s,r,n){const o=i[i.length-2],l=i[i.length-1]-t,h=o-e,c=r-t,u=s-e,d=Math.abs(l*u-h*c);if(d<1e-8||n===0){(i[i.length-2]!==e||i[i.length-1]!==t)&&i.push(e,t);return}const f=l*l+h*h,p=c*c+u*u,g=l*c+h*u,m=n*Math.sqrt(f)/d,_=n*Math.sqrt(p)/d,y=m*g/f,x=_*g/p,b=m*u+_*h,v=m*c+_*l,w=h*(_+y),T=l*(_+y),k=u*(m+x),E=c*(m+x),A=Math.atan2(T-v,w-b),M=Math.atan2(E-v,k-b);Ca(i,b+e,v+t,n,A,M,h*c>u*l)}const si=Math.PI*2,Sn={centerX:0,centerY:0,ang1:0,ang2:0},Cn=({x:i,y:e},t,s,r,n,o,a,l)=>{i*=t,e*=s;const h=r*i-n*e,c=n*i+r*e;return l.x=h+o,l.y=c+a,l};function L0(i,e){const t=e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),s=e===1.5707963267948966?.551915024494:t,r=Math.cos(i),n=Math.sin(i),o=Math.cos(i+e),a=Math.sin(i+e);return[{x:r-n*s,y:n+r*s},{x:o+a*s,y:a-o*s},{x:o,y:a}]}const mc=(i,e,t,s)=>{const r=i*s-e*t<0?-1:1;let n=i*t+e*s;return n>1&&(n=1),n<-1&&(n=-1),r*Math.acos(n)},U0=(i,e,t,s,r,n,o,a,l,h,c,u,d)=>{const f=Math.pow(r,2),p=Math.pow(n,2),g=Math.pow(c,2),m=Math.pow(u,2);let _=f*p-f*m-p*g;_<0&&(_=0),_/=f*m+p*g,_=Math.sqrt(_)*(o===a?-1:1);const y=_*r/n*u,x=_*-n/r*c,b=h*y-l*x+(i+t)/2,v=l*y+h*x+(e+s)/2,w=(c-y)/r,T=(u-x)/n,k=(-c-y)/r,E=(-u-x)/n,A=mc(1,0,w,T);let M=mc(w,T,k,E);a===0&&M>0&&(M-=si),a===1&&M<0&&(M+=si),d.centerX=b,d.centerY=v,d.ang1=A,d.ang2=M};function Ef(i,e,t,s,r,n,o,a=0,l=0,h=0){if(n===0||o===0)return;const c=Math.sin(a*si/360),u=Math.cos(a*si/360),d=u*(e-s)/2+c*(t-r)/2,f=-c*(e-s)/2+u*(t-r)/2;if(d===0&&f===0)return;n=Math.abs(n),o=Math.abs(o);const p=Math.pow(d,2)/Math.pow(n,2)+Math.pow(f,2)/Math.pow(o,2);p>1&&(n*=Math.sqrt(p),o*=Math.sqrt(p)),U0(e,t,s,r,n,o,l,h,c,u,d,f,Sn);let{ang1:g,ang2:m}=Sn;const{centerX:_,centerY:y}=Sn;let x=Math.abs(m)/(si/4);Math.abs(1-x)<1e-7&&(x=1);const b=Math.max(Math.ceil(x),1);m/=b;let v=i[i.length-2],w=i[i.length-1];const T={x:0,y:0};for(let k=0;k<b;k++){const E=L0(g,m),{x:A,y:M}=Cn(E[0],n,o,u,c,_,y,T),{x:B,y:G}=Cn(E[1],n,o,u,c,_,y,T),{x:O,y:I}=Cn(E[2],n,o,u,c,_,y,T);Sa(i,v,w,A,M,B,G,O,I),v=O,w=I,g+=m}}function Pf(i,e,t){const s=(o,a)=>{const l=a.x-o.x,h=a.y-o.y,c=Math.sqrt(l*l+h*h),u=l/c,d=h/c;return{len:c,nx:u,ny:d}},r=(o,a)=>{o===0?i.moveTo(a.x,a.y):i.lineTo(a.x,a.y)};let n=e[e.length-1];for(let o=0;o<e.length;o++){const a=e[o%e.length],l=a.radius??t;if(l<=0){r(o,a),n=a;continue}const h=e[(o+1)%e.length],c=s(a,n),u=s(a,h);if(c.len<1e-4||u.len<1e-4){r(o,a),n=a;continue}let d=Math.asin(c.nx*u.ny-c.ny*u.nx),f=1,p=!1;c.nx*u.nx-c.ny*-u.ny<0?d<0?d=Math.PI+d:(d=Math.PI-d,f=-1,p=!0):d>0&&(f=-1,p=!0);const g=d/2;let m,_=Math.abs(Math.cos(g)*l/Math.sin(g));_>Math.min(c.len/2,u.len/2)?(_=Math.min(c.len/2,u.len/2),m=Math.abs(_*Math.sin(g)/Math.cos(g))):m=l;const y=a.x+u.nx*_+-u.ny*m*f,x=a.y+u.ny*_+u.nx*m*f,b=Math.atan2(c.ny,c.nx)+Math.PI/2*f,v=Math.atan2(u.ny,u.nx)-Math.PI/2*f;o===0&&i.moveTo(y+Math.cos(b)*m,x+Math.sin(b)*m),i.arc(y,x,m,b,v,p),n=a}}function Af(i,e,t,s){const r=(a,l)=>Math.sqrt((a.x-l.x)**2+(a.y-l.y)**2),n=(a,l,h)=>({x:a.x+(l.x-a.x)*h,y:a.y+(l.y-a.y)*h}),o=e.length;for(let a=0;a<o;a++){const l=e[(a+1)%o],h=l.radius??t;if(h<=0){a===0?i.moveTo(l.x,l.y):i.lineTo(l.x,l.y);continue}const c=e[a],u=e[(a+2)%o],d=r(c,l);let f;if(d<1e-4)f=l;else{const m=Math.min(d/2,h);f=n(l,c,m/d)}const p=r(u,l);let g;if(p<1e-4)g=l;else{const m=Math.min(p/2,h);g=n(l,u,m/p)}a===0?i.moveTo(f.x,f.y):i.lineTo(f.x,f.y),i.quadraticCurveTo(l.x,l.y,g.x,g.y,s)}}const N0=new te;class Rf{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new Ee,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();const s=this._currentPoly.points,r=s[s.length-2],n=s[s.length-1];return(r!==e||n!==t)&&s.push(e,t),this}arc(e,t,s,r,n,o){this._ensurePoly(!1);const a=this._currentPoly.points;return Ca(a,e,t,s,r,n,o),this}arcTo(e,t,s,r,n){this._ensurePoly();const o=this._currentPoly.points;return kf(o,e,t,s,r,n),this}arcToSvg(e,t,s,r,n,o,a){const l=this._currentPoly.points;return Ef(l,this._currentPoly.lastX,this._currentPoly.lastY,o,a,e,t,s,r,n),this}bezierCurveTo(e,t,s,r,n,o,a){this._ensurePoly();const l=this._currentPoly;return Sa(this._currentPoly.points,l.lastX,l.lastY,e,t,s,r,n,o,a),this}quadraticCurveTo(e,t,s,r,n){this._ensurePoly();const o=this._currentPoly;return Mf(this._currentPoly.points,o.lastX,o.lastY,e,t,s,r,n),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));const s=this.shapePrimitives,r=s.length;for(let n=0;n<e.instructions.length;n++){const o=e.instructions[n];this[o.action](...o.data)}if(e.checkForHoles&&s.length-r>1){let n=null;for(let o=r;o<s.length;o++){const a=s[o];if(a.shape.type==="polygon"){const l=a.shape,h=n?.shape;h&&h.containsPolygon(l)?(n.holes||(n.holes=[]),n.holes.push(a),s.copyWithin(o,o+1),s.length--,o--):n=a}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,s,r,n){return this.drawShape(new te(e,t,s,r),n),this}circle(e,t,s,r){return this.drawShape(new Sr(e,t,s),r),this}poly(e,t,s){const r=new Ts(e);return r.closePath=t,this.drawShape(r,s),this}regularPoly(e,t,s,r,n=0,o){r=Math.max(r|0,3);const a=-1*Math.PI/2+n,l=Math.PI*2/r,h=[];for(let c=0;c<r;c++){const u=a-c*l;h.push(e+s*Math.cos(u),t+s*Math.sin(u))}return this.poly(h,!0,o),this}roundPoly(e,t,s,r,n,o=0,a){if(r=Math.max(r|0,3),n<=0)return this.regularPoly(e,t,s,r,o);const l=s*Math.sin(Math.PI/r)-.001;n=Math.min(n,l);const h=-1*Math.PI/2+o,c=Math.PI*2/r,u=(r-2)*Math.PI/r/2;for(let d=0;d<r;d++){const f=d*c+h,p=e+s*Math.cos(f),g=t+s*Math.sin(f),m=f+Math.PI+u,_=f-Math.PI-u,y=p+n*Math.cos(m),x=g+n*Math.sin(m),b=p+n*Math.cos(_),v=g+n*Math.sin(_);d===0?this.moveTo(y,x):this.lineTo(y,x),this.quadraticCurveTo(p,g,b,v,a)}return this.closePath()}roundShape(e,t,s=!1,r){return e.length<3?this:(s?Af(this,e,t,r):Pf(this,e,t),this.closePath())}filletRect(e,t,s,r,n){if(n===0)return this.rect(e,t,s,r);const o=Math.min(s,r)/2,a=Math.min(o,Math.max(-o,n)),l=e+s,h=t+r,c=a<0?-a:0,u=Math.abs(a);return this.moveTo(e,t+u).arcTo(e+c,t+c,e+u,t,u).lineTo(l-u,t).arcTo(l-c,t+c,l,t+u,u).lineTo(l,h-u).arcTo(l-c,h-c,e+s-u,h,u).lineTo(e+u,h).arcTo(e+c,h-c,e,h-u,u).closePath()}chamferRect(e,t,s,r,n,o){if(n<=0)return this.rect(e,t,s,r);const a=Math.min(n,Math.min(s,r)/2),l=e+s,h=t+r,c=[e+a,t,l-a,t,l,t+a,l,h-a,l-a,h,e+a,h,e,h-a,e,t+a];for(let u=c.length-1;u>=2;u-=2)c[u]===c[u-2]&&c[u-1]===c[u-3]&&c.splice(u-1,2);return this.poly(c,!0,o)}ellipse(e,t,s,r,n){return this.drawShape(new Cr(e,t,s,r),n),this}roundRect(e,t,s,r,n,o){return this.drawShape(new Mr(e,t,s,r,n),o),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let s=this._currentPoly;return s&&this.endPoly(),s=new Ts,s.points.push(e,t),this._currentPoly=s,this}endPoly(e=!1){const t=this._currentPoly;return t&&t.points.length>2&&(t.closePath=e,this.shapePrimitives.push({shape:t})),this._currentPoly=null,this}_ensurePoly(e=!0){if(!this._currentPoly&&(this._currentPoly=new Ts,e)){const t=this.shapePrimitives[this.shapePrimitives.length-1];if(t){let s=t.shape.x,r=t.shape.y;if(t.transform&&!t.transform.isIdentity()){const n=t.transform,o=s;s=n.a*s+n.c*r+n.tx,r=n.b*o+n.d*r+n.ty}this._currentPoly.points.push(s,r)}else this._currentPoly.points.push(0,0)}}buildPath(){const e=this._graphicsPath2D;this.shapePrimitives.length=0,this._currentPoly=null;for(let t=0;t<e.instructions.length;t++){const s=e.instructions[t];this[s.action](...s.data)}this.finish()}get bounds(){const e=this._bounds;e.clear();const t=this.shapePrimitives;for(let s=0;s<t.length;s++){const r=t[s],n=r.shape.getBounds(N0);r.transform?e.addRect(n,r.transform):e.addRect(n)}return e}}class dt{constructor(e,t=!1){this.instructions=[],this.uid=oe("graphicsPath"),this._dirty=!0,this.checkForHoles=t,typeof e=="string"?Wd(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||(this._shapePath=new Rf(this)),this._dirty&&(this._dirty=!1,this._shapePath.buildPath()),this._shapePath}addPath(e,t){return e=e.clone(),this.instructions.push({action:"addPath",data:[e,t]}),this._dirty=!0,this}arc(...e){return this.instructions.push({action:"arc",data:e}),this._dirty=!0,this}arcTo(...e){return this.instructions.push({action:"arcTo",data:e}),this._dirty=!0,this}arcToSvg(...e){return this.instructions.push({action:"arcToSvg",data:e}),this._dirty=!0,this}bezierCurveTo(...e){return this.instructions.push({action:"bezierCurveTo",data:e}),this._dirty=!0,this}bezierCurveToShort(e,t,s,r,n){const o=this.instructions[this.instructions.length-1],a=this.getLastPoint(he.shared);let l=0,h=0;if(!o||o.action!=="bezierCurveTo")l=a.x,h=a.y;else{l=o.data[2],h=o.data[3];const c=a.x,u=a.y;l=c+(c-l),h=u+(u-h)}return this.instructions.push({action:"bezierCurveTo",data:[l,h,e,t,s,r,n]}),this._dirty=!0,this}closePath(){return this.instructions.push({action:"closePath",data:[]}),this._dirty=!0,this}ellipse(...e){return this.instructions.push({action:"ellipse",data:e}),this._dirty=!0,this}lineTo(...e){return this.instructions.push({action:"lineTo",data:e}),this._dirty=!0,this}moveTo(...e){return this.instructions.push({action:"moveTo",data:e}),this}quadraticCurveTo(...e){return this.instructions.push({action:"quadraticCurveTo",data:e}),this._dirty=!0,this}quadraticCurveToShort(e,t,s){const r=this.instructions[this.instructions.length-1],n=this.getLastPoint(he.shared);let o=0,a=0;if(!r||r.action!=="quadraticCurveTo")o=n.x,a=n.y;else{o=r.data[0],a=r.data[1];const l=n.x,h=n.y;o=l+(l-o),a=h+(h-a)}return this.instructions.push({action:"quadraticCurveTo",data:[o,a,e,t,s]}),this._dirty=!0,this}rect(e,t,s,r,n){return this.instructions.push({action:"rect",data:[e,t,s,r,n]}),this._dirty=!0,this}circle(e,t,s,r){return this.instructions.push({action:"circle",data:[e,t,s,r]}),this._dirty=!0,this}roundRect(...e){return this.instructions.push({action:"roundRect",data:e}),this._dirty=!0,this}poly(...e){return this.instructions.push({action:"poly",data:e}),this._dirty=!0,this}regularPoly(...e){return this.instructions.push({action:"regularPoly",data:e}),this._dirty=!0,this}roundPoly(...e){return this.instructions.push({action:"roundPoly",data:e}),this._dirty=!0,this}roundShape(...e){return this.instructions.push({action:"roundShape",data:e}),this._dirty=!0,this}filletRect(...e){return this.instructions.push({action:"filletRect",data:e}),this._dirty=!0,this}chamferRect(...e){return this.instructions.push({action:"chamferRect",data:e}),this._dirty=!0,this}star(e,t,s,r,n,o,a){n||(n=r/2);const l=-1*Math.PI/2+o,h=s*2,c=Math.PI*2/h,u=[];for(let d=0;d<h;d++){const f=d%2?n:r,p=d*c+l;u.push(e+f*Math.cos(p),t+f*Math.sin(p))}return this.poly(u,!0,a),this}clone(e=!1){const t=new dt;if(t.checkForHoles=this.checkForHoles,!e)t.instructions=this.instructions.slice();else for(let s=0;s<this.instructions.length;s++){const r=this.instructions[s];t.instructions.push({action:r.action,data:r.data.slice()})}return t}clear(){return this.instructions.length=0,this._dirty=!0,this}transform(e){if(e.isIdentity())return this;const t=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty;let l=0,h=0,c=0,u=0,d=0,f=0,p=0,g=0;for(let m=0;m<this.instructions.length;m++){const _=this.instructions[m],y=_.data;switch(_.action){case"moveTo":case"lineTo":l=y[0],h=y[1],y[0]=t*l+r*h+o,y[1]=s*l+n*h+a;break;case"bezierCurveTo":c=y[0],u=y[1],d=y[2],f=y[3],l=y[4],h=y[5],y[0]=t*c+r*u+o,y[1]=s*c+n*u+a,y[2]=t*d+r*f+o,y[3]=s*d+n*f+a,y[4]=t*l+r*h+o,y[5]=s*l+n*h+a;break;case"quadraticCurveTo":c=y[0],u=y[1],l=y[2],h=y[3],y[0]=t*c+r*u+o,y[1]=s*c+n*u+a,y[2]=t*l+r*h+o,y[3]=s*l+n*h+a;break;case"arcToSvg":l=y[5],h=y[6],p=y[0],g=y[1],y[0]=t*p+r*g,y[1]=s*p+n*g,y[5]=t*l+r*h+o,y[6]=s*l+n*h+a;break;case"circle":y[4]=ds(y[3],e);break;case"rect":y[4]=ds(y[4],e);break;case"ellipse":y[8]=ds(y[8],e);break;case"roundRect":y[5]=ds(y[5],e);break;case"addPath":y[0].transform(e);break;case"poly":y[2]=ds(y[2],e);break;case"regularPoly":case"chamferRect":y[5]=ds(y[5],e);break;case"closePath":break;default:z("unknown transform action",_.action);break}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,s=this.instructions[t];if(!s)return e.x=0,e.y=0,e;for(;s.action==="closePath";){if(t--,t<0)return e.x=0,e.y=0,e;s=this.instructions[t]}switch(s.action){case"moveTo":case"lineTo":e.x=s.data[0],e.y=s.data[1];break;case"quadraticCurveTo":e.x=s.data[2],e.y=s.data[3];break;case"bezierCurveTo":e.x=s.data[4],e.y=s.data[5];break;case"arc":case"arcToSvg":e.x=s.data[5],e.y=s.data[6];break;case"addPath":s.data[0].getLastPoint(e);break}return e}}function ds(i,e){return i?i.prepend(e):e.clone()}function ve(i,e,t){const s=i.getAttribute(e);return s?Number(s):t}function Bf(i,e){const t=i.querySelectorAll("defs");for(let s=0;s<t.length;s++){const r=t[s];for(let n=0;n<r.children.length;n++){const o=r.children[n];switch(o.nodeName.toLowerCase()){case"lineargradient":e.defs[o.id]=H0(o);break;case"radialgradient":e.defs[o.id]=z0(o);break}}}}function it(i,e,t){const s=i.getAttribute(e);if(s?.trim().endsWith("%")){const r=Number(s.trim().slice(0,-1));return Number.isNaN(r)?t:r/100}return ve(i,e,t)}function If(i){return(i.getAttribute("gradientUnits")||"objectBoundingBox")==="objectBoundingBox"?"local":"global"}function Gf(i){const e=[];for(let t=0;t<i.children.length;t++){const s=i.children[t],r=it(s,"offset",0),n=ae.shared.setValue(s.getAttribute("stop-color")).toNumber();e.push({offset:r,color:n})}return e}function H0(i){const e=it(i,"x1",0),t=it(i,"y1",0),s=it(i,"x2",1),r=it(i,"y2",0);return new je({type:"linear",start:{x:e,y:t},end:{x:s,y:r},textureSpace:If(i),colorStops:Gf(i)})}function z0(i){const e=it(i,"cx",.5),t=it(i,"cy",.5),s=it(i,"r",.5),r=it(i,"fx",e),n=it(i,"fy",t),o=it(i,"fr",0);return new je({type:"radial",center:{x:r,y:n},innerRadius:o,outerCenter:{x:e,y:t},outerRadius:s,textureSpace:If(i),colorStops:Gf(i)})}function _o(i){const e=i.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return e?e[1]:""}const yo={fill:{type:"paint",default:0},"fill-opacity":{type:"number",default:1},stroke:{type:"paint",default:0},"stroke-width":{type:"number",default:1},"stroke-opacity":{type:"number",default:1},"stroke-linecap":{type:"string",default:"butt"},"stroke-linejoin":{type:"string",default:"miter"},"stroke-miterlimit":{type:"number",default:10},"stroke-dasharray":{type:"string",default:"none"},"stroke-dashoffset":{type:"number",default:0},opacity:{type:"number",default:1}};function Ma(i,e){const t=i.getAttribute("style"),s={},r={},n={strokeStyle:s,fillStyle:r,useFill:!1,useStroke:!1};for(const o in yo){const a=i.getAttribute(o);a&&gc(e,n,o,a.trim())}if(t){const o=t.split(";");for(let a=0;a<o.length;a++){const l=o[a].trim(),[h,c]=l.split(":");yo[h]&&gc(e,n,h,c.trim())}}return{strokeStyle:n.useStroke?s:null,fillStyle:n.useFill?r:null,useFill:n.useFill,useStroke:n.useStroke}}function gc(i,e,t,s){switch(t){case"stroke":if(s!=="none"){if(s.startsWith("url(")){const r=_o(s);e.strokeStyle.fill=i.defs[r]}else e.strokeStyle.color=ae.shared.setValue(s).toNumber();e.useStroke=!0}break;case"stroke-width":e.strokeStyle.width=Number(s);break;case"fill":if(s!=="none"){if(s.startsWith("url(")){const r=_o(s);e.fillStyle.fill=i.defs[r]}else e.fillStyle.color=ae.shared.setValue(s).toNumber();e.useFill=!0}break;case"fill-opacity":e.fillStyle.alpha=Number(s);break;case"stroke-opacity":e.strokeStyle.alpha=Number(s);break;case"opacity":e.fillStyle.alpha=Number(s),e.strokeStyle.alpha=Number(s);break}}function Df(i){if(i.length<=2)return!0;const e=i.map(a=>a.area).sort((a,l)=>l-a),[t,s]=e,r=e[e.length-1],n=t/s,o=s/r;return!(n>3&&o<2)}function Ff(i){return i.split(/(?=[Mm])/).filter(s=>s.trim().length>0)}function Of(i){const e=i.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!e||e.length<4)return 0;const t=e.map(Number),s=[],r=[];for(let c=0;c<t.length;c+=2)c+1<t.length&&(s.push(t[c]),r.push(t[c+1]));if(s.length===0||r.length===0)return 0;const n=Math.min(...s),o=Math.max(...s),a=Math.min(...r),l=Math.max(...r);return(o-n)*(l-a)}function xo(i,e){const t=new dt(i,!1);for(const s of t.instructions)e.instructions.push(s)}function Lf(i,e){if(typeof i=="string"){const o=document.createElement("div");o.innerHTML=i.trim(),i=o.querySelector("svg")}const t={context:e,defs:{},path:new dt};Bf(i,t);const s=i.children,{fillStyle:r,strokeStyle:n}=Ma(i,t);for(let o=0;o<s.length;o++){const a=s[o];a.nodeName.toLowerCase()!=="defs"&&Uf(a,t,r,n)}return e}function Uf(i,e,t,s){const r=i.children,{fillStyle:n,strokeStyle:o}=Ma(i,e);n&&t?t={...t,...n}:n&&(t=n),o&&s?s={...s,...o}:o&&(s=o);const a=!t&&!s;a&&(t={color:0});let l,h,c,u,d,f,p,g,m,_,y,x,b,v,w,T,k;switch(i.nodeName.toLowerCase()){case"path":{v=i.getAttribute("d");const E=i.getAttribute("fill-rule"),A=Ff(v),M=E==="evenodd",B=A.length>1;if(M&&B){const O=A.map(P=>({path:P,area:Of(P)}));if(O.sort((P,C)=>C.area-P.area),A.length>3||!Df(O))for(let P=0;P<O.length;P++){const C=O[P],D=P===0;e.context.beginPath();const R=new dt(void 0,!0);xo(C.path,R),e.context.path(R),D?(t&&e.context.fill(t),s&&e.context.stroke(s)):e.context.cut()}else for(let P=0;P<O.length;P++){const C=O[P],D=P%2===1;e.context.beginPath();const R=new dt(void 0,!0);xo(C.path,R),e.context.path(R),D?e.context.cut():(t&&e.context.fill(t),s&&e.context.stroke(s))}}else{const O=E?E==="evenodd":!0;w=new dt(v,O),e.context.path(w),t&&e.context.fill(t),s&&e.context.stroke(s)}break}case"circle":p=ve(i,"cx",0),g=ve(i,"cy",0),m=ve(i,"r",0),e.context.ellipse(p,g,m,m),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"rect":l=ve(i,"x",0),h=ve(i,"y",0),T=ve(i,"width",0),k=ve(i,"height",0),_=ve(i,"rx",0),y=ve(i,"ry",0),_||y?e.context.roundRect(l,h,T,k,_||y):e.context.rect(l,h,T,k),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"ellipse":p=ve(i,"cx",0),g=ve(i,"cy",0),_=ve(i,"rx",0),y=ve(i,"ry",0),e.context.beginPath(),e.context.ellipse(p,g,_,y),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"line":c=ve(i,"x1",0),u=ve(i,"y1",0),d=ve(i,"x2",0),f=ve(i,"y2",0),e.context.beginPath(),e.context.moveTo(c,u),e.context.lineTo(d,f),s&&e.context.stroke(s);break;case"polygon":b=i.getAttribute("points"),x=b.match(/-?\d+/g).map(E=>parseInt(E,10)),e.context.poly(x,!0),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"polyline":b=i.getAttribute("points"),x=b.match(/-?\d+/g).map(E=>parseInt(E,10)),e.context.poly(x,!1),s&&e.context.stroke(s);break;case"g":case"svg":break;default:{z(`[SVG parser] <${i.nodeName}> elements unsupported`);break}}a&&(t=null);for(let E=0;E<r.length;E++)Uf(r[E],e,t,s)}function W0(i){return i.texture!==void 0}const _c={repeat:{addressModeU:"repeat",addressModeV:"repeat"},"repeat-x":{addressModeU:"repeat",addressModeV:"clamp-to-edge"},"repeat-y":{addressModeU:"clamp-to-edge",addressModeV:"repeat"},"no-repeat":{addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}};class Fs{constructor(e,t){this.uid=oe("fillPattern"),this._tick=0,this.transform=new U;const s=W0(e)?e:{texture:e,repetition:t};this.texture=s.texture,this.textureSpace=s.textureSpace??"global";const r=s.repetition;r&&(this.texture.source.style.addressModeU=_c[r].addressModeU,this.texture.source.style.addressModeV=_c[r].addressModeV)}setTransform(e){if(e){if(this.transform.equals(e))return;this.transform.copyFrom(e)}else{if(this.transform.isIdentity())return;this.transform.identity()}this._tick++}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture=e,this._tick++)}get styleKey(){return`fill-pattern-${this.uid}-${this._tick}`}destroy(){this.texture.destroy(!0),this.texture=null}}function $0(i){return ae.isColorLike(i)}function yc(i){return i instanceof Fs}function xc(i){return i instanceof je}function V0(i){return i instanceof W}function j0(i,e,t){const s=ae.shared.setValue(e??0);return i.color=s.toNumber(),i.alpha=s.alpha===1?t.alpha:s.alpha,i.texture=W.WHITE,{...t,...i}}function X0(i,e,t){return i.texture=e,{...t,...i}}function bc(i,e,t){return i.fill=e,i.color=16777215,i.texture=e.texture,i.matrix=e.transform,i.textureSpace=e.textureSpace,{...t,...i}}function vc(i,e,t){return e.buildGradient(),i.fill=e,i.color=16777215,i.texture=e.texture,i.matrix=e.transform,i.textureSpace=e.textureSpace,{...t,...i}}function q0(i,e){const t={...e,...i},s=ae.shared.setValue(t.color);return t.alpha*=s.alpha,t.color=s.toNumber(),t}function Gt(i,e){if(i==null)return null;const t={},s=i;return $0(i)?j0(t,i,e):V0(i)?X0(t,i,e):yc(i)?bc(t,i,e):xc(i)?vc(t,i,e):s.fill&&yc(s.fill)?bc(s,s.fill,e):s.fill&&xc(s.fill)?vc(s,s.fill,e):q0(s,e)}function yi(i,e){const{width:t,alignment:s,miterLimit:r,cap:n,join:o,pixelLine:a,...l}=e,h=Gt(i,l);return h?{width:t,alignment:s,miterLimit:r,cap:n,join:o,pixelLine:a,...h}:null}function Nf(i,e){let t=1;const s=i.shapePath.shapePrimitives;for(let r=0;r<s.length;r++){const n=s[r].shape;if(n.type!=="polygon")continue;const o=n.points,a=o.length;if(a<6)continue;const l=n.closePath;for(let h=0;h<a;h+=2){if(!l&&(h===0||h===a-2))continue;const c=(h-2+a)%a,u=(h+2)%a,d=o[c],f=o[c+1],p=o[h],g=o[h+1],m=o[u],_=o[u+1],y=d-p,x=f-g,b=m-p,v=_-g,w=y*y+x*x,T=b*b+v*v;if(w<1e-12||T<1e-12)continue;let A=(y*b+x*v)/Math.sqrt(w*T);A<-1?A=-1:A>1&&(A=1);const M=Math.sqrt((1-A)*.5);if(M<1e-6)continue;const B=Math.min(1/M,e);B>t&&(t=B)}}return t}const Y0=new he,wc=new U,ka=class at extends Re{constructor(){super(...arguments),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=oe("graphicsContext"),this.dirty=!0,this.batchMode="auto",this.instructions=[],this.destroyed=!1,this._activePath=new dt,this._transform=new U,this._fillStyle={...at.defaultFillStyle},this._strokeStyle={...at.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new Ee,this._boundsDirty=!0}clone(){const e=new at;return e.batchMode=this.batchMode,e.instructions=this.instructions.slice(),e._activePath=this._activePath.clone(),e._transform=this._transform.clone(),e._fillStyle={...this._fillStyle},e._strokeStyle={...this._strokeStyle},e._stateStack=this._stateStack.slice(),e._bounds=this._bounds.clone(),e._boundsDirty=!0,e}get fillStyle(){return this._fillStyle}set fillStyle(e){this._fillStyle=Gt(e,at.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(e){this._strokeStyle=yi(e,at.defaultStrokeStyle)}setFillStyle(e){return this._fillStyle=Gt(e,at.defaultFillStyle),this}setStrokeStyle(e){return this._strokeStyle=Gt(e,at.defaultStrokeStyle),this}texture(e,t,s,r,n,o){return this.instructions.push({action:"texture",data:{image:e,dx:s||0,dy:r||0,dw:n||e.frame.width,dh:o||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t||t===0?ae.shared.setValue(t).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new dt,this}fill(e,t){let s;const r=this.instructions[this.instructions.length-1];return this._tick===0&&r?.action==="stroke"?s=r.data.path:s=this._activePath.clone(),s?(e!=null&&(t!==void 0&&typeof e=="number"&&(H(ue,"GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead"),e={color:e,alpha:t}),this._fillStyle=Gt(e,at.defaultFillStyle)),this.instructions.push({action:"fill",data:{style:this.fillStyle,path:s}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){const{x:e,y:t}=this._activePath.getLastPoint(he.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(e){let t;const s=this.instructions[this.instructions.length-1];return this._tick===0&&s?.action==="fill"?t=s.data.path:t=this._activePath.clone(),t?(e!=null&&(this._strokeStyle=yi(e,at.defaultStrokeStyle)),this.instructions.push({action:"stroke",data:{style:this.strokeStyle,path:t}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}cut(){for(let e=0;e<2;e++){const t=this.instructions[this.instructions.length-1-e],s=this._activePath.clone();if(t&&(t.action==="stroke"||t.action==="fill"))if(t.data.hole)t.data.hole.addPath(s);else{t.data.hole=s;break}}return this._initNextPathLocation(),this}arc(e,t,s,r,n,o){this._tick++;const a=this._transform;return this._activePath.arc(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,s,r,n,o),this}arcTo(e,t,s,r,n){this._tick++;const o=this._transform;return this._activePath.arcTo(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,o.a*s+o.c*r+o.tx,o.b*s+o.d*r+o.ty,n),this}arcToSvg(e,t,s,r,n,o,a){this._tick++;const l=this._transform;return this._activePath.arcToSvg(e,t,s,r,n,l.a*o+l.c*a+l.tx,l.b*o+l.d*a+l.ty),this}bezierCurveTo(e,t,s,r,n,o,a){this._tick++;const l=this._transform;return this._activePath.bezierCurveTo(l.a*e+l.c*t+l.tx,l.b*e+l.d*t+l.ty,l.a*s+l.c*r+l.tx,l.b*s+l.d*r+l.ty,l.a*n+l.c*o+l.tx,l.b*n+l.d*o+l.ty,a),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,s,r){return this._tick++,this._activePath.ellipse(e,t,s,r,this._transform.clone()),this}circle(e,t,s){return this._tick++,this._activePath.circle(e,t,s,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;const s=this._transform;return this._activePath.lineTo(s.a*e+s.c*t+s.tx,s.b*e+s.d*t+s.ty),this}moveTo(e,t){this._tick++;const s=this._transform,r=this._activePath.instructions,n=s.a*e+s.c*t+s.tx,o=s.b*e+s.d*t+s.ty;return r.length===1&&r[0].action==="moveTo"?(r[0].data[0]=n,r[0].data[1]=o,this):(this._activePath.moveTo(n,o),this)}quadraticCurveTo(e,t,s,r,n){this._tick++;const o=this._transform;return this._activePath.quadraticCurveTo(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,o.a*s+o.c*r+o.tx,o.b*s+o.d*r+o.ty,n),this}rect(e,t,s,r){return this._tick++,this._activePath.rect(e,t,s,r,this._transform.clone()),this}roundRect(e,t,s,r,n){return this._tick++,this._activePath.roundRect(e,t,s,r,n,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,s,r,n=0,o){return this._tick++,this._activePath.regularPoly(e,t,s,r,n,o),this}roundPoly(e,t,s,r,n,o){return this._tick++,this._activePath.roundPoly(e,t,s,r,n,o),this}roundShape(e,t,s,r){return this._tick++,this._activePath.roundShape(e,t,s,r),this}filletRect(e,t,s,r,n){return this._tick++,this._activePath.filletRect(e,t,s,r,n),this}chamferRect(e,t,s,r,n,o){return this._tick++,this._activePath.chamferRect(e,t,s,r,n,o),this}star(e,t,s,r,n=0,o=0){return this._tick++,this._activePath.star(e,t,s,r,n,o,this._transform.clone()),this}svg(e){return this._tick++,Lf(e,this),this}restore(){const e=this._stateStack.pop();return e&&(this._transform=e.transform,this._fillStyle=e.fillStyle,this._strokeStyle=e.strokeStyle),this}save(){return this._stateStack.push({transform:this._transform.clone(),fillStyle:{...this._fillStyle},strokeStyle:{...this._strokeStyle}}),this}getTransform(){return this._transform}resetTransform(){return this._transform.identity(),this}rotate(e){return this._transform.rotate(e),this}scale(e,t=e){return this._transform.scale(e,t),this}setTransform(e,t,s,r,n,o){return e instanceof U?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,s,r,n,o),this)}transform(e,t,s,r,n,o){return e instanceof U?(this._transform.append(e),this):(wc.set(e,t,s,r,n,o),this._transform.append(wc),this)}translate(e,t=e){return this._transform.translate(e,t),this}clear(){return this._activePath.clear(),this.instructions.length=0,this.resetTransform(),this.onUpdate(),this}onUpdate(){this._boundsDirty=!0,this.dirty=!0,this.emit("update",this,16)}get bounds(){if(!this._boundsDirty)return this._bounds;this._boundsDirty=!1;const e=this._bounds;e.clear();for(let t=0;t<this.instructions.length;t++){const s=this.instructions[t],r=s.action;if(r==="fill"){const n=s.data;e.addBounds(n.path.bounds)}else if(r==="texture"){const n=s.data;e.addFrame(n.dx,n.dy,n.dx+n.dw,n.dy+n.dh,n.transform)}if(r==="stroke"){const n=s.data,o=n.style.alignment;let a=n.style.width*(1-o);n.style.join==="miter"&&(a*=Nf(n.path,n.style.miterLimit));const l=n.path.bounds;e.addFrame(l.minX-a,l.minY-a,l.maxX+a,l.maxY+a)}}return e.isValid||e.set(0,0,0,0),e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;const t=this.instructions;let s=!1;for(let r=0;r<t.length;r++){const n=t[r],o=n.data,a=o.path;if(!n.action||!a)continue;const l=o.style,h=a.shapePath.shapePrimitives;for(let c=0;c<h.length;c++){const u=h[c].shape;if(!l||!u)continue;const d=h[c].transform,f=d?d.applyInverse(e,Y0):e;if(n.action==="fill")s=u.contains(f.x,f.y);else{const g=l;s=u.strokeContains(f.x,f.y,g.width,g.alignment)}const p=o.hole;if(p){const g=p.shapePath?.shapePrimitives;if(g)for(let m=0;m<g.length;m++)g[m].shape.contains(f.x,f.y)&&(s=!1)}if(s)return!0}}return s}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){if(this.destroyed)return;if(this.destroyed=!0,this._stateStack.length=0,this._transform=null,this.unload(),this.emit("destroy",this),this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._fillStyle.texture&&(this._fillStyle.fill&&"uid"in this._fillStyle.fill?this._fillStyle.fill.destroy():this._fillStyle.texture.destroy(s)),this._strokeStyle.texture&&(this._strokeStyle.fill&&"uid"in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(s))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};ka.defaultFillStyle={color:16777215,alpha:1,texture:W.WHITE,matrix:null,fill:null,textureSpace:"local"};ka.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:"butt",join:"miter",texture:W.WHITE,matrix:null,fill:null,textureSpace:"local",pixelLine:!1};let qe=ka;class Hf{constructor(e){this._attachedDomElements=[],this._renderer=e,this._renderer.runners.postrender.add(this),this._renderer.runners.init.add(this),this._domElement=document.createElement("div"),this._domElement.style.position="absolute",this._domElement.style.top="0",this._domElement.style.left="0",this._domElement.style.pointerEvents="none",this._domElement.style.zIndex="1000"}init(){this._canvasObserver=new Zo({domElement:this._domElement,renderer:this._renderer})}addRenderable(e,t){this._attachedDomElements.includes(e)||this._attachedDomElements.push(e)}updateRenderable(e){}validateRenderable(e){return!0}postrender(){const e=this._attachedDomElements;if(e.length===0){this._domElement.remove();return}this._canvasObserver.ensureAttached();for(let t=0;t<e.length;t++){const s=e[t],r=s.element;if(!s.parent||s.globalDisplayStatus<7)r?.remove(),e.splice(t,1),t--;else{this._domElement.contains(r)||(r.style.position="absolute",r.style.pointerEvents="auto",this._domElement.appendChild(r));const n=s.worldTransform,o=s._anchor,a=s.width*o.x,l=s.height*o.y;r.style.transformOrigin=`${a}px ${l}px`,r.style.transform=`matrix(${n.a}, ${n.b}, ${n.c}, ${n.d}, ${n.tx-a}, ${n.ty-l})`,r.style.opacity=s.groupAlpha.toString()}}}destroy(){this._renderer.runners.postrender.remove(this);for(let e=0;e<this._attachedDomElements.length;e++)this._attachedDomElements[e].element?.remove();this._attachedDomElements.length=0,this._domElement.remove(),this._canvasObserver.destroy(),this._renderer=null}}Hf.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"dom"};class K0{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}init(e){this.removeTickerListener(),this.events=e,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(e){this._pauseUpdate=e}addTickerListener(){this._tickerAdded||!this.domElement||(We.system.add(this._tickerUpdate,this,is.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(We.system.remove(this._tickerUpdate,this),this._tickerAdded=!1)}pointerMoved(){this._didMove=!0}_update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const e=this.events._rootPointerEvent;this.events.supportsTouchEvents&&e.pointerType==="touch"||globalThis.document.dispatchEvent(this.events.supportsPointerEvents?new PointerEvent("pointermove",{clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,pointerId:e.pointerId}):new MouseEvent("mousemove",{clientX:e.clientX,clientY:e.clientY}))}_tickerUpdate(e){this._deltaTime+=e.deltaTime,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this._update())}destroy(){this.removeTickerListener(),this.events=null,this.domElement=null,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}}const ct=new K0;class xi extends Gs{constructor(){super(...arguments),this.client=new he,this.movement=new he,this.offset=new he,this.global=new he,this.screen=new he}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(e,t,s){return e.worldTransform.applyInverse(s||this.global,t)}getModifierState(e){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(e)}initMouseEvent(e,t,s,r,n,o,a,l,h,c,u,d,f,p,g){throw new Error("Method not implemented.")}}class Fe extends xi{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1,this.persistentDeviceId=0}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class os extends xi{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}os.DOM_DELTA_PIXEL=0;os.DOM_DELTA_LINE=1;os.DOM_DELTA_PAGE=2;const Z0=2048,Q0=new he,qs=new he;class zf{constructor(e){this.dispatch=new Re,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=e,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mapContextMenu=this.mapContextMenu.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel),this.addEventMapping("contextmenu",this.mapContextMenu)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((s,r)=>s.priority-r.priority)}dispatchEvent(e,t){e.propagationStopped=!1,e.propagationImmediatelyStopped=!1,this.propagate(e,t),this.dispatch.emit(t||e.type,e)}mapEvent(e){if(!this.rootTarget)return;const t=this.mappingTable[e.type];if(t)for(let s=0,r=t.length;s<r;s++)t[s].fn(e);else z(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){ct.pauseUpdate=!0;const r=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",n=this[r](this.rootTarget,this.rootTarget.eventMode,Q0.set(e,t),this.hitTestFn,this.hitPruneFn);return n&&n[0]}propagate(e,t){if(!e.target)return;const s=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let r=0,n=s.length-1;r<n;r++)if(e.currentTarget=s[r],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return;if(e.eventPhase=e.AT_TARGET,e.currentTarget=e.target,this.notifyTarget(e,t),!(e.propagationStopped||e.propagationImmediatelyStopped)){e.eventPhase=e.BUBBLING_PHASE;for(let r=s.length-2;r>=0;r--)if(e.currentTarget=s[r],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,s=this._allInteractiveElements){if(s.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const r=Array.isArray(t)?t:[t];for(let n=s.length-1;n>=0;n--)r.forEach(o=>{e.currentTarget=s[n],this.notifyTarget(e,o)})}propagationPath(e){const t=[e];for(let s=0;s<Z0&&e!==this.rootTarget&&e.parent;s++){if(!e.parent)throw new Error("Cannot find propagation path to disconnected target");t.push(e.parent),e=e.parent}return t.reverse(),t}hitTestMoveRecursive(e,t,s,r,n,o=!1){let a=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(ct.pauseUpdate=!1),e.interactiveChildren&&e.children){const c=e.children;for(let u=c.length-1;u>=0;u--){const d=c[u],f=this.hitTestMoveRecursive(d,this._isInteractive(t)?t:d.eventMode,s,r,n,o||n(e,s));if(f){if(f.length>0&&!f[f.length-1].parent)continue;const p=e.isInteractive();(f.length>0||p)&&(p&&this._allInteractiveElements.push(e),f.push(e)),this._hitElements.length===0&&(this._hitElements=f),a=!0}}}const l=this._isInteractive(t),h=e.isInteractive();return h&&h&&this._allInteractiveElements.push(e),o||this._hitElements.length>0?null:a?this._hitElements:l&&!n(e,s)&&r(e,s)?h?[e]:[]:null}hitTestRecursive(e,t,s,r,n){if(this._interactivePrune(e)||n(e,s))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(ct.pauseUpdate=!1),e.interactiveChildren&&e.children){const l=e.children,h=s;for(let c=l.length-1;c>=0;c--){const u=l[c],d=this.hitTestRecursive(u,this._isInteractive(t)?t:u.eventMode,h,r,n);if(d){if(d.length>0&&!d[d.length-1].parent)continue;const f=e.isInteractive();return(d.length>0||f)&&d.push(e),d}}}const o=this._isInteractive(t),a=e.isInteractive();return o&&r(e,s)?a?[e]:[]:null}_isInteractive(e){return e==="static"||e==="dynamic"}_interactivePrune(e){return!e||!e.visible||!e.renderable||!e.measurable||e.eventMode==="none"||e.eventMode==="passive"&&!e.interactiveChildren}hitPruneFn(e,t){if(e.hitArea&&(e.worldTransform.applyInverse(t,qs),!e.hitArea.contains(qs.x,qs.y)))return!0;if(e.effects&&e.effects.length)for(let s=0;s<e.effects.length;s++){const r=e.effects[s];if(r.containsPoint&&!r.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e?.containsPoint?(e.worldTransform.applyInverse(t,qs),e.containsPoint(qs)):!1}notifyTarget(e,t){if(!e.currentTarget.isInteractive())return;t??(t=e.type);const s=`on${t}`;e.currentTarget[s]?.(e);const r=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,r),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);if(this.dispatchEvent(t,"pointerdown"),t.pointerType==="touch")this.dispatchEvent(t,"touchstart");else if(t.pointerType==="mouse"||t.pointerType==="pen"){const r=t.button===2;this.dispatchEvent(t,r?"rightdown":"mousedown")}const s=this.trackingData(e.pointerId);s.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const t=this.createPointerEvent(e);this._isPointerMoveEvent=!1;const s=t.pointerType==="mouse"||t.pointerType==="pen",r=this.trackingData(e.pointerId),n=this.findMountedTarget(r.overTargets);if(r.overTargets?.length>0&&n!==t.target){const l=e.type==="mousemove"?"mouseout":"pointerout",h=this.createPointerEvent(e,l,n);if(this.dispatchEvent(h,"pointerout"),s&&this.dispatchEvent(h,"mouseout"),!t.composedPath().includes(n)){const c=this.createPointerEvent(e,"pointerleave",n);for(c.eventPhase=c.AT_TARGET;c.target&&!t.composedPath().includes(c.target);)c.currentTarget=c.target,this.notifyTarget(c),s&&this.notifyTarget(c,"mouseleave"),c.target=c.target.parent;this.freeEvent(c)}this.freeEvent(h)}if(n!==t.target){const l=e.type==="mousemove"?"mouseover":"pointerover",h=this.clonePointerEvent(t,l);this.dispatchEvent(h,"pointerover"),s&&this.dispatchEvent(h,"mouseover");let c=n?.parent;for(;c&&c!==this.rootTarget.parent&&c!==t.target;)c=c.parent;if(!c||c===this.rootTarget.parent){const d=this.clonePointerEvent(t,"pointerenter");for(d.eventPhase=d.AT_TARGET;d.target&&d.target!==n&&d.target!==this.rootTarget.parent;)d.currentTarget=d.target,this.notifyTarget(d),s&&this.notifyTarget(d,"mouseenter"),d.target=d.target.parent;this.freeEvent(d)}this.freeEvent(h)}const o=[],a=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(t,"pointermove"),a&&o.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),a&&o.push("globaltouchmove")),s&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),a&&o.push("globalmousemove"),this.cursor=t.target?.cursor),o.length>0&&this.all(t,o),this._allInteractiveElements.length=0,this._hitElements.length=0,r.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),s=this.createPointerEvent(e),r=s.pointerType==="mouse"||s.pointerType==="pen";this.dispatchEvent(s,"pointerover"),r&&this.dispatchEvent(s,"mouseover"),s.pointerType==="mouse"&&(this.cursor=s.target?.cursor);const n=this.clonePointerEvent(s,"pointerenter");for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),r&&this.notifyTarget(n,"mouseenter"),n.target=n.target.parent;t.overTargets=s.composedPath(),this.freeEvent(s),this.freeEvent(n)}mapPointerOut(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const s=e.pointerType==="mouse"||e.pointerType==="pen",r=this.findMountedTarget(t.overTargets),n=this.createPointerEvent(e,"pointerout",r);this.dispatchEvent(n),s&&this.dispatchEvent(n,"mouseout");const o=this.createPointerEvent(e,"pointerleave",r);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),s&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;t.overTargets=null,this.freeEvent(n),this.freeEvent(o)}this.cursor=null}mapPointerUp(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),s=this.createPointerEvent(e);if(this.dispatchEvent(s,"pointerup"),s.pointerType==="touch")this.dispatchEvent(s,"touchend");else if(s.pointerType==="mouse"||s.pointerType==="pen"){const a=s.button===2;this.dispatchEvent(s,a?"rightup":"mouseup")}const r=this.trackingData(e.pointerId),n=this.findMountedTarget(r.pressTargetsByButton[e.button]);let o=n;if(n&&!s.composedPath().includes(n)){let a=n;for(;a&&!s.composedPath().includes(a);){if(s.currentTarget=a,this.notifyTarget(s,"pointerupoutside"),s.pointerType==="touch")this.notifyTarget(s,"touchendoutside");else if(s.pointerType==="mouse"||s.pointerType==="pen"){const l=s.button===2;this.notifyTarget(s,l?"rightupoutside":"mouseupoutside")}a=a.parent}delete r.pressTargetsByButton[e.button],o=a}if(o){const a=this.clonePointerEvent(s,"click");a.target=o,a.path=null,r.clicksByButton[e.button]||(r.clicksByButton[e.button]={clickCount:0,target:a.target,timeStamp:t});const l=r.clicksByButton[e.button];if(l.target===a.target&&t-l.timeStamp<200?++l.clickCount:l.clickCount=1,l.target=a.target,l.timeStamp=t,a.detail=l.clickCount,a.pointerType==="mouse"){const h=a.button===2;this.dispatchEvent(a,h?"rightclick":"click")}else a.pointerType==="touch"&&this.dispatchEvent(a,"tap");this.dispatchEvent(a,"pointertap"),this.freeEvent(a)}this.freeEvent(s)}mapPointerUpOutside(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),s=this.findMountedTarget(t.pressTargetsByButton[e.button]),r=this.createPointerEvent(e);if(s){let n=s;for(;n;)r.currentTarget=n,this.notifyTarget(r,"pointerupoutside"),r.pointerType==="touch"?this.notifyTarget(r,"touchendoutside"):(r.pointerType==="mouse"||r.pointerType==="pen")&&this.notifyTarget(r,r.button===2?"rightupoutside":"mouseupoutside"),n=n.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(r)}mapWheel(e){if(!(e instanceof os)){z("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}mapContextMenu(e){if(!(e instanceof Fe)){z("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);this.dispatchEvent(t,"contextmenu"),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let s=1;s<e.length&&e[s].parent===t;s++)t=e[s];return t}createPointerEvent(e,t,s){const r=this.allocateEvent(Fe);return this.copyPointerData(e,r),this.copyMouseData(e,r),this.copyData(e,r),r.nativeEvent=e.nativeEvent,r.originalEvent=e,r.target=s??this.hitTest(r.global.x,r.global.y)??this._hitElements[0],typeof t=="string"&&(r.type=t),r}createWheelEvent(e){const t=this.allocateEvent(os);return this.copyWheelData(e,t),this.copyMouseData(e,t),this.copyData(e,t),t.nativeEvent=e.nativeEvent,t.originalEvent=e,t.target=this.hitTest(t.global.x,t.global.y),t}clonePointerEvent(e,t){const s=this.allocateEvent(Fe);return s.nativeEvent=e.nativeEvent,s.originalEvent=e.originalEvent,this.copyPointerData(e,s),this.copyMouseData(e,s),this.copyData(e,s),s.target=e.target,s.path=e.composedPath().slice(),s.type=t??s.type,s}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof Fe&&t instanceof Fe&&(t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,t.persistentDeviceId=e.persistentDeviceId)}copyMouseData(e,t){e instanceof xi&&t instanceof xi&&(t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.copyFrom(e.client),t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.copyFrom(e.movement),t.screen.copyFrom(e.screen),t.shiftKey=e.shiftKey,t.global.copyFrom(e.global))}copyData(e,t){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.detail=e.detail,t.view=e.view,t.which=e.which,t.layer.copyFrom(e.layer),t.page.copyFrom(e.page)}trackingData(e){return this.mappingState.trackingData[e]||(this.mappingState.trackingData[e]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[e]}allocateEvent(e){this.eventPool.has(e)||this.eventPool.set(e,[]);const t=this.eventPool.get(e).pop()||new e(this);return t.eventPhase=t.NONE,t.currentTarget=null,t.defaultPrevented=!1,t.path=null,t.target=null,t}freeEvent(e){if(e.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const t=e.constructor;this.eventPool.has(t)||this.eventPool.set(t,[]),this.eventPool.get(t).push(e)}_notifyListeners(e,t){const s=e.currentTarget._events[t];if(s)if("fn"in s)s.once&&e.currentTarget.removeListener(t,s.fn,void 0,!0),s.fn.call(s.context,e);else for(let r=0,n=s.length;r<n&&!e.propagationImmediatelyStopped;r++)s[r].once&&e.currentTarget.removeListener(t,s[r].fn,void 0,!0),s[r].fn.call(s[r].context,e)}}const J0=1,ey={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},Ea=class bo{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new zf(null),ct.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new Fe(null),this._rootWheelEvent=new os(null),this._rootContextMenuEvent=new Fe(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...bo.defaultEventFeatures},{set:(t,s,r)=>(s==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=r),t[s]=r,!0)}),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerMove=this._onPointerMove.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onPointerOverOut=this._onPointerOverOut.bind(this),this._onContextMenu=this._onContextMenu.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:s}=this.renderer;this.setTargetElement(t),this.resolution=s,bo._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){ct.destroy(),this.setTargetElement(null),this.renderer=null,this._currentCursor=null}setCursor(e){e||(e="default");let t=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(t=!1),this._currentCursor===e)return;this._currentCursor=e;const s=this.cursorStyles[e];if(s)switch(typeof s){case"string":t&&(this.domElement.style.cursor=s);break;case"function":s(e);break;case"object":t&&Object.assign(this.domElement.style,s);break}else t&&typeof e=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,e)&&(this.domElement.style.cursor=e)}get pointer(){return this._rootPointerEvent}_onPointerDown(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);this.autoPreventDefault&&t[0].isNormalized&&(e.cancelable||!("cancelable"in e))&&e.preventDefault();for(let s=0,r=t.length;s<r;s++){const n=t[s],o=this._bootstrapEvent(this._rootPointerEvent,n);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,ct.pointerMoved();const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootPointerEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}_onPointerUp(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let t=e.target;e.composedPath&&e.composedPath().length>0&&(t=e.composedPath()[0]);const s=t!==this.domElement?"outside":"",r=this._normalizeToPointerData(e);for(let n=0,o=r.length;n<o;n++){const a=this._bootstrapEvent(this._rootPointerEvent,r[n]);a.type+=s,this.rootBoundary.mapEvent(a)}this.setCursor(this.rootBoundary.cursor)}_onPointerOverOut(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootPointerEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}_onContextMenu(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootContextMenuEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}onWheel(e){if(!this.features.wheel)return;const t=this.normalizeWheelEvent(e);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(t)}setTargetElement(e){this._removeEvents(),this.domElement=e,ct.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;ct.addTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="none",e.msTouchAction="none"):this.supportsPointerEvents&&(e.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this._onPointerMove,!0),this.domElement.addEventListener("pointerdown",this._onPointerDown,!0),this.domElement.addEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this._onPointerOverOut,!0),globalThis.addEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this._onPointerMove,!0),this.domElement.addEventListener("mousedown",this._onPointerDown,!0),this.domElement.addEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this._onPointerOverOut,!0),globalThis.addEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this._onPointerDown,!0),this.domElement.addEventListener("touchend",this._onPointerUp,!0),this.domElement.addEventListener("touchmove",this._onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.domElement.addEventListener("contextmenu",this._onContextMenu,!0),this._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;ct.removeTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="",e.msTouchAction=""):this.supportsPointerEvents&&(e.touchAction="")),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this._onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this._onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this._onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this._onPointerMove,!0),this.domElement.removeEventListener("mousedown",this._onPointerDown,!0),this.domElement.removeEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this._onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this._onPointerDown,!0),this.domElement.removeEventListener("touchend",this._onPointerUp,!0),this.domElement.removeEventListener("touchmove",this._onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement.removeEventListener("contextmenu",this._onContextMenu,!0),this.domElement=null,this._eventsAdded=!1}mapPositionToPoint(e,t,s){const r=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},n=1/this.resolution;e.x=(t-r.left)*(this.domElement.width/r.width)*n,e.y=(s-r.top)*(this.domElement.height/r.height)*n}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let s=0,r=e.changedTouches.length;s<r;s++){const n=e.changedTouches[s];typeof n.button>"u"&&(n.button=0),typeof n.buttons>"u"&&(n.buttons=1),typeof n.isPrimary>"u"&&(n.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof n.width>"u"&&(n.width=n.radiusX||1),typeof n.height>"u"&&(n.height=n.radiusY||1),typeof n.tiltX>"u"&&(n.tiltX=0),typeof n.tiltY>"u"&&(n.tiltY=0),typeof n.pointerType>"u"&&(n.pointerType="touch"),typeof n.pointerId>"u"&&(n.pointerId=n.identifier||0),typeof n.pressure>"u"&&(n.pressure=n.force||.5),typeof n.twist>"u"&&(n.twist=0),typeof n.tangentialPressure>"u"&&(n.tangentialPressure=0),typeof n.layerX>"u"&&(n.layerX=n.offsetX=n.clientX),typeof n.layerY>"u"&&(n.layerY=n.offsetY=n.clientY),n.isNormalized=!0,n.type=e.type,n.altKey??(n.altKey=e.altKey),n.ctrlKey??(n.ctrlKey=e.ctrlKey),n.metaKey??(n.metaKey=e.metaKey),n.shiftKey??(n.shiftKey=e.shiftKey),t.push(n)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const s=e;typeof s.isPrimary>"u"&&(s.isPrimary=!0),typeof s.width>"u"&&(s.width=1),typeof s.height>"u"&&(s.height=1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="mouse"),typeof s.pointerId>"u"&&(s.pointerId=J0),typeof s.pressure>"u"&&(s.pressure=.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),s.isNormalized=!0,t.push(s)}else t.push(e);return t}normalizeWheelEvent(e){const t=this._rootWheelEvent;return this._transferMouseData(t,e),t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ,t.deltaMode=e.deltaMode,this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.nativeEvent=e,t.type=e.type,t}_bootstrapEvent(e,t){return e.originalEvent=null,e.nativeEvent=t,e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist,this._transferMouseData(e,t),this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.isTrusted=t.isTrusted,e.type==="pointerleave"&&(e.type="pointerout"),e.type.startsWith("mouse")&&(e.type=e.type.replace("mouse","pointer")),e.type.startsWith("touch")&&(e.type=ey[e.type]||e.type),e}_transferMouseData(e,t){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.x=t.clientX,e.client.y=t.clientY,e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.x=t.movementX,e.movement.y=t.movementY,e.page.x=t.pageX,e.page.y=t.pageY,e.relatedTarget=null,e.shiftKey=t.shiftKey}};Ea.extension={name:"events",type:[S.WebGLSystem,S.CanvasSystem,S.WebGPUSystem],priority:-1};Ea.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let Wf=Ea;const ty={onclick:null,oncontextmenu:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,get interactive(){return this.eventMode==="dynamic"||this.eventMode==="static"},set interactive(i){this.eventMode=i?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??Wf.defaultEventMode},set eventMode(i){this._internalEventMode=i},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(i,e,t){const s=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,r=typeof t=="object"?t.signal:void 0,n=typeof t=="object"?t.once===!0:!1,o=typeof e=="function"?void 0:e;i=s?`${i}capture`:i;const a=typeof e=="function"?e:e.handleEvent,l=this;r&&r.addEventListener("abort",()=>{l.off(i,a,o)}),n?l.once(i,a,o):l.on(i,a,o)},removeEventListener(i,e,t){const s=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,r=typeof e=="function"?void 0:e;i=s?`${i}capture`:i,e=typeof e=="function"?e:e.handleEvent,this.off(i,e,r)},dispatchEvent(i){if(!(i instanceof Gs))throw new Error("Container cannot propagate events outside of the Federated Events API");return i.defaultPrevented=!1,i.path=null,i.target=this,i.manager.dispatchEvent(i),!i.defaultPrevented}};let fs;function Tc(i){const e=ee.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=i,t.fillRect(0,0,6,1),e}function Pa(){if(fs!==void 0)return fs;try{const i=Tc("#ff00ff"),e=Tc("#ffff00"),s=ee.get().createCanvas(6,1).getContext("2d");s.globalCompositeOperation="multiply",s.drawImage(i,0,0),s.drawImage(e,2,0);const r=s.getImageData(2,0,1,1);if(!r)fs=!1;else{const n=r.data;fs=n[0]===255&&n[1]===0&&n[2]===0}}catch{fs=!1}return fs}const Y={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,canUseMultiply:Pa(),tintMethod:null,_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:i=>{const e=i.source,t=e?.resource;if(!t)return null;const s=e.alphaMode==="premultiplied-alpha",r=e.resourceWidth??e.pixelWidth,n=e.resourceHeight??e.pixelHeight,o=r!==e.pixelWidth||n!==e.pixelHeight;if(s){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!o)return t;const a=Y._unpremultipliedCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const a=Y._canvasSourceCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas;const l=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),h=l.getContext("2d"),c=h.createImageData(e.pixelWidth,e.pixelHeight),u=c.data,d=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let f=0;f<u.length&&f+3<d.length;f+=4)u[f]=d[f+2],u[f+1]=d[f+1],u[f+2]=d[f],u[f+3]=d[f+3];else u.set(d.subarray(0,u.length));return h.putImageData(c,0,0),Y._canvasSourceCache.set(e,{canvas:l,resourceId:e._resourceId}),l}if(s){const a=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),l=a.getContext("2d",{willReadFrequently:!0});a.width=e.pixelWidth,a.height=e.pixelHeight,l.drawImage(t,0,0);const h=l.getImageData(0,0,a.width,a.height),c=h.data;for(let u=0;u<c.length;u+=4){const d=c[u+3];if(d>0){const f=255/d;c[u]=Math.min(255,c[u]*f+.5),c[u+1]=Math.min(255,c[u+1]*f+.5),c[u+2]=Math.min(255,c[u+2]*f+.5)}}return l.putImageData(h,0,0),Y._unpremultipliedCache.set(e,{canvas:a,resourceId:e._resourceId}),a}if(o){const a=Y._canvasSourceCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas;const l=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),h=l.getContext("2d");return l.width=e.pixelWidth,l.height=e.pixelHeight,h.drawImage(t,0,0),Y._canvasSourceCache.set(e,{canvas:l,resourceId:e._resourceId}),l}return t},getTintedCanvas:(i,e)=>{const t=i.texture,s=ae.shared.setValue(e).toHex(),r=t.tintCache||(t.tintCache={}),n=r[s],o=t.source._resourceId;if(n?.tintId===o)return n;const a=n&&"getContext"in n?n:ee.get().createCanvas();return Y.tintMethod(t,e,a),a.tintId=o,r[s]=a,r[s]},getTintedPattern:(i,e)=>{const t=ae.shared.setValue(e).toHex(),s=i.patternCache||(i.patternCache={}),r=i.source._resourceId;let n=s[t];return n?.tintId===r||(Y.canvas||(Y.canvas=ee.get().createCanvas()),Y.tintMethod(i,e,Y.canvas),n=Y.canvas.getContext("2d").createPattern(Y.canvas,"repeat"),n.tintId=r,s[t]=n),n},applyPatternTransform:(i,e,t=!0)=>{if(!e)return;const s=i;if(!s.setTransform)return;const r=globalThis.DOMMatrix;if(!r)return;const n=new r([e.a,e.b,e.c,e.d,e.tx,e.ty]);s.setTransform(t?n.inverse():n)},tintWithMultiply:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),e!==16777215&&(s.fillStyle=ae.shared.setValue(e).toHex(),s.fillRect(0,0,l,h),s.globalCompositeOperation="multiply");const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),e!==16777215&&(s.globalCompositeOperation="destination-atop",s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height)),s.restore()},tintWithOverlay:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),s.globalCompositeOperation="copy",s.fillStyle=ae.shared.setValue(e).toHex(),s.fillRect(0,0,l,h),s.globalCompositeOperation="destination-atop";const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithPerPixel:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),s.globalCompositeOperation="copy";const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore();const u=e>>16&255,d=e>>8&255,f=e&255,p=s.getImageData(0,0,l,h),g=p.data;for(let m=0;m<g.length;m+=4)g[m]=g[m]*u/255,g[m+1]=g[m+1]*d/255,g[m+2]=g[m+2]*f/255;s.putImageData(p,0,0)},_applyInverseRotation:(i,e,t,s)=>{const r=Z.inv(e),n=Z.uX(r),o=Z.uY(r),a=Z.vX(r),l=Z.vY(r),h=-Math.min(0,n*t,a*s,n*t+a*s),c=-Math.min(0,o*t,l*s,o*t+l*s);i.transform(n,o,a,l,h,c)}};Y.tintMethod=Y.canUseMultiply?Y.tintWithMultiply:Y.tintWithPerPixel;const Mn=32767;function Sc(i,e){return(i<<17)+(e<<2)}class $f{constructor(e){this._buckets=new Map,this._screens=new Wo,this._enableFullScreen=!1,this.canvasOptions=e||{}}get enableFullScreen(){return H(ht,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen}set enableFullScreen(e){H(ht,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen=e}_createCanvasAndContext(e,t){const s=ee.get().createCanvas();s.width=e,s.height=t;const r=s.getContext("2d");return{canvas:s,context:r}}getOptimalCanvasAndContext(e,t,s=1){const{width:r,height:n}=this.getOptimalSize(e,t,s);(r>Mn||n>Mn)&&z(`CanvasPool: ${r}x${n} is larger than the ${Mn}px pool key limit, canvases of this size may be pooled together`);const o=Sc(r,n);let a=this._buckets.get(o);a||(a=[],this._buckets.set(o,a));let l=a.pop();return l||(l=this._createCanvasAndContext(r,n)),l}getOptimalSize(e,t,s=1){const r=Math.ceil(e*s-1e-6),n=Math.ceil(t*s-1e-6),o=es(r),a=this._screens.getFittingWidth(r),l=es(n),h=this._screens.getFittingHeight(n);return{width:a!==void 0?Math.min(a,o):o,height:h!==void 0?Math.min(h,l):l}}returnCanvasAndContext(e){const t=e.canvas,{width:s,height:r}=t,n=this._buckets.get(Sc(s,r));n&&(e.context.resetTransform(),e.context.clearRect(0,0,s,r),n.push(e))}setScreenSize(e,t,s){this._screens.set(e,t,s)&&this._pruneScreenCanvases()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenCanvases()}clear(){this._buckets.clear()}_pruneScreenCanvases(){for(const[e]of this._buckets){const t=e>>>17,s=e>>>2&32767;(ts(t)||this._screens.hasWidth(t))&&(ts(s)||this._screens.hasHeight(s))||this._buckets.delete(e)}}}const Et=new $f;as.register(Et);const Cc=new U;function Aa(i,e){e.clear();const t=e.matrix;for(let s=0;s<i.length;s++){const r=i[s];if(r.globalDisplayStatus<7)continue;const n=r.renderGroup??r.parentRenderGroup;n?.isCachedAsTexture?e.matrix=Cc.copyFrom(n.textureOffsetInverseTransform).append(r.worldTransform):n?._parentCacheAsTextureRenderGroup?e.matrix=Cc.copyFrom(n._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(r.groupTransform):e.matrix=r.worldTransform,e.addBounds(r.bounds)}return e.matrix=t,e}const sy=new Ee;function Ra(i,e,t,s,r=!1,n){const o=sy;o.minX=0,o.minY=0,o.maxX=i.width/s|0,o.maxY=i.height/s|0;const a=Te.getOptimalTexture({width:o.width,height:o.height,resolution:s,autoGenerateMipmaps:r,scaleMode:n});return a.source.uploadMethodId="image",a.source.resource=i,a.source.alphaMode="premultiply-alpha-on-upload",a.frame.width=e/s,a.frame.height=t/s,a.source.emit("update",a.source),a.updateUvs(),a}function vo(i){return typeof i.getCanvasFilterString=="function"}class iy{constructor(){this.skip=!1,this.useClip=!1,this.filters=null,this.container=null,this.bounds=new Ee,this.cssFilterString=""}}class Vf{constructor(e){this._filterStack=[],this._filterStackIndex=0,this._savedStates=[],this._alphaMultiplier=1,this._warnedFilterTypes=new Set,this.renderer=e}push(e){const t=this._pushFilterFrame(),s=e.filterEffect.filters;if(t.skip=!1,t.useClip=!1,t.filters=s,t.container=e.container,t.cssFilterString="",s.every(l=>!l.enabled)){t.skip=!0;return}const r=[],n=1;for(const l of s){if(!l.enabled)continue;if(!vo(l)){this._warnUnsupportedFilter(l);continue}const h=l.getCanvasFilterString();if(h===null){this._warnUnsupportedFilter(l);continue}h&&r.push(h)}if(r.length===0&&n===1){t.skip=!0;return}t.cssFilterString=r.join(" "),this._calculateFilterArea(e,t.bounds),t.useClip=!!e.filterEffect.filterArea;const o=this.renderer.canvasContext.activeContext,a=o.filter||"none";if(this._savedStates.push({filter:a,alphaMultiplier:this._alphaMultiplier}),t.useClip&&Number.isFinite(t.bounds.width)&&Number.isFinite(t.bounds.height)&&t.bounds.width>0&&t.bounds.height>0){const l=this.renderer.canvasContext.activeResolution||1;o.save(),o.setTransform(1,0,0,1,0,0),o.beginPath(),o.rect(t.bounds.x*l,t.bounds.y*l,t.bounds.width*l,t.bounds.height*l),o.clip()}else t.useClip=!1;t.cssFilterString&&(o.filter=a!=="none"?`${a} ${t.cssFilterString}`:t.cssFilterString)}pop(){const e=this._popFilterFrame();if(e.skip)return;const t=this._savedStates.pop();if(!t)return;const s=this.renderer.canvasContext.activeContext;e.useClip?s.restore():s.filter=t.filter,this._alphaMultiplier=t.alphaMultiplier}generateFilteredTexture({texture:e,filters:t}){if(!t?.length||t.every(_=>!_.enabled))return e;const s=[],r=1;for(const _ of t){if(!_.enabled)continue;if(!vo(_)){this._warnUnsupportedFilter(_);continue}const y=_.getCanvasFilterString();if(y===null){this._warnUnsupportedFilter(_);continue}y&&s.push(y)}if(s.length===0&&r===1)return e;const n=Y.getCanvasSource(e);if(!n)return e;const o=e.frame,a=e.source._resolution??e.source.resolution??1,l=o.width,h=o.height,c=Et.getOptimalCanvasAndContext(l,h,a),{canvas:u,context:d}=c;d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,u.width,u.height),s.length&&(d.filter=s.join(" "));const f=o.x*a,p=o.y*a,g=l*a,m=h*a;return d.drawImage(n,f,p,g,m,0,0,g,m),d.filter="none",d.globalAlpha=1,Ra(u,l,h,a)}_calculateFilterArea(e,t){if(e.renderables?Aa(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const r=(e.container.renderGroup||e.container.parentRenderGroup)?.cacheToLocalTransform;r&&t.applyMatrix(r)}}_warnUnsupportedFilter(e){const t=e?.constructor?.name||"Filter";this._warnedFilterTypes.has(t)||(this._warnedFilterTypes.add(t),console.warn(`CanvasRenderer: filter "${t}" is not supported in Canvas2D and will be skipped.`))}get alphaMultiplier(){return this._alphaMultiplier}_pushFilterFrame(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new iy),this._filterStackIndex++,e}_popFilterFrame(){return this._filterStackIndex<=0?this._filterStack[0]:(this._filterStackIndex--,this._filterStack[this._filterStackIndex])}destroy(){this._filterStack=null,this._savedStates=null,this._warnedFilterTypes=null,this._alphaMultiplier=1}}Vf.extension={type:[S.CanvasSystem],name:"filter"};var jf=`in vec2 aPosition;
253
+ `}},uc={};function Sa(i){let e=uc[i];if(e)return e;const t=new Int32Array(i);for(let s=0;s<i;s++)t[s]=s;return e=uc[i]=new Ze({uTextures:{value:t,type:"i32",size:i}},{isStatic:!0}),e}class _o extends gt{constructor(e){const t=Br({name:"batch",bits:[va,Ta(e),Gr]}),s=Rr({name:"batch",bits:[ba,wa(e),Ir]});super({glProgram:t,gpuProgram:s,resources:{batchSamplers:Sa(e)}}),this.maxTextures=e}}let Ys=null;const _f=class yf extends sf{constructor(e){super(e),this.geometry=new nf,this.name=yf.extension.name,this.vertexSize=6,Ys??(Ys=new _o(e.maxTextures)),this.shader=Ys}packAttributes(e,t,s,r,n){const o=n<<16|e.roundPixels&65535,a=e.transform,l=a.a,h=a.b,c=a.c,u=a.d,d=a.tx,f=a.ty,{positions:p,uvs:g}=e,m=e.color,_=e.attributeOffset,y=_+e.attributeSize;for(let x=_;x<y;x++){const b=x*2,v=p[b],w=p[b+1];t[r++]=l*v+c*w+d,t[r++]=u*w+h*v+f,t[r++]=g[b],t[r++]=g[b+1],s[r++]=m,s[r++]=o}}packQuadAttributes(e,t,s,r,n){const o=e.texture,a=e.transform,l=a.a,h=a.b,c=a.c,u=a.d,d=a.tx,f=a.ty,p=e.bounds,g=p.maxX,m=p.minX,_=p.maxY,y=p.minY,x=o.uvs,b=e.color,v=n<<16|e.roundPixels&65535;t[r+0]=l*m+c*y+d,t[r+1]=u*y+h*m+f,t[r+2]=x.x0,t[r+3]=x.y0,s[r+4]=b,s[r+5]=v,t[r+6]=l*g+c*y+d,t[r+7]=u*y+h*g+f,t[r+8]=x.x1,t[r+9]=x.y1,s[r+10]=b,s[r+11]=v,t[r+12]=l*g+c*_+d,t[r+13]=u*_+h*g+f,t[r+14]=x.x2,t[r+15]=x.y2,s[r+16]=b,s[r+17]=v,t[r+18]=l*m+c*_+d,t[r+19]=u*_+h*m+f,t[r+20]=x.x3,t[r+21]=x.y3,s[r+22]=b,s[r+23]=v}_updateMaxTextures(e){this.shader.maxTextures!==e&&(Ys=new _o(e),this.shader=Ys)}destroy(){this.shader=null,super.destroy()}};_f.extension={type:[S.Batcher],name:"default"};let Dr=_f;class at{constructor(e){this.items=Object.create(null);const{renderer:t,type:s,onUnload:r,priority:n,name:o}=e;this._renderer=t,t.gc.addResourceHash(this,"items",s,n??0),this._onUnload=r,this.name=o}add(e){return this.items[e.uid]?!1:(this.items[e.uid]=e,e.once("unload",this.remove,this),e._gcLastUsed=this._renderer.gc.now,!0)}remove(e,...t){if(!this.items[e.uid])return;const s=e._gpuData[this._renderer.uid];s&&(this._onUnload?.(e,...t),e.off("unload",this.remove,this),s.destroy(),e._gpuData[this._renderer.uid]=null,this.items[e.uid]=null)}removeAll(...e){Object.values(this.items).forEach(t=>t&&this.remove(t,...e))}destroy(...e){this.removeAll(...e),this.items=Object.create(null),this._renderer=null,this._onUnload=null}}function xf(i,e,t,s,r,n,o,a=null){let l=0;t*=e,r*=n;const h=a.a,c=a.b,u=a.c,d=a.d,f=a.tx,p=a.ty;for(;l<o;){const g=i[t],m=i[t+1];s[r]=h*g+u*m+f,s[r+1]=c*g+d*m+p,r+=n,t+=e,l++}}function bf(i,e,t,s){let r=0;for(e*=t;r<s;)i[e]=0,i[e+1]=0,e+=t,r++}function Ca(i,e,t,s,r){const n=e.a,o=e.b,a=e.c,l=e.d,h=e.tx,c=e.ty;t||(t=0),s||(s=2),r||(r=i.length/s-t);let u=t*s;for(let d=0;d<r;d++){const f=i[u],p=i[u+1];i[u]=n*f+a*p+h,i[u+1]=o*f+l*p+c,u+=s}}const k0=new U;class Fr{constructor(){this.packAsQuad=!1,this.batcherName="default",this.topology="triangle-list",this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:"normal"}get color(){const e=this.baseColor,t=e>>16|e&65280|(e&255)<<16,s=this.renderable;return s?es(t,s.groupColor)+(this.alpha*s.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||k0}copyTo(e){e.indexOffset=this.indexOffset,e.indexSize=this.indexSize,e.attributeOffset=this.attributeOffset,e.attributeSize=this.attributeSize,e.baseColor=this.baseColor,e.alpha=this.alpha,e.texture=this.texture,e.geometryData=this.geometryData,e.topology=this.topology}reset(){this.applyTransform=!0,this.renderable=null,this.topology="triangle-list"}destroy(){this.renderable=null,this.texture=null,this.geometryData=null,this._batcher=null,this._batch=null}}const Bs={extension:{type:S.ShapeBuilder,name:"circle"},build(i,e){let t,s,r,n,o,a;if(i.type==="circle"){const b=i;if(o=a=b.radius,o<=0)return!1;t=b.x,s=b.y,r=n=0}else if(i.type==="ellipse"){const b=i;if(o=b.halfWidth,a=b.halfHeight,o<=0||a<=0)return!1;t=b.x,s=b.y,r=n=0}else{const b=i,v=b.width/2,w=b.height/2;t=b.x+v,s=b.y+w,o=a=Math.max(0,Math.min(b.radius,Math.min(v,w))),r=v-o,n=w-a}if(r<0||n<0)return!1;const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(r?4:0)+(n?4:0);if(h===0)return!1;if(l===0)return e[0]=e[6]=t+r,e[1]=e[3]=s+n,e[2]=e[4]=t-r,e[5]=e[7]=s-n,!0;let c=0,u=l*4+(r?2:0)+2,d=u,f=h,p=r+o,g=n,m=t+p,_=t-p,y=s+g;if(e[c++]=m,e[c++]=y,e[--u]=y,e[--u]=_,n){const b=s-g;e[d++]=_,e[d++]=b,e[--f]=b,e[--f]=m}for(let b=1;b<l;b++){const v=Math.PI/2*(b/l),w=r+Math.cos(v)*o,T=n+Math.sin(v)*a,k=t+w,E=t-w,A=s+T,M=s-T;e[c++]=k,e[c++]=A,e[--u]=A,e[--u]=E,e[d++]=E,e[d++]=M,e[--f]=M,e[--f]=k}p=r,g=n+a,m=t+p,_=t-p,y=s+g;const x=s-g;return e[c++]=m,e[c++]=y,e[--f]=x,e[--f]=m,r&&(e[c++]=_,e[c++]=y,e[--f]=x,e[--f]=_),!0},triangulate(i,e,t,s,r,n){if(i.length===0)return;let o=0,a=0;for(let c=0;c<i.length;c+=2)o+=i[c],a+=i[c+1];o/=i.length/2,a/=i.length/2;let l=s;e[l*t]=o,e[l*t+1]=a;const h=l++;for(let c=0;c<i.length;c+=2)e[l*t]=i[c],e[l*t+1]=i[c+1],c>0&&(r[n++]=l,r[n++]=h,r[n++]=l-1),l++;r[n++]=h+1,r[n++]=h,r[n++]=l-1}},vf={...Bs,extension:{...Bs.extension,name:"ellipse"}},wf={...Bs,extension:{...Bs.extension,name:"roundedRectangle"}},Ma=1e-4,yo=1e-4;function dc(i,e,t,s,r,n,o,a){const l=i-t*r,h=e-s*r,c=i+t*n,u=e+s*n;let d,f;o?(d=s,f=-t):(d=-s,f=t);const p=l+d,g=h+f,m=c+d,_=u+f;return a.push(p,g),a.push(m,_),2}function zt(i,e,t,s,r,n,o,a){const l=t-i,h=s-e;let c=Math.atan2(l,h),u=Math.atan2(r-i,n-e);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),g=Math.sqrt(l*l+h*h),m=(15*p*Math.sqrt(g)/Math.PI>>0)+1,_=f/m;if(d+=_,a){o.push(i,e),o.push(t,s);for(let y=1,x=d;y<m;y++,x+=_)o.push(i,e),o.push(i+Math.sin(x)*g,e+Math.cos(x)*g);o.push(i,e),o.push(r,n)}else{o.push(t,s),o.push(i,e);for(let y=1,x=d;y<m;y++,x+=_)o.push(i+Math.sin(x)*g,e+Math.cos(x)*g),o.push(i,e);o.push(r,n),o.push(i,e)}return m*2}function Or(i,e,t,s,r,n){const o=Ma;if(i.length===0)return;const a=e;let l=a.alignment;if(e.alignment!==.5){let R=_a(i);l=(l-.5)*R+.5}const h=new ce(i[0],i[1]),c=new ce(i[i.length-2],i[i.length-1]),u=s,d=Math.abs(h.x-c.x)<o&&Math.abs(h.y-c.y)<o;if(u){i=i.slice(),d&&(i.pop(),i.pop(),c.set(i[i.length-2],i[i.length-1]));const R=(h.x+c.x)*.5,L=(c.y+h.y)*.5;i.unshift(R,L),i.push(R,L)}const f=r,p=i.length/2;let g=i.length;const m=f.length/2,_=a.width/2,y=_*_,x=a.miterLimit*a.miterLimit;let b=i[0],v=i[1],w=i[2],T=i[3],k=0,E=0,A=-(v-T),M=b-w,B=0,G=0,O=Math.sqrt(A*A+M*M);A/=O,M/=O,A*=_,M*=_;const I=l,P=(1-I)*2,C=I*2;u||(a.cap==="round"?g+=zt(b-A*(P-C)*.5,v-M*(P-C)*.5,b-A*P,v-M*P,b+A*C,v+M*C,f,!0)+2:a.cap==="square"&&(g+=dc(b,v,A,M,P,C,!0,f))),f.push(b-A*P,v-M*P),f.push(b+A*C,v+M*C);for(let R=1;R<p-1;++R){b=i[(R-1)*2],v=i[(R-1)*2+1],w=i[R*2],T=i[R*2+1],k=i[(R+1)*2],E=i[(R+1)*2+1],A=-(v-T),M=b-w,O=Math.sqrt(A*A+M*M),A/=O,M/=O,A*=_,M*=_,B=-(T-E),G=w-k,O=Math.sqrt(B*B+G*G),B/=O,G/=O,B*=_,G*=_;const L=w-b,N=v-T,se=w-k,Q=E-T,re=L*se+N*Q,j=N*se-Q*L,Qe=j<0;if(Math.abs(j)<.001*Math.abs(re)){f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),re>=0&&(a.join==="round"?g+=zt(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+4:g+=2,f.push(w-B*C,T-G*C),f.push(w+B*P,T+G*P));continue}const ki=(-A+b)*(-M+T)-(-A+w)*(-M+v),Us=(-B+k)*(-G+T)-(-B+w)*(-G+E),Ns=(L*Us-se*ki)/j,yt=(Q*ki-N*Us)/j,Ut=(Ns-w)*(Ns-w)+(yt-T)*(yt-T),Je=w+(Ns-w)*P,Oe=T+(yt-T)*P,Le=w-(Ns-w)*C,et=T-(yt-T)*C,It=Math.min(L*L+N*N,se*se+Q*Q),xt=Qe?P:C,zs=It+xt*xt*y;Ut<=zs?a.join==="bevel"||Ut/y>x?(Qe?(f.push(Je,Oe),f.push(w+A*C,T+M*C),f.push(Je,Oe),f.push(w+B*C,T+G*C)):(f.push(w-A*P,T-M*P),f.push(Le,et),f.push(w-B*P,T-G*P),f.push(Le,et)),g+=2):a.join==="round"?Qe?(f.push(Je,Oe),f.push(w+A*C,T+M*C),g+=zt(w,T,w+A*C,T+M*C,w+B*C,T+G*C,f,!0)+4,f.push(Je,Oe),f.push(w+B*C,T+G*C)):(f.push(w-A*P,T-M*P),f.push(Le,et),g+=zt(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+4,f.push(w-B*P,T-G*P),f.push(Le,et)):(f.push(Je,Oe),f.push(Le,et)):(f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),a.join==="round"?Qe?g+=zt(w,T,w+A*C,T+M*C,w+B*C,T+G*C,f,!0)+2:g+=zt(w,T,w-A*P,T-M*P,w-B*P,T-G*P,f,!1)+2:a.join==="miter"&&Ut/y<=x&&(Qe?(f.push(Le,et),f.push(Le,et)):(f.push(Je,Oe),f.push(Je,Oe)),g+=2),f.push(w-B*P,T-G*P),f.push(w+B*C,T+G*C),g+=2)}b=i[(p-2)*2],v=i[(p-2)*2+1],w=i[(p-1)*2],T=i[(p-1)*2+1],A=-(v-T),M=b-w,O=Math.sqrt(A*A+M*M),A/=O,M/=O,A*=_,M*=_,f.push(w-A*P,T-M*P),f.push(w+A*C,T+M*C),u||(a.cap==="round"?g+=zt(w-A*(P-C)*.5,T-M*(P-C)*.5,w-A*P,T-M*P,w+A*C,T+M*C,f,!1)+2:a.cap==="square"&&(g+=dc(w,T,A,M,P,C,!1,f)));const D=yo*yo;for(let R=m;R<g+m-2;++R)b=f[R*2],v=f[R*2+1],w=f[(R+1)*2],T=f[(R+1)*2+1],k=f[(R+2)*2],E=f[(R+2)*2+1],!(Math.abs(b*(T-E)+w*(E-v)+k*(v-T))<D)&&n.push(R,R+1,R+2)}function Tf(i,e,t,s){const r=Ma;if(i.length===0)return;const n=i[0],o=i[1],a=i[i.length-2],l=i[i.length-1],h=e||Math.abs(n-a)<r&&Math.abs(o-l)<r,c=t,u=i.length/2,d=c.length/2;for(let f=0;f<u;f++)c.push(i[f*2]),c.push(i[f*2+1]);for(let f=0;f<u-1;f++)s.push(d+f,d+f+1);h&&s.push(d+u-1,d)}function ka(i,e,t,s,r,n,o){const a=Nd(i,e,2);if(!a)return;for(let h=0;h<a.length;h+=3)n[o++]=a[h]+r,n[o++]=a[h+1]+r,n[o++]=a[h+2]+r;let l=r*s;for(let h=0;h<i.length;h+=2)t[l]=i[h],t[l+1]=i[h+1],l+=s}const E0=[],Sf={extension:{type:S.ShapeBuilder,name:"polygon"},build(i,e){for(let t=0;t<i.points.length;t++)e[t]=i.points[t];return!0},triangulate(i,e,t,s,r,n){ka(i,E0,e,t,s,r,n)}},Cf={extension:{type:S.ShapeBuilder,name:"rectangle"},build(i,e){const t=i,s=t.x,r=t.y,n=t.width,o=t.height;return n>0&&o>0?(e[0]=s,e[1]=r,e[2]=s+n,e[3]=r,e[4]=s+n,e[5]=r+o,e[6]=s,e[7]=r+o,!0):!1},triangulate(i,e,t,s,r,n){let o=0;s*=t,e[s+o]=i[0],e[s+o+1]=i[1],o+=t,e[s+o]=i[2],e[s+o+1]=i[3],o+=t,e[s+o]=i[6],e[s+o+1]=i[7],o+=t,e[s+o]=i[4],e[s+o+1]=i[5],o+=t;const a=s/t;r[n++]=a,r[n++]=a+1,r[n++]=a+2,r[n++]=a+1,r[n++]=a+3,r[n++]=a+2}},Mf={extension:{type:S.ShapeBuilder,name:"triangle"},build(i,e){return e[0]=i.x,e[1]=i.y,e[2]=i.x2,e[3]=i.y2,e[4]=i.x3,e[5]=i.y3,!0},triangulate(i,e,t,s,r,n){let o=0;s*=t,e[s+o]=i[0],e[s+o+1]=i[1],o+=t,e[s+o]=i[2],e[s+o+1]=i[3],o+=t,e[s+o]=i[4],e[s+o+1]=i[5];const a=s/t;r[n++]=a,r[n++]=a+1,r[n++]=a+2}},fc=[{offset:0,color:"white"},{offset:1,color:"black"}],Ea=class xo{constructor(...e){this.uid=oe("fillGradient"),this._tick=0,this.type="linear",this.colorStops=[];let t=P0(e);t={...t.type==="radial"?xo.defaultRadialOptions:xo.defaultLinearOptions,...Vo(t)},this._textureSize=t.textureSize,this._wrapMode=t.wrapMode,t.type==="radial"?(this.center=t.center,this.outerCenter=t.outerCenter??this.center,this.innerRadius=t.innerRadius,this.outerRadius=t.outerRadius,this.scale=t.scale,this.rotation=t.rotation):(this.start=t.start,this.end=t.end),this.textureSpace=t.textureSpace,this.type=t.type,t.colorStops.forEach(r=>{this.addColorStop(r.offset,r.color)})}addColorStop(e,t){return this.colorStops.push({offset:e,color:le.shared.setValue(t).toHexa()}),this}buildLinearGradient(){if(this.texture)return;let{x:e,y:t}=this.start,{x:s,y:r}=this.end,n=s-e,o=r-t;const a=n<0||o<0;if(this._wrapMode==="clamp-to-edge"){if(n<0){const m=e;e=s,s=m,n*=-1}if(o<0){const m=t;t=r,r=m,o*=-1}}const l=this.colorStops.length?this.colorStops:fc,h=this._textureSize,{canvas:c,context:u}=mc(h,1),d=a?u.createLinearGradient(this._textureSize,0,0,0):u.createLinearGradient(0,0,this._textureSize,0);pc(d,l),u.fillStyle=d,u.fillRect(0,0,h,1),this.texture=new W({source:new fi({resource:c,addressMode:this._wrapMode})});const f=Math.sqrt(n*n+o*o),p=Math.atan2(o,n),g=new U;g.scale(f/h,1),g.rotate(p),g.translate(e,t),this.textureSpace==="local"&&g.scale(h,h),this.transform=g}buildGradient(){this.texture||this._tick++,this.type==="linear"?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;const e=this.colorStops.length?this.colorStops:fc,t=this._textureSize,{canvas:s,context:r}=mc(t,t),{x:n,y:o}=this.center,{x:a,y:l}=this.outerCenter,h=this.innerRadius,c=this.outerRadius,u=a-c,d=l-c,f=t/(c*2),p=(n-u)*f,g=(o-d)*f,m=r.createRadialGradient(p,g,h*f,(a-u)*f,(l-d)*f,c*f);pc(m,e),r.fillStyle=e[e.length-1].color,r.fillRect(0,0,t,t),r.fillStyle=m,r.translate(p,g),r.rotate(this.rotation),r.scale(1,this.scale),r.translate(-p,-g),r.fillRect(0,0,t,t),this.texture=new W({source:new fi({resource:s,addressMode:this._wrapMode})});const _=new U;this.textureSpace==="local"?_.scale(2*c,2*c):_.scale(1/f,1/f),_.translate(u,d),this.transform=_}destroy(){this.texture?.destroy(!0),this.texture=null,this.transform=null,this.colorStops=[],this.start=null,this.end=null,this.center=null,this.outerCenter=null}get styleKey(){return`fill-gradient-${this.uid}-${this._tick}`}};Ea.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:"local",type:"linear",textureSize:256,wrapMode:"clamp-to-edge"};Ea.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,rotation:0,textureSpace:"local",type:"radial",textureSize:256,wrapMode:"clamp-to-edge"};let je=Ea;function pc(i,e){for(let t=0;t<e.length;t++){const s=e[t];i.addColorStop(s.offset,s.color)}}function mc(i,e){const t=ee.get().createCanvas(i,e),s=t.getContext("2d");return{canvas:t,context:s}}function P0(i){let e=i[0]??{};return(typeof e=="number"||i[1])&&(z("8.5.2","use options object instead"),e={type:"linear",start:{x:i[0],y:i[1]},end:{x:i[2],y:i[3]},textureSpace:i[4],textureSize:i[5]??je.defaultLinearOptions.textureSize}),e}const A0=new U,R0=new te,B0=new U;function Pa(i,e,t,s){const r=e.matrix?i.copyFrom(e.matrix).invert():i.identity();if(e.textureSpace==="local"){const o=t.getBounds(R0);e.width&&o.pad(e.width);const{x:a,y:l}=o,h=1/o.width,c=1/o.height,u=-a*h,d=-l*c,f=r.a,p=r.b,g=r.c,m=r.d;r.a*=h,r.b*=h,r.c*=c,r.d*=c,r.tx=u*f+d*g+r.tx,r.ty=u*p+d*m+r.ty}else if(e.texture.rotate){const{uvs:o,orig:a}=e.texture;r.scale(1/a.width,1/a.height),r.prepend(B0.set(o.x1-o.x0,o.y1-o.y0,o.x3-o.x0,o.y3-o.y0,o.x0,o.y0))}else r.translate(e.texture.frame.x,e.texture.frame.y),r.scale(1/e.texture.source.width,1/e.texture.source.height);const n=e.texture.source.style;return!(e.fill instanceof je)&&n.addressMode==="clamp-to-edge"&&(n.addressMode="repeat",n.update()),s&&r.append(A0.copyFrom(s).invert()),r}const fs={};q.handleByMap(S.ShapeBuilder,fs);q.add(Cf,Sf,Mf,Bs,vf,wf);const I0=new te,G0=new U;function kf(i,e){const{geometryData:t,batches:s}=e;s.length=0,t.indices.length=0,t.vertices.length=0,t.uvs.length=0;for(let r=0;r<i.instructions.length;r++){const n=i.instructions[r];if(n.action==="texture")D0(n.data,s,t);else if(n.action==="fill"||n.action==="stroke"){const o=n.action==="stroke",a=n.data.path.shapePath,l=n.data.style,h=n.data.hole;o&&h&&gc(h.shapePath,l,!0,s,t),h&&(a.shapePrimitives[a.shapePrimitives.length-1].holes=h.shapePath.shapePrimitives),gc(a,l,o,s,t)}}}function D0(i,e,t){const s=[],r=fs.rectangle,n=I0;n.x=i.dx,n.y=i.dy,n.width=i.dw,n.height=i.dh;const o=i.transform;if(!r.build(n,s))return;const{vertices:a,uvs:l,indices:h}=t,c=h.length,u=a.length/2;o&&Ca(s,o),r.triangulate(s,a,2,u,h,c);const d=i.image,f=d.uvs;l.push(f.x0,f.y0,f.x1,f.y1,f.x3,f.y3,f.x2,f.y2);const p=Se.get(Fr);p.indexOffset=c,p.indexSize=h.length-c,p.attributeOffset=u,p.attributeSize=a.length/2-u,p.baseColor=i.style,p.alpha=i.alpha,p.texture=d,p.geometryData=t,e.push(p)}function gc(i,e,t,s,r){const{vertices:n,uvs:o,indices:a}=r;i.shapePrimitives.forEach(({shape:l,transform:h,holes:c})=>{const u=[],d=fs[l.type];if(!d.build(l,u))return;const f=a.length,p=n.length/2;let g="triangle-list";if(h&&Ca(u,h),t){const x=l.closePath??!0,b=e;b.pixelLine?(Tf(u,x,n,a),g="line-list"):Or(u,b,!1,x,n,a)}else if(c){const x=[],b=u.slice();F0(c).forEach(w=>{x.push(b.length/2),b.push(...w)}),ka(b,x,n,2,p,a,f)}else d.triangulate(u,n,2,p,a,f);const m=o.length/2,_=e.texture;if(_!==W.WHITE){const x=Pa(G0,e,l,h);xf(n,2,p,o,m,2,n.length/2-p,x)}else bf(o,m,2,n.length/2-p);const y=Se.get(Fr);y.indexOffset=f,y.indexSize=a.length-f,y.attributeOffset=p,y.attributeSize=n.length/2-p,y.baseColor=e.color,y.alpha=e.alpha,y.texture=_,y.geometryData=r,y.topology=g,s.push(y)})}function F0(i){const e=[];for(let t=0;t<i.length;t++){const s=i[t].shape,r=[];fs[s.type].build(s,r)&&e.push(r)}return e}class Ef{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}reset(){this.batches&&this.batches.forEach(e=>{Se.return(e)}),this.graphicsData&&Se.return(this.graphicsData),this.isBatchable=!1,this.context=null,this.batches.length=0,this.geometryData.indices.length=0,this.geometryData.vertices.length=0,this.geometryData.uvs.length=0,this.graphicsData=null}destroy(){this.reset(),this.batches=null,this.geometryData=null}}class Pf{constructor(){this.instructions=new Tr}init(e){const t=e.maxTextures;this.batcher?this.batcher._updateMaxTextures(t):this.batcher=new Dr({maxTextures:t}),this.instructions.reset()}get geometry(){return z(Mu,"GraphicsContextRenderData#geometry is deprecated, please use batcher.geometry instead."),this.batcher.geometry}destroy(){this.batcher.destroy(),this.instructions.destroy(),this.batcher=null,this.instructions=null}}const Aa=class bo{constructor(e){this._renderer=e,this._managedContexts=new at({renderer:e,type:"resource",name:"graphicsContext"})}init(e){bo.defaultOptions.bezierSmoothness=e?.bezierSmoothness??bo.defaultOptions.bezierSmoothness}getContextRenderData(e){return e._gpuData[this._renderer.uid].graphicsData||this._initContextRenderData(e)}updateGpuContext(e){const t=!!e._gpuData[this._renderer.uid],s=e._gpuData[this._renderer.uid]||this._initContext(e);if(e.dirty||!t){t&&s.reset(),kf(e,s);const r=e.batchMode;e.customShader||r==="no-batch"?s.isBatchable=!1:r==="auto"?s.isBatchable=s.geometryData.vertices.length<400:s.isBatchable=!0,e.dirty=!1}return s}getGpuContext(e){return e._gpuData[this._renderer.uid]||this._initContext(e)}_initContextRenderData(e){const t=Se.get(Pf,{maxTextures:this._renderer.limits.maxBatchableTextures}),s=e._gpuData[this._renderer.uid],{batches:r,geometryData:n}=s;s.graphicsData=t;const o=n.vertices.length,a=n.indices.length;for(let u=0;u<r.length;u++)r[u].applyTransform=!1;const l=t.batcher;l.ensureAttributeBuffer(o),l.ensureIndexBuffer(a),l.begin();for(let u=0;u<r.length;u++){const d=r[u];l.add(d)}l.finish(t.instructions);const h=l.geometry;h.indexBuffer.setDataWithSize(l.indexBuffer,l.indexSize,!0),h.buffers[0].setDataWithSize(l.attributeBuffer.float32View,l.attributeSize,!0);const c=l.batches;for(let u=0;u<l.batchIndex;u++){const d=c[u];d.bindGroup=Ar(d.textures.textures,d.textures.count,this._renderer.limits.maxBatchableTextures)}return t}_initContext(e){const t=new Ef;return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};Aa.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"graphicsContext"};Aa.defaultOptions={bezierSmoothness:.5};let Lr=Aa;const O0=8,Hi=11920929e-14,L0=1;function Ra(i,e,t,s,r,n,o,a,l,h){const u=Math.min(.99,Math.max(0,h??Lr.defaultOptions.bezierSmoothness));let d=(L0-u)/1;return d*=d,U0(e,t,s,r,n,o,a,l,i,d),i}function U0(i,e,t,s,r,n,o,a,l,h){vo(i,e,t,s,r,n,o,a,l,h,0),l.push(o,a)}function vo(i,e,t,s,r,n,o,a,l,h,c){if(c>O0)return;const u=(i+t)/2,d=(e+s)/2,f=(t+r)/2,p=(s+n)/2,g=(r+o)/2,m=(n+a)/2,_=(u+f)/2,y=(d+p)/2,x=(f+g)/2,b=(p+m)/2,v=(_+x)/2,w=(y+b)/2;if(c>0){let T=o-i,k=a-e;const E=Math.abs((t-o)*k-(s-a)*T),A=Math.abs((r-o)*k-(n-a)*T);if(E>Hi&&A>Hi){if((E+A)*(E+A)<=h*(T*T+k*k)){l.push(v,w);return}}else if(E>Hi){if(E*E<=h*(T*T+k*k)){l.push(v,w);return}}else if(A>Hi){if(A*A<=h*(T*T+k*k)){l.push(v,w);return}}else if(T=v-(i+o)/2,k=w-(e+a)/2,T*T+k*k<=h){l.push(v,w);return}}vo(i,e,u,d,_,y,v,w,l,h,c+1),vo(v,w,x,b,g,m,o,a,l,h,c+1)}const N0=8,z0=11920929e-14,H0=1;function Af(i,e,t,s,r,n,o,a){const h=Math.min(.99,Math.max(0,a??Lr.defaultOptions.bezierSmoothness));let c=(H0-h)/1;return c*=c,W0(e,t,s,r,n,o,i,c),i}function W0(i,e,t,s,r,n,o,a){wo(o,i,e,t,s,r,n,a,0),o.push(r,n)}function wo(i,e,t,s,r,n,o,a,l){if(l>N0)return;const h=(e+s)/2,c=(t+r)/2,u=(s+n)/2,d=(r+o)/2,f=(h+u)/2,p=(c+d)/2;let g=n-e,m=o-t;const _=Math.abs((s-n)*m-(r-o)*g);if(_>z0){if(_*_<=a*(g*g+m*m)){i.push(f,p);return}}else if(g=f-(e+n)/2,m=p-(t+o)/2,g*g+m*m<=a){i.push(f,p);return}wo(i,e,t,h,c,f,p,a,l+1),wo(i,f,p,u,d,n,o,a,l+1)}function Ba(i,e,t,s,r,n,o,a){let l=Math.abs(r-n);(!o&&r>n||o&&n>r)&&(l=2*Math.PI-l),a||(a=Math.max(6,Math.floor(6*Math.pow(s,1/3)*(l/Math.PI)))),a=Math.max(a,3);let h=l/a,c=r;h*=o?-1:1;for(let u=0;u<a+1;u++){const d=Math.cos(c),f=Math.sin(c),p=e+d*s,g=t+f*s;i.push(p,g),c+=h}}function Rf(i,e,t,s,r,n){const o=i[i.length-2],l=i[i.length-1]-t,h=o-e,c=r-t,u=s-e,d=Math.abs(l*u-h*c);if(d<1e-8||n===0){(i[i.length-2]!==e||i[i.length-1]!==t)&&i.push(e,t);return}const f=l*l+h*h,p=c*c+u*u,g=l*c+h*u,m=n*Math.sqrt(f)/d,_=n*Math.sqrt(p)/d,y=m*g/f,x=_*g/p,b=m*u+_*h,v=m*c+_*l,w=h*(_+y),T=l*(_+y),k=u*(m+x),E=c*(m+x),A=Math.atan2(T-v,w-b),M=Math.atan2(E-v,k-b);Ba(i,b+e,v+t,n,A,M,h*c>u*l)}const ri=Math.PI*2,Rn={centerX:0,centerY:0,ang1:0,ang2:0},Bn=({x:i,y:e},t,s,r,n,o,a,l)=>{i*=t,e*=s;const h=r*i-n*e,c=n*i+r*e;return l.x=h+o,l.y=c+a,l};function $0(i,e){const t=e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),s=e===1.5707963267948966?.551915024494:t,r=Math.cos(i),n=Math.sin(i),o=Math.cos(i+e),a=Math.sin(i+e);return[{x:r-n*s,y:n+r*s},{x:o+a*s,y:a-o*s},{x:o,y:a}]}const _c=(i,e,t,s)=>{const r=i*s-e*t<0?-1:1;let n=i*t+e*s;return n>1&&(n=1),n<-1&&(n=-1),r*Math.acos(n)},V0=(i,e,t,s,r,n,o,a,l,h,c,u,d)=>{const f=Math.pow(r,2),p=Math.pow(n,2),g=Math.pow(c,2),m=Math.pow(u,2);let _=f*p-f*m-p*g;_<0&&(_=0),_/=f*m+p*g,_=Math.sqrt(_)*(o===a?-1:1);const y=_*r/n*u,x=_*-n/r*c,b=h*y-l*x+(i+t)/2,v=l*y+h*x+(e+s)/2,w=(c-y)/r,T=(u-x)/n,k=(-c-y)/r,E=(-u-x)/n,A=_c(1,0,w,T);let M=_c(w,T,k,E);a===0&&M>0&&(M-=ri),a===1&&M<0&&(M+=ri),d.centerX=b,d.centerY=v,d.ang1=A,d.ang2=M};function Bf(i,e,t,s,r,n,o,a=0,l=0,h=0){if(n===0||o===0)return;const c=Math.sin(a*ri/360),u=Math.cos(a*ri/360),d=u*(e-s)/2+c*(t-r)/2,f=-c*(e-s)/2+u*(t-r)/2;if(d===0&&f===0)return;n=Math.abs(n),o=Math.abs(o);const p=Math.pow(d,2)/Math.pow(n,2)+Math.pow(f,2)/Math.pow(o,2);p>1&&(n*=Math.sqrt(p),o*=Math.sqrt(p)),V0(e,t,s,r,n,o,l,h,c,u,d,f,Rn);let{ang1:g,ang2:m}=Rn;const{centerX:_,centerY:y}=Rn;let x=Math.abs(m)/(ri/4);Math.abs(1-x)<1e-7&&(x=1);const b=Math.max(Math.ceil(x),1);m/=b;let v=i[i.length-2],w=i[i.length-1];const T={x:0,y:0};for(let k=0;k<b;k++){const E=$0(g,m),{x:A,y:M}=Bn(E[0],n,o,u,c,_,y,T),{x:B,y:G}=Bn(E[1],n,o,u,c,_,y,T),{x:O,y:I}=Bn(E[2],n,o,u,c,_,y,T);Ra(i,v,w,A,M,B,G,O,I),v=O,w=I,g+=m}}function If(i,e,t){const s=(o,a)=>{const l=a.x-o.x,h=a.y-o.y,c=Math.sqrt(l*l+h*h),u=l/c,d=h/c;return{len:c,nx:u,ny:d}},r=(o,a)=>{o===0?i.moveTo(a.x,a.y):i.lineTo(a.x,a.y)};let n=e[e.length-1];for(let o=0;o<e.length;o++){const a=e[o%e.length],l=a.radius??t;if(l<=0){r(o,a),n=a;continue}const h=e[(o+1)%e.length],c=s(a,n),u=s(a,h);if(c.len<1e-4||u.len<1e-4){r(o,a),n=a;continue}let d=Math.asin(c.nx*u.ny-c.ny*u.nx),f=1,p=!1;c.nx*u.nx-c.ny*-u.ny<0?d<0?d=Math.PI+d:(d=Math.PI-d,f=-1,p=!0):d>0&&(f=-1,p=!0);const g=d/2;let m,_=Math.abs(Math.cos(g)*l/Math.sin(g));_>Math.min(c.len/2,u.len/2)?(_=Math.min(c.len/2,u.len/2),m=Math.abs(_*Math.sin(g)/Math.cos(g))):m=l;const y=a.x+u.nx*_+-u.ny*m*f,x=a.y+u.ny*_+u.nx*m*f,b=Math.atan2(c.ny,c.nx)+Math.PI/2*f,v=Math.atan2(u.ny,u.nx)-Math.PI/2*f;o===0&&i.moveTo(y+Math.cos(b)*m,x+Math.sin(b)*m),i.arc(y,x,m,b,v,p),n=a}}function Gf(i,e,t,s){const r=(a,l)=>Math.sqrt((a.x-l.x)**2+(a.y-l.y)**2),n=(a,l,h)=>({x:a.x+(l.x-a.x)*h,y:a.y+(l.y-a.y)*h}),o=e.length;for(let a=0;a<o;a++){const l=e[(a+1)%o],h=l.radius??t;if(h<=0){a===0?i.moveTo(l.x,l.y):i.lineTo(l.x,l.y);continue}const c=e[a],u=e[(a+2)%o],d=r(c,l);let f;if(d<1e-4)f=l;else{const m=Math.min(d/2,h);f=n(l,c,m/d)}const p=r(u,l);let g;if(p<1e-4)g=l;else{const m=Math.min(p/2,h);g=n(l,u,m/p)}a===0?i.moveTo(f.x,f.y):i.lineTo(f.x,f.y),i.quadraticCurveTo(l.x,l.y,g.x,g.y,s)}}const j0=new te;class Df{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new Ee,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();const s=this._currentPoly.points,r=s[s.length-2],n=s[s.length-1];return(r!==e||n!==t)&&s.push(e,t),this}arc(e,t,s,r,n,o){this._ensurePoly(!1);const a=this._currentPoly.points;return Ba(a,e,t,s,r,n,o),this}arcTo(e,t,s,r,n){this._ensurePoly();const o=this._currentPoly.points;return Rf(o,e,t,s,r,n),this}arcToSvg(e,t,s,r,n,o,a){const l=this._currentPoly.points;return Bf(l,this._currentPoly.lastX,this._currentPoly.lastY,o,a,e,t,s,r,n),this}bezierCurveTo(e,t,s,r,n,o,a){this._ensurePoly();const l=this._currentPoly;return Ra(this._currentPoly.points,l.lastX,l.lastY,e,t,s,r,n,o,a),this}quadraticCurveTo(e,t,s,r,n){this._ensurePoly();const o=this._currentPoly;return Af(this._currentPoly.points,o.lastX,o.lastY,e,t,s,r,n),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));const s=this.shapePrimitives,r=s.length;for(let n=0;n<e.instructions.length;n++){const o=e.instructions[n];this[o.action](...o.data)}if(e.checkForHoles&&s.length-r>1){let n=null;for(let o=r;o<s.length;o++){const a=s[o];if(a.shape.type==="polygon"){const l=a.shape,h=n?.shape;h&&h.containsPolygon(l)?(n.holes||(n.holes=[]),n.holes.push(a),s.copyWithin(o,o+1),s.length--,o--):n=a}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,s,r,n){return this.drawShape(new te(e,t,s,r),n),this}circle(e,t,s,r){return this.drawShape(new kr(e,t,s),r),this}poly(e,t,s){const r=new ks(e);return r.closePath=t,this.drawShape(r,s),this}regularPoly(e,t,s,r,n=0,o){r=Math.max(r|0,3);const a=-1*Math.PI/2+n,l=Math.PI*2/r,h=[];for(let c=0;c<r;c++){const u=a-c*l;h.push(e+s*Math.cos(u),t+s*Math.sin(u))}return this.poly(h,!0,o),this}roundPoly(e,t,s,r,n,o=0,a){if(r=Math.max(r|0,3),n<=0)return this.regularPoly(e,t,s,r,o);const l=s*Math.sin(Math.PI/r)-.001;n=Math.min(n,l);const h=-1*Math.PI/2+o,c=Math.PI*2/r,u=(r-2)*Math.PI/r/2;for(let d=0;d<r;d++){const f=d*c+h,p=e+s*Math.cos(f),g=t+s*Math.sin(f),m=f+Math.PI+u,_=f-Math.PI-u,y=p+n*Math.cos(m),x=g+n*Math.sin(m),b=p+n*Math.cos(_),v=g+n*Math.sin(_);d===0?this.moveTo(y,x):this.lineTo(y,x),this.quadraticCurveTo(p,g,b,v,a)}return this.closePath()}roundShape(e,t,s=!1,r){return e.length<3?this:(s?Gf(this,e,t,r):If(this,e,t),this.closePath())}filletRect(e,t,s,r,n){if(n===0)return this.rect(e,t,s,r);const o=Math.min(s,r)/2,a=Math.min(o,Math.max(-o,n)),l=e+s,h=t+r,c=a<0?-a:0,u=Math.abs(a);return this.moveTo(e,t+u).arcTo(e+c,t+c,e+u,t,u).lineTo(l-u,t).arcTo(l-c,t+c,l,t+u,u).lineTo(l,h-u).arcTo(l-c,h-c,e+s-u,h,u).lineTo(e+u,h).arcTo(e+c,h-c,e,h-u,u).closePath()}chamferRect(e,t,s,r,n,o){if(n<=0)return this.rect(e,t,s,r);const a=Math.min(n,Math.min(s,r)/2),l=e+s,h=t+r,c=[e+a,t,l-a,t,l,t+a,l,h-a,l-a,h,e+a,h,e,h-a,e,t+a];for(let u=c.length-1;u>=2;u-=2)c[u]===c[u-2]&&c[u-1]===c[u-3]&&c.splice(u-1,2);return this.poly(c,!0,o)}ellipse(e,t,s,r,n){return this.drawShape(new Er(e,t,s,r),n),this}roundRect(e,t,s,r,n,o){return this.drawShape(new Pr(e,t,s,r,n),o),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let s=this._currentPoly;return s&&this.endPoly(),s=new ks,s.points.push(e,t),this._currentPoly=s,this}endPoly(e=!1){const t=this._currentPoly;return t&&t.points.length>2&&(t.closePath=e,this.shapePrimitives.push({shape:t})),this._currentPoly=null,this}_ensurePoly(e=!0){if(!this._currentPoly&&(this._currentPoly=new ks,e)){const t=this.shapePrimitives[this.shapePrimitives.length-1];if(t){let s=t.shape.x,r=t.shape.y;if(t.transform&&!t.transform.isIdentity()){const n=t.transform,o=s;s=n.a*s+n.c*r+n.tx,r=n.b*o+n.d*r+n.ty}this._currentPoly.points.push(s,r)}else this._currentPoly.points.push(0,0)}}buildPath(){const e=this._graphicsPath2D;this.shapePrimitives.length=0,this._currentPoly=null;for(let t=0;t<e.instructions.length;t++){const s=e.instructions[t];this[s.action](...s.data)}this.finish()}get bounds(){const e=this._bounds;e.clear();const t=this.shapePrimitives;for(let s=0;s<t.length;s++){const r=t[s],n=r.shape.getBounds(j0);r.transform?e.addRect(n,r.transform):e.addRect(n)}return e}}class pt{constructor(e,t=!1){this.instructions=[],this.uid=oe("graphicsPath"),this._dirty=!0,this.checkForHoles=t,typeof e=="string"?Xd(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||(this._shapePath=new Df(this)),this._dirty&&(this._dirty=!1,this._shapePath.buildPath()),this._shapePath}addPath(e,t){return e=e.clone(),this.instructions.push({action:"addPath",data:[e,t]}),this._dirty=!0,this}arc(...e){return this.instructions.push({action:"arc",data:e}),this._dirty=!0,this}arcTo(...e){return this.instructions.push({action:"arcTo",data:e}),this._dirty=!0,this}arcToSvg(...e){return this.instructions.push({action:"arcToSvg",data:e}),this._dirty=!0,this}bezierCurveTo(...e){return this.instructions.push({action:"bezierCurveTo",data:e}),this._dirty=!0,this}bezierCurveToShort(e,t,s,r,n){const o=this.instructions[this.instructions.length-1],a=this.getLastPoint(ce.shared);let l=0,h=0;if(!o||o.action!=="bezierCurveTo")l=a.x,h=a.y;else{l=o.data[2],h=o.data[3];const c=a.x,u=a.y;l=c+(c-l),h=u+(u-h)}return this.instructions.push({action:"bezierCurveTo",data:[l,h,e,t,s,r,n]}),this._dirty=!0,this}closePath(){return this.instructions.push({action:"closePath",data:[]}),this._dirty=!0,this}ellipse(...e){return this.instructions.push({action:"ellipse",data:e}),this._dirty=!0,this}lineTo(...e){return this.instructions.push({action:"lineTo",data:e}),this._dirty=!0,this}moveTo(...e){return this.instructions.push({action:"moveTo",data:e}),this}quadraticCurveTo(...e){return this.instructions.push({action:"quadraticCurveTo",data:e}),this._dirty=!0,this}quadraticCurveToShort(e,t,s){const r=this.instructions[this.instructions.length-1],n=this.getLastPoint(ce.shared);let o=0,a=0;if(!r||r.action!=="quadraticCurveTo")o=n.x,a=n.y;else{o=r.data[0],a=r.data[1];const l=n.x,h=n.y;o=l+(l-o),a=h+(h-a)}return this.instructions.push({action:"quadraticCurveTo",data:[o,a,e,t,s]}),this._dirty=!0,this}rect(e,t,s,r,n){return this.instructions.push({action:"rect",data:[e,t,s,r,n]}),this._dirty=!0,this}circle(e,t,s,r){return this.instructions.push({action:"circle",data:[e,t,s,r]}),this._dirty=!0,this}roundRect(...e){return this.instructions.push({action:"roundRect",data:e}),this._dirty=!0,this}poly(...e){return this.instructions.push({action:"poly",data:e}),this._dirty=!0,this}regularPoly(...e){return this.instructions.push({action:"regularPoly",data:e}),this._dirty=!0,this}roundPoly(...e){return this.instructions.push({action:"roundPoly",data:e}),this._dirty=!0,this}roundShape(...e){return this.instructions.push({action:"roundShape",data:e}),this._dirty=!0,this}filletRect(...e){return this.instructions.push({action:"filletRect",data:e}),this._dirty=!0,this}chamferRect(...e){return this.instructions.push({action:"chamferRect",data:e}),this._dirty=!0,this}star(e,t,s,r,n,o,a){n||(n=r/2);const l=-1*Math.PI/2+o,h=s*2,c=Math.PI*2/h,u=[];for(let d=0;d<h;d++){const f=d%2?n:r,p=d*c+l;u.push(e+f*Math.cos(p),t+f*Math.sin(p))}return this.poly(u,!0,a),this}clone(e=!1){const t=new pt;if(t.checkForHoles=this.checkForHoles,!e)t.instructions=this.instructions.slice();else for(let s=0;s<this.instructions.length;s++){const r=this.instructions[s];t.instructions.push({action:r.action,data:r.data.slice()})}return t}clear(){return this.instructions.length=0,this._dirty=!0,this}transform(e){if(e.isIdentity())return this;const t=e.a,s=e.b,r=e.c,n=e.d,o=e.tx,a=e.ty;let l=0,h=0,c=0,u=0,d=0,f=0,p=0,g=0;for(let m=0;m<this.instructions.length;m++){const _=this.instructions[m],y=_.data;switch(_.action){case"moveTo":case"lineTo":l=y[0],h=y[1],y[0]=t*l+r*h+o,y[1]=s*l+n*h+a;break;case"bezierCurveTo":c=y[0],u=y[1],d=y[2],f=y[3],l=y[4],h=y[5],y[0]=t*c+r*u+o,y[1]=s*c+n*u+a,y[2]=t*d+r*f+o,y[3]=s*d+n*f+a,y[4]=t*l+r*h+o,y[5]=s*l+n*h+a;break;case"quadraticCurveTo":c=y[0],u=y[1],l=y[2],h=y[3],y[0]=t*c+r*u+o,y[1]=s*c+n*u+a,y[2]=t*l+r*h+o,y[3]=s*l+n*h+a;break;case"arcToSvg":l=y[5],h=y[6],p=y[0],g=y[1],y[0]=t*p+r*g,y[1]=s*p+n*g,y[5]=t*l+r*h+o,y[6]=s*l+n*h+a;break;case"circle":y[4]=gs(y[3],e);break;case"rect":y[4]=gs(y[4],e);break;case"ellipse":y[8]=gs(y[8],e);break;case"roundRect":y[5]=gs(y[5],e);break;case"addPath":y[0].transform(e);break;case"poly":y[2]=gs(y[2],e);break;case"regularPoly":case"chamferRect":y[5]=gs(y[5],e);break;case"closePath":break;default:H("unknown transform action",_.action);break}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,s=this.instructions[t];if(!s)return e.x=0,e.y=0,e;for(;s.action==="closePath";){if(t--,t<0)return e.x=0,e.y=0,e;s=this.instructions[t]}switch(s.action){case"moveTo":case"lineTo":e.x=s.data[0],e.y=s.data[1];break;case"quadraticCurveTo":e.x=s.data[2],e.y=s.data[3];break;case"bezierCurveTo":e.x=s.data[4],e.y=s.data[5];break;case"arc":case"arcToSvg":e.x=s.data[5],e.y=s.data[6];break;case"addPath":s.data[0].getLastPoint(e);break}return e}}function gs(i,e){return i?i.prepend(e):e.clone()}function ve(i,e,t){const s=i.getAttribute(e);return s?Number(s):t}function Ff(i,e){const t=i.querySelectorAll("defs");for(let s=0;s<t.length;s++){const r=t[s];for(let n=0;n<r.children.length;n++){const o=r.children[n];switch(o.nodeName.toLowerCase()){case"lineargradient":e.defs[o.id]=X0(o);break;case"radialgradient":e.defs[o.id]=q0(o);break}}}}function rt(i,e,t){const s=i.getAttribute(e);if(s?.trim().endsWith("%")){const r=Number(s.trim().slice(0,-1));return Number.isNaN(r)?t:r/100}return ve(i,e,t)}function Of(i){return(i.getAttribute("gradientUnits")||"objectBoundingBox")==="objectBoundingBox"?"local":"global"}function Lf(i){const e=[];for(let t=0;t<i.children.length;t++){const s=i.children[t],r=rt(s,"offset",0),n=le.shared.setValue(s.getAttribute("stop-color")).toNumber();e.push({offset:r,color:n})}return e}function X0(i){const e=rt(i,"x1",0),t=rt(i,"y1",0),s=rt(i,"x2",1),r=rt(i,"y2",0);return new je({type:"linear",start:{x:e,y:t},end:{x:s,y:r},textureSpace:Of(i),colorStops:Lf(i)})}function q0(i){const e=rt(i,"cx",.5),t=rt(i,"cy",.5),s=rt(i,"r",.5),r=rt(i,"fx",e),n=rt(i,"fy",t),o=rt(i,"fr",0);return new je({type:"radial",center:{x:r,y:n},innerRadius:o,outerCenter:{x:e,y:t},outerRadius:s,textureSpace:Of(i),colorStops:Lf(i)})}function To(i){const e=i.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return e?e[1]:""}const So={fill:{type:"paint",default:0},"fill-opacity":{type:"number",default:1},stroke:{type:"paint",default:0},"stroke-width":{type:"number",default:1},"stroke-opacity":{type:"number",default:1},"stroke-linecap":{type:"string",default:"butt"},"stroke-linejoin":{type:"string",default:"miter"},"stroke-miterlimit":{type:"number",default:10},"stroke-dasharray":{type:"string",default:"none"},"stroke-dashoffset":{type:"number",default:0},opacity:{type:"number",default:1}};function Ia(i,e){const t=i.getAttribute("style"),s={},r={},n={strokeStyle:s,fillStyle:r,useFill:!1,useStroke:!1};for(const o in So){const a=i.getAttribute(o);a&&yc(e,n,o,a.trim())}if(t){const o=t.split(";");for(let a=0;a<o.length;a++){const l=o[a].trim(),[h,c]=l.split(":");So[h]&&yc(e,n,h,c.trim())}}return{strokeStyle:n.useStroke?s:null,fillStyle:n.useFill?r:null,useFill:n.useFill,useStroke:n.useStroke}}function yc(i,e,t,s){switch(t){case"stroke":if(s!=="none"){if(s.startsWith("url(")){const r=To(s);e.strokeStyle.fill=i.defs[r]}else e.strokeStyle.color=le.shared.setValue(s).toNumber();e.useStroke=!0}break;case"stroke-width":e.strokeStyle.width=Number(s);break;case"fill":if(s!=="none"){if(s.startsWith("url(")){const r=To(s);e.fillStyle.fill=i.defs[r]}else e.fillStyle.color=le.shared.setValue(s).toNumber();e.useFill=!0}break;case"fill-opacity":e.fillStyle.alpha=Number(s);break;case"stroke-opacity":e.strokeStyle.alpha=Number(s);break;case"opacity":e.fillStyle.alpha=Number(s),e.strokeStyle.alpha=Number(s);break}}function Uf(i){if(i.length<=2)return!0;const e=i.map(a=>a.area).sort((a,l)=>l-a),[t,s]=e,r=e[e.length-1],n=t/s,o=s/r;return!(n>3&&o<2)}function Nf(i){return i.split(/(?=[Mm])/).filter(s=>s.trim().length>0)}function zf(i){const e=i.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!e||e.length<4)return 0;const t=e.map(Number),s=[],r=[];for(let c=0;c<t.length;c+=2)c+1<t.length&&(s.push(t[c]),r.push(t[c+1]));if(s.length===0||r.length===0)return 0;const n=Math.min(...s),o=Math.max(...s),a=Math.min(...r),l=Math.max(...r);return(o-n)*(l-a)}function Co(i,e){const t=new pt(i,!1);for(const s of t.instructions)e.instructions.push(s)}function Hf(i,e){if(typeof i=="string"){const o=document.createElement("div");o.innerHTML=i.trim(),i=o.querySelector("svg")}const t={context:e,defs:{},path:new pt};Ff(i,t);const s=i.children,{fillStyle:r,strokeStyle:n}=Ia(i,t);for(let o=0;o<s.length;o++){const a=s[o];a.nodeName.toLowerCase()!=="defs"&&Wf(a,t,r,n)}return e}function Wf(i,e,t,s){const r=i.children,{fillStyle:n,strokeStyle:o}=Ia(i,e);n&&t?t={...t,...n}:n&&(t=n),o&&s?s={...s,...o}:o&&(s=o);const a=!t&&!s;a&&(t={color:0});let l,h,c,u,d,f,p,g,m,_,y,x,b,v,w,T,k;switch(i.nodeName.toLowerCase()){case"path":{v=i.getAttribute("d");const E=i.getAttribute("fill-rule"),A=Nf(v),M=E==="evenodd",B=A.length>1;if(M&&B){const O=A.map(P=>({path:P,area:zf(P)}));if(O.sort((P,C)=>C.area-P.area),A.length>3||!Uf(O))for(let P=0;P<O.length;P++){const C=O[P],D=P===0;e.context.beginPath();const R=new pt(void 0,!0);Co(C.path,R),e.context.path(R),D?(t&&e.context.fill(t),s&&e.context.stroke(s)):e.context.cut()}else for(let P=0;P<O.length;P++){const C=O[P],D=P%2===1;e.context.beginPath();const R=new pt(void 0,!0);Co(C.path,R),e.context.path(R),D?e.context.cut():(t&&e.context.fill(t),s&&e.context.stroke(s))}}else{const O=E?E==="evenodd":!0;w=new pt(v,O),e.context.path(w),t&&e.context.fill(t),s&&e.context.stroke(s)}break}case"circle":p=ve(i,"cx",0),g=ve(i,"cy",0),m=ve(i,"r",0),e.context.ellipse(p,g,m,m),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"rect":l=ve(i,"x",0),h=ve(i,"y",0),T=ve(i,"width",0),k=ve(i,"height",0),_=ve(i,"rx",0),y=ve(i,"ry",0),_||y?e.context.roundRect(l,h,T,k,_||y):e.context.rect(l,h,T,k),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"ellipse":p=ve(i,"cx",0),g=ve(i,"cy",0),_=ve(i,"rx",0),y=ve(i,"ry",0),e.context.beginPath(),e.context.ellipse(p,g,_,y),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"line":c=ve(i,"x1",0),u=ve(i,"y1",0),d=ve(i,"x2",0),f=ve(i,"y2",0),e.context.beginPath(),e.context.moveTo(c,u),e.context.lineTo(d,f),s&&e.context.stroke(s);break;case"polygon":b=i.getAttribute("points"),x=b.match(/-?\d+/g).map(E=>parseInt(E,10)),e.context.poly(x,!0),t&&e.context.fill(t),s&&e.context.stroke(s);break;case"polyline":b=i.getAttribute("points"),x=b.match(/-?\d+/g).map(E=>parseInt(E,10)),e.context.poly(x,!1),s&&e.context.stroke(s);break;case"g":case"svg":break;default:{H(`[SVG parser] <${i.nodeName}> elements unsupported`);break}}a&&(t=null);for(let E=0;E<r.length;E++)Wf(r[E],e,t,s)}function Y0(i){return i.texture!==void 0}const xc={repeat:{addressModeU:"repeat",addressModeV:"repeat"},"repeat-x":{addressModeU:"repeat",addressModeV:"clamp-to-edge"},"repeat-y":{addressModeU:"clamp-to-edge",addressModeV:"repeat"},"no-repeat":{addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge"}};class Ls{constructor(e,t){this.uid=oe("fillPattern"),this._tick=0,this.transform=new U;const s=Y0(e)?e:{texture:e,repetition:t};this.texture=s.texture,this.textureSpace=s.textureSpace??"global";const r=s.repetition;r&&(this.texture.source.style.addressModeU=xc[r].addressModeU,this.texture.source.style.addressModeV=xc[r].addressModeV)}setTransform(e){if(e){if(this.transform.equals(e))return;this.transform.copyFrom(e)}else{if(this.transform.isIdentity())return;this.transform.identity()}this._tick++}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture=e,this._tick++)}get styleKey(){return`fill-pattern-${this.uid}-${this._tick}`}destroy(){this.texture.destroy(!0),this.texture=null}}function K0(i){return le.isColorLike(i)}function bc(i){return i instanceof Ls}function vc(i){return i instanceof je}function Z0(i){return i instanceof W}function Q0(i,e,t){const s=le.shared.setValue(e??0);return i.color=s.toNumber(),i.alpha=s.alpha===1?t.alpha:s.alpha,i.texture=W.WHITE,{...t,...i}}function J0(i,e,t){return i.texture=e,{...t,...i}}function wc(i,e,t){return i.fill=e,i.color=16777215,i.texture=e.texture,i.matrix=e.transform,i.textureSpace=e.textureSpace,{...t,...i}}function Tc(i,e,t){return e.buildGradient(),i.fill=e,i.color=16777215,i.texture=e.texture,i.matrix=e.transform,i.textureSpace=e.textureSpace,{...t,...i}}function ey(i,e){const t={...e,...i},s=le.shared.setValue(t.color);return t.alpha*=s.alpha,t.color=s.toNumber(),t}function Ft(i,e){if(i==null)return null;const t={},s=i;return K0(i)?Q0(t,i,e):Z0(i)?J0(t,i,e):bc(i)?wc(t,i,e):vc(i)?Tc(t,i,e):s.fill&&bc(s.fill)?wc(s,s.fill,e):s.fill&&vc(s.fill)?Tc(s,s.fill,e):ey(s,e)}function xi(i,e){const{width:t,alignment:s,miterLimit:r,cap:n,join:o,pixelLine:a,...l}=e,h=Ft(i,l);return h?{width:t,alignment:s,miterLimit:r,cap:n,join:o,pixelLine:a,...h}:null}function $f(i,e){let t=1;const s=i.shapePath.shapePrimitives;for(let r=0;r<s.length;r++){const n=s[r].shape;if(n.type!=="polygon")continue;const o=n.points,a=o.length;if(a<6)continue;const l=n.closePath;for(let h=0;h<a;h+=2){if(!l&&(h===0||h===a-2))continue;const c=(h-2+a)%a,u=(h+2)%a,d=o[c],f=o[c+1],p=o[h],g=o[h+1],m=o[u],_=o[u+1],y=d-p,x=f-g,b=m-p,v=_-g,w=y*y+x*x,T=b*b+v*v;if(w<1e-12||T<1e-12)continue;let A=(y*b+x*v)/Math.sqrt(w*T);A<-1?A=-1:A>1&&(A=1);const M=Math.sqrt((1-A)*.5);if(M<1e-6)continue;const B=Math.min(1/M,e);B>t&&(t=B)}}return t}const ty=new ce,Sc=new U,Ga=class ht extends Re{constructor(){super(...arguments),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=oe("graphicsContext"),this.dirty=!0,this.batchMode="auto",this.instructions=[],this.destroyed=!1,this._activePath=new pt,this._transform=new U,this._fillStyle={...ht.defaultFillStyle},this._strokeStyle={...ht.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new Ee,this._boundsDirty=!0}clone(){const e=new ht;return e.batchMode=this.batchMode,e.instructions=this.instructions.slice(),e._activePath=this._activePath.clone(),e._transform=this._transform.clone(),e._fillStyle={...this._fillStyle},e._strokeStyle={...this._strokeStyle},e._stateStack=this._stateStack.slice(),e._bounds=this._bounds.clone(),e._boundsDirty=!0,e}get fillStyle(){return this._fillStyle}set fillStyle(e){this._fillStyle=Ft(e,ht.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(e){this._strokeStyle=xi(e,ht.defaultStrokeStyle)}setFillStyle(e){return this._fillStyle=Ft(e,ht.defaultFillStyle),this}setStrokeStyle(e){return this._strokeStyle=Ft(e,ht.defaultStrokeStyle),this}texture(e,t,s,r,n,o){return this.instructions.push({action:"texture",data:{image:e,dx:s||0,dy:r||0,dw:n||e.frame.width,dh:o||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t||t===0?le.shared.setValue(t).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new pt,this}fill(e,t){let s;const r=this.instructions[this.instructions.length-1];return this._tick===0&&r?.action==="stroke"?s=r.data.path:s=this._activePath.clone(),s?(e!=null&&(t!==void 0&&typeof e=="number"&&(z(de,"GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead"),e={color:e,alpha:t}),this._fillStyle=Ft(e,ht.defaultFillStyle)),this.instructions.push({action:"fill",data:{style:this.fillStyle,path:s}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){const{x:e,y:t}=this._activePath.getLastPoint(ce.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(e){let t;const s=this.instructions[this.instructions.length-1];return this._tick===0&&s?.action==="fill"?t=s.data.path:t=this._activePath.clone(),t?(e!=null&&(this._strokeStyle=xi(e,ht.defaultStrokeStyle)),this.instructions.push({action:"stroke",data:{style:this.strokeStyle,path:t}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}cut(){for(let e=0;e<2;e++){const t=this.instructions[this.instructions.length-1-e],s=this._activePath.clone();if(t&&(t.action==="stroke"||t.action==="fill"))if(t.data.hole)t.data.hole.addPath(s);else{t.data.hole=s;break}}return this._initNextPathLocation(),this}arc(e,t,s,r,n,o){this._tick++;const a=this._transform;return this._activePath.arc(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,s,r,n,o),this}arcTo(e,t,s,r,n){this._tick++;const o=this._transform;return this._activePath.arcTo(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,o.a*s+o.c*r+o.tx,o.b*s+o.d*r+o.ty,n),this}arcToSvg(e,t,s,r,n,o,a){this._tick++;const l=this._transform;return this._activePath.arcToSvg(e,t,s,r,n,l.a*o+l.c*a+l.tx,l.b*o+l.d*a+l.ty),this}bezierCurveTo(e,t,s,r,n,o,a){this._tick++;const l=this._transform;return this._activePath.bezierCurveTo(l.a*e+l.c*t+l.tx,l.b*e+l.d*t+l.ty,l.a*s+l.c*r+l.tx,l.b*s+l.d*r+l.ty,l.a*n+l.c*o+l.tx,l.b*n+l.d*o+l.ty,a),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,s,r){return this._tick++,this._activePath.ellipse(e,t,s,r,this._transform.clone()),this}circle(e,t,s){return this._tick++,this._activePath.circle(e,t,s,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;const s=this._transform;return this._activePath.lineTo(s.a*e+s.c*t+s.tx,s.b*e+s.d*t+s.ty),this}moveTo(e,t){this._tick++;const s=this._transform,r=this._activePath.instructions,n=s.a*e+s.c*t+s.tx,o=s.b*e+s.d*t+s.ty;return r.length===1&&r[0].action==="moveTo"?(r[0].data[0]=n,r[0].data[1]=o,this):(this._activePath.moveTo(n,o),this)}quadraticCurveTo(e,t,s,r,n){this._tick++;const o=this._transform;return this._activePath.quadraticCurveTo(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,o.a*s+o.c*r+o.tx,o.b*s+o.d*r+o.ty,n),this}rect(e,t,s,r){return this._tick++,this._activePath.rect(e,t,s,r,this._transform.clone()),this}roundRect(e,t,s,r,n){return this._tick++,this._activePath.roundRect(e,t,s,r,n,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,s,r,n=0,o){return this._tick++,this._activePath.regularPoly(e,t,s,r,n,o),this}roundPoly(e,t,s,r,n,o){return this._tick++,this._activePath.roundPoly(e,t,s,r,n,o),this}roundShape(e,t,s,r){return this._tick++,this._activePath.roundShape(e,t,s,r),this}filletRect(e,t,s,r,n){return this._tick++,this._activePath.filletRect(e,t,s,r,n),this}chamferRect(e,t,s,r,n,o){return this._tick++,this._activePath.chamferRect(e,t,s,r,n,o),this}star(e,t,s,r,n=0,o=0){return this._tick++,this._activePath.star(e,t,s,r,n,o,this._transform.clone()),this}svg(e){return this._tick++,Hf(e,this),this}restore(){const e=this._stateStack.pop();return e&&(this._transform=e.transform,this._fillStyle=e.fillStyle,this._strokeStyle=e.strokeStyle),this}save(){return this._stateStack.push({transform:this._transform.clone(),fillStyle:{...this._fillStyle},strokeStyle:{...this._strokeStyle}}),this}getTransform(){return this._transform}resetTransform(){return this._transform.identity(),this}rotate(e){return this._transform.rotate(e),this}scale(e,t=e){return this._transform.scale(e,t),this}setTransform(e,t,s,r,n,o){return e instanceof U?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,s,r,n,o),this)}transform(e,t,s,r,n,o){return e instanceof U?(this._transform.append(e),this):(Sc.set(e,t,s,r,n,o),this._transform.append(Sc),this)}translate(e,t=e){return this._transform.translate(e,t),this}clear(){return this._activePath.clear(),this.instructions.length=0,this.resetTransform(),this.onUpdate(),this}onUpdate(){this._boundsDirty=!0,this.dirty=!0,this.emit("update",this,16)}get bounds(){if(!this._boundsDirty)return this._bounds;this._boundsDirty=!1;const e=this._bounds;e.clear();for(let t=0;t<this.instructions.length;t++){const s=this.instructions[t],r=s.action;if(r==="fill"){const n=s.data;e.addBounds(n.path.bounds)}else if(r==="texture"){const n=s.data;e.addFrame(n.dx,n.dy,n.dx+n.dw,n.dy+n.dh,n.transform)}if(r==="stroke"){const n=s.data,o=n.style.alignment;let a=n.style.width*(1-o);n.style.join==="miter"&&(a*=$f(n.path,n.style.miterLimit));const l=n.path.bounds;e.addFrame(l.minX-a,l.minY-a,l.maxX+a,l.maxY+a)}}return e.isValid||e.set(0,0,0,0),e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;const t=this.instructions;let s=!1;for(let r=0;r<t.length;r++){const n=t[r],o=n.data,a=o.path;if(!n.action||!a)continue;const l=o.style,h=a.shapePath.shapePrimitives;for(let c=0;c<h.length;c++){const u=h[c].shape;if(!l||!u)continue;const d=h[c].transform,f=d?d.applyInverse(e,ty):e;if(n.action==="fill")s=u.contains(f.x,f.y);else{const g=l;s=u.strokeContains(f.x,f.y,g.width,g.alignment)}const p=o.hole;if(p){const g=p.shapePath?.shapePrimitives;if(g)for(let m=0;m<g.length;m++)g[m].shape.contains(f.x,f.y)&&(s=!1)}if(s)return!0}}return s}unload(){this.emit("unload",this);for(const e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){if(this.destroyed)return;if(this.destroyed=!0,this._stateStack.length=0,this._transform=null,this.unload(),this.emit("destroy",this),this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._fillStyle.texture&&(this._fillStyle.fill&&"uid"in this._fillStyle.fill?this._fillStyle.fill.destroy():this._fillStyle.texture.destroy(s)),this._strokeStyle.texture&&(this._strokeStyle.fill&&"uid"in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(s))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};Ga.defaultFillStyle={color:16777215,alpha:1,texture:W.WHITE,matrix:null,fill:null,textureSpace:"local"};Ga.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:"butt",join:"miter",texture:W.WHITE,matrix:null,fill:null,textureSpace:"local",pixelLine:!1};let qe=Ga;class Vf{constructor(e){this._attachedDomElements=[],this._renderer=e,this._renderer.runners.postrender.add(this),this._renderer.runners.init.add(this),this._domElement=document.createElement("div"),this._domElement.style.position="absolute",this._domElement.style.top="0",this._domElement.style.left="0",this._domElement.style.pointerEvents="none",this._domElement.style.zIndex="1000"}init(){this._canvasObserver=new ra({domElement:this._domElement,renderer:this._renderer})}addRenderable(e,t){this._attachedDomElements.includes(e)||this._attachedDomElements.push(e)}updateRenderable(e){}validateRenderable(e){return!0}postrender(){const e=this._attachedDomElements;if(e.length===0){this._domElement.remove();return}this._canvasObserver.ensureAttached();for(let t=0;t<e.length;t++){const s=e[t],r=s.element;if(!s.parent||s.globalDisplayStatus<7)r?.remove(),e.splice(t,1),t--;else{this._domElement.contains(r)||(r.style.position="absolute",r.style.pointerEvents="auto",this._domElement.appendChild(r));const n=s.worldTransform,o=s._anchor,a=s.width*o.x,l=s.height*o.y;r.style.transformOrigin=`${a}px ${l}px`,r.style.transform=`matrix(${n.a}, ${n.b}, ${n.c}, ${n.d}, ${n.tx-a}, ${n.ty-l})`,r.style.opacity=s.groupAlpha.toString()}}}destroy(){this._renderer.runners.postrender.remove(this);for(let e=0;e<this._attachedDomElements.length;e++)this._attachedDomElements[e].element?.remove();this._attachedDomElements.length=0,this._domElement.remove(),this._canvasObserver.destroy(),this._renderer=null}}Vf.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"dom"};class sy{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}init(e){this.removeTickerListener(),this.events=e,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(e){this._pauseUpdate=e}addTickerListener(){this._tickerAdded||!this.domElement||(We.system.add(this._tickerUpdate,this,os.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(We.system.remove(this._tickerUpdate,this),this._tickerAdded=!1)}pointerMoved(){this._didMove=!0}_update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const e=this.events._rootPointerEvent;this.events.supportsTouchEvents&&e.pointerType==="touch"||globalThis.document.dispatchEvent(this.events.supportsPointerEvents?new PointerEvent("pointermove",{clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,pointerId:e.pointerId}):new MouseEvent("mousemove",{clientX:e.clientX,clientY:e.clientY}))}_tickerUpdate(e){this._deltaTime+=e.deltaTime,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this._update())}destroy(){this.removeTickerListener(),this.events=null,this.domElement=null,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}}const dt=new sy;class bi extends Os{constructor(){super(...arguments),this.client=new ce,this.movement=new ce,this.offset=new ce,this.global=new ce,this.screen=new ce}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(e,t,s){return e.worldTransform.applyInverse(s||this.global,t)}getModifierState(e){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(e)}initMouseEvent(e,t,s,r,n,o,a,l,h,c,u,d,f,p,g){throw new Error("Method not implemented.")}}class Fe extends bi{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1,this.persistentDeviceId=0}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class hs extends bi{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}hs.DOM_DELTA_PIXEL=0;hs.DOM_DELTA_LINE=1;hs.DOM_DELTA_PAGE=2;const iy=2048,ry=new ce,Ks=new ce;class jf{constructor(e){this.dispatch=new Re,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=e,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mapContextMenu=this.mapContextMenu.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel),this.addEventMapping("contextmenu",this.mapContextMenu)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((s,r)=>s.priority-r.priority)}dispatchEvent(e,t){e.propagationStopped=!1,e.propagationImmediatelyStopped=!1,this.propagate(e,t),this.dispatch.emit(t||e.type,e)}mapEvent(e){if(!this.rootTarget)return;const t=this.mappingTable[e.type];if(t)for(let s=0,r=t.length;s<r;s++)t[s].fn(e);else H(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){dt.pauseUpdate=!0;const r=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",n=this[r](this.rootTarget,this.rootTarget.eventMode,ry.set(e,t),this.hitTestFn,this.hitPruneFn);return n&&n[0]}propagate(e,t){if(!e.target)return;const s=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let r=0,n=s.length-1;r<n;r++)if(e.currentTarget=s[r],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return;if(e.eventPhase=e.AT_TARGET,e.currentTarget=e.target,this.notifyTarget(e,t),!(e.propagationStopped||e.propagationImmediatelyStopped)){e.eventPhase=e.BUBBLING_PHASE;for(let r=s.length-2;r>=0;r--)if(e.currentTarget=s[r],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,s=this._allInteractiveElements){if(s.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const r=Array.isArray(t)?t:[t];for(let n=s.length-1;n>=0;n--)r.forEach(o=>{e.currentTarget=s[n],this.notifyTarget(e,o)})}propagationPath(e){const t=[e];for(let s=0;s<iy&&e!==this.rootTarget&&e.parent;s++){if(!e.parent)throw new Error("Cannot find propagation path to disconnected target");t.push(e.parent),e=e.parent}return t.reverse(),t}hitTestMoveRecursive(e,t,s,r,n,o=!1){let a=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(dt.pauseUpdate=!1),e.interactiveChildren&&e.children){const c=e.children;for(let u=c.length-1;u>=0;u--){const d=c[u],f=this.hitTestMoveRecursive(d,this._isInteractive(t)?t:d.eventMode,s,r,n,o||n(e,s));if(f){if(f.length>0&&!f[f.length-1].parent)continue;const p=e.isInteractive();(f.length>0||p)&&(p&&this._allInteractiveElements.push(e),f.push(e)),this._hitElements.length===0&&(this._hitElements=f),a=!0}}}const l=this._isInteractive(t),h=e.isInteractive();return h&&h&&this._allInteractiveElements.push(e),o||this._hitElements.length>0?null:a?this._hitElements:l&&!n(e,s)&&r(e,s)?h?[e]:[]:null}hitTestRecursive(e,t,s,r,n){if(this._interactivePrune(e)||n(e,s))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(dt.pauseUpdate=!1),e.interactiveChildren&&e.children){const l=e.children,h=s;for(let c=l.length-1;c>=0;c--){const u=l[c],d=this.hitTestRecursive(u,this._isInteractive(t)?t:u.eventMode,h,r,n);if(d){if(d.length>0&&!d[d.length-1].parent)continue;const f=e.isInteractive();return(d.length>0||f)&&d.push(e),d}}}const o=this._isInteractive(t),a=e.isInteractive();return o&&r(e,s)?a?[e]:[]:null}_isInteractive(e){return e==="static"||e==="dynamic"}_interactivePrune(e){return!e||!e.visible||!e.renderable||!e.measurable||e.eventMode==="none"||e.eventMode==="passive"&&!e.interactiveChildren}hitPruneFn(e,t){if(e.hitArea&&(e.worldTransform.applyInverse(t,Ks),!e.hitArea.contains(Ks.x,Ks.y)))return!0;if(e.effects&&e.effects.length)for(let s=0;s<e.effects.length;s++){const r=e.effects[s];if(r.containsPoint&&!r.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e?.containsPoint?(e.worldTransform.applyInverse(t,Ks),e.containsPoint(Ks)):!1}notifyTarget(e,t){if(!e.currentTarget.isInteractive())return;t??(t=e.type);const s=`on${t}`;e.currentTarget[s]?.(e);const r=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,r),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);if(this.dispatchEvent(t,"pointerdown"),t.pointerType==="touch")this.dispatchEvent(t,"touchstart");else if(t.pointerType==="mouse"||t.pointerType==="pen"){const r=t.button===2;this.dispatchEvent(t,r?"rightdown":"mousedown")}const s=this.trackingData(e.pointerId);s.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const t=this.createPointerEvent(e);this._isPointerMoveEvent=!1;const s=t.pointerType==="mouse"||t.pointerType==="pen",r=this.trackingData(e.pointerId),n=this.findMountedTarget(r.overTargets);if(r.overTargets?.length>0&&n!==t.target){const l=e.type==="mousemove"?"mouseout":"pointerout",h=this.createPointerEvent(e,l,n);if(this.dispatchEvent(h,"pointerout"),s&&this.dispatchEvent(h,"mouseout"),!t.composedPath().includes(n)){const c=this.createPointerEvent(e,"pointerleave",n);for(c.eventPhase=c.AT_TARGET;c.target&&!t.composedPath().includes(c.target);)c.currentTarget=c.target,this.notifyTarget(c),s&&this.notifyTarget(c,"mouseleave"),c.target=c.target.parent;this.freeEvent(c)}this.freeEvent(h)}if(n!==t.target){const l=e.type==="mousemove"?"mouseover":"pointerover",h=this.clonePointerEvent(t,l);this.dispatchEvent(h,"pointerover"),s&&this.dispatchEvent(h,"mouseover");let c=n?.parent;for(;c&&c!==this.rootTarget.parent&&c!==t.target;)c=c.parent;if(!c||c===this.rootTarget.parent){const d=this.clonePointerEvent(t,"pointerenter");for(d.eventPhase=d.AT_TARGET;d.target&&d.target!==n&&d.target!==this.rootTarget.parent;)d.currentTarget=d.target,this.notifyTarget(d),s&&this.notifyTarget(d,"mouseenter"),d.target=d.target.parent;this.freeEvent(d)}this.freeEvent(h)}const o=[],a=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(t,"pointermove"),a&&o.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),a&&o.push("globaltouchmove")),s&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),a&&o.push("globalmousemove"),this.cursor=t.target?.cursor),o.length>0&&this.all(t,o),this._allInteractiveElements.length=0,this._hitElements.length=0,r.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),s=this.createPointerEvent(e),r=s.pointerType==="mouse"||s.pointerType==="pen";this.dispatchEvent(s,"pointerover"),r&&this.dispatchEvent(s,"mouseover"),s.pointerType==="mouse"&&(this.cursor=s.target?.cursor);const n=this.clonePointerEvent(s,"pointerenter");for(n.eventPhase=n.AT_TARGET;n.target&&n.target!==this.rootTarget.parent;)n.currentTarget=n.target,this.notifyTarget(n),r&&this.notifyTarget(n,"mouseenter"),n.target=n.target.parent;t.overTargets=s.composedPath(),this.freeEvent(s),this.freeEvent(n)}mapPointerOut(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const s=e.pointerType==="mouse"||e.pointerType==="pen",r=this.findMountedTarget(t.overTargets),n=this.createPointerEvent(e,"pointerout",r);this.dispatchEvent(n),s&&this.dispatchEvent(n,"mouseout");const o=this.createPointerEvent(e,"pointerleave",r);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),s&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;t.overTargets=null,this.freeEvent(n),this.freeEvent(o)}this.cursor=null}mapPointerUp(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),s=this.createPointerEvent(e);if(this.dispatchEvent(s,"pointerup"),s.pointerType==="touch")this.dispatchEvent(s,"touchend");else if(s.pointerType==="mouse"||s.pointerType==="pen"){const a=s.button===2;this.dispatchEvent(s,a?"rightup":"mouseup")}const r=this.trackingData(e.pointerId),n=this.findMountedTarget(r.pressTargetsByButton[e.button]);let o=n;if(n&&!s.composedPath().includes(n)){let a=n;for(;a&&!s.composedPath().includes(a);){if(s.currentTarget=a,this.notifyTarget(s,"pointerupoutside"),s.pointerType==="touch")this.notifyTarget(s,"touchendoutside");else if(s.pointerType==="mouse"||s.pointerType==="pen"){const l=s.button===2;this.notifyTarget(s,l?"rightupoutside":"mouseupoutside")}a=a.parent}delete r.pressTargetsByButton[e.button],o=a}if(o){const a=this.clonePointerEvent(s,"click");a.target=o,a.path=null,r.clicksByButton[e.button]||(r.clicksByButton[e.button]={clickCount:0,target:a.target,timeStamp:t});const l=r.clicksByButton[e.button];if(l.target===a.target&&t-l.timeStamp<200?++l.clickCount:l.clickCount=1,l.target=a.target,l.timeStamp=t,a.detail=l.clickCount,a.pointerType==="mouse"){const h=a.button===2;this.dispatchEvent(a,h?"rightclick":"click")}else a.pointerType==="touch"&&this.dispatchEvent(a,"tap");this.dispatchEvent(a,"pointertap"),this.freeEvent(a)}this.freeEvent(s)}mapPointerUpOutside(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),s=this.findMountedTarget(t.pressTargetsByButton[e.button]),r=this.createPointerEvent(e);if(s){let n=s;for(;n;)r.currentTarget=n,this.notifyTarget(r,"pointerupoutside"),r.pointerType==="touch"?this.notifyTarget(r,"touchendoutside"):(r.pointerType==="mouse"||r.pointerType==="pen")&&this.notifyTarget(r,r.button===2?"rightupoutside":"mouseupoutside"),n=n.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(r)}mapWheel(e){if(!(e instanceof hs)){H("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}mapContextMenu(e){if(!(e instanceof Fe)){H("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);this.dispatchEvent(t,"contextmenu"),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let s=1;s<e.length&&e[s].parent===t;s++)t=e[s];return t}createPointerEvent(e,t,s){const r=this.allocateEvent(Fe);return this.copyPointerData(e,r),this.copyMouseData(e,r),this.copyData(e,r),r.nativeEvent=e.nativeEvent,r.originalEvent=e,r.target=s??this.hitTest(r.global.x,r.global.y)??this._hitElements[0],typeof t=="string"&&(r.type=t),r}createWheelEvent(e){const t=this.allocateEvent(hs);return this.copyWheelData(e,t),this.copyMouseData(e,t),this.copyData(e,t),t.nativeEvent=e.nativeEvent,t.originalEvent=e,t.target=this.hitTest(t.global.x,t.global.y),t}clonePointerEvent(e,t){const s=this.allocateEvent(Fe);return s.nativeEvent=e.nativeEvent,s.originalEvent=e.originalEvent,this.copyPointerData(e,s),this.copyMouseData(e,s),this.copyData(e,s),s.target=e.target,s.path=e.composedPath().slice(),s.type=t??s.type,s}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof Fe&&t instanceof Fe&&(t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,t.persistentDeviceId=e.persistentDeviceId)}copyMouseData(e,t){e instanceof bi&&t instanceof bi&&(t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.copyFrom(e.client),t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.copyFrom(e.movement),t.screen.copyFrom(e.screen),t.shiftKey=e.shiftKey,t.global.copyFrom(e.global))}copyData(e,t){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.detail=e.detail,t.view=e.view,t.which=e.which,t.layer.copyFrom(e.layer),t.page.copyFrom(e.page)}trackingData(e){return this.mappingState.trackingData[e]||(this.mappingState.trackingData[e]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[e]}allocateEvent(e){this.eventPool.has(e)||this.eventPool.set(e,[]);const t=this.eventPool.get(e).pop()||new e(this);return t.eventPhase=t.NONE,t.currentTarget=null,t.defaultPrevented=!1,t.path=null,t.target=null,t}freeEvent(e){if(e.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const t=e.constructor;this.eventPool.has(t)||this.eventPool.set(t,[]),this.eventPool.get(t).push(e)}_notifyListeners(e,t){const s=e.currentTarget._events[t];if(s)if("fn"in s)s.once&&e.currentTarget.removeListener(t,s.fn,void 0,!0),s.fn.call(s.context,e);else for(let r=0,n=s.length;r<n&&!e.propagationImmediatelyStopped;r++)s[r].once&&e.currentTarget.removeListener(t,s[r].fn,void 0,!0),s[r].fn.call(s[r].context,e)}}const ny=1,oy={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},Da=class Mo{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new jf(null),dt.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new Fe(null),this._rootWheelEvent=new hs(null),this._rootContextMenuEvent=new Fe(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...Mo.defaultEventFeatures},{set:(t,s,r)=>(s==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=r),t[s]=r,!0)}),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerMove=this._onPointerMove.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onPointerOverOut=this._onPointerOverOut.bind(this),this._onContextMenu=this._onContextMenu.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:s}=this.renderer;this.setTargetElement(t),this.resolution=s,Mo._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){dt.destroy(),this.setTargetElement(null),this.renderer=null,this._currentCursor=null}setCursor(e){e||(e="default");let t=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(t=!1),this._currentCursor===e)return;this._currentCursor=e;const s=this.cursorStyles[e];if(s)switch(typeof s){case"string":t&&(this.domElement.style.cursor=s);break;case"function":s(e);break;case"object":t&&Object.assign(this.domElement.style,s);break}else t&&typeof e=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,e)&&(this.domElement.style.cursor=e)}get pointer(){return this._rootPointerEvent}_onPointerDown(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);this.autoPreventDefault&&t[0].isNormalized&&(e.cancelable||!("cancelable"in e))&&e.preventDefault();for(let s=0,r=t.length;s<r;s++){const n=t[s],o=this._bootstrapEvent(this._rootPointerEvent,n);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,dt.pointerMoved();const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootPointerEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}_onPointerUp(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let t=e.target;e.composedPath&&e.composedPath().length>0&&(t=e.composedPath()[0]);const s=t!==this.domElement?"outside":"",r=this._normalizeToPointerData(e);for(let n=0,o=r.length;n<o;n++){const a=this._bootstrapEvent(this._rootPointerEvent,r[n]);a.type+=s,this.rootBoundary.mapEvent(a)}this.setCursor(this.rootBoundary.cursor)}_onPointerOverOut(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootPointerEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}_onContextMenu(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let s=0,r=t.length;s<r;s++){const n=this._bootstrapEvent(this._rootContextMenuEvent,t[s]);this.rootBoundary.mapEvent(n)}this.setCursor(this.rootBoundary.cursor)}onWheel(e){if(!this.features.wheel)return;const t=this.normalizeWheelEvent(e);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(t)}setTargetElement(e){this._removeEvents(),this.domElement=e,dt.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;dt.addTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="none",e.msTouchAction="none"):this.supportsPointerEvents&&(e.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this._onPointerMove,!0),this.domElement.addEventListener("pointerdown",this._onPointerDown,!0),this.domElement.addEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this._onPointerOverOut,!0),globalThis.addEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this._onPointerMove,!0),this.domElement.addEventListener("mousedown",this._onPointerDown,!0),this.domElement.addEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this._onPointerOverOut,!0),globalThis.addEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this._onPointerDown,!0),this.domElement.addEventListener("touchend",this._onPointerUp,!0),this.domElement.addEventListener("touchmove",this._onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.domElement.addEventListener("contextmenu",this._onContextMenu,!0),this._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;dt.removeTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="",e.msTouchAction=""):this.supportsPointerEvents&&(e.touchAction="")),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this._onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this._onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this._onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this._onPointerMove,!0),this.domElement.removeEventListener("mousedown",this._onPointerDown,!0),this.domElement.removeEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this._onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this._onPointerDown,!0),this.domElement.removeEventListener("touchend",this._onPointerUp,!0),this.domElement.removeEventListener("touchmove",this._onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement.removeEventListener("contextmenu",this._onContextMenu,!0),this.domElement=null,this._eventsAdded=!1}mapPositionToPoint(e,t,s){const r=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},n=1/this.resolution;e.x=(t-r.left)*(this.domElement.width/r.width)*n,e.y=(s-r.top)*(this.domElement.height/r.height)*n}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let s=0,r=e.changedTouches.length;s<r;s++){const n=e.changedTouches[s];typeof n.button>"u"&&(n.button=0),typeof n.buttons>"u"&&(n.buttons=1),typeof n.isPrimary>"u"&&(n.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof n.width>"u"&&(n.width=n.radiusX||1),typeof n.height>"u"&&(n.height=n.radiusY||1),typeof n.tiltX>"u"&&(n.tiltX=0),typeof n.tiltY>"u"&&(n.tiltY=0),typeof n.pointerType>"u"&&(n.pointerType="touch"),typeof n.pointerId>"u"&&(n.pointerId=n.identifier||0),typeof n.pressure>"u"&&(n.pressure=n.force||.5),typeof n.twist>"u"&&(n.twist=0),typeof n.tangentialPressure>"u"&&(n.tangentialPressure=0),typeof n.layerX>"u"&&(n.layerX=n.offsetX=n.clientX),typeof n.layerY>"u"&&(n.layerY=n.offsetY=n.clientY),n.isNormalized=!0,n.type=e.type,n.altKey??(n.altKey=e.altKey),n.ctrlKey??(n.ctrlKey=e.ctrlKey),n.metaKey??(n.metaKey=e.metaKey),n.shiftKey??(n.shiftKey=e.shiftKey),t.push(n)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const s=e;typeof s.isPrimary>"u"&&(s.isPrimary=!0),typeof s.width>"u"&&(s.width=1),typeof s.height>"u"&&(s.height=1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="mouse"),typeof s.pointerId>"u"&&(s.pointerId=ny),typeof s.pressure>"u"&&(s.pressure=.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),s.isNormalized=!0,t.push(s)}else t.push(e);return t}normalizeWheelEvent(e){const t=this._rootWheelEvent;return this._transferMouseData(t,e),t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ,t.deltaMode=e.deltaMode,this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.nativeEvent=e,t.type=e.type,t}_bootstrapEvent(e,t){return e.originalEvent=null,e.nativeEvent=t,e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist,this._transferMouseData(e,t),this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.isTrusted=t.isTrusted,e.type==="pointerleave"&&(e.type="pointerout"),e.type.startsWith("mouse")&&(e.type=e.type.replace("mouse","pointer")),e.type.startsWith("touch")&&(e.type=oy[e.type]||e.type),e}_transferMouseData(e,t){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.x=t.clientX,e.client.y=t.clientY,e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.x=t.movementX,e.movement.y=t.movementY,e.page.x=t.pageX,e.page.y=t.pageY,e.relatedTarget=null,e.shiftKey=t.shiftKey}};Da.extension={name:"events",type:[S.WebGLSystem,S.CanvasSystem,S.WebGPUSystem],priority:-1};Da.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let Xf=Da;const ay={onclick:null,oncontextmenu:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,get interactive(){return this.eventMode==="dynamic"||this.eventMode==="static"},set interactive(i){this.eventMode=i?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??Xf.defaultEventMode},set eventMode(i){this._internalEventMode=i},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(i,e,t){const s=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,r=typeof t=="object"?t.signal:void 0,n=typeof t=="object"?t.once===!0:!1,o=typeof e=="function"?void 0:e;i=s?`${i}capture`:i;const a=typeof e=="function"?e:e.handleEvent,l=this;r&&r.addEventListener("abort",()=>{l.off(i,a,o)}),n?l.once(i,a,o):l.on(i,a,o)},removeEventListener(i,e,t){const s=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,r=typeof e=="function"?void 0:e;i=s?`${i}capture`:i,e=typeof e=="function"?e:e.handleEvent,this.off(i,e,r)},dispatchEvent(i){if(!(i instanceof Os))throw new Error("Container cannot propagate events outside of the Federated Events API");return i.defaultPrevented=!1,i.path=null,i.target=this,i.manager.dispatchEvent(i),!i.defaultPrevented}};let _s;function Cc(i){const e=ee.get().createCanvas(6,1),t=e.getContext("2d");return t.fillStyle=i,t.fillRect(0,0,6,1),e}function Fa(){if(_s!==void 0)return _s;try{const i=Cc("#ff00ff"),e=Cc("#ffff00"),s=ee.get().createCanvas(6,1).getContext("2d");s.globalCompositeOperation="multiply",s.drawImage(i,0,0),s.drawImage(e,2,0);const r=s.getImageData(2,0,1,1);if(!r)_s=!1;else{const n=r.data;_s=n[0]===255&&n[1]===0&&n[2]===0}}catch{_s=!1}return _s}const Y={canvas:null,convertTintToImage:!1,cacheStepsPerColorChannel:8,canUseMultiply:Fa(),tintMethod:null,_canvasSourceCache:new WeakMap,_unpremultipliedCache:new WeakMap,getCanvasSource:i=>{const e=i.source,t=e?.resource;if(!t)return null;const s=e.alphaMode==="premultiplied-alpha",r=e.resourceWidth??e.pixelWidth,n=e.resourceHeight??e.pixelHeight,o=r!==e.pixelWidth||n!==e.pixelHeight;if(s){if((t instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&t instanceof OffscreenCanvas)&&!o)return t;const a=Y._unpremultipliedCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas}if(t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Int8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Uint32Array||t instanceof Int32Array||t instanceof Float32Array||t instanceof ArrayBuffer){const a=Y._canvasSourceCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas;const l=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),h=l.getContext("2d"),c=h.createImageData(e.pixelWidth,e.pixelHeight),u=c.data,d=t instanceof ArrayBuffer?new Uint8Array(t):new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(e.format==="bgra8unorm")for(let f=0;f<u.length&&f+3<d.length;f+=4)u[f]=d[f+2],u[f+1]=d[f+1],u[f+2]=d[f],u[f+3]=d[f+3];else u.set(d.subarray(0,u.length));return h.putImageData(c,0,0),Y._canvasSourceCache.set(e,{canvas:l,resourceId:e._resourceId}),l}if(s){const a=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),l=a.getContext("2d",{willReadFrequently:!0});a.width=e.pixelWidth,a.height=e.pixelHeight,l.drawImage(t,0,0);const h=l.getImageData(0,0,a.width,a.height),c=h.data;for(let u=0;u<c.length;u+=4){const d=c[u+3];if(d>0){const f=255/d;c[u]=Math.min(255,c[u]*f+.5),c[u+1]=Math.min(255,c[u+1]*f+.5),c[u+2]=Math.min(255,c[u+2]*f+.5)}}return l.putImageData(h,0,0),Y._unpremultipliedCache.set(e,{canvas:a,resourceId:e._resourceId}),a}if(o){const a=Y._canvasSourceCache.get(e);if(a?.resourceId===e._resourceId)return a.canvas;const l=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),h=l.getContext("2d");return l.width=e.pixelWidth,l.height=e.pixelHeight,h.drawImage(t,0,0),Y._canvasSourceCache.set(e,{canvas:l,resourceId:e._resourceId}),l}return t},getTintedCanvas:(i,e)=>{const t=i.texture,s=le.shared.setValue(e).toHex(),r=t.tintCache||(t.tintCache={}),n=r[s],o=t.source._resourceId;if(n?.tintId===o)return n;const a=n&&"getContext"in n?n:ee.get().createCanvas();return Y.tintMethod(t,e,a),a.tintId=o,r[s]=a,r[s]},getTintedPattern:(i,e)=>{const t=le.shared.setValue(e).toHex(),s=i.patternCache||(i.patternCache={}),r=i.source._resourceId;let n=s[t];return n?.tintId===r||(Y.canvas||(Y.canvas=ee.get().createCanvas()),Y.tintMethod(i,e,Y.canvas),n=Y.canvas.getContext("2d").createPattern(Y.canvas,"repeat"),n.tintId=r,s[t]=n),n},applyPatternTransform:(i,e,t=!0)=>{if(!e)return;const s=i;if(!s.setTransform)return;const r=globalThis.DOMMatrix;if(!r)return;const n=new r([e.a,e.b,e.c,e.d,e.tx,e.ty]);s.setTransform(t?n.inverse():n)},tintWithMultiply:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),e!==16777215&&(s.fillStyle=le.shared.setValue(e).toHex(),s.fillRect(0,0,l,h),s.globalCompositeOperation="multiply");const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),e!==16777215&&(s.globalCompositeOperation="destination-atop",s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height)),s.restore()},tintWithOverlay:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),s.globalCompositeOperation="copy",s.fillStyle=le.shared.setValue(e).toHex(),s.fillRect(0,0,l,h),s.globalCompositeOperation="destination-atop";const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore()},tintWithPerPixel:(i,e,t)=>{const s=t.getContext("2d"),r=i.frame.clone(),n=i.source._resolution??i.source.resolution??1,o=i.rotate;r.x*=n,r.y*=n,r.width*=n,r.height*=n;const a=Z.isVertical(o),l=a?r.height:r.width,h=a?r.width:r.height;t.width=Math.ceil(l),t.height=Math.ceil(h),s.save(),s.globalCompositeOperation="copy";const c=Y.getCanvasSource(i);if(!c){s.restore();return}o&&Y._applyInverseRotation(s,o,r.width,r.height),s.drawImage(c,r.x,r.y,r.width,r.height,0,0,r.width,r.height),s.restore();const u=e>>16&255,d=e>>8&255,f=e&255,p=s.getImageData(0,0,l,h),g=p.data;for(let m=0;m<g.length;m+=4)g[m]=g[m]*u/255,g[m+1]=g[m+1]*d/255,g[m+2]=g[m+2]*f/255;s.putImageData(p,0,0)},_applyInverseRotation:(i,e,t,s)=>{const r=Z.inv(e),n=Z.uX(r),o=Z.uY(r),a=Z.vX(r),l=Z.vY(r),h=-Math.min(0,n*t,a*s,n*t+a*s),c=-Math.min(0,o*t,l*s,o*t+l*s);i.transform(n,o,a,l,h,c)}};Y.tintMethod=Y.canUseMultiply?Y.tintWithMultiply:Y.tintWithPerPixel;const In=32767;function Mc(i,e){return(i<<17)+(e<<2)}class qf{constructor(e){this._buckets=new Map,this._screens=new Ko,this._enableFullScreen=!1,this.canvasOptions=e||{}}get enableFullScreen(){return z(ut,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen}set enableFullScreen(e){z(ut,"CanvasPool.enableFullScreen is no longer used, the pool sizes canvases to the screens registered with setScreenSize."),this._enableFullScreen=e}_createCanvasAndContext(e,t){const s=ee.get().createCanvas();s.width=e,s.height=t;const r=s.getContext("2d");return{canvas:s,context:r}}getOptimalCanvasAndContext(e,t,s=1){const{width:r,height:n}=this.getOptimalSize(e,t,s);(r>In||n>In)&&H(`CanvasPool: ${r}x${n} is larger than the ${In}px pool key limit, canvases of this size may be pooled together`);const o=Mc(r,n);let a=this._buckets.get(o);a||(a=[],this._buckets.set(o,a));let l=a.pop();return l||(l=this._createCanvasAndContext(r,n)),l}getOptimalSize(e,t,s=1){const r=Math.ceil(e*s-1e-6),n=Math.ceil(t*s-1e-6),o=is(r),a=this._screens.getFittingWidth(r),l=is(n),h=this._screens.getFittingHeight(n);return{width:a!==void 0?Math.min(a,o):o,height:h!==void 0?Math.min(h,l):l}}returnCanvasAndContext(e){const t=e.canvas,{width:s,height:r}=t,n=this._buckets.get(Mc(s,r));n&&(e.context.resetTransform(),e.context.clearRect(0,0,s,r),n.push(e))}setScreenSize(e,t,s){this._screens.set(e,t,s)&&this._pruneScreenCanvases()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenCanvases()}clear(){this._buckets.clear()}_pruneScreenCanvases(){for(const[e]of this._buckets){const t=e>>>17,s=e>>>2&32767;(rs(t)||this._screens.hasWidth(t))&&(rs(s)||this._screens.hasHeight(s))||this._buckets.delete(e)}}}const At=new qf;cs.register(At);const kc=new U;function Oa(i,e){e.clear();const t=e.matrix;for(let s=0;s<i.length;s++){const r=i[s];if(r.globalDisplayStatus<7)continue;const n=r.renderGroup??r.parentRenderGroup;n?.isCachedAsTexture?e.matrix=kc.copyFrom(n.textureOffsetInverseTransform).append(r.worldTransform):n?._parentCacheAsTextureRenderGroup?e.matrix=kc.copyFrom(n._parentCacheAsTextureRenderGroup.inverseWorldTransform).append(r.groupTransform):e.matrix=r.worldTransform,e.addBounds(r.bounds)}return e.matrix=t,e}const ly=new Ee;function La(i,e,t,s,r=!1,n){const o=ly;o.minX=0,o.minY=0,o.maxX=i.width/s|0,o.maxY=i.height/s|0;const a=Te.getOptimalTexture({width:o.width,height:o.height,resolution:s,autoGenerateMipmaps:r,scaleMode:n});return a.source.uploadMethodId="image",a.source.resource=i,a.source.alphaMode="premultiply-alpha-on-upload",a.frame.width=e/s,a.frame.height=t/s,a.source.emit("update",a.source),a.updateUvs(),a}function ko(i){return typeof i.getCanvasFilterString=="function"}class hy{constructor(){this.skip=!1,this.useClip=!1,this.filters=null,this.container=null,this.bounds=new Ee,this.cssFilterString=""}}class Yf{constructor(e){this._filterStack=[],this._filterStackIndex=0,this._savedStates=[],this._alphaMultiplier=1,this._warnedFilterTypes=new Set,this.renderer=e}push(e){const t=this._pushFilterFrame(),s=e.filterEffect.filters;if(t.skip=!1,t.useClip=!1,t.filters=s,t.container=e.container,t.cssFilterString="",s.every(l=>!l.enabled)){t.skip=!0;return}const r=[],n=1;for(const l of s){if(!l.enabled)continue;if(!ko(l)){this._warnUnsupportedFilter(l);continue}const h=l.getCanvasFilterString();if(h===null){this._warnUnsupportedFilter(l);continue}h&&r.push(h)}if(r.length===0&&n===1){t.skip=!0;return}t.cssFilterString=r.join(" "),this._calculateFilterArea(e,t.bounds),t.useClip=!!e.filterEffect.filterArea;const o=this.renderer.canvasContext.activeContext,a=o.filter||"none";if(this._savedStates.push({filter:a,alphaMultiplier:this._alphaMultiplier}),t.useClip&&Number.isFinite(t.bounds.width)&&Number.isFinite(t.bounds.height)&&t.bounds.width>0&&t.bounds.height>0){const l=this.renderer.canvasContext.activeResolution||1;o.save(),o.setTransform(1,0,0,1,0,0),o.beginPath(),o.rect(t.bounds.x*l,t.bounds.y*l,t.bounds.width*l,t.bounds.height*l),o.clip()}else t.useClip=!1;t.cssFilterString&&(o.filter=a!=="none"?`${a} ${t.cssFilterString}`:t.cssFilterString)}pop(){const e=this._popFilterFrame();if(e.skip)return;const t=this._savedStates.pop();if(!t)return;const s=this.renderer.canvasContext.activeContext;e.useClip?s.restore():s.filter=t.filter,this._alphaMultiplier=t.alphaMultiplier}generateFilteredTexture({texture:e,filters:t}){if(!t?.length||t.every(_=>!_.enabled))return e;const s=[],r=1;for(const _ of t){if(!_.enabled)continue;if(!ko(_)){this._warnUnsupportedFilter(_);continue}const y=_.getCanvasFilterString();if(y===null){this._warnUnsupportedFilter(_);continue}y&&s.push(y)}if(s.length===0&&r===1)return e;const n=Y.getCanvasSource(e);if(!n)return e;const o=e.frame,a=e.source._resolution??e.source.resolution??1,l=o.width,h=o.height,c=At.getOptimalCanvasAndContext(l,h,a),{canvas:u,context:d}=c;d.setTransform(1,0,0,1,0,0),d.clearRect(0,0,u.width,u.height),s.length&&(d.filter=s.join(" "));const f=o.x*a,p=o.y*a,g=l*a,m=h*a;return d.drawImage(n,f,p,g,m,0,0,g,m),d.filter="none",d.globalAlpha=1,La(u,l,h,a)}_calculateFilterArea(e,t){if(e.renderables?Oa(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const r=(e.container.renderGroup||e.container.parentRenderGroup)?.cacheToLocalTransform;r&&t.applyMatrix(r)}}_warnUnsupportedFilter(e){const t=e?.constructor?.name||"Filter";this._warnedFilterTypes.has(t)||(this._warnedFilterTypes.add(t),console.warn(`CanvasRenderer: filter "${t}" is not supported in Canvas2D and will be skipped.`))}get alphaMultiplier(){return this._alphaMultiplier}_pushFilterFrame(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new hy),this._filterStackIndex++,e}_popFilterFrame(){return this._filterStackIndex<=0?this._filterStack[0]:(this._filterStackIndex--,this._filterStack[this._filterStackIndex])}destroy(){this._filterStack=null,this._savedStates=null,this._warnedFilterTypes=null,this._alphaMultiplier=1}}Yf.extension={type:[S.CanvasSystem],name:"filter"};var Kf=`in vec2 aPosition;
254
254
  out vec2 vTextureCoord;
255
255
 
256
256
  uniform vec4 uInputSize;
@@ -277,13 +277,13 @@ void main(void)
277
277
  gl_Position = filterVertexPosition();
278
278
  vTextureCoord = filterTextureCoord();
279
279
  }
280
- `,Xf=`in vec2 vTextureCoord;
280
+ `,Zf=`in vec2 vTextureCoord;
281
281
  out vec4 finalColor;
282
282
  uniform sampler2D uTexture;
283
283
  void main() {
284
284
  finalColor = texture(uTexture, vTextureCoord);
285
285
  }
286
- `,wo=`struct GlobalFilterUniforms {
286
+ `,Eo=`struct GlobalFilterUniforms {
287
287
  uInputSize: vec4<f32>,
288
288
  uInputPixel: vec4<f32>,
289
289
  uInputClamp: vec4<f32>,
@@ -332,7 +332,7 @@ fn mainFragment(
332
332
  ) -> @location(0) vec4<f32> {
333
333
  return textureSample(uTexture, uSampler, uv);
334
334
  }
335
- `;class qf extends sa{constructor(){const e=Ft.from({vertex:{source:wo,entryPoint:"mainVertex"},fragment:{source:wo,entryPoint:"mainFragment"},name:"passthrough-filter"}),t=ls.from({vertex:jf,fragment:Xf,name:"passthrough-filter"});super({gpuProgram:e,glProgram:t})}}class Yf{constructor(e){this._renderer=e}push(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"filter",canBundle:!1,action:"pushFilter",container:t,filterEffect:e})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}execute(e){e.action==="pushFilter"?this._renderer.filter.push(e):e.action==="popFilter"&&this._renderer.filter.pop()}destroy(){this._renderer=null}}Yf.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"filter"};const ry=new Er({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:"float32x2",stride:8,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});class ny{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new Ee,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.firstEnabledIndex=-1,this.lastEnabledIndex=-1}}class Kf{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new rt({uInputSize:{value:new Float32Array(4),type:"vec4<f32>"},uInputPixel:{value:new Float32Array(4),type:"vec4<f32>"},uInputClamp:{value:new Float32Array(4),type:"vec4<f32>"},uOutputFrame:{value:new Float32Array(4),type:"vec4<f32>"},uGlobalFrame:{value:new Float32Array(4),type:"vec4<f32>"},uOutputTexture:{value:new Float32Array(4),type:"vec4<f32>"}}),this._globalFilterBindGroup=new Mt({}),this.renderer=e}get activeBackTexture(){return this._activeFilterData?.backTexture}push(e){const t=this.renderer,s=e.filterEffect.filters,r=this._pushFilterData();r.skip=!1,r.filters=s,r.container=e.container,r.outputRenderSurface=t.renderTarget.renderSurface;const n=t.renderTarget.renderTarget.colorTexture.source,o=n.resolution,a=n.antialias;if(s.every(c=>!c.enabled)){r.skip=!0;return}const l=r.bounds;if(this._calculateFilterArea(e,l),this._calculateFilterBounds(r,t.renderTarget.rootViewPort,a,o,1),r.skip)return;const h=this._getPreviousFilterData();this._setupFilterTextures(r,l,t,h)}generateFilteredTexture({texture:e,filters:t}){if(t.every(c=>!c.enabled))return e;const s=this._pushFilterData();this._activeFilterData=s,s.skip=!1,s.filters=t;const r=e.source,n=r.resolution,o=r.antialias,a=s.bounds;if(a.clear(),a.addRect(e.frame),this._calculateFilterBounds(s,a.rectangle,o,n,0),s.skip)return this._popFilterData(),e;s.outputRenderSurface=Te.getOptimalTexture({width:a.width,height:a.height,resolution:s.resolution,antialias:s.antialias}),s.backTexture=W.EMPTY,s.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(s,!0);const h=s.outputRenderSurface;return h.source.alphaMode="premultiplied-alpha",this._popFilterData(),h}pop(){const e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&Te.returnTexture(t.backTexture),Te.returnTexture(t.inputTexture))}getBackTexture(e,t,s){const r=e.colorTexture.source._resolution,n=Te.getOptimalTexture({width:t.width,height:t.height,resolution:r});let o=t.minX,a=t.minY;s&&(o-=s.minX,a-=s.minY),o=Math.floor(o*r),a=Math.floor(a*r);const l=Math.ceil(t.width*r),h=Math.ceil(t.height*r);return this.renderer.renderTarget.copyToTexture(e,n,{x:o,y:a},{width:l,height:h},{x:0,y:0}),n}applyFilter(e,t,s,r){const n=this.renderer,o=this._activeFilterData,l=o.outputRenderSurface===s,h=this._findClosestFilterData(),c=h?h.inputTexture.source._resolution:n.renderTarget.rootRenderTarget.colorTexture.source._resolution;let u=0,d=0;l&&h&&(u=h.bounds.minX,d=h.bounds.minY),this._updateFilterUniforms(t,s,o,u,d,c,l,r);const f=e.enabled?e:this._getPassthroughFilter();this._setupBindGroupsAndRender(f,t,n)}calculateSpriteMatrix(e,t){const s=this._activeFilterData,r=e.set(s.inputTexture._source.width,0,0,s.inputTexture._source.height,s.bounds.minX,s.bounds.minY),n=t.worldTransform.copyTo(U.shared),o=t.renderGroup||t.parentRenderGroup;return o&&o.cacheToLocalTransform&&n.prepend(o.cacheToLocalTransform),n.invert(),r.prepend(n),r.scale(1/t.texture.orig.width,1/t.texture.orig.height),r.translate(t.anchor.x,t.anchor.y),r}destroy(){this._passthroughFilter?.destroy(!0),this._passthroughFilter=null}_getPassthroughFilter(){return this._passthroughFilter??(this._passthroughFilter=new qf),this._passthroughFilter}_setupBindGroupsAndRender(e,t,s){if(s.renderPipes.uniformBatch){const r=s.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(r,0)}else this._globalFilterBindGroup.setResource(this._filterGlobalUniforms,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,s.encoder.draw({geometry:ry,shader:e,state:e._state,topology:"triangle-list"}),s.type===Ke.WEBGL&&s.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,s,r){if(e.backTexture=W.EMPTY,e.inputTexture=Te.getOptimalTexture({width:t.width,height:t.height,resolution:e.resolution,antialias:e.antialias}),e.blendRequired){s.renderTarget.finishRenderPass();const n=s.renderTarget.getRenderTarget(e.outputRenderSurface);e.backTexture=this.getBackTexture(n,t,r?.bounds)}s.renderTarget.bind({target:e.inputTexture,clear:!0}),s.globalUniforms.push({offset:t})}_updateFilterUniforms(e,t,s,r,n,o,a,l){const h=this._filterGlobalUniforms.uniforms,c=h.uOutputFrame,u=h.uInputSize,d=h.uInputPixel,f=h.uInputClamp,p=h.uGlobalFrame,g=h.uOutputTexture;a?(c[0]=s.bounds.minX-r,c[1]=s.bounds.minY-n):(c[0]=0,c[1]=0),c[2]=e.frame.width,c[3]=e.frame.height,u[0]=e.source.width,u[1]=e.source.height,u[2]=1/u[0],u[3]=1/u[1],d[0]=e.source.pixelWidth,d[1]=e.source.pixelHeight,d[2]=1/d[0],d[3]=1/d[1],f[0]=.5*d[2],f[1]=.5*d[3],f[2]=e.frame.width*u[2]-.5*d[2],f[3]=e.frame.height*u[3]-.5*d[3];const m=this.renderer.renderTarget.rootRenderTarget.colorTexture;p[0]=r*o,p[1]=n*o,p[2]=m.source.width*o,p[3]=m.source.height*o,t instanceof W&&(t.source.resource=null);const _=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind({target:t,clear:!!l}),t instanceof W?(g[0]=t.frame.width,g[1]=t.frame.height):(g[0]=_.width,g[1]=_.height),g[2]=_.isRoot?-1:1,this._filterGlobalUniforms.update()}_findClosestFilterData(){for(let e=this._filterStackIndex-1;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_calculateFilterArea(e,t){if(e.renderables?Aa(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const r=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;r&&t.applyMatrix(r)}}_applyFiltersToTexture(e,t){const s=e.inputTexture,r=e.bounds,n=e.filters,o=e.firstEnabledIndex,a=e.lastEnabledIndex;if(this._globalFilterBindGroup.setResource(s.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),o===a)n[o].apply(this,s,e.outputRenderSurface,t);else{let l=e.inputTexture;const h=Te.getOptimalTexture({width:r.width,height:r.height,resolution:l.source._resolution});let c=h;for(let u=o;u<a;u++){const d=n[u];if(!d.enabled)continue;d.apply(this,l,c,!0);const f=l;l=c,c=f}n[a].apply(this,l,e.outputRenderSurface,t),Te.returnTexture(h)}}_calculateFilterBounds(e,t,s,r,n){const o=this.renderer,a=e.bounds,l=e.filters;let h=1/0,c=0,u=!0,d=!1,f=!1,p=!0,g=-1,m=-1;for(let _=0;_<l.length;_++){const y=l[_];if(!y.enabled)continue;if(g===-1&&(g=_),m=_,h=Math.min(h,y.resolution==="inherit"?r:y.resolution),c+=y.padding,y.antialias==="off"?u=!1:y.antialias==="inherit"&&u&&(u=s),y.clipToViewport||(p=!1),!!!(y.compatibleRenderers&o.type)){f=!1;break}if(y.blendRequired&&!(o.backBuffer?.useBackBuffer??!0)){z("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),f=!1;break}f=!0,d||(d=y.blendRequired)}if(!f){e.skip=!0;return}if(p&&a.fitBounds(0,t.width/r,0,t.height/r),a.scale(h).ceil().scale(1/h).pad((c|0)*n),!a.isPositive){e.skip=!0;return}e.antialias=u,e.resolution=h,e.blendRequired=d,e.firstEnabledIndex=g,e.lastEnabledIndex=m}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){for(let e=this._filterStackIndex-2;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new ny),this._filterStackIndex++,e}}Kf.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"filter"};var Zf=`in vec2 vMaskCoord;
335
+ `;class Qf extends ha{constructor(){const e=Lt.from({vertex:{source:Eo,entryPoint:"mainVertex"},fragment:{source:Eo,entryPoint:"mainFragment"},name:"passthrough-filter"}),t=us.from({vertex:Kf,fragment:Zf,name:"passthrough-filter"});super({gpuProgram:e,glProgram:t})}}class Jf{constructor(e){this._renderer=e}push(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"filter",canBundle:!1,action:"pushFilter",container:t,filterEffect:e})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}execute(e){e.action==="pushFilter"?this._renderer.filter.push(e):e.action==="popFilter"&&this._renderer.filter.pop()}destroy(){this._renderer=null}}Jf.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"filter"};const cy=new Si({attributes:{aPosition:{buffer:new Float32Array([0,0,1,0,1,1,0,1]),format:"float32x2",stride:8,offset:0}},indexBuffer:new Uint32Array([0,1,2,0,2,3])});class uy{constructor(){this.skip=!1,this.inputTexture=null,this.backTexture=null,this.filters=null,this.bounds=new Ee,this.container=null,this.blendRequired=!1,this.outputRenderSurface=null,this.firstEnabledIndex=-1,this.lastEnabledIndex=-1}}class ep{constructor(e){this._filterStackIndex=0,this._filterStack=[],this._filterGlobalUniforms=new Ze({uInputSize:{value:new Float32Array(4),type:"vec4<f32>"},uInputPixel:{value:new Float32Array(4),type:"vec4<f32>"},uInputClamp:{value:new Float32Array(4),type:"vec4<f32>"},uOutputFrame:{value:new Float32Array(4),type:"vec4<f32>"},uGlobalFrame:{value:new Float32Array(4),type:"vec4<f32>"},uOutputTexture:{value:new Float32Array(4),type:"vec4<f32>"}}),this._globalFilterBindGroup=new Pt({}),this.renderer=e}get activeBackTexture(){return this._activeFilterData?.backTexture}push(e){const t=this.renderer,s=e.filterEffect.filters,r=this._pushFilterData();r.skip=!1,r.filters=s,r.container=e.container,r.outputRenderSurface=t.renderTarget.renderSurface;const n=t.renderTarget.renderTarget.colorTexture.source,o=n.resolution,a=n.antialias;if(s.every(c=>!c.enabled)){r.skip=!0;return}const l=r.bounds;if(this._calculateFilterArea(e,l),this._calculateFilterBounds(r,t.renderTarget.rootViewPort,a,o,1),r.skip)return;const h=this._getPreviousFilterData();this._setupFilterTextures(r,l,t,h)}generateFilteredTexture({texture:e,filters:t}){if(t.every(c=>!c.enabled))return e;const s=this._pushFilterData();this._activeFilterData=s,s.skip=!1,s.filters=t;const r=e.source,n=r.resolution,o=r.antialias,a=s.bounds;if(a.clear(),a.addRect(e.frame),this._calculateFilterBounds(s,a.rectangle,o,n,0),s.skip)return this._popFilterData(),e;s.outputRenderSurface=Te.getOptimalTexture({width:a.width,height:a.height,resolution:s.resolution,antialias:s.antialias}),s.backTexture=W.EMPTY,s.inputTexture=e,this.renderer.renderTarget.finishRenderPass(),this._applyFiltersToTexture(s,!0);const h=s.outputRenderSurface;return h.source.alphaMode="premultiplied-alpha",this._popFilterData(),h}pop(){const e=this.renderer,t=this._popFilterData();t.skip||(e.globalUniforms.pop(),e.renderTarget.finishRenderPass(),this._activeFilterData=t,this._applyFiltersToTexture(t,!1),t.blendRequired&&Te.returnTexture(t.backTexture),Te.returnTexture(t.inputTexture))}getBackTexture(e,t,s){const r=e.colorTexture.source._resolution,n=Te.getOptimalTexture({width:t.width,height:t.height,resolution:r});let o=t.minX,a=t.minY;s&&(o-=s.minX,a-=s.minY),o=Math.floor(o*r),a=Math.floor(a*r);const l=Math.ceil(t.width*r),h=Math.ceil(t.height*r);return this.renderer.renderTarget.copyToTexture(e,n,{x:o,y:a},{width:l,height:h},{x:0,y:0}),n}applyFilter(e,t,s,r){const n=this.renderer,o=this._activeFilterData,l=o.outputRenderSurface===s,h=this._findClosestFilterData(),c=h?h.inputTexture.source._resolution:n.renderTarget.rootRenderTarget.colorTexture.source._resolution;let u=0,d=0;l&&h&&(u=h.bounds.minX,d=h.bounds.minY),this._updateFilterUniforms(t,s,o,u,d,c,l,r);const f=e.enabled?e:this._getPassthroughFilter();this._setupBindGroupsAndRender(f,t,n)}calculateSpriteMatrix(e,t){const s=this._activeFilterData,r=e.set(s.inputTexture._source.width,0,0,s.inputTexture._source.height,s.bounds.minX,s.bounds.minY),n=t.worldTransform.copyTo(U.shared),o=t.renderGroup||t.parentRenderGroup;return o&&o.cacheToLocalTransform&&n.prepend(o.cacheToLocalTransform),n.invert(),r.prepend(n),r.scale(1/t.texture.orig.width,1/t.texture.orig.height),r.translate(t.anchor.x,t.anchor.y),r}destroy(){this._passthroughFilter?.destroy(!0),this._passthroughFilter=null}_getPassthroughFilter(){return this._passthroughFilter??(this._passthroughFilter=new Qf),this._passthroughFilter}_setupBindGroupsAndRender(e,t,s){if(s.renderPipes.uniformBatch){const r=s.renderPipes.uniformBatch.getUboResource(this._filterGlobalUniforms);this._globalFilterBindGroup.setResource(r,0)}else this._globalFilterBindGroup.setResource(this._filterGlobalUniforms,0);this._globalFilterBindGroup.setResource(t.source,1),this._globalFilterBindGroup.setResource(t.source.style,2),e.groups[0]=this._globalFilterBindGroup,s.encoder.draw({geometry:cy,shader:e,state:e._state,topology:"triangle-list"}),s.type===Ke.WEBGL&&s.renderTarget.finishRenderPass()}_setupFilterTextures(e,t,s,r){if(e.backTexture=W.EMPTY,e.inputTexture=Te.getOptimalTexture({width:t.width,height:t.height,resolution:e.resolution,antialias:e.antialias}),e.blendRequired){s.renderTarget.finishRenderPass();const n=s.renderTarget.getRenderTarget(e.outputRenderSurface);e.backTexture=this.getBackTexture(n,t,r?.bounds)}s.renderTarget.bind({target:e.inputTexture,clear:!0}),s.globalUniforms.push({offset:t})}_updateFilterUniforms(e,t,s,r,n,o,a,l){const h=this._filterGlobalUniforms.uniforms,c=h.uOutputFrame,u=h.uInputSize,d=h.uInputPixel,f=h.uInputClamp,p=h.uGlobalFrame,g=h.uOutputTexture;a?(c[0]=s.bounds.minX-r,c[1]=s.bounds.minY-n):(c[0]=0,c[1]=0),c[2]=e.frame.width,c[3]=e.frame.height,u[0]=e.source.width,u[1]=e.source.height,u[2]=1/u[0],u[3]=1/u[1],d[0]=e.source.pixelWidth,d[1]=e.source.pixelHeight,d[2]=1/d[0],d[3]=1/d[1],f[0]=.5*d[2],f[1]=.5*d[3],f[2]=e.frame.width*u[2]-.5*d[2],f[3]=e.frame.height*u[3]-.5*d[3];const m=this.renderer.renderTarget.rootRenderTarget.colorTexture;p[0]=r*o,p[1]=n*o,p[2]=m.source.width*o,p[3]=m.source.height*o,t instanceof W&&(t.source.resource=null);const _=this.renderer.renderTarget.getRenderTarget(t);this.renderer.renderTarget.bind({target:t,clear:!!l}),t instanceof W?(g[0]=t.frame.width,g[1]=t.frame.height):(g[0]=_.width,g[1]=_.height),g[2]=_.isRoot?-1:1,this._filterGlobalUniforms.update()}_findClosestFilterData(){for(let e=this._filterStackIndex-1;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_calculateFilterArea(e,t){if(e.renderables?Oa(e.renderables,t):e.filterEffect.filterArea?(t.clear(),t.addRect(e.filterEffect.filterArea),t.applyMatrix(e.container.worldTransform)):e.container.getFastGlobalBounds(!0,t),e.container){const r=(e.container.renderGroup||e.container.parentRenderGroup).cacheToLocalTransform;r&&t.applyMatrix(r)}}_applyFiltersToTexture(e,t){const s=e.inputTexture,r=e.bounds,n=e.filters,o=e.firstEnabledIndex,a=e.lastEnabledIndex;if(this._globalFilterBindGroup.setResource(s.source.style,2),this._globalFilterBindGroup.setResource(e.backTexture.source,3),o===a)n[o].apply(this,s,e.outputRenderSurface,t);else{let l=e.inputTexture;const h=Te.getOptimalTexture({width:r.width,height:r.height,resolution:l.source._resolution});let c=h;for(let u=o;u<a;u++){const d=n[u];if(!d.enabled)continue;d.apply(this,l,c,!0);const f=l;l=c,c=f}n[a].apply(this,l,e.outputRenderSurface,t),Te.returnTexture(h)}}_calculateFilterBounds(e,t,s,r,n){const o=this.renderer,a=e.bounds,l=e.filters;let h=1/0,c=0,u=!0,d=!1,f=!1,p=!0,g=-1,m=-1;for(let _=0;_<l.length;_++){const y=l[_];if(!y.enabled)continue;if(g===-1&&(g=_),m=_,h=Math.min(h,y.resolution==="inherit"?r:y.resolution),c+=y.padding,y.antialias==="off"?u=!1:y.antialias==="inherit"&&u&&(u=s),y.clipToViewport||(p=!1),!!!(y.compatibleRenderers&o.type)){f=!1;break}if(y.blendRequired&&!(o.backBuffer?.useBackBuffer??!0)){H("Blend filter requires backBuffer on WebGL renderer to be enabled. Set `useBackBuffer: true` in the renderer options."),f=!1;break}f=!0,d||(d=y.blendRequired)}if(!f){e.skip=!0;return}if(p&&a.fitBounds(0,t.width/r,0,t.height/r),a.scale(h).ceil().scale(1/h).pad((c|0)*n),!a.isPositive){e.skip=!0;return}e.antialias=u,e.resolution=h,e.blendRequired=d,e.firstEnabledIndex=g,e.lastEnabledIndex=m}_popFilterData(){return this._filterStackIndex--,this._filterStack[this._filterStackIndex]}_getPreviousFilterData(){for(let e=this._filterStackIndex-2;e>=0;e--){const t=this._filterStack[e];if(!t.skip)return t}return null}_pushFilterData(){let e=this._filterStack[this._filterStackIndex];return e||(e=this._filterStack[this._filterStackIndex]=new uy),this._filterStackIndex++,e}}ep.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"filter"};var tp=`in vec2 vMaskCoord;
336
336
  in vec2 vTextureCoord;
337
337
 
338
338
  uniform sampler2D uTexture;
@@ -372,7 +372,7 @@ void main(void)
372
372
 
373
373
  finalColor = original * a;
374
374
  }
375
- `,Qf=`in vec2 aPosition;
375
+ `,sp=`in vec2 aPosition;
376
376
 
377
377
  out vec2 vTextureCoord;
378
378
  out vec2 vMaskCoord;
@@ -409,7 +409,7 @@ void main(void)
409
409
  vTextureCoord = filterTextureCoord(aPosition);
410
410
  vMaskCoord = getFilterCoord(aPosition);
411
411
  }
412
- `,To=`struct GlobalFilterUniforms {
412
+ `,Po=`struct GlobalFilterUniforms {
413
413
  uInputSize:vec4<f32>,
414
414
  uInputPixel:vec4<f32>,
415
415
  uInputClamp:vec4<f32>,
@@ -513,7 +513,7 @@ fn mainFragment(
513
513
 
514
514
  return source * a;
515
515
  }
516
- `;class Jf extends sa{constructor(e){const{sprite:t,...s}=e,r=new Uo(t.texture),n=new rt({uFilterMatrix:{value:new U,type:"mat3x3<f32>"},uMaskClamp:{value:r.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"},uChannel:{value:e.channel==="alpha"?1:0,type:"f32"}}),o=Ft.from({vertex:{source:To,entryPoint:"mainVertex"},fragment:{source:To,entryPoint:"mainFragment"}}),a=ls.from({vertex:Qf,fragment:Zf,name:"mask-filter"});super({...s,gpuProgram:o,glProgram:a,clipToViewport:!1,resources:{filterUniforms:n,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=r}setSprite(e){this.sprite=e;const t=this._getSafeTexture();this._textureMatrix.texture=t,this.resources.uMaskTexture=t.source}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}set channel(e){this.resources.filterUniforms.uniforms.uChannel=e==="alpha"?1:0}get channel(){return this.resources.filterUniforms.uniforms.uChannel===1?"alpha":"red"}apply(e,t,s,r){const n=this._getSafeTexture();this._textureMatrix.texture=n,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=n.source,e.applyFilter(this,t,s,r)}_getSafeTexture(){const e=this.sprite.texture;return e.destroyed||!e.source||e.source.destroyed?(z("[MaskFilter] The mask texture was destroyed while the mask is still in use. Remove the mask before destroying its texture."),W.EMPTY):e}destroy(e=!1){this._textureMatrix.destroy(),super.destroy(e)}}class oy{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&(this.graphicsData.destroy(),this.graphicsData=null)}destroy(){this.reset()}}class ay{constructor(){this.instructions=new br}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}}const Ba=class So{constructor(e){this._renderer=e,this._managedContexts=new nt({renderer:e,type:"resource",name:"graphicsContext"})}init(e){So.defaultOptions.bezierSmoothness=e?.bezierSmoothness??So.defaultOptions.bezierSmoothness}getContextRenderData(e){return this.getGpuContext(e).graphicsData||this._initContextRenderData(e)}updateGpuContext(e){const t=e._gpuData,s=!!t[this._renderer.uid],r=t[this._renderer.uid]||this._initContext(e);return(e.dirty||!s)&&(s&&r.reset(),r.isBatchable=!1,e.dirty=!1),r}getGpuContext(e){return e._gpuData[this._renderer.uid]||this._initContext(e)}_initContextRenderData(e){const t=new ay,s=this.getGpuContext(e);return s.graphicsData=t,t.init(),t}_initContext(e){const t=new oy;return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};Ba.extension={type:[S.CanvasSystem],name:"graphicsContext"};Ba.defaultOptions={bezierSmoothness:.5};let ep=Ba;class Ia{constructor(e,t){this.state=pt.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new nt({renderer:e,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){return!1}addRenderable(e,t){this._managedGraphics.add(e),this.renderer.renderPipes.batch.break(t),t.add(e)}updateRenderable(e){}execute(e){e.isRenderable&&this._adaptor.execute(this,e)}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null}}Ia.extension={type:[S.CanvasPipes],name:"graphics"};function Ga(i,e,t){const s=(i>>24&255)/255;e[t++]=(i&255)/255*s,e[t++]=(i>>8&255)/255*s,e[t++]=(i>>16&255)/255*s,e[t++]=s}class tp{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(e=>{Se.return(e)}),this.batches.length=0}}class Da{constructor(e,t){this.state=pt.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new nt({renderer:e,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){const t=e.context,s=!!e._gpuData,n=this.renderer.graphicsContext.updateGpuContext(t);return!!(n.isBatchable||s!==n.isBatchable)}addRenderable(e,t){const r=this.renderer.graphicsContext.updateGpuContext(e.context);(e.didViewUpdate||!e._gpuData[this.renderer.uid])&&this._rebuild(e),r.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){const s=this._getGpuDataForRenderable(e).batches;for(let r=0;r<s.length;r++){const n=s[r];n._batcher.updateElement(n)}}execute(e){if(!e.isRenderable)return;const t=this.renderer,s=e.context;if(!t.graphicsContext.getGpuContext(s).batches.length)return;const n=s.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;const o=n.resources.localUniforms.uniforms;o.uTransformMatrix=e.groupTransform,o.uRound=t._roundPixels|e._roundPixels,Ga(e.groupColorAlpha,o.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){const t=this._getGpuDataForRenderable(e),r=this.renderer.graphicsContext.updateGpuContext(e.context);t.destroy(),r.isBatchable&&this._updateBatchesForRenderable(e,t)}_addToBatcher(e,t){const s=this.renderer.renderPipes.batch,r=this._getGpuDataForRenderable(e).batches;for(let n=0;n<r.length;n++){const o=r[n];s.addToBatch(o,t)}}_getGpuDataForRenderable(e){return e._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(e)}_initGpuDataForRenderable(e){const t=new tp;return e._gpuData[this.renderer.uid]=t,this._managedGraphics.add(e),t}_updateBatchesForRenderable(e,t){const s=e.context,n=this.renderer.graphicsContext.getGpuContext(s),o=this.renderer._roundPixels|e._roundPixels;t.batches=n.batches.map(a=>{const l=Se.get(Gr);return a.copyTo(l),l.renderable=e,l.roundPixels=o,l})}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}}Da.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"graphics"};q.add(Ia);q.add(Da);q.add(ep);q.add(Fr);class Pe extends wr{constructor(e){e instanceof qe&&(e={context:e});const{context:t,roundPixels:s,...r}=e||{};super({label:"Graphics",...r}),this.renderPipeId="graphics",t?this.context=t:(this.context=this._ownedContext=new qe,this.context.autoGarbageCollect=this.autoGarbageCollect),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=s??!1}set context(e){e!==this._context&&(this._context&&(this._context.off("update",this.onViewUpdate,this),this._context.off("unload",this.unload,this)),this._context=e,this._context.on("update",this.onViewUpdate,this),this._context.on("unload",this.unload,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(e){return this._context.containsPoint(e)}destroy(e){this._ownedContext&&!e?this._ownedContext.destroy(e):(e===!0||e?.context===!0)&&this._context.destroy(e),this._context?.off("update",this.onViewUpdate,this),this._context?.off("unload",this.unload,this),this._ownedContext=null,this._context=null,super.destroy(e)}_onTouch(e){this._gcLastUsed=e,this._context._gcLastUsed=e}_callContextMethod(e,t){return this.context[e](...t),this}setFillStyle(...e){return this._callContextMethod("setFillStyle",e)}setStrokeStyle(...e){return this._callContextMethod("setStrokeStyle",e)}fill(...e){return this._callContextMethod("fill",e)}stroke(...e){return this._callContextMethod("stroke",e)}texture(...e){return this._callContextMethod("texture",e)}beginPath(){return this._callContextMethod("beginPath",[])}cut(){return this._callContextMethod("cut",[])}arc(...e){return this._callContextMethod("arc",e)}arcTo(...e){return this._callContextMethod("arcTo",e)}arcToSvg(...e){return this._callContextMethod("arcToSvg",e)}bezierCurveTo(...e){return this._callContextMethod("bezierCurveTo",e)}closePath(){return this._callContextMethod("closePath",[])}ellipse(...e){return this._callContextMethod("ellipse",e)}circle(...e){return this._callContextMethod("circle",e)}path(...e){return this._callContextMethod("path",e)}lineTo(...e){return this._callContextMethod("lineTo",e)}moveTo(...e){return this._callContextMethod("moveTo",e)}quadraticCurveTo(...e){return this._callContextMethod("quadraticCurveTo",e)}rect(...e){return this._callContextMethod("rect",e)}roundRect(...e){return this._callContextMethod("roundRect",e)}poly(...e){return this._callContextMethod("poly",e)}regularPoly(...e){return this._callContextMethod("regularPoly",e)}roundPoly(...e){return this._callContextMethod("roundPoly",e)}roundShape(...e){return this._callContextMethod("roundShape",e)}filletRect(...e){return this._callContextMethod("filletRect",e)}chamferRect(...e){return this._callContextMethod("chamferRect",e)}star(...e){return this._callContextMethod("star",e)}svg(...e){return this._callContextMethod("svg",e)}restore(...e){return this._callContextMethod("restore",e)}save(){return this._callContextMethod("save",[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod("resetTransform",[])}rotateTransform(...e){return this._callContextMethod("rotate",e)}scaleTransform(...e){return this._callContextMethod("scale",e)}setTransform(...e){return this._callContextMethod("setTransform",e)}transform(...e){return this._callContextMethod("transform",e)}translateTransform(...e){return this._callContextMethod("translate",e)}clear(){return this._callContextMethod("clear",[])}get fillStyle(){return this._context.fillStyle}set fillStyle(e){this._context.fillStyle=e}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(e){this._context.strokeStyle=e}clone(e=!1){return e?new Pe(this._context.clone()):(this._ownedContext=null,new Pe(this._context))}lineStyle(e,t,s){H(ue,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const r={};return e&&(r.width=e),t&&(r.color=t),s&&(r.alpha=s),this.context.strokeStyle=r,this}beginFill(e,t){H(ue,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const s={};return e!==void 0&&(s.color=e),t!==void 0&&(s.alpha=t),this.context.fillStyle=s,this}endFill(){H(ue,"Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style."),this.context.fill();const e=this.context.strokeStyle;return(e.width!==qe.defaultStrokeStyle.width||e.color!==qe.defaultStrokeStyle.color||e.alpha!==qe.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return H(ue,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",e)}drawEllipse(...e){return H(ue,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",e)}drawPolygon(...e){return H(ue,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",e)}drawRect(...e){return H(ue,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",e)}drawRoundedRect(...e){return H(ue,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",e)}drawStar(...e){return H(ue,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",e)}}const ii={name:"local-uniform-bit",vertex:{header:`
516
+ `;class ip extends ha{constructor(e){const{sprite:t,...s}=e,r=new jo(t.texture),n=new Ze({uFilterMatrix:{value:new U,type:"mat3x3<f32>"},uMaskClamp:{value:r.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"},uChannel:{value:e.channel==="alpha"?1:0,type:"f32"}}),o=Lt.from({vertex:{source:Po,entryPoint:"mainVertex"},fragment:{source:Po,entryPoint:"mainFragment"}}),a=us.from({vertex:sp,fragment:tp,name:"mask-filter"});super({...s,gpuProgram:o,glProgram:a,clipToViewport:!1,resources:{filterUniforms:n,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=r}setSprite(e){this.sprite=e;const t=this._getSafeTexture();this._textureMatrix.texture=t,this.resources.uMaskTexture=t.source}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}set channel(e){this.resources.filterUniforms.uniforms.uChannel=e==="alpha"?1:0}get channel(){return this.resources.filterUniforms.uniforms.uChannel===1?"alpha":"red"}apply(e,t,s,r){const n=this._getSafeTexture();this._textureMatrix.texture=n,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=n.source,e.applyFilter(this,t,s,r)}_getSafeTexture(){const e=this.sprite.texture;return e.destroyed||!e.source||e.source.destroyed?(H("[MaskFilter] The mask texture was destroyed while the mask is still in use. Remove the mask before destroying its texture."),W.EMPTY):e}destroy(e=!1){this._textureMatrix.destroy(),super.destroy(e)}}class dy{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&(this.graphicsData.destroy(),this.graphicsData=null)}destroy(){this.reset()}}class fy{constructor(){this.instructions=new Tr}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}}const Ua=class Ao{constructor(e){this._renderer=e,this._managedContexts=new at({renderer:e,type:"resource",name:"graphicsContext"})}init(e){Ao.defaultOptions.bezierSmoothness=e?.bezierSmoothness??Ao.defaultOptions.bezierSmoothness}getContextRenderData(e){return this.getGpuContext(e).graphicsData||this._initContextRenderData(e)}updateGpuContext(e){const t=e._gpuData,s=!!t[this._renderer.uid],r=t[this._renderer.uid]||this._initContext(e);return(e.dirty||!s)&&(s&&r.reset(),r.isBatchable=!1,e.dirty=!1),r}getGpuContext(e){return e._gpuData[this._renderer.uid]||this._initContext(e)}_initContextRenderData(e){const t=new fy,s=this.getGpuContext(e);return s.graphicsData=t,t.init(),t}_initContext(e){const t=new dy;return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};Ua.extension={type:[S.CanvasSystem],name:"graphicsContext"};Ua.defaultOptions={bezierSmoothness:.5};let rp=Ua;class Na{constructor(e,t){this.state=_t.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new at({renderer:e,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){return!1}addRenderable(e,t){this._managedGraphics.add(e),this.renderer.renderPipes.batch.break(t),t.add(e)}updateRenderable(e){}execute(e){e.isRenderable&&this._adaptor.execute(this,e)}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null}}Na.extension={type:[S.CanvasPipes],name:"graphics"};function za(i,e,t){const s=(i>>24&255)/255;e[t++]=(i&255)/255*s,e[t++]=(i>>8&255)/255*s,e[t++]=(i>>16&255)/255*s,e[t++]=s}class np{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(e=>{Se.return(e)}),this.batches.length=0}}class Ha{constructor(e,t){this.state=_t.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new at({renderer:e,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){const t=e.context,s=!!e._gpuData,n=this.renderer.graphicsContext.updateGpuContext(t);return!!(n.isBatchable||s!==n.isBatchable)}addRenderable(e,t){const r=this.renderer.graphicsContext.updateGpuContext(e.context);(e.didViewUpdate||!e._gpuData[this.renderer.uid])&&this._rebuild(e),r.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){const s=this._getGpuDataForRenderable(e).batches;for(let r=0;r<s.length;r++){const n=s[r];n._batcher.updateElement(n)}}execute(e){if(!e.isRenderable)return;const t=this.renderer,s=e.context;if(!t.graphicsContext.getGpuContext(s).batches.length)return;const n=s.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;const o=n.resources.localUniforms.uniforms;o.uTransformMatrix=e.groupTransform,o.uRound=t._roundPixels|e._roundPixels,za(e.groupColorAlpha,o.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){const t=this._getGpuDataForRenderable(e),r=this.renderer.graphicsContext.updateGpuContext(e.context);t.destroy(),r.isBatchable&&this._updateBatchesForRenderable(e,t)}_addToBatcher(e,t){const s=this.renderer.renderPipes.batch,r=this._getGpuDataForRenderable(e).batches;for(let n=0;n<r.length;n++){const o=r[n];s.addToBatch(o,t)}}_getGpuDataForRenderable(e){return e._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(e)}_initGpuDataForRenderable(e){const t=new np;return e._gpuData[this.renderer.uid]=t,this._managedGraphics.add(e),t}_updateBatchesForRenderable(e,t){const s=e.context,n=this.renderer.graphicsContext.getGpuContext(s),o=this.renderer._roundPixels|e._roundPixels;t.batches=n.batches.map(a=>{const l=Se.get(Fr);return a.copyTo(l),l.renderable=e,l.roundPixels=o,l})}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}}Ha.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"graphics"};q.add(Na);q.add(Ha);q.add(rp);q.add(Lr);class Pe extends Cr{constructor(e){e instanceof qe&&(e={context:e});const{context:t,roundPixels:s,...r}=e||{};super({label:"Graphics",...r}),this.renderPipeId="graphics",t?this.context=t:(this.context=this._ownedContext=new qe,this.context.autoGarbageCollect=this.autoGarbageCollect),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=s??!1}set context(e){e!==this._context&&(this._context&&(this._context.off("update",this.onViewUpdate,this),this._context.off("unload",this.unload,this)),this._context=e,this._context.on("update",this.onViewUpdate,this),this._context.on("unload",this.unload,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(e){return this._context.containsPoint(e)}destroy(e){this._ownedContext&&!e?this._ownedContext.destroy(e):(e===!0||e?.context===!0)&&this._context.destroy(e),this._context?.off("update",this.onViewUpdate,this),this._context?.off("unload",this.unload,this),this._ownedContext=null,this._context=null,super.destroy(e)}_onTouch(e){this._gcLastUsed=e,this._context._gcLastUsed=e}_callContextMethod(e,t){return this.context[e](...t),this}setFillStyle(...e){return this._callContextMethod("setFillStyle",e)}setStrokeStyle(...e){return this._callContextMethod("setStrokeStyle",e)}fill(...e){return this._callContextMethod("fill",e)}stroke(...e){return this._callContextMethod("stroke",e)}texture(...e){return this._callContextMethod("texture",e)}beginPath(){return this._callContextMethod("beginPath",[])}cut(){return this._callContextMethod("cut",[])}arc(...e){return this._callContextMethod("arc",e)}arcTo(...e){return this._callContextMethod("arcTo",e)}arcToSvg(...e){return this._callContextMethod("arcToSvg",e)}bezierCurveTo(...e){return this._callContextMethod("bezierCurveTo",e)}closePath(){return this._callContextMethod("closePath",[])}ellipse(...e){return this._callContextMethod("ellipse",e)}circle(...e){return this._callContextMethod("circle",e)}path(...e){return this._callContextMethod("path",e)}lineTo(...e){return this._callContextMethod("lineTo",e)}moveTo(...e){return this._callContextMethod("moveTo",e)}quadraticCurveTo(...e){return this._callContextMethod("quadraticCurveTo",e)}rect(...e){return this._callContextMethod("rect",e)}roundRect(...e){return this._callContextMethod("roundRect",e)}poly(...e){return this._callContextMethod("poly",e)}regularPoly(...e){return this._callContextMethod("regularPoly",e)}roundPoly(...e){return this._callContextMethod("roundPoly",e)}roundShape(...e){return this._callContextMethod("roundShape",e)}filletRect(...e){return this._callContextMethod("filletRect",e)}chamferRect(...e){return this._callContextMethod("chamferRect",e)}star(...e){return this._callContextMethod("star",e)}svg(...e){return this._callContextMethod("svg",e)}restore(...e){return this._callContextMethod("restore",e)}save(){return this._callContextMethod("save",[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod("resetTransform",[])}rotateTransform(...e){return this._callContextMethod("rotate",e)}scaleTransform(...e){return this._callContextMethod("scale",e)}setTransform(...e){return this._callContextMethod("setTransform",e)}transform(...e){return this._callContextMethod("transform",e)}translateTransform(...e){return this._callContextMethod("translate",e)}clear(){return this._callContextMethod("clear",[])}get fillStyle(){return this._context.fillStyle}set fillStyle(e){this._context.fillStyle=e}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(e){this._context.strokeStyle=e}clone(e=!1){return e?new Pe(this._context.clone()):(this._ownedContext=null,new Pe(this._context))}lineStyle(e,t,s){z(de,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const r={};return e&&(r.width=e),t&&(r.color=t),s&&(r.alpha=s),this.context.strokeStyle=r,this}beginFill(e,t){z(de,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const s={};return e!==void 0&&(s.color=e),t!==void 0&&(s.alpha=t),this.context.fillStyle=s,this}endFill(){z(de,"Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style."),this.context.fill();const e=this.context.strokeStyle;return(e.width!==qe.defaultStrokeStyle.width||e.color!==qe.defaultStrokeStyle.color||e.alpha!==qe.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return z(de,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",e)}drawEllipse(...e){return z(de,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",e)}drawPolygon(...e){return z(de,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",e)}drawRect(...e){return z(de,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",e)}drawRoundedRect(...e){return z(de,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",e)}drawStar(...e){return z(de,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",e)}}const ni={name:"local-uniform-bit",vertex:{header:`
517
517
 
518
518
  struct LocalUniforms {
519
519
  uTransformMatrix:mat3x3<f32>,
@@ -530,7 +530,7 @@ fn mainFragment(
530
530
  {
531
531
  vPosition = vec4(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
532
532
  }
533
- `}},sp={...ii,vertex:{...ii.vertex,header:ii.vertex.header.replace("group(1)","group(2)")}},Fa={name:"local-uniform-bit",vertex:{header:`
533
+ `}},op={...ni,vertex:{...ni.vertex,header:ni.vertex.header.replace("group(1)","group(2)")}},Wa={name:"local-uniform-bit",vertex:{header:`
534
534
 
535
535
  uniform mat3 uTransformMatrix;
536
536
  uniform vec4 uColor;
@@ -543,18 +543,18 @@ fn mainFragment(
543
543
  {
544
544
  gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
545
545
  }
546
- `}};class ip extends wr{constructor(e,t){const{text:s,resolution:r,style:n,anchor:o,width:a,height:l,roundPixels:h,...c}=e;super({...c}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=s??"",this.style=n,this.resolution=r??null,this.allowChildren=!1,this._anchor=new Ce({_onUpdate:()=>{this.onViewUpdate()}}),o&&(this.anchor=o),this.roundPixels=h??!1,a!==void 0&&(this.width=a),l!==void 0&&(this.height=l)}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}set text(e){e=e.toString(),this._text!==e&&(this._text=e,this.onViewUpdate())}get text(){return this._text}set resolution(e){this._autoResolution=e===null,this._resolution=e,this.onViewUpdate()}get resolution(){return this._resolution}get style(){return this._style}set style(e){e||(e={}),this._style?.off("update",this.onViewUpdate,this),e instanceof this._styleClass?this._style=e:this._style=new this._styleClass(e),this._style.on("update",this.onViewUpdate,this),this.onViewUpdate()}get width(){return Math.abs(this.scale.x)*this.bounds.width}set width(e){this._setWidth(e,this.bounds.width)}get height(){return Math.abs(this.scale.y)*this.bounds.height}set height(e){this._setHeight(e,this.bounds.height)}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this.bounds.width,e.height=Math.abs(this.scale.y)*this.bounds.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this.bounds.width),t!==void 0&&this._setHeight(t,this.bounds.height)}containsPoint(e){const t=this.bounds.width,s=this.bounds.height,r=-t*this.anchor.x;let n=0;return e.x>=r&&e.x<=r+t&&(n=-s*this.anchor.y,e.y>=n&&e.y<=n+s)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){this._style?.off("update",this.onViewUpdate,this),super.destroy(e),this.owner=null,this._bounds=null,this._anchor=null,(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._text=null}get styleKey(){return`${this._text}:${this._style.styleKey}:${this._resolution}`}}function rp(i,e){let t=i[0]??{};return(typeof t=="string"||i[1])&&(H(ue,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:i[1]}),t}let Nt=null,vt=null;function ly(i,e){Nt||(Nt=ee.get().createCanvas(256,128),vt=Nt.getContext("2d",{willReadFrequently:!0}),vt.globalCompositeOperation="copy",vt.globalAlpha=1),(Nt.width<i||Nt.height<e)&&(Nt.width=es(i),Nt.height=es(e))}function Mc(i,e,t){for(let s=0,r=4*t*e;s<e;++s,r+=4)if(i[r+3]!==0)return!1;return!0}function kc(i,e,t,s,r){const n=4*e;for(let o=s,a=s*n+4*t;o<=r;++o,a+=n)if(i[a+3]!==0)return!1;return!0}function np(...i){let e=i[0];e.canvas||(e={canvas:i[0],resolution:i[1]});const{canvas:t}=e,s=Math.min(e.resolution??1,1),r=e.width??t.width,n=e.height??t.height;let o=e.output;if(ly(r,n),!vt)throw new TypeError("Failed to get canvas 2D context");vt.drawImage(t,0,0,r,n,0,0,r*s,n*s);const l=vt.getImageData(0,0,r,n).data;let h=0,c=0,u=r-1,d=n-1;for(;c<n&&Mc(l,r,c);)++c;if(c===n)return te.EMPTY;for(;Mc(l,r,d);)--d;for(;kc(l,r,h,c,d);)++h;for(;kc(l,r,u,c,d);)--u;return++u,++d,vt.globalCompositeOperation="source-over",vt.strokeRect(h,c,u-h,d-c),vt.globalCompositeOperation="copy",o??(o=new te),o.set(h/s,c/s,(u-h)/s,(d-c)/s),o}/**
546
+ `}};class ap extends Cr{constructor(e,t){const{text:s,resolution:r,style:n,anchor:o,width:a,height:l,roundPixels:h,...c}=e;super({...c}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=s??"",this.style=n,this.resolution=r??null,this.allowChildren=!1,this._anchor=new Ce({_onUpdate:()=>{this.onViewUpdate()}}),o&&(this.anchor=o),this.roundPixels=h??!1,a!==void 0&&(this.width=a),l!==void 0&&(this.height=l)}get anchor(){return this._anchor}set anchor(e){typeof e=="number"?this._anchor.set(e):this._anchor.copyFrom(e)}set text(e){e=e.toString(),this._text!==e&&(this._text=e,this.onViewUpdate())}get text(){return this._text}set resolution(e){this._autoResolution=e===null,this._resolution=e,this.onViewUpdate()}get resolution(){return this._resolution}get style(){return this._style}set style(e){e||(e={}),this._style?.off("update",this.onViewUpdate,this),e instanceof this._styleClass?this._style=e:this._style=new this._styleClass(e),this._style.on("update",this.onViewUpdate,this),this.onViewUpdate()}get width(){return Math.abs(this.scale.x)*this.bounds.width}set width(e){this._setWidth(e,this.bounds.width)}get height(){return Math.abs(this.scale.y)*this.bounds.height}set height(e){this._setHeight(e,this.bounds.height)}getSize(e){return e||(e={}),e.width=Math.abs(this.scale.x)*this.bounds.width,e.height=Math.abs(this.scale.y)*this.bounds.height,e}setSize(e,t){typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,this.bounds.width),t!==void 0&&this._setHeight(t,this.bounds.height)}containsPoint(e){const t=this.bounds.width,s=this.bounds.height,r=-t*this.anchor.x;let n=0;return e.x>=r&&e.x<=r+t&&(n=-s*this.anchor.y,e.y>=n&&e.y<=n+s)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){this._style?.off("update",this.onViewUpdate,this),super.destroy(e),this.owner=null,this._bounds=null,this._anchor=null,(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._text=null}get styleKey(){return`${this._text}:${this._style.styleKey}:${this._resolution}`}}function lp(i,e){let t=i[0]??{};return(typeof t=="string"||i[1])&&(z(de,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:i[1]}),t}let Ht=null,St=null;function py(i,e){Ht||(Ht=ee.get().createCanvas(256,128),St=Ht.getContext("2d",{willReadFrequently:!0}),St.globalCompositeOperation="copy",St.globalAlpha=1),(Ht.width<i||Ht.height<e)&&(Ht.width=is(i),Ht.height=is(e))}function Ec(i,e,t){for(let s=0,r=4*t*e;s<e;++s,r+=4)if(i[r+3]!==0)return!1;return!0}function Pc(i,e,t,s,r){const n=4*e;for(let o=s,a=s*n+4*t;o<=r;++o,a+=n)if(i[a+3]!==0)return!1;return!0}function hp(...i){let e=i[0];e.canvas||(e={canvas:i[0],resolution:i[1]});const{canvas:t}=e,s=Math.min(e.resolution??1,1),r=e.width??t.width,n=e.height??t.height;let o=e.output;if(py(r,n),!St)throw new TypeError("Failed to get canvas 2D context");St.drawImage(t,0,0,r,n,0,0,r*s,n*s);const l=St.getImageData(0,0,r,n).data;let h=0,c=0,u=r-1,d=n-1;for(;c<n&&Ec(l,r,c);)++c;if(c===n)return te.EMPTY;for(;Ec(l,r,d);)--d;for(;Pc(l,r,h,c,d);)++h;for(;Pc(l,r,u,c,d);)--u;return++u,++d,St.globalCompositeOperation="source-over",St.strokeRect(h,c,u-h,d-c),St.globalCompositeOperation="copy",o??(o=new te),o.set(h/s,c/s,(u-h)/s,(d-c)/s),o}/**
547
547
  * tiny-lru
548
548
  *
549
549
  * @copyright 2026 Jason Mulligan <jason.mulligan@avoidwork.com>
550
550
  * @license BSD-3-Clause
551
551
  * @version 11.4.7
552
- */class hy{constructor(e=0,t=0,s=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=s,this.size=0,this.ttl=t}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(e){if(this.has(e)){const t=this.items[e];delete this.items[e],this.size--,t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),this.last===t&&(this.last=t.prev)}return this}entries(e=this.keys()){const t=new Array(e.length);for(let s=0;s<e.length;s++){const r=e[s];t[s]=[r,this.get(r)]}return t}evict(e=!1){if(e||this.size>0){const t=this.first;delete this.items[t.key],--this.size===0?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(e){let t;return this.has(e)&&(t=this.items[e].expiry),t}get(e){const t=this.items[e];if(t!==void 0){if(this.ttl>0&&t.expiry<=Date.now()){this.delete(e);return}return this.moveToEnd(t),t.value}}has(e){return e in this.items}moveToEnd(e){this.last!==e&&(e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),e.prev=this.last,e.next=null,this.last!==null&&(this.last.next=e),this.last=e,this.first===null&&(this.first=e))}keys(){const e=new Array(this.size);let t=this.first,s=0;for(;t!==null;)e[s++]=t.key,t=t.next;return e}setWithEvicted(e,t,s=this.resetTtl){let r=null;if(this.has(e))this.set(e,t,!0,s);else{this.max>0&&this.size===this.max&&(r={...this.first},this.evict(!0));let n=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t};++this.size===1?this.first=n:this.last.next=n,this.last=n}return r}set(e,t,s=!1,r=this.resetTtl){let n=this.items[e];return s||n!==void 0?(n.value=t,s===!1&&r&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(n)):(this.max>0&&this.size===this.max&&this.evict(!0),n=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t},++this.size===1?this.first=n:this.last.next=n,this.last=n),this}values(e=this.keys()){const t=new Array(e.length);for(let s=0;s<e.length;s++)t[s]=this.get(e[s]);return t}}function cy(i=1e3,e=0,t=!1){if(isNaN(i)||i<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if(typeof t!="boolean")throw new TypeError("Invalid resetTtl value");return new hy(i,e,t)}function Oa(i){return!!i.tagStyles&&Object.keys(i.tagStyles).length>0}function La(i){return i.includes("<")}function uy(i,e){return i.clone().assign(e)}function op(i,e){const t=[],s=e.tagStyles;if(!Oa(e)||!La(i))return t.push({text:i,style:e}),t;const r=[e],n=[];let o="",a=0;for(;a<i.length;){const l=i[a];if(l==="<"){const h=i.indexOf(">",a);if(h===-1){o+=l,a++;continue}const c=i.indexOf("<",a+1);if(c!==-1&&c<h){o+=l,a++;continue}const u=i.slice(a+1,h);if(u.startsWith("/")){const d=u.slice(1).trim();if(n.length>0&&n[n.length-1]===d){o.length>0&&(t.push({text:o,style:r[r.length-1]}),o=""),r.pop(),n.pop(),a=h+1;continue}else{o+=i.slice(a,h+1),a=h+1;continue}}else{const d=u.trim();if(s[d]){o.length>0&&(t.push({text:o,style:r[r.length-1]}),o="");const f=r[r.length-1],p=uy(f,s[d]);r.push(p),n.push(d),a=h+1;continue}else{o+=i.slice(a,h+1),a=h+1;continue}}}else o+=l,a++}return o.length>0&&t.push({text:o,style:r[r.length-1]}),t}const ap=[10,13],lp=new Set(ap),hp=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],cp=new Set(hp),up=[9,32];new Set(up);const dp=[45,8208,8211,8212,173],fp=new Set(dp),pp=/(\r\n|\r|\n)/,mp=/(?:\r\n|\r|\n)/;function bi(i){return typeof i!="string"?!1:lp.has(i.charCodeAt(0))}function $e(i,e){return typeof i!="string"?!1:cp.has(i.charCodeAt(0))}function gp(i){return typeof i!="string"?!1:fp.has(i.charCodeAt(0))}function Ua(i){return i==="normal"||i==="pre-line"}function Na(i){return i==="normal"}function lt(i){if(typeof i!="string")return"";let e=i.length-1;for(;e>=0&&$e(i[e]);)e--;return e<i.length-1?i.slice(0,e+1):i}function Ha(i){const e=[],t=[];if(typeof i!="string")return e;for(let s=0;s<i.length;s++){const r=i[s],n=i[s+1];if($e(r)||bi(r)){t.length>0&&(e.push(t.join("")),t.length=0),r==="\r"&&n===`
552
+ */class my{constructor(e=0,t=0,s=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=s,this.size=0,this.ttl=t}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(e){if(this.has(e)){const t=this.items[e];delete this.items[e],this.size--,t.prev!==null&&(t.prev.next=t.next),t.next!==null&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),this.last===t&&(this.last=t.prev)}return this}entries(e=this.keys()){const t=new Array(e.length);for(let s=0;s<e.length;s++){const r=e[s];t[s]=[r,this.get(r)]}return t}evict(e=!1){if(e||this.size>0){const t=this.first;delete this.items[t.key],--this.size===0?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(e){let t;return this.has(e)&&(t=this.items[e].expiry),t}get(e){const t=this.items[e];if(t!==void 0){if(this.ttl>0&&t.expiry<=Date.now()){this.delete(e);return}return this.moveToEnd(t),t.value}}has(e){return e in this.items}moveToEnd(e){this.last!==e&&(e.prev!==null&&(e.prev.next=e.next),e.next!==null&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),e.prev=this.last,e.next=null,this.last!==null&&(this.last.next=e),this.last=e,this.first===null&&(this.first=e))}keys(){const e=new Array(this.size);let t=this.first,s=0;for(;t!==null;)e[s++]=t.key,t=t.next;return e}setWithEvicted(e,t,s=this.resetTtl){let r=null;if(this.has(e))this.set(e,t,!0,s);else{this.max>0&&this.size===this.max&&(r={...this.first},this.evict(!0));let n=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t};++this.size===1?this.first=n:this.last.next=n,this.last=n}return r}set(e,t,s=!1,r=this.resetTtl){let n=this.items[e];return s||n!==void 0?(n.value=t,s===!1&&r&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(n)):(this.max>0&&this.size===this.max&&this.evict(!0),n=this.items[e]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:e,prev:this.last,next:null,value:t},++this.size===1?this.first=n:this.last.next=n,this.last=n),this}values(e=this.keys()){const t=new Array(e.length);for(let s=0;s<e.length;s++)t[s]=this.get(e[s]);return t}}function gy(i=1e3,e=0,t=!1){if(isNaN(i)||i<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if(typeof t!="boolean")throw new TypeError("Invalid resetTtl value");return new my(i,e,t)}function $a(i){return!!i.tagStyles&&Object.keys(i.tagStyles).length>0}function Va(i){return i.includes("<")}function _y(i,e){return i.clone().assign(e)}function cp(i,e){const t=[],s=e.tagStyles;if(!$a(e)||!Va(i))return t.push({text:i,style:e}),t;const r=[e],n=[];let o="",a=0;for(;a<i.length;){const l=i[a];if(l==="<"){const h=i.indexOf(">",a);if(h===-1){o+=l,a++;continue}const c=i.indexOf("<",a+1);if(c!==-1&&c<h){o+=l,a++;continue}const u=i.slice(a+1,h);if(u.startsWith("/")){const d=u.slice(1).trim();if(n.length>0&&n[n.length-1]===d){o.length>0&&(t.push({text:o,style:r[r.length-1]}),o=""),r.pop(),n.pop(),a=h+1;continue}else{o+=i.slice(a,h+1),a=h+1;continue}}else{const d=u.trim();if(s[d]){o.length>0&&(t.push({text:o,style:r[r.length-1]}),o="");const f=r[r.length-1],p=_y(f,s[d]);r.push(p),n.push(d),a=h+1;continue}else{o+=i.slice(a,h+1),a=h+1;continue}}}else o+=l,a++}return o.length>0&&t.push({text:o,style:r[r.length-1]}),t}const up=[10,13],dp=new Set(up),fp=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],pp=new Set(fp),mp=[9,32];new Set(mp);const gp=[45,8208,8211,8212,173],_p=new Set(gp),yp=/(\r\n|\r|\n)/,xp=/(?:\r\n|\r|\n)/;function vi(i){return typeof i!="string"?!1:dp.has(i.charCodeAt(0))}function $e(i,e){return typeof i!="string"?!1:pp.has(i.charCodeAt(0))}function bp(i){return typeof i!="string"?!1:_p.has(i.charCodeAt(0))}function ja(i){return i==="normal"||i==="pre-line"}function Xa(i){return i==="normal"}function ct(i){if(typeof i!="string")return"";let e=i.length-1;for(;e>=0&&$e(i[e]);)e--;return e<i.length-1?i.slice(0,e+1):i}function qa(i){const e=[],t=[];if(typeof i!="string")return e;for(let s=0;s<i.length;s++){const r=i[s],n=i[s+1];if($e(r)||vi(r)){t.length>0&&(e.push(t.join("")),t.length=0),r==="\r"&&n===`
553
553
  `?(e.push(`\r
554
- `),s++):e.push(r);continue}t.push(r),gp(r)&&n&&!$e(n)&&!bi(n)&&(e.push(t.join("")),t.length=0)}return t.length>0&&e.push(t.join("")),e}function za(i,e,t,s){const r=t(i),n=[];for(let o=0;o<r.length;o++){let a=r[o],l=a,h=1;for(;r[o+h];){const c=r[o+h];if(!s(l,c,i,o,e))a+=c,l=c,h++;else break}o+=h-1,n.push(a)}return n}const dy=/\r\n|\r|\n/g;function _p(i,e,t,s,r,n,o,a,l){const h=op(i,e);if(Na(e.whiteSpace))for(let O=0;O<h.length;O++){const I=h[O];h[O]={text:I.text.replace(dy," "),style:I.style}}const u=[];let d=[];for(const O of h){const I=O.text.split(pp);for(let P=0;P<I.length;P++){const C=I[P];C===`\r
554
+ `),s++):e.push(r);continue}t.push(r),bp(r)&&n&&!$e(n)&&!vi(n)&&(e.push(t.join("")),t.length=0)}return t.length>0&&e.push(t.join("")),e}function Ya(i,e,t,s){const r=t(i),n=[];for(let o=0;o<r.length;o++){let a=r[o],l=a,h=1;for(;r[o+h];){const c=r[o+h];if(!s(l,c,i,o,e))a+=c,l=c,h++;else break}o+=h-1,n.push(a)}return n}const yy=/\r\n|\r|\n/g;function vp(i,e,t,s,r,n,o,a,l){const h=cp(i,e);if(Xa(e.whiteSpace))for(let O=0;O<h.length;O++){const I=h[O];h[O]={text:I.text.replace(yy," "),style:I.style}}const u=[];let d=[];for(const O of h){const I=O.text.split(yp);for(let P=0;P<I.length;P++){const C=I[P];C===`\r
555
555
  `||C==="\r"||C===`
556
- `?(u.push(d),d=[]):C.length>0&&d.push({text:C,style:O.style})}}(d.length>0||u.length===0)&&u.push(d);const f=t?yp(u,e,s,n,a,l):u,p=[],g=[],m=[],_=[],y=[];let x=0;const b=e._fontString,v=o(b);v.fontSize===0&&(v.fontSize=e.fontSize,v.ascent=e.fontSize);let w="",T=!!e.dropShadow,k=e._stroke?.width||0;for(const O of f){let I=0,P=v.ascent,C=v.descent,D="";for(const L of O){const N=L.style._fontString,se=o(N);N!==w&&(s.font=N,w=N);const Q=r(L.text,L.style.letterSpacing,s);I+=Q,P=Math.max(P,se.ascent),C=Math.max(C,se.descent),D+=L.text;const re=L.style._stroke?.width||0;re>k&&(k=re),!T&&L.style.dropShadow&&(T=!0)}O.length===0&&(P=v.ascent,C=v.descent),p.push(I),g.push(P),m.push(C),y.push(D);const R=e.lineHeight||P+C;_.push(R+e.leading),x=Math.max(x,I)}const E=k,A=x+E+(e.dropShadow?e.dropShadow.distance:0);let M=0;for(let O=0;O<_.length;O++)M+=_[O];M=Math.max(M,_[0]+E);const B=M+(e.dropShadow?e.dropShadow.distance:0),G=e.lineHeight||v.fontSize;return{width:A,height:B,lines:y,lineWidths:p,lineHeight:G+e.leading,maxLineWidth:x,fontProperties:v,runsByLine:f,lineAscents:g,lineDescents:m,lineHeights:_,hasDropShadow:T}}function yp(i,e,t,s,r,n){const{letterSpacing:o,whiteSpace:a,wordWrapWidth:l,breakWords:h}=e,c=Ua(a),u=l+o,d={};let f="";const p=(m,_)=>{const y=`${m}|${_.styleKey}`;let x=d[y];if(x===void 0){const b=_._fontString;b!==f&&(t.font=b,f=b),x=s(m,_.letterSpacing,t)+_.letterSpacing,d[y]=x}return x},g=[];for(const m of i){const _=xp(m),y=g.length,x=M=>{let B=0,G=M;do{const{token:O,style:I}=_[G];B+=p(O,I),G++}while(G<_.length&&_[G].continuesFromPrevious);return B},b=M=>{const B=[];let G=M;do B.push({token:_[G].token,style:_[G].style}),G++;while(G<_.length&&_[G].continuesFromPrevious);return B};let v=[],w=0,T=!c,k=null;const E=()=>{k&&k.text.length>0&&v.push(k),k=null},A=()=>{if(E(),v.length>0){const M=v[v.length-1];M.text=lt(M.text),M.text.length===0&&v.pop()}g.push(v),v=[],w=0,T=!1};for(let M=0;M<_.length;M++){const{token:B,style:G,continuesFromPrevious:O}=_[M],I=p(B,G);if(c){const D=$e(B),R=k?.text[k.text.length-1]??v[v.length-1]?.text.slice(-1)??"",L=R?$e(R):!1;if(D&&L)continue}const P=!O,C=P?x(M):I;if(C>u&&P)if(w>0&&A(),h){const D=b(M);for(let R=0;R<D.length;R++){const L=D[R].token,N=D[R].style,se=za(L,h,n,r);for(const Q of se){const re=p(Q,N);re+w>u&&A(),!k||k.style!==N?(E(),k={text:Q,style:N}):k.text+=Q,w+=re}}M+=D.length-1}else{const D=b(M);E(),g.push(D.map(R=>({text:R.token,style:R.style}))),T=!1,M+=D.length-1}else if(C+w>u&&P){if($e(B)){T=!1;continue}A(),k={text:B,style:G},w=I}else if(O&&!h)!k||k.style!==G?(E(),k={text:B,style:G}):k.text+=B,w+=I;else{const D=$e(B);if(w===0&&D&&!T)continue;!k||k.style!==G?(E(),k={text:B,style:G}):k.text+=B,w+=I}}if(E(),v.length>0){const M=v[v.length-1];M.text=lt(M.text),M.text.length===0&&v.pop()}(v.length>0||g.length===y)&&g.push(v)}return g}function xp(i){const e=[];let t=!1;for(const s of i){const r=Ha(s.text);let n=!0;for(const o of r){const a=$e(o)||bi(o),l=n&&t&&!a;e.push({token:o,style:s.style,continuesFromPrevious:l}),t=!a,n=!1}}return e}const fy={willReadFrequently:!0};function Ec(i,e,t,s,r){let n=t[i];return typeof n!="number"&&(n=r(i,e,s)+e,t[i]=n),n}function bp(i,e,t,s,r,n,o){const a=t.getContext("2d",fy);a.font=e._fontString;let l=0,h="";const c=[],u=Object.create(null),{letterSpacing:d,whiteSpace:f}=e,p=Ua(f),g=Na(f);let m=!p;const _=e.wordWrapWidth+d,y=Ha(i);for(let b=0;b<y.length;b++){let v=y[b];if(bi(v)){if(!g){c.push(lt(h)),m=!p,h="",l=0;continue}v=" "}if(p){const T=$e(v),k=$e(h[h.length-1]);if(T&&k)continue}const w=Ec(v,d,u,a,s);if(w>_)if(h!==""&&(c.push(lt(h)),h="",l=0),r(v,e.breakWords)){const T=za(v,e.breakWords,o,n);for(const k of T){const E=Ec(k,d,u,a,s);E+l>_&&(c.push(lt(h)),m=!1,h="",l=0),h+=k,l+=E}}else h.length>0&&(c.push(lt(h)),h="",l=0),c.push(lt(v)),m=!1,h="",l=0;else w+l>_&&(m=!1,c.push(lt(h)),h="",l=0),(h.length>0||!$e(v)||m)&&(h+=v,l+=w)}const x=lt(h);return x.length>0&&c.push(x),c.join(`
557
- `)}const Pc={willReadFrequently:!0},Pt=class V{static get experimentalLetterSpacingSupported(){let e=V._experimentalLetterSpacingSupported;if(e===void 0){const t=ee.get().getCanvasRenderingContext2D().prototype;e=V._experimentalLetterSpacingSupported="letterSpacing"in t||"textLetterSpacing"in t}return e}constructor(e,t,s,r,n,o,a,l,h,c){this.text=e,this.style=t,this.width=s,this.height=r,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h,c&&(this.runsByLine=c.runsByLine,this.lineAscents=c.lineAscents,this.lineDescents=c.lineDescents,this.lineHeights=c.lineHeights,this.hasDropShadow=c.hasDropShadow)}static measureText(e=" ",t,s=V._canvas,r=t.wordWrap){const n=`${e}-${t.styleKey}-wordWrap-${r}`;if(V._measurementCache.has(n))return V._measurementCache.get(n);if(Oa(t)&&La(e)){const b=_p(e,t,r,V._context,V._measureText,V._measureTextAdvance,V.measureFont,V.canBreakChars,V.wordWrapSplit),v=new V(e,t,b.width,b.height,b.lines,b.lineWidths,b.lineHeight,b.maxLineWidth,b.fontProperties,{runsByLine:b.runsByLine,lineAscents:b.lineAscents,lineDescents:b.lineDescents,lineHeights:b.lineHeights,hasDropShadow:b.hasDropShadow});return V._measurementCache.set(n,v),v}const a=t._fontString,l=V.measureFont(a);l.fontSize===0&&(l.fontSize=t.fontSize,l.ascent=t.fontSize,l.descent=0);const h=V._context;h.font=a;const u=(r?V._wordWrap(e,t,s):e).split(mp),d=new Array(u.length);let f=0;for(let b=0;b<u.length;b++){const v=V._measureText(u[b],t.letterSpacing,h);d[b]=v,f=Math.max(f,v)}const p=t._stroke?.width??0,g=t.lineHeight||l.fontSize,m=V._adjustWidthForStyle(f,t),_=Math.max(g,l.fontSize+p)+(u.length-1)*(g+t.leading),y=V._adjustHeightForStyle(_,t),x=new V(e,t,m,y,u,d,g+t.leading,f,l);return V._measurementCache.set(n,x),x}static _adjustWidthForStyle(e,t){const s=t._stroke?.width||0;let r=e+s;return t.dropShadow&&(r+=t.dropShadow.distance),r}static _adjustHeightForStyle(e,t){let s=e;return t.dropShadow&&(s+=t.dropShadow.distance),s}static _measureText(e,t,s){const{metricWidth:r,metrics:n,letterSpacingVal:o}=V._measureTextCore(e,t,s),a=-(n.actualBoundingBoxLeft??0);let h=(n.actualBoundingBoxRight??0)-a;return n.width>0&&(h+=o),Math.max(r,h)}static _measureTextAdvance(e,t,s){return V._measureTextCore(e,t,s).metricWidth}static _measureTextCore(e,t,s){let r=!1;V.experimentalLetterSpacingSupported&&(V.experimentalLetterSpacing?(s.letterSpacing=`${t}px`,s.textLetterSpacing=`${t}px`,r=!0):(s.letterSpacing="0px",s.textLetterSpacing="0px"));const n=s.measureText(e);let o=n.width,a=0;return o>0&&(r?a=-t:a=(V.graphemeSegmenter(e).length-1)*t,o+=a),{metricWidth:o,metrics:n,letterSpacingVal:a}}static _wordWrap(e,t,s=V._canvas){return bp(e,t,s,V._measureTextAdvance,V.canBreakWords,V.canBreakChars,V.wordWrapSplit)}static isBreakingSpace(e,t){return $e(e)}static canBreakWords(e,t){return t}static canBreakChars(e,t,s,r,n){return!0}static wordWrapSplit(e){return V.graphemeSegmenter(e)}static measureFont(e){if(V._fonts[e])return V._fonts[e];const t=V._context;t.font=e;const s=t.measureText(V.METRICS_STRING+V.BASELINE_SYMBOL),r=s.actualBoundingBoxAscent??0,n=s.actualBoundingBoxDescent??0,o={ascent:r,descent:n,fontSize:r+n};return V._fonts[e]=o,o}static clearMetrics(e=""){e?delete V._fonts[e]:V._fonts={}}static get _canvas(){if(!V.__canvas){let e;try{const t=new OffscreenCanvas(0,0);if(t.getContext("2d",Pc)?.measureText)return V.__canvas=t,t;e=ee.get().createCanvas()}catch{e=ee.get().createCanvas()}e.width=e.height=10,V.__canvas=e}return V.__canvas}static get _context(){return V.__context||(V.__context=V._canvas.getContext("2d",Pc)),V.__context}};Pt.METRICS_STRING="|ÉqÅ";Pt.BASELINE_SYMBOL="M";Pt.BASELINE_MULTIPLIER=1.4;Pt.HEIGHT_MULTIPLIER=2;Pt.graphemeSegmenter=(()=>{if(typeof Intl?.Segmenter=="function"){const i=new Intl.Segmenter;return e=>{const t=i.segment(e),s=[];let r=0;for(const n of t)s[r++]=n.segment;return s}}return i=>[...i]})();Pt.experimentalLetterSpacing=!1;Pt._fonts={};Pt._measurementCache=cy(1e3);let bt=Pt;const py=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function cr(i){const e=typeof i.fontSize=="number"?`${i.fontSize}px`:i.fontSize;let t=i.fontFamily;Array.isArray(i.fontFamily)||(t=i.fontFamily.split(","));for(let s=t.length-1;s>=0;s--){let r=t[s].trim();!/([\"\'])[^\'\"]+\1/.test(r)&&!py.includes(r)&&(r=`"${r}"`),t[s]=r}return`${i.fontStyle} ${i.fontVariant} ${i.fontWeight} ${e} ${t.join(",")}`}const Ac=1e5;function Js(i,e,t,s=0,r=0,n=0){if(i.texture===W.WHITE&&!i.fill)return ae.shared.setValue(i.color).setAlpha(i.alpha??1).toHexa();if(i.fill){if(i.fill instanceof Fs){const o=i.fill,a=e.createPattern(o.texture.source.resource,"repeat");return Y.applyPatternTransform(a,o.transform,!1),a}else if(i.fill instanceof je){const o=i.fill,a=o.type==="linear",l=o.textureSpace==="local";let h=1,c=1;l&&t&&(h=t.width+s,c=t.height+s);let u,d=!1;if(a){const{start:f,end:p}=o;u=e.createLinearGradient(f.x*h+r,f.y*c+n,p.x*h+r,p.y*c+n),d=Math.abs(p.x-f.x)<Math.abs((p.y-f.y)*.1)}else{const{center:f,innerRadius:p,outerCenter:g,outerRadius:m}=o;u=e.createRadialGradient(f.x*h+r,f.y*c+n,p*h,g.x*h+r,g.y*c+n,m*h)}if(d&&l&&t){const f=t.lineHeight/c;for(let p=0;p<t.lines.length;p++){const g=(p*t.lineHeight+s/2)/c;o.colorStops.forEach(m=>{let _=g+m.offset*f;_=Math.max(0,Math.min(1,_)),u.addColorStop(Math.floor(_*Ac)/Ac,ae.shared.setValue(m.color).toHex())})}}else o.colorStops.forEach(f=>{u.addColorStop(f.offset,ae.shared.setValue(f.color).toHex())});return u}}else{const o=e.createPattern(i.texture.source.resource,"repeat"),a=i.matrix.copyTo(U.shared);return a.scale(i.texture.source.pixelWidth,i.texture.source.pixelHeight),o.setTransform(a),o}return z("FillStyle not recognised",i),"red"}const Rc=new te;function ps(i){let e=0;for(let t=0;t<i.length;t++)i.charCodeAt(t)===32&&e++;return e}class my{getCanvasAndContext(e){const{text:t,style:s,resolution:r=1}=e,n=s._getFinalPadding(),o=bt.measureText(t||" ",s),a=Math.ceil(Math.ceil(Math.max(1,o.width)+n*2)*r),l=Math.ceil(Math.ceil(Math.max(1,o.height)+n*2)*r),h=Et.getOptimalCanvasAndContext(a,l);this._renderTextToCanvas(s,n,r,h,o);const c=s.trim?np({canvas:h.canvas,width:a,height:l,resolution:1,output:Rc}):Rc.set(0,0,a,l);return{canvasAndContext:h,frame:c}}returnCanvasAndContext(e){Et.returnCanvasAndContext(e)}_renderTextToCanvas(e,t,s,r,n){if(n.runsByLine&&n.runsByLine.length>0){this._renderTaggedTextToCanvas(n,e,t,s,r);return}const{canvas:o,context:a}=r,l=cr(e),h=n.lines,c=n.lineHeight,u=n.lineWidths,d=n.maxLineWidth,f=n.fontProperties,p=o.height;if(a.resetTransform(),a.scale(s,s),a.textBaseline=e.textBaseline,e._stroke?.width){const v=e._stroke;a.lineWidth=v.width,a.miterLimit=v.miterLimit,a.lineJoin=v.join,a.lineCap=v.cap}a.font=l;let g,m;const _=e.dropShadow?2:1,x=(e._stroke?.width??0)/2;let b=(c-f.fontSize)/2;c-f.fontSize<0&&(b=0);for(let v=0;v<_;++v){const w=e.dropShadow&&v===0,T=w?Math.ceil(Math.max(1,p)+t*2):0,k=T*s;if(w)this._setupDropShadow(a,e,s,k);else{const E=e._gradientBounds,A=e._gradientOffset;if(E){const M={width:E.width,height:E.height,lineHeight:E.height,lines:n.lines};this._setFillAndStrokeStyles(a,e,M,t,x,A?.x??0,A?.y??0)}else A?this._setFillAndStrokeStyles(a,e,n,t,x,A.x,A.y):this._setFillAndStrokeStyles(a,e,n,t,x);a.shadowColor="rgba(0,0,0,0)"}for(let E=0;E<h.length;E++){g=x,m=x+E*c+f.ascent+b,g+=this._getAlignmentOffset(u[E],d,e.align);let A=0;if(e.align==="justify"&&e.wordWrap&&E<h.length-1){const M=ps(h[E]);M>0&&(A=(d-u[E])/M)}e._stroke?.width&&this._drawLetterSpacing(h[E],e,r,g+t,m+t-T,!0,A),e._fill!==void 0&&this._drawLetterSpacing(h[E],e,r,g+t,m+t-T,!1,A)}}}_renderTaggedTextToCanvas(e,t,s,r,n){const{canvas:o,context:a}=n,{runsByLine:l,lineWidths:h,maxLineWidth:c,lineAscents:u,lineHeights:d,hasDropShadow:f}=e,p=o.height;a.resetTransform(),a.scale(r,r),a.textBaseline=t.textBaseline;const g=f?2:1;let m=t._stroke?.width??0;for(const x of l)for(const b of x){const v=b.style._stroke?.width??0;v>m&&(m=v)}const _=m/2,y=[];for(let x=0;x<l.length;x++){const b=l[x],v=[];for(const w of b){const T=cr(w.style);a.font=T,v.push({width:bt._measureText(w.text,w.style.letterSpacing,a),font:T})}y.push(v)}for(let x=0;x<g;++x){const b=f&&x===0,v=b?Math.ceil(Math.max(1,p)+s*2):0,w=v*r;b||(a.shadowColor="rgba(0,0,0,0)");let T=_;for(let k=0;k<l.length;k++){const E=l[k],A=h[k],M=u[k],B=d[k],G=y[k];let O=_;O+=this._getAlignmentOffset(A,c,t.align);let I=0;if(t.align==="justify"&&t.wordWrap&&k<l.length-1){let D=0;for(const R of E)D+=ps(R.text);D>0&&(I=(c-A)/D)}const P=T+M;let C=O+s;for(let D=0;D<E.length;D++){const R=E[D],{width:L,font:N}=G[D];if(a.font=N,a.textBaseline=R.style.textBaseline,R.style._stroke?.width){const Q=R.style._stroke;if(a.lineWidth=Q.width,a.miterLimit=Q.miterLimit,a.lineJoin=Q.join,a.lineCap=Q.cap,b)if(R.style.dropShadow)this._setupDropShadow(a,R.style,r,w);else{const re=ps(R.text);C+=L+re*I;continue}else{const re=bt.measureFont(N),j=R.style.lineHeight||re.fontSize,Ze={width:L,height:j,lineHeight:j,lines:[R.text]};a.strokeStyle=Js(Q,a,Ze,s*2,C-s,T)}this._drawLetterSpacing(R.text,R.style,n,C,P+s-v,!0,I)}const se=ps(R.text);C+=L+se*I}C=O+s;for(let D=0;D<E.length;D++){const R=E[D],{width:L,font:N}=G[D];if(a.font=N,a.textBaseline=R.style.textBaseline,R.style._fill!==void 0){if(b)if(R.style.dropShadow)this._setupDropShadow(a,R.style,r,w);else{const Q=ps(R.text);C+=L+Q*I;continue}else{const Q=bt.measureFont(N),re=R.style.lineHeight||Q.fontSize,j={width:L,height:re,lineHeight:re,lines:[R.text]};a.fillStyle=Js(R.style._fill,a,j,s*2,C-s,T)}this._drawLetterSpacing(R.text,R.style,n,C,P+s-v,!1,I)}const se=ps(R.text);C+=L+se*I}T+=B}}}_setFillAndStrokeStyles(e,t,s,r,n,o=0,a=0){if(e.fillStyle=t._fill?Js(t._fill,e,s,r*2,o,a):null,t._stroke?.width){const l=n+r*2;e.strokeStyle=Js(t._stroke,e,s,l,o,a)}}_setupDropShadow(e,t,s,r){e.fillStyle="black",e.strokeStyle="black";const n=t.dropShadow,o=n.color,a=n.alpha;e.shadowColor=ae.shared.setValue(o).setAlpha(a).toRgbaString();const l=n.blur*s,h=n.distance*s;e.shadowBlur=l,e.shadowOffsetX=Math.cos(n.angle)*h,e.shadowOffsetY=Math.sin(n.angle)*h+r}_getAlignmentOffset(e,t,s){return s==="right"?t-e:s==="center"?(t-e)/2:0}_drawLetterSpacing(e,t,s,r,n,o=!1,a=0){const{context:l}=s,h=t.letterSpacing;let c=!1;if(bt.experimentalLetterSpacingSupported&&(bt.experimentalLetterSpacing?(l.letterSpacing=`${h}px`,l.textLetterSpacing=`${h}px`,c=!0):(l.letterSpacing="0px",l.textLetterSpacing="0px")),(h===0||c)&&a===0){o?l.strokeText(e,r,n):l.fillText(e,r,n);return}if(a!==0&&(h===0||c)){const g=e.split(" ");let m=r;const _=l.measureText(" ").width;for(let y=0;y<g.length;y++)o?l.strokeText(g[y],m,n):l.fillText(g[y],m,n),m+=l.measureText(g[y]).width+_+a;return}let u=r;const d=bt.graphemeSegmenter(e);let f=l.measureText(e).width,p=0;for(let g=0;g<d.length;++g){const m=d[g];o?l.strokeText(m,u,n):l.fillText(m,u,n);let _="";for(let y=g+1;y<d.length;++y)_+=d[y];p=l.measureText(_).width,u+=f-p+h,m===" "&&(u+=a),f=p}}}const Yt=new my,Wa=class Vt extends Re{constructor(e={}){super(),this.uid=oe("textStyle"),this._tick=0,this._cachedFontString=null,gy(e),e instanceof Vt&&(e=e._toObject());const r={...Vt.defaultTextStyle,...e};for(const n in r){const o=n;this[o]=r[n]}this._tagStyles=e.tagStyles??void 0,this.update(),this._tick=0}get align(){return this._align}set align(e){this._align!==e&&(this._align=e,this.update())}get breakWords(){return this._breakWords}set breakWords(e){this._breakWords!==e&&(this._breakWords=e,this.update())}get dropShadow(){return this._dropShadow}set dropShadow(e){this._dropShadow!==e&&(e!==null&&typeof e=="object"?this._dropShadow=this._createProxy({...Vt.defaultDropShadow,...e}):this._dropShadow=e?this._createProxy({...Vt.defaultDropShadow}):null,this.update())}get fontFamily(){return this._fontFamily}set fontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.update())}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize!==e&&(typeof e=="string"?this._fontSize=parseInt(e,10):this._fontSize=e,this.update())}get fontStyle(){return this._fontStyle}set fontStyle(e){this._fontStyle!==e&&(this._fontStyle=e.toLowerCase(),this.update())}get fontVariant(){return this._fontVariant}set fontVariant(e){this._fontVariant!==e&&(this._fontVariant=e,this.update())}get fontWeight(){return this._fontWeight}set fontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.update())}get leading(){return this._leading}set leading(e){this._leading!==e&&(this._leading=e,this.update())}get letterSpacing(){return this._letterSpacing}set letterSpacing(e){this._letterSpacing!==e&&(this._letterSpacing=e,this.update())}get lineHeight(){return this._lineHeight}set lineHeight(e){this._lineHeight!==e&&(this._lineHeight=e,this.update())}get padding(){return this._padding}set padding(e){this._padding!==e&&(this._padding=e,this.update())}get filters(){return this._filters}set filters(e){this._filters!==e&&(this._filters=Object.freeze(e),this.update())}get trim(){return this._trim}set trim(e){this._trim!==e&&(this._trim=e,this.update())}get textBaseline(){return this._textBaseline}set textBaseline(e){this._textBaseline!==e&&(this._textBaseline=e,this.update())}get whiteSpace(){return this._whiteSpace}set whiteSpace(e){this._whiteSpace!==e&&(this._whiteSpace=e,this.update())}get wordWrap(){return this._wordWrap}set wordWrap(e){this._wordWrap!==e&&(this._wordWrap=e,this.update())}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(e){this._wordWrapWidth!==e&&(this._wordWrapWidth=e,this.update())}get fill(){return this._originalFill}set fill(e){e!==this._originalFill&&(this._originalFill=e,this._isFillStyle(e)&&(this._originalFill=this._createProxy({...qe.defaultFillStyle,...e},()=>{this._fill=Gt({...this._originalFill},qe.defaultFillStyle)})),this._fill=Gt(e===0?"black":e,qe.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...qe.defaultStrokeStyle,...e},()=>{this._stroke=yi({...this._originalStroke},qe.defaultStrokeStyle)})),this._stroke=yi(e,qe.defaultStrokeStyle),this.update())}get tagStyles(){return this._tagStyles}set tagStyles(e){this._tagStyles!==e&&(this._tagStyles=e??void 0,this.update())}update(){this._tick++,this._cachedFontString=null,this.emit("update",this)}reset(){const e=Vt.defaultTextStyle;for(const t in e)this[t]=e[t]}assign(e){for(const t in e){const s=t;this[s]=e[t]}return this}get styleKey(){return`${this.uid}-${this._tick}`}get _fontString(){return this._cachedFontString===null&&(this._cachedFontString=cr(this)),this._cachedFontString}_toObject(){return{align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill?{...this._fill}:void 0,fontFamily:this.fontFamily,fontSize:this.fontSize,fontStyle:this.fontStyle,fontVariant:this.fontVariant,fontWeight:this.fontWeight,leading:this.leading,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,padding:this.padding,stroke:this._stroke?{...this._stroke}:void 0,textBaseline:this.textBaseline,trim:this.trim,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0,tagStyles:this._tagStyles?{...this._tagStyles}:void 0}}clone(){return new Vt(this._toObject())}_getFinalPadding(){let e=0;if(this._filters)for(let t=0;t<this._filters.length;t++)e+=this._filters[t].padding;return Math.max(this._padding,e)}destroy(e=!1){if(this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(s),this._originalFill?.texture&&this._originalFill.texture.destroy(s),this._stroke?.texture&&this._stroke.texture.destroy(s),this._originalStroke?.texture&&this._originalStroke.texture.destroy(s)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(s,r,n)=>(s[r]===n||(s[r]=n,t?.(r,n),this.update()),!0)})}_isFillStyle(e){return(e??null)!==null&&!(ae.isColorLike(e)||e instanceof je||e instanceof Fs)}};Wa.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5};Wa.defaultTextStyle={align:"left",breakWords:!1,dropShadow:null,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,padding:0,stroke:null,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let As=Wa;function gy(i){const e=i;if(typeof e.dropShadow=="boolean"&&e.dropShadow){const t=As.defaultDropShadow;i.dropShadow={alpha:e.dropShadowAlpha??t.alpha,angle:e.dropShadowAngle??t.angle,blur:e.dropShadowBlur??t.blur,color:e.dropShadowColor??t.color,distance:e.dropShadowDistance??t.distance}}if(e.strokeThickness!==void 0){H(ue,"strokeThickness is now a part of stroke");const t=e.stroke;let s={};if(ae.isColorLike(t))s.color=t;else if(t instanceof je||t instanceof Fs)s.fill=t;else if(Object.hasOwnProperty.call(t,"color")||Object.hasOwnProperty.call(t,"fill"))s=t;else throw new Error("Invalid stroke value.");i.stroke={...s,width:e.strokeThickness}}if(Array.isArray(e.fillGradientStops)){if(H(ue,"gradient fill is now a fill pattern: `new FillGradient(...)`"),!Array.isArray(e.fill)||e.fill.length===0)throw new Error("Invalid fill value. Expected an array of colors for gradient fill.");e.fill.length!==e.fillGradientStops.length&&z("The number of fill colors must match the number of fill gradient stops.");const t=new je({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),s=e.fillGradientStops.slice(),r=e.fill.map(n=>ae.shared.setValue(n).toNumber());s.forEach((n,o)=>{t.addColorStop(n,r[o])}),i.fill={fill:t}}}let Bc=!1;function vp(i){if(Bc)return;const e=new Dt({scaleMode:i.scaleMode});i._resourceId!==e._resourceId&&(Bc=!0,z("Text textureStyle: only scaleMode is applied to a text texture, the other fields are ignored"))}function wp(i,e){const{texture:t,bounds:s}=i,r=e._style._getFinalPadding();No(s,e._anchor,t);const n=e._anchor._x*r*2,o=e._anchor._y*r*2;s.minX-=r-n,s.minY-=r-o,s.maxX-=r-n,s.maxY-=r-o}class Or{constructor(){this.batcherName="default",this.topology="triangle-list",this.attributeSize=4,this.indexSize=6,this.packAsQuad=!0,this.roundPixels=0,this._attributeStart=0,this._batcher=null,this._batch=null}get blendMode(){return this.renderable.groupBlendMode}get color(){return this.renderable.groupColorAlpha}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.bounds=null}destroy(){this.reset()}}class Tp extends Or{}class $a{constructor(e){this._renderer=e,e.runners.resolutionChange.add(this),e.runners.contextChange.add(this),this._managedTexts=new nt({renderer:e,type:"renderable",onUnload:this.onTextUnload.bind(this),name:"canvasText"})}resolutionChange(){for(const e in this._managedTexts.items){const t=this._managedTexts.items[e];t?._autoResolution&&t.onViewUpdate()}}contextChange(){for(const e in this._managedTexts.items)this._managedTexts.items[e]?.unload()}validateRenderable(e){const t=this._getGpuText(e),s=e.styleKey;return t.currentKey!==s?!0:e._didTextUpdate}addRenderable(e,t){const s=this._getGpuText(e);if(e._didTextUpdate||s.currentKey!==e.styleKey){const r=e._autoResolution?this._renderer.resolution:e.resolution;(s.currentKey!==e.styleKey||e._resolution!==r)&&this._updateGpuText(e),e._didTextUpdate=!1,wp(s,e)}this._renderer.renderPipes.batch.addToBatch(s,t)}updateRenderable(e){const t=this._getGpuText(e);t._batcher.updateElement(t)}_updateGpuText(e){const t=this._getGpuText(e);t.texture&&this._renderer.canvasText.decreaseReferenceCount(t.currentKey),e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,t.texture=this._renderer.canvasText.getManagedTexture(e),t.currentKey=e.styleKey}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new Tp;return t.currentKey="--",t.renderable=e,t.transform=e.groupTransform,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,this._managedTexts.add(e),t}onTextUnload(e){const t=e._gpuData[this._renderer.uid];if(!t)return;const{canvasText:s}=this._renderer;s.getReferenceCount(t.currentKey)>0?s.decreaseReferenceCount(t.currentKey):t.texture&&s.returnTexture(t.texture)}destroy(){this._managedTexts.destroy(),this._renderer=null}}$a.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"text"};class Va{constructor(e,t){this._activeTextures={},this._renderer=e,this._retainCanvasContext=t}getTexture(e,t,s,r){typeof e=="string"&&(H("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:s,resolution:t}),e.style instanceof As||(e.style=new As(e.style)),typeof e.text!="string"&&(e.text=e.text.toString());const{text:n,style:o,textureStyle:a,autoGenerateMipmaps:l}=e,h=e.resolution??this._renderer.resolution,{frame:c,canvasAndContext:u}=Yt.getCanvasAndContext({text:n,style:o,resolution:h}),d=Ra(u.canvas,c.width,c.height,h,l,a?.scaleMode);if(o.trim&&(c.pad(o.padding),d.frame.copyFrom(c),d.frame.scale(1/h),d.updateUvs()),o.filters){const f=this._applyFilters(d,o.filters);return this.returnTexture(d),Yt.returnCanvasAndContext(u),f}return this._renderer.texture.initSource(d._source),this._retainCanvasContext||Yt.returnCanvasAndContext(u),d}returnTexture(e){const t=e.source,s=t.resource;if(this._retainCanvasContext&&s?.getContext){const r=s.getContext("2d");r&&Yt.returnCanvasAndContext({canvas:s,context:r})}t.resource=null,t.uploadMethodId="unknown",t.alphaMode="no-premultiply-alpha",Te.returnTexture(e)}renderTextToCanvas(){H("8.10.0","CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead")}getManagedTexture(e){e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].texture;const s=this.getTexture({text:e.text,style:e.style,resolution:e._resolution,textureStyle:e.textureStyle,autoGenerateMipmaps:e.autoGenerateMipmaps});return this._activeTextures[t]={texture:s,usageCount:1},s}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(this.returnTexture(t.texture),this._activeTextures[e]=null))}getReferenceCount(e){return this._activeTextures[e]?.usageCount??0}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}_applyFilters(e,t){const s=this._renderer.renderTarget.renderTarget,r=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind({target:s,clear:!1}),r}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexture(this._activeTextures[e].texture);this._activeTextures=null}}class ja extends Va{constructor(e){super(e,!0)}}ja.extension={type:[S.CanvasSystem],name:"canvasText"};class Xa extends Va{constructor(e){super(e,!1)}}Xa.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"canvasText"};q.add(ja);q.add(Xa);q.add($a);class Sp extends ip{constructor(...e){const t=rp(e,"Text");super(t,As),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof Dt?t.textureStyle:new Dt(t.textureStyle),vp(this.textureStyle)),this.autoGenerateMipmaps=t.autoGenerateMipmaps??de.defaultOptions.autoGenerateMipmaps}updateBounds(){const e=this._bounds,t=this._anchor;let s=0,r=0;if(this._style.trim){const{frame:n,canvasAndContext:o}=Yt.getCanvasAndContext({text:this.text,style:this._style,resolution:1});Yt.returnCanvasAndContext(o),s=n.width,r=n.height}else{const n=bt.measureText(this._text,this._style);s=n.width,r=n.height}e.minX=-t._x*s,e.maxX=e.minX+s,e.minY=-t._y*r,e.maxY=e.minY+r}}function Cp(){const{userAgent:i}=ee.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(i)}const qa=class jt{static _getPatternRepeat(e,t){const s=e&&e!=="clamp-to-edge",r=t&&t!=="clamp-to-edge";return s&&r?"repeat":s?"repeat-x":r?"repeat-y":"no-repeat"}start(e,t,s){}execute(e,t){const s=t.elements;if(!s||!s.length)return;const r=e.renderer,n=r.canvasContext,o=n.activeContext;for(let a=0;a<s.length;a++){const l=s[a];if(!l.packAsQuad)continue;const h=l,c=h.texture,u=c?Y.getCanvasSource(c):null;if(!u)continue;const d=c.source.style,f=n.smoothProperty,p=d.scaleMode!=="nearest";o[f]!==p&&(o[f]=p),n.setBlendMode(t.blendMode);const g=r.globalUniforms.globalUniformData?.worldColor??4294967295,m=h.color,_=(g>>>24&255)/255,y=(m>>>24&255)/255,x=r.filter?.alphaMultiplier??1,b=_*y*x;if(b<=0)continue;o.globalAlpha=b;const v=g&16777215,w=m&16777215,T=Zt(Kt(w,v)),k=c.frame,E=d.addressModeU??d.addressMode,A=d.addressModeV??d.addressMode,M=jt._getPatternRepeat(E,A),B=c.source._resolution??c.source.resolution??1,G=h.renderable?.renderGroup?.isCachedAsTexture,O=k.x*B,I=k.y*B,P=k.width*B,C=k.height*B,D=h.bounds,R=r.renderTarget.renderTarget.isRoot,L=D.minX,N=D.minY,se=D.maxX-D.minX,Q=D.maxY-D.minY,re=c.rotate,j=c.uvs,Ze=Math.min(j.x0,j.x1,j.x2,j.x3,j.y0,j.y1,j.y2,j.y3),Si=Math.max(j.x0,j.x1,j.x2,j.x3,j.y0,j.y1,j.y2,j.y3),Os=M!=="no-repeat"&&(Ze<0||Si>1),mt=re&&!(!Os&&(T!==16777215||re));mt?(jt._tempPatternMatrix.copyFrom(h.transform),Z.matrixAppendRotationInv(jt._tempPatternMatrix,re,L,N,se,Q),n.setContextTransform(jt._tempPatternMatrix,h.roundPixels===1,void 0,G&&R)):n.setContextTransform(h.transform,h.roundPixels===1,void 0,G&&R);const Ot=se,Qe=Q;let Oe=mt?0:L,Le=mt?0:N;if(!mt&&h.roundPixels===1&&(Oe|=0,Le|=0),Os){let Je=u;const Rt=T!==16777215&&!re,gt=k.width<=c.source.width&&k.height<=c.source.height;Rt&&gt&&(Je=Y.getTintedCanvas({texture:c},T));const Us=o.createPattern(Je,M);if(!Us)continue;const Yr=Ot,uh=Qe;if(Yr===0||uh===0)continue;const dh=1/Yr,fh=1/uh,ph=(j.x1-j.x0)*dh,mh=(j.y1-j.y0)*dh,gh=(j.x3-j.x0)*fh,_h=(j.y3-j.y0)*fh,Gg=j.x0-ph*Oe-gh*Le,Dg=j.y0-mh*Oe-_h*Le,Kr=c.source.pixelWidth,Zr=c.source.pixelHeight;jt._tempPatternMatrix.set(ph*Kr,mh*Zr,gh*Kr,_h*Zr,Gg*Kr,Dg*Zr),Y.applyPatternTransform(Us,jt._tempPatternMatrix),o.fillStyle=Us,o.fillRect(Oe,Le,Ot,Qe)}else{const Rt=T!==16777215||re?Y.getTintedCanvas({texture:c},T):u,gt=Rt!==u;o.drawImage(Rt,gt?0:O,gt?0:I,gt?Rt.width:P,gt?Rt.height:C,Oe,Le,Ot,Qe)}}}};qa._tempPatternMatrix=new U;qa.extension={type:[S.CanvasPipesAdaptor],name:"batch"};let Mp=qa;class Ya{constructor(){this._tempState=pt.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,s){const r=e.renderer,n=this._didUploadHash[s.uid];r.shader.bind(s,n),n||(this._didUploadHash[s.uid]=!0),r.shader.updateUniformGroup(r.globalUniforms.uniformGroup),r.geometry.bind(t,s.glProgram)}execute(e,t){const s=e.renderer;this._tempState.blendMode=t.blendMode,s.state.set(this._tempState);const r=t.textures.textures;for(let n=0;n<t.textures.count;n++)s.texture.bind(r[n],n);s.texture.unbindIntegerTextures(t.textures.count),s.geometry.draw(t.topology,t.size,t.start)}}Ya.extension={type:[S.WebGLPipesAdaptor],name:"batch"};const Ni=pt.for2d();class Ka{start(e,t,s){const r=e.renderer,n=r.encoder,o=s.gpuProgram;this._shader=s,this._geometry=t,n.setGeometry(t,o),Ni.blendMode="normal",r.pipeline.getPipeline(t,o,Ni,void 0,s._overrides);const a=r.globalUniforms.bindGroup;n.resetBindGroup(1),n.setBindGroup(0,a,o)}execute(e,t){const s=this._shader.gpuProgram,r=e.renderer,n=r.encoder;if(!t.bindGroup){const l=t.textures;t.bindGroup=kr(l.textures,l.count,r.limits.maxBatchableTextures)}Ni.blendMode=t.blendMode;const o=r.bindGroup.getBindGroup(t.bindGroup,s,1),a=r.pipeline.getPipeline(this._geometry,s,Ni,t.topology,this._shader._overrides);t.bindGroup._touch(r.gc.now),n.setPipeline(a),n.renderPassEncoder.setBindGroup(1,o),n.renderPassEncoder.drawIndexed(t.size,1,t.start)}}Ka.extension={type:[S.WebGPUPipesAdaptor],name:"batch"};const Za=class kp{constructor(e,t){this.state=pt.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init?.(this)}static getBatcher(e,t){return new this._availableBatchers[e]({maxTextures:t})}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new Ir({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const s in this._activeBatches)this._activeBatches[s].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let s=this._activeBatches[e.batcherName];s||(s=this._activeBatches[e.batcherName]=kp.getBatcher(e.batcherName,this.renderer.limits.maxBatchableTextures),s.begin()),this._activeBatch=s}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const s in t){const r=t[s],n=r.geometry;n.indexBuffer.setDataWithSize(r.indexBuffer,r.indexSize,!0),n.buffers[0].setDataWithSize(r.attributeBuffer.float32View,r.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const s in t){const r=t[s],n=r.geometry;r.dirty&&(r.dirty=!1,n.buffers[0].update(r.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,s=t.geometry,r=t.shader;this._adaptor.start(this,s,r)}this._adaptor.execute(this,e)}destroyInstructionSet(e){const t=this._batchersByInstructionSet[e.uid];if(t){for(const s in t)t[s].destroy();delete this._batchersByInstructionSet[e.uid],this._activeBatches===t&&(this._activeBatches=Object.create(null),this._activeBatch=null)}}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};Za.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"batch"};Za._availableBatchers=Object.create(null);let Lr=Za;q.handleByMap(S.Batcher,Lr._availableBatchers);q.add(Ir);const Ep={name:"texture-bit",vertex:{header:`
556
+ `?(u.push(d),d=[]):C.length>0&&d.push({text:C,style:O.style})}}(d.length>0||u.length===0)&&u.push(d);const f=t?wp(u,e,s,n,a,l):u,p=[],g=[],m=[],_=[],y=[];let x=0;const b=e._fontString,v=o(b);v.fontSize===0&&(v.fontSize=e.fontSize,v.ascent=e.fontSize);let w="",T=!!e.dropShadow,k=e._stroke?.width||0;for(const O of f){let I=0,P=v.ascent,C=v.descent,D="";for(const L of O){const N=L.style._fontString,se=o(N);N!==w&&(s.font=N,w=N);const Q=r(L.text,L.style.letterSpacing,s);I+=Q,P=Math.max(P,se.ascent),C=Math.max(C,se.descent),D+=L.text;const re=L.style._stroke?.width||0;re>k&&(k=re),!T&&L.style.dropShadow&&(T=!0)}O.length===0&&(P=v.ascent,C=v.descent),p.push(I),g.push(P),m.push(C),y.push(D);const R=e.lineHeight||P+C;_.push(R+e.leading),x=Math.max(x,I)}const E=k,A=x+E+(e.dropShadow?e.dropShadow.distance:0);let M=0;for(let O=0;O<_.length;O++)M+=_[O];M=Math.max(M,_[0]+E);const B=M+(e.dropShadow?e.dropShadow.distance:0),G=e.lineHeight||v.fontSize;return{width:A,height:B,lines:y,lineWidths:p,lineHeight:G+e.leading,maxLineWidth:x,fontProperties:v,runsByLine:f,lineAscents:g,lineDescents:m,lineHeights:_,hasDropShadow:T}}function wp(i,e,t,s,r,n){const{letterSpacing:o,whiteSpace:a,wordWrapWidth:l,breakWords:h}=e,c=ja(a),u=l+o,d={};let f="";const p=(m,_)=>{const y=`${m}|${_.styleKey}`;let x=d[y];if(x===void 0){const b=_._fontString;b!==f&&(t.font=b,f=b),x=s(m,_.letterSpacing,t)+_.letterSpacing,d[y]=x}return x},g=[];for(const m of i){const _=Tp(m),y=g.length,x=M=>{let B=0,G=M;do{const{token:O,style:I}=_[G];B+=p(O,I),G++}while(G<_.length&&_[G].continuesFromPrevious);return B},b=M=>{const B=[];let G=M;do B.push({token:_[G].token,style:_[G].style}),G++;while(G<_.length&&_[G].continuesFromPrevious);return B};let v=[],w=0,T=!c,k=null;const E=()=>{k&&k.text.length>0&&v.push(k),k=null},A=()=>{if(E(),v.length>0){const M=v[v.length-1];M.text=ct(M.text),M.text.length===0&&v.pop()}g.push(v),v=[],w=0,T=!1};for(let M=0;M<_.length;M++){const{token:B,style:G,continuesFromPrevious:O}=_[M],I=p(B,G);if(c){const D=$e(B),R=k?.text[k.text.length-1]??v[v.length-1]?.text.slice(-1)??"",L=R?$e(R):!1;if(D&&L)continue}const P=!O,C=P?x(M):I;if(C>u&&P)if(w>0&&A(),h){const D=b(M);for(let R=0;R<D.length;R++){const L=D[R].token,N=D[R].style,se=Ya(L,h,n,r);for(const Q of se){const re=p(Q,N);re+w>u&&A(),!k||k.style!==N?(E(),k={text:Q,style:N}):k.text+=Q,w+=re}}M+=D.length-1}else{const D=b(M);E(),g.push(D.map(R=>({text:R.token,style:R.style}))),T=!1,M+=D.length-1}else if(C+w>u&&P){if($e(B)){T=!1;continue}A(),k={text:B,style:G},w=I}else if(O&&!h)!k||k.style!==G?(E(),k={text:B,style:G}):k.text+=B,w+=I;else{const D=$e(B);if(w===0&&D&&!T)continue;!k||k.style!==G?(E(),k={text:B,style:G}):k.text+=B,w+=I}}if(E(),v.length>0){const M=v[v.length-1];M.text=ct(M.text),M.text.length===0&&v.pop()}(v.length>0||g.length===y)&&g.push(v)}return g}function Tp(i){const e=[];let t=!1;for(const s of i){const r=qa(s.text);let n=!0;for(const o of r){const a=$e(o)||vi(o),l=n&&t&&!a;e.push({token:o,style:s.style,continuesFromPrevious:l}),t=!a,n=!1}}return e}const xy={willReadFrequently:!0};function Ac(i,e,t,s,r){let n=t[i];return typeof n!="number"&&(n=r(i,e,s)+e,t[i]=n),n}function Sp(i,e,t,s,r,n,o){const a=t.getContext("2d",xy);a.font=e._fontString;let l=0,h="";const c=[],u=Object.create(null),{letterSpacing:d,whiteSpace:f}=e,p=ja(f),g=Xa(f);let m=!p;const _=e.wordWrapWidth+d,y=qa(i);for(let b=0;b<y.length;b++){let v=y[b];if(vi(v)){if(!g){c.push(ct(h)),m=!p,h="",l=0;continue}v=" "}if(p){const T=$e(v),k=$e(h[h.length-1]);if(T&&k)continue}const w=Ac(v,d,u,a,s);if(w>_)if(h!==""&&(c.push(ct(h)),h="",l=0),r(v,e.breakWords)){const T=Ya(v,e.breakWords,o,n);for(const k of T){const E=Ac(k,d,u,a,s);E+l>_&&(c.push(ct(h)),m=!1,h="",l=0),h+=k,l+=E}}else h.length>0&&(c.push(ct(h)),h="",l=0),c.push(ct(v)),m=!1,h="",l=0;else w+l>_&&(m=!1,c.push(ct(h)),h="",l=0),(h.length>0||!$e(v)||m)&&(h+=v,l+=w)}const x=ct(h);return x.length>0&&c.push(x),c.join(`
557
+ `)}const Rc={willReadFrequently:!0},Rt=class V{static get experimentalLetterSpacingSupported(){let e=V._experimentalLetterSpacingSupported;if(e===void 0){const t=ee.get().getCanvasRenderingContext2D().prototype;e=V._experimentalLetterSpacingSupported="letterSpacing"in t||"textLetterSpacing"in t}return e}constructor(e,t,s,r,n,o,a,l,h,c){this.text=e,this.style=t,this.width=s,this.height=r,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h,c&&(this.runsByLine=c.runsByLine,this.lineAscents=c.lineAscents,this.lineDescents=c.lineDescents,this.lineHeights=c.lineHeights,this.hasDropShadow=c.hasDropShadow)}static measureText(e=" ",t,s=V._canvas,r=t.wordWrap){const n=`${e}-${t.styleKey}-wordWrap-${r}`;if(V._measurementCache.has(n))return V._measurementCache.get(n);if($a(t)&&Va(e)){const b=vp(e,t,r,V._context,V._measureText,V._measureTextAdvance,V.measureFont,V.canBreakChars,V.wordWrapSplit),v=new V(e,t,b.width,b.height,b.lines,b.lineWidths,b.lineHeight,b.maxLineWidth,b.fontProperties,{runsByLine:b.runsByLine,lineAscents:b.lineAscents,lineDescents:b.lineDescents,lineHeights:b.lineHeights,hasDropShadow:b.hasDropShadow});return V._measurementCache.set(n,v),v}const a=t._fontString,l=V.measureFont(a);l.fontSize===0&&(l.fontSize=t.fontSize,l.ascent=t.fontSize,l.descent=0);const h=V._context;h.font=a;const u=(r?V._wordWrap(e,t,s):e).split(xp),d=new Array(u.length);let f=0;for(let b=0;b<u.length;b++){const v=V._measureText(u[b],t.letterSpacing,h);d[b]=v,f=Math.max(f,v)}const p=t._stroke?.width??0,g=t.lineHeight||l.fontSize,m=V._adjustWidthForStyle(f,t),_=Math.max(g,l.fontSize+p)+(u.length-1)*(g+t.leading),y=V._adjustHeightForStyle(_,t),x=new V(e,t,m,y,u,d,g+t.leading,f,l);return V._measurementCache.set(n,x),x}static _adjustWidthForStyle(e,t){const s=t._stroke?.width||0;let r=e+s;return t.dropShadow&&(r+=t.dropShadow.distance),r}static _adjustHeightForStyle(e,t){let s=e;return t.dropShadow&&(s+=t.dropShadow.distance),s}static _measureText(e,t,s){const{metricWidth:r,metrics:n,letterSpacingVal:o}=V._measureTextCore(e,t,s),a=-(n.actualBoundingBoxLeft??0);let h=(n.actualBoundingBoxRight??0)-a;return n.width>0&&(h+=o),Math.max(r,h)}static _measureTextAdvance(e,t,s){return V._measureTextCore(e,t,s).metricWidth}static _measureTextCore(e,t,s){let r=!1;V.experimentalLetterSpacingSupported&&(V.experimentalLetterSpacing?(s.letterSpacing=`${t}px`,s.textLetterSpacing=`${t}px`,r=!0):(s.letterSpacing="0px",s.textLetterSpacing="0px"));const n=s.measureText(e);let o=n.width,a=0;return o>0&&(r?a=-t:a=(V.graphemeSegmenter(e).length-1)*t,o+=a),{metricWidth:o,metrics:n,letterSpacingVal:a}}static _wordWrap(e,t,s=V._canvas){return Sp(e,t,s,V._measureTextAdvance,V.canBreakWords,V.canBreakChars,V.wordWrapSplit)}static isBreakingSpace(e,t){return $e(e)}static canBreakWords(e,t){return t}static canBreakChars(e,t,s,r,n){return!0}static wordWrapSplit(e){return V.graphemeSegmenter(e)}static measureFont(e){if(V._fonts[e])return V._fonts[e];const t=V._context;t.font=e;const s=t.measureText(V.METRICS_STRING+V.BASELINE_SYMBOL),r=s.actualBoundingBoxAscent??0,n=s.actualBoundingBoxDescent??0,o={ascent:r,descent:n,fontSize:r+n};return V._fonts[e]=o,o}static clearMetrics(e=""){e?delete V._fonts[e]:V._fonts={}}static get _canvas(){if(!V.__canvas){let e;try{const t=new OffscreenCanvas(0,0);if(t.getContext("2d",Rc)?.measureText)return V.__canvas=t,t;e=ee.get().createCanvas()}catch{e=ee.get().createCanvas()}e.width=e.height=10,V.__canvas=e}return V.__canvas}static get _context(){return V.__context||(V.__context=V._canvas.getContext("2d",Rc)),V.__context}};Rt.METRICS_STRING="|ÉqÅ";Rt.BASELINE_SYMBOL="M";Rt.BASELINE_MULTIPLIER=1.4;Rt.HEIGHT_MULTIPLIER=2;Rt.graphemeSegmenter=(()=>{if(typeof Intl?.Segmenter=="function"){const i=new Intl.Segmenter;return e=>{const t=i.segment(e),s=[];let r=0;for(const n of t)s[r++]=n.segment;return s}}return i=>[...i]})();Rt.experimentalLetterSpacing=!1;Rt._fonts={};Rt._measurementCache=gy(1e3);let Tt=Rt;const by=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function fr(i){const e=typeof i.fontSize=="number"?`${i.fontSize}px`:i.fontSize;let t=i.fontFamily;Array.isArray(i.fontFamily)||(t=i.fontFamily.split(","));for(let s=t.length-1;s>=0;s--){let r=t[s].trim();!/([\"\'])[^\'\"]+\1/.test(r)&&!by.includes(r)&&(r=`"${r}"`),t[s]=r}return`${i.fontStyle} ${i.fontVariant} ${i.fontWeight} ${e} ${t.join(",")}`}const Bc=1e5;function ti(i,e,t,s=0,r=0,n=0){if(i.texture===W.WHITE&&!i.fill)return le.shared.setValue(i.color).setAlpha(i.alpha??1).toHexa();if(i.fill){if(i.fill instanceof Ls){const o=i.fill,a=e.createPattern(o.texture.source.resource,"repeat");return Y.applyPatternTransform(a,o.transform,!1),a}else if(i.fill instanceof je){const o=i.fill,a=o.type==="linear",l=o.textureSpace==="local";let h=1,c=1;l&&t&&(h=t.width+s,c=t.height+s);let u,d=!1;if(a){const{start:f,end:p}=o;u=e.createLinearGradient(f.x*h+r,f.y*c+n,p.x*h+r,p.y*c+n),d=Math.abs(p.x-f.x)<Math.abs((p.y-f.y)*.1)}else{const{center:f,innerRadius:p,outerCenter:g,outerRadius:m}=o;u=e.createRadialGradient(f.x*h+r,f.y*c+n,p*h,g.x*h+r,g.y*c+n,m*h)}if(d&&l&&t){const f=t.lineHeight/c;for(let p=0;p<t.lines.length;p++){const g=(p*t.lineHeight+s/2)/c;o.colorStops.forEach(m=>{let _=g+m.offset*f;_=Math.max(0,Math.min(1,_)),u.addColorStop(Math.floor(_*Bc)/Bc,le.shared.setValue(m.color).toHex())})}}else o.colorStops.forEach(f=>{u.addColorStop(f.offset,le.shared.setValue(f.color).toHex())});return u}}else{const o=e.createPattern(i.texture.source.resource,"repeat"),a=i.matrix.copyTo(U.shared);return a.scale(i.texture.source.pixelWidth,i.texture.source.pixelHeight),o.setTransform(a),o}return H("FillStyle not recognised",i),"red"}const Ic=new te;function ys(i){let e=0;for(let t=0;t<i.length;t++)i.charCodeAt(t)===32&&e++;return e}class vy{getCanvasAndContext(e){const{text:t,style:s,resolution:r=1}=e,n=s._getFinalPadding(),o=Tt.measureText(t||" ",s),a=Math.ceil(Math.ceil(Math.max(1,o.width)+n*2)*r),l=Math.ceil(Math.ceil(Math.max(1,o.height)+n*2)*r),h=At.getOptimalCanvasAndContext(a,l);this._renderTextToCanvas(s,n,r,h,o);const c=s.trim?hp({canvas:h.canvas,width:a,height:l,resolution:1,output:Ic}):Ic.set(0,0,a,l);return{canvasAndContext:h,frame:c}}returnCanvasAndContext(e){At.returnCanvasAndContext(e)}_renderTextToCanvas(e,t,s,r,n){if(n.runsByLine&&n.runsByLine.length>0){this._renderTaggedTextToCanvas(n,e,t,s,r);return}const{canvas:o,context:a}=r,l=fr(e),h=n.lines,c=n.lineHeight,u=n.lineWidths,d=n.maxLineWidth,f=n.fontProperties,p=o.height;if(a.resetTransform(),a.scale(s,s),a.textBaseline=e.textBaseline,e._stroke?.width){const v=e._stroke;a.lineWidth=v.width,a.miterLimit=v.miterLimit,a.lineJoin=v.join,a.lineCap=v.cap}a.font=l;let g,m;const _=e.dropShadow?2:1,x=(e._stroke?.width??0)/2;let b=(c-f.fontSize)/2;c-f.fontSize<0&&(b=0);for(let v=0;v<_;++v){const w=e.dropShadow&&v===0,T=w?Math.ceil(Math.max(1,p)+t*2):0,k=T*s;if(w)this._setupDropShadow(a,e,s,k);else{const E=e._gradientBounds,A=e._gradientOffset;if(E){const M={width:E.width,height:E.height,lineHeight:E.height,lines:n.lines};this._setFillAndStrokeStyles(a,e,M,t,x,A?.x??0,A?.y??0)}else A?this._setFillAndStrokeStyles(a,e,n,t,x,A.x,A.y):this._setFillAndStrokeStyles(a,e,n,t,x);a.shadowColor="rgba(0,0,0,0)"}for(let E=0;E<h.length;E++){g=x,m=x+E*c+f.ascent+b,g+=this._getAlignmentOffset(u[E],d,e.align);let A=0;if(e.align==="justify"&&e.wordWrap&&E<h.length-1){const M=ys(h[E]);M>0&&(A=(d-u[E])/M)}e._stroke?.width&&this._drawLetterSpacing(h[E],e,r,g+t,m+t-T,!0,A),e._fill!==void 0&&this._drawLetterSpacing(h[E],e,r,g+t,m+t-T,!1,A)}}}_renderTaggedTextToCanvas(e,t,s,r,n){const{canvas:o,context:a}=n,{runsByLine:l,lineWidths:h,maxLineWidth:c,lineAscents:u,lineHeights:d,hasDropShadow:f}=e,p=o.height;a.resetTransform(),a.scale(r,r),a.textBaseline=t.textBaseline;const g=f?2:1;let m=t._stroke?.width??0;for(const x of l)for(const b of x){const v=b.style._stroke?.width??0;v>m&&(m=v)}const _=m/2,y=[];for(let x=0;x<l.length;x++){const b=l[x],v=[];for(const w of b){const T=fr(w.style);a.font=T,v.push({width:Tt._measureText(w.text,w.style.letterSpacing,a),font:T})}y.push(v)}for(let x=0;x<g;++x){const b=f&&x===0,v=b?Math.ceil(Math.max(1,p)+s*2):0,w=v*r;b||(a.shadowColor="rgba(0,0,0,0)");let T=_;for(let k=0;k<l.length;k++){const E=l[k],A=h[k],M=u[k],B=d[k],G=y[k];let O=_;O+=this._getAlignmentOffset(A,c,t.align);let I=0;if(t.align==="justify"&&t.wordWrap&&k<l.length-1){let D=0;for(const R of E)D+=ys(R.text);D>0&&(I=(c-A)/D)}const P=T+M;let C=O+s;for(let D=0;D<E.length;D++){const R=E[D],{width:L,font:N}=G[D];if(a.font=N,a.textBaseline=R.style.textBaseline,R.style._stroke?.width){const Q=R.style._stroke;if(a.lineWidth=Q.width,a.miterLimit=Q.miterLimit,a.lineJoin=Q.join,a.lineCap=Q.cap,b)if(R.style.dropShadow)this._setupDropShadow(a,R.style,r,w);else{const re=ys(R.text);C+=L+re*I;continue}else{const re=Tt.measureFont(N),j=R.style.lineHeight||re.fontSize,Qe={width:L,height:j,lineHeight:j,lines:[R.text]};a.strokeStyle=ti(Q,a,Qe,s*2,C-s,T)}this._drawLetterSpacing(R.text,R.style,n,C,P+s-v,!0,I)}const se=ys(R.text);C+=L+se*I}C=O+s;for(let D=0;D<E.length;D++){const R=E[D],{width:L,font:N}=G[D];if(a.font=N,a.textBaseline=R.style.textBaseline,R.style._fill!==void 0){if(b)if(R.style.dropShadow)this._setupDropShadow(a,R.style,r,w);else{const Q=ys(R.text);C+=L+Q*I;continue}else{const Q=Tt.measureFont(N),re=R.style.lineHeight||Q.fontSize,j={width:L,height:re,lineHeight:re,lines:[R.text]};a.fillStyle=ti(R.style._fill,a,j,s*2,C-s,T)}this._drawLetterSpacing(R.text,R.style,n,C,P+s-v,!1,I)}const se=ys(R.text);C+=L+se*I}T+=B}}}_setFillAndStrokeStyles(e,t,s,r,n,o=0,a=0){if(e.fillStyle=t._fill?ti(t._fill,e,s,r*2,o,a):null,t._stroke?.width){const l=n+r*2;e.strokeStyle=ti(t._stroke,e,s,l,o,a)}}_setupDropShadow(e,t,s,r){e.fillStyle="black",e.strokeStyle="black";const n=t.dropShadow,o=n.color,a=n.alpha;e.shadowColor=le.shared.setValue(o).setAlpha(a).toRgbaString();const l=n.blur*s,h=n.distance*s;e.shadowBlur=l,e.shadowOffsetX=Math.cos(n.angle)*h,e.shadowOffsetY=Math.sin(n.angle)*h+r}_getAlignmentOffset(e,t,s){return s==="right"?t-e:s==="center"?(t-e)/2:0}_drawLetterSpacing(e,t,s,r,n,o=!1,a=0){const{context:l}=s,h=t.letterSpacing;let c=!1;if(Tt.experimentalLetterSpacingSupported&&(Tt.experimentalLetterSpacing?(l.letterSpacing=`${h}px`,l.textLetterSpacing=`${h}px`,c=!0):(l.letterSpacing="0px",l.textLetterSpacing="0px")),(h===0||c)&&a===0){o?l.strokeText(e,r,n):l.fillText(e,r,n);return}if(a!==0&&(h===0||c)){const g=e.split(" ");let m=r;const _=l.measureText(" ").width;for(let y=0;y<g.length;y++)o?l.strokeText(g[y],m,n):l.fillText(g[y],m,n),m+=l.measureText(g[y]).width+_+a;return}let u=r;const d=Tt.graphemeSegmenter(e);let f=l.measureText(e).width,p=0;for(let g=0;g<d.length;++g){const m=d[g];o?l.strokeText(m,u,n):l.fillText(m,u,n);let _="";for(let y=g+1;y<d.length;++y)_+=d[y];p=l.measureText(_).width,u+=f-p+h,m===" "&&(u+=a),f=p}}}const Qt=new vy,Ka=class Xt extends Re{constructor(e={}){super(),this.uid=oe("textStyle"),this._tick=0,this._cachedFontString=null,wy(e),e instanceof Xt&&(e=e._toObject());const r={...Xt.defaultTextStyle,...e};for(const n in r){const o=n;this[o]=r[n]}this._tagStyles=e.tagStyles??void 0,this.update(),this._tick=0}get align(){return this._align}set align(e){this._align!==e&&(this._align=e,this.update())}get breakWords(){return this._breakWords}set breakWords(e){this._breakWords!==e&&(this._breakWords=e,this.update())}get dropShadow(){return this._dropShadow}set dropShadow(e){this._dropShadow!==e&&(e!==null&&typeof e=="object"?this._dropShadow=this._createProxy({...Xt.defaultDropShadow,...e}):this._dropShadow=e?this._createProxy({...Xt.defaultDropShadow}):null,this.update())}get fontFamily(){return this._fontFamily}set fontFamily(e){this._fontFamily!==e&&(this._fontFamily=e,this.update())}get fontSize(){return this._fontSize}set fontSize(e){this._fontSize!==e&&(typeof e=="string"?this._fontSize=parseInt(e,10):this._fontSize=e,this.update())}get fontStyle(){return this._fontStyle}set fontStyle(e){this._fontStyle!==e&&(this._fontStyle=e.toLowerCase(),this.update())}get fontVariant(){return this._fontVariant}set fontVariant(e){this._fontVariant!==e&&(this._fontVariant=e,this.update())}get fontWeight(){return this._fontWeight}set fontWeight(e){this._fontWeight!==e&&(this._fontWeight=e,this.update())}get leading(){return this._leading}set leading(e){this._leading!==e&&(this._leading=e,this.update())}get letterSpacing(){return this._letterSpacing}set letterSpacing(e){this._letterSpacing!==e&&(this._letterSpacing=e,this.update())}get lineHeight(){return this._lineHeight}set lineHeight(e){this._lineHeight!==e&&(this._lineHeight=e,this.update())}get padding(){return this._padding}set padding(e){this._padding!==e&&(this._padding=e,this.update())}get filters(){return this._filters}set filters(e){this._filters!==e&&(this._filters=Object.freeze(e),this.update())}get trim(){return this._trim}set trim(e){this._trim!==e&&(this._trim=e,this.update())}get textBaseline(){return this._textBaseline}set textBaseline(e){this._textBaseline!==e&&(this._textBaseline=e,this.update())}get whiteSpace(){return this._whiteSpace}set whiteSpace(e){this._whiteSpace!==e&&(this._whiteSpace=e,this.update())}get wordWrap(){return this._wordWrap}set wordWrap(e){this._wordWrap!==e&&(this._wordWrap=e,this.update())}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(e){this._wordWrapWidth!==e&&(this._wordWrapWidth=e,this.update())}get fill(){return this._originalFill}set fill(e){e!==this._originalFill&&(this._originalFill=e,this._isFillStyle(e)&&(this._originalFill=this._createProxy({...qe.defaultFillStyle,...e},()=>{this._fill=Ft({...this._originalFill},qe.defaultFillStyle)})),this._fill=Ft(e===0?"black":e,qe.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...qe.defaultStrokeStyle,...e},()=>{this._stroke=xi({...this._originalStroke},qe.defaultStrokeStyle)})),this._stroke=xi(e,qe.defaultStrokeStyle),this.update())}get tagStyles(){return this._tagStyles}set tagStyles(e){this._tagStyles!==e&&(this._tagStyles=e??void 0,this.update())}update(){this._tick++,this._cachedFontString=null,this.emit("update",this)}reset(){const e=Xt.defaultTextStyle;for(const t in e)this[t]=e[t]}assign(e){for(const t in e){const s=t;this[s]=e[t]}return this}get styleKey(){return`${this.uid}-${this._tick}`}get _fontString(){return this._cachedFontString===null&&(this._cachedFontString=fr(this)),this._cachedFontString}_toObject(){return{align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill?{...this._fill}:void 0,fontFamily:this.fontFamily,fontSize:this.fontSize,fontStyle:this.fontStyle,fontVariant:this.fontVariant,fontWeight:this.fontWeight,leading:this.leading,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,padding:this.padding,stroke:this._stroke?{...this._stroke}:void 0,textBaseline:this.textBaseline,trim:this.trim,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0,tagStyles:this._tagStyles?{...this._tagStyles}:void 0}}clone(){return new Xt(this._toObject())}_getFinalPadding(){let e=0;if(this._filters)for(let t=0;t<this._filters.length;t++)e+=this._filters[t].padding;return Math.max(this._padding,e)}destroy(e=!1){if(this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const s=typeof e=="boolean"?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(s),this._originalFill?.texture&&this._originalFill.texture.destroy(s),this._stroke?.texture&&this._stroke.texture.destroy(s),this._originalStroke?.texture&&this._originalStroke.texture.destroy(s)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(s,r,n)=>(s[r]===n||(s[r]=n,t?.(r,n),this.update()),!0)})}_isFillStyle(e){return(e??null)!==null&&!(le.isColorLike(e)||e instanceof je||e instanceof Ls)}};Ka.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5};Ka.defaultTextStyle={align:"left",breakWords:!1,dropShadow:null,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,padding:0,stroke:null,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let Is=Ka;function wy(i){const e=i;if(typeof e.dropShadow=="boolean"&&e.dropShadow){const t=Is.defaultDropShadow;i.dropShadow={alpha:e.dropShadowAlpha??t.alpha,angle:e.dropShadowAngle??t.angle,blur:e.dropShadowBlur??t.blur,color:e.dropShadowColor??t.color,distance:e.dropShadowDistance??t.distance}}if(e.strokeThickness!==void 0){z(de,"strokeThickness is now a part of stroke");const t=e.stroke;let s={};if(le.isColorLike(t))s.color=t;else if(t instanceof je||t instanceof Ls)s.fill=t;else if(Object.hasOwnProperty.call(t,"color")||Object.hasOwnProperty.call(t,"fill"))s=t;else throw new Error("Invalid stroke value.");i.stroke={...s,width:e.strokeThickness}}if(Array.isArray(e.fillGradientStops)){if(z(de,"gradient fill is now a fill pattern: `new FillGradient(...)`"),!Array.isArray(e.fill)||e.fill.length===0)throw new Error("Invalid fill value. Expected an array of colors for gradient fill.");e.fill.length!==e.fillGradientStops.length&&H("The number of fill colors must match the number of fill gradient stops.");const t=new je({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),s=e.fillGradientStops.slice(),r=e.fill.map(n=>le.shared.setValue(n).toNumber());s.forEach((n,o)=>{t.addColorStop(n,r[o])}),i.fill={fill:t}}}let Gc=!1;function Cp(i){if(Gc)return;const e=new Ot({scaleMode:i.scaleMode});i._resourceId!==e._resourceId&&(Gc=!0,H("Text textureStyle: only scaleMode is applied to a text texture, the other fields are ignored"))}function Mp(i,e){const{texture:t,bounds:s}=i,r=e._style._getFinalPadding();Xo(s,e._anchor,t);const n=e._anchor._x*r*2,o=e._anchor._y*r*2;s.minX-=r-n,s.minY-=r-o,s.maxX-=r-n,s.maxY-=r-o}class Ur{constructor(){this.batcherName="default",this.topology="triangle-list",this.attributeSize=4,this.indexSize=6,this.packAsQuad=!0,this.roundPixels=0,this._attributeStart=0,this._batcher=null,this._batch=null}get blendMode(){return this.renderable.groupBlendMode}get color(){return this.renderable.groupColorAlpha}reset(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null,this.bounds=null}destroy(){this.reset()}}class kp extends Ur{}class Za{constructor(e){this._renderer=e,e.runners.resolutionChange.add(this),e.runners.contextChange.add(this),this._managedTexts=new at({renderer:e,type:"renderable",onUnload:this.onTextUnload.bind(this),name:"canvasText"})}resolutionChange(){for(const e in this._managedTexts.items){const t=this._managedTexts.items[e];t?._autoResolution&&t.onViewUpdate()}}contextChange(){for(const e in this._managedTexts.items)this._managedTexts.items[e]?.unload()}validateRenderable(e){const t=this._getGpuText(e),s=e.styleKey;return t.currentKey!==s?!0:e._didTextUpdate}addRenderable(e,t){const s=this._getGpuText(e);if(e._didTextUpdate||s.currentKey!==e.styleKey){const r=e._autoResolution?this._renderer.resolution:e.resolution;(s.currentKey!==e.styleKey||e._resolution!==r)&&this._updateGpuText(e),e._didTextUpdate=!1,Mp(s,e)}this._renderer.renderPipes.batch.addToBatch(s,t)}updateRenderable(e){const t=this._getGpuText(e);t._batcher.updateElement(t)}_updateGpuText(e){const t=this._getGpuText(e);t.texture&&this._renderer.canvasText.decreaseReferenceCount(t.currentKey),e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,t.texture=this._renderer.canvasText.getManagedTexture(e),t.currentKey=e.styleKey}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new kp;return t.currentKey="--",t.renderable=e,t.transform=e.groupTransform,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,this._managedTexts.add(e),t}onTextUnload(e){const t=e._gpuData[this._renderer.uid];if(!t)return;const{canvasText:s}=this._renderer;s.getReferenceCount(t.currentKey)>0?s.decreaseReferenceCount(t.currentKey):t.texture&&s.returnTexture(t.texture)}destroy(){this._managedTexts.destroy(),this._renderer=null}}Za.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"text"};class Qa{constructor(e,t){this._activeTextures={},this._renderer=e,this._retainCanvasContext=t}getTexture(e,t,s,r){typeof e=="string"&&(z("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:s,resolution:t}),e.style instanceof Is||(e.style=new Is(e.style)),typeof e.text!="string"&&(e.text=e.text.toString());const{text:n,style:o,textureStyle:a,autoGenerateMipmaps:l}=e,h=e.resolution??this._renderer.resolution,{frame:c,canvasAndContext:u}=Qt.getCanvasAndContext({text:n,style:o,resolution:h}),d=La(u.canvas,c.width,c.height,h,l,a?.scaleMode);if(o.trim&&(c.pad(o.padding),d.frame.copyFrom(c),d.frame.scale(1/h),d.updateUvs()),o.filters){const f=this._applyFilters(d,o.filters);return this.returnTexture(d),Qt.returnCanvasAndContext(u),f}return this._renderer.texture.initSource(d._source),this._retainCanvasContext||Qt.returnCanvasAndContext(u),d}returnTexture(e){const t=e.source,s=t.resource;if(this._retainCanvasContext&&s?.getContext){const r=s.getContext("2d");r&&Qt.returnCanvasAndContext({canvas:s,context:r})}t.resource=null,t.uploadMethodId="unknown",t.alphaMode="no-premultiply-alpha",Te.returnTexture(e)}renderTextToCanvas(){z("8.10.0","CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead")}getManagedTexture(e){e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].texture;const s=this.getTexture({text:e.text,style:e.style,resolution:e._resolution,textureStyle:e.textureStyle,autoGenerateMipmaps:e.autoGenerateMipmaps});return this._activeTextures[t]={texture:s,usageCount:1},s}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(this.returnTexture(t.texture),this._activeTextures[e]=null))}getReferenceCount(e){return this._activeTextures[e]?.usageCount??0}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}_applyFilters(e,t){const s=this._renderer.renderTarget.renderTarget,r=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind({target:s,clear:!1}),r}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexture(this._activeTextures[e].texture);this._activeTextures=null}}class Ja extends Qa{constructor(e){super(e,!0)}}Ja.extension={type:[S.CanvasSystem],name:"canvasText"};class el extends Qa{constructor(e){super(e,!1)}}el.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"canvasText"};q.add(Ja);q.add(el);q.add(Za);class Ep extends ap{constructor(...e){const t=lp(e,"Text");super(t,Is),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof Ot?t.textureStyle:new Ot(t.textureStyle),Cp(this.textureStyle)),this.autoGenerateMipmaps=t.autoGenerateMipmaps??ue.defaultOptions.autoGenerateMipmaps}updateBounds(){const e=this._bounds,t=this._anchor;let s=0,r=0;if(this._style.trim){const{frame:n,canvasAndContext:o}=Qt.getCanvasAndContext({text:this.text,style:this._style,resolution:1});Qt.returnCanvasAndContext(o),s=n.width,r=n.height}else{const n=Tt.measureText(this._text,this._style);s=n.width,r=n.height}e.minX=-t._x*s,e.maxX=e.minX+s,e.minY=-t._y*r,e.maxY=e.minY+r}}function Pp(){const{userAgent:i}=ee.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(i)}const tl=class qt{static _getPatternRepeat(e,t){const s=e&&e!=="clamp-to-edge",r=t&&t!=="clamp-to-edge";return s&&r?"repeat":s?"repeat-x":r?"repeat-y":"no-repeat"}start(e,t,s){}execute(e,t){const s=t.elements;if(!s||!s.length)return;const r=e.renderer,n=r.canvasContext,o=n.activeContext;for(let a=0;a<s.length;a++){const l=s[a];if(!l.packAsQuad)continue;const h=l,c=h.texture,u=c?Y.getCanvasSource(c):null;if(!u)continue;const d=c.source.style,f=n.smoothProperty,p=d.scaleMode!=="nearest";o[f]!==p&&(o[f]=p),n.setBlendMode(t.blendMode);const g=r.globalUniforms.globalUniformData?.worldColor??4294967295,m=h.color,_=(g>>>24&255)/255,y=(m>>>24&255)/255,x=r.filter?.alphaMultiplier??1,b=_*y*x;if(b<=0)continue;o.globalAlpha=b;const v=g&16777215,w=m&16777215,T=ts(es(w,v)),k=c.frame,E=d.addressModeU??d.addressMode,A=d.addressModeV??d.addressMode,M=qt._getPatternRepeat(E,A),B=c.source._resolution??c.source.resolution??1,G=h.renderable?.renderGroup?.isCachedAsTexture,O=k.x*B,I=k.y*B,P=k.width*B,C=k.height*B,D=h.bounds,R=r.renderTarget.renderTarget.isRoot,L=D.minX,N=D.minY,se=D.maxX-D.minX,Q=D.maxY-D.minY,re=c.rotate,j=c.uvs,Qe=Math.min(j.x0,j.x1,j.x2,j.x3,j.y0,j.y1,j.y2,j.y3),ki=Math.max(j.x0,j.x1,j.x2,j.x3,j.y0,j.y1,j.y2,j.y3),Us=M!=="no-repeat"&&(Qe<0||ki>1),yt=re&&!(!Us&&(T!==16777215||re));yt?(qt._tempPatternMatrix.copyFrom(h.transform),Z.matrixAppendRotationInv(qt._tempPatternMatrix,re,L,N,se,Q),n.setContextTransform(qt._tempPatternMatrix,h.roundPixels===1,void 0,G&&R)):n.setContextTransform(h.transform,h.roundPixels===1,void 0,G&&R);const Ut=se,Je=Q;let Oe=yt?0:L,Le=yt?0:N;if(!yt&&h.roundPixels===1&&(Oe|=0,Le|=0),Us){let et=u;const It=T!==16777215&&!re,xt=k.width<=c.source.width&&k.height<=c.source.height;It&&xt&&(et=Y.getTintedCanvas({texture:c},T));const zs=o.createPattern(et,M);if(!zs)continue;const sn=Ut,fh=Je;if(sn===0||fh===0)continue;const ph=1/sn,mh=1/fh,gh=(j.x1-j.x0)*ph,_h=(j.y1-j.y0)*ph,yh=(j.x3-j.x0)*mh,xh=(j.y3-j.y0)*mh,Ng=j.x0-gh*Oe-yh*Le,zg=j.y0-_h*Oe-xh*Le,rn=c.source.pixelWidth,nn=c.source.pixelHeight;qt._tempPatternMatrix.set(gh*rn,_h*nn,yh*rn,xh*nn,Ng*rn,zg*nn),Y.applyPatternTransform(zs,qt._tempPatternMatrix),o.fillStyle=zs,o.fillRect(Oe,Le,Ut,Je)}else{const It=T!==16777215||re?Y.getTintedCanvas({texture:c},T):u,xt=It!==u;o.drawImage(It,xt?0:O,xt?0:I,xt?It.width:P,xt?It.height:C,Oe,Le,Ut,Je)}}}};tl._tempPatternMatrix=new U;tl.extension={type:[S.CanvasPipesAdaptor],name:"batch"};let Ap=tl;class sl{constructor(){this._tempState=_t.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,s){const r=e.renderer,n=this._didUploadHash[s.uid];r.shader.bind(s,n),n||(this._didUploadHash[s.uid]=!0),r.shader.updateUniformGroup(r.globalUniforms.uniformGroup),r.geometry.bind(t,s.glProgram)}execute(e,t){const s=e.renderer;this._tempState.blendMode=t.blendMode,s.state.set(this._tempState);const r=t.textures.textures;for(let n=0;n<t.textures.count;n++)s.texture.bind(r[n],n);s.texture.unbindIntegerTextures(t.textures.count),s.geometry.draw(t.topology,t.size,t.start)}}sl.extension={type:[S.WebGLPipesAdaptor],name:"batch"};const Wi=_t.for2d();class il{start(e,t,s){const r=e.renderer,n=r.encoder,o=s.gpuProgram;this._shader=s,this._geometry=t,n.setGeometry(t,o),Wi.blendMode="normal",r.pipeline.getPipeline(t,o,Wi,void 0,s._overrides);const a=r.globalUniforms.bindGroup;n.resetBindGroup(1),n.setBindGroup(0,a,o)}execute(e,t){const s=this._shader.gpuProgram,r=e.renderer,n=r.encoder;if(!t.bindGroup){const l=t.textures;t.bindGroup=Ar(l.textures,l.count,r.limits.maxBatchableTextures)}Wi.blendMode=t.blendMode;const o=r.bindGroup.getBindGroup(t.bindGroup,s,1),a=r.pipeline.getPipeline(this._geometry,s,Wi,t.topology,this._shader._overrides);t.bindGroup._touch(r.gc.now),n.setPipeline(a),n.renderPassEncoder.setBindGroup(1,o),n.renderPassEncoder.drawIndexed(t.size,1,t.start)}}il.extension={type:[S.WebGPUPipesAdaptor],name:"batch"};const rl=class Rp{constructor(e,t){this.state=_t.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init?.(this)}static getBatcher(e,t){return new this._availableBatchers[e]({maxTextures:t})}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new Dr({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const s in this._activeBatches)this._activeBatches[s].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let s=this._activeBatches[e.batcherName];s||(s=this._activeBatches[e.batcherName]=Rp.getBatcher(e.batcherName,this.renderer.limits.maxBatchableTextures),s.begin()),this._activeBatch=s}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const s in t){const r=t[s],n=r.geometry;n.indexBuffer.setDataWithSize(r.indexBuffer,r.indexSize,!0),n.buffers[0].setDataWithSize(r.attributeBuffer.float32View,r.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const s in t){const r=t[s],n=r.geometry;r.dirty&&(r.dirty=!1,n.buffers[0].update(r.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,s=t.geometry,r=t.shader;this._adaptor.start(this,s,r)}this._adaptor.execute(this,e)}destroyInstructionSet(e){const t=this._batchersByInstructionSet[e.uid];if(t){for(const s in t)t[s].destroy();delete this._batchersByInstructionSet[e.uid],this._activeBatches===t&&(this._activeBatches=Object.create(null),this._activeBatch=null)}}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};rl.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"batch"};rl._availableBatchers=Object.create(null);let Nr=rl;q.handleByMap(S.Batcher,Nr._availableBatchers);q.add(Dr);const Bp={name:"texture-bit",vertex:{header:`
558
558
 
559
559
  struct TextureUniforms {
560
560
  uTextureMatrix:mat3x3<f32>,
@@ -570,7 +570,7 @@ fn mainFragment(
570
570
 
571
571
  `,main:`
572
572
  outColor = textureSample(uTexture, uSampler, vUV);
573
- `}},Pp={name:"texture-bit",vertex:{header:`
573
+ `}},Ip={name:"texture-bit",vertex:{header:`
574
574
  uniform mat3 uTextureMatrix;
575
575
  `,main:`
576
576
  uv = (uTextureMatrix * vec3(uv, 1.0)).xy;
@@ -580,9 +580,9 @@ fn mainFragment(
580
580
 
581
581
  `,main:`
582
582
  outColor = texture(uTexture, vUV);
583
- `}},_y=new Ee;class yy extends hi{constructor(){super(),this._placeholderSprite=new ss(W.EMPTY),this.filters=[new Jf({sprite:this._placeholderSprite,inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].setSprite(e)}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}get channel(){return this.filters[0].channel}set channel(e){this.filters[0].channel=e}reset(){this._placeholderSprite.texture=W.EMPTY,this.sprite=this._placeholderSprite}}class Ur{constructor(e){this._activeMaskStage=[],this._usedEffects=[],this._renderer=e,e.runners.postrender.add(this)}push(e,t,s){const r=this._renderer;if(r.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.channel=t._maskOptions.channel??"red",e.renderMaskToTexture){const n=e.mask;n.includeInBuild=!0,n.collectRenderables(s,r,null),n.includeInBuild=!1}r.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,s=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const r=Se.get(yy);if(r.inverse=e.inverse,r.channel=e.mask.channel,s){e.mask.mask.measurable=!0;const n=_r(e.mask.mask,!0,_y);e.mask.mask.measurable=!1,n.ceil();const o=t.renderTarget.renderTarget.colorTexture.source,a=Te.getOptimalTexture({width:n.width,height:n.height,resolution:o._resolution,antialias:o.antialias});t.renderTarget.push({target:a,clear:!0}),t.globalUniforms.push({offset:n,worldColor:4294967295});const l=r.sprite;l.texture=a,l.worldTransform.tx=n.minX,l.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:r,maskedContainer:e.maskedContainer,filterTexture:a})}else r.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:r,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const r=this._activeMaskStage[this._activeMaskStage.length-1];s&&(t.type===Ke.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:r.maskedContainer,filterEffect:r.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const r=this._activeMaskStage.pop();s&&Te.returnTexture(r.filterTexture),this._usedEffects.push(r.filterEffect)}}postrender(){const e=this._usedEffects;for(let t=0;t<e.length;t++)Se.return(e[t]);e.length=0}destroy(){this.postrender(),this._renderer.runners.postrender.remove(this),this._renderer=null,this._activeMaskStage=null,this._usedEffects=null}}Ur.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"alphaMask"};class Qa{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,s){this._renderer.renderPipes.batch.break(s);const r=this._colorStack;r[this._colorStackIndex]=r[this._colorStackIndex-1]&e.mask;const n=this._colorStack[this._colorStackIndex];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1})),this._colorStackIndex++}pop(e,t,s){this._renderer.renderPipes.batch.break(s);const r=this._colorStack;this._colorStackIndex--;const n=r[this._colorStackIndex-1];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}Qa.extension={type:[S.CanvasPipes],name:"colorMask"};class Ja{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}Ja.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"colorMask"};function xy(i,e,t,s,r,n){n=Math.max(0,Math.min(n,Math.min(s,r)/2)),i.moveTo(e+n,t),i.lineTo(e+s-n,t),i.quadraticCurveTo(e+s,t,e+s,t+n),i.lineTo(e+s,t+r-n),i.quadraticCurveTo(e+s,t+r,e+s-n,t+r),i.lineTo(e+n,t+r),i.quadraticCurveTo(e,t+r,e,t+r-n),i.lineTo(e,t+n),i.quadraticCurveTo(e,t,e+n,t)}function Ap(i,e){switch(e.type){case"rectangle":{const t=e;i.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;xy(i,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;i.moveTo(t.x+t.radius,t.y),i.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;i.ellipse?(i.moveTo(t.x+t.halfWidth,t.y),i.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(i.save(),i.translate(t.x,t.y),i.scale(t.halfWidth,t.halfHeight),i.moveTo(1,0),i.arc(0,0,1,0,Math.PI*2),i.restore());break}case"triangle":{const t=e;i.moveTo(t.x,t.y),i.lineTo(t.x2,t.y2),i.lineTo(t.x3,t.y3),i.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!s?.length)break;i.moveTo(s[0],s[1]);for(let r=2;r<s.length;r+=2)i.lineTo(s[r],s[r+1]);t.closePath&&i.closePath();break}}}function by(i,e,t){const s=[],r=[],n=[];if(!hs[e.type]?.build(e,s))return!1;const a=e.closePath??!0;Dr(s,t,!1,a,r,n);for(let l=0;l<n.length;l+=3){const h=n[l]*2,c=n[l+1]*2,u=n[l+2]*2;i.moveTo(r[h],r[h+1]),i.lineTo(r[c],r[c+1]),i.lineTo(r[u],r[u+1]),i.closePath()}return!0}function vy(i,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!s?.shape)continue;const r=s.transform,n=r&&!r.isIdentity();n&&(i.save(),i.transform(r.a,r.b,r.c,r.d,r.tx,r.ty)),Ap(i,s.shape),n&&i.restore()}return!0}class el{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,s=t.canvasContext,r=s?.activeContext;if(!r)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&r.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const n=e.mask.mask;if(!(n instanceof Pe)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const o=n,a=o.context?.instructions;if(!a?.length){this._canvasMaskStack.push(!1);return}r.save(),s.setContextTransform(o.groupTransform,(t._roundPixels|o._roundPixels)===1),r.beginPath();let l=!1,h=!1;for(let c=0;c<a.length;c++){const u=a[c],d=u.action;if(d!=="fill"&&d!=="stroke")continue;const f=u.data,p=f?.path?.shapePath;if(!p?.shapePrimitives?.length)continue;const g=d==="stroke",m=p.shapePrimitives;for(let _=0;_<m.length;_++){const y=m[_];if(!y?.shape)continue;const x=y.transform,b=x&&!x.isIdentity();b&&(r.save(),r.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),g&&f.style?l=by(r,y.shape,f.style)||l:(Ap(r,y.shape),h=vy(r,y.holes)||h,l=!0),b&&r.restore()}}if(!l){r.restore(),this._canvasMaskStack.push(!1);return}h?r.clip("evenodd"):r.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),z(t))}}el.extension={type:[S.CanvasPipes],name:"stencilMask"};class tl{constructor(e){this._maskHash=new WeakMap,this._renderer=e}push(e,t,s){const r=e,n=this._renderer;n.renderPipes.batch.break(s),n.renderPipes.blendMode.setBlendMode(r.mask,"none",s),s.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const o=r.mask;o.includeInBuild=!0,this._maskHash.has(r)||this._maskHash.set(r,{instructionsStart:0,instructionsLength:0});const a=this._maskHash.get(r);a.instructionsStart=s.instructionSize,o.collectRenderables(s,n,null),o.includeInBuild=!1,n.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const l=s.instructionSize-a.instructionsStart-1;a.instructionsLength=l}pop(e,t,s){const r=e,n=this._renderer;n.renderPipes.batch.break(s),n.renderPipes.blendMode.setBlendMode(r.mask,"none",s),s.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const o=this._maskHash.get(e);for(let a=0;a<o.instructionsLength;a++)s.instructions[s.instructionSize++]=s.instructions[o.instructionsStart++];s.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){const s=this._renderer,r=s.renderTarget.getGpuRenderTarget(s.renderTarget.renderTarget);let n=r.maskStackIndex;e.action==="pushMaskBegin"?(s.renderTarget.ensureDepthStencil(),s.stencil.setStencilMode(me.RENDERING_MASK_ADD,n),n++,s.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?s.stencil.setStencilMode(me.INVERSE_MASK_ACTIVE,n):s.stencil.setStencilMode(me.MASK_ACTIVE,n),s.colorMask.setMask(15)):e.action==="popMaskBegin"?(s.colorMask.setMask(0),n!==0?s.stencil.setStencilMode(me.RENDERING_MASK_REMOVE,n):(s.renderTarget.clear(null,ye.STENCIL),s.stencil.setStencilMode(me.DISABLED,n)),n--):e.action==="popMaskEnd"&&(e.inverse?s.stencil.setStencilMode(me.INVERSE_MASK_ACTIVE,n):s.stencil.setStencilMode(me.MASK_ACTIVE,n),s.colorMask.setMask(15)),r.maskStackIndex=n}destroy(){this._renderer=null,this._maskHash=null}}tl.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"stencilMask"};const le="source-over";function Rp(){const i=Pa(),e=Object.create(null);return e.inherit=le,e.none=le,e.normal="source-over",e.add="lighter",e.multiply=i?"multiply":le,e.screen=i?"screen":le,e.overlay=i?"overlay":le,e.darken=i?"darken":le,e.lighten=i?"lighten":le,e["color-dodge"]=i?"color-dodge":le,e["color-burn"]=i?"color-burn":le,e["hard-light"]=i?"hard-light":le,e["soft-light"]=i?"soft-light":le,e.difference=i?"difference":le,e.exclusion=i?"exclusion":le,e.saturation=i?"saturation":le,e.color=i?"color":le,e.luminosity=i?"luminosity":le,e["linear-burn"]=i?"color-burn":le,e["linear-dodge"]=i?"color-dodge":le,e["linear-light"]=i?"hard-light":le,e["pin-light"]=i?"hard-light":le,e["vivid-light"]=i?"hard-light":le,e["hard-mix"]=le,e.negation=i?"difference":le,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=le,e.divide=le,e.min=le,e.max=le,e}const wy=new U;class sl{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=Rp(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,s,r){const n=r?U.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||U.IDENTITY;let o=wy;o.copyFrom(n),o.append(e);const a=this._projTransform,l=this.activeResolution;if(s=s||l,a){const h=U.shared;h.copyFrom(o),h.prepend(a),o=h}t?this.activeContext.setTransform(o.a*s,o.b*s,o.c*s,o.d*s,o.tx*l|0,o.ty*l|0):this.activeContext.setTransform(o.a*s,o.b*s,o.c*s,o.d*s,o.tx*l,o.ty*l)}clear(e,t){const s=this.activeContext,r=this._renderer;if(s.clearRect(0,0,r.width,r.height),e){const n=ae.shared.setValue(e);s.globalAlpha=t??n.alpha,s.fillStyle=n.toHex(),s.fillRect(0,0,r.width,r.height),s.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}sl.extension={type:[S.CanvasSystem],name:"canvasContext"};class il{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}il.extension={type:[S.CanvasSystem],name:"limits"};class Nr{constructor(e){this._renderer=e}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}addRenderable(e,t){this._renderer.renderPipes.batch.break(t),t.add(e)}execute(e){e.isRenderable&&e.render(this._renderer)}destroy(){this._renderer=null}}Nr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"customRender"};function ur(i,e){const t=i.instructionSet,s=t.instructions;for(let r=0;r<t.instructionSize;r++){const n=s[r];e[n.renderPipeId].execute(n)}}class Hr{constructor(e){this._renderer=e}addRenderGroup(e,t){e.isCachedAsTexture?this._addRenderableCacheAsTexture(e,t):this._addRenderableDirect(e,t)}execute(e){e.isRenderable&&(e.isCachedAsTexture?this._executeCacheAsTexture(e):this._executeDirect(e))}destroy(){this._renderer=null}_addRenderableDirect(e,t){this._renderer.renderPipes.batch.break(t),e._batchableRenderGroup&&(Se.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const s=e._batchableRenderGroup??(e._batchableRenderGroup=Se.get(Or));s.renderable=e.root,s.transform=e.root.relativeGroupTransform,s.texture=e.texture,s.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(s,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=new U().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push({target:e.texture,clear:!0,frame:e.texture.frame}),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),ur(e,this._renderer.renderPipes),this._renderer.renderTarget.finishRenderPass(),this._renderer.renderTarget.pop(),this._renderer.globalUniforms.pop()}e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup),e._batchableRenderGroup._batcher.geometry.buffers[0].update()}_executeDirect(e){this._renderer.globalUniforms.push({worldTransformMatrix:e.inverseParentTextureTransform,worldColor:e.worldColorAlpha}),ur(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Hr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"renderGroup"};const Ty="#808080",Hi=new U,Sy=new U,Cy=new U,kn=new U,My=new U;function ky(i,e,t){i.beginPath();for(let s=0;s<t.length;s+=3){const r=t[s]*2,n=t[s+1]*2,o=t[s+2]*2;i.moveTo(e[r],e[r+1]),i.lineTo(e[n],e[n+1]),i.lineTo(e[o],e[o+1]),i.closePath()}i.fill()}function Ey(i){return`#${(i&16777215).toString(16).padStart(6,"0")}`}function Py(i,e,t,s,r,n){n=Math.max(0,Math.min(n,Math.min(s,r)/2)),i.moveTo(e+n,t),i.lineTo(e+s-n,t),i.quadraticCurveTo(e+s,t,e+s,t+n),i.lineTo(e+s,t+r-n),i.quadraticCurveTo(e+s,t+r,e+s-n,t+r),i.lineTo(e+n,t+r),i.quadraticCurveTo(e,t+r,e,t+r-n),i.lineTo(e,t+n),i.quadraticCurveTo(e,t,e+n,t)}function Ki(i,e){switch(e.type){case"rectangle":{const t=e;i.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;Py(i,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;i.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;i.ellipse?i.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(i.save(),i.translate(t.x,t.y),i.scale(t.halfWidth,t.halfHeight),i.arc(0,0,1,0,Math.PI*2),i.restore());break}case"triangle":{const t=e;i.moveTo(t.x,t.y),i.lineTo(t.x2,t.y2),i.lineTo(t.x3,t.y3),i.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!s?.length)break;i.moveTo(s[0],s[1]);for(let r=2;r<s.length;r+=2)i.lineTo(s[r],s[r+1]);t.closePath&&i.closePath();break}}}function Ay(i,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!s?.shape)continue;const r=s.transform,n=r&&!r.isIdentity();n&&(i.save(),i.transform(r.a,r.b,r.c,r.d,r.tx,r.ty)),Ki(i,s.shape),n&&i.restore()}return!0}function Ry(i,e,t,s){const r=i.fill;if(r instanceof je){r.buildGradient();const o=r.texture;if(o){const a=Y.getTintedPattern(o,e),l=t?kn.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):kn.copyFrom(r.transform);return s&&!i.textureSpace&&l.append(s),Y.applyPatternTransform(a,l),a}}if(r instanceof Fs){const o=Y.getTintedPattern(r.texture,e);return Y.applyPatternTransform(o,r.transform,!1),o}const n=i.texture;if(n&&n!==W.WHITE){if(!n.source.resource)return Ty;const o=Y.getTintedPattern(n,e);let a=i.matrix;if(t){const{resolution:l}=n.source;if(a=kn.copyFrom(t),n.rotate){const{uvs:h,orig:c}=n;a.prepend(My.set(h.x1-h.x0,h.y1-h.y0,h.x3-h.x0,h.y3-h.y0,h.x0,h.y0).invert()).scale(c.width*l,c.height*l)}else a.scale(n.source.pixelWidth,n.source.pixelHeight).translate(-n.frame.x*l,-n.frame.y*l)}return Y.applyPatternTransform(o,a),o}return Ey(e)}class rl{constructor(){this.shader=null}contextChange(e){}execute(e,t){const s=e.renderer,r=s.canvasContext,n=r.activeContext,o=t.groupTransform,a=s.globalUniforms.globalUniformData?.worldColor??4294967295,l=t.groupColorAlpha,h=(a>>>24&255)/255,c=(l>>>24&255)/255,u=s.filter?.alphaMultiplier??1,d=h*c*u;if(d<=0)return;const f=a&16777215,p=l&16777215,g=Zt(Kt(p,f)),m=s._roundPixels|t._roundPixels;n.save(),r.setContextTransform(o,m===1),r.setBlendMode(t.groupBlendMode);const _=t.context.instructions;for(let y=0;y<_.length;y++){const x=_[y];if(x.action==="texture"){const M=x.data,B=M.image,G=B?Y.getCanvasSource(B):null;if(!G)continue;const O=M.alpha*d;if(O<=0)continue;const I=Kt(M.style,g);n.globalAlpha=O;let P=G;I!==16777215&&(P=Y.getTintedCanvas({texture:B},I));const C=B.frame,D=B.source._resolution??B.source.resolution??1;let R=C.x*D,L=C.y*D;const N=C.width*D,se=C.height*D;P!==G&&(R=0,L=0);const Q=M.transform,re=Q&&!Q.isIdentity(),j=B.rotate;re||j?(Hi.copyFrom(o),re&&Hi.append(Q),j&&Z.matrixAppendRotationInv(Hi,j,M.dx,M.dy,M.dw,M.dh),r.setContextTransform(Hi,m===1)):r.setContextTransform(o,m===1),n.drawImage(P,R,L,P===G?N:P.width,P===G?se:P.height,j?0:M.dx,j?0:M.dy,M.dw,M.dh),(re||j)&&r.setContextTransform(o,m===1);continue}const b=x.data,v=b?.path?.shapePath;if(!v?.shapePrimitives?.length)continue;const w=b.style,T=Kt(w.color,g),k=w.alpha*d;if(k<=0)continue;const E=x.action==="stroke";if(n.globalAlpha=k,E){const M=w;n.lineWidth=M.width,n.lineCap=M.cap,n.lineJoin=M.join,n.miterLimit=M.miterLimit}const A=v.shapePrimitives;if(!E&&b.hole?.shapePath?.shapePrimitives?.length){const M=A[A.length-1];M.holes=b.hole.shapePath.shapePrimitives}for(let M=0;M<A.length;M++){const B=A[M];if(!B?.shape)continue;const G=B.transform,O=G&&!G.isIdentity(),I=w.texture&&w.texture!==W.WHITE,P=w.textureSpace==="global"?G:null,C=I?wa(Sy,w,B.shape,P):null,D=O?Cy.copyFrom(o).append(G):o,R=Ry(w,T,C,D);if(O&&(n.save(),n.transform(G.a,G.b,G.c,G.d,G.tx,G.ty)),E){const L=w;if(L.alignment!==.5&&!L.pixelLine){const se=[],Q=[],re=[];if(hs[B.shape.type]?.build(B.shape,se)){const Ze=B.shape.closePath??!0;Dr(se,L,!1,Ze,Q,re),n.fillStyle=R,ky(n,Q,re)}else n.strokeStyle=R,n.beginPath(),Ki(n,B.shape),n.stroke()}else n.strokeStyle=R,n.beginPath(),Ki(n,B.shape),n.stroke()}else n.fillStyle=R,n.beginPath(),Ki(n,B.shape),Ay(n,B.holes)?n.fill("evenodd"):n.fill();O&&n.restore()}}n.restore()}destroy(){this.shader=null}}rl.extension={type:[S.CanvasPipesAdaptor],name:"graphics"};class zr{constructor(e){this._renderer=e}addRenderable(e,t){const s=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,s),this._renderer.renderPipes.batch.addToBatch(s,t)}updateRenderable(e){const t=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,t),t._batcher.updateElement(t)}validateRenderable(e){const t=this._getGpuSprite(e);return!t._batcher.checkAndUpdateTexture(t,e._texture)}_updateBatchableSprite(e,t){t.bounds=e.visualBounds,t.texture=e._texture}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=new Or;return t.renderable=e,t.transform=e.groupTransform,t.texture=e._texture,t.bounds=e.visualBounds,t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}zr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"sprite"};const ri={};q.handle(S.BlendMode,i=>{if(!i.name)throw new Error("BlendMode extension must have a name property");ri[i.name]=i.ref},i=>{delete ri[i.name]});class Wr{constructor(e){this._blendModeStack=[],this._isAdvanced=!1,this._filterHash=Object.create(null),this._renderer=e,this._renderer.runners.prerender.add(this)}prerender(){this._activeBlendMode="normal",this._isAdvanced=!1}pushBlendMode(e,t,s){this._blendModeStack.push(t),this.setBlendMode(e,t,s)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,s){const r=e instanceof nr;if(this._activeBlendMode===t){this._isAdvanced&&e&&!r&&this._renderableList?.push(e);return}this._isAdvanced&&this._endAdvancedBlendMode(s),this._activeBlendMode=t,e&&(this._isAdvanced=!!ri[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,s))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const s=this._activeBlendMode;if(!ri[s]){z(`Unable to assign BlendMode: '${s}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const r=this._ensureFilterEffect(s),n=e instanceof nr,o={renderPipeId:"filter",action:"pushFilter",filterEffect:r,renderables:n?null:[e],container:n?e.root:null,canBundle:!1};this._renderableList=o.renderables,t.add(o)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new hi,t.filters=[new ri[e]]),t}_endAdvancedBlendMode(e){this._isAdvanced=!1,this._renderableList=null,this._renderer.renderPipes.batch.break(e),e.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}buildStart(){this._isAdvanced=!1}buildEnd(e){this._isAdvanced&&this._endAdvancedBlendMode(e)}destroy(){this._renderer=null,this._renderableList=null;for(const e in this._filterHash)this._filterHash[e].destroy();this._filterHash=null}}Wr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"blendMode"};function dr(i,e){e||(e=0);for(let t=e;t<i.length&&i[t];t++)i[t]=null}const By=new _e,Ic=ws|ui|vr;function nl(i,e=!1){Bp(i);const t=i.childrenToUpdate,s=i.updateTick++;for(const r in t){const n=Number(r),o=t[r],a=o.list,l=o.index;for(let h=0;h<l;h++){const c=a[h];c.parentRenderGroup===i&&c.relativeRenderGroupDepth===n&&ol(c,s,0)}dr(a,l),o.index=0}if(e)for(let r=0;r<i.renderGroupChildren.length;r++)nl(i.renderGroupChildren[r],e)}function Bp(i){const e=i.root;let t;if(i.renderGroupParent){const s=i.renderGroupParent;i.worldTransform.appendFrom(e.relativeGroupTransform,s.worldTransform),i.worldColor=ci(e.groupColor,s.worldColor),t=e.groupAlpha*s.worldAlpha}else i.worldTransform.copyFrom(e.localTransform),i.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,i.worldAlpha=t,i.worldColorAlpha=i.worldColor+((t*255|0)<<24)}function ol(i,e,t){if(e===i.updateTick)return;i.updateTick=e,i.didChange=!1;const s=i.localTransform;i.updateLocalTransform();const r=i.parent;if(r&&!r.renderGroup?(t|=i._updateFlags,i.relativeGroupTransform.appendFrom(s,r.relativeGroupTransform),t&Ic&&Gc(i,r,t)):(t=i._updateFlags,i.relativeGroupTransform.copyFrom(s),t&Ic&&Gc(i,By,t)),!i.renderGroup){const n=i.children,o=n.length;for(let h=0;h<o;h++)ol(n[h],e,t);const a=i.parentRenderGroup,l=i;l.renderPipeId&&!a.structureDidChange&&a.updateRenderable(l)}}function Gc(i,e,t){if(t&ui){i.groupColor=ci(i.localColor,e.groupColor);let s=i.localAlpha*e.groupAlpha;s=s<0?0:s>1?1:s,i.groupAlpha=s,i.groupColorAlpha=i.groupColor+((s*255|0)<<24)}t&vr&&(i.groupBlendMode=i.localBlendMode==="inherit"?e.groupBlendMode:i.localBlendMode),t&ws&&(i.globalDisplayStatus=i.localDisplayStatus&e.globalDisplayStatus),i._updateFlags=0}function Ip(i,e){const{list:t}=i.childrenRenderablesToUpdate;let s=!1;for(let r=0;r<i.childrenRenderablesToUpdate.index;r++){const n=t[r];if(s=e[n.renderPipeId].validateRenderable(n),s)break}return i.structureDidChange=s,s}const Iy=new U;class al{constructor(e){this._renderer=e}render({container:e,transform:t}){const s=e.parent,r=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const n=this._renderer,o=Iy;t&&(o.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const a=n.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),n.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),ur(e.renderGroup,a),a.uniformBatch&&a.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(o),e.parent=s,e.renderGroup.renderGroupParent=r}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let s=e.renderGroupChildren.length-1;s>=0;s--)this._updateCachedRenderGroups(e.renderGroupChildren[s],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const s=e.root.getLocalBounds(),r=this._renderer,n=e.textureOptions.resolution||r.view.resolution,o=e.textureOptions.antialias??r.view.antialias,a=e.textureOptions.scaleMode??"linear",l=e.texture;s.ceil(),e.texture&&Te.returnTexture(e.texture);const h=Te.getOptimalTexture({width:s.width,height:s.height,resolution:n,antialias:o,scaleMode:a});e.texture=h,e._textureBounds||(e._textureBounds=new Ee),e._textureBounds.copyFrom(s),l!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(Te.returnTexture(e.texture),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,s=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=s,e.structureDidChange?dr(e.childrenRenderablesToUpdate.list,0):Ip(e,s),nl(e),e.structureDidChange?(e.structureDidChange=!1,this._buildInstructions(e,t)):this._updateRenderables(e),e.childrenRenderablesToUpdate.index=0,t.renderPipes.batch.upload(e.instructionSet),!(e.isCachedAsTexture&&!e.textureNeedsUpdate))for(let r=0;r<e.renderGroupChildren.length;r++)this._updateRenderGroups(e.renderGroupChildren[r])}_updateRenderables(e){const{list:t,index:s}=e.childrenRenderablesToUpdate;for(let r=0;r<s;r++){const n=t[r];n.didViewUpdate&&e.updateRenderable(n)}dr(t,s)}_buildInstructions(e,t){const s=e.root,r=e.instructionSet;r.reset();const n=t.renderPipes?t:t.batch.renderer,o=n.renderPipes;o.batch.buildStart(r),o.blendMode.buildStart(),o.colorMask.buildStart(),s.sortableChildren&&s.sortChildren(),s.collectRenderablesWithEffects(r,n,null),o.batch.buildEnd(r),o.blendMode.buildEnd(r)}}al.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"renderGroup"};const ll=class Gp{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new ae(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...Gp.defaultOptions,...e},this.clearBeforeRender=e.clearBeforeRender,this.color=e.background||e.backgroundColor||this._backgroundColor,this.alpha=e.backgroundAlpha,this._backgroundColor.setAlpha(e.backgroundAlpha)}get color(){return this._backgroundColor}set color(e){ae.shared.setValue(e).alpha<1&&this._backgroundColor.alpha===1&&z("Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."),this._backgroundColor.setValue(e)}get alpha(){return this._backgroundColor.alpha}set alpha(e){this._backgroundColor.setAlpha(e)}get colorRgba(){return this._backgroundColor.toArray()}destroy(){}};ll.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"background",priority:0};ll.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let Dp=ll;const En={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},hl=class Fp{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof _e||e instanceof W?{target:e,...t}:{...t,...e}}async image(e){const t=ee.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Fp.defaultImageOptions);const{format:t,quality:s}=e,r=this.canvas(e);if(r.toBlob!==void 0)return new Promise((n,o)=>{r.toBlob(a=>{if(!a){o(new Error("ICanvas.toBlob failed!"));return}const l=new FileReader;l.onload=()=>n(l.result),l.onerror=o,l.readAsDataURL(a)},En[t],s)});if(r.toDataURL!==void 0)return r.toDataURL(En[t],s);if(r.convertToBlob!==void 0){const n=await r.convertToBlob({type:En[t],quality:s});return new Promise((o,a)=>{const l=new FileReader;l.onload=()=>o(l.result),l.onerror=a,l.readAsDataURL(n)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(e){e=this._normalizeOptions(e);const t=e.target,s=this._renderer;if(t instanceof W)return s.texture.generateCanvas(t);const r=s.textureGenerator.generateTexture(e),n=s.texture.generateCanvas(r);return r.destroy(!0),n}pixels(e){e=this._normalizeOptions(e);const t=e.target,s=this._renderer,r=t instanceof W?t:s.textureGenerator.generateTexture(e),n=s.texture.getPixels(r);return t instanceof _e&&r.destroy(!0),n}texture(e){return e=this._normalizeOptions(e),e.target instanceof W?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),s=document.createElement("a");s.download=e.filename??"image.png",s.href=t.toDataURL("image/png"),document.body.appendChild(s),s.click(),document.body.removeChild(s)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const s=this.canvas(e),r=s.toDataURL();console.log(`[Pixi Texture] ${s.width}px ${s.height}px`);const n=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${r}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",n)}destroy(){this._renderer=null}};hl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"extract"};hl.defaultImageOptions={format:"png",quality:1};let Op=hl;class Ti extends W{static create(e){const{dynamic:t,textureOptions:s,...r}=e;return new Ti({...s,source:new de(r),dynamic:t??!1})}resize(e,t,s){return this.source.resize(e,t,s),this}}const Gy=new te,Dy=new Ee,Fy=[0,0,0,0];class cl{constructor(e){this._renderer=e}generateTexture(e){e instanceof _e&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,s=e.antialias||this._renderer.view.antialias,r=e.target;let n=e.clearColor;n?n=Array.isArray(n)&&n.length===4?n:ae.shared.setValue(n).toArray():n=Fy;const o=e.frame?.copyTo(Gy)||xr(r,Dy).rectangle,a=e.defaultAnchor&&{defaultAnchor:e.defaultAnchor};o.width=Math.max(o.width,1/t)|0,o.height=Math.max(o.height,1/t)|0;const l=Ti.create({...e.textureSourceOptions,width:o.width,height:o.height,resolution:t,antialias:s,textureOptions:a}),h=U.shared.translate(-o.x,-o.y);return this._renderer.render({container:r,transform:h,target:l,clearColor:n}),l.source.updateMipmaps(),l}destroy(){this._renderer=null}}cl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"textureGenerator"};function Lp(i){let e=!1;for(const s in i)if(i[s]==null){e=!0;break}if(!e)return i;const t=Object.create(null);for(const s in i){const r=i[s];r&&(t[s]=r)}return t}function Up(i){let e=0;for(let t=0;t<i.length;t++)i[t]==null?e++:i[t-e]=i[t];return i.length-=e,i}const ul=class Np{constructor(e){this._managedResources=[],this._managedResourceHashes=[],this._managedCollections=[],this._ready=!1,this._running=!1,this._renderer=e}init(e){e={...Np.defaultOptions,...e},this.maxUnusedTime=e.gcMaxUnusedTime,this._frequency=e.gcFrequency,this.enabled=e.gcActive,this.now=performance.now()}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>{this._ready=!0},this._frequency,!1),this._collectionsHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedCollections){const{context:s,collection:r,type:n}=t;n==="hash"?s[r]=Lp(s[r]):s[r]=Up(s[r])}},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._collectionsHandler),this._handler=0,this._collectionsHandler=0))}prerender({container:e}){this.now=performance.now(),e.renderGroup.gcTick=this._renderer.tick++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}postrender(){!this._ready||!this.enabled||(this.run(),this._ready=!1)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t,e.gcTick=t;for(const s of e.renderGroupChildren)this._updateInstructionGCTick(s,t)}addCollection(e,t,s){this._managedCollections.push({context:e,collection:t,type:s})}addResource(e,t){if(e._gcLastUsed!==-1){e._gcLastUsed=this.now,e._onTouch?.(this.now);return}const s=this._managedResources.length;e._gcData={index:s,type:t},e._gcLastUsed=this.now,e._onTouch?.(this.now),e.once("unload",this.removeResource,this),this._managedResources.push(e)}removeResource(e){const t=e._gcData;if(!t)return;const s=t.index,r=this._managedResources.length-1;if(this._running)this._managedResources[s]=null;else{if(s!==r){const n=this._managedResources[r];this._managedResources[s]=n,n._gcData.index=s}this._managedResources.length--}e._gcData=null,e._gcLastUsed=-1}addResourceHash(e,t,s,r=0){this._managedResourceHashes.push({context:e,hash:t,type:s,priority:r}),this._managedResourceHashes.sort((n,o)=>n.priority-o.priority)}run(){if(this._running)return;const e=performance.now(),t=this._managedResourceHashes,s=this._managedResources;this._running=!0;try{for(const n of t)this.runOnHash(n,e);const r=s.length;for(let n=0;n<r;n++){const o=s[n];o&&this.runOnResource(o,e)}}finally{let r=0;for(let n=0;n<s.length;n++){const o=s[n];o&&(r!==n&&(s[r]=o,o._gcData.index=r),r++)}s.length=r,this._running=!1}}updateRenderableGCTick(e,t){const s=e.renderGroup??e.parentRenderGroup,r=s?.instructionSet?.gcTick??-1;(s?.gcTick??0)===r&&(e._gcLastUsed=t,e._onTouch?.(t))}runOnResource(e,t){e._gcData.type==="renderable"&&this.updateRenderableGCTick(e,t),!(t-e._gcLastUsed<this.maxUnusedTime||!e.autoGarbageCollect)&&(e.off("unload",this.removeResource,this),e.unload(),this.removeResource(e))}_createHashClone(e,t){const s=Object.create(null);for(const r in e){if(r===t)break;e[r]!==null&&(s[r]=e[r])}return s}runOnHash(e,t){const{context:s,hash:r,type:n}=e,o=s[r];let a=null,l=0;for(const h in o){const c=o[h];if(c===null){l++,l===1e4&&!a&&(a=this._createHashClone(o,h));continue}if(c._gcLastUsed===-1){c._gcLastUsed=t,c._onTouch?.(t),a&&(a[h]=c);continue}if(n==="renderable"&&this.updateRenderableGCTick(c,t),!(t-c._gcLastUsed<this.maxUnusedTime)&&c.autoGarbageCollect){if(n==="renderable"){const d=c,f=d.renderGroup??d.parentRenderGroup;f&&(f.structureDidChange=!0)}c.unload(),c._gcData=null,c._gcLastUsed=-1,a||(l+1!==1e4?(o[h]=null,l++):a=this._createHashClone(o,h))}else a&&(a[h]=c)}a&&(s[r]=a)}destroy(){this.enabled=!1,this._managedResources.forEach(e=>{e?.off("unload",this.removeResource,this)}),this._managedResources.length=0,this._managedResourceHashes.length=0,this._managedCollections.length=0,this._renderer=null}};ul.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"gc",priority:0};ul.defaultOptions={gcActive:!0,gcMaxUnusedTime:6e4,gcFrequency:3e4};let Hp=ul;class dl{constructor(e){this._stackIndex=0,this._globalUniformDataStack=[],this._uniformsPool=[],this._activeUniforms=[],this._bindGroupPool=[],this._activeBindGroups=[],this._renderer=e}reset(){this._stackIndex=0;for(let e=0;e<this._activeUniforms.length;e++)this._uniformsPool.push(this._activeUniforms[e]);for(let e=0;e<this._activeBindGroups.length;e++)this._bindGroupPool.push(this._activeBindGroups[e]);this._activeUniforms.length=0,this._activeBindGroups.length=0}start(e){this.reset(),this.push(e)}bind({size:e,projectionMatrix:t,worldTransformMatrix:s,worldColor:r,offset:n}){const o=this._renderer.renderTarget.renderTarget,a=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new U,worldColor:4294967295,offset:new he},l={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||o.size,worldTransformMatrix:s||a.worldTransformMatrix,worldColor:r||a.worldColor,offset:n||a.offset,bindGroup:null},h=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(h);const c=h.uniforms;c.uProjectionMatrix=l.projectionMatrix,c.uResolution=l.resolution,c.uWorldTransformMatrix.copyFrom(l.worldTransformMatrix),c.uWorldTransformMatrix.tx-=l.offset.x,c.uWorldTransformMatrix.ty-=l.offset.y,Ga(l.worldColor,c.uWorldColorAlpha,0),h.update();let u;this._renderer.renderPipes.uniformBatch?u=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(h,!1):(u=this._bindGroupPool.pop()||new Mt,this._activeBindGroups.push(u),u.setResource(h,0)),l.bindGroup=u,this._currentGlobalUniformData=l}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===Ke.WEBGL&&this._currentGlobalUniformData.bindGroup.resources[0].update()}get bindGroup(){return this._currentGlobalUniformData.bindGroup}get globalUniformData(){return this._currentGlobalUniformData}get uniformGroup(){return this._currentGlobalUniformData.bindGroup.resources[0]}_createUniforms(){return new rt({uProjectionMatrix:{value:new U,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new U,type:"mat3x3<f32>"},uWorldColorAlpha:{value:new Float32Array(4),type:"vec4<f32>"},uResolution:{value:[0,0],type:"vec2<f32>"}},{isStatic:!0})}destroy(){this._renderer=null,this._globalUniformDataStack.length=0,this._uniformsPool.length=0,this._activeUniforms.length=0,this._bindGroupPool.length=0,this._activeBindGroups.length=0,this._currentGlobalUniformData=null}}dl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"globalUniforms"};let Oy=1;class fl{constructor(){this._tasks=[],this._offset=0}init(){We.system.add(this._update,this)}repeat(e,t,s=!0){const r=Oy++;let n=0;return s&&(this._offset+=1e3,n=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:n,last:performance.now(),repeat:!0,id:r}),r}cancel(e){for(let t=0;t<this._tasks.length;t++)if(this._tasks[t].id===e){this._tasks.splice(t,1);return}}_update(){const e=performance.now();for(let t=0;t<this._tasks.length;t++){const s=this._tasks[t];if(e-s.offset-s.last>=s.duration){const r=e-s.start;s.func(r),s.last=e}}}destroy(){We.system.remove(this._update,this),this._tasks.length=0}}fl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"scheduler",priority:0};let Dc=!1;function zp(i){if(!Dc){if(ee.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${_i} (${i}) http://www.pixijs.com/
583
+ `}},Ty=new Ee;class Sy extends ci{constructor(){super(),this._placeholderSprite=new ns(W.EMPTY),this.filters=[new ip({sprite:this._placeholderSprite,inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].setSprite(e)}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}get channel(){return this.filters[0].channel}set channel(e){this.filters[0].channel=e}reset(){this._placeholderSprite.texture=W.EMPTY,this.sprite=this._placeholderSprite}}class zr{constructor(e){this._activeMaskStage=[],this._usedEffects=[],this._renderer=e,e.runners.postrender.add(this)}push(e,t,s){const r=this._renderer;if(r.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.channel=t._maskOptions.channel??"red",e.renderMaskToTexture){const n=e.mask;n.includeInBuild=!0,n.collectRenderables(s,r,null),n.includeInBuild=!1}r.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,s=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const r=Se.get(Sy);if(r.inverse=e.inverse,r.channel=e.mask.channel,s){e.mask.mask.measurable=!0;const n=br(e.mask.mask,!0,Ty);e.mask.mask.measurable=!1,n.ceil();const o=t.renderTarget.renderTarget.colorTexture.source,a=Te.getOptimalTexture({width:n.width,height:n.height,resolution:o._resolution,antialias:o.antialias});t.renderTarget.push({target:a,clear:!0}),t.globalUniforms.push({offset:n,worldColor:4294967295});const l=r.sprite;l.texture=a,l.worldTransform.tx=n.minX,l.worldTransform.ty=n.minY,this._activeMaskStage.push({filterEffect:r,maskedContainer:e.maskedContainer,filterTexture:a})}else r.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:r,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const r=this._activeMaskStage[this._activeMaskStage.length-1];s&&(t.type===Ke.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:r.maskedContainer,filterEffect:r.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const r=this._activeMaskStage.pop();s&&Te.returnTexture(r.filterTexture),this._usedEffects.push(r.filterEffect)}}postrender(){const e=this._usedEffects;for(let t=0;t<e.length;t++)Se.return(e[t]);e.length=0}destroy(){this.postrender(),this._renderer.runners.postrender.remove(this),this._renderer=null,this._activeMaskStage=null,this._usedEffects=null}}zr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"alphaMask"};class nl{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,s){this._renderer.renderPipes.batch.break(s);const r=this._colorStack;r[this._colorStackIndex]=r[this._colorStackIndex-1]&e.mask;const n=this._colorStack[this._colorStackIndex];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1})),this._colorStackIndex++}pop(e,t,s){this._renderer.renderPipes.batch.break(s);const r=this._colorStack;this._colorStackIndex--;const n=r[this._colorStackIndex-1];n!==this._currentColor&&(this._currentColor=n,s.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1}))}execute(e){}destroy(){this._renderer=null,this._colorStack=null}}nl.extension={type:[S.CanvasPipes],name:"colorMask"};class ol{constructor(e){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=e}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&e.mask;const o=this._colorStack[this._colorStackIndex];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1})),this._colorStackIndex++}pop(e,t,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;this._colorStackIndex--;const o=n[this._colorStackIndex-1];o!==this._currentColor&&(this._currentColor=o,s.add({renderPipeId:"colorMask",colorMask:o,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}ol.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"colorMask"};function Cy(i,e,t,s,r,n){n=Math.max(0,Math.min(n,Math.min(s,r)/2)),i.moveTo(e+n,t),i.lineTo(e+s-n,t),i.quadraticCurveTo(e+s,t,e+s,t+n),i.lineTo(e+s,t+r-n),i.quadraticCurveTo(e+s,t+r,e+s-n,t+r),i.lineTo(e+n,t+r),i.quadraticCurveTo(e,t+r,e,t+r-n),i.lineTo(e,t+n),i.quadraticCurveTo(e,t,e+n,t)}function Gp(i,e){switch(e.type){case"rectangle":{const t=e;i.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;Cy(i,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;i.moveTo(t.x+t.radius,t.y),i.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;i.ellipse?(i.moveTo(t.x+t.halfWidth,t.y),i.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2)):(i.save(),i.translate(t.x,t.y),i.scale(t.halfWidth,t.halfHeight),i.moveTo(1,0),i.arc(0,0,1,0,Math.PI*2),i.restore());break}case"triangle":{const t=e;i.moveTo(t.x,t.y),i.lineTo(t.x2,t.y2),i.lineTo(t.x3,t.y3),i.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!s?.length)break;i.moveTo(s[0],s[1]);for(let r=2;r<s.length;r+=2)i.lineTo(s[r],s[r+1]);t.closePath&&i.closePath();break}}}function My(i,e,t){const s=[],r=[],n=[];if(!fs[e.type]?.build(e,s))return!1;const a=e.closePath??!0;Or(s,t,!1,a,r,n);for(let l=0;l<n.length;l+=3){const h=n[l]*2,c=n[l+1]*2,u=n[l+2]*2;i.moveTo(r[h],r[h+1]),i.lineTo(r[c],r[c+1]),i.lineTo(r[u],r[u+1]),i.closePath()}return!0}function ky(i,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!s?.shape)continue;const r=s.transform,n=r&&!r.isIdentity();n&&(i.save(),i.transform(r.a,r.b,r.c,r.d,r.tx,r.ty)),Gp(i,s.shape),n&&i.restore()}return!0}class al{constructor(e){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=e}push(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,s){this._renderer.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){if(e.action!=="pushMaskBegin"&&e.action!=="popMaskEnd")return;const t=this._renderer,s=t.canvasContext,r=s?.activeContext;if(!r)return;if(e.action==="popMaskEnd"){this._canvasMaskStack.pop()&&r.restore();return}e.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");const n=e.mask.mask;if(!(n instanceof Pe)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}const o=n,a=o.context?.instructions;if(!a?.length){this._canvasMaskStack.push(!1);return}r.save(),s.setContextTransform(o.groupTransform,(t._roundPixels|o._roundPixels)===1),r.beginPath();let l=!1,h=!1;for(let c=0;c<a.length;c++){const u=a[c],d=u.action;if(d!=="fill"&&d!=="stroke")continue;const f=u.data,p=f?.path?.shapePath;if(!p?.shapePrimitives?.length)continue;const g=d==="stroke",m=p.shapePrimitives;for(let _=0;_<m.length;_++){const y=m[_];if(!y?.shape)continue;const x=y.transform,b=x&&!x.isIdentity();b&&(r.save(),r.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),g&&f.style?l=My(r,y.shape,f.style)||l:(Gp(r,y.shape),h=ky(r,y.holes)||h,l=!0),b&&r.restore()}}if(!l){r.restore(),this._canvasMaskStack.push(!1);return}h?r.clip("evenodd"):r.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(e,t){this._warnedMaskTypes.has(e)||(this._warnedMaskTypes.add(e),H(t))}}al.extension={type:[S.CanvasPipes],name:"stencilMask"};class ll{constructor(e){this._maskHash=new WeakMap,this._renderer=e}push(e,t,s){const r=e,n=this._renderer;n.renderPipes.batch.break(s),n.renderPipes.blendMode.setBlendMode(r.mask,"none",s),s.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const o=r.mask;o.includeInBuild=!0,this._maskHash.has(r)||this._maskHash.set(r,{instructionsStart:0,instructionsLength:0});const a=this._maskHash.get(r);a.instructionsStart=s.instructionSize,o.collectRenderables(s,n,null),o.includeInBuild=!1,n.renderPipes.batch.break(s),s.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const l=s.instructionSize-a.instructionsStart-1;a.instructionsLength=l}pop(e,t,s){const r=e,n=this._renderer;n.renderPipes.batch.break(s),n.renderPipes.blendMode.setBlendMode(r.mask,"none",s),s.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const o=this._maskHash.get(e);for(let a=0;a<o.instructionsLength;a++)s.instructions[s.instructionSize++]=s.instructions[o.instructionsStart++];s.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){const s=this._renderer,r=s.renderTarget.getGpuRenderTarget(s.renderTarget.renderTarget);let n=r.maskStackIndex;e.action==="pushMaskBegin"?(s.renderTarget.ensureDepthStencil(),s.stencil.setStencilMode(me.RENDERING_MASK_ADD,n),n++,s.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?s.stencil.setStencilMode(me.INVERSE_MASK_ACTIVE,n):s.stencil.setStencilMode(me.MASK_ACTIVE,n),s.colorMask.setMask(15)):e.action==="popMaskBegin"?(s.colorMask.setMask(0),n!==0?s.stencil.setStencilMode(me.RENDERING_MASK_REMOVE,n):(s.renderTarget.clear(null,ye.STENCIL),s.stencil.setStencilMode(me.DISABLED,n)),n--):e.action==="popMaskEnd"&&(e.inverse?s.stencil.setStencilMode(me.INVERSE_MASK_ACTIVE,n):s.stencil.setStencilMode(me.MASK_ACTIVE,n),s.colorMask.setMask(15)),r.maskStackIndex=n}destroy(){this._renderer=null,this._maskHash=null}}ll.extension={type:[S.WebGLPipes,S.WebGPUPipes],name:"stencilMask"};const he="source-over";function Dp(){const i=Fa(),e=Object.create(null);return e.inherit=he,e.none=he,e.normal="source-over",e.add="lighter",e.multiply=i?"multiply":he,e.screen=i?"screen":he,e.overlay=i?"overlay":he,e.darken=i?"darken":he,e.lighten=i?"lighten":he,e["color-dodge"]=i?"color-dodge":he,e["color-burn"]=i?"color-burn":he,e["hard-light"]=i?"hard-light":he,e["soft-light"]=i?"soft-light":he,e.difference=i?"difference":he,e.exclusion=i?"exclusion":he,e.saturation=i?"saturation":he,e.color=i?"color":he,e.luminosity=i?"luminosity":he,e["linear-burn"]=i?"color-burn":he,e["linear-dodge"]=i?"color-dodge":he,e["linear-light"]=i?"hard-light":he,e["pin-light"]=i?"hard-light":he,e["vivid-light"]=i?"hard-light":he,e["hard-mix"]=he,e.negation=i?"difference":he,e["normal-npm"]=e.normal,e["add-npm"]=e.add,e["screen-npm"]=e.screen,e.erase="destination-out",e.subtract=he,e.divide=he,e.min=he,e.max=he,e}const Ey=new U;class hl{constructor(e){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=Dp(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=e}resolutionChange(e){this.activeResolution=e}init(){const e=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:e}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){const t=this.rootContext;t.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":t.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":t.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":t.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(e,t,s,r){const n=r?U.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||U.IDENTITY;let o=Ey;o.copyFrom(n),o.append(e);const a=this._projTransform,l=this.activeResolution;if(s=s||l,a){const h=U.shared;h.copyFrom(o),h.prepend(a),o=h}t?this.activeContext.setTransform(o.a*s,o.b*s,o.c*s,o.d*s,o.tx*l|0,o.ty*l|0):this.activeContext.setTransform(o.a*s,o.b*s,o.c*s,o.d*s,o.tx*l,o.ty*l)}clear(e,t){const s=this.activeContext,r=this._renderer;if(s.clearRect(0,0,r.width,r.height),e){const n=le.shared.setValue(e);s.globalAlpha=t??n.alpha,s.fillStyle=n.toHex(),s.fillRect(0,0,r.width,r.height),s.globalAlpha=1}}setBlendMode(e){if(this._activeBlendMode===e)return;this._activeBlendMode=e,this._outerBlend=!1;const t=this.blendModes[e];if(!t){this._warnedBlendModes.has(e)||(console.warn(`CanvasRenderer: blend mode "${e}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(e)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=t}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}}hl.extension={type:[S.CanvasSystem],name:"canvasContext"};class cl{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}}cl.extension={type:[S.CanvasSystem],name:"limits"};class Hr{constructor(e){this._renderer=e}updateRenderable(){}destroyRenderable(){}validateRenderable(){return!1}addRenderable(e,t){this._renderer.renderPipes.batch.break(t),t.add(e)}execute(e){e.isRenderable&&e.render(this._renderer)}destroy(){this._renderer=null}}Hr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"customRender"};function pr(i,e){const t=i.instructionSet,s=t.instructions;for(let r=0;r<t.instructionSize;r++){const n=s[r];e[n.renderPipeId].execute(n)}}class Wr{constructor(e){this._renderer=e}addRenderGroup(e,t){e.isCachedAsTexture?this._addRenderableCacheAsTexture(e,t):this._addRenderableDirect(e,t)}execute(e){e.isRenderable&&(e.isCachedAsTexture?this._executeCacheAsTexture(e):this._executeDirect(e))}destroy(){this._renderer=null}_addRenderableDirect(e,t){this._renderer.renderPipes.batch.break(t),e._batchableRenderGroup&&(Se.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const s=e._batchableRenderGroup??(e._batchableRenderGroup=Se.get(Ur));s.renderable=e.root,s.transform=e.root.relativeGroupTransform,s.texture=e.texture,s.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(s,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=new U().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push({target:e.texture,clear:!0,frame:e.texture.frame}),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),pr(e,this._renderer.renderPipes),this._renderer.renderTarget.finishRenderPass(),this._renderer.renderTarget.pop(),this._renderer.globalUniforms.pop()}e._batchableRenderGroup._batcher.updateElement(e._batchableRenderGroup),e._batchableRenderGroup._batcher.geometry.buffers[0].update()}_executeDirect(e){this._renderer.globalUniforms.push({worldTransformMatrix:e.inverseParentTextureTransform,worldColor:e.worldColorAlpha}),pr(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Wr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"renderGroup"};const Py="#808080",$i=new U,Ay=new U,Ry=new U,Gn=new U,By=new U;function Iy(i,e,t){i.beginPath();for(let s=0;s<t.length;s+=3){const r=t[s]*2,n=t[s+1]*2,o=t[s+2]*2;i.moveTo(e[r],e[r+1]),i.lineTo(e[n],e[n+1]),i.lineTo(e[o],e[o+1]),i.closePath()}i.fill()}function Gy(i){return`#${(i&16777215).toString(16).padStart(6,"0")}`}function Dy(i,e,t,s,r,n){n=Math.max(0,Math.min(n,Math.min(s,r)/2)),i.moveTo(e+n,t),i.lineTo(e+s-n,t),i.quadraticCurveTo(e+s,t,e+s,t+n),i.lineTo(e+s,t+r-n),i.quadraticCurveTo(e+s,t+r,e+s-n,t+r),i.lineTo(e+n,t+r),i.quadraticCurveTo(e,t+r,e,t+r-n),i.lineTo(e,t+n),i.quadraticCurveTo(e,t,e+n,t)}function Ji(i,e){switch(e.type){case"rectangle":{const t=e;i.rect(t.x,t.y,t.width,t.height);break}case"roundedRectangle":{const t=e;Dy(i,t.x,t.y,t.width,t.height,t.radius);break}case"circle":{const t=e;i.arc(t.x,t.y,t.radius,0,Math.PI*2);break}case"ellipse":{const t=e;i.ellipse?i.ellipse(t.x,t.y,t.halfWidth,t.halfHeight,0,0,Math.PI*2):(i.save(),i.translate(t.x,t.y),i.scale(t.halfWidth,t.halfHeight),i.arc(0,0,1,0,Math.PI*2),i.restore());break}case"triangle":{const t=e;i.moveTo(t.x,t.y),i.lineTo(t.x2,t.y2),i.lineTo(t.x3,t.y3),i.closePath();break}case"polygon":default:{const t=e,s=t.points;if(!s?.length)break;i.moveTo(s[0],s[1]);for(let r=2;r<s.length;r+=2)i.lineTo(s[r],s[r+1]);t.closePath&&i.closePath();break}}}function Fy(i,e){if(!e?.length)return!1;for(let t=0;t<e.length;t++){const s=e[t];if(!s?.shape)continue;const r=s.transform,n=r&&!r.isIdentity();n&&(i.save(),i.transform(r.a,r.b,r.c,r.d,r.tx,r.ty)),Ji(i,s.shape),n&&i.restore()}return!0}function Oy(i,e,t,s){const r=i.fill;if(r instanceof je){r.buildGradient();const o=r.texture;if(o){const a=Y.getTintedPattern(o,e),l=t?Gn.copyFrom(t).scale(o.source.pixelWidth,o.source.pixelHeight):Gn.copyFrom(r.transform);return s&&!i.textureSpace&&l.append(s),Y.applyPatternTransform(a,l),a}}if(r instanceof Ls){const o=Y.getTintedPattern(r.texture,e);return Y.applyPatternTransform(o,r.transform,!1),o}const n=i.texture;if(n&&n!==W.WHITE){if(!n.source.resource)return Py;const o=Y.getTintedPattern(n,e);let a=i.matrix;if(t){const{resolution:l}=n.source;if(a=Gn.copyFrom(t),n.rotate){const{uvs:h,orig:c}=n;a.prepend(By.set(h.x1-h.x0,h.y1-h.y0,h.x3-h.x0,h.y3-h.y0,h.x0,h.y0).invert()).scale(c.width*l,c.height*l)}else a.scale(n.source.pixelWidth,n.source.pixelHeight).translate(-n.frame.x*l,-n.frame.y*l)}return Y.applyPatternTransform(o,a),o}return Gy(e)}class ul{constructor(){this.shader=null}contextChange(e){}execute(e,t){const s=e.renderer,r=s.canvasContext,n=r.activeContext,o=t.groupTransform,a=s.globalUniforms.globalUniformData?.worldColor??4294967295,l=t.groupColorAlpha,h=(a>>>24&255)/255,c=(l>>>24&255)/255,u=s.filter?.alphaMultiplier??1,d=h*c*u;if(d<=0)return;const f=a&16777215,p=l&16777215,g=ts(es(p,f)),m=s._roundPixels|t._roundPixels;n.save(),r.setContextTransform(o,m===1),r.setBlendMode(t.groupBlendMode);const _=t.context.instructions;for(let y=0;y<_.length;y++){const x=_[y];if(x.action==="texture"){const M=x.data,B=M.image,G=B?Y.getCanvasSource(B):null;if(!G)continue;const O=M.alpha*d;if(O<=0)continue;const I=es(M.style,g);n.globalAlpha=O;let P=G;I!==16777215&&(P=Y.getTintedCanvas({texture:B},I));const C=B.frame,D=B.source._resolution??B.source.resolution??1;let R=C.x*D,L=C.y*D;const N=C.width*D,se=C.height*D;P!==G&&(R=0,L=0);const Q=M.transform,re=Q&&!Q.isIdentity(),j=B.rotate;re||j?($i.copyFrom(o),re&&$i.append(Q),j&&Z.matrixAppendRotationInv($i,j,M.dx,M.dy,M.dw,M.dh),r.setContextTransform($i,m===1)):r.setContextTransform(o,m===1),n.drawImage(P,R,L,P===G?N:P.width,P===G?se:P.height,j?0:M.dx,j?0:M.dy,M.dw,M.dh),(re||j)&&r.setContextTransform(o,m===1);continue}const b=x.data,v=b?.path?.shapePath;if(!v?.shapePrimitives?.length)continue;const w=b.style,T=es(w.color,g),k=w.alpha*d;if(k<=0)continue;const E=x.action==="stroke";if(n.globalAlpha=k,E){const M=w;n.lineWidth=M.width,n.lineCap=M.cap,n.lineJoin=M.join,n.miterLimit=M.miterLimit}const A=v.shapePrimitives;if(!E&&b.hole?.shapePath?.shapePrimitives?.length){const M=A[A.length-1];M.holes=b.hole.shapePath.shapePrimitives}for(let M=0;M<A.length;M++){const B=A[M];if(!B?.shape)continue;const G=B.transform,O=G&&!G.isIdentity(),I=w.texture&&w.texture!==W.WHITE,P=w.textureSpace==="global"?G:null,C=I?Pa(Ay,w,B.shape,P):null,D=O?Ry.copyFrom(o).append(G):o,R=Oy(w,T,C,D);if(O&&(n.save(),n.transform(G.a,G.b,G.c,G.d,G.tx,G.ty)),E){const L=w;if(L.alignment!==.5&&!L.pixelLine){const se=[],Q=[],re=[];if(fs[B.shape.type]?.build(B.shape,se)){const Qe=B.shape.closePath??!0;Or(se,L,!1,Qe,Q,re),n.fillStyle=R,Iy(n,Q,re)}else n.strokeStyle=R,n.beginPath(),Ji(n,B.shape),n.stroke()}else n.strokeStyle=R,n.beginPath(),Ji(n,B.shape),n.stroke()}else n.fillStyle=R,n.beginPath(),Ji(n,B.shape),Fy(n,B.holes)?n.fill("evenodd"):n.fill();O&&n.restore()}}n.restore()}destroy(){this.shader=null}}ul.extension={type:[S.CanvasPipesAdaptor],name:"graphics"};class $r{constructor(e){this._renderer=e}addRenderable(e,t){const s=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,s),this._renderer.renderPipes.batch.addToBatch(s,t)}updateRenderable(e){const t=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,t),t._batcher.updateElement(t)}validateRenderable(e){const t=this._getGpuSprite(e);return!t._batcher.checkAndUpdateTexture(t,e._texture)}_updateBatchableSprite(e,t){t.bounds=e.visualBounds,t.texture=e._texture}_getGpuSprite(e){return e._gpuData[this._renderer.uid]||this._initGPUSprite(e)}_initGPUSprite(e){const t=new Ur;return t.renderable=e,t.transform=e.groupTransform,t.texture=e._texture,t.bounds=e.visualBounds,t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}$r.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"sprite"};const oi={};q.handle(S.BlendMode,i=>{if(!i.name)throw new Error("BlendMode extension must have a name property");oi[i.name]=i.ref},i=>{delete oi[i.name]});class Vr{constructor(e){this._blendModeStack=[],this._isAdvanced=!1,this._filterHash=Object.create(null),this._renderer=e,this._renderer.runners.prerender.add(this)}prerender(){this._activeBlendMode="normal",this._isAdvanced=!1}pushBlendMode(e,t,s){this._blendModeStack.push(t),this.setBlendMode(e,t,s)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,s){const r=e instanceof lr;if(this._activeBlendMode===t){this._isAdvanced&&e&&!r&&this._renderableList?.push(e);return}this._isAdvanced&&this._endAdvancedBlendMode(s),this._activeBlendMode=t,e&&(this._isAdvanced=!!oi[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,s))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const s=this._activeBlendMode;if(!oi[s]){H(`Unable to assign BlendMode: '${s}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const r=this._ensureFilterEffect(s),n=e instanceof lr,o={renderPipeId:"filter",action:"pushFilter",filterEffect:r,renderables:n?null:[e],container:n?e.root:null,canBundle:!1};this._renderableList=o.renderables,t.add(o)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new ci,t.filters=[new oi[e]]),t}_endAdvancedBlendMode(e){this._isAdvanced=!1,this._renderableList=null,this._renderer.renderPipes.batch.break(e),e.add({renderPipeId:"filter",action:"popFilter",canBundle:!1})}buildStart(){this._isAdvanced=!1}buildEnd(e){this._isAdvanced&&this._endAdvancedBlendMode(e)}destroy(){this._renderer=null,this._renderableList=null;for(const e in this._filterHash)this._filterHash[e].destroy();this._filterHash=null}}Vr.extension={type:[S.WebGLPipes,S.WebGPUPipes,S.CanvasPipes],name:"blendMode"};function mr(i,e){e||(e=0);for(let t=e;t<i.length&&i[t];t++)i[t]=null}const Ly=new _e,Dc=Ms|di|Sr;function dl(i,e=!1){Fp(i);const t=i.childrenToUpdate,s=i.updateTick++;for(const r in t){const n=Number(r),o=t[r],a=o.list,l=o.index;for(let h=0;h<l;h++){const c=a[h];c.parentRenderGroup===i&&c.relativeRenderGroupDepth===n&&fl(c,s,0)}mr(a,l),o.index=0}if(e)for(let r=0;r<i.renderGroupChildren.length;r++)dl(i.renderGroupChildren[r],e)}function Fp(i){const e=i.root;let t;if(i.renderGroupParent){const s=i.renderGroupParent;i.worldTransform.appendFrom(e.relativeGroupTransform,s.worldTransform),i.worldColor=ui(e.groupColor,s.worldColor),t=e.groupAlpha*s.worldAlpha}else i.worldTransform.copyFrom(e.localTransform),i.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,i.worldAlpha=t,i.worldColorAlpha=i.worldColor+((t*255|0)<<24)}function fl(i,e,t){if(e===i.updateTick)return;i.updateTick=e,i.didChange=!1;const s=i.localTransform;i.updateLocalTransform();const r=i.parent;if(r&&!r.renderGroup?(t|=i._updateFlags,i.relativeGroupTransform.appendFrom(s,r.relativeGroupTransform),t&Dc&&Fc(i,r,t)):(t=i._updateFlags,i.relativeGroupTransform.copyFrom(s),t&Dc&&Fc(i,Ly,t)),!i.renderGroup){const n=i.children,o=n.length;for(let h=0;h<o;h++)fl(n[h],e,t);const a=i.parentRenderGroup,l=i;l.renderPipeId&&!a.structureDidChange&&a.updateRenderable(l)}}function Fc(i,e,t){if(t&di){i.groupColor=ui(i.localColor,e.groupColor);let s=i.localAlpha*e.groupAlpha;s=s<0?0:s>1?1:s,i.groupAlpha=s,i.groupColorAlpha=i.groupColor+((s*255|0)<<24)}t&Sr&&(i.groupBlendMode=i.localBlendMode==="inherit"?e.groupBlendMode:i.localBlendMode),t&Ms&&(i.globalDisplayStatus=i.localDisplayStatus&e.globalDisplayStatus),i._updateFlags=0}function Op(i,e){const{list:t}=i.childrenRenderablesToUpdate;let s=!1;for(let r=0;r<i.childrenRenderablesToUpdate.index;r++){const n=t[r];if(s=e[n.renderPipeId].validateRenderable(n),s)break}return i.structureDidChange=s,s}const Uy=new U;class pl{constructor(e){this._renderer=e}render({container:e,transform:t}){const s=e.parent,r=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const n=this._renderer,o=Uy;t&&(o.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const a=n.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),n.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),pr(e.renderGroup,a),a.uniformBatch&&a.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(o),e.parent=s,e.renderGroup.renderGroupParent=r}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let s=e.renderGroupChildren.length-1;s>=0;s--)this._updateCachedRenderGroups(e.renderGroupChildren[s],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const s=e.root.getLocalBounds(),r=this._renderer,n=e.textureOptions.resolution||r.view.resolution,o=e.textureOptions.antialias??r.view.antialias,a=e.textureOptions.scaleMode??"linear",l=e.texture;s.ceil(),e.texture&&Te.returnTexture(e.texture);const h=Te.getOptimalTexture({width:s.width,height:s.height,resolution:n,antialias:o,scaleMode:a});e.texture=h,e._textureBounds||(e._textureBounds=new Ee),e._textureBounds.copyFrom(s),l!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(Te.returnTexture(e.texture),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,s=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=s,e.structureDidChange?mr(e.childrenRenderablesToUpdate.list,0):Op(e,s),dl(e),e.structureDidChange?(e.structureDidChange=!1,this._buildInstructions(e,t)):this._updateRenderables(e),e.childrenRenderablesToUpdate.index=0,t.renderPipes.batch.upload(e.instructionSet),!(e.isCachedAsTexture&&!e.textureNeedsUpdate))for(let r=0;r<e.renderGroupChildren.length;r++)this._updateRenderGroups(e.renderGroupChildren[r])}_updateRenderables(e){const{list:t,index:s}=e.childrenRenderablesToUpdate;for(let r=0;r<s;r++){const n=t[r];n.didViewUpdate&&e.updateRenderable(n)}mr(t,s)}_buildInstructions(e,t){const s=e.root,r=e.instructionSet;r.reset();const n=t.renderPipes?t:t.batch.renderer,o=n.renderPipes;o.batch.buildStart(r),o.blendMode.buildStart(),o.colorMask.buildStart(),s.sortableChildren&&s.sortChildren(),s.collectRenderablesWithEffects(r,n,null),o.batch.buildEnd(r),o.blendMode.buildEnd(r)}}pl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"renderGroup"};const ml=class Lp{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new le(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...Lp.defaultOptions,...e},this.clearBeforeRender=e.clearBeforeRender,this.color=e.background||e.backgroundColor||this._backgroundColor,this.alpha=e.backgroundAlpha,this._backgroundColor.setAlpha(e.backgroundAlpha)}get color(){return this._backgroundColor}set color(e){le.shared.setValue(e).alpha<1&&this._backgroundColor.alpha===1&&H("Cannot set a transparent background on an opaque canvas. To enable transparency, set backgroundAlpha < 1 when initializing your Application."),this._backgroundColor.setValue(e)}get alpha(){return this._backgroundColor.alpha}set alpha(e){this._backgroundColor.setAlpha(e)}get colorRgba(){return this._backgroundColor.toArray()}destroy(){}};ml.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"background",priority:0};ml.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let Up=ml;const Dn={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},gl=class Np{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof _e||e instanceof W?{target:e,...t}:{...t,...e}}async image(e){const t=ee.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Np.defaultImageOptions);const{format:t,quality:s}=e,r=this.canvas(e);if(r.toBlob!==void 0)return new Promise((n,o)=>{r.toBlob(a=>{if(!a){o(new Error("ICanvas.toBlob failed!"));return}const l=new FileReader;l.onload=()=>n(l.result),l.onerror=o,l.readAsDataURL(a)},Dn[t],s)});if(r.toDataURL!==void 0)return r.toDataURL(Dn[t],s);if(r.convertToBlob!==void 0){const n=await r.convertToBlob({type:Dn[t],quality:s});return new Promise((o,a)=>{const l=new FileReader;l.onload=()=>o(l.result),l.onerror=a,l.readAsDataURL(n)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(e){e=this._normalizeOptions(e);const t=e.target,s=this._renderer;if(t instanceof W)return s.texture.generateCanvas(t);const r=s.textureGenerator.generateTexture(e),n=s.texture.generateCanvas(r);return r.destroy(!0),n}pixels(e){e=this._normalizeOptions(e);const t=e.target,s=this._renderer,r=t instanceof W?t:s.textureGenerator.generateTexture(e),n=s.texture.getPixels(r);return t instanceof _e&&r.destroy(!0),n}texture(e){return e=this._normalizeOptions(e),e.target instanceof W?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),s=document.createElement("a");s.download=e.filename??"image.png",s.href=t.toDataURL("image/png"),document.body.appendChild(s),s.click(),document.body.removeChild(s)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const s=this.canvas(e),r=s.toDataURL();console.log(`[Pixi Texture] ${s.width}px ${s.height}px`);const n=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${r}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",n)}destroy(){this._renderer=null}};gl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"extract"};gl.defaultImageOptions={format:"png",quality:1};let zp=gl;class Ci extends W{static create(e){const{dynamic:t,textureOptions:s,...r}=e;return new Ci({...s,source:new ue(r),dynamic:t??!1})}resize(e,t,s){return this.source.resize(e,t,s),this}}const Ny=new te,zy=new Ee,Hy=[0,0,0,0];class _l{constructor(e){this._renderer=e}generateTexture(e){e instanceof _e&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,s=e.antialias||this._renderer.view.antialias,r=e.target;let n=e.clearColor;n?n=Array.isArray(n)&&n.length===4?n:le.shared.setValue(n).toArray():n=Hy;const o=e.frame?.copyTo(Ny)||wr(r,zy).rectangle,a=e.defaultAnchor&&{defaultAnchor:e.defaultAnchor};o.width=Math.max(o.width,1/t)|0,o.height=Math.max(o.height,1/t)|0;const l=Ci.create({...e.textureSourceOptions,width:o.width,height:o.height,resolution:t,antialias:s,textureOptions:a}),h=U.shared.translate(-o.x,-o.y);return this._renderer.render({container:r,transform:h,target:l,clearColor:n}),l.source.updateMipmaps(),l}destroy(){this._renderer=null}}_l.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"textureGenerator"};function Hp(i){let e=!1;for(const s in i)if(i[s]==null){e=!0;break}if(!e)return i;const t=Object.create(null);for(const s in i){const r=i[s];r&&(t[s]=r)}return t}function Wp(i){let e=0;for(let t=0;t<i.length;t++)i[t]==null?e++:i[t-e]=i[t];return i.length-=e,i}const yl=class $p{constructor(e){this._managedResources=[],this._managedResourceHashes=[],this._managedCollections=[],this._ready=!1,this._running=!1,this._renderer=e}init(e){e={...$p.defaultOptions,...e},this.maxUnusedTime=e.gcMaxUnusedTime,this._frequency=e.gcFrequency,this.enabled=e.gcActive,this.now=performance.now()}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>{this._ready=!0},this._frequency,!1),this._collectionsHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedCollections){const{context:s,collection:r,type:n}=t;n==="hash"?s[r]=Hp(s[r]):s[r]=Wp(s[r])}},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._collectionsHandler),this._handler=0,this._collectionsHandler=0))}prerender({container:e}){this.now=performance.now(),e.renderGroup.gcTick=this._renderer.tick++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}postrender(){!this._ready||!this.enabled||(this.run(),this._ready=!1)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t,e.gcTick=t;for(const s of e.renderGroupChildren)this._updateInstructionGCTick(s,t)}addCollection(e,t,s){this._managedCollections.push({context:e,collection:t,type:s})}addResource(e,t){if(e._gcLastUsed!==-1){e._gcLastUsed=this.now,e._onTouch?.(this.now);return}const s=this._managedResources.length;e._gcData={index:s,type:t},e._gcLastUsed=this.now,e._onTouch?.(this.now),e.once("unload",this.removeResource,this),this._managedResources.push(e)}removeResource(e){const t=e._gcData;if(!t)return;const s=t.index,r=this._managedResources.length-1;if(this._running)this._managedResources[s]=null;else{if(s!==r){const n=this._managedResources[r];this._managedResources[s]=n,n._gcData.index=s}this._managedResources.length--}e._gcData=null,e._gcLastUsed=-1}addResourceHash(e,t,s,r=0){this._managedResourceHashes.push({context:e,hash:t,type:s,priority:r}),this._managedResourceHashes.sort((n,o)=>n.priority-o.priority)}run(){if(this._running)return;const e=performance.now(),t=this._managedResourceHashes,s=this._managedResources;this._running=!0;try{for(const n of t)this.runOnHash(n,e);const r=s.length;for(let n=0;n<r;n++){const o=s[n];o&&this.runOnResource(o,e)}}finally{let r=0;for(let n=0;n<s.length;n++){const o=s[n];o&&(r!==n&&(s[r]=o,o._gcData.index=r),r++)}s.length=r,this._running=!1}}updateRenderableGCTick(e,t){const s=e.renderGroup??e.parentRenderGroup,r=s?.instructionSet?.gcTick??-1;(s?.gcTick??0)===r&&(e._gcLastUsed=t,e._onTouch?.(t))}runOnResource(e,t){e._gcData.type==="renderable"&&this.updateRenderableGCTick(e,t),!(t-e._gcLastUsed<this.maxUnusedTime||!e.autoGarbageCollect)&&(e.off("unload",this.removeResource,this),e.unload(),this.removeResource(e))}_createHashClone(e,t){const s=Object.create(null);for(const r in e){if(r===t)break;e[r]!==null&&(s[r]=e[r])}return s}runOnHash(e,t){const{context:s,hash:r,type:n}=e,o=s[r];let a=null,l=0;for(const h in o){const c=o[h];if(c===null){l++,l===1e4&&!a&&(a=this._createHashClone(o,h));continue}if(c._gcLastUsed===-1){c._gcLastUsed=t,c._onTouch?.(t),a&&(a[h]=c);continue}if(n==="renderable"&&this.updateRenderableGCTick(c,t),!(t-c._gcLastUsed<this.maxUnusedTime)&&c.autoGarbageCollect){if(n==="renderable"){const d=c,f=d.renderGroup??d.parentRenderGroup;f&&(f.structureDidChange=!0)}c.unload(),c._gcData=null,c._gcLastUsed=-1,a||(l+1!==1e4?(o[h]=null,l++):a=this._createHashClone(o,h))}else a&&(a[h]=c)}a&&(s[r]=a)}destroy(){this.enabled=!1,this._managedResources.forEach(e=>{e?.off("unload",this.removeResource,this)}),this._managedResources.length=0,this._managedResourceHashes.length=0,this._managedCollections.length=0,this._renderer=null}};yl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"gc",priority:0};yl.defaultOptions={gcActive:!0,gcMaxUnusedTime:6e4,gcFrequency:3e4};let Vp=yl;class xl{constructor(e){this._stackIndex=0,this._globalUniformDataStack=[],this._uniformsPool=[],this._activeUniforms=[],this._bindGroupPool=[],this._activeBindGroups=[],this._renderer=e}reset(){this._stackIndex=0;for(let e=0;e<this._activeUniforms.length;e++)this._uniformsPool.push(this._activeUniforms[e]);for(let e=0;e<this._activeBindGroups.length;e++)this._bindGroupPool.push(this._activeBindGroups[e]);this._activeUniforms.length=0,this._activeBindGroups.length=0}start(e){this.reset(),this.push(e)}bind({size:e,projectionMatrix:t,worldTransformMatrix:s,worldColor:r,offset:n}){const o=this._renderer.renderTarget.renderTarget,a=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new U,worldColor:4294967295,offset:new ce},l={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||o.size,worldTransformMatrix:s||a.worldTransformMatrix,worldColor:r||a.worldColor,offset:n||a.offset,bindGroup:null},h=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(h);const c=h.uniforms;c.uProjectionMatrix=l.projectionMatrix,c.uResolution=l.resolution,c.uWorldTransformMatrix.copyFrom(l.worldTransformMatrix),c.uWorldTransformMatrix.tx-=l.offset.x,c.uWorldTransformMatrix.ty-=l.offset.y,za(l.worldColor,c.uWorldColorAlpha,0),h.update();let u;this._renderer.renderPipes.uniformBatch?u=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(h,!1):(u=this._bindGroupPool.pop()||new Pt,this._activeBindGroups.push(u),u.setResource(h,0)),l.bindGroup=u,this._currentGlobalUniformData=l}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===Ke.WEBGL&&this._currentGlobalUniformData.bindGroup.resources[0].update()}get bindGroup(){return this._currentGlobalUniformData.bindGroup}get globalUniformData(){return this._currentGlobalUniformData}get uniformGroup(){return this._currentGlobalUniformData.bindGroup.resources[0]}_createUniforms(){return new Ze({uProjectionMatrix:{value:new U,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new U,type:"mat3x3<f32>"},uWorldColorAlpha:{value:new Float32Array(4),type:"vec4<f32>"},uResolution:{value:[0,0],type:"vec2<f32>"}},{isStatic:!0})}destroy(){this._renderer=null,this._globalUniformDataStack.length=0,this._uniformsPool.length=0,this._activeUniforms.length=0,this._bindGroupPool.length=0,this._activeBindGroups.length=0,this._currentGlobalUniformData=null}}xl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"globalUniforms"};let Wy=1;class bl{constructor(){this._tasks=[],this._offset=0}init(){We.system.add(this._update,this)}repeat(e,t,s=!0){const r=Wy++;let n=0;return s&&(this._offset+=1e3,n=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:n,last:performance.now(),repeat:!0,id:r}),r}cancel(e){for(let t=0;t<this._tasks.length;t++)if(this._tasks[t].id===e){this._tasks.splice(t,1);return}}_update(){const e=performance.now();for(let t=0;t<this._tasks.length;t++){const s=this._tasks[t];if(e-s.offset-s.last>=s.duration){const r=e-s.start;s.func(r),s.last=e}}}destroy(){We.system.remove(this._update,this),this._tasks.length=0}}bl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"scheduler",priority:0};let Oc=!1;function jp(i){if(!Oc){if(ee.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${yi} (${i}) http://www.pixijs.com/
584
584
 
585
- `,"background: #E72264; padding:5px 0;","background: #6CA2EA; padding:5px 0;","background: #B5D33D; padding:5px 0;","background: #FED23F; padding:5px 0;","color: #FFFFFF; background: #E72264; padding:5px 0;","color: #E72264; background: #FFFFFF; padding:5px 0;"];globalThis.console.log(...e)}else globalThis.console&&globalThis.console.log(`PixiJS ${_i} - ${i} - http://www.pixijs.com/`);Dc=!0}}class $r{constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===Ke.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),zp(t)}}}$r.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"hello",priority:-2};$r.defaultOptions={hello:!1};const pl=class Wp{constructor(e){this._renderer=e}init(e){e={...Wp.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime}get enabled(){return H("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled}set enabled(e){H("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled=e}addManagedHash(e,t){H("8.15.0","RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"hash")}addManagedArray(e,t){H("8.15.0","RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"array")}addRenderable(e){H("8.15.0","RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead."),this._renderer.gc.addResource(e,"renderable")}run(){H("8.15.0","RenderableGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};pl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"renderableGC",priority:0};pl.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let $p=pl;const ml=class Zi{get count(){return this._renderer.tick}get checkCount(){return this._checkCount}set checkCount(e){H("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._checkCount=e}get maxIdle(){return this._renderer.gc.maxUnusedTime/1e3*60}set maxIdle(e){H("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.maxUnusedTime=e/60*1e3}get checkCountMax(){return Math.floor(this._renderer.gc._frequency/1e3)}set checkCountMax(e){H("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead.")}get active(){return this._renderer.gc.enabled}set active(e){H("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.enabled=e}constructor(e){this._renderer=e,this._checkCount=0}init(e){e.textureGCActive!==Zi.defaultOptions.textureGCActive&&(this.active=e.textureGCActive),e.textureGCMaxIdle!==Zi.defaultOptions.textureGCMaxIdle&&(this.maxIdle=e.textureGCMaxIdle),e.textureGCCheckCountMax!==Zi.defaultOptions.textureGCCheckCountMax&&(this.checkCountMax=e.textureGCCheckCountMax)}run(){H("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};ml.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"textureGC"};ml.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let Vp=ml;const jp=class Xp extends Re{constructor(e={}){super(),this.uid=oe("renderTarget"),this.colorAttachments=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,this._depth=!1,this._stencil=!1,this._colorTextures=null;const t="colorAttachments"in e?e:this._normalizeOptions(e);if(this.isRoot=t.isRoot??!1,this.label=t.label,this.colorAttachments=t.colorAttachments,this.depthStencilAttachment=t.depthStencilAttachment,this.depthStencilAttachment){const s=this.depthStencilAttachment.texture.format;this._depth||(this._depth=s.includes("depth")),this._stencil||(this._stencil=s.includes("stencil"))}if(this.colorAttachments.length===0&&!this.depthStencilAttachment)throw new Error("[RenderTarget] no color textures or depth textures were provided. Provide a depthStencilTexture or set depth/stencil to true when using colorTextures: 0.");if(this.colorAttachments.length>0){const s=this.colorTexture;this.resize(s.width,s.height,s._resolution)}this.sizeSource&&this.sizeSource.on("resize",this.onSourceResize,this)}_normalizeOptions(e){const t={...Xp.defaultOptions,...e},s=[];let r;if(typeof t.colorTextures=="number"){if(t.colorTextures>0){this._managedColorTextures=!0;for(let o=0;o<t.colorTextures;o++)s.push({texture:new de({width:t.width,height:t.height,resolution:t.resolution,antialias:t.antialias}),loadOp:"clear",storeOp:"store"})}}else t.colorTextures.forEach(o=>{s.push({texture:o.source,loadOp:"clear",storeOp:"store"})});const n=t.depthStencilTexture===!0;if(this._depth=!!(t.depth||n),this._stencil=!!(t.stencil||n),t.depthStencilTexture instanceof W||t.depthStencilTexture instanceof de){if(t.isRoot)throw new Error("[RenderTarget] cannot attach a depth-stencil texture to the screen — the canvas owns its own depth/stencil buffers. Render to a texture target instead.");r={texture:t.depthStencilTexture.source}}else(n&&!t.isRoot||(t.stencil||t.depth)&&s.length===0)&&(r=this._createDepthStencilTexture(t.width,t.height,t.resolution));return{colorAttachments:s,depthStencilAttachment:r,isRoot:t.isRoot,label:t.label}}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.sizeSource.width}get height(){return this.sizeSource.height}get pixelWidth(){return this.sizeSource.pixelWidth}get pixelHeight(){return this.sizeSource.pixelHeight}get resolution(){return this.sizeSource._resolution}get colorTextures(){return this._colorTextures||(this._colorTextures=this.colorAttachments.map(e=>e.texture)),this._colorTextures}get depthStencilTexture(){return this.depthStencilAttachment?.texture??null}get depth(){return this._depth}get stencil(){return this._stencil}get colorTexture(){return this.colorAttachments[0]?.texture}get sizeSource(){return this.colorAttachments[0]?.texture??this.depthStencilAttachment?.texture}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this._createDepthStencilTexture(this.sizeSource.width,this.sizeSource.height,this.sizeSource._resolution),this._depth=!0,this._stencil=!0}resize(e,t,s=this.resolution,r=!1){if(this.dirtyId++,this.colorAttachments.forEach((n,o)=>{r&&o===0||n.texture.resize(e,t,s)}),this.depthStencilAttachment){if(r&&this.colorAttachments.length===0)return;this.depthStencilAttachment.texture.resize(e,t,s)}}destroy(){!this.colorAttachments&&!this.depthStencilAttachment||(this.emit("destroy",this),this.sizeSource.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorAttachments.forEach(e=>{e.texture.destroy()}),this.depthStencilAttachment&&(this.depthStencilAttachment.texture.destroy(),delete this.depthStencilAttachment),this.colorAttachments=null,this._colorTextures=null,this.removeAllListeners())}_createDepthStencilTexture(e,t,s){return this.depthStencilAttachment??(this.depthStencilAttachment={texture:new de({width:e,height:t,resolution:s,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1})}),this.depthStencilAttachment}};jp.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let ni=jp;const xs=new Map;as.register(xs);function gl(i,e){if(!xs.has(i)){const t=new W({source:new Ve({resource:i,...e})}),s=()=>{xs.get(i)===t&&xs.delete(i)};t.once("destroy",s),t.source.once("destroy",s),xs.set(i,t)}return xs.get(i)}const _l=class qp{get autoDensity(){return this.texture.source.autoDensity}set autoDensity(e){this.texture.source.autoDensity=e}get resolution(){return this.texture.source._resolution}set resolution(e){this.texture.source.resize(this.texture.source.width,this.texture.source.height,e)}constructor(e){this._renderer=e}init(e){e={...qp.defaultOptions,...e},e.view&&(H(ue,"ViewSystem.view has been renamed to ViewSystem.canvas"),e.canvas=e.view),this.screen=new te(0,0,e.width,e.height),this.canvas=e.canvas||ee.get().createCanvas(),this.antialias=!!e.antialias;const{depth:t,...s}=e;this.texture=gl(this.canvas,s),this.renderTarget=new ni({colorTextures:[this.texture],depth:!!t,isRoot:!0}),this.texture.source.transparent=e.backgroundAlpha<1,this.texture.source.on("resize",this._updateScreenSize,this),this.resolution=e.resolution,this._updateScreenSize()}resize(e,t,s){this.texture.source.resize(e,t,s),this.screen.width=this.texture.frame.width,this.screen.height=this.texture.frame.height}destroy(e=!1){(typeof e=="boolean"?e:!!e?.removeView)&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.texture.source.off("resize",this._updateScreenSize,this),Te.removeScreen(this._renderer.uid),Et.removeScreen(this._renderer.uid),this.texture.destroy()}_updateScreenSize(){const{pixelWidth:e,pixelHeight:t}=this.texture.source,s=this._renderer.uid;Te.setScreenSize(s,e,t),Et.setScreenSize(s,e,t)}};_l.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"view",priority:0};_l.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let Yp=_l;const Vr=[Dp,dl,$r,Yp,al,Hp,Vp,cl,Op,oa,$p,fl],yl=[Wr,Lr,zr,Hr,Ur,tl,Ja,Nr];function Kp(i,e,t,s,r,n){const o=n?1:-1;return i.identity(),i.a=1/s*2,i.d=o*(1/r*2),i.tx=-1-e*i.a,i.ty=-o-t*i.d,i}function Zp(i){if(i.colorAttachments.length===0)return!1;const e=i.colorTexture.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}class jr{constructor(e){this.rootViewPort=new te,this.viewport=new te,this.onRenderTargetChange=new ra("onRenderTargetChange"),this.projectionMatrix=new U,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._bindState={target:null,frame:void 0,mipLevel:0,layer:0,flipY:!1},this._bindFrame=new te,this._renderer=e,e.gc.addCollection(this,"_gpuRenderTargetHash","hash")}get renderSurface(){return this._bindState.target}get mipLevel(){return this._bindState.mipLevel}get layer(){return this._bindState.layer}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart(e){this._renderTargetStack.length=0,this.push(e),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=Zp(this.rootRenderTarget),this.adaptor.prerender?.(this.rootRenderTarget)}postrender(){this.adaptor.postrender?.(this.rootRenderTarget)}bind(e,t=!0,s,r,n=0,o=0,a){let l;"target"in e?l=e:(H("8.20.0","RenderTargetSystem.bind: positional arguments are deprecated, please use an options object instead: bind({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),l={target:e,clear:t,clearColor:s,frame:r,mipLevel:n,layer:o,flipY:a});const h=l.target;t=l.clear??!0,s=l.clearColor,n=(l.mipLevel??0)|0,o=(l.layer??0)|0,a=l.flipY,r=l.frame;const c=this.getRenderTarget(h),u=this.renderTarget!==c||!!c.flipY!=!!a;this.renderTarget=c;const d=this.getGpuRenderTarget(c);(c.pixelWidth!==d.width||c.pixelHeight!==d.height)&&(this.adaptor.resizeGpuRenderTarget(c),d.width=c.pixelWidth,d.height=c.pixelHeight);const f=c.colorAttachments[0]?.texture||c.depthStencilAttachment?.texture,p=this.viewport,g=f.dimension==="3d"?Math.max(f.depth>>n,1):f.depthOrArrayLayers;if(o<0||o>=g)throw new Error(`[RenderTargetSystem] layer ${o} is out of bounds (layer count=${g}).`);const m=this._bindState;m.target=h,m.frame=r?this._bindFrame.copyFrom(r):void 0,m.mipLevel=n,m.layer=o,m.flipY=a;const _=Math.max(f.pixelWidth>>n,1),y=Math.max(f.pixelHeight>>n,1);if(!r&&h instanceof W&&(r=h.frame),r){const x=f._resolution,b=1<<Math.max(n,0),v=r.x*x+.5|0,w=r.y*x+.5|0,T=r.width*x+.5|0,k=r.height*x+.5|0;let E=Math.floor(v/b),A=Math.floor(w/b),M=Math.ceil(T/b),B=Math.ceil(k/b);E<0&&(M+=E,E=0),A<0&&(B+=A,A=0),E=Math.min(E,_-1),A=Math.min(A,y-1),M=Math.min(M,_-E),B=Math.min(B,y-A),M=Math.max(M,1),B=Math.max(B,1),p.x=E,p.y=A,p.width=M,p.height=B}else p.x=0,p.y=0,p.width=_,p.height=y;return c.flipY=a,Kp(this.projectionMatrix,0,0,p.width/f.resolution,p.height/f.resolution,!c.isRoot!=!!c.flipY),this.adaptor.startRenderPass(c,t,s,p,n,o),u&&this.onRenderTargetChange.emit(c),c}getBindState(e){if(!this.renderTarget)throw new Error("[RenderTargetSystem] getBindState is only valid while a render surface is bound");const t=this._bindState;return e??(e={}),e.target=t.target,e.clear=ye.NONE,e.clearColor=void 0,t.frame?e.frame?e.frame.copyFrom(t.frame):e.frame=t.frame.clone():e.frame=void 0,e.mipLevel=t.mipLevel,e.layer=t.layer,e.flipY=!!t.flipY,e}isFrontFaceInverted(e,t){if(!e){if(e=this.renderTarget,!e)return!1;t=e.flipY}return!!t!=(this._renderer.type===Ke.WEBGL&&!e.isRoot)}get frontFaceInverted(){return H(ht,"RenderTargetSystem.frontFaceInverted is deprecated, use isFrontFaceInverted() instead"),this.isFrontFaceInverted()}clear(e,t=ye.ALL,s,r=this.mipLevel,n=this.layer){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,s,this.viewport,r,n))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=ye.ALL,s,r,n=0,o=0,a){let l;"target"in e?l=e:(H("8.20.0","RenderTargetSystem.push: positional arguments are deprecated, please use an options object instead: push({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),l={target:e,clear:t,clearColor:s,frame:r,mipLevel:n,layer:o,flipY:a});const h=this.bind(l);return this._renderTargetStack.push({target:l.target,clear:!1,clearColor:void 0,frame:l.frame?l.frame.clone():void 0,mipLevel:l.mipLevel,layer:l.layer,flipY:l.flipY}),h}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];if(!e)throw new Error("[RenderTargetSystem] pop: no previous binding to restore (unbalanced pop)");return this.bind(e)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,s,r,n){const o=this.getRenderTarget(e);s.x<0&&(r.width+=s.x,n.x-=s.x,s.x=0),s.y<0&&(r.height+=s.y,n.y-=s.y,s.y=0);const{pixelWidth:a,pixelHeight:l}=o;return r.width=Math.min(r.width,a-s.x),r.height=Math.min(r.height,l-s.y),this.adaptor.copyToTexture(o,t,s,r,n)}copyDepthTexture(e,t,s,r,n={x:0,y:0}){const o=this.getRenderTarget(e);if(!o.depthStencilAttachment){z("[RenderTargetSystem] copyDepthTexture: the source render target has no depth attachment to copy from");return}const a=t.source;if(!a.format.includes("depth")&&!a.format.includes("stencil")){z(`[RenderTargetSystem] copyDepthTexture: the destination texture must have a depth/stencil format (got '${a.format}')`);return}let l=s.x,h=s.y,c=n.x,u=n.y,d=r.width,f=r.height;l<0&&(d+=l,c-=l,l=0),h<0&&(f+=h,u-=h,h=0),d=Math.min(d,o.pixelWidth-l),f=Math.min(f,o.pixelHeight-h),d=Math.min(d,a.pixelWidth-c),f=Math.min(f,a.pixelHeight-u),!(d<=0||f<=0)&&this.adaptor.copyDepthTexture(o,t,{x:l,y:h},{width:d,height:f},{x:c,y:u})}ensureDepthStencil(){if(!this.renderTarget.stencil){if(this.renderTarget.depthStencilTexture){z(`[RenderTargetSystem] a stencil mask is being used, but the render target's depthStencilTexture format '${this.renderTarget.depthStencilTexture.format}' has no stencil aspect, so masking cannot work here. Use a 'depth24plus-stencil8' texture instead.`);return}this.renderTarget._depth=!0,this.renderTarget._stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport,0,this.layer)}}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t?this._releaseRenderTarget(t,e):e.off("destroy",this._onRenderTargetDestroy,this)}),this._renderSurfaceToRenderTargetHash.clear();for(const e of Object.values(this._gpuRenderTargetHash))e&&this.adaptor.destroyGpuRenderTarget(e);this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;if(Ve.test(e)&&(e=gl(e).source),e instanceof ni)t=e,e.once("destroy",this._onRenderTargetDestroy,this);else if(e instanceof de){const s=e.format;t=s.includes("depth")||s.includes("stencil")?new ni({colorTextures:0,depthStencilTexture:e}):new ni({colorTextures:[e]}),e.source instanceof Ve&&(t.isRoot=!0),e.once("destroy",this._onRenderSurfaceDestroy,this)}return this._renderSurfaceToRenderTargetHash.set(e,t),t}_onRenderSurfaceDestroy(e){const t=this._renderSurfaceToRenderTargetHash.get(e);t&&this._releaseRenderTarget(e,t)}_onRenderTargetDestroy(e){this._renderSurfaceToRenderTargetHash.delete(e),this._releaseGpuRenderTarget(e)}_releaseRenderTarget(e,t){t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e),e.off("destroy",this._onRenderSurfaceDestroy,this),this._releaseGpuRenderTarget(t)}_releaseGpuRenderTarget(e){const t=this._gpuRenderTargetHash[e.uid];t&&(this._gpuRenderTargetHash[e.uid]=null,this.adaptor.destroyGpuRenderTarget(t))}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this._bindState.target=null}}class Qp{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:s,context:r}=this._ensureCanvas(t);return{canvas:s,context:r,width:s.width,height:s.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:s}=this._ensureCanvas(t);s.width=e.pixelWidth,s.height=e.pixelHeight}startRenderPass(e,t,s,r){const n=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=n.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,s,r)}clear(e,t,s,r){const o=this._renderTargetSystem.getGpuRenderTarget(e).context,a=r||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(o.setTransform(1,0,0,1,0,0),o.clearRect(a.x,a.y,a.width,a.height),s){const l=ae.shared.setValue(s);l.alpha>0&&(o.globalAlpha=l.alpha,o.fillStyle=l.toHex(),o.fillRect(a.x,a.y,a.width,a.height),o.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,s,r,n){const a=this._renderTargetSystem.getGpuRenderTarget(e).canvas,l=t.source,{context:h}=this._ensureCanvas(l),c=n?.x??0,u=n?.y??0;return h.drawImage(a,s.x,s.y,r.width,r.height,c,u,r.width,r.height),l.update(),t}copyDepthTexture(e,t,s,r,n){z("[CanvasRenderTargetAdaptor] copyDepthTexture is not supported in the canvas renderer")}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Ve.test(t))&&(t=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const s=t.getContext("2d");return{canvas:t,context:s}}}class xl extends jr{constructor(e){super(e),this.adaptor=new Qp,this.adaptor.init(e,this)}}xl.extension={type:[S.CanvasSystem],name:"renderTarget"};class bl{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=ee.get().createCanvas(),s=t.getContext("2d"),r=Y.getCanvasSource(e);if(!r)return t;const n=e.frame,o=e.source._resolution??e.source.resolution??1,a=n.x*o,l=n.y*o,h=n.width*o,c=n.height*o;return t.width=Math.ceil(h),t.height=Math.ceil(c),s.drawImage(r,a,l,h,c,0,0,h,c),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}bl.extension={type:[S.CanvasSystem],name:"texture"};const Ly=[...Vr,sl,il,bl,xl],Uy=[Wr,Lr,zr,Hr,Ur,el,Qa,Nr],Ny=[Mp,rl],Jp=[],em=[],tm=[],sm=[];q.handleByNamedList(S.CanvasSystem,Jp);q.handleByNamedList(S.CanvasPipes,em);q.handleByNamedList(S.CanvasPipesAdaptor,tm);q.handleByNamedList(S.CanvasLoader,sm);q.add(...Ly,...Uy,...Ny);class im extends Ds{constructor(){const e={name:"canvas",type:Ke.CANVAS,systems:Jp,renderPipes:em,renderPipeAdaptors:tm,loaders:sm};super(e)}}const Hy=Object.freeze(Object.defineProperty({__proto__:null,CanvasRenderer:im},Symbol.toStringTag,{value:"Module"}));var oi=(i=>(i[i.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",i[i.ARRAY_BUFFER=34962]="ARRAY_BUFFER",i[i.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",i))(oi||{});class rm{constructor(e,t){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class vl{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new nt({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:t}=this,s=this.getGlBuffer(e);t.bindBuffer(s.type,s.buffer)}bindBufferBase(e,t){const{_gl:s}=this;this._boundBufferBases[t]!==e&&(this._boundBufferBases[t]=e,e._lastBindBaseLocation=t,s.bindBufferBase(s.UNIFORM_BUFFER,t,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let t=this.getLastBindBaseLocation(e);if(t>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,t;let s=0,r=this._nextBindBaseIndex;for(;s<2;){r>=this._maxBindings&&(r=this._minBaseLocation,s++);const n=this._boundBufferBases[r];if(n&&n._lastBindCallId===this._bindCallId){r++;continue}break}return t=r,this._nextBindBaseIndex=r+1,s>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[t]=null,t)}getLastBindBaseLocation(e){const t=e._lastBindBaseLocation;return this._boundBufferBases[t]===e?t:-1}bindBufferRange(e,t,s,r){const{_gl:n}=this;s||(s=0),t||(t=0),this._boundBufferBases[t]=null,n.bindBufferRange(n.UNIFORM_BUFFER,t||0,e.buffer,s*256,r||256)}updateBuffer(e){const{_gl:t}=this,s=this.getGlBuffer(e);if(e._updateID===s.updateID)return s;s.updateID=e._updateID,t.bindBuffer(s.type,s.buffer);const r=e.data,n=e.descriptor.usage&ce.STATIC?t.STATIC_DRAW:t.DYNAMIC_DRAW;return r?s.byteLength>=r.byteLength?t.bufferSubData(s.type,e._updateOffset,r,e._updateOffset/r.BYTES_PER_ELEMENT,(e._updateSize||r.byteLength)/r.BYTES_PER_ELEMENT):(s.byteLength=r.byteLength,t.bufferData(s.type,r,n)):(s.byteLength=e.descriptor.size,t.bufferData(s.type,s.byteLength,n)),s}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];s&&(t||this._gl.deleteBuffer(s.buffer))}createGLBuffer(e){const{_gl:t}=this;let s=oi.ARRAY_BUFFER;e.descriptor.usage&ce.INDEX?s=oi.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&ce.UNIFORM&&(s=oi.UNIFORM_BUFFER);const r=new rm(t.createBuffer(),s);return e._gpuData[this._renderer.uid]=r,this._managedBuffers.add(e),r}resetState(){this._boundBufferBases=Object.create(null)}}vl.extension={type:[S.WebGLSystem],name:"buffer"};const wl=class nm{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...nm.defaultOptions,...e};let t=this.multiView=e.multiView;if(e.context&&t&&(z("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),t=!1),t?this.canvas=ee.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const s=this._renderer.background.alpha<1,r=e.premultipliedAlpha??!0,n=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:s,premultipliedAlpha:r,antialias:n,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&z("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:t}=this;(t.width<e.width||t.height<e.height)&&(t.width=Math.max(e.width,e.width),t.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof ee.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const t=this._renderer.view.canvas;t.addEventListener("webglcontextlost",this.handleContextLost,!1),t.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,t){let s;const r=this.canvas;if(e===2&&(s=r.getContext("webgl2",t)),!s&&(s=r.getContext("webgl",t),!s))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=s,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,t={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...t,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...t,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const s=e.getExtension("WEBGL_provoking_vertex");s&&s.provokingVertexWEBGL(s.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext?.restoreContext()},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext?.loseContext()}forceContextLoss(){this.extensions.loseContext?.loseContext(),this._contextLossForced=!0}validateContext(e){const t=e.getContextAttributes();t&&!t.stencil&&z("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const s=this.supports,r=this.webGLVersion===2,n=this.extensions;s.uint32Indices=r||!!n.uint32ElementIndex,s.uniformBufferObject=r,s.vertexArrayObject=r||!!n.vertexArrayObject,s.srgbTextures=r||!!n.srgb,s.nonPowOf2wrapping=r,s.nonPowOf2mipmaps=r,s.msaa=r,s.uint32Indices||z("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};wl.extension={type:[S.WebGLSystem],name:"context"};wl.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let om=wl;function fr(i,e){for(const t in i.attributes){const s=i.attributes[t],r=e[t];r?(s.format??(s.format=r.format),s.offset??(s.offset=r.offset),s.instance??(s.instance=r.instance)):s.format||z(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}zy(i)}function zy(i){const{buffers:e,attributes:t}=i,s={},r={};for(const n in e){const o=e[n];s[o.uid]=0,r[o.uid]=0}for(const n in t){const o=t[n];s[o.buffer.uid]+=ks(o.format).stride}for(const n in t){const o=t[n];o.stride??(o.stride=s[o.buffer.uid]),o.start??(o.start=r[o.buffer.uid]),r[o.buffer.uid]+=ks(o.format).stride}}var pr=(i=>(i[i.RGBA=6408]="RGBA",i[i.RGB=6407]="RGB",i[i.RG=33319]="RG",i[i.RED=6403]="RED",i[i.RGBA_INTEGER=36249]="RGBA_INTEGER",i[i.RGB_INTEGER=36248]="RGB_INTEGER",i[i.RG_INTEGER=33320]="RG_INTEGER",i[i.RED_INTEGER=36244]="RED_INTEGER",i[i.ALPHA=6406]="ALPHA",i[i.LUMINANCE=6409]="LUMINANCE",i[i.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",i[i.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",i[i.DEPTH_STENCIL=34041]="DEPTH_STENCIL",i))(pr||{}),Rs=(i=>(i[i.TEXTURE_2D=3553]="TEXTURE_2D",i[i.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",i[i.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",i[i.TEXTURE_3D=32879]="TEXTURE_3D",i[i.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",i[i.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",i[i.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",i[i.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",i))(Rs||{}),ie=(i=>(i[i.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",i[i.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",i[i.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",i[i.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",i[i.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",i[i.UNSIGNED_INT=5125]="UNSIGNED_INT",i[i.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",i[i.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",i[i.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",i[i.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",i[i.BYTE=5120]="BYTE",i[i.SHORT=5122]="SHORT",i[i.INT=5124]="INT",i[i.FLOAT=5126]="FLOAT",i[i.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",i[i.HALF_FLOAT=36193]="HALF_FLOAT",i))(ie||{});const Fc={uint8x2:ie.UNSIGNED_BYTE,uint8x4:ie.UNSIGNED_BYTE,sint8x2:ie.BYTE,sint8x4:ie.BYTE,unorm8x2:ie.UNSIGNED_BYTE,unorm8x4:ie.UNSIGNED_BYTE,snorm8x2:ie.BYTE,snorm8x4:ie.BYTE,uint16x2:ie.UNSIGNED_SHORT,uint16x4:ie.UNSIGNED_SHORT,sint16x2:ie.SHORT,sint16x4:ie.SHORT,unorm16x2:ie.UNSIGNED_SHORT,unorm16x4:ie.UNSIGNED_SHORT,snorm16x2:ie.SHORT,snorm16x4:ie.SHORT,float16x2:ie.HALF_FLOAT,float16x4:ie.HALF_FLOAT,float32:ie.FLOAT,float32x2:ie.FLOAT,float32x3:ie.FLOAT,float32x4:ie.FLOAT,uint32:ie.UNSIGNED_INT,uint32x2:ie.UNSIGNED_INT,uint32x3:ie.UNSIGNED_INT,uint32x4:ie.UNSIGNED_INT,sint32:ie.INT,sint32x2:ie.INT,sint32x3:ie.INT,sint32x4:ie.INT};function am(i){return Fc[i]??Fc.float32}const Wy={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class lm{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class Tl{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new nt({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=r=>t.bindVertexArrayOES(r),e.deleteVertexArray=r=>t.deleteVertexArrayOES(r));const s=this._renderer.context.extensions.vertexAttribDivisorANGLE;s&&(e.drawArraysInstanced=(r,n,o,a)=>{s.drawArraysInstancedANGLE(r,n,o,a)},e.drawElementsInstanced=(r,n,o,a,l)=>{s.drawElementsInstancedANGLE(r,n,o,a,l)},e.vertexAttribDivisor=(r,n)=>s.vertexAttribDivisorANGLE(r,n)),this._activeGeometry=null,this._activeVao=null}bind(e,t){const s=this.gl;this._activeGeometry=e;const r=this.getVao(e,t);this._activeVao!==r&&(this._activeVao=r,s.bindVertexArray(r)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,t=this._renderer.buffer;for(let s=0;s<e.buffers.length;s++){const r=e.buffers[s];t.updateBuffer(r)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,t){const s=e.attributes,r=t._attributeData;for(const n in r)if(!s[n])throw new Error(`shader and geometry incompatible, geometry missing the "${n}" attribute`)}getSignature(e,t){const s=e.attributes,r=t._attributeData,n=["g",e.uid];for(const o in s)r[o]&&n.push(o,r[o].location);return n.join("-")}getVao(e,t){return e._gpuData[this._renderer.uid]?.vaoCache[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,s=!0){const r=this._renderer.gl,n=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);const o=this.getSignature(e,t);let a=e._gpuData[this._renderer.uid];a||(a=new lm,e._gpuData[this._renderer.uid]=a,this._managedGeometries.add(e));const l=a.vaoCache;let h=l[o];if(h)return l[t._key]=h,h;fr(e,t._attributeData);const c=e.buffers;h=r.createVertexArray(),r.bindVertexArray(h);for(let u=0;u<c.length;u++){const d=c[u];n.bind(d)}return this.activateVao(e,t),l[t._key]=h,l[o]=h,r.bindVertexArray(null),h}onGeometryUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];if(!s)return;const r=s.vaoCache;if(!t)for(const n in r)this._activeVao===r[n]&&this.resetState(),this.gl.deleteVertexArray(r[n])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,t){const s=this._renderer.gl,r=this._renderer.buffer,n=e.attributes;e.indexBuffer&&r.bind(e.indexBuffer);let o=null;for(const a in n){const l=n[a],h=l.buffer,c=r.getGlBuffer(h),u=t._attributeData[a];if(u){o!==c&&(r.bind(h),o=c);const d=u.location;s.enableVertexAttribArray(d);const f=ks(l.format),p=am(l.format);if(u.format?.substring(1,4)==="int"?s.vertexAttribIPointer(d,f.size,p,l.stride,l.offset):s.vertexAttribPointer(d,f.size,p,f.normalised,l.stride,l.offset),l.instance)if(this.hasInstance){const g=l.divisor??1;s.vertexAttribDivisor(d,g)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,t,s,r){const{gl:n}=this._renderer,o=this._activeGeometry,a=Wy[e||o.topology];if(r??(r=o.instanceCount),o.indexBuffer){const l=o.indexBuffer.data.BYTES_PER_ELEMENT,h=l===2?n.UNSIGNED_SHORT:n.UNSIGNED_INT,c=t||o.indexCount||o.indexBuffer.data.length,u=(s||0)*l;r!==1?n.drawElementsInstanced(a,c,h,u,r):n.drawElements(a,c,h,u)}else r!==1?n.drawArraysInstanced(a,s||0,t||o.vertexCount,r):n.drawArrays(a,s||0,t||o.vertexCount);return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}Tl.extension={type:[S.WebGLSystem],name:"geometry"};const $y=new Er({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),Sl=class hm{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:t,antialias:s}={...hm.defaultOptions,...e};this.useBackBuffer=t,this._antialias=s,this._renderer.context.supports.msaa||(z("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=pt.for2d();const r=new ls({vertex:`
585
+ `,"background: #E72264; padding:5px 0;","background: #6CA2EA; padding:5px 0;","background: #B5D33D; padding:5px 0;","background: #FED23F; padding:5px 0;","color: #FFFFFF; background: #E72264; padding:5px 0;","color: #E72264; background: #FFFFFF; padding:5px 0;"];globalThis.console.log(...e)}else globalThis.console&&globalThis.console.log(`PixiJS ${yi} - ${i} - http://www.pixijs.com/`);Oc=!0}}class jr{constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===Ke.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),jp(t)}}}jr.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"hello",priority:-2};jr.defaultOptions={hello:!1};const vl=class Xp{constructor(e){this._renderer=e}init(e){e={...Xp.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime}get enabled(){return z("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled}set enabled(e){z("8.15.0","RenderableGCSystem.enabled is deprecated, please use the GCSystem.enabled instead."),this._renderer.gc.enabled=e}addManagedHash(e,t){z("8.15.0","RenderableGCSystem.addManagedHash is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"hash")}addManagedArray(e,t){z("8.15.0","RenderableGCSystem.addManagedArray is deprecated, please use the GCSystem.addCollection instead."),this._renderer.gc.addCollection(e,t,"array")}addRenderable(e){z("8.15.0","RenderableGCSystem.addRenderable is deprecated, please use the GCSystem instead."),this._renderer.gc.addResource(e,"renderable")}run(){z("8.15.0","RenderableGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};vl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"renderableGC",priority:0};vl.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let qp=vl;const wl=class er{get count(){return this._renderer.tick}get checkCount(){return this._checkCount}set checkCount(e){z("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._checkCount=e}get maxIdle(){return this._renderer.gc.maxUnusedTime/1e3*60}set maxIdle(e){z("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.maxUnusedTime=e/60*1e3}get checkCountMax(){return Math.floor(this._renderer.gc._frequency/1e3)}set checkCountMax(e){z("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead.")}get active(){return this._renderer.gc.enabled}set active(e){z("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.enabled=e}constructor(e){this._renderer=e,this._checkCount=0}init(e){e.textureGCActive!==er.defaultOptions.textureGCActive&&(this.active=e.textureGCActive),e.textureGCMaxIdle!==er.defaultOptions.textureGCMaxIdle&&(this.maxIdle=e.textureGCMaxIdle),e.textureGCCheckCountMax!==er.defaultOptions.textureGCCheckCountMax&&(this.checkCountMax=e.textureGCCheckCountMax)}run(){z("8.15.0","TextureGCSystem.run is deprecated, please use the GCSystem instead."),this._renderer.gc.run()}destroy(){this._renderer=null}};wl.extension={type:[S.WebGLSystem,S.WebGPUSystem],name:"textureGC"};wl.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let Yp=wl;const Kp=class Zp extends Re{constructor(e={}){super(),this.uid=oe("renderTarget"),this.colorAttachments=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,this._depth=!1,this._stencil=!1,this._colorTextures=null;const t="colorAttachments"in e?e:this._normalizeOptions(e);if(this.isRoot=t.isRoot??!1,this.label=t.label,this.colorAttachments=t.colorAttachments,this.depthStencilAttachment=t.depthStencilAttachment,this.depthStencilAttachment){const s=this.depthStencilAttachment.texture.format;this._depth||(this._depth=s.includes("depth")),this._stencil||(this._stencil=s.includes("stencil"))}if(this.colorAttachments.length===0&&!this.depthStencilAttachment)throw new Error("[RenderTarget] no color textures or depth textures were provided. Provide a depthStencilTexture or set depth/stencil to true when using colorTextures: 0.");if(this.colorAttachments.length>0){const s=this.colorTexture;this.resize(s.width,s.height,s._resolution)}this.sizeSource&&this.sizeSource.on("resize",this.onSourceResize,this)}_normalizeOptions(e){const t={...Zp.defaultOptions,...e},s=[];let r;if(typeof t.colorTextures=="number"){if(t.colorTextures>0){this._managedColorTextures=!0;for(let o=0;o<t.colorTextures;o++)s.push({texture:new ue({width:t.width,height:t.height,resolution:t.resolution,antialias:t.antialias}),loadOp:"clear",storeOp:"store"})}}else t.colorTextures.forEach(o=>{s.push({texture:o.source,loadOp:"clear",storeOp:"store"})});const n=t.depthStencilTexture===!0;if(this._depth=!!(t.depth||n),this._stencil=!!(t.stencil||n),t.depthStencilTexture instanceof W||t.depthStencilTexture instanceof ue){if(t.isRoot)throw new Error("[RenderTarget] cannot attach a depth-stencil texture to the screen — the canvas owns its own depth/stencil buffers. Render to a texture target instead.");r={texture:t.depthStencilTexture.source}}else(n&&!t.isRoot||(t.stencil||t.depth)&&s.length===0)&&(r=this._createDepthStencilTexture(t.width,t.height,t.resolution));return{colorAttachments:s,depthStencilAttachment:r,isRoot:t.isRoot,label:t.label}}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.sizeSource.width}get height(){return this.sizeSource.height}get pixelWidth(){return this.sizeSource.pixelWidth}get pixelHeight(){return this.sizeSource.pixelHeight}get resolution(){return this.sizeSource._resolution}get colorTextures(){return this._colorTextures||(this._colorTextures=this.colorAttachments.map(e=>e.texture)),this._colorTextures}get depthStencilTexture(){return this.depthStencilAttachment?.texture??null}get depth(){return this._depth}get stencil(){return this._stencil}get colorTexture(){return this.colorAttachments[0]?.texture}get sizeSource(){return this.colorAttachments[0]?.texture??this.depthStencilAttachment?.texture}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this._createDepthStencilTexture(this.sizeSource.width,this.sizeSource.height,this.sizeSource._resolution),this._depth=!0,this._stencil=!0}resize(e,t,s=this.resolution,r=!1){if(this.dirtyId++,this.colorAttachments.forEach((n,o)=>{r&&o===0||n.texture.resize(e,t,s)}),this.depthStencilAttachment){if(r&&this.colorAttachments.length===0)return;this.depthStencilAttachment.texture.resize(e,t,s)}}destroy(){!this.colorAttachments&&!this.depthStencilAttachment||(this.emit("destroy",this),this.sizeSource.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorAttachments.forEach(e=>{e.texture.destroy()}),this.depthStencilAttachment&&(this.depthStencilAttachment.texture.destroy(),delete this.depthStencilAttachment),this.colorAttachments=null,this._colorTextures=null,this.removeAllListeners())}_createDepthStencilTexture(e,t,s){return this.depthStencilAttachment??(this.depthStencilAttachment={texture:new ue({width:e,height:t,resolution:s,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1})}),this.depthStencilAttachment}};Kp.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let ai=Kp;const Ts=new Map;cs.register(Ts);function Tl(i,e){if(!Ts.has(i)){const t=new W({source:new Ve({resource:i,...e})}),s=()=>{Ts.get(i)===t&&Ts.delete(i)};t.once("destroy",s),t.source.once("destroy",s),Ts.set(i,t)}return Ts.get(i)}const Sl=class Qp{get autoDensity(){return this.texture.source.autoDensity}set autoDensity(e){this.texture.source.autoDensity=e}get resolution(){return this.texture.source._resolution}set resolution(e){this.texture.source.resize(this.texture.source.width,this.texture.source.height,e)}constructor(e){this._renderer=e}init(e){e={...Qp.defaultOptions,...e},e.view&&(z(de,"ViewSystem.view has been renamed to ViewSystem.canvas"),e.canvas=e.view),this.screen=new te(0,0,e.width,e.height),this.canvas=e.canvas||ee.get().createCanvas(),this.antialias=!!e.antialias;const{depth:t,...s}=e;this.texture=Tl(this.canvas,s),this.renderTarget=new ai({colorTextures:[this.texture],depth:!!t,isRoot:!0}),this.texture.source.transparent=e.backgroundAlpha<1,this.texture.source.on("resize",this._updateScreenSize,this),this.resolution=e.resolution,this._updateScreenSize()}resize(e,t,s){this.texture.source.resize(e,t,s),this.screen.width=this.texture.frame.width,this.screen.height=this.texture.frame.height}destroy(e=!1){(typeof e=="boolean"?e:!!e?.removeView)&&this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.texture.source.off("resize",this._updateScreenSize,this),Te.removeScreen(this._renderer.uid),At.removeScreen(this._renderer.uid),this.texture.destroy()}_updateScreenSize(){const{pixelWidth:e,pixelHeight:t}=this.texture.source,s=this._renderer.uid;Te.setScreenSize(s,e,t),At.setScreenSize(s,e,t)}};Sl.extension={type:[S.WebGLSystem,S.WebGPUSystem,S.CanvasSystem],name:"view",priority:0};Sl.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};let Jp=Sl;const Xr=[Up,xl,jr,Jp,pl,Vp,Yp,_l,zp,fa,qp,bl],Cl=[Vr,Nr,$r,Wr,zr,ll,ol,Hr];function em(i,e,t,s,r,n){const o=n?1:-1;return i.identity(),i.a=1/s*2,i.d=o*(1/r*2),i.tx=-1-e*i.a,i.ty=-o-t*i.d,i}function tm(i){if(i.colorAttachments.length===0)return!1;const e=i.colorTexture.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}class qr{constructor(e){this.rootViewPort=new te,this.viewport=new te,this.onRenderTargetChange=new ua("onRenderTargetChange"),this.projectionMatrix=new U,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._bindState={target:null,frame:void 0,mipLevel:0,layer:0,flipY:!1},this._bindFrame=new te,this._renderer=e,e.gc.addCollection(this,"_gpuRenderTargetHash","hash")}get renderSurface(){return this._bindState.target}get mipLevel(){return this._bindState.mipLevel}get layer(){return this._bindState.layer}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart(e){this._renderTargetStack.length=0,this.push(e),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=tm(this.rootRenderTarget),this.adaptor.prerender?.(this.rootRenderTarget)}postrender(){this.adaptor.postrender?.(this.rootRenderTarget)}bind(e,t=!0,s,r,n=0,o=0,a){let l;"target"in e?l=e:(z("8.20.0","RenderTargetSystem.bind: positional arguments are deprecated, please use an options object instead: bind({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),l={target:e,clear:t,clearColor:s,frame:r,mipLevel:n,layer:o,flipY:a});const h=l.target;t=l.clear??!0,s=l.clearColor,n=(l.mipLevel??0)|0,o=(l.layer??0)|0,a=l.flipY,r=l.frame;const c=this.getRenderTarget(h),u=this.renderTarget!==c||!!c.flipY!=!!a;this.renderTarget=c;const d=this.getGpuRenderTarget(c);(c.pixelWidth!==d.width||c.pixelHeight!==d.height)&&(this.adaptor.resizeGpuRenderTarget(c),d.width=c.pixelWidth,d.height=c.pixelHeight);const f=c.colorAttachments[0]?.texture||c.depthStencilAttachment?.texture,p=this.viewport,g=f.dimension==="3d"?Math.max(f.depth>>n,1):f.depthOrArrayLayers;if(o<0||o>=g)throw new Error(`[RenderTargetSystem] layer ${o} is out of bounds (layer count=${g}).`);const m=this._bindState;m.target=h,m.frame=r?this._bindFrame.copyFrom(r):void 0,m.mipLevel=n,m.layer=o,m.flipY=a;const _=Math.max(f.pixelWidth>>n,1),y=Math.max(f.pixelHeight>>n,1);if(!r&&h instanceof W&&(r=h.frame),r){const x=f._resolution,b=1<<Math.max(n,0),v=r.x*x+.5|0,w=r.y*x+.5|0,T=r.width*x+.5|0,k=r.height*x+.5|0;let E=Math.floor(v/b),A=Math.floor(w/b),M=Math.ceil(T/b),B=Math.ceil(k/b);E<0&&(M+=E,E=0),A<0&&(B+=A,A=0),E=Math.min(E,_-1),A=Math.min(A,y-1),M=Math.min(M,_-E),B=Math.min(B,y-A),M=Math.max(M,1),B=Math.max(B,1),p.x=E,p.y=A,p.width=M,p.height=B}else p.x=0,p.y=0,p.width=_,p.height=y;return c.flipY=a,em(this.projectionMatrix,0,0,p.width/f.resolution,p.height/f.resolution,!c.isRoot!=!!c.flipY),this.adaptor.startRenderPass(c,t,s,p,n,o),u&&this.onRenderTargetChange.emit(c),c}getBindState(e){if(!this.renderTarget)throw new Error("[RenderTargetSystem] getBindState is only valid while a render surface is bound");const t=this._bindState;return e??(e={}),e.target=t.target,e.clear=ye.NONE,e.clearColor=void 0,t.frame?e.frame?e.frame.copyFrom(t.frame):e.frame=t.frame.clone():e.frame=void 0,e.mipLevel=t.mipLevel,e.layer=t.layer,e.flipY=!!t.flipY,e}isFrontFaceInverted(e,t){if(!e){if(e=this.renderTarget,!e)return!1;t=e.flipY}return!!t!=(this._renderer.type===Ke.WEBGL&&!e.isRoot)}get frontFaceInverted(){return z(ut,"RenderTargetSystem.frontFaceInverted is deprecated, use isFrontFaceInverted() instead"),this.isFrontFaceInverted()}clear(e,t=ye.ALL,s,r=this.mipLevel,n=this.layer){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,s,this.viewport,r,n))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=ye.ALL,s,r,n=0,o=0,a){let l;"target"in e?l=e:(z("8.20.0","RenderTargetSystem.push: positional arguments are deprecated, please use an options object instead: push({ target, clear, clearColor, frame, mipLevel, layer, flipY })"),l={target:e,clear:t,clearColor:s,frame:r,mipLevel:n,layer:o,flipY:a});const h=this.bind(l);return this._renderTargetStack.push({target:l.target,clear:!1,clearColor:void 0,frame:l.frame?l.frame.clone():void 0,mipLevel:l.mipLevel,layer:l.layer,flipY:l.flipY}),h}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];if(!e)throw new Error("[RenderTargetSystem] pop: no previous binding to restore (unbalanced pop)");return this.bind(e)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,s,r,n){const o=this.getRenderTarget(e);s.x<0&&(r.width+=s.x,n.x-=s.x,s.x=0),s.y<0&&(r.height+=s.y,n.y-=s.y,s.y=0);const{pixelWidth:a,pixelHeight:l}=o;return r.width=Math.min(r.width,a-s.x),r.height=Math.min(r.height,l-s.y),this.adaptor.copyToTexture(o,t,s,r,n)}copyDepthTexture(e,t,s,r,n={x:0,y:0}){const o=this.getRenderTarget(e);if(!o.depthStencilAttachment){H("[RenderTargetSystem] copyDepthTexture: the source render target has no depth attachment to copy from");return}const a=t.source;if(!a.format.includes("depth")&&!a.format.includes("stencil")){H(`[RenderTargetSystem] copyDepthTexture: the destination texture must have a depth/stencil format (got '${a.format}')`);return}let l=s.x,h=s.y,c=n.x,u=n.y,d=r.width,f=r.height;l<0&&(d+=l,c-=l,l=0),h<0&&(f+=h,u-=h,h=0),d=Math.min(d,o.pixelWidth-l),f=Math.min(f,o.pixelHeight-h),d=Math.min(d,a.pixelWidth-c),f=Math.min(f,a.pixelHeight-u),!(d<=0||f<=0)&&this.adaptor.copyDepthTexture(o,t,{x:l,y:h},{width:d,height:f},{x:c,y:u})}ensureDepthStencil(){if(!this.renderTarget.stencil){if(this.renderTarget.depthStencilTexture){H(`[RenderTargetSystem] a stencil mask is being used, but the render target's depthStencilTexture format '${this.renderTarget.depthStencilTexture.format}' has no stencil aspect, so masking cannot work here. Use a 'depth24plus-stencil8' texture instead.`);return}this.renderTarget._depth=!0,this.renderTarget._stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport,0,this.layer)}}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t?this._releaseRenderTarget(t,e):e.off("destroy",this._onRenderTargetDestroy,this)}),this._renderSurfaceToRenderTargetHash.clear();for(const e of Object.values(this._gpuRenderTargetHash))e&&this.adaptor.destroyGpuRenderTarget(e);this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;if(Ve.test(e)&&(e=Tl(e).source),e instanceof ai)t=e,e.once("destroy",this._onRenderTargetDestroy,this);else if(e instanceof ue){const s=e.format;t=s.includes("depth")||s.includes("stencil")?new ai({colorTextures:0,depthStencilTexture:e}):new ai({colorTextures:[e]}),e.source instanceof Ve&&(t.isRoot=!0),e.once("destroy",this._onRenderSurfaceDestroy,this)}return this._renderSurfaceToRenderTargetHash.set(e,t),t}_onRenderSurfaceDestroy(e){const t=this._renderSurfaceToRenderTargetHash.get(e);t&&this._releaseRenderTarget(e,t)}_onRenderTargetDestroy(e){this._renderSurfaceToRenderTargetHash.delete(e),this._releaseGpuRenderTarget(e)}_releaseRenderTarget(e,t){t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e),e.off("destroy",this._onRenderSurfaceDestroy,this),this._releaseGpuRenderTarget(t)}_releaseGpuRenderTarget(e){const t=this._gpuRenderTargetHash[e.uid];t&&(this._gpuRenderTargetHash[e.uid]=null,this.adaptor.destroyGpuRenderTarget(t))}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this._bindState.target=null}}class sm{init(e,t){this._renderer=e,this._renderTargetSystem=t}initGpuRenderTarget(e){const t=e.colorTexture,{canvas:s,context:r}=this._ensureCanvas(t);return{canvas:s,context:r,width:s.width,height:s.height}}resizeGpuRenderTarget(e){const t=e.colorTexture,{canvas:s}=this._ensureCanvas(t);s.width=e.pixelWidth,s.height=e.pixelHeight}startRenderPass(e,t,s,r){const n=this._renderTargetSystem.getGpuRenderTarget(e);this._renderer.canvasContext.activeContext=n.context,this._renderer.canvasContext.activeResolution=e.resolution,t&&this.clear(e,t,s,r)}clear(e,t,s,r){const o=this._renderTargetSystem.getGpuRenderTarget(e).context,a=r||{x:0,y:0,width:e.pixelWidth,height:e.pixelHeight};if(o.setTransform(1,0,0,1,0,0),o.clearRect(a.x,a.y,a.width,a.height),s){const l=le.shared.setValue(s);l.alpha>0&&(o.globalAlpha=l.alpha,o.fillStyle=l.toHex(),o.fillRect(a.x,a.y,a.width,a.height),o.globalAlpha=1)}}finishRenderPass(){}copyToTexture(e,t,s,r,n){const a=this._renderTargetSystem.getGpuRenderTarget(e).canvas,l=t.source,{context:h}=this._ensureCanvas(l),c=n?.x??0,u=n?.y??0;return h.drawImage(a,s.x,s.y,r.width,r.height,c,u,r.width,r.height),l.update(),t}copyDepthTexture(e,t,s,r,n){H("[CanvasRenderTargetAdaptor] copyDepthTexture is not supported in the canvas renderer")}destroyGpuRenderTarget(e){}_ensureCanvas(e){let t=e.resource;(!t||!Ve.test(t))&&(t=ee.get().createCanvas(e.pixelWidth,e.pixelHeight),e.resource=t),(t.width!==e.pixelWidth||t.height!==e.pixelHeight)&&(t.width=e.pixelWidth,t.height=e.pixelHeight);const s=t.getContext("2d");return{canvas:t,context:s}}}class Ml extends qr{constructor(e){super(e),this.adaptor=new sm,this.adaptor.init(e,this)}}Ml.extension={type:[S.CanvasSystem],name:"renderTarget"};class kl{constructor(e){}init(){}initSource(e){}generateCanvas(e){const t=ee.get().createCanvas(),s=t.getContext("2d"),r=Y.getCanvasSource(e);if(!r)return t;const n=e.frame,o=e.source._resolution??e.source.resolution??1,a=n.x*o,l=n.y*o,h=n.width*o,c=n.height*o;return t.width=Math.ceil(h),t.height=Math.ceil(c),s.drawImage(r,a,l,h,c,0,0,h,c),t}getPixels(e){const t=this.generateCanvas(e);return{pixels:t.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,t.width,t.height).data,width:t.width,height:t.height}}destroy(){}}kl.extension={type:[S.CanvasSystem],name:"texture"};const $y=[...Xr,hl,cl,kl,Ml],Vy=[Vr,Nr,$r,Wr,zr,al,nl,Hr],jy=[Ap,ul],im=[],rm=[],nm=[],om=[];q.handleByNamedList(S.CanvasSystem,im);q.handleByNamedList(S.CanvasPipes,rm);q.handleByNamedList(S.CanvasPipesAdaptor,nm);q.handleByNamedList(S.CanvasLoader,om);q.add(...$y,...Vy,...jy);class am extends ds{constructor(){const e={name:"canvas",type:Ke.CANVAS,systems:im,renderPipes:rm,renderPipeAdaptors:nm,loaders:om};super(e)}}const Xy=Object.freeze(Object.defineProperty({__proto__:null,CanvasRenderer:am},Symbol.toStringTag,{value:"Module"}));var li=(i=>(i[i.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",i[i.ARRAY_BUFFER=34962]="ARRAY_BUFFER",i[i.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",i))(li||{});class lm{constructor(e,t){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class El{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new at({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:t}=this,s=this.getGlBuffer(e);t.bindBuffer(s.type,s.buffer)}bindBufferBase(e,t){const{_gl:s}=this;this._boundBufferBases[t]!==e&&(this._boundBufferBases[t]=e,e._lastBindBaseLocation=t,s.bindBufferBase(s.UNIFORM_BUFFER,t,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let t=this.getLastBindBaseLocation(e);if(t>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,t;let s=0,r=this._nextBindBaseIndex;for(;s<2;){r>=this._maxBindings&&(r=this._minBaseLocation,s++);const n=this._boundBufferBases[r];if(n&&n._lastBindCallId===this._bindCallId){r++;continue}break}return t=r,this._nextBindBaseIndex=r+1,s>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[t]=null,t)}getLastBindBaseLocation(e){const t=e._lastBindBaseLocation;return this._boundBufferBases[t]===e?t:-1}bindBufferRange(e,t,s,r){const{_gl:n}=this;s||(s=0),t||(t=0),this._boundBufferBases[t]=null,n.bindBufferRange(n.UNIFORM_BUFFER,t||0,e.buffer,s*256,r||256)}updateBuffer(e){const{_gl:t}=this,s=this.getGlBuffer(e);if(e._updateID===s.updateID)return s;s.updateID=e._updateID,t.bindBuffer(s.type,s.buffer);const r=e.data,n=e.descriptor.usage&ae.STATIC?t.STATIC_DRAW:t.DYNAMIC_DRAW;return r?s.byteLength>=r.byteLength?t.bufferSubData(s.type,e._updateOffset,r,e._updateOffset/r.BYTES_PER_ELEMENT,(e._updateSize||r.byteLength)/r.BYTES_PER_ELEMENT):(s.byteLength=r.byteLength,t.bufferData(s.type,r,n)):(s.byteLength=e.descriptor.size,t.bufferData(s.type,s.byteLength,n)),s}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];s&&(t||this._gl.deleteBuffer(s.buffer))}createGLBuffer(e){const{_gl:t}=this;let s=li.ARRAY_BUFFER;e.descriptor.usage&ae.INDEX?s=li.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&ae.UNIFORM&&(s=li.UNIFORM_BUFFER);const r=new lm(t.createBuffer(),s);return e._gpuData[this._renderer.uid]=r,this._managedBuffers.add(e),r}resetState(){this._boundBufferBases=Object.create(null)}}El.extension={type:[S.WebGLSystem],name:"buffer"};const Pl=class hm{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...hm.defaultOptions,...e};let t=this.multiView=e.multiView;if(e.context&&t&&(H("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),t=!1),t?this.canvas=ee.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const s=this._renderer.background.alpha<1,r=e.premultipliedAlpha??!0,n=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:s,premultipliedAlpha:r,antialias:n,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&H("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:t}=this;(t.width<e.width||t.height<e.height)&&(t.width=Math.max(e.width,e.width),t.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof ee.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const t=this._renderer.view.canvas;t.addEventListener("webglcontextlost",this.handleContextLost,!1),t.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,t){let s;const r=this.canvas;if(e===2&&(s=r.getContext("webgl2",t)),!s&&(s=r.getContext("webgl",t),!s))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=s,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,t={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...t,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...t,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const s=e.getExtension("WEBGL_provoking_vertex");s&&s.provokingVertexWEBGL(s.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{this.gl.isContextLost()&&this.extensions.loseContext?.restoreContext()},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),this.extensions.loseContext?.loseContext()}forceContextLoss(){this.extensions.loseContext?.loseContext(),this._contextLossForced=!0}validateContext(e){const t=e.getContextAttributes();t&&!t.stencil&&H("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const s=this.supports,r=this.webGLVersion===2,n=this.extensions;s.uint32Indices=r||!!n.uint32ElementIndex,s.uniformBufferObject=r,s.vertexArrayObject=r||!!n.vertexArrayObject,s.srgbTextures=r||!!n.srgb,s.nonPowOf2wrapping=r,s.nonPowOf2mipmaps=r,s.msaa=r,s.uint32Indices||H("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};Pl.extension={type:[S.WebGLSystem],name:"context"};Pl.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let cm=Pl;function gr(i,e){for(const t in i.attributes){const s=i.attributes[t],r=e[t];r?(s.format??(s.format=r.format),s.offset??(s.offset=r.offset),s.instance??(s.instance=r.instance)):s.format||H(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}qy(i)}function qy(i){const{buffers:e,attributes:t}=i,s={},r={};for(const n in e){const o=e[n];s[o.uid]=0,r[o.uid]=0}for(const n in t){const o=t[n];s[o.buffer.uid]+=mt(o.format).stride}for(const n in t){const o=t[n];o.stride??(o.stride=s[o.buffer.uid]),o.start??(o.start=r[o.buffer.uid]),r[o.buffer.uid]+=mt(o.format).stride}}var _r=(i=>(i[i.RGBA=6408]="RGBA",i[i.RGB=6407]="RGB",i[i.RG=33319]="RG",i[i.RED=6403]="RED",i[i.RGBA_INTEGER=36249]="RGBA_INTEGER",i[i.RGB_INTEGER=36248]="RGB_INTEGER",i[i.RG_INTEGER=33320]="RG_INTEGER",i[i.RED_INTEGER=36244]="RED_INTEGER",i[i.ALPHA=6406]="ALPHA",i[i.LUMINANCE=6409]="LUMINANCE",i[i.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",i[i.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",i[i.DEPTH_STENCIL=34041]="DEPTH_STENCIL",i))(_r||{}),Gs=(i=>(i[i.TEXTURE_2D=3553]="TEXTURE_2D",i[i.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",i[i.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",i[i.TEXTURE_3D=32879]="TEXTURE_3D",i[i.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",i[i.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",i[i.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",i[i.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",i[i.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",i))(Gs||{}),ie=(i=>(i[i.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",i[i.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",i[i.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",i[i.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",i[i.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",i[i.UNSIGNED_INT=5125]="UNSIGNED_INT",i[i.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",i[i.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",i[i.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",i[i.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",i[i.BYTE=5120]="BYTE",i[i.SHORT=5122]="SHORT",i[i.INT=5124]="INT",i[i.FLOAT=5126]="FLOAT",i[i.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",i[i.HALF_FLOAT=36193]="HALF_FLOAT",i))(ie||{});const Lc={uint8x2:ie.UNSIGNED_BYTE,uint8x4:ie.UNSIGNED_BYTE,sint8x2:ie.BYTE,sint8x4:ie.BYTE,unorm8x2:ie.UNSIGNED_BYTE,unorm8x4:ie.UNSIGNED_BYTE,snorm8x2:ie.BYTE,snorm8x4:ie.BYTE,uint16x2:ie.UNSIGNED_SHORT,uint16x4:ie.UNSIGNED_SHORT,sint16x2:ie.SHORT,sint16x4:ie.SHORT,unorm16x2:ie.UNSIGNED_SHORT,unorm16x4:ie.UNSIGNED_SHORT,snorm16x2:ie.SHORT,snorm16x4:ie.SHORT,float16x2:ie.HALF_FLOAT,float16x4:ie.HALF_FLOAT,float32:ie.FLOAT,float32x2:ie.FLOAT,float32x3:ie.FLOAT,float32x4:ie.FLOAT,uint32:ie.UNSIGNED_INT,uint32x2:ie.UNSIGNED_INT,uint32x3:ie.UNSIGNED_INT,uint32x4:ie.UNSIGNED_INT,sint32:ie.INT,sint32x2:ie.INT,sint32x3:ie.INT,sint32x4:ie.INT};function um(i){return Lc[i]??Lc.float32}const Yy={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class dm{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class Al{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new at({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=r=>t.bindVertexArrayOES(r),e.deleteVertexArray=r=>t.deleteVertexArrayOES(r));const s=this._renderer.context.extensions.vertexAttribDivisorANGLE;s&&(e.drawArraysInstanced=(r,n,o,a)=>{s.drawArraysInstancedANGLE(r,n,o,a)},e.drawElementsInstanced=(r,n,o,a,l)=>{s.drawElementsInstancedANGLE(r,n,o,a,l)},e.vertexAttribDivisor=(r,n)=>s.vertexAttribDivisorANGLE(r,n)),this._activeGeometry=null,this._activeVao=null}bind(e,t){const s=this.gl;this._activeGeometry=e;const r=this.getVao(e,t);this._activeVao!==r&&(this._activeVao=r,s.bindVertexArray(r)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,t=this._renderer.buffer;for(let s=0;s<e.buffers.length;s++){const r=e.buffers[s];t.updateBuffer(r)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,t){const s=e.attributes,r=t._attributeData;for(const n in r)if(!s[n])throw new Error(`shader and geometry incompatible, geometry missing the "${n}" attribute`)}getSignature(e,t){const s=e.attributes,r=t._attributeData,n=["g",e.uid];for(const o in s)r[o]&&n.push(o,r[o].location);return n.join("-")}getVao(e,t){return e._gpuData[this._renderer.uid]?.vaoCache[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,s=!0){const r=this._renderer.gl,n=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);const o=this.getSignature(e,t);let a=e._gpuData[this._renderer.uid];a||(a=new dm,e._gpuData[this._renderer.uid]=a,this._managedGeometries.add(e));const l=a.vaoCache;let h=l[o];if(h)return l[t._key]=h,h;gr(e,t._attributeData);const c=e.buffers;h=r.createVertexArray(),r.bindVertexArray(h);for(let u=0;u<c.length;u++){const d=c[u];n.bind(d)}return this.activateVao(e,t),l[t._key]=h,l[o]=h,r.bindVertexArray(null),h}onGeometryUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];if(!s)return;const r=s.vaoCache;if(!t)for(const n in r)this._activeVao===r[n]&&this.resetState(),this.gl.deleteVertexArray(r[n])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,t){const s=this._renderer.gl,r=this._renderer.buffer,n=e.attributes;e.indexBuffer&&r.bind(e.indexBuffer);let o=null;for(const a in n){const l=n[a],h=l.buffer,c=r.getGlBuffer(h),u=t._attributeData[a];if(u){o!==c&&(r.bind(h),o=c);const d=u.location;s.enableVertexAttribArray(d);const f=mt(l.format),p=um(l.format);if(u.format?.substring(1,4)==="int"?s.vertexAttribIPointer(d,f.size,p,l.stride,l.offset):s.vertexAttribPointer(d,f.size,p,f.normalised,l.stride,l.offset),l.instance)if(this.hasInstance){const g=l.divisor??1;s.vertexAttribDivisor(d,g)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,t,s,r){const{gl:n}=this._renderer,o=this._activeGeometry,a=Yy[e||o.topology];if(r??(r=o.instanceCount),o.indexBuffer){const l=o.indexBuffer.data.BYTES_PER_ELEMENT,h=l===2?n.UNSIGNED_SHORT:n.UNSIGNED_INT,c=t||o.indexCount||o.indexBuffer.data.length,u=(s||0)*l;r!==1?n.drawElementsInstanced(a,c,h,u,r):n.drawElements(a,c,h,u)}else r!==1?n.drawArraysInstanced(a,s||0,t||o.vertexCount,r):n.drawArrays(a,s||0,t||o.vertexCount);return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}Al.extension={type:[S.WebGLSystem],name:"geometry"};const Ky=new Si({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),Rl=class fm{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:t,antialias:s}={...fm.defaultOptions,...e};this.useBackBuffer=t,this._antialias=s,this._renderer.context.supports.msaa||(H("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=_t.for2d();const r=new us({vertex:`
586
586
  attribute vec2 aPosition;
587
587
  out vec2 vUv;
588
588
 
@@ -601,7 +601,7 @@ fn mainFragment(
601
601
 
602
602
  void main() {
603
603
  finalColor = texture(uTexture, vUv);
604
- }`,name:"big-triangle"});this._bigTriangleShader=new ft({glProgram:r,resources:{uTexture:W.WHITE.source}})}renderStart(e){const t=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!t.isRoot,this._useBackBufferThisRender){const s=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=s.colorTexture,e.target=this._getBackBufferTexture(s.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind({target:this._targetTexture,clear:!1}),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:$y,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new W({source:new de({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};Sl.extension={type:[S.WebGLSystem],name:"backBuffer",priority:1};Sl.defaultOptions={useBackBuffer:!1};let cm=Sl;class Cl{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}Cl.extension={type:[S.WebGLSystem],name:"colorMask"};class Ml{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,t){this._renderer.geometry.bind(e,t.glProgram)}finishRenderPass(){}draw(e){const t=this._renderer,{geometry:s,shader:r,state:n,skipSync:o,topology:a,size:l,start:h,instanceCount:c}=e;t.shader.bind(r,o),t.geometry.bind(s,t.shader._activeProgram),n&&t.state.set(n),t.geometry.draw(a,l,h,c??s.instanceCount)}destroy(){this._renderer=null}}Ml.extension={type:[S.WebGLSystem],name:"encoder"};class kl{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=ua(this.maxTextures,e);const t=this._renderer.context.webGLVersion===2;this.maxUniformBindings=t?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}kl.extension={type:[S.WebGLSystem],name:"limits"};class um{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[],this.stencilMode=me.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}const At=[];At[me.NONE]=void 0;At[me.DISABLED]={stencilWriteMask:0,stencilReadMask:0};At[me.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}};At[me.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}};At[me.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};At[me.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class El{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:me.NONE},this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this._activeGpuRenderTarget=null,this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;const t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=me.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,t){const s=this._activeGpuRenderTarget??(this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget)),r=this._gl,n=At[e],o=this._stencilCache;if(s.stencilMode=e,s.stencilReference=t,e===me.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,r.disable(r.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,r.enable(r.STENCIL_TEST)),(e!==o.stencilMode||o.stencilReference!==t)&&(o.stencilMode=e,o.stencilReference=t,r.stencilFunc(this._comparisonFuncMapping[n.stencilBack.compare],t,255),r.stencilOp(r.KEEP,r.KEEP,this._stencilOpsMapping[n.stencilBack.passOp]))}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._gl=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}El.extension={type:[S.WebGLSystem],name:"stencil"};class Pl{constructor(e){this._syncFunctionHash=Object.create(null),this._adaptor=e,this._systemCheck()}_systemCheck(){if(!ia())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}ensureUniformGroup(e){const t=this.getUniformGroupData(e);e.buffer||(e.buffer=new kt({data:new Float32Array(t.layout.size/4),usage:ce.UNIFORM|ce.COPY_DST}))}getUniformGroupData(e){return this._syncFunctionHash[e._signature]||this._initUniformGroup(e)}_initUniformGroup(e){const t=e._signature;let s=this._syncFunctionHash[t];if(!s){const r=Object.keys(e.uniformStructures).map(a=>e.uniformStructures[a]),n=this._adaptor.createUboElements(r),o=this._generateUboSync(n.uboElements);s=this._syncFunctionHash[t]={layout:n,syncFunction:o}}return this._syncFunctionHash[t]}_generateUboSync(e){return this._adaptor.generateUboSync(e)}syncUniformGroup(e,t,s){const r=this.getUniformGroupData(e);e.buffer||(e.buffer=new kt({data:new Float32Array(r.layout.size/4),usage:ce.UNIFORM|ce.COPY_DST}));let n=null;return t||(t=e.buffer.data,n=e.buffer.dataInt32),s||(s=0),r.syncFunction(e.uniforms,t,n,s),!0}updateUniformGroup(e){if(e.isStatic&&!e._dirtyId)return!1;e._dirtyId=0;const t=this.syncUniformGroup(e);return e.buffer.update(),t}destroy(){this._syncFunctionHash=null}}const Al={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,u32:4,"vec2<u32>":8,"vec3<u32>":12,"vec4<u32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function dm(i){const e=i.map(n=>({data:n,offset:0,size:0})),t=16;let s=0,r=0;for(let n=0;n<e.length;n++){const o=e[n];if(s=Al[o.data.type],!s)throw new Error(`Unknown type ${o.data.type}`);o.data.size>1&&(s=Math.max(s,t)*o.data.size);const a=s===12?16:s;o.size=s;const l=r%t;l>0&&t-l<a?r+=(t-l)%16:r+=(s-l%s)%s,o.offset=r,r+=s}return r=Math.ceil(r/16)*16,{uboElements:e,size:r}}const Qt=[{type:"mat3x3<f32>",test:i=>i.value.a!==void 0,ubo:`
604
+ }`,name:"big-triangle"});this._bigTriangleShader=new gt({glProgram:r,resources:{uTexture:W.WHITE.source}})}renderStart(e){const t=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!t.isRoot,this._useBackBufferThisRender){const s=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=s.colorTexture,e.target=this._getBackBufferTexture(s.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind({target:this._targetTexture,clear:!1}),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:Ky,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new W({source:new ue({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};Rl.extension={type:[S.WebGLSystem],name:"backBuffer",priority:1};Rl.defaultOptions={useBackBuffer:!1};let pm=Rl;class Bl{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}Bl.extension={type:[S.WebGLSystem],name:"colorMask"};class Il{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,t){this._renderer.geometry.bind(e,t.glProgram)}finishRenderPass(){}draw(e){const t=this._renderer,{geometry:s,shader:r,state:n,skipSync:o,topology:a,size:l,start:h,instanceCount:c}=e;t.shader.bind(r,o),t.geometry.bind(s,t.shader._activeProgram),n&&t.state.set(n),t.geometry.draw(a,l,h,c??s.instanceCount)}destroy(){this._renderer=null}}Il.extension={type:[S.WebGLSystem],name:"encoder"};class Gl{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=ya(this.maxTextures,e);const t=this._renderer.context.webGLVersion===2;this.maxUniformBindings=t?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}Gl.extension={type:[S.WebGLSystem],name:"limits"};class mm{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[],this.stencilMode=me.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}const Bt=[];Bt[me.NONE]=void 0;Bt[me.DISABLED]={stencilWriteMask:0,stencilReadMask:0};Bt[me.RENDERING_MASK_ADD]={stencilFront:{compare:"equal",passOp:"increment-clamp"},stencilBack:{compare:"equal",passOp:"increment-clamp"}};Bt[me.RENDERING_MASK_REMOVE]={stencilFront:{compare:"equal",passOp:"decrement-clamp"},stencilBack:{compare:"equal",passOp:"decrement-clamp"}};Bt[me.MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"equal",passOp:"keep"},stencilBack:{compare:"equal",passOp:"keep"}};Bt[me.INVERSE_MASK_ACTIVE]={stencilWriteMask:0,stencilFront:{compare:"not-equal",passOp:"keep"},stencilBack:{compare:"not-equal",passOp:"keep"}};class Dl{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:me.NONE},this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this._activeGpuRenderTarget=null,this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;const t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=me.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,t){const s=this._activeGpuRenderTarget??(this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget)),r=this._gl,n=Bt[e],o=this._stencilCache;if(s.stencilMode=e,s.stencilReference=t,e===me.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,r.disable(r.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,r.enable(r.STENCIL_TEST)),(e!==o.stencilMode||o.stencilReference!==t)&&(o.stencilMode=e,o.stencilReference=t,r.stencilFunc(this._comparisonFuncMapping[n.stencilBack.compare],t,255),r.stencilOp(r.KEEP,r.KEEP,this._stencilOpsMapping[n.stencilBack.passOp]))}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._gl=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}Dl.extension={type:[S.WebGLSystem],name:"stencil"};class Yr{constructor(e){this._syncFunctionHash=Object.create(null),this._adaptor=e,this._systemCheck()}_systemCheck(){if(!ca())throw new Error("Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.")}ensureUniformGroup(e){const t=this.getUniformGroupData(e);e.buffer||(e.buffer=new ot({data:new Float32Array(t.layout.size/4),usage:ae.UNIFORM|ae.COPY_DST}))}getUniformGroupData(e){return this._syncFunctionHash[e._signature]||this._initUniformGroup(e)}_initUniformGroup(e){const t=e._signature;let s=this._syncFunctionHash[t];if(!s){const r=Object.keys(e.uniformStructures).map(a=>e.uniformStructures[a]),n=this._adaptor.createUboElements(r),o=this._generateUboSync(n.uboElements);s=this._syncFunctionHash[t]={layout:n,syncFunction:o}}return this._syncFunctionHash[t]}_generateUboSync(e){return this._adaptor.generateUboSync(e)}syncUniformGroup(e,t,s){const r=this.getUniformGroupData(e);e.buffer||(e.buffer=new ot({data:new Float32Array(r.layout.size/4),usage:ae.UNIFORM|ae.COPY_DST}));let n=null;return t||(t=e.buffer.data,n=e.buffer.dataInt32),s||(s=0),r.syncFunction(e.uniforms,t,n,s),!0}updateUniformGroup(e){if(e.isStatic&&!e._dirtyId)return!1;e._dirtyId=0;const t=this.syncUniformGroup(e);return e.buffer.update(),t}destroy(){this._syncFunctionHash=null}}const Kr={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,u32:4,"vec2<u32>":8,"vec3<u32>":12,"vec4<u32>":16,"mat2x2<f32>":32,"mat3x3<f32>":48,"mat4x4<f32>":64};function gm(i){const e=i.map(n=>({data:n,offset:0,size:0})),t=16;let s=0,r=0;for(let n=0;n<e.length;n++){const o=e[n];if(s=Kr[o.data.type],!s)throw new Error(`Unknown type ${o.data.type}`);o.data.size>1&&(s=Math.max(s,t)*o.data.size);const a=s===12?16:s;o.size=s;const l=r%t;l>0&&t-l<a?r+=(t-l)%16:r+=(s-l%s)%s,o.offset=r,r+=s}return r=Math.ceil(r/16)*16,{uboElements:e,size:r}}const nt=[{type:"mat3x3<f32>",test:i=>i.value.a!==void 0,ubo:`
605
605
  var matrix = uv[name].toArray(true);
606
606
  data[offset] = matrix[0];
607
607
  data[offset + 1] = matrix[1];
@@ -672,23 +672,23 @@ fn mainFragment(
672
672
  cv[2] = v.blue;
673
673
  gl.uniform3f(ud[name].location, v.red, v.green, v.blue);
674
674
  }
675
- `}];function Rl(i,e,t){const s=[`
675
+ `}];function Fl(i,e,t){const s=[`
676
676
  var v = null;
677
677
  var v2 = null;
678
678
  var t = 0;
679
679
  var index = 0;
680
680
  var name = null;
681
681
  var arrayOffset = null;
682
- `];let r=0;for(let o=0;o<i.length;o++){const a=i[o],l=a.data.name;let h=!1,c=0;for(let u=0;u<Qt.length;u++)if(Qt[u].test(a.data)){c=a.offset/4,s.push(`name = "${l}";`,`offset += ${c-r};`,Qt[u].ubo),h=!0;break}if(!h)if(a.data.size>1)c=a.offset/4,s.push(t(a,c-r));else{const u=e[a.data.type];c=a.offset/4,s.push(`
682
+ `];let r=0;for(let o=0;o<i.length;o++){const a=i[o],l=a.data.name;let h=!1,c=0;for(let u=0;u<nt.length;u++)if(nt[u].test(a.data)){c=a.offset/4,s.push(`name = "${l}";`,`offset += ${c-r};`,nt[u].ubo),h=!0;break}if(!h)if(a.data.size>1)c=a.offset/4,s.push(t(a,c-r));else{const u=e[a.data.type];c=a.offset/4,s.push(`
683
683
  v = uv.${l};
684
684
  offset += ${c-r};
685
685
  ${u};
686
686
  `)}r=c}const n=s.join(`
687
- `);return new Function("uv","data","dataInt32","offset",n)}function ms(i,e){return`
687
+ `);return new Function("uv","data","dataInt32","offset",n)}function xs(i,e){return`
688
688
  for (let i = 0; i < ${i*e}; i++) {
689
689
  data[offset + (((i / ${i})|0) * 4) + (i % ${i})] = v[i];
690
690
  }
691
- `}const Bl={f32:`
691
+ `}const Ol={f32:`
692
692
  data[offset] = v;`,i32:`
693
693
  dataInt32[offset] = v;`,u32:`
694
694
  dataInt32[offset] = v;`,"vec2<f32>":`
@@ -734,12 +734,12 @@ fn mainFragment(
734
734
  data[offset + 10] = v[8];`,"mat4x4<f32>":`
735
735
  for (let i = 0; i < 16; i++) {
736
736
  data[offset + i] = v[i];
737
- }`,"mat3x2<f32>":ms(3,2),"mat4x2<f32>":ms(4,2),"mat2x3<f32>":ms(2,3),"mat4x3<f32>":ms(4,3),"mat2x4<f32>":ms(2,4),"mat3x4<f32>":ms(3,4)},fm={...Bl,"mat2x2<f32>":`
737
+ }`,"mat3x2<f32>":xs(3,2),"mat4x2<f32>":xs(4,2),"mat2x3<f32>":xs(2,3),"mat4x3<f32>":xs(4,3),"mat2x4<f32>":xs(2,4),"mat3x4<f32>":xs(3,4)},_m={...Ol,"mat2x2<f32>":`
738
738
  data[offset] = v[0];
739
739
  data[offset + 1] = v[1];
740
740
  data[offset + 2] = v[2];
741
741
  data[offset + 3] = v[3];
742
- `};function pm(i,e){const t=Math.max(Al[i.data.type]/16,1),s=i.data.value.length/i.data.size,r=(4-s%4)%4,n=i.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
742
+ `};function ym(i,e){const t=Math.max(Kr[i.data.type]/16,1),s=i.data.value.length/i.data.size,r=(4-s%4)%4,n=i.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
743
743
  v = uv.${i.data.name};
744
744
  offset += ${e};
745
745
 
@@ -755,7 +755,7 @@ fn mainFragment(
755
755
  }
756
756
  ${r!==0?`arrayOffset += ${r};`:""}
757
757
  }
758
- `}function mm(i){return Rl(i,Bl,pm)}class Il extends Pl{constructor(){super({createUboElements:dm,generateUboSync:mm})}}Il.extension={type:[S.WebGLSystem],name:"ubo"};class gm{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new te,this._boundFramebuffer=void 0}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new te,this._boundFramebuffer=void 0;const e=this._renderer.gl;this._drawBuffersCache=[];for(let t=1;t<=16;t++)this._drawBuffersCache[t]=Array.from({length:t},(s,r)=>e.COLOR_ATTACHMENT0+r)}copyToTexture(e,t,s,r,n){const o=this._renderTargetSystem,a=this._renderer,l=o.getGpuRenderTarget(e),h=a.gl;return this.finishRenderPass(e),h.bindFramebuffer(h.FRAMEBUFFER,l.resolveTargetFramebuffer),this._boundFramebuffer=l.resolveTargetFramebuffer,a.texture.bind(t,0),h.copyTexSubImage2D(h.TEXTURE_2D,0,n.x,n.y,s.x,s.y,r.width,r.height),t}copyDepthTexture(e,t,s,r,n){const o=this._renderTargetSystem,a=this._renderer.gl;this.finishRenderPass(e);const l=o.getRenderTarget(t),h=o.getGpuRenderTarget(e),c=o.getGpuRenderTarget(l);a.bindFramebuffer(a.READ_FRAMEBUFFER,h.framebuffer),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,c.framebuffer),this._boundFramebuffer=void 0,a.blitFramebuffer(s.x,s.y,s.x+r.width,s.y+r.height,n.x,n.y,n.x+r.width,n.y+r.height,a.DEPTH_BUFFER_BIT,a.NEAREST)}startRenderPass(e,t=!0,s,r,n=0,o=0){const l=this._renderTargetSystem.getGpuRenderTarget(e);if(o!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(n>0){if(l.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}e.colorAttachments.forEach(d=>{this._renderer.texture.unbind(d.texture)});const h=this._renderer.gl;this.bindFramebuffer(l.framebuffer),!e.isRoot&&e.colorAttachments.length>0&&(l._attachedMipLevel!==n||l._attachedLayer!==o)&&(e.colorAttachments.forEach((d,f)=>{const p=d.texture,g=this._renderer.texture.getGlSource(p);if(g.target===h.TEXTURE_2D){if(o!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,h.TEXTURE_2D,g.texture,n)}else if(g.target===h.TEXTURE_2D_ARRAY||g.target===h.TEXTURE_3D)h.framebufferTextureLayer(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,g.texture,n,o);else if(g.target===h.TEXTURE_CUBE_MAP){if(o<0||o>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,h.TEXTURE_CUBE_MAP_POSITIVE_X+o,g.texture,n)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),l._attachedMipLevel=n,l._attachedLayer=o),l.framebuffer&&(e.depthStencilAttachment?this._attachDepthStencilTexture(e,n,o):!l.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(l)),e.colorAttachments.length>1&&this._setDrawBuffers(e,h);let c=r.y;e.isRoot&&(c=e.pixelHeight-r.height-r.y);const u=this._viewPortCache;(u.x!==r.x||u.y!==c||u.width!==r.width||u.height!==r.height)&&(u.x=r.x,u.y=c,u.width=r.width,u.height=r.height,h.viewport(r.x,c,r.width,r.height)),this.clear(e,t,s)}finishRenderPass(e){const s=this._renderTargetSystem.getGpuRenderTarget(e);if(!s.msaa||e.colorAttachments.length===0)return;const r=this._renderer.gl;r.bindFramebuffer(r.FRAMEBUFFER,s.resolveTargetFramebuffer),r.bindFramebuffer(r.READ_FRAMEBUFFER,s.framebuffer),r.blitFramebuffer(0,0,s.width,s.height,0,0,s.width,s.height,r.COLOR_BUFFER_BIT,r.NEAREST),r.bindFramebuffer(r.FRAMEBUFFER,s.framebuffer),this._boundFramebuffer=s.framebuffer}initGpuRenderTarget(e){const s=this._renderer.gl,r=new um;r._attachedMipLevel=0,r._attachedLayer=0;const n=e.colorTexture;return n instanceof Ve?(this._renderer.context.ensureCanvasSize(n.resource),r.framebuffer=null,r):(r.width=e.pixelWidth,r.height=e.pixelHeight,e.colorAttachments.length===0?this._initDepth(e,r):this._initColor(e,r),e.depthStencilAttachment&&this._attachDepthStencilTexture(e,0,0),s.bindFramebuffer(s.FRAMEBUFFER,null),this._boundFramebuffer=null,r)}destroyGpuRenderTarget(e){const t=this._renderer.gl;e.framebuffer&&(t.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(t.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(t.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(s=>{t.deleteRenderbuffer(s)}),e.msaaRenderBuffer.length=0}clear(e,t,s,r,n=0,o=0){if(!t)return;if(o!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const a=this._renderTargetSystem;if(typeof t=="boolean"&&(t=t?ye.ALL:ye.NONE),e.colorAttachments.length===0&&(t&=~ye.COLOR,!t))return;const l=this._renderer.gl,h=!!(t&ye.DEPTH)&&!this._renderer.state.depthMaskEnabled;if(t&ye.COLOR){s??(s=a.defaultClearColor);const c=this._clearColorCache,u=s;(c[0]!==u[0]||c[1]!==u[1]||c[2]!==u[2]||c[3]!==u[3])&&(c[0]=u[0],c[1]=u[1],c[2]=u[2],c[3]=u[3],l.clearColor(u[0],u[1],u[2],u[3]))}h&&l.depthMask(!0),l.clear(t),h&&l.depthMask(!1)}resizeGpuRenderTarget(e){if(e.isRoot)return;const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.pixelWidth,t.height=e.pixelHeight,e.colorAttachments.length>0&&this._resizeColor(e,t),t.depthStencilRenderBuffer&&this._resizeStencil(t),this._boundFramebuffer=void 0}_initColor(e,t){const s=this._renderer,r=s.gl,n=r.createFramebuffer();if(t.resolveTargetFramebuffer=n,r.bindFramebuffer(r.FRAMEBUFFER,n),e.colorAttachments.forEach((a,l)=>{const h=a.texture;h.antialias&&(s.context.supports.msaa?t.msaa=!0:z("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),s.texture.bindSource(h,0);const c=s.texture.getGlSource(h),u=c.texture;if(c.target===r.TEXTURE_2D)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,r.TEXTURE_2D,u,0);else if(c.target===r.TEXTURE_2D_ARRAY||c.target===r.TEXTURE_3D)r.framebufferTextureLayer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,u,0,0);else if(c.target===r.TEXTURE_CUBE_MAP)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,r.TEXTURE_CUBE_MAP_POSITIVE_X,u,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),t.msaa){const a=r.createFramebuffer();t.framebuffer=a,r.bindFramebuffer(r.FRAMEBUFFER,a),e.colorAttachments.forEach((l,h)=>{const c=r.createRenderbuffer();t.msaaRenderBuffer[h]=c})}else t.framebuffer=n;this._resizeColor(e,t)}_initDepth(e,t){const s=this._renderer;if(s.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Depth-only render targets require WebGL2.");const r=s.gl,n=r.createFramebuffer();t.resolveTargetFramebuffer=n,t.framebuffer=n,r.bindFramebuffer(r.FRAMEBUFFER,n),r.drawBuffers([r.NONE]),r.readBuffer(r.NONE)}_resizeColor(e,t){const s=e.colorAttachments[0].texture;if(t._attachedMipLevel=0,t._attachedLayer=0,e.colorAttachments.forEach((r,n)=>{n!==0&&r.texture.resize(s.width,s.height,s._resolution)}),t.msaa){const r=this._renderer,n=r.gl,o=t.framebuffer;n.bindFramebuffer(n.FRAMEBUFFER,o),e.colorAttachments.forEach((a,l)=>{const h=a.texture;r.texture.bindSource(h,0);const u=r.texture.getGlSource(h).internalFormat,d=t.msaaRenderBuffer[l];n.bindRenderbuffer(n.RENDERBUFFER,d),n.renderbufferStorageMultisample(n.RENDERBUFFER,4,u,h.pixelWidth,h.pixelHeight),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+l,n.RENDERBUFFER,d)})}}_attachDepthStencilTexture(e,t,s){const r=this._renderer,n=r.gl,o=e.depthStencilAttachment.texture,a=r.texture.getGlSource(o),l=a.texture,h=o.format;let c;h==="depth24plus-stencil8"||h==="depth32float-stencil8"?c=n.DEPTH_STENCIL_ATTACHMENT:h==="stencil8"?c=n.STENCIL_ATTACHMENT:c=n.DEPTH_ATTACHMENT,a.target===n.TEXTURE_2D?n.framebufferTexture2D(n.FRAMEBUFFER,c,n.TEXTURE_2D,l,t):a.target===n.TEXTURE_2D_ARRAY||a.target===n.TEXTURE_3D?n.framebufferTextureLayer(n.FRAMEBUFFER,c,l,t,s):a.target===n.TEXTURE_CUBE_MAP&&n.framebufferTexture2D(n.FRAMEBUFFER,c,n.TEXTURE_CUBE_MAP_POSITIVE_X+s,l,t)}_initStencil(e){if(e.framebuffer===null)return;const t=this._renderer.gl,s=t.createRenderbuffer();e.depthStencilRenderBuffer=s,t.bindRenderbuffer(t.RENDERBUFFER,s),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,s),this._resizeStencil(e)}_resizeStencil(e){const t=this._renderer.gl;t.bindRenderbuffer(t.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?t.renderbufferStorageMultisample(t.RENDERBUFFER,4,t.DEPTH24_STENCIL8,e.width,e.height):t.renderbufferStorage(t.RENDERBUFFER,this._renderer.context.webGLVersion===2?t.DEPTH24_STENCIL8:t.DEPTH_STENCIL,e.width,e.height)}prerender(e){if(e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture.resource;this._renderer.context.multiView&&Ve.test(t)&&this._renderer.context.ensureCanvasSize(t)}postrender(e){if(!this._renderer.context.multiView||e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture;if(Ve.test(t.resource)){const s=this._renderer.context.canvas,r=t;r.context2D.drawImage(s,0,r.pixelHeight-s.height)}}_setDrawBuffers(e,t){const s=e.colorAttachments.length,r=this._drawBuffersCache[s];if(this._renderer.context.webGLVersion===1){const n=this._renderer.context.extensions.drawBuffers;n?n.drawBuffersWEBGL(r):z("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else t.drawBuffers(r)}resetState(){this._boundFramebuffer=void 0,this._viewPortCache=new te,this._clearColorCache=[0,0,0,0]}bindFramebuffer(e){this._boundFramebuffer!==e&&(this._boundFramebuffer=e,this._renderer.gl.bindFramebuffer(this._renderer.gl.FRAMEBUFFER,e))}}class Gl extends jr{constructor(e){super(e),this.adaptor=new gm,this.adaptor.init(e,this)}resetState(){this.adaptor.resetState()}}Gl.extension={type:[S.WebGLSystem],name:"renderTarget"};class Xr extends Re{constructor({buffer:e,offset:t,size:s}){super(),this.uid=oe("buffer"),this._resourceType="bufferResource",this._resourceId=oe("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=e,this.offset=t|0,this.size=s,this.buffer.on("change",this.onBufferChange,this)}get _gcLastUsed(){return this.buffer?._gcLastUsed??-1}set _gcLastUsed(e){this.buffer&&(this.buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=oe("resource"),this.emit("change",this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}class _m extends Re{constructor(e,t){super(),this._resourceType="textureView",this._resourceId=oe("resource"),this.source=e,this.viewDescriptor=t,this._onChange=this._onChange.bind(this),this._onDestroy=this._onDestroy.bind(this),this.source.on("change",this._onChange),this.source.on("destroy",this._onDestroy)}_onChange(){this.emit("change",this)}_onDestroy(){this.destroy()}get destroyed(){return this.source.destroyed}destroy(){this.source&&(this.source.off("change",this._onChange),this.source.off("destroy",this._onDestroy)),this.emit("destroy",this),this.removeAllListeners()}}function ym(i,e){const t=[],s=[`
758
+ `}function xm(i){return Fl(i,Ol,ym)}class Zr extends Yr{constructor(){super({createUboElements:gm,generateUboSync:xm})}}Zr.extension={type:[S.WebGLSystem],name:"ubo"};class bm{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new te,this._boundFramebuffer=void 0}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new te,this._boundFramebuffer=void 0;const e=this._renderer.gl;this._drawBuffersCache=[];for(let t=1;t<=16;t++)this._drawBuffersCache[t]=Array.from({length:t},(s,r)=>e.COLOR_ATTACHMENT0+r)}copyToTexture(e,t,s,r,n){const o=this._renderTargetSystem,a=this._renderer,l=o.getGpuRenderTarget(e),h=a.gl;return this.finishRenderPass(e),h.bindFramebuffer(h.FRAMEBUFFER,l.resolveTargetFramebuffer),this._boundFramebuffer=l.resolveTargetFramebuffer,a.texture.bind(t,0),h.copyTexSubImage2D(h.TEXTURE_2D,0,n.x,n.y,s.x,s.y,r.width,r.height),t}copyDepthTexture(e,t,s,r,n){const o=this._renderTargetSystem,a=this._renderer.gl;this.finishRenderPass(e);const l=o.getRenderTarget(t),h=o.getGpuRenderTarget(e),c=o.getGpuRenderTarget(l);a.bindFramebuffer(a.READ_FRAMEBUFFER,h.framebuffer),a.bindFramebuffer(a.DRAW_FRAMEBUFFER,c.framebuffer),this._boundFramebuffer=void 0,a.blitFramebuffer(s.x,s.y,s.x+r.width,s.y+r.height,n.x,n.y,n.x+r.width,n.y+r.height,a.DEPTH_BUFFER_BIT,a.NEAREST)}startRenderPass(e,t=!0,s,r,n=0,o=0){const l=this._renderTargetSystem.getGpuRenderTarget(e);if(o!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(n>0){if(l.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}e.colorAttachments.forEach(d=>{this._renderer.texture.unbind(d.texture)});const h=this._renderer.gl;this.bindFramebuffer(l.framebuffer),!e.isRoot&&e.colorAttachments.length>0&&(l._attachedMipLevel!==n||l._attachedLayer!==o)&&(e.colorAttachments.forEach((d,f)=>{const p=d.texture,g=this._renderer.texture.getGlSource(p);if(g.target===h.TEXTURE_2D){if(o!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,h.TEXTURE_2D,g.texture,n)}else if(g.target===h.TEXTURE_2D_ARRAY||g.target===h.TEXTURE_3D)h.framebufferTextureLayer(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,g.texture,n,o);else if(g.target===h.TEXTURE_CUBE_MAP){if(o<0||o>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0+f,h.TEXTURE_CUBE_MAP_POSITIVE_X+o,g.texture,n)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),l._attachedMipLevel=n,l._attachedLayer=o),l.framebuffer&&(e.depthStencilAttachment?this._attachDepthStencilTexture(e,n,o):!l.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(l)),e.colorAttachments.length>1&&this._setDrawBuffers(e,h);let c=r.y;e.isRoot&&(c=e.pixelHeight-r.height-r.y);const u=this._viewPortCache;(u.x!==r.x||u.y!==c||u.width!==r.width||u.height!==r.height)&&(u.x=r.x,u.y=c,u.width=r.width,u.height=r.height,h.viewport(r.x,c,r.width,r.height)),this.clear(e,t,s)}finishRenderPass(e){const s=this._renderTargetSystem.getGpuRenderTarget(e);if(!s.msaa||e.colorAttachments.length===0)return;const r=this._renderer.gl;r.bindFramebuffer(r.FRAMEBUFFER,s.resolveTargetFramebuffer),r.bindFramebuffer(r.READ_FRAMEBUFFER,s.framebuffer),r.blitFramebuffer(0,0,s.width,s.height,0,0,s.width,s.height,r.COLOR_BUFFER_BIT,r.NEAREST),r.bindFramebuffer(r.FRAMEBUFFER,s.framebuffer),this._boundFramebuffer=s.framebuffer}initGpuRenderTarget(e){const s=this._renderer.gl,r=new mm;r._attachedMipLevel=0,r._attachedLayer=0;const n=e.colorTexture;return n instanceof Ve?(this._renderer.context.ensureCanvasSize(n.resource),r.framebuffer=null,r):(r.width=e.pixelWidth,r.height=e.pixelHeight,e.colorAttachments.length===0?this._initDepth(e,r):this._initColor(e,r),e.depthStencilAttachment&&this._attachDepthStencilTexture(e,0,0),s.bindFramebuffer(s.FRAMEBUFFER,null),this._boundFramebuffer=null,r)}destroyGpuRenderTarget(e){const t=this._renderer.gl;e.framebuffer&&(t.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(t.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(t.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(s=>{t.deleteRenderbuffer(s)}),e.msaaRenderBuffer.length=0}clear(e,t,s,r,n=0,o=0){if(!t)return;if(o!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const a=this._renderTargetSystem;if(typeof t=="boolean"&&(t=t?ye.ALL:ye.NONE),e.colorAttachments.length===0&&(t&=~ye.COLOR,!t))return;const l=this._renderer.gl,h=!!(t&ye.DEPTH)&&!this._renderer.state.depthMaskEnabled;if(t&ye.COLOR){s??(s=a.defaultClearColor);const c=this._clearColorCache,u=s;(c[0]!==u[0]||c[1]!==u[1]||c[2]!==u[2]||c[3]!==u[3])&&(c[0]=u[0],c[1]=u[1],c[2]=u[2],c[3]=u[3],l.clearColor(u[0],u[1],u[2],u[3]))}h&&l.depthMask(!0),l.clear(t),h&&l.depthMask(!1)}resizeGpuRenderTarget(e){if(e.isRoot)return;const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.pixelWidth,t.height=e.pixelHeight,e.colorAttachments.length>0&&this._resizeColor(e,t),t.depthStencilRenderBuffer&&this._resizeStencil(t),this._boundFramebuffer=void 0}_initColor(e,t){const s=this._renderer,r=s.gl,n=r.createFramebuffer();if(t.resolveTargetFramebuffer=n,r.bindFramebuffer(r.FRAMEBUFFER,n),e.colorAttachments.forEach((a,l)=>{const h=a.texture;h.antialias&&(s.context.supports.msaa?t.msaa=!0:H("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),s.texture.bindSource(h,0);const c=s.texture.getGlSource(h),u=c.texture;if(c.target===r.TEXTURE_2D)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,r.TEXTURE_2D,u,0);else if(c.target===r.TEXTURE_2D_ARRAY||c.target===r.TEXTURE_3D)r.framebufferTextureLayer(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,u,0,0);else if(c.target===r.TEXTURE_CUBE_MAP)r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,r.TEXTURE_CUBE_MAP_POSITIVE_X,u,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),t.msaa){const a=r.createFramebuffer();t.framebuffer=a,r.bindFramebuffer(r.FRAMEBUFFER,a),e.colorAttachments.forEach((l,h)=>{const c=r.createRenderbuffer();t.msaaRenderBuffer[h]=c})}else t.framebuffer=n;this._resizeColor(e,t)}_initDepth(e,t){const s=this._renderer;if(s.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Depth-only render targets require WebGL2.");const r=s.gl,n=r.createFramebuffer();t.resolveTargetFramebuffer=n,t.framebuffer=n,r.bindFramebuffer(r.FRAMEBUFFER,n),r.drawBuffers([r.NONE]),r.readBuffer(r.NONE)}_resizeColor(e,t){const s=e.colorAttachments[0].texture;if(t._attachedMipLevel=0,t._attachedLayer=0,e.colorAttachments.forEach((r,n)=>{n!==0&&r.texture.resize(s.width,s.height,s._resolution)}),t.msaa){const r=this._renderer,n=r.gl,o=t.framebuffer;n.bindFramebuffer(n.FRAMEBUFFER,o),e.colorAttachments.forEach((a,l)=>{const h=a.texture;r.texture.bindSource(h,0);const u=r.texture.getGlSource(h).internalFormat,d=t.msaaRenderBuffer[l];n.bindRenderbuffer(n.RENDERBUFFER,d),n.renderbufferStorageMultisample(n.RENDERBUFFER,4,u,h.pixelWidth,h.pixelHeight),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+l,n.RENDERBUFFER,d)})}}_attachDepthStencilTexture(e,t,s){const r=this._renderer,n=r.gl,o=e.depthStencilAttachment.texture,a=r.texture.getGlSource(o),l=a.texture,h=o.format;let c;h==="depth24plus-stencil8"||h==="depth32float-stencil8"?c=n.DEPTH_STENCIL_ATTACHMENT:h==="stencil8"?c=n.STENCIL_ATTACHMENT:c=n.DEPTH_ATTACHMENT,a.target===n.TEXTURE_2D?n.framebufferTexture2D(n.FRAMEBUFFER,c,n.TEXTURE_2D,l,t):a.target===n.TEXTURE_2D_ARRAY||a.target===n.TEXTURE_3D?n.framebufferTextureLayer(n.FRAMEBUFFER,c,l,t,s):a.target===n.TEXTURE_CUBE_MAP&&n.framebufferTexture2D(n.FRAMEBUFFER,c,n.TEXTURE_CUBE_MAP_POSITIVE_X+s,l,t)}_initStencil(e){if(e.framebuffer===null)return;const t=this._renderer.gl,s=t.createRenderbuffer();e.depthStencilRenderBuffer=s,t.bindRenderbuffer(t.RENDERBUFFER,s),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,s),this._resizeStencil(e)}_resizeStencil(e){const t=this._renderer.gl;t.bindRenderbuffer(t.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?t.renderbufferStorageMultisample(t.RENDERBUFFER,4,t.DEPTH24_STENCIL8,e.width,e.height):t.renderbufferStorage(t.RENDERBUFFER,this._renderer.context.webGLVersion===2?t.DEPTH24_STENCIL8:t.DEPTH_STENCIL,e.width,e.height)}prerender(e){if(e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture.resource;this._renderer.context.multiView&&Ve.test(t)&&this._renderer.context.ensureCanvasSize(t)}postrender(e){if(!this._renderer.context.multiView||e.colorAttachments.length===0)return;const t=e.colorAttachments[0].texture;if(Ve.test(t.resource)){const s=this._renderer.context.canvas,r=t;r.context2D.drawImage(s,0,r.pixelHeight-s.height)}}_setDrawBuffers(e,t){const s=e.colorAttachments.length,r=this._drawBuffersCache[s];if(this._renderer.context.webGLVersion===1){const n=this._renderer.context.extensions.drawBuffers;n?n.drawBuffersWEBGL(r):H("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else t.drawBuffers(r)}resetState(){this._boundFramebuffer=void 0,this._viewPortCache=new te,this._clearColorCache=[0,0,0,0]}bindFramebuffer(e){this._boundFramebuffer!==e&&(this._boundFramebuffer=e,this._renderer.gl.bindFramebuffer(this._renderer.gl.FRAMEBUFFER,e))}}class Ll extends qr{constructor(e){super(e),this.adaptor=new bm,this.adaptor.init(e,this)}resetState(){this.adaptor.resetState()}}Ll.extension={type:[S.WebGLSystem],name:"renderTarget"};class Mi extends Re{constructor({buffer:e,offset:t,size:s}){super(),this.uid=oe("buffer"),this._resourceType="bufferResource",this._resourceId=oe("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=e,this.offset=t|0,this.size=s,this.buffer.on("change",this.onBufferChange,this)}get _gcLastUsed(){return this.buffer?._gcLastUsed??-1}set _gcLastUsed(e){this.buffer&&(this.buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=oe("resource"),this.emit("change",this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}class Ul extends Re{constructor(e,t){super(),this._resourceType="textureView",this._resourceId=oe("resource"),this.source=e,this.viewDescriptor=t,this._onChange=this._onChange.bind(this),this._onDestroy=this._onDestroy.bind(this),this.source.on("change",this._onChange),this.source.on("destroy",this._onDestroy)}_onChange(){this.emit("change",this)}_onDestroy(){this.destroy()}get destroyed(){return this.source.destroyed}destroy(){this.source&&(this.source.off("change",this._onChange),this.source.off("destroy",this._onDestroy)),this.emit("destroy",this),this.removeAllListeners()}}function vm(i,e){const t=[],s=[`
759
759
  var g = s.groups;
760
760
  var sS = r.shader;
761
761
  var p = s.glProgram;
@@ -763,7 +763,7 @@ fn mainFragment(
763
763
  var resources;
764
764
  `];let r=!1,n=0;const o=e._getProgramData(i.glProgram);for(const l in i.groups){const h=i.groups[l];t.push(`
765
765
  resources = g[${l}].resources;
766
- `);for(const c in h.resources){const u=h.resources[c];if(u instanceof rt)if(u.ubo){const d=i._uniformBindMap[l][Number(c)];t.push(`
766
+ `);for(const c in h.resources){const u=h.resources[c];if(u instanceof Ze)if(u.ubo){const d=i._uniformBindMap[l][Number(c)];t.push(`
767
767
  sS.bindUniformBlock(
768
768
  resources[${c}],
769
769
  '${d}',
@@ -771,21 +771,21 @@ fn mainFragment(
771
771
  );
772
772
  `)}else t.push(`
773
773
  ugS.updateUniformGroup(resources[${c}], p, sD);
774
- `);else if(u instanceof Xr){const d=i._uniformBindMap[l][Number(c)];t.push(`
774
+ `);else if(u instanceof Mi){const d=i._uniformBindMap[l][Number(c)];t.push(`
775
775
  sS.bindUniformBlock(
776
776
  resources[${c}],
777
777
  '${d}',
778
778
  ${i.glProgram._uniformBlockData[d].index}
779
779
  );
780
- `)}else if(u instanceof de||u instanceof _m){const d=i._uniformBindMap[l][c],f=o.uniformData[d];f&&(r||(r=!0,s.push(`
780
+ `)}else if(u instanceof ue||u instanceof Ul){const d=i._uniformBindMap[l][c],f=o.uniformData[d];f&&(r||(r=!0,s.push(`
781
781
  var tS = r.texture;
782
782
  `)),e._gl.uniform1i(f.location,n),t.push(`
783
783
  tS.bind(resources[${c}], ${n});
784
784
  `),n++)}}}const a=[...s,...t].join(`
785
- `);return new Function("r","s","sD",a)}class xm{constructor(e,t){this.program=e,this.uniformData=t,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function Co(i,e,t){const s=i.createShader(e);return i.shaderSource(s,t),i.compileShader(s),s}function Pn(i){const e=new Array(i);for(let t=0;t<e.length;t++)e[t]=!1;return e}function Dl(i,e){switch(i){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":case"sampler3D":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return Pn(2*e);case"bvec3":return Pn(3*e);case"bvec4":return Pn(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let zi=null;const Oc={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_2D_SHADOW:"sampler2DShadow",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_CUBE_SHADOW:"samplerCubeShadow",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray",SAMPLER_2D_ARRAY_SHADOW:"sampler2DArrayShadow",SAMPLER_3D:"sampler3D",INT_SAMPLER_3D:"sampler3D",UNSIGNED_INT_SAMPLER_3D:"sampler3D"},Vy={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function Fl(i,e){if(!zi){const t=Object.keys(Oc);zi={};for(let s=0;s<t.length;++s){const r=t[s];zi[i[r]]=Oc[r]}}return zi[e]}function bm(i,e){const t=Fl(i,e);return Vy[t]||"float32"}function vm(i,e,t=!1){const s={},r=e.getProgramParameter(i,e.ACTIVE_ATTRIBUTES);for(let o=0;o<r;o++){const a=e.getActiveAttrib(i,o);if(a.name.startsWith("gl_"))continue;const l=bm(e,a.type);s[a.name]={location:0,format:l,stride:ks(l).stride,offset:0,instance:!1,start:0}}const n=Object.keys(s);if(t){n.sort((o,a)=>o>a?1:-1);for(let o=0;o<n.length;o++)s[n[o]].location=o,e.bindAttribLocation(i,o,n[o]);e.linkProgram(i)}else for(let o=0;o<n.length;o++)s[n[o]].location=e.getAttribLocation(i,n[o]);return s}function wm(i,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const t={},s=e.getProgramParameter(i,e.ACTIVE_UNIFORM_BLOCKS);for(let r=0;r<s;r++){const n=e.getActiveUniformBlockName(i,r),o=e.getUniformBlockIndex(i,n),a=e.getActiveUniformBlockParameter(i,r,e.UNIFORM_BLOCK_DATA_SIZE);t[n]={name:n,index:o,size:a}}return t}function Tm(i,e){const t={},s=e.getProgramParameter(i,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){const n=e.getActiveUniform(i,r),o=n.name.replace(/\[.*?\]$/,""),a=!!n.name.match(/\[.*?\]$/),l=Fl(e,n.type);t[o]={name:o,index:r,type:l,size:n.size,isArray:a,value:Dl(l,n.size)}}return t}function Lc(i,e){const t=i.getShaderSource(e);if(t===null){console.error("PixiJS Error: Could not retrieve shader source (WebGL context may be lost).");return}const s=t.split(`
785
+ `);return new Function("r","s","sD",a)}class wm{constructor(e,t){this.program=e,this.uniformData=t,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function Ro(i,e,t){const s=i.createShader(e);return i.shaderSource(s,t),i.compileShader(s),s}function Fn(i){const e=new Array(i);for(let t=0;t<e.length;t++)e[t]=!1;return e}function Nl(i,e){switch(i){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":case"sampler3D":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return Fn(2*e);case"bvec3":return Fn(3*e);case"bvec4":return Fn(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let Vi=null;const Uc={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_2D_SHADOW:"sampler2DShadow",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_CUBE_SHADOW:"samplerCubeShadow",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray",SAMPLER_2D_ARRAY_SHADOW:"sampler2DArrayShadow",SAMPLER_3D:"sampler3D",INT_SAMPLER_3D:"sampler3D",UNSIGNED_INT_SAMPLER_3D:"sampler3D"},Zy={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function zl(i,e){if(!Vi){const t=Object.keys(Uc);Vi={};for(let s=0;s<t.length;++s){const r=t[s];Vi[i[r]]=Uc[r]}}return Vi[e]}function Tm(i,e){const t=zl(i,e);return Zy[t]||"float32"}function Sm(i,e,t=!1){const s={},r=e.getProgramParameter(i,e.ACTIVE_ATTRIBUTES);for(let o=0;o<r;o++){const a=e.getActiveAttrib(i,o);if(a.name.startsWith("gl_"))continue;const l=Tm(e,a.type);s[a.name]={location:0,format:l,stride:mt(l).stride,offset:0,instance:!1,start:0}}const n=Object.keys(s);if(t){n.sort((o,a)=>o>a?1:-1);for(let o=0;o<n.length;o++)s[n[o]].location=o,e.bindAttribLocation(i,o,n[o]);e.linkProgram(i)}else for(let o=0;o<n.length;o++)s[n[o]].location=e.getAttribLocation(i,n[o]);return s}function Cm(i,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const t={},s=e.getProgramParameter(i,e.ACTIVE_UNIFORM_BLOCKS);for(let r=0;r<s;r++){const n=e.getActiveUniformBlockName(i,r),o=e.getUniformBlockIndex(i,n),a=e.getActiveUniformBlockParameter(i,r,e.UNIFORM_BLOCK_DATA_SIZE);t[n]={name:n,index:o,size:a}}return t}function Mm(i,e){const t={},s=e.getProgramParameter(i,e.ACTIVE_UNIFORMS);for(let r=0;r<s;r++){const n=e.getActiveUniform(i,r),o=n.name.replace(/\[.*?\]$/,""),a=!!n.name.match(/\[.*?\]$/),l=zl(e,n.type);t[o]={name:o,index:r,type:l,size:n.size,isArray:a,value:Nl(l,n.size)}}return t}function Nc(i,e){const t=i.getShaderSource(e);if(t===null){console.error("PixiJS Error: Could not retrieve shader source (WebGL context may be lost).");return}const s=t.split(`
786
786
  `).map((c,u)=>`${u}: ${c}`),r=i.getShaderInfoLog(e)??"",n=r.split(`
787
787
  `),o={},a=n.map(c=>parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(c=>c&&!o[c]?(o[c]=!0,!0):!1),l=[""];a.forEach(c=>{s[c-1]=`%c${s[c-1]}%c`,l.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const h=s.join(`
788
- `);l[0]=h,console.error(r),console.groupCollapsed("click to view full shader code"),console.warn(...l),console.groupEnd()}function Sm(i,e,t,s){i.getProgramParameter(e,i.LINK_STATUS)||(i.getShaderParameter(t,i.COMPILE_STATUS)||Lc(i,t),i.getShaderParameter(s,i.COMPILE_STATUS)||Lc(i,s),console.error("PixiJS Error: Could not initialize shader."),i.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",i.getProgramInfoLog(e)))}function Cm(i,e){const t=Co(i,i.VERTEX_SHADER,e.vertex),s=Co(i,i.FRAGMENT_SHADER,e.fragment),r=i.createProgram();i.attachShader(r,t),i.attachShader(r,s);const n=e.transformFeedbackVaryings;n&&(typeof i.transformFeedbackVaryings!="function"?z("TransformFeedback is not supported but TransformFeedbackVaryings are given."):i.transformFeedbackVaryings(r,n.names,n.bufferMode==="separate"?i.SEPARATE_ATTRIBS:i.INTERLEAVED_ATTRIBS)),i.linkProgram(r),i.getProgramParameter(r,i.LINK_STATUS)||Sm(i,r,t,s),e._attributeData=vm(r,i,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=Tm(r,i),e._uniformBlockData=wm(r,i),i.deleteShader(t),i.deleteShader(s);const o={};for(const l in e._uniformData){const h=e._uniformData[l];o[l]={location:i.getUniformLocation(r,l),value:Dl(h.type,h.size)}}return new xm(r,o)}const Wi={textureCount:0,blockIndex:0};class Ol{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,t){if(this._setProgram(e.glProgram),t)return;Wi.textureCount=0,Wi.blockIndex=0;let s=this._shaderSyncFunctions[e.glProgram._key];s||(s=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),s(this._renderer,e,Wi)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,Wi)}bindUniformBlock(e,t,s=0){const r=this._renderer.buffer,n=this._getProgramData(this._activeProgram),o=e._bufferResource;o||this._renderer.ubo.updateUniformGroup(e);const a=e.buffer,l=r.updateBuffer(a),h=r.freeLocationForBufferBase(l);if(o){const{offset:u,size:d}=e;u===0&&d===a.data.byteLength?r.bindBufferBase(l,h):r.bindBufferRange(l,h,u)}else r.getLastBindBaseLocation(l)!==h&&r.bindBufferBase(l,h);const c=this._activeProgram._uniformBlockData[t].index;n.uniformBlockBindings[s]!==h&&(n.uniformBlockBindings[s]=h,this._renderer.gl.uniformBlockBinding(n.program,c,h))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const t=this._getProgramData(e);this._gl.useProgram(t.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const t=e._key;return this._programDataHash[t]=Cm(this._gl,e),this._programDataHash[t]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,t){return ym(e,t)}resetState(){this._activeProgram=null}}Ol.extension={type:[S.WebGLSystem],name:"shader"};const Mm={f32:`if (cv !== v) {
788
+ `);l[0]=h,console.error(r),console.groupCollapsed("click to view full shader code"),console.warn(...l),console.groupEnd()}function km(i,e,t,s){i.getProgramParameter(e,i.LINK_STATUS)||(i.getShaderParameter(t,i.COMPILE_STATUS)||Nc(i,t),i.getShaderParameter(s,i.COMPILE_STATUS)||Nc(i,s),console.error("PixiJS Error: Could not initialize shader."),i.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",i.getProgramInfoLog(e)))}function Em(i,e){const t=Ro(i,i.VERTEX_SHADER,e.vertex),s=Ro(i,i.FRAGMENT_SHADER,e.fragment),r=i.createProgram();i.attachShader(r,t),i.attachShader(r,s);const n=e.transformFeedbackVaryings;n&&(typeof i.transformFeedbackVaryings!="function"?H("TransformFeedback is not supported but TransformFeedbackVaryings are given."):i.transformFeedbackVaryings(r,n.names,n.bufferMode==="separate"?i.SEPARATE_ATTRIBS:i.INTERLEAVED_ATTRIBS)),i.linkProgram(r),i.getProgramParameter(r,i.LINK_STATUS)||km(i,r,t,s),e._attributeData=Sm(r,i,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=Mm(r,i),e._uniformBlockData=Cm(r,i),i.deleteShader(t),i.deleteShader(s);const o={};for(const l in e._uniformData){const h=e._uniformData[l];o[l]={location:i.getUniformLocation(r,l),value:Nl(h.type,h.size)}}return new wm(r,o)}const ji={textureCount:0,blockIndex:0};class Qr{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,t){if(this._setProgram(e.glProgram),t)return;ji.textureCount=0,ji.blockIndex=0;let s=this._shaderSyncFunctions[e.glProgram._key];s||(s=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),s(this._renderer,e,ji)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,ji)}bindUniformBlock(e,t,s=0){const r=this._renderer.buffer,n=this._getProgramData(this._activeProgram),o=e._bufferResource;o||this._renderer.ubo.updateUniformGroup(e);const a=e.buffer,l=r.updateBuffer(a),h=r.freeLocationForBufferBase(l);if(o){const{offset:u,size:d}=e;u===0&&d===a.data.byteLength?r.bindBufferBase(l,h):r.bindBufferRange(l,h,u)}else r.getLastBindBaseLocation(l)!==h&&r.bindBufferBase(l,h);const c=this._activeProgram._uniformBlockData[t].index;n.uniformBlockBindings[s]!==h&&(n.uniformBlockBindings[s]=h,this._renderer.gl.uniformBlockBinding(n.program,c,h))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const t=this._getProgramData(e);this._gl.useProgram(t.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const t=e._key;return this._programDataHash[t]=Em(this._gl,e),this._programDataHash[t]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,t){return vm(e,t)}resetState(){this._activeProgram=null}}Qr.extension={type:[S.WebGLSystem],name:"shader"};const Pm={f32:`if (cv !== v) {
789
789
  cu.value = v;
790
790
  gl.uniform1f(location, v);
791
791
  }`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
@@ -857,26 +857,26 @@ fn mainFragment(
857
857
  cv[2] = v[2];
858
858
  cv[3] = v[3];
859
859
  gl.uniform4i(location, v[0], v[1], v[2], v[3]);
860
- }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},km={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function Em(i,e){const t=[`
860
+ }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},Am={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function Rm(i,e){const t=[`
861
861
  var v = null;
862
862
  var cv = null;
863
863
  var cu = null;
864
864
  var t = 0;
865
865
  var gl = renderer.gl;
866
866
  var name = null;
867
- `];for(const s in i.uniforms){if(!e[s]){i.uniforms[s]instanceof rt?i.uniforms[s].ubo?t.push(`
867
+ `];for(const s in i.uniforms){if(!e[s]){i.uniforms[s]instanceof Ze?i.uniforms[s].ubo?t.push(`
868
868
  renderer.shader.bindUniformBlock(uv.${s}, "${s}");
869
869
  `):t.push(`
870
870
  renderer.shader.updateUniformGroup(uv.${s});
871
- `):i.uniforms[s]instanceof Xr&&t.push(`
871
+ `):i.uniforms[s]instanceof Mi&&t.push(`
872
872
  renderer.shader.bindBufferResource(uv.${s}, "${s}");
873
- `);continue}const r=i.uniformStructures[s];let n=!1;for(let o=0;o<Qt.length;o++){const a=Qt[o];if(r.type===a.type&&a.test(r)){t.push(`name = "${s}";`,Qt[o].uniform),n=!0;break}}if(!n){const a=(r.size===1?Mm:km)[r.type].replace("location",`ud["${s}"].location`);t.push(`
873
+ `);continue}const r=i.uniformStructures[s];let n=!1;for(let o=0;o<nt.length;o++){const a=nt[o];if(r.type===a.type&&a.test(r)){t.push(`name = "${s}";`,nt[o].uniform),n=!0;break}}if(!n){const a=(r.size===1?Pm:Am)[r.type].replace("location",`ud["${s}"].location`);t.push(`
874
874
  cu = ud["${s}"];
875
875
  cv = cu.value;
876
876
  v = uv["${s}"];
877
877
  ${a};`)}}return new Function("ud","uv","renderer","syncData",t.join(`
878
- `))}class Ll{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,t,s){const r=this._renderer.shader._getProgramData(t);(!e.isStatic||e._dirtyId!==r.uniformDirtyGroups[e.uid])&&(r.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,t)(r.uniformData,e.uniforms,this._renderer,s))}_getUniformSyncFunction(e,t){return this._uniformGroupSyncHash[e._signature]?.[t._key]||this._createUniformSyncFunction(e,t)}_createUniformSyncFunction(e,t){const s=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),r=this._getSignature(e,t._uniformData,"u");return this._cache[r]||(this._cache[r]=this._generateUniformsSync(e,t._uniformData)),s[t._key]=this._cache[r],s[t._key]}_generateUniformsSync(e,t){return Em(e,t)}_getSignature(e,t,s){const r=e.uniforms,n=[`${s}-`];for(const o in r)n.push(o),t[o]&&n.push(t[o].type);return n.join("-")}destroy(){this._renderer=null,this._cache=null}}Ll.extension={type:[S.WebGLSystem],name:"uniformGroup"};function Pm(i){const e={};if(e.normal=[i.ONE,i.ONE_MINUS_SRC_ALPHA],e.add=[i.ONE,i.ONE],e.multiply=[i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.screen=[i.ONE,i.ONE_MINUS_SRC_COLOR,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[i.SRC_ALPHA,i.ONE,i.ONE,i.ONE],e["screen-npm"]=[i.SRC_ALPHA,i.ONE_MINUS_SRC_COLOR,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.erase=[i.ZERO,i.ONE_MINUS_SRC_ALPHA],!(i instanceof ee.get().getWebGLRenderingContext()))e.min=[i.ONE,i.ONE,i.ONE,i.ONE,i.MIN,i.MIN],e.max=[i.ONE,i.ONE,i.ONE,i.ONE,i.MAX,i.MAX];else{const s=i.getExtension("EXT_blend_minmax");s&&(e.min=[i.ONE,i.ONE,i.ONE,i.ONE,s.MIN_EXT,s.MIN_EXT],e.max=[i.ONE,i.ONE,i.ONE,i.ONE,s.MAX_EXT,s.MAX_EXT])}return e}const{BLEND:jy,OFFSET:Xy,CULLING:qy,DEPTH_TEST:Yy,WINDING:Ky,DEPTH_MASK:Uc}=ta,Am=class Mo{constructor(e){this._invertFrontFace=!1,this._renderer=e,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[jy]=this.setBlend,this.map[Xy]=this.setOffset,this.map[qy]=this.setCullFace,this.map[Yy]=this.setDepthTest,this.map[Ky]=this.setFrontFace,this.map[Uc]=this.setDepthMask,this.checks=[],this.defaultState=pt.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(e,e.flipY),this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=Pm(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let t=this.stateId^e.data,s=0;for(;t;)t&1&&this.map[s].call(this,!!(e.data&1<<s)),t>>=1,s++;this.stateId=e.data}for(let t=0;t<this.checks.length;t++)this.checks[t](this,e)}forceState(e){e||(e=this.defaultState);for(let t=0;t<this.map.length;t++)this.map[t].call(this,!!(e.data&1<<t));for(let t=0;t<this.checks.length;t++)this.checks[t](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(Mo._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(Mo._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}get depthMaskEnabled(){return!!(this.stateId&1<<Uc)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const t=this._invertFrontFace?!e:e;this._glFrontFace!==t&&(this._glFrontFace=t,this.gl.frontFace(this.gl[t?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const t=this.blendModesMap[e],s=this.gl;t.length===2?s.blendFunc(t[0],t[1]):s.blendFuncSeparate(t[0],t[1],t[2],t[3]),t.length===6?(this._blendEq=!0,s.blendEquationSeparate(t[4],t[5])):this._blendEq&&(this._blendEq=!1,s.blendEquationSeparate(s.FUNC_ADD,s.FUNC_ADD))}setPolygonOffset(e,t){this.gl.polygonOffset(e,t)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,t){const s=this.checks.indexOf(e);t&&s===-1?this.checks.push(e):!t&&s!==-1&&this.checks.splice(s,1)}static _checkBlendMode(e,t){e.setBlendMode(t.blendMode)}static _checkPolygonOffset(e,t){e.setPolygonOffset(1,t.polygonOffset)}destroy(){this.gl=null,this.checks.length=0,this._renderer=null}};Am.extension={type:[S.WebGLSystem],name:"state"};let Rm=Am;class Bm{constructor(e){this.target=Rs.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=ie.UNSIGNED_BYTE,this.internalFormat=pr.RGBA,this.format=pr.RGBA,this.samplerType=0}destroy(){}}function Ul(i,e,t,s,r){if(i=Math.max(0,i),e=Math.min(e,t*s),i>=e)return 0;const n=Math.floor(i/t),o=i-n*t,a=Math.floor(e/t),l=e-a*t;if(n===a)return r[0].set(o,n,l-o,1),1;let h=0,c=n;return o>0&&(r[h++].set(o,n,t-o,1),c++),a>c&&r[h++].set(0,c,t,a-c),l>0&&r[h++].set(0,a,l,1),h}const Nc=[new te,new te,new te],Im={id:"buffer",upload(i,e,t,s,r,n=!1){const o=r||e.target,a=i.resource;if(o===Rs.TEXTURE_3D||o===Rs.TEXTURE_2D_ARRAY){n||e.width!==i.width||e.height!==i.height?t.texImage3D(o,0,e.internalFormat,i.width,i.height,i.depthOrArrayLayers,0,e.format,e.type,a):t.texSubImage3D(o,0,0,0,0,i.width,i.height,i.depthOrArrayLayers,e.format,e.type,a),e.width=i.width,e.height=i.height;return}const l=i.width*i.height,h=n||e.width!==i.width||e.height!==i.height,c=i._updateStart>0||i._updateEnd<l;if(h)t.texImage2D(o,0,e.internalFormat,i.width,i.height,0,e.format,e.type,a);else if(c){const u=a.length/l,d=Ul(i._updateStart,i._updateEnd,i.width,i.height,Nc);for(let f=0;f<d;f++){const p=Nc[f],g=(p.y*i.width+p.x)*u;t.texSubImage2D(o,0,p.x,p.y,p.width,p.height,e.format,e.type,a.subarray(g,g+p.width*p.height*u))}}else t.texSubImage2D(o,0,0,0,i.width,i.height,e.format,e.type,a);e.width=i.width,e.height=i.height}},Zy={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},Gm={id:"compressed",upload(i,e,t,s,r,n){const o=r??e.target;t.pixelStorei(t.UNPACK_ALIGNMENT,4);let a=i.pixelWidth,l=i.pixelHeight;const h=!!Zy[i.format];for(let c=0;c<i.resource.length;c++){const u=i.resource[c];h?t.compressedTexImage2D(o,c,e.internalFormat,a,l,0,u):t.texImage2D(o,c,e.internalFormat,a,l,0,e.format,e.type,u),a=Math.max(a>>1,1),l=Math.max(l>>1,1)}}},Hc=["right","left","top","bottom","front","back"];function Dm(i){return{id:"cube",upload(e,t,s,r){const n=e.faces;for(let o=0;o<Hc.length;o++){const a=Hc[o],l=n[a];if(!l.resource)continue;(i[l.uploadMethodId]||i.image).upload(l,t,s,r,Rs.TEXTURE_CUBE_MAP_POSITIVE_X+o,(t._layerInitMask&1<<o)===0),t._layerInitMask|=1<<o}t.width=e.pixelWidth,t.height=e.pixelHeight}}}const Nl={id:"image",upload(i,e,t,s,r,n=!1){const o=r||e.target,a=i.pixelWidth,l=i.pixelHeight,h=i.resourceWidth,c=i.resourceHeight,u=s===2,d=n||e.width!==a||e.height!==l,f=h>=a&&c>=l,p=i.resource;(u?Qy:Jy)(t,o,e,a,l,h,c,p,d,f),e.width=a,e.height=l}};function Qy(i,e,t,s,r,n,o,a,l,h){if(!h){l&&i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,null),i.texSubImage2D(e,0,0,0,n,o,t.format,t.type,a);return}if(!l){i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,a)}function Jy(i,e,t,s,r,n,o,a,l,h){if(!h){l&&i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,null),i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}if(!l){i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}i.texImage2D(e,0,t.internalFormat,t.format,t.type,a)}const ex=Cp(),Fm={id:"video",upload(i,e,t,s,r,n=ex){if(!i.isValid){const o=r??e.target;t.texImage2D(o,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Nl.upload(i,e,t,s,r,n)}},ko={linear:9729,nearest:9728},Om={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},Qi={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Lm={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Eo(i,e,t,s,r,n,o,a){const l=n;if(!a||i.addressModeU!=="repeat"||i.addressModeV!=="repeat"||i.addressModeW!=="repeat"){const h=Qi[o?"clamp-to-edge":i.addressModeU],c=Qi[o?"clamp-to-edge":i.addressModeV],u=Qi[o?"clamp-to-edge":i.addressModeW];e[r](l,e.TEXTURE_WRAP_S,h),e[r](l,e.TEXTURE_WRAP_T,c),e.TEXTURE_WRAP_R&&e[r](l,e.TEXTURE_WRAP_R,u)}if((!a||i.magFilter!=="linear")&&e[r](l,e.TEXTURE_MAG_FILTER,ko[i.magFilter]),t){if(!a||i.mipmapFilter!=="linear"){const h=Om[i.minFilter][i.mipmapFilter];e[r](l,e.TEXTURE_MIN_FILTER,h)}}else e[r](l,e.TEXTURE_MIN_FILTER,ko[i.minFilter]);if(s&&i.maxAnisotropy>1){const h=Math.min(i.maxAnisotropy,e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[r](l,s.TEXTURE_MAX_ANISOTROPY_EXT,h)}i.compare?(e[r](l,e.TEXTURE_COMPARE_FUNC,Lm[i.compare]),e[r](l,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE)):a||e[r](l,e.TEXTURE_COMPARE_MODE,e.NONE)}function Um(i){return{r8unorm:i.RED,r8snorm:i.RED,r8uint:i.RED_INTEGER,r8sint:i.RED_INTEGER,r16uint:i.RED_INTEGER,r16sint:i.RED_INTEGER,r16float:i.RED,rg8unorm:i.RG,rg8snorm:i.RG,rg8uint:i.RG_INTEGER,rg8sint:i.RG_INTEGER,r32uint:i.RED_INTEGER,r32sint:i.RED_INTEGER,r32float:i.RED,rg16uint:i.RG_INTEGER,rg16sint:i.RG_INTEGER,rg16float:i.RG,rgba8unorm:i.RGBA,"rgba8unorm-srgb":i.RGBA,rgba8snorm:i.RGBA,rgba8uint:i.RGBA_INTEGER,rgba8sint:i.RGBA_INTEGER,bgra8unorm:i.RGBA,"bgra8unorm-srgb":i.RGBA,rgb9e5ufloat:i.RGB,rgb10a2unorm:i.RGBA,rg11b10ufloat:i.RGB,rg32uint:i.RG_INTEGER,rg32sint:i.RG_INTEGER,rg32float:i.RG,rgba16uint:i.RGBA_INTEGER,rgba16sint:i.RGBA_INTEGER,rgba16float:i.RGBA,rgba32uint:i.RGBA_INTEGER,rgba32sint:i.RGBA_INTEGER,rgba32float:i.RGBA,stencil8:i.STENCIL_INDEX8,depth16unorm:i.DEPTH_COMPONENT,depth24plus:i.DEPTH_COMPONENT,"depth24plus-stencil8":i.DEPTH_STENCIL,depth32float:i.DEPTH_COMPONENT,"depth32float-stencil8":i.DEPTH_STENCIL}}function Nm(i,e){let t={},s=i.RGBA;return i instanceof ee.get().getWebGLRenderingContext()?e.srgb&&(t={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(t={"rgba8unorm-srgb":i.SRGB8_ALPHA8,"bgra8unorm-srgb":i.SRGB8_ALPHA8},s=i.RGBA8),{r8unorm:i.R8,r8snorm:i.R8_SNORM,r8uint:i.R8UI,r8sint:i.R8I,r16uint:i.R16UI,r16sint:i.R16I,r16float:i.R16F,rg8unorm:i.RG8,rg8snorm:i.RG8_SNORM,rg8uint:i.RG8UI,rg8sint:i.RG8I,r32uint:i.R32UI,r32sint:i.R32I,r32float:i.R32F,rg16uint:i.RG16UI,rg16sint:i.RG16I,rg16float:i.RG16F,rgba8unorm:i.RGBA,...t,rgba8snorm:i.RGBA8_SNORM,rgba8uint:i.RGBA8UI,rgba8sint:i.RGBA8I,bgra8unorm:s,rgb9e5ufloat:i.RGB9_E5,rgb10a2unorm:i.RGB10_A2,rg11b10ufloat:i.R11F_G11F_B10F,rg32uint:i.RG32UI,rg32sint:i.RG32I,rg32float:i.RG32F,rgba16uint:i.RGBA16UI,rgba16sint:i.RGBA16I,rgba16float:i.RGBA16F,rgba32uint:i.RGBA32UI,rgba32sint:i.RGBA32I,rgba32float:i.RGBA32F,stencil8:i.STENCIL_INDEX8,depth16unorm:i.DEPTH_COMPONENT16,depth24plus:i.DEPTH_COMPONENT24,"depth24plus-stencil8":i.DEPTH24_STENCIL8,depth32float:i.DEPTH_COMPONENT32F,"depth32float-stencil8":i.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function Hm(i){return{r8unorm:i.UNSIGNED_BYTE,r8snorm:i.BYTE,r8uint:i.UNSIGNED_BYTE,r8sint:i.BYTE,r16uint:i.UNSIGNED_SHORT,r16sint:i.SHORT,r16float:i.HALF_FLOAT,rg8unorm:i.UNSIGNED_BYTE,rg8snorm:i.BYTE,rg8uint:i.UNSIGNED_BYTE,rg8sint:i.BYTE,r32uint:i.UNSIGNED_INT,r32sint:i.INT,r32float:i.FLOAT,rg16uint:i.UNSIGNED_SHORT,rg16sint:i.SHORT,rg16float:i.HALF_FLOAT,rgba8unorm:i.UNSIGNED_BYTE,"rgba8unorm-srgb":i.UNSIGNED_BYTE,rgba8snorm:i.BYTE,rgba8uint:i.UNSIGNED_BYTE,rgba8sint:i.BYTE,bgra8unorm:i.UNSIGNED_BYTE,"bgra8unorm-srgb":i.UNSIGNED_BYTE,rgb9e5ufloat:i.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:i.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:i.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:i.UNSIGNED_INT,rg32sint:i.INT,rg32float:i.FLOAT,rgba16uint:i.UNSIGNED_SHORT,rgba16sint:i.SHORT,rgba16float:i.HALF_FLOAT,rgba32uint:i.UNSIGNED_INT,rgba32sint:i.INT,rgba32float:i.FLOAT,stencil8:i.UNSIGNED_BYTE,depth16unorm:i.UNSIGNED_SHORT,depth24plus:i.UNSIGNED_INT,"depth24plus-stencil8":i.UNSIGNED_INT_24_8,depth32float:i.FLOAT,"depth32float-stencil8":i.FLOAT_32_UNSIGNED_INT_24_8_REV}}function zm(i){return{"2d":i.TEXTURE_2D,cube:i.TEXTURE_CUBE_MAP,"1d":null,"3d":i?.TEXTURE_3D||null,"2d-array":i?.TEXTURE_2D_ARRAY||null,"cube-array":i?.TEXTURE_CUBE_MAP_ARRAY||null}}const tx=4,Hl=class Wm{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._integerUnits=0,this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new nt({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const t={image:Nl,buffer:Im,video:Fm,compressed:Gm,...Wm.uploadExtensions};this._uploads={...t,cube:Dm(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Nm(e,this._renderer.context.extensions),this._mapFormatToType=Hm(e),this._mapFormatToFormat=Um(e),this._mapViewDimensionToGlTarget=zm(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let t=0;t<16;t++)this.bind(W.EMPTY,t)}initSource(e){this.bind(e)}bind(e,t=0){const s=e.source;e?(this.bindSource(s,t),this._useSeparateSamplers&&this._bindSampler(s.style,t)):(this.bindSource(null,t),this._useSeparateSamplers&&this._bindSampler(null,t))}bindSource(e,t=0){const s=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[t]!==e){this._setBoundTexture(t,e),this._activateLocation(t),e||(e=W.EMPTY.source);const r=this.getGlSource(e);s.bindTexture(r.target,r.texture)}}unbindIntegerTextures(e){if(e>=32)return;let t=this._integerUnits>>>e<<e;for(;t;){const s=31-Math.clz32(t);t&=~(1<<s),this.bind(W.EMPTY,s)}}_setBoundTexture(e,t){this._boundTextures[e]=t,!(e<0||e>31)&&(!t||t.viewDimension!=="2d"||(ir(t.format)?this._integerUnits|=1<<e:this._integerUnits&=~(1<<e)))}_bindSampler(e,t=0){const s=this._gl;if(!e){this._boundSamplers[t]=null,s.bindSampler(t,null);return}const r=this._getGlSampler(e);this._boundSamplers[t]!==r&&(this._boundSamplers[t]=r,s.bindSampler(t,r))}unbind(e){const t=e.source,s=this._boundTextures,r=this._gl;for(let n=0;n<s.length;n++)if(s[n]===t){this._activateLocation(n);const o=this.getGlSource(t);r.bindTexture(o.target,null),this._setBoundTexture(n,null)}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const t=this._gl,s=new Bm(t.createTexture());if(s.type=this._mapFormatToType[e.format],s.internalFormat=this._mapFormatToInternalFormat[e.format],s.format=this._mapFormatToFormat[e.format],s.target=this._mapViewDimensionToGlTarget[e.viewDimension],s.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const n=Math.max(e.width,e.height,e.depth);e.mipLevelCount=Math.floor(Math.log2(n))+1}return e._gpuData[this._renderer.uid]=s,this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),this.updateStyle(e,!1),s}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,t){const s=this._gl,r=this.getGlSource(e);s.bindTexture(r.target,r.texture),this._setBoundTexture(this._activeTextureLocation,e),Eo(e.style,s,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",r.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,t)}onSourceUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];s&&(t||(this.unbind(e),this._gl.deleteTexture(s.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const t=this._gl,s=this.getGlSource(e);t.bindTexture(s.target,s.texture),this._setBoundTexture(this._activeTextureLocation,e);const r=e.alphaMode==="premultiply-alpha-on-upload"&&!ir(e.format)&&s.target!==t.TEXTURE_3D&&s.target!==t.TEXTURE_2D_ARRAY;if(this._premultiplyAlpha!==r&&(this._premultiplyAlpha=r,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,s,t,this._renderer.context.webGLVersion);else if(s.target===t.TEXTURE_2D)this._initEmptyTexture2D(s,e);else if(s.target===t.TEXTURE_2D_ARRAY||s.target===t.TEXTURE_3D)this._initEmptyTexture3D(s,e);else if(s.target===t.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(s,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(s,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,t=!0){t&&this.bindSource(e,0);const s=this.getGlSource(e);this._gl.generateMipmap(s.target)}_initEmptyTexture2D(e,t){const s=this._gl;s.texImage2D(s.TEXTURE_2D,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let r=Math.max(t.pixelWidth>>1,1),n=Math.max(t.pixelHeight>>1,1);for(let o=1;o<t.mipLevelCount;o++)s.texImage2D(s.TEXTURE_2D,o,e.internalFormat,r,n,0,e.format,e.type,null),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}_initEmptyTexture3D(e,t){const s=this._gl,r=e.target===s.TEXTURE_3D;let n=t.pixelWidth,o=t.pixelHeight,a=t.depthOrArrayLayers;for(let l=0;l<t.mipLevelCount;l++)s.texImage3D(e.target,l,e.internalFormat,n,o,a,0,e.format,e.type,null),n=Math.max(n>>1,1),o=Math.max(o>>1,1),r&&(a=Math.max(a>>1,1))}_initEmptyTextureCube(e,t){const s=this._gl,r=6;for(let a=0;a<r;a++)s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let n=Math.max(t.pixelWidth>>1,1),o=Math.max(t.pixelHeight>>1,1);for(let a=1;a<t.mipLevelCount;a++){for(let l=0;l<r;l++)s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+l,a,e.internalFormat,n,o,0,e.format,e.type,null);n=Math.max(n>>1,1),o=Math.max(o>>1,1)}}_applyMipRange(e,t){if(this._renderer.context.webGLVersion!==2||t.mipLevelCount<=1)return;const s=this._gl,r=Math.max((t.mipLevelCount|0)-1,0);s.texParameteri(e.target,s.TEXTURE_BASE_LEVEL,0),s.texParameteri(e.target,s.TEXTURE_MAX_LEVEL,r)}_initSampler(e){const t=this._gl,s=this._gl.createSampler();return this._glSamplers[e._resourceId]=s,Eo(e,t,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",s,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:t,width:s,height:r}=this.getPixels(e),n=ee.get().createCanvas();n.width=s,n.height=r;const o=n.getContext("2d");if(o){const a=o.createImageData(s,r);a.data.set(t),o.putImageData(a,0,0)}return n}getPixels(e){const t=e.source.resolution,s=e.frame,r=Math.max(Math.round(s.width*t),1),n=Math.max(Math.round(s.height*t),1),o=new Uint8Array(tx*r*n),a=this._renderer,l=a.renderTarget.getRenderTarget(e),h=a.renderTarget.getGpuRenderTarget(l),c=a.gl;return a.renderTarget.adaptor.bindFramebuffer(h.resolveTargetFramebuffer),c.readPixels(Math.round(s.x*t),Math.round(s.y*t),r,n,c.RGBA,c.UNSIGNED_BYTE,o),{pixels:new Uint8ClampedArray(o.buffer),width:r,height:n}}destroy(){this._managedTextures.destroy(),this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){const e=this._renderer.limits.maxTextures;this._activeTextureLocation=-1,this._boundTextures.fill(null),this._integerUnits=e>=32?-1:(1<<e)-1,this._boundSamplers=Object.create(null);const t=this._gl;this._premultiplyAlpha=!1,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}};Hl.extension={type:[S.WebGLSystem],name:"texture"};Hl.uploadExtensions=Object.create(null);let zl=Hl;q.handleByMap(S.TextureUploaderWebGL,zl.uploadExtensions);class Wl{contextChange(e){const t=new rt({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new U,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),s=e.limits.maxBatchableTextures,r=Ar({name:"graphics",bits:[pa,ga(s),Fa,Br]});this.shader=new ft({glProgram:r,resources:{localUniforms:t,batchSamplers:_a(s)}})}execute(e,t){const s=t.context,r=s.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(s);r.groups[0]=n.globalUniforms.bindGroup,n.state.set(e.state),n.shader.bind(r),n.geometry.bind(a.geometry,r.glProgram);const h=l.instructions;for(let c=0;c<l.instructionSize;c++){const u=h[c];if(u.size){for(let d=0;d<u.textures.count;d++)n.texture.bind(u.textures.textures[d],d);n.texture.unbindIntegerTextures(u.textures.count),n.geometry.draw(u.topology,u.size,u.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}Wl.extension={type:[S.WebGLPipesAdaptor],name:"graphics"};class $l{init(){const e=Ar({name:"mesh",bits:[Fa,Pp,Br]});this._shader=new ft({glProgram:e,resources:{uTexture:W.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new U}}}})}execute(e,t){const s=e.renderer;let r=t._shader;if(r){if(!r.glProgram){z("Mesh shader has no glProgram",t.shader);return}}else{r=this._shader;const n=t.texture,o=n.source;r.resources.uTexture=o,r.resources.uSampler=o.style,r.resources.textureUniforms.uniforms.uTextureMatrix=n.textureMatrix.mapCoord}r.groups[100]=s.globalUniforms.bindGroup,r.groups[101]=e.localUniformsBindGroup,s.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}$l.extension={type:[S.WebGLPipesAdaptor],name:"mesh"};const sx=[...Vr,Il,cm,om,kl,vl,zl,Gl,Tl,Ll,Ol,Ml,Rm,El,Cl],ix=[...yl],rx=[Ya,$l,Wl],$m=[],Vm=[],jm=[],Xm=[];q.handleByNamedList(S.WebGLSystem,$m);q.handleByNamedList(S.WebGLPipes,Vm);q.handleByNamedList(S.WebGLPipesAdaptor,jm);q.handleByNamedList(S.WebGLLoader,Xm);q.add(...sx,...ix,...rx);class qm extends Ds{constructor(){const e={name:"webgl",type:Ke.WEBGL,systems:$m,renderPipes:Vm,renderPipeAdaptors:jm,loaders:Xm};super(e)}}const nx=Object.freeze(Object.defineProperty({__proto__:null,WebGLRenderer:qm},Symbol.toStringTag,{value:"Module"}));class ox{constructor(e,t){this.autoGarbageCollect=!0,this._gpuData=null,this.gpuBindGroup=e,this._gcLastUsed=t}unload(){this.gpuBindGroup=null}}class Vl{constructor(e){this._hash=Object.create(null),this._renderer=e,e.gc.addResourceHash(this,"_hash","resource"),e.gc.addCollection(this,"_hash","hash")}contextChange(e){this._gpu=e,this._hash=Object.create(null)}getBindGroup(e,t,s){const r=`${e._key}:${t._layoutKey<<4|s}`,n=this._hash[r];return n?(n._gcLastUsed=this._renderer.gc.now,n.gpuBindGroup):this._createBindGroup(r,e,t,s)}_createBindGroup(e,t,s,r){const n=this._gpu.device,o=s.layout[r],a=[],l=this._renderer;for(const u in o){const d=t.resources[u]??t.resources[o[u]];if(!d||d.destroyed)throw new Error(`[BindGroup] the resource bound as '${u}' was destroyed while a shader still uses it. Remove it from the shader before destroying it.`);let f;if(d._resourceType==="uniformGroup"){const p=d;l.ubo.updateUniformGroup(p);const g=p.buffer;f={buffer:l.buffer.getGPUBuffer(g),offset:0,size:g.descriptor.size}}else if(d._resourceType==="buffer"){const p=d;f={buffer:l.buffer.getGPUBuffer(p),offset:0,size:p.descriptor.size}}else if(d._resourceType==="bufferResource"){const p=d;f={buffer:l.buffer.getGPUBuffer(p.buffer),offset:p.offset,size:p.size??p.buffer.descriptor.size}}else if(d._resourceType==="textureSampler"){const p=d;f=l.texture.getGpuSampler(p)}else if(d._resourceType==="textureSource"){const p=d;f=l.texture.getTextureView(p)}else if(d._resourceType==="textureView"){const p=d;f=l.texture.getTextureView(p.source,p.viewDescriptor)}a.push({binding:o[u],resource:f})}const h=l.shader.getProgramData(s).bindGroups[r],c=n.createBindGroup({layout:h,entries:a});return this._hash[e]=new ox(c,l.gc.now),c}destroy(){this._hash=null,this._renderer=null}}Vl.extension={type:[S.WebGPUSystem],name:"bindGroup"};class Ym{constructor(e){this.gpuBuffer=e}destroy(){this.gpuBuffer.destroy(),this.gpuBuffer=null}}class jl{constructor(e){this._renderer=e,this._managedBuffers=new nt({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"gpuBuffer"})}contextChange(e){this._gpu=e,this.destroyAll()}getGPUBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuBuffer||this.createGPUBuffer(e)}updateBuffer(e){const t=this.getGPUBuffer(e),s=e.data;return e._updateID&&s&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,e._updateOffset,s.buffer,s.byteOffset+e._updateOffset,(e._updateSize||s.byteLength)+3&-4)),t}destroyAll(){this._managedBuffers.removeAll()}onBufferUnload(e){e.off("update",this.updateBuffer,this),e.off("change",this.onBufferChange,this)}createGPUBuffer(e){const t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(lr(e.data.buffer,t.getMappedRange(),e.data.byteOffset,e.data.byteLength),t.unmap()),e._gpuData[this._renderer.uid]=new Ym(t),this._managedBuffers.add(e)&&(e.on("update",this.updateBuffer,this),e.on("change",this.onBufferChange,this)),t}onBufferChange(e){this._managedBuffers.remove(e),e._updateID=0,this.createGPUBuffer(e)}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gpu=null}}jl.extension={type:[S.WebGPUSystem],name:"buffer"};class Km{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw new Error(`UniformBufferBatch: array is too large: ${e*4}`);const t=this.byteIndex;let s=t+e*4;if(s=Math.ceil(s/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,s>this.data.length*4)throw new Error("UniformBufferBatch: ubo batch got too big");return this.byteIndex=s,t}addGroup(e){const t=this.addEmptyGroup(e.length);for(let s=0;s<e.length;s++)this.data[t/4+s]=e[s];return t}destroy(){this.data=null}}class Xl{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}}Xl.extension={type:[S.WebGPUSystem],name:"colorMask"};const ax=new Set(["apple","arm","qualcomm","img-tec"]);class qr{constructor(e){this._renderer=e}async init(e){return this._initPromise?this._initPromise:(this._options=e,this._initPromise=(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(t=>this._setGpu(t)),this._initPromise)}_setGpu(e){this.gpu=e,this.extensions={transientAttachment:typeof GPUTextureUsage.TRANSIENT_ATTACHMENT=="number",tileBased:ax.has(e.adapter?.info?.vendor)},this._options.gpu||e.device.lost.then(()=>this._restoreDevice()).catch(t=>z("WebGPU device was lost and could not be restored",t)),this._renderer.runners.contextChange.emit(this.gpu)}async _restoreDevice(){if(!this._renderer)return;const e=await this._createDeviceAndAdaptor(this._options);if(!this._renderer){e.device.destroy();return}this._setGpu(e)}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){const t=await ee.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter});if(!t)throw new Error("WebGPU not supported. No GPU adapter was returned by navigator.gpu.requestAdapter().");const s=["texture-compression-bc","texture-compression-astc","texture-compression-etc2","indirect-first-instance","bgra8unorm-storage","texture-formats-tier1"].filter(n=>t.features.has(n)),r=await t.requestDevice({requiredFeatures:s,requiredLimits:{maxSampledTexturesPerShaderStage:t.limits.maxSampledTexturesPerShaderStage,maxSamplersPerShaderStage:t.limits.maxSamplersPerShaderStage}});return{adapter:t,device:r}}destroy(){this._options?.gpu||this.gpu?.device.destroy(),this.gpu=null,this.extensions=null,this._renderer=null}}qr.extension={type:[S.WebGPUSystem],name:"device"};qr.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};class Zm{constructor(e,t,s,r){this.gpuBundle=e,this.stateKey=t,this.device=s,this.label=r}}class ql{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e;for(let t=0;t<16;t++)this._boundBindGroup[t]={bindGroup:null,program:null,key:null}}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){return this.endRenderPass(),this._clearCache(),this._passEncoder=this.commandEncoder.beginRenderPass(e.descriptor),this.renderPassEncoder=this._passEncoder,this._passEncoder}endRenderPass(){this._passEncoder&&this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null}beginBundle(e){if(this._passEncoder!==this.renderPassEncoder)throw new Error("Cannot begin a new render bundle while one is already being recorded.");this._clearCache();const t=this._renderer.pipeline,s=t.getBundleDescriptor();s.label=e,this._bundleStateKey=t.bundleStateKey,this._bundleLabel=e,this.renderPassEncoder=this._gpu.device.createRenderBundleEncoder(s)}endBundle(){const e=this.renderPassEncoder;if(!e||!("finish"in e))throw new Error("endBundle called without an active render bundle.");const t=e.finish({label:this._bundleLabel});return this.renderPassEncoder=this._passEncoder,this._clearCache(),new Zm(t,this._bundleStateKey,this._gpu.device,this._bundleLabel)}isBundleValid(e){return e?.stateKey===this._renderer.pipeline.bundleStateKey&&e.device===this._gpu.device}executeBundle(e){const t=[];if(Array.isArray(e))for(let s=0;s<e.length;s++)t[s]=this._getGpuBundle(e[s]);else t[0]=this._getGpuBundle(e);this._clearCache(),this._passEncoder.executeBundles(t)}_getGpuBundle(e){return this.isBundleValid(e)||z(`Render bundle ${e?.label??"(unlabeled)"} was recorded against a different render target state or on a lost device. Re-record it — replaying it will either be rejected by WebGPU or draw with the wrong winding. Check encoder.isBundleValid(bundle) before executing.`),e.gpuBundle}setViewport(e){this._passEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setStencilReference(e){this._passEncoder.setStencilReference(e)}setPipelineFromGeometryProgramAndState(e,t,s,r,n){const o=this._renderer.pipeline.getPipeline(e,t,s,r,n);this.setPipeline(o)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;const t=e.data.BYTES_PER_ELEMENT===2?"uint16":"uint32";this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){const t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.key=null}setBindGroup(e,t,s){const r=this._boundBindGroup[e];if(r.bindGroup===t&&r.program===s&&r.key===t._key)return;r.bindGroup=t,r.program=s,r.key=t._key,t._touch(this._renderer.gc.now);const n=this._renderer.bindGroup.getBindGroup(t,s,e);this.renderPassEncoder.setBindGroup(e,n)}setGeometry(e,t){const s=this._renderer.pipeline.getBufferNamesToBind(e,t);for(let r=0;r<s.length;r++)this._setVertexBuffer(r,e.attributes[s[r]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){const s=e.gpuProgram,r=s.layout;for(let n=0;n<r.length;n++){const o=e.groups[n];!r[n]||!o||(t||this._syncBindGroup(o),this.setBindGroup(n,o,s))}}_syncBindGroup(e){const t=e.resources,s=e._resourceKeys;for(let r=0;r<s.length;r++){const n=t[s[r]];n&&n.isUniformGroup&&this._renderer.ubo.updateUniformGroup(n)}}draw(e){const{geometry:t,shader:s,state:r,topology:n,size:o,start:a,baseVertex:l,instanceCount:h,skipSync:c,firstInstance:u}=e;this.setPipelineFromGeometryProgramAndState(t,s.gpuProgram,r,n,s._overrides),this.setGeometry(t,s.gpuProgram),this._setShaderBindGroups(s,c),t.indexBuffer?this.renderPassEncoder.drawIndexed(o||t.indexCount||t.indexBuffer.data.length,h??t.instanceCount,a||0,l||0,u||0):this.renderPassEncoder.draw(o||t.vertexCount,h??t.instanceCount,a||0,u||0)}drawIndirect(e){const{geometry:t,shader:s,state:r,topology:n,skipSync:o,indirectBuffer:a,indirectOffset:l}=e;this.setPipelineFromGeometryProgramAndState(t,s.gpuProgram,r,n,s._overrides),this.setGeometry(t,s.gpuProgram),this._setShaderBindGroups(s,o),t.indexBuffer?this.renderPassEncoder.drawIndexedIndirect(a,l):this.renderPassEncoder.drawIndirect(a,l)}finishRenderPass(){this._passEncoder&&(this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}_clearCache(){for(let e=0;e<16;e++){const t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.key=null,this._boundVertexBuffer[e]=null}this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null,this.renderPassEncoder=null,this._passEncoder=null}contextChange(e){this._gpu=e}}ql.extension={type:[S.WebGPUSystem],name:"encoder",priority:1};class Yl{constructor(e){this.supportsOverrideConstants=!1,this._renderer=e}contextChange(){const e=this._renderer.device.gpu.device;this.maxTextures=Math.min(e.limits.maxSampledTexturesPerShaderStage,e.limits.maxSamplersPerShaderStage),this.maxBatchableTextures=this.maxTextures,this._detectOverrideConstantsSupport(e)}_detectOverrideConstantsSupport(e){e.pushErrorScope("validation");const t=e.createShaderModule({code:`override TEST_VALUE: f32 = 0.0;
879
- @compute @workgroup_size(1) fn main() {}`});e.createComputePipeline({layout:"auto",compute:{module:t,entryPoint:"main",constants:{TEST_VALUE:1}}}),e.popErrorScope().then(s=>{this.supportsOverrideConstants=!s})}destroy(){}}Yl.extension={type:[S.WebGPUSystem],name:"limits"};class Kl{constructor(e){this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}contextChange(){this._activeGpuRenderTarget=null}onRenderTargetChange(e){const t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeRenderTarget=e,this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){const s=this._activeGpuRenderTarget??(this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget));s.stencilMode=e,s.stencilReference=t;const r=this._renderer;r.pipeline.setStencilMode(e),r.encoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}Kl.extension={type:[S.WebGPUSystem],name:"stencil"};const ai={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function Qm(i){const e=i.map(s=>({data:s,offset:0,size:0}));let t=0;for(let s=0;s<e.length;s++){const r=e[s];let n=ai[r.data.type].size;const o=ai[r.data.type].align;if(!ai[r.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${r.data.type}`);r.data.size>1&&(n=Math.max(n,o)*r.data.size),t=Math.ceil(t/o)*o,r.size=n,r.offset=t,t+=n}return t=Math.ceil(t/16)*16,{uboElements:e,size:t}}function Jm(i,e){const{size:t,align:s}=ai[i.data.type],r=(Math.max(t,s)-t)/4,n=i.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
878
+ `))}class Jr{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,t,s){const r=this._renderer.shader._getProgramData(t);(!e.isStatic||e._dirtyId!==r.uniformDirtyGroups[e.uid])&&(r.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,t)(r.uniformData,e.uniforms,this._renderer,s))}_getUniformSyncFunction(e,t){return this._uniformGroupSyncHash[e._signature]?.[t._key]||this._createUniformSyncFunction(e,t)}_createUniformSyncFunction(e,t){const s=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),r=this._getSignature(e,t._uniformData,"u");return this._cache[r]||(this._cache[r]=this._generateUniformsSync(e,t._uniformData)),s[t._key]=this._cache[r],s[t._key]}_generateUniformsSync(e,t){return Rm(e,t)}_getSignature(e,t,s){const r=e.uniforms,n=[`${s}-`];for(const o in r)n.push(o),t[o]&&n.push(t[o].type);return n.join("-")}destroy(){this._renderer=null,this._cache=null}}Jr.extension={type:[S.WebGLSystem],name:"uniformGroup"};function Bm(i){const e={};if(e.normal=[i.ONE,i.ONE_MINUS_SRC_ALPHA],e.add=[i.ONE,i.ONE],e.multiply=[i.DST_COLOR,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.screen=[i.ONE,i.ONE_MINUS_SRC_COLOR,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[i.SRC_ALPHA,i.ONE_MINUS_SRC_ALPHA,i.ONE,i.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[i.SRC_ALPHA,i.ONE,i.ONE,i.ONE],e["screen-npm"]=[i.SRC_ALPHA,i.ONE_MINUS_SRC_COLOR,i.ONE,i.ONE_MINUS_SRC_ALPHA],e.erase=[i.ZERO,i.ONE_MINUS_SRC_ALPHA],!(i instanceof ee.get().getWebGLRenderingContext()))e.min=[i.ONE,i.ONE,i.ONE,i.ONE,i.MIN,i.MIN],e.max=[i.ONE,i.ONE,i.ONE,i.ONE,i.MAX,i.MAX];else{const s=i.getExtension("EXT_blend_minmax");s&&(e.min=[i.ONE,i.ONE,i.ONE,i.ONE,s.MIN_EXT,s.MIN_EXT],e.max=[i.ONE,i.ONE,i.ONE,i.ONE,s.MAX_EXT,s.MAX_EXT])}return e}const{BLEND:Qy,OFFSET:Jy,CULLING:ex,DEPTH_TEST:tx,WINDING:sx,DEPTH_MASK:zc}=la,Im=class Bo{constructor(e){this._invertFrontFace=!1,this._renderer=e,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[Qy]=this.setBlend,this.map[Jy]=this.setOffset,this.map[ex]=this.setCullFace,this.map[tx]=this.setDepthTest,this.map[sx]=this.setFrontFace,this.map[zc]=this.setDepthMask,this.checks=[],this.defaultState=_t.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(e,e.flipY),this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=Bm(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let t=this.stateId^e.data,s=0;for(;t;)t&1&&this.map[s].call(this,!!(e.data&1<<s)),t>>=1,s++;this.stateId=e.data}for(let t=0;t<this.checks.length;t++)this.checks[t](this,e)}forceState(e){e||(e=this.defaultState);for(let t=0;t<this.map.length;t++)this.map[t].call(this,!!(e.data&1<<t));for(let t=0;t<this.checks.length;t++)this.checks[t](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(Bo._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(Bo._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}get depthMaskEnabled(){return!!(this.stateId&1<<zc)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const t=this._invertFrontFace?!e:e;this._glFrontFace!==t&&(this._glFrontFace=t,this.gl.frontFace(this.gl[t?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const t=this.blendModesMap[e],s=this.gl;t.length===2?s.blendFunc(t[0],t[1]):s.blendFuncSeparate(t[0],t[1],t[2],t[3]),t.length===6?(this._blendEq=!0,s.blendEquationSeparate(t[4],t[5])):this._blendEq&&(this._blendEq=!1,s.blendEquationSeparate(s.FUNC_ADD,s.FUNC_ADD))}setPolygonOffset(e,t){this.gl.polygonOffset(e,t)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,t){const s=this.checks.indexOf(e);t&&s===-1?this.checks.push(e):!t&&s!==-1&&this.checks.splice(s,1)}static _checkBlendMode(e,t){e.setBlendMode(t.blendMode)}static _checkPolygonOffset(e,t){e.setPolygonOffset(1,t.polygonOffset)}destroy(){this.gl=null,this.checks.length=0,this._renderer=null}};Im.extension={type:[S.WebGLSystem],name:"state"};let Gm=Im;class Dm{constructor(e){this.target=Gs.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=ie.UNSIGNED_BYTE,this.internalFormat=_r.RGBA,this.format=_r.RGBA,this.samplerType=0}destroy(){}}function Hl(i,e,t,s,r){if(i=Math.max(0,i),e=Math.min(e,t*s),i>=e)return 0;const n=Math.floor(i/t),o=i-n*t,a=Math.floor(e/t),l=e-a*t;if(n===a)return r[0].set(o,n,l-o,1),1;let h=0,c=n;return o>0&&(r[h++].set(o,n,t-o,1),c++),a>c&&r[h++].set(0,c,t,a-c),l>0&&r[h++].set(0,a,l,1),h}const Hc=[new te,new te,new te],Fm={id:"buffer",upload(i,e,t,s,r,n=!1){const o=r||e.target,a=i.resource;if(o===Gs.TEXTURE_3D||o===Gs.TEXTURE_2D_ARRAY){n||e.width!==i.width||e.height!==i.height?t.texImage3D(o,0,e.internalFormat,i.width,i.height,i.depthOrArrayLayers,0,e.format,e.type,a):t.texSubImage3D(o,0,0,0,0,i.width,i.height,i.depthOrArrayLayers,e.format,e.type,a),e.width=i.width,e.height=i.height;return}const l=i.width*i.height,h=n||e.width!==i.width||e.height!==i.height,c=i._updateStart>0||i._updateEnd<l;if(h)t.texImage2D(o,0,e.internalFormat,i.width,i.height,0,e.format,e.type,a);else if(c){const u=a.length/l,d=Hl(i._updateStart,i._updateEnd,i.width,i.height,Hc);for(let f=0;f<d;f++){const p=Hc[f],g=(p.y*i.width+p.x)*u;t.texSubImage2D(o,0,p.x,p.y,p.width,p.height,e.format,e.type,a.subarray(g,g+p.width*p.height*u))}}else t.texSubImage2D(o,0,0,0,i.width,i.height,e.format,e.type,a);e.width=i.width,e.height=i.height}},ix={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},Om={id:"compressed",upload(i,e,t,s,r,n){const o=r??e.target;t.pixelStorei(t.UNPACK_ALIGNMENT,4);let a=i.pixelWidth,l=i.pixelHeight;const h=!!ix[i.format];for(let c=0;c<i.resource.length;c++){const u=i.resource[c];h?t.compressedTexImage2D(o,c,e.internalFormat,a,l,0,u):t.texImage2D(o,c,e.internalFormat,a,l,0,e.format,e.type,u),a=Math.max(a>>1,1),l=Math.max(l>>1,1)}}},Wc=["right","left","top","bottom","front","back"];function Lm(i){return{id:"cube",upload(e,t,s,r){const n=e.faces;for(let o=0;o<Wc.length;o++){const a=Wc[o],l=n[a];if(!l.resource)continue;(i[l.uploadMethodId]||i.image).upload(l,t,s,r,Gs.TEXTURE_CUBE_MAP_POSITIVE_X+o,(t._layerInitMask&1<<o)===0),t._layerInitMask|=1<<o}t.width=e.pixelWidth,t.height=e.pixelHeight}}}const Wl={id:"image",upload(i,e,t,s,r,n=!1){const o=r||e.target,a=i.pixelWidth,l=i.pixelHeight,h=i.resourceWidth,c=i.resourceHeight,u=s===2,d=n||e.width!==a||e.height!==l,f=h>=a&&c>=l,p=i.resource;(u?rx:nx)(t,o,e,a,l,h,c,p,d,f),e.width=a,e.height=l}};function rx(i,e,t,s,r,n,o,a,l,h){if(!h){l&&i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,null),i.texSubImage2D(e,0,0,0,n,o,t.format,t.type,a);return}if(!l){i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,a)}function nx(i,e,t,s,r,n,o,a,l,h){if(!h){l&&i.texImage2D(e,0,t.internalFormat,s,r,0,t.format,t.type,null),i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}if(!l){i.texSubImage2D(e,0,0,0,t.format,t.type,a);return}i.texImage2D(e,0,t.internalFormat,t.format,t.type,a)}const ox=Pp(),Um={id:"video",upload(i,e,t,s,r,n=ox){if(!i.isValid){const o=r??e.target;t.texImage2D(o,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Wl.upload(i,e,t,s,r,n)}},Io={linear:9729,nearest:9728},Nm={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},tr={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},zm={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Go(i,e,t,s,r,n,o,a){const l=n;if(!a||i.addressModeU!=="repeat"||i.addressModeV!=="repeat"||i.addressModeW!=="repeat"){const h=tr[o?"clamp-to-edge":i.addressModeU],c=tr[o?"clamp-to-edge":i.addressModeV],u=tr[o?"clamp-to-edge":i.addressModeW];e[r](l,e.TEXTURE_WRAP_S,h),e[r](l,e.TEXTURE_WRAP_T,c),e.TEXTURE_WRAP_R&&e[r](l,e.TEXTURE_WRAP_R,u)}if((!a||i.magFilter!=="linear")&&e[r](l,e.TEXTURE_MAG_FILTER,Io[i.magFilter]),t){if(!a||i.mipmapFilter!=="linear"){const h=Nm[i.minFilter][i.mipmapFilter];e[r](l,e.TEXTURE_MIN_FILTER,h)}}else e[r](l,e.TEXTURE_MIN_FILTER,Io[i.minFilter]);if(s&&i.maxAnisotropy>1){const h=Math.min(i.maxAnisotropy,e.getParameter(s.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[r](l,s.TEXTURE_MAX_ANISOTROPY_EXT,h)}i.compare?(e[r](l,e.TEXTURE_COMPARE_FUNC,zm[i.compare]),e[r](l,e.TEXTURE_COMPARE_MODE,e.COMPARE_REF_TO_TEXTURE)):a||e[r](l,e.TEXTURE_COMPARE_MODE,e.NONE)}function Hm(i){return{r8unorm:i.RED,r8snorm:i.RED,r8uint:i.RED_INTEGER,r8sint:i.RED_INTEGER,r16uint:i.RED_INTEGER,r16sint:i.RED_INTEGER,r16float:i.RED,rg8unorm:i.RG,rg8snorm:i.RG,rg8uint:i.RG_INTEGER,rg8sint:i.RG_INTEGER,r32uint:i.RED_INTEGER,r32sint:i.RED_INTEGER,r32float:i.RED,rg16uint:i.RG_INTEGER,rg16sint:i.RG_INTEGER,rg16float:i.RG,rgba8unorm:i.RGBA,"rgba8unorm-srgb":i.RGBA,rgba8snorm:i.RGBA,rgba8uint:i.RGBA_INTEGER,rgba8sint:i.RGBA_INTEGER,bgra8unorm:i.RGBA,"bgra8unorm-srgb":i.RGBA,rgb9e5ufloat:i.RGB,rgb10a2unorm:i.RGBA,rg11b10ufloat:i.RGB,rg32uint:i.RG_INTEGER,rg32sint:i.RG_INTEGER,rg32float:i.RG,rgba16uint:i.RGBA_INTEGER,rgba16sint:i.RGBA_INTEGER,rgba16float:i.RGBA,rgba32uint:i.RGBA_INTEGER,rgba32sint:i.RGBA_INTEGER,rgba32float:i.RGBA,stencil8:i.STENCIL_INDEX8,depth16unorm:i.DEPTH_COMPONENT,depth24plus:i.DEPTH_COMPONENT,"depth24plus-stencil8":i.DEPTH_STENCIL,depth32float:i.DEPTH_COMPONENT,"depth32float-stencil8":i.DEPTH_STENCIL}}function Wm(i,e){let t={},s=i.RGBA;return i instanceof ee.get().getWebGLRenderingContext()?e.srgb&&(t={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(t={"rgba8unorm-srgb":i.SRGB8_ALPHA8,"bgra8unorm-srgb":i.SRGB8_ALPHA8},s=i.RGBA8),{r8unorm:i.R8,r8snorm:i.R8_SNORM,r8uint:i.R8UI,r8sint:i.R8I,r16uint:i.R16UI,r16sint:i.R16I,r16float:i.R16F,rg8unorm:i.RG8,rg8snorm:i.RG8_SNORM,rg8uint:i.RG8UI,rg8sint:i.RG8I,r32uint:i.R32UI,r32sint:i.R32I,r32float:i.R32F,rg16uint:i.RG16UI,rg16sint:i.RG16I,rg16float:i.RG16F,rgba8unorm:i.RGBA,...t,rgba8snorm:i.RGBA8_SNORM,rgba8uint:i.RGBA8UI,rgba8sint:i.RGBA8I,bgra8unorm:s,rgb9e5ufloat:i.RGB9_E5,rgb10a2unorm:i.RGB10_A2,rg11b10ufloat:i.R11F_G11F_B10F,rg32uint:i.RG32UI,rg32sint:i.RG32I,rg32float:i.RG32F,rgba16uint:i.RGBA16UI,rgba16sint:i.RGBA16I,rgba16float:i.RGBA16F,rgba32uint:i.RGBA32UI,rgba32sint:i.RGBA32I,rgba32float:i.RGBA32F,stencil8:i.STENCIL_INDEX8,depth16unorm:i.DEPTH_COMPONENT16,depth24plus:i.DEPTH_COMPONENT24,"depth24plus-stencil8":i.DEPTH24_STENCIL8,depth32float:i.DEPTH_COMPONENT32F,"depth32float-stencil8":i.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function $m(i){return{r8unorm:i.UNSIGNED_BYTE,r8snorm:i.BYTE,r8uint:i.UNSIGNED_BYTE,r8sint:i.BYTE,r16uint:i.UNSIGNED_SHORT,r16sint:i.SHORT,r16float:i.HALF_FLOAT,rg8unorm:i.UNSIGNED_BYTE,rg8snorm:i.BYTE,rg8uint:i.UNSIGNED_BYTE,rg8sint:i.BYTE,r32uint:i.UNSIGNED_INT,r32sint:i.INT,r32float:i.FLOAT,rg16uint:i.UNSIGNED_SHORT,rg16sint:i.SHORT,rg16float:i.HALF_FLOAT,rgba8unorm:i.UNSIGNED_BYTE,"rgba8unorm-srgb":i.UNSIGNED_BYTE,rgba8snorm:i.BYTE,rgba8uint:i.UNSIGNED_BYTE,rgba8sint:i.BYTE,bgra8unorm:i.UNSIGNED_BYTE,"bgra8unorm-srgb":i.UNSIGNED_BYTE,rgb9e5ufloat:i.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:i.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:i.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:i.UNSIGNED_INT,rg32sint:i.INT,rg32float:i.FLOAT,rgba16uint:i.UNSIGNED_SHORT,rgba16sint:i.SHORT,rgba16float:i.HALF_FLOAT,rgba32uint:i.UNSIGNED_INT,rgba32sint:i.INT,rgba32float:i.FLOAT,stencil8:i.UNSIGNED_BYTE,depth16unorm:i.UNSIGNED_SHORT,depth24plus:i.UNSIGNED_INT,"depth24plus-stencil8":i.UNSIGNED_INT_24_8,depth32float:i.FLOAT,"depth32float-stencil8":i.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Vm(i){return{"2d":i.TEXTURE_2D,cube:i.TEXTURE_CUBE_MAP,"1d":null,"3d":i?.TEXTURE_3D||null,"2d-array":i?.TEXTURE_2D_ARRAY||null,"cube-array":i?.TEXTURE_CUBE_MAP_ARRAY||null}}const ax=4,$l=class jm{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._integerUnits=0,this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new at({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const t={image:Wl,buffer:Fm,video:Um,compressed:Om,...jm.uploadExtensions};this._uploads={...t,cube:Lm(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Wm(e,this._renderer.context.extensions),this._mapFormatToType=$m(e),this._mapFormatToFormat=Hm(e),this._mapViewDimensionToGlTarget=Vm(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let t=0;t<16;t++)this.bind(W.EMPTY,t)}initSource(e){this.bind(e)}bind(e,t=0){const s=e.source;e?(this.bindSource(s,t),this._useSeparateSamplers&&this._bindSampler(s.style,t)):(this.bindSource(null,t),this._useSeparateSamplers&&this._bindSampler(null,t))}bindSource(e,t=0){const s=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[t]!==e){this._setBoundTexture(t,e),this._activateLocation(t),e||(e=W.EMPTY.source);const r=this.getGlSource(e);s.bindTexture(r.target,r.texture)}}unbindIntegerTextures(e){if(e>=32)return;let t=this._integerUnits>>>e<<e;for(;t;){const s=31-Math.clz32(t);t&=~(1<<s),this.bind(W.EMPTY,s)}}_setBoundTexture(e,t){this._boundTextures[e]=t,!(e<0||e>31)&&(!t||t.viewDimension!=="2d"||(or(t.format)?this._integerUnits|=1<<e:this._integerUnits&=~(1<<e)))}_bindSampler(e,t=0){const s=this._gl;if(!e){this._boundSamplers[t]=null,s.bindSampler(t,null);return}const r=this._getGlSampler(e);this._boundSamplers[t]!==r&&(this._boundSamplers[t]=r,s.bindSampler(t,r))}unbind(e){const t=e.source,s=this._boundTextures,r=this._gl;for(let n=0;n<s.length;n++)if(s[n]===t){this._activateLocation(n);const o=this.getGlSource(t);r.bindTexture(o.target,null),this._setBoundTexture(n,null)}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const t=this._gl,s=new Dm(t.createTexture());if(s.type=this._mapFormatToType[e.format],s.internalFormat=this._mapFormatToInternalFormat[e.format],s.format=this._mapFormatToFormat[e.format],s.target=this._mapViewDimensionToGlTarget[e.viewDimension],s.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const n=Math.max(e.width,e.height,e.depth);e.mipLevelCount=Math.floor(Math.log2(n))+1}return e._gpuData[this._renderer.uid]=s,this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),this.updateStyle(e,!1),s}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,t){const s=this._gl,r=this.getGlSource(e);s.bindTexture(r.target,r.texture),this._setBoundTexture(this._activeTextureLocation,e),Go(e.style,s,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",r.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,t)}onSourceUnload(e,t=!1){const s=e._gpuData[this._renderer.uid];s&&(t||(this.unbind(e),this._gl.deleteTexture(s.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const t=this._gl,s=this.getGlSource(e);t.bindTexture(s.target,s.texture),this._setBoundTexture(this._activeTextureLocation,e);const r=e.alphaMode==="premultiply-alpha-on-upload"&&!or(e.format)&&s.target!==t.TEXTURE_3D&&s.target!==t.TEXTURE_2D_ARRAY;if(this._premultiplyAlpha!==r&&(this._premultiplyAlpha=r,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,s,t,this._renderer.context.webGLVersion);else if(s.target===t.TEXTURE_2D)this._initEmptyTexture2D(s,e);else if(s.target===t.TEXTURE_2D_ARRAY||s.target===t.TEXTURE_3D)this._initEmptyTexture3D(s,e);else if(s.target===t.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(s,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(s,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,t=!0){t&&this.bindSource(e,0);const s=this.getGlSource(e);this._gl.generateMipmap(s.target)}_initEmptyTexture2D(e,t){const s=this._gl;s.texImage2D(s.TEXTURE_2D,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let r=Math.max(t.pixelWidth>>1,1),n=Math.max(t.pixelHeight>>1,1);for(let o=1;o<t.mipLevelCount;o++)s.texImage2D(s.TEXTURE_2D,o,e.internalFormat,r,n,0,e.format,e.type,null),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}_initEmptyTexture3D(e,t){const s=this._gl,r=e.target===s.TEXTURE_3D;let n=t.pixelWidth,o=t.pixelHeight,a=t.depthOrArrayLayers;for(let l=0;l<t.mipLevelCount;l++)s.texImage3D(e.target,l,e.internalFormat,n,o,a,0,e.format,e.type,null),n=Math.max(n>>1,1),o=Math.max(o>>1,1),r&&(a=Math.max(a>>1,1))}_initEmptyTextureCube(e,t){const s=this._gl,r=6;for(let a=0;a<r;a++)s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+a,0,e.internalFormat,t.pixelWidth,t.pixelHeight,0,e.format,e.type,null);let n=Math.max(t.pixelWidth>>1,1),o=Math.max(t.pixelHeight>>1,1);for(let a=1;a<t.mipLevelCount;a++){for(let l=0;l<r;l++)s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+l,a,e.internalFormat,n,o,0,e.format,e.type,null);n=Math.max(n>>1,1),o=Math.max(o>>1,1)}}_applyMipRange(e,t){if(this._renderer.context.webGLVersion!==2||t.mipLevelCount<=1)return;const s=this._gl,r=Math.max((t.mipLevelCount|0)-1,0);s.texParameteri(e.target,s.TEXTURE_BASE_LEVEL,0),s.texParameteri(e.target,s.TEXTURE_MAX_LEVEL,r)}_initSampler(e){const t=this._gl,s=this._gl.createSampler();return this._glSamplers[e._resourceId]=s,Go(e,t,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",s,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:t,width:s,height:r}=this.getPixels(e),n=ee.get().createCanvas();n.width=s,n.height=r;const o=n.getContext("2d");if(o){const a=o.createImageData(s,r);a.data.set(t),o.putImageData(a,0,0)}return n}getPixels(e){const t=e.source.resolution,s=e.frame,r=Math.max(Math.round(s.width*t),1),n=Math.max(Math.round(s.height*t),1),o=new Uint8Array(ax*r*n),a=this._renderer,l=a.renderTarget.getRenderTarget(e),h=a.renderTarget.getGpuRenderTarget(l),c=a.gl;return a.renderTarget.adaptor.bindFramebuffer(h.resolveTargetFramebuffer),c.readPixels(Math.round(s.x*t),Math.round(s.y*t),r,n,c.RGBA,c.UNSIGNED_BYTE,o),{pixels:new Uint8ClampedArray(o.buffer),width:r,height:n}}destroy(){this._managedTextures.destroy(),this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){const e=this._renderer.limits.maxTextures;this._activeTextureLocation=-1,this._boundTextures.fill(null),this._integerUnits=e>=32?-1:(1<<e)-1,this._boundSamplers=Object.create(null);const t=this._gl;this._premultiplyAlpha=!1,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}};$l.extension={type:[S.WebGLSystem],name:"texture"};$l.uploadExtensions=Object.create(null);let Vl=$l;q.handleByMap(S.TextureUploaderWebGL,Vl.uploadExtensions);class jl{contextChange(e){const t=new Ze({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new U,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),s=e.limits.maxBatchableTextures,r=Br({name:"graphics",bits:[va,Ta(s),Wa,Gr]});this.shader=new gt({glProgram:r,resources:{localUniforms:t,batchSamplers:Sa(s)}})}execute(e,t){const s=t.context,r=s.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(s);r.groups[0]=n.globalUniforms.bindGroup,n.state.set(e.state),n.shader.bind(r),n.geometry.bind(a.geometry,r.glProgram);const h=l.instructions;for(let c=0;c<l.instructionSize;c++){const u=h[c];if(u.size){for(let d=0;d<u.textures.count;d++)n.texture.bind(u.textures.textures[d],d);n.texture.unbindIntegerTextures(u.textures.count),n.geometry.draw(u.topology,u.size,u.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}jl.extension={type:[S.WebGLPipesAdaptor],name:"graphics"};class Xl{init(){const e=Br({name:"mesh",bits:[Wa,Ip,Gr]});this._shader=new gt({glProgram:e,resources:{uTexture:W.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new U}}}})}execute(e,t){const s=e.renderer;let r=t._shader;if(r){if(!r.glProgram){H("Mesh shader has no glProgram",t.shader);return}}else{r=this._shader;const n=t.texture,o=n.source;r.resources.uTexture=o,r.resources.uSampler=o.style,r.resources.textureUniforms.uniforms.uTextureMatrix=n.textureMatrix.mapCoord}r.groups[100]=s.globalUniforms.bindGroup,r.groups[101]=e.localUniformsBindGroup,s.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Xl.extension={type:[S.WebGLPipesAdaptor],name:"mesh"};const lx=[...Xr,Zr,pm,cm,Gl,El,Vl,Ll,Al,Jr,Qr,Il,Gm,Dl,Bl],hx=[...Cl],cx=[sl,Xl,jl],Xm=[],qm=[],Ym=[],Km=[];q.handleByNamedList(S.WebGLSystem,Xm);q.handleByNamedList(S.WebGLPipes,qm);q.handleByNamedList(S.WebGLPipesAdaptor,Ym);q.handleByNamedList(S.WebGLLoader,Km);q.add(...lx,...hx,...cx);class Zm extends ds{constructor(){const e={name:"webgl",type:Ke.WEBGL,systems:Xm,renderPipes:qm,renderPipeAdaptors:Ym,loaders:Km};super(e)}}const ux=Object.freeze(Object.defineProperty({__proto__:null,WebGLRenderer:Zm},Symbol.toStringTag,{value:"Module"}));class dx{constructor(e,t){this.autoGarbageCollect=!0,this._gpuData=null,this.gpuBindGroup=e,this._gcLastUsed=t}unload(){this.gpuBindGroup=null}}class ql{constructor(e){this._hash=Object.create(null),this._renderer=e,e.gc.addResourceHash(this,"_hash","resource"),e.gc.addCollection(this,"_hash","hash")}contextChange(e){this._gpu=e,this._hash=Object.create(null)}getBindGroup(e,t,s){const r=`${e._key}:${t._layoutKey<<4|s}`,n=this._hash[r];return n?(n._gcLastUsed=this._renderer.gc.now,n.gpuBindGroup):this._createBindGroup(r,e,t,s)}_createBindGroup(e,t,s,r){const n=this._gpu.device,o=s.layout[r],a=[],l=this._renderer;for(const u in o){const d=t.resources[u]??t.resources[o[u]];if(!d||d.destroyed)throw new Error(`[BindGroup] the resource bound as '${u}' was destroyed while a shader still uses it. Remove it from the shader before destroying it.`);let f;if(d._resourceType==="uniformGroup"){const p=d;l.ubo.updateUniformGroup(p);const g=p.buffer;f={buffer:l.buffer.getGPUBuffer(g),offset:0,size:g.descriptor.size}}else if(d._resourceType==="buffer"){const p=d;f={buffer:l.buffer.getGPUBuffer(p),offset:0,size:p.descriptor.size}}else if(d._resourceType==="bufferResource"){const p=d;f={buffer:l.buffer.getGPUBuffer(p.buffer),offset:p.offset,size:p.size??p.buffer.descriptor.size}}else if(d._resourceType==="textureSampler"){const p=d;f=l.texture.getGpuSampler(p)}else if(d._resourceType==="textureSource"){const p=d;f=l.texture.getTextureView(p)}else if(d._resourceType==="textureView"){const p=d;f=l.texture.getTextureView(p.source,p.viewDescriptor)}a.push({binding:o[u],resource:f})}const h=l.shader.getProgramData(s).bindGroups[r],c=n.createBindGroup({layout:h,entries:a});return this._hash[e]=new dx(c,l.gc.now),c}destroy(){this._hash=null,this._renderer=null}}ql.extension={type:[S.WebGPUSystem],name:"bindGroup"};class Qm{constructor(e){this.gpuBuffer=e}destroy(){this.gpuBuffer.destroy(),this.gpuBuffer=null}}class Yl{constructor(e){this._renderer=e,this._managedBuffers=new at({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"gpuBuffer"})}contextChange(e){this._gpu=e,this.destroyAll()}getGPUBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuBuffer||this.createGPUBuffer(e)}updateBuffer(e){const t=this.getGPUBuffer(e),s=e.data;return e._updateID&&s&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,e._updateOffset,s.buffer,s.byteOffset+e._updateOffset,(e._updateSize||s.byteLength)+3&-4)),t}destroyAll(){this._managedBuffers.removeAll()}onBufferUnload(e){e.off("update",this.updateBuffer,this),e.off("change",this.onBufferChange,this)}createGPUBuffer(e){const t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(ur(e.data.buffer,t.getMappedRange(),e.data.byteOffset,e.data.byteLength),t.unmap()),e._gpuData[this._renderer.uid]=new Qm(t),this._managedBuffers.add(e)&&(e.on("update",this.updateBuffer,this),e.on("change",this.onBufferChange,this)),t}onBufferChange(e){this._managedBuffers.remove(e),e._updateID=0,this.createGPUBuffer(e)}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gpu=null}}Yl.extension={type:[S.WebGPUSystem],name:"buffer"};class Jm{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw new Error(`UniformBufferBatch: array is too large: ${e*4}`);const t=this.byteIndex;let s=t+e*4;if(s=Math.ceil(s/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,s>this.data.length*4)throw new Error("UniformBufferBatch: ubo batch got too big");return this.byteIndex=s,t}addGroup(e){const t=this.addEmptyGroup(e.length);for(let s=0;s<e.length;s++)this.data[t/4+s]=e[s];return t}destroy(){this.data=null}}class Kl{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}}Kl.extension={type:[S.WebGPUSystem],name:"colorMask"};const fx=new Set(["apple","arm","qualcomm","img-tec"]);class en{constructor(e){this._renderer=e}async init(e){return this._initPromise?this._initPromise:(this._options=e,this._initPromise=(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(t=>this._setGpu(t)),this._initPromise)}_setGpu(e){this.gpu=e,this.extensions={transientAttachment:typeof GPUTextureUsage.TRANSIENT_ATTACHMENT=="number",tileBased:fx.has(e.adapter?.info?.vendor)},this._options.gpu||e.device.lost.then(()=>this._restoreDevice()).catch(t=>H("WebGPU device was lost and could not be restored",t)),this._renderer.runners.contextChange.emit(this.gpu)}async _restoreDevice(){if(!this._renderer)return;const e=await this._createDeviceAndAdaptor(this._options);if(!this._renderer){e.device.destroy();return}this._setGpu(e)}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){const t=await ee.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter});if(!t)throw new Error("WebGPU not supported. No GPU adapter was returned by navigator.gpu.requestAdapter().");const s=["texture-compression-bc","texture-compression-astc","texture-compression-etc2","indirect-first-instance","bgra8unorm-storage","texture-formats-tier1"].filter(n=>t.features.has(n)),r=await t.requestDevice({requiredFeatures:s,requiredLimits:{maxSampledTexturesPerShaderStage:t.limits.maxSampledTexturesPerShaderStage,maxSamplersPerShaderStage:t.limits.maxSamplersPerShaderStage}});return{adapter:t,device:r}}destroy(){this._options?.gpu||this.gpu?.device.destroy(),this.gpu=null,this.extensions=null,this._renderer=null}}en.extension={type:[S.WebGPUSystem],name:"device"};en.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};class eg{constructor(e,t,s,r){this.gpuBundle=e,this.stateKey=t,this.device=s,this.label=r}}class Zl{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e;for(let t=0;t<16;t++)this._boundBindGroup[t]={bindGroup:null,program:null,key:null}}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){return this.endRenderPass(),this._clearCache(),this._passEncoder=this.commandEncoder.beginRenderPass(e.descriptor),this.renderPassEncoder=this._passEncoder,this._passEncoder}endRenderPass(){this._passEncoder&&this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null}beginBundle(e){if(this._passEncoder!==this.renderPassEncoder)throw new Error("Cannot begin a new render bundle while one is already being recorded.");this._clearCache();const t=this._renderer.pipeline,s=t.getBundleDescriptor();s.label=e,this._bundleStateKey=t.bundleStateKey,this._bundleLabel=e,this.renderPassEncoder=this._gpu.device.createRenderBundleEncoder(s)}endBundle(){const e=this.renderPassEncoder;if(!e||!("finish"in e))throw new Error("endBundle called without an active render bundle.");const t=e.finish({label:this._bundleLabel});return this.renderPassEncoder=this._passEncoder,this._clearCache(),new eg(t,this._bundleStateKey,this._gpu.device,this._bundleLabel)}isBundleValid(e){return e?.stateKey===this._renderer.pipeline.bundleStateKey&&e.device===this._gpu.device}executeBundle(e){const t=[];if(Array.isArray(e))for(let s=0;s<e.length;s++)t[s]=this._getGpuBundle(e[s]);else t[0]=this._getGpuBundle(e);this._clearCache(),this._passEncoder.executeBundles(t)}_getGpuBundle(e){return this.isBundleValid(e)||H(`Render bundle ${e?.label??"(unlabeled)"} was recorded against a different render target state or on a lost device. Re-record it — replaying it will either be rejected by WebGPU or draw with the wrong winding. Check encoder.isBundleValid(bundle) before executing.`),e.gpuBundle}setViewport(e){this._passEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setStencilReference(e){this._passEncoder.setStencilReference(e)}setPipelineFromGeometryProgramAndState(e,t,s,r,n){const o=this._renderer.pipeline.getPipeline(e,t,s,r,n);this.setPipeline(o)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;const t=e.data.BYTES_PER_ELEMENT===2?"uint16":"uint32";this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){const t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.key=null}setBindGroup(e,t,s){const r=this._boundBindGroup[e];if(r.bindGroup===t&&r.program===s&&r.key===t._key)return;r.bindGroup=t,r.program=s,r.key=t._key,t._touch(this._renderer.gc.now);const n=this._renderer.bindGroup.getBindGroup(t,s,e);this.renderPassEncoder.setBindGroup(e,n)}setGeometry(e,t){const s=this._renderer.pipeline.getBufferNamesToBind(e,t);for(let r=0;r<s.length;r++)this._setVertexBuffer(r,e.attributes[s[r]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){const s=e.gpuProgram,r=s.layout;for(let n=0;n<r.length;n++){const o=e.groups[n];!r[n]||!o||(t||this._syncBindGroup(o),this.setBindGroup(n,o,s))}}_syncBindGroup(e){const t=e.resources,s=e._resourceKeys;for(let r=0;r<s.length;r++){const n=t[s[r]];n&&n.isUniformGroup&&this._renderer.ubo.updateUniformGroup(n)}}draw(e){const{geometry:t,shader:s,state:r,topology:n,size:o,start:a,baseVertex:l,instanceCount:h,skipSync:c,firstInstance:u}=e;this.setPipelineFromGeometryProgramAndState(t,s.gpuProgram,r,n,s._overrides),this.setGeometry(t,s.gpuProgram),this._setShaderBindGroups(s,c),t.indexBuffer?this.renderPassEncoder.drawIndexed(o||t.indexCount||t.indexBuffer.data.length,h??t.instanceCount,a||0,l||0,u||0):this.renderPassEncoder.draw(o||t.vertexCount,h??t.instanceCount,a||0,u||0)}drawIndirect(e){const{geometry:t,shader:s,state:r,topology:n,skipSync:o,indirectBuffer:a,indirectOffset:l}=e;this.setPipelineFromGeometryProgramAndState(t,s.gpuProgram,r,n,s._overrides),this.setGeometry(t,s.gpuProgram),this._setShaderBindGroups(s,o),t.indexBuffer?this.renderPassEncoder.drawIndexedIndirect(a,l):this.renderPassEncoder.drawIndirect(a,l)}finishRenderPass(){this._passEncoder&&(this._passEncoder.end(),this.renderPassEncoder=null,this._passEncoder=null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}_clearCache(){for(let e=0;e<16;e++){const t=this._boundBindGroup[e];t.bindGroup=null,t.program=null,t.key=null,this._boundVertexBuffer[e]=null}this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null,this.renderPassEncoder=null,this._passEncoder=null}contextChange(e){this._gpu=e}}Zl.extension={type:[S.WebGPUSystem],name:"encoder",priority:1};class Ql{constructor(e){this.supportsOverrideConstants=!1,this._renderer=e}contextChange(){const e=this._renderer.device.gpu.device;this.maxTextures=Math.min(e.limits.maxSampledTexturesPerShaderStage,e.limits.maxSamplersPerShaderStage),this.maxBatchableTextures=this.maxTextures,this._detectOverrideConstantsSupport(e)}_detectOverrideConstantsSupport(e){e.pushErrorScope("validation");const t=e.createShaderModule({code:`override TEST_VALUE: f32 = 0.0;
879
+ @compute @workgroup_size(1) fn main() {}`});e.createComputePipeline({layout:"auto",compute:{module:t,entryPoint:"main",constants:{TEST_VALUE:1}}}),e.popErrorScope().then(s=>{this.supportsOverrideConstants=!s})}destroy(){}}Ql.extension={type:[S.WebGPUSystem],name:"limits"};class Jl{constructor(e){this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}contextChange(){this._activeGpuRenderTarget=null}onRenderTargetChange(e){const t=this._renderer.renderTarget.getGpuRenderTarget(e);this._activeRenderTarget=e,this._activeGpuRenderTarget=t,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){const s=this._activeGpuRenderTarget??(this._activeGpuRenderTarget=this._renderer.renderTarget.getGpuRenderTarget(this._activeRenderTarget));s.stencilMode=e,s.stencilReference=t;const r=this._renderer;r.pipeline.setStencilMode(e),r.encoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._activeGpuRenderTarget=null}}Jl.extension={type:[S.WebGPUSystem],name:"stencil"};const Es={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function tg(i){const e=i.map(s=>({data:s,offset:0,size:0}));let t=0;for(let s=0;s<e.length;s++){const r=e[s];let n=Es[r.data.type].size;const o=Es[r.data.type].align;if(!Es[r.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${r.data.type}`);r.data.size>1&&(n=Math.max(n,o)*r.data.size),t=Math.ceil(t/o)*o,r.size=n,r.offset=t,t+=n}return t=Math.ceil(t/16)*16,{uboElements:e,size:t}}function sg(i,e){const{size:t,align:s}=Es[i.data.type],r=(Math.max(t,s)-t)/4,n=i.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
880
880
  v = uv.${i.data.name};
881
881
  ${e!==0?`offset += ${e};`:""}
882
882
 
@@ -892,7 +892,7 @@ fn mainFragment(
892
892
  }
893
893
  ${r!==0?`arrayOffset += ${r};`:""}
894
894
  }
895
- `}function eg(i){return Rl(i,fm,Jm)}class Zl extends Pl{constructor(){super({createUboElements:Qm,generateUboSync:eg})}}Zl.extension={type:[S.WebGPUSystem],name:"ubo"};const Bt=128;class Ql{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._batchBuffer=new Km({minUniformOffsetAlignment:Bt});const t=256/Bt;for(let s=0;s<t;s++){let r=ce.UNIFORM|ce.COPY_DST;s===0&&(r|=ce.COPY_SRC),this._buffers.push(new kt({data:this._batchBuffer.data,usage:r}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){this._bindGroupHash=Object.create(null),this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const s=e.buffer.data,r=this._batchBuffer.addEmptyGroup(s.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,r/4),this._bindGroupHash[e.uid]=this._getBindGroup(r/Bt),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,s=this._batchBuffer.addGroup(t);return this._getBufferResource(s/Bt)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/Bt)}getArrayBufferResource(e){const s=this._batchBuffer.addGroup(e)/Bt;return this._getBufferResource(s)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new Xr({buffer:t,offset:(e/2|0)*256,size:Bt})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new Mt({0:this._getBufferResource(e)});this._bindGroups[e]=t}return this._bindGroups[e]}_uploadBindGroups(){const e=this._renderer.buffer,t=this._buffers[0];t.update(this._batchBuffer.byteIndex),e.updateBuffer(t);const s=this._renderer.gpu.device.createCommandEncoder();for(let r=1;r<this._buffers.length;r++){const n=this._buffers[r];s.copyBufferToBuffer(e.getGPUBuffer(t),Bt,e.getGPUBuffer(n),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([s.finish()])}destroy(){for(let e=0;e<this._bindGroups.length;e++)this._bindGroups[e]?.destroy();this._bindGroups=null,this._bindGroupHash=null;for(let e=0;e<this._buffers.length;e++)this._buffers[e].destroy();this._buffers=null;for(let e=0;e<this._bufferResources.length;e++)this._bufferResources[e].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._renderer=null}}Ql.extension={type:[S.WebGPUPipes],name:"uniformBatch"};const zc={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4},lx=new Es({}),hx={"depth24plus-stencil8":{depth:!0,stencil:!0,index:1},depth24plus:{depth:!0,stencil:!1,index:2},depth32float:{depth:!0,stencil:!1,index:3},"depth32float-stencil8":{depth:!0,stencil:!0,index:4},depth16unorm:{depth:!0,stencil:!1,index:5},stencil8:{depth:!1,stencil:!0,index:6}},Wc={depth:!1,stencil:!1,index:0};function Po(i,e){for(const[t,s]of Object.entries(e)){const r=new RegExp(`override\\s+${t}\\s*:\\s*(\\w+)\\s*(?:=[^;]*)?;`);i=i.replace(r,(n,o)=>{let a;return o==="u32"?a=`${Math.trunc(s)}u`:o==="i32"?a=`${Math.trunc(s)}`:a=Number.isInteger(s)?`${s}.0`:`${s}`,`const ${t}: ${o} = ${a};`})}return i}function $c(i,e,t,s,r,n){return i*35184372088832+e*536870912+n*16384+(t<<8)+(s<<3)+r}const Vc=Object.create(null);let cx=0;function jc(i){let e=Vc[i];return e===void 0&&(e=Vc[i]=cx++),e}function ux(i,e,t,s,r,n,o,a){return a<<20|n<<16|r<<13|t<<9|i<<6|o<<5|s<<1|e}function dx(i,e,t,s,r,n,o){return o<<11|n<<10|r<<9|s<<8|t<<5|e<<1|i}class Jl{constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=new Map,this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._colorTargetCount=1,this._colorFormat="bgra8unorm",this._colorFormatId=jc("bgra8unorm"),this._depthStencilFormat="depth24plus-stencil8",this._depthStencilFormatData=Wc,this._depthReadOnly=!1,this._stencilReadOnly=!1,this._invertFrontFace=!1,this._renderer=e}contextChange(e){this._gpu=e,this._moduleCache=Object.create(null),this._pipeStateCaches=Object.create(null),this.setStencilMode(me.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){const t=e.colorAttachments[0]?.texture;this._multisampleCount=t?.source.antialias?4:1,this._colorTargetCount=e.colorAttachments.length,this._colorFormat=t?.format??"bgra8unorm",this._colorFormatId=jc(this._colorFormat),this._depthStencilFormat=e.depthStencilAttachment?.texture.format,this._depthStencilFormatData=hx[this._depthStencilFormat]||Wc,this._depthReadOnly=e.depthStencilAttachment?.depthReadOnly??!1,this._stencilReadOnly=e.depthStencilAttachment?.stencilReadOnly??this._depthReadOnly,this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(e,e.flipY),this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=At[e],this._updatePipeHash())}get bundleStateKey(){const e=this._depthStencilFormatData;return dx(this._multisampleCount===1?0:1,this._colorTargetCount,e.index,e.depth&&this._depthReadOnly?1:0,e.stencil&&this._stencilReadOnly?1:0,this._invertFrontFace?1:0,this._colorFormatId)}getBundleDescriptor(){const e=[];for(let r=0;r<this._colorTargetCount;r++)e.push(this._colorFormat);const t={colorFormats:e,sampleCount:this._multisampleCount},s=this._depthStencilFormatData;return(s.depth||s.stencil)&&(t.depthStencilFormat=this._depthStencilFormat,s.depth&&this._depthReadOnly&&(t.depthReadOnly=!0),s.stencil&&this._stencilReadOnly&&(t.stencilReadOnly=!0)),t}setPipeline(e,t,s,r){const n=this.getPipeline(e,t,s);r.setPipeline(n)}getPipelineKey(e,t,s,r,n){return e._layoutKey||(fr(e,t.attributeData),this._generateBufferKey(e)),$c(e._layoutKey,t._layoutKey,s.data,s._blendModeId,zc[r],n.id)}getPipeline(e,t,s,r,n){e._layoutKey||(fr(e,t.attributeData),this._generateBufferKey(e)),r||(r=e.topology),n||(n=lx);const o=$c(e._layoutKey,t._layoutKey,s.data,s._blendModeId,zc[r],n.id);let a=this._pipeCache.get(o);return a||(a=this._createPipeline(e,t,s,r,n),this._pipeCache.set(o,a)),a}_createPipeline(e,t,s,r,n){const o=this._gpu.device,a=this._createVertexBufferLayouts(e,t),l=this._renderer.state.getColorTargets(s,this._colorTargetCount,this._colorFormat),h=this._stencilMode===me.RENDERING_MASK_ADD?0:this._colorMask;for(let _=0;_<l.length;_++)l[_].writeMask=h;const c=this._renderer.shader.getProgramData(t).pipeline,u=Object.keys(n.data).length>0;let d=t.vertex.source,f=t.fragment.source,p;u&&(this._renderer.limits.supportsOverrideConstants?p=n.data:(d=Po(d,n.data),f=Po(f,n.data)));const g={vertex:{module:this._getModule(d),entryPoint:t.vertex.entryPoint,constants:p,buffers:a},fragment:{module:this._getModule(f),entryPoint:t.fragment.entryPoint,targets:l,constants:p},primitive:{topology:r,cullMode:s.culling?"back":"none",frontFace:s.clockwiseFrontFace!==this._invertFrontFace?"cw":"ccw"},layout:c,multisample:{count:this._multisampleCount},label:t.name?`PIXI Pipeline (${t.name})`:"PIXI Pipeline"};if(this._depthStencilFormatData.depth||this._depthStencilFormatData.stencil){const _=this._depthStencilFormatData;g.depthStencil={...this._stencilState,format:this._depthStencilFormat,depthWriteEnabled:_.depth?s.depthMask&&!this._depthReadOnly:!1,depthCompare:_.depth&&s.depthTest?"less":"always"}}return o.createRenderPipeline(g)}_getModule(e){return this._moduleCache[e]||this._createModule(e)}_createModule(e){const t=this._gpu.device;return this._moduleCache[e]=t.createShaderModule({code:e}),this._moduleCache[e]}_generateBufferKey(e){const t=[];let s=0;const r=Object.keys(e.attributes).sort();for(let o=0;o<r.length;o++){const a=e.attributes[r[o]];t[s++]=a.offset,t[s++]=a.format,t[s++]=a.stride,t[s++]=a.instance}const n=t.join("|");return e._layoutKey=rs(n,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let s=0;const r=Object.keys(e.attributeData).sort();for(let o=0;o<r.length;o++){const a=e.attributeData[r[o]];t[s++]=a.location}const n=t.join("|");return e._attributeLocationsKey=rs(n,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const s=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[s])return this._bindingNamesCache[s];const r=this._createVertexBufferLayouts(e,t),n=[],o=t.attributeData;for(let a=0;a<r.length;a++){const h=Object.values(r[a].attributes)[0].shaderLocation;for(const c in o)if(o[c].location===h){n[a]=c;break}}return this._bindingNamesCache[s]=n,n}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const s=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[s])return this._bufferLayoutsCache[s];const r=[];return e.buffers.forEach(n=>{const o={arrayStride:0,stepMode:"vertex",attributes:[]},a=o.attributes;for(const l in t.attributeData){const h=e.attributes[l];(h.divisor??1)!==1&&z(`Attribute ${l} has an invalid divisor value of '${h.divisor}'. WebGPU only supports a divisor value of 1`),h.buffer===n&&(o.arrayStride=h.stride,o.stepMode=h.instance?"instance":"vertex",a.push({shaderLocation:t.attributeData[l].location,offset:h.offset,format:h.format}))}a.length&&r.push(o)}),this._bufferLayoutsCache[s]=r,r}_updatePipeHash(){var e;const t=ux(this._stencilMode,this._multisampleCount===1?0:1,this._colorMask,this._colorTargetCount,this._depthStencilFormatData.index,this._colorFormatId,this._depthReadOnly?1:0,this._invertFrontFace?1:0);this._pipeCache=(e=this._pipeStateCaches)[t]??(e[t]=new Map)}destroy(){this._bufferLayoutsCache=null,this._pipeCache=null,this._gpu=null,this._renderer=null,this._bindingNamesCache=null,this._pipeStateCaches=null,this._moduleCache=null}}Jl.extension={type:[S.WebGPUSystem],name:"pipeline"};class tg{constructor(e){this._pipelines=Object.create(null),this._modules=Object.create(null),this._bindGroups=new WeakMap,this._renderer=e,this._device=e.gpu.device,this._layout=this._device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"unfilterable-float"}}]}),this._pipelineLayout=this._device.createPipelineLayout({bindGroupLayouts:[this._layout]})}copy(e,t,s,r){var n;const o=this._renderer.renderTarget.getGpuRenderTarget(t),a=t.colorAttachments[s].texture;(n=o.msaaBackTextures)[s]??(n[s]=new de({label:"msaa-back-texture",width:a.width,height:a.height,resolution:a._resolution,format:o.msaaTextures[s].format,autoGenerateMipmaps:!1,autoGarbageCollect:!0}));const l=this._renderer.texture.getGpuSource(o.msaaBackTextures[s]);e.copyTextureToTexture({texture:r},{texture:l},{width:Math.min(r.width,l.width),height:Math.min(r.height,l.height)})}draw(e,t,s){var r;const n=this._renderer.renderTarget.getGpuRenderTarget(t),o=this._renderer.texture.getGpuSource(n.msaaBackTextures[s]);let a=t.depthStencilAttachment?.texture.format??"";for(const c of t.colorAttachments)a+=`|${c.texture.format}`;const l=(r=this._pipelines)[a]??(r[a]=[]);let h=this._bindGroups.get(o);h||(h=this._device.createBindGroup({layout:this._layout,entries:[{binding:0,resource:o.createView()}]}),this._bindGroups.set(o,h)),e.setPipeline(l[s]??(l[s]=this._createPipeline(t,s))),e.setBindGroup(0,h),e.draw(3)}_getModule(e){var t;return(t=this._modules)[e]??(t[e]=this._device.createShaderModule({label:"msaa-restore",code:`
895
+ `}function ig(i){return Fl(i,_m,sg)}class tn extends Yr{constructor(){super({createUboElements:tg,generateUboSync:ig})}}tn.extension={type:[S.WebGPUSystem],name:"ubo"};const Gt=128;class eh{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._batchBuffer=new Jm({minUniformOffsetAlignment:Gt});const t=256/Gt;for(let s=0;s<t;s++){let r=ae.UNIFORM|ae.COPY_DST;s===0&&(r|=ae.COPY_SRC),this._buffers.push(new ot({data:this._batchBuffer.data,usage:r}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){this._bindGroupHash=Object.create(null),this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const s=e.buffer.data,r=this._batchBuffer.addEmptyGroup(s.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,r/4),this._bindGroupHash[e.uid]=this._getBindGroup(r/Gt),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,s=this._batchBuffer.addGroup(t);return this._getBufferResource(s/Gt)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/Gt)}getArrayBufferResource(e){const s=this._batchBuffer.addGroup(e)/Gt;return this._getBufferResource(s)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new Mi({buffer:t,offset:(e/2|0)*256,size:Gt})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new Pt({0:this._getBufferResource(e)});this._bindGroups[e]=t}return this._bindGroups[e]}_uploadBindGroups(){const e=this._renderer.buffer,t=this._buffers[0];t.update(this._batchBuffer.byteIndex),e.updateBuffer(t);const s=this._renderer.gpu.device.createCommandEncoder();for(let r=1;r<this._buffers.length;r++){const n=this._buffers[r];s.copyBufferToBuffer(e.getGPUBuffer(t),Gt,e.getGPUBuffer(n),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([s.finish()])}destroy(){for(let e=0;e<this._bindGroups.length;e++)this._bindGroups[e]?.destroy();this._bindGroups=null,this._bindGroupHash=null;for(let e=0;e<this._buffers.length;e++)this._buffers[e].destroy();this._buffers=null;for(let e=0;e<this._bufferResources.length;e++)this._bufferResources[e].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._renderer=null}}eh.extension={type:[S.WebGPUPipes],name:"uniformBatch"};const $c={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4},px=new Rs({}),mx={"depth24plus-stencil8":{depth:!0,stencil:!0,index:1},depth24plus:{depth:!0,stencil:!1,index:2},depth32float:{depth:!0,stencil:!1,index:3},"depth32float-stencil8":{depth:!0,stencil:!0,index:4},depth16unorm:{depth:!0,stencil:!1,index:5},stencil8:{depth:!1,stencil:!0,index:6}},Vc={depth:!1,stencil:!1,index:0};function Do(i,e){for(const[t,s]of Object.entries(e)){const r=new RegExp(`override\\s+${t}\\s*:\\s*(\\w+)\\s*(?:=[^;]*)?;`);i=i.replace(r,(n,o)=>{let a;return o==="u32"?a=`${Math.trunc(s)}u`:o==="i32"?a=`${Math.trunc(s)}`:a=Number.isInteger(s)?`${s}.0`:`${s}`,`const ${t}: ${o} = ${a};`})}return i}function jc(i,e,t,s,r,n){return i*35184372088832+e*536870912+n*16384+(t<<8)+(s<<3)+r}const Xc=Object.create(null);let gx=0;function qc(i){let e=Xc[i];return e===void 0&&(e=Xc[i]=gx++),e}function _x(i,e,t,s,r,n,o,a){return a<<20|n<<16|r<<13|t<<9|i<<6|o<<5|s<<1|e}function yx(i,e,t,s,r,n,o){return o<<11|n<<10|r<<9|s<<8|t<<5|e<<1|i}class th{constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=new Map,this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._colorTargetCount=1,this._colorFormat="bgra8unorm",this._colorFormatId=qc("bgra8unorm"),this._depthStencilFormat="depth24plus-stencil8",this._depthStencilFormatData=Vc,this._depthReadOnly=!1,this._stencilReadOnly=!1,this._invertFrontFace=!1,this._renderer=e}contextChange(e){this._gpu=e,this._moduleCache=Object.create(null),this._pipeStateCaches=Object.create(null),this.setStencilMode(me.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){const t=e.colorAttachments[0]?.texture;this._multisampleCount=t?.source.antialias?4:1,this._colorTargetCount=e.colorAttachments.length,this._colorFormat=t?.format??"bgra8unorm",this._colorFormatId=qc(this._colorFormat),this._depthStencilFormat=e.depthStencilAttachment?.texture.format,this._depthStencilFormatData=mx[this._depthStencilFormat]||Vc,this._depthReadOnly=e.depthStencilAttachment?.depthReadOnly??!1,this._stencilReadOnly=e.depthStencilAttachment?.stencilReadOnly??this._depthReadOnly,this._invertFrontFace=this._renderer.renderTarget.isFrontFaceInverted(e,e.flipY),this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=Bt[e],this._updatePipeHash())}get bundleStateKey(){const e=this._depthStencilFormatData;return yx(this._multisampleCount===1?0:1,this._colorTargetCount,e.index,e.depth&&this._depthReadOnly?1:0,e.stencil&&this._stencilReadOnly?1:0,this._invertFrontFace?1:0,this._colorFormatId)}getBundleDescriptor(){const e=[];for(let r=0;r<this._colorTargetCount;r++)e.push(this._colorFormat);const t={colorFormats:e,sampleCount:this._multisampleCount},s=this._depthStencilFormatData;return(s.depth||s.stencil)&&(t.depthStencilFormat=this._depthStencilFormat,s.depth&&this._depthReadOnly&&(t.depthReadOnly=!0),s.stencil&&this._stencilReadOnly&&(t.stencilReadOnly=!0)),t}setPipeline(e,t,s,r){const n=this.getPipeline(e,t,s);r.setPipeline(n)}getPipelineKey(e,t,s,r,n){return e._layoutKey||(gr(e,t.attributeData),this._generateBufferKey(e)),jc(e._layoutKey,t._layoutKey,s.data,s._blendModeId,$c[r],n.id)}getPipeline(e,t,s,r,n){e._layoutKey||(gr(e,t.attributeData),this._generateBufferKey(e)),r||(r=e.topology),n||(n=px);const o=jc(e._layoutKey,t._layoutKey,s.data,s._blendModeId,$c[r],n.id);let a=this._pipeCache.get(o);return a||(a=this._createPipeline(e,t,s,r,n),this._pipeCache.set(o,a)),a}_createPipeline(e,t,s,r,n){const o=this._gpu.device,a=this._createVertexBufferLayouts(e,t),l=this._renderer.state.getColorTargets(s,this._colorTargetCount,this._colorFormat),h=this._stencilMode===me.RENDERING_MASK_ADD?0:this._colorMask;for(let _=0;_<l.length;_++)l[_].writeMask=h;const c=this._renderer.shader.getProgramData(t).pipeline,u=Object.keys(n.data).length>0;let d=t.vertex.source,f=t.fragment.source,p;u&&(this._renderer.limits.supportsOverrideConstants?p=n.data:(d=Do(d,n.data),f=Do(f,n.data)));const g={vertex:{module:this._getModule(d),entryPoint:t.vertex.entryPoint,constants:p,buffers:a},fragment:{module:this._getModule(f),entryPoint:t.fragment.entryPoint,targets:l,constants:p},primitive:{topology:r,cullMode:s.culling?"back":"none",frontFace:s.clockwiseFrontFace!==this._invertFrontFace?"cw":"ccw"},layout:c,multisample:{count:this._multisampleCount},label:t.name?`PIXI Pipeline (${t.name})`:"PIXI Pipeline"};if(this._depthStencilFormatData.depth||this._depthStencilFormatData.stencil){const _=this._depthStencilFormatData;g.depthStencil={...this._stencilState,format:this._depthStencilFormat,depthWriteEnabled:_.depth?s.depthMask&&!this._depthReadOnly:!1,depthCompare:_.depth&&s.depthTest?"less":"always"}}return o.createRenderPipeline(g)}_getModule(e){return this._moduleCache[e]||this._createModule(e)}_createModule(e){const t=this._gpu.device;return this._moduleCache[e]=t.createShaderModule({code:e}),this._moduleCache[e]}_generateBufferKey(e){const t=[];let s=0;const r=Object.keys(e.attributes).sort();for(let o=0;o<r.length;o++){const a=e.attributes[r[o]];t[s++]=a.offset,t[s++]=a.format,t[s++]=a.stride,t[s++]=a.instance}const n=t.join("|");return e._layoutKey=as(n,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let s=0;const r=Object.keys(e.attributeData).sort();for(let o=0;o<r.length;o++){const a=e.attributeData[r[o]];t[s++]=a.location}const n=t.join("|");return e._attributeLocationsKey=as(n,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const s=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[s])return this._bindingNamesCache[s];const r=this._createVertexBufferLayouts(e,t),n=[],o=t.attributeData;for(let a=0;a<r.length;a++){const h=Object.values(r[a].attributes)[0].shaderLocation;for(const c in o)if(o[c].location===h){n[a]=c;break}}return this._bindingNamesCache[s]=n,n}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const s=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[s])return this._bufferLayoutsCache[s];const r=[];return e.buffers.forEach(n=>{const o={arrayStride:0,stepMode:"vertex",attributes:[]},a=o.attributes;for(const l in t.attributeData){const h=e.attributes[l];(h.divisor??1)!==1&&H(`Attribute ${l} has an invalid divisor value of '${h.divisor}'. WebGPU only supports a divisor value of 1`),h.buffer===n&&(o.arrayStride=h.stride,o.stepMode=h.instance?"instance":"vertex",a.push({shaderLocation:t.attributeData[l].location,offset:h.offset,format:h.format}))}a.length&&r.push(o)}),this._bufferLayoutsCache[s]=r,r}_updatePipeHash(){var e;const t=_x(this._stencilMode,this._multisampleCount===1?0:1,this._colorMask,this._colorTargetCount,this._depthStencilFormatData.index,this._colorFormatId,this._depthReadOnly?1:0,this._invertFrontFace?1:0);this._pipeCache=(e=this._pipeStateCaches)[t]??(e[t]=new Map)}destroy(){this._bufferLayoutsCache=null,this._pipeCache=null,this._gpu=null,this._renderer=null,this._bindingNamesCache=null,this._pipeStateCaches=null,this._moduleCache=null}}th.extension={type:[S.WebGPUSystem],name:"pipeline"};class rg{constructor(e){this._pipelines=Object.create(null),this._modules=Object.create(null),this._bindGroups=new WeakMap,this._renderer=e,this._device=e.gpu.device,this._layout=this._device.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"unfilterable-float"}}]}),this._pipelineLayout=this._device.createPipelineLayout({bindGroupLayouts:[this._layout]})}copy(e,t,s,r){var n;const o=this._renderer.renderTarget.getGpuRenderTarget(t),a=t.colorAttachments[s].texture;(n=o.msaaBackTextures)[s]??(n[s]=new ue({label:"msaa-back-texture",width:a.width,height:a.height,resolution:a._resolution,format:o.msaaTextures[s].format,autoGenerateMipmaps:!1,autoGarbageCollect:!0}));const l=this._renderer.texture.getGpuSource(o.msaaBackTextures[s]);e.copyTextureToTexture({texture:r},{texture:l},{width:Math.min(r.width,l.width),height:Math.min(r.height,l.height)})}draw(e,t,s){var r;const n=this._renderer.renderTarget.getGpuRenderTarget(t),o=this._renderer.texture.getGpuSource(n.msaaBackTextures[s]);let a=t.depthStencilAttachment?.texture.format??"";for(const c of t.colorAttachments)a+=`|${c.texture.format}`;const l=(r=this._pipelines)[a]??(r[a]=[]);let h=this._bindGroups.get(o);h||(h=this._device.createBindGroup({layout:this._layout,entries:[{binding:0,resource:o.createView()}]}),this._bindGroups.set(o,h)),e.setPipeline(l[s]??(l[s]=this._createPipeline(t,s))),e.setBindGroup(0,h),e.draw(3)}_getModule(e){var t;return(t=this._modules)[e]??(t[e]=this._device.createShaderModule({label:"msaa-restore",code:`
896
896
  @group(0) @binding(0) var resolved: texture_2d<f32>;
897
897
 
898
898
  @vertex
@@ -906,12 +906,12 @@ fn mainFragment(
906
906
  fn fragmentMain(@builtin(position) position: vec4<f32>) -> @location(${e}) vec4<f32> {
907
907
  return textureLoad(resolved, vec2<i32>(position.xy), 0);
908
908
  }
909
- `})),this._modules[e]}_createPipeline(e,t){const s=e.depthStencilAttachment?.texture.format;let r;s&&(r={format:s},s.includes("depth")&&(r.depthWriteEnabled=!1,r.depthCompare="always"));const n=this._getModule(t);return this._device.createRenderPipeline({label:"msaa-restore",layout:this._pipelineLayout,vertex:{module:n,entryPoint:"vertexMain"},fragment:{module:n,entryPoint:"fragmentMain",targets:e.colorAttachments.map((o,a)=>({format:o.texture.format,writeMask:a===t?GPUColorWrite.ALL:0}))},depthStencil:r,multisample:{count:4}})}}class sg{constructor(){this.contexts=[],this.canvasTextures=[],this.msaaTextures=[],this.transient=!1,this.msaaSamples=1,this.msaaBackTextures=[],this.stencilMode=me.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}const fx={bgra8unorm:!0,rgba8unorm:!0,rgba16float:!0};function px(i){if(fx[i])return i;const e=navigator.gpu.getPreferredCanvasFormat();return z(`[WebGPU] CanvasSource format '${i}' is not a valid GPUCanvasContext format. Falling back to '${e}'. Allowed formats are: bgra8unorm, rgba8unorm, rgba16float.`),e}class ig{constructor(){this._activePass=null}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this),e.runners.destroy.add(this)}contextChange(){this._msaaRestore=null}destroy(){this._msaaRestore=null}copyToTexture(e,t,s,r,n){const o=this._renderer;this.finishRenderPass();const a=this._getGpuColorTexture(e),l=o.texture.getGpuSource(t.source);return o.encoder.commandEncoder.copyTextureToTexture({texture:a,origin:s},{texture:l,origin:n},r),t}copyDepthTexture(e,t,s,r,n){const o=this._renderer;this.finishRenderPass();const a=e.depthStencilAttachment.texture,l=o.texture.getGpuSource(a),h=o.texture.getGpuSource(t.source),c=o.encoder.commandEncoder===null,u=c?o.gpu.device.createCommandEncoder():o.encoder.commandEncoder;u.copyTextureToTexture({texture:l,origin:s},{texture:h,origin:n},{width:r.width,height:r.height}),c&&o.gpu.device.queue.submit([u.finish()])}startRenderPass(e,t=!0,s,r,n=0,o=0){const l=this._renderTargetSystem.getGpuRenderTarget(e);if(o!==0&&l.msaaTextures?.length)throw new Error("[RenderTargetSystem] Rendering to array layers is not supported with MSAA render targets.");if(n>0&&l.msaaTextures?.length)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");let h=t;typeof h=="boolean"&&(h=h?ye.ALL:ye.NONE),(e.stencil||e.depth)&&!e.depthStencilAttachment&&e.ensureDepthStencilTexture();const c=!!e.depthStencilAttachment,u=this._activePass,d=u!==null&&u.renderTarget===e&&u.mipLevel===n&&u.layer===o&&u.depthStencil===c&&this._renderer.encoder.renderPassEncoder!==null&&h===ye.NONE;if(this._renderer.pipeline.setRenderTarget(e),d){this._renderer.encoder.setViewport(r);return}const{descriptor:f,restore:p}=this._buildDescriptor(e,t,s,n,o);l.descriptor=f;const g=this._renderer.encoder;p?(g.endRenderPass(),this._beginRestoredPass(e,p,g.commandEncoder,()=>g.beginRenderPass(l))):g.beginRenderPass(l),g.setViewport(r),this._activePass={renderTarget:e,mipLevel:n,layer:o,depthStencil:c}}finishRenderPass(){this._renderer.encoder.endRenderPass(),this._activePass=null}_beginRestoredPass(e,t,s,r){const n=this._msaaRestore??(this._msaaRestore=new tg(this._renderer));for(const a of t)n.copy(s,e,a,this._getGpuColorTexture(e,a));const o=r();for(const a of t)n.draw(o,e,a);return o}_getGpuColorTexture(e,t=0){if(e.colorAttachments.length===0)throw new Error("[GpuRenderTargetAdaptor] cannot get gpu color texture from a depth-only render target");const s=e.colorAttachments[t].texture;return s instanceof Ve&&s._gpuContext?s._gpuContext.getCurrentTexture():this._renderer.texture.getGpuSource(s)}getDescriptor(e,t,s,r=0,n=0){return this._buildDescriptor(e,t,s,r,n).descriptor}_buildDescriptor(e,t,s,r=0,n=0){let o=null;typeof t=="boolean"&&(t=t?ye.ALL:ye.NONE);const a=this._renderTargetSystem,l=a.getGpuRenderTarget(e),h=e.colorAttachments.map((d,f)=>{const p=d.texture,g=p instanceof Ve?p._gpuContext:null;let m,_,y=!1;if(g){if(n!==0)throw new Error("[RenderTargetSystem] Rendering to array layers is not supported for canvas targets.");const E=g.getCurrentTexture();y=l.canvasTextures[f]!==E,l.canvasTextures[f]=E,m=E.createView(d.viewDescriptor)}else m=this._renderer.texture.getTextureRenderTargetView(d.texture,r,n,d.viewDescriptor);const x=l.msaaTextures[f];x&&(_=m,m=this._renderer.texture.getTextureView(x));let b=d.loadOp;t!==void 0&&(b=t&ye.COLOR?"clear":"load"),s??(s=a.defaultClearColor);const v=!!x?.transient,w=v&&b!=="clear",T=w&&!y;w&&(b="clear",T&&(o??(o=[])).push(f));const k={view:m,resolveTarget:_,storeOp:v?"discard":d.storeOp??"store",loadOp:b};p.dimension==="3d"&&(k.depthSlice=n),w?k.clearValue=[0,0,0,0]:b==="clear"&&(s??(s=d.clearValue??a.defaultClearColor),k.clearValue=s);for(const E in d)E!=="texture"&&E!=="viewDescriptor"&&E!=="clearValue"&&E!=="loadOp"&&E!=="storeOp"&&(k[E]=d[E]);return k});let c;if(e.depthStencilAttachment){this._prepareDepthStencil(e,l);const d=e.depthStencilAttachment,f=d.texture.format.includes("stencil"),p=d.texture.format.includes("depth"),g=l.transient?"discard":"store",m=l.transient?"clear":"load";c={view:this._renderer.texture.getTextureRenderTargetView(d.texture,r,n,d.viewDescriptor)};const _=d.depthReadOnly??!1,y=d.stencilReadOnly??_;f&&!y?(c.stencilLoadOp=t&ye.STENCIL?"clear":d.stencilLoadOp??m,c.stencilStoreOp=d.stencilStoreOp??g,c.stencilLoadOp==="clear"&&(c.stencilClearValue=d.stencilClearValue??0)):f&&y&&(c.stencilReadOnly=!0),p&&!_?(c.depthLoadOp=t&ye.DEPTH?"clear":d.depthLoadOp??m,c.depthStoreOp=d.depthStoreOp??g,c.depthLoadOp==="clear"&&(c.depthClearValue=d.depthClearValue??1)):p&&_&&(c.depthReadOnly=!0);for(const x in d)x!=="texture"&&x!=="viewDescriptor"&&x!=="stencilLoadOp"&&x!=="stencilStoreOp"&&x!=="stencilClearValue"&&x!=="stencilReadOnly"&&x!=="depthLoadOp"&&x!=="depthStoreOp"&&x!=="depthClearValue"&&x!=="depthReadOnly"&&(c[x]=d[x])}return{descriptor:{colorAttachments:h,depthStencilAttachment:c,label:e.label},restore:o}}clear(e,t=!0,s,r,n=0,o=0){if(!t)return;const{gpu:a,encoder:l}=this._renderer,h=a.device;if(l.commandEncoder===null){const u=h.createCommandEncoder(),{descriptor:d,restore:f}=this._buildDescriptor(e,t,s,n,o),p=()=>u.beginRenderPass(d),g=f?this._beginRestoredPass(e,f,u,p):p();g.setViewport(r.x,r.y,r.width,r.height,0,1),g.end();const m=u.finish();h.queue.submit([m])}else this.startRenderPass(e,t,s,r,n,o)}initGpuRenderTarget(e){e.isRoot=!0;const t=new sg;return t.transient=!!e.colorTexture?.antialias&&!!e.colorTexture.transient,e.colorAttachments.forEach((s,r)=>{const n=s.texture;if(n instanceof Ve){const o=n._gpuContext??(n._gpuContext=n.resource.getContext("webgpu")),a=n.transparent?"premultiplied":"opaque",l=px(n.format);try{o.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:l,alphaMode:a,...l==="rgba16float"?{toneMapping:{mode:"extended"}}:{}})}catch(h){console.error(h)}t.contexts[r]=o}if(t.msaa=n.source.antialias,n.antialias){const o=new de({width:0,height:0,sampleCount:4,autoGenerateMipmaps:!1,transient:this._renderer.device.extensions.tileBased||t.transient,arrayLayerCount:n.arrayLayerCount,format:n.format});t.msaaTextures[r]=o}}),t.msaa&&(t.msaaSamples=4),t}_prepareDepthStencil(e,t){const s=e.depthStencilAttachment?.texture;!s||!t.msaa||(s.sampleCount=4,s.transient=t.transient)}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaBackTextures.forEach(t=>{t?.destroy()}),e.msaaTextures.length=0,e.msaaBackTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){this._prepareDepthStencil(e,this._renderTargetSystem.getGpuRenderTarget(e))}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorAttachments.forEach((s,r)=>{const n=s.texture;t.msaaTextures[r]?.resize(n.width,n.height,n._resolution),t.msaaBackTextures[r]?.resize(n.width,n.height,n._resolution)})}}class eh extends jr{constructor(e){super(e),this.adaptor=new ig,this.adaptor.init(e,this)}}eh.extension={type:[S.WebGPUSystem],name:"renderTarget"};class th{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e,this._gpuProgramData=Object.create(null)}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,s=e.gpuLayout.map(n=>t.createBindGroupLayout({entries:n})),r={bindGroupLayouts:s};return this._gpuProgramData[e._layoutKey]={bindGroups:s,pipeline:t.createPipelineLayout(r)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}th.extension={type:[S.WebGPUSystem],name:"shader"};const Ge={};Ge.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}};Ge.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};Ge.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};Ge.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}};Ge["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}};Ge["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}};Ge.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}};Ge.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}};Ge.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class sh{constructor(){this.defaultState=new pt,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e,t,s){const r=e.blend?Ge[e.blendMode]||Ge.normal:void 0,n=[];for(let o=0;o<t;o++)n[o]={format:s,writeMask:0,blend:r};return n}destroy(){this.gpu=null}}sh.extension={type:[S.WebGPUSystem],name:"state"};const Xc=[new te,new te,new te],rg={type:"image",upload(i,e,t,s=0){const r=i.resource,n=i.pixelWidth|0,o=i.pixelHeight|0,a=i.depthOrArrayLayers,l=r.byteLength/(n*o*a);if(a>1){t.device.queue.writeTexture({texture:e,origin:{x:0,y:0,z:s}},r,{offset:0,rowsPerImage:o,bytesPerRow:n*l},{width:n,height:o,depthOrArrayLayers:a});return}const h=Ul(i._updateStart,i._updateEnd,n,o,Xc);for(let c=0;c<h;c++){const u=Xc[c];t.device.queue.writeTexture({texture:e,origin:{x:u.x,y:u.y,z:s}},r,{offset:(u.y*n+u.x)*l,rowsPerImage:u.height,bytesPerRow:n*l},{width:u.width,height:u.height,depthOrArrayLayers:1})}}},ih={"bc1-rgba-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"bc2-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc3-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc7-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"etc1-rgb-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"etc2-rgba8unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"astc-4x4-unorm":{blockBytes:16,blockWidth:4,blockHeight:4}},mx={blockBytes:4,blockWidth:1,blockHeight:1},ng={type:"compressed",upload(i,e,t,s=0){let r=i.pixelWidth,n=i.pixelHeight;const o=ih[i.format]||mx;for(let a=0;a<i.resource.length;a++){const l=i.resource[a],h=Math.ceil(r/o.blockWidth)*o.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:a,origin:{x:0,y:0,z:s}},l,{offset:0,bytesPerRow:h},{width:Math.ceil(r/o.blockWidth)*o.blockWidth,height:Math.ceil(n/o.blockHeight)*o.blockHeight,depthOrArrayLayers:1}),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}}},qc=["right","left","top","bottom","front","back"];function og(i){return{type:"cube",upload(e,t,s){const r=e.faces;for(let n=0;n<qc.length;n++){const o=qc[n],a=r[o];(i[a.uploadMethodId]||i.image).upload(a,t,s,n)}}}}const rh={type:"image",upload(i,e,t,s=0){const r=i.resource;if(!r)return;if(globalThis.HTMLImageElement&&r instanceof HTMLImageElement){const l=ee.get().createCanvas(r.width,r.height);l.getContext("2d").drawImage(r,0,0,r.width,r.height),i.resource=l,z("ImageSource: Image element passed, converting to canvas and replacing resource.")}const n=Math.min(e.width,i.resourceWidth||i.pixelWidth),o=Math.min(e.height,i.resourceHeight||i.pixelHeight),a=i.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:r},{texture:e,origin:{x:0,y:0,z:s},premultipliedAlpha:a},{width:n,height:o})}},ag={type:"video",upload(i,e,t,s){rh.upload(i,e,t,s)}},Yc=["rgba8unorm","rgba16float"],gs=4;function nh(i,e){if(!e)throw new Error("[Gpu3dMipmapGenerator] generating mipmaps for a 3D texture needs storage: true.");if(!Yc.includes(i))throw new Error(`[Gpu3dMipmapGenerator] format '${i}' can't be downsampled. Use ${Yc.join(", ")}.`)}class lg{constructor(e){this._pipelines={},this._device=e,this._sampler=e.createSampler({magFilter:"linear",minFilter:"linear"})}_getMipmapPipeline(e){var t;return(t=this._pipelines)[e]??(t[e]=this._device.createComputePipeline({layout:"auto",compute:{module:this._device.createShaderModule({code:`
909
+ `})),this._modules[e]}_createPipeline(e,t){const s=e.depthStencilAttachment?.texture.format;let r;s&&(r={format:s},s.includes("depth")&&(r.depthWriteEnabled=!1,r.depthCompare="always"));const n=this._getModule(t);return this._device.createRenderPipeline({label:"msaa-restore",layout:this._pipelineLayout,vertex:{module:n,entryPoint:"vertexMain"},fragment:{module:n,entryPoint:"fragmentMain",targets:e.colorAttachments.map((o,a)=>({format:o.texture.format,writeMask:a===t?GPUColorWrite.ALL:0}))},depthStencil:r,multisample:{count:4}})}}class ng{constructor(){this.contexts=[],this.canvasTextures=[],this.msaaTextures=[],this.transient=!1,this.msaaSamples=1,this.msaaBackTextures=[],this.stencilMode=me.DISABLED,this.stencilReference=0,this.maskStackIndex=0}}const xx={bgra8unorm:!0,rgba8unorm:!0,rgba16float:!0};function bx(i){if(xx[i])return i;const e=navigator.gpu.getPreferredCanvasFormat();return H(`[WebGPU] CanvasSource format '${i}' is not a valid GPUCanvasContext format. Falling back to '${e}'. Allowed formats are: bgra8unorm, rgba8unorm, rgba16float.`),e}class og{constructor(){this._activePass=null}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this),e.runners.destroy.add(this)}contextChange(){this._msaaRestore=null}destroy(){this._msaaRestore=null}copyToTexture(e,t,s,r,n){const o=this._renderer;this.finishRenderPass();const a=this._getGpuColorTexture(e),l=o.texture.getGpuSource(t.source);return o.encoder.commandEncoder.copyTextureToTexture({texture:a,origin:s},{texture:l,origin:n},r),t}copyDepthTexture(e,t,s,r,n){const o=this._renderer;this.finishRenderPass();const a=e.depthStencilAttachment.texture,l=o.texture.getGpuSource(a),h=o.texture.getGpuSource(t.source),c=o.encoder.commandEncoder===null,u=c?o.gpu.device.createCommandEncoder():o.encoder.commandEncoder;u.copyTextureToTexture({texture:l,origin:s},{texture:h,origin:n},{width:r.width,height:r.height}),c&&o.gpu.device.queue.submit([u.finish()])}startRenderPass(e,t=!0,s,r,n=0,o=0){const l=this._renderTargetSystem.getGpuRenderTarget(e);if(o!==0&&l.msaaTextures?.length)throw new Error("[RenderTargetSystem] Rendering to array layers is not supported with MSAA render targets.");if(n>0&&l.msaaTextures?.length)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");let h=t;typeof h=="boolean"&&(h=h?ye.ALL:ye.NONE),(e.stencil||e.depth)&&!e.depthStencilAttachment&&e.ensureDepthStencilTexture();const c=!!e.depthStencilAttachment,u=this._activePass,d=u!==null&&u.renderTarget===e&&u.mipLevel===n&&u.layer===o&&u.depthStencil===c&&this._renderer.encoder.renderPassEncoder!==null&&h===ye.NONE;if(this._renderer.pipeline.setRenderTarget(e),d){this._renderer.encoder.setViewport(r);return}const{descriptor:f,restore:p}=this._buildDescriptor(e,t,s,n,o);l.descriptor=f;const g=this._renderer.encoder;p?(g.endRenderPass(),this._beginRestoredPass(e,p,g.commandEncoder,()=>g.beginRenderPass(l))):g.beginRenderPass(l),g.setViewport(r),this._activePass={renderTarget:e,mipLevel:n,layer:o,depthStencil:c}}finishRenderPass(){this._renderer.encoder.endRenderPass(),this._activePass=null}_beginRestoredPass(e,t,s,r){const n=this._msaaRestore??(this._msaaRestore=new rg(this._renderer));for(const a of t)n.copy(s,e,a,this._getGpuColorTexture(e,a));const o=r();for(const a of t)n.draw(o,e,a);return o}_getGpuColorTexture(e,t=0){if(e.colorAttachments.length===0)throw new Error("[GpuRenderTargetAdaptor] cannot get gpu color texture from a depth-only render target");const s=e.colorAttachments[t].texture;return s instanceof Ve&&s._gpuContext?s._gpuContext.getCurrentTexture():this._renderer.texture.getGpuSource(s)}getDescriptor(e,t,s,r=0,n=0){return this._buildDescriptor(e,t,s,r,n).descriptor}_buildDescriptor(e,t,s,r=0,n=0){let o=null;typeof t=="boolean"&&(t=t?ye.ALL:ye.NONE);const a=this._renderTargetSystem,l=a.getGpuRenderTarget(e),h=e.colorAttachments.map((d,f)=>{const p=d.texture,g=p instanceof Ve?p._gpuContext:null;let m,_,y=!1;if(g){if(n!==0)throw new Error("[RenderTargetSystem] Rendering to array layers is not supported for canvas targets.");const E=g.getCurrentTexture();y=l.canvasTextures[f]!==E,l.canvasTextures[f]=E,m=E.createView(d.viewDescriptor)}else m=this._renderer.texture.getTextureRenderTargetView(d.texture,r,n,d.viewDescriptor);const x=l.msaaTextures[f];x&&(_=m,m=this._renderer.texture.getTextureView(x));let b=d.loadOp;t!==void 0&&(b=t&ye.COLOR?"clear":"load"),s??(s=a.defaultClearColor);const v=!!x?.transient,w=v&&b!=="clear",T=w&&!y;w&&(b="clear",T&&(o??(o=[])).push(f));const k={view:m,resolveTarget:_,storeOp:v?"discard":d.storeOp??"store",loadOp:b};p.dimension==="3d"&&(k.depthSlice=n),w?k.clearValue=[0,0,0,0]:b==="clear"&&(s??(s=d.clearValue??a.defaultClearColor),k.clearValue=s);for(const E in d)E!=="texture"&&E!=="viewDescriptor"&&E!=="clearValue"&&E!=="loadOp"&&E!=="storeOp"&&(k[E]=d[E]);return k});let c;if(e.depthStencilAttachment){this._prepareDepthStencil(e,l);const d=e.depthStencilAttachment,f=d.texture.format.includes("stencil"),p=d.texture.format.includes("depth"),g=l.transient?"discard":"store",m=l.transient?"clear":"load";c={view:this._renderer.texture.getTextureRenderTargetView(d.texture,r,n,d.viewDescriptor)};const _=d.depthReadOnly??!1,y=d.stencilReadOnly??_;f&&!y?(c.stencilLoadOp=t&ye.STENCIL?"clear":d.stencilLoadOp??m,c.stencilStoreOp=d.stencilStoreOp??g,c.stencilLoadOp==="clear"&&(c.stencilClearValue=d.stencilClearValue??0)):f&&y&&(c.stencilReadOnly=!0),p&&!_?(c.depthLoadOp=t&ye.DEPTH?"clear":d.depthLoadOp??m,c.depthStoreOp=d.depthStoreOp??g,c.depthLoadOp==="clear"&&(c.depthClearValue=d.depthClearValue??1)):p&&_&&(c.depthReadOnly=!0);for(const x in d)x!=="texture"&&x!=="viewDescriptor"&&x!=="stencilLoadOp"&&x!=="stencilStoreOp"&&x!=="stencilClearValue"&&x!=="stencilReadOnly"&&x!=="depthLoadOp"&&x!=="depthStoreOp"&&x!=="depthClearValue"&&x!=="depthReadOnly"&&(c[x]=d[x])}return{descriptor:{colorAttachments:h,depthStencilAttachment:c,label:e.label},restore:o}}clear(e,t=!0,s,r,n=0,o=0){if(!t)return;const{gpu:a,encoder:l}=this._renderer,h=a.device;if(l.commandEncoder===null){const u=h.createCommandEncoder(),{descriptor:d,restore:f}=this._buildDescriptor(e,t,s,n,o),p=()=>u.beginRenderPass(d),g=f?this._beginRestoredPass(e,f,u,p):p();g.setViewport(r.x,r.y,r.width,r.height,0,1),g.end();const m=u.finish();h.queue.submit([m])}else this.startRenderPass(e,t,s,r,n,o)}initGpuRenderTarget(e){e.isRoot=!0;const t=new ng;return t.transient=!!e.colorTexture?.antialias&&!!e.colorTexture.transient,e.colorAttachments.forEach((s,r)=>{const n=s.texture;if(n instanceof Ve){const o=n._gpuContext??(n._gpuContext=n.resource.getContext("webgpu")),a=n.transparent?"premultiplied":"opaque",l=bx(n.format);try{o.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:l,alphaMode:a,...l==="rgba16float"?{toneMapping:{mode:"extended"}}:{}})}catch(h){console.error(h)}t.contexts[r]=o}if(t.msaa=n.source.antialias,n.antialias){const o=new ue({width:0,height:0,sampleCount:4,autoGenerateMipmaps:!1,transient:this._renderer.device.extensions.tileBased||t.transient,arrayLayerCount:n.arrayLayerCount,format:n.format});t.msaaTextures[r]=o}}),t.msaa&&(t.msaaSamples=4),t}_prepareDepthStencil(e,t){const s=e.depthStencilAttachment?.texture;!s||!t.msaa||(s.sampleCount=4,s.transient=t.transient)}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaBackTextures.forEach(t=>{t?.destroy()}),e.msaaTextures.length=0,e.msaaBackTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){this._prepareDepthStencil(e,this._renderTargetSystem.getGpuRenderTarget(e))}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorAttachments.forEach((s,r)=>{const n=s.texture;t.msaaTextures[r]?.resize(n.width,n.height,n._resolution),t.msaaBackTextures[r]?.resize(n.width,n.height,n._resolution)})}}class sh extends qr{constructor(e){super(e),this.adaptor=new og,this.adaptor.init(e,this)}}sh.extension={type:[S.WebGPUSystem],name:"renderTarget"};class ih{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e,this._gpuProgramData=Object.create(null)}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,s=e.gpuLayout.map(n=>t.createBindGroupLayout({entries:n})),r={bindGroupLayouts:s};return this._gpuProgramData[e._layoutKey]={bindGroups:s,pipeline:t.createPipelineLayout(r)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}ih.extension={type:[S.WebGPUSystem],name:"shader"};const Ge={};Ge.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}};Ge.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};Ge.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};Ge.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}};Ge["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}};Ge["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}};Ge["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}};Ge.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}};Ge.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}};Ge.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class rh{constructor(){this.defaultState=new _t,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e,t,s){const r=e.blend?Ge[e.blendMode]||Ge.normal:void 0,n=[];for(let o=0;o<t;o++)n[o]={format:s,writeMask:0,blend:r};return n}destroy(){this.gpu=null}}rh.extension={type:[S.WebGPUSystem],name:"state"};const Yc=[new te,new te,new te],ag={type:"image",upload(i,e,t,s=0){const r=i.resource,n=i.pixelWidth|0,o=i.pixelHeight|0,a=i.depthOrArrayLayers,l=r.byteLength/(n*o*a);if(a>1){t.device.queue.writeTexture({texture:e,origin:{x:0,y:0,z:s}},r,{offset:0,rowsPerImage:o,bytesPerRow:n*l},{width:n,height:o,depthOrArrayLayers:a});return}const h=Hl(i._updateStart,i._updateEnd,n,o,Yc);for(let c=0;c<h;c++){const u=Yc[c];t.device.queue.writeTexture({texture:e,origin:{x:u.x,y:u.y,z:s}},r,{offset:(u.y*n+u.x)*l,rowsPerImage:u.height,bytesPerRow:n*l},{width:u.width,height:u.height,depthOrArrayLayers:1})}}},nh={"bc1-rgba-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"bc2-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc3-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc7-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"etc1-rgb-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"etc2-rgba8unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"astc-4x4-unorm":{blockBytes:16,blockWidth:4,blockHeight:4}},vx={blockBytes:4,blockWidth:1,blockHeight:1},lg={type:"compressed",upload(i,e,t,s=0){let r=i.pixelWidth,n=i.pixelHeight;const o=nh[i.format]||vx;for(let a=0;a<i.resource.length;a++){const l=i.resource[a],h=Math.ceil(r/o.blockWidth)*o.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:a,origin:{x:0,y:0,z:s}},l,{offset:0,bytesPerRow:h},{width:Math.ceil(r/o.blockWidth)*o.blockWidth,height:Math.ceil(n/o.blockHeight)*o.blockHeight,depthOrArrayLayers:1}),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}}},Kc=["right","left","top","bottom","front","back"];function hg(i){return{type:"cube",upload(e,t,s){const r=e.faces;for(let n=0;n<Kc.length;n++){const o=Kc[n],a=r[o];(i[a.uploadMethodId]||i.image).upload(a,t,s,n)}}}}const oh={type:"image",upload(i,e,t,s=0){const r=i.resource;if(!r)return;if(globalThis.HTMLImageElement&&r instanceof HTMLImageElement){const l=ee.get().createCanvas(r.width,r.height);l.getContext("2d").drawImage(r,0,0,r.width,r.height),i.resource=l,H("ImageSource: Image element passed, converting to canvas and replacing resource.")}const n=Math.min(e.width,i.resourceWidth||i.pixelWidth),o=Math.min(e.height,i.resourceHeight||i.pixelHeight),a=i.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:r},{texture:e,origin:{x:0,y:0,z:s},premultipliedAlpha:a},{width:n,height:o})}},cg={type:"video",upload(i,e,t,s){oh.upload(i,e,t,s)}},Zc=["rgba8unorm","rgba16float"],bs=4;function ah(i,e){if(!e)throw new Error("[Gpu3dMipmapGenerator] generating mipmaps for a 3D texture needs storage: true.");if(!Zc.includes(i))throw new Error(`[Gpu3dMipmapGenerator] format '${i}' can't be downsampled. Use ${Zc.join(", ")}.`)}class ug{constructor(e){this._pipelines={},this._device=e,this._sampler=e.createSampler({magFilter:"linear",minFilter:"linear"})}_getMipmapPipeline(e){var t;return(t=this._pipelines)[e]??(t[e]=this._device.createComputePipeline({layout:"auto",compute:{module:this._device.createShaderModule({code:`
910
910
  @group(0) @binding(0) var srcSampler : sampler;
911
911
  @group(0) @binding(1) var src : texture_3d<f32>;
912
912
  @group(0) @binding(2) var dst : texture_storage_3d<${e}, write>;
913
913
 
914
- @compute @workgroup_size(${gs}, ${gs}, ${gs})
914
+ @compute @workgroup_size(${bs}, ${bs}, ${bs})
915
915
  fn main(@builtin(global_invocation_id) gid : vec3<u32>) {
916
916
  let dstSize = textureDimensions(dst);
917
917
 
@@ -925,7 +925,7 @@ fn mainFragment(
925
925
 
926
926
  textureStore(dst, gid, textureSampleLevel(src, srcSampler, uv, 0.0));
927
927
  }
928
- `}),entryPoint:"main"}})),this._pipelines[e]}generateMipmap(e){if(e.dimension!=="3d")throw new Error("[Gpu3dMipmapGenerator] generateMipmap expects a 3D texture.");if(e.mipLevelCount<2)return;nh(e.format,(e.usage&GPUTextureUsage.STORAGE_BINDING)!==0);const t=this._getMipmapPipeline(e.format),s=t.getBindGroupLayout(0),r=this._device.createCommandEncoder({label:"Gpu3dMipmapGenerator"}),n=r.beginComputePass();n.setPipeline(t);let o=e.width,a=e.height,l=e.depthOrArrayLayers,h=e.createView({dimension:"3d",baseMipLevel:0,mipLevelCount:1});for(let c=1;c<e.mipLevelCount;c++){o=Math.max(1,o>>1),a=Math.max(1,a>>1),l=Math.max(1,l>>1);const u=e.createView({dimension:"3d",baseMipLevel:c,mipLevelCount:1});n.setBindGroup(0,this._device.createBindGroup({layout:s,entries:[{binding:0,resource:this._sampler},{binding:1,resource:h},{binding:2,resource:u}]})),n.dispatchWorkgroups(Math.ceil(o/gs),Math.ceil(a/gs),Math.ceil(l/gs)),h=u}n.end(),this._device.queue.submit([r.finish()])}}class hg{constructor(e){this._pipelines={},this._device=e,this._sampler=e.createSampler({minFilter:"linear"})}_getMipmapPipeline(e){let t=this._pipelines[e];return t||(this._mipmapShaderModule||(this._mipmapShaderModule=this._device.createShaderModule({code:`
928
+ `}),entryPoint:"main"}})),this._pipelines[e]}generateMipmap(e){if(e.dimension!=="3d")throw new Error("[Gpu3dMipmapGenerator] generateMipmap expects a 3D texture.");if(e.mipLevelCount<2)return;ah(e.format,(e.usage&GPUTextureUsage.STORAGE_BINDING)!==0);const t=this._getMipmapPipeline(e.format),s=t.getBindGroupLayout(0),r=this._device.createCommandEncoder({label:"Gpu3dMipmapGenerator"}),n=r.beginComputePass();n.setPipeline(t);let o=e.width,a=e.height,l=e.depthOrArrayLayers,h=e.createView({dimension:"3d",baseMipLevel:0,mipLevelCount:1});for(let c=1;c<e.mipLevelCount;c++){o=Math.max(1,o>>1),a=Math.max(1,a>>1),l=Math.max(1,l>>1);const u=e.createView({dimension:"3d",baseMipLevel:c,mipLevelCount:1});n.setBindGroup(0,this._device.createBindGroup({layout:s,entries:[{binding:0,resource:this._sampler},{binding:1,resource:h},{binding:2,resource:u}]})),n.dispatchWorkgroups(Math.ceil(o/bs),Math.ceil(a/bs),Math.ceil(l/bs)),h=u}n.end(),this._device.queue.submit([r.finish()])}}class dg{constructor(e){this._pipelines={},this._device=e,this._sampler=e.createSampler({minFilter:"linear"})}_getMipmapPipeline(e){let t=this._pipelines[e];return t||(this._mipmapShaderModule||(this._mipmapShaderModule=this._device.createShaderModule({code:`
929
929
  var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
930
930
  vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
931
931
 
@@ -949,10 +949,24 @@ fn mainFragment(
949
949
  fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
950
950
  return textureSample(img, imgSampler, texCoord);
951
951
  }
952
- `})),t=this._device.createRenderPipeline({layout:"auto",vertex:{module:this._mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this._mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this._pipelines[e]=t),t}generateMipmap(e){if(e.dimension==="3d")throw new Error("[GpuMipmapGenerator] a 3D texture uses Gpu3dMipmapGenerator.");if(e.dimension==="1d")throw new Error("Generating mipmaps for 1d textures is currently unsupported!");const t=this._getMipmapPipeline(e.format);let s=e;const r=e.depthOrArrayLayers||1,n=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const l={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};s=this._device.createTexture(l)}const o=this._device.createCommandEncoder({}),a=t.getBindGroupLayout(0);for(let l=0;l<r;++l){let h=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),c=n?1:0;for(let u=1;u<e.mipLevelCount;++u){const d=s.createView({baseMipLevel:c++,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),f=o.beginRenderPass({colorAttachments:[{view:d,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),p=this._device.createBindGroup({layout:a,entries:[{binding:0,resource:this._sampler},{binding:1,resource:h}]});f.setPipeline(t),f.setBindGroup(0,p),f.draw(3,1,0,0),f.end(),h=d}}if(!n){const l={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r};for(let h=1;h<e.mipLevelCount;++h)o.copyTextureToTexture({texture:s,mipLevel:h-1},{texture:e,mipLevel:h},l),l.width=Math.ceil(l.width/2),l.height=Math.ceil(l.height/2)}return this._device.queue.submit([o.finish()]),n||s.destroy(),e}}class cg{constructor(e){this.textureView=null,this.textureViews=Object.create(null),this.gpuTexture=e}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.textureViews=null,this.gpuTexture=null}}const gx=/^(rgba8|bgra8|bc[1237]-rgba-|etc2-rgb8|etc2-rgb8a1|etc2-rgba8|astc-\d+x\d+-)unorm$/;function _x(i){return gx.test(i)?[`${i}-srgb`]:void 0}function Kc(i){return`${i.format||""}.${i.dimension||""}.${i.aspect||""}.${i.baseMipLevel||0}.${i.mipLevelCount||""}.${i.baseArrayLayer||0}.${i.arrayLayerCount||""}`}const oh=class ug{constructor(e){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=e,e.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new nt({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const t={image:rh,buffer:rg,video:ag,compressed:ng,...ug.uploadExtensions};this._uploads={...t,cube:og(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gpu=e,this._managedTextures.removeAll(),this._gpuSamplers=Object.create(null),this._mipmapGenerator=null,this._mipmap3dGenerator=null}initSource(e){return e._gpuData[this._renderer.uid]?.gpuTexture||this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){e.dimension==="3d"&&nh(e.format,e.storage);const c=Math.max(e.pixelWidth,e.pixelHeight,e.depth);e.mipLevelCount=Math.floor(Math.log2(c))+1}let t,s;e.sampleCount>1?(t=GPUTextureUsage.RENDER_ATTACHMENT,e.transient&&this._renderer.device.extensions.transientAttachment&&(t|=GPUTextureUsage.TRANSIENT_ATTACHMENT)):(t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST,e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC),e.storage&&(t|=GPUTextureUsage.STORAGE_BINDING),s=_x(e.format));const r=ih[e.format]||{blockWidth:1,blockHeight:1},n=Math.ceil(e.pixelWidth/r.blockWidth)*r.blockWidth,o=Math.ceil(e.pixelHeight/r.blockHeight)*r.blockHeight,a={label:e.label,size:{width:n,height:o,depthOrArrayLayers:e.depthOrArrayLayers},format:e.format,viewFormats:s,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},l=this._gpu.device.createTexture(a);return e._gpuData[this._renderer.uid]=new cg(l),this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),l}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onUpdateMipmaps(e){const t=this.getGpuSource(e);if(e.dimension==="3d"){this._mipmap3dGenerator??(this._mipmap3dGenerator=new lg(this._gpu.device)),this._mipmap3dGenerator.generateMipmap(t);return}this._mipmapGenerator??(this._mipmapGenerator=new hg(this._gpu.device)),this._mipmapGenerator.generateMipmap(t)}onSourceUnload(e){e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this)}onSourceResize(e){e._gcLastUsed=this._renderer.gc.now;const t=e._gpuData[this._renderer.uid],s=t?.gpuTexture;s?(s.width!==e.pixelWidth||s.height!==e.pixelHeight)&&(t.destroy(),this._bindGroupHash[e.uid]=null,e._gpuData[this._renderer.uid]=null,this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuTexture||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]||this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new Mt({0:t,1:t.style,2:new rt({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e,t){var s;const r=e.source;r._gcLastUsed=this._renderer.gc.now;let n=r._gpuData[this._renderer.uid];n||(this.initSource(r),n=r._gpuData[this._renderer.uid]);const o=t?Kc(t):0;return(s=n.textureViews)[o]||(s[o]=n.gpuTexture.createView({dimension:r.viewDimension,...t})),n.textureViews[o]}getTextureRenderTargetView(e,t=0,s=0,r){var n;const o=e.source;o._gcLastUsed=this._renderer.gc.now;let a=o._gpuData[this._renderer.uid];a||(this.initSource(o),a=o._gpuData[this._renderer.uid]);const l=o.dimension==="3d";l&&(s=0);let h=s*(o.mipLevelCount||1)+t+1;return r&&(h=`${h}.${Kc(r)}`),(n=a.textureViews)[h]||(n[h]=a.gpuTexture.createView({dimension:l?"3d":"2d",baseMipLevel:t,mipLevelCount:1,baseArrayLayer:s,arrayLayerCount:1,...r})),a.textureViews[h]}generateCanvas(e){const t=this._renderer,s=t.gpu.device.createCommandEncoder(),r=ee.get().createCanvas();r.width=e.source.pixelWidth,r.height=e.source.pixelHeight;const n=r.getContext("webgpu");return n.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:ee.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),s.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:n.getCurrentTexture()},{width:r.width,height:r.height}),t.gpu.device.queue.submit([s.finish()]),r}getPixels(e){const t=this.generateCanvas(e),s=Et.getOptimalCanvasAndContext(t.width,t.height),r=s.context;r.drawImage(t,0,0);const{width:n,height:o}=t,a=r.getImageData(0,0,n,o),l=new Uint8ClampedArray(a.data.buffer);return Et.returnCanvasAndContext(s),{pixels:l,width:n,height:o}}destroy(){this._managedTextures.destroy();for(const e of Object.keys(this._bindGroupHash)){const t=Number(e);this._bindGroupHash[t]?.destroy()}this._renderer=null,this._gpu=null,this._mipmapGenerator=null,this._mipmap3dGenerator=null,this._gpuSamplers=null,this._bindGroupHash=null}};oh.extension={type:[S.WebGPUSystem],name:"texture"};oh.uploadExtensions=Object.create(null);let ah=oh;q.handleByMap(S.TextureUploaderWebGPU,ah.uploadExtensions);class lh{constructor(){this._maxTextures=0}contextChange(e){const t=new rt({uTransformMatrix:{value:new U,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const s=Pr({name:"graphics",bits:[fa,ma(this._maxTextures),sp,Rr]});this.shader=new ft({gpuProgram:s,resources:{localUniforms:t}})}execute(e,t){const s=t.context,r=s.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(s),h=n.encoder;h.setGeometry(a.geometry,r.gpuProgram);const c=n.globalUniforms.bindGroup;h.setBindGroup(0,c,r.gpuProgram);const u=n.renderPipes.uniformBatch.getUniformBindGroup(r.resources.localUniforms,!0);h.setBindGroup(2,u,r.gpuProgram);const d=l.instructions;let f=null;for(let p=0;p<l.instructionSize;p++){const g=d[p];if(g.topology!==f&&(f=g.topology,h.setPipelineFromGeometryProgramAndState(a.geometry,r.gpuProgram,e.state,g.topology,r._overrides)),r.groups[1]=g.bindGroup,!g.gpuBindGroup){const m=g.textures;g.bindGroup=kr(m.textures,m.count,this._maxTextures),g.gpuBindGroup=n.bindGroup.getBindGroup(g.bindGroup,r.gpuProgram,1)}h.setBindGroup(1,g.bindGroup,r.gpuProgram),h.renderPassEncoder.drawIndexed(g.size,1,g.start)}}destroy(){this.shader.destroy(),this.shader=null}}lh.extension={type:[S.WebGPUPipesAdaptor],name:"graphics"};class hh{init(){const e=Pr({name:"mesh",bits:[ii,Ep,Rr]});this._shader=new ft({gpuProgram:e,resources:{uTexture:W.EMPTY._source,uSampler:W.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new U}}}})}execute(e,t){const s=e.renderer;let r=t._shader;if(!r)r=this._shader,r.groups[2]=s.texture.getTextureBindGroup(t.texture);else if(!r.gpuProgram){z("Mesh shader has no gpuProgram",t.shader);return}const n=r.gpuProgram;if(n.autoAssignGlobalUniforms&&(r.groups[0]=s.globalUniforms.bindGroup),n.autoAssignLocalUniforms){const o=e.localUniforms;r.groups[1]=s.renderPipes.uniformBatch.getUniformBindGroup(o,!0)}s.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(),this._shader=null}}hh.extension={type:[S.WebGPUPipesAdaptor],name:"mesh"};const yx=[...Vr,Zl,ql,qr,Yl,jl,ah,eh,th,sh,Jl,Xl,Kl,Vl],xx=[...yl,Ql],bx=[Ka,hh,lh],dg=[],fg=[],pg=[],mg=[];q.handleByNamedList(S.WebGPUSystem,dg);q.handleByNamedList(S.WebGPUPipes,fg);q.handleByNamedList(S.WebGPUPipesAdaptor,pg);q.handleByNamedList(S.WebGPULoader,mg);q.add(...yx,...xx,...bx);class gg extends Ds{constructor(){const e={name:"webgpu",type:Ke.WEBGPU,systems:dg,renderPipes:fg,renderPipeAdaptors:pg,loaders:mg};super(e)}}const vx=Object.freeze(Object.defineProperty({__proto__:null,WebGPURenderer:gg},Symbol.toStringTag,{value:"Module"}));q.add(gu,_u);const wx=Object.freeze(Object.defineProperty({__proto__:null,AbstractRenderer:Ds,AbstractText:ip,AbstractTextSystem:Va,AccessibilitySystem:C_,AlphaMask:jo,AlphaMaskPipe:Ur,Application:ha,ApplicationInitHook:na,BLEND_TO_NPM:jd,BREAKING_SPACES:hp,BREAKING_SPACES_SET:cp,BREAK_AFTER_CHARS:dp,BREAK_AFTER_CHARS_SET:fp,BUFFER_TYPE:oi,BackgroundSystem:Dp,Batch:Yd,BatchGeometry:ef,BatchTextureArray:qd,BatchableGraphics:Gr,BatchableSprite:Or,BatchableText:Tp,Batcher:Qd,BatcherPipe:Lr,BigPool:Se,BindGroup:Mt,BindGroupSystem:Vl,BlendModePipe:Wr,Bounds:Ee,BrowserAdapter:Zu,Buffer:kt,BufferImageSource:gr,BufferResource:Xr,BufferUsage:ce,CLEAR:ye,COLLAPSIBLE_SPACES:up,Cache:qt,CanvasBatchAdaptor:Mp,CanvasColorMaskPipe:Qa,CanvasContextSystem:sl,CanvasFilterSystem:Vf,CanvasGraphicsAdaptor:rl,CanvasGraphicsContextSystem:ep,CanvasGraphicsPipe:Ia,CanvasLimitsSystem:il,CanvasObserver:Zo,CanvasPool:Et,CanvasPoolClass:$f,CanvasRenderTargetAdaptor:Qp,CanvasRenderTargetSystem:xl,CanvasRenderer:im,CanvasRendererTextSystem:ja,CanvasSource:Ve,CanvasStencilMaskPipe:el,CanvasTextGenerator:Yt,CanvasTextMetrics:bt,CanvasTextPipe:$a,CanvasTextSystem:Xa,CanvasTextureSystem:bl,Circle:Sr,Color:ae,ColorMask:Xo,ColorMaskPipe:Ja,Container:_e,CustomRenderPipe:Nr,DEG_TO_RAD:bu,DOMAdapter:ee,DOMPipe:Hf,DefaultBatcher:Ir,DefaultShader:co,Ellipse:Cr,EventBoundary:zf,EventEmitter:Re,EventSystem:Wf,EventsTicker:ct,ExtensionType:S,ExtractSystem:Op,FederatedContainer:ty,FederatedEvent:Gs,FederatedMouseEvent:xi,FederatedPointerEvent:Fe,FederatedWheelEvent:os,FillGradient:je,FillPattern:Fs,Filter:sa,FilterEffect:hi,FilterPipe:Yf,FilterSystem:Kf,GCManagedHash:nt,GCSystem:Hp,GL_FORMATS:pr,GL_TARGETS:Rs,GL_TYPES:ie,GPUTextureGpuData:cg,GenerateTextureSystem:cl,Geometry:Er,GlBackBufferSystem:cm,GlBatchAdaptor:Ya,GlBuffer:rm,GlBufferSystem:vl,GlColorMaskSystem:Cl,GlContextSystem:om,GlEncoderSystem:Ml,GlGeometryGpuData:lm,GlGeometrySystem:Tl,GlGraphicsAdaptor:Wl,GlLimitsSystem:kl,GlMeshAdaptor:$l,GlProgram:ls,GlProgramData:xm,GlRenderTarget:um,GlRenderTargetAdaptor:gm,GlRenderTargetSystem:Gl,GlShaderSystem:Ol,GlStateSystem:Rm,GlStencilSystem:El,GlTexture:Bm,GlTextureSystem:zl,GlUboSystem:Il,GlUniformGroupSystem:Ll,GlobalResourceRegistry:as,GlobalUniformSystem:dl,Gpu3dMipmapGenerator:lg,GpuBatchAdaptor:Ka,GpuBlendModesToPixi:Ge,GpuBufferData:Ym,GpuBufferSystem:jl,GpuColorMaskSystem:Xl,GpuDeviceSystem:qr,GpuEncoderSystem:ql,GpuGraphicsAdaptor:lh,GpuGraphicsContext:Sf,GpuLimitsSystem:Yl,GpuMeshAdapter:hh,GpuMipmapGenerator:hg,GpuMsaaRestore:tg,GpuProgram:Ft,GpuRenderTarget:sg,GpuRenderTargetAdaptor:ig,GpuRenderTargetSystem:eh,GpuShaderSystem:th,GpuStateSystem:sh,GpuStencilModesToPixi:At,GpuStencilSystem:Kl,GpuTextureSystem:ah,GpuUboSystem:Zl,GpuUniformBatchPipe:Ql,Graphics:Pe,GraphicsContext:qe,GraphicsContextRenderData:Cf,GraphicsContextSystem:Fr,GraphicsGpuData:tp,GraphicsPath:dt,GraphicsPipe:Da,HelloSystem:$r,ImageSource:di,InstructionSet:br,LoaderParserPriority:Yo,MaskEffectManager:rr,MaskEffectManagerClass:Ou,MaskFilter:Jf,Matrix:U,NEWLINES:ap,NEWLINES_SET:lp,NEWLINE_MATCH_REGEX:mp,NEWLINE_SPLIT_REGEX:pp,NOOP:Oo,ObservablePoint:Ce,PI_2:yu,PassthroughFilter:qf,PipelineSystem:Jl,Point:he,Polygon:Ts,Pool:Bu,PoolGroupClass:Iu,RAD_TO_DEG:xu,Rectangle:te,RenderBundle:Zm,RenderGroup:nr,RenderGroupPipe:Hr,RenderGroupSystem:al,RenderTarget:ni,RenderTargetSystem:jr,RenderTexture:Ti,RenderableGCSystem:$p,RendererInitHook:oa,RendererType:Ke,ResizePlugin:aa,Resolver:Ko,RoundedRectangle:Mr,STATE_BITS:ta,STENCIL_MODES:me,SVGParser:Lf,SchedulerSystem:fl,ScreenSizeRegistry:Wo,Shader:ft,ShaderOverrides:Es,ShaderStage:fe,ShapePath:Rf,SharedRenderPipes:yl,SharedSystems:Vr,Sprite:ss,SpritePipe:zr,Spritesheet:Vn,State:pt,StencilMask:qo,StencilMaskPipe:tl,SystemRunner:ra,Text:Sp,TextStyle:As,Texture:W,TextureGCSystem:Vp,TextureMatrix:Uo,TexturePool:Te,TexturePoolClass:qu,TextureSource:de,TextureStyle:Dt,TextureView:_m,Ticker:We,TickerListener:qi,TickerPlugin:la,UNIFORM_TO_ARRAY_SETTERS:km,UNIFORM_TO_SINGLE_SETTERS:Mm,UNIFORM_TYPES_MAP:Sd,UNIFORM_TYPES_VALUES:ea,UPDATE_BLEND:vr,UPDATE_COLOR:ui,UPDATE_PRIORITY:is,UPDATE_VISIBLE:ws,UboBatch:Km,UboSystem:Pl,UniformGroup:rt,VERSION:_i,VideoSource:td,ViewContainer:wr,ViewSystem:Yp,ViewableBuffer:ro,WGSL_ALIGN_SIZE_DATA:ai,WGSL_TO_STD40_SIZE:Al,WebGLRenderer:qm,WebGPURenderer:gg,accessibilityTarget:M_,addBits:oo,addMaskBounds:$o,addMaskLocalBounds:Vo,addProgramDefines:pd,appendSVGPath:xo,applyStyleParams:Eo,assertMipmap3dTexture:nh,assignWithIgnore:Yu,autoDetectRenderer:Hd,bakeOverridesIntoSource:Po,bgr2rgb:Zt,blockDataMap:ih,boundsPool:ut,browserExt:gu,buildAdaptiveBezier:Sa,buildAdaptiveQuadratic:Mf,buildArc:Ca,buildArcTo:kf,buildArcToSvg:Ef,buildCircle:Ps,buildContextBatches:Tf,buildEllipse:_f,buildLine:Dr,buildPixelLine:xf,buildPolygon:bf,buildRectangle:vf,buildRoundedRectangle:yf,buildSimpleUvs:gf,buildTriangle:wf,buildUvs:mf,cacheAsTextureMixin:Gu,calculatePathArea:Of,calculateProjection:Kp,canUseNewCanvasBlendModes:Pa,canvasUtils:Y,checkChildrenDidChange:zo,checkForNestedPattern:Df,checkMaxIfStatementsInShader:ua,childrenHelperMixin:Du,cleanArray:Up,cleanHash:Lp,clearList:dr,closePointEps:xa,collapseNewlines:Na,collapseSpaces:Ua,collectRenderablesMixin:Fu,color32BitToUniform:Ga,colorBit:fa,colorBitGl:pa,compareModeToGlCompare:Lm,compileBufferSync:Rl,compileHighShader:sf,compileHighShaderGl:rf,compileHighShaderGlProgram:Ar,compileHighShaderGpuProgram:Pr,compileHooks:ao,compileInputs:lo,compileOutputs:tf,compileShader:Co,convertToList:Xt,copySearchParams:$n,createGlUploadCubeTextureResource:Dm,createGpuUploadCubeTextureResource:og,createIdFromString:rs,createStringVariations:od,createUboElementsSTD40:dm,createUboElementsWGSL:Qm,createUboSyncFunctionSTD40:mm,createUboSyncFunctionWGSL:eg,cullingMixin:Ru,curveEps:uo,defaultFilterVert:jf,defaultValue:Dl,definedProps:Lo,deprecation:H,detectVideoAlphaMode:Ju,earcut:Fd,effectsMixin:Lu,ensureAttributes:fr,ensureIsBuffer:da,ensurePrecision:md,ensureTextOptions:rp,executeInstructions:ur,extensions:q,extractAttributesFromGlProgram:vm,extractAttributesFromGpuProgram:bd,extractStructAndGroups:Yi,extractSubpaths:Ff,extractSvgUrlId:_o,fastCopy:lr,findMixin:Uu,fontStringFromTextStyle:cr,fragmentGPUTemplate:lf,fragmentGlTemplate:cf,generateArraySyncSTD40:pm,generateArraySyncWGSL:Jm,generateGpuLayoutGroups:vd,generateLayoutHash:wd,generateProgram:Cm,generateShaderSyncCode:ym,generateTextureBatchBit:ma,generateTextureBatchBitGl:ga,generateTextureMatrix:wa,generateUniformsSync:Em,getAdjustedBlendModeBlend:no,getAttributeInfoFromFormat:ks,getBatchSamplersUniformGroup:_a,getCanvasBoundingBox:np,getCanvasFillStyle:Js,getCanvasTexture:gl,getCharacterGroups:za,getDefaultUniformValue:Cd,getFastGlobalBoundsMixin:Nu,getGeometryBounds:Jd,getGlTypeFromFormat:am,getGlobalBounds:_r,getGlobalMixin:zu,getGlobalRenderableBounds:Aa,getLocalBounds:xr,getMaxFragmentPrecision:fd,getMaxMiterRatio:Nf,getMaxTexturesPerBatch:Xd,getOrientationOfPoints:ca,getPo2TextureFromSource:Ra,getTestContext:Jo,getTexelRangeRects:Ul,getTextureBatchBindGroup:kr,getUboData:wm,getUniformData:Tm,getUrlExtension:ad,glUploadBufferImageResource:Im,glUploadCompressedTextureResource:Gm,glUploadImageResource:Nl,glUploadVideoResource:Fm,globalUniformsBit:uf,globalUniformsBitGl:df,gpuUploadBufferImageResource:rg,gpuUploadCompressedTextureResource:ng,gpuUploadImageResource:rh,gpuUploadVideoResource:ag,groupD8:Z,hasTagMarkup:La,hasTagStyles:Oa,injectBits:ho,insertVersion:gd,isBreakAfterChar:gp,isBreakingSpace:$e,isCanvasFilterCapable:vo,isIntegerFormat:ir,isMobile:ud,isNewline:bi,isPow2:ts,isRenderingToScreen:Zp,isSafari:Cp,isSingleItem:Wn,isWebGLSupported:Ud,isWebGPUSupported:Nd,loadEnvironmentExtensions:Ad,localUniformBit:ii,localUniformBitGl:Fa,localUniformBitGroup2:sp,logProgramError:Sm,mapCanvasBlendModesToPixi:Rp,mapFormatToGlFormat:Um,mapFormatToGlInternalFormat:Nm,mapFormatToGlType:Hm,mapGlToVertexFormat:bm,mapType:Fl,mapViewDimensionToGlTarget:zm,mapWebGLBlendModesToPixi:Pm,maskFrag:Zf,maskVert:Qf,maskWgsl:To,matrixPool:Ae,measureMixin:$u,measureTaggedText:_p,mipmapScaleModeToGlFilter:Om,multiplyColors:ci,multiplyHexColors:Kt,nextPow2:es,normalizeExtensionPriority:Ks,onRenderMixin:Vu,parseSVGDefinitions:Bf,parseSVGFloatAttribute:ve,parseSVGPath:Wd,parseSVGStyle:Ma,parseTaggedText:op,passthroughFrag:Xf,passthroughWgsl:wo,path:Ms,removeItems:Ho,removeStructAndGroupDuplicates:Td,resourceToTexture:id,roundPixelsBit:Rr,roundPixelsBitGl:Br,roundedShapeArc:Pf,roundedShapeQuadraticCurve:Af,sayHello:zp,scaleModeToGlFilter:ko,setProgramName:_d,shapeBuilders:hs,sortMixin:ju,spritesheetAsset:cd,squaredDistanceToLineSegment:$d,stripVersion:yd,styleAttributes:yo,textureBit:Ep,textureBitGl:Pp,textureFrom:rd,toFillStyle:Gt,toLocalGlobalMixin:Xu,toStrokeStyle:yi,tokenize:Ha,tokenizeTaggedRuns:xp,transformVertices:ya,triangulateWithHoles:ba,trimRight:lt,uboSyncFunctionsSTD40:Bl,uboSyncFunctionsWGSL:fm,uid:oe,uniformParsers:Qt,unsafeEvalSupported:ia,updateQuadBounds:No,updateRenderGroupTransform:Bp,updateRenderGroupTransforms:nl,updateTextBounds:wp,updateTransformAndChildren:ol,updateTransformBackwards:yr,v8_0_0:ue,v8_21_0:ht,v8_22_0:Tu,v8_3_4:wu,validateRenderables:Ip,vertexGPUTemplate:af,vertexGlTemplate:hf,warn:z,warnIgnoredTextureStyle:vp,webworkerExt:_u,wordWrap:bp,wordWrapTaggedLines:yp,wrapModeToGlAddress:Qi},Symbol.toStringTag,{value:"Module"}));function Ji(i){return i.replace(/\\/g,"/").replace(/\/+$/,"")}function Tx(i,e){const t=Ji(i),s=Ji(e.cwd);if(s&&(t===s||t.startsWith(s+"/")))return t.slice(s.length+1)||".";if(e.home){const n=Ji(e.home);if(n&&(t===n||t.startsWith(n+"/")))return"~/"+t.slice(n.length+1)}return t.startsWith("/")?`//ext/${t.slice(t.lastIndexOf("/")+1)}`:t}function Sx(i){const e=Ji(i);return e.slice(e.lastIndexOf("/")+1)}function _g(i){return/(^|\/)(tests?|__tests__|spec|specs)\//i.test(i)||/\.(test|spec)\.[cm]?[jt]sx?$/i.test(i)||/(^|\/)test_[^/]+\.py$/i.test(i)||/_test\.(go|rs|py)$/i.test(i)}var Cx=/\b(vitest|jest|mocha|pytest|py\.test|go\s+test|cargo\s+test|npm\s+test|pnpm\s+test|yarn\s+test|bun\s+test|npx\s+(vitest|jest|playwright)|rspec|phpunit|dotnet\s+test|mvn\s+test|gradle\s+test|make\s+test)\b/,Mx=/\b(tsc|tsup|vite\s+build|webpack|esbuild|rollup|next\s+build|cargo\s+build|go\s+build|make\b(?!\s+test)|npm\s+run\s+build|pnpm\s+(run\s+)?build|yarn\s+build|gradle\s+build|mvn\s+package|docker\s+build)\b/,kx=/\b(npm\s+(i|install|ci)|pnpm\s+(i|install|add)|yarn(\s+add|\s+install)?|pip3?\s+install|poetry\s+(add|install)|cargo\s+add|go\s+get|brew\s+install|apt(-get)?\s+install|bun\s+(i|install|add))\b/,Ex=/\b(grep|rg|ag|ack|find|fd|locate)\b/,Px=/^\s*(cat|head|tail|less|more|bat|wc|stat|jq)\b/;function yg(i){const t=(i.split(/\s*(?:&&|\|\||;|\|)\s*/)[0]??"").trim().split(/\s+/).map(n=>n.replace(/^[({]+/,"")).filter(Boolean);let s=0;for(;s<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s]);)s++;if(t[s]==="cd"&&t.length>s+1){const n=i.split(/\s*&&\s*/)[1];if(n)return yg(n)}return(t[s]??"").replace(/^.*\//,"").slice(0,40)||"sh"}function bs(i){const e=i.replace(/^["']|["']$/g,"").trim();return!e||e.startsWith("-")||e==="/dev/null"||e.includes("$(")||e.startsWith("$")||/^\/dev\//.test(e)||/^&\d/.test(e)?null:e}function Ax(i){const e=new Set;for(const t of i.matchAll(/(?:^|[\s)])\d?>{1,2}\s*([^\s|&;<>]+)/g)){const s=bs(t[1]??"");s&&e.add(s)}for(const t of i.matchAll(/\btee\s+(?:-[a-z]+\s+)*((?:[^\s|&;<>]+\s*)+)/g))for(const s of(t[1]??"").split(/\s+/)){const r=bs(s);r&&e.add(r)}for(const t of i.matchAll(/\bsed\s+-i\S*\s+(.+?)(?=\s*(?:&&|\|\||;|\||$))/g)){const r=((t[1]??"").match(/"[^"]*"|'[^']*'|\S+/g)??[]).filter(n=>!n.startsWith("-")&&!n.startsWith("'")&&!n.startsWith('"')&&!/^s[/|#]/.test(n)&&!/^-e$/.test(n));for(const n of r){const o=bs(n);o&&e.add(o)}}for(const t of i.matchAll(/\b(?:cp|mv)\s+(?:-[a-zA-Z]+\s+)*((?:[^\s|&;<>]+\s+)+)([^\s|&;<>]+)/g)){const s=bs(t[2]??"");s&&e.add(s)}for(const t of i.matchAll(/\btouch\s+((?:[^\s|&;<>]+\s*)+)/g))for(const s of(t[1]??"").split(/\s+/)){const r=bs(s);r&&e.add(r)}return[...e]}function Rx(i){const e=new Set;for(const t of i.split(/\s*(?:&&|\|\||;|\|)\s*/)){const s=t.match(/^\s*(?:cat|head|tail|less|more|bat|wc)\s+(?:-[^\s]+\s+)*((?:[^\s|&;<>]+\s*)+)/);if(s)for(const r of(s[1]??"").split(/\s+/)){const n=bs(r);n&&!/^\d+$/.test(n)&&e.add(n)}}return[...e]}function Bx(i){const e=yg(i),t=Ax(i),s=Rx(i);let r="other";return Cx.test(i)?r="test":Mx.test(i)?r="build":kx.test(i)?r="install":/^\s*git\b/.test(i)||e==="git"||e==="gh"?r="git":t.length?r="write_file":Ex.test(i)&&e!=="cd"?r="search":Px.test(i)&&s.length&&(r="read_file"),{argv0:e,intent:r,writes:t,reads:s}}var ge=i=>i?parseInt(i,10):0;function Ix(i){const e=i.length>2e4?i.slice(-2e4):i;let t=e.match(/Tests\s+(?:(\d+)\s+failed\s*\|\s*)?(\d+)\s+passed(?:\s*\|\s*(\d+)\s+skipped)?/);if(t)return{failed:ge(t[1]),passed:ge(t[2]),...t[3]?{skipped:ge(t[3])}:{},framework:"vitest"};if(t=e.match(/Tests\s+(\d+)\s+failed\s*\((\d+)\)/),t)return{failed:ge(t[1]),passed:Math.max(0,ge(t[2])-ge(t[1])),framework:"vitest"};if(t=e.match(/Tests:\s+(?:(\d+)\s+failed,\s*)?(?:(\d+)\s+skipped,\s*)?(\d+)\s+passed,\s*(?:(\d+)\s+skipped,\s*)?\d+\s+total/),t)return{failed:ge(t[1]),passed:ge(t[3]),...t[2]??t[4]?{skipped:ge(t[2]??t[4])}:{},framework:"jest"};if(t=e.match(/Tests:\s+(\d+)\s+failed,\s*\d+\s+total/),t)return{failed:ge(t[1]),passed:0,framework:"jest"};if(t=e.match(/=+\s*(?:(\d+)\s+failed,?\s*)?(?:(\d+)\s+passed,?\s*)?(?:(\d+)\s+skipped,?\s*)?(?:\d+\s+(?:error|errors|warnings?|deselected|xfailed|xpassed),?\s*)*in\s+[\d.]+s/),t&&(t[1]||t[2]))return{failed:ge(t[1]),passed:ge(t[2]),...t[3]?{skipped:ge(t[3])}:{},framework:"pytest"};if(/^--- (?:PASS|FAIL):/m.test(e)||/^(?:ok|FAIL)\s+\S+\s+(?:[\d.]+s|\(cached\))/m.test(e)){const a=(e.match(/^--- FAIL:/gm)??[]).length||(e.match(/^FAIL\s+\S+\s+[\d.]+s/gm)??[]).length,l=(e.match(/^--- PASS:/gm)??[]).length||(e.match(/^ok\s+\S+/gm)??[]).length;return{failed:a,passed:l,framework:"go"}}if(t=e.match(/test result:\s*\w+\.\s*(\d+)\s+passed;\s*(\d+)\s+failed;\s*(\d+)\s+ignored/),t)return{passed:ge(t[1]),failed:ge(t[2]),skipped:ge(t[3]),framework:"cargo"};const s=e.match(/^\s*(\d+)\s+passing\b/m),r=e.match(/^\s*(\d+)\s+failing\b/m);if(s||r){const a=e.match(/^\s*(\d+)\s+pending\b/m);return{passed:ge(s?.[1]),failed:ge(r?.[1]),...a?{skipped:ge(a[1])}:{},framework:"mocha"}}const n=e.match(/^\s*(\d+)\s+passed\s*\(/m),o=e.match(/^\s*(\d+)\s+failed\b/m);return n||o?{passed:ge(n?.[1]),failed:ge(o?.[1]),framework:"playwright"}:null}var ze=i=>i&&typeof i=="object"?i:{},we=i=>typeof i=="string"?i:void 0,er=i=>i?(i.match(/\n/g)?.length??0)+(i.endsWith(`
953
- `)?0:1):0;function Gx(i){const e=ze(i).structuredPatch;if(!Array.isArray(e))return null;let t=0,s=0;for(const r of e){const n=ze(r).lines;if(Array.isArray(n))for(const o of n)typeof o=="string"&&(o.startsWith("+")?t++:o.startsWith("-")&&s++)}return{added:t,removed:s,hunks:e.length}}function Dx(i){if(typeof i=="string")return i;const e=ze(i),t=[we(e.stdout),we(e.stderr),we(e.output)].filter(s=>!!s);return t.length?t.join(`
954
- `):Array.isArray(i)?i.map(s=>we(ze(s).text)??"").join(`
955
- `):""}function Fx(i){let e=0;for(const t of i.matchAll(/<<-?\s*(['"]?)(\w+)\1[^\n]*\n([\s\S]*?)\n\2(?=\n|$)/g))e+=er(t[3]);return e===0&&/(?:^|[\s)])\d?>{1,2}\s*[^\s|&;<>]+/.test(i)&&!/>\s*\/dev\/null/.test(i)&&(e=1),e}var Ox=new Set(["Grep","Glob","LS","ToolSearch"]),Lx=new Set(["WebSearch","WebFetch"]),Ux=new Set(["TodoWrite","TodoRead","Skill","EnterPlanMode","ExitPlanMode","EnterWorktree","ExitWorktree","NotebookRead","ListAgents","SendMessage","TaskStop","Monitor","ScheduleWakeup","ReportFindings"]);function Zc(i,e){const t=ze(i.input),s=i.response,r=!i.isError&&ze(s).interrupted!==!0,n=a=>Tx(a,e),o=i.durationMs!==void 0?{durationMs:i.durationMs}:{};switch(i.name){case"Read":{const a=we(t.file_path)??we(t.path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:"Read without file_path"}};const l=we(ze(ze(s).file).content);return{bodies:[{kind:"read_file",path:n(a),...l!==void 0?{bytes:l.length}:{}}]}}case"Edit":case"MultiEdit":case"NotebookEdit":{const a=we(t.file_path)??we(t.notebook_path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:`${i.name} without file_path`}};const l=Gx(s)??{added:er(we(t.new_string)??we(t.new_source)),removed:er(we(t.old_string)),hunks:1};return{bodies:[{kind:"edit_file",path:n(a),...l}]}}case"Write":{const a=we(t.file_path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:"Write without file_path"}};const l=ze(s),h=l.type==="create"||l.type===void 0&&l.originalFile===null;return{bodies:[{kind:"write_file",path:n(a),added:er(we(t.content)),created:h}]}}case"Bash":{const a=we(t.command)??"",l=Bx(a),h=[...new Set([...l.writes,...l.reads].map(n))],c=[{kind:"run_command",argv0:l.argv0,intent:l.intent,touched:h,ok:r,...o}],u=Fx(a);l.writes.forEach((d,f)=>c.push({kind:"write_file",path:n(d),added:f===0?u:0,created:!1}));for(const d of l.reads)c.push({kind:"read_file",path:n(d)});if(l.intent==="test"){const d=Ix(Dx(s));d?c.push({kind:"test_result",ok:d.failed===0&&r,passed:d.passed,failed:d.failed,...d.skipped!==void 0?{skipped:d.skipped}:{},framework:d.framework,...o}):c.push({kind:"test_result",ok:r,passed:0,failed:0,framework:"unknown",...o})}return{bodies:c}}case"Agent":case"Task":{const a=ze(s),l=we(a.agentId)??we(a.agent_id)??"",h=we(t.description)??we(t.subagent_type),c={kind:"subagent_start",childId:l,...h?{label:h}:{}};return a.status==="async_launched"||a.isAsync===!0?{bodies:[c],pendingSubagent:{childId:l}}:{bodies:[c,{kind:"subagent_stop",childId:l,ok:r}]}}case"AskUserQuestion":return{bodies:[{kind:"waiting_for_user",reason:"question"}]}}if(Ox.has(i.name)){const a=ze(s).numFiles??ze(s).numLines??ze(s).count;return{bodies:[{kind:"search",scope:"repo",...typeof a=="number"?{hits:a}:{}}]}}return Lx.has(i.name)?{bodies:[{kind:"search",scope:"web"}]}:Ux.has(i.name)?{bodies:[]}:{bodies:[{kind:"run_command",argv0:i.name.slice(0,40),intent:"other",touched:[],ok:r,...o}],warning:{code:"unknown_tool",detail:i.name.slice(0,80)}}}var Nx=[/\ball (?:\d+ )?tests? (?:are )?pass(?:ing|ed)?\b/i,/\btests? (?:are |is )?(?:now )?(?:passing|green)\b/i,/\b(?:is|are|it's|that's|everything(?:'s| is)) (?:now )?(?:fixed|working|done|complete|resolved)\b/i,/\bshould (?:now )?work\b/i,/\bworks now\b/i,/\b(?:done|complete|completed|fixed|resolved|shipped|implemented)[.!]/i,/✅/],Hx=[/\bnot (?:yet )?(?:done|fixed|working|tested|verified|complete)\b/i,/\bstill (?:fail|broken|not)/i,/\b(?:could ?n[’']?t|cannot|can ?not|unable to|wasn[’']?t able)\b/i,/\bfail(?:ed|ing|s)\b/i,/\bTODO\b/,/\bhaven[’']?t (?:run|tested|verified|checked)/i,/\buntested\b/i,/\bI did not (?:run|test|verify)/i],Qc=600;function Jc(i){if(!i)return!1;const e=i.length>Qc?i.slice(-Qc):i;return Hx.some(t=>t.test(e))?!1:Nx.some(t=>t.test(e))}var zx=new Set(["user","assistant","system"]),$i=i=>i&&typeof i=="object"?i:{},be=i=>typeof i=="string"?i:void 0;function Wx(i,e={}){const t=[],s=[],r=i.split(/\r?\n/);for(let o=0;o<r.length;o++){const a=r[o];if(a.trim())try{t.push(JSON.parse(a))}catch{s.push({code:"bad_json",detail:`line ${o+1}`,line:o+1})}}const n=$x(t,e);return{events:n.events,warnings:[...s,...n.warnings]}}function $x(i,e={}){const t=[],s=[],r=new Set,n=new Map,o=new Map;let a="",l="",h,c=Number.NaN,u=Number.NaN,d="",f=0,p=!1;const g=()=>({cwd:l,...e.home?{home:e.home}:{}}),m=(x,b,v,w={})=>{t.push({id:b,seq:f++,ts:x,sessionId:a,source:"transcript",...w,...v})},_=x=>{const b=be(x.timestamp),v=b?Date.parse(b):Number.NaN;return Number.isFinite(v)?v:Number.isFinite(u)?u:0},y=x=>be(x.agentId)??(x.isSidechain===!0?e.sidechainAgentId??"sidechain":void 0);for(const x of i){const b=$i(x),v=be(b.type)??"";if(!zx.has(v)){v&&r.add(v);continue}!a&&be(b.sessionId)&&(a=be(b.sessionId)),!l&&be(b.cwd)&&(l=be(b.cwd)),!h&&be(b.gitBranch)&&(h=be(b.gitBranch));const w=_(b);Number.isFinite(c)||(c=w,m(w,`${a||"session"}:start`,{kind:"session_start",repoId:Sx(l)||"repo",...h?{branch:h}:{}})),u=w;const T=y(b),k=$i(b.message),E=k.content;if(v==="system"){if(b.subtype==="api_error"){const M=typeof b.retryAttempt=="number"?b.retryAttempt:0,B=typeof b.maxRetries=="number"?b.maxRetries:0;m(w,be(b.uuid)??`sys:${f}`,{kind:"error",where:"api",retrying:M<B},T?{agentId:T}:{})}continue}if(v==="assistant"){const M=Array.isArray(E)?E:[];for(const B of M){const G=$i(B);if(G.type==="tool_use"&&be(G.id)&&be(G.name))n.set(be(G.id),{name:be(G.name),input:G.input,ts:w,...T?{agentId:T}:{}});else if(G.type==="text"&&!T){const O=be(G.text);O&&(d=O)}}typeof E=="string"&&!T&&(d=E),k.stop_reason==="end_turn"&&!T&&m(w,`${be(b.uuid)??f}:turn`,{kind:"turn_end",claimedSuccess:Jc(d)});continue}b.toolDenialKind!==void 0&&m(w,`${be(b.uuid)??f}:deny`,{kind:"waiting_for_user",reason:"permission"});const A=Array.isArray(E)?E:[];for(const M of A){const B=$i(M);if(B.type!=="tool_result")continue;const G=be(B.tool_use_id);if(!G)continue;const O=n.get(G);if(!O){s.push({code:"unpaired_result",detail:G});continue}n.delete(G);const I=b.toolUseResult??B.content,P=Zc({name:O.name,input:O.input,response:I,isError:B.is_error===!0,durationMs:Math.max(0,w-O.ts)},g());P.warning&&s.push(P.warning);const C=O.agentId??T,D=C?o.get(C):void 0,R={...C?{agentId:C}:{},...D?{parentId:D}:{}};P.bodies.forEach((L,N)=>m(O.ts,N===0?G:`${G}:${N}`,L,R)),P.pendingSubagent&&o.set(P.pendingSubagent.childId,G)}A.length===0&&typeof E=="string"&&/\[Request interrupted by user/i.test(E)&&m(w,`${be(b.uuid)??f}:interrupt`,{kind:"waiting_for_user",reason:"idle"})}for(const[x,b]of n){s.push({code:"unpaired_result",detail:`tool_use ${x} (${b.name}) has no result`});const v=Zc({name:b.name,input:b.input,isError:!0},g());v.warning&&s.push(v.warning),v.bodies.forEach((w,T)=>m(b.ts,T===0?x:`${x}:${T}`,w,b.agentId?{agentId:b.agentId}:{}))}for(const[x,b]of o)m(u,`${b}:stop`,{kind:"subagent_stop",childId:x,ok:!0},{parentId:b});for(const x of r)s.push({code:"unknown_row_type",detail:x});return Number.isFinite(c)&&!p&&(p=!0,m(u,`${a||"session"}:end`,{kind:"session_end",reason:"stop",claimedSuccess:Jc(d)})),{events:t,warnings:s}}function Ao(i){let e=2166136261;for(let t=0;t<i.length;t++)e^=i.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0}function li(i){let e=i>>>0;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}var Vx=/(^|\/)(schema\.(sql|prisma|graphql|gql)|.*\.(sql|prisma|db|sqlite)|migrations?\/|drizzle\/|models?\/.*\.(ts|js|py|rb)$)/i,jx=/(^|\/)(node_modules|\.git|dist|build|out|coverage|_site|\.next|\.turbo|target|vendor|__pycache__|\.venv|venv)(\/|$)|(^|\/)\.[^/]+$|\.(lock|map|min\.js|png|jpg|jpeg|gif|webp|svg|ico|woff2?|ttf|mp4|mp3|pdf|zip)$/i;function Xx(i){return jx.test(i)}function xg(i){return _g(i)?"beacon":Vx.test(i)?"archive":"building"}function eu(i){return typeof i.loc=="number"?i.loc:typeof i.size=="number"?Math.max(1,Math.round(i.size/40)):1}function qx(i,e){const t=i.filter(n=>!Xx(n.path)),s=Math.max(1,...t.map(eu)),r=Math.max(1,...t.map(n=>n.churn??0));return t.map(n=>{const o=eu(n),a=e.has(n.path),l=.5*Math.sqrt(o/s)+.3*((n.churn??0)/r)+(a?.2:0);return{file:n,loc:o,score:l,kind:xg(n.path),touched:a}})}function tu(i,e){const t=Math.sqrt(i/Math.max(1,e));return Math.max(1,Math.min(5,Math.ceil(t*5)))}function su(i){return i>=5?3:i>=3?2:1}var Yx={ts:"TypeScript",tsx:"TypeScript",js:"JavaScript",jsx:"JavaScript",mjs:"JavaScript",py:"Python",go:"Go",rs:"Rust",java:"Java",kt:"Kotlin",swift:"Swift",rb:"Ruby",php:"PHP",cs:"C#",cpp:"C++",cc:"C++",c:"C",h:"C",m:"Objective-C",scala:"Scala",ex:"Elixir",exs:"Elixir",dart:"Dart",lua:"Lua",zig:"Zig",sh:"Shell",sql:"SQL",md:"Markdown",mdx:"Markdown",html:"HTML",css:"CSS",scss:"CSS",vue:"Vue",svelte:"Svelte",tf:"Terraform",yaml:"YAML",yml:"YAML",ipynb:"Notebook"};function Kx(i,e={}){const t=i.map(p=>p.path.toLowerCase()),s=p=>t.some(g=>p.test(g)),r=p=>t.filter(g=>p.test(g)).length,n=new Map;for(const p of t){const g=p.slice(p.lastIndexOf(".")+1),m=Yx[g];m&&!/^(markdown|yaml|html|css|shell|sql)$/i.test(m)&&n.set(m,(n.get(m)??0)+1)}const o=[...n.entries()].sort((p,g)=>g[1]-p[1]).map(([p])=>p).slice(0,4),a=(e["package.json"]??"").toLowerCase(),l=((e["pyproject.toml"]??"")+(e["requirements.txt"]??"")).toLowerCase(),h=p=>p.test(a)||p.test(l),c=new Map,u=(p,g)=>c.set(p,(c.get(p)??0)+g);h(/"(react|react-dom|next|vue|nuxt|svelte|@sveltejs\/kit|@angular\/core|solid-js|astro|remix|vite)"/)&&u("web-frontend",3),r(/\.(tsx|jsx|vue|svelte)$/)>3&&u("web-frontend",2),(s(/(^|\/)(index|app)\.html$/)||r(/\.(css|scss)$/)>3)&&u("web-frontend",1),h(/"(express|fastify|hono|koa|@nestjs\/core|apollo-server|prisma|drizzle-orm|django|flask|fastapi|sqlalchemy|gin|fiber|actix|axum|rails|spring)"/)&&u("backend-api",3),(s(/(^|\/)(routes?|controllers?|api|handlers?|migrations?)\//)||s(/\.(sql|prisma)$/))&&u("backend-api",2),(a.includes('"bin"')||s(/(^|\/)(cli|cmd|bin)\//)||h(/"(commander|yargs|clap|cobra|click|typer)"/))&&u("cli-tool",3),(h(/"(torch|tensorflow|jax|pandas|numpy|scikit-learn|sklearn|transformers|xgboost|lightgbm|polars)"/)||r(/\.ipynb$/)>0||s(/(^|\/)(notebooks?|models?|datasets?|training)\//))&&u("data-ml",3),(s(/\.(swift|kt)$/)||s(/(^|\/)(ios|android)\//)||s(/package\.swift$/)||s(/build\.gradle(\.kts)?$/)||h(/"(react-native|expo|flutter)"/)||s(/\.dart$/))&&u("mobile",3),(s(/\.(unity|unitypackage|godot|tscn|gd)$/)||s(/(^|\/)assets\/.*\.(prefab|fbx)$/)||h(/"(phaser|pixi\.js|three|babylonjs|@react-three\/fiber|excalibur|kaplay|bevy|godot)"/))&&u("game",3),(s(/\.tf$/)||s(/(^|\/)(dockerfile|docker-compose\.ya?ml|helm|k8s|kubernetes|\.github\/workflows|ansible|pulumi)/))&&u("infra-devops",s(/\.tf$/)||s(/(^|\/)(helm|k8s|kubernetes|ansible|pulumi)\//)?3:1);const d=r(/\.(md|mdx|rst)$/)/Math.max(1,t.length);(d>.4||s(/(^|\/)(mkdocs|docusaurus)\.config|(^|\/)docs\/.*\.mdx?$/)&&d>.25)&&u("docs-content",3),(s(/(^|\/)pnpm-workspace\.ya?ml$/)||s(/(^|\/)packages\/[^/]+\/package\.json$/)||s(/(^|\/)(lerna|nx|turbo)\.json$/)||s(/(^|\/)cargo\.toml$/)&&r(/(^|\/)crates\/[^/]+\//)>0)&&u("monorepo",2),r(/\.(rs|go|c|cpp|cc|h|zig)$/)>5&&!c.has("web-frontend")&&u("systems",2),a.includes('"main"')&&!a.includes('"bin"')&&!c.has("web-frontend")&&!c.has("backend-api")&&u("library",2),s(/(^|\/)(lib|src\/lib)\//)&&!c.has("web-frontend")&&u("library",1);const f=[...c.entries()].filter(([,p])=>p>=2).sort((p,g)=>g[1]-p[1]).map(([p])=>p);return{kinds:f.length?f:["unknown"],languages:o,files:i.length}}function Zx(i){const e=i.cap??60,t=i.beaconCap??8,s=i.touchedCap??48,r=new Set((i.touched??[]).map(iu).slice(0,s)),n=Ao(i.repoId),o=li(n),a=i.files.map(C=>({...C,path:iu(C.path)})),l=qx(a,r),h=Math.max(1,...l.map(C=>C.loc)),c=[...l].sort((C,D)=>D.score-C.score||C.file.path.localeCompare(D.file.path)),u=ou(c.filter(C=>C.kind==="beacon"),t),d=ou(c.filter(C=>C.kind!=="beacon"),e),f=[...d,...u],p=f.length<l.length,g=new Map;for(const C of d){const D=An(C.file.path);(g.get(D)??g.set(D,[]).get(D)).push(C)}const m=[...g.keys()].sort(),_=new Set,y=[],x=[],b={id:"forge",kind:"forge",path:"",label:"forge",district:"",gx:-1,gy:-1,footprint:2,height:2,score:0,touched:!1};y.push(b);const v=i.layout??vi[n%vi.length],w=o()*Math.PI*2,T=m.map(C=>{const D=g.get(C).sort((N,se)=>se.score-N.score||N.file.path.localeCompare(se.file.path)),R=D.reduce((N,se)=>N+su(tu(se.loc,h))**2,0),L=Math.max(3,Math.ceil(Math.sqrt(R*1.45)));return{name:C,items:D,side:L}}),k=[],E={x:-2,y:-2,w:4,h:4},A=Sg(v,T.map(C=>C.side),E,w,o);k.push(E,...A);const M=Cg(v,A);b.gx=M[0],b.gy=M[1],_.clear(),Tt(_,b),T.forEach((C,D)=>{const R=A[D],L={id:`d:${C.name}`,label:C.name===""?"/":`${C.name}/`,bounds:R,cx:R.x+Math.floor(R.w/2),cy:R.y+Math.floor(R.h/2),placeIds:[]};for(const N of C.items){const se=tu(N.loc,h),Q=su(se),re=Ro(_,L.cx,L.cy,Q,R),j={id:`p:${N.file.path}`,kind:N.kind,path:N.file.path,label:ru(N.file.path),district:L.id,gx:re[0],gy:re[1],footprint:Q,height:se,score:nu(N.score),touched:N.touched};Tt(_,j),y.push(j),L.placeIds.push(j.id)}x.push(L)}),Math.ceil(wg(k));for(const C of k)for(let D=C.x-1;D<C.x+C.w+1;D++)for(let R=C.y-1;R<C.y+C.h+1;R++)_.add(`${D},${R}`);for(const C of u){const D=x.find(N=>N.id===`d:${An(C.file.path)}`),R=D?kg(_,D,b,1):wi(_,b.gx+1,b.gy+1,o()*Math.PI*2,4,1),L={id:`p:${C.file.path}`,kind:"beacon",path:C.file.path,label:ru(C.file.path),district:D?.id??"",gx:R[0],gy:R[1],footprint:1,height:4,score:nu(C.score),touched:C.touched};Tt(_,L),y.push(L),D?.placeIds.push(L.id)}const B=wi(_,b.gx+1,b.gy+1,w+Math.PI,5,2),G={id:"dock",kind:"dock",path:"",label:"dock",district:"",gx:B[0],gy:B[1],footprint:2,height:1,score:0,touched:!1};Tt(_,G),y.push(G);const O=Mg(v,x,b,G);if(p)for(const C of x){const D=C.id.slice(2),R=l.filter(se=>se.kind!=="beacon"&&An(se.file.path)===D).length;if(R<=C.placeIds.length)continue;const L=Ro(_,C.cx,C.cy,1,C.bounds),N={id:`p:${D?D+"/":""}…`,kind:"overflow",path:`${D?D+"/":""}…`,label:`+${R-C.placeIds.length} more`,district:C.id,gx:L[0],gy:L[1],footprint:1,height:2,score:0,touched:!1};Tt(_,N),y.push(N),C.placeIds.push(N.id)}const I=Tg(y,2),P=Kx(a,i.manifests??{});return{repoId:i.repoId,seed:n,layout:v,profile:P,districts:x,places:y,paths:O,bounds:I,stats:{files:l.length,placed:f.length,capped:p}}}var iu=i=>i.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""),ru=i=>i.slice(i.lastIndexOf("/")+1),An=i=>i.includes("/")?i.slice(0,i.indexOf("/")):"",nu=i=>Math.round(i*1e3)/1e3;function ou(i,e){const t=i.filter(r=>r.touched),s=i.filter(r=>!r.touched);return[...t,...s.slice(0,Math.max(0,e-t.length))]}function au(i,e,t){return i.x<e.x+e.w+t&&e.x<i.x+i.w+t&&i.y<e.y+e.h+t&&e.y<i.y+i.h+t}function bg(i,e,t){const s=[];for(let r=0;r<t;r++)for(let n=0;n<t;n++)s.push(`${i+r},${e+n}`);return s}function vg(i,e,t,s){return bg(e,t,s).every(r=>!i.has(r))}function Tt(i,e){for(const t of bg(e.gx,e.gy,e.footprint))i.add(t)}function Ro(i,e,t,s,r){let n=0,o=0,a=0,l=-1,h=null;for(let c=0;c<4096;c++){const u=e+n-Math.floor(s/2),d=t+o-Math.floor(s/2);if(vg(i,u,d,s)){if(u>=r.x-1&&d>=r.y-1&&u+s<=r.x+r.w+1&&d+s<=r.y+r.h+1)return[u,d];if(h??=[u,d],c>600)return h}(n===o||n<0&&n===-o||n>0&&n===1-o)&&([a,l]=[-l,a]),n+=a,o+=l}return h??[e,t]}function wg(i){return Math.max(...i.map(e=>Math.max(Math.abs(e.x),Math.abs(e.x+e.w),Math.abs(e.y),Math.abs(e.y+e.h))))}function Tg(i,e){const t=i.flatMap(o=>[o.gx,o.gx+o.footprint]),s=i.flatMap(o=>[o.gy,o.gy+o.footprint]),r=Math.min(...t)-e,n=Math.min(...s)-e;return{x:r,y:n,w:Math.max(...t)+e-r,h:Math.max(...s)+e-n}}var vi=["ring","grid","strip","scatter","terrace","spine"];function Sg(i,e,t,s,r){const n=e.length,o=[],a=Math.max(3,...e),l=c=>!au(t,c,1)&&!o.some(u=>au(u,c,1)),h=(c,u,d)=>{const f={x:c,y:u,w:d,h:d};return o.push(f),f};switch(i){case"grid":{const c=Math.max(2,Math.ceil(Math.sqrt(n+1))),u=[];let d=0,f=0;for(;f<n;){const m=e.slice(f,f+c),_=Math.max(...m)+2;let y=0;for(const x of m)u.push({x:y,y:d}),y+=x+2;d+=_,f+=c}const p=Math.max(...u.map((m,_)=>m.x+e[_])),g=d;for(let m=0;m<n;m++){let _={x:u[m].x-Math.round(p/2),y:u[m].y-Math.round(g/2),w:e[m],h:e[m]};for(;!l(_);)_={..._,x:_.x+1};o.push(_)}return o}case"strip":{const c=e.reduce((d,f)=>d+f+2,0);let u=Math.round(-c/2)+6;for(let d=0;d<n;d++){const f=Math.round((r()-.5)*3);h(u,f-Math.floor(e[d]/2),e[d]),u+=e[d]+2}return o}case"terrace":{let c=-Math.round(n*(a+1)/2),u=-Math.round(n*(a+1)*.3);for(let d=0;d<n;d++)h(c,u,e[d]),c+=e[d]+1,u+=Math.round(e[d]*.6)+1;return o}case"spine":{let c=-Math.round(n*(a+2)/4);for(let u=0;u<n;u++){const d=u%2===0;h(d?-e[u]-3:3,c,e[u]),d||(c+=a+2)}return o}case"scatter":{for(let c=0;c<n;c++){let u=5+a,d=!1;for(let f=0;f<400&&!d;f++){const p=s+r()*Math.PI*2,g=u*(.5+r()*.7),m={x:Math.round(Math.cos(p)*g),y:Math.round(Math.sin(p)*g*.8),w:e[c],h:e[c]};l(m)&&(o.push(m),d=!0),f%40===39&&(u+=2)}d||h(u+c*2,0,e[c])}return o}default:{let c=3;for(let u=0;u<n;u++){const d=e[u],f=s+u/Math.max(1,n)*Math.PI*2;let p=c+d/2,g;for(;;){const m=Math.round(Math.cos(f)*p),_=Math.round(Math.sin(f)*p*.8);if(g={x:m-Math.floor(d/2),y:_-Math.floor(d/2),w:d,h:d},l(g))break;p+=1}o.push(g),c=Math.max(c,p-d/2)}return o}}}function Cg(i,e){if(!e.length)return[-1,-1];const t=Math.min(...e.map(r=>r.x)),s=Math.min(...e.map(r=>r.y));switch(i){case"strip":return[t-5,-1];case"terrace":return[t-5,s-1];case"spine":return[-1,s-5];default:return[-1,-1]}}function Mg(i,e,t,s){const r=[t.gx+1,t.gy+1],n=[];if(i==="strip"||i==="terrace"){const o=[...e].sort((h,c)=>h.cx-c.cx||h.cy-c.cy);let a=r,l="forge";for(const h of o)n.push({from:l,to:h.id,points:[a,[h.cx,h.cy]]}),a=[h.cx,h.cy],l=h.id}else if(i==="grid"||i==="spine")for(const o of e)n.push({from:o.id,to:"forge",points:[[o.cx,o.cy],[o.cx,r[1]],r]});else for(const o of e)n.push({from:o.id,to:"forge",points:[[o.cx,o.cy],[Math.round((o.cx+r[0])/2),Math.round((o.cy+r[1])/2)],r]});return n.push({from:"dock",to:"forge",points:[[s.gx,s.gy],r]}),n}function Qx(i,e){if(i.layout===e)return i;const t=i.seed,s=li(t^1374496523^vi.indexOf(e)),r=new Set,n=[],o={...i.places.find(y=>y.kind==="forge"),gx:-1,gy:-1};n.push(o);const a=s()*Math.PI*2,h=i.districts.map(y=>({d:y,items:i.places.filter(x=>x.district===y.id&&(x.kind==="building"||x.kind==="archive"||x.kind==="overflow")).sort((x,b)=>b.score-x.score||x.path.localeCompare(b.path))})).map(y=>{const x=y.items.reduce((b,v)=>b+v.footprint**2,0);return{...y,side:Math.max(3,Math.ceil(Math.sqrt(x*1.45)))}}),c={x:-2,y:-2,w:4,h:4},u=Sg(e,h.map(y=>y.side),c,a,s),d=[c,...u],f=Cg(e,u);o.gx=f[0],o.gy=f[1],Tt(r,o);const p=h.map((y,x)=>{const b=u[x],v={...y.d,bounds:b,cx:b.x+Math.floor(b.w/2),cy:b.y+Math.floor(b.h/2),placeIds:[]};for(const w of y.items){const T=Ro(r,v.cx,v.cy,w.footprint,b),k={...w,gx:T[0],gy:T[1]};Tt(r,k),n.push(k),v.placeIds.push(k.id)}return v});Math.ceil(wg(d));for(const y of d)for(let x=y.x-1;x<y.x+y.w+1;x++)for(let b=y.y-1;b<y.y+y.h+1;b++)r.add(`${x},${b}`);for(const y of i.places.filter(x=>x.kind==="beacon")){const x=p.find(w=>w.id===y.district),b=x?kg(r,x,o,1):wi(r,o.gx+1,o.gy+1,s()*Math.PI*2,4,1),v={...y,gx:b[0],gy:b[1]};Tt(r,v),n.push(v),x?.placeIds.push(v.id)}const g=wi(r,o.gx+1,o.gy+1,a+Math.PI,5,2),m={...i.places.find(y=>y.kind==="dock"),gx:g[0],gy:g[1]};Tt(r,m),n.push(m);const _=Mg(e,p,o,m);return{...i,layout:e,districts:p,places:n,paths:_,bounds:Tg(n,2)}}function wi(i,e,t,s,r,n){for(let o=r;o<r+40;o++)for(let a=0;a<64;a++){const l=s+(a%2?1:-1)*Math.ceil(a/2)*(Math.PI/32),h=Math.round(e+Math.cos(l)*o),c=Math.round(t+Math.sin(l)*o*.85);if(vg(i,h,c,n))return[h,c]}return[e+r,t]}function kg(i,e,t,s){const r=Math.atan2(e.cy-t.gy,e.cx-t.gx),n=Math.ceil(Math.max(e.bounds.w,e.bounds.h)/2)+2;return wi(i,e.cx,e.cy,r,n,s)}var Jx=class{constructor(i){this.windowMs=i}windowMs;mood="curious";trouble=[];recordTrouble(i){return this.trouble=this.trouble.filter(e=>i-e<=this.windowMs),this.trouble.push(i),this.trouble.length>=2}onRead(){return this.mood=this.mood==="lost"?"lost":"curious"}onBuild(){return this.mood=this.mood==="lost"?"lost":"focused"}onFail(i){return this.mood=this.recordTrouble(i)?"lost":"uneasy"}onError(i){return this.mood=this.recordTrouble(i)?"lost":"uneasy"}onPass(){return this.trouble=[],this.mood="happy"}onClaimUnverified(){return this.mood="uneasy"}},eb=class{constructor(i,e={}){this.world=i;for(const t of i.places)this.places.set(t.id,t),t.path&&this.byPath.set(t.path,t);this.beacons=i.places.filter(t=>t.kind==="beacon"),this.forge=i.places.find(t=>t.kind==="forge")??i.places[0],this.dock=i.places.find(t=>t.kind==="dock")??this.forge,this.maxGap=e.maxGapMs??2500,this.msPerCell=e.walkMsPerCell??90,this.mood=new Jx(e.lostWindowMs??9e4),this.actorAt.set("pip",this.forge.id)}world;places=new Map;byPath=new Map;beacons;forge;dock;maxGap;msPerCell;mood;beats=[];sceneMs=0;lastRealTs=null;seq=0;actorAt=new Map;helpers=new Map;gremlins=new Map;lastEdited=null;pendingBeacon=null;editedSinceTurn=!1;verifiedSinceEdit=!1;everVerified=!1;claimGremlin=null;get timeline(){return this.beats}feed(i){const e=this.beats.length;this.advanceClock(i.ts,i.id);const t=i.agentId&&this.helpers.has(i.agentId)?i.agentId:"pip";switch(i.kind){case"session_start":this.emit(i,t,{kind:"curtain_up",repoId:i.repoId},1200);break;case"read_file":{const s=this.placeFor(i.path,i,t);this.walk(i,t,s),this.emit(i,t,{kind:"read",target:s.id},_s(700+(i.bytes??400)/4,900,1800),this.mood.onRead());break}case"edit_file":case"write_file":{const s=this.placeFor(i.path,i,t);this.walk(i,t,s);const r=i.kind==="edit_file"?i.added+i.removed:i.added,n=_s(Math.sqrt(r/50),.15,1),o=[...this.gremlins].find(([,a])=>a===s.id);o&&this.emit(i,t,{kind:"chase",gremlinId:o[0],target:s.id},900,this.mood.mood),i.kind==="write_file"&&i.created&&this.emit(i,t,{kind:"raise",target:s.id},900,this.mood.onBuild()),this.emit(i,t,{kind:"build",target:s.id,intensity:n},_s(600+n*1900,800,2500),this.mood.onBuild()),this.lastEdited=s,this.editedSinceTurn=!0,this.verifiedSinceEdit=!1;break}case"run_command":{if(i.intent==="test"){const s=this.beaconFor(i.touched);this.walk(i,t,s),this.pendingBeacon=s,this.emit(i,t,{kind:"run_tests",target:s.id},_s(i.durationMs??1200,900,3e3),this.mood.mood)}else if(i.intent==="search")this.emit(i,t,{kind:"search",scope:"repo"},700,this.mood.onRead());else if(i.touched.length===0||i.intent==="git"||i.intent==="install"||i.intent==="build"){this.walk(i,t,this.forge);const s=i.intent==="build"||i.intent==="install"?.8:i.intent==="git"?.4:.5;this.emit(i,t,{kind:"forge",intensity:s},_s(i.durationMs??800,700,2e3),this.mood.mood)}!i.ok&&i.intent!=="test"&&this.emit(i,t,{kind:"stumble",retrying:!1},600,this.mood.onError(i.ts));break}case"test_result":{const s=this.pendingBeacon??this.beaconFor([]);this.pendingBeacon=null;const r=(i.framework==="unknown"&&i.passed===0&&i.failed===0,i.ok?"pass":"fail");if(r==="pass"){this.emit(i,t,{kind:"test_outcome",target:s.id,outcome:r,passed:i.passed,failed:i.failed},800,this.mood.onPass()),(i.passed>0||i.framework==="unknown")&&(this.verifiedSinceEdit=!0,this.everVerified=!0);for(const[n]of this.gremlins)this.emit(i,t,{kind:"banish",gremlinId:n},700,"happy");this.gremlins.clear(),this.claimGremlin&&(this.emit(i,t,{kind:"banish",gremlinId:this.claimGremlin},700,"happy"),this.claimGremlin=null),this.emit(i,t,{kind:"celebrate",target:s.id},1600,"happy")}else{this.emit(i,t,{kind:"test_outcome",target:s.id,outcome:r,passed:i.passed,failed:i.failed},800,this.mood.onFail(i.ts));const n=this.lastEdited??s,o=`g:${i.id}`;this.gremlins.set(o,n.id),this.emit(i,t,{kind:"spawn_gremlin",gremlinId:o,target:n.id},900,this.mood.mood)}break}case"search":this.emit(i,t,{kind:"search",scope:i.scope},700,this.mood.onRead());break;case"subagent_start":this.helpers.set(i.childId,i.label?{label:i.label}:{}),this.actorAt.set(i.childId,this.dock.id),this.emit(i,"pip",{kind:"summon_helper",helperId:i.childId,...i.label?{label:i.label}:{}},1400,this.mood.mood);break;case"subagent_stop":this.helpers.has(i.childId)&&(this.emit(i,i.childId,{kind:"dismiss_helper",helperId:i.childId,ok:i.ok},1e3,this.mood.mood),this.helpers.delete(i.childId),this.actorAt.delete(i.childId));break;case"waiting_for_user":i.reason==="idle"?this.emit(i,t,{kind:"your_turn"},1e3,this.mood.mood):this.emit(i,t,{kind:"blocked_on_you",reason:i.reason},1200,this.mood.mood);break;case"error":this.emit(i,t,{kind:"stumble",retrying:i.retrying},700,this.mood.onError(i.ts));break;case"turn_end":{if(i.claimedSuccess&&this.editedSinceTurn&&!this.verifiedSinceEdit){const s=`claim:${i.id}`;this.claimGremlin=s,this.emit(i,t,{kind:"unverified_claim",gremlinId:s},1400,this.mood.onClaimUnverified())}this.editedSinceTurn=!1,this.emit(i,t,{kind:"your_turn"},1e3,this.mood.mood);break}case"session_end":this.emit(i,t,{kind:"curtain_down",verified:this.everVerified&&!this.claimGremlin},1500,this.mood.mood);break}return this.beats.slice(e)}advanceClock(i,e){if(this.lastRealTs!==null){const t=this.beats.length?Math.max(...this.beats.slice(-3).map(n=>n.atMs+n.durationMs)):this.sceneMs,s=Math.min(Math.max(0,i-this.lastRealTs),this.maxGap),r=Math.max(t,this.sceneMs)+s;if(r-t>=1e3){const n={id:`b${this.seq++}`,atMs:t,durationMs:r-t,realTs:this.lastRealTs,mood:this.mood.mood,actor:"pip",sourceEventIds:[e],kind:"idle"};this.beats.push(n)}this.sceneMs=Math.max(this.sceneMs,r)}this.lastRealTs=i}emit(i,e,t,s,r=this.mood.mood){s=Math.round(s),"intensity"in t&&(t={...t,intensity:Math.round(t.intensity*1e3)/1e3});const n={id:`b${this.seq++}`,atMs:Math.round(this.sceneMs),durationMs:s,realTs:i.ts,mood:r,actor:e,sourceEventIds:[i.id],...t};return this.beats.push(n),this.sceneMs+=s,n}walk(i,e,t){const s=this.actorAt.get(e)??this.forge.id;if(s===t.id)return;const r=this.places.get(s)??this.forge,n=Math.hypot(t.gx-r.gx,t.gy-r.gy);this.emit(i,e,{kind:"walk_to",target:t.id},_s(Math.round(n*this.msPerCell),300,2500)),this.actorAt.set(e,t.id)}raised=0;placeFor(i,e,t){const s=this.byPath.get(i);if(s)return s;const r=i.includes("/")?i.slice(0,i.indexOf("/")):"",n=this.byPath.get(`${r?r+"/":""}…`);if(n&&(this.raised>=24||this.world.stats.capped))return n;if(this.raised>=24)return n??this.forge;this.raised++;const o=this.world.districts.find(h=>h.id===`d:${r}`)??this.world.districts[0],a=o?{gx:o.cx,gy:o.cy}:{gx:this.forge.gx+3,gy:this.forge.gy},l={id:`p:${i}`,kind:xg(i),path:i,label:i.slice(i.lastIndexOf("/")+1),district:o?.id??"",gx:a.gx,gy:a.gy,footprint:1,height:1,score:0,touched:!0};return this.places.set(l.id,l),this.byPath.set(i,l),l.kind==="beacon"&&this.beacons.push(l),this.emit(e,t,{kind:"raise",target:l.id,newPlace:{path:i,label:l.label,kind:l.kind,district:l.district}},900),l}beaconFor(i){const e=i.find(t=>_g(t));if(e){const t=this.byPath.get(e);if(t)return t}if(this.lastEdited){const t=this.beacons.find(s=>s.district===this.lastEdited.district);if(t)return t}return this.beacons[0]??this.forge}};function tr(i,e,t){const s=new eb(e,t);for(const r of i)s.feed(r);return[...s.timeline]}var _s=(i,e,t)=>Math.min(t,Math.max(e,i));function tb(i){const e=new Map,t=(r,n)=>e.set(r,(e.get(r)??0)+n);for(const r of i)if(r.kind==="read_file")t(r.path,Math.max(5,Math.round((r.bytes??400)/40)));else if(r.kind==="edit_file")t(r.path,Math.max(5,(r.added+r.removed)*3));else if(r.kind==="write_file")t(r.path,Math.max(5,r.added*2));else if(r.kind==="run_command")for(const n of r.touched)t(n,5);const s=[...e.keys()].sort((r,n)=>e.get(n)-e.get(r));return{files:s.map(r=>({path:r,loc:e.get(r)})),touched:s}}class sb{ctx=null;master=null;sfxBus=null;ambBus=null;duck=0;_muted=!1;_volume=.6;_ambience=!0;get ambienceEnabled(){return this._ambience}setAmbienceEnabled(e){this._ambience=e,this.ambBus&&this.ctx&&this.ambBus.gain.setTargetAtTime(e?.35:0,this.ctx.currentTime,.1)}noiseBuf=null;get ready(){return!!this.ctx&&this.ctx.state==="running"}get muted(){return this._muted}get volume(){return this._volume}async arm(){if(!this.ctx){const e=globalThis.AudioContext??globalThis.webkitAudioContext;if(!e)return;this.ctx=new e,this.master=this.ctx.createGain(),this.sfxBus=this.ctx.createGain(),this.ambBus=this.ctx.createGain(),this.sfxBus.connect(this.master),this.ambBus.connect(this.master),this.master.connect(this.ctx.destination),this.ambBus.gain.value=this._ambience?.35:0,this.applyGain();const t=this.ctx.sampleRate*2;this.noiseBuf=this.ctx.createBuffer(1,t,this.ctx.sampleRate);const s=this.noiseBuf.getChannelData(0);for(let r=0;r<t;r++)s[r]=Math.random()*2-1}this.ctx.state==="suspended"&&await this.ctx.resume()}setMuted(e){this._muted=e,this.applyGain()}setVolume(e){this._volume=Math.max(0,Math.min(1,e)),this.applyGain()}applyGain(){this.master&&this.master.gain.setTargetAtTime(this._muted?0:this._volume,this.ctx.currentTime,.02)}duckAmbience(e=.5,t=350){if(!this.ambBus||!this.ctx)return;const s=this.ctx.currentTime;this.ambBus.gain.cancelScheduledValues(s),this._ambience&&(this.ambBus.gain.setTargetAtTime(.35*(1-e),s,.01),this.ambBus.gain.setTargetAtTime(.35,s+t/1e3,.12),this.duck++)}tone(e,t,s={}){if(!this.ready||!this.ctx||!this.sfxBus)return;const r=this.ctx,n=r.currentTime,o=r.createOscillator();o.type=s.type??"sine",o.frequency.setValueAtTime(e,n),s.detune&&(o.detune.value=s.detune),s.slideTo&&o.frequency.exponentialRampToValueAtTime(Math.max(20,s.slideTo),n+t);const a=r.createGain(),l=s.attack??.005,h=s.decay??t;a.gain.setValueAtTime(1e-4,n),a.gain.exponentialRampToValueAtTime(s.gain??.25,n+l),a.gain.exponentialRampToValueAtTime(1e-4,n+l+h);let c=o;if(s.lowpass){const d=r.createBiquadFilter();d.type="lowpass",d.frequency.value=s.lowpass,o.connect(d),c=d}const u=r.createStereoPanner();u.pan.value=s.pan??0,c.connect(a),a.connect(u),u.connect(this.sfxBus),o.start(n),o.stop(n+l+h+.05),this.duckAmbience(.35,(l+h)*1e3)}noise(e,t={}){if(!this.ready||!this.ctx||!this.sfxBus||!this.noiseBuf)return;const s=this.ctx,r=s.currentTime,n=s.createBufferSource();n.buffer=this.noiseBuf,n.loop=!0;const o=s.createBiquadFilter();o.type=t.filter??"bandpass",o.frequency.setValueAtTime(t.freq??1200,r),o.Q.value=t.q??.8,t.sweepTo&&o.frequency.exponentialRampToValueAtTime(Math.max(40,t.sweepTo),r+e);const a=s.createGain(),l=t.attack??.004;a.gain.setValueAtTime(1e-4,r),a.gain.exponentialRampToValueAtTime(t.gain??.12,r+l),a.gain.exponentialRampToValueAtTime(1e-4,r+e);const h=s.createStereoPanner();h.pan.value=t.pan??0,n.connect(o),o.connect(a),a.connect(h),h.connect(this.sfxBus),n.start(r),n.stop(r+e+.05)}pad(e,t,s="sine"){if(!this.ready||!this.ctx||!this.ambBus)return()=>{};const r=this.ctx,n=r.currentTime,o=[],a=r.createGain();a.gain.setValueAtTime(1e-4,n),a.gain.exponentialRampToValueAtTime(t,n+1.5),a.connect(this.ambBus);for(const l of e){const h=r.createOscillator();h.type=s,h.frequency.value=l,h.detune.value=(Math.random()-.5)*6,h.connect(a),h.start(n),o.push(h)}return()=>{const l=r.currentTime;a.gain.cancelScheduledValues(l),a.gain.setTargetAtTime(1e-4,l,.4);for(const h of o)h.stop(l+2)}}wash(e,t,s,r=.12,n=.5){if(!this.ready||!this.ctx||!this.ambBus||!this.noiseBuf)return()=>{};const o=this.ctx,a=o.currentTime,l=o.createBufferSource();l.buffer=this.noiseBuf,l.loop=!0;const h=o.createBiquadFilter();h.type="lowpass",h.frequency.value=e,h.Q.value=t;const c=o.createGain();c.gain.setValueAtTime(1e-4,a),c.gain.exponentialRampToValueAtTime(s,a+2);const u=o.createOscillator();u.frequency.value=r;const d=o.createGain();return d.gain.value=s*n,u.connect(d),d.connect(c.gain),l.connect(h),h.connect(c),c.connect(this.ambBus),l.start(a),u.start(a),()=>{const f=o.currentTime;c.gain.setTargetAtTime(1e-4,f,.5),l.stop(f+2.5),u.stop(f+2.5)}}now(){return this.ctx?.currentTime??0}captureStream(){if(!this.ctx||!this.master)return null;const e=this.ctx.createMediaStreamDestination();return this.master.connect(e),e.stream}note(e,t,s,r="sine",n=0){if(!this.ready||!this.ctx||!this.ambBus)return;const o=this.ctx,a=o.currentTime,l=o.createGain();l.gain.setValueAtTime(1e-4,a),l.gain.exponentialRampToValueAtTime(s,a+Math.min(.12,t*.3)),l.gain.setTargetAtTime(1e-4,a+t*.6,t*.35);const h=o.createStereoPanner();h.pan.value=n,l.connect(h),h.connect(this.ambBus);const c=o.createBiquadFilter();c.type="lowpass",c.frequency.value=Math.min(6e3,e*4),c.connect(l);for(const f of[0,4]){const p=o.createOscillator();p.type=r,p.frequency.value=e,p.detune.value=f,p.connect(c),p.start(a),p.stop(a+t*1.6)}const u=o.createOscillator();u.type="sine",u.frequency.value=e/2;const d=o.createGain();d.gain.value=.35,u.connect(d),d.connect(c),u.start(a),u.stop(a+t*1.6)}extra(e,t=(Math.random()-.5)*1.2){if(!this.ready||!this.ctx||!this.ambBus)return;const s=this.ctx,r=s.currentTime,n=(a,l,h,c,u,d=.01)=>{const f=s.createOscillator();f.type=a,f.frequency.setValueAtTime(l,r),f.frequency.exponentialRampToValueAtTime(Math.max(20,h),r+c);const p=s.createGain();p.gain.setValueAtTime(1e-4,r),p.gain.exponentialRampToValueAtTime(u,r+d),p.gain.exponentialRampToValueAtTime(1e-4,r+c);const g=s.createStereoPanner();g.pan.value=t,f.connect(p),p.connect(g),g.connect(this.ambBus),f.start(r),f.stop(r+c+.05)},o=(a,l,h,c,u,d="bandpass")=>{if(!this.noiseBuf)return;const f=s.createBufferSource();f.buffer=this.noiseBuf,f.loop=!0;const p=s.createBiquadFilter();p.type=d,p.frequency.setValueAtTime(a,r),u&&p.frequency.exponentialRampToValueAtTime(u,r+h),p.Q.value=l;const g=s.createGain();g.gain.setValueAtTime(1e-4,r),g.gain.exponentialRampToValueAtTime(c,r+.05),g.gain.exponentialRampToValueAtTime(1e-4,r+h);const m=s.createStereoPanner();m.pan.value=t,f.connect(p),p.connect(g),g.connect(m),m.connect(this.ambBus),f.start(r),f.stop(r+h+.05)};switch(e){case"gull":n("sine",1800,1100,.35,.05,.03),setTimeout(()=>n("sine",1700,1250,.3,.04,.03),260);return;case"cricket":for(let a=0;a<6;a++)setTimeout(()=>n("sine",4200,4100,.04,.02),a*70);return;case"bell":n("sine",880,870,2.2,.06,.005),n("sine",1760,1740,1.4,.03,.005),n("sine",2640,2600,.8,.015,.005);return;case"bubble":n("sine",300+Math.random()*300,900+Math.random()*600,.18,.04,.01);return;case"wind":o(500+Math.random()*400,.5,2.5+Math.random()*2,.05,300+Math.random()*300);return;case"horn":n("sawtooth",180,176,.8,.03,.08);return;case"hum":n("sine",60,60,2.5,.03,.4);return;case"chime":n("sine",1318.5,1316,1.2,.035,.005);return;case"owl":n("sine",420,380,.5,.04,.05),setTimeout(()=>n("sine",400,360,.6,.035,.05),420);return;case"rumble":o(90,1.2,2.5,.09,60,"lowpass");return;case"drip":n("sine",1200,600,.12,.04,.003);return;case"market":for(let a=0;a<4;a++)setTimeout(()=>o(600+Math.random()*1200,2,.12,.02),a*120);return}}}const ib=i=>1-Math.pow(1-i,3),Rn=i=>rb(.4,0,.2,1,i),lu=i=>1+(1.70158+1)*Math.pow(i-1,3)+1.70158*Math.pow(i-1,2),st=i=>Math.sin(Math.PI*Math.min(1,Math.max(0,i)));function rb(i,e,t,s,r){const n=3*i,o=3*(t-i)-n,a=1-n-o,l=3*e,h=3*(s-e)-l,c=1-l-h,u=g=>((a*g+o)*g+n)*g,d=g=>((c*g+h)*g+l)*g,f=g=>(3*a*g+2*o)*g+n;let p=r;for(let g=0;g<6;g++){const m=f(p);if(Math.abs(m)<1e-6)break;p-=(u(p)-r)/m}return d(Math.min(1,Math.max(0,p)))}const nb=64,Bo=32,K=(i,e)=>({x:(i-e)*nb/2,y:(i+e)*Bo/2}),F=(i,e)=>({x:i.x,y:i.y-e}),Jt=(i,e,t)=>i+(e-i)*t,Be=(i,e,t)=>({x:Jt(i.x,e.x,t),y:Jt(i.y,e.y,t)}),ob=(i,e,t)=>i<e?e:i>t?t:i,Ue=(i,e,t)=>ob((i-e)/(t-e),0,1),hu=(i,e,t=1)=>i+e+t;function De(i,e,t,s=0){return[K(i,e),K(i+t,e),K(i+t,e+t),K(i,e+t)].map(r=>F(r,s))}const X=i=>i.flatMap(e=>[e.x,e.y]);class ab{constructor(e,t){this.stage=e,this.reducedMotion=t}cx=0;cy=0;zoom=1;tx=0;ty=0;tz=1;punch=0;shakeT=0;drift=0;t=0;fit(e,t,s,r,n=1.08){this.tz=Math.min(s/(e*n),r/(t*n))}follow(e,t,s=1){this.tx=Jt(this.tx,e,s),this.ty=Jt(this.ty,t,s)}setZoomFactor(e){this.tz=e}pushIn(e=.08){this.reducedMotion||(this.punch=Math.max(this.punch,e))}shake(e=220){this.reducedMotion||(this.shakeT=e/1e3)}setDrift(e){this.drift=this.reducedMotion?0:e?1:0}snap(){this.cx=this.tx,this.cy=this.ty,this.zoom=this.tz}update(e,t,s){const r=Number.isFinite(e)?Math.max(0,Math.min(.05,e/1e3)):0;this.t+=r;const n=1-Math.pow(.012,r),o=1-Math.pow(.05,r);this.cx+=(this.tx-this.cx)*n,this.cy+=(this.ty-this.cy)*n,this.punch=Math.max(0,this.punch-r*.12),this.zoom+=(this.tz*(1+ib(this.punch/.08)*this.punch)-this.zoom)*o;let a=0,l=0;if(this.shakeT>0){this.shakeT-=r;const h=this.shakeT*18;a=Math.sin(this.t*60)*h,l=Math.cos(this.t*47)*h}this.drift&&(a+=Math.sin(this.t*.7)*2.2,l+=Math.cos(this.t*.5)*1.6),this.stage.scale.set(this.zoom),this.stage.position.set(t/2-(this.cx+a)*this.zoom,s/2-(this.cy+l)*this.zoom)}toScreen(e,t){return{x:this.stage.position.x+e*this.zoom,y:this.stage.position.y+t*this.zoom}}get scale(){return this.zoom}}const lb={roof:"pitched",eave:.14,furniture:"chimney",stripes:!1},hb={roof:"flat",eave:.05,furniture:"vent",stripes:!1},cb={roof:"capsule",eave:0,furniture:"dish",stripes:!1},Bn={island:lb,orbit:cb,metropolis:hb,harbour:{roof:"gable",eave:.16,furniture:"chimney",stripes:!1},observatory:{roof:"dome",eave:.04,furniture:"dish",stripes:!1},greenhouse:{roof:"gable",eave:.1,furniture:"vent",stripes:!1},workshop:{roof:"gable",eave:.12,furniture:"chimney",stripes:!1},arcade:{roof:"flat",eave:.08,furniture:"mast",stripes:!0},kingdom:{roof:"pitched",eave:.1,furniture:"finial",stripes:!1},outpost:{roof:"flat",eave:.12,furniture:"vent",stripes:!1},snowfield:{roof:"pitched",eave:.2,furniture:"chimney",stripes:!1},canopy:{roof:"pitched",eave:.22,furniture:"none",stripes:!1},lagoon:{roof:"tent",eave:.18,furniture:"none",stripes:!0},volcano:{roof:"flat",eave:.06,furniture:"vent",stripes:!1},cloudtop:{roof:"dome",eave:.06,furniture:"finial",stripes:!1},reef:{roof:"dome",eave:.02,furniture:"none",stripes:!1},bazaar:{roof:"tent",eave:.2,furniture:"none",stripes:!0},monastery:{roof:"onion",eave:.08,furniture:"finial",stripes:!1},moonbase:{roof:"capsule",eave:0,furniture:"dish",stripes:!1},lanterns:{roof:"tiered",eave:.26,furniture:"lantern",stripes:!1}};class Eg{constructor(e,t){this.world=e,this.theme=t,this.container.addChild(this.ripples,this.terrain,this.paths,this.labels,this.shadows,this.clouds,this.objects),this.objects.sortableChildren=!0,this.shadows.alpha=.9,this.drawTerrain(),this.drawPaths(),this.drawLabels();for(const s of e.places)this.addPlace(s);this.placeProps()}container=new _e;terrain=new Pe;ripples=new Pe;paths=new Pe;labels=new _e;shadows=new Pe;clouds=new Pe;objects=new _e;drawn=new Map;props=[];time=0;gradients=new Map;vGrad(e,t,s,r){const n=Vi(s),o=Vi(r),a=`v${e}|${t}|${n}|${o}`;let l=this.gradients.get(a);return l||(l=db(e,t,n,o),this.gradients.set(a,l)),l}hGrad(e,t,s,r){const n=Vi(s),o=Vi(r),a=`h${e}|${t}|${n}|${o}`;let l=this.gradients.get(a);return l||(l=fb(e,t,n,o),this.gradients.set(a,l)),l}destroy(){for(const e of this.gradients.values())e.destroy();this.gradients.clear(),this.container.destroy({children:!0})}positionOf(e){const t=this.drawn.get(e);if(!t)return null;const s=t.place,r=s.gx+s.footprint/2,n=s.gy+s.footprint/2,o=K(r,n);return{ground:o,top:F(o,this.heightPx(t)+10),place:s}}standingSpot(e){const t=this.drawn.get(e);if(!t)return K(0,0);const s=t.place;return K(s.gx+s.footprint/2,s.gy+s.footprint+.55)}setGlow(e,t){const s=this.drawn.get(e);s&&s.glow!==t&&(s.glow=t,s.dirty=!0)}setGrowth(e,t){const s=this.drawn.get(e);s&&s.extraH!==t&&(s.extraH=t,s.dirty=!0)}setScaffold(e,t){const s=this.drawn.get(e);s&&s.scaffold!==t&&(s.scaffold=t,s.dirty=!0)}setLamp(e,t){const s=this.drawn.get(e);s&&s.lamp!==t&&(s.lamp=t,s.dirty=!0)}lampOf(e){return this.drawn.get(e)?.lamp??"idle"}has(e){return this.drawn.has(e)}addPlace(e){if(this.drawn.has(e.id))return;const t=new Pe;t.zIndex=hu(e.gx,e.gy,e.footprint);const s=Math.max(0,this.world.districts.findIndex(u=>u.id===e.district)),r=e.kind==="beacon"?this.theme.beacon:e.kind==="archive"?this.theme.archive:e.kind==="forge"?this.theme.forge:this.theme.palettes[s%this.theme.palettes.length],n=e.kind==="building"?Ao(e.path):0,o=e.kind==="building"?(n%5-2)*.05:0,a=e.kind==="building"&&n%3===0?this.theme.palettes[(s+1+n%2)%this.theme.palettes.length]:r,l=u=>o>=0?J(u,16777215,o):J(u,0,-o),h={top:l(r.top),left:l(r.left),right:l(r.right),roof:a.roof,roofD:a.roofD,win:r.win},c={place:e,g:t,palette:h,extraH:0,glow:0,lamp:"idle",scaffold:0,dirty:!0};this.drawn.set(e.id,c),this.objects.addChild(t),this.redraw(c)}update(e){this.time+=e/1e3,this.drawRipples(),this.drawCloudShadows();for(const t of this.props)t.canopy&&(t.canopy.x=Math.sin(this.time*1.4+t.phase)*1.2);for(const t of this.drawn.values())(t.glow>0||t.lamp==="scan"||t.lamp==="fail"||t.lamp==="pass"||t.place.kind==="dock"||t.place.kind==="forge")&&(t.dirty=!0),t.dirty&&this.redraw(t)}heightPx(e){const t=e.place;return(t.kind==="beacon"?70:t.kind==="forge"?34:t.kind==="dock"?4:t.kind==="archive"?30:18+t.height*8)+e.extraH}redraw(e){const{g:t,place:s,palette:r}=e;t.clear(),e.dirty=!1;const n=this.heightPx(e),o=s.footprint,a=De(s.gx+.12,s.gy+.12,o);if(t.poly(X(a)).fill({color:this.shadowInk,alpha:.22}),s.kind!=="dock"&&this.castShadow(t,s,n),s.kind==="dock")return this.drawDock(t,s);if(s.kind==="beacon")return this.drawBeacon(e,n);const l=this.box(t,s.gx,s.gy,o,n,s.kind==="forge"?r.roof:r.top,r.left,r.right),h=e.glow>0?.6+.4*Math.sin(this.time*10):0,c=e.glow>0?J(r.win,16771496,.5+.5*h):r.win;if(s.kind!=="archive"&&s.kind!=="forge"){const u=Math.max(1,Math.round(n/28)),d=o>=3?3:2;this.windows(t,l[3],l[2],n,u,d,c,e.glow>0?1:.9),this.windows(t,l[2],l[1],n,u,d,c,e.glow>0?1:.8);const f=Be(l[3],l[2],.3);t.poly([f.x-3,f.y-1,f.x+3,f.y+1,f.x+3,f.y-9,f.x-3,f.y-11]).fill({color:r.roofD,alpha:.9})}if(s.kind==="building"&&o<=2&&this.roof(t,s,n,r),s.kind==="building"&&o>=3&&Bn[this.theme.id].roof!=="capsule"&&Bn[this.theme.id].roof!=="dome"){const u=l.map(p=>F(p,n));t.poly(X([u[3],u[2],F(u[2],4),F(u[3],4)])).fill(r.roofD),t.poly(X([u[2],u[1],F(u[1],4),F(u[2],4)])).fill(J(r.roofD,0,.2)),t.poly(X(u.map(p=>F(p,4)))).fill(r.roof);const d=De(s.gx+.8,s.gy+.8,o-1.6,n+4);t.poly(X([d[3],d[2],F(d[2],10),F(d[3],10)])).fill(r.left),t.poly(X([d[2],d[1],F(d[1],10),F(d[2],10)])).fill(r.right),t.poly(X(d.map(p=>F(p,10)))).fill(r.top);const f=F(K(s.gx+o/2,s.gy+o/2),n+14);t.moveTo(f.x,f.y).lineTo(f.x,f.y-12).stroke({width:1.6,color:r.roofD}),t.circle(f.x,f.y-13-14,2.2).fill(e.glow>0?16766571:r.roof)}if(s.kind==="archive"){for(let u=1;u<6;u++){const d=Be(l[3],l[2],u/6);t.moveTo(d.x,d.y-3).lineTo(d.x,d.y-n+5).stroke({width:1.3,color:16777215,alpha:.6})}for(let u=1;u<5;u++){const d=Be(l[2],l[1],u/5);t.moveTo(d.x,d.y-3).lineTo(d.x,d.y-n+5).stroke({width:1.3,color:16777215,alpha:.45})}this.pyramid(t,l.map(u=>F(u,n)),F(K(s.gx+o/2,s.gy+o/2),n+10),r.roof,r.roofD)}if(s.kind==="forge"){const u=this.theme.forge.ember,d=Be(l[3],l[2],.5);t.poly([d.x-7,d.y-2,d.x+7,d.y+2,d.x+7,d.y-18,d.x-7,d.y-22]).fill({color:u,alpha:.85}),this.windows(t,l[2],l[1],n,2,2,u,.9),this.pyramid(t,l.map(g=>F(g,n)),F(K(s.gx+o/2,s.gy+o/2),n+16),r.roof,r.roofD);const f=F(K(s.gx+o*.75,s.gy+o*.3),n+6);t.rect(f.x-4,f.y-16,8,16).fill(r.roofD);for(let g=0;g<3;g++){const m=(this.time*.35+g/3)%1;t.circle(f.x+Math.sin(m*6+g)*4,f.y-18-m*26,3+m*6).fill({color:16777215,alpha:.22*(1-m)})}const p=.5+.5*Math.sin(this.time*3);t.circle(d.x,d.y-8,12+p*4).fill({color:u,alpha:.12+.08*p})}e.glow>0&&this.outline(t,l,n,16762970,.4+.4*h),e.scaffold>0&&this.scaffold(t,s,n,e.scaffold)}roof(e,t,s,r){const n=Bn[this.theme.id],o=t.footprint,a=n.eave,l=Ao(t.path),h=De(t.gx-a,t.gy-a,o+a*2,s),c=K(t.gx+o/2,t.gy+o/2),u=J(r.roofD,this.shadowInk,.35);switch(a>0&&(e.poly(X([h[3],h[2],F(h[2],-3),F(h[3],-3)])).fill({color:u,alpha:.9}),e.poly(X([h[2],h[1],F(h[1],-3),F(h[2],-3)])).fill({color:J(u,0,.2),alpha:.9})),n.roof){case"pitched":{this.pyramid(e,h,F(c,s+12+o*9),r.roof,r.roofD);break}case"gable":{const f=11+o*7,p=F(Be(h[0],h[3],.5),s+f),g=F(Be(h[1],h[2],.5),s+f);e.poly(X([h[3],h[2],g,p])).fill(this.vGrad(J(r.roof,16777215,.1),r.roof,p.y,h[3].y)),e.poly(X([h[0],h[1],g,p])).fill(J(r.roofD,this.shadowInk,.2)),e.poly(X([h[2],h[1],g])).fill(J(r.right,this.shadowInk,.1)),e.poly(X([h[3],h[0],p])).fill(r.left),e.moveTo(p.x,p.y).lineTo(g.x,g.y).stroke({width:1.4,color:16777215,alpha:.4,cap:"round"});break}case"flat":{const f=h.map(g=>F(g,3));e.poly(X([h[3],h[2],f[2],f[3]])).fill(r.roofD),e.poly(X([h[2],h[1],f[1],f[2]])).fill(J(r.roofD,0,.2)),e.poly(X(f)).fill(this.hGrad(J(r.roof,16777215,.08),r.roof,f[3].x,f[1].x));const p=De(t.gx+.25+l%3*.1,t.gy+.3,.4,s+3);e.poly(X([p[3],p[2],F(p[2],6),F(p[3],6)])).fill(r.left),e.poly(X([p[2],p[1],F(p[1],6),F(p[2],6)])).fill(r.right),e.poly(X(p.map(g=>F(g,6)))).fill(r.top);break}case"dome":{const f=o*32*.78,p=c.y-s+2;e.ellipse(c.x,p,f,f*.62).fill(this.vGrad(J(r.roof,16777215,.22),J(r.roofD,this.shadowInk,.15),p-f*.62,p+f*.3)),e.rect(c.x-f,p,f*2,f*.62).fill({color:0,alpha:0}),e.ellipse(c.x-f*.3,p-f*.28,f*.28,f*.14).fill({color:16777215,alpha:.32});break}case"onion":{const f=o*16,p=c.y-s;e.moveTo(c.x-f,p).quadraticCurveTo(c.x-f*1.15,p-f*1.1,c.x,p-f*2.2).quadraticCurveTo(c.x+f*1.15,p-f*1.1,c.x+f,p).fill(this.vGrad(J(r.roof,16777215,.2),r.roofD,p-f*2.2,p)),e.moveTo(c.x-f*.4,p-f*.3).quadraticCurveTo(c.x-f*.5,p-f*1.2,c.x-f*.05,p-f*1.9).stroke({width:1.6,color:16777215,alpha:.35,cap:"round"});break}case"tiered":{for(let f=0;f<2;f++){const p=s+f*14,g=a*(1-f*.45),m=De(t.gx-g,t.gy-g,o+g*2,p);e.poly(X([m[3],m[2],F(m[2],-2),F(m[3],-2)])).fill(u);const _=F(c,p+9+o*3);e.poly(X([F(m[3],3),F(m[2],3),_])).fill(r.roof),e.poly(X([F(m[2],3),F(m[1],3),_])).fill(r.roofD),e.poly(X([F(m[3],3),F(m[0],3),_])).fill(J(r.roof,16777215,.1));for(const y of[m[1],m[2],m[3]])e.moveTo(y.x,y.y+1).quadraticCurveTo(y.x+(y.x<c.x?-4:4),y.y-1,y.x+(y.x<c.x?-5:5),y.y-6).stroke({width:2,color:r.roofD,cap:"round"})}break}case"tent":{const f=F(c,s+16+o*8);this.pyramid(e,h,f,r.roof,r.roofD);for(let p=0;p<o*3;p++){const g=Be(h[3],h[2],p/(o*3)),m=Be(h[3],h[2],(p+1)/(o*3));e.moveTo(g.x,g.y).quadraticCurveTo((g.x+m.x)/2,(g.y+m.y)/2+4,m.x,m.y).fill(r.roofD)}e.moveTo(f.x,f.y).lineTo(f.x,f.y-8).stroke({width:1.5,color:r.roofD}),e.poly([f.x,f.y-8,f.x+7,f.y-6,f.x,f.y-4]).fill(r.win);break}case"capsule":{const f=o*32*.7,p=c.y-s+1;e.ellipse(c.x,p,f*1.02,f*.5).fill(this.vGrad(J(r.top,16777215,.25),r.top,p-f*.5,p+f*.1)),e.ellipse(c.x-f*.3,p-f*.22,f*.3,f*.1).fill({color:16777215,alpha:.4}),e.ellipse(c.x,p,f*1.02,f*.5).stroke({width:1.2,color:J(r.roofD,16777215,.1),alpha:.6});break}}const d=F(K(t.gx+o*.72,t.gy+o*.3),s+(n.roof==="flat"?3:n.roof==="pitched"||n.roof==="gable"?8:0));switch(n.furniture){case"chimney":l%2===0&&(e.rect(d.x-3,d.y-12,6,12).fill(r.roofD),e.rect(d.x-4,d.y-13,8,3).fill(J(r.roofD,0,.2)));break;case"vent":e.rect(d.x-4,d.y-5,8,5).fill(J(r.left,this.shadowInk,.2)),e.ellipse(d.x,d.y-5,4,1.6).fill(r.top);break;case"mast":e.moveTo(d.x,d.y).lineTo(d.x,d.y-16).stroke({width:1.4,color:r.roofD}),e.circle(d.x,d.y-17,2).fill(r.win);break;case"finial":{const f=F(c,s+12+o*9+(n.roof==="onion"?o*16*2.2-12-o*9:0));e.moveTo(f.x,f.y).lineTo(f.x,f.y-7).stroke({width:1.4,color:16766571}),e.circle(f.x,f.y-8,2).fill(16766571);break}case"lantern":{const f=Be(h[3],h[2],.5);e.moveTo(f.x,f.y).lineTo(f.x,f.y+5).stroke({width:1,color:r.roofD}),e.roundRect(f.x-3,f.y+5,6,8,2).fill(ub(r.win));break}case"dish":e.ellipse(d.x,d.y-2,6,3).stroke({width:1.4,color:16777215,alpha:.7}),e.moveTo(d.x,d.y-2).lineTo(d.x+2,d.y-7).stroke({width:1,color:16777215,alpha:.7});break}if(n.stripes){const f=De(t.gx,t.gy,o);for(let p=0;p<o*4;p+=2){const g=Be(f[3],f[2],p/(o*4)),m=Be(f[3],f[2],(p+1)/(o*4));e.poly([g.x,g.y,m.x,m.y,m.x,m.y-s*.35,g.x,g.y-s*.35]).fill({color:16777215,alpha:.22})}}}box(e,t,s,r,n,o,a,l){const[h,c,u,d]=De(t,s,r),f=this.hazeOf(s+t),p=g=>J(g,this.theme.sky[0],f);return e.poly(X([d,u,F(u,n),F(d,n)])).fill(this.vGrad(p(J(a,16777215,.08)),p(J(a,this.shadowInk,.28)),d.y-n,d.y)),e.poly(X([u,c,F(c,n),F(u,n)])).fill(this.vGrad(p(J(l,this.coolInk,.06)),p(J(l,this.shadowInk,.38)),u.y-n,u.y)),e.poly(X([F(h,n),F(c,n),F(u,n),F(d,n)])).fill(this.hGrad(p(J(o,16777215,.16)),p(o),d.x,c.x)),e.moveTo(d.x,d.y-n).lineTo(h.x,h.y-n).lineTo(c.x,c.y-n).stroke({width:1.3,color:16777215,alpha:.42,cap:"round"}),e.moveTo(d.x,d.y-n).lineTo(d.x,d.y).stroke({width:1.1,color:16777215,alpha:.22}),[h,c,u,d]}hazeOf(e){const t=this.world.bounds,s=t.x+t.y,r=t.x+t.w+t.y+t.h;return .16*(1-Math.max(0,Math.min(1,(e-s)/Math.max(1,r-s))))}get shadowInk(){return J(this.theme.vignette,0,.3)}get coolInk(){return J(this.theme.sky[0],2768746,.5)}castShadow(e,t,s){const r=t.footprint,n=s/36,o=De(t.gx,t.gy,r),a=.55*n,l=.95*n,h=[K(t.gx+a,t.gy+l),K(t.gx+r+a,t.gy+l),K(t.gx+r+a,t.gy+r+l),K(t.gx+a,t.gy+r+l)],c=[o[1],h[1],h[2],h[3],o[3],o[2]];e.poly(X(c)).fill({color:this.shadowInk,alpha:.16});const u=[K(t.gx+a*.6,t.gy+l*.6),K(t.gx+r+a*.6,t.gy+l*.6),K(t.gx+r+a*.6,t.gy+r+l*.6)];e.poly(X([o[1],u[1],u[2],o[3],o[2]])).fill({color:this.shadowInk,alpha:.12})}drawCloudShadows(){const e=this.clouds;if(e.clear(),this.theme.terrain!=="island"&&this.theme.terrain!=="block")return;const t=this.world.bounds,s=K(t.x+t.w/2,t.y+t.h/2),r=(t.w+t.h)*24;for(let n=0;n<3;n++){const o=(this.time*.012+n*.37)%1,a=s.x-r/2+o*r*1.3-r*.15,l=s.y-90+Math.sin(n*2.1)*120;e.ellipse(a,l,150+n*30,56+n*8).fill({color:this.shadowInk,alpha:.075}),e.ellipse(a+90,l+18,110,40).fill({color:this.shadowInk,alpha:.06})}}pyramid(e,t,s,r,n){e.poly(X([t[0],t[1],s])).fill(J(n,this.shadowInk,.25)),e.poly(X([t[3],t[0],s])).fill(J(r,16777215,.12)),e.poly(X([t[3],t[2],s])).fill(this.vGrad(J(r,16777215,.06),r,s.y,t[2].y)),e.poly(X([t[2],t[1],s])).fill(this.vGrad(n,J(n,this.shadowInk,.3),s.y,t[1].y)),e.moveTo(t[3].x,t[3].y).lineTo(s.x,s.y).stroke({width:1.2,color:16777215,alpha:.35,cap:"round"})}windows(e,t,s,r,n,o,a,l){const h=(s.x-t.x)/o*.3,c=(s.y-t.y)/o*.3;for(let u=0;u<n;u++)for(let d=0;d<o;d++){const f=Be(t,s,(d+.5)/o),p=f.y-r*(u+.75)/(n+.5),g=f.x;e.poly([g-h,p-c,g+h,p+c,g+h,p+c-6,g-h,p-c-6]).fill({color:a,alpha:l}),e.poly([g-h,p-c-4.5,g+h,p+c-4.5,g+h,p+c-6,g-h,p-c-6]).fill({color:16777215,alpha:l*.45})}}outline(e,t,s,r,n){const o=t.map(a=>F(a,s));e.moveTo(t[3].x,t[3].y).lineTo(t[2].x,t[2].y).lineTo(t[1].x,t[1].y).lineTo(o[1].x,o[1].y).lineTo(o[0].x,o[0].y).lineTo(o[3].x,o[3].y).closePath().stroke({width:2,color:r,alpha:n,join:"round"}),e.moveTo(t[2].x,t[2].y).lineTo(o[2].x,o[2].y).stroke({width:2,color:r,alpha:n})}scaffold(e,t,s,r){const n=De(t.gx-.12,t.gy-.12,t.footprint+.24);for(const o of[n[1],n[2],n[3]])e.moveTo(o.x,o.y).lineTo(o.x,o.y-s-8).stroke({width:1.1,color:16768150,alpha:r});for(let o=10;o<s+8;o+=11)e.moveTo(n[3].x,n[3].y-o).lineTo(n[2].x,n[2].y-o).lineTo(n[1].x,n[1].y-o).stroke({width:1.1,color:16768150,alpha:r})}drawBeacon(e,t){const{g:s,place:r}=e,n=this.theme.beacon,o=n.lamp[e.lamp],a=this.box(s,r.gx+.2,r.gy+.2,.6,t,n.top,n.left,n.right);for(const[u,d]of[[.2,.33],[.52,.65]])s.poly(X([F(a[3],t*u),F(a[2],t*u),F(a[2],t*d),F(a[3],t*d)])).fill(n.roof),s.poly(X([F(a[2],t*u),F(a[1],t*u),F(a[1],t*d),F(a[2],t*d)])).fill(n.roofD);const l=F(K(r.gx+.5,r.gy+.5),t+6),h=e.lamp==="fail"?.55+.45*Math.sin(this.time*9):e.lamp==="scan"?.8+.2*Math.sin(this.time*20):1,c=e.lamp==="idle"?16:26;if(s.circle(l.x,l.y,c).fill({color:o,alpha:.22*h}),s.circle(l.x,l.y,c*.55).fill({color:o,alpha:.3*h}),e.lamp==="scan"||e.lamp==="pass"){const u=e.lamp==="scan"?this.time*5:this.time*1.1,d=e.lamp==="scan"?190:120,f=.2;s.moveTo(l.x,l.y).arc(l.x,l.y,d,u-f,u+f).closePath().fill({color:o,alpha:.18})}this.box(s,r.gx+.28,r.gy+.28,.44,11,2899538,o,J(o,0,.25)),this.pyramid(s,De(r.gx+.2,r.gy+.2,.6,t+11),F(K(r.gx+.5,r.gy+.5),t+22),n.roof,n.roofD)}drawDock(e,t){const s=De(t.gx,t.gy,t.footprint);e.poly(X([s[3],s[2],F(s[2],-5),F(s[3],-5)])).fill(this.theme.dock.post),e.poly(X([s[2],s[1],F(s[1],-5),F(s[2],-5)])).fill(J(this.theme.dock.post,0,.2)),e.poly(X(s)).fill(this.theme.dock.deck);for(let o=1;o<5;o++){const a=Be(s[0],s[3],o/5),l=Be(s[1],s[2],o/5);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:0,alpha:.12})}for(const o of[s[0],s[1],s[2],s[3]])e.rect(o.x-2,o.y-12,4,12).fill(this.theme.dock.post);const r=Be(s[1],s[2],.5),n=Math.sin(this.time*1.6)*1.5;e.ellipse(r.x+22,r.y+6+n,16,6).fill(this.theme.dock.vessel),e.ellipse(r.x+22,r.y+3+n,13,4).fill(J(this.theme.dock.vessel,0,.12)),e.rect(r.x+20,r.y-12+n,3,15).fill(this.theme.dock.post),e.poly([r.x+23,r.y-12+n,r.x+34,r.y-6+n,r.x+23,r.y-2+n]).fill({color:16777215,alpha:.9})}blobPath(e,t,s){const r=this.world.bounds,n=r.x+r.w/2,o=r.y+r.h/2,a=r.w/2+1.2,l=r.h/2+1.2,h=[],c=li(this.world.seed^1540483477)()*6.28;for(let u=0;u<80;u++){const d=u/80*Math.PI*2,f=1+.07*Math.sin(3*d+c)+.04*Math.sin(5*d+2.1+c)+.025*Math.sin(8*d+1.3),p=K(n+Math.cos(d)*a*f*t,o+Math.sin(d)*l*f*t);h.push(p.x,p.y+s)}return e.poly(h)}drawTerrain(){const e=this.terrain,t=this.theme.ground;if(this.theme.terrain==="island"){this.blobPath(e,1,18).fill(t.edgeDark),this.blobPath(e,1,10).fill(t.edge),this.blobPath(e,1,0).fill(t.sand),this.blobPath(e,.88,-1).fill(t.fill),this.blobPath(e,.6,-2).fill({color:t.fillLight,alpha:.55});const s=this.world.bounds,r=K(s.x+s.w/2,s.y+s.h/2),n=(s.w+s.h)*14;e.circle(r.x-n*.45,r.y-n*.35,n*.9).fill({color:16777215,alpha:.07}),e.circle(r.x+n*.5,r.y+n*.4,n*1.1).fill({color:this.shadowInk,alpha:.08})}else if(this.theme.terrain==="platform"){const s=this.world.bounds,r=De(s.x,s.y,Math.max(s.w,s.h));e.poly(X([r[3],r[2],F(r[2],-14),F(r[3],-14)])).fill(t.edgeDark),e.poly(X([r[2],r[1],F(r[1],-14),F(r[2],-14)])).fill(t.edge),e.poly(X(r)).fill(t.fill),e.poly(X(De(s.x+1,s.y+1,Math.max(s.w,s.h)-2))).fill({color:t.fillLight,alpha:.25}),e.poly(X(r)).stroke({width:2,color:t.sand,alpha:.6})}else{const s=this.world.bounds,r=Math.max(s.w,s.h),n=De(s.x,s.y,r);e.poly(X([n[3],n[2],F(n[2],-10),F(n[3],-10)])).fill(t.edgeDark),e.poly(X([n[2],n[1],F(n[1],-10),F(n[2],-10)])).fill(t.edge),e.poly(X(n)).fill(t.fill);for(let o=1;o<r;o+=2){const a=K(s.x+o,s.y),l=K(s.x+o,s.y+r);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:t.sand,alpha:.12})}for(let o=1;o<r;o+=2){const a=K(s.x,s.y+o),l=K(s.x+r,s.y+o);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:t.sand,alpha:.12})}}}drawRipples(){const e=this.ripples;if(e.clear(),this.theme.terrain!=="island"){const t=li(this.world.seed);for(let s=0;s<70;s++){const r=(t()-.5)*2600,n=(t()-.5)*1600,o=.5+.5*Math.sin(this.time*(.6+t())+s);e.circle(r,n,.8+t()*1.2).fill({color:this.theme.water.ripple,alpha:this.theme.water.rippleAlpha*o})}return}for(let t=0;t<3;t++){const s=(this.time*.06+t/3)%1;this.blobPath(e,1.04+s*.45,8).stroke({width:1.4,color:this.theme.water.ripple,alpha:this.theme.water.rippleAlpha*.7*(1-s)})}}drawPaths(){const e=this.paths;for(const t of this.world.paths){const s=t.points.map(([r,n])=>K(r+.5,n+.5));e.moveTo(s[0].x,s[0].y);for(const r of s.slice(1))e.lineTo(r.x,r.y);e.stroke({width:7,color:this.theme.pathColor,alpha:.9,cap:"round",join:"round"})}}drawLabels(){const e=new As({fontFamily:"Fredoka, Trebuchet MS, sans-serif",fontSize:22,fontWeight:"700",fill:16777215,letterSpacing:2,stroke:{color:this.theme.vignette,width:4,join:"round"}});for(const t of this.world.districts){const s=new Sp({text:t.label,style:e});s.anchor.set(.5,.5);const r=K(t.bounds.x+t.bounds.w/2+.5,t.bounds.y+t.bounds.h+.55);s.position.set(r.x,r.y),s.alpha=.55,s.skew.set(-.35,.17),this.labels.addChild(s)}}placeProps(){const e=li(this.world.seed^2654435769),t=new Set;for(const a of this.world.places)for(let l=0;l<a.footprint;l++)for(let h=0;h<a.footprint;h++)t.add(`${a.gx+l},${a.gy+h}`);const s=this.world.bounds;let r=0,n=0;const o=Math.min(18,5+Math.floor(this.world.places.length/5));for(;n<o&&r++<700;){const a=Math.floor(s.x+1+e()*(s.w-2)),l=Math.floor(s.y+1+e()*(s.h-2));if(t.has(`${a},${l}`)||this.world.districts.some(_=>a>=_.bounds.x&&a<_.bounds.x+_.bounds.w&&l>=_.bounds.y&&l<_.bounds.y+_.bounds.h))continue;t.add(`${a},${l}`);const h=new _e;h.zIndex=hu(a,l);const c=new Pe;h.addChild(c);const u=K(a+.5,l+.5),d=(.85+e()*.4)*1.25,[f,p,g]=this.theme.propColors;let m;this.theme.prop==="tree"?(c.ellipse(u.x+3,u.y+1,9*d,4*d).fill({color:666138,alpha:.18}),c.rect(u.x-1.5,u.y-10*d,3,10*d).fill(g),m=new Pe,m.ellipse(u.x+1*d,u.y-13*d,9.5*d,7.5*d).fill(J(f,this.shadowInk,.25)),m.ellipse(u.x,u.y-16*d,9*d,8.5*d).fill(f),m.ellipse(u.x-4*d,u.y-19*d,6.5*d,6*d).fill(p),m.ellipse(u.x+4.5*d,u.y-20*d,5.5*d,5*d).fill(p),m.ellipse(u.x-3.5*d,u.y-22*d,3.2*d,2.4*d).fill({color:16777215,alpha:.32}),h.addChild(m)):this.theme.prop==="antenna"?(c.rect(u.x-1,u.y-18*d,2,18*d).fill(f),c.circle(u.x,u.y-20*d,2.5).fill(p),c.ellipse(u.x,u.y,5*d,2.5*d).fill(g)):(c.rect(u.x-1,u.y-16*d,2,16*d).fill(g),c.circle(u.x,u.y-17*d,3).fill(f),c.circle(u.x,u.y-17*d,7).fill({color:p,alpha:.18})),this.objects.addChild(h),this.props.push({g:c,gx:a,gy:l,phase:e()*6.28,...m?{canopy:m}:{}}),n++}}}const ub=i=>J(i,16777215,.25);function db(i,e,t,s){return new je({start:{x:0,y:t},end:{x:0,y:s},colorStops:[{offset:0,color:i},{offset:1,color:e}],textureSpace:"global"})}function fb(i,e,t,s){return new je({start:{x:t,y:0},end:{x:s,y:0},colorStops:[{offset:0,color:i},{offset:1,color:e}],textureSpace:"global"})}const Vi=i=>Math.round(i/2)*2;function J(i,e,t){const s=i>>16&255,r=i>>8&255,n=i&255,o=e>>16&255,a=e>>8&255,l=e&255,h=Math.round(s+(o-s)*t),c=Math.round(r+(a-r)*t),u=Math.round(n+(l-n)*t);return h<<16|c<<8|u}class Io{constructor(e,t,s){this.id=e,this.theme=t,this.reducedMotion=s,this.container.addChild(this.g)}container=new _e;g=new Pe;t=Math.random()*10;x=0;y=0;scale=1;alpha=1;lift=0;panic=0;peek=0;update(e){this.t+=e/1e3;const t=this.t,s=this.g,r=this.theme.gremlin,n=this.reducedMotion?0:Math.abs(Math.sin(t*(7+this.panic*5)))*(6+this.panic*3);this.container.position.set(this.x,this.y),this.container.alpha=this.alpha,s.clear(),s.ellipse(0,0,7*this.scale,3*this.scale).fill({color:994600,alpha:.25}),s.position.set(0,0);const o=this.scale,a=9,l=[];for(let u=0;u<=a*2;u++){const d=u/(a*2)*Math.PI*2,f=(u%2?7.2:9.6+Math.sin(t*20+u)*.7)*o;l.push(Math.cos(d)*f,-9*o-n-this.lift+Math.sin(d)*f*.9)}s.poly(l).fill(r.body);const h=-10*o-n-this.lift;s.ellipse(-3*o,h,2.4*o,2.6*o).fill(16777215),s.ellipse(3*o,h,2.4*o,2.6*o).fill(16777215);const c=this.panic?Math.sin(t*9)*.8:.4;s.ellipse(-2.6*o+c,h+.4,1.2*o,1.3*o).fill(r.eye),s.ellipse(3.4*o+c,h+.4,1.2*o,1.3*o).fill(r.eye),s.moveTo(-5.5*o,h-4*o).lineTo(-1.2*o,h-2.4*o).moveTo(5.5*o,h-4*o).lineTo(1.2*o,h-2.4*o).stroke({width:1.3*o,color:r.eye,cap:"round"}),s.moveTo(-2.6*o,h+4.4*o).lineTo(-1.2*o,h+3.4*o).lineTo(.2*o,h+4.4*o).lineTo(1.6*o,h+3.4*o).lineTo(2.9*o,h+4.4*o).stroke({width:1.3*o,color:r.eye,cap:"round"})}}const pb=Object.freeze(Object.defineProperty({__proto__:null,Gremlin:Io},Symbol.toStringTag,{value:"Module"}));class mb{constructor(e){this.reducedMotion=e}g=new Pe;parts=[];burst(e,t,s,r,n,o=0){this.reducedMotion&&(s=Math.ceil(s/4));for(let a=0;a<s;a++){const l=Math.random()*Math.PI*2,h=n*(.4+Math.random()*.8);this.parts.push({x:e,y:t,vx:Math.cos(l)*h,vy:Math.sin(l)*h*.6-o*(.5+Math.random()),life:0,max:.7+Math.random()*.8,c:r[a%r.length],r:1.4+Math.random()*2.4})}}clear(){this.parts=[],this.g.clear()}get count(){return this.parts.length}update(e){const t=e/1e3;this.parts=this.parts.filter(s=>(s.life+=t)<s.max),this.g.clear();for(const s of this.parts)s.vy+=140*t,s.x+=s.vx*t,s.y+=s.vy*t,this.g.rect(s.x-s.r/2,s.y-s.r/2,s.r,s.r*1.3).fill({color:s.c,alpha:1-s.life/s.max})}}const wt=[{id:"pip",name:"Pip",bio:"Curious, quick, a little clumsy. The original.",shape:"round",topper:"antenna",eyes:"wide",body:16751164,bodyLight:16765566,belly:16774620,ear:14712620,cheek:16739930,ink:2759959,size:1},{id:"mo",name:"Mo",bio:"Tall, calm, measures twice.",shape:"tall",topper:"tuft",eyes:"sleepy",body:6269183,bodyLight:11129599,belly:15398143,ear:4161488,cheek:16748448,ink:1385274,size:1.1},{id:"juno",name:"Juno",bio:"Bright, chatty, finds the bug by talking to it.",shape:"bean",topper:"ears",eyes:"wide",body:8380554,bodyLight:13172672,belly:15990768,ear:5223526,cheek:16756896,ink:1456671,size:.95},{id:"rook",name:"Rook",bio:"Boxy, deliberate, never guesses.",shape:"boxy",topper:"crest",eyes:"visor",body:10134712,bodyLight:14015462,belly:15659510,ear:7239820,cheek:8188927,ink:1778224,size:1.05},{id:"fen",name:"Fen",bio:"Quiet and sharp. Reads everything first.",shape:"teardrop",topper:"leaf",eyes:"dot",body:11967743,bodyLight:14734079,belly:16183551,ear:9401062,cheek:16754392,ink:2759498,size:.9},{id:"sol",name:"Sol",bio:"Warm, loud, celebrates everything.",shape:"round",topper:"halo",eyes:"wide",body:16765503,bodyLight:16773288,belly:16776166,ear:14723072,cheek:16747610,ink:3811845,size:1.08},{id:"ivy",name:"Ivy",bio:"Patient gardener of code. Hates loose ends.",shape:"bean",topper:"leaf",eyes:"sleepy",body:4177818,bodyLight:10481880,belly:15400952,ear:2788464,cheek:16756896,ink:997934,size:1},{id:"bolt",name:"Bolt",bio:"Fast. Sometimes too fast.",shape:"teardrop",topper:"crest",eyes:"dot",body:16734878,bodyLight:16756944,belly:16773366,ear:13645178,cheek:16765566,ink:3804962,size:.92},{id:"ash",name:"Ash",bio:"Dry wit, steady hands.",shape:"tall",topper:"ears",eyes:"sleepy",body:8024976,bodyLight:12104396,belly:15657973,ear:5656684,cheek:16758087,ink:1709872,size:1.06},{id:"nimbus",name:"Nimbus",bio:"Soft, cloud-headed, surprisingly precise.",shape:"round",topper:"halo",eyes:"wide",body:15660287,bodyLight:16777215,belly:16777215,ear:13228272,cheek:16756936,ink:2767442,size:1.02},{id:"ember",name:"Ember",bio:"Runs hot. Loves a red lighthouse.",shape:"boxy",topper:"antenna",eyes:"visor",body:16739133,bodyLight:16756874,belly:16773606,ear:12862506,cheek:16769899,ink:3805704,size:1},{id:"tove",name:"Tove",bio:"Small, brave, follows the map.",shape:"bean",topper:"tuft",eyes:"dot",body:13214827,bodyLight:15653293,belly:16775142,ear:10254916,cheek:16747610,ink:3811856,size:.85}],Pg=i=>wt.find(e=>e.id===i),cu=i=>(.2126*(i>>16&255)+.7152*(i>>8&255)+.0722*(i&255))/255,Ag=(i,e)=>Math.abs(cu(i.body)-cu(e))>.22;function Rg(i,e,t){const s=a=>t===void 0||Ag(a,t);let r=Pg(e)??wt[i%wt.length];s(r)||(r=wt.find((a,l)=>l>=i%wt.length&&s(a))??wt.find(s)??r);const n=wt.filter(a=>a.id!==r.id&&s(a)),o=n.length?(i>>>3)%n.length:0;return{lead:r,helpers:[...n.slice(o),...n.slice(0,o)]}}const gb=Object.freeze(Object.defineProperty({__proto__:null,CAST:wt,castById:Pg,pickCompany:Rg,readableOn:Ag},Symbol.toStringTag,{value:"Module"}));class Go{constructor(e,t,s=wt[0]){this.theme=e,this.reducedMotion=t,this.spec=s,this.container.addChild(this.shadow,this.body),this.container.scale.set(1.75*s.size)}container=new _e;shadow=new Pe;body=new Pe;t=0;pose={x:0,y:0,lift:0,sx:1,sy:1,lean:0,face:1,moving:!1,look:"fwd",mood:"curious",hiding:0};shown={x:0,y:0,lift:0,sx:1,sy:1,lean:0,face:1,faceK:1};snapNext=!0;snap(){this.snapNext=!0}get drawn(){return{x:this.shown.x,y:this.shown.y}}setTheme(e){this.theme=e}update(e){this.t+=e/1e3;const t=this.pose,s=this.spec,r=this.t,n=this.shown,o=Math.min(.05,e/1e3);this.snapNext&&(Object.assign(n,{x:t.x,y:t.y,lift:t.lift,sx:t.sx,sy:t.sy,lean:t.lean,face:t.face,faceK:1}),this.snapNext=!1);const a=1-Math.pow(5e-4,o),l=1-Math.pow(.002,o);n.x+=(t.x-n.x)*l,n.y+=(t.y-n.y)*l,n.lift+=(t.lift-n.lift)*a,n.sx+=(t.sx-n.sx)*a,n.sy+=(t.sy-n.sy)*a,n.lean+=(t.lean-n.lean)*a,n.face!==t.face?(n.faceK-=o*9,n.faceK<=0&&(n.face=t.face,n.faceK=.01)):n.faceK=Math.min(1,n.faceK+o*9);const h={...t,x:n.x,y:n.y,lift:n.lift,sx:n.sx*Math.max(.15,n.faceK),sy:n.sy,lean:n.lean,face:n.face};this.container.position.set(h.x,h.y),this.container.zIndex=1e6;const c=1-Math.min(.6,h.lift/90);this.shadow.clear().ellipse(0,0,11*c,5*c).fill({color:0,alpha:.28}),this.shadow.ellipse(0,0,14*c,7*c).fill({color:0,alpha:.1});const u=this.body;u.clear(),u.position.set(0,-h.lift),u.rotation=h.lean,u.scale.set(h.sx,h.sy);const d=h.moving||this.reducedMotion?0:Math.sin(r*2.2)*.012;u.scale.set(h.sx*(1-d),h.sy*(1+d));const f=h.moving?Math.sin(r*11)*3:0;switch(u.ellipse(-5+f,-1.5,4.2,2.6).fill(s.ear),u.ellipse(5-f,-1.5,4.2,2.6).fill(s.ear),s.shape){case"tall":u.ellipse(0,-16,9.5,16.5).fill(s.body),u.ellipse(-1.5,-21,7.5,9).fill({color:s.bodyLight,alpha:.55});break;case"boxy":u.roundRect(-11,-26,22,26,6).fill(s.body),u.roundRect(-9,-24,12,10,4).fill({color:s.bodyLight,alpha:.5});break;case"teardrop":u.moveTo(0,-30).quadraticCurveTo(13,-16,11,-6).quadraticCurveTo(0,2,-11,-6).quadraticCurveTo(-13,-16,0,-30).fill(s.body),u.ellipse(-2,-16,6,7).fill({color:s.bodyLight,alpha:.5});break;case"bean":u.ellipse(0,-12,12.5,11.5).fill(s.body),u.ellipse(-2,-18,8,6).fill({color:s.bodyLight,alpha:.55});break;default:u.ellipse(0,-13.5,11.5,13.5).fill(s.body),u.ellipse(-1.5,-17,9.5,9).fill({color:s.bodyLight,alpha:.55})}const p=s.shape==="tall"?9.5:s.shape==="boxy"?11:s.shape==="bean"?12.5:11.5,g=s.shape==="tall"?-16:s.shape==="boxy"?-13:s.shape==="bean"?-12:-13.5;u.moveTo(-p*.9,g-p*.2).quadraticCurveTo(-p*.75,g-p*.95,p*.1,g-p*1.02).stroke({width:2.2,color:16777215,alpha:.5,cap:"round"}),u.moveTo(p*.95,g+p*.1).quadraticCurveTo(p*.8,g+p*.8,p*.1,g+p*.98).stroke({width:2.4,color:this.theme.sky[0],alpha:.28,cap:"round"}),u.ellipse(h.face*1.2,-7.5,6.5,5.5).fill({color:s.belly,alpha:.92}),u.ellipse(-8+h.face*1.5,-11,2.4,1.5).fill({color:s.cheek,alpha:.45}),u.ellipse(8+h.face*1.5,-11,2.4,1.5).fill({color:s.cheek,alpha:.45});const m=h.moving?Math.sin(r*14)*.25:0,_=s.shape==="tall"?-33:s.shape==="teardrop"?-30:-27;switch(s.topper){case"ears":u.ellipse(-9,_+4+m*6,3.2,5).fill(s.ear),u.ellipse(9,_+4-m*6,3.2,5).fill(s.ear);break;case"tuft":u.moveTo(-3,_+1).quadraticCurveTo(-6,_-9,1,_-12).moveTo(0,_).quadraticCurveTo(4,_-10,8,_-8).stroke({width:2.2,color:s.ear,cap:"round"});break;case"leaf":u.moveTo(0,_).quadraticCurveTo(2+m*10,_-8,8,_-12).quadraticCurveTo(4,_-4,0,_).fill(s.ear),u.moveTo(0,_).lineTo(5,_-7).stroke({width:1,color:s.belly,alpha:.7});break;case"crest":for(const T of[-6,-2,2,6])u.moveTo(T,_+1).lineTo(T*1.4,_-7-Math.abs(T)*.3).stroke({width:2.4,color:s.ear,cap:"round"});break;case"halo":u.ellipse(0,_-7,9,2.6).stroke({width:1.8,color:this.theme.mood[h.mood],alpha:.9});break;case"antenna":u.ellipse(-9,_+4+m*6,3.2,5).fill(s.ear),u.ellipse(9,_+4-m*6,3.2,5).fill(s.ear);break}const y=h.face*1.8,x=-16,b=!this.reducedMotion&&r%3.3<.13&&h.mood!=="happy";for(const T of[-1,1]){const k=y+T*4.6;if(h.mood==="happy"){u.beginPath(),u.arc(k,x+1.5,2.8,Math.PI*1.1,Math.PI*1.9).stroke({width:1.6,color:s.ink,cap:"round"});continue}if(b){u.moveTo(k-2.6,x).lineTo(k+2.6,x).stroke({width:1.6,color:s.ink,cap:"round"});continue}if(s.eyes==="visor"){T<0&&(u.roundRect(y-8.5,x-3,17,6,3).fill(16777215),u.roundRect(y-7+(h.look==="up"?0:1),x-1.5,5,3,1.5).fill(s.ink),u.roundRect(y+2+(h.look==="up"?0:1),x-1.5,5,3,1.5).fill(s.ink));continue}const E=s.eyes==="dot"?2.6:s.eyes==="sleepy"?2.4:h.mood==="focused"?3:4.3;u.ellipse(k,x,s.eyes==="dot"?2.6:3.4,E).fill(16777215),s.eyes==="sleepy"&&u.moveTo(k-3.4,x-2.2).lineTo(k+3.4,x-2.2).stroke({width:2,color:s.body});const A=!h.moving&&!this.reducedMotion&&r%4.1>3.3?Math.sin((r%4.1-3.3)/.8*Math.PI):0;let M=h.face*1.1+A*1.6,B=(h.look==="up"?-1.6:h.look==="down"?1.4:.3)-A*.8;h.mood==="lost"&&(M=Math.sin(r*3)*1.4,B=-1.2),u.ellipse(k+M,x+B,1.9,h.mood==="focused"?1.8:2.2).fill(s.ink),u.ellipse(k+M+.7,x+B-.8,.6,.6).fill(16777215),h.mood==="lost"&&u.moveTo(k-3,x-5.6-(T>0?0:1.3)).lineTo(k+3,x-5.6-(T>0?1.3:0)).stroke({width:1.6,color:s.ink,cap:"round"}),h.mood==="focused"&&u.moveTo(k-3.2,x-3.7-(T>0?1:0)).lineTo(k+3.2,x-3.7-(T>0?0:1)).stroke({width:1.6,color:s.ink,cap:"round"}),h.mood==="uneasy"&&u.moveTo(k-3,x-5).lineTo(k+3,x-6+(T>0?1.5:-1.5)).stroke({width:1.4,color:s.ink,cap:"round"})}u.beginPath(),h.mood==="happy"?u.arc(y,-10.5,3.2,0,Math.PI).fill(8007202):h.mood==="lost"||h.mood==="uneasy"?u.arc(y,-8.4,2.2,Math.PI*1.15,Math.PI*1.85).stroke({width:1.6,color:s.ink,cap:"round"}):u.arc(y,-11.2,1.9,Math.PI*.15,Math.PI*.85).stroke({width:1.6,color:s.ink,cap:"round"});const v=(this.reducedMotion?0:Math.sin(r*5)*2)-h.lean*10,w=this.theme.mood[h.mood];if(s.topper==="antenna"?(u.moveTo(0,_+.5).quadraticCurveTo(v*.5,_-5,v+1.5,_-9).stroke({width:1.4,color:s.ear}),u.circle(v+1.5,_-10,9).fill({color:w,alpha:.28}),u.circle(v+1.5,_-10,5.5).fill({color:w,alpha:.35}),u.circle(v+1.5,_-10,2.8).fill(w)):s.topper!=="halo"&&(u.circle(0,_-2,7).fill({color:w,alpha:.22}),u.circle(0,_-2,2.2).fill({color:w,alpha:.9})),h.hiding>0){const T=st(r*.5%1)*h.hiding;u.rotation=h.lean+T*.06}}}const _b=Object.freeze(Object.defineProperty({__proto__:null,Pip:Go},Symbol.toStringTag,{value:"Module"})),xt=[0,2,4,7,9],yb=[0,3,5,7,10],uu=[0,2,4,6,7,9,11],du=[0,2,3,5,7,9,10],xb=[0,2,4,5,7,9,10],bb=[0,2,4,6,8,10],vb=[0,1,4,5,7,8,11],In=[0,2,3,5,7,8,10],wb={island:{scale:xt,root:261.6,wave:"sine",gain:.05,every:16,len:[.45,.9]},orbit:{scale:uu,root:220,wave:"triangle",gain:.035,every:20,len:[.8,1.6]},metropolis:{scale:du,root:196,wave:"triangle",gain:.04,every:18,len:[.3,.7]},harbour:{scale:xb,root:233,wave:"sine",gain:.045,every:17,len:[.5,1.1]},observatory:{scale:bb,root:329.6,wave:"sine",gain:.035,every:22,len:[.9,1.8]},greenhouse:{scale:xt,root:293.7,wave:"triangle",gain:.045,every:15,len:[.35,.8]},workshop:{scale:xt,root:220,wave:"triangle",gain:.045,every:16,len:[.3,.6]},arcade:{scale:yb,root:261.6,wave:"square",gain:.025,every:12,len:[.15,.35]},kingdom:{scale:du,root:174.6,wave:"triangle",gain:.045,every:19,len:[.6,1.2]},outpost:{scale:In,root:196,wave:"sine",gain:.04,every:21,len:[.8,1.6]},snowfield:{scale:xt,root:392,wave:"sine",gain:.04,every:18,len:[.7,1.5]},canopy:{scale:xt,root:246.9,wave:"triangle",gain:.045,every:14,len:[.3,.7]},lagoon:{scale:xt,root:329.6,wave:"sine",gain:.045,every:15,len:[.4,.9]},volcano:{scale:In,root:146.8,wave:"sawtooth",gain:.03,every:20,len:[.9,1.8]},cloudtop:{scale:uu,root:392,wave:"sine",gain:.04,every:17,len:[.8,1.6]},reef:{scale:xt,root:174.6,wave:"sine",gain:.045,every:14,len:[.9,2]},bazaar:{scale:vb,root:220,wave:"triangle",gain:.045,every:13,len:[.25,.6]},monastery:{scale:xt,root:196,wave:"sine",gain:.05,every:24,len:[1.2,2.4]},moonbase:{scale:In,root:164.8,wave:"sine",gain:.035,every:23,len:[1,2]},lanterns:{scale:xt,root:523.3,wave:"sine",gain:.04,every:14,len:[.3,.7]}},Xe={wave:"triangle",pitch:1,decay:1,tone:3200,surface:"grass"},Gn={wave:"square",pitch:1.18,decay:.8,tone:2600,surface:"metal"},fu={wave:"sawtooth",pitch:.95,decay:1.1,tone:2200,surface:"stone"},Tb={island:"pluck",orbit:"blip",metropolis:"synth",harbour:"wood",observatory:"glass",greenhouse:"marimba",workshop:"wood",arcade:"blip",kingdom:"bell",outpost:"pluck",snowfield:"glass",canopy:"marimba",lagoon:"drop",volcano:"synth",cloudtop:"glass",reef:"drop",bazaar:"pluck",monastery:"bell",moonbase:"blip",lanterns:"bell"},Sb={island:"relax",orbit:"focus",metropolis:"focus",harbour:"relax",observatory:"focus",greenhouse:"relax",workshop:"fun",arcade:"fun",kingdom:"fun",outpost:"focus",snowfield:"relax",canopy:"fun",lagoon:"relax",volcano:"focus",cloudtop:"relax",reef:"relax",bazaar:"fun",monastery:"focus",moonbase:"focus",lanterns:"fun"},Cb={island:{voice:Xe,ambience:{washes:[{hz:520,q:.6,gain:.09,lfoHz:.11,depth:.6},{hz:240,q:.9,gain:.05,lfoHz:.07,depth:.8}],extras:["gull","cricket"],every:9}},orbit:{voice:Gn,ambience:{washes:[{hz:900,q:2,gain:.015,lfoHz:.05,depth:.9}],pad:{chord:[55,110,164.8],gain:.05,wave:"sine"},extras:["hum","chime"],every:11}},metropolis:{voice:fu,ambience:{washes:[{hz:380,q:.5,gain:.07,lfoHz:.2,depth:.5}],pad:{chord:[65.4,98],gain:.03,wave:"triangle"},extras:["horn","hum"],every:10}},harbour:{voice:{...Xe,surface:"wood",decay:1.3},ambience:{washes:[{hz:420,q:.6,gain:.1,lfoHz:.09,depth:.7}],extras:["gull","bell","horn"],every:8}},observatory:{voice:{...Gn,wave:"sine",pitch:1.3,decay:1.6,tone:4e3,surface:"stone"},ambience:{washes:[{hz:300,q:.8,gain:.04,lfoHz:.04,depth:.9}],pad:{chord:[49,98,146.8],gain:.04,wave:"sine"},extras:["wind","chime"],every:12}},greenhouse:{voice:{...Xe,pitch:1.1,decay:1.2},ambience:{washes:[{hz:600,q:.6,gain:.05,lfoHz:.1,depth:.5}],extras:["cricket","drip","bell"],every:7}},workshop:{voice:{...Xe,wave:"triangle",pitch:.9,decay:.8,tone:2800,surface:"wood"},ambience:{washes:[{hz:500,q:.6,gain:.05,lfoHz:.12,depth:.5}],extras:["cricket","bell"],every:9}},arcade:{voice:{wave:"square",pitch:1.35,decay:.6,tone:3600,surface:"neon"},ambience:{washes:[{hz:300,q:.5,gain:.05,lfoHz:.25,depth:.4}],pad:{chord:[65.4,82.4,98],gain:.03,wave:"square"},extras:["chime","horn"],every:6}},kingdom:{voice:{...Xe,wave:"triangle",pitch:.85,decay:1.5,tone:2400,surface:"stone"},ambience:{washes:[{hz:450,q:.6,gain:.07,lfoHz:.1,depth:.6}],extras:["bell","wind","owl"],every:10}},outpost:{voice:{...Xe,pitch:.92,decay:1.4,tone:2600,surface:"sand"},ambience:{washes:[{hz:700,q:.4,gain:.08,lfoHz:.06,depth:.9}],extras:["wind","hum"],every:9}},snowfield:{voice:{...Xe,wave:"sine",pitch:1.15,decay:1.7,tone:3400,surface:"snow"},ambience:{washes:[{hz:800,q:.4,gain:.05,lfoHz:.05,depth:.9}],extras:["wind","chime","owl"],every:11}},canopy:{voice:{...Xe,pitch:1.05,decay:1.2,tone:3e3,surface:"wood"},ambience:{washes:[{hz:650,q:.7,gain:.07,lfoHz:.09,depth:.5}],extras:["cricket","owl","drip"],every:6}},lagoon:{voice:{...Xe,wave:"sine",pitch:1.2,decay:1.3,tone:3600,surface:"sand"},ambience:{washes:[{hz:480,q:.6,gain:.1,lfoHz:.1,depth:.7}],extras:["gull","bubble"],every:8}},volcano:{voice:{wave:"sawtooth",pitch:.75,decay:1.6,tone:1600,surface:"stone"},ambience:{washes:[{hz:160,q:1,gain:.1,lfoHz:.08,depth:.8}],pad:{chord:[41.2,61.7],gain:.04,wave:"sawtooth"},extras:["rumble","wind"],every:8}},cloudtop:{voice:{...Xe,wave:"sine",pitch:1.25,decay:1.8,tone:4200,surface:"grass"},ambience:{washes:[{hz:900,q:.4,gain:.05,lfoHz:.04,depth:.9}],pad:{chord:[130.8,196,261.6],gain:.025,wave:"sine"},extras:["wind","chime"],every:12}},reef:{voice:{wave:"sine",pitch:.9,decay:1.9,tone:1400,surface:"water"},ambience:{washes:[{hz:220,q:1.2,gain:.09,lfoHz:.09,depth:.7}],extras:["bubble","drip"],every:5}},bazaar:{voice:{...Xe,pitch:1.05,decay:.9,tone:3e3,surface:"sand"},ambience:{washes:[{hz:500,q:.5,gain:.06,lfoHz:.3,depth:.4}],extras:["market","bell","chime"],every:6}},monastery:{voice:{...Xe,wave:"sine",pitch:.95,decay:2,tone:2600,surface:"stone"},ambience:{washes:[{hz:420,q:.5,gain:.05,lfoHz:.05,depth:.8}],extras:["bell","wind","owl"],every:12}},moonbase:{voice:{...Gn,pitch:1.05,decay:1.2,tone:2200},ambience:{washes:[{hz:240,q:1.5,gain:.03,lfoHz:.03,depth:.9}],pad:{chord:[55,82.4],gain:.04,wave:"sine"},extras:["hum","chime"],every:13}},lanterns:{voice:{...fu,wave:"triangle",pitch:1.1,decay:1.2,tone:3e3,surface:"stone"},ambience:{washes:[{hz:400,q:.5,gain:.05,lfoHz:.2,depth:.5}],extras:["market","chime","bell"],every:6}}},Do=Object.fromEntries(Object.entries(Cb).map(([i,e])=>[i,{...e,voice:{...e.voice,instrument:Tb[i]},ambience:{...e.ambience,mood:Sb[i]},tune:wb[i]}])),Mb=i=>i,kb=new Set(["curtain_up","curtain_down","test_outcome","celebrate","blocked_on_you","unverified_claim","spawn_gremlin","banish"]),Eb=[523.25,659.25,783.99,1046.5],Ie=(i,e)=>i+Math.random()*(e-i);class ji{constructor(e){this.a=e}footstep(e,t){const s=this.a;switch(e){case"stone":s.noise(.04,{filter:"bandpass",freq:Ie(1400,1900),q:2,gain:.05,pan:t}),s.tone(Ie(160,200),.03,{type:"triangle",gain:.03,pan:t});return;case"metal":s.tone(Ie(700,900),.05,{type:"square",gain:.03,lowpass:2e3,pan:t}),s.noise(.03,{filter:"highpass",freq:3e3,gain:.03,pan:t});return;case"sand":s.noise(.09,{filter:"lowpass",freq:Ie(700,1e3),q:.5,gain:.05,pan:t});return;case"snow":s.noise(.08,{filter:"bandpass",freq:Ie(2500,3500),q:.8,gain:.04,pan:t});return;case"wood":s.tone(Ie(220,300),.05,{type:"triangle",gain:.05,slideTo:120,pan:t});return;case"water":s.noise(.08,{filter:"bandpass",freq:Ie(400,700),q:1,gain:.05,sweepTo:1200,pan:t});return;case"neon":s.tone(Ie(900,1200),.035,{type:"square",gain:.025,lowpass:3e3,pan:t});return;default:s.noise(.05,{filter:"bandpass",freq:Ie(900,1300),q:1.2,gain:.05,pan:t});return}}static plays(e,t){return t<=1.01||kb.has(e)}take={pitch:.92+Math.random()*.18,decay:.85+Math.random()*.4,tone:.8+Math.random()*.5,swap:Math.random()<.3};play(e,t){const s=this.a,r=t.pan??0,n=t.intensity??.5,o=Do[t.theme.id].voice,a=this.take,l={sine:"triangle",triangle:"sine",square:"sawtooth",sawtooth:"square",custom:"sine"},h={...o,pitch:o.pitch*a.pitch,decay:o.decay*a.decay,tone:o.tone*a.tone,wave:a.swap?l[o.wave]:o.wave},c={tone:(u,d,f={})=>{const p=.97+Math.random()*.06,g=.85+Math.random()*.3,m=u*h.pitch*p,_=d*h.decay*g,y=f.gain??.25,x={...f,lowpass:Math.min(f.lowpass??h.tone,h.tone),...f.slideTo?{slideTo:f.slideTo*h.pitch*p}:{}};switch(Mb(h.instrument)){case"pluck":s.tone(m,_*.6,{...x,type:"triangle",attack:.003,gain:y}),s.tone(m*2,_*.25,{...x,type:"sine",attack:.002,gain:y*.35}),s.noise(.012,{filter:"highpass",freq:3e3,gain:y*.3});return;case"bell":s.tone(m,_*1.8,{...x,type:"sine",attack:.004,gain:y}),s.tone(m*2.76,_*1.1,{...x,type:"sine",attack:.004,gain:y*.3}),s.tone(m*5.4,_*.5,{...x,type:"sine",attack:.004,gain:y*.12});return;case"marimba":s.tone(m,_*.5,{...x,type:"sine",attack:.003,gain:y}),s.tone(m*4,_*.12,{...x,type:"sine",attack:.002,gain:y*.25}),s.noise(.02,{filter:"bandpass",freq:1800,q:2,gain:y*.25});return;case"blip":s.tone(m,_*.35,{...x,type:"square",attack:.002,gain:y*.7}),s.tone(m*1.5,_*.2,{...x,type:"square",attack:.002,gain:y*.2});return;case"glass":s.tone(m,_*2,{...x,type:"sine",attack:.02,gain:y*.9}),s.tone(m*1.005,_*2,{...x,type:"sine",attack:.02,gain:y*.6}),s.tone(m*3,_*.8,{...x,type:"sine",attack:.01,gain:y*.15});return;case"wood":s.tone(m*.5,_*.3,{...x,type:"triangle",attack:.002,gain:y*.9,slideTo:m*.35}),s.noise(.04,{filter:"lowpass",freq:1200,gain:y*.5});return;case"drop":s.tone(m*.8,_*.7,{...x,type:"sine",attack:.006,gain:y,slideTo:m*1.6}),s.noise(.05,{filter:"bandpass",freq:900,q:1.5,gain:y*.25,sweepTo:2400});return;default:s.tone(m,_,{...x,type:f.type??h.wave,gain:y}),s.tone(m*.5,_*.8,{...x,type:"sawtooth",attack:.01,gain:y*.25,lowpass:900});return}},noise:s.noise.bind(s)};if(e==="footstep")return this.footstep(h.surface,r);switch(e){case"curtain_up":c.tone(392,1.2,{attack:.3,gain:.14}),c.tone(587.3,1.3,{attack:.5,gain:.1}),c.tone(784,1.4,{attack:.7,gain:.08});return;case"curtain_down":c.tone(523.25,1.6,{attack:.2,gain:.12}),c.tone(392,1.8,{attack:.4,gain:.1});return;case"walk_to":return;case"read":c.noise(.14,{filter:"highpass",freq:2500,sweepTo:6e3,gain:.07,pan:r}),c.tone(2200,.05,{gain:.04,pan:r});return;case"hammer":c.tone(Ie(180,240)*(1+n*.4),.06,{type:"triangle",gain:.12+n*.1,slideTo:90,pan:r}),c.noise(.03,{filter:"bandpass",freq:3e3,q:2,gain:.05,pan:r});return;case"build":return;case"raise":c.tone(220,.7,{type:"sawtooth",slideTo:660,gain:.08,lowpass:1800,pan:r}),c.tone(440,.3,{gain:.06,pan:r,attack:.3});return;case"forge":c.tone(620,.25,{type:"square",gain:.06,slideTo:580,lowpass:2400,pan:r}),c.tone(1240,.18,{type:"triangle",gain:.05,detune:30,pan:r}),c.noise(.08,{filter:"highpass",freq:4e3,gain:.04,pan:r});return;case"spark":c.tone(Ie(2500,4200),.04,{gain:.03,pan:r});return;case"search":c.noise(.35,{filter:"bandpass",freq:700,sweepTo:2600,q:1.5,gain:.08,pan:r}),c.tone(1568,.12,{gain:.05,pan:r,attack:.02});return;case"run_tests":c.tone(330,.9,{attack:.15,gain:.06,type:"triangle",lowpass:1200,pan:r}),c.tone(495,.9,{attack:.25,gain:.04,type:"triangle",lowpass:1200,pan:r});return;case"test_outcome":t.outcome==="pass"?Eb.forEach((u,d)=>setTimeout(()=>c.tone(u,.5,{gain:.12,attack:.01,pan:r}),d*70)):(c.tone(311,.35,{type:"sawtooth",gain:.09,lowpass:900,slideTo:262,pan:r}),setTimeout(()=>c.tone(233,.5,{type:"sawtooth",gain:.09,lowpass:700,slideTo:196,pan:r}),170));return;case"spawn_gremlin":for(let u=0;u<4;u++)setTimeout(()=>c.tone(Ie(900,1300)+u*80,.07,{type:"square",gain:.05,lowpass:2600,slideTo:Ie(700,1100),pan:r}),u*60);return;case"chase":for(let u=0;u<3;u++)setTimeout(()=>c.tone(600+u*120,.08,{type:"triangle",gain:.06,pan:r}),u*90);return;case"banish":c.noise(.06,{filter:"lowpass",freq:1500,gain:.14,pan:r}),setTimeout(()=>c.tone(2093,.25,{gain:.07,pan:r}),40),setTimeout(()=>c.tone(2637,.3,{gain:.05,pan:r}),90);return;case"celebrate":[523.25,659.25,783.99,1046.5,1318.5].forEach((u,d)=>setTimeout(()=>c.tone(u,.45,{gain:.11,attack:.01,pan:r}),d*60));for(let u=0;u<10;u++)setTimeout(()=>c.tone(Ie(1800,4e3),.05,{gain:.03,pan:Ie(-.8,.8)}),200+u*55);return;case"summon_helper":t.theme.id==="orbit"?c.noise(.7,{filter:"bandpass",freq:300,sweepTo:1800,q:1.2,gain:.1,pan:r}):t.theme.id==="metropolis"?(c.tone(880,.12,{type:"square",gain:.06,lowpass:2500,pan:r}),setTimeout(()=>c.tone(880,.12,{type:"square",gain:.06,lowpass:2500,pan:r}),180)):(c.tone(146.8,.8,{type:"triangle",attack:.08,gain:.12,lowpass:800,pan:r}),c.tone(147.5,.8,{type:"triangle",attack:.08,gain:.08,lowpass:800,pan:r}));return;case"dismiss_helper":c.noise(.5,{filter:"bandpass",freq:1800,sweepTo:300,q:1.2,gain:.07,pan:r});return;case"blocked_on_you":c.tone(880,.35,{gain:.16,attack:.01}),setTimeout(()=>c.tone(659.25,.6,{gain:.16,attack:.01}),220);return;case"your_turn":c.tone(1046.5,.5,{gain:.07,attack:.02});return;case"stumble":c.noise(.12,{filter:"lowpass",freq:400,gain:.14,pan:r}),c.tone(120,.25,{type:"triangle",gain:.1,slideTo:70,pan:r});return;case"unverified_claim":c.tone(196,.14,{type:"triangle",gain:.07,lowpass:900,pan:r}),setTimeout(()=>c.tone(185,.14,{type:"triangle",gain:.07,lowpass:900,pan:r}),240),setTimeout(()=>c.tone(174.6,.24,{type:"triangle",gain:.06,lowpass:900,pan:r}),480);return;case"idle":return}}}class Pb{constructor(e){this.a=e}stops=[];current=null;padStop=null;padMood=null;extraTimer=null;tuneTimer=null;moodTimer=null;start(e){if(!this.a.ready||this.current===e.id)return;this.stop(),this.current=e.id;const t=Do[e.id].ambience,s=Math.floor(Math.random()*8)-3,r=Math.pow(2,s/12),n={...t,washes:t.washes.map(d=>({...d,hz:d.hz*(.85+Math.random()*.35),lfoHz:d.lfoHz*(.7+Math.random()*.6),gain:d.gain*(.8+Math.random()*.4)})),pad:t.pad?{...t.pad,chord:t.pad.chord.map((d,f)=>d*r*(f>0&&Math.random()<.35?2:1))}:void 0,extras:[...t.extras].sort(()=>Math.random()-.5).slice(0,Math.max(1,Math.ceil(t.extras.length*(.5+Math.random()*.5)))),every:t.every*(.7+Math.random()*.6)};for(const d of n.washes)this.stops.push(this.a.wash(d.hz,d.q,d.gain,d.lfoHz,d.depth));n.pad&&this.stops.push(this.a.pad(n.pad.chord,n.pad.gain,n.pad.wave));const o=()=>{if(this.current!==e.id)return;const d=n.extras[Math.floor(Math.random()*n.extras.length)];d&&this.a.extra(d),this.extraTimer=setTimeout(o,n.every*1e3*(.5+Math.random()))};this.extraTimer=setTimeout(o,2e3+Math.random()*3e3);const a=Do[e.id].tune,l=Math.floor(Math.random()*a.scale.length),h={...a,root:a.root*r,scale:a.scale.map((d,f)=>(a.scale[(f+l)%a.scale.length]-a.scale[l]+12)%12).sort((d,f)=>d-f),every:a.every*(.7+Math.random()*.6)},c=()=>{if(this.current!==e.id)return;const d=4+Math.floor(Math.random()*4);let f=Math.floor(Math.random()*h.scale.length),p=Math.random()<.3?1:0,g=0;for(let m=0;m<d;m++){const _=m===d-1?-(f%3):Math.round((Math.random()-.5)*4);f+=_,f<0&&(f+=h.scale.length,p=Math.max(0,p-1)),f>=h.scale.length&&(f-=h.scale.length,p=Math.min(1,p+1));const y=h.root*Math.pow(2,(h.scale[f]+12*p)/12),x=h.len[0]+Math.random()*(h.len[1]-h.len[0]),b=m===d-1?x*2.2:x;setTimeout(()=>{this.current===e.id&&this.a.note(y,b,h.gain*(.8+Math.random()*.4),h.wave,(Math.random()-.5)*.8)},g*1e3),g+=x*(Math.random()<.2?1.5:1)}this.tuneTimer=setTimeout(c,(g+h.every*(.6+Math.random()*.9))*1e3)};this.tuneTimer=setTimeout(c,4e3+Math.random()*4e3);const u=n.pad?.chord??[h.root/2,h.root*.75,h.root];if(n.mood==="focus"){const d=56+Math.random()*10,f=u[0]/2,p=()=>{this.current===e.id&&(this.a.note(f,.18,.035,"sine",0),this.moodTimer=setTimeout(p,6e4/d))};this.moodTimer=setTimeout(p,1500)}else if(n.mood==="fun"){const d=()=>{if(this.current!==e.id)return;const f=[...u,...u.slice(0,-1).reverse()].map(p=>p*(Math.random()<.5?2:4));f.forEach((p,g)=>setTimeout(()=>{this.current===e.id&&this.a.note(p,.22,.03,"triangle",(g/f.length-.5)*.8)},g*(150+g%2*40))),this.moodTimer=setTimeout(d,9e3+Math.random()*12e3)};this.moodTimer=setTimeout(d,3e3+Math.random()*3e3)}}setMood(e){if(!this.a.ready||e===this.padMood)return;this.padMood=e,this.padStop?.();const t=e==="happy"?[261.6,329.6,392]:e==="lost"?[261.6,311.1,370]:e==="uneasy"?[261.6,311.1,392]:e==="focused"?[261.6,392]:[261.6,329.6];this.padStop=this.a.pad(t.map(s=>s/2),.022,"sine")}stop(){this.extraTimer&&clearTimeout(this.extraTimer),this.extraTimer=null,this.tuneTimer&&clearTimeout(this.tuneTimer),this.tuneTimer=null,this.moodTimer&&clearTimeout(this.moodTimer),this.moodTimer=null;for(const e of this.stops)e();this.stops=[],this.padStop?.(),this.padStop=null,this.padMood=null,this.current=null}}class Ys{constructor(e,t,s,r,n,o){this.app=e,this.world=t,this.theme=s,this.audio=r,this.reducedMotion=n,this.worldLayer=new Eg(t,s),this.particles=new mb(n),this.company=Rg(t.seed,o,s.ground.fill),this.pip=new Go(s,n,this.company.lead),this.camera=new ab(this.stage,n),this.sfx=new ji(r),this.amb=new Pb(r),this.stage.sortableChildren=!0,this.stage.addChild(this.worldLayer.container),this.worldLayer.container.sortableChildren=!0,this.worldLayer.container.addChild(this.pip.container,this.particles.g),this.particles.g.zIndex=1e7,e.stage.addChild(this.stage),this.actorAt.set("pip","forge"),this.fitCamera(),this.camera.snap()}stage=new _e;worldLayer;camera;pip;helpers=new Map;gremlins=new Map;particles;sfx;amb;beats=[];t=0;prevT=-1;_playing=!1;rate=1;duration=0;mood="curious";actorAt=new Map;walkFrom=new Map;growth=new Map;lastPass=0;signal="ok";footT=0;hammerT=0;claimGremlinId=null;evidenceCount=null;company;helperIndex=0;load(e){this.beats=e,this.duration=e.length?Math.max(...e.map(t=>t.atMs+t.durationMs)):0,this.seek(0)}get beatCount(){return this.beats.length}append(e){this.beats.push(...e),this.duration=Math.max(this.duration,...e.map(t=>t.atMs+t.durationMs))}get playing(){return this._playing}play(){this._playing=!0,this.amb.start(this.theme)}audioReady(){this.amb.stop(),this._playing&&this.amb.start(this.theme)}pause(){this._playing=!1}setRate(e){this.rate=e}setSignal(e){this.signal=e}seek(e){this.t=Math.max(0,Math.min(this.duration,e)),this.rebuild(this.t),this.prevT=this.t,this.particles.clear()}get leadName(){return this.company.lead.name}get state(){const e=this.currentBeat();return{t:this.t,duration:this.duration,playing:this._playing,rate:this.rate,current:e,mood:this.mood,bubble:this.bubble(e),labels:this.labels(e),evidence:this.evidenceCount!==null?{passed:this.evidenceCount}:null,signal:this.signal}}update(e){this._playing&&(this.t=Math.min(this.duration,this.t+e*this.rate),this.t>=this.duration&&this.duration>0&&(this._playing=!1),this.triggerBetween(this.prevT,this.t),this.prevT=this.t);const t=this.currentBeat();this.pose(t,e),this.worldState(t),this.worldLayer.update(e),this.pip.update(e);for(const s of this.helpers.values())s.update(e);for(const s of this.gremlins.values())s.update(e);this.particles.update(e),this.cameraStep(t,e),this.amb.setMood(this.mood)}currentBeat(){let e=null;for(const t of this.beats)if(t.atMs<=this.t)(!e||t.atMs>=e.atMs)&&(t.kind==="idle"&&e&&e.kind!=="idle"&&e.atMs+e.durationMs>this.t||(e=t));else break;return e}completed(){return this.beats.filter(e=>e.atMs+e.durationMs<=this.t)}rebuild(e){this.actorAt.clear(),this.actorAt.set("pip","forge"),this.growth.clear(),this.lastPass=0,this.evidenceCount=null,this.mood="curious",this.claimGremlinId=null,this.helperIndex=0;for(const s of this.gremlins.values())s.container.destroy();this.gremlins.clear();for(const s of this.helpers.values())s.container.destroy();this.helpers.clear();for(const s of this.world.places)this.worldLayer.setLamp(s.id,"idle"),this.worldLayer.setGrowth(s.id,0),this.worldLayer.setGlow(s.id,0),this.worldLayer.setScaffold(s.id,0);for(const s of this.beats){if(s.atMs>e)break;this.onStart(s,!0),s.atMs+s.durationMs<=e&&this.onEnd(s,!0)}this.pip.pose.mood=this.mood;const t=this.worldLayer.standingSpot(this.actorAt.get("pip")??"forge");this.pip.pose.x=t.x,this.pip.pose.y=t.y,this.pip.snap(),this.camTarget=null,this.fitCamera(),this.cameraStep(this.currentBeat(),0),this.camera.snap()}triggerBetween(e,t){for(const s of this.beats){s.atMs>e&&s.atMs<=t&&this.onStart(s,!1);const r=s.atMs+s.durationMs;r>e&&r<=t&&this.onEnd(s,!1)}}onStart(e,t){this.mood=e.mood;const s=this.theme,r=o=>{const a=this.worldLayer.positionOf(o);return a?Math.max(-.8,Math.min(.8,a.ground.x/600)):0},n=(o,a={})=>{!t&&ji.plays(o,this.rate)&&this.sfx.play(o,{theme:s,...a})};switch(e.kind){case"curtain_up":n("curtain_up"),t||this.camera.pushIn(.12);break;case"walk_to":{const o=this.worldLayer.standingSpot(this.actorAt.get(e.actor)??"forge");this.walkFrom.set(e.actor,o);break}case"read":n("read",{pan:r(e.target)});break;case"raise":{if(e.newPlace&&!this.worldLayer.has(e.target)){const o=this.world.districts.find(l=>l.id===e.newPlace.district)??this.world.districts[0],a={id:e.target,kind:e.newPlace.kind,path:e.newPlace.path,label:e.newPlace.label,district:e.newPlace.district,gx:(o?.cx??2)+1,gy:(o?.cy??2)+1,footprint:1,height:1,score:0,touched:!0};this.world.places.push(a),this.worldLayer.addPlace(a)}n("raise",{pan:r(e.target)});break}case"build":n("build");break;case"forge":n("forge");break;case"search":n("search",{pan:r("forge")});break;case"run_tests":this.worldLayer.setLamp(e.target,"scan"),n("run_tests",{pan:r(e.target)});break;case"test_outcome":{const o=e.outcome==="pass"?"pass":e.outcome==="fail"?"fail":"idle";if(this.worldLayer.setLamp(e.target,o),e.outcome==="pass"&&(this.lastPass=e.atMs,this.evidenceCount=e.passed),n("test_outcome",{outcome:e.outcome,pan:r(e.target)}),!t&&e.outcome==="fail"&&this.camera.shake(200),!t&&e.outcome==="pass"){const a=this.worldLayer.positionOf(e.target);a&&this.particles.burst(a.top.x,a.top.y,16,[s.beacon.lamp.pass,14090217],70,40)}break}case"spawn_gremlin":{const o=new Io(e.gremlinId,s,this.reducedMotion),a=this.worldLayer.positionOf(e.target),l=a?a.ground:K(0,0);o.x=l.x+18,o.y=l.y+8,o.scale=t?1:.01,this.worldLayer.container.addChild(o.container),this.gremlins.set(e.gremlinId,o),n("spawn_gremlin",{pan:r(e.target)}),t||(this.camera.pushIn(.06),this.particles.burst(o.x,o.y-10,18,[s.gremlin.body,11967743],60,30));break}case"chase":{const o=this.gremlins.get(e.gremlinId);o&&(o.panic=1),n("chase",{pan:r(e.target)});break}case"banish":{const o=this.gremlins.get(e.gremlinId);o&&(t||this.particles.burst(o.x,o.y-10,30,[16777215,s.gremlin.body],80,35),o.container.destroy(),this.gremlins.delete(e.gremlinId)),this.claimGremlinId===e.gremlinId&&(this.claimGremlinId=null,this.pip.pose.hiding=0),n("banish");break}case"celebrate":{if(n("celebrate"),!t){this.camera.pushIn(.1);const o=this.worldLayer.standingSpot(this.actorAt.get("pip")??"forge");this.particles.burst(o.x,o.y-30,56,[16758087,6287526,8177919,16743273,11967743,16777215],130,90)}break}case"summon_helper":{const o=this.company.helpers[this.helperIndex++%this.company.helpers.length],a=new Go(s,this.reducedMotion,o);a.container.scale.set(.82*o.size);const l=this.worldLayer.standingSpot("dock");a.pose.x=l.x,a.pose.y=l.y,this.worldLayer.container.addChild(a.container),this.helpers.set(e.helperId,a),this.actorAt.set(e.helperId,"dock"),n("summon_helper",{pan:r("dock")});break}case"dismiss_helper":n("dismiss_helper",{pan:r("dock")});break;case"blocked_on_you":n("blocked_on_you");break;case"your_turn":n("your_turn");break;case"stumble":n("stumble"),t||this.camera.shake(160);break;case"unverified_claim":{const o=new Io(e.gremlinId,s,this.reducedMotion);o.scale=.8,o.alpha=.95,this.worldLayer.container.addChild(o.container),this.gremlins.set(e.gremlinId,o),this.claimGremlinId=e.gremlinId,this.pip.pose.hiding=1,n("unverified_claim");break}case"curtain_down":n("curtain_down");break}}onEnd(e,t){switch(e.kind){case"walk_to":this.actorAt.set(e.actor,e.target),this.walkFrom.delete(e.actor);break;case"build":this.growth.set(e.target,Math.min(18,(this.growth.get(e.target)??0)+3+Math.round(e.intensity*6))),this.worldLayer.setGrowth(e.target,this.growth.get(e.target)),this.worldLayer.setScaffold(e.target,0);break;case"dismiss_helper":{const s=this.helpers.get(e.helperId);s&&(s.container.destroy(),this.helpers.delete(e.helperId),this.actorAt.delete(e.helperId));break}}}pose(e,t){const s=t/1e3;for(const[r,n]of[["pip",this.pip],...this.helpers.entries()]){const o=n.pose;o.moving=!1,o.lift=0,o.sx=1,o.sy=1,o.lean=0,o.look="fwd",o.mood=this.mood;const a=e&&e.actor===r?e:null,l=this.worldLayer.standingSpot(this.actorAt.get(r)??(r==="pip"?"forge":"dock"));if(o.x=l.x,o.y=l.y,!a){r!=="pip"&&(o.sy=.96);continue}const h=Ue(this.t,a.atMs,a.atMs+a.durationMs),c="target"in a?this.worldLayer.standingSpot(a.target):l;switch(a.kind){case"curtain_up":{o.lift=(1-Math.min(1,h/.5))**2*150,o.sy=h<.5?1.1:1-.25*st(Ue(h,.5,.75)),o.sx=1/o.sy;break}case"walk_to":{const u=this.walkFrom.get(r)??l,d=Math.min(.22,140/a.durationMs),f=h<d?0:Rn((h-d)/(1-d));if(o.x=Jt(u.x,c.x,f),o.y=Jt(u.y,c.y,f),o.moving=h>=d&&h<.98,o.face=c.x>=u.x?1:-1,h<d){const p=st(h/d);o.sy=1-.1*p,o.sx=1+.08*p,o.lean=-o.face*.12*p}else{const p=this.t/1e3*(this.mood==="lost"?16:11);o.lift=Math.abs(Math.sin(p))*3.5;const g=Math.cos(p*2);if(o.sy=1+.05*g,o.sx=1-.05*g,o.lean=o.face*.07,h>.86){const m=st((h-.86)/.14);o.lean=o.face*.16*m,o.sy=1-.06*m,o.sx=1+.05*m}}r==="pip"&&this._playing&&(this.footT+=s,this.footT>.19&&ji.plays("footstep",this.rate)&&(this.footT=0,this.sfx.play("footstep",{theme:this.theme,pan:Math.max(-.8,Math.min(.8,o.x/600))})));break}case"read":{const u=st(this.t/1e3%1.4/.25);o.lean=-.17+Math.sin(this.t/1e3*3)*.03-u*.05,o.sy=1-u*.03,o.face=this.facing(o,a.target);break}case"build":case"forge":{const u=a.kind==="build"?.28-a.intensity*.1:.34,d=this.t/1e3%u/u,f=d<.7?d/.7:1-(d-.7)/.3;if(o.lift=f*4,o.lean=d<.7?-.06*f:.12*(1-f),o.sy=d<.7?1+.04*f:1-.08*(1-f),o.sx=1/o.sy,"target"in a&&(o.face=this.facing(o,a.target)),r==="pip"&&this._playing&&!this.reducedMotion){this.hammerT+=s;const p=a.kind==="build"?.28-a.intensity*.1:.34;if(this.hammerT>p){this.hammerT=0,ji.plays("hammer",this.rate)&&this.sfx.play(a.kind==="build"?"hammer":"spark",{theme:this.theme,intensity:a.kind==="build"?a.intensity:.5});const g="target"in a?this.worldLayer.positionOf(a.target):this.worldLayer.positionOf("forge");g&&Math.random()<.7&&this.particles.burst(g.top.x+(Math.random()*24-12),g.top.y+10,2,[16766571,16774084],50,60)}}break}case"raise":o.look="up",o.sy=1+.05*st(h);break;case"search":o.look="up",o.lean=Math.sin(this.t/1e3*1.5)*.12;break;case"run_tests":o.look="up",o.lean=Math.sin(this.t/1e3*2)*.04;break;case"test_outcome":if(a.outcome==="fail"){const u=st(Ue(h,0,.5));o.lean=-.25*u,o.sy=1-.1*u,o.sx=1+.08*u}else o.lift=st(h)*14;break;case"spawn_gremlin":{const u=st(Ue(h,0,.5));o.lift=Math.sin(Math.PI*Ue(h,.05,.45))*12,o.lean=-.22*u,o.sx=1+.1*u,o.sy=1-.1*u,o.look="down",o.x=l.x-o.face*10*u;break}case"chase":{const u=this.gremlins.get(a.gremlinId),d=c,f=h*Math.PI*2*1.5,p=26,g=d.x+Math.cos(f)*p,m=d.y+Math.sin(f)*p*.5;u&&(u.x=g,u.y=m,u.panic=1);const _=f-1.1;o.x=d.x+Math.cos(_)*p,o.y=d.y+Math.sin(_)*p*.5,o.moving=!0,o.face=Math.cos(f)>Math.cos(_)?1:-1;const y=this.t/1e3*16;o.lift=Math.abs(Math.sin(y))*4,o.lean=o.face*.12;break}case"banish":{o.sy=1-.2*st(Ue(h,0,.4)),o.sx=1/o.sy;break}case"celebrate":{const u=(this.t-a.atMs)%1300/1300;if(u<.22){const d=Math.sin(Math.PI*u/.22);o.sy=1-.24*d,o.sx=1+.2*d}else if(u<.8){const d=(u-.22)/.58;o.lift=Math.sin(Math.PI*d)*32,o.sy=d<.5?1+.14*(1-d*2):1,o.sx=1/o.sy}else{const d=Math.sin(Math.PI*(u-.8)/.2);o.sy=1-.2*d,o.sx=1+.16*d}break}case"blocked_on_you":o.face=1,o.look="fwd",o.sy=1+.03*Math.sin(this.t/1e3*6),o.sx=1/o.sy;break;case"your_turn":o.sy=.86,o.sx=1.08;break;case"stumble":{const u=st(Ue(h,0,.7));o.lean=Math.sin(this.t/1e3*40)*.12*u,o.sy=1-.08*u,o.sx=1+.06*u;break}case"unverified_claim":{o.face=1,o.hiding=1;const u=this.claimGremlinId?this.gremlins.get(this.claimGremlinId):null;u&&(u.x=o.x-o.face*14,u.y=o.y-2,u.peek=1);break}case"curtain_down":o.lean=Math.sin(this.t/1e3*6)*.15,o.face=1;break}if(this.claimGremlinId&&a.kind!=="unverified_claim"){const u=this.gremlins.get(this.claimGremlinId);u&&(u.x=o.x-o.face*14,u.y=o.y-2)}n.container.zIndex=o.y/(Bo/2)+.6,r!=="pip"&&(o.mood="focused")}for(const r of this.gremlins.values())r.container.zIndex=r.y/(Bo/2)+.7}facing(e,t){const s=this.worldLayer.positionOf(t);return s&&s.ground.x<e.x?-1:1}worldState(e){for(const t of this.world.places)this.worldLayer.setGlow(t.id,0);if(e){if((e.kind==="read"||e.kind==="build"||e.kind==="chase"||e.kind==="raise")&&this.worldLayer.setGlow(e.target,e.kind==="read"?.5:1),e.kind==="build"){const t=Ue(this.t,e.atMs,e.atMs+e.durationMs);this.worldLayer.setScaffold(e.target,.85*Math.min(Ue(t,0,.12),1-Ue(t,.85,1))),this.worldLayer.setGrowth(e.target,(this.growth.get(e.target)??0)+Math.round((3+e.intensity*6)*Rn(t)))}if(e.kind==="raise"){const t=Ue(this.t,e.atMs,e.atMs+e.durationMs);this.worldLayer.positionOf(e.target)&&this.worldLayer.setGrowth(e.target,Math.round(-30*(1-lu(t))))}if(e.kind==="spawn_gremlin"){const t=this.gremlins.get(e.gremlinId);t&&(t.scale=Math.max(.01,lu(Ue(this.t,e.atMs,e.atMs+400))))}for(const t of this.world.places)t.kind==="beacon"&&this.worldLayer.lampOf(t.id)==="pass"&&this.t-this.lastPass>12e3&&this.worldLayer.setLamp(t.id,"idle")}}fitCamera(){this.camera.setZoomFactor(this.fitZoom()),this.baseZoom=this.fitZoom()}baseZoom=1;camTarget=null;overview=!1;userZoom=1;setOverview(e){this.overview=e,this.userZoom=1}zoomBy(e){this.userZoom=Math.max(.4,Math.min(3,this.userZoom*e))}cameraStep(e,t){const s={w:this.app.renderer.screen.width,h:this.app.renderer.screen.height},r=s.w<640,n=!e||e.kind==="curtain_up"||e.kind==="curtain_down"||e.kind==="celebrate",o=this.world.places.map(w=>K(w.gx+w.footprint/2,w.gy+w.footprint/2)),a=Math.min(...o.map(w=>w.x))-70,l=Math.max(...o.map(w=>w.x))+70,h=Math.min(...o.map(w=>w.y))-110,c=Math.max(...o.map(w=>w.y))+50,u={x:(a+l)/2,y:(h+c)/2},d=Math.max(.05,this.camera.scale),f=s.w/d/2,p=s.h/d/2,g=(w,T,k)=>T+f>k-f?(T+k)/2:Math.max(T+f,Math.min(k-f,w)),m=(w,T,k)=>T+p>k-p?(T+k)/2:Math.max(T+p,Math.min(k-p,w)),_=this.pip.drawn,y=this.pip.pose.moving?this.pip.pose.face*f*.18:0,x={x:_.x+y,y:_.y-24};if(n||r)this.camTarget=n?{x:u.x,y:u.y}:x;else{this.camTarget||(this.camTarget=x);const w=f*.28,T=p*.26,k=x.x-this.camTarget.x,E=x.y-this.camTarget.y;Math.abs(k)>w&&(this.camTarget.x+=k-Math.sign(k)*w),Math.abs(E)>T&&(this.camTarget.y+=E-Math.sign(E)*T)}const b=g(this.camTarget.x,a,l),v=m(this.camTarget.y,h,c);this.camera.follow(b,v,1),this.camera.setDrift(this.mood==="lost"),this.overview&&(this.camTarget={x:u.x,y:u.y},this.camera.follow(u.x,u.y,1)),this.camera.setZoomFactor((this.overview?this.fitZoom()*.96:this.zoomFor(e,s.h))*this.userZoom),this.camera.update(t,s.w,s.h)}zoomFor(e,t){const s=this.fitZoom();if(!e)return s;const r=Math.max(s,Math.min(1.7,Math.max(.95,t/430)));switch(e.kind){case"curtain_up":return s*Jt(1.08,1,Rn(Ue(this.t,e.atMs,e.atMs+e.durationMs)));case"curtain_down":return s*1.05;case"celebrate":return s*1.15;default:return r}}fitZoom(){const e=this.world.places.flatMap(l=>[K(l.gx,l.gy),K(l.gx+l.footprint,l.gy+l.footprint)]),t=e.map(l=>l.x),s=e.map(l=>l.y),r=Math.max(60,Math.max(...t)-Math.min(...t)+140),n=Math.max(60,Math.max(...s)-Math.min(...s)+150),o=this.app.renderer.screen.width,a=this.app.renderer.screen.height;return Math.min(o/(r*1.05),a/(n*1.05),2.2)}bubble(e){if(!e)return null;const t=this.pip.pose,s=this.camera.toScreen(t.x+16,t.y-t.lift-52);return e.kind==="read"||e.kind==="search"?{text:"…",color:4219274,screen:s}:e.kind==="spawn_gremlin"||this.mood==="lost"&&e.kind!=="celebrate"?{text:"?",color:14833484,screen:s}:e.kind==="celebrate"?{text:"!",color:2071139,screen:s}:e.kind==="blocked_on_you"?{text:"!",color:16758087,screen:s}:e.kind==="unverified_claim"?{text:"…",color:8215807,screen:s}:null}labels(e){const t=[],s=e&&"target"in e?e.target:null;for(const r of this.world.places){if(r.kind==="forge"||r.kind==="dock")continue;const n=r.id===s,o=r.kind==="beacon"?this.worldLayer.lampOf(r.id):"idle";if(!n&&o==="idle")continue;const a=this.worldLayer.positionOf(r.id);a&&t.push({text:r.label,screen:this.camera.toScreen(a.top.x,a.top.y-2),active:n})}return t}destroy(){this.amb.stop(),this.worldLayer.destroy(),this.stage.destroy({children:!0})}}const ke={id:"island",name:"Island",tagline:"A warm little island at golden hour.",fits:["cli-tool","library","unknown"],flagship:!0,sky:[2191498,1195610],terrain:"island",ground:{fill:6073960,fillLight:10740879,edge:9070154,edgeDark:6966328,sand:15915942},water:{ripple:16777215,rippleAlpha:.24},pathColor:16245940,labelColor:1592880,palettes:[{top:16310456,left:15382917,right:13605734,roof:15495007,roofD:12735050,win:9067068},{top:14478328,left:11455462,right:9153999,roof:5934020,roofD:4616351,win:4219274},{top:13625820,left:9226664,right:6464387,roof:3122570,roofD:2393199,win:3106389},{top:16507860,left:15908774,right:14261124,roof:14248828,roofD:11554657,win:8014418},{top:16774086,left:16112010,right:14268778,roof:14916398,roofD:12220959,win:8018476}],beacon:{top:16514040,left:15855592,right:14276043,roof:14833484,roofD:12141627,win:3820122,lamp:{idle:16766571,scan:16777215,fail:16734798,pass:6287526}},archive:{top:15327743,left:12891376,right:10916824,roof:9073359,roofD:7231664,win:5062278},forge:{top:7041664,left:4937059,right:3621201,roof:10265519,roofD:7041664,win:16758087,ember:16751164},dock:{deck:11569754,post:8018490,vessel:15855592},prop:"tree",propColors:[4168284,6472819,9067066],gremlin:{body:8215807,eye:1773616},pip:{body:16751164,bodyLight:16765566,belly:16774620,ear:14712620,cheek:16739930,ink:2759959},mood:{curious:16769899,focused:8177919,lost:16743273,happy:6287526,uneasy:16754250},vignette:332832},Bs={...ke,id:"orbit",name:"Orbit",tagline:"A quiet station turning above a blue planet.",fits:["backend-api","infra-devops","systems"],flagship:!0,sky:[725030,1780309],terrain:"platform",ground:{fill:3885675,fillLight:7045032,edge:2568522,edgeDark:1712695,sand:9082808},water:{ripple:10473727,rippleAlpha:.18},pathColor:13624319,labelColor:14411775,palettes:[{top:15266303,left:12571890,right:9678036,roof:6280191,roofD:3844566,win:8188927},{top:16054011,left:14015464,right:11187143,roof:11967743,roofD:9401062,win:13481983},{top:15138806,left:12185820,right:9423800,roof:6287526,roofD:4177795,win:11075542}],beacon:{top:16777215,left:15133685,right:12174038,roof:6280191,roofD:3844566,win:8188927,lamp:{idle:10473727,scan:16777215,fail:16734798,pass:6287526}},forge:{top:10134712,left:7239820,right:5133930,roof:12634328,roofD:9081768,win:8188927,ember:8188927},dock:{deck:7239820,post:5133930,vessel:16777215},prop:"antenna",propColors:[12174038,8188927,5133930],gremlin:{body:16734878,eye:1773616},vignette:198162},mr={...ke,id:"metropolis",name:"Metropolis",tagline:"A warm night city, lights just coming on.",fits:["web-frontend","monorepo"],flagship:!0,sky:[1708080,3874127],terrain:"block",ground:{fill:3814736,fillLight:5919864,edge:2762304,edgeDark:1709872,sand:6972296},water:{ripple:16758087,rippleAlpha:.1},pathColor:16767392,labelColor:16771527,palettes:[{top:16769730,left:15907216,right:13208422,roof:16743273,roofD:13916746,win:16766571},{top:14933247,left:12036592,right:9075664,roof:11967743,roofD:9401062,win:16771496},{top:14087423,left:10147568,right:7318220,roof:6280191,roofD:3844566,win:16774084},{top:16770799,left:16234188,right:13929126,roof:16740261,roofD:14241919,win:16766571}],beacon:{top:16119285,left:14277081,right:11579568,roof:16740261,roofD:14241919,win:3355443,lamp:{idle:16758087,scan:16777215,fail:16734798,pass:6287526}},forge:{top:8024976,left:5656684,right:3946572,roof:10656699,roofD:7301256,win:16758087,ember:16758087},dock:{deck:5656684,post:3946572,vessel:16766571},prop:"lamp",propColors:[16766571,16774084,3946572],gremlin:{body:6287526,eye:993820},vignette:525332},Ab={...ke,id:"harbour",name:"Harbour",tagline:"Fog lifting off a working port.",fits:["backend-api","infra-devops"],flagship:!1,sky:[2841971,995135],ground:{fill:8032106,fillLight:11124115,edge:6052434,edgeDark:4012853,sand:13222829},water:{ripple:14283263,rippleAlpha:.3},pathColor:14275261,labelColor:2046506,palettes:[{top:16051424,left:14273459,right:11772806,roof:4090762,roofD:2969446,win:5917242},{top:16247268,left:14925746,right:12556423,roof:13195850,roofD:10503482,win:7027248},{top:15331298,left:12898743,right:10201996,roof:5209950,roofD:3825990,win:3099192}],dock:{deck:9203532,post:5916210,vessel:15223612},prop:"lamp",propColors:[16767392,16773590,4868682],vignette:398879},Rb={...Bs,id:"observatory",name:"Observatory",tagline:"A mountaintop under a hard, clear sky.",fits:["data-ml","systems"],flagship:!1,sky:[659504,2367562],terrain:"block",ground:{fill:4867942,fillLight:7236495,edge:3091781,edgeDark:1907502,sand:9275818},water:{ripple:16777215,rippleAlpha:.22},pathColor:14276336,labelColor:15394815,palettes:[{top:15855615,left:13617646,right:10722761,roof:11967743,roofD:9401062,win:16773544},{top:15135743,left:12375795,right:9415113,roof:6280191,roofD:3844566,win:16773544}],beacon:{...Bs.beacon,roof:11967743,roofD:9401062},prop:"antenna",propColors:[13617646,16773544,3091781],vignette:329756},Bb={...ke,id:"greenhouse",name:"Greenhouse",tagline:"Glass, leaves and warm afternoon light.",fits:["data-ml","library"],flagship:!1,sky:[9423280,4098938],ground:{fill:8175466,fillLight:11985823,edge:8020552,edgeDark:5916212,sand:15129779},water:{ripple:16777215,rippleAlpha:.18},pathColor:15985874,labelColor:1985843,palettes:[{top:15794166,left:13496029,right:10735033,roof:8115107,roofD:5220732,win:14286832},{top:16775654,left:15918008,right:13483407,roof:15774556,roofD:13077307,win:8018476},{top:16183551,left:14470131,right:11903953,roof:11832575,roofD:9070294,win:5062278}],prop:"tree",propColors:[5223530,9429132,8018490],vignette:731676},Bg={...ke,id:"workshop",name:"Workshop",tagline:"A village of makers, sawdust in the air.",fits:["cli-tool","library","systems"],flagship:!1,sky:[14264428,9064238],ground:{fill:10404970,fillLight:13624221,edge:9067066,edgeDark:6701098,sand:15323811},water:{ripple:16771527,rippleAlpha:.2},pathColor:15916982,labelColor:4860432,palettes:[{top:16245699,left:14727562,right:12160867,roof:10902330,roofD:8340265,win:16765566},{top:15919320,left:14206894,right:11574144,roof:6057866,roofD:4543594,win:16765566},{top:16508889,left:15712936,right:13343362,roof:13190970,roofD:10499372,win:16765566}],forge:{...ke.forge,ember:16758087},prop:"tree",propColors:[5940060,8832366,8014378],vignette:2757640},Ib={...mr,id:"arcade",name:"Arcade",tagline:"Neon rain on a late-night strip.",fits:["game","web-frontend"],flagship:!1,sky:[1181734,2756426],ground:{fill:2366012,fillLight:3811932,edge:1445930,edgeDark:788506,sand:5913228},water:{ripple:16732120,rippleAlpha:.12},pathColor:8188927,labelColor:16773375,palettes:[{top:16766710,left:16748512,right:13916856,roof:8188927,roofD:3848406,win:8188927},{top:14284543,left:9430271,right:5944532,roof:16732120,roofD:12987048,win:16773227},{top:16774604,left:16769899,right:14071882,roof:11967743,roofD:9401062,win:16732120}],beacon:{...mr.beacon,roof:16732120,roofD:12987048,lamp:{idle:8188927,scan:16777215,fail:16734798,pass:6287526}},gremlin:{body:16773227,eye:2759173},prop:"lamp",propColors:[16732120,16766710,1445930],vignette:328206},Ig={...ke,id:"kingdom",name:"Kingdom",tagline:"Stone walls, banners, a river below.",fits:["monorepo","backend-api","unknown"],flagship:!1,sky:[8369113,3894937],ground:{fill:7319134,fillLight:10933647,edge:8354410,edgeDark:6117709,sand:14209725},water:{ripple:16777215,rippleAlpha:.22},pathColor:13616813,labelColor:2828834,palettes:[{top:15855075,left:13880767,right:11248791,roof:4153231,roofD:3032683,win:5917242},{top:15855075,left:13880767,right:11248791,roof:11024954,roofD:8465452,win:5917242},{top:15855075,left:13880767,right:11248791,roof:4882258,roofD:3563581,win:5917242}],beacon:{...ke.beacon,top:15328470,left:13617334,right:10722701,roof:4153231,roofD:3032683},prop:"tree",propColors:[4165458,7323498,5916212],vignette:858662},Gb={...ke,id:"outpost",name:"Outpost",tagline:"A desert station at dusk, dust in the light.",fits:["infra-devops","cli-tool","systems"],flagship:!1,sky:[15770458,7024458],ground:{fill:14267502,fillLight:15848346,edge:10842175,edgeDark:8016429,sand:15980451},water:{ripple:16769200,rippleAlpha:.14},pathColor:16509124,labelColor:4860432,palettes:[{top:16509392,left:15255450,right:12885875,roof:14246463,roofD:11094061,win:5913120},{top:16182752,left:14667960,right:12101261,roof:3116938,roofD:2321255,win:5913120}],prop:"antenna",propColors:[12885875,16769200,8016429],vignette:2756372},Db={...ke,id:"snowfield",name:"Snowfield",tagline:"Blue hour, fresh snow, chimney smoke.",fits:["library","docs-content","unknown"],flagship:!1,sky:[10470374,4153231],ground:{fill:15397370,fillLight:16777215,edge:9346485,edgeDark:6714764,sand:14082802},water:{ripple:16777215,rippleAlpha:.3},pathColor:12833768,labelColor:2767442,palettes:[{top:16183526,left:14470070,right:11969164,roof:12077626,roofD:9188648,win:16765566},{top:15791352,left:13358560,right:10661564,roof:4090762,roofD:2969446,win:16765566},{top:15661040,left:13032912,right:10467498,roof:4882258,roofD:3563581,win:16765566}],prop:"tree",propColors:[3107658,5216874,5916212],vignette:858666},Fb={...ke,id:"canopy",name:"Canopy",tagline:"Treehouses strung through an old forest.",fits:["docs-content","data-ml","library"],flagship:!1,sky:[6266731,2050611],ground:{fill:5214031,fillLight:8372074,edge:5916212,edgeDark:4075556,sand:11050866},water:{ripple:14218704,rippleAlpha:.18},pathColor:14076314,labelColor:15398879,palettes:[{top:15918793,left:14271643,right:11770482,roof:6983487,roofD:5139245,win:16765566},{top:16181976,left:14927782,right:12558206,roof:12085818,roofD:9195306,win:16765566}],prop:"tree",propColors:[3111487,6075226,4863268],vignette:398860},Ob={...ke,id:"lagoon",name:"Lagoon",tagline:"Turquoise shallows and white sand at noon.",fits:["web-frontend","library","docs-content"],flagship:!1,sky:[8378351,2068408],ground:{fill:10147978,fillLight:13890493,edge:13218430,edgeDark:10719327,sand:16774102},water:{ripple:16777215,rippleAlpha:.36},pathColor:16774620,labelColor:1002074,palettes:[{top:16777215,left:15790056,right:13618628,roof:3126217,roofD:2133923,win:3107450},{top:16774886,left:16769464,right:14728332,roof:16747610,roofD:14051902,win:8014380},{top:15925240,left:13235165,right:10473913,roof:4177818,roofD:2788464,win:2054730}],prop:"tree",propColors:[4169564,9166970,10254916],vignette:536640},Lb={...ke,id:"volcano",name:"Volcano",tagline:"Black rock, red sky, light from below.",fits:["systems","infra-devops","game"],flagship:!1,sky:[5904922,1705992],ground:{fill:3813167,fillLight:5917256,edge:2365978,edgeDark:1182218,sand:6969942},water:{ripple:16743226,rippleAlpha:.22},pathColor:16751194,labelColor:16769479,palettes:[{top:4866114,left:3813940,right:2761766,roof:16739133,roofD:12864036,win:16758087},{top:5917266,left:4602432,right:3353135,roof:16758087,roofD:14257186,win:16739133}],beacon:{...ke.beacon,top:3813940,left:2761766,right:2038300,roof:16739133,roofD:12864036,lamp:{idle:16758087,scan:16777215,fail:16734798,pass:6287526}},forge:{...ke.forge,ember:16739133},dock:{deck:4602432,post:2761766,vessel:16758087},prop:"antenna",propColors:[5917256,16739133,2365978],gremlin:{body:8188927,eye:666160},vignette:655874},Ub={...Bs,id:"cloudtop",name:"Cloudtop",tagline:"A floating town above a sea of cloud.",fits:["web-frontend","mobile","docs-content"],flagship:!1,sky:[13625087,8368358],terrain:"platform",ground:{fill:15988475,fillLight:16777215,edge:14147822,edgeDark:12043480,sand:16777215},water:{ripple:16777215,rippleAlpha:.5},pathColor:16771496,labelColor:2767442,palettes:[{top:16777215,left:15791354,right:13621478,roof:16748448,roofD:14051964,win:16765566},{top:16777215,left:15791354,right:13621478,roof:8177919,roofD:5216982,win:16765566},{top:16777215,left:15791354,right:13621478,roof:11967743,roofD:9401062,win:16765566}],beacon:{...Bs.beacon,roof:16748448,roofD:14051964,lamp:{idle:16765566,scan:16777215,fail:16734798,pass:6287526}},dock:{deck:15791354,post:12043480,vessel:16748448},prop:"tree",propColors:[9426848,13168832,12043480],vignette:4876954},Nb={...ke,id:"reef",name:"Reef",tagline:"Underwater, where the light comes in ribbons.",fits:["data-ml","game","library"],flagship:!1,sky:[1802144,404032],terrain:"island",ground:{fill:13220234,fillLight:15326384,edge:9075290,edgeDark:5918266,sand:14930854},water:{ripple:10479871,rippleAlpha:.3},pathColor:15984579,labelColor:15137791,palettes:[{top:16767462,left:16752320,right:14052498,roof:16740261,roofD:14241919,win:8006218},{top:16773577,left:16765566,right:14265690,roof:16747610,roofD:14051902,win:8014380},{top:14286838,left:10481880,right:7129520,roof:4177818,roofD:2788464,win:2054730}],prop:"antenna",propColors:[16752320,10481880,9075290],gremlin:{body:1773616,eye:10479871},vignette:136224},Hb={...Bg,id:"bazaar",name:"Bazaar",tagline:"Ochre walls, striped awnings, late light.",fits:["monorepo","web-frontend","backend-api"],flagship:!1,sky:[15909498,11033146],ground:{fill:14200945,fillLight:15849120,edge:9067066,edgeDark:6701098,sand:15981742},water:{ripple:16773577,rippleAlpha:.16},pathColor:16773577,labelColor:4860432,palettes:[{top:16640463,left:15386528,right:12885875,roof:14240570,roofD:11024940,win:5913120},{top:16640463,left:15386528,right:12885875,roof:3116938,roofD:2321255,win:5913120},{top:16640463,left:15386528,right:12885875,roof:4153231,roofD:3032683,win:5913120},{top:16640463,left:15386528,right:12885875,roof:14916398,roofD:12220959,win:5913120}],prop:"lamp",propColors:[16765566,16773577,6701098],vignette:2757640},zb={...Ig,id:"monastery",name:"Monastery",tagline:"Mist on the mountain, a bell somewhere.",fits:["docs-content","library","systems"],flagship:!1,sky:[12110276,5204842],ground:{fill:8363898,fillLight:11585958,edge:6975334,edgeDark:4869703,sand:13093309},water:{ripple:16777215,rippleAlpha:.2},pathColor:14275520,labelColor:2042408,palettes:[{top:15855075,left:13880767,right:11248791,roof:5917242,roofD:4076072,win:16765566},{top:15855075,left:13880767,right:11248791,roof:9058858,roofD:6695454,win:16765566}],prop:"tree",propColors:[4157258,6986346,4863268],vignette:1055256},Wb={...Bs,id:"moonbase",name:"Moonbase",tagline:"Grey dust, black sky, one blue marble.",fits:["systems","infra-devops","data-ml"],flagship:!1,sky:[329228,724248],terrain:"platform",ground:{fill:9276821,fillLight:12105920,edge:6184550,edgeDark:3816e3,sand:11053232},water:{ripple:16777215,rippleAlpha:.28},pathColor:14474468,labelColor:15790326,palettes:[{top:16185082,left:14474468,right:11842750,roof:8188927,roofD:3848406,win:16765566},{top:16185082,left:14474468,right:11842750,roof:16758087,roofD:14257186,win:8188927}],prop:"antenna",propColors:[12105920,8188927,3816e3],vignette:0},$b={...mr,id:"lanterns",name:"Lanterns",tagline:"A night festival, paper light everywhere.",fits:["web-frontend","game","unknown"],flagship:!1,sky:[1706542,3805232],terrain:"block",ground:{fill:3811908,fillLight:5915750,edge:2365998,edgeDark:1314332,sand:6969976},water:{ripple:16751194,rippleAlpha:.14},pathColor:16767392,labelColor:16771527,palettes:[{top:16771535,left:15910816,right:13211758,roof:14240570,roofD:11024940,win:16765566},{top:16180223,left:14268402,right:11177161,roof:16740261,roofD:14241919,win:16765566},{top:16774870,left:16769952,right:14268778,roof:14916398,roofD:12220959,win:16751194}],prop:"lamp",propColors:[16751194,16769952,2365998],vignette:656404},Ct=[ke,Bs,mr,Ab,Rb,Bb,Bg,Ib,Ig,Gb,Db,Fb,Ob,Lb,Ub,Nb,Hb,zb,Wb,$b],sr=i=>Ct.find(e=>e.id===i)??ke;function Fo(i,e=0){const t=i?.kinds?.length?i.kinds:["unknown"],s=l=>t.reduce((h,c,u)=>h+(l.fits.includes(c)?(t.length-u)*2:0),0)+(l.flagship?1:0),r=Ct.filter(l=>s(l)>1),n=r.length>=3?r:Ct;let o=e>>>0||1;const a=()=>(o^=o<<13,o^=o>>>17,o^=o<<5,(o>>>0)%1e3/1e3);return[...n].map(l=>({s:l,k:s(l)+a()*.5})).sort((l,h)=>h.k-l.k).map(({s:l})=>l)}class ch{constructor(e){this.payload=e}mode="replay";onReady(e){queueMicrotask(()=>e(this.payload))}onBeats(){}}class Vb{constructor(e=""){this.base=e,this.connect()}mode="live";readyCb=null;beatsCb=null;signalCb=null;pending=null;async connect(){const e=await(await fetch(`${this.base}/api/scene`)).json(),t={world:e.world,events:e.events,beats:e.beats,repoId:e.repoId};this.readyCb?this.readyCb(t):this.pending=t,e.signal&&this.signalCb?.(e.signal);const s=()=>{const r=/^https?:/.test(this.base)?this.base:location.origin+this.base,n=new WebSocket(`${r.replace(/^http/,"ws")}/live`);n.onmessage=o=>{const a=JSON.parse(String(o.data));a.type==="beats"&&a.beats&&this.beatsCb?.(a.beats,a.events??[]),a.type==="signal"&&a.state&&this.signalCb?.(a.state)},n.onclose=()=>{this.signalCb?.("lost"),setTimeout(s,2e3)}};s()}onReady(e){if(this.readyCb=e,this.pending){const t=this.pending;this.pending=null,e(t)}}onBeats(e){this.beatsCb=e}onSignal(e){this.signalCb=e}}class jb{constructor(e,t){this.host=e,this.session=t,addEventListener("message",s=>{const r=s.data;if(r?.type==="scene"&&r.payload){const n=r.payload,o={world:n.world,events:n.events,beats:n.beats,repoId:n.title?`${n.repoId} — ${n.title}`:n.repoId};this.readyCb?this.readyCb(o):this.pending=o,n.signal&&this.signalCb?.(n.signal)}r?.type==="beats"&&r.beats&&this.beatsCb?.(r.beats,r.events??[]),r?.type==="signal"&&r.state&&this.signalCb?.(r.state)}),e.postMessage(t?{type:"replay",id:t}:{type:"scene"})}mode="live";readyCb=null;beatsCb=null;signalCb=null;pending=null;onReady(e){if(this.readyCb=e,this.pending){const t=this.pending;this.pending=null,e(t)}}onBeats(e){this.beatsCb=e}onSignal(e){this.signalCb=e}}async function Xb(i,e=""){const t=await fetch(`${e}/api/replay/${encodeURIComponent(i)}`);if(!t.ok)throw new Error(`session not found: ${i}`);const s=await t.json();return new ch({world:s.world,events:s.events,beats:s.beats,repoId:s.title?`${s.repoId} — ${s.title}`:s.repoId})}function qb(i,e,t){const s=n=>e.places.find(o=>o.id===n)?.label??n.replace(/^p:/,""),r=i.actor==="pip"?"Pip":t?`A helper (${t})`:"A helper";switch(i.kind){case"curtain_up":return`${i.repoId}. Every building on this stage is a file in the repo.`;case"curtain_down":return i.verified?"Curtain. Every claim in this session was backed by a passing test.":"Curtain. Something was called done without a passing test to show for it.";case"walk_to":return`${r} heads to ${s(i.target)}.`;case"read":return`${r} reads ${s(i.target)}.`;case"build":return`${r} is working on ${s(i.target)}${i.intensity>.6?" — a big change":""}.`;case"raise":return`A new file rises: ${s(i.target)}.`;case"forge":return`${r} runs a command at the forge.`;case"search":return i.scope==="web"?`${r} looks something up on the web.`:`${r} searches the repo.`;case"run_tests":return`Running the tests at ${s(i.target)}…`;case"test_outcome":return i.outcome==="pass"?`${i.passed} tests pass.`:i.outcome==="fail"?`${i.failed} test${i.failed===1?"":"s"} fail${i.failed===1?"s":""}.`:"Tests ran — the runner didn't say how many.";case"spawn_gremlin":return`A bug gremlin pops out of ${s(i.target)}.`;case"chase":return`${r} chases the gremlin around ${s(i.target)}.`;case"banish":return"Caught. The gremlin is gone.";case"summon_helper":return`A helper arrives at the dock${i.label?` to ${i.label.toLowerCase()}`:""}.`;case"dismiss_helper":return i.ok?"The helper reports back and leaves.":"The helper leaves without finishing.";case"blocked_on_you":return i.reason==="permission"?"Pip needs your permission to continue.":"Pip has a question for you.";case"your_turn":return"Pip is done for now. Your turn.";case"stumble":return i.retrying?"Something went wrong. Pip tries again.":"Something went wrong.";case"celebrate":return"All green. Pip celebrates.";case"idle":return"";case"unverified_claim":return"Pip says it's done — but no test has passed since the last change. Something's hiding."}}function Yb(i){if(!i.length)return[{label:"Scene",fromMs:0,toMs:0}];const e=Math.max(...i.map(l=>l.atMs+l.durationMs));let t=0,s=!1;const r=[];for(const l of i){let h=null;switch(l.kind){case"curtain_up":h="Arrive";break;case"curtain_down":h="Curtain";break;case"read":case"search":h=t?"Fix":s?"Explore":"Arrive",s=!0;break;case"build":case"raise":case"forge":h=t?"Fix":"Build";break;case"run_tests":h=t?"Fix":"Build";break;case"test_outcome":{h=l.outcome==="fail"?"Trouble":"Finale";const c=r.at(-1);c&&c.kind==="run_tests"&&(c.phase=h);break}case"spawn_gremlin":t++,h="Trouble";break;case"chase":h="Fix";break;case"banish":t=Math.max(0,t-1),h="Finale";break;case"celebrate":h="Finale";break;case"summon_helper":case"dismiss_helper":h="Help";break;case"blocked_on_you":h="Waiting";break;case"unverified_claim":h="Hmm";break;case"stumble":h="Trouble";break;case"your_turn":case"walk_to":case"idle":h=null;break}h&&r.push({phase:h,at:l.atMs,end:l.atMs+l.durationMs,kind:l.kind})}const n=[];for(const l of r){const h=n.at(-1);h&&h.phase===l.phase?h.to=Math.max(h.to,l.end):n.push({phase:l.phase,from:h?h.to:0,to:l.end})}n.length&&(n[0].from=0,n.at(-1).to=e);const o=2200;for(let l=n.length-1;l>=0&&n.length>1;l--){const h=n[l];h.to-h.from>=o||(l>0?(n[l-1].to=h.to,n.splice(l,1)):(n[1].from=h.from,n.splice(0,1)))}const a=n.at(-1);return a&&a.phase==="Curtain"&&n.length>1&&(n[n.length-2].to=a.to,n.pop()),n.map(l=>({label:l.phase==="Curtain"?"Finale":l.phase,fromMs:l.from,toMs:l.to}))}const Dn=i=>{const e=Math.floor(i/1e3);return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`},Fn=i=>`#${i.toString(16).padStart(6,"0")}`,$=(i,e,t)=>{const s=document.createElement(i);return e&&(s.className=e),t!==void 0&&(s.innerHTML=t),s},Kb='<svg viewBox="0 0 16 16" fill="currentColor"><path d="M4.5 2.8v10.4a.6.6 0 0 0 .9.5l8.3-5.2a.6.6 0 0 0 0-1L5.4 2.3a.6.6 0 0 0-.9.5z"/></svg>',pu='<svg viewBox="0 0 16 16" fill="currentColor"><rect x="3.5" y="3" width="3" height="10" rx="1"/><rect x="9.5" y="3" width="3" height="10" rx="1"/></svg>',Zb='<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5l3.2 3L13 4.5"/></svg>';class Qb{constructor(e,t){this.h=t,this.root=$("div","wrap");const s=$("header"),r=$("div","brand",'<a class="eyebrow" href="https://agenttheatre.dev/" title="Back to agenttheatre.dev">← Agent Theatre</a><h1 id="title">Loading…</h1>'),n=$("div","toolbar");this.setBtn=$("button","btn ghost","Set"),this.setBtn.type="button",this.setBtn.onclick=()=>this.showPicker(!0),this.muteBtn=$("button","btn ghost","Effects on"),this.muteBtn.type="button",this.muteBtn.title="Sound effects",this.muteBtn.onclick=()=>t.onMute(),this.ambBtn=$("button","btn ghost","Ambience on"),this.ambBtn.type="button",this.ambBtn.title="Background sound",this.ambBtn.onclick=()=>t.onAmbience(),this.overviewBtn=$("button","btn ghost","Whole repo"),this.overviewBtn.type="button",this.overviewBtn.title="Pull back to see every building (follow camera off)",this.overviewBtn.onclick=()=>{this.overviewOn=!this.overviewOn,this.overviewBtn.textContent=this.overviewOn?"Follow":"Whole repo",this.overviewBtn.setAttribute("aria-pressed",String(this.overviewOn)),t.onOverview(this.overviewOn)},this.exportBtn=$("button","btn ghost","Export clip"),this.exportBtn.type="button",this.exportBtn.title="Record the stage (with sound) to a .webm you can share",this.exportBtn.onclick=()=>t.onExport(),n.append(this.setBtn,this.overviewBtn,this.muteBtn,this.ambBtn,this.exportBtn),this.nudge=$("div","nudge","Sound is off — turn on effects and ambience to hear the stage"),this.nudge.hidden=!0,n.append(this.nudge),s.append(r,n);const o=$("div","grid"),a=$("div","stage-col");this.stageEl=$("div","stage"),this.overlay=$("div","overlay"),this.bubbleEl=$("div","bubble"),this.bubbleEl.hidden=!0,this.overlay.append(this.bubbleEl),this.signal=$("div","signal","<i></i><span>live</span>"),this.signal.hidden=!0,this.chip=$("div","chip ok"),this.chip.hidden=!0,this.caption=$("div","caption","<span></span>"),this.title=$("div","card",'<div class="small">Agent Theatre</div><div class="big" id="titleBig">…</div>'),this.end=$("div","card",'<div class="big">Every agent run has a story.</div><div class="small">Agent Theatre</div>'),this.end.style.opacity="0",this.picker=$("div","picker"),this.picker.hidden=!0,this.waiting=$("div","waiting",'<div class="wt"><b></b><span></span></div><button type="button" class="go"></button>'),this.waiting.hidden=!0,this.vscode=globalThis.__vsapi??null,this.waiting.querySelector(".go").onclick=()=>{this.vscode?this.vscode.postMessage({type:"focus-agent"}):this.notify()},this.prompt=$("form","prompt",'<input type="text" placeholder="" autocomplete="off" spellcheck="false"><button type="submit">Send</button><span class="st"></span>'),this.prompt.hidden=!0,this.prompt.addEventListener("submit",f=>{f.preventDefault();const p=this.prompt.querySelector("input"),g=this.prompt.querySelector(".st"),m=p.value.trim();m&&(g.textContent="sending…",t.onPrompt(m).then(_=>{g.textContent=_,p.value=""}))}),this.stageEl.append($("div","vignette"),this.overlay,this.signal,this.chip,this.caption,this.title,this.end,this.picker,this.waiting,this.prompt),this.stageEl.addEventListener("wheel",f=>{!f.ctrlKey&&Math.abs(f.deltaY)<1||(f.preventDefault(),t.onZoom(Math.exp(-f.deltaY*.0015)))},{passive:!1});const l=$("div","controls");this.playBtn=$("button","btn",`${pu}<span>Pause</span>`),this.playBtn.type="button",this.playBtn.onclick=()=>t.onPlayPause();const h=$("div","track");this.actsEl=$("div","acts"),this.labelsEl=$("div","actlabels"),this.head=$("div","head"),h.append(this.actsEl,this.labelsEl,this.head),h.addEventListener("pointerdown",f=>{const p=this.actsEl.getBoundingClientRect(),g=(f.clientX-p.left)/p.width;t.onSeek(g*this.durationMs)}),this.time=$("div","time","0:00 / 0:00"),this.rateBtn=$("button","btn ghost","1×"),this.rateBtn.type="button",this.rateBtn.onclick=()=>t.onRate(),l.append(this.playBtn,h,this.time,this.rateBtn),a.append(this.stageEl,l);const c=$("aside"),u=$("section","panel",'<h2>Event log</h2><p class="sub">Every scene is driven by one of these agent events. Tap one to jump there.</p>');this.logEl=$("ul","log"),u.append(this.logEl);const d=$("section","panel",`<h2>How to read the stage</h2><p class="sub">Buildings are files, districts are folders, beacons are test suites. Gremlins are failing tests. The lead character is the agent; its light shows its mood. Helpers are subagents. If the agent says it's done without a passing test, something hides behind it.</p>`);c.append(u,d),o.append(a,c),this.root.append(s,o,$("p","note","Everything you see is generated locally from agent events. No code, prompts or file contents are shown or sent anywhere.")),e.append(this.root)}root;stageEl;nudge;showNudge(){this.nudge.hidden=!1}showShare(e){const t=URL.createObjectURL(e.blob),s=new File([e.blob],e.name,{type:e.blob.type}),r=typeof navigator.share=="function"&&typeof navigator.canShare=="function"&&navigator.canShare({files:[s]}),n=$("div","share",`<div class="sh-head"><b>Your clip is ready</b><span>${(e.blob.size/1048576).toFixed(1)} MB · ${e.name.split(".").pop()}</span></div>
952
+ `})),t=this._device.createRenderPipeline({layout:"auto",vertex:{module:this._mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this._mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this._pipelines[e]=t),t}generateMipmap(e){if(e.dimension==="3d")throw new Error("[GpuMipmapGenerator] a 3D texture uses Gpu3dMipmapGenerator.");if(e.dimension==="1d")throw new Error("Generating mipmaps for 1d textures is currently unsupported!");const t=this._getMipmapPipeline(e.format);let s=e;const r=e.depthOrArrayLayers||1,n=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!n){const l={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};s=this._device.createTexture(l)}const o=this._device.createCommandEncoder({}),a=t.getBindGroupLayout(0);for(let l=0;l<r;++l){let h=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),c=n?1:0;for(let u=1;u<e.mipLevelCount;++u){const d=s.createView({baseMipLevel:c++,mipLevelCount:1,dimension:"2d",baseArrayLayer:l,arrayLayerCount:1}),f=o.beginRenderPass({colorAttachments:[{view:d,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),p=this._device.createBindGroup({layout:a,entries:[{binding:0,resource:this._sampler},{binding:1,resource:h}]});f.setPipeline(t),f.setBindGroup(0,p),f.draw(3,1,0,0),f.end(),h=d}}if(!n){const l={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:r};for(let h=1;h<e.mipLevelCount;++h)o.copyTextureToTexture({texture:s,mipLevel:h-1},{texture:e,mipLevel:h},l),l.width=Math.ceil(l.width/2),l.height=Math.ceil(l.height/2)}return this._device.queue.submit([o.finish()]),n||s.destroy(),e}}class fg{constructor(e){this.textureView=null,this.textureViews=Object.create(null),this.gpuTexture=e}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.textureViews=null,this.gpuTexture=null}}const wx=/^(rgba8|bgra8|bc[1237]-rgba-|etc2-rgb8|etc2-rgb8a1|etc2-rgba8|astc-\d+x\d+-)unorm$/;function Tx(i){return wx.test(i)?[`${i}-srgb`]:void 0}function Qc(i){return`${i.format||""}.${i.dimension||""}.${i.aspect||""}.${i.baseMipLevel||0}.${i.mipLevelCount||""}.${i.baseArrayLayer||0}.${i.arrayLayerCount||""}`}const lh=class pg{constructor(e){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=e,e.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new at({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const t={image:oh,buffer:ag,video:cg,compressed:lg,...pg.uploadExtensions};this._uploads={...t,cube:hg(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gpu=e,this._managedTextures.removeAll(),this._gpuSamplers=Object.create(null),this._mipmapGenerator=null,this._mipmap3dGenerator=null}initSource(e){return e._gpuData[this._renderer.uid]?.gpuTexture||this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){e.dimension==="3d"&&ah(e.format,e.storage);const c=Math.max(e.pixelWidth,e.pixelHeight,e.depth);e.mipLevelCount=Math.floor(Math.log2(c))+1}let t,s;e.sampleCount>1?(t=GPUTextureUsage.RENDER_ATTACHMENT,e.transient&&this._renderer.device.extensions.transientAttachment&&(t|=GPUTextureUsage.TRANSIENT_ATTACHMENT)):(t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST,e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC),e.storage&&(t|=GPUTextureUsage.STORAGE_BINDING),s=Tx(e.format));const r=nh[e.format]||{blockWidth:1,blockHeight:1},n=Math.ceil(e.pixelWidth/r.blockWidth)*r.blockWidth,o=Math.ceil(e.pixelHeight/r.blockHeight)*r.blockHeight,a={label:e.label,size:{width:n,height:o,depthOrArrayLayers:e.depthOrArrayLayers},format:e.format,viewFormats:s,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},l=this._gpu.device.createTexture(a);return e._gpuData[this._renderer.uid]=new fg(l),this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),l}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onUpdateMipmaps(e){const t=this.getGpuSource(e);if(e.dimension==="3d"){this._mipmap3dGenerator??(this._mipmap3dGenerator=new ug(this._gpu.device)),this._mipmap3dGenerator.generateMipmap(t);return}this._mipmapGenerator??(this._mipmapGenerator=new dg(this._gpu.device)),this._mipmapGenerator.generateMipmap(t)}onSourceUnload(e){e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this)}onSourceResize(e){e._gcLastUsed=this._renderer.gc.now;const t=e._gpuData[this._renderer.uid],s=t?.gpuTexture;s?(s.width!==e.pixelWidth||s.height!==e.pixelHeight)&&(t.destroy(),this._bindGroupHash[e.uid]=null,e._gpuData[this._renderer.uid]=null,this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]?.gpuTexture||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]||this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new Pt({0:t,1:t.style,2:new Ze({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e,t){var s;const r=e.source;r._gcLastUsed=this._renderer.gc.now;let n=r._gpuData[this._renderer.uid];n||(this.initSource(r),n=r._gpuData[this._renderer.uid]);const o=t?Qc(t):0;return(s=n.textureViews)[o]||(s[o]=n.gpuTexture.createView({dimension:r.viewDimension,...t})),n.textureViews[o]}getTextureRenderTargetView(e,t=0,s=0,r){var n;const o=e.source;o._gcLastUsed=this._renderer.gc.now;let a=o._gpuData[this._renderer.uid];a||(this.initSource(o),a=o._gpuData[this._renderer.uid]);const l=o.dimension==="3d";l&&(s=0);let h=s*(o.mipLevelCount||1)+t+1;return r&&(h=`${h}.${Qc(r)}`),(n=a.textureViews)[h]||(n[h]=a.gpuTexture.createView({dimension:l?"3d":"2d",baseMipLevel:t,mipLevelCount:1,baseArrayLayer:s,arrayLayerCount:1,...r})),a.textureViews[h]}generateCanvas(e){const t=this._renderer,s=t.gpu.device.createCommandEncoder(),r=ee.get().createCanvas();r.width=e.source.pixelWidth,r.height=e.source.pixelHeight;const n=r.getContext("webgpu");return n.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:ee.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),s.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:n.getCurrentTexture()},{width:r.width,height:r.height}),t.gpu.device.queue.submit([s.finish()]),r}getPixels(e){const t=this.generateCanvas(e),s=At.getOptimalCanvasAndContext(t.width,t.height),r=s.context;r.drawImage(t,0,0);const{width:n,height:o}=t,a=r.getImageData(0,0,n,o),l=new Uint8ClampedArray(a.data.buffer);return At.returnCanvasAndContext(s),{pixels:l,width:n,height:o}}destroy(){this._managedTextures.destroy();for(const e of Object.keys(this._bindGroupHash)){const t=Number(e);this._bindGroupHash[t]?.destroy()}this._renderer=null,this._gpu=null,this._mipmapGenerator=null,this._mipmap3dGenerator=null,this._gpuSamplers=null,this._bindGroupHash=null}};lh.extension={type:[S.WebGPUSystem],name:"texture"};lh.uploadExtensions=Object.create(null);let hh=lh;q.handleByMap(S.TextureUploaderWebGPU,hh.uploadExtensions);class ch{constructor(){this._maxTextures=0}contextChange(e){const t=new Ze({uTransformMatrix:{value:new U,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const s=Rr({name:"graphics",bits:[ba,wa(this._maxTextures),op,Ir]});this.shader=new gt({gpuProgram:s,resources:{localUniforms:t}})}execute(e,t){const s=t.context,r=s.customShader||this.shader,n=e.renderer,o=n.graphicsContext,{batcher:a,instructions:l}=o.getContextRenderData(s),h=n.encoder;h.setGeometry(a.geometry,r.gpuProgram);const c=n.globalUniforms.bindGroup;h.setBindGroup(0,c,r.gpuProgram);const u=n.renderPipes.uniformBatch.getUniformBindGroup(r.resources.localUniforms,!0);h.setBindGroup(2,u,r.gpuProgram);const d=l.instructions;let f=null;for(let p=0;p<l.instructionSize;p++){const g=d[p];if(g.topology!==f&&(f=g.topology,h.setPipelineFromGeometryProgramAndState(a.geometry,r.gpuProgram,e.state,g.topology,r._overrides)),r.groups[1]=g.bindGroup,!g.gpuBindGroup){const m=g.textures;g.bindGroup=Ar(m.textures,m.count,this._maxTextures),g.gpuBindGroup=n.bindGroup.getBindGroup(g.bindGroup,r.gpuProgram,1)}h.setBindGroup(1,g.bindGroup,r.gpuProgram),h.renderPassEncoder.drawIndexed(g.size,1,g.start)}}destroy(){this.shader.destroy(),this.shader=null}}ch.extension={type:[S.WebGPUPipesAdaptor],name:"graphics"};class uh{init(){const e=Rr({name:"mesh",bits:[ni,Bp,Ir]});this._shader=new gt({gpuProgram:e,resources:{uTexture:W.EMPTY._source,uSampler:W.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new U}}}})}execute(e,t){const s=e.renderer;let r=t._shader;if(!r)r=this._shader,r.groups[2]=s.texture.getTextureBindGroup(t.texture);else if(!r.gpuProgram){H("Mesh shader has no gpuProgram",t.shader);return}const n=r.gpuProgram;if(n.autoAssignGlobalUniforms&&(r.groups[0]=s.globalUniforms.bindGroup),n.autoAssignLocalUniforms){const o=e.localUniforms;r.groups[1]=s.renderPipes.uniformBatch.getUniformBindGroup(o,!0)}s.encoder.draw({geometry:t._geometry,shader:r,state:t.state})}destroy(){this._shader.destroy(),this._shader=null}}uh.extension={type:[S.WebGPUPipesAdaptor],name:"mesh"};const Sx=[...Xr,tn,Zl,en,Ql,Yl,hh,sh,ih,rh,th,Kl,Jl,ql],Cx=[...Cl,eh],Mx=[il,uh,ch],mg=[],gg=[],_g=[],yg=[];q.handleByNamedList(S.WebGPUSystem,mg);q.handleByNamedList(S.WebGPUPipes,gg);q.handleByNamedList(S.WebGPUPipesAdaptor,_g);q.handleByNamedList(S.WebGPULoader,yg);q.add(...Sx,...Cx,...Mx);class xg extends ds{constructor(){const e={name:"webgpu",type:Ke.WEBGPU,systems:mg,renderPipes:gg,renderPipeAdaptors:_g,loaders:yg};super(e)}}const kx=Object.freeze(Object.defineProperty({__proto__:null,WebGPURenderer:xg},Symbol.toStringTag,{value:"Module"}));function Fo(i,e=null){const t=i*6;if(t>65535?e||(e=new Uint32Array(t)):e||(e=new Uint16Array(t)),e.length!==t)throw new Error(`Out buffer length is incorrect, got ${e.length} and expected ${t}`);for(let s=0,r=0;s<t;s+=6,r+=4)e[s+0]=r+0,e[s+1]=r+1,e[s+2]=r+2,e[s+3]=r+0,e[s+4]=r+2,e[s+5]=r+3;return e}function bg(i){return{dynamicUpdate:Jc(i,!0),staticUpdate:Jc(i,!1)}}function Jc(i,e){const t=[];t.push(`
953
+
954
+ var index = 0;
955
+
956
+ for (let i = 0; i < ps.length; ++i)
957
+ {
958
+ const p = ps[i];
959
+
960
+ `);let s=0;for(const n in i){const o=i[n];if(e!==o.dynamic)continue;t.push(`offset = index + ${s}`),t.push(o.code);const a=mt(o.format);s+=a.stride/4}t.push(`
961
+ index += stride * 4;
962
+ }
963
+ `),t.unshift(`
964
+ var stride = ${s};
965
+ `);const r=t.join(`
966
+ `);return new Function("ps","f32v","u32v",r)}class vg{constructor(e){this._size=0,this._generateParticleUpdateCache={};const t=this._size=e.size??1e3,s=e.properties;let r=0,n=0;for(const c in s){const u=s[c],d=mt(u.format);u.dynamic?n+=d.stride:r+=d.stride}this._dynamicStride=n/4,this._staticStride=r/4,this.staticAttributeBuffer=new Zt(t*4*r),this.dynamicAttributeBuffer=new Zt(t*4*n),this.indexBuffer=Fo(t);const o=new Si;let a=0,l=0;this._staticBuffer=new ot({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:ae.VERTEX|ae.COPY_DST}),this._dynamicBuffer=new ot({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:ae.VERTEX|ae.COPY_DST});for(const c in s){const u=s[c],d=mt(u.format);u.dynamic?(o.addAttribute(u.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:u.format}),a+=d.size):(o.addAttribute(u.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:l*4,format:u.format}),l+=d.size)}o.addIndex(this.indexBuffer);const h=this.getParticleUpdate(s);this._dynamicUpload=h.dynamicUpdate,this._staticUpload=h.staticUpdate,this.geometry=o}getParticleUpdate(e){const t=Ex(e);return this._generateParticleUpdateCache[t]?this._generateParticleUpdateCache[t]:(this._generateParticleUpdateCache[t]=this.generateParticleUpdate(e),this._generateParticleUpdateCache[t])}generateParticleUpdate(e){return bg(e)}update(e,t){e.length>this._size&&(t=!0,this._size=Math.max(e.length,this._size*1.5|0),this.staticAttributeBuffer=new Zt(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new Zt(this._size*this._dynamicStride*4*4),this.indexBuffer=Fo(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));const s=this.dynamicAttributeBuffer;if(this._dynamicUpload(e,s.float32View,s.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,e.length*this._dynamicStride*4,!0),t){const r=this.staticAttributeBuffer;this._staticUpload(e,r.float32View,r.uint32View),this._staticBuffer.setDataWithSize(r.float32View,e.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}}function Ex(i){const e=[];for(const t in i){const s=i[t];e.push(t,s.code,s.dynamic?"d":"s")}return e.join("_")}q.add(bu,vu);const Px=Object.freeze(Object.defineProperty({__proto__:null,AbstractRenderer:ds,AbstractText:ap,AbstractTextSystem:Qa,AccessibilitySystem:R_,AlphaMask:Jo,AlphaMaskPipe:zr,Application:ga,ApplicationInitHook:da,BLEND_TO_NPM:Kd,BREAKING_SPACES:fp,BREAKING_SPACES_SET:pp,BREAK_AFTER_CHARS:gp,BREAK_AFTER_CHARS_SET:_p,BUFFER_TYPE:li,BackgroundSystem:Up,Batch:Jd,BatchGeometry:nf,BatchTextureArray:Qd,BatchableGraphics:Fr,BatchableSprite:Ur,BatchableText:kp,Batcher:sf,BatcherPipe:Nr,BigPool:Se,BindGroup:Pt,BindGroupSystem:ql,BlendModePipe:Vr,Bounds:Ee,BrowserAdapter:td,Buffer:ot,BufferImageSource:xr,BufferResource:Mi,BufferUsage:ae,CLEAR:ye,COLLAPSIBLE_SPACES:mp,Cache:Kt,CanvasBatchAdaptor:Ap,CanvasColorMaskPipe:nl,CanvasContextSystem:hl,CanvasFilterSystem:Yf,CanvasGraphicsAdaptor:ul,CanvasGraphicsContextSystem:rp,CanvasGraphicsPipe:Na,CanvasLimitsSystem:cl,CanvasObserver:ra,CanvasPool:At,CanvasPoolClass:qf,CanvasRenderTargetAdaptor:sm,CanvasRenderTargetSystem:Ml,CanvasRenderer:am,CanvasRendererTextSystem:Ja,CanvasSource:Ve,CanvasStencilMaskPipe:al,CanvasTextGenerator:Qt,CanvasTextMetrics:Tt,CanvasTextPipe:Za,CanvasTextSystem:el,CanvasTextureSystem:kl,Circle:kr,Color:le,ColorMask:ea,ColorMaskPipe:ol,Container:_e,CustomRenderPipe:Hr,DEG_TO_RAD:Su,DOMAdapter:ee,DOMPipe:Vf,DefaultBatcher:Dr,DefaultShader:_o,Ellipse:Er,EventBoundary:jf,EventEmitter:Re,EventSystem:Xf,EventsTicker:dt,ExtensionType:S,ExtractSystem:zp,FederatedContainer:ay,FederatedEvent:Os,FederatedMouseEvent:bi,FederatedPointerEvent:Fe,FederatedWheelEvent:hs,FillGradient:je,FillPattern:Ls,Filter:ha,FilterEffect:ci,FilterPipe:Jf,FilterSystem:ep,GCManagedHash:at,GCSystem:Vp,GL_FORMATS:_r,GL_TARGETS:Gs,GL_TYPES:ie,GPUTextureGpuData:fg,GenerateTextureSystem:_l,Geometry:Si,GlBackBufferSystem:pm,GlBatchAdaptor:sl,GlBuffer:lm,GlBufferSystem:El,GlColorMaskSystem:Bl,GlContextSystem:cm,GlEncoderSystem:Il,GlGeometryGpuData:dm,GlGeometrySystem:Al,GlGraphicsAdaptor:jl,GlLimitsSystem:Gl,GlMeshAdaptor:Xl,GlProgram:us,GlProgramData:wm,GlRenderTarget:mm,GlRenderTargetAdaptor:bm,GlRenderTargetSystem:Ll,GlShaderSystem:Qr,GlStateSystem:Gm,GlStencilSystem:Dl,GlTexture:Dm,GlTextureSystem:Vl,GlUboSystem:Zr,GlUniformGroupSystem:Jr,GlobalResourceRegistry:cs,GlobalUniformSystem:xl,Gpu3dMipmapGenerator:ug,GpuBatchAdaptor:il,GpuBlendModesToPixi:Ge,GpuBufferData:Qm,GpuBufferSystem:Yl,GpuColorMaskSystem:Kl,GpuDeviceSystem:en,GpuEncoderSystem:Zl,GpuGraphicsAdaptor:ch,GpuGraphicsContext:Ef,GpuLimitsSystem:Ql,GpuMeshAdapter:uh,GpuMipmapGenerator:dg,GpuMsaaRestore:rg,GpuProgram:Lt,GpuRenderTarget:ng,GpuRenderTargetAdaptor:og,GpuRenderTargetSystem:sh,GpuShaderSystem:ih,GpuStateSystem:rh,GpuStencilModesToPixi:Bt,GpuStencilSystem:Jl,GpuTextureSystem:hh,GpuUboSystem:tn,GpuUniformBatchPipe:eh,Graphics:Pe,GraphicsContext:qe,GraphicsContextRenderData:Pf,GraphicsContextSystem:Lr,GraphicsGpuData:np,GraphicsPath:pt,GraphicsPipe:Ha,HelloSystem:jr,ImageSource:fi,InstructionSet:Tr,LoaderParserPriority:sa,MaskEffectManager:ar,MaskEffectManagerClass:zu,MaskFilter:ip,Matrix:U,NEWLINES:up,NEWLINES_SET:dp,NEWLINE_MATCH_REGEX:xp,NEWLINE_SPLIT_REGEX:yp,NOOP:$o,ObservablePoint:Ce,PI_2:wu,ParticleBuffer:vg,PassthroughFilter:Qf,PipelineSystem:th,Point:ce,Polygon:ks,Pool:Fu,PoolGroupClass:Ou,RAD_TO_DEG:Tu,Rectangle:te,RenderBundle:eg,RenderGroup:lr,RenderGroupPipe:Wr,RenderGroupSystem:pl,RenderTarget:ai,RenderTargetSystem:qr,RenderTexture:Ci,RenderableGCSystem:qp,RendererInitHook:fa,RendererType:Ke,ResizePlugin:pa,Resolver:ia,RoundedRectangle:Pr,STATE_BITS:la,STENCIL_MODES:me,SVGParser:Hf,SchedulerSystem:bl,ScreenSizeRegistry:Ko,Shader:gt,ShaderOverrides:Rs,ShaderStage:fe,ShapePath:Df,SharedRenderPipes:Cl,SharedSystems:Xr,Sprite:ns,SpritePipe:$r,Spritesheet:Qn,State:_t,StencilMask:ta,StencilMaskPipe:ll,SystemRunner:ua,Text:Ep,TextStyle:Is,Texture:W,TextureGCSystem:Yp,TextureMatrix:jo,TexturePool:Te,TexturePoolClass:Qu,TextureSource:ue,TextureStyle:Ot,TextureView:Ul,Ticker:We,TickerListener:Zi,TickerPlugin:ma,UNIFORM_TO_ARRAY_SETTERS:Am,UNIFORM_TO_SINGLE_SETTERS:Pm,UNIFORM_TYPES_MAP:Ed,UNIFORM_TYPES_VALUES:aa,UPDATE_BLEND:Sr,UPDATE_COLOR:di,UPDATE_PRIORITY:os,UPDATE_VISIBLE:Ms,UboBatch:Jm,UboSystem:Yr,UniformGroup:Ze,VERSION:yi,VideoSource:nd,ViewContainer:Cr,ViewSystem:Jp,ViewableBuffer:Zt,WGSL_ALIGN_SIZE_DATA:Es,WGSL_TO_STD40_SIZE:Kr,WebGLRenderer:Zm,WebGPURenderer:xg,accessibilityTarget:B_,addBits:fo,addMaskBounds:Zo,addMaskLocalBounds:Qo,addProgramDefines:yd,appendSVGPath:Co,applyStyleParams:Go,assertMipmap3dTexture:ah,assignWithIgnore:Ju,autoDetectRenderer:Vd,bakeOverridesIntoSource:Do,bgr2rgb:ts,blockDataMap:nh,boundsPool:ft,browserExt:bu,buildAdaptiveBezier:Ra,buildAdaptiveQuadratic:Af,buildArc:Ba,buildArcTo:Rf,buildArcToSvg:Bf,buildCircle:Bs,buildContextBatches:kf,buildEllipse:vf,buildLine:Or,buildPixelLine:Tf,buildPolygon:Sf,buildRectangle:Cf,buildRoundedRectangle:wf,buildSimpleUvs:bf,buildTriangle:Mf,buildUvs:xf,cacheAsTextureMixin:Lu,calculatePathArea:zf,calculateProjection:em,canUseNewCanvasBlendModes:Fa,canvasUtils:Y,checkChildrenDidChange:Yo,checkForNestedPattern:Uf,checkMaxIfStatementsInShader:ya,childrenHelperMixin:Uu,cleanArray:Wp,cleanHash:Hp,clearList:mr,closePointEps:Ma,collapseNewlines:Xa,collapseSpaces:ja,collectRenderablesMixin:Nu,color32BitToUniform:za,colorBit:ba,colorBitGl:va,compareModeToGlCompare:zm,compileBufferSync:Fl,compileHighShader:af,compileHighShaderGl:lf,compileHighShaderGlProgram:Br,compileHighShaderGpuProgram:Rr,compileHooks:po,compileInputs:mo,compileOutputs:of,compileShader:Ro,convertToList:Yt,copySearchParams:Zn,createGlUploadCubeTextureResource:Lm,createGpuUploadCubeTextureResource:hg,createIdFromString:as,createIndicesForQuads:Fo,createStringVariations:cd,createUboElementsSTD40:gm,createUboElementsWGSL:tg,createUboSyncFunctionSTD40:xm,createUboSyncFunctionWGSL:ig,cullingMixin:Du,curveEps:yo,defaultFilterVert:Kf,defaultValue:Nl,definedProps:Vo,deprecation:z,detectVideoAlphaMode:id,earcut:Nd,effectsMixin:Hu,ensureAttributes:gr,ensureIsBuffer:xa,ensurePrecision:xd,ensureTextOptions:lp,executeInstructions:pr,extensions:q,extractAttributesFromGlProgram:Sm,extractAttributesFromGpuProgram:Sd,extractStructAndGroups:Qi,extractSubpaths:Nf,extractSvgUrlId:To,fastCopy:ur,findMixin:Wu,fontStringFromTextStyle:fr,fragmentGPUTemplate:df,fragmentGlTemplate:pf,generateArraySyncSTD40:ym,generateArraySyncWGSL:sg,generateGpuLayoutGroups:Cd,generateLayoutHash:Md,generateParticleUpdateFunction:bg,generateProgram:Em,generateShaderSyncCode:vm,generateTextureBatchBit:wa,generateTextureBatchBitGl:Ta,generateTextureMatrix:Pa,generateUniformsSync:Rm,getAdjustedBlendModeBlend:uo,getAttributeInfoFromFormat:mt,getBatchSamplersUniformGroup:Sa,getCanvasBoundingBox:hp,getCanvasFillStyle:ti,getCanvasTexture:Tl,getCharacterGroups:Ya,getDefaultUniformValue:Pd,getFastGlobalBoundsMixin:$u,getGeometryBounds:rf,getGlTypeFromFormat:um,getGlobalBounds:br,getGlobalMixin:ju,getGlobalRenderableBounds:Oa,getLocalBounds:wr,getMaxFragmentPrecision:_d,getMaxMiterRatio:$f,getMaxTexturesPerBatch:Zd,getOrientationOfPoints:_a,getPo2TextureFromSource:La,getTestContext:oa,getTexelRangeRects:Hl,getTextureBatchBindGroup:Ar,getUboData:Cm,getUniformData:Mm,getUrlExtension:ud,glUploadBufferImageResource:Fm,glUploadCompressedTextureResource:Om,glUploadImageResource:Wl,glUploadVideoResource:Um,globalUniformsBit:mf,globalUniformsBitGl:gf,gpuUploadBufferImageResource:ag,gpuUploadCompressedTextureResource:lg,gpuUploadImageResource:oh,gpuUploadVideoResource:cg,groupD8:Z,hasTagMarkup:Va,hasTagStyles:$a,injectBits:go,insertVersion:bd,isBreakAfterChar:bp,isBreakingSpace:$e,isCanvasFilterCapable:ko,isIntegerFormat:or,isMobile:md,isNewline:vi,isPow2:rs,isRenderingToScreen:tm,isSafari:Pp,isSingleItem:Kn,isWebGLSupported:Wd,isWebGPUSupported:$d,loadEnvironmentExtensions:Gd,localUniformBit:ni,localUniformBitGl:Wa,localUniformBitGroup2:op,logProgramError:km,mapCanvasBlendModesToPixi:Dp,mapFormatToGlFormat:Hm,mapFormatToGlInternalFormat:Wm,mapFormatToGlType:$m,mapGlToVertexFormat:Tm,mapType:zl,mapViewDimensionToGlTarget:Vm,mapWebGLBlendModesToPixi:Bm,maskFrag:tp,maskVert:sp,maskWgsl:Po,matrixPool:Ae,measureMixin:qu,measureTaggedText:vp,mipmapScaleModeToGlFilter:Nm,multiplyColors:ui,multiplyHexColors:es,nextPow2:is,normalizeExtensionPriority:Qs,onRenderMixin:Yu,parseSVGDefinitions:Ff,parseSVGFloatAttribute:ve,parseSVGPath:Xd,parseSVGStyle:Ia,parseTaggedText:cp,passthroughFrag:Zf,passthroughWgsl:Eo,path:As,removeItems:qo,removeStructAndGroupDuplicates:kd,resourceToTexture:ad,roundPixelsBit:Ir,roundPixelsBitGl:Gr,roundedShapeArc:If,roundedShapeQuadraticCurve:Gf,sayHello:jp,scaleModeToGlFilter:Io,setProgramName:vd,shapeBuilders:fs,sortMixin:Ku,spritesheetAsset:pd,squaredDistanceToLineSegment:qd,stripVersion:wd,styleAttributes:So,textureBit:Bp,textureBitGl:Ip,textureFrom:ld,toFillStyle:Ft,toLocalGlobalMixin:Zu,toStrokeStyle:xi,tokenize:qa,tokenizeTaggedRuns:Tp,transformVertices:Ca,triangulateWithHoles:ka,trimRight:ct,uboSyncFunctionsSTD40:Ol,uboSyncFunctionsWGSL:_m,uid:oe,uniformParsers:nt,unsafeEvalSupported:ca,updateQuadBounds:Xo,updateRenderGroupTransform:Fp,updateRenderGroupTransforms:dl,updateTextBounds:Mp,updateTransformAndChildren:fl,updateTransformBackwards:vr,v8_0_0:de,v8_21_0:ut,v8_22_0:ku,v8_3_4:Mu,validateRenderables:Op,vertexGPUTemplate:uf,vertexGlTemplate:ff,warn:H,warnIgnoredTextureStyle:Cp,webworkerExt:vu,wordWrap:Sp,wordWrapTaggedLines:wp,wrapModeToGlAddress:tr},Symbol.toStringTag,{value:"Module"}));function sr(i){return i.replace(/\\/g,"/").replace(/\/+$/,"")}function Ax(i,e){const t=sr(i),s=sr(e.cwd);if(s&&(t===s||t.startsWith(s+"/")))return t.slice(s.length+1)||".";if(e.home){const n=sr(e.home);if(n&&(t===n||t.startsWith(n+"/")))return"~/"+t.slice(n.length+1)}return t.startsWith("/")?`//ext/${t.slice(t.lastIndexOf("/")+1)}`:t}function Rx(i){const e=sr(i);return e.slice(e.lastIndexOf("/")+1)}function wg(i){return/(^|\/)(tests?|__tests__|spec|specs)\//i.test(i)||/\.(test|spec)\.[cm]?[jt]sx?$/i.test(i)||/(^|\/)test_[^/]+\.py$/i.test(i)||/_test\.(go|rs|py)$/i.test(i)}var Bx=/\b(vitest|jest|mocha|pytest|py\.test|go\s+test|cargo\s+test|npm\s+test|pnpm\s+test|yarn\s+test|bun\s+test|npx\s+(vitest|jest|playwright)|rspec|phpunit|dotnet\s+test|mvn\s+test|gradle\s+test|make\s+test)\b/,Ix=/\b(tsc|tsup|vite\s+build|webpack|esbuild|rollup|next\s+build|cargo\s+build|go\s+build|make\b(?!\s+test)|npm\s+run\s+build|pnpm\s+(run\s+)?build|yarn\s+build|gradle\s+build|mvn\s+package|docker\s+build)\b/,Gx=/\b(npm\s+(i|install|ci)|pnpm\s+(i|install|add)|yarn(\s+add|\s+install)?|pip3?\s+install|poetry\s+(add|install)|cargo\s+add|go\s+get|brew\s+install|apt(-get)?\s+install|bun\s+(i|install|add))\b/,Dx=/\b(grep|rg|ag|ack|find|fd|locate)\b/,Fx=/^\s*(cat|head|tail|less|more|bat|wc|stat|jq)\b/;function Tg(i){const t=(i.split(/\s*(?:&&|\|\||;|\|)\s*/)[0]??"").trim().split(/\s+/).map(n=>n.replace(/^[({]+/,"")).filter(Boolean);let s=0;for(;s<t.length&&/^[A-Za-z_][A-Za-z0-9_]*=/.test(t[s]);)s++;if(t[s]==="cd"&&t.length>s+1){const n=i.split(/\s*&&\s*/)[1];if(n)return Tg(n)}return(t[s]??"").replace(/^.*\//,"").slice(0,40)||"sh"}function Ss(i){const e=i.replace(/^["']|["']$/g,"").trim();return!e||e.startsWith("-")||e==="/dev/null"||e.includes("$(")||e.startsWith("$")||/^\/dev\//.test(e)||/^&\d/.test(e)?null:e}function Ox(i){const e=new Set;for(const t of i.matchAll(/(?:^|[\s)])\d?>{1,2}\s*([^\s|&;<>]+)/g)){const s=Ss(t[1]??"");s&&e.add(s)}for(const t of i.matchAll(/\btee\s+(?:-[a-z]+\s+)*((?:[^\s|&;<>]+\s*)+)/g))for(const s of(t[1]??"").split(/\s+/)){const r=Ss(s);r&&e.add(r)}for(const t of i.matchAll(/\bsed\s+-i\S*\s+(.+?)(?=\s*(?:&&|\|\||;|\||$))/g)){const r=((t[1]??"").match(/"[^"]*"|'[^']*'|\S+/g)??[]).filter(n=>!n.startsWith("-")&&!n.startsWith("'")&&!n.startsWith('"')&&!/^s[/|#]/.test(n)&&!/^-e$/.test(n));for(const n of r){const o=Ss(n);o&&e.add(o)}}for(const t of i.matchAll(/\b(?:cp|mv)\s+(?:-[a-zA-Z]+\s+)*((?:[^\s|&;<>]+\s+)+)([^\s|&;<>]+)/g)){const s=Ss(t[2]??"");s&&e.add(s)}for(const t of i.matchAll(/\btouch\s+((?:[^\s|&;<>]+\s*)+)/g))for(const s of(t[1]??"").split(/\s+/)){const r=Ss(s);r&&e.add(r)}return[...e]}function Lx(i){const e=new Set;for(const t of i.split(/\s*(?:&&|\|\||;|\|)\s*/)){const s=t.match(/^\s*(?:cat|head|tail|less|more|bat|wc)\s+(?:-[^\s]+\s+)*((?:[^\s|&;<>]+\s*)+)/);if(s)for(const r of(s[1]??"").split(/\s+/)){const n=Ss(r);n&&!/^\d+$/.test(n)&&e.add(n)}}return[...e]}function Ux(i){const e=Tg(i),t=Ox(i),s=Lx(i);let r="other";return Bx.test(i)?r="test":Ix.test(i)?r="build":Gx.test(i)?r="install":/^\s*git\b/.test(i)||e==="git"||e==="gh"?r="git":t.length?r="write_file":Dx.test(i)&&e!=="cd"?r="search":Fx.test(i)&&s.length&&(r="read_file"),{argv0:e,intent:r,writes:t,reads:s}}var ge=i=>i?parseInt(i,10):0;function Nx(i){const e=i.length>2e4?i.slice(-2e4):i;let t=e.match(/Tests\s+(?:(\d+)\s+failed\s*\|\s*)?(\d+)\s+passed(?:\s*\|\s*(\d+)\s+skipped)?/);if(t)return{failed:ge(t[1]),passed:ge(t[2]),...t[3]?{skipped:ge(t[3])}:{},framework:"vitest"};if(t=e.match(/Tests\s+(\d+)\s+failed\s*\((\d+)\)/),t)return{failed:ge(t[1]),passed:Math.max(0,ge(t[2])-ge(t[1])),framework:"vitest"};if(t=e.match(/Tests:\s+(?:(\d+)\s+failed,\s*)?(?:(\d+)\s+skipped,\s*)?(\d+)\s+passed,\s*(?:(\d+)\s+skipped,\s*)?\d+\s+total/),t)return{failed:ge(t[1]),passed:ge(t[3]),...t[2]??t[4]?{skipped:ge(t[2]??t[4])}:{},framework:"jest"};if(t=e.match(/Tests:\s+(\d+)\s+failed,\s*\d+\s+total/),t)return{failed:ge(t[1]),passed:0,framework:"jest"};if(t=e.match(/=+\s*(?:(\d+)\s+failed,?\s*)?(?:(\d+)\s+passed,?\s*)?(?:(\d+)\s+skipped,?\s*)?(?:\d+\s+(?:error|errors|warnings?|deselected|xfailed|xpassed),?\s*)*in\s+[\d.]+s/),t&&(t[1]||t[2]))return{failed:ge(t[1]),passed:ge(t[2]),...t[3]?{skipped:ge(t[3])}:{},framework:"pytest"};if(/^--- (?:PASS|FAIL):/m.test(e)||/^(?:ok|FAIL)\s+\S+\s+(?:[\d.]+s|\(cached\))/m.test(e)){const a=(e.match(/^--- FAIL:/gm)??[]).length||(e.match(/^FAIL\s+\S+\s+[\d.]+s/gm)??[]).length,l=(e.match(/^--- PASS:/gm)??[]).length||(e.match(/^ok\s+\S+/gm)??[]).length;return{failed:a,passed:l,framework:"go"}}if(t=e.match(/test result:\s*\w+\.\s*(\d+)\s+passed;\s*(\d+)\s+failed;\s*(\d+)\s+ignored/),t)return{passed:ge(t[1]),failed:ge(t[2]),skipped:ge(t[3]),framework:"cargo"};const s=e.match(/^\s*(\d+)\s+passing\b/m),r=e.match(/^\s*(\d+)\s+failing\b/m);if(s||r){const a=e.match(/^\s*(\d+)\s+pending\b/m);return{passed:ge(s?.[1]),failed:ge(r?.[1]),...a?{skipped:ge(a[1])}:{},framework:"mocha"}}const n=e.match(/^\s*(\d+)\s+passed\s*\(/m),o=e.match(/^\s*(\d+)\s+failed\b/m);return n||o?{passed:ge(n?.[1]),failed:ge(o?.[1]),framework:"playwright"}:null}var He=i=>i&&typeof i=="object"?i:{},we=i=>typeof i=="string"?i:void 0,ir=i=>i?(i.match(/\n/g)?.length??0)+(i.endsWith(`
967
+ `)?0:1):0;function zx(i){const e=He(i).structuredPatch;if(!Array.isArray(e))return null;let t=0,s=0;for(const r of e){const n=He(r).lines;if(Array.isArray(n))for(const o of n)typeof o=="string"&&(o.startsWith("+")?t++:o.startsWith("-")&&s++)}return{added:t,removed:s,hunks:e.length}}function Hx(i){if(typeof i=="string")return i;const e=He(i),t=[we(e.stdout),we(e.stderr),we(e.output)].filter(s=>!!s);return t.length?t.join(`
968
+ `):Array.isArray(i)?i.map(s=>we(He(s).text)??"").join(`
969
+ `):""}function Wx(i){let e=0;for(const t of i.matchAll(/<<-?\s*(['"]?)(\w+)\1[^\n]*\n([\s\S]*?)\n\2(?=\n|$)/g))e+=ir(t[3]);return e===0&&/(?:^|[\s)])\d?>{1,2}\s*[^\s|&;<>]+/.test(i)&&!/>\s*\/dev\/null/.test(i)&&(e=1),e}var $x=new Set(["Grep","Glob","LS","ToolSearch"]),Vx=new Set(["WebSearch","WebFetch"]),jx=new Set(["TodoWrite","TodoRead","Skill","EnterPlanMode","ExitPlanMode","EnterWorktree","ExitWorktree","NotebookRead","ListAgents","SendMessage","TaskStop","Monitor","ScheduleWakeup","ReportFindings"]);function eu(i,e){const t=He(i.input),s=i.response,r=!i.isError&&He(s).interrupted!==!0,n=a=>Ax(a,e),o=i.durationMs!==void 0?{durationMs:i.durationMs}:{};switch(i.name){case"Read":{const a=we(t.file_path)??we(t.path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:"Read without file_path"}};const l=we(He(He(s).file).content);return{bodies:[{kind:"read_file",path:n(a),...l!==void 0?{bytes:l.length}:{}}]}}case"Edit":case"MultiEdit":case"NotebookEdit":{const a=we(t.file_path)??we(t.notebook_path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:`${i.name} without file_path`}};const l=zx(s)??{added:ir(we(t.new_string)??we(t.new_source)),removed:ir(we(t.old_string)),hunks:1};return{bodies:[{kind:"edit_file",path:n(a),...l}]}}case"Write":{const a=we(t.file_path);if(!a)return{bodies:[],warning:{code:"missing_field",detail:"Write without file_path"}};const l=He(s),h=l.type==="create"||l.type===void 0&&l.originalFile===null;return{bodies:[{kind:"write_file",path:n(a),added:ir(we(t.content)),created:h}]}}case"Bash":{const a=we(t.command)??"",l=Ux(a),h=[...new Set([...l.writes,...l.reads].map(n))],c=[{kind:"run_command",argv0:l.argv0,intent:l.intent,touched:h,ok:r,...o}],u=Wx(a);l.writes.forEach((d,f)=>c.push({kind:"write_file",path:n(d),added:f===0?u:0,created:!1}));for(const d of l.reads)c.push({kind:"read_file",path:n(d)});if(l.intent==="test"){const d=Nx(Hx(s));d?c.push({kind:"test_result",ok:d.failed===0&&r,passed:d.passed,failed:d.failed,...d.skipped!==void 0?{skipped:d.skipped}:{},framework:d.framework,...o}):c.push({kind:"test_result",ok:r,passed:0,failed:0,framework:"unknown",...o})}return{bodies:c}}case"Agent":case"Task":{const a=He(s),l=we(a.agentId)??we(a.agent_id)??"",h=we(t.description)??we(t.subagent_type),c={kind:"subagent_start",childId:l,...h?{label:h}:{}};return a.status==="async_launched"||a.isAsync===!0?{bodies:[c],pendingSubagent:{childId:l}}:{bodies:[c,{kind:"subagent_stop",childId:l,ok:r}]}}case"AskUserQuestion":return{bodies:[{kind:"waiting_for_user",reason:"question"}]}}if($x.has(i.name)){const a=He(s).numFiles??He(s).numLines??He(s).count;return{bodies:[{kind:"search",scope:"repo",...typeof a=="number"?{hits:a}:{}}]}}return Vx.has(i.name)?{bodies:[{kind:"search",scope:"web"}]}:jx.has(i.name)?{bodies:[]}:{bodies:[{kind:"run_command",argv0:i.name.slice(0,40),intent:"other",touched:[],ok:r,...o}],warning:{code:"unknown_tool",detail:i.name.slice(0,80)}}}var Xx=[/\ball (?:\d+ )?tests? (?:are )?pass(?:ing|ed)?\b/i,/\btests? (?:are |is )?(?:now )?(?:passing|green)\b/i,/\b(?:is|are|it's|that's|everything(?:'s| is)) (?:now )?(?:fixed|working|done|complete|resolved)\b/i,/\bshould (?:now )?work\b/i,/\bworks now\b/i,/\b(?:done|complete|completed|fixed|resolved|shipped|implemented)[.!]/i,/✅/],qx=[/\bnot (?:yet )?(?:done|fixed|working|tested|verified|complete)\b/i,/\bstill (?:fail|broken|not)/i,/\b(?:could ?n[’']?t|cannot|can ?not|unable to|wasn[’']?t able)\b/i,/\bfail(?:ed|ing|s)\b/i,/\bTODO\b/,/\bhaven[’']?t (?:run|tested|verified|checked)/i,/\buntested\b/i,/\bI did not (?:run|test|verify)/i],tu=600;function su(i){if(!i)return!1;const e=i.length>tu?i.slice(-tu):i;return qx.some(t=>t.test(e))?!1:Xx.some(t=>t.test(e))}var Yx=new Set(["user","assistant","system"]),Xi=i=>i&&typeof i=="object"?i:{},be=i=>typeof i=="string"?i:void 0;function Kx(i,e={}){const t=[],s=[],r=i.split(/\r?\n/);for(let o=0;o<r.length;o++){const a=r[o];if(a.trim())try{t.push(JSON.parse(a))}catch{s.push({code:"bad_json",detail:`line ${o+1}`,line:o+1})}}const n=Zx(t,e);return{events:n.events,warnings:[...s,...n.warnings]}}function Zx(i,e={}){const t=[],s=[],r=new Set,n=new Map,o=new Map;let a="",l="",h,c=Number.NaN,u=Number.NaN,d="",f=0,p=!1;const g=()=>({cwd:l,...e.home?{home:e.home}:{}}),m=(x,b,v,w={})=>{t.push({id:b,seq:f++,ts:x,sessionId:a,source:"transcript",...w,...v})},_=x=>{const b=be(x.timestamp),v=b?Date.parse(b):Number.NaN;return Number.isFinite(v)?v:Number.isFinite(u)?u:0},y=x=>be(x.agentId)??(x.isSidechain===!0?e.sidechainAgentId??"sidechain":void 0);for(const x of i){const b=Xi(x),v=be(b.type)??"";if(!Yx.has(v)){v&&r.add(v);continue}!a&&be(b.sessionId)&&(a=be(b.sessionId)),!l&&be(b.cwd)&&(l=be(b.cwd)),!h&&be(b.gitBranch)&&(h=be(b.gitBranch));const w=_(b);Number.isFinite(c)||(c=w,m(w,`${a||"session"}:start`,{kind:"session_start",repoId:Rx(l)||"repo",...h?{branch:h}:{}})),u=w;const T=y(b),k=Xi(b.message),E=k.content;if(v==="system"){if(b.subtype==="api_error"){const M=typeof b.retryAttempt=="number"?b.retryAttempt:0,B=typeof b.maxRetries=="number"?b.maxRetries:0;m(w,be(b.uuid)??`sys:${f}`,{kind:"error",where:"api",retrying:M<B},T?{agentId:T}:{})}continue}if(v==="assistant"){const M=Array.isArray(E)?E:[];for(const B of M){const G=Xi(B);if(G.type==="tool_use"&&be(G.id)&&be(G.name))n.set(be(G.id),{name:be(G.name),input:G.input,ts:w,...T?{agentId:T}:{}});else if(G.type==="text"&&!T){const O=be(G.text);O&&(d=O)}}typeof E=="string"&&!T&&(d=E),k.stop_reason==="end_turn"&&!T&&m(w,`${be(b.uuid)??f}:turn`,{kind:"turn_end",claimedSuccess:su(d)});continue}b.toolDenialKind!==void 0&&m(w,`${be(b.uuid)??f}:deny`,{kind:"waiting_for_user",reason:"permission"});const A=Array.isArray(E)?E:[];for(const M of A){const B=Xi(M);if(B.type!=="tool_result")continue;const G=be(B.tool_use_id);if(!G)continue;const O=n.get(G);if(!O){s.push({code:"unpaired_result",detail:G});continue}n.delete(G);const I=b.toolUseResult??B.content,P=eu({name:O.name,input:O.input,response:I,isError:B.is_error===!0,durationMs:Math.max(0,w-O.ts)},g());P.warning&&s.push(P.warning);const C=O.agentId??T,D=C?o.get(C):void 0,R={...C?{agentId:C}:{},...D?{parentId:D}:{}};P.bodies.forEach((L,N)=>m(O.ts,N===0?G:`${G}:${N}`,L,R)),P.pendingSubagent&&o.set(P.pendingSubagent.childId,G)}A.length===0&&typeof E=="string"&&/\[Request interrupted by user/i.test(E)&&m(w,`${be(b.uuid)??f}:interrupt`,{kind:"waiting_for_user",reason:"idle"})}for(const[x,b]of n){s.push({code:"unpaired_result",detail:`tool_use ${x} (${b.name}) has no result`});const v=eu({name:b.name,input:b.input,isError:!0},g());v.warning&&s.push(v.warning),v.bodies.forEach((w,T)=>m(b.ts,T===0?x:`${x}:${T}`,w,b.agentId?{agentId:b.agentId}:{}))}for(const[x,b]of o)m(u,`${b}:stop`,{kind:"subagent_stop",childId:x,ok:!0},{parentId:b});for(const x of r)s.push({code:"unknown_row_type",detail:x});return Number.isFinite(c)&&!p&&(p=!0,m(u,`${a||"session"}:end`,{kind:"session_end",reason:"stop",claimedSuccess:su(d)})),{events:t,warnings:s}}function Oo(i){let e=2166136261;for(let t=0;t<i.length;t++)e^=i.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0}function hi(i){let e=i>>>0;return()=>{e=e+1831565813>>>0;let t=e;return t=Math.imul(t^t>>>15,t|1),t^=t+Math.imul(t^t>>>7,t|61),((t^t>>>14)>>>0)/4294967296}}var Qx=/(^|\/)(schema\.(sql|prisma|graphql|gql)|.*\.(sql|prisma|db|sqlite)|migrations?\/|drizzle\/|models?\/.*\.(ts|js|py|rb)$)/i,Jx=/(^|\/)(node_modules|\.git|dist|build|out|coverage|_site|\.next|\.turbo|target|vendor|__pycache__|\.venv|venv)(\/|$)|(^|\/)\.[^/]+$|\.(lock|map|min\.js|png|jpg|jpeg|gif|webp|svg|ico|woff2?|ttf|mp4|mp3|pdf|zip)$/i;function eb(i){return Jx.test(i)}function Sg(i){return wg(i)?"beacon":Qx.test(i)?"archive":"building"}function iu(i){return typeof i.loc=="number"?i.loc:typeof i.size=="number"?Math.max(1,Math.round(i.size/40)):1}function tb(i,e){const t=i.filter(n=>!eb(n.path)),s=Math.max(1,...t.map(iu)),r=Math.max(1,...t.map(n=>n.churn??0));return t.map(n=>{const o=iu(n),a=e.has(n.path),l=.5*Math.sqrt(o/s)+.3*((n.churn??0)/r)+(a?.2:0);return{file:n,loc:o,score:l,kind:Sg(n.path),touched:a}})}function ru(i,e){const t=Math.sqrt(i/Math.max(1,e));return Math.max(1,Math.min(5,Math.ceil(t*5)))}function nu(i){return i>=5?3:i>=3?2:1}var sb={ts:"TypeScript",tsx:"TypeScript",js:"JavaScript",jsx:"JavaScript",mjs:"JavaScript",py:"Python",go:"Go",rs:"Rust",java:"Java",kt:"Kotlin",swift:"Swift",rb:"Ruby",php:"PHP",cs:"C#",cpp:"C++",cc:"C++",c:"C",h:"C",m:"Objective-C",scala:"Scala",ex:"Elixir",exs:"Elixir",dart:"Dart",lua:"Lua",zig:"Zig",sh:"Shell",sql:"SQL",md:"Markdown",mdx:"Markdown",html:"HTML",css:"CSS",scss:"CSS",vue:"Vue",svelte:"Svelte",tf:"Terraform",yaml:"YAML",yml:"YAML",ipynb:"Notebook"};function ib(i,e={}){const t=i.map(p=>p.path.toLowerCase()),s=p=>t.some(g=>p.test(g)),r=p=>t.filter(g=>p.test(g)).length,n=new Map;for(const p of t){const g=p.slice(p.lastIndexOf(".")+1),m=sb[g];m&&!/^(markdown|yaml|html|css|shell|sql)$/i.test(m)&&n.set(m,(n.get(m)??0)+1)}const o=[...n.entries()].sort((p,g)=>g[1]-p[1]).map(([p])=>p).slice(0,4),a=(e["package.json"]??"").toLowerCase(),l=((e["pyproject.toml"]??"")+(e["requirements.txt"]??"")).toLowerCase(),h=p=>p.test(a)||p.test(l),c=new Map,u=(p,g)=>c.set(p,(c.get(p)??0)+g);h(/"(react|react-dom|next|vue|nuxt|svelte|@sveltejs\/kit|@angular\/core|solid-js|astro|remix|vite)"/)&&u("web-frontend",3),r(/\.(tsx|jsx|vue|svelte)$/)>3&&u("web-frontend",2),(s(/(^|\/)(index|app)\.html$/)||r(/\.(css|scss)$/)>3)&&u("web-frontend",1),h(/"(express|fastify|hono|koa|@nestjs\/core|apollo-server|prisma|drizzle-orm|django|flask|fastapi|sqlalchemy|gin|fiber|actix|axum|rails|spring)"/)&&u("backend-api",3),(s(/(^|\/)(routes?|controllers?|api|handlers?|migrations?)\//)||s(/\.(sql|prisma)$/))&&u("backend-api",2),(a.includes('"bin"')||s(/(^|\/)(cli|cmd|bin)\//)||h(/"(commander|yargs|clap|cobra|click|typer)"/))&&u("cli-tool",3),(h(/"(torch|tensorflow|jax|pandas|numpy|scikit-learn|sklearn|transformers|xgboost|lightgbm|polars)"/)||r(/\.ipynb$/)>0||s(/(^|\/)(notebooks?|models?|datasets?|training)\//))&&u("data-ml",3),(s(/\.(swift|kt)$/)||s(/(^|\/)(ios|android)\//)||s(/package\.swift$/)||s(/build\.gradle(\.kts)?$/)||h(/"(react-native|expo|flutter)"/)||s(/\.dart$/))&&u("mobile",3),(s(/\.(unity|unitypackage|godot|tscn|gd)$/)||s(/(^|\/)assets\/.*\.(prefab|fbx)$/)||h(/"(phaser|pixi\.js|three|babylonjs|@react-three\/fiber|excalibur|kaplay|bevy|godot)"/))&&u("game",3),(s(/\.tf$/)||s(/(^|\/)(dockerfile|docker-compose\.ya?ml|helm|k8s|kubernetes|\.github\/workflows|ansible|pulumi)/))&&u("infra-devops",s(/\.tf$/)||s(/(^|\/)(helm|k8s|kubernetes|ansible|pulumi)\//)?3:1);const d=r(/\.(md|mdx|rst)$/)/Math.max(1,t.length);(d>.4||s(/(^|\/)(mkdocs|docusaurus)\.config|(^|\/)docs\/.*\.mdx?$/)&&d>.25)&&u("docs-content",3),(s(/(^|\/)pnpm-workspace\.ya?ml$/)||s(/(^|\/)packages\/[^/]+\/package\.json$/)||s(/(^|\/)(lerna|nx|turbo)\.json$/)||s(/(^|\/)cargo\.toml$/)&&r(/(^|\/)crates\/[^/]+\//)>0)&&u("monorepo",2),r(/\.(rs|go|c|cpp|cc|h|zig)$/)>5&&!c.has("web-frontend")&&u("systems",2),a.includes('"main"')&&!a.includes('"bin"')&&!c.has("web-frontend")&&!c.has("backend-api")&&u("library",2),s(/(^|\/)(lib|src\/lib)\//)&&!c.has("web-frontend")&&u("library",1);const f=[...c.entries()].filter(([,p])=>p>=2).sort((p,g)=>g[1]-p[1]).map(([p])=>p);return{kinds:f.length?f:["unknown"],languages:o,files:i.length}}function rb(i){const e=i.cap??60,t=i.beaconCap??8,s=i.touchedCap??48,r=new Set((i.touched??[]).map(ou).slice(0,s)),n=Oo(i.repoId),o=hi(n),a=i.files.map(C=>({...C,path:ou(C.path)})),l=tb(a,r),h=Math.max(1,...l.map(C=>C.loc)),c=[...l].sort((C,D)=>D.score-C.score||C.file.path.localeCompare(D.file.path)),u=hu(c.filter(C=>C.kind==="beacon"),t),d=hu(c.filter(C=>C.kind!=="beacon"),e),f=[...d,...u],p=f.length<l.length,g=new Map;for(const C of d){const D=On(C.file.path);(g.get(D)??g.set(D,[]).get(D)).push(C)}const m=[...g.keys()].sort(),_=new Set,y=[],x=[],b={id:"forge",kind:"forge",path:"",label:"forge",district:"",gx:-1,gy:-1,footprint:2,height:2,score:0,touched:!1};y.push(b);const v=i.layout??wi[n%wi.length],w=o()*Math.PI*2,T=m.map(C=>{const D=g.get(C).sort((N,se)=>se.score-N.score||N.file.path.localeCompare(se.file.path)),R=D.reduce((N,se)=>N+nu(ru(se.loc,h))**2,0),L=Math.max(3,Math.ceil(Math.sqrt(R*1.45)));return{name:C,items:D,side:L}}),k=[],E={x:-2,y:-2,w:4,h:4},A=Pg(v,T.map(C=>C.side),E,w,o);k.push(E,...A);const M=Ag(v,A);b.gx=M[0],b.gy=M[1],_.clear(),Mt(_,b),T.forEach((C,D)=>{const R=A[D],L={id:`d:${C.name}`,label:C.name===""?"/":`${C.name}/`,bounds:R,cx:R.x+Math.floor(R.w/2),cy:R.y+Math.floor(R.h/2),placeIds:[]};for(const N of C.items){const se=ru(N.loc,h),Q=nu(se),re=Lo(_,L.cx,L.cy,Q,R),j={id:`p:${N.file.path}`,kind:N.kind,path:N.file.path,label:au(N.file.path),district:L.id,gx:re[0],gy:re[1],footprint:Q,height:se,score:lu(N.score),touched:N.touched};Mt(_,j),y.push(j),L.placeIds.push(j.id)}x.push(L)}),Math.ceil(kg(k));for(const C of k)for(let D=C.x-1;D<C.x+C.w+1;D++)for(let R=C.y-1;R<C.y+C.h+1;R++)_.add(`${D},${R}`);for(const C of u){const D=x.find(N=>N.id===`d:${On(C.file.path)}`),R=D?Bg(_,D,b,1):Ti(_,b.gx+1,b.gy+1,o()*Math.PI*2,4,1),L={id:`p:${C.file.path}`,kind:"beacon",path:C.file.path,label:au(C.file.path),district:D?.id??"",gx:R[0],gy:R[1],footprint:1,height:4,score:lu(C.score),touched:C.touched};Mt(_,L),y.push(L),D?.placeIds.push(L.id)}const B=Ti(_,b.gx+1,b.gy+1,w+Math.PI,5,2),G={id:"dock",kind:"dock",path:"",label:"dock",district:"",gx:B[0],gy:B[1],footprint:2,height:1,score:0,touched:!1};Mt(_,G),y.push(G);const O=Rg(v,x,b,G);if(p)for(const C of x){const D=C.id.slice(2),R=l.filter(se=>se.kind!=="beacon"&&On(se.file.path)===D).length;if(R<=C.placeIds.length)continue;const L=Lo(_,C.cx,C.cy,1,C.bounds),N={id:`p:${D?D+"/":""}…`,kind:"overflow",path:`${D?D+"/":""}…`,label:`+${R-C.placeIds.length} more`,district:C.id,gx:L[0],gy:L[1],footprint:1,height:2,score:0,touched:!1};Mt(_,N),y.push(N),C.placeIds.push(N.id)}const I=Eg(y,2),P=ib(a,i.manifests??{});return{repoId:i.repoId,seed:n,layout:v,profile:P,districts:x,places:y,paths:O,bounds:I,stats:{files:l.length,placed:f.length,capped:p}}}var ou=i=>i.replace(/\\/g,"/").replace(/^\.\//,"").replace(/^\/+/,""),au=i=>i.slice(i.lastIndexOf("/")+1),On=i=>i.includes("/")?i.slice(0,i.indexOf("/")):"",lu=i=>Math.round(i*1e3)/1e3;function hu(i,e){const t=i.filter(r=>r.touched),s=i.filter(r=>!r.touched);return[...t,...s.slice(0,Math.max(0,e-t.length))]}function cu(i,e,t){return i.x<e.x+e.w+t&&e.x<i.x+i.w+t&&i.y<e.y+e.h+t&&e.y<i.y+i.h+t}function Cg(i,e,t){const s=[];for(let r=0;r<t;r++)for(let n=0;n<t;n++)s.push(`${i+r},${e+n}`);return s}function Mg(i,e,t,s){return Cg(e,t,s).every(r=>!i.has(r))}function Mt(i,e){for(const t of Cg(e.gx,e.gy,e.footprint))i.add(t)}function Lo(i,e,t,s,r){let n=0,o=0,a=0,l=-1,h=null;for(let c=0;c<4096;c++){const u=e+n-Math.floor(s/2),d=t+o-Math.floor(s/2);if(Mg(i,u,d,s)){if(u>=r.x-1&&d>=r.y-1&&u+s<=r.x+r.w+1&&d+s<=r.y+r.h+1)return[u,d];if(h??=[u,d],c>600)return h}(n===o||n<0&&n===-o||n>0&&n===1-o)&&([a,l]=[-l,a]),n+=a,o+=l}return h??[e,t]}function kg(i){return Math.max(...i.map(e=>Math.max(Math.abs(e.x),Math.abs(e.x+e.w),Math.abs(e.y),Math.abs(e.y+e.h))))}function Eg(i,e){const t=i.flatMap(o=>[o.gx,o.gx+o.footprint]),s=i.flatMap(o=>[o.gy,o.gy+o.footprint]),r=Math.min(...t)-e,n=Math.min(...s)-e;return{x:r,y:n,w:Math.max(...t)+e-r,h:Math.max(...s)+e-n}}var wi=["ring","grid","strip","scatter","terrace","spine"];function Pg(i,e,t,s,r){const n=e.length,o=[],a=Math.max(3,...e),l=c=>!cu(t,c,1)&&!o.some(u=>cu(u,c,1)),h=(c,u,d)=>{const f={x:c,y:u,w:d,h:d};return o.push(f),f};switch(i){case"grid":{const c=Math.max(2,Math.ceil(Math.sqrt(n+1))),u=[];let d=0,f=0;for(;f<n;){const m=e.slice(f,f+c),_=Math.max(...m)+2;let y=0;for(const x of m)u.push({x:y,y:d}),y+=x+2;d+=_,f+=c}const p=Math.max(...u.map((m,_)=>m.x+e[_])),g=d;for(let m=0;m<n;m++){let _={x:u[m].x-Math.round(p/2),y:u[m].y-Math.round(g/2),w:e[m],h:e[m]};for(;!l(_);)_={..._,x:_.x+1};o.push(_)}return o}case"strip":{const c=e.reduce((d,f)=>d+f+2,0);let u=Math.round(-c/2)+6;for(let d=0;d<n;d++){const f=Math.round((r()-.5)*3);h(u,f-Math.floor(e[d]/2),e[d]),u+=e[d]+2}return o}case"terrace":{let c=-Math.round(n*(a+1)/2),u=-Math.round(n*(a+1)*.3);for(let d=0;d<n;d++)h(c,u,e[d]),c+=e[d]+1,u+=Math.round(e[d]*.6)+1;return o}case"spine":{let c=-Math.round(n*(a+2)/4);for(let u=0;u<n;u++){const d=u%2===0;h(d?-e[u]-3:3,c,e[u]),d||(c+=a+2)}return o}case"scatter":{for(let c=0;c<n;c++){let u=5+a,d=!1;for(let f=0;f<400&&!d;f++){const p=s+r()*Math.PI*2,g=u*(.5+r()*.7),m={x:Math.round(Math.cos(p)*g),y:Math.round(Math.sin(p)*g*.8),w:e[c],h:e[c]};l(m)&&(o.push(m),d=!0),f%40===39&&(u+=2)}d||h(u+c*2,0,e[c])}return o}default:{let c=3;for(let u=0;u<n;u++){const d=e[u],f=s+u/Math.max(1,n)*Math.PI*2;let p=c+d/2,g;for(;;){const m=Math.round(Math.cos(f)*p),_=Math.round(Math.sin(f)*p*.8);if(g={x:m-Math.floor(d/2),y:_-Math.floor(d/2),w:d,h:d},l(g))break;p+=1}o.push(g),c=Math.max(c,p-d/2)}return o}}}function Ag(i,e){if(!e.length)return[-1,-1];const t=Math.min(...e.map(r=>r.x)),s=Math.min(...e.map(r=>r.y));switch(i){case"strip":return[t-5,-1];case"terrace":return[t-5,s-1];case"spine":return[-1,s-5];default:return[-1,-1]}}function Rg(i,e,t,s){const r=[t.gx+1,t.gy+1],n=[];if(i==="strip"||i==="terrace"){const o=[...e].sort((h,c)=>h.cx-c.cx||h.cy-c.cy);let a=r,l="forge";for(const h of o)n.push({from:l,to:h.id,points:[a,[h.cx,h.cy]]}),a=[h.cx,h.cy],l=h.id}else if(i==="grid"||i==="spine")for(const o of e)n.push({from:o.id,to:"forge",points:[[o.cx,o.cy],[o.cx,r[1]],r]});else for(const o of e)n.push({from:o.id,to:"forge",points:[[o.cx,o.cy],[Math.round((o.cx+r[0])/2),Math.round((o.cy+r[1])/2)],r]});return n.push({from:"dock",to:"forge",points:[[s.gx,s.gy],r]}),n}function nb(i,e){if(i.layout===e)return i;const t=i.seed,s=hi(t^1374496523^wi.indexOf(e)),r=new Set,n=[],o={...i.places.find(y=>y.kind==="forge"),gx:-1,gy:-1};n.push(o);const a=s()*Math.PI*2,h=i.districts.map(y=>({d:y,items:i.places.filter(x=>x.district===y.id&&(x.kind==="building"||x.kind==="archive"||x.kind==="overflow")).sort((x,b)=>b.score-x.score||x.path.localeCompare(b.path))})).map(y=>{const x=y.items.reduce((b,v)=>b+v.footprint**2,0);return{...y,side:Math.max(3,Math.ceil(Math.sqrt(x*1.45)))}}),c={x:-2,y:-2,w:4,h:4},u=Pg(e,h.map(y=>y.side),c,a,s),d=[c,...u],f=Ag(e,u);o.gx=f[0],o.gy=f[1],Mt(r,o);const p=h.map((y,x)=>{const b=u[x],v={...y.d,bounds:b,cx:b.x+Math.floor(b.w/2),cy:b.y+Math.floor(b.h/2),placeIds:[]};for(const w of y.items){const T=Lo(r,v.cx,v.cy,w.footprint,b),k={...w,gx:T[0],gy:T[1]};Mt(r,k),n.push(k),v.placeIds.push(k.id)}return v});Math.ceil(kg(d));for(const y of d)for(let x=y.x-1;x<y.x+y.w+1;x++)for(let b=y.y-1;b<y.y+y.h+1;b++)r.add(`${x},${b}`);for(const y of i.places.filter(x=>x.kind==="beacon")){const x=p.find(w=>w.id===y.district),b=x?Bg(r,x,o,1):Ti(r,o.gx+1,o.gy+1,s()*Math.PI*2,4,1),v={...y,gx:b[0],gy:b[1]};Mt(r,v),n.push(v),x?.placeIds.push(v.id)}const g=Ti(r,o.gx+1,o.gy+1,a+Math.PI,5,2),m={...i.places.find(y=>y.kind==="dock"),gx:g[0],gy:g[1]};Mt(r,m),n.push(m);const _=Rg(e,p,o,m);return{...i,layout:e,districts:p,places:n,paths:_,bounds:Eg(n,2)}}function Ti(i,e,t,s,r,n){for(let o=r;o<r+40;o++)for(let a=0;a<64;a++){const l=s+(a%2?1:-1)*Math.ceil(a/2)*(Math.PI/32),h=Math.round(e+Math.cos(l)*o),c=Math.round(t+Math.sin(l)*o*.85);if(Mg(i,h,c,n))return[h,c]}return[e+r,t]}function Bg(i,e,t,s){const r=Math.atan2(e.cy-t.gy,e.cx-t.gx),n=Math.ceil(Math.max(e.bounds.w,e.bounds.h)/2)+2;return Ti(i,e.cx,e.cy,r,n,s)}var ob=class{constructor(i){this.windowMs=i}windowMs;mood="curious";trouble=[];recordTrouble(i){return this.trouble=this.trouble.filter(e=>i-e<=this.windowMs),this.trouble.push(i),this.trouble.length>=2}onRead(){return this.mood=this.mood==="lost"?"lost":"curious"}onBuild(){return this.mood=this.mood==="lost"?"lost":"focused"}onFail(i){return this.mood=this.recordTrouble(i)?"lost":"uneasy"}onError(i){return this.mood=this.recordTrouble(i)?"lost":"uneasy"}onPass(){return this.trouble=[],this.mood="happy"}onClaimUnverified(){return this.mood="uneasy"}},ab=class{constructor(i,e={}){this.world=i;for(const t of i.places)this.places.set(t.id,t),t.path&&this.byPath.set(t.path,t);this.beacons=i.places.filter(t=>t.kind==="beacon"),this.forge=i.places.find(t=>t.kind==="forge")??i.places[0],this.dock=i.places.find(t=>t.kind==="dock")??this.forge,this.maxGap=e.maxGapMs??2500,this.msPerCell=e.walkMsPerCell??90,this.mood=new ob(e.lostWindowMs??9e4),this.actorAt.set("pip",this.forge.id)}world;places=new Map;byPath=new Map;beacons;forge;dock;maxGap;msPerCell;mood;beats=[];sceneMs=0;lastRealTs=null;seq=0;actorAt=new Map;helpers=new Map;gremlins=new Map;lastEdited=null;pendingBeacon=null;editedSinceTurn=!1;verifiedSinceEdit=!1;everVerified=!1;claimGremlin=null;get timeline(){return this.beats}feed(i){const e=this.beats.length;this.advanceClock(i.ts,i.id);const t=i.agentId&&this.helpers.has(i.agentId)?i.agentId:"pip";switch(i.kind){case"session_start":this.emit(i,t,{kind:"curtain_up",repoId:i.repoId},1200);break;case"read_file":{const s=this.placeFor(i.path,i,t);this.walk(i,t,s),this.emit(i,t,{kind:"read",target:s.id},vs(700+(i.bytes??400)/4,900,1800),this.mood.onRead());break}case"edit_file":case"write_file":{const s=this.placeFor(i.path,i,t);this.walk(i,t,s);const r=i.kind==="edit_file"?i.added+i.removed:i.added,n=vs(Math.sqrt(r/50),.15,1),o=[...this.gremlins].find(([,a])=>a===s.id);o&&this.emit(i,t,{kind:"chase",gremlinId:o[0],target:s.id},900,this.mood.mood),i.kind==="write_file"&&i.created&&this.emit(i,t,{kind:"raise",target:s.id},900,this.mood.onBuild()),this.emit(i,t,{kind:"build",target:s.id,intensity:n},vs(600+n*1900,800,2500),this.mood.onBuild()),this.lastEdited=s,this.editedSinceTurn=!0,this.verifiedSinceEdit=!1;break}case"run_command":{if(i.intent==="test"){const s=this.beaconFor(i.touched);this.walk(i,t,s),this.pendingBeacon=s,this.emit(i,t,{kind:"run_tests",target:s.id},vs(i.durationMs??1200,900,3e3),this.mood.mood)}else if(i.intent==="search")this.emit(i,t,{kind:"search",scope:"repo"},700,this.mood.onRead());else if(i.touched.length===0||i.intent==="git"||i.intent==="install"||i.intent==="build"){this.walk(i,t,this.forge);const s=i.intent==="build"||i.intent==="install"?.8:i.intent==="git"?.4:.5;this.emit(i,t,{kind:"forge",intensity:s},vs(i.durationMs??800,700,2e3),this.mood.mood)}!i.ok&&i.intent!=="test"&&this.emit(i,t,{kind:"stumble",retrying:!1},600,this.mood.onError(i.ts));break}case"test_result":{const s=this.pendingBeacon??this.beaconFor([]);this.pendingBeacon=null;const r=(i.framework==="unknown"&&i.passed===0&&i.failed===0,i.ok?"pass":"fail");if(r==="pass"){this.emit(i,t,{kind:"test_outcome",target:s.id,outcome:r,passed:i.passed,failed:i.failed},800,this.mood.onPass()),(i.passed>0||i.framework==="unknown")&&(this.verifiedSinceEdit=!0,this.everVerified=!0);for(const[n]of this.gremlins)this.emit(i,t,{kind:"banish",gremlinId:n},700,"happy");this.gremlins.clear(),this.claimGremlin&&(this.emit(i,t,{kind:"banish",gremlinId:this.claimGremlin},700,"happy"),this.claimGremlin=null),this.emit(i,t,{kind:"celebrate",target:s.id},1600,"happy")}else{this.emit(i,t,{kind:"test_outcome",target:s.id,outcome:r,passed:i.passed,failed:i.failed},800,this.mood.onFail(i.ts));const n=this.lastEdited??s,o=`g:${i.id}`;this.gremlins.set(o,n.id),this.emit(i,t,{kind:"spawn_gremlin",gremlinId:o,target:n.id},900,this.mood.mood)}break}case"search":this.emit(i,t,{kind:"search",scope:i.scope},700,this.mood.onRead());break;case"subagent_start":this.helpers.set(i.childId,i.label?{label:i.label}:{}),this.actorAt.set(i.childId,this.dock.id),this.emit(i,"pip",{kind:"summon_helper",helperId:i.childId,...i.label?{label:i.label}:{}},1400,this.mood.mood);break;case"subagent_stop":this.helpers.has(i.childId)&&(this.emit(i,i.childId,{kind:"dismiss_helper",helperId:i.childId,ok:i.ok},1e3,this.mood.mood),this.helpers.delete(i.childId),this.actorAt.delete(i.childId));break;case"waiting_for_user":i.reason==="idle"?this.emit(i,t,{kind:"your_turn"},1e3,this.mood.mood):this.emit(i,t,{kind:"blocked_on_you",reason:i.reason},1200,this.mood.mood);break;case"error":this.emit(i,t,{kind:"stumble",retrying:i.retrying},700,this.mood.onError(i.ts));break;case"turn_end":{if(i.claimedSuccess&&this.editedSinceTurn&&!this.verifiedSinceEdit){const s=`claim:${i.id}`;this.claimGremlin=s,this.emit(i,t,{kind:"unverified_claim",gremlinId:s},1400,this.mood.onClaimUnverified())}this.editedSinceTurn=!1,this.emit(i,t,{kind:"your_turn"},1e3,this.mood.mood);break}case"session_end":this.emit(i,t,{kind:"curtain_down",verified:this.everVerified&&!this.claimGremlin},1500,this.mood.mood);break}return this.beats.slice(e)}advanceClock(i,e){if(this.lastRealTs!==null){const t=this.beats.length?Math.max(...this.beats.slice(-3).map(n=>n.atMs+n.durationMs)):this.sceneMs,s=Math.min(Math.max(0,i-this.lastRealTs),this.maxGap),r=Math.max(t,this.sceneMs)+s;if(r-t>=1e3){const n={id:`b${this.seq++}`,atMs:t,durationMs:r-t,realTs:this.lastRealTs,mood:this.mood.mood,actor:"pip",sourceEventIds:[e],kind:"idle"};this.beats.push(n)}this.sceneMs=Math.max(this.sceneMs,r)}this.lastRealTs=i}emit(i,e,t,s,r=this.mood.mood){s=Math.round(s),"intensity"in t&&(t={...t,intensity:Math.round(t.intensity*1e3)/1e3});const n={id:`b${this.seq++}`,atMs:Math.round(this.sceneMs),durationMs:s,realTs:i.ts,mood:r,actor:e,sourceEventIds:[i.id],...t};return this.beats.push(n),this.sceneMs+=s,n}walk(i,e,t){const s=this.actorAt.get(e)??this.forge.id;if(s===t.id)return;const r=this.places.get(s)??this.forge,n=Math.hypot(t.gx-r.gx,t.gy-r.gy);this.emit(i,e,{kind:"walk_to",target:t.id},vs(Math.round(n*this.msPerCell),300,2500)),this.actorAt.set(e,t.id)}raised=0;placeFor(i,e,t){const s=this.byPath.get(i);if(s)return s;const r=i.includes("/")?i.slice(0,i.indexOf("/")):"",n=this.byPath.get(`${r?r+"/":""}…`);if(n&&(this.raised>=24||this.world.stats.capped))return n;if(this.raised>=24)return n??this.forge;this.raised++;const o=this.world.districts.find(h=>h.id===`d:${r}`)??this.world.districts[0],a=o?{gx:o.cx,gy:o.cy}:{gx:this.forge.gx+3,gy:this.forge.gy},l={id:`p:${i}`,kind:Sg(i),path:i,label:i.slice(i.lastIndexOf("/")+1),district:o?.id??"",gx:a.gx,gy:a.gy,footprint:1,height:1,score:0,touched:!0};return this.places.set(l.id,l),this.byPath.set(i,l),l.kind==="beacon"&&this.beacons.push(l),this.emit(e,t,{kind:"raise",target:l.id,newPlace:{path:i,label:l.label,kind:l.kind,district:l.district}},900),l}beaconFor(i){const e=i.find(t=>wg(t));if(e){const t=this.byPath.get(e);if(t)return t}if(this.lastEdited){const t=this.beacons.find(s=>s.district===this.lastEdited.district);if(t)return t}return this.beacons[0]??this.forge}};function rr(i,e,t){const s=new ab(e,t);for(const r of i)s.feed(r);return[...s.timeline]}var vs=(i,e,t)=>Math.min(t,Math.max(e,i));function lb(i){const e=new Map,t=(r,n)=>e.set(r,(e.get(r)??0)+n);for(const r of i)if(r.kind==="read_file")t(r.path,Math.max(5,Math.round((r.bytes??400)/40)));else if(r.kind==="edit_file")t(r.path,Math.max(5,(r.added+r.removed)*3));else if(r.kind==="write_file")t(r.path,Math.max(5,r.added*2));else if(r.kind==="run_command")for(const n of r.touched)t(n,5);const s=[...e.keys()].sort((r,n)=>e.get(n)-e.get(r));return{files:s.map(r=>({path:r,loc:e.get(r)})),touched:s}}class hb{ctx=null;master=null;sfxBus=null;ambBus=null;duck=0;_muted=!1;_volume=.6;_ambience=!0;get ambienceEnabled(){return this._ambience}setAmbienceEnabled(e){this._ambience=e,this.ambBus&&this.ctx&&this.ambBus.gain.setTargetAtTime(e?.35:0,this.ctx.currentTime,.1)}noiseBuf=null;get ready(){return!!this.ctx&&this.ctx.state==="running"}get muted(){return this._muted}get volume(){return this._volume}async arm(){if(!this.ctx){const e=globalThis.AudioContext??globalThis.webkitAudioContext;if(!e)return;this.ctx=new e,this.master=this.ctx.createGain(),this.sfxBus=this.ctx.createGain(),this.ambBus=this.ctx.createGain(),this.sfxBus.connect(this.master),this.ambBus.connect(this.master),this.master.connect(this.ctx.destination),this.ambBus.gain.value=this._ambience?.35:0,this.applyGain();const t=this.ctx.sampleRate*2;this.noiseBuf=this.ctx.createBuffer(1,t,this.ctx.sampleRate);const s=this.noiseBuf.getChannelData(0);for(let r=0;r<t;r++)s[r]=Math.random()*2-1}this.ctx.state==="suspended"&&await this.ctx.resume()}setMuted(e){this._muted=e,this.applyGain()}setVolume(e){this._volume=Math.max(0,Math.min(1,e)),this.applyGain()}applyGain(){this.master&&this.master.gain.setTargetAtTime(this._muted?0:this._volume,this.ctx.currentTime,.02)}duckAmbience(e=.5,t=350){if(!this.ambBus||!this.ctx)return;const s=this.ctx.currentTime;this.ambBus.gain.cancelScheduledValues(s),this._ambience&&(this.ambBus.gain.setTargetAtTime(.35*(1-e),s,.01),this.ambBus.gain.setTargetAtTime(.35,s+t/1e3,.12),this.duck++)}tone(e,t,s={}){if(!this.ready||!this.ctx||!this.sfxBus)return;const r=this.ctx,n=r.currentTime,o=r.createOscillator();o.type=s.type??"sine",o.frequency.setValueAtTime(e,n),s.detune&&(o.detune.value=s.detune),s.slideTo&&o.frequency.exponentialRampToValueAtTime(Math.max(20,s.slideTo),n+t);const a=r.createGain(),l=s.attack??.005,h=s.decay??t;a.gain.setValueAtTime(1e-4,n),a.gain.exponentialRampToValueAtTime(s.gain??.25,n+l),a.gain.exponentialRampToValueAtTime(1e-4,n+l+h);let c=o;if(s.lowpass){const d=r.createBiquadFilter();d.type="lowpass",d.frequency.value=s.lowpass,o.connect(d),c=d}const u=r.createStereoPanner();u.pan.value=s.pan??0,c.connect(a),a.connect(u),u.connect(this.sfxBus),o.start(n),o.stop(n+l+h+.05),this.duckAmbience(.35,(l+h)*1e3)}noise(e,t={}){if(!this.ready||!this.ctx||!this.sfxBus||!this.noiseBuf)return;const s=this.ctx,r=s.currentTime,n=s.createBufferSource();n.buffer=this.noiseBuf,n.loop=!0;const o=s.createBiquadFilter();o.type=t.filter??"bandpass",o.frequency.setValueAtTime(t.freq??1200,r),o.Q.value=t.q??.8,t.sweepTo&&o.frequency.exponentialRampToValueAtTime(Math.max(40,t.sweepTo),r+e);const a=s.createGain(),l=t.attack??.004;a.gain.setValueAtTime(1e-4,r),a.gain.exponentialRampToValueAtTime(t.gain??.12,r+l),a.gain.exponentialRampToValueAtTime(1e-4,r+e);const h=s.createStereoPanner();h.pan.value=t.pan??0,n.connect(o),o.connect(a),a.connect(h),h.connect(this.sfxBus),n.start(r),n.stop(r+e+.05)}pad(e,t,s="sine"){if(!this.ready||!this.ctx||!this.ambBus)return()=>{};const r=this.ctx,n=r.currentTime,o=[],a=r.createGain();a.gain.setValueAtTime(1e-4,n),a.gain.exponentialRampToValueAtTime(t,n+1.5),a.connect(this.ambBus);for(const l of e){const h=r.createOscillator();h.type=s,h.frequency.value=l,h.detune.value=(Math.random()-.5)*6,h.connect(a),h.start(n),o.push(h)}return()=>{const l=r.currentTime;a.gain.cancelScheduledValues(l),a.gain.setTargetAtTime(1e-4,l,.4);for(const h of o)h.stop(l+2)}}wash(e,t,s,r=.12,n=.5){if(!this.ready||!this.ctx||!this.ambBus||!this.noiseBuf)return()=>{};const o=this.ctx,a=o.currentTime,l=o.createBufferSource();l.buffer=this.noiseBuf,l.loop=!0;const h=o.createBiquadFilter();h.type="lowpass",h.frequency.value=e,h.Q.value=t;const c=o.createGain();c.gain.setValueAtTime(1e-4,a),c.gain.exponentialRampToValueAtTime(s,a+2);const u=o.createOscillator();u.frequency.value=r;const d=o.createGain();return d.gain.value=s*n,u.connect(d),d.connect(c.gain),l.connect(h),h.connect(c),c.connect(this.ambBus),l.start(a),u.start(a),()=>{const f=o.currentTime;c.gain.setTargetAtTime(1e-4,f,.5),l.stop(f+2.5),u.stop(f+2.5)}}now(){return this.ctx?.currentTime??0}captureStream(){if(!this.ctx||!this.master)return null;const e=this.ctx.createMediaStreamDestination();return this.master.connect(e),e.stream}note(e,t,s,r="sine",n=0){if(!this.ready||!this.ctx||!this.ambBus)return;const o=this.ctx,a=o.currentTime,l=o.createGain();l.gain.setValueAtTime(1e-4,a),l.gain.exponentialRampToValueAtTime(s,a+Math.min(.12,t*.3)),l.gain.setTargetAtTime(1e-4,a+t*.6,t*.35);const h=o.createStereoPanner();h.pan.value=n,l.connect(h),h.connect(this.ambBus);const c=o.createBiquadFilter();c.type="lowpass",c.frequency.value=Math.min(6e3,e*4),c.connect(l);for(const f of[0,4]){const p=o.createOscillator();p.type=r,p.frequency.value=e,p.detune.value=f,p.connect(c),p.start(a),p.stop(a+t*1.6)}const u=o.createOscillator();u.type="sine",u.frequency.value=e/2;const d=o.createGain();d.gain.value=.35,u.connect(d),d.connect(c),u.start(a),u.stop(a+t*1.6)}extra(e,t=(Math.random()-.5)*1.2){if(!this.ready||!this.ctx||!this.ambBus)return;const s=this.ctx,r=s.currentTime,n=(a,l,h,c,u,d=.01)=>{const f=s.createOscillator();f.type=a,f.frequency.setValueAtTime(l,r),f.frequency.exponentialRampToValueAtTime(Math.max(20,h),r+c);const p=s.createGain();p.gain.setValueAtTime(1e-4,r),p.gain.exponentialRampToValueAtTime(u,r+d),p.gain.exponentialRampToValueAtTime(1e-4,r+c);const g=s.createStereoPanner();g.pan.value=t,f.connect(p),p.connect(g),g.connect(this.ambBus),f.start(r),f.stop(r+c+.05)},o=(a,l,h,c,u,d="bandpass")=>{if(!this.noiseBuf)return;const f=s.createBufferSource();f.buffer=this.noiseBuf,f.loop=!0;const p=s.createBiquadFilter();p.type=d,p.frequency.setValueAtTime(a,r),u&&p.frequency.exponentialRampToValueAtTime(u,r+h),p.Q.value=l;const g=s.createGain();g.gain.setValueAtTime(1e-4,r),g.gain.exponentialRampToValueAtTime(c,r+.05),g.gain.exponentialRampToValueAtTime(1e-4,r+h);const m=s.createStereoPanner();m.pan.value=t,f.connect(p),p.connect(g),g.connect(m),m.connect(this.ambBus),f.start(r),f.stop(r+h+.05)};switch(e){case"gull":n("sine",1800,1100,.35,.05,.03),setTimeout(()=>n("sine",1700,1250,.3,.04,.03),260);return;case"cricket":for(let a=0;a<6;a++)setTimeout(()=>n("sine",4200,4100,.04,.02),a*70);return;case"bell":n("sine",880,870,2.2,.06,.005),n("sine",1760,1740,1.4,.03,.005),n("sine",2640,2600,.8,.015,.005);return;case"bubble":n("sine",300+Math.random()*300,900+Math.random()*600,.18,.04,.01);return;case"wind":o(500+Math.random()*400,.5,2.5+Math.random()*2,.05,300+Math.random()*300);return;case"horn":n("sawtooth",180,176,.8,.03,.08);return;case"hum":n("sine",60,60,2.5,.03,.4);return;case"chime":n("sine",1318.5,1316,1.2,.035,.005);return;case"owl":n("sine",420,380,.5,.04,.05),setTimeout(()=>n("sine",400,360,.6,.035,.05),420);return;case"rumble":o(90,1.2,2.5,.09,60,"lowpass");return;case"drip":n("sine",1200,600,.12,.04,.003);return;case"market":for(let a=0;a<4;a++)setTimeout(()=>o(600+Math.random()*1200,2,.12,.02),a*120);return}}}const cb=i=>1-Math.pow(1-i,3),Ln=i=>ub(.4,0,.2,1,i),uu=i=>1+(1.70158+1)*Math.pow(i-1,3)+1.70158*Math.pow(i-1,2),it=i=>Math.sin(Math.PI*Math.min(1,Math.max(0,i)));function ub(i,e,t,s,r){const n=3*i,o=3*(t-i)-n,a=1-n-o,l=3*e,h=3*(s-e)-l,c=1-l-h,u=g=>((a*g+o)*g+n)*g,d=g=>((c*g+h)*g+l)*g,f=g=>(3*a*g+2*o)*g+n;let p=r;for(let g=0;g<6;g++){const m=f(p);if(Math.abs(m)<1e-6)break;p-=(u(p)-r)/m}return d(Math.min(1,Math.max(0,p)))}const db=64,Uo=32,K=(i,e)=>({x:(i-e)*db/2,y:(i+e)*Uo/2}),F=(i,e)=>({x:i.x,y:i.y-e}),ss=(i,e,t)=>i+(e-i)*t,Be=(i,e,t)=>({x:ss(i.x,e.x,t),y:ss(i.y,e.y,t)}),fb=(i,e,t)=>i<e?e:i>t?t:i,Ue=(i,e,t)=>fb((i-e)/(t-e),0,1),du=(i,e,t=1)=>i+e+t;function De(i,e,t,s=0){return[K(i,e),K(i+t,e),K(i+t,e+t),K(i,e+t)].map(r=>F(r,s))}const X=i=>i.flatMap(e=>[e.x,e.y]);class pb{constructor(e,t){this.stage=e,this.reducedMotion=t}cx=0;cy=0;zoom=1;tx=0;ty=0;tz=1;punch=0;shakeT=0;drift=0;t=0;fit(e,t,s,r,n=1.08){this.tz=Math.min(s/(e*n),r/(t*n))}follow(e,t,s=1){this.tx=ss(this.tx,e,s),this.ty=ss(this.ty,t,s)}setZoomFactor(e){this.tz=e}pushIn(e=.08){this.reducedMotion||(this.punch=Math.max(this.punch,e))}shake(e=220){this.reducedMotion||(this.shakeT=e/1e3)}setDrift(e){this.drift=this.reducedMotion?0:e?1:0}snap(){this.cx=this.tx,this.cy=this.ty,this.zoom=this.tz}update(e,t,s){const r=Number.isFinite(e)?Math.max(0,Math.min(.05,e/1e3)):0;this.t+=r;const n=1-Math.pow(.012,r),o=1-Math.pow(.05,r);this.cx+=(this.tx-this.cx)*n,this.cy+=(this.ty-this.cy)*n,this.punch=Math.max(0,this.punch-r*.12),this.zoom+=(this.tz*(1+cb(this.punch/.08)*this.punch)-this.zoom)*o;let a=0,l=0;if(this.shakeT>0){this.shakeT-=r;const h=this.shakeT*18;a=Math.sin(this.t*60)*h,l=Math.cos(this.t*47)*h}this.drift&&(a+=Math.sin(this.t*.7)*2.2,l+=Math.cos(this.t*.5)*1.6),this.stage.scale.set(this.zoom),this.stage.position.set(t/2-(this.cx+a)*this.zoom,s/2-(this.cy+l)*this.zoom)}toScreen(e,t){return{x:this.stage.position.x+e*this.zoom,y:this.stage.position.y+t*this.zoom}}get scale(){return this.zoom}}const mb={roof:"pitched",eave:.14,furniture:"chimney",stripes:!1},gb={roof:"flat",eave:.05,furniture:"vent",stripes:!1},_b={roof:"capsule",eave:0,furniture:"dish",stripes:!1},Un={island:mb,orbit:_b,metropolis:gb,harbour:{roof:"gable",eave:.16,furniture:"chimney",stripes:!1},observatory:{roof:"dome",eave:.04,furniture:"dish",stripes:!1},greenhouse:{roof:"gable",eave:.1,furniture:"vent",stripes:!1},workshop:{roof:"gable",eave:.12,furniture:"chimney",stripes:!1},arcade:{roof:"flat",eave:.08,furniture:"mast",stripes:!0},kingdom:{roof:"pitched",eave:.1,furniture:"finial",stripes:!1},outpost:{roof:"flat",eave:.12,furniture:"vent",stripes:!1},snowfield:{roof:"pitched",eave:.2,furniture:"chimney",stripes:!1},canopy:{roof:"pitched",eave:.22,furniture:"none",stripes:!1},lagoon:{roof:"tent",eave:.18,furniture:"none",stripes:!0},volcano:{roof:"flat",eave:.06,furniture:"vent",stripes:!1},cloudtop:{roof:"dome",eave:.06,furniture:"finial",stripes:!1},reef:{roof:"dome",eave:.02,furniture:"none",stripes:!1},bazaar:{roof:"tent",eave:.2,furniture:"none",stripes:!0},monastery:{roof:"onion",eave:.08,furniture:"finial",stripes:!1},moonbase:{roof:"capsule",eave:0,furniture:"dish",stripes:!1},lanterns:{roof:"tiered",eave:.26,furniture:"lantern",stripes:!1}};class Ig{constructor(e,t){this.world=e,this.theme=t,this.container.addChild(this.ripples,this.terrain,this.paths,this.labels,this.shadows,this.clouds,this.objects),this.objects.sortableChildren=!0,this.shadows.alpha=.9,this.drawTerrain(),this.drawPaths(),this.drawLabels();for(const s of e.places)this.addPlace(s);this.placeProps()}container=new _e;terrain=new Pe;ripples=new Pe;paths=new Pe;labels=new _e;shadows=new Pe;clouds=new Pe;objects=new _e;drawn=new Map;props=[];time=0;gradients=new Map;vGrad(e,t,s,r){const n=qi(s),o=qi(r),a=`v${e}|${t}|${n}|${o}`;let l=this.gradients.get(a);return l||(l=xb(e,t,n,o),this.gradients.set(a,l)),l}hGrad(e,t,s,r){const n=qi(s),o=qi(r),a=`h${e}|${t}|${n}|${o}`;let l=this.gradients.get(a);return l||(l=bb(e,t,n,o),this.gradients.set(a,l)),l}destroy(){for(const e of this.gradients.values())e.destroy();this.gradients.clear(),this.container.destroy({children:!0})}positionOf(e){const t=this.drawn.get(e);if(!t)return null;const s=t.place,r=s.gx+s.footprint/2,n=s.gy+s.footprint/2,o=K(r,n);return{ground:o,top:F(o,this.heightPx(t)+10),place:s}}standingSpot(e){const t=this.drawn.get(e);if(!t)return K(0,0);const s=t.place;return K(s.gx+s.footprint/2,s.gy+s.footprint+.55)}setGlow(e,t){const s=this.drawn.get(e);s&&s.glow!==t&&(s.glow=t,s.dirty=!0)}setGrowth(e,t){const s=this.drawn.get(e);s&&s.extraH!==t&&(s.extraH=t,s.dirty=!0)}setScaffold(e,t){const s=this.drawn.get(e);s&&s.scaffold!==t&&(s.scaffold=t,s.dirty=!0)}setLamp(e,t){const s=this.drawn.get(e);s&&s.lamp!==t&&(s.lamp=t,s.dirty=!0)}lampOf(e){return this.drawn.get(e)?.lamp??"idle"}has(e){return this.drawn.has(e)}addPlace(e){if(this.drawn.has(e.id))return;const t=new Pe;t.zIndex=du(e.gx,e.gy,e.footprint);const s=Math.max(0,this.world.districts.findIndex(u=>u.id===e.district)),r=e.kind==="beacon"?this.theme.beacon:e.kind==="archive"?this.theme.archive:e.kind==="forge"?this.theme.forge:this.theme.palettes[s%this.theme.palettes.length],n=e.kind==="building"?Oo(e.path):0,o=e.kind==="building"?(n%5-2)*.05:0,a=e.kind==="building"&&n%3===0?this.theme.palettes[(s+1+n%2)%this.theme.palettes.length]:r,l=u=>o>=0?J(u,16777215,o):J(u,0,-o),h={top:l(r.top),left:l(r.left),right:l(r.right),roof:a.roof,roofD:a.roofD,win:r.win},c={place:e,g:t,palette:h,extraH:0,glow:0,lamp:"idle",scaffold:0,dirty:!0};this.drawn.set(e.id,c),this.objects.addChild(t),this.redraw(c)}update(e){this.time+=e/1e3,this.drawRipples(),this.drawCloudShadows();for(const t of this.props)t.canopy&&(t.canopy.x=Math.sin(this.time*1.4+t.phase)*1.2);for(const t of this.drawn.values())(t.glow>0||t.lamp==="scan"||t.lamp==="fail"||t.lamp==="pass"||t.place.kind==="dock"||t.place.kind==="forge")&&(t.dirty=!0),t.dirty&&this.redraw(t)}heightPx(e){const t=e.place;return(t.kind==="beacon"?70:t.kind==="forge"?34:t.kind==="dock"?4:t.kind==="archive"?30:18+t.height*8)+e.extraH}redraw(e){const{g:t,place:s,palette:r}=e;t.clear(),e.dirty=!1;const n=this.heightPx(e),o=s.footprint,a=De(s.gx+.12,s.gy+.12,o);if(t.poly(X(a)).fill({color:this.shadowInk,alpha:.22}),s.kind!=="dock"&&this.castShadow(t,s,n),s.kind==="dock")return this.drawDock(t,s);if(s.kind==="beacon")return this.drawBeacon(e,n);const l=this.box(t,s.gx,s.gy,o,n,s.kind==="forge"?r.roof:r.top,r.left,r.right),h=e.glow>0?.6+.4*Math.sin(this.time*10):0,c=e.glow>0?J(r.win,16771496,.5+.5*h):r.win;if(s.kind!=="archive"&&s.kind!=="forge"){const u=Math.max(1,Math.round(n/28)),d=o>=3?3:2;this.windows(t,l[3],l[2],n,u,d,c,e.glow>0?1:.9),this.windows(t,l[2],l[1],n,u,d,c,e.glow>0?1:.8);const f=Be(l[3],l[2],.3);t.poly([f.x-3,f.y-1,f.x+3,f.y+1,f.x+3,f.y-9,f.x-3,f.y-11]).fill({color:r.roofD,alpha:.9})}if(s.kind==="building"&&o<=2&&this.roof(t,s,n,r),s.kind==="building"&&o>=3&&Un[this.theme.id].roof!=="capsule"&&Un[this.theme.id].roof!=="dome"){const u=l.map(p=>F(p,n));t.poly(X([u[3],u[2],F(u[2],4),F(u[3],4)])).fill(r.roofD),t.poly(X([u[2],u[1],F(u[1],4),F(u[2],4)])).fill(J(r.roofD,0,.2)),t.poly(X(u.map(p=>F(p,4)))).fill(r.roof);const d=De(s.gx+.8,s.gy+.8,o-1.6,n+4);t.poly(X([d[3],d[2],F(d[2],10),F(d[3],10)])).fill(r.left),t.poly(X([d[2],d[1],F(d[1],10),F(d[2],10)])).fill(r.right),t.poly(X(d.map(p=>F(p,10)))).fill(r.top);const f=F(K(s.gx+o/2,s.gy+o/2),n+14);t.moveTo(f.x,f.y).lineTo(f.x,f.y-12).stroke({width:1.6,color:r.roofD}),t.circle(f.x,f.y-13-14,2.2).fill(e.glow>0?16766571:r.roof)}if(s.kind==="archive"){for(let u=1;u<6;u++){const d=Be(l[3],l[2],u/6);t.moveTo(d.x,d.y-3).lineTo(d.x,d.y-n+5).stroke({width:1.3,color:16777215,alpha:.6})}for(let u=1;u<5;u++){const d=Be(l[2],l[1],u/5);t.moveTo(d.x,d.y-3).lineTo(d.x,d.y-n+5).stroke({width:1.3,color:16777215,alpha:.45})}this.pyramid(t,l.map(u=>F(u,n)),F(K(s.gx+o/2,s.gy+o/2),n+10),r.roof,r.roofD)}if(s.kind==="forge"){const u=this.theme.forge.ember,d=Be(l[3],l[2],.5);t.poly([d.x-7,d.y-2,d.x+7,d.y+2,d.x+7,d.y-18,d.x-7,d.y-22]).fill({color:u,alpha:.85}),this.windows(t,l[2],l[1],n,2,2,u,.9),this.pyramid(t,l.map(g=>F(g,n)),F(K(s.gx+o/2,s.gy+o/2),n+16),r.roof,r.roofD);const f=F(K(s.gx+o*.75,s.gy+o*.3),n+6);t.rect(f.x-4,f.y-16,8,16).fill(r.roofD);for(let g=0;g<3;g++){const m=(this.time*.35+g/3)%1;t.circle(f.x+Math.sin(m*6+g)*4,f.y-18-m*26,3+m*6).fill({color:16777215,alpha:.22*(1-m)})}const p=.5+.5*Math.sin(this.time*3);t.circle(d.x,d.y-8,12+p*4).fill({color:u,alpha:.12+.08*p})}e.glow>0&&this.outline(t,l,n,16762970,.4+.4*h),e.scaffold>0&&this.scaffold(t,s,n,e.scaffold)}roof(e,t,s,r){const n=Un[this.theme.id],o=t.footprint,a=n.eave,l=Oo(t.path),h=De(t.gx-a,t.gy-a,o+a*2,s),c=K(t.gx+o/2,t.gy+o/2),u=J(r.roofD,this.shadowInk,.35);switch(a>0&&(e.poly(X([h[3],h[2],F(h[2],-3),F(h[3],-3)])).fill({color:u,alpha:.9}),e.poly(X([h[2],h[1],F(h[1],-3),F(h[2],-3)])).fill({color:J(u,0,.2),alpha:.9})),n.roof){case"pitched":{this.pyramid(e,h,F(c,s+12+o*9),r.roof,r.roofD);break}case"gable":{const f=11+o*7,p=F(Be(h[0],h[3],.5),s+f),g=F(Be(h[1],h[2],.5),s+f);e.poly(X([h[3],h[2],g,p])).fill(this.vGrad(J(r.roof,16777215,.1),r.roof,p.y,h[3].y)),e.poly(X([h[0],h[1],g,p])).fill(J(r.roofD,this.shadowInk,.2)),e.poly(X([h[2],h[1],g])).fill(J(r.right,this.shadowInk,.1)),e.poly(X([h[3],h[0],p])).fill(r.left),e.moveTo(p.x,p.y).lineTo(g.x,g.y).stroke({width:1.4,color:16777215,alpha:.4,cap:"round"});break}case"flat":{const f=h.map(g=>F(g,3));e.poly(X([h[3],h[2],f[2],f[3]])).fill(r.roofD),e.poly(X([h[2],h[1],f[1],f[2]])).fill(J(r.roofD,0,.2)),e.poly(X(f)).fill(this.hGrad(J(r.roof,16777215,.08),r.roof,f[3].x,f[1].x));const p=De(t.gx+.25+l%3*.1,t.gy+.3,.4,s+3);e.poly(X([p[3],p[2],F(p[2],6),F(p[3],6)])).fill(r.left),e.poly(X([p[2],p[1],F(p[1],6),F(p[2],6)])).fill(r.right),e.poly(X(p.map(g=>F(g,6)))).fill(r.top);break}case"dome":{const f=o*32*.78,p=c.y-s+2;e.ellipse(c.x,p,f,f*.62).fill(this.vGrad(J(r.roof,16777215,.22),J(r.roofD,this.shadowInk,.15),p-f*.62,p+f*.3)),e.rect(c.x-f,p,f*2,f*.62).fill({color:0,alpha:0}),e.ellipse(c.x-f*.3,p-f*.28,f*.28,f*.14).fill({color:16777215,alpha:.32});break}case"onion":{const f=o*16,p=c.y-s;e.moveTo(c.x-f,p).quadraticCurveTo(c.x-f*1.15,p-f*1.1,c.x,p-f*2.2).quadraticCurveTo(c.x+f*1.15,p-f*1.1,c.x+f,p).fill(this.vGrad(J(r.roof,16777215,.2),r.roofD,p-f*2.2,p)),e.moveTo(c.x-f*.4,p-f*.3).quadraticCurveTo(c.x-f*.5,p-f*1.2,c.x-f*.05,p-f*1.9).stroke({width:1.6,color:16777215,alpha:.35,cap:"round"});break}case"tiered":{for(let f=0;f<2;f++){const p=s+f*14,g=a*(1-f*.45),m=De(t.gx-g,t.gy-g,o+g*2,p);e.poly(X([m[3],m[2],F(m[2],-2),F(m[3],-2)])).fill(u);const _=F(c,p+9+o*3);e.poly(X([F(m[3],3),F(m[2],3),_])).fill(r.roof),e.poly(X([F(m[2],3),F(m[1],3),_])).fill(r.roofD),e.poly(X([F(m[3],3),F(m[0],3),_])).fill(J(r.roof,16777215,.1));for(const y of[m[1],m[2],m[3]])e.moveTo(y.x,y.y+1).quadraticCurveTo(y.x+(y.x<c.x?-4:4),y.y-1,y.x+(y.x<c.x?-5:5),y.y-6).stroke({width:2,color:r.roofD,cap:"round"})}break}case"tent":{const f=F(c,s+16+o*8);this.pyramid(e,h,f,r.roof,r.roofD);for(let p=0;p<o*3;p++){const g=Be(h[3],h[2],p/(o*3)),m=Be(h[3],h[2],(p+1)/(o*3));e.moveTo(g.x,g.y).quadraticCurveTo((g.x+m.x)/2,(g.y+m.y)/2+4,m.x,m.y).fill(r.roofD)}e.moveTo(f.x,f.y).lineTo(f.x,f.y-8).stroke({width:1.5,color:r.roofD}),e.poly([f.x,f.y-8,f.x+7,f.y-6,f.x,f.y-4]).fill(r.win);break}case"capsule":{const f=o*32*.7,p=c.y-s+1;e.ellipse(c.x,p,f*1.02,f*.5).fill(this.vGrad(J(r.top,16777215,.25),r.top,p-f*.5,p+f*.1)),e.ellipse(c.x-f*.3,p-f*.22,f*.3,f*.1).fill({color:16777215,alpha:.4}),e.ellipse(c.x,p,f*1.02,f*.5).stroke({width:1.2,color:J(r.roofD,16777215,.1),alpha:.6});break}}const d=F(K(t.gx+o*.72,t.gy+o*.3),s+(n.roof==="flat"?3:n.roof==="pitched"||n.roof==="gable"?8:0));switch(n.furniture){case"chimney":l%2===0&&(e.rect(d.x-3,d.y-12,6,12).fill(r.roofD),e.rect(d.x-4,d.y-13,8,3).fill(J(r.roofD,0,.2)));break;case"vent":e.rect(d.x-4,d.y-5,8,5).fill(J(r.left,this.shadowInk,.2)),e.ellipse(d.x,d.y-5,4,1.6).fill(r.top);break;case"mast":e.moveTo(d.x,d.y).lineTo(d.x,d.y-16).stroke({width:1.4,color:r.roofD}),e.circle(d.x,d.y-17,2).fill(r.win);break;case"finial":{const f=F(c,s+12+o*9+(n.roof==="onion"?o*16*2.2-12-o*9:0));e.moveTo(f.x,f.y).lineTo(f.x,f.y-7).stroke({width:1.4,color:16766571}),e.circle(f.x,f.y-8,2).fill(16766571);break}case"lantern":{const f=Be(h[3],h[2],.5);e.moveTo(f.x,f.y).lineTo(f.x,f.y+5).stroke({width:1,color:r.roofD}),e.roundRect(f.x-3,f.y+5,6,8,2).fill(yb(r.win));break}case"dish":e.ellipse(d.x,d.y-2,6,3).stroke({width:1.4,color:16777215,alpha:.7}),e.moveTo(d.x,d.y-2).lineTo(d.x+2,d.y-7).stroke({width:1,color:16777215,alpha:.7});break}if(n.stripes){const f=De(t.gx,t.gy,o);for(let p=0;p<o*4;p+=2){const g=Be(f[3],f[2],p/(o*4)),m=Be(f[3],f[2],(p+1)/(o*4));e.poly([g.x,g.y,m.x,m.y,m.x,m.y-s*.35,g.x,g.y-s*.35]).fill({color:16777215,alpha:.22})}}}box(e,t,s,r,n,o,a,l){const[h,c,u,d]=De(t,s,r),f=this.hazeOf(s+t),p=g=>J(g,this.theme.sky[0],f);return e.poly(X([d,u,F(u,n),F(d,n)])).fill(this.vGrad(p(J(a,16777215,.08)),p(J(a,this.shadowInk,.28)),d.y-n,d.y)),e.poly(X([u,c,F(c,n),F(u,n)])).fill(this.vGrad(p(J(l,this.coolInk,.06)),p(J(l,this.shadowInk,.38)),u.y-n,u.y)),e.poly(X([F(h,n),F(c,n),F(u,n),F(d,n)])).fill(this.hGrad(p(J(o,16777215,.16)),p(o),d.x,c.x)),e.moveTo(d.x,d.y-n).lineTo(h.x,h.y-n).lineTo(c.x,c.y-n).stroke({width:1.3,color:16777215,alpha:.42,cap:"round"}),e.moveTo(d.x,d.y-n).lineTo(d.x,d.y).stroke({width:1.1,color:16777215,alpha:.22}),[h,c,u,d]}hazeOf(e){const t=this.world.bounds,s=t.x+t.y,r=t.x+t.w+t.y+t.h;return .16*(1-Math.max(0,Math.min(1,(e-s)/Math.max(1,r-s))))}get shadowInk(){return J(this.theme.vignette,0,.3)}get coolInk(){return J(this.theme.sky[0],2768746,.5)}castShadow(e,t,s){const r=t.footprint,n=s/36,o=De(t.gx,t.gy,r),a=.55*n,l=.95*n,h=[K(t.gx+a,t.gy+l),K(t.gx+r+a,t.gy+l),K(t.gx+r+a,t.gy+r+l),K(t.gx+a,t.gy+r+l)],c=[o[1],h[1],h[2],h[3],o[3],o[2]];e.poly(X(c)).fill({color:this.shadowInk,alpha:.16});const u=[K(t.gx+a*.6,t.gy+l*.6),K(t.gx+r+a*.6,t.gy+l*.6),K(t.gx+r+a*.6,t.gy+r+l*.6)];e.poly(X([o[1],u[1],u[2],o[3],o[2]])).fill({color:this.shadowInk,alpha:.12})}drawCloudShadows(){const e=this.clouds;if(e.clear(),this.theme.terrain!=="island"&&this.theme.terrain!=="block")return;const t=this.world.bounds,s=K(t.x+t.w/2,t.y+t.h/2),r=(t.w+t.h)*24;for(let n=0;n<3;n++){const o=(this.time*.012+n*.37)%1,a=s.x-r/2+o*r*1.3-r*.15,l=s.y-90+Math.sin(n*2.1)*120;e.ellipse(a,l,150+n*30,56+n*8).fill({color:this.shadowInk,alpha:.075}),e.ellipse(a+90,l+18,110,40).fill({color:this.shadowInk,alpha:.06})}}pyramid(e,t,s,r,n){e.poly(X([t[0],t[1],s])).fill(J(n,this.shadowInk,.25)),e.poly(X([t[3],t[0],s])).fill(J(r,16777215,.12)),e.poly(X([t[3],t[2],s])).fill(this.vGrad(J(r,16777215,.06),r,s.y,t[2].y)),e.poly(X([t[2],t[1],s])).fill(this.vGrad(n,J(n,this.shadowInk,.3),s.y,t[1].y)),e.moveTo(t[3].x,t[3].y).lineTo(s.x,s.y).stroke({width:1.2,color:16777215,alpha:.35,cap:"round"})}windows(e,t,s,r,n,o,a,l){const h=(s.x-t.x)/o*.3,c=(s.y-t.y)/o*.3;for(let u=0;u<n;u++)for(let d=0;d<o;d++){const f=Be(t,s,(d+.5)/o),p=f.y-r*(u+.75)/(n+.5),g=f.x;e.poly([g-h,p-c,g+h,p+c,g+h,p+c-6,g-h,p-c-6]).fill({color:a,alpha:l}),e.poly([g-h,p-c-4.5,g+h,p+c-4.5,g+h,p+c-6,g-h,p-c-6]).fill({color:16777215,alpha:l*.45})}}outline(e,t,s,r,n){const o=t.map(a=>F(a,s));e.moveTo(t[3].x,t[3].y).lineTo(t[2].x,t[2].y).lineTo(t[1].x,t[1].y).lineTo(o[1].x,o[1].y).lineTo(o[0].x,o[0].y).lineTo(o[3].x,o[3].y).closePath().stroke({width:2,color:r,alpha:n,join:"round"}),e.moveTo(t[2].x,t[2].y).lineTo(o[2].x,o[2].y).stroke({width:2,color:r,alpha:n})}scaffold(e,t,s,r){const n=De(t.gx-.12,t.gy-.12,t.footprint+.24);for(const o of[n[1],n[2],n[3]])e.moveTo(o.x,o.y).lineTo(o.x,o.y-s-8).stroke({width:1.1,color:16768150,alpha:r});for(let o=10;o<s+8;o+=11)e.moveTo(n[3].x,n[3].y-o).lineTo(n[2].x,n[2].y-o).lineTo(n[1].x,n[1].y-o).stroke({width:1.1,color:16768150,alpha:r})}drawBeacon(e,t){const{g:s,place:r}=e,n=this.theme.beacon,o=n.lamp[e.lamp],a=this.box(s,r.gx+.2,r.gy+.2,.6,t,n.top,n.left,n.right);for(const[u,d]of[[.2,.33],[.52,.65]])s.poly(X([F(a[3],t*u),F(a[2],t*u),F(a[2],t*d),F(a[3],t*d)])).fill(n.roof),s.poly(X([F(a[2],t*u),F(a[1],t*u),F(a[1],t*d),F(a[2],t*d)])).fill(n.roofD);const l=F(K(r.gx+.5,r.gy+.5),t+6),h=e.lamp==="fail"?.55+.45*Math.sin(this.time*9):e.lamp==="scan"?.8+.2*Math.sin(this.time*20):1,c=e.lamp==="idle"?16:26;if(s.circle(l.x,l.y,c).fill({color:o,alpha:.22*h}),s.circle(l.x,l.y,c*.55).fill({color:o,alpha:.3*h}),e.lamp==="scan"||e.lamp==="pass"){const u=e.lamp==="scan"?this.time*5:this.time*1.1,d=e.lamp==="scan"?190:120,f=.2;s.moveTo(l.x,l.y).arc(l.x,l.y,d,u-f,u+f).closePath().fill({color:o,alpha:.18})}this.box(s,r.gx+.28,r.gy+.28,.44,11,2899538,o,J(o,0,.25)),this.pyramid(s,De(r.gx+.2,r.gy+.2,.6,t+11),F(K(r.gx+.5,r.gy+.5),t+22),n.roof,n.roofD)}drawDock(e,t){const s=De(t.gx,t.gy,t.footprint);e.poly(X([s[3],s[2],F(s[2],-5),F(s[3],-5)])).fill(this.theme.dock.post),e.poly(X([s[2],s[1],F(s[1],-5),F(s[2],-5)])).fill(J(this.theme.dock.post,0,.2)),e.poly(X(s)).fill(this.theme.dock.deck);for(let o=1;o<5;o++){const a=Be(s[0],s[3],o/5),l=Be(s[1],s[2],o/5);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:0,alpha:.12})}for(const o of[s[0],s[1],s[2],s[3]])e.rect(o.x-2,o.y-12,4,12).fill(this.theme.dock.post);const r=Be(s[1],s[2],.5),n=Math.sin(this.time*1.6)*1.5;e.ellipse(r.x+22,r.y+6+n,16,6).fill(this.theme.dock.vessel),e.ellipse(r.x+22,r.y+3+n,13,4).fill(J(this.theme.dock.vessel,0,.12)),e.rect(r.x+20,r.y-12+n,3,15).fill(this.theme.dock.post),e.poly([r.x+23,r.y-12+n,r.x+34,r.y-6+n,r.x+23,r.y-2+n]).fill({color:16777215,alpha:.9})}blobPath(e,t,s){const r=this.world.bounds,n=r.x+r.w/2,o=r.y+r.h/2,a=r.w/2+1.2,l=r.h/2+1.2,h=[],c=hi(this.world.seed^1540483477)()*6.28;for(let u=0;u<80;u++){const d=u/80*Math.PI*2,f=1+.07*Math.sin(3*d+c)+.04*Math.sin(5*d+2.1+c)+.025*Math.sin(8*d+1.3),p=K(n+Math.cos(d)*a*f*t,o+Math.sin(d)*l*f*t);h.push(p.x,p.y+s)}return e.poly(h)}drawTerrain(){const e=this.terrain,t=this.theme.ground;if(this.theme.terrain==="island"){this.blobPath(e,1,18).fill(t.edgeDark),this.blobPath(e,1,10).fill(t.edge),this.blobPath(e,1,0).fill(t.sand),this.blobPath(e,.88,-1).fill(t.fill),this.blobPath(e,.6,-2).fill({color:t.fillLight,alpha:.55});const s=this.world.bounds,r=K(s.x+s.w/2,s.y+s.h/2),n=(s.w+s.h)*14;e.circle(r.x-n*.45,r.y-n*.35,n*.9).fill({color:16777215,alpha:.07}),e.circle(r.x+n*.5,r.y+n*.4,n*1.1).fill({color:this.shadowInk,alpha:.08})}else if(this.theme.terrain==="platform"){const s=this.world.bounds,r=De(s.x,s.y,Math.max(s.w,s.h));e.poly(X([r[3],r[2],F(r[2],-14),F(r[3],-14)])).fill(t.edgeDark),e.poly(X([r[2],r[1],F(r[1],-14),F(r[2],-14)])).fill(t.edge),e.poly(X(r)).fill(t.fill),e.poly(X(De(s.x+1,s.y+1,Math.max(s.w,s.h)-2))).fill({color:t.fillLight,alpha:.25}),e.poly(X(r)).stroke({width:2,color:t.sand,alpha:.6})}else{const s=this.world.bounds,r=Math.max(s.w,s.h),n=De(s.x,s.y,r);e.poly(X([n[3],n[2],F(n[2],-10),F(n[3],-10)])).fill(t.edgeDark),e.poly(X([n[2],n[1],F(n[1],-10),F(n[2],-10)])).fill(t.edge),e.poly(X(n)).fill(t.fill);for(let o=1;o<r;o+=2){const a=K(s.x+o,s.y),l=K(s.x+o,s.y+r);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:t.sand,alpha:.12})}for(let o=1;o<r;o+=2){const a=K(s.x,s.y+o),l=K(s.x+r,s.y+o);e.moveTo(a.x,a.y).lineTo(l.x,l.y).stroke({width:1,color:t.sand,alpha:.12})}}}drawRipples(){const e=this.ripples;if(e.clear(),this.theme.terrain!=="island"){const t=hi(this.world.seed);for(let s=0;s<70;s++){const r=(t()-.5)*2600,n=(t()-.5)*1600,o=.5+.5*Math.sin(this.time*(.6+t())+s);e.circle(r,n,.8+t()*1.2).fill({color:this.theme.water.ripple,alpha:this.theme.water.rippleAlpha*o})}return}for(let t=0;t<3;t++){const s=(this.time*.06+t/3)%1;this.blobPath(e,1.04+s*.45,8).stroke({width:1.4,color:this.theme.water.ripple,alpha:this.theme.water.rippleAlpha*.7*(1-s)})}}drawPaths(){const e=this.paths;for(const t of this.world.paths){const s=t.points.map(([r,n])=>K(r+.5,n+.5));e.moveTo(s[0].x,s[0].y);for(const r of s.slice(1))e.lineTo(r.x,r.y);e.stroke({width:7,color:this.theme.pathColor,alpha:.9,cap:"round",join:"round"})}}drawLabels(){const e=new Is({fontFamily:"Fredoka, Trebuchet MS, sans-serif",fontSize:22,fontWeight:"700",fill:16777215,letterSpacing:2,stroke:{color:this.theme.vignette,width:4,join:"round"}});for(const t of this.world.districts){const s=new Ep({text:t.label,style:e});s.anchor.set(.5,.5);const r=K(t.bounds.x+t.bounds.w/2+.5,t.bounds.y+t.bounds.h+.55);s.position.set(r.x,r.y),s.alpha=.55,s.skew.set(-.35,.17),this.labels.addChild(s)}}placeProps(){const e=hi(this.world.seed^2654435769),t=new Set;for(const a of this.world.places)for(let l=0;l<a.footprint;l++)for(let h=0;h<a.footprint;h++)t.add(`${a.gx+l},${a.gy+h}`);const s=this.world.bounds;let r=0,n=0;const o=Math.min(18,5+Math.floor(this.world.places.length/5));for(;n<o&&r++<700;){const a=Math.floor(s.x+1+e()*(s.w-2)),l=Math.floor(s.y+1+e()*(s.h-2));if(t.has(`${a},${l}`)||this.world.districts.some(_=>a>=_.bounds.x&&a<_.bounds.x+_.bounds.w&&l>=_.bounds.y&&l<_.bounds.y+_.bounds.h))continue;t.add(`${a},${l}`);const h=new _e;h.zIndex=du(a,l);const c=new Pe;h.addChild(c);const u=K(a+.5,l+.5),d=(.85+e()*.4)*1.25,[f,p,g]=this.theme.propColors;let m;this.theme.prop==="tree"?(c.ellipse(u.x+3,u.y+1,9*d,4*d).fill({color:666138,alpha:.18}),c.rect(u.x-1.5,u.y-10*d,3,10*d).fill(g),m=new Pe,m.ellipse(u.x+1*d,u.y-13*d,9.5*d,7.5*d).fill(J(f,this.shadowInk,.25)),m.ellipse(u.x,u.y-16*d,9*d,8.5*d).fill(f),m.ellipse(u.x-4*d,u.y-19*d,6.5*d,6*d).fill(p),m.ellipse(u.x+4.5*d,u.y-20*d,5.5*d,5*d).fill(p),m.ellipse(u.x-3.5*d,u.y-22*d,3.2*d,2.4*d).fill({color:16777215,alpha:.32}),h.addChild(m)):this.theme.prop==="antenna"?(c.rect(u.x-1,u.y-18*d,2,18*d).fill(f),c.circle(u.x,u.y-20*d,2.5).fill(p),c.ellipse(u.x,u.y,5*d,2.5*d).fill(g)):(c.rect(u.x-1,u.y-16*d,2,16*d).fill(g),c.circle(u.x,u.y-17*d,3).fill(f),c.circle(u.x,u.y-17*d,7).fill({color:p,alpha:.18})),this.objects.addChild(h),this.props.push({g:c,gx:a,gy:l,phase:e()*6.28,...m?{canopy:m}:{}}),n++}}}const yb=i=>J(i,16777215,.25);function xb(i,e,t,s){return new je({start:{x:0,y:t},end:{x:0,y:s},colorStops:[{offset:0,color:i},{offset:1,color:e}],textureSpace:"global"})}function bb(i,e,t,s){return new je({start:{x:t,y:0},end:{x:s,y:0},colorStops:[{offset:0,color:i},{offset:1,color:e}],textureSpace:"global"})}const qi=i=>Math.round(i/2)*2;function J(i,e,t){const s=i>>16&255,r=i>>8&255,n=i&255,o=e>>16&255,a=e>>8&255,l=e&255,h=Math.round(s+(o-s)*t),c=Math.round(r+(a-r)*t),u=Math.round(n+(l-n)*t);return h<<16|c<<8|u}class No{constructor(e,t,s){this.id=e,this.theme=t,this.reducedMotion=s,this.container.addChild(this.g)}container=new _e;g=new Pe;t=Math.random()*10;x=0;y=0;scale=1;alpha=1;lift=0;panic=0;peek=0;update(e){this.t+=e/1e3;const t=this.t,s=this.g,r=this.theme.gremlin,n=this.reducedMotion?0:Math.abs(Math.sin(t*(7+this.panic*5)))*(6+this.panic*3);this.container.position.set(this.x,this.y),this.container.alpha=this.alpha,s.clear(),s.ellipse(0,0,7*this.scale,3*this.scale).fill({color:994600,alpha:.25}),s.position.set(0,0);const o=this.scale,a=9,l=[];for(let u=0;u<=a*2;u++){const d=u/(a*2)*Math.PI*2,f=(u%2?7.2:9.6+Math.sin(t*20+u)*.7)*o;l.push(Math.cos(d)*f,-9*o-n-this.lift+Math.sin(d)*f*.9)}s.poly(l).fill(r.body);const h=-10*o-n-this.lift;s.ellipse(-3*o,h,2.4*o,2.6*o).fill(16777215),s.ellipse(3*o,h,2.4*o,2.6*o).fill(16777215);const c=this.panic?Math.sin(t*9)*.8:.4;s.ellipse(-2.6*o+c,h+.4,1.2*o,1.3*o).fill(r.eye),s.ellipse(3.4*o+c,h+.4,1.2*o,1.3*o).fill(r.eye),s.moveTo(-5.5*o,h-4*o).lineTo(-1.2*o,h-2.4*o).moveTo(5.5*o,h-4*o).lineTo(1.2*o,h-2.4*o).stroke({width:1.3*o,color:r.eye,cap:"round"}),s.moveTo(-2.6*o,h+4.4*o).lineTo(-1.2*o,h+3.4*o).lineTo(.2*o,h+4.4*o).lineTo(1.6*o,h+3.4*o).lineTo(2.9*o,h+4.4*o).stroke({width:1.3*o,color:r.eye,cap:"round"})}}const vb=Object.freeze(Object.defineProperty({__proto__:null,Gremlin:No},Symbol.toStringTag,{value:"Module"}));class wb{constructor(e){this.reducedMotion=e}g=new Pe;parts=[];burst(e,t,s,r,n,o=0){this.reducedMotion&&(s=Math.ceil(s/4));for(let a=0;a<s;a++){const l=Math.random()*Math.PI*2,h=n*(.4+Math.random()*.8);this.parts.push({x:e,y:t,vx:Math.cos(l)*h,vy:Math.sin(l)*h*.6-o*(.5+Math.random()),life:0,max:.7+Math.random()*.8,c:r[a%r.length],r:1.4+Math.random()*2.4})}}clear(){this.parts=[],this.g.clear()}get count(){return this.parts.length}update(e){const t=e/1e3;this.parts=this.parts.filter(s=>(s.life+=t)<s.max),this.g.clear();for(const s of this.parts)s.vy+=140*t,s.x+=s.vx*t,s.y+=s.vy*t,this.g.rect(s.x-s.r/2,s.y-s.r/2,s.r,s.r*1.3).fill({color:s.c,alpha:1-s.life/s.max})}}const Ct=[{id:"pip",name:"Pip",bio:"Curious, quick, a little clumsy. The original.",shape:"round",topper:"antenna",eyes:"wide",body:16751164,bodyLight:16765566,belly:16774620,ear:14712620,cheek:16739930,ink:2759959,size:1},{id:"mo",name:"Mo",bio:"Tall, calm, measures twice.",shape:"tall",topper:"tuft",eyes:"sleepy",body:6269183,bodyLight:11129599,belly:15398143,ear:4161488,cheek:16748448,ink:1385274,size:1.1},{id:"juno",name:"Juno",bio:"Bright, chatty, finds the bug by talking to it.",shape:"bean",topper:"ears",eyes:"wide",body:8380554,bodyLight:13172672,belly:15990768,ear:5223526,cheek:16756896,ink:1456671,size:.95},{id:"rook",name:"Rook",bio:"Boxy, deliberate, never guesses.",shape:"boxy",topper:"crest",eyes:"visor",body:10134712,bodyLight:14015462,belly:15659510,ear:7239820,cheek:8188927,ink:1778224,size:1.05},{id:"fen",name:"Fen",bio:"Quiet and sharp. Reads everything first.",shape:"teardrop",topper:"leaf",eyes:"dot",body:11967743,bodyLight:14734079,belly:16183551,ear:9401062,cheek:16754392,ink:2759498,size:.9},{id:"sol",name:"Sol",bio:"Warm, loud, celebrates everything.",shape:"round",topper:"halo",eyes:"wide",body:16765503,bodyLight:16773288,belly:16776166,ear:14723072,cheek:16747610,ink:3811845,size:1.08},{id:"ivy",name:"Ivy",bio:"Patient gardener of code. Hates loose ends.",shape:"bean",topper:"leaf",eyes:"sleepy",body:4177818,bodyLight:10481880,belly:15400952,ear:2788464,cheek:16756896,ink:997934,size:1},{id:"bolt",name:"Bolt",bio:"Fast. Sometimes too fast.",shape:"teardrop",topper:"crest",eyes:"dot",body:16734878,bodyLight:16756944,belly:16773366,ear:13645178,cheek:16765566,ink:3804962,size:.92},{id:"ash",name:"Ash",bio:"Dry wit, steady hands.",shape:"tall",topper:"ears",eyes:"sleepy",body:8024976,bodyLight:12104396,belly:15657973,ear:5656684,cheek:16758087,ink:1709872,size:1.06},{id:"nimbus",name:"Nimbus",bio:"Soft, cloud-headed, surprisingly precise.",shape:"round",topper:"halo",eyes:"wide",body:15660287,bodyLight:16777215,belly:16777215,ear:13228272,cheek:16756936,ink:2767442,size:1.02},{id:"ember",name:"Ember",bio:"Runs hot. Loves a red lighthouse.",shape:"boxy",topper:"antenna",eyes:"visor",body:16739133,bodyLight:16756874,belly:16773606,ear:12862506,cheek:16769899,ink:3805704,size:1},{id:"tove",name:"Tove",bio:"Small, brave, follows the map.",shape:"bean",topper:"tuft",eyes:"dot",body:13214827,bodyLight:15653293,belly:16775142,ear:10254916,cheek:16747610,ink:3811856,size:.85}],Gg=i=>Ct.find(e=>e.id===i),fu=i=>(.2126*(i>>16&255)+.7152*(i>>8&255)+.0722*(i&255))/255,Dg=(i,e)=>Math.abs(fu(i.body)-fu(e))>.22;function Fg(i,e,t){const s=a=>t===void 0||Dg(a,t);let r=Gg(e)??Ct[i%Ct.length];s(r)||(r=Ct.find((a,l)=>l>=i%Ct.length&&s(a))??Ct.find(s)??r);const n=Ct.filter(a=>a.id!==r.id&&s(a)),o=n.length?(i>>>3)%n.length:0;return{lead:r,helpers:[...n.slice(o),...n.slice(0,o)]}}const Tb=Object.freeze(Object.defineProperty({__proto__:null,CAST:Ct,castById:Gg,pickCompany:Fg,readableOn:Dg},Symbol.toStringTag,{value:"Module"}));class zo{constructor(e,t,s=Ct[0]){this.theme=e,this.reducedMotion=t,this.spec=s,this.container.addChild(this.shadow,this.body),this.container.scale.set(1.75*s.size)}container=new _e;shadow=new Pe;body=new Pe;t=0;pose={x:0,y:0,lift:0,sx:1,sy:1,lean:0,face:1,moving:!1,look:"fwd",mood:"curious",hiding:0};shown={x:0,y:0,lift:0,sx:1,sy:1,lean:0,face:1,faceK:1};snapNext=!0;snap(){this.snapNext=!0}get drawn(){return{x:this.shown.x,y:this.shown.y}}setTheme(e){this.theme=e}update(e){this.t+=e/1e3;const t=this.pose,s=this.spec,r=this.t,n=this.shown,o=Math.min(.05,e/1e3);this.snapNext&&(Object.assign(n,{x:t.x,y:t.y,lift:t.lift,sx:t.sx,sy:t.sy,lean:t.lean,face:t.face,faceK:1}),this.snapNext=!1);const a=1-Math.pow(5e-4,o),l=1-Math.pow(.002,o);n.x+=(t.x-n.x)*l,n.y+=(t.y-n.y)*l,n.lift+=(t.lift-n.lift)*a,n.sx+=(t.sx-n.sx)*a,n.sy+=(t.sy-n.sy)*a,n.lean+=(t.lean-n.lean)*a,n.face!==t.face?(n.faceK-=o*9,n.faceK<=0&&(n.face=t.face,n.faceK=.01)):n.faceK=Math.min(1,n.faceK+o*9);const h={...t,x:n.x,y:n.y,lift:n.lift,sx:n.sx*Math.max(.15,n.faceK),sy:n.sy,lean:n.lean,face:n.face};this.container.position.set(h.x,h.y),this.container.zIndex=1e6;const c=1-Math.min(.6,h.lift/90);this.shadow.clear().ellipse(0,0,11*c,5*c).fill({color:0,alpha:.28}),this.shadow.ellipse(0,0,14*c,7*c).fill({color:0,alpha:.1});const u=this.body;u.clear(),u.position.set(0,-h.lift),u.rotation=h.lean,u.scale.set(h.sx,h.sy);const d=h.moving||this.reducedMotion?0:Math.sin(r*2.2)*.012;u.scale.set(h.sx*(1-d),h.sy*(1+d));const f=h.moving?Math.sin(r*11)*3:0;switch(u.ellipse(-5+f,-1.5,4.2,2.6).fill(s.ear),u.ellipse(5-f,-1.5,4.2,2.6).fill(s.ear),s.shape){case"tall":u.ellipse(0,-16,9.5,16.5).fill(s.body),u.ellipse(-1.5,-21,7.5,9).fill({color:s.bodyLight,alpha:.55});break;case"boxy":u.roundRect(-11,-26,22,26,6).fill(s.body),u.roundRect(-9,-24,12,10,4).fill({color:s.bodyLight,alpha:.5});break;case"teardrop":u.moveTo(0,-30).quadraticCurveTo(13,-16,11,-6).quadraticCurveTo(0,2,-11,-6).quadraticCurveTo(-13,-16,0,-30).fill(s.body),u.ellipse(-2,-16,6,7).fill({color:s.bodyLight,alpha:.5});break;case"bean":u.ellipse(0,-12,12.5,11.5).fill(s.body),u.ellipse(-2,-18,8,6).fill({color:s.bodyLight,alpha:.55});break;default:u.ellipse(0,-13.5,11.5,13.5).fill(s.body),u.ellipse(-1.5,-17,9.5,9).fill({color:s.bodyLight,alpha:.55})}const p=s.shape==="tall"?9.5:s.shape==="boxy"?11:s.shape==="bean"?12.5:11.5,g=s.shape==="tall"?-16:s.shape==="boxy"?-13:s.shape==="bean"?-12:-13.5;u.moveTo(-p*.9,g-p*.2).quadraticCurveTo(-p*.75,g-p*.95,p*.1,g-p*1.02).stroke({width:2.2,color:16777215,alpha:.5,cap:"round"}),u.moveTo(p*.95,g+p*.1).quadraticCurveTo(p*.8,g+p*.8,p*.1,g+p*.98).stroke({width:2.4,color:this.theme.sky[0],alpha:.28,cap:"round"}),u.ellipse(h.face*1.2,-7.5,6.5,5.5).fill({color:s.belly,alpha:.92}),u.ellipse(-8+h.face*1.5,-11,2.4,1.5).fill({color:s.cheek,alpha:.45}),u.ellipse(8+h.face*1.5,-11,2.4,1.5).fill({color:s.cheek,alpha:.45});const m=h.moving?Math.sin(r*14)*.25:0,_=s.shape==="tall"?-33:s.shape==="teardrop"?-30:-27;switch(s.topper){case"ears":u.ellipse(-9,_+4+m*6,3.2,5).fill(s.ear),u.ellipse(9,_+4-m*6,3.2,5).fill(s.ear);break;case"tuft":u.moveTo(-3,_+1).quadraticCurveTo(-6,_-9,1,_-12).moveTo(0,_).quadraticCurveTo(4,_-10,8,_-8).stroke({width:2.2,color:s.ear,cap:"round"});break;case"leaf":u.moveTo(0,_).quadraticCurveTo(2+m*10,_-8,8,_-12).quadraticCurveTo(4,_-4,0,_).fill(s.ear),u.moveTo(0,_).lineTo(5,_-7).stroke({width:1,color:s.belly,alpha:.7});break;case"crest":for(const T of[-6,-2,2,6])u.moveTo(T,_+1).lineTo(T*1.4,_-7-Math.abs(T)*.3).stroke({width:2.4,color:s.ear,cap:"round"});break;case"halo":u.ellipse(0,_-7,9,2.6).stroke({width:1.8,color:this.theme.mood[h.mood],alpha:.9});break;case"antenna":u.ellipse(-9,_+4+m*6,3.2,5).fill(s.ear),u.ellipse(9,_+4-m*6,3.2,5).fill(s.ear);break}const y=h.face*1.8,x=-16,b=!this.reducedMotion&&r%3.3<.13&&h.mood!=="happy";for(const T of[-1,1]){const k=y+T*4.6;if(h.mood==="happy"){u.beginPath(),u.arc(k,x+1.5,2.8,Math.PI*1.1,Math.PI*1.9).stroke({width:1.6,color:s.ink,cap:"round"});continue}if(b){u.moveTo(k-2.6,x).lineTo(k+2.6,x).stroke({width:1.6,color:s.ink,cap:"round"});continue}if(s.eyes==="visor"){T<0&&(u.roundRect(y-8.5,x-3,17,6,3).fill(16777215),u.roundRect(y-7+(h.look==="up"?0:1),x-1.5,5,3,1.5).fill(s.ink),u.roundRect(y+2+(h.look==="up"?0:1),x-1.5,5,3,1.5).fill(s.ink));continue}const E=s.eyes==="dot"?2.6:s.eyes==="sleepy"?2.4:h.mood==="focused"?3:4.3;u.ellipse(k,x,s.eyes==="dot"?2.6:3.4,E).fill(16777215),s.eyes==="sleepy"&&u.moveTo(k-3.4,x-2.2).lineTo(k+3.4,x-2.2).stroke({width:2,color:s.body});const A=!h.moving&&!this.reducedMotion&&r%4.1>3.3?Math.sin((r%4.1-3.3)/.8*Math.PI):0;let M=h.face*1.1+A*1.6,B=(h.look==="up"?-1.6:h.look==="down"?1.4:.3)-A*.8;h.mood==="lost"&&(M=Math.sin(r*3)*1.4,B=-1.2),u.ellipse(k+M,x+B,1.9,h.mood==="focused"?1.8:2.2).fill(s.ink),u.ellipse(k+M+.7,x+B-.8,.6,.6).fill(16777215),h.mood==="lost"&&u.moveTo(k-3,x-5.6-(T>0?0:1.3)).lineTo(k+3,x-5.6-(T>0?1.3:0)).stroke({width:1.6,color:s.ink,cap:"round"}),h.mood==="focused"&&u.moveTo(k-3.2,x-3.7-(T>0?1:0)).lineTo(k+3.2,x-3.7-(T>0?0:1)).stroke({width:1.6,color:s.ink,cap:"round"}),h.mood==="uneasy"&&u.moveTo(k-3,x-5).lineTo(k+3,x-6+(T>0?1.5:-1.5)).stroke({width:1.4,color:s.ink,cap:"round"})}u.beginPath(),h.mood==="happy"?u.arc(y,-10.5,3.2,0,Math.PI).fill(8007202):h.mood==="lost"||h.mood==="uneasy"?u.arc(y,-8.4,2.2,Math.PI*1.15,Math.PI*1.85).stroke({width:1.6,color:s.ink,cap:"round"}):u.arc(y,-11.2,1.9,Math.PI*.15,Math.PI*.85).stroke({width:1.6,color:s.ink,cap:"round"});const v=(this.reducedMotion?0:Math.sin(r*5)*2)-h.lean*10,w=this.theme.mood[h.mood];if(s.topper==="antenna"?(u.moveTo(0,_+.5).quadraticCurveTo(v*.5,_-5,v+1.5,_-9).stroke({width:1.4,color:s.ear}),u.circle(v+1.5,_-10,9).fill({color:w,alpha:.28}),u.circle(v+1.5,_-10,5.5).fill({color:w,alpha:.35}),u.circle(v+1.5,_-10,2.8).fill(w)):s.topper!=="halo"&&(u.circle(0,_-2,7).fill({color:w,alpha:.22}),u.circle(0,_-2,2.2).fill({color:w,alpha:.9})),h.hiding>0){const T=it(r*.5%1)*h.hiding;u.rotation=h.lean+T*.06}}}const Sb=Object.freeze(Object.defineProperty({__proto__:null,Pip:zo},Symbol.toStringTag,{value:"Module"})),wt=[0,2,4,7,9],Cb=[0,3,5,7,10],pu=[0,2,4,6,7,9,11],mu=[0,2,3,5,7,9,10],Mb=[0,2,4,5,7,9,10],kb=[0,2,4,6,8,10],Eb=[0,1,4,5,7,8,11],Nn=[0,2,3,5,7,8,10],Pb={island:{scale:wt,root:261.6,wave:"sine",gain:.05,every:16,len:[.45,.9]},orbit:{scale:pu,root:220,wave:"triangle",gain:.035,every:20,len:[.8,1.6]},metropolis:{scale:mu,root:196,wave:"triangle",gain:.04,every:18,len:[.3,.7]},harbour:{scale:Mb,root:233,wave:"sine",gain:.045,every:17,len:[.5,1.1]},observatory:{scale:kb,root:329.6,wave:"sine",gain:.035,every:22,len:[.9,1.8]},greenhouse:{scale:wt,root:293.7,wave:"triangle",gain:.045,every:15,len:[.35,.8]},workshop:{scale:wt,root:220,wave:"triangle",gain:.045,every:16,len:[.3,.6]},arcade:{scale:Cb,root:261.6,wave:"square",gain:.025,every:12,len:[.15,.35]},kingdom:{scale:mu,root:174.6,wave:"triangle",gain:.045,every:19,len:[.6,1.2]},outpost:{scale:Nn,root:196,wave:"sine",gain:.04,every:21,len:[.8,1.6]},snowfield:{scale:wt,root:392,wave:"sine",gain:.04,every:18,len:[.7,1.5]},canopy:{scale:wt,root:246.9,wave:"triangle",gain:.045,every:14,len:[.3,.7]},lagoon:{scale:wt,root:329.6,wave:"sine",gain:.045,every:15,len:[.4,.9]},volcano:{scale:Nn,root:146.8,wave:"sawtooth",gain:.03,every:20,len:[.9,1.8]},cloudtop:{scale:pu,root:392,wave:"sine",gain:.04,every:17,len:[.8,1.6]},reef:{scale:wt,root:174.6,wave:"sine",gain:.045,every:14,len:[.9,2]},bazaar:{scale:Eb,root:220,wave:"triangle",gain:.045,every:13,len:[.25,.6]},monastery:{scale:wt,root:196,wave:"sine",gain:.05,every:24,len:[1.2,2.4]},moonbase:{scale:Nn,root:164.8,wave:"sine",gain:.035,every:23,len:[1,2]},lanterns:{scale:wt,root:523.3,wave:"sine",gain:.04,every:14,len:[.3,.7]}},Xe={wave:"triangle",pitch:1,decay:1,tone:3200,surface:"grass"},zn={wave:"square",pitch:1.18,decay:.8,tone:2600,surface:"metal"},gu={wave:"sawtooth",pitch:.95,decay:1.1,tone:2200,surface:"stone"},Ab={island:"pluck",orbit:"blip",metropolis:"synth",harbour:"wood",observatory:"glass",greenhouse:"marimba",workshop:"wood",arcade:"blip",kingdom:"bell",outpost:"pluck",snowfield:"glass",canopy:"marimba",lagoon:"drop",volcano:"synth",cloudtop:"glass",reef:"drop",bazaar:"pluck",monastery:"bell",moonbase:"blip",lanterns:"bell"},Rb={island:"relax",orbit:"focus",metropolis:"focus",harbour:"relax",observatory:"focus",greenhouse:"relax",workshop:"fun",arcade:"fun",kingdom:"fun",outpost:"focus",snowfield:"relax",canopy:"fun",lagoon:"relax",volcano:"focus",cloudtop:"relax",reef:"relax",bazaar:"fun",monastery:"focus",moonbase:"focus",lanterns:"fun"},Bb={island:{voice:Xe,ambience:{washes:[{hz:520,q:.6,gain:.09,lfoHz:.11,depth:.6},{hz:240,q:.9,gain:.05,lfoHz:.07,depth:.8}],extras:["gull","cricket"],every:9}},orbit:{voice:zn,ambience:{washes:[{hz:900,q:2,gain:.015,lfoHz:.05,depth:.9}],pad:{chord:[55,110,164.8],gain:.05,wave:"sine"},extras:["hum","chime"],every:11}},metropolis:{voice:gu,ambience:{washes:[{hz:380,q:.5,gain:.07,lfoHz:.2,depth:.5}],pad:{chord:[65.4,98],gain:.03,wave:"triangle"},extras:["horn","hum"],every:10}},harbour:{voice:{...Xe,surface:"wood",decay:1.3},ambience:{washes:[{hz:420,q:.6,gain:.1,lfoHz:.09,depth:.7}],extras:["gull","bell","horn"],every:8}},observatory:{voice:{...zn,wave:"sine",pitch:1.3,decay:1.6,tone:4e3,surface:"stone"},ambience:{washes:[{hz:300,q:.8,gain:.04,lfoHz:.04,depth:.9}],pad:{chord:[49,98,146.8],gain:.04,wave:"sine"},extras:["wind","chime"],every:12}},greenhouse:{voice:{...Xe,pitch:1.1,decay:1.2},ambience:{washes:[{hz:600,q:.6,gain:.05,lfoHz:.1,depth:.5}],extras:["cricket","drip","bell"],every:7}},workshop:{voice:{...Xe,wave:"triangle",pitch:.9,decay:.8,tone:2800,surface:"wood"},ambience:{washes:[{hz:500,q:.6,gain:.05,lfoHz:.12,depth:.5}],extras:["cricket","bell"],every:9}},arcade:{voice:{wave:"square",pitch:1.35,decay:.6,tone:3600,surface:"neon"},ambience:{washes:[{hz:300,q:.5,gain:.05,lfoHz:.25,depth:.4}],pad:{chord:[65.4,82.4,98],gain:.03,wave:"square"},extras:["chime","horn"],every:6}},kingdom:{voice:{...Xe,wave:"triangle",pitch:.85,decay:1.5,tone:2400,surface:"stone"},ambience:{washes:[{hz:450,q:.6,gain:.07,lfoHz:.1,depth:.6}],extras:["bell","wind","owl"],every:10}},outpost:{voice:{...Xe,pitch:.92,decay:1.4,tone:2600,surface:"sand"},ambience:{washes:[{hz:700,q:.4,gain:.08,lfoHz:.06,depth:.9}],extras:["wind","hum"],every:9}},snowfield:{voice:{...Xe,wave:"sine",pitch:1.15,decay:1.7,tone:3400,surface:"snow"},ambience:{washes:[{hz:800,q:.4,gain:.05,lfoHz:.05,depth:.9}],extras:["wind","chime","owl"],every:11}},canopy:{voice:{...Xe,pitch:1.05,decay:1.2,tone:3e3,surface:"wood"},ambience:{washes:[{hz:650,q:.7,gain:.07,lfoHz:.09,depth:.5}],extras:["cricket","owl","drip"],every:6}},lagoon:{voice:{...Xe,wave:"sine",pitch:1.2,decay:1.3,tone:3600,surface:"sand"},ambience:{washes:[{hz:480,q:.6,gain:.1,lfoHz:.1,depth:.7}],extras:["gull","bubble"],every:8}},volcano:{voice:{wave:"sawtooth",pitch:.75,decay:1.6,tone:1600,surface:"stone"},ambience:{washes:[{hz:160,q:1,gain:.1,lfoHz:.08,depth:.8}],pad:{chord:[41.2,61.7],gain:.04,wave:"sawtooth"},extras:["rumble","wind"],every:8}},cloudtop:{voice:{...Xe,wave:"sine",pitch:1.25,decay:1.8,tone:4200,surface:"grass"},ambience:{washes:[{hz:900,q:.4,gain:.05,lfoHz:.04,depth:.9}],pad:{chord:[130.8,196,261.6],gain:.025,wave:"sine"},extras:["wind","chime"],every:12}},reef:{voice:{wave:"sine",pitch:.9,decay:1.9,tone:1400,surface:"water"},ambience:{washes:[{hz:220,q:1.2,gain:.09,lfoHz:.09,depth:.7}],extras:["bubble","drip"],every:5}},bazaar:{voice:{...Xe,pitch:1.05,decay:.9,tone:3e3,surface:"sand"},ambience:{washes:[{hz:500,q:.5,gain:.06,lfoHz:.3,depth:.4}],extras:["market","bell","chime"],every:6}},monastery:{voice:{...Xe,wave:"sine",pitch:.95,decay:2,tone:2600,surface:"stone"},ambience:{washes:[{hz:420,q:.5,gain:.05,lfoHz:.05,depth:.8}],extras:["bell","wind","owl"],every:12}},moonbase:{voice:{...zn,pitch:1.05,decay:1.2,tone:2200},ambience:{washes:[{hz:240,q:1.5,gain:.03,lfoHz:.03,depth:.9}],pad:{chord:[55,82.4],gain:.04,wave:"sine"},extras:["hum","chime"],every:13}},lanterns:{voice:{...gu,wave:"triangle",pitch:1.1,decay:1.2,tone:3e3,surface:"stone"},ambience:{washes:[{hz:400,q:.5,gain:.05,lfoHz:.2,depth:.5}],extras:["market","chime","bell"],every:6}}},Ho=Object.fromEntries(Object.entries(Bb).map(([i,e])=>[i,{...e,voice:{...e.voice,instrument:Ab[i]},ambience:{...e.ambience,mood:Rb[i]},tune:Pb[i]}])),Ib=i=>i,Gb=new Set(["curtain_up","curtain_down","test_outcome","celebrate","blocked_on_you","unverified_claim","spawn_gremlin","banish"]),Db=[523.25,659.25,783.99,1046.5],Ie=(i,e)=>i+Math.random()*(e-i);class Yi{constructor(e){this.a=e}footstep(e,t){const s=this.a;switch(e){case"stone":s.noise(.04,{filter:"bandpass",freq:Ie(1400,1900),q:2,gain:.05,pan:t}),s.tone(Ie(160,200),.03,{type:"triangle",gain:.03,pan:t});return;case"metal":s.tone(Ie(700,900),.05,{type:"square",gain:.03,lowpass:2e3,pan:t}),s.noise(.03,{filter:"highpass",freq:3e3,gain:.03,pan:t});return;case"sand":s.noise(.09,{filter:"lowpass",freq:Ie(700,1e3),q:.5,gain:.05,pan:t});return;case"snow":s.noise(.08,{filter:"bandpass",freq:Ie(2500,3500),q:.8,gain:.04,pan:t});return;case"wood":s.tone(Ie(220,300),.05,{type:"triangle",gain:.05,slideTo:120,pan:t});return;case"water":s.noise(.08,{filter:"bandpass",freq:Ie(400,700),q:1,gain:.05,sweepTo:1200,pan:t});return;case"neon":s.tone(Ie(900,1200),.035,{type:"square",gain:.025,lowpass:3e3,pan:t});return;default:s.noise(.05,{filter:"bandpass",freq:Ie(900,1300),q:1.2,gain:.05,pan:t});return}}static plays(e,t){return t<=1.01||Gb.has(e)}take={pitch:.92+Math.random()*.18,decay:.85+Math.random()*.4,tone:.8+Math.random()*.5,swap:Math.random()<.3};play(e,t){const s=this.a,r=t.pan??0,n=t.intensity??.5,o=Ho[t.theme.id].voice,a=this.take,l={sine:"triangle",triangle:"sine",square:"sawtooth",sawtooth:"square",custom:"sine"},h={...o,pitch:o.pitch*a.pitch,decay:o.decay*a.decay,tone:o.tone*a.tone,wave:a.swap?l[o.wave]:o.wave},c={tone:(u,d,f={})=>{const p=.97+Math.random()*.06,g=.85+Math.random()*.3,m=u*h.pitch*p,_=d*h.decay*g,y=f.gain??.25,x={...f,lowpass:Math.min(f.lowpass??h.tone,h.tone),...f.slideTo?{slideTo:f.slideTo*h.pitch*p}:{}};switch(Ib(h.instrument)){case"pluck":s.tone(m,_*.6,{...x,type:"triangle",attack:.003,gain:y}),s.tone(m*2,_*.25,{...x,type:"sine",attack:.002,gain:y*.35}),s.noise(.012,{filter:"highpass",freq:3e3,gain:y*.3});return;case"bell":s.tone(m,_*1.8,{...x,type:"sine",attack:.004,gain:y}),s.tone(m*2.76,_*1.1,{...x,type:"sine",attack:.004,gain:y*.3}),s.tone(m*5.4,_*.5,{...x,type:"sine",attack:.004,gain:y*.12});return;case"marimba":s.tone(m,_*.5,{...x,type:"sine",attack:.003,gain:y}),s.tone(m*4,_*.12,{...x,type:"sine",attack:.002,gain:y*.25}),s.noise(.02,{filter:"bandpass",freq:1800,q:2,gain:y*.25});return;case"blip":s.tone(m,_*.35,{...x,type:"square",attack:.002,gain:y*.7}),s.tone(m*1.5,_*.2,{...x,type:"square",attack:.002,gain:y*.2});return;case"glass":s.tone(m,_*2,{...x,type:"sine",attack:.02,gain:y*.9}),s.tone(m*1.005,_*2,{...x,type:"sine",attack:.02,gain:y*.6}),s.tone(m*3,_*.8,{...x,type:"sine",attack:.01,gain:y*.15});return;case"wood":s.tone(m*.5,_*.3,{...x,type:"triangle",attack:.002,gain:y*.9,slideTo:m*.35}),s.noise(.04,{filter:"lowpass",freq:1200,gain:y*.5});return;case"drop":s.tone(m*.8,_*.7,{...x,type:"sine",attack:.006,gain:y,slideTo:m*1.6}),s.noise(.05,{filter:"bandpass",freq:900,q:1.5,gain:y*.25,sweepTo:2400});return;default:s.tone(m,_,{...x,type:f.type??h.wave,gain:y}),s.tone(m*.5,_*.8,{...x,type:"sawtooth",attack:.01,gain:y*.25,lowpass:900});return}},noise:s.noise.bind(s)};if(e==="footstep")return this.footstep(h.surface,r);switch(e){case"curtain_up":c.tone(392,1.2,{attack:.3,gain:.14}),c.tone(587.3,1.3,{attack:.5,gain:.1}),c.tone(784,1.4,{attack:.7,gain:.08});return;case"curtain_down":c.tone(523.25,1.6,{attack:.2,gain:.12}),c.tone(392,1.8,{attack:.4,gain:.1});return;case"walk_to":return;case"read":c.noise(.14,{filter:"highpass",freq:2500,sweepTo:6e3,gain:.07,pan:r}),c.tone(2200,.05,{gain:.04,pan:r});return;case"hammer":c.tone(Ie(180,240)*(1+n*.4),.06,{type:"triangle",gain:.12+n*.1,slideTo:90,pan:r}),c.noise(.03,{filter:"bandpass",freq:3e3,q:2,gain:.05,pan:r});return;case"build":return;case"raise":c.tone(220,.7,{type:"sawtooth",slideTo:660,gain:.08,lowpass:1800,pan:r}),c.tone(440,.3,{gain:.06,pan:r,attack:.3});return;case"forge":c.tone(620,.25,{type:"square",gain:.06,slideTo:580,lowpass:2400,pan:r}),c.tone(1240,.18,{type:"triangle",gain:.05,detune:30,pan:r}),c.noise(.08,{filter:"highpass",freq:4e3,gain:.04,pan:r});return;case"spark":c.tone(Ie(2500,4200),.04,{gain:.03,pan:r});return;case"search":c.noise(.35,{filter:"bandpass",freq:700,sweepTo:2600,q:1.5,gain:.08,pan:r}),c.tone(1568,.12,{gain:.05,pan:r,attack:.02});return;case"run_tests":c.tone(330,.9,{attack:.15,gain:.06,type:"triangle",lowpass:1200,pan:r}),c.tone(495,.9,{attack:.25,gain:.04,type:"triangle",lowpass:1200,pan:r});return;case"test_outcome":t.outcome==="pass"?Db.forEach((u,d)=>setTimeout(()=>c.tone(u,.5,{gain:.12,attack:.01,pan:r}),d*70)):(c.tone(311,.35,{type:"sawtooth",gain:.09,lowpass:900,slideTo:262,pan:r}),setTimeout(()=>c.tone(233,.5,{type:"sawtooth",gain:.09,lowpass:700,slideTo:196,pan:r}),170));return;case"spawn_gremlin":for(let u=0;u<4;u++)setTimeout(()=>c.tone(Ie(900,1300)+u*80,.07,{type:"square",gain:.05,lowpass:2600,slideTo:Ie(700,1100),pan:r}),u*60);return;case"chase":for(let u=0;u<3;u++)setTimeout(()=>c.tone(600+u*120,.08,{type:"triangle",gain:.06,pan:r}),u*90);return;case"banish":c.noise(.06,{filter:"lowpass",freq:1500,gain:.14,pan:r}),setTimeout(()=>c.tone(2093,.25,{gain:.07,pan:r}),40),setTimeout(()=>c.tone(2637,.3,{gain:.05,pan:r}),90);return;case"celebrate":[523.25,659.25,783.99,1046.5,1318.5].forEach((u,d)=>setTimeout(()=>c.tone(u,.45,{gain:.11,attack:.01,pan:r}),d*60));for(let u=0;u<10;u++)setTimeout(()=>c.tone(Ie(1800,4e3),.05,{gain:.03,pan:Ie(-.8,.8)}),200+u*55);return;case"summon_helper":t.theme.id==="orbit"?c.noise(.7,{filter:"bandpass",freq:300,sweepTo:1800,q:1.2,gain:.1,pan:r}):t.theme.id==="metropolis"?(c.tone(880,.12,{type:"square",gain:.06,lowpass:2500,pan:r}),setTimeout(()=>c.tone(880,.12,{type:"square",gain:.06,lowpass:2500,pan:r}),180)):(c.tone(146.8,.8,{type:"triangle",attack:.08,gain:.12,lowpass:800,pan:r}),c.tone(147.5,.8,{type:"triangle",attack:.08,gain:.08,lowpass:800,pan:r}));return;case"dismiss_helper":c.noise(.5,{filter:"bandpass",freq:1800,sweepTo:300,q:1.2,gain:.07,pan:r});return;case"blocked_on_you":c.tone(880,.35,{gain:.16,attack:.01}),setTimeout(()=>c.tone(659.25,.6,{gain:.16,attack:.01}),220);return;case"your_turn":c.tone(1046.5,.5,{gain:.07,attack:.02});return;case"stumble":c.noise(.12,{filter:"lowpass",freq:400,gain:.14,pan:r}),c.tone(120,.25,{type:"triangle",gain:.1,slideTo:70,pan:r});return;case"unverified_claim":c.tone(196,.14,{type:"triangle",gain:.07,lowpass:900,pan:r}),setTimeout(()=>c.tone(185,.14,{type:"triangle",gain:.07,lowpass:900,pan:r}),240),setTimeout(()=>c.tone(174.6,.24,{type:"triangle",gain:.06,lowpass:900,pan:r}),480);return;case"idle":return}}}class Fb{constructor(e){this.a=e}stops=[];current=null;padStop=null;padMood=null;extraTimer=null;tuneTimer=null;moodTimer=null;start(e){if(!this.a.ready||this.current===e.id)return;this.stop(),this.current=e.id;const t=Ho[e.id].ambience,s=Math.floor(Math.random()*8)-3,r=Math.pow(2,s/12),n={...t,washes:t.washes.map(d=>({...d,hz:d.hz*(.85+Math.random()*.35),lfoHz:d.lfoHz*(.7+Math.random()*.6),gain:d.gain*(.8+Math.random()*.4)})),pad:t.pad?{...t.pad,chord:t.pad.chord.map((d,f)=>d*r*(f>0&&Math.random()<.35?2:1))}:void 0,extras:[...t.extras].sort(()=>Math.random()-.5).slice(0,Math.max(1,Math.ceil(t.extras.length*(.5+Math.random()*.5)))),every:t.every*(.7+Math.random()*.6)};for(const d of n.washes)this.stops.push(this.a.wash(d.hz,d.q,d.gain,d.lfoHz,d.depth));n.pad&&this.stops.push(this.a.pad(n.pad.chord,n.pad.gain,n.pad.wave));const o=()=>{if(this.current!==e.id)return;const d=n.extras[Math.floor(Math.random()*n.extras.length)];d&&this.a.extra(d),this.extraTimer=setTimeout(o,n.every*1e3*(.5+Math.random()))};this.extraTimer=setTimeout(o,2e3+Math.random()*3e3);const a=Ho[e.id].tune,l=Math.floor(Math.random()*a.scale.length),h={...a,root:a.root*r,scale:a.scale.map((d,f)=>(a.scale[(f+l)%a.scale.length]-a.scale[l]+12)%12).sort((d,f)=>d-f),every:a.every*(.7+Math.random()*.6)},c=()=>{if(this.current!==e.id)return;const d=4+Math.floor(Math.random()*4);let f=Math.floor(Math.random()*h.scale.length),p=Math.random()<.3?1:0,g=0;for(let m=0;m<d;m++){const _=m===d-1?-(f%3):Math.round((Math.random()-.5)*4);f+=_,f<0&&(f+=h.scale.length,p=Math.max(0,p-1)),f>=h.scale.length&&(f-=h.scale.length,p=Math.min(1,p+1));const y=h.root*Math.pow(2,(h.scale[f]+12*p)/12),x=h.len[0]+Math.random()*(h.len[1]-h.len[0]),b=m===d-1?x*2.2:x;setTimeout(()=>{this.current===e.id&&this.a.note(y,b,h.gain*(.8+Math.random()*.4),h.wave,(Math.random()-.5)*.8)},g*1e3),g+=x*(Math.random()<.2?1.5:1)}this.tuneTimer=setTimeout(c,(g+h.every*(.6+Math.random()*.9))*1e3)};this.tuneTimer=setTimeout(c,4e3+Math.random()*4e3);const u=n.pad?.chord??[h.root/2,h.root*.75,h.root];if(n.mood==="focus"){const d=56+Math.random()*10,f=u[0]/2,p=()=>{this.current===e.id&&(this.a.note(f,.18,.035,"sine",0),this.moodTimer=setTimeout(p,6e4/d))};this.moodTimer=setTimeout(p,1500)}else if(n.mood==="fun"){const d=()=>{if(this.current!==e.id)return;const f=[...u,...u.slice(0,-1).reverse()].map(p=>p*(Math.random()<.5?2:4));f.forEach((p,g)=>setTimeout(()=>{this.current===e.id&&this.a.note(p,.22,.03,"triangle",(g/f.length-.5)*.8)},g*(150+g%2*40))),this.moodTimer=setTimeout(d,9e3+Math.random()*12e3)};this.moodTimer=setTimeout(d,3e3+Math.random()*3e3)}}setMood(e){if(!this.a.ready||e===this.padMood)return;this.padMood=e,this.padStop?.();const t=e==="happy"?[261.6,329.6,392]:e==="lost"?[261.6,311.1,370]:e==="uneasy"?[261.6,311.1,392]:e==="focused"?[261.6,392]:[261.6,329.6];this.padStop=this.a.pad(t.map(s=>s/2),.022,"sine")}stop(){this.extraTimer&&clearTimeout(this.extraTimer),this.extraTimer=null,this.tuneTimer&&clearTimeout(this.tuneTimer),this.tuneTimer=null,this.moodTimer&&clearTimeout(this.moodTimer),this.moodTimer=null;for(const e of this.stops)e();this.stops=[],this.padStop?.(),this.padStop=null,this.padMood=null,this.current=null}}class Zs{constructor(e,t,s,r,n,o){this.app=e,this.world=t,this.theme=s,this.audio=r,this.reducedMotion=n,this.worldLayer=new Ig(t,s),this.particles=new wb(n),this.company=Fg(t.seed,o,s.ground.fill),this.pip=new zo(s,n,this.company.lead),this.camera=new pb(this.stage,n),this.sfx=new Yi(r),this.amb=new Fb(r),this.stage.sortableChildren=!0,this.stage.addChild(this.worldLayer.container),this.worldLayer.container.sortableChildren=!0,this.worldLayer.container.addChild(this.pip.container,this.particles.g),this.particles.g.zIndex=1e7,e.stage.addChild(this.stage),this.actorAt.set("pip","forge"),this.fitCamera(),this.camera.snap()}stage=new _e;worldLayer;camera;pip;helpers=new Map;gremlins=new Map;particles;sfx;amb;beats=[];t=0;prevT=-1;_playing=!1;rate=1;duration=0;mood="curious";actorAt=new Map;walkFrom=new Map;growth=new Map;lastPass=0;signal="ok";footT=0;hammerT=0;claimGremlinId=null;evidenceCount=null;company;helperIndex=0;load(e){this.beats=e,this.duration=e.length?Math.max(...e.map(t=>t.atMs+t.durationMs)):0,this.seek(0)}get beatCount(){return this.beats.length}append(e){this.beats.push(...e),this.duration=Math.max(this.duration,...e.map(t=>t.atMs+t.durationMs))}get playing(){return this._playing}play(){this._playing=!0,this.amb.start(this.theme)}audioReady(){this.amb.stop(),this._playing&&this.amb.start(this.theme)}pause(){this._playing=!1}setRate(e){this.rate=e}setSignal(e){this.signal=e}seek(e){this.t=Math.max(0,Math.min(this.duration,e)),this.rebuild(this.t),this.prevT=this.t,this.particles.clear()}get leadName(){return this.company.lead.name}get state(){const e=this.currentBeat();return{t:this.t,duration:this.duration,playing:this._playing,rate:this.rate,current:e,mood:this.mood,bubble:this.bubble(e),labels:this.labels(e),evidence:this.evidenceCount!==null?{passed:this.evidenceCount}:null,signal:this.signal}}update(e){this._playing&&(this.t=Math.min(this.duration,this.t+e*this.rate),this.t>=this.duration&&this.duration>0&&(this._playing=!1),this.triggerBetween(this.prevT,this.t),this.prevT=this.t);const t=this.currentBeat();this.pose(t,e),this.worldState(t),this.worldLayer.update(e),this.pip.update(e);for(const s of this.helpers.values())s.update(e);for(const s of this.gremlins.values())s.update(e);this.particles.update(e),this.cameraStep(t,e),this.amb.setMood(this.mood)}currentBeat(){let e=null;for(const t of this.beats)if(t.atMs<=this.t)(!e||t.atMs>=e.atMs)&&(t.kind==="idle"&&e&&e.kind!=="idle"&&e.atMs+e.durationMs>this.t||(e=t));else break;return e}completed(){return this.beats.filter(e=>e.atMs+e.durationMs<=this.t)}rebuild(e){this.actorAt.clear(),this.actorAt.set("pip","forge"),this.growth.clear(),this.lastPass=0,this.evidenceCount=null,this.mood="curious",this.claimGremlinId=null,this.helperIndex=0;for(const s of this.gremlins.values())s.container.destroy();this.gremlins.clear();for(const s of this.helpers.values())s.container.destroy();this.helpers.clear();for(const s of this.world.places)this.worldLayer.setLamp(s.id,"idle"),this.worldLayer.setGrowth(s.id,0),this.worldLayer.setGlow(s.id,0),this.worldLayer.setScaffold(s.id,0);for(const s of this.beats){if(s.atMs>e)break;this.onStart(s,!0),s.atMs+s.durationMs<=e&&this.onEnd(s,!0)}this.pip.pose.mood=this.mood;const t=this.worldLayer.standingSpot(this.actorAt.get("pip")??"forge");this.pip.pose.x=t.x,this.pip.pose.y=t.y,this.pip.snap(),this.camTarget=null,this.fitCamera(),this.cameraStep(this.currentBeat(),0),this.camera.snap()}triggerBetween(e,t){for(const s of this.beats){s.atMs>e&&s.atMs<=t&&this.onStart(s,!1);const r=s.atMs+s.durationMs;r>e&&r<=t&&this.onEnd(s,!1)}}onStart(e,t){this.mood=e.mood;const s=this.theme,r=o=>{const a=this.worldLayer.positionOf(o);return a?Math.max(-.8,Math.min(.8,a.ground.x/600)):0},n=(o,a={})=>{!t&&Yi.plays(o,this.rate)&&this.sfx.play(o,{theme:s,...a})};switch(e.kind){case"curtain_up":n("curtain_up"),t||this.camera.pushIn(.12);break;case"walk_to":{const o=this.worldLayer.standingSpot(this.actorAt.get(e.actor)??"forge");this.walkFrom.set(e.actor,o);break}case"read":n("read",{pan:r(e.target)});break;case"raise":{if(e.newPlace&&!this.worldLayer.has(e.target)){const o=this.world.districts.find(l=>l.id===e.newPlace.district)??this.world.districts[0],a={id:e.target,kind:e.newPlace.kind,path:e.newPlace.path,label:e.newPlace.label,district:e.newPlace.district,gx:(o?.cx??2)+1,gy:(o?.cy??2)+1,footprint:1,height:1,score:0,touched:!0};this.world.places.push(a),this.worldLayer.addPlace(a)}n("raise",{pan:r(e.target)});break}case"build":n("build");break;case"forge":n("forge");break;case"search":n("search",{pan:r("forge")});break;case"run_tests":this.worldLayer.setLamp(e.target,"scan"),n("run_tests",{pan:r(e.target)});break;case"test_outcome":{const o=e.outcome==="pass"?"pass":e.outcome==="fail"?"fail":"idle";if(this.worldLayer.setLamp(e.target,o),e.outcome==="pass"&&(this.lastPass=e.atMs,this.evidenceCount=e.passed),n("test_outcome",{outcome:e.outcome,pan:r(e.target)}),!t&&e.outcome==="fail"&&this.camera.shake(200),!t&&e.outcome==="pass"){const a=this.worldLayer.positionOf(e.target);a&&this.particles.burst(a.top.x,a.top.y,16,[s.beacon.lamp.pass,14090217],70,40)}break}case"spawn_gremlin":{const o=new No(e.gremlinId,s,this.reducedMotion),a=this.worldLayer.positionOf(e.target),l=a?a.ground:K(0,0);o.x=l.x+18,o.y=l.y+8,o.scale=t?1:.01,this.worldLayer.container.addChild(o.container),this.gremlins.set(e.gremlinId,o),n("spawn_gremlin",{pan:r(e.target)}),t||(this.camera.pushIn(.06),this.particles.burst(o.x,o.y-10,18,[s.gremlin.body,11967743],60,30));break}case"chase":{const o=this.gremlins.get(e.gremlinId);o&&(o.panic=1),n("chase",{pan:r(e.target)});break}case"banish":{const o=this.gremlins.get(e.gremlinId);o&&(t||this.particles.burst(o.x,o.y-10,30,[16777215,s.gremlin.body],80,35),o.container.destroy(),this.gremlins.delete(e.gremlinId)),this.claimGremlinId===e.gremlinId&&(this.claimGremlinId=null,this.pip.pose.hiding=0),n("banish");break}case"celebrate":{if(n("celebrate"),!t){this.camera.pushIn(.1);const o=this.worldLayer.standingSpot(this.actorAt.get("pip")??"forge");this.particles.burst(o.x,o.y-30,56,[16758087,6287526,8177919,16743273,11967743,16777215],130,90)}break}case"summon_helper":{const o=this.company.helpers[this.helperIndex++%this.company.helpers.length],a=new zo(s,this.reducedMotion,o);a.container.scale.set(.82*o.size);const l=this.worldLayer.standingSpot("dock");a.pose.x=l.x,a.pose.y=l.y,this.worldLayer.container.addChild(a.container),this.helpers.set(e.helperId,a),this.actorAt.set(e.helperId,"dock"),n("summon_helper",{pan:r("dock")});break}case"dismiss_helper":n("dismiss_helper",{pan:r("dock")});break;case"blocked_on_you":n("blocked_on_you");break;case"your_turn":n("your_turn");break;case"stumble":n("stumble"),t||this.camera.shake(160);break;case"unverified_claim":{const o=new No(e.gremlinId,s,this.reducedMotion);o.scale=.8,o.alpha=.95,this.worldLayer.container.addChild(o.container),this.gremlins.set(e.gremlinId,o),this.claimGremlinId=e.gremlinId,this.pip.pose.hiding=1,n("unverified_claim");break}case"curtain_down":n("curtain_down");break}}onEnd(e,t){switch(e.kind){case"walk_to":this.actorAt.set(e.actor,e.target),this.walkFrom.delete(e.actor);break;case"build":this.growth.set(e.target,Math.min(18,(this.growth.get(e.target)??0)+3+Math.round(e.intensity*6))),this.worldLayer.setGrowth(e.target,this.growth.get(e.target)),this.worldLayer.setScaffold(e.target,0);break;case"dismiss_helper":{const s=this.helpers.get(e.helperId);s&&(s.container.destroy(),this.helpers.delete(e.helperId),this.actorAt.delete(e.helperId));break}}}pose(e,t){const s=t/1e3;for(const[r,n]of[["pip",this.pip],...this.helpers.entries()]){const o=n.pose;o.moving=!1,o.lift=0,o.sx=1,o.sy=1,o.lean=0,o.look="fwd",o.mood=this.mood;const a=e&&e.actor===r?e:null,l=this.worldLayer.standingSpot(this.actorAt.get(r)??(r==="pip"?"forge":"dock"));if(o.x=l.x,o.y=l.y,!a){r!=="pip"&&(o.sy=.96);continue}const h=Ue(this.t,a.atMs,a.atMs+a.durationMs),c="target"in a?this.worldLayer.standingSpot(a.target):l;switch(a.kind){case"curtain_up":{o.lift=(1-Math.min(1,h/.5))**2*150,o.sy=h<.5?1.1:1-.25*it(Ue(h,.5,.75)),o.sx=1/o.sy;break}case"walk_to":{const u=this.walkFrom.get(r)??l,d=Math.min(.22,140/a.durationMs),f=h<d?0:Ln((h-d)/(1-d));if(o.x=ss(u.x,c.x,f),o.y=ss(u.y,c.y,f),o.moving=h>=d&&h<.98,o.face=c.x>=u.x?1:-1,h<d){const p=it(h/d);o.sy=1-.1*p,o.sx=1+.08*p,o.lean=-o.face*.12*p}else{const p=this.t/1e3*(this.mood==="lost"?16:11);o.lift=Math.abs(Math.sin(p))*3.5;const g=Math.cos(p*2);if(o.sy=1+.05*g,o.sx=1-.05*g,o.lean=o.face*.07,h>.86){const m=it((h-.86)/.14);o.lean=o.face*.16*m,o.sy=1-.06*m,o.sx=1+.05*m}}r==="pip"&&this._playing&&(this.footT+=s,this.footT>.19&&Yi.plays("footstep",this.rate)&&(this.footT=0,this.sfx.play("footstep",{theme:this.theme,pan:Math.max(-.8,Math.min(.8,o.x/600))})));break}case"read":{const u=it(this.t/1e3%1.4/.25);o.lean=-.17+Math.sin(this.t/1e3*3)*.03-u*.05,o.sy=1-u*.03,o.face=this.facing(o,a.target);break}case"build":case"forge":{const u=a.kind==="build"?.28-a.intensity*.1:.34,d=this.t/1e3%u/u,f=d<.7?d/.7:1-(d-.7)/.3;if(o.lift=f*4,o.lean=d<.7?-.06*f:.12*(1-f),o.sy=d<.7?1+.04*f:1-.08*(1-f),o.sx=1/o.sy,"target"in a&&(o.face=this.facing(o,a.target)),r==="pip"&&this._playing&&!this.reducedMotion){this.hammerT+=s;const p=a.kind==="build"?.28-a.intensity*.1:.34;if(this.hammerT>p){this.hammerT=0,Yi.plays("hammer",this.rate)&&this.sfx.play(a.kind==="build"?"hammer":"spark",{theme:this.theme,intensity:a.kind==="build"?a.intensity:.5});const g="target"in a?this.worldLayer.positionOf(a.target):this.worldLayer.positionOf("forge");g&&Math.random()<.7&&this.particles.burst(g.top.x+(Math.random()*24-12),g.top.y+10,2,[16766571,16774084],50,60)}}break}case"raise":o.look="up",o.sy=1+.05*it(h);break;case"search":o.look="up",o.lean=Math.sin(this.t/1e3*1.5)*.12;break;case"run_tests":o.look="up",o.lean=Math.sin(this.t/1e3*2)*.04;break;case"test_outcome":if(a.outcome==="fail"){const u=it(Ue(h,0,.5));o.lean=-.25*u,o.sy=1-.1*u,o.sx=1+.08*u}else o.lift=it(h)*14;break;case"spawn_gremlin":{const u=it(Ue(h,0,.5));o.lift=Math.sin(Math.PI*Ue(h,.05,.45))*12,o.lean=-.22*u,o.sx=1+.1*u,o.sy=1-.1*u,o.look="down",o.x=l.x-o.face*10*u;break}case"chase":{const u=this.gremlins.get(a.gremlinId),d=c,f=h*Math.PI*2*1.5,p=26,g=d.x+Math.cos(f)*p,m=d.y+Math.sin(f)*p*.5;u&&(u.x=g,u.y=m,u.panic=1);const _=f-1.1;o.x=d.x+Math.cos(_)*p,o.y=d.y+Math.sin(_)*p*.5,o.moving=!0,o.face=Math.cos(f)>Math.cos(_)?1:-1;const y=this.t/1e3*16;o.lift=Math.abs(Math.sin(y))*4,o.lean=o.face*.12;break}case"banish":{o.sy=1-.2*it(Ue(h,0,.4)),o.sx=1/o.sy;break}case"celebrate":{const u=(this.t-a.atMs)%1300/1300;if(u<.22){const d=Math.sin(Math.PI*u/.22);o.sy=1-.24*d,o.sx=1+.2*d}else if(u<.8){const d=(u-.22)/.58;o.lift=Math.sin(Math.PI*d)*32,o.sy=d<.5?1+.14*(1-d*2):1,o.sx=1/o.sy}else{const d=Math.sin(Math.PI*(u-.8)/.2);o.sy=1-.2*d,o.sx=1+.16*d}break}case"blocked_on_you":o.face=1,o.look="fwd",o.sy=1+.03*Math.sin(this.t/1e3*6),o.sx=1/o.sy;break;case"your_turn":o.sy=.86,o.sx=1.08;break;case"stumble":{const u=it(Ue(h,0,.7));o.lean=Math.sin(this.t/1e3*40)*.12*u,o.sy=1-.08*u,o.sx=1+.06*u;break}case"unverified_claim":{o.face=1,o.hiding=1;const u=this.claimGremlinId?this.gremlins.get(this.claimGremlinId):null;u&&(u.x=o.x-o.face*14,u.y=o.y-2,u.peek=1);break}case"curtain_down":o.lean=Math.sin(this.t/1e3*6)*.15,o.face=1;break}if(this.claimGremlinId&&a.kind!=="unverified_claim"){const u=this.gremlins.get(this.claimGremlinId);u&&(u.x=o.x-o.face*14,u.y=o.y-2)}n.container.zIndex=o.y/(Uo/2)+.6,r!=="pip"&&(o.mood="focused")}for(const r of this.gremlins.values())r.container.zIndex=r.y/(Uo/2)+.7}facing(e,t){const s=this.worldLayer.positionOf(t);return s&&s.ground.x<e.x?-1:1}worldState(e){for(const t of this.world.places)this.worldLayer.setGlow(t.id,0);if(e){if((e.kind==="read"||e.kind==="build"||e.kind==="chase"||e.kind==="raise")&&this.worldLayer.setGlow(e.target,e.kind==="read"?.5:1),e.kind==="build"){const t=Ue(this.t,e.atMs,e.atMs+e.durationMs);this.worldLayer.setScaffold(e.target,.85*Math.min(Ue(t,0,.12),1-Ue(t,.85,1))),this.worldLayer.setGrowth(e.target,(this.growth.get(e.target)??0)+Math.round((3+e.intensity*6)*Ln(t)))}if(e.kind==="raise"){const t=Ue(this.t,e.atMs,e.atMs+e.durationMs);this.worldLayer.positionOf(e.target)&&this.worldLayer.setGrowth(e.target,Math.round(-30*(1-uu(t))))}if(e.kind==="spawn_gremlin"){const t=this.gremlins.get(e.gremlinId);t&&(t.scale=Math.max(.01,uu(Ue(this.t,e.atMs,e.atMs+400))))}for(const t of this.world.places)t.kind==="beacon"&&this.worldLayer.lampOf(t.id)==="pass"&&this.t-this.lastPass>12e3&&this.worldLayer.setLamp(t.id,"idle")}}fitCamera(){this.camera.setZoomFactor(this.fitZoom()),this.baseZoom=this.fitZoom()}baseZoom=1;camTarget=null;overview=!1;userZoom=1;setOverview(e){this.overview=e,this.userZoom=1}zoomBy(e){this.userZoom=Math.max(.4,Math.min(3,this.userZoom*e))}cameraStep(e,t){const s={w:this.app.renderer.screen.width,h:this.app.renderer.screen.height},r=s.w<640,n=!e||e.kind==="curtain_up"||e.kind==="curtain_down"||e.kind==="celebrate",o=this.world.places.map(w=>K(w.gx+w.footprint/2,w.gy+w.footprint/2)),a=Math.min(...o.map(w=>w.x))-70,l=Math.max(...o.map(w=>w.x))+70,h=Math.min(...o.map(w=>w.y))-110,c=Math.max(...o.map(w=>w.y))+50,u={x:(a+l)/2,y:(h+c)/2},d=Math.max(.05,this.camera.scale),f=s.w/d/2,p=s.h/d/2,g=(w,T,k)=>T+f>k-f?(T+k)/2:Math.max(T+f,Math.min(k-f,w)),m=(w,T,k)=>T+p>k-p?(T+k)/2:Math.max(T+p,Math.min(k-p,w)),_=this.pip.drawn,y=this.pip.pose.moving?this.pip.pose.face*f*.18:0,x={x:_.x+y,y:_.y-24};if(n||r)this.camTarget=n?{x:u.x,y:u.y}:x;else{this.camTarget||(this.camTarget=x);const w=f*.28,T=p*.26,k=x.x-this.camTarget.x,E=x.y-this.camTarget.y;Math.abs(k)>w&&(this.camTarget.x+=k-Math.sign(k)*w),Math.abs(E)>T&&(this.camTarget.y+=E-Math.sign(E)*T)}const b=g(this.camTarget.x,a,l),v=m(this.camTarget.y,h,c);this.camera.follow(b,v,1),this.camera.setDrift(this.mood==="lost"),this.overview&&(this.camTarget={x:u.x,y:u.y},this.camera.follow(u.x,u.y,1)),this.camera.setZoomFactor((this.overview?this.fitZoom()*.96:this.zoomFor(e,s.h))*this.userZoom),this.camera.update(t,s.w,s.h)}zoomFor(e,t){const s=this.fitZoom();if(!e)return s;const r=Math.max(s,Math.min(1.7,Math.max(.95,t/430)));switch(e.kind){case"curtain_up":return s*ss(1.08,1,Ln(Ue(this.t,e.atMs,e.atMs+e.durationMs)));case"curtain_down":return s*1.05;case"celebrate":return s*1.15;default:return r}}fitZoom(){const e=this.world.places.flatMap(l=>[K(l.gx,l.gy),K(l.gx+l.footprint,l.gy+l.footprint)]),t=e.map(l=>l.x),s=e.map(l=>l.y),r=Math.max(60,Math.max(...t)-Math.min(...t)+140),n=Math.max(60,Math.max(...s)-Math.min(...s)+150),o=this.app.renderer.screen.width,a=this.app.renderer.screen.height;return Math.min(o/(r*1.05),a/(n*1.05),2.2)}bubble(e){if(!e)return null;const t=this.pip.pose,s=this.camera.toScreen(t.x+16,t.y-t.lift-52);return e.kind==="read"||e.kind==="search"?{text:"…",color:4219274,screen:s}:e.kind==="spawn_gremlin"||this.mood==="lost"&&e.kind!=="celebrate"?{text:"?",color:14833484,screen:s}:e.kind==="celebrate"?{text:"!",color:2071139,screen:s}:e.kind==="blocked_on_you"?{text:"!",color:16758087,screen:s}:e.kind==="unverified_claim"?{text:"…",color:8215807,screen:s}:null}labels(e){const t=[],s=e&&"target"in e?e.target:null;for(const r of this.world.places){if(r.kind==="forge"||r.kind==="dock")continue;const n=r.id===s,o=r.kind==="beacon"?this.worldLayer.lampOf(r.id):"idle";if(!n&&o==="idle")continue;const a=this.worldLayer.positionOf(r.id);a&&t.push({text:r.label,screen:this.camera.toScreen(a.top.x,a.top.y-2),active:n})}return t}destroy(){this.amb.stop(),this.worldLayer.destroy(),this.stage.destroy({children:!0})}}const ke={id:"island",name:"Island",tagline:"A warm little island at golden hour.",fits:["cli-tool","library","unknown"],flagship:!0,sky:[2191498,1195610],terrain:"island",ground:{fill:6073960,fillLight:10740879,edge:9070154,edgeDark:6966328,sand:15915942},water:{ripple:16777215,rippleAlpha:.24},pathColor:16245940,labelColor:1592880,palettes:[{top:16310456,left:15382917,right:13605734,roof:15495007,roofD:12735050,win:9067068},{top:14478328,left:11455462,right:9153999,roof:5934020,roofD:4616351,win:4219274},{top:13625820,left:9226664,right:6464387,roof:3122570,roofD:2393199,win:3106389},{top:16507860,left:15908774,right:14261124,roof:14248828,roofD:11554657,win:8014418},{top:16774086,left:16112010,right:14268778,roof:14916398,roofD:12220959,win:8018476}],beacon:{top:16514040,left:15855592,right:14276043,roof:14833484,roofD:12141627,win:3820122,lamp:{idle:16766571,scan:16777215,fail:16734798,pass:6287526}},archive:{top:15327743,left:12891376,right:10916824,roof:9073359,roofD:7231664,win:5062278},forge:{top:7041664,left:4937059,right:3621201,roof:10265519,roofD:7041664,win:16758087,ember:16751164},dock:{deck:11569754,post:8018490,vessel:15855592},prop:"tree",propColors:[4168284,6472819,9067066],gremlin:{body:8215807,eye:1773616},pip:{body:16751164,bodyLight:16765566,belly:16774620,ear:14712620,cheek:16739930,ink:2759959},mood:{curious:16769899,focused:8177919,lost:16743273,happy:6287526,uneasy:16754250},vignette:332832},Ds={...ke,id:"orbit",name:"Orbit",tagline:"A quiet station turning above a blue planet.",fits:["backend-api","infra-devops","systems"],flagship:!0,sky:[725030,1780309],terrain:"platform",ground:{fill:3885675,fillLight:7045032,edge:2568522,edgeDark:1712695,sand:9082808},water:{ripple:10473727,rippleAlpha:.18},pathColor:13624319,labelColor:14411775,palettes:[{top:15266303,left:12571890,right:9678036,roof:6280191,roofD:3844566,win:8188927},{top:16054011,left:14015464,right:11187143,roof:11967743,roofD:9401062,win:13481983},{top:15138806,left:12185820,right:9423800,roof:6287526,roofD:4177795,win:11075542}],beacon:{top:16777215,left:15133685,right:12174038,roof:6280191,roofD:3844566,win:8188927,lamp:{idle:10473727,scan:16777215,fail:16734798,pass:6287526}},forge:{top:10134712,left:7239820,right:5133930,roof:12634328,roofD:9081768,win:8188927,ember:8188927},dock:{deck:7239820,post:5133930,vessel:16777215},prop:"antenna",propColors:[12174038,8188927,5133930],gremlin:{body:16734878,eye:1773616},vignette:198162},yr={...ke,id:"metropolis",name:"Metropolis",tagline:"A warm night city, lights just coming on.",fits:["web-frontend","monorepo"],flagship:!0,sky:[1708080,3874127],terrain:"block",ground:{fill:3814736,fillLight:5919864,edge:2762304,edgeDark:1709872,sand:6972296},water:{ripple:16758087,rippleAlpha:.1},pathColor:16767392,labelColor:16771527,palettes:[{top:16769730,left:15907216,right:13208422,roof:16743273,roofD:13916746,win:16766571},{top:14933247,left:12036592,right:9075664,roof:11967743,roofD:9401062,win:16771496},{top:14087423,left:10147568,right:7318220,roof:6280191,roofD:3844566,win:16774084},{top:16770799,left:16234188,right:13929126,roof:16740261,roofD:14241919,win:16766571}],beacon:{top:16119285,left:14277081,right:11579568,roof:16740261,roofD:14241919,win:3355443,lamp:{idle:16758087,scan:16777215,fail:16734798,pass:6287526}},forge:{top:8024976,left:5656684,right:3946572,roof:10656699,roofD:7301256,win:16758087,ember:16758087},dock:{deck:5656684,post:3946572,vessel:16766571},prop:"lamp",propColors:[16766571,16774084,3946572],gremlin:{body:6287526,eye:993820},vignette:525332},Ob={...ke,id:"harbour",name:"Harbour",tagline:"Fog lifting off a working port.",fits:["backend-api","infra-devops"],flagship:!1,sky:[2841971,995135],ground:{fill:8032106,fillLight:11124115,edge:6052434,edgeDark:4012853,sand:13222829},water:{ripple:14283263,rippleAlpha:.3},pathColor:14275261,labelColor:2046506,palettes:[{top:16051424,left:14273459,right:11772806,roof:4090762,roofD:2969446,win:5917242},{top:16247268,left:14925746,right:12556423,roof:13195850,roofD:10503482,win:7027248},{top:15331298,left:12898743,right:10201996,roof:5209950,roofD:3825990,win:3099192}],dock:{deck:9203532,post:5916210,vessel:15223612},prop:"lamp",propColors:[16767392,16773590,4868682],vignette:398879},Lb={...Ds,id:"observatory",name:"Observatory",tagline:"A mountaintop under a hard, clear sky.",fits:["data-ml","systems"],flagship:!1,sky:[659504,2367562],terrain:"block",ground:{fill:4867942,fillLight:7236495,edge:3091781,edgeDark:1907502,sand:9275818},water:{ripple:16777215,rippleAlpha:.22},pathColor:14276336,labelColor:15394815,palettes:[{top:15855615,left:13617646,right:10722761,roof:11967743,roofD:9401062,win:16773544},{top:15135743,left:12375795,right:9415113,roof:6280191,roofD:3844566,win:16773544}],beacon:{...Ds.beacon,roof:11967743,roofD:9401062},prop:"antenna",propColors:[13617646,16773544,3091781],vignette:329756},Ub={...ke,id:"greenhouse",name:"Greenhouse",tagline:"Glass, leaves and warm afternoon light.",fits:["data-ml","library"],flagship:!1,sky:[9423280,4098938],ground:{fill:8175466,fillLight:11985823,edge:8020552,edgeDark:5916212,sand:15129779},water:{ripple:16777215,rippleAlpha:.18},pathColor:15985874,labelColor:1985843,palettes:[{top:15794166,left:13496029,right:10735033,roof:8115107,roofD:5220732,win:14286832},{top:16775654,left:15918008,right:13483407,roof:15774556,roofD:13077307,win:8018476},{top:16183551,left:14470131,right:11903953,roof:11832575,roofD:9070294,win:5062278}],prop:"tree",propColors:[5223530,9429132,8018490],vignette:731676},Og={...ke,id:"workshop",name:"Workshop",tagline:"A village of makers, sawdust in the air.",fits:["cli-tool","library","systems"],flagship:!1,sky:[14264428,9064238],ground:{fill:10404970,fillLight:13624221,edge:9067066,edgeDark:6701098,sand:15323811},water:{ripple:16771527,rippleAlpha:.2},pathColor:15916982,labelColor:4860432,palettes:[{top:16245699,left:14727562,right:12160867,roof:10902330,roofD:8340265,win:16765566},{top:15919320,left:14206894,right:11574144,roof:6057866,roofD:4543594,win:16765566},{top:16508889,left:15712936,right:13343362,roof:13190970,roofD:10499372,win:16765566}],forge:{...ke.forge,ember:16758087},prop:"tree",propColors:[5940060,8832366,8014378],vignette:2757640},Nb={...yr,id:"arcade",name:"Arcade",tagline:"Neon rain on a late-night strip.",fits:["game","web-frontend"],flagship:!1,sky:[1181734,2756426],ground:{fill:2366012,fillLight:3811932,edge:1445930,edgeDark:788506,sand:5913228},water:{ripple:16732120,rippleAlpha:.12},pathColor:8188927,labelColor:16773375,palettes:[{top:16766710,left:16748512,right:13916856,roof:8188927,roofD:3848406,win:8188927},{top:14284543,left:9430271,right:5944532,roof:16732120,roofD:12987048,win:16773227},{top:16774604,left:16769899,right:14071882,roof:11967743,roofD:9401062,win:16732120}],beacon:{...yr.beacon,roof:16732120,roofD:12987048,lamp:{idle:8188927,scan:16777215,fail:16734798,pass:6287526}},gremlin:{body:16773227,eye:2759173},prop:"lamp",propColors:[16732120,16766710,1445930],vignette:328206},Lg={...ke,id:"kingdom",name:"Kingdom",tagline:"Stone walls, banners, a river below.",fits:["monorepo","backend-api","unknown"],flagship:!1,sky:[8369113,3894937],ground:{fill:7319134,fillLight:10933647,edge:8354410,edgeDark:6117709,sand:14209725},water:{ripple:16777215,rippleAlpha:.22},pathColor:13616813,labelColor:2828834,palettes:[{top:15855075,left:13880767,right:11248791,roof:4153231,roofD:3032683,win:5917242},{top:15855075,left:13880767,right:11248791,roof:11024954,roofD:8465452,win:5917242},{top:15855075,left:13880767,right:11248791,roof:4882258,roofD:3563581,win:5917242}],beacon:{...ke.beacon,top:15328470,left:13617334,right:10722701,roof:4153231,roofD:3032683},prop:"tree",propColors:[4165458,7323498,5916212],vignette:858662},zb={...ke,id:"outpost",name:"Outpost",tagline:"A desert station at dusk, dust in the light.",fits:["infra-devops","cli-tool","systems"],flagship:!1,sky:[15770458,7024458],ground:{fill:14267502,fillLight:15848346,edge:10842175,edgeDark:8016429,sand:15980451},water:{ripple:16769200,rippleAlpha:.14},pathColor:16509124,labelColor:4860432,palettes:[{top:16509392,left:15255450,right:12885875,roof:14246463,roofD:11094061,win:5913120},{top:16182752,left:14667960,right:12101261,roof:3116938,roofD:2321255,win:5913120}],prop:"antenna",propColors:[12885875,16769200,8016429],vignette:2756372},Hb={...ke,id:"snowfield",name:"Snowfield",tagline:"Blue hour, fresh snow, chimney smoke.",fits:["library","docs-content","unknown"],flagship:!1,sky:[10470374,4153231],ground:{fill:15397370,fillLight:16777215,edge:9346485,edgeDark:6714764,sand:14082802},water:{ripple:16777215,rippleAlpha:.3},pathColor:12833768,labelColor:2767442,palettes:[{top:16183526,left:14470070,right:11969164,roof:12077626,roofD:9188648,win:16765566},{top:15791352,left:13358560,right:10661564,roof:4090762,roofD:2969446,win:16765566},{top:15661040,left:13032912,right:10467498,roof:4882258,roofD:3563581,win:16765566}],prop:"tree",propColors:[3107658,5216874,5916212],vignette:858666},Wb={...ke,id:"canopy",name:"Canopy",tagline:"Treehouses strung through an old forest.",fits:["docs-content","data-ml","library"],flagship:!1,sky:[6266731,2050611],ground:{fill:5214031,fillLight:8372074,edge:5916212,edgeDark:4075556,sand:11050866},water:{ripple:14218704,rippleAlpha:.18},pathColor:14076314,labelColor:15398879,palettes:[{top:15918793,left:14271643,right:11770482,roof:6983487,roofD:5139245,win:16765566},{top:16181976,left:14927782,right:12558206,roof:12085818,roofD:9195306,win:16765566}],prop:"tree",propColors:[3111487,6075226,4863268],vignette:398860},$b={...ke,id:"lagoon",name:"Lagoon",tagline:"Turquoise shallows and white sand at noon.",fits:["web-frontend","library","docs-content"],flagship:!1,sky:[8378351,2068408],ground:{fill:10147978,fillLight:13890493,edge:13218430,edgeDark:10719327,sand:16774102},water:{ripple:16777215,rippleAlpha:.36},pathColor:16774620,labelColor:1002074,palettes:[{top:16777215,left:15790056,right:13618628,roof:3126217,roofD:2133923,win:3107450},{top:16774886,left:16769464,right:14728332,roof:16747610,roofD:14051902,win:8014380},{top:15925240,left:13235165,right:10473913,roof:4177818,roofD:2788464,win:2054730}],prop:"tree",propColors:[4169564,9166970,10254916],vignette:536640},Vb={...ke,id:"volcano",name:"Volcano",tagline:"Black rock, red sky, light from below.",fits:["systems","infra-devops","game"],flagship:!1,sky:[5904922,1705992],ground:{fill:3813167,fillLight:5917256,edge:2365978,edgeDark:1182218,sand:6969942},water:{ripple:16743226,rippleAlpha:.22},pathColor:16751194,labelColor:16769479,palettes:[{top:4866114,left:3813940,right:2761766,roof:16739133,roofD:12864036,win:16758087},{top:5917266,left:4602432,right:3353135,roof:16758087,roofD:14257186,win:16739133}],beacon:{...ke.beacon,top:3813940,left:2761766,right:2038300,roof:16739133,roofD:12864036,lamp:{idle:16758087,scan:16777215,fail:16734798,pass:6287526}},forge:{...ke.forge,ember:16739133},dock:{deck:4602432,post:2761766,vessel:16758087},prop:"antenna",propColors:[5917256,16739133,2365978],gremlin:{body:8188927,eye:666160},vignette:655874},jb={...Ds,id:"cloudtop",name:"Cloudtop",tagline:"A floating town above a sea of cloud.",fits:["web-frontend","mobile","docs-content"],flagship:!1,sky:[13625087,8368358],terrain:"platform",ground:{fill:15988475,fillLight:16777215,edge:14147822,edgeDark:12043480,sand:16777215},water:{ripple:16777215,rippleAlpha:.5},pathColor:16771496,labelColor:2767442,palettes:[{top:16777215,left:15791354,right:13621478,roof:16748448,roofD:14051964,win:16765566},{top:16777215,left:15791354,right:13621478,roof:8177919,roofD:5216982,win:16765566},{top:16777215,left:15791354,right:13621478,roof:11967743,roofD:9401062,win:16765566}],beacon:{...Ds.beacon,roof:16748448,roofD:14051964,lamp:{idle:16765566,scan:16777215,fail:16734798,pass:6287526}},dock:{deck:15791354,post:12043480,vessel:16748448},prop:"tree",propColors:[9426848,13168832,12043480],vignette:4876954},Xb={...ke,id:"reef",name:"Reef",tagline:"Underwater, where the light comes in ribbons.",fits:["data-ml","game","library"],flagship:!1,sky:[1802144,404032],terrain:"island",ground:{fill:13220234,fillLight:15326384,edge:9075290,edgeDark:5918266,sand:14930854},water:{ripple:10479871,rippleAlpha:.3},pathColor:15984579,labelColor:15137791,palettes:[{top:16767462,left:16752320,right:14052498,roof:16740261,roofD:14241919,win:8006218},{top:16773577,left:16765566,right:14265690,roof:16747610,roofD:14051902,win:8014380},{top:14286838,left:10481880,right:7129520,roof:4177818,roofD:2788464,win:2054730}],prop:"antenna",propColors:[16752320,10481880,9075290],gremlin:{body:1773616,eye:10479871},vignette:136224},qb={...Og,id:"bazaar",name:"Bazaar",tagline:"Ochre walls, striped awnings, late light.",fits:["monorepo","web-frontend","backend-api"],flagship:!1,sky:[15909498,11033146],ground:{fill:14200945,fillLight:15849120,edge:9067066,edgeDark:6701098,sand:15981742},water:{ripple:16773577,rippleAlpha:.16},pathColor:16773577,labelColor:4860432,palettes:[{top:16640463,left:15386528,right:12885875,roof:14240570,roofD:11024940,win:5913120},{top:16640463,left:15386528,right:12885875,roof:3116938,roofD:2321255,win:5913120},{top:16640463,left:15386528,right:12885875,roof:4153231,roofD:3032683,win:5913120},{top:16640463,left:15386528,right:12885875,roof:14916398,roofD:12220959,win:5913120}],prop:"lamp",propColors:[16765566,16773577,6701098],vignette:2757640},Yb={...Lg,id:"monastery",name:"Monastery",tagline:"Mist on the mountain, a bell somewhere.",fits:["docs-content","library","systems"],flagship:!1,sky:[12110276,5204842],ground:{fill:8363898,fillLight:11585958,edge:6975334,edgeDark:4869703,sand:13093309},water:{ripple:16777215,rippleAlpha:.2},pathColor:14275520,labelColor:2042408,palettes:[{top:15855075,left:13880767,right:11248791,roof:5917242,roofD:4076072,win:16765566},{top:15855075,left:13880767,right:11248791,roof:9058858,roofD:6695454,win:16765566}],prop:"tree",propColors:[4157258,6986346,4863268],vignette:1055256},Kb={...Ds,id:"moonbase",name:"Moonbase",tagline:"Grey dust, black sky, one blue marble.",fits:["systems","infra-devops","data-ml"],flagship:!1,sky:[329228,724248],terrain:"platform",ground:{fill:9276821,fillLight:12105920,edge:6184550,edgeDark:3816e3,sand:11053232},water:{ripple:16777215,rippleAlpha:.28},pathColor:14474468,labelColor:15790326,palettes:[{top:16185082,left:14474468,right:11842750,roof:8188927,roofD:3848406,win:16765566},{top:16185082,left:14474468,right:11842750,roof:16758087,roofD:14257186,win:8188927}],prop:"antenna",propColors:[12105920,8188927,3816e3],vignette:0},Zb={...yr,id:"lanterns",name:"Lanterns",tagline:"A night festival, paper light everywhere.",fits:["web-frontend","game","unknown"],flagship:!1,sky:[1706542,3805232],terrain:"block",ground:{fill:3811908,fillLight:5915750,edge:2365998,edgeDark:1314332,sand:6969976},water:{ripple:16751194,rippleAlpha:.14},pathColor:16767392,labelColor:16771527,palettes:[{top:16771535,left:15910816,right:13211758,roof:14240570,roofD:11024940,win:16765566},{top:16180223,left:14268402,right:11177161,roof:16740261,roofD:14241919,win:16765566},{top:16774870,left:16769952,right:14268778,roof:14916398,roofD:12220959,win:16751194}],prop:"lamp",propColors:[16751194,16769952,2365998],vignette:656404},Et=[ke,Ds,yr,Ob,Lb,Ub,Og,Nb,Lg,zb,Hb,Wb,$b,Vb,jb,Xb,qb,Yb,Kb,Zb],nr=i=>Et.find(e=>e.id===i)??ke;function Wo(i,e=0){const t=i?.kinds?.length?i.kinds:["unknown"],s=l=>t.reduce((h,c,u)=>h+(l.fits.includes(c)?(t.length-u)*2:0),0)+(l.flagship?1:0),r=Et.filter(l=>s(l)>1),n=r.length>=3?r:Et;let o=e>>>0||1;const a=()=>(o^=o<<13,o^=o>>>17,o^=o<<5,(o>>>0)%1e3/1e3);return[...n].map(l=>({s:l,k:s(l)+a()*.5})).sort((l,h)=>h.k-l.k).map(({s:l})=>l)}const Qb={aVertex:(i,e,t,s,r)=>{let n=0,o=0,a=0,l=0;for(let h=0;h<i.length;++h){const c=i[h],u=c.texture,d=c.scaleX,f=c.scaleY,p=c.anchorX,g=c.anchorY,m=u.trim,_=u.orig;m?(o=m.x-p*_.width,n=o+m.width,l=m.y-g*_.height,a=l+m.height):(n=_.width*(1-p),o=_.width*-p,a=_.height*(1-g),l=_.height*-g),e[s]=o*d,e[s+1]=l*f,e[s+r]=n*d,e[s+r+1]=l*f,e[s+r*2]=n*d,e[s+r*2+1]=a*f,e[s+r*3]=o*d,e[s+r*3+1]=a*f,s+=r*4}},aPosition:(i,e,t,s,r)=>{for(let n=0;n<i.length;++n){const o=i[n],a=o.x,l=o.y;e[s]=a,e[s+1]=l,e[s+r]=a,e[s+r+1]=l,e[s+r*2]=a,e[s+r*2+1]=l,e[s+r*3]=a,e[s+r*3+1]=l,s+=r*4}},aRotation:(i,e,t,s,r)=>{for(let n=0;n<i.length;++n){const o=i[n].rotation;e[s]=o,e[s+r]=o,e[s+r*2]=o,e[s+r*3]=o,s+=r*4}},aUV:(i,e,t,s,r)=>{for(let n=0;n<i.length;++n){const o=i[n].texture.uvs;e[s]=o.x0,e[s+1]=o.y0,e[s+r]=o.x1,e[s+r+1]=o.y1,e[s+r*2]=o.x2,e[s+r*2+1]=o.y2,e[s+r*3]=o.x3,e[s+r*3+1]=o.y3,s+=r*4}},aColor:(i,e,t,s,r)=>{for(let n=0;n<i.length;++n){const o=i[n].color;t[s]=o,t[s+r]=o,t[s+r*2]=o,t[s+r*3]=o,s+=r*4}}};function Jb(i){const e=Object.values(i),t=e.filter(r=>r.dynamic),s=e.filter(r=>!r.dynamic);return{dynamicUpdate:_u(t),staticUpdate:_u(s)}}function _u(i){let e=0;const t=[];for(let s=0;s<i.length;s++){const r=i[s],n=mt(r.format).stride/4;e+=n,t.push({stride:n,updateFunction:r.updateFunction||Qb[r.attributeName]})}return(s,r,n)=>{let o=0;for(let a=0;a<t.length;a++){const l=t[a];l.updateFunction(s,r,n,o,e),o+=l.stride}}}function e1(){return t1}function t1(i,e,t){const s=i.gl,r=i.shader,n=r._getProgramData(e.glProgram);for(const o in e.groups){const a=e.groups[o];for(const l in a.resources){const h=a.resources[l];if(h instanceof Ze)h.ubo?r.bindUniformBlock(h,e._uniformBindMap[o][l],t.blockIndex++):r.updateUniformGroup(h);else if(h instanceof Mi)r.bindUniformBlock(h,e._uniformBindMap[o][l],t.blockIndex++);else if(h instanceof ue||h instanceof Ul){i.texture.bind(h,t.textureCount);const c=e._uniformBindMap[o][l],u=n.uniformData[c];u&&(u.value!==t.textureCount&&s.uniform1i(u.location,t.textureCount),t.textureCount++)}}}}const s1=[(i,e,t,s,r)=>{const n=s[i].toArray(!0);e[t]=n[0],e[t+1]=n[1],e[t+2]=n[2],e[t+4]=n[3],e[t+5]=n[4],e[t+6]=n[5],e[t+8]=n[6],e[t+9]=n[7],e[t+10]=n[8]},(i,e,t,s,r)=>{r=s[i],e[t]=r.x,e[t+1]=r.y,e[t+2]=r.width,e[t+3]=r.height},(i,e,t,s,r)=>{r=s[i],e[t]=r.x,e[t+1]=r.y},(i,e,t,s,r)=>{r=s[i],e[t]=r.red,e[t+1]=r.green,e[t+2]=r.blue,e[t+3]=r.alpha},(i,e,t,s,r)=>{r=s[i],e[t]=r.red,e[t+1]=r.green,e[t+2]=r.blue}],i1={f32:(i,e,t,s,r)=>{e[t]=r},i32:(i,e,t,s,r)=>{e[t]=r},"vec2<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1]},"vec3<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2]},"vec4<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3]},"mat2x2<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3]},"mat3x3<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+4]=r[3],e[t+5]=r[4],e[t+6]=r[5],e[t+8]=r[6],e[t+9]=r[7],e[t+10]=r[8]},"mat4x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<16;n++)e[t+n]=r[n]},"mat3x2<f32>":(i,e,t,s,r)=>{for(let n=0;n<6;n++)e[t+(n/3|0)*4+n%3]=r[n]},"mat4x2<f32>":(i,e,t,s,r)=>{for(let n=0;n<8;n++)e[t+(n/4|0)*4+n%4]=r[n]},"mat2x3<f32>":(i,e,t,s,r)=>{for(let n=0;n<6;n++)e[t+(n/2|0)*4+n%2]=r[n]},"mat4x3<f32>":(i,e,t,s,r)=>{for(let n=0;n<12;n++)e[t+(n/4|0)*4+n%4]=r[n]},"mat2x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<8;n++)e[t+(n/2|0)*4+n%2]=r[n]},"mat3x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<12;n++)e[t+(n/3|0)*4+n%3]=r[n]}},r1={f32:(i,e,t,s,r)=>{e[t]=r},i32:(i,e,t,s,r)=>{e[t]=r},"vec2<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1]},"vec3<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2]},"vec4<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+3]=r[3]},"mat2x2<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+4]=r[2],e[t+5]=r[3]},"mat3x3<f32>":(i,e,t,s,r)=>{e[t]=r[0],e[t+1]=r[1],e[t+2]=r[2],e[t+4]=r[3],e[t+5]=r[4],e[t+6]=r[5],e[t+8]=r[6],e[t+9]=r[7],e[t+10]=r[8]},"mat4x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<16;n++)e[t+n]=r[n]},"mat3x2<f32>":(i,e,t,s,r)=>{for(let n=0;n<6;n++)e[t+(n/3|0)*4+n%3]=r[n]},"mat4x2<f32>":(i,e,t,s,r)=>{for(let n=0;n<8;n++)e[t+(n/4|0)*4+n%4]=r[n]},"mat2x3<f32>":(i,e,t,s,r)=>{for(let n=0;n<6;n++)e[t+(n/2|0)*4+n%2]=r[n]},"mat4x3<f32>":(i,e,t,s,r)=>{for(let n=0;n<12;n++)e[t+(n/4|0)*4+n%4]=r[n]},"mat2x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<8;n++)e[t+(n/2|0)*4+n%2]=r[n]},"mat3x4<f32>":(i,e,t,s,r)=>{for(let n=0;n<12;n++)e[t+(n/3|0)*4+n%3]=r[n]}};function n1(i){return Ug(i,r1,e=>{const t=Math.max(Kr[e.data.type]/16,1),s=e.data.value.length/e.data.size,r=(4-s%4)%4;return(n,o,a,l,h)=>{let c=0;for(let u=0;u<e.data.size*t;u++){for(let d=0;d<s;d++)o[a++]=h[c++];a+=r}}})}function o1(i){return Ug(i,i1,e=>{const{size:t,align:s}=Es[e.data.type],r=(Math.max(t,s)-t)/4;return(n,o,a,l,h)=>{let c=0;for(let u=0;u<e.data.size;u++){for(let d=0;d<t/4;d++)o[a++]=h[c++];a+=r}}})}function Ug(i,e,t){const s={};for(const r in i){const n=i[r],o=n.data;let a=!1;s[o.name]={offset:n.offset/4,func:null};for(let l=0;l<nt.length;l++){const h=nt[l];if(o.type===h.type&&h.test(o)){s[o.name].func=s1[l],a=!0;break}}a||(o.size===1?s[o.name].func=e[o.type]:s[o.name].func=t(n))}return(r,n,o,a)=>{for(const l in s)s[l].func(l,n,a+s[l].offset,r,r[l])}}const a1={f32(i,e,t,s,r,n,o){t!==s&&(e.value=s,o.uniform1f(r[i].location,s))},"vec2<f32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1])&&(t[0]=s[0],t[1]=s[1],o.uniform2f(r[i].location,s[0],s[1]))},"vec3<f32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],o.uniform3f(r[i].location,s[0],s[1],s[2]))},"vec4<f32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2]||t[3]!==s[3])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],o.uniform4f(r[i].location,s[0],s[1],s[2],s[3]))},i32(i,e,t,s,r,n,o){t!==s&&(e.value=s,o.uniform1i(r[i].location,s))},"vec2<i32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1])&&(t[0]=s[0],t[1]=s[1],o.uniform2i(r[i].location,s[0],s[1]))},"vec3<i32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],o.uniform3i(r[i].location,s[0],s[1],s[2]))},"vec4<i32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2]||t[3]!==s[3])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],o.uniform4i(r[i].location,s[0],s[1],s[2],s[3]))},u32(i,e,t,s,r,n,o){t!==s&&(e.value=s,o.uniform1ui(r[i].location,s))},"vec2<u32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1])&&(t[0]=s[0],t[1]=s[1],o.uniform2ui(r[i].location,s[0],s[1]))},"vec3<u32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],o.uniform3ui(r[i].location,s[0],s[1],s[2]))},"vec4<u32>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2]||t[3]!==s[3])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],o.uniform4ui(r[i].location,s[0],s[1],s[2],s[3]))},bool(i,e,t,s,r,n,o){t!==s&&(e.value=s,o.uniform1i(r[i].location,s))},"vec2<bool>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1])&&(t[0]=s[0],t[1]=s[1],o.uniform2i(r[i].location,s[0],s[1]))},"vec3<bool>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],o.uniform3i(r[i].location,s[0],s[1],s[2]))},"vec4<bool>"(i,e,t,s,r,n,o){(t[0]!==s[0]||t[1]!==s[1]||t[2]!==s[2]||t[3]!==s[3])&&(t[0]=s[0],t[1]=s[1],t[2]=s[2],t[3]=s[3],o.uniform4i(r[i].location,s[0],s[1],s[2],s[3]))},"mat2x2<f32>"(i,e,t,s,r,n,o){o.uniformMatrix2fv(r[i].location,!1,s)},"mat3x3<f32>"(i,e,t,s,r,n,o){o.uniformMatrix3fv(r[i].location,!1,s)},"mat4x4<f32>"(i,e,t,s,r,n,o){o.uniformMatrix4fv(r[i].location,!1,s)}},l1={f32(i,e,t,s,r,n,o){o.uniform1fv(r[i].location,s)},"vec2<f32>"(i,e,t,s,r,n,o){o.uniform2fv(r[i].location,s)},"vec3<f32>"(i,e,t,s,r,n,o){o.uniform3fv(r[i].location,s)},"vec4<f32>"(i,e,t,s,r,n,o){o.uniform4fv(r[i].location,s)},"mat2x2<f32>"(i,e,t,s,r,n,o){o.uniformMatrix2fv(r[i].location,!1,s)},"mat3x3<f32>"(i,e,t,s,r,n,o){o.uniformMatrix3fv(r[i].location,!1,s)},"mat4x4<f32>"(i,e,t,s,r,n,o){o.uniformMatrix4fv(r[i].location,!1,s)},i32(i,e,t,s,r,n,o){o.uniform1iv(r[i].location,s)},"vec2<i32>"(i,e,t,s,r,n,o){o.uniform2iv(r[i].location,s)},"vec3<i32>"(i,e,t,s,r,n,o){o.uniform3iv(r[i].location,s)},"vec4<i32>"(i,e,t,s,r,n,o){o.uniform4iv(r[i].location,s)},u32(i,e,t,s,r,n,o){o.uniform1iv(r[i].location,s)},"vec2<u32>"(i,e,t,s,r,n,o){o.uniform2iv(r[i].location,s)},"vec3<u32>"(i,e,t,s,r,n,o){o.uniform3iv(r[i].location,s)},"vec4<u32>"(i,e,t,s,r,n,o){o.uniform4iv(r[i].location,s)},bool(i,e,t,s,r,n,o){o.uniform1iv(r[i].location,s)},"vec2<bool>"(i,e,t,s,r,n,o){o.uniform2iv(r[i].location,s)},"vec3<bool>"(i,e,t,s,r,n,o){o.uniform3iv(r[i].location,s)},"vec4<bool>"(i,e,t,s,r,n,o){o.uniform4iv(r[i].location,s)}},h1=[(i,e,t,s,r,n,o)=>{o.uniformMatrix3fv(r[i].location,!1,n[i].toArray(!0))},(i,e,t,s,r,n,o)=>{t=r[i].value,s=n[i],(t[0]!==s.x||t[1]!==s.y||t[2]!==s.width||t[3]!==s.height)&&(t[0]=s.x,t[1]=s.y,t[2]=s.width,t[3]=s.height,o.uniform4f(r[i].location,s.x,s.y,s.width,s.height))},(i,e,t,s,r,n,o)=>{t=r[i].value,s=n[i],(t[0]!==s.x||t[1]!==s.y)&&(t[0]=s.x,t[1]=s.y,o.uniform2f(r[i].location,s.x,s.y))},(i,e,t,s,r,n,o)=>{t=r[i].value,s=n[i],(t[0]!==s.red||t[1]!==s.green||t[2]!==s.blue||t[3]!==s.alpha)&&(t[0]=s.red,t[1]=s.green,t[2]=s.blue,t[3]=s.alpha,o.uniform4f(r[i].location,s.red,s.green,s.blue,s.alpha))},(i,e,t,s,r,n,o)=>{t=r[i].value,s=n[i],(t[0]!==s.red||t[1]!==s.green||t[2]!==s.blue)&&(t[0]=s.red,t[1]=s.green,t[2]=s.blue,o.uniform3f(r[i].location,s.red,s.green,s.blue))}];function c1(i,e){const t={};for(const s in i.uniformStructures){if(!e[s])continue;const r=i.uniformStructures[s];let n=!1;for(let o=0;o<nt.length;o++){const a=nt[o];if(r.type===a.type&&a.test(r)){t[s]=h1[o],n=!0;break}}if(!n){const o=r.size===1?a1:l1;t[s]=o[r.type]}}return(s,r,n)=>{const o=n.gl;for(const a in t){const l=r[a],h=s[a],c=s[a].value;t[a](a,h,c,l,s,r,o)}}}function u1(){Object.assign(ds.prototype,{_unsafeEvalCheck(){}}),Object.assign(Yr.prototype,{_systemCheck(){}}),Object.assign(Jr.prototype,{_generateUniformsSync:c1}),Object.assign(Zr.prototype,{_generateUboSync:n1}),Object.assign(tn.prototype,{_generateUboSync:o1}),Object.assign(Qr.prototype,{_generateShaderSync:e1}),Object.assign(vg.prototype,{generateParticleUpdate:Jb})}u1();class dh{constructor(e){this.payload=e}mode="replay";onReady(e){queueMicrotask(()=>e(this.payload))}onBeats(){}}class d1{constructor(e=""){this.base=e,this.connect()}mode="live";readyCb=null;beatsCb=null;signalCb=null;pending=null;async connect(){const e=await(await fetch(`${this.base}/api/scene`)).json(),t={world:e.world,events:e.events,beats:e.beats,repoId:e.repoId};this.readyCb?this.readyCb(t):this.pending=t,e.signal&&this.signalCb?.(e.signal);const s=()=>{const r=/^https?:/.test(this.base)?this.base:location.origin+this.base,n=new WebSocket(`${r.replace(/^http/,"ws")}/live`);n.onmessage=o=>{const a=JSON.parse(String(o.data));a.type==="beats"&&a.beats&&this.beatsCb?.(a.beats,a.events??[]),a.type==="signal"&&a.state&&this.signalCb?.(a.state)},n.onclose=()=>{this.signalCb?.("lost"),setTimeout(s,2e3)}};s()}onReady(e){if(this.readyCb=e,this.pending){const t=this.pending;this.pending=null,e(t)}}onBeats(e){this.beatsCb=e}onSignal(e){this.signalCb=e}}class f1{constructor(e,t){this.host=e,this.session=t,addEventListener("message",s=>{const r=s.data;if(r?.type==="scene"&&r.payload){const n=r.payload,o={world:n.world,events:n.events,beats:n.beats,repoId:n.title?`${n.repoId} — ${n.title}`:n.repoId};this.readyCb?this.readyCb(o):this.pending=o,n.signal&&this.signalCb?.(n.signal)}r?.type==="beats"&&r.beats&&this.beatsCb?.(r.beats,r.events??[]),r?.type==="signal"&&r.state&&this.signalCb?.(r.state)}),e.postMessage(t?{type:"replay",id:t}:{type:"scene"})}mode="live";readyCb=null;beatsCb=null;signalCb=null;pending=null;onReady(e){if(this.readyCb=e,this.pending){const t=this.pending;this.pending=null,e(t)}}onBeats(e){this.beatsCb=e}onSignal(e){this.signalCb=e}}async function p1(i,e=""){const t=await fetch(`${e}/api/replay/${encodeURIComponent(i)}`);if(!t.ok)throw new Error(`session not found: ${i}`);const s=await t.json();return new dh({world:s.world,events:s.events,beats:s.beats,repoId:s.title?`${s.repoId} — ${s.title}`:s.repoId})}function m1(i,e,t){const s=n=>e.places.find(o=>o.id===n)?.label??n.replace(/^p:/,""),r=i.actor==="pip"?"Pip":t?`A helper (${t})`:"A helper";switch(i.kind){case"curtain_up":return`${i.repoId}. Every building on this stage is a file in the repo.`;case"curtain_down":return i.verified?"Curtain. Every claim in this session was backed by a passing test.":"Curtain. Something was called done without a passing test to show for it.";case"walk_to":return`${r} heads to ${s(i.target)}.`;case"read":return`${r} reads ${s(i.target)}.`;case"build":return`${r} is working on ${s(i.target)}${i.intensity>.6?" — a big change":""}.`;case"raise":return`A new file rises: ${s(i.target)}.`;case"forge":return`${r} runs a command at the forge.`;case"search":return i.scope==="web"?`${r} looks something up on the web.`:`${r} searches the repo.`;case"run_tests":return`Running the tests at ${s(i.target)}…`;case"test_outcome":return i.outcome==="pass"?`${i.passed} tests pass.`:i.outcome==="fail"?`${i.failed} test${i.failed===1?"":"s"} fail${i.failed===1?"s":""}.`:"Tests ran — the runner didn't say how many.";case"spawn_gremlin":return`A bug gremlin pops out of ${s(i.target)}.`;case"chase":return`${r} chases the gremlin around ${s(i.target)}.`;case"banish":return"Caught. The gremlin is gone.";case"summon_helper":return`A helper arrives at the dock${i.label?` to ${i.label.toLowerCase()}`:""}.`;case"dismiss_helper":return i.ok?"The helper reports back and leaves.":"The helper leaves without finishing.";case"blocked_on_you":return i.reason==="permission"?"Pip needs your permission to continue.":"Pip has a question for you.";case"your_turn":return"Pip is done for now. Your turn.";case"stumble":return i.retrying?"Something went wrong. Pip tries again.":"Something went wrong.";case"celebrate":return"All green. Pip celebrates.";case"idle":return"";case"unverified_claim":return"Pip says it's done — but no test has passed since the last change. Something's hiding."}}function g1(i){if(!i.length)return[{label:"Scene",fromMs:0,toMs:0}];const e=Math.max(...i.map(l=>l.atMs+l.durationMs));let t=0,s=!1;const r=[];for(const l of i){let h=null;switch(l.kind){case"curtain_up":h="Arrive";break;case"curtain_down":h="Curtain";break;case"read":case"search":h=t?"Fix":s?"Explore":"Arrive",s=!0;break;case"build":case"raise":case"forge":h=t?"Fix":"Build";break;case"run_tests":h=t?"Fix":"Build";break;case"test_outcome":{h=l.outcome==="fail"?"Trouble":"Finale";const c=r.at(-1);c&&c.kind==="run_tests"&&(c.phase=h);break}case"spawn_gremlin":t++,h="Trouble";break;case"chase":h="Fix";break;case"banish":t=Math.max(0,t-1),h="Finale";break;case"celebrate":h="Finale";break;case"summon_helper":case"dismiss_helper":h="Help";break;case"blocked_on_you":h="Waiting";break;case"unverified_claim":h="Hmm";break;case"stumble":h="Trouble";break;case"your_turn":case"walk_to":case"idle":h=null;break}h&&r.push({phase:h,at:l.atMs,end:l.atMs+l.durationMs,kind:l.kind})}const n=[];for(const l of r){const h=n.at(-1);h&&h.phase===l.phase?h.to=Math.max(h.to,l.end):n.push({phase:l.phase,from:h?h.to:0,to:l.end})}n.length&&(n[0].from=0,n.at(-1).to=e);const o=2200;for(let l=n.length-1;l>=0&&n.length>1;l--){const h=n[l];h.to-h.from>=o||(l>0?(n[l-1].to=h.to,n.splice(l,1)):(n[1].from=h.from,n.splice(0,1)))}const a=n.at(-1);return a&&a.phase==="Curtain"&&n.length>1&&(n[n.length-2].to=a.to,n.pop()),n.map(l=>({label:l.phase==="Curtain"?"Finale":l.phase,fromMs:l.from,toMs:l.to}))}const Hn=i=>{const e=Math.floor(i/1e3);return`${Math.floor(e/60)}:${String(e%60).padStart(2,"0")}`},Wn=i=>`#${i.toString(16).padStart(6,"0")}`,$=(i,e,t)=>{const s=document.createElement(i);return e&&(s.className=e),t!==void 0&&(s.innerHTML=t),s},_1='<svg viewBox="0 0 16 16" fill="currentColor"><path d="M4.5 2.8v10.4a.6.6 0 0 0 .9.5l8.3-5.2a.6.6 0 0 0 0-1L5.4 2.3a.6.6 0 0 0-.9.5z"/></svg>',yu='<svg viewBox="0 0 16 16" fill="currentColor"><rect x="3.5" y="3" width="3" height="10" rx="1"/><rect x="9.5" y="3" width="3" height="10" rx="1"/></svg>',y1='<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M3 8.5l3.2 3L13 4.5"/></svg>';class x1{constructor(e,t){this.h=t,this.root=$("div","wrap");const s=$("header"),r=$("div","brand",'<a class="eyebrow" href="https://agenttheatre.dev/" title="Back to agenttheatre.dev">← Agent Theatre</a><h1 id="title">Loading…</h1>'),n=$("div","toolbar");this.setBtn=$("button","btn ghost","Set"),this.setBtn.type="button",this.setBtn.onclick=()=>this.showPicker(!0),this.muteBtn=$("button","btn ghost","Effects on"),this.muteBtn.type="button",this.muteBtn.title="Sound effects",this.muteBtn.onclick=()=>t.onMute(),this.ambBtn=$("button","btn ghost","Ambience on"),this.ambBtn.type="button",this.ambBtn.title="Background sound",this.ambBtn.onclick=()=>t.onAmbience(),this.overviewBtn=$("button","btn ghost","Whole repo"),this.overviewBtn.type="button",this.overviewBtn.title="Pull back to see every building (follow camera off)",this.overviewBtn.onclick=()=>{this.overviewOn=!this.overviewOn,this.overviewBtn.textContent=this.overviewOn?"Follow":"Whole repo",this.overviewBtn.setAttribute("aria-pressed",String(this.overviewOn)),t.onOverview(this.overviewOn)},this.exportBtn=$("button","btn ghost","Export clip"),this.exportBtn.type="button",this.exportBtn.title="Record the stage (with sound) to a .webm you can share",this.exportBtn.onclick=()=>t.onExport(),n.append(this.setBtn,this.overviewBtn,this.muteBtn,this.ambBtn,this.exportBtn),this.nudge=$("div","nudge","Sound is off — turn on effects and ambience to hear the stage"),this.nudge.hidden=!0,n.append(this.nudge),s.append(r,n);const o=$("div","grid"),a=$("div","stage-col");this.stageEl=$("div","stage"),this.overlay=$("div","overlay"),this.bubbleEl=$("div","bubble"),this.bubbleEl.hidden=!0,this.overlay.append(this.bubbleEl),this.signal=$("div","signal","<i></i><span>live</span>"),this.signal.hidden=!0,this.chip=$("div","chip ok"),this.chip.hidden=!0,this.caption=$("div","caption","<span></span>"),this.title=$("div","card",'<div class="small">Agent Theatre</div><div class="big" id="titleBig">…</div>'),this.end=$("div","card",'<div class="big">Every agent run has a story.</div><div class="small">Agent Theatre</div>'),this.end.style.opacity="0",this.picker=$("div","picker"),this.picker.hidden=!0,this.waiting=$("div","waiting",'<div class="wt"><b></b><span></span></div><button type="button" class="go"></button>'),this.waiting.hidden=!0,this.vscode=globalThis.__vsapi??null,this.waiting.querySelector(".go").onclick=()=>{this.vscode?this.vscode.postMessage({type:"focus-agent"}):this.notify()},this.prompt=$("form","prompt",'<input type="text" placeholder="" autocomplete="off" spellcheck="false"><button type="submit">Send</button><span class="st"></span>'),this.prompt.hidden=!0,this.prompt.addEventListener("submit",f=>{f.preventDefault();const p=this.prompt.querySelector("input"),g=this.prompt.querySelector(".st"),m=p.value.trim();m&&(g.textContent="sending…",t.onPrompt(m).then(_=>{g.textContent=_,p.value=""}))}),this.stageEl.append($("div","vignette"),this.overlay,this.signal,this.chip,this.caption,this.title,this.end,this.picker,this.waiting,this.prompt),this.stageEl.addEventListener("wheel",f=>{!f.ctrlKey&&Math.abs(f.deltaY)<1||(f.preventDefault(),t.onZoom(Math.exp(-f.deltaY*.0015)))},{passive:!1});const l=$("div","controls");this.playBtn=$("button","btn",`${yu}<span>Pause</span>`),this.playBtn.type="button",this.playBtn.onclick=()=>t.onPlayPause();const h=$("div","track");this.actsEl=$("div","acts"),this.labelsEl=$("div","actlabels"),this.head=$("div","head"),h.append(this.actsEl,this.labelsEl,this.head),h.addEventListener("pointerdown",f=>{const p=this.actsEl.getBoundingClientRect(),g=(f.clientX-p.left)/p.width;t.onSeek(g*this.durationMs)}),this.time=$("div","time","0:00 / 0:00"),this.rateBtn=$("button","btn ghost","1×"),this.rateBtn.type="button",this.rateBtn.onclick=()=>t.onRate(),l.append(this.playBtn,h,this.time,this.rateBtn),a.append(this.stageEl,l);const c=$("aside"),u=$("section","panel",'<h2>Event log</h2><p class="sub">Every scene is driven by one of these agent events. Tap one to jump there.</p>');this.logEl=$("ul","log"),u.append(this.logEl);const d=$("section","panel",`<h2>How to read the stage</h2><p class="sub">Buildings are files, districts are folders, beacons are test suites. Gremlins are failing tests. The lead character is the agent; its light shows its mood. Helpers are subagents. If the agent says it's done without a passing test, something hides behind it.</p>`);c.append(u,d),o.append(a,c),this.root.append(s,o,$("p","note","Everything you see is generated locally from agent events. No code, prompts or file contents are shown or sent anywhere.")),e.append(this.root)}root;stageEl;nudge;showNudge(){this.nudge.hidden=!1}showShare(e){const t=URL.createObjectURL(e.blob),s=new File([e.blob],e.name,{type:e.blob.type}),r=typeof navigator.share=="function"&&typeof navigator.canShare=="function"&&navigator.canShare({files:[s]}),n=$("div","share",`<div class="sh-head"><b>Your clip is ready</b><span>${(e.blob.size/1048576).toFixed(1)} MB · ${e.name.split(".").pop()}</span></div>
956
970
  <div class="sh-row"><a class="btn primary" download="${e.name}" href="${t}">Download</a>${r?'<button type="button" class="btn ghost" data-act="share">Share…</button>':""}<a class="btn ghost" target="_blank" rel="noopener" href="https://x.com/intent/post?text=${encodeURIComponent(e.caption)}">Post on X</a><a class="btn ghost" target="_blank" rel="noopener" href="https://www.linkedin.com/feed/?shareActive=true&text=${encodeURIComponent(e.caption)}">Post on LinkedIn</a><button type="button" class="btn ghost" data-act="caption">Copy caption</button><button type="button" class="btn ghost" data-act="close">Close</button></div>
957
- <p class="sh-note">Posts open with the caption; attach the downloaded clip there.</p>`);n.addEventListener("click",o=>{const a=o.target.closest("[data-act]")?.getAttribute("data-act");a==="share"&&navigator.share({files:[s],title:"Agent Theatre",text:e.caption}).catch(()=>{}),a==="caption"&&navigator.clipboard?.writeText(e.caption),a==="close"&&(n.remove(),setTimeout(()=>URL.revokeObjectURL(t),1e3))}),this.stageEl.append(n)}nudgeSeen(){this.nudge.hidden=!0;try{localStorage.setItem("at:nudged","1")}catch{}}overviewBtn;overviewOn=!1;exportBtn;prompt;waiting;vscode;notifiedFor="";overlay;caption;chip;signal;title;end;picker;playBtn;rateBtn;muteBtn;ambBtn;setBtn;actsEl;labelsEl;head;time;logEl;acts=[];actBtns=[];actLabels=[];logBtns=[];lastCaption="";lastBeatId="";lastAct=-1;lastEv=-2;tagPool=[];bubbleEl;durationMs=0;repoId="";promptEnabled=!1;setTitle(e,t){const s=e.replace(/\/+$/,"").split(/[/\\]/).filter(Boolean).pop()??e,r=this.root.querySelector("#title");r.textContent=s,r.title=e,this.root.querySelector("#titleBig").textContent=t??s}setMuted(e){this.muteBtn.textContent=e?"Effects off":"Effects on",this.muteBtn.setAttribute("aria-pressed",String(!e))}setAmbience(e){this.ambBtn.textContent=e?"Ambience on":"Ambience off",this.ambBtn.setAttribute("aria-pressed",String(e))}setRate(e){this.rateBtn.textContent=`${e}×`}loadTimeline(e,t,s){this.durationMs=e.length?Math.max(...e.map(n=>n.atMs+n.durationMs)):0,this.acts=Yb(e),this.actsEl.innerHTML="",this.labelsEl.innerHTML="",this.actBtns=[],this.actLabels=[];for(const n of this.acts){const o=(n.toMs-n.fromMs)/Math.max(1,this.durationMs)*100,a=$("button");a.type="button",a.style.flex=`0 0 calc(${o}% - 3px)`,a.setAttribute("aria-label",`Jump to ${n.label}`),a.onclick=h=>{h.stopPropagation(),this.h.onSeek(n.fromMs+1)};const l=$("span","",n.label);l.style.flex=`0 0 calc(${o}% - 3px)`,this.actsEl.append(a),this.labelsEl.append(l),this.actBtns.push(a),this.actLabels.push(l)}this.logEl.innerHTML="",this.logBtns=[],t[0]?.ts;const r=n=>e.find(o=>o.sourceEventIds.includes(n));for(const n of t){if(n.kind==="session_start"||n.kind==="session_end")continue;const o=r(n.id);if(!o)continue;const a=$("li"),l=$("button");l.type="button";const[h,c]=Jb(n),u=n.kind==="test_result"&&!n.ok;l.innerHTML=`<time>${Dn(o.atMs)}</time><span class="dot k-${n.kind}${u?" fail":""}"></span><span class="ev"><b>${mu(h)}</b><code>${mu(c)}</code></span>`,l.onclick=()=>this.h.onSeek(o.atMs+1),a.append(l),this.logEl.append(a),this.logBtns.push({btn:l,ms:o.atMs})}}previews=new Map;get pickerOpen(){return!this.picker.hidden}profile;leadName="Pip";showAll=!1;showPicker(e,t){if(this.picker.hidden=!e,!e)return;this.picker.innerHTML="";const s=this.profile?.kinds?.[0],r=s&&s!=="unknown"?{"web-frontend":"a web app","backend-api":"a backend","cli-tool":"a CLI",library:"a library","data-ml":"data & ML work",mobile:"a mobile app",game:"a game","infra-devops":"infrastructure","docs-content":"documentation",monorepo:"a monorepo",systems:"systems code"}[s]:null,n=Fo(this.profile,e1(this.repoId)).slice(0,3),o=this.showAll?[...Ct]:n;this.picker.append($("h3","",this.showAll?"All sets":"Choose your set"),$("p","",r&&!this.showAll?`This looks like ${r}${this.profile?.languages?.[0]?` in ${this.profile.languages[0]}`:""}. These stages suit it — or browse them all.`:"Same repo, same story — pick the stage. You can change it any time."));const a=$("div","setcards");for(const u of o){const d=$("button","setcard");d.type="button";const f=this.previews.get(u.id);d.innerHTML=`<div class="sw" style="--a:${Fn(u.sky[0])};--b:${Fn(u.palettes[0].left)}">${f?`<img src="${f}" alt="" />`:""}</div><div class="nm">${u.name}${u.id===t?" ✓":""}</div><div class="tg">${u.tagline}</div>`,d.onclick=()=>{this.h.onPickSet(u.id),this.showPicker(!1)},a.append(d)}const l=$("div","toolbar"),h=$("button","btn ghost","Surprise me");h.type="button",h.onclick=()=>this.h.onShuffle();const c=$("button","btn ghost",this.showAll?"Suggested":`All ${Ct.length} sets`);c.type="button",c.onclick=()=>{this.showAll=!this.showAll,this.showPicker(!0,t)},l.append(h,c),this.picker.append(a,l)}update(e,t,s,r){this.time.textContent=`${Dn(e.t)} / ${Dn(e.duration)}`,this.head.style.left=`${e.t/Math.max(1,e.duration)*100}%`,this.playBtn.innerHTML=e.playing?`${pu}<span>Pause</span>`:`${Kb}<span>${e.t>=e.duration-1?"Replay":"Play"}</span>`;const n=e.current;this.title.style.opacity=String(n&&n.kind==="curtain_up"?1-Math.min(1,Math.max(0,(e.t-n.atMs-600)/700)):e.t<600?1:0);const o=n&&n.kind==="curtain_down"?n:null;this.end.style.opacity=String(o?Math.min(1,Math.max(0,(e.t-o.atMs-400)/600)):0);const a=n?qb(n,t,r).replace(/\bPip\b/g,this.leadName):"";n&&n.id!==this.lastBeatId&&(this.lastBeatId=n.id,a&&(this.lastCaption=a));const l=this.caption.firstElementChild;l.textContent=this.lastCaption,l.style.opacity=this.lastCaption&&!(n?.kind==="curtain_up"&&e.t-(n?.atMs??0)<900)?"1":"0",e.evidence?(this.chip.hidden=!1,this.chip.className="chip ok",this.chip.innerHTML=`${Zb}Evidence · ${e.evidence.passed} tests passed`):n?.kind==="unverified_claim"||n?.kind==="curtain_down"&&!n.verified?(this.chip.hidden=!1,this.chip.className="chip warn",this.chip.textContent="No test evidence"):this.chip.hidden=!0;const h=this.liveMode&&n?.kind==="your_turn"&&this.promptEnabled;this.prompt.hidden=!h,h&&(this.prompt.querySelector("input").placeholder=`${this.leadName||"The agent"} is done. What's next?`);const c=this.liveMode&&n?.kind==="blocked_on_you";if(this.waiting.hidden=!c,c&&n?.kind==="blocked_on_you"){const m=n.reason==="permission"?"needs your permission to continue":"has a question for you";this.waiting.querySelector("b").textContent=`${this.leadName||"The agent"} ${m}.`,this.waiting.querySelector("span").textContent=this.vscode?"Answer in Claude Code.":"Answer in the terminal or editor where Claude Code is running.",this.waiting.querySelector(".go").textContent=this.vscode?"Go to Claude Code":"Notify me next time",this.notifiedFor!==n.id&&(this.notifiedFor=n.id,!this.vscode&&"Notification"in globalThis&&Notification.permission==="granted"&&new Notification("Agent Theatre",{body:`${this.leadName||"The agent"} ${m}.`}))}if(this.liveMode&&e.duration===0){const m=(this.repoId||"this folder").split(/[/\\]/).filter(Boolean).pop();this.caption.hidden=!1,this.caption.firstElementChild.textContent=`Waiting for a Claude Code session in ${m}. Run \`claude\` in that folder and the stage comes alive.`}this.signal.hidden=e.signal==="ok"||!this.liveMode,this.signal.className=`signal ${e.signal}`,this.signal.lastElementChild.textContent=e.signal==="lost"?"quiet — no events for 90 s":"live";let u=0;this.acts.forEach((m,_)=>{e.t>=m.fromMs&&(u=_)}),u!==this.lastAct&&(this.lastAct=u,this.actBtns.forEach((m,_)=>{m.classList.toggle("on",_<u),m.classList.toggle("now",_===u)}),this.actLabels.forEach((m,_)=>m.classList.toggle("now",_===u)));let d=-1;this.logBtns.forEach((m,_)=>{e.t>=m.ms&&(d=_)}),d!==this.lastEv&&(this.lastEv=d,this.logBtns.forEach((m,_)=>{m.btn.classList.toggle("done",_<d),m.btn.classList.toggle("now",_===d)}),this.logBtns[d]?.btn.scrollIntoView({block:"nearest",behavior:"smooth"}));const p=this.stageEl.getBoundingClientRect().width<600,g=e.labels.filter(m=>m.active||!p).sort((m,_)=>m.screen.y-_.screen.y||m.screen.x-_.screen.x);for(let m=0;m<g.length;m++)for(let _=0;_<m;_++){const y=g[_],x=g[m];Math.abs(y.screen.x-x.screen.x)<76&&Math.abs(y.screen.y-x.screen.y)<20&&(x.screen={x:x.screen.x,y:y.screen.y-20})}for(;this.tagPool.length<g.length;){const m=$("div","tag");this.overlay.append(m),this.tagPool.push(m)}this.tagPool.forEach((m,_)=>{const y=g[_];if(!y){m.hidden=!0;return}m.hidden=!1,m.textContent=y.text;const x=t.places.find(v=>v.label===y.text)?.id??"",b=s(x);m.className=`tag${y.active?" active":""}${b!=="idle"?` lamp-${b}`:""}`,m.style.left=`${y.screen.x}px`,m.style.top=`${y.screen.y}px`}),e.bubble?(this.bubbleEl.hidden=!1,this.bubbleEl.textContent=e.bubble.text,this.bubbleEl.style.color=Fn(e.bubble.color),this.bubbleEl.style.left=`${e.bubble.screen.x}px`,this.bubbleEl.style.top=`${e.bubble.screen.y}px`,this.bubbleEl.classList.toggle("pulse",n?.kind==="blocked_on_you")):this.bubbleEl.hidden=!0}liveMode=!1;async notify(){if(!("Notification"in globalThis))return;(Notification.permission==="default"?await Notification.requestPermission():Notification.permission)==="granted"&&new Notification("Agent Theatre",{body:"You'll get a notification whenever the agent waits on you."})}}function Jb(i,e){const t=s=>s.split("/").pop()??s;switch(i.kind){case"read_file":return["Read",i.path];case"edit_file":return["Edit",`${i.path} · +${i.added} −${i.removed}`];case"write_file":return[i.created?"Create":"Write",i.path];case"run_command":return[i.intent==="test"?"Run tests":i.intent==="git"?"Git":i.intent==="build"?"Build":i.intent==="install"?"Install":"Run",`${i.argv0}${i.touched.length?" · "+i.touched.map(t).join(", "):""}`];case"test_result":return[i.ok?`${i.passed} passed`:`${i.failed} failed`,i.framework?`${i.framework}`:""];case"search":return["Search",i.scope];case"subagent_start":return["Helper",i.label??i.childId];case"subagent_stop":return["Helper done",i.childId];case"waiting_for_user":return[i.reason==="permission"?"Needs permission":i.reason==="question"?"Has a question":"Waiting",""];case"error":return["Error",i.where];case"turn_end":return[i.claimedSuccess?"Says it's done":"Turn ends",""];default:return[i.kind,""]}}const e1=i=>{let e=2166136261;for(let t=0;t<i.length;t++)e^=i.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0},mu=i=>i.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]??e);async function t1(i,e,t,s=360,r=200){const n=new Eg(e,t);n.update(0);const o=new _e,a=e.places.flatMap(g=>[K(g.gx,g.gy),K(g.gx+g.footprint,g.gy+g.footprint)]),l=a.map(g=>g.x),h=a.map(g=>g.y),c=Math.max(...l)-Math.min(...l)+160,u=Math.max(...h)-Math.min(...h)+170,d=Math.min(s/c,r/u);o.scale.set(d),o.position.set(s/2-(Math.min(...l)+Math.max(...l))/2*d,r/2-((Math.min(...h)+Math.max(...h))/2-20)*d),o.addChild(n.container);const f=Ti.create({width:s,height:r,resolution:1});i.renderer.render({container:o,target:f,clear:!0,clearColor:t.sky[1]});const p=await i.renderer.extract.base64(f);return f.destroy(!0),n.destroy(),o.destroy({children:!0}),p}const ne=new URLSearchParams(globalThis.__AT_QUERY??location.search),Is=ne.get("base")??"",Ss=globalThis.acquireVsCodeApi?.()??null;globalThis.__vsapi=Ss;const Xi=matchMedia("(prefers-reduced-motion: reduce)").matches,tt={get:i=>{try{return localStorage.getItem(i)}catch{return null}},set:(i,e)=>{try{localStorage.setItem(i,e)}catch{}}};async function s1(i){try{const e=await(await fetch("/demo/demos.json")).json();return i==="any"?e[Math.floor(Math.random()*e.length)]??null:e.find(t=>t.id===i)??null}catch{return null}}async function i1(i){const e=await s1(i);e&&(i=e.id,ne.has("episode")||ne.set("episode",`${e.title} · ${e.kind}`),!ne.has("set")&&ne.has("cinema")&&ne.set("set",e.set));const t=await(await fetch(`/demo/${i}.jsonl`)).text(),{events:s}=Wx(t),r=tb(s);let n=r.files,o=s[0]?.repoId??i;try{const h=await(await fetch(`/demo/${i}.files.json`)).json();if(Array.isArray(h.files)){const c=new Set(h.files.map(u=>u.path));n=[...h.files,...r.files.filter(u=>!c.has(u.path))],h.repoId&&(o=h.repoId)}}catch{}const a=Zx({repoId:o,files:n,touched:r.touched}),l=tr(s,a);return new ch({world:a,events:s,beats:l,repoId:o})}async function r1(i,e){const t=new sb;let s=()=>{};const r=async()=>{await t.arm(),t.ready&&a?.audioReady()};let n=!1;for(const I of["pointerdown","keydown"])addEventListener(I,()=>{t.ready||(n=!0,setTimeout(()=>{n=!1},700),r())},{passive:!0});let o=sr(ne.get("set")),a=null,l=Number(ne.get("rate"))||1,h=tt.get("at:muted")!=="0",c=tt.get("at:ambience")==="1";t.setMuted(h),t.setAmbienceEnabled(c);const u=new Qb(i,{onPlayPause:()=>{a&&(r(),a.playing?a.pause():(a.state.t>=a.state.duration-1&&a.seek(0),a.play()))},onSeek:I=>{a?.seek(I)},onRate:()=>{l=l>=4?1:l*2,a?.setRate(l),u.setRate(l)},onMute:()=>{if(!t.ready||n){r(),h&&(h=!1,t.setMuted(!1),tt.set("at:muted","0"),u.setMuted(!1)),u.nudgeSeen();return}h=!h,u.nudgeSeen(),t.setMuted(h),tt.set("at:muted",h?"1":"0"),u.setMuted(h)},onAmbience:()=>{if(!t.ready||n){r(),c||(c=!0,t.setAmbienceEnabled(!0),tt.set("at:ambience","1"),u.setAmbience(!0)),u.nudgeSeen();return}c=!c,u.nudgeSeen(),t.setAmbienceEnabled(c),tt.set("at:ambience",c?"1":"0"),u.setAmbience(c)},onPickSet:I=>{o=sr(I),a&&(tt.set(`at:set:${a.world.repoId}`,I),v())},onOverview:I=>{a?.setOverview(I),s()},onZoom:I=>{a?.zoomBy(I),s()},onExport:()=>{p()},onPrompt:async I=>{if(Ss)return Ss.postMessage({type:"prompt",text:I}),"sent — watch the stage";try{const P=await fetch(`${Is}/api/prompt`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:I})}),C=await P.json();return C.ok?"sent — watch the stage":`couldn't send: ${C.error??P.status}`}catch(P){return`couldn't send: ${String(P)}`}},onShuffle:()=>{const I=Fo(m?.world.profile).filter(C=>C.id!==o.id),P=I.slice(0,Math.max(3,Math.min(5,I.length)));o=P[Math.floor(Math.random()*P.length)]??Ct[0],a&&(tt.set(`at:set:${a.world.repoId}`,o.id),v()),u.showPicker(!1)}});u.setMuted(h),u.setAmbience(c),u.setRate(l),h&&c===!1&&!tt.get("at:nudged")&&u.showNudge(),u.liveMode=e.mode==="live";const d=ne.has("cinema");d&&(document.documentElement.classList.add("cinema"),h=!0,t.setMuted(!0));let f=null;async function p(){if(f){f.stop();return}await r();const P=g.canvas.captureStream(30),C=t.captureStream();if(C)for(const N of C.getAudioTracks())P.addTrack(N);const D=[],R=["video/mp4;codecs=avc1.42E01E,mp4a.40.2","video/mp4","video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"].find(N=>MediaRecorder.isTypeSupported(N))??"",L=R.startsWith("video/mp4")?"mp4":"webm";f=new MediaRecorder(P,R?{mimeType:R,videoBitsPerSecond:6e6}:void 0),f.ondataavailable=N=>{N.data.size&&D.push(N.data)},f.onstop=()=>{f=null,u.exportBtn.textContent="Export clip";const N=new Blob(D,{type:R.split(";")[0]||"video/webm"}),se=`agent-theatre-${(m?.repoId??"stage").split(/[/\\]/).pop()}-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.${L}`,Q=`${a?.leadName??"The agent"} on the ${o.name} stage — ${(m?.repoId??"my repo").split(/[/\\]/).pop()} in Agent Theatre. Watch your coding agent work, as a film, not a log. https://agenttheatre.dev`;u.showShare({blob:N,name:se,caption:Q})},f.start(500),u.exportBtn.textContent="■ Stop & save",a&&!a.playing&&a.play()}const g=new ha;await g.init({resizeTo:u.stageEl,antialias:!0,backgroundAlpha:1,background:o.sky[1],preference:"webgl",resolution:Math.min(2,devicePixelRatio||1),autoDensity:!0}),u.stageEl.prepend(g.canvas);let m=null;const _=(I,P)=>Qx(I,vi[(I.seed+Ct.findIndex(C=>C.id===P.id)*7)%vi.length]);let y=0,x=!1,b="";function v(){if(!m)return;a&&(y=a.state.t,x=a.playing,a.destroy()),g.renderer.background.color=o.sky[1];const I=_(m.world,o),P=I===m.world?m.beats:tr(m.events,I);a=new Ys(g,I,o,t,Xi,ne.get("cast")??tt.get(`at:cast:${m.repoId}`)),globalThis.__agentTheatre={app:g,get player(){return a},panel:u},u.leadName=a.leadName,a.load(P),a.setRate(l),a.theme.id!==b?(a.seek(0),a.play()):(a.seek(y),x&&a.play()),b=a.theme.id,u.loadTimeline(P,m.events,I)}e.onReady(I=>{m=I;const P=tt.get(`at:set:${I.repoId}`),C=ne.get("set")??P;u.profile=I.world.profile,u.repoId=I.repoId,C?o=sr(C):o=Fo(I.world.profile,I.world.seed)[0]??Ct[0],u.setTitle(I.repoId,ne.get("episode")??void 0),Ss?u.promptEnabled=!0:e.mode==="live"&&fetch(`${Is}/api/prompt`).then(L=>L.json()).then(L=>{u.promptEnabled=!!L.available}).catch(()=>{}),u.loadTimeline(I.beats,I.events,I.world),v();const D=Number(ne.get("t"));D>0&&a&&a.seek(D*1e3);const R=(async()=>{if(!ne.has("nopreview")){for(const L of Ct)try{u.previews.set(L.id,await t1(g,_(I.world,L),L))}catch(N){console.warn("set preview failed",L.id,N)}u.pickerOpen&&u.showPicker(!0,o.id),s()}})();!C&&!ne.has("t")&&R.then(()=>u.showPicker(!0,o.id)),ne.get("paused")!=="1"&&!Xi&&a?.play(),d&&a&&!Xi&&a.play(),Xi&&!ne.has("t")&&a?.seek(Math.min(a.state.duration,25400))}),e.onBeats((I,P)=>{if(!(!a||!m)){if(m.beats.push(...I),m.events.push(...P),a.world===m.world)a.append(I);else{const C=tr(m.events,a.world);a.append(C.slice(a.beatCount))}u.loadTimeline(a.world===m.world?m.beats:tr(m.events,a.world),m.events,a.world),a.playing||a.play(),s()}}),e.onSignal?.(I=>a?.setSignal(I));const w=Number(ne.get("step"))||0;let T=performance.now(),k=0,E=!1,A=null;const M=I=>{E=!1;const P=w||Math.min(50,I-T);T=I,a&&!document.hidden&&((d||ne.has("loop"))&&a.state.t>=a.state.duration-1&&a.state.duration>0&&(A||(A=setTimeout(()=>{A=null,a?.seek(0),a?.play()},600))),a.update(P),u.update(a.state,a.world,C=>a.worldLayer.lampOf(C)),a.playing?k=45:k--),(a?.playing||k>0)&&!document.hidden&&B()},B=()=>{E||(E=!0,requestAnimationFrame(M))};s=()=>{k=45,T=performance.now(),B()},s();for(const I of["pointerdown","keydown","resize"])addEventListener(I,s,{passive:!0});document.addEventListener("visibilitychange",()=>{document.hidden||s()});const G=Ys.prototype.play;Ys.prototype.play=function(){G.call(this),s()};const O=Ys.prototype.seek;Ys.prototype.seek=function(I){O.call(this,I),s()}}async function n1(i){const{Application:e}=await St(async()=>{const{Application:l}=await Promise.resolve().then(()=>wx);return{Application:l}},void 0),{Pip:t}=await St(async()=>{const{Pip:l}=await Promise.resolve().then(()=>_b);return{Pip:l}},void 0),{castById:s,CAST:r}=await St(async()=>{const{castById:l,CAST:h}=await Promise.resolve().then(()=>gb);return{castById:l,CAST:h}},void 0),n=s(i)??r[0],o=sr(ne.get("set")??"island");document.documentElement.style.background="transparent",document.body.style.background="transparent",document.body.style.margin="0";const a=new e;if(await a.init({width:320,height:320,backgroundAlpha:0,antialias:!0,resolution:2,autoDensity:!0,preference:"webgl"}),document.body.replaceChildren(a.canvas),i==="gremlin"){const{Gremlin:l}=await St(async()=>{const{Gremlin:c}=await Promise.resolve().then(()=>pb);return{Gremlin:c}},void 0),h=new l("g",o,!1);h.scale=7,h.x=160,h.y=250,a.stage.addChild(h.container),a.ticker.add(c=>h.update(c.deltaMS))}else{const l=new t(o,!1,n);l.container.scale.set(6*n.size),l.pose.x=160,l.pose.y=272,a.stage.addChild(l.container),l.pose.mood=ne.get("mood")??"curious",a.ticker.add(h=>l.update(h.deltaMS))}globalThis.__agentTheatre={app:a,player:!0}}const On=document.getElementById("app"),o1=ne.has("portrait")?Promise.resolve(new ch({world:null,events:[],beats:[],repoId:""})):Ss&&(ne.has("live")||ne.get("session"))?Promise.resolve(new jb(Ss,ne.get("session"))):ne.has("live")?Promise.resolve(new Vb(Is)):ne.get("session")?Xb(ne.get("session"),Is):i1(ne.get("demo")??"episode-1");ne.has("portrait")?n1(ne.get("portrait")).catch(i=>{On.textContent=`Could not start: ${i}`}):o1.then(i=>r1(On,i)).catch(i=>{On.textContent=`Could not start: ${i}${Is?` (server: ${Is})`:""}`});export{C_ as A,_e as C,Hf as D,Wf as E,ty as F,M_ as a,Kf as b,Vf as c,Yf as d,q as e};
958
- //# sourceMappingURL=index-vIjrCnHW.js.map
971
+ <p class="sh-note">Posts open with the caption; attach the downloaded clip there.</p>`);n.addEventListener("click",o=>{const a=o.target.closest("[data-act]")?.getAttribute("data-act");a==="share"&&navigator.share({files:[s],title:"Agent Theatre",text:e.caption}).catch(()=>{}),a==="caption"&&navigator.clipboard?.writeText(e.caption),a==="close"&&(n.remove(),setTimeout(()=>URL.revokeObjectURL(t),1e3))}),this.stageEl.append(n)}nudgeSeen(){this.nudge.hidden=!0;try{localStorage.setItem("at:nudged","1")}catch{}}overviewBtn;overviewOn=!1;exportBtn;prompt;waiting;vscode;notifiedFor="";overlay;caption;chip;signal;title;end;picker;playBtn;rateBtn;muteBtn;ambBtn;setBtn;actsEl;labelsEl;head;time;logEl;acts=[];actBtns=[];actLabels=[];logBtns=[];lastCaption="";lastBeatId="";lastAct=-1;lastEv=-2;tagPool=[];bubbleEl;durationMs=0;repoId="";promptEnabled=!1;setTitle(e,t){const s=e.replace(/\/+$/,"").split(/[/\\]/).filter(Boolean).pop()??e,r=this.root.querySelector("#title");r.textContent=s,r.title=e,this.root.querySelector("#titleBig").textContent=t??s}setMuted(e){this.muteBtn.textContent=e?"Effects off":"Effects on",this.muteBtn.setAttribute("aria-pressed",String(!e))}setAmbience(e){this.ambBtn.textContent=e?"Ambience on":"Ambience off",this.ambBtn.setAttribute("aria-pressed",String(e))}setRate(e){this.rateBtn.textContent=`${e}×`}loadTimeline(e,t,s){this.durationMs=e.length?Math.max(...e.map(n=>n.atMs+n.durationMs)):0,this.acts=g1(e),this.actsEl.innerHTML="",this.labelsEl.innerHTML="",this.actBtns=[],this.actLabels=[];for(const n of this.acts){const o=(n.toMs-n.fromMs)/Math.max(1,this.durationMs)*100,a=$("button");a.type="button",a.style.flex=`0 0 calc(${o}% - 3px)`,a.setAttribute("aria-label",`Jump to ${n.label}`),a.onclick=h=>{h.stopPropagation(),this.h.onSeek(n.fromMs+1)};const l=$("span","",n.label);l.style.flex=`0 0 calc(${o}% - 3px)`,this.actsEl.append(a),this.labelsEl.append(l),this.actBtns.push(a),this.actLabels.push(l)}this.logEl.innerHTML="",this.logBtns=[],t[0]?.ts;const r=n=>e.find(o=>o.sourceEventIds.includes(n));for(const n of t){if(n.kind==="session_start"||n.kind==="session_end")continue;const o=r(n.id);if(!o)continue;const a=$("li"),l=$("button");l.type="button";const[h,c]=b1(n),u=n.kind==="test_result"&&!n.ok;l.innerHTML=`<time>${Hn(o.atMs)}</time><span class="dot k-${n.kind}${u?" fail":""}"></span><span class="ev"><b>${xu(h)}</b><code>${xu(c)}</code></span>`,l.onclick=()=>this.h.onSeek(o.atMs+1),a.append(l),this.logEl.append(a),this.logBtns.push({btn:l,ms:o.atMs})}}previews=new Map;get pickerOpen(){return!this.picker.hidden}profile;leadName="Pip";showAll=!1;showPicker(e,t){if(this.picker.hidden=!e,!e)return;this.picker.innerHTML="";const s=this.profile?.kinds?.[0],r=s&&s!=="unknown"?{"web-frontend":"a web app","backend-api":"a backend","cli-tool":"a CLI",library:"a library","data-ml":"data & ML work",mobile:"a mobile app",game:"a game","infra-devops":"infrastructure","docs-content":"documentation",monorepo:"a monorepo",systems:"systems code"}[s]:null,n=Wo(this.profile,v1(this.repoId)).slice(0,3),o=this.showAll?[...Et]:n;this.picker.append($("h3","",this.showAll?"All sets":"Choose your set"),$("p","",r&&!this.showAll?`This looks like ${r}${this.profile?.languages?.[0]?` in ${this.profile.languages[0]}`:""}. These stages suit it — or browse them all.`:"Same repo, same story — pick the stage. You can change it any time."));const a=$("div","setcards");for(const u of o){const d=$("button","setcard");d.type="button";const f=this.previews.get(u.id);d.innerHTML=`<div class="sw" style="--a:${Wn(u.sky[0])};--b:${Wn(u.palettes[0].left)}">${f?`<img src="${f}" alt="" />`:""}</div><div class="nm">${u.name}${u.id===t?" ✓":""}</div><div class="tg">${u.tagline}</div>`,d.onclick=()=>{this.h.onPickSet(u.id),this.showPicker(!1)},a.append(d)}const l=$("div","toolbar"),h=$("button","btn ghost","Surprise me");h.type="button",h.onclick=()=>this.h.onShuffle();const c=$("button","btn ghost",this.showAll?"Suggested":`All ${Et.length} sets`);c.type="button",c.onclick=()=>{this.showAll=!this.showAll,this.showPicker(!0,t)},l.append(h,c),this.picker.append(a,l)}update(e,t,s,r){this.time.textContent=`${Hn(e.t)} / ${Hn(e.duration)}`,this.head.style.left=`${e.t/Math.max(1,e.duration)*100}%`,this.playBtn.innerHTML=e.playing?`${yu}<span>Pause</span>`:`${_1}<span>${e.t>=e.duration-1?"Replay":"Play"}</span>`;const n=e.current;this.title.style.opacity=String(n&&n.kind==="curtain_up"?1-Math.min(1,Math.max(0,(e.t-n.atMs-600)/700)):e.t<600?1:0);const o=n&&n.kind==="curtain_down"?n:null;this.end.style.opacity=String(o?Math.min(1,Math.max(0,(e.t-o.atMs-400)/600)):0);const a=n?m1(n,t,r).replace(/\bPip\b/g,this.leadName):"";n&&n.id!==this.lastBeatId&&(this.lastBeatId=n.id,a&&(this.lastCaption=a));const l=this.caption.firstElementChild;l.textContent=this.lastCaption,l.style.opacity=this.lastCaption&&!(n?.kind==="curtain_up"&&e.t-(n?.atMs??0)<900)?"1":"0",e.evidence?(this.chip.hidden=!1,this.chip.className="chip ok",this.chip.innerHTML=`${y1}Evidence · ${e.evidence.passed} tests passed`):n?.kind==="unverified_claim"||n?.kind==="curtain_down"&&!n.verified?(this.chip.hidden=!1,this.chip.className="chip warn",this.chip.textContent="No test evidence"):this.chip.hidden=!0;const h=this.liveMode&&n?.kind==="your_turn"&&this.promptEnabled;this.prompt.hidden=!h,h&&(this.prompt.querySelector("input").placeholder=`${this.leadName||"The agent"} is done. What's next?`);const c=this.liveMode&&n?.kind==="blocked_on_you";if(this.waiting.hidden=!c,c&&n?.kind==="blocked_on_you"){const m=n.reason==="permission"?"needs your permission to continue":"has a question for you";this.waiting.querySelector("b").textContent=`${this.leadName||"The agent"} ${m}.`,this.waiting.querySelector("span").textContent=this.vscode?"Answer in Claude Code.":"Answer in the terminal or editor where Claude Code is running.",this.waiting.querySelector(".go").textContent=this.vscode?"Go to Claude Code":"Notify me next time",this.notifiedFor!==n.id&&(this.notifiedFor=n.id,!this.vscode&&"Notification"in globalThis&&Notification.permission==="granted"&&new Notification("Agent Theatre",{body:`${this.leadName||"The agent"} ${m}.`}))}if(this.liveMode&&e.duration===0){const m=(this.repoId||"this folder").split(/[/\\]/).filter(Boolean).pop();this.caption.hidden=!1,this.caption.firstElementChild.textContent=`Waiting for a Claude Code session in ${m}. Run \`claude\` in that folder and the stage comes alive.`}this.signal.hidden=e.signal==="ok"||!this.liveMode,this.signal.className=`signal ${e.signal}`,this.signal.lastElementChild.textContent=e.signal==="lost"?"quiet — no events for 90 s":"live";let u=0;this.acts.forEach((m,_)=>{e.t>=m.fromMs&&(u=_)}),u!==this.lastAct&&(this.lastAct=u,this.actBtns.forEach((m,_)=>{m.classList.toggle("on",_<u),m.classList.toggle("now",_===u)}),this.actLabels.forEach((m,_)=>m.classList.toggle("now",_===u)));let d=-1;this.logBtns.forEach((m,_)=>{e.t>=m.ms&&(d=_)}),d!==this.lastEv&&(this.lastEv=d,this.logBtns.forEach((m,_)=>{m.btn.classList.toggle("done",_<d),m.btn.classList.toggle("now",_===d)}),this.logBtns[d]?.btn.scrollIntoView({block:"nearest",behavior:"smooth"}));const p=this.stageEl.getBoundingClientRect().width<600,g=e.labels.filter(m=>m.active||!p).sort((m,_)=>m.screen.y-_.screen.y||m.screen.x-_.screen.x);for(let m=0;m<g.length;m++)for(let _=0;_<m;_++){const y=g[_],x=g[m];Math.abs(y.screen.x-x.screen.x)<76&&Math.abs(y.screen.y-x.screen.y)<20&&(x.screen={x:x.screen.x,y:y.screen.y-20})}for(;this.tagPool.length<g.length;){const m=$("div","tag");this.overlay.append(m),this.tagPool.push(m)}this.tagPool.forEach((m,_)=>{const y=g[_];if(!y){m.hidden=!0;return}m.hidden=!1,m.textContent=y.text;const x=t.places.find(v=>v.label===y.text)?.id??"",b=s(x);m.className=`tag${y.active?" active":""}${b!=="idle"?` lamp-${b}`:""}`,m.style.left=`${y.screen.x}px`,m.style.top=`${y.screen.y}px`}),e.bubble?(this.bubbleEl.hidden=!1,this.bubbleEl.textContent=e.bubble.text,this.bubbleEl.style.color=Wn(e.bubble.color),this.bubbleEl.style.left=`${e.bubble.screen.x}px`,this.bubbleEl.style.top=`${e.bubble.screen.y}px`,this.bubbleEl.classList.toggle("pulse",n?.kind==="blocked_on_you")):this.bubbleEl.hidden=!0}liveMode=!1;async notify(){if(!("Notification"in globalThis))return;(Notification.permission==="default"?await Notification.requestPermission():Notification.permission)==="granted"&&new Notification("Agent Theatre",{body:"You'll get a notification whenever the agent waits on you."})}}function b1(i,e){const t=s=>s.split("/").pop()??s;switch(i.kind){case"read_file":return["Read",i.path];case"edit_file":return["Edit",`${i.path} · +${i.added} −${i.removed}`];case"write_file":return[i.created?"Create":"Write",i.path];case"run_command":return[i.intent==="test"?"Run tests":i.intent==="git"?"Git":i.intent==="build"?"Build":i.intent==="install"?"Install":"Run",`${i.argv0}${i.touched.length?" · "+i.touched.map(t).join(", "):""}`];case"test_result":return[i.ok?`${i.passed} passed`:`${i.failed} failed`,i.framework?`${i.framework}`:""];case"search":return["Search",i.scope];case"subagent_start":return["Helper",i.label??i.childId];case"subagent_stop":return["Helper done",i.childId];case"waiting_for_user":return[i.reason==="permission"?"Needs permission":i.reason==="question"?"Has a question":"Waiting",""];case"error":return["Error",i.where];case"turn_end":return[i.claimedSuccess?"Says it's done":"Turn ends",""];default:return[i.kind,""]}}const v1=i=>{let e=2166136261;for(let t=0;t<i.length;t++)e^=i.charCodeAt(t),e=Math.imul(e,16777619);return e>>>0},xu=i=>i.replace(/[&<>"]/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"})[e]??e);async function w1(i,e,t,s=360,r=200){const n=new Ig(e,t);n.update(0);const o=new _e,a=e.places.flatMap(g=>[K(g.gx,g.gy),K(g.gx+g.footprint,g.gy+g.footprint)]),l=a.map(g=>g.x),h=a.map(g=>g.y),c=Math.max(...l)-Math.min(...l)+160,u=Math.max(...h)-Math.min(...h)+170,d=Math.min(s/c,r/u);o.scale.set(d),o.position.set(s/2-(Math.min(...l)+Math.max(...l))/2*d,r/2-((Math.min(...h)+Math.max(...h))/2-20)*d),o.addChild(n.container);const f=Ci.create({width:s,height:r,resolution:1});i.renderer.render({container:o,target:f,clear:!0,clearColor:t.sky[1]});const p=await i.renderer.extract.base64(f);return f.destroy(!0),n.destroy(),o.destroy({children:!0}),p}const ne=new URLSearchParams(globalThis.__AT_QUERY??location.search),Fs=ne.get("base")??"",Jt=globalThis.acquireVsCodeApi?.()??null;globalThis.__vsapi=Jt;const Ki=matchMedia("(prefers-reduced-motion: reduce)").matches,st={get:i=>{try{return localStorage.getItem(i)}catch{return null}},set:(i,e)=>{try{localStorage.setItem(i,e)}catch{}}};async function T1(i){try{const e=await(await fetch("/demo/demos.json")).json();return i==="any"?e[Math.floor(Math.random()*e.length)]??null:e.find(t=>t.id===i)??null}catch{return null}}async function S1(i){const e=await T1(i);e&&(i=e.id,ne.has("episode")||ne.set("episode",`${e.title} · ${e.kind}`),!ne.has("set")&&ne.has("cinema")&&ne.set("set",e.set));const t=await(await fetch(`/demo/${i}.jsonl`)).text(),{events:s}=Kx(t),r=lb(s);let n=r.files,o=s[0]?.repoId??i;try{const h=await(await fetch(`/demo/${i}.files.json`)).json();if(Array.isArray(h.files)){const c=new Set(h.files.map(u=>u.path));n=[...h.files,...r.files.filter(u=>!c.has(u.path))],h.repoId&&(o=h.repoId)}}catch{}const a=rb({repoId:o,files:n,touched:r.touched}),l=rr(s,a);return new dh({world:a,events:s,beats:l,repoId:o})}async function C1(i,e){const t=new hb;let s=()=>{};const r=async()=>{await t.arm(),t.ready&&a?.audioReady()};let n=!1;for(const I of["pointerdown","keydown"])addEventListener(I,()=>{t.ready||(n=!0,setTimeout(()=>{n=!1},700),r())},{passive:!0});let o=nr(ne.get("set")),a=null,l=Number(ne.get("rate"))||1,h=st.get("at:muted")!=="0",c=st.get("at:ambience")==="1";t.setMuted(h),t.setAmbienceEnabled(c);const u=new x1(i,{onPlayPause:()=>{a&&(r(),a.playing?a.pause():(a.state.t>=a.state.duration-1&&a.seek(0),a.play()))},onSeek:I=>{a?.seek(I)},onRate:()=>{l=l>=4?1:l*2,a?.setRate(l),u.setRate(l)},onMute:()=>{if(!t.ready||n){r(),h&&(h=!1,t.setMuted(!1),st.set("at:muted","0"),u.setMuted(!1)),u.nudgeSeen();return}h=!h,u.nudgeSeen(),t.setMuted(h),st.set("at:muted",h?"1":"0"),u.setMuted(h)},onAmbience:()=>{if(!t.ready||n){r(),c||(c=!0,t.setAmbienceEnabled(!0),st.set("at:ambience","1"),u.setAmbience(!0)),u.nudgeSeen();return}c=!c,u.nudgeSeen(),t.setAmbienceEnabled(c),st.set("at:ambience",c?"1":"0"),u.setAmbience(c)},onPickSet:I=>{o=nr(I),a&&(st.set(`at:set:${a.world.repoId}`,I),v())},onOverview:I=>{a?.setOverview(I),s()},onZoom:I=>{a?.zoomBy(I),s()},onExport:()=>{p()},onPrompt:async I=>{if(Jt)return Jt.postMessage({type:"prompt",text:I}),"sent — watch the stage";try{const P=await fetch(`${Fs}/api/prompt`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text:I})}),C=await P.json();return C.ok?"sent — watch the stage":`couldn't send: ${C.error??P.status}`}catch(P){return`couldn't send: ${String(P)}`}},onShuffle:()=>{const I=Wo(m?.world.profile).filter(C=>C.id!==o.id),P=I.slice(0,Math.max(3,Math.min(5,I.length)));o=P[Math.floor(Math.random()*P.length)]??Et[0],a&&(st.set(`at:set:${a.world.repoId}`,o.id),v()),u.showPicker(!1)}});u.setMuted(h),u.setAmbience(c),u.setRate(l),h&&c===!1&&!st.get("at:nudged")&&u.showNudge(),u.liveMode=e.mode==="live";const d=ne.has("cinema");d&&(document.documentElement.classList.add("cinema"),h=!0,t.setMuted(!0));let f=null;async function p(){if(f){f.stop();return}await r();const P=g.canvas.captureStream(30),C=t.captureStream();if(C)for(const N of C.getAudioTracks())P.addTrack(N);const D=[],R=["video/mp4;codecs=avc1.42E01E,mp4a.40.2","video/mp4","video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"].find(N=>MediaRecorder.isTypeSupported(N))??"",L=R.startsWith("video/mp4")?"mp4":"webm";f=new MediaRecorder(P,R?{mimeType:R,videoBitsPerSecond:6e6}:void 0),f.ondataavailable=N=>{N.data.size&&D.push(N.data)},f.onstop=()=>{f=null,u.exportBtn.textContent="Export clip";const N=new Blob(D,{type:R.split(";")[0]||"video/webm"}),se=`agent-theatre-${(m?.repoId??"stage").split(/[/\\]/).pop()}-${new Date().toISOString().slice(0,19).replace(/[:T]/g,"-")}.${L}`,Q=`${a?.leadName??"The agent"} on the ${o.name} stage — ${(m?.repoId??"my repo").split(/[/\\]/).pop()} in Agent Theatre. Watch your coding agent work, as a film, not a log. https://agenttheatre.dev`;u.showShare({blob:N,name:se,caption:Q})},f.start(500),u.exportBtn.textContent="■ Stop & save",a&&!a.playing&&a.play()}const g=new ga;await g.init({resizeTo:u.stageEl,antialias:!0,backgroundAlpha:1,background:o.sky[1],preference:"webgl",resolution:Math.min(2,devicePixelRatio||1),autoDensity:!0}),u.stageEl.prepend(g.canvas);let m=null;const _=(I,P)=>nb(I,wi[(I.seed+Et.findIndex(C=>C.id===P.id)*7)%wi.length]);let y=0,x=!1,b="";function v(){if(!m)return;a&&(y=a.state.t,x=a.playing,a.destroy()),g.renderer.background.color=o.sky[1];const I=_(m.world,o),P=I===m.world?m.beats:rr(m.events,I);a=new Zs(g,I,o,t,Ki,ne.get("cast")??st.get(`at:cast:${m.repoId}`)),globalThis.__agentTheatre={app:g,get player(){return a},panel:u},Jt?.postMessage({type:"ready",places:I.places.length}),u.leadName=a.leadName,a.load(P),a.setRate(l),a.theme.id!==b?(a.seek(0),a.play()):(a.seek(y),x&&a.play()),b=a.theme.id,u.loadTimeline(P,m.events,I)}e.onReady(I=>{m=I;const P=st.get(`at:set:${I.repoId}`),C=ne.get("set")??P;u.profile=I.world.profile,u.repoId=I.repoId,C?o=nr(C):o=Wo(I.world.profile,I.world.seed)[0]??Et[0],u.setTitle(I.repoId,ne.get("episode")??void 0),Jt?u.promptEnabled=!0:e.mode==="live"&&fetch(`${Fs}/api/prompt`).then(L=>L.json()).then(L=>{u.promptEnabled=!!L.available}).catch(()=>{}),u.loadTimeline(I.beats,I.events,I.world),v();const D=Number(ne.get("t"));D>0&&a&&a.seek(D*1e3);const R=(async()=>{if(!ne.has("nopreview")){for(const L of Et)try{u.previews.set(L.id,await w1(g,_(I.world,L),L))}catch(N){console.warn("set preview failed",L.id,N)}u.pickerOpen&&u.showPicker(!0,o.id),s()}})();!C&&!ne.has("t")&&R.then(()=>u.showPicker(!0,o.id)),ne.get("paused")!=="1"&&!Ki&&a?.play(),d&&a&&!Ki&&a.play(),Ki&&!ne.has("t")&&a?.seek(Math.min(a.state.duration,25400))}),e.onBeats((I,P)=>{if(!(!a||!m)){if(m.beats.push(...I),m.events.push(...P),a.world===m.world)a.append(I);else{const C=rr(m.events,a.world);a.append(C.slice(a.beatCount))}u.loadTimeline(a.world===m.world?m.beats:rr(m.events,a.world),m.events,a.world),a.playing||a.play(),s()}}),e.onSignal?.(I=>a?.setSignal(I));const w=Number(ne.get("step"))||0;let T=performance.now(),k=0,E=!1,A=null;const M=I=>{E=!1;const P=w||Math.min(50,I-T);T=I,a&&!document.hidden&&((d||ne.has("loop"))&&a.state.t>=a.state.duration-1&&a.state.duration>0&&(A||(A=setTimeout(()=>{A=null,a?.seek(0),a?.play()},600))),a.update(P),u.update(a.state,a.world,C=>a.worldLayer.lampOf(C)),a.playing?k=45:k--),(a?.playing||k>0)&&!document.hidden&&B()},B=()=>{E||(E=!0,requestAnimationFrame(M))};s=()=>{k=45,T=performance.now(),B()},s();for(const I of["pointerdown","keydown","resize"])addEventListener(I,s,{passive:!0});document.addEventListener("visibilitychange",()=>{document.hidden||s()});const G=Zs.prototype.play;Zs.prototype.play=function(){G.call(this),s()};const O=Zs.prototype.seek;Zs.prototype.seek=function(I){O.call(this,I),s()}}async function M1(i){const{Application:e}=await kt(async()=>{const{Application:l}=await Promise.resolve().then(()=>Px);return{Application:l}},void 0),{Pip:t}=await kt(async()=>{const{Pip:l}=await Promise.resolve().then(()=>Sb);return{Pip:l}},void 0),{castById:s,CAST:r}=await kt(async()=>{const{castById:l,CAST:h}=await Promise.resolve().then(()=>Tb);return{castById:l,CAST:h}},void 0),n=s(i)??r[0],o=nr(ne.get("set")??"island");document.documentElement.style.background="transparent",document.body.style.background="transparent",document.body.style.margin="0";const a=new e;if(await a.init({width:320,height:320,backgroundAlpha:0,antialias:!0,resolution:2,autoDensity:!0,preference:"webgl"}),document.body.replaceChildren(a.canvas),i==="gremlin"){const{Gremlin:l}=await kt(async()=>{const{Gremlin:c}=await Promise.resolve().then(()=>vb);return{Gremlin:c}},void 0),h=new l("g",o,!1);h.scale=7,h.x=160,h.y=250,a.stage.addChild(h.container),a.ticker.add(c=>h.update(c.deltaMS))}else{const l=new t(o,!1,n);l.container.scale.set(6*n.size),l.pose.x=160,l.pose.y=272,a.stage.addChild(l.container),l.pose.mood=ne.get("mood")??"curious",a.ticker.add(h=>l.update(h.deltaMS))}globalThis.__agentTheatre={app:a,player:!0}}const $n=document.getElementById("app"),k1=ne.has("portrait")?Promise.resolve(new dh({world:null,events:[],beats:[],repoId:""})):Jt&&(ne.has("live")||ne.get("session"))?Promise.resolve(new f1(Jt,ne.get("session"))):ne.has("live")?Promise.resolve(new d1(Fs)):ne.get("session")?p1(ne.get("session"),Fs):S1(ne.get("demo")??"episode-1");ne.has("portrait")?M1(ne.get("portrait")).catch(i=>{$n.textContent=`Could not start: ${i}`}):k1.then(i=>C1($n,i)).catch(i=>{$n.textContent=`Could not start: ${i}${Fs?` (server: ${Fs})`:""}`});export{R_ as A,_e as C,Vf as D,Xf as E,ay as F,B_ as a,ep as b,Yf as c,Jf as d,q as e};
972
+ //# sourceMappingURL=index-18kUlmBs.js.map