@designcombo/video 0.1.2 → 0.1.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.
- package/dist/{SharedSystems-Xp4pkXxw.js → SharedSystems-CnuXOu2j.js} +1 -1
- package/dist/{WebGLRenderer-DUV0VFr8.js → WebGLRenderer-VL1VJMp0.js} +2 -2
- package/dist/{WebGPURenderer-CvQagiEk.js → WebGPURenderer-4sawtMPs.js} +2 -2
- package/dist/{browserAll-DJgUQT97.js → browserAll-C2ux6pzj.js} +2 -2
- package/dist/{index-fYFtiQSh.js → index-Vj0SflFX.js} +66 -60
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +18 -18
- package/dist/{webworkerAll-glUt5Asr.js → webworkerAll-DbyC0uRZ.js} +1 -1
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -61,10 +61,10 @@ void main() {
|
|
|
61
61
|
<div xmlns="http://www.w3.org/1999/xhtml">${r.outerHTML}</div>
|
|
62
62
|
</foreignObject>
|
|
63
63
|
</svg>
|
|
64
|
-
`.replace(/\t/g,"").replace(/#/g,"%23");return c.src=`data:image/svg+xml;charset=utf-8,${d}`,await new Promise(f=>{c.onload=f}),c}async function Nf(s,e,t={}){const r=await Lf(s,e,t),n=new OffscreenCanvas(r.width,r.height);return n.getContext("2d")?.drawImage(r,0,0,r.width,r.height),await createImageBitmap(n)}async function zf(s,e){const t={type:e,data:s},r=new ImageDecoder(t);await Promise.all([r.completed,r.tracks.ready]);const n=r.tracks.selectedTrack?.frameCount??1,o=[];for(let c=0;c<n;c+=1)o.push((await r.decode({frameIndex:c})).image);return o}let oa=class{all=new Map;on(e,t){const r=this.all.get(e);r?r.push(t):this.all.set(e,[t])}off(e,t){const r=this.all.get(e);r&&(t?r.splice(r.indexOf(t)>>>0,1):this.all.set(e,[]))}emit(e,t){let r=this.all.get(e);r&&r.slice().forEach(n=>{n(t)}),r=this.all.get("*"),r&&r.slice().forEach(n=>{n(e,t)})}};class Hf extends oa{id="";display={from:0,to:0};duration=0;playbackRate=1;trim={from:0,to:0};constructor(){super()}_left=0;get left(){return this._left}set left(e){const t=this._left!==e;this._left=e,t&&this.emit("propsChange",{left:e})}_top=0;get top(){return this._top}set top(e){const t=this._top!==e;this._top=e,t&&this.emit("propsChange",{top:e})}_width=0;get width(){return this._width}set width(e){const t=this._width!==e;this._width=e,t&&this.emit("propsChange",{width:e})}_height=0;get height(){return this._height}set height(e){const t=this._height!==e;this._height=e,t&&this.emit("propsChange",{height:e})}_angle=0;get angle(){return this._angle}set angle(e){const t=this._angle!==e;this._angle=e,t&&this.emit("propsChange",{angle:e})}get center(){return{x:this.left+this.width/2,y:this.top+this.height/2}}_zIndex=0;get zIndex(){return this._zIndex}set zIndex(e){const t=this._zIndex!==e;this._zIndex=e,t&&this.emit("propsChange",{zIndex:e})}_opacity=1;get opacity(){return this._opacity}set opacity(e){const t=this._opacity!==e;this._opacity=e,t&&this.emit("propsChange",{opacity:e})}_volume=1;get volume(){return this._volume}set volume(e){const t=this._volume!==e;this._volume=e,t&&this.emit("propsChange",{volume:e})}flip=null;effects=[];animatKeyFrame=null;animatOpts=null;ready=Promise.resolve();_render(e){const{center:t}=this;e.setTransform(this.flip==="horizontal"?-1:1,0,0,this.flip==="vertical"?-1:1,t.x,t.y);const r=this.angle*Math.PI/180;e.rotate((this.flip==null?1:-1)*r),e.globalAlpha=this.opacity}setAnimation(e,t){this.animatKeyFrame=Object.entries(e).map(([r,n])=>{const o={from:0,to:100}[r]??Number(r.slice(0,-1));if(isNaN(o)||o>100||o<0)throw Error("keyFrame must between 0~100");return[o/100,n]}),this.animatOpts=Object.assign({},this.animatOpts,{duration:t.duration,delay:t.delay??0,iterCount:t.iterCount??1/0})}animate(e){if(this.animatKeyFrame==null||this.animatOpts==null||e<this.animatOpts.delay)return;const t=Wf(e,this.animatKeyFrame,this.animatOpts);for(const r in t)switch(r){case"opacity":this.opacity=t[r];break;case"x":this.left=t[r];break;case"y":this.top=t[r];break;case"w":this.width=t[r];break;case"h":this.height=t[r];break;case"angle":this.angle=t[r];break}}copyStateTo(e){e.animatKeyFrame=this.animatKeyFrame,e.animatOpts=this.animatOpts,e.zIndex=this.zIndex,e.opacity=this.opacity,e.volume=this.volume,e.flip=this.flip,e.left=this.left,e.top=this.top,e.width=this.width,e.height=this.height,e.angle=this.angle,e.display={...this.display},e.duration=this.duration,e.playbackRate=this.playbackRate,e.trim={...this.trim},"src"in this&&"src"in e&&(e.src=this.src)}update(e){Object.assign(this,e),this.emit("propsChange",e)}destroy(){this.all.clear()}}function Wf(s,e,t){const r=s-t.delay,n=r%t.duration,o=r/t.duration>=t.iterCount||r===t.duration?1:n/t.duration,c=e.findIndex(y=>y[0]>=o);if(c===-1)return{};const l=e[c-1],d=e[c],f=d[1];if(l==null)return f;const m=l[1],g={},_=(o-l[0])/(d[0]-l[0]);for(const y in f){if(!Object.hasOwn(f,y)||typeof y!="string")continue;const a=y;m[a]!=null&&(g[a]=(f[a]-m[a])*_+m[a])}return g}class kt extends Hf{lastVf=null;destroyed=!1;src="";transition;constructor(){super()}async getFrame(e){const t=e*this.playbackRate,{video:r,audio:n,state:o}=await this.tick(t);let c=n??[];n!=null&&this.playbackRate!==1&&(c=n.map(d=>sa(d,this.playbackRate)));let l=null;return r!=null?(this.lastVf?.close(),r instanceof VideoFrame?(l=await createImageBitmap(r),r.close()):l=r,this.lastVf=l):this.lastVf!=null&&(l=this.lastVf),{video:l,audio:c,done:o==="done"}}async offscreenRender(e,t){const r=t*this.playbackRate;this.animate(r),super._render(e);const{width:n,height:o}=this,{video:c,audio:l,state:d}=await this.tick(r);let f=l??[];if(l!=null&&this.playbackRate!==1&&(f=l.map(g=>sa(g,this.playbackRate))),d==="done")return{audio:f,done:!0};let m=c??this.lastVf;return m!=null&&e.drawImage(m,-n/2,-o/2,n,o),c!=null&&(this.lastVf?.close(),c instanceof ImageBitmap&&(this.lastVf=c)),{audio:f,done:!1}}set(e,t=30){if(e.display&&(e.display.from!==void 0&&(this.display.from=e.display.from<1e6?e.display.from/t*1e6:e.display.from),e.display.to!==void 0&&(this.display.to=e.display.to<1e6?e.display.to/t*1e6:e.display.to)),e.x!==void 0&&(this.left=e.x),e.y!==void 0&&(this.top=e.y),e.width!==void 0&&(this.width=e.width),e.height!==void 0&&(this.height=e.height),e.duration!==void 0){const r=e.duration<1e6?e.duration/t*1e6:e.duration;this.duration=r,this.display.from!==void 0&&(this.display.to=this.display.from+r)}return this}toJSON(e=!1){const t=this.animatKeyFrame&&this.animatOpts?{keyFrames:this.animatKeyFrame.reduce((r,[n,o])=>{const c=n===0?"from":n===1?"to":`${Math.round(n*100)}%`;return r[c]=o,r},{}),opts:this.animatOpts}:void 0;return{type:this.constructor.name,src:this.src,display:{from:this.display.from,to:this.display.to},playbackRate:this.playbackRate,duration:this.duration,left:this.left,top:this.top,width:this.width,height:this.height,angle:this.angle,zIndex:this.zIndex,opacity:this.opacity,flip:this.flip,trim:{from:this.trim.from,to:this.trim.to},...t&&{animation:t},...e&&{main:!0}}}destroy(){this.destroyed||(this.destroyed=!0,W.info("BaseClip destroy"),super.destroy(),this.lastVf?.close(),this.lastVf=null)}}let Ss=null;async function aa(){return Ss===null&&(Ss=Cf()),await Ss}const oe={get codec(){return xr()?.codec??"mp4a.40.2"},get codecType(){return xr()?.codecType??"aac"},get sampleRate(){return xr()?.sampleRate??48e3},get channelCount(){return xr()?.channelCount??2}};class Me extends kt{type="Audio";static ctx=null;ready;_meta={duration:0,width:0,height:0};get meta(){return{...this._meta,sampleRate:oe.sampleRate,chanCount:2}}chan0Buf=new Float32Array;chan1Buf=new Float32Array;getPCMData(){return[this.chan0Buf,this.chan1Buf]}opts;loop=!1;static async fromUrl(e,t={}){const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch audio from ${e}: ${r.status} ${r.statusText}`);const n=new Me(r.body,t,e);return await n.ready,n}static async fromObject(e){if(e.type!=="Audio")throw new Error(`Expected Audio, got ${e.type}`);if(!e.src||e.src.trim()==="")throw new Error("AudioClip requires a valid source URL");const t={};e.loop!==void 0&&(t.loop=e.loop),e.volume!==void 0&&(t.volume=e.volume);const r=await Me.fromUrl(e.src,t);return r.left=e.left,r.top=e.top,r.width=e.width,r.height=e.height,r.angle=e.angle,r.display.from=e.display.from,r.display.to=e.display.to,r.duration=e.duration,r.playbackRate=e.playbackRate,r.zIndex=e.zIndex,r.opacity=e.opacity,r.flip=e.flip,e.animation&&r.setAnimation(e.animation.keyFrames,e.animation.opts),r}constructor(e,t={},r){super(),this.src=r!==void 0?r:"",this.opts={loop:!1,volume:1,...t},this.loop=this.opts.loop??!1,this.volume=this.opts.volume??1,this.ready=this.init(e).then(n=>{const o={width:0,height:0,duration:t.loop?1/0:this._meta.duration};return this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration=this.duration===0?o.duration:this.duration,this.display.to=this.display.from+this.duration,o})}async init(e){Me.ctx==null&&(Me.ctx=new AudioContext({sampleRate:oe.sampleRate}));const t=performance.now(),r=e instanceof ReadableStream?await Yf(e,Me.ctx):e;W.info("Audio clip decoded complete:",performance.now()-t),this._meta.duration=r[0].length/oe.sampleRate*1e6,this.chan0Buf=r[0],this.chan1Buf=r[1]??this.chan0Buf,W.info("Audio clip convert to AudioData, time:",performance.now()-t)}tickInterceptor=async(e,t)=>t;timestamp=0;frameOffset=0;async tick(e){if(!this.opts.loop&&e>=this._meta.duration)return await this.tickInterceptor(e,{audio:[],state:"done"});const t=e-this.timestamp;if(e<this.timestamp||t>3e6)return this.timestamp=e,this.frameOffset=Math.ceil(this.timestamp/1e6*oe.sampleRate),await this.tickInterceptor(e,{audio:[new Float32Array(0),new Float32Array(0)],state:"success"});this.timestamp=e;const r=Math.ceil(t/1e6*oe.sampleRate),n=this.frameOffset+r,o=this.opts.loop?[Ts(this.chan0Buf,this.frameOffset,n),Ts(this.chan1Buf,this.frameOffset,n)]:[this.chan0Buf.slice(this.frameOffset,n),this.chan1Buf.slice(this.frameOffset,n)];if(this.volume!==1)for(const c of o)for(let l=0;l<c.length;l++)c[l]*=this.volume;return this.frameOffset=n,await this.tickInterceptor(e,{audio:o,state:"success"})}async split(e){await this.ready;const t=Math.ceil(e/1e6*oe.sampleRate),r=new Me(this.getPCMData().map(o=>o.slice(0,t)),this.opts,this.src),n=new Me(this.getPCMData().map(o=>o.slice(t)),this.opts,this.src);return[r,n]}async clone(){await this.ready;const e=new Me(this.getPCMData(),this.opts,this.src);return await e.ready,this.copyStateTo(e),e}destroy(){this.chan0Buf=new Float32Array(0),this.chan1Buf=new Float32Array(0),W.info("---- audioclip destroy ----"),super.destroy()}toJSON(e=!1){return{...super.toJSON(e),type:"Audio",loop:this.loop,volume:this.volume}}static concatAudioClip=Vf;async createPlaybackElement(){if(await this.ready,!this.src||this.src.trim()==="")throw new Error("AudioClip requires a source URL for playback");const e=this.src.startsWith("blob:")?this.src:void 0,t=document.createElement("audio");return t.crossOrigin="anonymous",t.autoplay=!1,t.preload="auto",t.loop=this.opts.loop||!1,t.src=this.src,await new Promise((r,n)=>{const o=()=>{t.removeEventListener("loadeddata",o),t.removeEventListener("error",c),t.pause(),t.currentTime=0,r()},c=()=>{t.removeEventListener("loadeddata",o),t.removeEventListener("error",c),n(new Error("Failed to load audio"))};t.addEventListener("loadeddata",o,{once:!0}),t.addEventListener("error",c,{once:!0}),t.load()}),{element:t,objectUrl:e}}async play(e,t){const r=e;if(Math.abs(r.currentTime-t)>.1&&(r.currentTime=t),r.paused)try{await r.play()}catch{try{await r.play()}catch(o){console.warn("Failed to play audio:",o)}}}pause(e){e.pause()}async seek(e,t){const r=e;return r.pause(),r.currentTime=t,new Promise(n=>{if(Math.abs(r.currentTime-t)<.01){n();return}const o=()=>{r.removeEventListener("seeked",o),n()};r.addEventListener("seeked",o,{once:!0}),setTimeout(()=>{r.removeEventListener("seeked",o),n()},500)})}syncPlayback(e,t,r){const n=e,o=this.meta.duration/1e6,c=r>=0&&r<o;n.volume=this.volume,t&&c?n.paused&&this.play(n,r).catch(console.warn):(n.paused||n.pause(),c&&Math.abs(n.currentTime-r)>.1&&(n.currentTime=r))}cleanupPlayback(e,t){const r=e;r.pause(),r.removeAttribute("src"),r.load(),t&&t.startsWith("blob:")&&URL.revokeObjectURL(t)}}async function Vf(s,e){const t=[];for(const r of s)await r.ready,t.push(r.getPCMData());return new Me(ta(t),e)}async function Yf(s,e){const t=await new Response(s).arrayBuffer();return bs(await e.decodeAudioData(t))}var C=(s=>(s.Application="application",s.WebGLPipes="webgl-pipes",s.WebGLPipesAdaptor="webgl-pipes-adaptor",s.WebGLSystem="webgl-system",s.WebGPUPipes="webgpu-pipes",s.WebGPUPipesAdaptor="webgpu-pipes-adaptor",s.WebGPUSystem="webgpu-system",s.CanvasSystem="canvas-system",s.CanvasPipesAdaptor="canvas-pipes-adaptor",s.CanvasPipes="canvas-pipes",s.Asset="asset",s.LoadParser="load-parser",s.ResolveParser="resolve-parser",s.CacheParser="cache-parser",s.DetectionParser="detection-parser",s.MaskEffect="mask-effect",s.BlendMode="blend-mode",s.TextureSource="texture-source",s.Environment="environment",s.ShapeBuilder="shape-builder",s.Batcher="batcher",s))(C||{});const Cs=s=>{if(typeof s=="function"||typeof s=="object"&&s.extension){if(!s.extension)throw new Error("Extension class must have an extension object");s={...typeof s.extension!="object"?{type:s.extension}:s.extension,ref:s}}if(typeof s=="object")s={...s};else throw new Error("Invalid extension type");return typeof s.type=="string"&&(s.type=[s.type]),s},br=(s,e)=>Cs(s).priority??e,L={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...s){return s.map(Cs).forEach(e=>{e.type.forEach(t=>this._removeHandlers[t]?.(e))}),this},add(...s){return s.map(Cs).forEach(e=>{e.type.forEach(t=>{const r=this._addHandlers,n=this._queue;r[t]?r[t]?.(e):(n[t]=n[t]||[],n[t]?.push(e))})}),this},handle(s,e,t){const r=this._addHandlers,n=this._removeHandlers;if(r[s]||n[s])throw new Error(`Extension type ${s} already has a handler`);r[s]=e,n[s]=t;const o=this._queue;return o[s]&&(o[s]?.forEach(c=>e(c)),delete o[s]),this},handleByMap(s,e){return this.handle(s,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(s,e,t=-1){return this.handle(s,r=>{e.findIndex(o=>o.name===r.name)>=0||(e.push({name:r.name,value:r.ref}),e.sort((o,c)=>br(c.value,t)-br(o.value,t)))},r=>{const n=e.findIndex(o=>o.name===r.name);n!==-1&&e.splice(n,1)})},handleByList(s,e,t=-1){return this.handle(s,r=>{e.includes(r.ref)||(e.push(r.ref),e.sort((n,o)=>br(o,t)-br(n,t)))},r=>{const n=e.indexOf(r.ref);n!==-1&&e.splice(n,1)})},mixin(s,...e){for(const t of e)Object.defineProperties(s.prototype,Object.getOwnPropertyDescriptors(t))}},Xf={extension:{type:C.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>d2)}},$f={extension:{type:C.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>f2)}};class be{constructor(e,t,r){this._x=t||0,this._y=r||0,this._observer=e}clone(e){return new be(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}var As={exports:{}},la;function qf(){return la||(la=1,(function(s){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function n(d,f,m){this.fn=d,this.context=f,this.once=m||!1}function o(d,f,m,g,_){if(typeof m!="function")throw new TypeError("The listener must be a function");var y=new n(m,g||d,_),a=t?t+f:f;return d._events[a]?d._events[a].fn?d._events[a]=[d._events[a],y]:d._events[a].push(y):(d._events[a]=y,d._eventsCount++),d}function c(d,f){--d._eventsCount===0?d._events=new r:delete d._events[f]}function l(){this._events=new r,this._eventsCount=0}l.prototype.eventNames=function(){var f=[],m,g;if(this._eventsCount===0)return f;for(g in m=this._events)e.call(m,g)&&f.push(t?g.slice(1):g);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(m)):f},l.prototype.listeners=function(f){var m=t?t+f:f,g=this._events[m];if(!g)return[];if(g.fn)return[g.fn];for(var _=0,y=g.length,a=new Array(y);_<y;_++)a[_]=g[_].fn;return a},l.prototype.listenerCount=function(f){var m=t?t+f:f,g=this._events[m];return g?g.fn?1:g.length:0},l.prototype.emit=function(f,m,g,_,y,a){var h=t?t+f:f;if(!this._events[h])return!1;var u=this._events[h],p=arguments.length,v,x;if(u.fn){switch(u.once&&this.removeListener(f,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,m),!0;case 3:return u.fn.call(u.context,m,g),!0;case 4:return u.fn.call(u.context,m,g,_),!0;case 5:return u.fn.call(u.context,m,g,_,y),!0;case 6:return u.fn.call(u.context,m,g,_,y,a),!0}for(x=1,v=new Array(p-1);x<p;x++)v[x-1]=arguments[x];u.fn.apply(u.context,v)}else{var b=u.length,T;for(x=0;x<b;x++)switch(u[x].once&&this.removeListener(f,u[x].fn,void 0,!0),p){case 1:u[x].fn.call(u[x].context);break;case 2:u[x].fn.call(u[x].context,m);break;case 3:u[x].fn.call(u[x].context,m,g);break;case 4:u[x].fn.call(u[x].context,m,g,_);break;default:if(!v)for(T=1,v=new Array(p-1);T<p;T++)v[T-1]=arguments[T];u[x].fn.apply(u[x].context,v)}}return!0},l.prototype.on=function(f,m,g){return o(this,f,m,g,!1)},l.prototype.once=function(f,m,g){return o(this,f,m,g,!0)},l.prototype.removeListener=function(f,m,g,_){var y=t?t+f:f;if(!this._events[y])return this;if(!m)return c(this,y),this;var a=this._events[y];if(a.fn)a.fn===m&&(!_||a.once)&&(!g||a.context===g)&&c(this,y);else{for(var h=0,u=[],p=a.length;h<p;h++)(a[h].fn!==m||_&&!a[h].once||g&&a[h].context!==g)&&u.push(a[h]);u.length?this._events[y]=u.length===1?u[0]:u:c(this,y)}return this},l.prototype.removeAllListeners=function(f){var m;return f?(m=t?t+f:f,this._events[m]&&c(this,m)):(this._events=new r,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=t,l.EventEmitter=l,s.exports=l})(As)),As.exports}var Kf=qf();const Ge=St(Kf),jf=Math.PI*2,Zf=180/Math.PI,Jf=Math.PI/180;class J{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new J(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 Es.x=0,Es.y=0,Es}}const Es=new J;class B{constructor(e=1,t=0,r=0,n=1,o=0,c=0){this.array=null,this.a=e,this.b=t,this.c=r,this.d=n,this.tx=o,this.ty=c}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,r,n,o,c){return this.a=e,this.b=t,this.c=r,this.d=n,this.tx=o,this.ty=c,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const r=t||this.array;return e?(r[0]=this.a,r[1]=this.b,r[2]=0,r[3]=this.c,r[4]=this.d,r[5]=0,r[6]=this.tx,r[7]=this.ty,r[8]=1):(r[0]=this.a,r[1]=this.c,r[2]=this.tx,r[3]=this.b,r[4]=this.d,r[5]=this.ty,r[6]=0,r[7]=0,r[8]=1),r}apply(e,t){t=t||new J;const r=e.x,n=e.y;return t.x=this.a*r+this.c*n+this.tx,t.y=this.b*r+this.d*n+this.ty,t}applyInverse(e,t){t=t||new J;const r=this.a,n=this.b,o=this.c,c=this.d,l=this.tx,d=this.ty,f=1/(r*c+o*-n),m=e.x,g=e.y;return t.x=c*f*m+-o*f*g+(d*o-l*c)*f,t.y=r*f*g+-n*f*m+(-d*r+l*n)*f,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),r=Math.sin(e),n=this.a,o=this.c,c=this.tx;return this.a=n*t-this.b*r,this.b=n*r+this.b*t,this.c=o*t-this.d*r,this.d=o*r+this.d*t,this.tx=c*t-this.ty*r,this.ty=c*r+this.ty*t,this}append(e){const t=this.a,r=this.b,n=this.c,o=this.d;return this.a=e.a*t+e.b*n,this.b=e.a*r+e.b*o,this.c=e.c*t+e.d*n,this.d=e.c*r+e.d*o,this.tx=e.tx*t+e.ty*n+this.tx,this.ty=e.tx*r+e.ty*o+this.ty,this}appendFrom(e,t){const r=e.a,n=e.b,o=e.c,c=e.d,l=e.tx,d=e.ty,f=t.a,m=t.b,g=t.c,_=t.d;return this.a=r*f+n*g,this.b=r*m+n*_,this.c=o*f+c*g,this.d=o*m+c*_,this.tx=l*f+d*g+t.tx,this.ty=l*m+d*_+t.ty,this}setTransform(e,t,r,n,o,c,l,d,f){return this.a=Math.cos(l+f)*o,this.b=Math.sin(l+f)*o,this.c=-Math.sin(l-d)*c,this.d=Math.cos(l-d)*c,this.tx=e-(r*this.a+n*this.c),this.ty=t-(r*this.b+n*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const r=this.a,n=this.c;this.a=r*e.a+this.b*e.c,this.b=r*e.b+this.b*e.d,this.c=n*e.a+this.d*e.c,this.d=n*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,r=this.b,n=this.c,o=this.d,c=e.pivot,l=-Math.atan2(-n,o),d=Math.atan2(r,t),f=Math.abs(l+d);return f<1e-5||Math.abs(jf-f)<1e-5?(e.rotation=d,e.skew.x=e.skew.y=0):(e.rotation=0,e.skew.x=l,e.skew.y=d),e.scale.x=Math.sqrt(t*t+r*r),e.scale.y=Math.sqrt(n*n+o*o),e.position.x=this.tx+(c.x*t+c.y*n),e.position.y=this.ty+(c.x*r+c.y*o),e}invert(){const e=this.a,t=this.b,r=this.c,n=this.d,o=this.tx,c=e*n-t*r;return this.a=n/c,this.b=-t/c,this.c=-r/c,this.d=e/c,this.tx=(r*this.ty-n*o)/c,this.ty=-(e*this.ty-t*o)/c,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 B;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 ep.identity()}static get shared(){return Qf.identity()}}const Qf=new B,ep=new B,Bt=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Dt=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Ot=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Gt=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Is=[],ca=[],Tr=Math.sign;function tp(){for(let s=0;s<16;s++){const e=[];Is.push(e);for(let t=0;t<16;t++){const r=Tr(Bt[s]*Bt[t]+Ot[s]*Dt[t]),n=Tr(Dt[s]*Bt[t]+Gt[s]*Dt[t]),o=Tr(Bt[s]*Ot[t]+Ot[s]*Gt[t]),c=Tr(Dt[s]*Ot[t]+Gt[s]*Gt[t]);for(let l=0;l<16;l++)if(Bt[l]===r&&Dt[l]===n&&Ot[l]===o&&Gt[l]===c){e.push(l);break}}}for(let s=0;s<16;s++){const e=new B;e.set(Bt[s],Dt[s],Ot[s],Gt[s],0,0),ca.push(e)}}tp();const ie={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:s=>Bt[s],uY:s=>Dt[s],vX:s=>Ot[s],vY:s=>Gt[s],inv:s=>s&8?s&15:-s&7,add:(s,e)=>Is[s][e],sub:(s,e)=>Is[s][ie.inv(e)],rotate180:s=>s^4,isVertical:s=>(s&3)===2,byDirection:(s,e)=>Math.abs(s)*2<=Math.abs(e)?e>=0?ie.S:ie.N:Math.abs(e)*2<=Math.abs(s)?s>0?ie.E:ie.W:e>0?s>0?ie.SE:ie.SW:s>0?ie.NE:ie.NW,matrixAppendRotationInv:(s,e,t=0,r=0)=>{const n=ca[ie.inv(e)];n.tx=t,n.ty=r,s.append(n)},transformRectCoords:(s,e,t,r)=>{const{x:n,y:o,width:c,height:l}=s,{x:d,y:f,width:m,height:g}=e;return t===ie.E?(r.set(n+d,o+f,c,l),r):t===ie.S?r.set(m-o-l+d,n+f,l,c):t===ie.W?r.set(m-n-c+d,g-o-l+f,c,l):t===ie.N?r.set(o+d,g-n-c+f,l,c):r.set(n+d,o+f,c,l)}},wr=[new J,new J,new J,new J];class z{constructor(e=0,t=0,r=0,n=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),this.width=Number(r),this.height=Number(n)}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 z(0,0,0,0)}clone(){return new z(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,r,n=.5){const{width:o,height:c}=this;if(o<=0||c<=0)return!1;const l=this.x,d=this.y,f=r*(1-n),m=r-f,g=l-f,_=l+o+f,y=d-f,a=d+c+f,h=l+m,u=l+o-m,p=d+m,v=d+c-m;return e>=g&&e<=_&&t>=y&&t<=a&&!(e>h&&e<u&&t>p&&t<v)}intersects(e,t){if(!t){const E=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=E)return!1;const P=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>P}const r=this.left,n=this.right,o=this.top,c=this.bottom;if(n<=r||c<=o)return!1;const l=wr[0].set(e.left,e.top),d=wr[1].set(e.left,e.bottom),f=wr[2].set(e.right,e.top),m=wr[3].set(e.right,e.bottom);if(f.x<=l.x||d.y<=l.y)return!1;const g=Math.sign(t.a*t.d-t.b*t.c);if(g===0||(t.apply(l,l),t.apply(d,d),t.apply(f,f),t.apply(m,m),Math.max(l.x,d.x,f.x,m.x)<=r||Math.min(l.x,d.x,f.x,m.x)>=n||Math.max(l.y,d.y,f.y,m.y)<=o||Math.min(l.y,d.y,f.y,m.y)>=c))return!1;const _=g*(d.y-l.y),y=g*(l.x-d.x),a=_*r+y*o,h=_*n+y*o,u=_*r+y*c,p=_*n+y*c;if(Math.max(a,h,u,p)<=_*l.x+y*l.y||Math.min(a,h,u,p)>=_*m.x+y*m.y)return!1;const v=g*(l.y-f.y),x=g*(f.x-l.x),b=v*r+x*o,T=v*n+x*o,w=v*r+x*c,S=v*n+x*c;return!(Math.max(b,T,w,S)<=v*l.x+x*l.y||Math.min(b,T,w,S)>=v*m.x+x*m.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),r=Math.min(this.x+this.width,e.x+e.width),n=Math.max(this.y,e.y),o=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(r-t,0),this.y=n,this.height=Math.max(o-n,0),this}ceil(e=1,t=.001){const r=Math.ceil((this.x+this.width-t)*e)/e,n=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=r-this.x,this.height=n-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),r=Math.max(this.x+this.width,e.x+e.width),n=Math.min(this.y,e.y),o=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=r-t,this.y=n,this.height=o-n,this}getBounds(e){return e||(e=new z),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,r=e.y,n=e.x+e.width,o=e.y+e.height;return t>=this.x&&t<this.x+this.width&&r>=this.y&&r<this.y+this.height&&n>=this.x&&n<this.x+this.width&&o>=this.y&&o<this.y+this.height}set(e,t,r,n){return this.x=e,this.y=t,this.width=r,this.height=n,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Ps={default:-1};function ae(s="default"){return Ps[s]===void 0&&(Ps[s]=-1),++Ps[s]}const ha=new Set,j="8.0.0",ip="8.3.4",Zt={quiet:!1,noColor:!1},H=(s,e,t=3)=>{if(Zt.quiet||ha.has(e))return;let r=new Error().stack;const n=`${e}
|
|
64
|
+
`.replace(/\t/g,"").replace(/#/g,"%23");return c.src=`data:image/svg+xml;charset=utf-8,${d}`,await new Promise(f=>{c.onload=f}),c}async function Nf(s,e,t={}){const r=await Lf(s,e,t),n=new OffscreenCanvas(r.width,r.height);return n.getContext("2d")?.drawImage(r,0,0,r.width,r.height),await createImageBitmap(n)}async function zf(s,e){const t={type:e,data:s},r=new ImageDecoder(t);await Promise.all([r.completed,r.tracks.ready]);const n=r.tracks.selectedTrack?.frameCount??1,o=[];for(let c=0;c<n;c+=1)o.push((await r.decode({frameIndex:c})).image);return o}let oa=class{all=new Map;on(e,t){const r=this.all.get(e);r?r.push(t):this.all.set(e,[t])}off(e,t){const r=this.all.get(e);r&&(t?r.splice(r.indexOf(t)>>>0,1):this.all.set(e,[]))}emit(e,t){let r=this.all.get(e);r&&r.slice().forEach(n=>{n(t)}),r=this.all.get("*"),r&&r.slice().forEach(n=>{n(e,t)})}};class Hf extends oa{id="";display={from:0,to:0};duration=0;playbackRate=1;trim={from:0,to:0};constructor(){super()}_left=0;get left(){return this._left}set left(e){const t=this._left!==e;this._left=e,t&&this.emit("propsChange",{left:e})}_top=0;get top(){return this._top}set top(e){const t=this._top!==e;this._top=e,t&&this.emit("propsChange",{top:e})}_width=0;get width(){return this._width}set width(e){const t=this._width!==e;this._width=e,t&&this.emit("propsChange",{width:e})}_height=0;get height(){return this._height}set height(e){const t=this._height!==e;this._height=e,t&&this.emit("propsChange",{height:e})}_angle=0;get angle(){return this._angle}set angle(e){const t=this._angle!==e;this._angle=e,t&&this.emit("propsChange",{angle:e})}get center(){return{x:this.left+this.width/2,y:this.top+this.height/2}}_zIndex=0;get zIndex(){return this._zIndex}set zIndex(e){const t=this._zIndex!==e;this._zIndex=e,t&&this.emit("propsChange",{zIndex:e})}_opacity=1;get opacity(){return this._opacity}set opacity(e){const t=this._opacity!==e;this._opacity=e,t&&this.emit("propsChange",{opacity:e})}_volume=1;get volume(){return this._volume}set volume(e){const t=this._volume!==e;this._volume=e,t&&this.emit("propsChange",{volume:e})}flip=null;effects=[];animatKeyFrame=null;animatOpts=null;ready=Promise.resolve();_render(e){const{center:t}=this;e.setTransform(this.flip==="horizontal"?-1:1,0,0,this.flip==="vertical"?-1:1,t.x,t.y);const r=this.angle*Math.PI/180;e.rotate((this.flip==null?1:-1)*r),e.globalAlpha=this.opacity}setAnimation(e,t){this.animatKeyFrame=Object.entries(e).map(([r,n])=>{const o={from:0,to:100}[r]??Number(r.slice(0,-1));if(isNaN(o)||o>100||o<0)throw Error("keyFrame must between 0~100");return[o/100,n]}),this.animatOpts=Object.assign({},this.animatOpts,{duration:t.duration,delay:t.delay??0,iterCount:t.iterCount??1/0})}animate(e){if(this.animatKeyFrame==null||this.animatOpts==null||e<this.animatOpts.delay)return;const t=Wf(e,this.animatKeyFrame,this.animatOpts);for(const r in t)switch(r){case"opacity":this.opacity=t[r];break;case"x":this.left=t[r];break;case"y":this.top=t[r];break;case"w":this.width=t[r];break;case"h":this.height=t[r];break;case"angle":this.angle=t[r];break}}copyStateTo(e){e.animatKeyFrame=this.animatKeyFrame,e.animatOpts=this.animatOpts,e.zIndex=this.zIndex,e.opacity=this.opacity,e.volume=this.volume,e.flip=this.flip,e.left=this.left,e.top=this.top,e.width=this.width,e.height=this.height,e.angle=this.angle,e.display={...this.display},e.duration=this.duration,e.playbackRate=this.playbackRate,e.trim={...this.trim},"src"in this&&"src"in e&&(e.src=this.src)}update(e){Object.assign(this,e),this.emit("propsChange",e)}destroy(){this.all.clear()}}function Wf(s,e,t){const r=s-t.delay,n=r%t.duration,o=r/t.duration>=t.iterCount||r===t.duration?1:n/t.duration,c=e.findIndex(y=>y[0]>=o);if(c===-1)return{};const l=e[c-1],d=e[c],f=d[1];if(l==null)return f;const m=l[1],g={},_=(o-l[0])/(d[0]-l[0]);for(const y in f){if(!Object.hasOwn(f,y)||typeof y!="string")continue;const a=y;m[a]!=null&&(g[a]=(f[a]-m[a])*_+m[a])}return g}class kt extends Hf{lastVf=null;destroyed=!1;src="";transition;constructor(){super()}async getFrame(e){const t=e*this.playbackRate,{video:r,audio:n,state:o}=await this.tick(t);let c=n??[];n!=null&&this.playbackRate!==1&&(c=n.map(d=>sa(d,this.playbackRate)));let l=null;return r!=null?(this.lastVf?.close(),r instanceof VideoFrame?(l=await createImageBitmap(r),r.close()):l=r,this.lastVf=l):this.lastVf!=null&&(l=this.lastVf),{video:l,audio:c,done:o==="done"}}async offscreenRender(e,t){const r=t*this.playbackRate;this.animate(r),super._render(e);const{width:n,height:o}=this,{video:c,audio:l,state:d}=await this.tick(r);let f=l??[];if(l!=null&&this.playbackRate!==1&&(f=l.map(g=>sa(g,this.playbackRate))),d==="done")return{audio:f,done:!0};let m=c??this.lastVf;return m!=null&&e.drawImage(m,-n/2,-o/2,n,o),c!=null&&(this.lastVf?.close(),c instanceof ImageBitmap&&(this.lastVf=c)),{audio:f,done:!1}}set(e,t=30){if(e.display&&(e.display.from!==void 0&&(this.display.from=e.display.from<1e6?e.display.from/t*1e6:e.display.from),e.display.to!==void 0&&(this.display.to=e.display.to<1e6?e.display.to/t*1e6:e.display.to)),e.x!==void 0&&(this.left=e.x),e.y!==void 0&&(this.top=e.y),e.width!==void 0&&(this.width=e.width),e.height!==void 0&&(this.height=e.height),e.duration!==void 0){const r=e.duration<1e6?e.duration/t*1e6:e.duration;this.duration=r,this.display.from!==void 0&&(this.display.to=this.display.from+r)}return this}toJSON(e=!1){const t=this.animatKeyFrame&&this.animatOpts?{keyFrames:this.animatKeyFrame.reduce((r,[n,o])=>{const c=n===0?"from":n===1?"to":`${Math.round(n*100)}%`;return r[c]=o,r},{}),opts:this.animatOpts}:void 0;return{type:this.constructor.name,src:this.src,display:{from:this.display.from,to:this.display.to},playbackRate:this.playbackRate,duration:this.duration,left:this.left,top:this.top,width:this.width,height:this.height,angle:this.angle,zIndex:this.zIndex,opacity:this.opacity,flip:this.flip,trim:{from:this.trim.from,to:this.trim.to},...t&&{animation:t},...e&&{main:!0}}}destroy(){this.destroyed||(this.destroyed=!0,W.info("BaseClip destroy"),super.destroy(),this.lastVf?.close(),this.lastVf=null)}}let Ss=null;async function aa(){return Ss===null&&(Ss=Cf()),await Ss}const oe={get codec(){return xr()?.codec??"mp4a.40.2"},get codecType(){return xr()?.codecType??"aac"},get sampleRate(){return xr()?.sampleRate??48e3},get channelCount(){return xr()?.channelCount??2}};class Me extends kt{type="Audio";static ctx=null;ready;_meta={duration:0,width:0,height:0};get meta(){return{...this._meta,sampleRate:oe.sampleRate,chanCount:2}}chan0Buf=new Float32Array;chan1Buf=new Float32Array;getPCMData(){return[this.chan0Buf,this.chan1Buf]}opts;loop=!1;static async fromUrl(e,t={}){const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch audio from ${e}: ${r.status} ${r.statusText}`);const n=new Me(r.body,t,e);return await n.ready,n}static async fromObject(e){if(e.type!=="Audio")throw new Error(`Expected Audio, got ${e.type}`);if(!e.src||e.src.trim()==="")throw new Error("AudioClip requires a valid source URL");const t={};e.loop!==void 0&&(t.loop=e.loop),e.volume!==void 0&&(t.volume=e.volume);const r=await Me.fromUrl(e.src,t);return r.left=e.left,r.top=e.top,r.width=e.width,r.height=e.height,r.angle=e.angle,r.display.from=e.display.from,r.display.to=e.display.to,r.duration=e.duration,r.playbackRate=e.playbackRate,r.zIndex=e.zIndex,r.opacity=e.opacity,r.flip=e.flip,e.animation&&r.setAnimation(e.animation.keyFrames,e.animation.opts),r}constructor(e,t={},r){super(),this.src=r!==void 0?r:"",this.opts={loop:!1,volume:1,...t},this.loop=this.opts.loop??!1,this.volume=this.opts.volume??1,this.ready=this.init(e).then(n=>{const o={width:0,height:0,duration:t.loop?1/0:this._meta.duration};return this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration=this.duration===0?o.duration:this.duration,this.display.to=this.display.from+this.duration,o})}async init(e){Me.ctx==null&&(Me.ctx=new AudioContext({sampleRate:oe.sampleRate}));const t=performance.now(),r=e instanceof ReadableStream?await Yf(e,Me.ctx):e;W.info("Audio clip decoded complete:",performance.now()-t),this._meta.duration=r[0].length/oe.sampleRate*1e6,this.chan0Buf=r[0],this.chan1Buf=r[1]??this.chan0Buf,W.info("Audio clip convert to AudioData, time:",performance.now()-t)}tickInterceptor=async(e,t)=>t;timestamp=0;frameOffset=0;async tick(e){if(!this.opts.loop&&e>=this._meta.duration)return await this.tickInterceptor(e,{audio:[],state:"done"});const t=e-this.timestamp;if(e<this.timestamp||t>3e6)return this.timestamp=e,this.frameOffset=Math.ceil(this.timestamp/1e6*oe.sampleRate),await this.tickInterceptor(e,{audio:[new Float32Array(0),new Float32Array(0)],state:"success"});this.timestamp=e;const r=Math.ceil(t/1e6*oe.sampleRate),n=this.frameOffset+r,o=this.opts.loop?[Ts(this.chan0Buf,this.frameOffset,n),Ts(this.chan1Buf,this.frameOffset,n)]:[this.chan0Buf.slice(this.frameOffset,n),this.chan1Buf.slice(this.frameOffset,n)];if(this.volume!==1)for(const c of o)for(let l=0;l<c.length;l++)c[l]*=this.volume;return this.frameOffset=n,await this.tickInterceptor(e,{audio:o,state:"success"})}async split(e){await this.ready;const t=Math.ceil(e/1e6*oe.sampleRate),r=new Me(this.getPCMData().map(o=>o.slice(0,t)),this.opts,this.src),n=new Me(this.getPCMData().map(o=>o.slice(t)),this.opts,this.src);return[r,n]}async clone(){await this.ready;const e=new Me(this.getPCMData(),this.opts,this.src);return await e.ready,this.copyStateTo(e),e}destroy(){this.chan0Buf=new Float32Array(0),this.chan1Buf=new Float32Array(0),W.info("---- audioclip destroy ----"),super.destroy()}toJSON(e=!1){return{...super.toJSON(e),type:"Audio",loop:this.loop,volume:this.volume}}static concatAudioClip=Vf;async createPlaybackElement(){if(await this.ready,!this.src||this.src.trim()==="")throw new Error("AudioClip requires a source URL for playback");const e=this.src.startsWith("blob:")?this.src:void 0,t=document.createElement("audio");return t.crossOrigin="anonymous",t.autoplay=!1,t.preload="auto",t.loop=this.opts.loop||!1,t.src=this.src,await new Promise((r,n)=>{const o=()=>{t.removeEventListener("loadeddata",o),t.removeEventListener("error",c),t.pause(),t.currentTime=0,r()},c=()=>{t.removeEventListener("loadeddata",o),t.removeEventListener("error",c),n(new Error("Failed to load audio"))};t.addEventListener("loadeddata",o,{once:!0}),t.addEventListener("error",c,{once:!0}),t.load()}),{element:t,objectUrl:e}}async play(e,t){const r=e;if(Math.abs(r.currentTime-t)>.1&&(r.currentTime=t),r.paused)try{await r.play()}catch{try{await r.play()}catch(o){console.warn("Failed to play audio:",o)}}}pause(e){e.pause()}async seek(e,t){const r=e;return r.pause(),r.currentTime=t,new Promise(n=>{if(Math.abs(r.currentTime-t)<.01){n();return}const o=()=>{r.removeEventListener("seeked",o),n()};r.addEventListener("seeked",o,{once:!0}),setTimeout(()=>{r.removeEventListener("seeked",o),n()},500)})}syncPlayback(e,t,r){const n=e,o=this.meta.duration/1e6,c=r>=0&&r<o;n.volume=this.volume,t&&c?n.paused&&this.play(n,r).catch(console.warn):(n.paused||n.pause(),c&&Math.abs(n.currentTime-r)>.1&&(n.currentTime=r))}cleanupPlayback(e,t){const r=e;r.pause(),r.removeAttribute("src"),r.load(),t&&t.startsWith("blob:")&&URL.revokeObjectURL(t)}}async function Vf(s,e){const t=[];for(const r of s)await r.ready,t.push(r.getPCMData());return new Me(ta(t),e)}async function Yf(s,e){const t=await new Response(s).arrayBuffer();return bs(await e.decodeAudioData(t))}var C=(s=>(s.Application="application",s.WebGLPipes="webgl-pipes",s.WebGLPipesAdaptor="webgl-pipes-adaptor",s.WebGLSystem="webgl-system",s.WebGPUPipes="webgpu-pipes",s.WebGPUPipesAdaptor="webgpu-pipes-adaptor",s.WebGPUSystem="webgpu-system",s.CanvasSystem="canvas-system",s.CanvasPipesAdaptor="canvas-pipes-adaptor",s.CanvasPipes="canvas-pipes",s.Asset="asset",s.LoadParser="load-parser",s.ResolveParser="resolve-parser",s.CacheParser="cache-parser",s.DetectionParser="detection-parser",s.MaskEffect="mask-effect",s.BlendMode="blend-mode",s.TextureSource="texture-source",s.Environment="environment",s.ShapeBuilder="shape-builder",s.Batcher="batcher",s))(C||{});const Cs=s=>{if(typeof s=="function"||typeof s=="object"&&s.extension){if(!s.extension)throw new Error("Extension class must have an extension object");s={...typeof s.extension!="object"?{type:s.extension}:s.extension,ref:s}}if(typeof s=="object")s={...s};else throw new Error("Invalid extension type");return typeof s.type=="string"&&(s.type=[s.type]),s},br=(s,e)=>Cs(s).priority??e,L={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...s){return s.map(Cs).forEach(e=>{e.type.forEach(t=>this._removeHandlers[t]?.(e))}),this},add(...s){return s.map(Cs).forEach(e=>{e.type.forEach(t=>{const r=this._addHandlers,n=this._queue;r[t]?r[t]?.(e):(n[t]=n[t]||[],n[t]?.push(e))})}),this},handle(s,e,t){const r=this._addHandlers,n=this._removeHandlers;if(r[s]||n[s])throw new Error(`Extension type ${s} already has a handler`);r[s]=e,n[s]=t;const o=this._queue;return o[s]&&(o[s]?.forEach(c=>e(c)),delete o[s]),this},handleByMap(s,e){return this.handle(s,t=>{t.name&&(e[t.name]=t.ref)},t=>{t.name&&delete e[t.name]})},handleByNamedList(s,e,t=-1){return this.handle(s,r=>{e.findIndex(o=>o.name===r.name)>=0||(e.push({name:r.name,value:r.ref}),e.sort((o,c)=>br(c.value,t)-br(o.value,t)))},r=>{const n=e.findIndex(o=>o.name===r.name);n!==-1&&e.splice(n,1)})},handleByList(s,e,t=-1){return this.handle(s,r=>{e.includes(r.ref)||(e.push(r.ref),e.sort((n,o)=>br(o,t)-br(n,t)))},r=>{const n=e.indexOf(r.ref);n!==-1&&e.splice(n,1)})},mixin(s,...e){for(const t of e)Object.defineProperties(s.prototype,Object.getOwnPropertyDescriptors(t))}},Xf={extension:{type:C.Environment,name:"browser",priority:-1},test:()=>!0,load:async()=>{await Promise.resolve().then(()=>d2)}},$f={extension:{type:C.Environment,name:"webworker",priority:0},test:()=>typeof self<"u"&&self.WorkerGlobalScope!==void 0,load:async()=>{await Promise.resolve().then(()=>f2)}};class be{constructor(e,t,r){this._x=t||0,this._y=r||0,this._observer=e}clone(e){return new be(e??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}}var As={exports:{}},la;function qf(){return la||(la=1,(function(s){var e=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function n(d,f,m){this.fn=d,this.context=f,this.once=m||!1}function o(d,f,m,g,_){if(typeof m!="function")throw new TypeError("The listener must be a function");var y=new n(m,g||d,_),a=t?t+f:f;return d._events[a]?d._events[a].fn?d._events[a]=[d._events[a],y]:d._events[a].push(y):(d._events[a]=y,d._eventsCount++),d}function c(d,f){--d._eventsCount===0?d._events=new r:delete d._events[f]}function l(){this._events=new r,this._eventsCount=0}l.prototype.eventNames=function(){var f=[],m,g;if(this._eventsCount===0)return f;for(g in m=this._events)e.call(m,g)&&f.push(t?g.slice(1):g);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(m)):f},l.prototype.listeners=function(f){var m=t?t+f:f,g=this._events[m];if(!g)return[];if(g.fn)return[g.fn];for(var _=0,y=g.length,a=new Array(y);_<y;_++)a[_]=g[_].fn;return a},l.prototype.listenerCount=function(f){var m=t?t+f:f,g=this._events[m];return g?g.fn?1:g.length:0},l.prototype.emit=function(f,m,g,_,y,a){var h=t?t+f:f;if(!this._events[h])return!1;var u=this._events[h],p=arguments.length,v,x;if(u.fn){switch(u.once&&this.removeListener(f,u.fn,void 0,!0),p){case 1:return u.fn.call(u.context),!0;case 2:return u.fn.call(u.context,m),!0;case 3:return u.fn.call(u.context,m,g),!0;case 4:return u.fn.call(u.context,m,g,_),!0;case 5:return u.fn.call(u.context,m,g,_,y),!0;case 6:return u.fn.call(u.context,m,g,_,y,a),!0}for(x=1,v=new Array(p-1);x<p;x++)v[x-1]=arguments[x];u.fn.apply(u.context,v)}else{var b=u.length,T;for(x=0;x<b;x++)switch(u[x].once&&this.removeListener(f,u[x].fn,void 0,!0),p){case 1:u[x].fn.call(u[x].context);break;case 2:u[x].fn.call(u[x].context,m);break;case 3:u[x].fn.call(u[x].context,m,g);break;case 4:u[x].fn.call(u[x].context,m,g,_);break;default:if(!v)for(T=1,v=new Array(p-1);T<p;T++)v[T-1]=arguments[T];u[x].fn.apply(u[x].context,v)}}return!0},l.prototype.on=function(f,m,g){return o(this,f,m,g,!1)},l.prototype.once=function(f,m,g){return o(this,f,m,g,!0)},l.prototype.removeListener=function(f,m,g,_){var y=t?t+f:f;if(!this._events[y])return this;if(!m)return c(this,y),this;var a=this._events[y];if(a.fn)a.fn===m&&(!_||a.once)&&(!g||a.context===g)&&c(this,y);else{for(var h=0,u=[],p=a.length;h<p;h++)(a[h].fn!==m||_&&!a[h].once||g&&a[h].context!==g)&&u.push(a[h]);u.length?this._events[y]=u.length===1?u[0]:u:c(this,y)}return this},l.prototype.removeAllListeners=function(f){var m;return f?(m=t?t+f:f,this._events[m]&&c(this,m)):(this._events=new r,this._eventsCount=0),this},l.prototype.off=l.prototype.removeListener,l.prototype.addListener=l.prototype.on,l.prefixed=t,l.EventEmitter=l,s.exports=l})(As)),As.exports}var Kf=qf();const Le=St(Kf),jf=Math.PI*2,Zf=180/Math.PI,Jf=Math.PI/180;class J{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new J(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 Es.x=0,Es.y=0,Es}}const Es=new J;class B{constructor(e=1,t=0,r=0,n=1,o=0,c=0){this.array=null,this.a=e,this.b=t,this.c=r,this.d=n,this.tx=o,this.ty=c}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,r,n,o,c){return this.a=e,this.b=t,this.c=r,this.d=n,this.tx=o,this.ty=c,this}toArray(e,t){this.array||(this.array=new Float32Array(9));const r=t||this.array;return e?(r[0]=this.a,r[1]=this.b,r[2]=0,r[3]=this.c,r[4]=this.d,r[5]=0,r[6]=this.tx,r[7]=this.ty,r[8]=1):(r[0]=this.a,r[1]=this.c,r[2]=this.tx,r[3]=this.b,r[4]=this.d,r[5]=this.ty,r[6]=0,r[7]=0,r[8]=1),r}apply(e,t){t=t||new J;const r=e.x,n=e.y;return t.x=this.a*r+this.c*n+this.tx,t.y=this.b*r+this.d*n+this.ty,t}applyInverse(e,t){t=t||new J;const r=this.a,n=this.b,o=this.c,c=this.d,l=this.tx,d=this.ty,f=1/(r*c+o*-n),m=e.x,g=e.y;return t.x=c*f*m+-o*f*g+(d*o-l*c)*f,t.y=r*f*g+-n*f*m+(-d*r+l*n)*f,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),r=Math.sin(e),n=this.a,o=this.c,c=this.tx;return this.a=n*t-this.b*r,this.b=n*r+this.b*t,this.c=o*t-this.d*r,this.d=o*r+this.d*t,this.tx=c*t-this.ty*r,this.ty=c*r+this.ty*t,this}append(e){const t=this.a,r=this.b,n=this.c,o=this.d;return this.a=e.a*t+e.b*n,this.b=e.a*r+e.b*o,this.c=e.c*t+e.d*n,this.d=e.c*r+e.d*o,this.tx=e.tx*t+e.ty*n+this.tx,this.ty=e.tx*r+e.ty*o+this.ty,this}appendFrom(e,t){const r=e.a,n=e.b,o=e.c,c=e.d,l=e.tx,d=e.ty,f=t.a,m=t.b,g=t.c,_=t.d;return this.a=r*f+n*g,this.b=r*m+n*_,this.c=o*f+c*g,this.d=o*m+c*_,this.tx=l*f+d*g+t.tx,this.ty=l*m+d*_+t.ty,this}setTransform(e,t,r,n,o,c,l,d,f){return this.a=Math.cos(l+f)*o,this.b=Math.sin(l+f)*o,this.c=-Math.sin(l-d)*c,this.d=Math.cos(l-d)*c,this.tx=e-(r*this.a+n*this.c),this.ty=t-(r*this.b+n*this.d),this}prepend(e){const t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){const r=this.a,n=this.c;this.a=r*e.a+this.b*e.c,this.b=r*e.b+this.b*e.d,this.c=n*e.a+this.d*e.c,this.d=n*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,r=this.b,n=this.c,o=this.d,c=e.pivot,l=-Math.atan2(-n,o),d=Math.atan2(r,t),f=Math.abs(l+d);return f<1e-5||Math.abs(jf-f)<1e-5?(e.rotation=d,e.skew.x=e.skew.y=0):(e.rotation=0,e.skew.x=l,e.skew.y=d),e.scale.x=Math.sqrt(t*t+r*r),e.scale.y=Math.sqrt(n*n+o*o),e.position.x=this.tx+(c.x*t+c.y*n),e.position.y=this.ty+(c.x*r+c.y*o),e}invert(){const e=this.a,t=this.b,r=this.c,n=this.d,o=this.tx,c=e*n-t*r;return this.a=n/c,this.b=-t/c,this.c=-r/c,this.d=e/c,this.tx=(r*this.ty-n*o)/c,this.ty=-(e*this.ty-t*o)/c,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 B;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 ep.identity()}static get shared(){return Qf.identity()}}const Qf=new B,ep=new B,Bt=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Dt=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Ot=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Gt=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Is=[],ca=[],Tr=Math.sign;function tp(){for(let s=0;s<16;s++){const e=[];Is.push(e);for(let t=0;t<16;t++){const r=Tr(Bt[s]*Bt[t]+Ot[s]*Dt[t]),n=Tr(Dt[s]*Bt[t]+Gt[s]*Dt[t]),o=Tr(Bt[s]*Ot[t]+Ot[s]*Gt[t]),c=Tr(Dt[s]*Ot[t]+Gt[s]*Gt[t]);for(let l=0;l<16;l++)if(Bt[l]===r&&Dt[l]===n&&Ot[l]===o&&Gt[l]===c){e.push(l);break}}}for(let s=0;s<16;s++){const e=new B;e.set(Bt[s],Dt[s],Ot[s],Gt[s],0,0),ca.push(e)}}tp();const ie={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:s=>Bt[s],uY:s=>Dt[s],vX:s=>Ot[s],vY:s=>Gt[s],inv:s=>s&8?s&15:-s&7,add:(s,e)=>Is[s][e],sub:(s,e)=>Is[s][ie.inv(e)],rotate180:s=>s^4,isVertical:s=>(s&3)===2,byDirection:(s,e)=>Math.abs(s)*2<=Math.abs(e)?e>=0?ie.S:ie.N:Math.abs(e)*2<=Math.abs(s)?s>0?ie.E:ie.W:e>0?s>0?ie.SE:ie.SW:s>0?ie.NE:ie.NW,matrixAppendRotationInv:(s,e,t=0,r=0)=>{const n=ca[ie.inv(e)];n.tx=t,n.ty=r,s.append(n)},transformRectCoords:(s,e,t,r)=>{const{x:n,y:o,width:c,height:l}=s,{x:d,y:f,width:m,height:g}=e;return t===ie.E?(r.set(n+d,o+f,c,l),r):t===ie.S?r.set(m-o-l+d,n+f,l,c):t===ie.W?r.set(m-n-c+d,g-o-l+f,c,l):t===ie.N?r.set(o+d,g-n-c+f,l,c):r.set(n+d,o+f,c,l)}},wr=[new J,new J,new J,new J];class z{constructor(e=0,t=0,r=0,n=0){this.type="rectangle",this.x=Number(e),this.y=Number(t),this.width=Number(r),this.height=Number(n)}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 z(0,0,0,0)}clone(){return new z(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,r,n=.5){const{width:o,height:c}=this;if(o<=0||c<=0)return!1;const l=this.x,d=this.y,f=r*(1-n),m=r-f,g=l-f,_=l+o+f,y=d-f,a=d+c+f,h=l+m,u=l+o-m,p=d+m,v=d+c-m;return e>=g&&e<=_&&t>=y&&t<=a&&!(e>h&&e<u&&t>p&&t<v)}intersects(e,t){if(!t){const E=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=E)return!1;const P=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>P}const r=this.left,n=this.right,o=this.top,c=this.bottom;if(n<=r||c<=o)return!1;const l=wr[0].set(e.left,e.top),d=wr[1].set(e.left,e.bottom),f=wr[2].set(e.right,e.top),m=wr[3].set(e.right,e.bottom);if(f.x<=l.x||d.y<=l.y)return!1;const g=Math.sign(t.a*t.d-t.b*t.c);if(g===0||(t.apply(l,l),t.apply(d,d),t.apply(f,f),t.apply(m,m),Math.max(l.x,d.x,f.x,m.x)<=r||Math.min(l.x,d.x,f.x,m.x)>=n||Math.max(l.y,d.y,f.y,m.y)<=o||Math.min(l.y,d.y,f.y,m.y)>=c))return!1;const _=g*(d.y-l.y),y=g*(l.x-d.x),a=_*r+y*o,h=_*n+y*o,u=_*r+y*c,p=_*n+y*c;if(Math.max(a,h,u,p)<=_*l.x+y*l.y||Math.min(a,h,u,p)>=_*m.x+y*m.y)return!1;const v=g*(l.y-f.y),x=g*(f.x-l.x),b=v*r+x*o,T=v*n+x*o,w=v*r+x*c,S=v*n+x*c;return!(Math.max(b,T,w,S)<=v*l.x+x*l.y||Math.min(b,T,w,S)>=v*m.x+x*m.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),r=Math.min(this.x+this.width,e.x+e.width),n=Math.max(this.y,e.y),o=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(r-t,0),this.y=n,this.height=Math.max(o-n,0),this}ceil(e=1,t=.001){const r=Math.ceil((this.x+this.width-t)*e)/e,n=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=r-this.x,this.height=n-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),r=Math.max(this.x+this.width,e.x+e.width),n=Math.min(this.y,e.y),o=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=r-t,this.y=n,this.height=o-n,this}getBounds(e){return e||(e=new z),e.copyFrom(this),e}containsRect(e){if(this.width<=0||this.height<=0)return!1;const t=e.x,r=e.y,n=e.x+e.width,o=e.y+e.height;return t>=this.x&&t<this.x+this.width&&r>=this.y&&r<this.y+this.height&&n>=this.x&&n<this.x+this.width&&o>=this.y&&o<this.y+this.height}set(e,t,r,n){return this.x=e,this.y=t,this.width=r,this.height=n,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}}const Ps={default:-1};function ae(s="default"){return Ps[s]===void 0&&(Ps[s]=-1),++Ps[s]}const ha=new Set,j="8.0.0",ip="8.3.4",Zt={quiet:!1,noColor:!1},H=(s,e,t=3)=>{if(Zt.quiet||ha.has(e))return;let r=new Error().stack;const n=`${e}
|
|
65
65
|
Deprecated since v${s}`,o=typeof console.groupCollapsed=="function"&&!Zt.noColor;typeof r>"u"?console.warn("PixiJS Deprecation Warning: ",n):(r=r.split(`
|
|
66
66
|
`).splice(t).join(`
|
|
67
|
-
`),o?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",n),console.warn(r),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",n),console.warn(r))),ha.add(e)};Object.defineProperties(H,{quiet:{get:()=>Zt.quiet,set:s=>{Zt.quiet=s},enumerable:!0,configurable:!1},noColor:{get:()=>Zt.noColor,set:s=>{Zt.noColor=s},enumerable:!0,configurable:!1}});const ua=()=>{};function Jt(s){return s+=s===0?1:0,--s,s|=s>>>1,s|=s>>>2,s|=s>>>4,s|=s>>>8,s|=s>>>16,s+1}function da(s){return!(s&s-1)&&!!s}function fa(s){const e={};for(const t in s)s[t]!==void 0&&(e[t]=s[t]);return e}const pa=Object.create(null);function rp(s){const e=pa[s];return e===void 0&&(pa[s]=ae("resource")),e}const ma=class hd extends Ge{constructor(e={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,e={...hd.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(j,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this.emit("change",this),this._sharedResourceId=null}_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=rp(e),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};ma.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let at=ma;const ga=class ud extends Ge{constructor(e={}){super(),this.options=e,this.uid=ae("textureSource"),this._resourceType="textureSource",this._resourceId=ae("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.antialias=!1,this._touched=0,this._batchTick=-1,this._textureBindLocation=-1,e={...ud.defaultOptions,...e},this.label=e.label??"",this.resource=e.resource,this.autoGarbageCollect=e.autoGarbageCollect,this._resolution=e.resolution,e.width?this.pixelWidth=e.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,e.height?this.pixelHeight=e.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=e.format,this.dimension=e.dimensions,this.mipLevelCount=e.mipLevelCount,this.autoGenerateMipmaps=e.autoGenerateMipmaps,this.sampleCount=e.sampleCount,this.antialias=e.antialias,this.alphaMode=e.alphaMode,this.style=new at(fa(e)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(e){this.style!==e&&(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.emit("destroy",this),this.emit("change",this),this._style&&(this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=ae("resource"),this.emit("change",this),this.emit("unload",this)}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,r){r||(r=this._resolution),e||(e=this.width),t||(t=this.height);const n=Math.round(e*r),o=Math.round(t*r);return this.width=n/r,this.height=o/r,this._resolution=r,this.pixelWidth===n&&this.pixelHeight===o?!1:(this._refreshPOT(),this.pixelWidth=n,this.pixelHeight=o,this.emit("resize",this),this._resourceId=ae("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=da(this.pixelWidth)&&da(this.pixelHeight)}static test(e){throw new Error("Unimplemented")}};ga.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",dimensions:"2d",mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let ge=ga;class Rs extends ge{constructor(e){const t=e.resource||new Float32Array(e.width*e.height*4);let r=e.format;r||(t instanceof Float32Array?r="rgba32float":t instanceof Int32Array||t instanceof Uint32Array?r="rgba32uint":t instanceof Int16Array||t instanceof Uint16Array?r="rgba16uint":(t instanceof Int8Array,r="bgra8unorm")),super({...e,resource:t,format:r}),this.uploadMethodId="buffer"}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}Rs.extension=C.TextureSource;const va=new B;class _a{constructor(e,t){this.mapCoord=new B,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof t>"u"?this.clampMargin=e.width<10?0:.5:this.clampMargin=t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){this.texture!==e&&(this._texture?.removeListener("update",this.update,this),this._texture=e,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(e,t){t===void 0&&(t=e);const r=this.mapCoord;for(let n=0;n<e.length;n+=2){const o=e[n],c=e[n+1];t[n]=o*r.a+c*r.c+r.tx,t[n+1]=o*r.b+c*r.d+r.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 r=e.orig,n=e.trim;n&&(va.set(r.width/n.width,0,0,r.height/n.height,-n.x/n.width,-n.y/n.height),this.mapCoord.append(va));const o=e.source,c=this.uClampFrame,l=this.clampMargin/o._resolution,d=this.clampOffset/o._resolution;return c[0]=(e.frame.x+l+d)/o.width,c[1]=(e.frame.y+l+d)/o.height,c[2]=(e.frame.x+e.frame.width-l+d)/o.width,c[3]=(e.frame.y+e.frame.height-l+d)/o.height,this.uClampOffset[0]=this.clampOffset/o.pixelWidth,this.uClampOffset[1]=this.clampOffset/o.pixelHeight,this.isSimple=e.frame.width===o.width&&e.frame.height===o.height&&e.rotate===0,!0}}class F extends Ge{constructor({source:e,label:t,frame:r,orig:n,trim:o,defaultAnchor:c,defaultBorders:l,rotate:d,dynamic:f}={}){if(super(),this.uid=ae("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new z,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=e?.source??new ge,this.noFrame=!r,r)this.frame.copyFrom(r);else{const{width:m,height:g}=this._source;this.frame.width=m,this.frame.height=g}this.orig=n||this.frame,this.trim=o,this.rotate=d??0,this.defaultAnchor=c,this.defaultBorders=l,this.destroyed=!1,this.dynamic=f||!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 _a(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:e,frame:t}=this,{width:r,height:n}=this._source,o=t.x/r,c=t.y/n,l=t.width/r,d=t.height/n;let f=this.rotate;if(f){const m=l/2,g=d/2,_=o+m,y=c+g;f=ie.add(f,ie.NW),e.x0=_+m*ie.uX(f),e.y0=y+g*ie.uY(f),f=ie.add(f,2),e.x1=_+m*ie.uX(f),e.y1=y+g*ie.uY(f),f=ie.add(f,2),e.x2=_+m*ie.uX(f),e.y2=y+g*ie.uY(f),f=ie.add(f,2),e.x3=_+m*ie.uX(f),e.y3=y+g*ie.uY(f)}else e.x0=o,e.y0=c,e.x1=o+l,e.y1=c,e.x2=o+l,e.y2=c+d,e.x3=o,e.y3=c+d}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(j,"Texture.baseTexture is now Texture.source"),this._source}}F.EMPTY=new F({label:"EMPTY",source:new ge({label:"EMPTY"})}),F.EMPTY.destroy=ua,F.WHITE=new F({source:new Rs({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"}),F.WHITE.destroy=ua;function ya(s,e,t){const{width:r,height:n}=t.orig,o=t.trim;if(o){const c=o.width,l=o.height;s.minX=o.x-e._x*r,s.maxX=s.minX+c,s.minY=o.y-e._y*n,s.maxY=s.minY+l}else s.minX=-e._x*r,s.maxX=s.minX+r,s.minY=-e._y*n,s.maxY=s.minY+n}const xa=new B;class Se{constructor(e=1/0,t=1/0,r=-1/0,n=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=xa,this.minX=e,this.minY=t,this.maxX=r,this.maxY=n}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new z);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=xa,this}set(e,t,r,n){this.minX=e,this.minY=t,this.maxX=r,this.maxY=n}addFrame(e,t,r,n,o){o||(o=this.matrix);const c=o.a,l=o.b,d=o.c,f=o.d,m=o.tx,g=o.ty;let _=this.minX,y=this.minY,a=this.maxX,h=this.maxY,u=c*e+d*t+m,p=l*e+f*t+g;u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*r+d*t+m,p=l*r+f*t+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*e+d*n+m,p=l*e+f*n+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*r+d*n+m,p=l*r+f*n+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),this.minX=_,this.minY=y,this.maxX=a,this.maxY=h}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,r=this.minY,n=this.maxX,o=this.maxY,{a:c,b:l,c:d,d:f,tx:m,ty:g}=e;let _=c*t+d*r+m,y=l*t+f*r+g;this.minX=_,this.minY=y,this.maxX=_,this.maxY=y,_=c*n+d*r+m,y=l*n+f*r+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y:this.maxY,_=c*t+d*o+m,y=l*t+f*o+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y:this.maxY,_=c*n+d*o+m,y=l*n+f*o+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y: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,r,n){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<r&&(this.minY=r),this.maxY>n&&(this.maxY=n),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 Se(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,r,n){let o=this.minX,c=this.minY,l=this.maxX,d=this.maxY;n||(n=this.matrix);const f=n.a,m=n.b,g=n.c,_=n.d,y=n.tx,a=n.ty;for(let h=t;h<r;h+=2){const u=e[h],p=e[h+1],v=f*u+g*p+y,x=m*u+_*p+a;o=v<o?v:o,c=x<c?x:c,l=v>l?v:l,d=x>d?x:d}this.minX=o,this.minY=c,this.maxX=l,this.maxY=d}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 sp={grad:.9,turn:360,rad:360/(2*Math.PI)},ft=function(s){return typeof s=="string"?s.length>0:typeof s=="number"},_e=function(s,e,t){return e===void 0&&(e=0),t===void 0&&(t=Math.pow(10,e)),Math.round(t*s)/t+0},$e=function(s,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),s>t?t:s>e?s:e},ba=function(s){return(s=isFinite(s)?s%360:0)>0?s:s+360},Ta=function(s){return{r:$e(s.r,0,255),g:$e(s.g,0,255),b:$e(s.b,0,255),a:$e(s.a)}},Ms=function(s){return{r:_e(s.r),g:_e(s.g),b:_e(s.b),a:_e(s.a,3)}},np=/^#([0-9a-f]{3,8})$/i,Sr=function(s){var e=s.toString(16);return e.length<2?"0"+e:e},wa=function(s){var e=s.r,t=s.g,r=s.b,n=s.a,o=Math.max(e,t,r),c=o-Math.min(e,t,r),l=c?o===e?(t-r)/c:o===t?2+(r-e)/c:4+(e-t)/c:0;return{h:60*(l<0?l+6:l),s:o?c/o*100:0,v:o/255*100,a:n}},Sa=function(s){var e=s.h,t=s.s,r=s.v,n=s.a;e=e/360*6,t/=100,r/=100;var o=Math.floor(e),c=r*(1-t),l=r*(1-(e-o)*t),d=r*(1-(1-e+o)*t),f=o%6;return{r:255*[r,l,c,c,d,r][f],g:255*[d,r,r,l,c,c][f],b:255*[c,c,d,r,r,l][f],a:n}},Ca=function(s){return{h:ba(s.h),s:$e(s.s,0,100),l:$e(s.l,0,100),a:$e(s.a)}},Aa=function(s){return{h:_e(s.h),s:_e(s.s),l:_e(s.l),a:_e(s.a,3)}},Ea=function(s){return Sa((t=(e=s).s,{h:e.h,s:(t*=((r=e.l)<50?r:100-r)/100)>0?2*t/(r+t)*100:0,v:r+t,a:e.a}));var e,t,r},Ai=function(s){return{h:(e=wa(s)).h,s:(n=(200-(t=e.s))*(r=e.v)/100)>0&&n<200?t*r/100/(n<=100?n:200-n)*100:0,l:n/2,a:e.a};var e,t,r,n},op=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ap=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,lp=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cp=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Fs={string:[[function(s){var e=np.exec(s);return e?(s=e[1]).length<=4?{r:parseInt(s[0]+s[0],16),g:parseInt(s[1]+s[1],16),b:parseInt(s[2]+s[2],16),a:s.length===4?_e(parseInt(s[3]+s[3],16)/255,2):1}:s.length===6||s.length===8?{r:parseInt(s.substr(0,2),16),g:parseInt(s.substr(2,2),16),b:parseInt(s.substr(4,2),16),a:s.length===8?_e(parseInt(s.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(s){var e=lp.exec(s)||cp.exec(s);return e?e[2]!==e[4]||e[4]!==e[6]?null:Ta({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(s){var e=op.exec(s)||ap.exec(s);if(!e)return null;var t,r,n=Ca({h:(t=e[1],r=e[2],r===void 0&&(r="deg"),Number(t)*(sp[r]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return Ea(n)},"hsl"]],object:[[function(s){var e=s.r,t=s.g,r=s.b,n=s.a,o=n===void 0?1:n;return ft(e)&&ft(t)&&ft(r)?Ta({r:Number(e),g:Number(t),b:Number(r),a:Number(o)}):null},"rgb"],[function(s){var e=s.h,t=s.s,r=s.l,n=s.a,o=n===void 0?1:n;if(!ft(e)||!ft(t)||!ft(r))return null;var c=Ca({h:Number(e),s:Number(t),l:Number(r),a:Number(o)});return Ea(c)},"hsl"],[function(s){var e=s.h,t=s.s,r=s.v,n=s.a,o=n===void 0?1:n;if(!ft(e)||!ft(t)||!ft(r))return null;var c=(function(l){return{h:ba(l.h),s:$e(l.s,0,100),v:$e(l.v,0,100),a:$e(l.a)}})({h:Number(e),s:Number(t),v:Number(r),a:Number(o)});return Sa(c)},"hsv"]]},Ia=function(s,e){for(var t=0;t<e.length;t++){var r=e[t][0](s);if(r)return[r,e[t][1]]}return[null,void 0]},hp=function(s){return typeof s=="string"?Ia(s.trim(),Fs.string):typeof s=="object"&&s!==null?Ia(s,Fs.object):[null,void 0]},Us=function(s,e){var t=Ai(s);return{h:t.h,s:$e(t.s+100*e,0,100),l:t.l,a:t.a}},ks=function(s){return(299*s.r+587*s.g+114*s.b)/1e3/255},Pa=function(s,e){var t=Ai(s);return{h:t.h,s:t.s,l:$e(t.l+100*e,0,100),a:t.a}},Bs=(function(){function s(e){this.parsed=hp(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return s.prototype.isValid=function(){return this.parsed!==null},s.prototype.brightness=function(){return _e(ks(this.rgba),2)},s.prototype.isDark=function(){return ks(this.rgba)<.5},s.prototype.isLight=function(){return ks(this.rgba)>=.5},s.prototype.toHex=function(){return e=Ms(this.rgba),t=e.r,r=e.g,n=e.b,c=(o=e.a)<1?Sr(_e(255*o)):"","#"+Sr(t)+Sr(r)+Sr(n)+c;var e,t,r,n,o,c},s.prototype.toRgb=function(){return Ms(this.rgba)},s.prototype.toRgbString=function(){return e=Ms(this.rgba),t=e.r,r=e.g,n=e.b,(o=e.a)<1?"rgba("+t+", "+r+", "+n+", "+o+")":"rgb("+t+", "+r+", "+n+")";var e,t,r,n,o},s.prototype.toHsl=function(){return Aa(Ai(this.rgba))},s.prototype.toHslString=function(){return e=Aa(Ai(this.rgba)),t=e.h,r=e.s,n=e.l,(o=e.a)<1?"hsla("+t+", "+r+"%, "+n+"%, "+o+")":"hsl("+t+", "+r+"%, "+n+"%)";var e,t,r,n,o},s.prototype.toHsv=function(){return e=wa(this.rgba),{h:_e(e.h),s:_e(e.s),v:_e(e.v),a:_e(e.a,3)};var e},s.prototype.invert=function(){return lt({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},s.prototype.saturate=function(e){return e===void 0&&(e=.1),lt(Us(this.rgba,e))},s.prototype.desaturate=function(e){return e===void 0&&(e=.1),lt(Us(this.rgba,-e))},s.prototype.grayscale=function(){return lt(Us(this.rgba,-1))},s.prototype.lighten=function(e){return e===void 0&&(e=.1),lt(Pa(this.rgba,e))},s.prototype.darken=function(e){return e===void 0&&(e=.1),lt(Pa(this.rgba,-e))},s.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},s.prototype.alpha=function(e){return typeof e=="number"?lt({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):_e(this.rgba.a,3);var t},s.prototype.hue=function(e){var t=Ai(this.rgba);return typeof e=="number"?lt({h:e,s:t.s,l:t.l,a:t.a}):_e(t.h)},s.prototype.isEqual=function(e){return this.toHex()===lt(e).toHex()},s})(),lt=function(s){return s instanceof Bs?s:new Bs(s)},Ra=[],up=function(s){s.forEach(function(e){Ra.indexOf(e)<0&&(e(Bs,Fs),Ra.push(e))})};function dp(s,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"},r={};for(var n in t)r[t[n]]=n;var o={};s.prototype.toName=function(c){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var l,d,f=r[this.toHex()];if(f)return f;if(c?.closest){var m=this.toRgb(),g=1/0,_="black";if(!o.length)for(var y in t)o[y]=new s(t[y]).toRgb();for(var a in t){var h=(l=m,d=o[a],Math.pow(l.r-d.r,2)+Math.pow(l.g-d.g,2)+Math.pow(l.b-d.b,2));h<g&&(g=h,_=a)}return _}},e.string.push([function(c){var l=c.toLowerCase(),d=l==="transparent"?"#0000":t[l];return d?new s(d).toRgb():null},"name"])}up([dp]);const Qt=class cr{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 cr)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 r=typeof e;if(r!==typeof t)return!1;if(r==="number"||r==="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((o,c)=>o===t[c]);if(e!==null&&t!==null){const o=Object.keys(e),c=Object.keys(t);return o.length!==c.length?!1:o.every(l=>e[l]===t[l])}return e===t}toRgba(){const[e,t,r,n]=this._components;return{r:e,g:t,b:r,a:n}}toRgb(){const[e,t,r]=this._components;return{r:e,g:t,b:r}}toRgbaString(){const[e,t,r]=this.toUint8RgbArray();return`rgba(${e},${t},${r},${this.alpha})`}toUint8RgbArray(e){const[t,r,n]=this._components;return this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb),e[0]=Math.round(t*255),e[1]=Math.round(r*255),e[2]=Math.round(n*255),e}toArray(e){this._arrayRgba||(this._arrayRgba=[]),e||(e=this._arrayRgba);const[t,r,n,o]=this._components;return e[0]=t,e[1]=r,e[2]=n,e[3]=o,e}toRgbArray(e){this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb);const[t,r,n]=this._components;return e[0]=t,e[1]=r,e[2]=n,e}toNumber(){return this._int}toBgrNumber(){const[e,t,r]=this.toUint8RgbArray();return(r<<16)+(t<<8)+e}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[t,r,n,o]=cr._temp.setValue(e)._components;return this._components[0]*=t,this._components[1]*=r,this._components[2]*=n,this._components[3]*=o,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 r=this._int>>16&255,n=this._int>>8&255,o=this._int&255;return t&&(r=r*e+.5|0,n=n*e+.5|0,o=o*e+.5|0),(e*255<<24)+(r<<16)+(n<<8)+o}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const t=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(e){return this._components[3]=this._clamp(e),this}_normalize(e){let t,r,n,o;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const c=e;t=(c>>16&255)/255,r=(c>>8&255)/255,n=(c&255)/255,o=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[t,r,n,o=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[t,r,n,o=255]=e,t/=255,r/=255,n/=255,o/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const l=cr.HEX_PATTERN.exec(e);l&&(e=`#${l[2]}`)}const c=lt(e);c.isValid()&&({r:t,g:r,b:n,a:o}=c.rgba,t/=255,r/=255,n/=255)}if(t!==void 0)this._components[0]=t,this._components[1]=r,this._components[2]=n,this._components[3]=o,this._refreshInt();else throw new Error(`Unable to convert color ${e}`)}_refreshInt(){this._clamp(this._components);const[e,t,r]=this._components;this._int=(e*255<<16)+(t*255<<8)+(r*255|0)}_clamp(e,t=0,r=1){return typeof e=="number"?Math.min(Math.max(e,t),r):(e.forEach((n,o)=>{e[o]=Math.min(Math.max(n,t),r)}),e)}static isColorLike(e){return typeof e=="number"||typeof e=="string"||e instanceof Number||e instanceof cr||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}};Qt.shared=new Qt,Qt._temp=new Qt,Qt.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let le=Qt;const fp={cullArea:null,cullable:!1,cullableChildren:!0};let Ds=0;const Ma=500;function G(...s){Ds!==Ma&&(Ds++,Ds===Ma?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...s))}const ei={_registeredResources:new Set,register(s){this._registeredResources.add(s)},unregister(s){this._registeredResources.delete(s)},release(){this._registeredResources.forEach(s=>s.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(s){return this._registeredResources.has(s)},reset(){this._registeredResources.clear()}};class pp{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 mp{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 pp(e)),this._poolsByClass.get(e)}stats(){const e={};return this._poolsByClass.forEach(t=>{const r=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[r]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}}const me=new mp;ei.register(me);const gp={get isCachedAsTexture(){return!!this.renderGroup?.isCachedAsTexture},cacheAsTexture(s){typeof s=="boolean"&&s===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(s===!0?{}:s))},updateCacheTexture(){this.renderGroup?.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(s){H("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(s)}};function Fa(s,e,t){const r=s.length;let n;if(e>=r||t===0)return;t=e+t>r?r-e:t;const o=r-t;for(n=e;n<o;++n)s[n]=s[n+t];s.length=o}const vp={allowChildren:!0,removeChildren(s=0,e){const t=e??this.children.length,r=t-s,n=[];if(r>0&&r<=t){for(let c=t-1;c>=s;c--){const l=this.children[c];l&&(n.push(l),l.parent=null)}Fa(this.children,s,t);const o=this.renderGroup||this.parentRenderGroup;o&&o.removeChildren(n);for(let c=0;c<n.length;++c){const l=n[c];l.parentRenderLayer?.detach(l),this.emit("childRemoved",l,this,c),n[c].emit("removed",this)}return n.length>0&&this._didViewChangeTick++,n}else if(r===0&&this.children.length===0)return n;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(s){const e=this.getChildAt(s);return this.removeChild(e)},getChildAt(s){if(s<0||s>=this.children.length)throw new Error(`getChildAt: Index (${s}) does not exist.`);return this.children[s]},setChildIndex(s,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);this.getChildIndex(s),this.addChildAt(s,e)},getChildIndex(s){const e=this.children.indexOf(s);if(e===-1)throw new Error("The supplied Container must be a child of the caller");return e},addChildAt(s,e){this.allowChildren||H(j,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:t}=this;if(e<0||e>t.length)throw new Error(`${s}addChildAt: The index ${e} supplied is out of bounds ${t.length}`);if(s.parent){const n=s.parent.children.indexOf(s);if(s.parent===this&&n===e)return s;n!==-1&&s.parent.children.splice(n,1)}e===t.length?t.push(s):t.splice(e,0,s),s.parent=this,s.didChange=!0,s._updateFlags=15;const r=this.renderGroup||this.parentRenderGroup;return r&&r.addChild(s),this.sortableChildren&&(this.sortDirty=!0),this.emit("childAdded",s,this,e),s.emit("added",this),s},swapChildren(s,e){if(s===e)return;const t=this.getChildIndex(s),r=this.getChildIndex(e);this.children[t]=e,this.children[r]=s;const n=this.renderGroup||this.parentRenderGroup;n&&(n.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){this.parent?.removeChild(this)},reparentChild(...s){return s.length===1?this.reparentChildAt(s[0],this.children.length):(s.forEach(e=>this.reparentChildAt(e,this.children.length)),s[0])},reparentChildAt(s,e){if(s.parent===this)return this.setChildIndex(s,e),s;const t=s.worldTransform.clone();s.removeFromParent(),this.addChildAt(s,e);const r=this.worldTransform.clone();return r.invert(),t.prepend(r),s.setFromMatrix(t),s},replaceChild(s,e){s.updateLocalTransform(),this.addChildAt(e,this.getChildIndex(s)),e.setFromMatrix(s.localTransform),e.updateLocalTransform(),this.removeChild(s)}},_p={collectRenderables(s,e,t){this.parentRenderLayer&&this.parentRenderLayer!==t||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(s,e,t):this.renderGroup?e.renderPipes.renderGroup.addRenderGroup(this.renderGroup,s):this.collectRenderablesWithEffects(s,e,t))},collectRenderablesSimple(s,e,t){const r=this.children,n=r.length;for(let o=0;o<n;o++)r[o].collectRenderables(s,e,t)},collectRenderablesWithEffects(s,e,t){const{renderPipes:r}=e;for(let n=0;n<this.effects.length;n++){const o=this.effects[n];r[o.pipe].push(o,this,s)}this.collectRenderablesSimple(s,e,t);for(let n=this.effects.length-1;n>=0;n--){const o=this.effects[n];r[o.pipe].pop(o,this,s)}}};class Cr{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 yp{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 r=this._tests[t];if(r.test(e))return me.get(r.maskClass,e)}return e}returnMaskEffect(e){me.return(e)}}const Os=new yp;L.handleByList(C.MaskEffect,Os._effectClasses);const xp={_maskEffect:null,_maskOptions:{inverse:!1},_filterEffect:null,effects:[],_markStructureAsChanged(){const s=this.renderGroup||this.parentRenderGroup;s&&(s.structureDidChange=!0)},addEffect(s){this.effects.indexOf(s)===-1&&(this.effects.push(s),this.effects.sort((t,r)=>t.priority-r.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(s){const e=this.effects.indexOf(s);e!==-1&&(this.effects.splice(e,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(s){const e=this._maskEffect;e?.mask!==s&&(e&&(this.removeEffect(e),Os.returnMaskEffect(e),this._maskEffect=null),s!=null&&(this._maskEffect=Os.getMaskEffect(s),this.addEffect(this._maskEffect)))},get mask(){return this._maskEffect?.mask},setMask(s){this._maskOptions={...this._maskOptions,...s},s.mask&&(this.mask=s.mask),this._markStructureAsChanged()},set filters(s){!Array.isArray(s)&&s&&(s=[s]);const e=this._filterEffect||(this._filterEffect=new Cr);s=s;const t=s?.length>0,r=e.filters?.length>0,n=t!==r;s=Array.isArray(s)?s.slice(0):s,e.filters=Object.freeze(s),n&&(t?this.addEffect(e):(this.removeEffect(e),e.filters=s??null))},get filters(){return this._filterEffect?.filters},set filterArea(s){this._filterEffect||(this._filterEffect=new Cr),this._filterEffect.filterArea=s},get filterArea(){return this._filterEffect?.filterArea}},bp={label:null,get name(){return H(j,"Container.name property has been removed, use Container.label instead"),this.label},set name(s){H(j,"Container.name property has been removed, use Container.label instead"),this.label=s},getChildByName(s,e=!1){return this.getChildByLabel(s,e)},getChildByLabel(s,e=!1){const t=this.children;for(let r=0;r<t.length;r++){const n=t[r];if(n.label===s||s instanceof RegExp&&s.test(n.label))return n}if(e)for(let r=0;r<t.length;r++){const o=t[r].getChildByLabel(s,!0);if(o)return o}return null},getChildrenByLabel(s,e=!1,t=[]){const r=this.children;for(let n=0;n<r.length;n++){const o=r[n];(o.label===s||s instanceof RegExp&&s.test(o.label))&&t.push(o)}if(e)for(let n=0;n<r.length;n++)r[n].getChildrenByLabel(s,!0,t);return t}},Fe=me.getPool(B),pt=me.getPool(Se),Tp=new B,wp={getFastGlobalBounds(s,e){e||(e=new Se),e.clear(),this._getGlobalBoundsRecursive(!!s,e,this.parentRenderLayer),e.isValid||e.set(0,0,0,0);const t=this.renderGroup||this.parentRenderGroup;return e.applyMatrix(t.worldTransform),e},_getGlobalBoundsRecursive(s,e,t){let r=e;if(s&&this.parentRenderLayer&&this.parentRenderLayer!==t||this.localDisplayStatus!==7||!this.measurable)return;const n=!!this.effects.length;if((this.renderGroup||n)&&(r=pt.get().clear()),this.boundsArea)e.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const c=this.bounds;r.addFrame(c.minX,c.minY,c.maxX,c.maxY,this.groupTransform)}const o=this.children;for(let c=0;c<o.length;c++)o[c]._getGlobalBoundsRecursive(s,r,t)}if(n){let o=!1;const c=this.renderGroup||this.parentRenderGroup;for(let l=0;l<this.effects.length;l++)this.effects[l].addBounds&&(o||(o=!0,r.applyMatrix(c.worldTransform)),this.effects[l].addBounds(r,!0));o&&r.applyMatrix(c.worldTransform.copyTo(Tp).invert()),e.addBounds(r),pt.return(r)}else this.renderGroup&&(e.addBounds(r,this.relativeGroupTransform),pt.return(r))}};function Gs(s,e,t){t.clear();let r,n;return s.parent?e?r=s.parent.worldTransform:(n=Fe.get().identity(),r=Ls(s,n)):r=B.IDENTITY,Ua(s,t,r,e),n&&Fe.return(n),t.isValid||t.set(0,0,0,0),t}function Ua(s,e,t,r){if(!s.visible||!s.measurable)return;let n;r?n=s.worldTransform:(s.updateLocalTransform(),n=Fe.get(),n.appendFrom(s.localTransform,t));const o=e,c=!!s.effects.length;if(c&&(e=pt.get().clear()),s.boundsArea)e.addRect(s.boundsArea,n);else{const l=s.bounds;l&&!l.isEmpty()&&(e.matrix=n,e.addBounds(l));for(let d=0;d<s.children.length;d++)Ua(s.children[d],e,n,r)}if(c){for(let l=0;l<s.effects.length;l++)s.effects[l].addBounds?.(e);o.addBounds(e,B.IDENTITY),pt.return(e)}r||Fe.return(n)}function Ls(s,e){const t=s.parent;return t&&(Ls(t,e),t.updateLocalTransform(),e.append(t.localTransform)),e}function ka(s,e){if(s===16777215||!e)return e;if(e===16777215||!s)return s;const t=s>>16&255,r=s>>8&255,n=s&255,o=e>>16&255,c=e>>8&255,l=e&255,d=t*o/255|0,f=r*c/255|0,m=n*l/255|0;return(d<<16)+(f<<8)+m}const Ba=16777215;function Ar(s,e){return s===Ba?e:e===Ba?s:ka(s,e)}function Er(s){return((s&255)<<16)+(s&65280)+(s>>16&255)}const Sp={getGlobalAlpha(s){if(s)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(s=new B,e){if(e)return s.copyFrom(this.worldTransform);this.updateLocalTransform();const t=Ls(this,Fe.get().identity());return s.appendFrom(this.localTransform,t),Fe.return(t),s},getGlobalTint(s){if(s)return this.renderGroup?Er(this.renderGroup.worldColor):this.parentRenderGroup?Er(Ar(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let e=this.localColor,t=this.parent;for(;t;)e=Ar(e,t.localColor),t=t.parent;return Er(e)}};function Ns(s,e,t){return e.clear(),t||(t=B.IDENTITY),Da(s,e,t,s,!0),e.isValid||e.set(0,0,0,0),e}function Da(s,e,t,r,n){let o;if(n)o=Fe.get(),o=t.copyTo(o);else{if(!s.visible||!s.measurable)return;s.updateLocalTransform();const d=s.localTransform;o=Fe.get(),o.appendFrom(d,t)}const c=e,l=!!s.effects.length;if(l&&(e=pt.get().clear()),s.boundsArea)e.addRect(s.boundsArea,o);else{s.renderPipeId&&(e.matrix=o,e.addBounds(s.bounds));const d=s.children;for(let f=0;f<d.length;f++)Da(d[f],e,o,r,!1)}if(l){for(let d=0;d<s.effects.length;d++)s.effects[d].addLocalBounds?.(e,r);c.addBounds(e,B.IDENTITY),pt.return(e)}Fe.return(o)}function Oa(s,e){const t=s.children;for(let r=0;r<t.length;r++){const n=t[r],o=n.uid,c=(n._didViewChangeTick&65535)<<16|n._didContainerChangeTick&65535,l=e.index;(e.data[l]!==o||e.data[l+1]!==c)&&(e.data[e.index]=o,e.data[e.index+1]=c,e.didChange=!0),e.index=l+2,n.children.length&&Oa(n,e)}return e.didChange}const Cp=new B,Ap={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(s,e){const t=Math.sign(this.scale.x)||1;e!==0?this.scale.x=s/e*t:this.scale.x=t},_setHeight(s,e){const t=Math.sign(this.scale.y)||1;e!==0?this.scale.y=s/e*t:this.scale.y=t},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Se});const s=this._localBoundsCacheData;return s.index=1,s.didChange=!1,s.data[0]!==this._didViewChangeTick&&(s.didChange=!0,s.data[0]=this._didViewChangeTick),Oa(this,s),s.didChange&&Ns(this,s.localBounds,Cp),s.localBounds},getBounds(s,e){return Gs(this,s,e||new Se)}},Ep={_onRender:null,set onRender(s){const e=this.renderGroup||this.parentRenderGroup;if(!s){this._onRender&&e?.removeOnRender(this),this._onRender=null;return}this._onRender||e?.addOnRender(this),this._onRender=s},get onRender(){return this._onRender}},Ip={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(s){this._zIndex!==s&&(this._zIndex=s,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(Pp))}};function Pp(s,e){return s._zIndex-e._zIndex}const Rp={getGlobalPosition(s=new J,e=!1){return this.parent?this.parent.toGlobal(this._position,s,e):(s.x=this._position.x,s.y=this._position.y),s},toGlobal(s,e,t=!1){const r=this.getGlobalTransform(Fe.get(),t);return e=r.apply(s,e),Fe.return(r),e},toLocal(s,e,t,r){e&&(s=e.toGlobal(s,t,r));const n=this.getGlobalTransform(Fe.get(),r);return t=n.applyInverse(s,t),Fe.return(n),t}};class Ga{constructor(){this.uid=ae("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let Mp=0;class Fp{constructor(e){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=e||{},this.enableFullScreen=!1,this.textureStyle=new at(this.textureOptions)}createTexture(e,t,r){const n=new ge({...this.textureOptions,width:e,height:t,resolution:1,antialias:r,autoGarbageCollect:!1});return new F({source:n,label:`texturePool_${Mp++}`})}getOptimalTexture(e,t,r=1,n){let o=Math.ceil(e*r-1e-6),c=Math.ceil(t*r-1e-6);o=Jt(o),c=Jt(c);const l=(o<<17)+(c<<1)+(n?1:0);this._texturePool[l]||(this._texturePool[l]=[]);let d=this._texturePool[l].pop();return d||(d=this.createTexture(o,c,n)),d.source._resolution=r,d.source.width=o/r,d.source.height=c/r,d.source.pixelWidth=o,d.source.pixelHeight=c,d.frame.x=0,d.frame.y=0,d.frame.width=e,d.frame.height=t,d.updateUvs(),this._poolKeyHash[d.uid]=l,d}getSameSizeTexture(e,t=!1){const r=e.source;return this.getOptimalTexture(e.width,e.height,r._resolution,t)}returnTexture(e,t=!1){const r=this._poolKeyHash[e.uid];t&&(e.source.style=this.textureStyle),this._texturePool[r].push(e)}clear(e){if(e=e!==!1,e)for(const t in this._texturePool){const r=this._texturePool[t];if(r)for(let n=0;n<r.length;n++)r[n].destroy(!0)}this._texturePool={}}}const Te=new Fp;ei.register(Te);class zs{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new B,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 Ga,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 r=0;r<t.length;r++){const n=t[r];n._updateFlags=15,this.addChild(n)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Te.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const e in this.childrenToUpdate){const t=this.childrenToUpdate[e];t.list.fill(null),t.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){const t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.parent===this.root?e.relativeRenderGroupDepth=1:e.relativeRenderGroupDepth=e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);const t=e.children;for(let r=0;r<t.length;r++)this.addChild(t[r])}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 r=0;r<t.length;r++)this.removeChild(t[r])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||(t=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]}),t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.push(e)}removeOnRender(e){this._onRenderContainers.splice(this._onRenderContainers.indexOf(e),1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet=null}getChildren(e=[]){const t=this.root.children;for(let r=0;r<t.length;r++)this._getChildren(t[r],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;const r=e.children;for(let n=0;n<r.length;n++)this._getChildren(r[n],t);return t}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return(this._matrixDirty&1)===0?this._inverseWorldTransform:(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new B),this._inverseWorldTransform.copyFrom(this.worldTransform).invert())}get textureOffsetInverseTransform(){return(this._matrixDirty&2)===0?this._textureOffsetInverseTransform:(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new B),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 B),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 Up(s,e,t={}){for(const r in e)!t[r]&&e[r]!==void 0&&(s[r]=e[r])}const Hs=new be(null),Ir=new be(null),Ws=new be(null,1,1),Pr=new be(null),Rr=1,Vs=2,Ei=4;class se extends Ge{constructor(e={}){super(),this.uid=ae("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 B,this.relativeGroupTransform=new B,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new be(this,0,0),this._scale=Ws,this._pivot=Ir,this._origin=Pr,this._skew=Hs,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=[],Up(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."),L.mixin(se,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(j,"addChild: Only Containers will be allowed to add children in v8.0.0"),e.length>1){for(let n=0;n<e.length;n++)this.addChild(e[n]);return e[0]}const t=e[0],r=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),r&&(r.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,r&&r.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 n=0;n<e.length;n++)this.removeChild(e[n]);return e[0]}const t=e[0],r=this.children.indexOf(t);return r>-1&&(this._didViewChangeTick++,this.children.splice(r,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,r),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=me.get(zs,this),this.groupTransform=B.IDENTITY,e?.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),me.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 B),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*Zf}set angle(e){this.rotation=e*Jf}get pivot(){return this._pivot===Ir&&(this._pivot=new be(this,0,0)),this._pivot}set pivot(e){this._pivot===Ir&&(this._pivot=new be(this,0,0),this._origin!==Pr&&G("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===Hs&&(this._skew=new be(this,0,0)),this._skew}set skew(e){this._skew===Hs&&(this._skew=new be(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===Ws&&(this._scale=new be(this,1,1)),this._scale}set scale(e){this._scale===Ws&&(this._scale=new be(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===Pr&&(this._origin=new be(this,0,0)),this._origin}set origin(e){this._origin===Pr&&(this._origin=new be(this,0,0),this._pivot!==Ir&&G("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 r=this.getLocalBounds();typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,r.width),t!==void 0&&this._setHeight(t,r.height)}_updateSkew(){const e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x=="number"?e.x:this.position.x,typeof e.y=="number"?e.y:this.position.y),this.scale.set(typeof e.scaleX=="number"?e.scaleX||1:this.scale.x,typeof e.scaleY=="number"?e.scaleY||1:this.scale.y),this.rotation=typeof e.rotation=="number"?e.rotation:this.rotation,this.skew.set(typeof e.skewX=="number"?e.skewX:this.skew.x,typeof e.skewY=="number"?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX=="number"?e.pivotX:this.pivot.x,typeof e.pivotY=="number"?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX=="number"?e.originX:this.origin.x,typeof e.originY=="number"?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){const e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;const t=this.localTransform,r=this._scale,n=this._pivot,o=this._origin,c=this._position,l=r._x,d=r._y,f=n._x,m=n._y,g=-o._x,_=-o._y;t.a=this._cx*l,t.b=this._sx*l,t.c=this._cy*d,t.d=this._sy*d,t.tx=c._x-(f*t.a+m*t.c)+(g*t.a+_*t.c)-g,t.ty=c._y-(f*t.b+m*t.d)+(g*t.b+_*t.d)-_}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=Rr,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){const r=le.shared.setValue(e??16777215).toBgrNumber();r!==this.localColor&&(this.localColor=r,this._updateFlags|=Rr,this._onUpdate())}get tint(){return Er(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Vs,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|=Ei,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(e){const t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Ei,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|=Ei,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 n=0;n<t.length;++n)t[n].destroy(e);this.renderGroup?.destroy(),this.renderGroup=null}}L.mixin(se,vp,wp,Rp,Ep,Ap,xp,bp,Ip,fp,gp,Sp,_p);class Ys extends se{constructor(e){super(e),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this._bounds=new Se(0,1,0,0),this._boundsDirty=!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:r,y:n}=e;return r>=t.minX&&r<=t.maxX&&n>=t.minY&&n<=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)}destroy(e){super.destroy(e),this._bounds=null;for(const t in this._gpuData)this._gpuData[t].destroy?.();this._gpuData=null}collectRenderablesSimple(e,t,r){const{renderPipes:n}=t;n.blendMode.pushBlendMode(this,this.groupBlendMode,e),n[this.renderPipeId].addRenderable(this,e),this.didViewUpdate=!1;const c=this.children,l=c.length;for(let d=0;d<l;d++)c[d].collectRenderables(e,t,r);n.blendMode.popBlendMode(e)}}class we extends Ys{constructor(e=F.EMPTY){e instanceof F&&(e={texture:e});const{texture:t=F.EMPTY,anchor:r,roundPixels:n,width:o,height:c,...l}=e;super({label:"Sprite",...l}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new be({_onUpdate:()=>{this.onViewUpdate()}}),r?this.anchor=r:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=n??!1,o!==void 0&&(this.width=o),c!==void 0&&(this.height=c)}static from(e,t=!1){return e instanceof F?new we(e):new we(F.from(e,t))}set texture(e){e||(e=F.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 ya(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,r=this._bounds,{width:n,height:o}=t.orig;r.minX=-e._x*n,r.maxX=r.minX+n,r.minY=-e._y*o,r.maxY=r.minY+o}destroy(e=!1){if(super.destroy(e),typeof e=="boolean"?e:e?.texture){const r=typeof e=="boolean"?e:e?.textureSource;this._texture.destroy(r)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null,this._gpuData=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 kp=new Se;function La(s,e,t){const r=kp;s.measurable=!0,Gs(s,t,r),e.addBoundsMask(r),s.measurable=!1}function Na(s,e,t){const r=pt.get();s.measurable=!0;const n=Fe.get().identity(),o=za(s,t,n);Ns(s,r,o),s.measurable=!1,e.addBoundsMask(r),Fe.return(n),pt.return(r)}function za(s,e,t){return s?(s!==e&&(za(s.parent,e,t),s.updateLocalTransform(),t.append(s.localTransform)),t):(G("Mask bounds, renderable is not inside the root container"),t)}class Ha{constructor(e){this.priority=0,this.inverse=!1,this.pipe="alphaMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e instanceof we),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||La(this.mask,e,t)}addLocalBounds(e,t){Na(this.mask,e,t)}containsPoint(e,t){const r=this.mask;return t(r,e)}destroy(){this.reset()}static test(e){return e instanceof we}}Ha.extension=C.MaskEffect;class Wa{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"}}Wa.extension=C.MaskEffect;class Va{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){La(this.mask,e,t)}addLocalBounds(e,t){Na(this.mask,e,t)}containsPoint(e,t){const r=this.mask;return t(r,e)}destroy(){this.reset()}static test(e){return e instanceof se}}Va.extension=C.MaskEffect;let Ya={createCanvas:(s,e)=>{const t=document.createElement("canvas");return t.width=s,t.height=e,t},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(s,e)=>fetch(s,e),parseXML:s=>new DOMParser().parseFromString(s,"text/xml")};const V={get(){return Ya},set(s){Ya=s}};class mt extends ge{constructor(e){e.resource||(e.resource=V.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,r=this._resolution){const n=super.resize(e,t,r);return n&&this.resizeCanvas(),n}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"))}}mt.extension=C.TextureSource;class ct extends ge{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}}ct.extension=C.TextureSource;var ti=(s=>(s[s.INTERACTION=50]="INTERACTION",s[s.HIGH=25]="HIGH",s[s.NORMAL=0]="NORMAL",s[s.LOW=-25]="LOW",s[s.UTILITY=-50]="UTILITY",s))(ti||{});class Xs{constructor(e,t=null,r=0,n=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=r,this._once=n}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 Xa=class Ve{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 Xs(null,null,1/0),this.deltaMS=1/Ve.targetFPMS,this.elapsedMS=1/Ve.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,r=ti.NORMAL){return this._addListener(new Xs(e,t,r))}addOnce(e,t,r=ti.NORMAL){return this._addListener(new Xs(e,t,r,!0))}_addListener(e){let t=this._head.next,r=this._head;if(!t)e.connect(r);else{for(;t;){if(e.priority>t.priority){e.connect(r);break}r=t,t=t.next}e.previous||e.connect(r)}return this._startIfPossible(),this}remove(e,t){let r=this._head.next;for(;r;)r.match(e,t)?r=r.destroy():r=r.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 o=e-this._lastFrame|0;if(o<this._minElapsedMS)return;this._lastFrame=e-o%this._minElapsedMS}this.deltaMS=t,this.deltaTime=this.deltaMS*Ve.targetFPMS;const r=this._head;let n=r.next;for(;n;)n=n.emit(this);r.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const t=Math.min(this.maxFPS,e),r=Math.min(Math.max(0,t)/1e3,Ve.targetFPMS);this._maxElapsedMS=1/r}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){if(e===0)this._minElapsedMS=0;else{const t=Math.max(this.minFPS,e);this._minElapsedMS=1/(t/1e3)}}static get shared(){if(!Ve._shared){const e=Ve._shared=new Ve;e.autoStart=!0,e._protected=!0}return Ve._shared}static get system(){if(!Ve._system){const e=Ve._system=new Ve;e.autoStart=!0,e._protected=!0}return Ve._system}};Xa.targetFPMS=.06;let Le=Xa,$s;async function $a(){return $s??($s=(async()=>{const e=V.get().createCanvas(1,1).getContext("webgl");if(!e)return"premultiply-alpha-on-upload";const t=await new Promise(c=>{const l=document.createElement("video");l.onloadeddata=()=>c(l),l.onerror=()=>c(null),l.autoplay=!1,l.crossOrigin="anonymous",l.preload="auto",l.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",l.load()});if(!t)return"premultiply-alpha-on-upload";const r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r);const n=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,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 o=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,o),e.deleteFramebuffer(n),e.deleteTexture(r),e.getExtension("WEBGL_lose_context")?.loseContext(),o[0]<=o[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),$s}const Mr=class dd extends ge{constructor(e){super(e),this.isReady=!1,this.uploadMethodId="video",e={...dd.defaultOptions,...e},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this.alphaMode=e.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),e.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const e=Le.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener("play",this._onPlayStart),e.addEventListener("pause",this._onPlayStop),e.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlayThrough),e.addEventListener("error",this._onError,!0)),this.alphaMode=await $a(),this._load=new Promise((r,n)=>{this.isValid?r(this):(this._resolve=r,this._reject=n,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.resource;return!e.paused&&!e.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this.isValid||this._mediaReady(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlay),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const e=this.resource;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlayThrough),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(Le.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||(Le.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Le.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};Mr.extension=C.TextureSource,Mr.defaultOptions={...ge.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 Ii=Mr;const Qe=(s,e,t=!1)=>(Array.isArray(s)||(s=[s]),e?s.map(r=>typeof r=="string"||t?e(r):r):s);class Bp{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||G(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){const r=Qe(e);let n;for(let d=0;d<this.parsers.length;d++){const f=this.parsers[d];if(f.test(t)){n=f.getCacheableAssets(r,t);break}}const o=new Map(Object.entries(n||{}));n||r.forEach(d=>{o.set(d,t)});const c=[...o.keys()],l={cacheKeys:c,keys:r};r.forEach(d=>{this._cacheMap.set(d,l)}),c.forEach(d=>{const f=n?n[d]:t;this._cache.has(d)&&this._cache.get(d)!==f&&G("[Cache] already has key:",d),this._cache.set(d,o.get(d))})}remove(e){if(!this._cacheMap.has(e)){G(`[Assets] Asset id ${e} was not found in the Cache`);return}const t=this._cacheMap.get(e);t.cacheKeys.forEach(n=>{this._cache.delete(n)}),t.keys.forEach(n=>{this._cacheMap.delete(n)})}get parsers(){return this._parsers}}const re=new Bp,qs=[];L.handleByList(C.TextureSource,qs);function qa(s={}){const e=s&&s.resource,t=e?s.resource:s,r=e?s:{resource:s};for(let n=0;n<qs.length;n++){const o=qs[n];if(o.test(t))return new o(r)}throw new Error(`Could not find a source type for resource: ${r.resource}`)}function Dp(s={},e=!1){const t=s&&s.resource,r=t?s.resource:s,n=t?s:{resource:s};if(!e&&re.has(r))return re.get(r);const o=new F({source:qa(n)});return o.on("destroy",()=>{re.has(r)&&re.remove(r)}),e||re.set(r,o),o}function Op(s,e=!1){return typeof s=="string"?re.get(s):s instanceof ge?new F({source:s}):Dp(s,e)}F.from=Op,ge.from=qa,L.add(Ha,Wa,Va,Ii,ct,mt,Rs);var At=(s=>(s[s.Low=0]="Low",s[s.Normal=1]="Normal",s[s.High=2]="High",s))(At||{});function et(s){if(typeof s!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(s)}`)}function Pi(s){return s.split("?")[0].split("#")[0]}function Gp(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Lp(s,e,t){return s.replace(new RegExp(Gp(e),"g"),t)}function Np(s,e){let t="",r=0,n=-1,o=0,c=-1;for(let l=0;l<=s.length;++l){if(l<s.length)c=s.charCodeAt(l);else{if(c===47)break;c=47}if(c===47){if(!(n===l-1||o===1))if(n!==l-1&&o===2){if(t.length<2||r!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){const d=t.lastIndexOf("/");if(d!==t.length-1){d===-1?(t="",r=0):(t=t.slice(0,d),r=t.length-1-t.lastIndexOf("/")),n=l,o=0;continue}}else if(t.length===2||t.length===1){t="",r=0,n=l,o=0;continue}}}else t.length>0?t+=`/${s.slice(n+1,l)}`:t=s.slice(n+1,l),r=l-n-1;n=l,o=0}else c===46&&o!==-1?++o:o=-1}return t}const Ne={toPosix(s){return Lp(s,"\\","/")},isUrl(s){return/^https?:/.test(this.toPosix(s))},isDataUrl(s){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(s)},isBlobUrl(s){return s.startsWith("blob:")},hasProtocol(s){return/^[^/:]+:/.test(this.toPosix(s))},getProtocol(s){et(s),s=this.toPosix(s);const e=/^file:\/\/\//.exec(s);if(e)return e[0];const t=/^[^/:]+:\/{0,2}/.exec(s);return t?t[0]:""},toAbsolute(s,e,t){if(et(s),this.isDataUrl(s)||this.isBlobUrl(s))return s;const r=Pi(this.toPosix(e??V.get().getBaseUrl())),n=Pi(this.toPosix(t??this.rootname(r)));return s=this.toPosix(s),s.startsWith("/")?Ne.join(n,s.slice(1)):this.isAbsolute(s)?s:this.join(r,s)},normalize(s){if(et(s),s.length===0)return".";if(this.isDataUrl(s)||this.isBlobUrl(s))return s;s=this.toPosix(s);let e="";const t=s.startsWith("/");this.hasProtocol(s)&&(e=this.rootname(s),s=s.slice(e.length));const r=s.endsWith("/");return s=Np(s),s.length>0&&r&&(s+="/"),t?`/${s}`:e+s},isAbsolute(s){return et(s),s=this.toPosix(s),this.hasProtocol(s)?!0:s.startsWith("/")},join(...s){if(s.length===0)return".";let e;for(let t=0;t<s.length;++t){const r=s[t];if(et(r),r.length>0)if(e===void 0)e=r;else{const n=s[t-1]??"";this.joinExtensions.includes(this.extname(n).toLowerCase())?e+=`/../${r}`:e+=`/${r}`}}return e===void 0?".":this.normalize(e)},dirname(s){if(et(s),s.length===0)return".";s=this.toPosix(s);let e=s.charCodeAt(0);const t=e===47;let r=-1,n=!0;const o=this.getProtocol(s),c=s;s=s.slice(o.length);for(let l=s.length-1;l>=1;--l)if(e=s.charCodeAt(l),e===47){if(!n){r=l;break}}else n=!1;return r===-1?t?"/":this.isUrl(c)?o+s:o:t&&r===1?"//":o+s.slice(0,r)},rootname(s){et(s),s=this.toPosix(s);let e="";if(s.startsWith("/")?e="/":e=this.getProtocol(s),this.isUrl(s)){const t=s.indexOf("/",e.length);t!==-1?e=s.slice(0,t):e=s,e.endsWith("/")||(e+="/")}return e},basename(s,e){et(s),e&&et(e),s=Pi(this.toPosix(s));let t=0,r=-1,n=!0,o;if(e!==void 0&&e.length>0&&e.length<=s.length){if(e.length===s.length&&e===s)return"";let c=e.length-1,l=-1;for(o=s.length-1;o>=0;--o){const d=s.charCodeAt(o);if(d===47){if(!n){t=o+1;break}}else l===-1&&(n=!1,l=o+1),c>=0&&(d===e.charCodeAt(c)?--c===-1&&(r=o):(c=-1,r=l))}return t===r?r=l:r===-1&&(r=s.length),s.slice(t,r)}for(o=s.length-1;o>=0;--o)if(s.charCodeAt(o)===47){if(!n){t=o+1;break}}else r===-1&&(n=!1,r=o+1);return r===-1?"":s.slice(t,r)},extname(s){et(s),s=Pi(this.toPosix(s));let e=-1,t=0,r=-1,n=!0,o=0;for(let c=s.length-1;c>=0;--c){const l=s.charCodeAt(c);if(l===47){if(!n){t=c+1;break}continue}r===-1&&(n=!1,r=c+1),l===46?e===-1?e=c:o!==1&&(o=1):e!==-1&&(o=-1)}return e===-1||r===-1||o===0||o===1&&e===r-1&&e===t+1?"":s.slice(e,r)},parse(s){et(s);const e={root:"",dir:"",base:"",ext:"",name:""};if(s.length===0)return e;s=Pi(this.toPosix(s));let t=s.charCodeAt(0);const r=this.isAbsolute(s);let n;e.root=this.rootname(s),r||this.hasProtocol(s)?n=1:n=0;let o=-1,c=0,l=-1,d=!0,f=s.length-1,m=0;for(;f>=n;--f){if(t=s.charCodeAt(f),t===47){if(!d){c=f+1;break}continue}l===-1&&(d=!1,l=f+1),t===46?o===-1?o=f:m!==1&&(m=1):o!==-1&&(m=-1)}return o===-1||l===-1||m===0||m===1&&o===l-1&&o===c+1?l!==-1&&(c===0&&r?e.base=e.name=s.slice(1,l):e.base=e.name=s.slice(c,l)):(c===0&&r?(e.name=s.slice(1,o),e.base=s.slice(1,l)):(e.name=s.slice(c,o),e.base=s.slice(c,l)),e.ext=s.slice(o,l)),e.dir=this.dirname(s),e},sep:"/",delimiter:":",joinExtensions:[".html"]};function Ka(s,e,t,r,n){const o=e[t];for(let c=0;c<o.length;c++){const l=o[c];t<e.length-1?Ka(s.replace(r[t],l),e,t+1,r,n):n.push(s.replace(r[t],l))}}function zp(s){const e=/\{(.*?)\}/g,t=s.match(e),r=[];if(t){const n=[];t.forEach(o=>{const c=o.substring(1,o.length-1).split(",");n.push(c)}),Ka(s,n,0,t,r)}else r.push(s);return r}const Fr=s=>!Array.isArray(s);class ii{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(r=>`${encodeURIComponent(r)}=${encodeURIComponent(t[r])}`).join("&")}}getAlias(e){const{alias:t,src:r}=e;return Qe(t||r,o=>typeof o=="string"?o:Array.isArray(o)?o.map(c=>c?.src??c):o?.src?o.src:o,!0)}addManifest(e){this._manifest&&G("[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 r=[];let n=t;Array.isArray(t)||(n=Object.entries(t).map(([o,c])=>typeof c=="string"||Array.isArray(c)?{alias:o,src:c}:{alias:o,...c})),n.forEach(o=>{const c=o.src,l=o.alias;let d;if(typeof l=="string"){const f=this._createBundleAssetId(e,l);r.push(f),d=[l,f]}else{const f=l.map(m=>this._createBundleAssetId(e,m));r.push(...f),d=[...l,...f]}this.add({...o,alias:d,src:c})}),this._bundles[e]=r}add(e){const t=[];Array.isArray(e)?t.push(...e):t.push(e);let r;r=o=>{this.hasKey(o)&&G(`[Resolver] already has key: ${o} overwriting`)},Qe(t).forEach(o=>{const{src:c}=o;let{data:l,format:d,loadParser:f,parser:m}=o;const g=Qe(c).map(h=>typeof h=="string"?zp(h):Array.isArray(h)?h:[h]),_=this.getAlias(o);Array.isArray(_)?_.forEach(r):r(_);const y=[],a=h=>({...this._parsers.find(p=>p.test(h))?.parse(h),src:h});g.forEach(h=>{h.forEach(u=>{let p={};if(typeof u!="object"?p=a(u):(l=u.data??l,d=u.format??d,(u.loadParser||u.parser)&&(f=u.loadParser??f,m=u.parser??m),p={...a(u.src),...u}),!_)throw new Error(`[Resolver] alias is undefined for this asset: ${p.src}`);p=this._buildResolvedAsset(p,{aliases:_,data:l,format:d,loadParser:f,parser:m,progressSize:o.progressSize}),y.push(p)})}),_.forEach(h=>{this._assetMap[h]=y})})}resolveBundle(e){const t=Fr(e);e=Qe(e);const r={};return e.forEach(n=>{const o=this._bundles[n];if(o){const c=this.resolve(o),l={};for(const d in c){const f=c[d];l[this._extractAssetIdFromBundle(n,d)]=f}r[n]=l}}),t?r[e[0]]:r}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const r={};for(const n in t)r[n]=t[n].src;return r}return t.src}resolve(e){const t=Fr(e);e=Qe(e);const r={};return e.forEach(n=>{if(!this._resolverHash[n])if(this._assetMap[n]){let o=this._assetMap[n];const c=this._getPreferredOrder(o);c?.priority.forEach(l=>{c.params[l].forEach(d=>{const f=o.filter(m=>m[l]?m[l]===d:!1);f.length&&(o=f)})}),this._resolverHash[n]=o[0]}else this._resolverHash[n]=this._buildResolvedAsset({alias:[n],src:n},{});r[n]=this._resolverHash[n]}),t?r[e[0]]:r}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const r=e[t],n=this._preferredOrder.find(o=>o.params.format.includes(r.format));if(n)return n}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:r,data:n,loadParser:o,parser:c,format:l,progressSize:d}=t;return(this._basePath||this._rootPath)&&(e.src=Ne.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=r??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...n||{},...e.data},e.loadParser=o??e.loadParser,e.parser=c??e.parser,e.format=l??e.format??Hp(e.src),d!==void 0&&(e.progressSize=d),e}}ii.RETINA_PREFIX=/@([0-9\.]+)x/;function Hp(s){return s.split(".").pop().split("?").shift().split("#").shift()}const Ks=(s,e)=>{const t=e.split("?")[1];return t&&(s+=`?${t}`),s},ja=class hr{constructor(e,t){this.linkedSheets=[];let r=e;e?.source instanceof ge&&(r={texture:e,data:t});const{texture:n,data:o,cachePrefix:c=""}=r;this.cachePrefix=c,this._texture=n instanceof F?n:null,this.textureSource=n.source,this.textures={},this.animations={},this.data=o;const l=parseFloat(o.meta.scale);l?(this.resolution=l,n.source.resolution=this.resolution):this.resolution=n.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<=hr.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(e){let t=e;const r=hr.BATCH_SIZE;for(;t-e<r&&t<this._frameKeys.length;){const n=this._frameKeys[t],o=this._frames[n],c=o.frame;if(c){let l=null,d=null;const f=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,m=new z(0,0,Math.floor(f.w)/this.resolution,Math.floor(f.h)/this.resolution);o.rotated?l=new z(Math.floor(c.x)/this.resolution,Math.floor(c.y)/this.resolution,Math.floor(c.h)/this.resolution,Math.floor(c.w)/this.resolution):l=new z(Math.floor(c.x)/this.resolution,Math.floor(c.y)/this.resolution,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution),o.trimmed!==!1&&o.spriteSourceSize&&(d=new z(Math.floor(o.spriteSourceSize.x)/this.resolution,Math.floor(o.spriteSourceSize.y)/this.resolution,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution)),this.textures[n]=new F({source:this.textureSource,frame:l,orig:m,trim:d,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:n.toString()})}t++}}_processAnimations(){const e=this.data.animations||{};for(const t in e){this.animations[t]=[];for(let r=0;r<e[t].length;r++){const n=e[t][r];this.animations[t].push(this.textures[n])}}}_parseComplete(){const e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*hr.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*hr.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=[]}};ja.BATCH_SIZE=1e3;let Za=ja;const Wp=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function Ja(s,e,t){const r={};if(s.forEach(n=>{r[n]=e}),Object.keys(e.textures).forEach(n=>{r[`${e.cachePrefix}${n}`]=e.textures[n]}),!t){const n=Ne.dirname(s[0]);e.linkedSheets.forEach((o,c)=>{const l=Ja([`${n}/${e.data.meta.related_multi_packs[c]}`],o,!0);Object.assign(r,l)})}return r}const Vp={extension:C.Asset,cache:{test:s=>s instanceof Za,getCacheableAssets:(s,e)=>Ja(s,e,!1)},resolver:{extension:{type:C.ResolveParser,name:"resolveSpritesheet"},test:s=>{const t=s.split("?")[0].split("."),r=t.pop(),n=t.pop();return r==="json"&&Wp.includes(n)},parse:s=>{const e=s.split(".");return{resolution:parseFloat(ii.RETINA_PREFIX.exec(s)?.[1]??"1"),format:e[e.length-2],src:s}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:C.LoadParser,priority:At.Normal,name:"spritesheetLoader"},async testParse(s,e){return Ne.extname(e.src).toLowerCase()===".json"&&!!s.frames},async parse(s,e,t){const{texture:r,imageFilename:n,textureOptions:o,cachePrefix:c}=e?.data??{};let l=Ne.dirname(e.src);l&&l.lastIndexOf("/")!==l.length-1&&(l+="/");let d;if(r instanceof F)d=r;else{const g=Ks(l+(n??s.meta.image),e.src);d=(await t.load([{src:g,data:o}]))[g]}const f=new Za({texture:d.source,data:s,cachePrefix:c});await f.parse();const m=s?.meta?.related_multi_packs;if(Array.isArray(m)){const g=[];for(const y of m){if(typeof y!="string")continue;let a=l+y;e.data?.ignoreMultiPack||(a=Ks(a,e.src),g.push(t.load({src:a,data:{textureOptions:o,ignoreMultiPack:!0}})))}const _=await Promise.all(g);f.linkedSheets=_,_.forEach(y=>{y.linkedSheets=[f].concat(f.linkedSheets.filter(a=>a!==y))})}return f},async unload(s,e,t){await t.unload(s.textureSource._sourceOrigin),s.destroy(!1)}}};L.add(Vp);class Qa{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),r=this._canvas.width,n=this._canvas.height,o=t.width/r*this._renderer.resolution,c=t.height/n*this._renderer.resolution,l=t.left,d=t.top,f=`translate(${l}px, ${d}px) scale(${o}, ${c})`;f!==this._lastTransform&&(this._domElement.style.transform=f,this._lastTransform=f)},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 r=this.canvas.width,n=this.canvas.height,o=t.contentRect.width/r*this._renderer.resolution,c=t.contentRect.height/n*this._renderer.resolution;(this._lastScaleX!==o||this._lastScaleY!==c)&&(this.updateTranslation(),this._lastScaleX=o,this._lastScaleY=c)}}),this._observer.observe(this._canvas)):this._tickerAttached||Le.shared.add(this.updateTranslation,this,ti.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&Le.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 Ri{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=Ri.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new J,this.page=new J,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,r){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,r,n,o){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 js=/iPhone/i,el=/iPod/i,tl=/iPad/i,il=/\biOS-universal(?:.+)Mac\b/i,Zs=/\bAndroid(?:.+)Mobile\b/i,rl=/Android/i,ri=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ur=/Silk/i,gt=/Windows Phone/i,sl=/\bWindows(?:.+)ARM\b/i,nl=/BlackBerry/i,ol=/BB10/i,al=/Opera Mini/i,ll=/\b(CriOS|Chrome)(?:.+)Mobile/i,cl=/Mobile(?:.+)Firefox\b/i,hl=function(s){return typeof s<"u"&&s.platform==="MacIntel"&&typeof s.maxTouchPoints=="number"&&s.maxTouchPoints>1&&typeof MSStream>"u"};function Yp(s){return function(e){return e.test(s)}}function ul(s){var e={userAgent:"",platform:"",maxTouchPoints:0};!s&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof s=="string"?e.userAgent=s:s&&s.userAgent&&(e={userAgent:s.userAgent,platform:s.platform,maxTouchPoints:s.maxTouchPoints||0});var t=e.userAgent,r=t.split("[FBAN");typeof r[1]<"u"&&(t=r[0]),r=t.split("Twitter"),typeof r[1]<"u"&&(t=r[0]);var n=Yp(t),o={apple:{phone:n(js)&&!n(gt),ipod:n(el),tablet:!n(js)&&(n(tl)||hl(e))&&!n(gt),universal:n(il),device:(n(js)||n(el)||n(tl)||n(il)||hl(e))&&!n(gt)},amazon:{phone:n(ri),tablet:!n(ri)&&n(Ur),device:n(ri)||n(Ur)},android:{phone:!n(gt)&&n(ri)||!n(gt)&&n(Zs),tablet:!n(gt)&&!n(ri)&&!n(Zs)&&(n(Ur)||n(rl)),device:!n(gt)&&(n(ri)||n(Ur)||n(Zs)||n(rl))||n(/\bokhttp\b/i)},windows:{phone:n(gt),tablet:n(sl),device:n(gt)||n(sl)},other:{blackberry:n(nl),blackberry10:n(ol),opera:n(al),firefox:n(cl),chrome:n(ll),device:n(nl)||n(ol)||n(al)||n(cl)||n(ll)},any:!1,phone:!1,tablet:!1};return o.any=o.apple.device||o.android.device||o.windows.device||o.other.device,o.phone=o.apple.phone||o.android.phone||o.windows.phone,o.tablet=o.apple.tablet||o.android.tablet||o.windows.tablet,o}const Xp=(ul.default??ul)(globalThis.navigator),$p=9,dl=100,qp=0,Kp=0,fl=2,pl=1,jp=-1e3,Zp=-1e3,Jp=2,Js=class fd{constructor(e,t=Xp){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=`${pl}px`,e.style.height=`${pl}px`,e.style.position="absolute",e.style.top=`${jp}px`,e.style.left=`${Zp}px`,e.style.zIndex=Jp.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=`${qp}px`,this._div.style.left=`${Kp}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=fl.toString(),this._canvasObserver=new Qa({domElement:this._div,renderer:this._renderer})),this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),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._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),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(r=>{r.parentNode&&r.parentNode.removeChild(r)}),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 r=0;r<t.length;r++)this._updateAccessibleObjects(t[r])}init(e){const r={accessibilityOptions:{...fd.defaultOptions,...e?.accessibilityOptions||{}}};this.debug=r.accessibilityOptions.debug,this._activateOnTab=r.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=r.accessibilityOptions.deactivateOnMouseMove,r.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 r of this._children)r._renderId===this._renderId&&t.add(this._children.indexOf(r))}for(let r=this._children.length-1;r>=0;r--){const n=this._children[r];t.has(r)||(n._accessibleDiv&&n._accessibleDiv.parentNode&&(n._accessibleDiv.parentNode.removeChild(n._accessibleDiv),this._getPool(n.accessibleType).push(n._accessibleDiv),n._accessibleDiv=null),n._accessibleActive=!1,Fa(this._children,r,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let r=0;r<this._children.length;r++){const n=this._children[r];if(!n._accessibleActive||!n._accessibleDiv)continue;const o=n._accessibleDiv,c=n.hitArea||n.getBounds().rectangle;if(n.hitArea){const l=n.worldTransform;o.style.left=`${l.tx+c.x*l.a}px`,o.style.top=`${l.ty+c.y*l.d}px`,o.style.width=`${c.width*l.a}px`,o.style.height=`${c.height*l.d}px`}else this._capHitArea(c),o.style.left=`${c.x}px`,o.style.top=`${c.y}px`,o.style.width=`${c.width}px`,o.style.height=`${c.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:r}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>r&&(e.height=r-e.y)}_addChild(e){let r=this._getPool(e.accessibleType).pop();r?(r.innerHTML="",r.removeAttribute("title"),r.removeAttribute("aria-label"),r.tabIndex=0):(e.accessibleType==="button"?r=document.createElement("button"):(r=document.createElement(e.accessibleType),r.style.cssText=`
|
|
67
|
+
`),o?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",n),console.warn(r),console.groupEnd()):(console.warn("PixiJS Deprecation Warning: ",n),console.warn(r))),ha.add(e)};Object.defineProperties(H,{quiet:{get:()=>Zt.quiet,set:s=>{Zt.quiet=s},enumerable:!0,configurable:!1},noColor:{get:()=>Zt.noColor,set:s=>{Zt.noColor=s},enumerable:!0,configurable:!1}});const ua=()=>{};function Jt(s){return s+=s===0?1:0,--s,s|=s>>>1,s|=s>>>2,s|=s>>>4,s|=s>>>8,s|=s>>>16,s+1}function da(s){return!(s&s-1)&&!!s}function fa(s){const e={};for(const t in s)s[t]!==void 0&&(e[t]=s[t]);return e}const pa=Object.create(null);function rp(s){const e=pa[s];return e===void 0&&(pa[s]=ae("resource")),e}const ma=class hd extends Le{constructor(e={}){super(),this._resourceType="textureSampler",this._touched=0,this._maxAnisotropy=1,this.destroyed=!1,e={...hd.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(j,"TextureStyle.wrapMode is now TextureStyle.addressMode"),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,16),this._maxAnisotropy>1&&(this.scaleMode="linear")}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this.emit("change",this),this._sharedResourceId=null}_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=rp(e),this._resourceId}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this.removeAllListeners()}};ma.defaultOptions={addressMode:"clamp-to-edge",scaleMode:"linear"};let at=ma;const ga=class ud extends Le{constructor(e={}){super(),this.options=e,this.uid=ae("textureSource"),this._resourceType="textureSource",this._resourceId=ae("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.antialias=!1,this._touched=0,this._batchTick=-1,this._textureBindLocation=-1,e={...ud.defaultOptions,...e},this.label=e.label??"",this.resource=e.resource,this.autoGarbageCollect=e.autoGarbageCollect,this._resolution=e.resolution,e.width?this.pixelWidth=e.width*this._resolution:this.pixelWidth=this.resource?this.resourceWidth??1:1,e.height?this.pixelHeight=e.height*this._resolution:this.pixelHeight=this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=e.format,this.dimension=e.dimensions,this.mipLevelCount=e.mipLevelCount,this.autoGenerateMipmaps=e.autoGenerateMipmaps,this.sampleCount=e.sampleCount,this.antialias=e.antialias,this.alphaMode=e.alphaMode,this.style=new at(fa(e)),this.destroyed=!1,this._refreshPOT()}get source(){return this}get style(){return this._style}set style(e){this.style!==e&&(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.emit("destroy",this),this.emit("change",this),this._style&&(this._style.destroy(),this._style=null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=ae("resource"),this.emit("change",this),this.emit("unload",this)}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,r){r||(r=this._resolution),e||(e=this.width),t||(t=this.height);const n=Math.round(e*r),o=Math.round(t*r);return this.width=n/r,this.height=o/r,this._resolution=r,this.pixelWidth===n&&this.pixelHeight===o?!1:(this._refreshPOT(),this.pixelWidth=n,this.pixelHeight=o,this.emit("resize",this),this._resourceId=ae("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=da(this.pixelWidth)&&da(this.pixelHeight)}static test(e){throw new Error("Unimplemented")}};ga.defaultOptions={resolution:1,format:"bgra8unorm",alphaMode:"premultiply-alpha-on-upload",dimensions:"2d",mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};let ge=ga;class Rs extends ge{constructor(e){const t=e.resource||new Float32Array(e.width*e.height*4);let r=e.format;r||(t instanceof Float32Array?r="rgba32float":t instanceof Int32Array||t instanceof Uint32Array?r="rgba32uint":t instanceof Int16Array||t instanceof Uint16Array?r="rgba16uint":(t instanceof Int8Array,r="bgra8unorm")),super({...e,resource:t,format:r}),this.uploadMethodId="buffer"}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}}Rs.extension=C.TextureSource;const va=new B;class _a{constructor(e,t){this.mapCoord=new B,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,typeof t>"u"?this.clampMargin=e.width<10?0:.5:this.clampMargin=t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){this.texture!==e&&(this._texture?.removeListener("update",this.update,this),this._texture=e,this._texture.addListener("update",this.update,this),this.update())}multiplyUvs(e,t){t===void 0&&(t=e);const r=this.mapCoord;for(let n=0;n<e.length;n+=2){const o=e[n],c=e[n+1];t[n]=o*r.a+c*r.c+r.tx,t[n+1]=o*r.b+c*r.d+r.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 r=e.orig,n=e.trim;n&&(va.set(r.width/n.width,0,0,r.height/n.height,-n.x/n.width,-n.y/n.height),this.mapCoord.append(va));const o=e.source,c=this.uClampFrame,l=this.clampMargin/o._resolution,d=this.clampOffset/o._resolution;return c[0]=(e.frame.x+l+d)/o.width,c[1]=(e.frame.y+l+d)/o.height,c[2]=(e.frame.x+e.frame.width-l+d)/o.width,c[3]=(e.frame.y+e.frame.height-l+d)/o.height,this.uClampOffset[0]=this.clampOffset/o.pixelWidth,this.uClampOffset[1]=this.clampOffset/o.pixelHeight,this.isSimple=e.frame.width===o.width&&e.frame.height===o.height&&e.rotate===0,!0}}class F extends Le{constructor({source:e,label:t,frame:r,orig:n,trim:o,defaultAnchor:c,defaultBorders:l,rotate:d,dynamic:f}={}){if(super(),this.uid=ae("texture"),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new z,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=e?.source??new ge,this.noFrame=!r,r)this.frame.copyFrom(r);else{const{width:m,height:g}=this._source;this.frame.width=m,this.frame.height=g}this.orig=n||this.frame,this.trim=o,this.rotate=d??0,this.defaultAnchor=c,this.defaultBorders=l,this.destroyed=!1,this.dynamic=f||!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 _a(this)),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){const{uvs:e,frame:t}=this,{width:r,height:n}=this._source,o=t.x/r,c=t.y/n,l=t.width/r,d=t.height/n;let f=this.rotate;if(f){const m=l/2,g=d/2,_=o+m,y=c+g;f=ie.add(f,ie.NW),e.x0=_+m*ie.uX(f),e.y0=y+g*ie.uY(f),f=ie.add(f,2),e.x1=_+m*ie.uX(f),e.y1=y+g*ie.uY(f),f=ie.add(f,2),e.x2=_+m*ie.uX(f),e.y2=y+g*ie.uY(f),f=ie.add(f,2),e.x3=_+m*ie.uX(f),e.y3=y+g*ie.uY(f)}else e.x0=o,e.y0=c,e.x1=o+l,e.y1=c,e.x2=o+l,e.y2=c+d,e.x3=o,e.y3=c+d}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(j,"Texture.baseTexture is now Texture.source"),this._source}}F.EMPTY=new F({label:"EMPTY",source:new ge({label:"EMPTY"})}),F.EMPTY.destroy=ua,F.WHITE=new F({source:new Rs({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:"premultiply-alpha-on-upload",label:"WHITE"}),label:"WHITE"}),F.WHITE.destroy=ua;function ya(s,e,t){const{width:r,height:n}=t.orig,o=t.trim;if(o){const c=o.width,l=o.height;s.minX=o.x-e._x*r,s.maxX=s.minX+c,s.minY=o.y-e._y*n,s.maxY=s.minY+l}else s.minX=-e._x*r,s.maxX=s.minX+r,s.minY=-e._y*n,s.maxY=s.minY+n}const xa=new B;class Se{constructor(e=1/0,t=1/0,r=-1/0,n=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=xa,this.minX=e,this.minY=t,this.maxX=r,this.maxY=n}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||(this._rectangle=new z);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=xa,this}set(e,t,r,n){this.minX=e,this.minY=t,this.maxX=r,this.maxY=n}addFrame(e,t,r,n,o){o||(o=this.matrix);const c=o.a,l=o.b,d=o.c,f=o.d,m=o.tx,g=o.ty;let _=this.minX,y=this.minY,a=this.maxX,h=this.maxY,u=c*e+d*t+m,p=l*e+f*t+g;u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*r+d*t+m,p=l*r+f*t+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*e+d*n+m,p=l*e+f*n+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),u=c*r+d*n+m,p=l*r+f*n+g,u<_&&(_=u),p<y&&(y=p),u>a&&(a=u),p>h&&(h=p),this.minX=_,this.minY=y,this.maxX=a,this.maxY=h}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,r=this.minY,n=this.maxX,o=this.maxY,{a:c,b:l,c:d,d:f,tx:m,ty:g}=e;let _=c*t+d*r+m,y=l*t+f*r+g;this.minX=_,this.minY=y,this.maxX=_,this.maxY=y,_=c*n+d*r+m,y=l*n+f*r+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y:this.maxY,_=c*t+d*o+m,y=l*t+f*o+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y:this.maxY,_=c*n+d*o+m,y=l*n+f*o+g,this.minX=_<this.minX?_:this.minX,this.minY=y<this.minY?y:this.minY,this.maxX=_>this.maxX?_:this.maxX,this.maxY=y>this.maxY?y: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,r,n){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<r&&(this.minY=r),this.maxY>n&&(this.maxY=n),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 Se(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,r,n){let o=this.minX,c=this.minY,l=this.maxX,d=this.maxY;n||(n=this.matrix);const f=n.a,m=n.b,g=n.c,_=n.d,y=n.tx,a=n.ty;for(let h=t;h<r;h+=2){const u=e[h],p=e[h+1],v=f*u+g*p+y,x=m*u+_*p+a;o=v<o?v:o,c=x<c?x:c,l=v>l?v:l,d=x>d?x:d}this.minX=o,this.minY=c,this.maxX=l,this.maxY=d}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 sp={grad:.9,turn:360,rad:360/(2*Math.PI)},ft=function(s){return typeof s=="string"?s.length>0:typeof s=="number"},_e=function(s,e,t){return e===void 0&&(e=0),t===void 0&&(t=Math.pow(10,e)),Math.round(t*s)/t+0},$e=function(s,e,t){return e===void 0&&(e=0),t===void 0&&(t=1),s>t?t:s>e?s:e},ba=function(s){return(s=isFinite(s)?s%360:0)>0?s:s+360},Ta=function(s){return{r:$e(s.r,0,255),g:$e(s.g,0,255),b:$e(s.b,0,255),a:$e(s.a)}},Ms=function(s){return{r:_e(s.r),g:_e(s.g),b:_e(s.b),a:_e(s.a,3)}},np=/^#([0-9a-f]{3,8})$/i,Sr=function(s){var e=s.toString(16);return e.length<2?"0"+e:e},wa=function(s){var e=s.r,t=s.g,r=s.b,n=s.a,o=Math.max(e,t,r),c=o-Math.min(e,t,r),l=c?o===e?(t-r)/c:o===t?2+(r-e)/c:4+(e-t)/c:0;return{h:60*(l<0?l+6:l),s:o?c/o*100:0,v:o/255*100,a:n}},Sa=function(s){var e=s.h,t=s.s,r=s.v,n=s.a;e=e/360*6,t/=100,r/=100;var o=Math.floor(e),c=r*(1-t),l=r*(1-(e-o)*t),d=r*(1-(1-e+o)*t),f=o%6;return{r:255*[r,l,c,c,d,r][f],g:255*[d,r,r,l,c,c][f],b:255*[c,c,d,r,r,l][f],a:n}},Ca=function(s){return{h:ba(s.h),s:$e(s.s,0,100),l:$e(s.l,0,100),a:$e(s.a)}},Aa=function(s){return{h:_e(s.h),s:_e(s.s),l:_e(s.l),a:_e(s.a,3)}},Ea=function(s){return Sa((t=(e=s).s,{h:e.h,s:(t*=((r=e.l)<50?r:100-r)/100)>0?2*t/(r+t)*100:0,v:r+t,a:e.a}));var e,t,r},Ai=function(s){return{h:(e=wa(s)).h,s:(n=(200-(t=e.s))*(r=e.v)/100)>0&&n<200?t*r/100/(n<=100?n:200-n)*100:0,l:n/2,a:e.a};var e,t,r,n},op=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ap=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,lp=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,cp=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Fs={string:[[function(s){var e=np.exec(s);return e?(s=e[1]).length<=4?{r:parseInt(s[0]+s[0],16),g:parseInt(s[1]+s[1],16),b:parseInt(s[2]+s[2],16),a:s.length===4?_e(parseInt(s[3]+s[3],16)/255,2):1}:s.length===6||s.length===8?{r:parseInt(s.substr(0,2),16),g:parseInt(s.substr(2,2),16),b:parseInt(s.substr(4,2),16),a:s.length===8?_e(parseInt(s.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(s){var e=lp.exec(s)||cp.exec(s);return e?e[2]!==e[4]||e[4]!==e[6]?null:Ta({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(s){var e=op.exec(s)||ap.exec(s);if(!e)return null;var t,r,n=Ca({h:(t=e[1],r=e[2],r===void 0&&(r="deg"),Number(t)*(sp[r]||1)),s:Number(e[3]),l:Number(e[4]),a:e[5]===void 0?1:Number(e[5])/(e[6]?100:1)});return Ea(n)},"hsl"]],object:[[function(s){var e=s.r,t=s.g,r=s.b,n=s.a,o=n===void 0?1:n;return ft(e)&&ft(t)&&ft(r)?Ta({r:Number(e),g:Number(t),b:Number(r),a:Number(o)}):null},"rgb"],[function(s){var e=s.h,t=s.s,r=s.l,n=s.a,o=n===void 0?1:n;if(!ft(e)||!ft(t)||!ft(r))return null;var c=Ca({h:Number(e),s:Number(t),l:Number(r),a:Number(o)});return Ea(c)},"hsl"],[function(s){var e=s.h,t=s.s,r=s.v,n=s.a,o=n===void 0?1:n;if(!ft(e)||!ft(t)||!ft(r))return null;var c=(function(l){return{h:ba(l.h),s:$e(l.s,0,100),v:$e(l.v,0,100),a:$e(l.a)}})({h:Number(e),s:Number(t),v:Number(r),a:Number(o)});return Sa(c)},"hsv"]]},Ia=function(s,e){for(var t=0;t<e.length;t++){var r=e[t][0](s);if(r)return[r,e[t][1]]}return[null,void 0]},hp=function(s){return typeof s=="string"?Ia(s.trim(),Fs.string):typeof s=="object"&&s!==null?Ia(s,Fs.object):[null,void 0]},Us=function(s,e){var t=Ai(s);return{h:t.h,s:$e(t.s+100*e,0,100),l:t.l,a:t.a}},ks=function(s){return(299*s.r+587*s.g+114*s.b)/1e3/255},Pa=function(s,e){var t=Ai(s);return{h:t.h,s:t.s,l:$e(t.l+100*e,0,100),a:t.a}},Bs=(function(){function s(e){this.parsed=hp(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return s.prototype.isValid=function(){return this.parsed!==null},s.prototype.brightness=function(){return _e(ks(this.rgba),2)},s.prototype.isDark=function(){return ks(this.rgba)<.5},s.prototype.isLight=function(){return ks(this.rgba)>=.5},s.prototype.toHex=function(){return e=Ms(this.rgba),t=e.r,r=e.g,n=e.b,c=(o=e.a)<1?Sr(_e(255*o)):"","#"+Sr(t)+Sr(r)+Sr(n)+c;var e,t,r,n,o,c},s.prototype.toRgb=function(){return Ms(this.rgba)},s.prototype.toRgbString=function(){return e=Ms(this.rgba),t=e.r,r=e.g,n=e.b,(o=e.a)<1?"rgba("+t+", "+r+", "+n+", "+o+")":"rgb("+t+", "+r+", "+n+")";var e,t,r,n,o},s.prototype.toHsl=function(){return Aa(Ai(this.rgba))},s.prototype.toHslString=function(){return e=Aa(Ai(this.rgba)),t=e.h,r=e.s,n=e.l,(o=e.a)<1?"hsla("+t+", "+r+"%, "+n+"%, "+o+")":"hsl("+t+", "+r+"%, "+n+"%)";var e,t,r,n,o},s.prototype.toHsv=function(){return e=wa(this.rgba),{h:_e(e.h),s:_e(e.s),v:_e(e.v),a:_e(e.a,3)};var e},s.prototype.invert=function(){return lt({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},s.prototype.saturate=function(e){return e===void 0&&(e=.1),lt(Us(this.rgba,e))},s.prototype.desaturate=function(e){return e===void 0&&(e=.1),lt(Us(this.rgba,-e))},s.prototype.grayscale=function(){return lt(Us(this.rgba,-1))},s.prototype.lighten=function(e){return e===void 0&&(e=.1),lt(Pa(this.rgba,e))},s.prototype.darken=function(e){return e===void 0&&(e=.1),lt(Pa(this.rgba,-e))},s.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},s.prototype.alpha=function(e){return typeof e=="number"?lt({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):_e(this.rgba.a,3);var t},s.prototype.hue=function(e){var t=Ai(this.rgba);return typeof e=="number"?lt({h:e,s:t.s,l:t.l,a:t.a}):_e(t.h)},s.prototype.isEqual=function(e){return this.toHex()===lt(e).toHex()},s})(),lt=function(s){return s instanceof Bs?s:new Bs(s)},Ra=[],up=function(s){s.forEach(function(e){Ra.indexOf(e)<0&&(e(Bs,Fs),Ra.push(e))})};function dp(s,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"},r={};for(var n in t)r[t[n]]=n;var o={};s.prototype.toName=function(c){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return"transparent";var l,d,f=r[this.toHex()];if(f)return f;if(c?.closest){var m=this.toRgb(),g=1/0,_="black";if(!o.length)for(var y in t)o[y]=new s(t[y]).toRgb();for(var a in t){var h=(l=m,d=o[a],Math.pow(l.r-d.r,2)+Math.pow(l.g-d.g,2)+Math.pow(l.b-d.b,2));h<g&&(g=h,_=a)}return _}},e.string.push([function(c){var l=c.toLowerCase(),d=l==="transparent"?"#0000":t[l];return d?new s(d).toRgb():null},"name"])}up([dp]);const Qt=class cr{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 cr)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 r=typeof e;if(r!==typeof t)return!1;if(r==="number"||r==="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((o,c)=>o===t[c]);if(e!==null&&t!==null){const o=Object.keys(e),c=Object.keys(t);return o.length!==c.length?!1:o.every(l=>e[l]===t[l])}return e===t}toRgba(){const[e,t,r,n]=this._components;return{r:e,g:t,b:r,a:n}}toRgb(){const[e,t,r]=this._components;return{r:e,g:t,b:r}}toRgbaString(){const[e,t,r]=this.toUint8RgbArray();return`rgba(${e},${t},${r},${this.alpha})`}toUint8RgbArray(e){const[t,r,n]=this._components;return this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb),e[0]=Math.round(t*255),e[1]=Math.round(r*255),e[2]=Math.round(n*255),e}toArray(e){this._arrayRgba||(this._arrayRgba=[]),e||(e=this._arrayRgba);const[t,r,n,o]=this._components;return e[0]=t,e[1]=r,e[2]=n,e[3]=o,e}toRgbArray(e){this._arrayRgb||(this._arrayRgb=[]),e||(e=this._arrayRgb);const[t,r,n]=this._components;return e[0]=t,e[1]=r,e[2]=n,e}toNumber(){return this._int}toBgrNumber(){const[e,t,r]=this.toUint8RgbArray();return(r<<16)+(t<<8)+e}toLittleEndianNumber(){const e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(e){const[t,r,n,o]=cr._temp.setValue(e)._components;return this._components[0]*=t,this._components[1]*=r,this._components[2]*=n,this._components[3]*=o,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 r=this._int>>16&255,n=this._int>>8&255,o=this._int&255;return t&&(r=r*e+.5|0,n=n*e+.5|0,o=o*e+.5|0),(e*255<<24)+(r<<16)+(n<<8)+o}toHex(){const e=this._int.toString(16);return`#${"000000".substring(0,6-e.length)+e}`}toHexa(){const t=Math.round(this._components[3]*255).toString(16);return this.toHex()+"00".substring(0,2-t.length)+t}setAlpha(e){return this._components[3]=this._clamp(e),this}_normalize(e){let t,r,n,o;if((typeof e=="number"||e instanceof Number)&&e>=0&&e<=16777215){const c=e;t=(c>>16&255)/255,r=(c>>8&255)/255,n=(c&255)/255,o=1}else if((Array.isArray(e)||e instanceof Float32Array)&&e.length>=3&&e.length<=4)e=this._clamp(e),[t,r,n,o=1]=e;else if((e instanceof Uint8Array||e instanceof Uint8ClampedArray)&&e.length>=3&&e.length<=4)e=this._clamp(e,0,255),[t,r,n,o=255]=e,t/=255,r/=255,n/=255,o/=255;else if(typeof e=="string"||typeof e=="object"){if(typeof e=="string"){const l=cr.HEX_PATTERN.exec(e);l&&(e=`#${l[2]}`)}const c=lt(e);c.isValid()&&({r:t,g:r,b:n,a:o}=c.rgba,t/=255,r/=255,n/=255)}if(t!==void 0)this._components[0]=t,this._components[1]=r,this._components[2]=n,this._components[3]=o,this._refreshInt();else throw new Error(`Unable to convert color ${e}`)}_refreshInt(){this._clamp(this._components);const[e,t,r]=this._components;this._int=(e*255<<16)+(t*255<<8)+(r*255|0)}_clamp(e,t=0,r=1){return typeof e=="number"?Math.min(Math.max(e,t),r):(e.forEach((n,o)=>{e[o]=Math.min(Math.max(n,t),r)}),e)}static isColorLike(e){return typeof e=="number"||typeof e=="string"||e instanceof Number||e instanceof cr||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}};Qt.shared=new Qt,Qt._temp=new Qt,Qt.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;let le=Qt;const fp={cullArea:null,cullable:!1,cullableChildren:!0};let Ds=0;const Ma=500;function G(...s){Ds!==Ma&&(Ds++,Ds===Ma?console.warn("PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS."):console.warn("PixiJS Warning: ",...s))}const ei={_registeredResources:new Set,register(s){this._registeredResources.add(s)},unregister(s){this._registeredResources.delete(s)},release(){this._registeredResources.forEach(s=>s.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(s){return this._registeredResources.has(s)},reset(){this._registeredResources.clear()}};class pp{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 mp{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 pp(e)),this._poolsByClass.get(e)}stats(){const e={};return this._poolsByClass.forEach(t=>{const r=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[r]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}}const me=new mp;ei.register(me);const gp={get isCachedAsTexture(){return!!this.renderGroup?.isCachedAsTexture},cacheAsTexture(s){typeof s=="boolean"&&s===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(s===!0?{}:s))},updateCacheTexture(){this.renderGroup?.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(s){H("v8.6.0","cacheAsBitmap is deprecated, use cacheAsTexture instead."),this.cacheAsTexture(s)}};function Fa(s,e,t){const r=s.length;let n;if(e>=r||t===0)return;t=e+t>r?r-e:t;const o=r-t;for(n=e;n<o;++n)s[n]=s[n+t];s.length=o}const vp={allowChildren:!0,removeChildren(s=0,e){const t=e??this.children.length,r=t-s,n=[];if(r>0&&r<=t){for(let c=t-1;c>=s;c--){const l=this.children[c];l&&(n.push(l),l.parent=null)}Fa(this.children,s,t);const o=this.renderGroup||this.parentRenderGroup;o&&o.removeChildren(n);for(let c=0;c<n.length;++c){const l=n[c];l.parentRenderLayer?.detach(l),this.emit("childRemoved",l,this,c),n[c].emit("removed",this)}return n.length>0&&this._didViewChangeTick++,n}else if(r===0&&this.children.length===0)return n;throw new RangeError("removeChildren: numeric values are outside the acceptable range.")},removeChildAt(s){const e=this.getChildAt(s);return this.removeChild(e)},getChildAt(s){if(s<0||s>=this.children.length)throw new Error(`getChildAt: Index (${s}) does not exist.`);return this.children[s]},setChildIndex(s,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);this.getChildIndex(s),this.addChildAt(s,e)},getChildIndex(s){const e=this.children.indexOf(s);if(e===-1)throw new Error("The supplied Container must be a child of the caller");return e},addChildAt(s,e){this.allowChildren||H(j,"addChildAt: Only Containers will be allowed to add children in v8.0.0");const{children:t}=this;if(e<0||e>t.length)throw new Error(`${s}addChildAt: The index ${e} supplied is out of bounds ${t.length}`);if(s.parent){const n=s.parent.children.indexOf(s);if(s.parent===this&&n===e)return s;n!==-1&&s.parent.children.splice(n,1)}e===t.length?t.push(s):t.splice(e,0,s),s.parent=this,s.didChange=!0,s._updateFlags=15;const r=this.renderGroup||this.parentRenderGroup;return r&&r.addChild(s),this.sortableChildren&&(this.sortDirty=!0),this.emit("childAdded",s,this,e),s.emit("added",this),s},swapChildren(s,e){if(s===e)return;const t=this.getChildIndex(s),r=this.getChildIndex(e);this.children[t]=e,this.children[r]=s;const n=this.renderGroup||this.parentRenderGroup;n&&(n.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){this.parent?.removeChild(this)},reparentChild(...s){return s.length===1?this.reparentChildAt(s[0],this.children.length):(s.forEach(e=>this.reparentChildAt(e,this.children.length)),s[0])},reparentChildAt(s,e){if(s.parent===this)return this.setChildIndex(s,e),s;const t=s.worldTransform.clone();s.removeFromParent(),this.addChildAt(s,e);const r=this.worldTransform.clone();return r.invert(),t.prepend(r),s.setFromMatrix(t),s},replaceChild(s,e){s.updateLocalTransform(),this.addChildAt(e,this.getChildIndex(s)),e.setFromMatrix(s.localTransform),e.updateLocalTransform(),this.removeChild(s)}},_p={collectRenderables(s,e,t){this.parentRenderLayer&&this.parentRenderLayer!==t||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(s,e,t):this.renderGroup?e.renderPipes.renderGroup.addRenderGroup(this.renderGroup,s):this.collectRenderablesWithEffects(s,e,t))},collectRenderablesSimple(s,e,t){const r=this.children,n=r.length;for(let o=0;o<n;o++)r[o].collectRenderables(s,e,t)},collectRenderablesWithEffects(s,e,t){const{renderPipes:r}=e;for(let n=0;n<this.effects.length;n++){const o=this.effects[n];r[o.pipe].push(o,this,s)}this.collectRenderablesSimple(s,e,t);for(let n=this.effects.length-1;n>=0;n--){const o=this.effects[n];r[o.pipe].pop(o,this,s)}}};class Cr{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 yp{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 r=this._tests[t];if(r.test(e))return me.get(r.maskClass,e)}return e}returnMaskEffect(e){me.return(e)}}const Os=new yp;L.handleByList(C.MaskEffect,Os._effectClasses);const xp={_maskEffect:null,_maskOptions:{inverse:!1},_filterEffect:null,effects:[],_markStructureAsChanged(){const s=this.renderGroup||this.parentRenderGroup;s&&(s.structureDidChange=!0)},addEffect(s){this.effects.indexOf(s)===-1&&(this.effects.push(s),this.effects.sort((t,r)=>t.priority-r.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(s){const e=this.effects.indexOf(s);e!==-1&&(this.effects.splice(e,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(s){const e=this._maskEffect;e?.mask!==s&&(e&&(this.removeEffect(e),Os.returnMaskEffect(e),this._maskEffect=null),s!=null&&(this._maskEffect=Os.getMaskEffect(s),this.addEffect(this._maskEffect)))},get mask(){return this._maskEffect?.mask},setMask(s){this._maskOptions={...this._maskOptions,...s},s.mask&&(this.mask=s.mask),this._markStructureAsChanged()},set filters(s){!Array.isArray(s)&&s&&(s=[s]);const e=this._filterEffect||(this._filterEffect=new Cr);s=s;const t=s?.length>0,r=e.filters?.length>0,n=t!==r;s=Array.isArray(s)?s.slice(0):s,e.filters=Object.freeze(s),n&&(t?this.addEffect(e):(this.removeEffect(e),e.filters=s??null))},get filters(){return this._filterEffect?.filters},set filterArea(s){this._filterEffect||(this._filterEffect=new Cr),this._filterEffect.filterArea=s},get filterArea(){return this._filterEffect?.filterArea}},bp={label:null,get name(){return H(j,"Container.name property has been removed, use Container.label instead"),this.label},set name(s){H(j,"Container.name property has been removed, use Container.label instead"),this.label=s},getChildByName(s,e=!1){return this.getChildByLabel(s,e)},getChildByLabel(s,e=!1){const t=this.children;for(let r=0;r<t.length;r++){const n=t[r];if(n.label===s||s instanceof RegExp&&s.test(n.label))return n}if(e)for(let r=0;r<t.length;r++){const o=t[r].getChildByLabel(s,!0);if(o)return o}return null},getChildrenByLabel(s,e=!1,t=[]){const r=this.children;for(let n=0;n<r.length;n++){const o=r[n];(o.label===s||s instanceof RegExp&&s.test(o.label))&&t.push(o)}if(e)for(let n=0;n<r.length;n++)r[n].getChildrenByLabel(s,!0,t);return t}},Fe=me.getPool(B),pt=me.getPool(Se),Tp=new B,wp={getFastGlobalBounds(s,e){e||(e=new Se),e.clear(),this._getGlobalBoundsRecursive(!!s,e,this.parentRenderLayer),e.isValid||e.set(0,0,0,0);const t=this.renderGroup||this.parentRenderGroup;return e.applyMatrix(t.worldTransform),e},_getGlobalBoundsRecursive(s,e,t){let r=e;if(s&&this.parentRenderLayer&&this.parentRenderLayer!==t||this.localDisplayStatus!==7||!this.measurable)return;const n=!!this.effects.length;if((this.renderGroup||n)&&(r=pt.get().clear()),this.boundsArea)e.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){const c=this.bounds;r.addFrame(c.minX,c.minY,c.maxX,c.maxY,this.groupTransform)}const o=this.children;for(let c=0;c<o.length;c++)o[c]._getGlobalBoundsRecursive(s,r,t)}if(n){let o=!1;const c=this.renderGroup||this.parentRenderGroup;for(let l=0;l<this.effects.length;l++)this.effects[l].addBounds&&(o||(o=!0,r.applyMatrix(c.worldTransform)),this.effects[l].addBounds(r,!0));o&&r.applyMatrix(c.worldTransform.copyTo(Tp).invert()),e.addBounds(r),pt.return(r)}else this.renderGroup&&(e.addBounds(r,this.relativeGroupTransform),pt.return(r))}};function Gs(s,e,t){t.clear();let r,n;return s.parent?e?r=s.parent.worldTransform:(n=Fe.get().identity(),r=Ls(s,n)):r=B.IDENTITY,Ua(s,t,r,e),n&&Fe.return(n),t.isValid||t.set(0,0,0,0),t}function Ua(s,e,t,r){if(!s.visible||!s.measurable)return;let n;r?n=s.worldTransform:(s.updateLocalTransform(),n=Fe.get(),n.appendFrom(s.localTransform,t));const o=e,c=!!s.effects.length;if(c&&(e=pt.get().clear()),s.boundsArea)e.addRect(s.boundsArea,n);else{const l=s.bounds;l&&!l.isEmpty()&&(e.matrix=n,e.addBounds(l));for(let d=0;d<s.children.length;d++)Ua(s.children[d],e,n,r)}if(c){for(let l=0;l<s.effects.length;l++)s.effects[l].addBounds?.(e);o.addBounds(e,B.IDENTITY),pt.return(e)}r||Fe.return(n)}function Ls(s,e){const t=s.parent;return t&&(Ls(t,e),t.updateLocalTransform(),e.append(t.localTransform)),e}function ka(s,e){if(s===16777215||!e)return e;if(e===16777215||!s)return s;const t=s>>16&255,r=s>>8&255,n=s&255,o=e>>16&255,c=e>>8&255,l=e&255,d=t*o/255|0,f=r*c/255|0,m=n*l/255|0;return(d<<16)+(f<<8)+m}const Ba=16777215;function Ar(s,e){return s===Ba?e:e===Ba?s:ka(s,e)}function Er(s){return((s&255)<<16)+(s&65280)+(s>>16&255)}const Sp={getGlobalAlpha(s){if(s)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(s=new B,e){if(e)return s.copyFrom(this.worldTransform);this.updateLocalTransform();const t=Ls(this,Fe.get().identity());return s.appendFrom(this.localTransform,t),Fe.return(t),s},getGlobalTint(s){if(s)return this.renderGroup?Er(this.renderGroup.worldColor):this.parentRenderGroup?Er(Ar(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let e=this.localColor,t=this.parent;for(;t;)e=Ar(e,t.localColor),t=t.parent;return Er(e)}};function Ns(s,e,t){return e.clear(),t||(t=B.IDENTITY),Da(s,e,t,s,!0),e.isValid||e.set(0,0,0,0),e}function Da(s,e,t,r,n){let o;if(n)o=Fe.get(),o=t.copyTo(o);else{if(!s.visible||!s.measurable)return;s.updateLocalTransform();const d=s.localTransform;o=Fe.get(),o.appendFrom(d,t)}const c=e,l=!!s.effects.length;if(l&&(e=pt.get().clear()),s.boundsArea)e.addRect(s.boundsArea,o);else{s.renderPipeId&&(e.matrix=o,e.addBounds(s.bounds));const d=s.children;for(let f=0;f<d.length;f++)Da(d[f],e,o,r,!1)}if(l){for(let d=0;d<s.effects.length;d++)s.effects[d].addLocalBounds?.(e,r);c.addBounds(e,B.IDENTITY),pt.return(e)}Fe.return(o)}function Oa(s,e){const t=s.children;for(let r=0;r<t.length;r++){const n=t[r],o=n.uid,c=(n._didViewChangeTick&65535)<<16|n._didContainerChangeTick&65535,l=e.index;(e.data[l]!==o||e.data[l+1]!==c)&&(e.data[e.index]=o,e.data[e.index+1]=c,e.didChange=!0),e.index=l+2,n.children.length&&Oa(n,e)}return e.didChange}const Cp=new B,Ap={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(s,e){const t=Math.sign(this.scale.x)||1;e!==0?this.scale.x=s/e*t:this.scale.x=t},_setHeight(s,e){const t=Math.sign(this.scale.y)||1;e!==0?this.scale.y=s/e*t:this.scale.y=t},getLocalBounds(){this._localBoundsCacheData||(this._localBoundsCacheData={data:[],index:1,didChange:!1,localBounds:new Se});const s=this._localBoundsCacheData;return s.index=1,s.didChange=!1,s.data[0]!==this._didViewChangeTick&&(s.didChange=!0,s.data[0]=this._didViewChangeTick),Oa(this,s),s.didChange&&Ns(this,s.localBounds,Cp),s.localBounds},getBounds(s,e){return Gs(this,s,e||new Se)}},Ep={_onRender:null,set onRender(s){const e=this.renderGroup||this.parentRenderGroup;if(!s){this._onRender&&e?.removeOnRender(this),this._onRender=null;return}this._onRender||e?.addOnRender(this),this._onRender=s},get onRender(){return this._onRender}},Ip={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(s){this._zIndex!==s&&(this._zIndex=s,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(Pp))}};function Pp(s,e){return s._zIndex-e._zIndex}const Rp={getGlobalPosition(s=new J,e=!1){return this.parent?this.parent.toGlobal(this._position,s,e):(s.x=this._position.x,s.y=this._position.y),s},toGlobal(s,e,t=!1){const r=this.getGlobalTransform(Fe.get(),t);return e=r.apply(s,e),Fe.return(r),e},toLocal(s,e,t,r){e&&(s=e.toGlobal(s,t,r));const n=this.getGlobalTransform(Fe.get(),r);return t=n.applyInverse(s,t),Fe.return(n),t}};class Ga{constructor(){this.uid=ae("instructionSet"),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,["type","action"])}}let Mp=0;class Fp{constructor(e){this._poolKeyHash=Object.create(null),this._texturePool={},this.textureOptions=e||{},this.enableFullScreen=!1,this.textureStyle=new at(this.textureOptions)}createTexture(e,t,r){const n=new ge({...this.textureOptions,width:e,height:t,resolution:1,antialias:r,autoGarbageCollect:!1});return new F({source:n,label:`texturePool_${Mp++}`})}getOptimalTexture(e,t,r=1,n){let o=Math.ceil(e*r-1e-6),c=Math.ceil(t*r-1e-6);o=Jt(o),c=Jt(c);const l=(o<<17)+(c<<1)+(n?1:0);this._texturePool[l]||(this._texturePool[l]=[]);let d=this._texturePool[l].pop();return d||(d=this.createTexture(o,c,n)),d.source._resolution=r,d.source.width=o/r,d.source.height=c/r,d.source.pixelWidth=o,d.source.pixelHeight=c,d.frame.x=0,d.frame.y=0,d.frame.width=e,d.frame.height=t,d.updateUvs(),this._poolKeyHash[d.uid]=l,d}getSameSizeTexture(e,t=!1){const r=e.source;return this.getOptimalTexture(e.width,e.height,r._resolution,t)}returnTexture(e,t=!1){const r=this._poolKeyHash[e.uid];t&&(e.source.style=this.textureStyle),this._texturePool[r].push(e)}clear(e){if(e=e!==!1,e)for(const t in this._texturePool){const r=this._texturePool[t];if(r)for(let n=0;n<r.length;n++)r[n].destroy(!0)}this._texturePool={}}}const Te=new Fp;ei.register(Te);class zs{constructor(){this.renderPipeId="renderGroup",this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new B,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 Ga,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 r=0;r<t.length;r++){const n=t[r];n._updateFlags=15,this.addChild(n)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&(Te.returnTexture(this.texture,!0),this.texture=null)}updateCacheTexture(){this.textureNeedsUpdate=!0;const e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(const e in this.childrenToUpdate){const t=this.childrenToUpdate[e];t.list.fill(null),t.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){const t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.parent===this.root?e.relativeRenderGroupDepth=1:e.relativeRenderGroupDepth=e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);const t=e.children;for(let r=0;r<t.length;r++)this.addChild(t[r])}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 r=0;r<t.length;r++)this.removeChild(t[r])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||(t=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]}),t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.push(e)}removeOnRender(e){this._onRenderContainers.splice(this._onRenderContainers.indexOf(e),1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet=null}getChildren(e=[]){const t=this.root.children;for(let r=0;r<t.length;r++)this._getChildren(t[r],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;const r=e.children;for(let n=0;n<r.length;n++)this._getChildren(r[n],t);return t}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return(this._matrixDirty&1)===0?this._inverseWorldTransform:(this._matrixDirty&=-2,this._inverseWorldTransform||(this._inverseWorldTransform=new B),this._inverseWorldTransform.copyFrom(this.worldTransform).invert())}get textureOffsetInverseTransform(){return(this._matrixDirty&2)===0?this._textureOffsetInverseTransform:(this._matrixDirty&=-3,this._textureOffsetInverseTransform||(this._textureOffsetInverseTransform=new B),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 B),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 Up(s,e,t={}){for(const r in e)!t[r]&&e[r]!==void 0&&(s[r]=e[r])}const Hs=new be(null),Ir=new be(null),Ws=new be(null,1,1),Pr=new be(null),Rr=1,Vs=2,Ei=4;class se extends Le{constructor(e={}){super(),this.uid=ae("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 B,this.relativeGroupTransform=new B,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new be(this,0,0),this._scale=Ws,this._pivot=Ir,this._origin=Pr,this._skew=Hs,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=[],Up(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."),L.mixin(se,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(j,"addChild: Only Containers will be allowed to add children in v8.0.0"),e.length>1){for(let n=0;n<e.length;n++)this.addChild(e[n]);return e[0]}const t=e[0],r=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),r&&(r.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,r&&r.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 n=0;n<e.length;n++)this.removeChild(e[n]);return e[0]}const t=e[0],r=this.children.indexOf(t);return r>-1&&(this._didViewChangeTick++,this.children.splice(r,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,r),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=me.get(zs,this),this.groupTransform=B.IDENTITY,e?.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;const e=this.parentRenderGroup;e?.removeChild(this),me.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 B),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*Zf}set angle(e){this.rotation=e*Jf}get pivot(){return this._pivot===Ir&&(this._pivot=new be(this,0,0)),this._pivot}set pivot(e){this._pivot===Ir&&(this._pivot=new be(this,0,0),this._origin!==Pr&&G("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===Hs&&(this._skew=new be(this,0,0)),this._skew}set skew(e){this._skew===Hs&&(this._skew=new be(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===Ws&&(this._scale=new be(this,1,1)),this._scale}set scale(e){this._scale===Ws&&(this._scale=new be(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===Pr&&(this._origin=new be(this,0,0)),this._origin}set origin(e){this._origin===Pr&&(this._origin=new be(this,0,0),this._pivot!==Ir&&G("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 r=this.getLocalBounds();typeof e=="object"?(t=e.height??e.width,e=e.width):t??(t=e),e!==void 0&&this._setWidth(e,r.width),t!==void 0&&this._setHeight(t,r.height)}_updateSkew(){const e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x=="number"?e.x:this.position.x,typeof e.y=="number"?e.y:this.position.y),this.scale.set(typeof e.scaleX=="number"?e.scaleX||1:this.scale.x,typeof e.scaleY=="number"?e.scaleY||1:this.scale.y),this.rotation=typeof e.rotation=="number"?e.rotation:this.rotation,this.skew.set(typeof e.skewX=="number"?e.skewX:this.skew.x,typeof e.skewY=="number"?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX=="number"?e.pivotX:this.pivot.x,typeof e.pivotY=="number"?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX=="number"?e.originX:this.origin.x,typeof e.originY=="number"?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){const e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;const t=this.localTransform,r=this._scale,n=this._pivot,o=this._origin,c=this._position,l=r._x,d=r._y,f=n._x,m=n._y,g=-o._x,_=-o._y;t.a=this._cx*l,t.b=this._sx*l,t.c=this._cy*d,t.d=this._sy*d,t.tx=c._x-(f*t.a+m*t.c)+(g*t.a+_*t.c)-g,t.ty=c._y-(f*t.b+m*t.d)+(g*t.b+_*t.d)-_}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=Rr,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){const r=le.shared.setValue(e??16777215).toBgrNumber();r!==this.localColor&&(this.localColor=r,this._updateFlags|=Rr,this._onUpdate())}get tint(){return Er(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Vs,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|=Ei,this.localDisplayStatus^=2,this._onUpdate())}get culled(){return!(this.localDisplayStatus&4)}set culled(e){const t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=Ei,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|=Ei,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 n=0;n<t.length;++n)t[n].destroy(e);this.renderGroup?.destroy(),this.renderGroup=null}}L.mixin(se,vp,wp,Rp,Ep,Ap,xp,bp,Ip,fp,gp,Sp,_p);class Ys extends se{constructor(e){super(e),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this._bounds=new Se(0,1,0,0),this._boundsDirty=!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:r,y:n}=e;return r>=t.minX&&r<=t.maxX&&n>=t.minY&&n<=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)}destroy(e){super.destroy(e),this._bounds=null;for(const t in this._gpuData)this._gpuData[t].destroy?.();this._gpuData=null}collectRenderablesSimple(e,t,r){const{renderPipes:n}=t;n.blendMode.pushBlendMode(this,this.groupBlendMode,e),n[this.renderPipeId].addRenderable(this,e),this.didViewUpdate=!1;const c=this.children,l=c.length;for(let d=0;d<l;d++)c[d].collectRenderables(e,t,r);n.blendMode.popBlendMode(e)}}class we extends Ys{constructor(e=F.EMPTY){e instanceof F&&(e={texture:e});const{texture:t=F.EMPTY,anchor:r,roundPixels:n,width:o,height:c,...l}=e;super({label:"Sprite",...l}),this.renderPipeId="sprite",this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new be({_onUpdate:()=>{this.onViewUpdate()}}),r?this.anchor=r:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=n??!1,o!==void 0&&(this.width=o),c!==void 0&&(this.height=c)}static from(e,t=!1){return e instanceof F?new we(e):new we(F.from(e,t))}set texture(e){e||(e=F.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 ya(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,r=this._bounds,{width:n,height:o}=t.orig;r.minX=-e._x*n,r.maxX=r.minX+n,r.minY=-e._y*o,r.maxY=r.minY+o}destroy(e=!1){if(super.destroy(e),typeof e=="boolean"?e:e?.texture){const r=typeof e=="boolean"?e:e?.textureSource;this._texture.destroy(r)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null,this._gpuData=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 kp=new Se;function La(s,e,t){const r=kp;s.measurable=!0,Gs(s,t,r),e.addBoundsMask(r),s.measurable=!1}function Na(s,e,t){const r=pt.get();s.measurable=!0;const n=Fe.get().identity(),o=za(s,t,n);Ns(s,r,o),s.measurable=!1,e.addBoundsMask(r),Fe.return(n),pt.return(r)}function za(s,e,t){return s?(s!==e&&(za(s.parent,e,t),s.updateLocalTransform(),t.append(s.localTransform)),t):(G("Mask bounds, renderable is not inside the root container"),t)}class Ha{constructor(e){this.priority=0,this.inverse=!1,this.pipe="alphaMask",e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e instanceof we),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||La(this.mask,e,t)}addLocalBounds(e,t){Na(this.mask,e,t)}containsPoint(e,t){const r=this.mask;return t(r,e)}destroy(){this.reset()}static test(e){return e instanceof we}}Ha.extension=C.MaskEffect;class Wa{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"}}Wa.extension=C.MaskEffect;class Va{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){La(this.mask,e,t)}addLocalBounds(e,t){Na(this.mask,e,t)}containsPoint(e,t){const r=this.mask;return t(r,e)}destroy(){this.reset()}static test(e){return e instanceof se}}Va.extension=C.MaskEffect;let Ya={createCanvas:(s,e)=>{const t=document.createElement("canvas");return t.width=s,t.height=e,t},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(s,e)=>fetch(s,e),parseXML:s=>new DOMParser().parseFromString(s,"text/xml")};const V={get(){return Ya},set(s){Ya=s}};class mt extends ge{constructor(e){e.resource||(e.resource=V.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,r=this._resolution){const n=super.resize(e,t,r);return n&&this.resizeCanvas(),n}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"))}}mt.extension=C.TextureSource;class ct extends ge{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}}ct.extension=C.TextureSource;var ti=(s=>(s[s.INTERACTION=50]="INTERACTION",s[s.HIGH=25]="HIGH",s[s.NORMAL=0]="NORMAL",s[s.LOW=-25]="LOW",s[s.UTILITY=-50]="UTILITY",s))(ti||{});class Xs{constructor(e,t=null,r=0,n=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=r,this._once=n}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 Xa=class Ve{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 Xs(null,null,1/0),this.deltaMS=1/Ve.targetFPMS,this.elapsedMS=1/Ve.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,r=ti.NORMAL){return this._addListener(new Xs(e,t,r))}addOnce(e,t,r=ti.NORMAL){return this._addListener(new Xs(e,t,r,!0))}_addListener(e){let t=this._head.next,r=this._head;if(!t)e.connect(r);else{for(;t;){if(e.priority>t.priority){e.connect(r);break}r=t,t=t.next}e.previous||e.connect(r)}return this._startIfPossible(),this}remove(e,t){let r=this._head.next;for(;r;)r.match(e,t)?r=r.destroy():r=r.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 o=e-this._lastFrame|0;if(o<this._minElapsedMS)return;this._lastFrame=e-o%this._minElapsedMS}this.deltaMS=t,this.deltaTime=this.deltaMS*Ve.targetFPMS;const r=this._head;let n=r.next;for(;n;)n=n.emit(this);r.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=e}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(e){const t=Math.min(this.maxFPS,e),r=Math.min(Math.max(0,t)/1e3,Ve.targetFPMS);this._maxElapsedMS=1/r}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){if(e===0)this._minElapsedMS=0;else{const t=Math.max(this.minFPS,e);this._minElapsedMS=1/(t/1e3)}}static get shared(){if(!Ve._shared){const e=Ve._shared=new Ve;e.autoStart=!0,e._protected=!0}return Ve._shared}static get system(){if(!Ve._system){const e=Ve._system=new Ve;e.autoStart=!0,e._protected=!0}return Ve._system}};Xa.targetFPMS=.06;let Ne=Xa,$s;async function $a(){return $s??($s=(async()=>{const e=V.get().createCanvas(1,1).getContext("webgl");if(!e)return"premultiply-alpha-on-upload";const t=await new Promise(c=>{const l=document.createElement("video");l.onloadeddata=()=>c(l),l.onerror=()=>c(null),l.autoplay=!1,l.crossOrigin="anonymous",l.preload="auto",l.src="data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=",l.load()});if(!t)return"premultiply-alpha-on-upload";const r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r);const n=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,n),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,r,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 o=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,o),e.deleteFramebuffer(n),e.deleteTexture(r),e.getExtension("WEBGL_lose_context")?.loseContext(),o[0]<=o[3]?"premultiplied-alpha":"premultiply-alpha-on-upload"})()),$s}const Mr=class dd extends ge{constructor(e){super(e),this.isReady=!1,this.uploadMethodId="video",e={...dd.defaultOptions,...e},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this.alphaMode=e.alphaMode??"premultiply-alpha-on-upload",this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),e.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){const e=Ne.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;const e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener("play",this._onPlayStart),e.addEventListener("pause",this._onPlayStop),e.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlayThrough),e.addEventListener("error",this._onError,!0)),this.alphaMode=await $a(),this._load=new Promise((r,n)=>{this.isValid?r(this):(this._resolve=r,this._reject=n,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){const e=this.resource;return!e.paused&&!e.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this.isValid||this._mediaReady(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onCanPlay(){this.resource.removeEventListener("canplay",this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener("canplaythrough",this._onCanPlay),this._preloadTimeout&&(clearTimeout(this._preloadTimeout),this._preloadTimeout=void 0),this._mediaReady()}_mediaReady(){const e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();const e=this.resource;e&&(e.removeEventListener("play",this._onPlayStart),e.removeEventListener("pause",this._onPlayStop),e.removeEventListener("seeked",this._onSeeked),e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlayThrough),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(Ne.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||(Ne.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Ne.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};Mr.extension=C.TextureSource,Mr.defaultOptions={...ge.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 Ii=Mr;const Qe=(s,e,t=!1)=>(Array.isArray(s)||(s=[s]),e?s.map(r=>typeof r=="string"||t?e(r):r):s);class Bp{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||G(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){const r=Qe(e);let n;for(let d=0;d<this.parsers.length;d++){const f=this.parsers[d];if(f.test(t)){n=f.getCacheableAssets(r,t);break}}const o=new Map(Object.entries(n||{}));n||r.forEach(d=>{o.set(d,t)});const c=[...o.keys()],l={cacheKeys:c,keys:r};r.forEach(d=>{this._cacheMap.set(d,l)}),c.forEach(d=>{const f=n?n[d]:t;this._cache.has(d)&&this._cache.get(d)!==f&&G("[Cache] already has key:",d),this._cache.set(d,o.get(d))})}remove(e){if(!this._cacheMap.has(e)){G(`[Assets] Asset id ${e} was not found in the Cache`);return}const t=this._cacheMap.get(e);t.cacheKeys.forEach(n=>{this._cache.delete(n)}),t.keys.forEach(n=>{this._cacheMap.delete(n)})}get parsers(){return this._parsers}}const re=new Bp,qs=[];L.handleByList(C.TextureSource,qs);function qa(s={}){const e=s&&s.resource,t=e?s.resource:s,r=e?s:{resource:s};for(let n=0;n<qs.length;n++){const o=qs[n];if(o.test(t))return new o(r)}throw new Error(`Could not find a source type for resource: ${r.resource}`)}function Dp(s={},e=!1){const t=s&&s.resource,r=t?s.resource:s,n=t?s:{resource:s};if(!e&&re.has(r))return re.get(r);const o=new F({source:qa(n)});return o.on("destroy",()=>{re.has(r)&&re.remove(r)}),e||re.set(r,o),o}function Op(s,e=!1){return typeof s=="string"?re.get(s):s instanceof ge?new F({source:s}):Dp(s,e)}F.from=Op,ge.from=qa,L.add(Ha,Wa,Va,Ii,ct,mt,Rs);var At=(s=>(s[s.Low=0]="Low",s[s.Normal=1]="Normal",s[s.High=2]="High",s))(At||{});function et(s){if(typeof s!="string")throw new TypeError(`Path must be a string. Received ${JSON.stringify(s)}`)}function Pi(s){return s.split("?")[0].split("#")[0]}function Gp(s){return s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Lp(s,e,t){return s.replace(new RegExp(Gp(e),"g"),t)}function Np(s,e){let t="",r=0,n=-1,o=0,c=-1;for(let l=0;l<=s.length;++l){if(l<s.length)c=s.charCodeAt(l);else{if(c===47)break;c=47}if(c===47){if(!(n===l-1||o===1))if(n!==l-1&&o===2){if(t.length<2||r!==2||t.charCodeAt(t.length-1)!==46||t.charCodeAt(t.length-2)!==46){if(t.length>2){const d=t.lastIndexOf("/");if(d!==t.length-1){d===-1?(t="",r=0):(t=t.slice(0,d),r=t.length-1-t.lastIndexOf("/")),n=l,o=0;continue}}else if(t.length===2||t.length===1){t="",r=0,n=l,o=0;continue}}}else t.length>0?t+=`/${s.slice(n+1,l)}`:t=s.slice(n+1,l),r=l-n-1;n=l,o=0}else c===46&&o!==-1?++o:o=-1}return t}const ze={toPosix(s){return Lp(s,"\\","/")},isUrl(s){return/^https?:/.test(this.toPosix(s))},isDataUrl(s){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(s)},isBlobUrl(s){return s.startsWith("blob:")},hasProtocol(s){return/^[^/:]+:/.test(this.toPosix(s))},getProtocol(s){et(s),s=this.toPosix(s);const e=/^file:\/\/\//.exec(s);if(e)return e[0];const t=/^[^/:]+:\/{0,2}/.exec(s);return t?t[0]:""},toAbsolute(s,e,t){if(et(s),this.isDataUrl(s)||this.isBlobUrl(s))return s;const r=Pi(this.toPosix(e??V.get().getBaseUrl())),n=Pi(this.toPosix(t??this.rootname(r)));return s=this.toPosix(s),s.startsWith("/")?ze.join(n,s.slice(1)):this.isAbsolute(s)?s:this.join(r,s)},normalize(s){if(et(s),s.length===0)return".";if(this.isDataUrl(s)||this.isBlobUrl(s))return s;s=this.toPosix(s);let e="";const t=s.startsWith("/");this.hasProtocol(s)&&(e=this.rootname(s),s=s.slice(e.length));const r=s.endsWith("/");return s=Np(s),s.length>0&&r&&(s+="/"),t?`/${s}`:e+s},isAbsolute(s){return et(s),s=this.toPosix(s),this.hasProtocol(s)?!0:s.startsWith("/")},join(...s){if(s.length===0)return".";let e;for(let t=0;t<s.length;++t){const r=s[t];if(et(r),r.length>0)if(e===void 0)e=r;else{const n=s[t-1]??"";this.joinExtensions.includes(this.extname(n).toLowerCase())?e+=`/../${r}`:e+=`/${r}`}}return e===void 0?".":this.normalize(e)},dirname(s){if(et(s),s.length===0)return".";s=this.toPosix(s);let e=s.charCodeAt(0);const t=e===47;let r=-1,n=!0;const o=this.getProtocol(s),c=s;s=s.slice(o.length);for(let l=s.length-1;l>=1;--l)if(e=s.charCodeAt(l),e===47){if(!n){r=l;break}}else n=!1;return r===-1?t?"/":this.isUrl(c)?o+s:o:t&&r===1?"//":o+s.slice(0,r)},rootname(s){et(s),s=this.toPosix(s);let e="";if(s.startsWith("/")?e="/":e=this.getProtocol(s),this.isUrl(s)){const t=s.indexOf("/",e.length);t!==-1?e=s.slice(0,t):e=s,e.endsWith("/")||(e+="/")}return e},basename(s,e){et(s),e&&et(e),s=Pi(this.toPosix(s));let t=0,r=-1,n=!0,o;if(e!==void 0&&e.length>0&&e.length<=s.length){if(e.length===s.length&&e===s)return"";let c=e.length-1,l=-1;for(o=s.length-1;o>=0;--o){const d=s.charCodeAt(o);if(d===47){if(!n){t=o+1;break}}else l===-1&&(n=!1,l=o+1),c>=0&&(d===e.charCodeAt(c)?--c===-1&&(r=o):(c=-1,r=l))}return t===r?r=l:r===-1&&(r=s.length),s.slice(t,r)}for(o=s.length-1;o>=0;--o)if(s.charCodeAt(o)===47){if(!n){t=o+1;break}}else r===-1&&(n=!1,r=o+1);return r===-1?"":s.slice(t,r)},extname(s){et(s),s=Pi(this.toPosix(s));let e=-1,t=0,r=-1,n=!0,o=0;for(let c=s.length-1;c>=0;--c){const l=s.charCodeAt(c);if(l===47){if(!n){t=c+1;break}continue}r===-1&&(n=!1,r=c+1),l===46?e===-1?e=c:o!==1&&(o=1):e!==-1&&(o=-1)}return e===-1||r===-1||o===0||o===1&&e===r-1&&e===t+1?"":s.slice(e,r)},parse(s){et(s);const e={root:"",dir:"",base:"",ext:"",name:""};if(s.length===0)return e;s=Pi(this.toPosix(s));let t=s.charCodeAt(0);const r=this.isAbsolute(s);let n;e.root=this.rootname(s),r||this.hasProtocol(s)?n=1:n=0;let o=-1,c=0,l=-1,d=!0,f=s.length-1,m=0;for(;f>=n;--f){if(t=s.charCodeAt(f),t===47){if(!d){c=f+1;break}continue}l===-1&&(d=!1,l=f+1),t===46?o===-1?o=f:m!==1&&(m=1):o!==-1&&(m=-1)}return o===-1||l===-1||m===0||m===1&&o===l-1&&o===c+1?l!==-1&&(c===0&&r?e.base=e.name=s.slice(1,l):e.base=e.name=s.slice(c,l)):(c===0&&r?(e.name=s.slice(1,o),e.base=s.slice(1,l)):(e.name=s.slice(c,o),e.base=s.slice(c,l)),e.ext=s.slice(o,l)),e.dir=this.dirname(s),e},sep:"/",delimiter:":",joinExtensions:[".html"]};function Ka(s,e,t,r,n){const o=e[t];for(let c=0;c<o.length;c++){const l=o[c];t<e.length-1?Ka(s.replace(r[t],l),e,t+1,r,n):n.push(s.replace(r[t],l))}}function zp(s){const e=/\{(.*?)\}/g,t=s.match(e),r=[];if(t){const n=[];t.forEach(o=>{const c=o.substring(1,o.length-1).split(",");n.push(c)}),Ka(s,n,0,t,r)}else r.push(s);return r}const Fr=s=>!Array.isArray(s);class ii{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(r=>`${encodeURIComponent(r)}=${encodeURIComponent(t[r])}`).join("&")}}getAlias(e){const{alias:t,src:r}=e;return Qe(t||r,o=>typeof o=="string"?o:Array.isArray(o)?o.map(c=>c?.src??c):o?.src?o.src:o,!0)}addManifest(e){this._manifest&&G("[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 r=[];let n=t;Array.isArray(t)||(n=Object.entries(t).map(([o,c])=>typeof c=="string"||Array.isArray(c)?{alias:o,src:c}:{alias:o,...c})),n.forEach(o=>{const c=o.src,l=o.alias;let d;if(typeof l=="string"){const f=this._createBundleAssetId(e,l);r.push(f),d=[l,f]}else{const f=l.map(m=>this._createBundleAssetId(e,m));r.push(...f),d=[...l,...f]}this.add({...o,alias:d,src:c})}),this._bundles[e]=r}add(e){const t=[];Array.isArray(e)?t.push(...e):t.push(e);let r;r=o=>{this.hasKey(o)&&G(`[Resolver] already has key: ${o} overwriting`)},Qe(t).forEach(o=>{const{src:c}=o;let{data:l,format:d,loadParser:f,parser:m}=o;const g=Qe(c).map(h=>typeof h=="string"?zp(h):Array.isArray(h)?h:[h]),_=this.getAlias(o);Array.isArray(_)?_.forEach(r):r(_);const y=[],a=h=>({...this._parsers.find(p=>p.test(h))?.parse(h),src:h});g.forEach(h=>{h.forEach(u=>{let p={};if(typeof u!="object"?p=a(u):(l=u.data??l,d=u.format??d,(u.loadParser||u.parser)&&(f=u.loadParser??f,m=u.parser??m),p={...a(u.src),...u}),!_)throw new Error(`[Resolver] alias is undefined for this asset: ${p.src}`);p=this._buildResolvedAsset(p,{aliases:_,data:l,format:d,loadParser:f,parser:m,progressSize:o.progressSize}),y.push(p)})}),_.forEach(h=>{this._assetMap[h]=y})})}resolveBundle(e){const t=Fr(e);e=Qe(e);const r={};return e.forEach(n=>{const o=this._bundles[n];if(o){const c=this.resolve(o),l={};for(const d in c){const f=c[d];l[this._extractAssetIdFromBundle(n,d)]=f}r[n]=l}}),t?r[e[0]]:r}resolveUrl(e){const t=this.resolve(e);if(typeof e!="string"){const r={};for(const n in t)r[n]=t[n].src;return r}return t.src}resolve(e){const t=Fr(e);e=Qe(e);const r={};return e.forEach(n=>{if(!this._resolverHash[n])if(this._assetMap[n]){let o=this._assetMap[n];const c=this._getPreferredOrder(o);c?.priority.forEach(l=>{c.params[l].forEach(d=>{const f=o.filter(m=>m[l]?m[l]===d:!1);f.length&&(o=f)})}),this._resolverHash[n]=o[0]}else this._resolverHash[n]=this._buildResolvedAsset({alias:[n],src:n},{});r[n]=this._resolverHash[n]}),t?r[e[0]]:r}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){const r=e[t],n=this._preferredOrder.find(o=>o.params.format.includes(r.format));if(n)return n}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:r,data:n,loadParser:o,parser:c,format:l,progressSize:d}=t;return(this._basePath||this._rootPath)&&(e.src=ze.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=r??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...n||{},...e.data},e.loadParser=o??e.loadParser,e.parser=c??e.parser,e.format=l??e.format??Hp(e.src),d!==void 0&&(e.progressSize=d),e}}ii.RETINA_PREFIX=/@([0-9\.]+)x/;function Hp(s){return s.split(".").pop().split("?").shift().split("#").shift()}const Ks=(s,e)=>{const t=e.split("?")[1];return t&&(s+=`?${t}`),s},ja=class hr{constructor(e,t){this.linkedSheets=[];let r=e;e?.source instanceof ge&&(r={texture:e,data:t});const{texture:n,data:o,cachePrefix:c=""}=r;this.cachePrefix=c,this._texture=n instanceof F?n:null,this.textureSource=n.source,this.textures={},this.animations={},this.data=o;const l=parseFloat(o.meta.scale);l?(this.resolution=l,n.source.resolution=this.resolution):this.resolution=n.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<=hr.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(e){let t=e;const r=hr.BATCH_SIZE;for(;t-e<r&&t<this._frameKeys.length;){const n=this._frameKeys[t],o=this._frames[n],c=o.frame;if(c){let l=null,d=null;const f=o.trimmed!==!1&&o.sourceSize?o.sourceSize:o.frame,m=new z(0,0,Math.floor(f.w)/this.resolution,Math.floor(f.h)/this.resolution);o.rotated?l=new z(Math.floor(c.x)/this.resolution,Math.floor(c.y)/this.resolution,Math.floor(c.h)/this.resolution,Math.floor(c.w)/this.resolution):l=new z(Math.floor(c.x)/this.resolution,Math.floor(c.y)/this.resolution,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution),o.trimmed!==!1&&o.spriteSourceSize&&(d=new z(Math.floor(o.spriteSourceSize.x)/this.resolution,Math.floor(o.spriteSourceSize.y)/this.resolution,Math.floor(c.w)/this.resolution,Math.floor(c.h)/this.resolution)),this.textures[n]=new F({source:this.textureSource,frame:l,orig:m,trim:d,rotate:o.rotated?2:0,defaultAnchor:o.anchor,defaultBorders:o.borders,label:n.toString()})}t++}}_processAnimations(){const e=this.data.animations||{};for(const t in e){this.animations[t]=[];for(let r=0;r<e[t].length;r++){const n=e[t][r];this.animations[t].push(this.textures[n])}}}_parseComplete(){const e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*hr.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*hr.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=[]}};ja.BATCH_SIZE=1e3;let Za=ja;const Wp=["jpg","png","jpeg","avif","webp","basis","etc2","bc7","bc6h","bc5","bc4","bc3","bc2","bc1","eac","astc"];function Ja(s,e,t){const r={};if(s.forEach(n=>{r[n]=e}),Object.keys(e.textures).forEach(n=>{r[`${e.cachePrefix}${n}`]=e.textures[n]}),!t){const n=ze.dirname(s[0]);e.linkedSheets.forEach((o,c)=>{const l=Ja([`${n}/${e.data.meta.related_multi_packs[c]}`],o,!0);Object.assign(r,l)})}return r}const Vp={extension:C.Asset,cache:{test:s=>s instanceof Za,getCacheableAssets:(s,e)=>Ja(s,e,!1)},resolver:{extension:{type:C.ResolveParser,name:"resolveSpritesheet"},test:s=>{const t=s.split("?")[0].split("."),r=t.pop(),n=t.pop();return r==="json"&&Wp.includes(n)},parse:s=>{const e=s.split(".");return{resolution:parseFloat(ii.RETINA_PREFIX.exec(s)?.[1]??"1"),format:e[e.length-2],src:s}}},loader:{name:"spritesheetLoader",id:"spritesheet",extension:{type:C.LoadParser,priority:At.Normal,name:"spritesheetLoader"},async testParse(s,e){return ze.extname(e.src).toLowerCase()===".json"&&!!s.frames},async parse(s,e,t){const{texture:r,imageFilename:n,textureOptions:o,cachePrefix:c}=e?.data??{};let l=ze.dirname(e.src);l&&l.lastIndexOf("/")!==l.length-1&&(l+="/");let d;if(r instanceof F)d=r;else{const g=Ks(l+(n??s.meta.image),e.src);d=(await t.load([{src:g,data:o}]))[g]}const f=new Za({texture:d.source,data:s,cachePrefix:c});await f.parse();const m=s?.meta?.related_multi_packs;if(Array.isArray(m)){const g=[];for(const y of m){if(typeof y!="string")continue;let a=l+y;e.data?.ignoreMultiPack||(a=Ks(a,e.src),g.push(t.load({src:a,data:{textureOptions:o,ignoreMultiPack:!0}})))}const _=await Promise.all(g);f.linkedSheets=_,_.forEach(y=>{y.linkedSheets=[f].concat(f.linkedSheets.filter(a=>a!==y))})}return f},async unload(s,e,t){await t.unload(s.textureSource._sourceOrigin),s.destroy(!1)}}};L.add(Vp);class Qa{constructor(e){this._lastTransform="",this._observer=null,this._tickerAttached=!1,this.updateTranslation=()=>{if(!this._canvas)return;const t=this._canvas.getBoundingClientRect(),r=this._canvas.width,n=this._canvas.height,o=t.width/r*this._renderer.resolution,c=t.height/n*this._renderer.resolution,l=t.left,d=t.top,f=`translate(${l}px, ${d}px) scale(${o}, ${c})`;f!==this._lastTransform&&(this._domElement.style.transform=f,this._lastTransform=f)},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 r=this.canvas.width,n=this.canvas.height,o=t.contentRect.width/r*this._renderer.resolution,c=t.contentRect.height/n*this._renderer.resolution;(this._lastScaleX!==o||this._lastScaleY!==c)&&(this.updateTranslation(),this._lastScaleX=o,this._lastScaleY=c)}}),this._observer.observe(this._canvas)):this._tickerAttached||Ne.shared.add(this.updateTranslation,this,ti.HIGH)}destroy(){this._observer?(this._observer.disconnect(),this._observer=null):this._tickerAttached&&Ne.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 Ri{constructor(e){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=Ri.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new J,this.page=new J,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,r){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(e,t,r,n,o){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 js=/iPhone/i,el=/iPod/i,tl=/iPad/i,il=/\biOS-universal(?:.+)Mac\b/i,Zs=/\bAndroid(?:.+)Mobile\b/i,rl=/Android/i,ri=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ur=/Silk/i,gt=/Windows Phone/i,sl=/\bWindows(?:.+)ARM\b/i,nl=/BlackBerry/i,ol=/BB10/i,al=/Opera Mini/i,ll=/\b(CriOS|Chrome)(?:.+)Mobile/i,cl=/Mobile(?:.+)Firefox\b/i,hl=function(s){return typeof s<"u"&&s.platform==="MacIntel"&&typeof s.maxTouchPoints=="number"&&s.maxTouchPoints>1&&typeof MSStream>"u"};function Yp(s){return function(e){return e.test(s)}}function ul(s){var e={userAgent:"",platform:"",maxTouchPoints:0};!s&&typeof navigator<"u"?e={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof s=="string"?e.userAgent=s:s&&s.userAgent&&(e={userAgent:s.userAgent,platform:s.platform,maxTouchPoints:s.maxTouchPoints||0});var t=e.userAgent,r=t.split("[FBAN");typeof r[1]<"u"&&(t=r[0]),r=t.split("Twitter"),typeof r[1]<"u"&&(t=r[0]);var n=Yp(t),o={apple:{phone:n(js)&&!n(gt),ipod:n(el),tablet:!n(js)&&(n(tl)||hl(e))&&!n(gt),universal:n(il),device:(n(js)||n(el)||n(tl)||n(il)||hl(e))&&!n(gt)},amazon:{phone:n(ri),tablet:!n(ri)&&n(Ur),device:n(ri)||n(Ur)},android:{phone:!n(gt)&&n(ri)||!n(gt)&&n(Zs),tablet:!n(gt)&&!n(ri)&&!n(Zs)&&(n(Ur)||n(rl)),device:!n(gt)&&(n(ri)||n(Ur)||n(Zs)||n(rl))||n(/\bokhttp\b/i)},windows:{phone:n(gt),tablet:n(sl),device:n(gt)||n(sl)},other:{blackberry:n(nl),blackberry10:n(ol),opera:n(al),firefox:n(cl),chrome:n(ll),device:n(nl)||n(ol)||n(al)||n(cl)||n(ll)},any:!1,phone:!1,tablet:!1};return o.any=o.apple.device||o.android.device||o.windows.device||o.other.device,o.phone=o.apple.phone||o.android.phone||o.windows.phone,o.tablet=o.apple.tablet||o.android.tablet||o.windows.tablet,o}const Xp=(ul.default??ul)(globalThis.navigator),$p=9,dl=100,qp=0,Kp=0,fl=2,pl=1,jp=-1e3,Zp=-1e3,Jp=2,Js=class fd{constructor(e,t=Xp){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=`${pl}px`,e.style.height=`${pl}px`,e.style.position="absolute",e.style.top=`${jp}px`,e.style.left=`${Zp}px`,e.style.zIndex=Jp.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=`${qp}px`,this._div.style.left=`${Kp}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=fl.toString(),this._canvasObserver=new Qa({domElement:this._div,renderer:this._renderer})),this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),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._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),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(r=>{r.parentNode&&r.parentNode.removeChild(r)}),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 r=0;r<t.length;r++)this._updateAccessibleObjects(t[r])}init(e){const r={accessibilityOptions:{...fd.defaultOptions,...e?.accessibilityOptions||{}}};this.debug=r.accessibilityOptions.debug,this._activateOnTab=r.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=r.accessibilityOptions.deactivateOnMouseMove,r.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 r of this._children)r._renderId===this._renderId&&t.add(this._children.indexOf(r))}for(let r=this._children.length-1;r>=0;r--){const n=this._children[r];t.has(r)||(n._accessibleDiv&&n._accessibleDiv.parentNode&&(n._accessibleDiv.parentNode.removeChild(n._accessibleDiv),this._getPool(n.accessibleType).push(n._accessibleDiv),n._accessibleDiv=null),n._accessibleActive=!1,Fa(this._children,r,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let r=0;r<this._children.length;r++){const n=this._children[r];if(!n._accessibleActive||!n._accessibleDiv)continue;const o=n._accessibleDiv,c=n.hitArea||n.getBounds().rectangle;if(n.hitArea){const l=n.worldTransform;o.style.left=`${l.tx+c.x*l.a}px`,o.style.top=`${l.ty+c.y*l.d}px`,o.style.width=`${c.width*l.a}px`,o.style.height=`${c.height*l.d}px`}else this._capHitArea(c),o.style.left=`${c.x}px`,o.style.top=`${c.y}px`,o.style.width=`${c.width}px`,o.style.height=`${c.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:r}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>r&&(e.height=r-e.y)}_addChild(e){let r=this._getPool(e.accessibleType).pop();r?(r.innerHTML="",r.removeAttribute("title"),r.removeAttribute("aria-label"),r.tabIndex=0):(e.accessibleType==="button"?r=document.createElement("button"):(r=document.createElement(e.accessibleType),r.style.cssText=`
|
|
68
68
|
color: transparent;
|
|
69
69
|
pointer-events: none;
|
|
70
70
|
padding: 0;
|
|
@@ -95,12 +95,12 @@ Deprecated since v${s}`,o=typeof console.groupCollapsed=="function"&&!Zt.noColor
|
|
|
95
95
|
`}function rm(s,e,t){const r=t?e.maxSupportedFragmentPrecision:e.maxSupportedVertexPrecision;if(s.substring(0,9)!=="precision"){let n=t?e.requestedFragmentPrecision:e.requestedVertexPrecision;return n==="highp"&&r!=="highp"&&(n="mediump"),`precision ${n} float;
|
|
96
96
|
${s}`}else if(r!=="highp"&&s.substring(0,15)==="precision highp")return s.replace("precision highp","precision mediump");return s}function sm(s,e){return e?`#version 300 es
|
|
97
97
|
${s}`:s}const nm={},om={};function am(s,{name:e="pixi-program"},t=!0){e=e.replace(/\s+/g,"-"),e+=t?"-fragment":"-vertex";const r=t?nm:om;return r[e]?(r[e]++,e+=`-${r[e]}`):r[e]=1,s.indexOf("#define SHADER_NAME")!==-1?s:`${`#define SHADER_NAME ${e}`}
|
|
98
|
-
${s}`}function lm(s,e){return e?s.replace("#version 300 es",""):s}const en={stripVersion:lm,ensurePrecision:rm,addProgramDefines:im,setProgramName:am,insertVersion:sm},Fi=Object.create(null),vl=class Ro{constructor(e){e={...Ro.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,r={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:tm()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let n=e.fragment,o=e.vertex;Object.keys(en).forEach(c=>{const l=r[c];n=en[c](n,l,!0),o=en[c](o,l,!1)}),this.fragment=n,this.vertex=o,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=Mi(`${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,Fi[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return Fi[t]||(Fi[t]=new Ro(e),Fi[t]._cacheKey=t),Fi[t]}};vl.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let vt=vl;const _l={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 Et(s){return _l[s]??_l.float32}const cm={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",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"};function hm({source:s,entryPoint:e}){const t={},r=s.indexOf(`fn ${e}`);if(r!==-1){const n=s.indexOf("->",r);if(n!==-1){const o=s.substring(r,n),c=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g;let l;for(;(l=c.exec(o))!==null;){const d=cm[l[3]]??"float32";t[l[2]]={location:parseInt(l[1],10),format:d,stride:Et(d).stride,offset:0,instance:!1,start:0}}}}return t}function tn(s){const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,r=/@binding\((\d+)\)/,n=/var(<[^>]+>)? (\w+)/,o=/:\s*(\w+)/,c=/struct\s+(\w+)\s*{([^}]+)}/g,l=/(\w+)\s*:\s*([\w\<\>]+)/g,d=/struct\s+(\w+)/,f=s.match(e)?.map(g=>({group:parseInt(g.match(t)[1],10),binding:parseInt(g.match(r)[1],10),name:g.match(n)[2],isUniform:g.match(n)[1]==="<uniform>",type:g.match(o)[1]}));if(!f)return{groups:[],structs:[]};const m=s.match(c)?.map(g=>{const _=g.match(d)[1],y=g.match(l).reduce((a,h)=>{const[u,p]=h.split(":");return a[u.trim()]=p.trim(),a},{});return y?{name:_,members:y}:null}).filter(({name:g})=>f.some(_=>_.type===g))??[];return{groups:f,structs:m}}var Ui=(s=>(s[s.VERTEX=1]="VERTEX",s[s.FRAGMENT=2]="FRAGMENT",s[s.COMPUTE=4]="COMPUTE",s))(Ui||{});function um({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]=[]),r.isUniform?e[r.group].push({binding:r.binding,visibility:Ui.VERTEX|Ui.FRAGMENT,buffer:{type:"uniform"}}):r.type==="sampler"?e[r.group].push({binding:r.binding,visibility:Ui.FRAGMENT,sampler:{type:"filtering"}}):r.type==="texture_2d"&&e[r.group].push({binding:r.binding,visibility:Ui.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}})}return e}function dm({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]={}),e[r.group][r.name]=r.binding}return e}function fm(s,e){const t=new Set,r=new Set,n=[...s.structs,...e.structs].filter(c=>t.has(c.name)?!1:(t.add(c.name),!0)),o=[...s.groups,...e.groups].filter(c=>{const l=`${c.name}-${c.binding}`;return r.has(l)?!1:(r.add(l),!0)});return{structs:n,groups:o}}const ki=Object.create(null);class It{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:r,layout:n,gpuLayout:o,name:c}=e;if(this.name=c,this.fragment=t,this.vertex=r,t.source===r.source){const l=tn(t.source);this.structsAndGroups=l}else{const l=tn(r.source),d=tn(t.source);this.structsAndGroups=fm(l,d)}this.layout=n??dm(this.structsAndGroups),this.gpuLayout=o??um(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,r=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=Mi(r,"program")}get attributeData(){return this._attributeData??(this._attributeData=hm(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,ki[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return ki[t]||(ki[t]=new It(e),ki[t]._cacheKey=t),ki[t]}}const yl=["f32","i32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>"],pm=yl.reduce((s,e)=>(s[e]=!0,s),{});function mm(s,e){switch(s){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 xl=class pd{constructor(e,t){this._touched=0,this.uid=ae("uniform"),this._resourceType="uniformGroup",this._resourceId=ae("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...pd.defaultOptions,...t},this.uniformStructures=e;const r={};for(const n in e){const o=e[n];if(o.name=n,o.size=o.size??1,!pm[o.type]){const c=o.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(c){const[,l,d]=c;throw new Error(`Uniform type ${o.type} is not supported. Use type: '${l}', size: ${d} instead.`)}throw new Error(`Uniform type ${o.type} is not supported. Supported uniform types are: ${yl.join(", ")}`)}o.value??(o.value=mm(o.type,o.size)),r[n]=o.value}this.uniforms=r,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=Mi(Object.keys(r).map(n=>`${n}-${e[n].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};xl.defaultOptions={ubo:!1,isStatic:!1};let Ue=xl;class _t{constructor(e){this.resources=Object.create(null),this._dirty=!0;let t=0;for(const r in e){const n=e[r];this.setResource(n,t++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const e=[];let t=0;for(const r in this.resources)e[t++]=this.resources[r]._resourceId;this._key=e.join("|")}setResource(e,t){const r=this.resources[t];e!==r&&(r&&e.off?.("change",this.onResourceChange,this),e.on?.("change",this.onResourceChange,this),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e){const t=this.resources;for(const r in t)t[r]._touched=e}destroy(){const e=this.resources;for(const t in e)e[t]?.off?.("change",this.onResourceChange,this);this.resources=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const r in t)t[r]===e&&(t[r]=null)}else this._updateKey()}}var tt=(s=>(s[s.WEBGL=1]="WEBGL",s[s.WEBGPU=2]="WEBGPU",s[s.BOTH=3]="BOTH",s))(tt||{});class qe extends Ge{constructor(e){super(),this.uid=ae("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:r,groups:n,resources:o,compatibleRenderers:c,groupMap:l}=e;this.gpuProgram=t,this.glProgram=r,c===void 0&&(c=0,t&&(c|=tt.WEBGPU),r&&(c|=tt.WEBGL)),this.compatibleRenderers=c;const d={};if(!o&&!n&&(o={}),o&&n)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&n&&!l)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!t&&n&&l)for(const f in l)for(const m in l[f]){const g=l[f][m];d[g]={group:f,binding:m,name:g}}else if(t&&n&&!l){const f=t.structsAndGroups.groups;l={},f.forEach(m=>{l[m.group]=l[m.group]||{},l[m.group][m.binding]=m.name,d[m.name]=m})}else if(o){n={},l={},t&&t.structsAndGroups.groups.forEach(g=>{l[g.group]=l[g.group]||{},l[g.group][g.binding]=g.name,d[g.name]=g});let f=0;for(const m in o)d[m]||(n[99]||(n[99]=new _t,this._ownedBindGroups.push(n[99])),d[m]={group:99,binding:f,name:m},l[99]=l[99]||{},l[99][f]=m,f++);for(const m in o){const g=m;let _=o[m];!_.source&&!_._resourceType&&(_=new Ue(_));const y=d[g];y&&(n[y.group]||(n[y.group]=new _t,this._ownedBindGroups.push(n[y.group])),n[y.group].setResource(_,y.binding))}}this.groups=n,this._uniformBindMap=l,this.resources=this._buildResourceAccessor(n,d)}addResource(e,t,r){var n,o;(n=this._uniformBindMap)[t]||(n[t]={}),(o=this._uniformBindMap[t])[r]||(o[r]=e),this.groups[t]||(this.groups[t]=new _t,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const r={};for(const n in t){const o=t[n];Object.defineProperty(r,o.name,{get(){return e[o.group].getResource(o.binding)},set(c){e[o.group].setResource(c,o.binding)}})}return r}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)}static from(e){const{gpu:t,gl:r,...n}=e;let o,c;return t&&(o=It.from(t)),r&&(c=vt.from(r)),new qe({gpuProgram:o,glProgram:c,...n})}}const gm={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},rn=0,sn=1,nn=2,on=3,an=4,ln=5,cn=class md{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<rn)}set blend(e){!!(this.data&1<<rn)!==e&&(this.data^=1<<rn)}get offsets(){return!!(this.data&1<<sn)}set offsets(e){!!(this.data&1<<sn)!==e&&(this.data^=1<<sn)}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<<nn)}set culling(e){!!(this.data&1<<nn)!==e&&(this.data^=1<<nn)}get depthTest(){return!!(this.data&1<<on)}set depthTest(e){!!(this.data&1<<on)!==e&&(this.data^=1<<on)}get depthMask(){return!!(this.data&1<<ln)}set depthMask(e){!!(this.data&1<<ln)!==e&&(this.data^=1<<ln)}get clockwiseFrontFace(){return!!(this.data&1<<an)}set clockwiseFrontFace(e){!!(this.data&1<<an)!==e&&(this.data^=1<<an)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=gm[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 md;return e.depthTest=!1,e.blend=!0,e}};cn.default2d=cn.for2d();let it=cn;const bl=class Mo extends qe{constructor(e){e={...Mo.defaultOptions,...e},super(e),this.enabled=!0,this._state=it.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,r,n){e.applyFilter(this,t,r,n)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:r,...n}=e;let o,c;return t&&(o=It.from(t)),r&&(c=vt.from(r)),new Mo({gpuProgram:o,glProgram:c,...n})}};bl.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Dr=bl;const hn=[];L.handleByNamedList(C.Environment,hn);async function vm(s){if(!s)for(let e=0;e<hn.length;e++){const t=hn[e];if(t.value.test()){await t.value.load();return}}}let Bi;function Tl(){if(typeof Bi=="boolean")return Bi;try{Bi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{Bi=!1}return Bi}function wl(s,e,t=2){const r=e&&e.length,n=r?e[0]*t:s.length;let o=Sl(s,0,n,t,!0);const c=[];if(!o||o.next===o.prev)return c;let l,d,f;if(r&&(o=Tm(s,e,o,t)),s.length>80*t){l=s[0],d=s[1];let m=l,g=d;for(let _=t;_<n;_+=t){const y=s[_],a=s[_+1];y<l&&(l=y),a<d&&(d=a),y>m&&(m=y),a>g&&(g=a)}f=Math.max(m-l,g-d),f=f!==0?32767/f:0}return Di(o,c,t,l,d,f,0),c}function Sl(s,e,t,r,n){let o;if(n===Um(s,e,t,r)>0)for(let c=e;c<t;c+=r)o=Il(c/r|0,s[c],s[c+1],o);else for(let c=t-r;c>=e;c-=r)o=Il(c/r|0,s[c],s[c+1],o);return o&&si(o,o.next)&&(Li(o),o=o.next),o}function Lt(s,e){if(!s)return s;e||(e=s);let t=s,r;do if(r=!1,!t.steiner&&(si(t,t.next)||ue(t.prev,t,t.next)===0)){if(Li(t),t=e=t.prev,t===t.next)break;r=!0}else t=t.next;while(r||t!==e);return e}function Di(s,e,t,r,n,o,c){if(!s)return;!c&&o&&Em(s,r,n,o);let l=s;for(;s.prev!==s.next;){const d=s.prev,f=s.next;if(o?ym(s,r,n,o):_m(s)){e.push(d.i,s.i,f.i),Li(s),s=f.next,l=f.next;continue}if(s=f,s===l){c?c===1?(s=xm(Lt(s),e),Di(s,e,t,r,n,o,2)):c===2&&bm(s,e,t,r,n,o):Di(Lt(s),e,t,r,n,o,1);break}}}function _m(s){const e=s.prev,t=s,r=s.next;if(ue(e,t,r)>=0)return!1;const n=e.x,o=t.x,c=r.x,l=e.y,d=t.y,f=r.y,m=Math.min(n,o,c),g=Math.min(l,d,f),_=Math.max(n,o,c),y=Math.max(l,d,f);let a=r.next;for(;a!==e;){if(a.x>=m&&a.x<=_&&a.y>=g&&a.y<=y&&Oi(n,l,o,d,c,f,a.x,a.y)&&ue(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function ym(s,e,t,r){const n=s.prev,o=s,c=s.next;if(ue(n,o,c)>=0)return!1;const l=n.x,d=o.x,f=c.x,m=n.y,g=o.y,_=c.y,y=Math.min(l,d,f),a=Math.min(m,g,_),h=Math.max(l,d,f),u=Math.max(m,g,_),p=un(y,a,e,t,r),v=un(h,u,e,t,r);let x=s.prevZ,b=s.nextZ;for(;x&&x.z>=p&&b&&b.z<=v;){if(x.x>=y&&x.x<=h&&x.y>=a&&x.y<=u&&x!==n&&x!==c&&Oi(l,m,d,g,f,_,x.x,x.y)&&ue(x.prev,x,x.next)>=0||(x=x.prevZ,b.x>=y&&b.x<=h&&b.y>=a&&b.y<=u&&b!==n&&b!==c&&Oi(l,m,d,g,f,_,b.x,b.y)&&ue(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;x&&x.z>=p;){if(x.x>=y&&x.x<=h&&x.y>=a&&x.y<=u&&x!==n&&x!==c&&Oi(l,m,d,g,f,_,x.x,x.y)&&ue(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;b&&b.z<=v;){if(b.x>=y&&b.x<=h&&b.y>=a&&b.y<=u&&b!==n&&b!==c&&Oi(l,m,d,g,f,_,b.x,b.y)&&ue(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function xm(s,e){let t=s;do{const r=t.prev,n=t.next.next;!si(r,n)&&Al(r,t,t.next,n)&&Gi(r,n)&&Gi(n,r)&&(e.push(r.i,t.i,n.i),Li(t),Li(t.next),t=s=n),t=t.next}while(t!==s);return Lt(t)}function bm(s,e,t,r,n,o){let c=s;do{let l=c.next.next;for(;l!==c.prev;){if(c.i!==l.i&&Rm(c,l)){let d=El(c,l);c=Lt(c,c.next),d=Lt(d,d.next),Di(c,e,t,r,n,o,0),Di(d,e,t,r,n,o,0);return}l=l.next}c=c.next}while(c!==s)}function Tm(s,e,t,r){const n=[];for(let o=0,c=e.length;o<c;o++){const l=e[o]*r,d=o<c-1?e[o+1]*r:s.length,f=Sl(s,l,d,r,!1);f===f.next&&(f.steiner=!0),n.push(Pm(f))}n.sort(wm);for(let o=0;o<n.length;o++)t=Sm(n[o],t);return t}function wm(s,e){let t=s.x-e.x;if(t===0&&(t=s.y-e.y,t===0)){const r=(s.next.y-s.y)/(s.next.x-s.x),n=(e.next.y-e.y)/(e.next.x-e.x);t=r-n}return t}function Sm(s,e){const t=Cm(s,e);if(!t)return e;const r=El(t,s);return Lt(r,r.next),Lt(t,t.next)}function Cm(s,e){let t=e;const r=s.x,n=s.y;let o=-1/0,c;if(si(s,t))return t;do{if(si(s,t.next))return t.next;if(n<=t.y&&n>=t.next.y&&t.next.y!==t.y){const g=t.x+(n-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(g<=r&&g>o&&(o=g,c=t.x<t.next.x?t:t.next,g===r))return c}t=t.next}while(t!==e);if(!c)return null;const l=c,d=c.x,f=c.y;let m=1/0;t=c;do{if(r>=t.x&&t.x>=d&&r!==t.x&&Cl(n<f?r:o,n,d,f,n<f?o:r,n,t.x,t.y)){const g=Math.abs(n-t.y)/(r-t.x);Gi(t,s)&&(g<m||g===m&&(t.x>c.x||t.x===c.x&&Am(c,t)))&&(c=t,m=g)}t=t.next}while(t!==l);return c}function Am(s,e){return ue(s.prev,s,e.prev)<0&&ue(e.next,s,s.next)<0}function Em(s,e,t,r){let n=s;do n.z===0&&(n.z=un(n.x,n.y,e,t,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==s);n.prevZ.nextZ=null,n.prevZ=null,Im(n)}function Im(s){let e,t=1;do{let r=s,n;s=null;let o=null;for(e=0;r;){e++;let c=r,l=0;for(let f=0;f<t&&(l++,c=c.nextZ,!!c);f++);let d=t;for(;l>0||d>0&&c;)l!==0&&(d===0||!c||r.z<=c.z)?(n=r,r=r.nextZ,l--):(n=c,c=c.nextZ,d--),o?o.nextZ=n:s=n,n.prevZ=o,o=n;r=c}o.nextZ=null,t*=2}while(e>1);return s}function un(s,e,t,r,n){return s=(s-t)*n|0,e=(e-r)*n|0,s=(s|s<<8)&16711935,s=(s|s<<4)&252645135,s=(s|s<<2)&858993459,s=(s|s<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,s|e<<1}function Pm(s){let e=s,t=s;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==s);return t}function Cl(s,e,t,r,n,o,c,l){return(n-c)*(e-l)>=(s-c)*(o-l)&&(s-c)*(r-l)>=(t-c)*(e-l)&&(t-c)*(o-l)>=(n-c)*(r-l)}function Oi(s,e,t,r,n,o,c,l){return!(s===c&&e===l)&&Cl(s,e,t,r,n,o,c,l)}function Rm(s,e){return s.next.i!==e.i&&s.prev.i!==e.i&&!Mm(s,e)&&(Gi(s,e)&&Gi(e,s)&&Fm(s,e)&&(ue(s.prev,s,e.prev)||ue(s,e.prev,e))||si(s,e)&&ue(s.prev,s,s.next)>0&&ue(e.prev,e,e.next)>0)}function ue(s,e,t){return(e.y-s.y)*(t.x-e.x)-(e.x-s.x)*(t.y-e.y)}function si(s,e){return s.x===e.x&&s.y===e.y}function Al(s,e,t,r){const n=Gr(ue(s,e,t)),o=Gr(ue(s,e,r)),c=Gr(ue(t,r,s)),l=Gr(ue(t,r,e));return!!(n!==o&&c!==l||n===0&&Or(s,t,e)||o===0&&Or(s,r,e)||c===0&&Or(t,s,r)||l===0&&Or(t,e,r))}function Or(s,e,t){return e.x<=Math.max(s.x,t.x)&&e.x>=Math.min(s.x,t.x)&&e.y<=Math.max(s.y,t.y)&&e.y>=Math.min(s.y,t.y)}function Gr(s){return s>0?1:s<0?-1:0}function Mm(s,e){let t=s;do{if(t.i!==s.i&&t.next.i!==s.i&&t.i!==e.i&&t.next.i!==e.i&&Al(t,t.next,s,e))return!0;t=t.next}while(t!==s);return!1}function Gi(s,e){return ue(s.prev,s,s.next)<0?ue(s,e,s.next)>=0&&ue(s,s.prev,e)>=0:ue(s,e,s.prev)<0||ue(s,s.next,e)<0}function Fm(s,e){let t=s,r=!1;const n=(s.x+e.x)/2,o=(s.y+e.y)/2;do t.y>o!=t.next.y>o&&t.next.y!==t.y&&n<(t.next.x-t.x)*(o-t.y)/(t.next.y-t.y)+t.x&&(r=!r),t=t.next;while(t!==s);return r}function El(s,e){const t=dn(s.i,s.x,s.y),r=dn(e.i,e.x,e.y),n=s.next,o=e.prev;return s.next=e,e.prev=s,t.next=n,n.prev=t,r.next=t,t.prev=r,o.next=r,r.prev=o,r}function Il(s,e,t,r){const n=dn(s,e,t);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function Li(s){s.next.prev=s.prev,s.prev.next=s.next,s.prevZ&&(s.prevZ.nextZ=s.nextZ),s.nextZ&&(s.nextZ.prevZ=s.prevZ)}function dn(s,e,t){return{i:s,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Um(s,e,t,r){let n=0;for(let o=e,c=t-r;o<t;o+=r)n+=(s[c]-s[o])*(s[o+1]+s[c+1]),c=o;return n}const km=wl.default||wl;var ze=(s=>(s[s.NONE=0]="NONE",s[s.COLOR=16384]="COLOR",s[s.STENCIL=1024]="STENCIL",s[s.DEPTH=256]="DEPTH",s[s.COLOR_DEPTH=16640]="COLOR_DEPTH",s[s.COLOR_STENCIL=17408]="COLOR_STENCIL",s[s.DEPTH_STENCIL=1280]="DEPTH_STENCIL",s[s.ALL=17664]="ALL",s))(ze||{});class Pl{constructor(e){this.items=[],this._name=e}emit(e,t,r,n,o,c,l,d){const{name:f,items:m}=this;for(let g=0,_=m.length;g<_;g++)m[g][f](e,t,r,n,o,c,l,d);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 Bm=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Rl=class gd extends Ge{constructor(e){super(),this.uid=ae("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=[...Bm,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await vm(t),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const r in this._systemsHash)e={...this._systemsHash[r].constructor.defaultOptions,...e};e={...gd.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let r=0;r<this.runners.init.items.length;r++)await this.runners.init.items[r].init(e);this._initOptions=e}render(e,t){let r=e;if(r instanceof se&&(r={container:r},t&&(H(j,"passing a second argument is deprecated, please use render options instead"),r.target=t.renderTexture)),r.target||(r.target=this.view.renderTarget),r.target===this.view.renderTarget&&(this._lastObjectRendered=r.container,r.clearColor??(r.clearColor=this.background.colorRgba),r.clear??(r.clear=this.background.clearBeforeRender)),r.clearColor){const n=Array.isArray(r.clearColor)&&r.clearColor.length===4;r.clearColor=n?r.clearColor:le.shared.setValue(r.clearColor).toArray()}r.transform||(r.container.updateLocalTransform(),r.transform=r.container.localTransform),r.container.visible&&(r.container.enableRenderGroup(),this.runners.prerender.emit(r),this.runners.renderStart.emit(r),this.runners.render.emit(r),this.runners.renderEnd.emit(r),this.runners.postrender.emit(r))}resize(e,t,r){const n=this.view.resolution;this.view.resize(e,t,r),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),r!==void 0&&r!==n&&this.runners.resolutionChange.emit(r)}clear(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=ze.ALL);const{clear:r,clearColor:n,target:o}=e;le.shared.setValue(n??this.background.colorRgba),t.renderTarget.clear(o,r,le.shared.toArray())}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 Pl(t)})}_addSystems(e){let t;for(t in e){const r=e[t];this._addSystem(r.value,r.name)}}_addSystem(e,t){const r=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=r,this._systemsHash[t]=r;for(const n in this.runners)this.runners[n].add(r);return this}_addPipes(e,t){const r=t.reduce((n,o)=>(n[o.name]=o.value,n),{});e.forEach(n=>{const o=n.value,c=n.name,l=r[c];this.renderPipes[c]=new o(this,l?new l:null),this.runners.destroy.add(this.renderPipes[c])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&ei.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Tl())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()}};Rl.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let Lr=Rl,Nr;function Dm(s){return Nr!==void 0||(Nr=(()=>{const e={stencil:!0,failIfMajorPerformanceCaveat:s??Lr.defaultOptions.failIfMajorPerformanceCaveat};try{if(!V.get().getWebGLRenderingContext())return!1;let r=V.get().createCanvas().getContext("webgl",e);const n=!!r?.getContextAttributes()?.stencil;if(r){const o=r.getExtension("WEBGL_lose_context");o&&o.loseContext()}return r=null,n}catch{return!1}})()),Nr}let zr;async function Om(s={}){return zr!==void 0||(zr=await(async()=>{const e=V.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(s)).requestDevice(),!0}catch{return!1}})()),zr}const Ml=["webgl","webgpu","canvas"];async function Gm(s){let e=[];s.preference?(e.push(s.preference),Ml.forEach(o=>{o!==s.preference&&e.push(o)})):e=Ml.slice();let t,r={};for(let o=0;o<e.length;o++){const c=e[o];if(c==="webgpu"&&await Om()){const{WebGPURenderer:l}=await Promise.resolve().then(()=>Ay);t=l,r={...s,...s.webgpu};break}else if(c==="webgl"&&Dm(s.failIfMajorPerformanceCaveat??Lr.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:l}=await Promise.resolve().then(()=>ay);t=l,r={...s,...s.webgl};break}else if(c==="canvas")throw r={...s},new Error("CanvasRenderer is not yet implemented")}if(delete r.webgpu,delete r.webgl,!t)throw new Error("No available renderer for the current environment");const n=new t;return await n.init(r),n}const Hr="8.14.3";class Fl{static init(){globalThis.__PIXI_APP_INIT__?.(this,Hr)}static destroy(){}}Fl.extension=C.Application;class Ul{constructor(e){this._renderer=e}init(){globalThis.__PIXI_RENDERER_INIT__?.(this._renderer,Hr)}destroy(){this._renderer=null}}Ul.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"initHook",priority:-10};const kl=class Fo{constructor(...e){this.stage=new se,e[0]!==void 0&&H(j,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new se),this.renderer=await Gm(e),Fo._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(j,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,t=!1){const r=Fo._plugins.slice(0);r.reverse(),r.forEach(n=>{n.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};kl._plugins=[];let fn=kl;L.handleByList(C.Application,fn._plugins),L.add(Fl);class Bl{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,r;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,r=globalThis.innerHeight;else{const{clientWidth:n,clientHeight:o}=this._resizeTo;t=n,r=o}this.renderer.resize(t,r),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}}Bl.extension=C.Application;class Dl{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,ti.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?Le.shared:new Le,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}Dl.extension=C.Application;class Ol extends Ge{constructor(){super(...arguments),this.chars=Object.create(null),this.lineHeight=0,this.fontFamily="",this.fontMetrics={fontSize:0,ascent:0,descent:0},this.baseLineOffset=0,this.distanceField={type:"none",range:0},this.pages=[],this.applyFillAsTint=!0,this.baseMeasurementFontSize=100,this.baseRenderedFontSize=100}get font(){return H(j,"BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."),this.fontFamily}get pageTextures(){return H(j,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}get size(){return H(j,"BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."),this.fontMetrics.fontSize}get distanceFieldRange(){return H(j,"BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."),this.distanceField.range}get distanceFieldType(){return H(j,"BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."),this.distanceField.type}destroy(e=!1){this.emit("destroy",this),this.removeAllListeners();for(const t in this.chars)this.chars[t].texture?.destroy();this.chars=null,e&&(this.pages.forEach(t=>t.texture.destroy(!0)),this.pages=null)}}class Lm{constructor(e=0,t=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=r,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()){return e.map(t=>[t,this.get(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=[];let t=this.first;for(;t!==null;)e.push(t.key),t=t.next;return e}setWithEvicted(e,t,r=this.resetTtl){let n=null;if(this.has(e))this.set(e,t,!0,r);else{this.max>0&&this.size===this.max&&(n={...this.first},this.evict(!0));let o=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=o:this.last.next=o,this.last=o}return n}set(e,t,r=!1,n=this.resetTtl){let o=this.items[e];return r||o!==void 0?(o.value=t,r===!1&&n&&(o.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(o)):(this.max>0&&this.size===this.max&&this.evict(!0),o=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=o:this.last.next=o,this.last=o),this}values(e=this.keys()){return e.map(t=>this.get(t))}}function Gl(s=1e3,e=0,t=!1){if(isNaN(s)||s<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 Lm(s,e,t)}const Nm=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function Wr(s){const e=typeof s.fontSize=="number"?`${s.fontSize}px`:s.fontSize;let t=s.fontFamily;Array.isArray(s.fontFamily)||(t=s.fontFamily.split(","));for(let r=t.length-1;r>=0;r--){let n=t[r].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&!Nm.includes(n)&&(n=`"${n}"`),t[r]=n}return`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${e} ${t.join(",")}`}const pn={willReadFrequently:!0},rt=class D{static get experimentalLetterSpacingSupported(){let e=D._experimentalLetterSpacingSupported;if(e===void 0){const t=V.get().getCanvasRenderingContext2D().prototype;e=D._experimentalLetterSpacingSupported="letterSpacing"in t||"textLetterSpacing"in t}return e}constructor(e,t,r,n,o,c,l,d,f){this.text=e,this.style=t,this.width=r,this.height=n,this.lines=o,this.lineWidths=c,this.lineHeight=l,this.maxLineWidth=d,this.fontProperties=f}static measureText(e=" ",t,r=D._canvas,n=t.wordWrap){const o=`${e}-${t.styleKey}-wordWrap-${n}`;if(D._measurementCache.has(o))return D._measurementCache.get(o);const c=Wr(t),l=D.measureFont(c);l.fontSize===0&&(l.fontSize=t.fontSize,l.ascent=t.fontSize);const d=D.__context;d.font=c;const m=(n?D._wordWrap(e,t,r):e).split(/(?:\r\n|\r|\n)/),g=new Array(m.length);let _=0;for(let v=0;v<m.length;v++){const x=D._measureText(m[v],t.letterSpacing,d);g[v]=x,_=Math.max(_,x)}const y=t._stroke?.width||0;let a=_+y;t.dropShadow&&(a+=t.dropShadow.distance);const h=t.lineHeight||l.fontSize;let u=Math.max(h,l.fontSize+y)+(m.length-1)*(h+t.leading);t.dropShadow&&(u+=t.dropShadow.distance);const p=new D(e,t,a,u,m,g,h+t.leading,_,l);return D._measurementCache.set(o,p),p}static _measureText(e,t,r){let n=!1;D.experimentalLetterSpacingSupported&&(D.experimentalLetterSpacing?(r.letterSpacing=`${t}px`,r.textLetterSpacing=`${t}px`,n=!0):(r.letterSpacing="0px",r.textLetterSpacing="0px"));const o=r.measureText(e);let c=o.width;const l=-o.actualBoundingBoxLeft;let f=o.actualBoundingBoxRight-l;if(c>0)if(n)c-=t,f-=t;else{const m=(D.graphemeSegmenter(e).length-1)*t;c+=m,f+=m}return Math.max(c,f)}static _wordWrap(e,t,r=D._canvas){const n=r.getContext("2d",pn);let o=0,c="",l="";const d=Object.create(null),{letterSpacing:f,whiteSpace:m}=t,g=D._collapseSpaces(m),_=D._collapseNewlines(m);let y=!g;const a=t.wordWrapWidth+f,h=D._tokenize(e);for(let u=0;u<h.length;u++){let p=h[u];if(D._isNewline(p)){if(!_){l+=D._addLine(c),y=!g,c="",o=0;continue}p=" "}if(g){const x=D.isBreakingSpace(p),b=D.isBreakingSpace(c[c.length-1]);if(x&&b)continue}const v=D._getFromCache(p,f,d,n);if(v>a)if(c!==""&&(l+=D._addLine(c),c="",o=0),D.canBreakWords(p,t.breakWords)){const x=D.wordWrapSplit(p);for(let b=0;b<x.length;b++){let T=x[b],w=T,S=1;for(;x[b+S];){const A=x[b+S];if(!D.canBreakChars(w,A,p,b,t.breakWords))T+=A;else break;w=A,S++}b+=S-1;const E=D._getFromCache(T,f,d,n);E+o>a&&(l+=D._addLine(c),y=!1,c="",o=0),c+=T,o+=E}}else{c.length>0&&(l+=D._addLine(c),c="",o=0);const x=u===h.length-1;l+=D._addLine(p,!x),y=!1,c="",o=0}else v+o>a&&(y=!1,l+=D._addLine(c),c="",o=0),(c.length>0||!D.isBreakingSpace(p)||y)&&(c+=p,o+=v)}return l+=D._addLine(c,!1),l}static _addLine(e,t=!0){return e=D._trimRight(e),e=t?`${e}
|
|
98
|
+
${s}`}function lm(s,e){return e?s.replace("#version 300 es",""):s}const en={stripVersion:lm,ensurePrecision:rm,addProgramDefines:im,setProgramName:am,insertVersion:sm},Fi=Object.create(null),vl=class Ro{constructor(e){e={...Ro.defaultOptions,...e};const t=e.fragment.indexOf("#version 300 es")!==-1,r={stripVersion:t,ensurePrecision:{requestedFragmentPrecision:e.preferredFragmentPrecision,requestedVertexPrecision:e.preferredVertexPrecision,maxSupportedVertexPrecision:"highp",maxSupportedFragmentPrecision:tm()},setProgramName:{name:e.name},addProgramDefines:t,insertVersion:t};let n=e.fragment,o=e.vertex;Object.keys(en).forEach(c=>{const l=r[c];n=en[c](n,l,!0),o=en[c](o,l,!1)}),this.fragment=n,this.vertex=o,this.transformFeedbackVaryings=e.transformFeedbackVaryings,this._key=Mi(`${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,Fi[this._cacheKey]=null}static from(e){const t=`${e.vertex}:${e.fragment}`;return Fi[t]||(Fi[t]=new Ro(e),Fi[t]._cacheKey=t),Fi[t]}};vl.defaultOptions={preferredVertexPrecision:"highp",preferredFragmentPrecision:"mediump"};let vt=vl;const _l={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 Et(s){return _l[s]??_l.float32}const cm={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",u32:"uint32","vec2<u32>":"uint32x2","vec3<u32>":"uint32x3","vec4<u32>":"uint32x4",bool:"uint32","vec2<bool>":"uint32x2","vec3<bool>":"uint32x3","vec4<bool>":"uint32x4"};function hm({source:s,entryPoint:e}){const t={},r=s.indexOf(`fn ${e}`);if(r!==-1){const n=s.indexOf("->",r);if(n!==-1){const o=s.substring(r,n),c=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|$)/g;let l;for(;(l=c.exec(o))!==null;){const d=cm[l[3]]??"float32";t[l[2]]={location:parseInt(l[1],10),format:d,stride:Et(d).stride,offset:0,instance:!1,start:0}}}}return t}function tn(s){const e=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,t=/@group\((\d+)\)/,r=/@binding\((\d+)\)/,n=/var(<[^>]+>)? (\w+)/,o=/:\s*(\w+)/,c=/struct\s+(\w+)\s*{([^}]+)}/g,l=/(\w+)\s*:\s*([\w\<\>]+)/g,d=/struct\s+(\w+)/,f=s.match(e)?.map(g=>({group:parseInt(g.match(t)[1],10),binding:parseInt(g.match(r)[1],10),name:g.match(n)[2],isUniform:g.match(n)[1]==="<uniform>",type:g.match(o)[1]}));if(!f)return{groups:[],structs:[]};const m=s.match(c)?.map(g=>{const _=g.match(d)[1],y=g.match(l).reduce((a,h)=>{const[u,p]=h.split(":");return a[u.trim()]=p.trim(),a},{});return y?{name:_,members:y}:null}).filter(({name:g})=>f.some(_=>_.type===g))??[];return{groups:f,structs:m}}var Ui=(s=>(s[s.VERTEX=1]="VERTEX",s[s.FRAGMENT=2]="FRAGMENT",s[s.COMPUTE=4]="COMPUTE",s))(Ui||{});function um({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]=[]),r.isUniform?e[r.group].push({binding:r.binding,visibility:Ui.VERTEX|Ui.FRAGMENT,buffer:{type:"uniform"}}):r.type==="sampler"?e[r.group].push({binding:r.binding,visibility:Ui.FRAGMENT,sampler:{type:"filtering"}}):r.type==="texture_2d"&&e[r.group].push({binding:r.binding,visibility:Ui.FRAGMENT,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}})}return e}function dm({groups:s}){const e=[];for(let t=0;t<s.length;t++){const r=s[t];e[r.group]||(e[r.group]={}),e[r.group][r.name]=r.binding}return e}function fm(s,e){const t=new Set,r=new Set,n=[...s.structs,...e.structs].filter(c=>t.has(c.name)?!1:(t.add(c.name),!0)),o=[...s.groups,...e.groups].filter(c=>{const l=`${c.name}-${c.binding}`;return r.has(l)?!1:(r.add(l),!0)});return{structs:n,groups:o}}const ki=Object.create(null);class It{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;const{fragment:t,vertex:r,layout:n,gpuLayout:o,name:c}=e;if(this.name=c,this.fragment=t,this.vertex=r,t.source===r.source){const l=tn(t.source);this.structsAndGroups=l}else{const l=tn(r.source),d=tn(t.source);this.structsAndGroups=fm(l,d)}this.layout=n??dm(this.structsAndGroups),this.gpuLayout=o??um(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,r=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=Mi(r,"program")}get attributeData(){return this._attributeData??(this._attributeData=hm(this.vertex)),this._attributeData}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,ki[this._cacheKey]=null}static from(e){const t=`${e.vertex.source}:${e.fragment.source}:${e.fragment.entryPoint}:${e.vertex.entryPoint}`;return ki[t]||(ki[t]=new It(e),ki[t]._cacheKey=t),ki[t]}}const yl=["f32","i32","vec2<f32>","vec3<f32>","vec4<f32>","mat2x2<f32>","mat3x3<f32>","mat4x4<f32>","mat3x2<f32>","mat4x2<f32>","mat2x3<f32>","mat4x3<f32>","mat2x4<f32>","mat3x4<f32>","vec2<i32>","vec3<i32>","vec4<i32>"],pm=yl.reduce((s,e)=>(s[e]=!0,s),{});function mm(s,e){switch(s){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 xl=class pd{constructor(e,t){this._touched=0,this.uid=ae("uniform"),this._resourceType="uniformGroup",this._resourceId=ae("resource"),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,t={...pd.defaultOptions,...t},this.uniformStructures=e;const r={};for(const n in e){const o=e[n];if(o.name=n,o.size=o.size??1,!pm[o.type]){const c=o.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(c){const[,l,d]=c;throw new Error(`Uniform type ${o.type} is not supported. Use type: '${l}', size: ${d} instead.`)}throw new Error(`Uniform type ${o.type} is not supported. Supported uniform types are: ${yl.join(", ")}`)}o.value??(o.value=mm(o.type,o.size)),r[n]=o.value}this.uniforms=r,this._dirtyId=1,this.ubo=t.ubo,this.isStatic=t.isStatic,this._signature=Mi(Object.keys(r).map(n=>`${n}-${e[n].type}`).join("-"),"uniform-group")}update(){this._dirtyId++}};xl.defaultOptions={ubo:!1,isStatic:!1};let Ue=xl;class _t{constructor(e){this.resources=Object.create(null),this._dirty=!0;let t=0;for(const r in e){const n=e[r];this.setResource(n,t++)}this._updateKey()}_updateKey(){if(!this._dirty)return;this._dirty=!1;const e=[];let t=0;for(const r in this.resources)e[t++]=this.resources[r]._resourceId;this._key=e.join("|")}setResource(e,t){const r=this.resources[t];e!==r&&(r&&e.off?.("change",this.onResourceChange,this),e.on?.("change",this.onResourceChange,this),this.resources[t]=e,this._dirty=!0)}getResource(e){return this.resources[e]}_touch(e){const t=this.resources;for(const r in t)t[r]._touched=e}destroy(){const e=this.resources;for(const t in e)e[t]?.off?.("change",this.onResourceChange,this);this.resources=null}onResourceChange(e){if(this._dirty=!0,e.destroyed){const t=this.resources;for(const r in t)t[r]===e&&(t[r]=null)}else this._updateKey()}}var tt=(s=>(s[s.WEBGL=1]="WEBGL",s[s.WEBGPU=2]="WEBGPU",s[s.BOTH=3]="BOTH",s))(tt||{});class qe extends Le{constructor(e){super(),this.uid=ae("shader"),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:r,groups:n,resources:o,compatibleRenderers:c,groupMap:l}=e;this.gpuProgram=t,this.glProgram=r,c===void 0&&(c=0,t&&(c|=tt.WEBGPU),r&&(c|=tt.WEBGL)),this.compatibleRenderers=c;const d={};if(!o&&!n&&(o={}),o&&n)throw new Error("[Shader] Cannot have both resources and groups");if(!t&&n&&!l)throw new Error("[Shader] No group map or WebGPU shader provided - consider using resources instead.");if(!t&&n&&l)for(const f in l)for(const m in l[f]){const g=l[f][m];d[g]={group:f,binding:m,name:g}}else if(t&&n&&!l){const f=t.structsAndGroups.groups;l={},f.forEach(m=>{l[m.group]=l[m.group]||{},l[m.group][m.binding]=m.name,d[m.name]=m})}else if(o){n={},l={},t&&t.structsAndGroups.groups.forEach(g=>{l[g.group]=l[g.group]||{},l[g.group][g.binding]=g.name,d[g.name]=g});let f=0;for(const m in o)d[m]||(n[99]||(n[99]=new _t,this._ownedBindGroups.push(n[99])),d[m]={group:99,binding:f,name:m},l[99]=l[99]||{},l[99][f]=m,f++);for(const m in o){const g=m;let _=o[m];!_.source&&!_._resourceType&&(_=new Ue(_));const y=d[g];y&&(n[y.group]||(n[y.group]=new _t,this._ownedBindGroups.push(n[y.group])),n[y.group].setResource(_,y.binding))}}this.groups=n,this._uniformBindMap=l,this.resources=this._buildResourceAccessor(n,d)}addResource(e,t,r){var n,o;(n=this._uniformBindMap)[t]||(n[t]={}),(o=this._uniformBindMap[t])[r]||(o[r]=e),this.groups[t]||(this.groups[t]=new _t,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){const r={};for(const n in t){const o=t[n];Object.defineProperty(r,o.name,{get(){return e[o.group].getResource(o.binding)},set(c){e[o.group].setResource(c,o.binding)}})}return r}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)}static from(e){const{gpu:t,gl:r,...n}=e;let o,c;return t&&(o=It.from(t)),r&&(c=vt.from(r)),new qe({gpuProgram:o,glProgram:c,...n})}}const gm={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},rn=0,sn=1,nn=2,on=3,an=4,ln=5,cn=class md{constructor(){this.data=0,this.blendMode="normal",this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<rn)}set blend(e){!!(this.data&1<<rn)!==e&&(this.data^=1<<rn)}get offsets(){return!!(this.data&1<<sn)}set offsets(e){!!(this.data&1<<sn)!==e&&(this.data^=1<<sn)}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<<nn)}set culling(e){!!(this.data&1<<nn)!==e&&(this.data^=1<<nn)}get depthTest(){return!!(this.data&1<<on)}set depthTest(e){!!(this.data&1<<on)!==e&&(this.data^=1<<on)}get depthMask(){return!!(this.data&1<<ln)}set depthMask(e){!!(this.data&1<<ln)!==e&&(this.data^=1<<ln)}get clockwiseFrontFace(){return!!(this.data&1<<an)}set clockwiseFrontFace(e){!!(this.data&1<<an)!==e&&(this.data^=1<<an)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!=="none",this._blendMode=e,this._blendModeId=gm[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 md;return e.depthTest=!1,e.blend=!0,e}};cn.default2d=cn.for2d();let it=cn;const bl=class Mo extends qe{constructor(e){e={...Mo.defaultOptions,...e},super(e),this.enabled=!0,this._state=it.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,r,n){e.applyFilter(this,t,r,n)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(e){const{gpu:t,gl:r,...n}=e;let o,c;return t&&(o=It.from(t)),r&&(c=vt.from(r)),new Mo({gpuProgram:o,glProgram:c,...n})}};bl.defaultOptions={blendMode:"normal",resolution:1,padding:0,antialias:"off",blendRequired:!1,clipToViewport:!0};let Dr=bl;const hn=[];L.handleByNamedList(C.Environment,hn);async function vm(s){if(!s)for(let e=0;e<hn.length;e++){const t=hn[e];if(t.value.test()){await t.value.load();return}}}let Bi;function Tl(){if(typeof Bi=="boolean")return Bi;try{Bi=new Function("param1","param2","param3","return param1[param2] === param3;")({a:"b"},"a","b")===!0}catch{Bi=!1}return Bi}function wl(s,e,t=2){const r=e&&e.length,n=r?e[0]*t:s.length;let o=Sl(s,0,n,t,!0);const c=[];if(!o||o.next===o.prev)return c;let l,d,f;if(r&&(o=Tm(s,e,o,t)),s.length>80*t){l=s[0],d=s[1];let m=l,g=d;for(let _=t;_<n;_+=t){const y=s[_],a=s[_+1];y<l&&(l=y),a<d&&(d=a),y>m&&(m=y),a>g&&(g=a)}f=Math.max(m-l,g-d),f=f!==0?32767/f:0}return Di(o,c,t,l,d,f,0),c}function Sl(s,e,t,r,n){let o;if(n===Um(s,e,t,r)>0)for(let c=e;c<t;c+=r)o=Il(c/r|0,s[c],s[c+1],o);else for(let c=t-r;c>=e;c-=r)o=Il(c/r|0,s[c],s[c+1],o);return o&&si(o,o.next)&&(Li(o),o=o.next),o}function Lt(s,e){if(!s)return s;e||(e=s);let t=s,r;do if(r=!1,!t.steiner&&(si(t,t.next)||ue(t.prev,t,t.next)===0)){if(Li(t),t=e=t.prev,t===t.next)break;r=!0}else t=t.next;while(r||t!==e);return e}function Di(s,e,t,r,n,o,c){if(!s)return;!c&&o&&Em(s,r,n,o);let l=s;for(;s.prev!==s.next;){const d=s.prev,f=s.next;if(o?ym(s,r,n,o):_m(s)){e.push(d.i,s.i,f.i),Li(s),s=f.next,l=f.next;continue}if(s=f,s===l){c?c===1?(s=xm(Lt(s),e),Di(s,e,t,r,n,o,2)):c===2&&bm(s,e,t,r,n,o):Di(Lt(s),e,t,r,n,o,1);break}}}function _m(s){const e=s.prev,t=s,r=s.next;if(ue(e,t,r)>=0)return!1;const n=e.x,o=t.x,c=r.x,l=e.y,d=t.y,f=r.y,m=Math.min(n,o,c),g=Math.min(l,d,f),_=Math.max(n,o,c),y=Math.max(l,d,f);let a=r.next;for(;a!==e;){if(a.x>=m&&a.x<=_&&a.y>=g&&a.y<=y&&Oi(n,l,o,d,c,f,a.x,a.y)&&ue(a.prev,a,a.next)>=0)return!1;a=a.next}return!0}function ym(s,e,t,r){const n=s.prev,o=s,c=s.next;if(ue(n,o,c)>=0)return!1;const l=n.x,d=o.x,f=c.x,m=n.y,g=o.y,_=c.y,y=Math.min(l,d,f),a=Math.min(m,g,_),h=Math.max(l,d,f),u=Math.max(m,g,_),p=un(y,a,e,t,r),v=un(h,u,e,t,r);let x=s.prevZ,b=s.nextZ;for(;x&&x.z>=p&&b&&b.z<=v;){if(x.x>=y&&x.x<=h&&x.y>=a&&x.y<=u&&x!==n&&x!==c&&Oi(l,m,d,g,f,_,x.x,x.y)&&ue(x.prev,x,x.next)>=0||(x=x.prevZ,b.x>=y&&b.x<=h&&b.y>=a&&b.y<=u&&b!==n&&b!==c&&Oi(l,m,d,g,f,_,b.x,b.y)&&ue(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;x&&x.z>=p;){if(x.x>=y&&x.x<=h&&x.y>=a&&x.y<=u&&x!==n&&x!==c&&Oi(l,m,d,g,f,_,x.x,x.y)&&ue(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;b&&b.z<=v;){if(b.x>=y&&b.x<=h&&b.y>=a&&b.y<=u&&b!==n&&b!==c&&Oi(l,m,d,g,f,_,b.x,b.y)&&ue(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function xm(s,e){let t=s;do{const r=t.prev,n=t.next.next;!si(r,n)&&Al(r,t,t.next,n)&&Gi(r,n)&&Gi(n,r)&&(e.push(r.i,t.i,n.i),Li(t),Li(t.next),t=s=n),t=t.next}while(t!==s);return Lt(t)}function bm(s,e,t,r,n,o){let c=s;do{let l=c.next.next;for(;l!==c.prev;){if(c.i!==l.i&&Rm(c,l)){let d=El(c,l);c=Lt(c,c.next),d=Lt(d,d.next),Di(c,e,t,r,n,o,0),Di(d,e,t,r,n,o,0);return}l=l.next}c=c.next}while(c!==s)}function Tm(s,e,t,r){const n=[];for(let o=0,c=e.length;o<c;o++){const l=e[o]*r,d=o<c-1?e[o+1]*r:s.length,f=Sl(s,l,d,r,!1);f===f.next&&(f.steiner=!0),n.push(Pm(f))}n.sort(wm);for(let o=0;o<n.length;o++)t=Sm(n[o],t);return t}function wm(s,e){let t=s.x-e.x;if(t===0&&(t=s.y-e.y,t===0)){const r=(s.next.y-s.y)/(s.next.x-s.x),n=(e.next.y-e.y)/(e.next.x-e.x);t=r-n}return t}function Sm(s,e){const t=Cm(s,e);if(!t)return e;const r=El(t,s);return Lt(r,r.next),Lt(t,t.next)}function Cm(s,e){let t=e;const r=s.x,n=s.y;let o=-1/0,c;if(si(s,t))return t;do{if(si(s,t.next))return t.next;if(n<=t.y&&n>=t.next.y&&t.next.y!==t.y){const g=t.x+(n-t.y)*(t.next.x-t.x)/(t.next.y-t.y);if(g<=r&&g>o&&(o=g,c=t.x<t.next.x?t:t.next,g===r))return c}t=t.next}while(t!==e);if(!c)return null;const l=c,d=c.x,f=c.y;let m=1/0;t=c;do{if(r>=t.x&&t.x>=d&&r!==t.x&&Cl(n<f?r:o,n,d,f,n<f?o:r,n,t.x,t.y)){const g=Math.abs(n-t.y)/(r-t.x);Gi(t,s)&&(g<m||g===m&&(t.x>c.x||t.x===c.x&&Am(c,t)))&&(c=t,m=g)}t=t.next}while(t!==l);return c}function Am(s,e){return ue(s.prev,s,e.prev)<0&&ue(e.next,s,s.next)<0}function Em(s,e,t,r){let n=s;do n.z===0&&(n.z=un(n.x,n.y,e,t,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==s);n.prevZ.nextZ=null,n.prevZ=null,Im(n)}function Im(s){let e,t=1;do{let r=s,n;s=null;let o=null;for(e=0;r;){e++;let c=r,l=0;for(let f=0;f<t&&(l++,c=c.nextZ,!!c);f++);let d=t;for(;l>0||d>0&&c;)l!==0&&(d===0||!c||r.z<=c.z)?(n=r,r=r.nextZ,l--):(n=c,c=c.nextZ,d--),o?o.nextZ=n:s=n,n.prevZ=o,o=n;r=c}o.nextZ=null,t*=2}while(e>1);return s}function un(s,e,t,r,n){return s=(s-t)*n|0,e=(e-r)*n|0,s=(s|s<<8)&16711935,s=(s|s<<4)&252645135,s=(s|s<<2)&858993459,s=(s|s<<1)&1431655765,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,s|e<<1}function Pm(s){let e=s,t=s;do(e.x<t.x||e.x===t.x&&e.y<t.y)&&(t=e),e=e.next;while(e!==s);return t}function Cl(s,e,t,r,n,o,c,l){return(n-c)*(e-l)>=(s-c)*(o-l)&&(s-c)*(r-l)>=(t-c)*(e-l)&&(t-c)*(o-l)>=(n-c)*(r-l)}function Oi(s,e,t,r,n,o,c,l){return!(s===c&&e===l)&&Cl(s,e,t,r,n,o,c,l)}function Rm(s,e){return s.next.i!==e.i&&s.prev.i!==e.i&&!Mm(s,e)&&(Gi(s,e)&&Gi(e,s)&&Fm(s,e)&&(ue(s.prev,s,e.prev)||ue(s,e.prev,e))||si(s,e)&&ue(s.prev,s,s.next)>0&&ue(e.prev,e,e.next)>0)}function ue(s,e,t){return(e.y-s.y)*(t.x-e.x)-(e.x-s.x)*(t.y-e.y)}function si(s,e){return s.x===e.x&&s.y===e.y}function Al(s,e,t,r){const n=Gr(ue(s,e,t)),o=Gr(ue(s,e,r)),c=Gr(ue(t,r,s)),l=Gr(ue(t,r,e));return!!(n!==o&&c!==l||n===0&&Or(s,t,e)||o===0&&Or(s,r,e)||c===0&&Or(t,s,r)||l===0&&Or(t,e,r))}function Or(s,e,t){return e.x<=Math.max(s.x,t.x)&&e.x>=Math.min(s.x,t.x)&&e.y<=Math.max(s.y,t.y)&&e.y>=Math.min(s.y,t.y)}function Gr(s){return s>0?1:s<0?-1:0}function Mm(s,e){let t=s;do{if(t.i!==s.i&&t.next.i!==s.i&&t.i!==e.i&&t.next.i!==e.i&&Al(t,t.next,s,e))return!0;t=t.next}while(t!==s);return!1}function Gi(s,e){return ue(s.prev,s,s.next)<0?ue(s,e,s.next)>=0&&ue(s,s.prev,e)>=0:ue(s,e,s.prev)<0||ue(s,s.next,e)<0}function Fm(s,e){let t=s,r=!1;const n=(s.x+e.x)/2,o=(s.y+e.y)/2;do t.y>o!=t.next.y>o&&t.next.y!==t.y&&n<(t.next.x-t.x)*(o-t.y)/(t.next.y-t.y)+t.x&&(r=!r),t=t.next;while(t!==s);return r}function El(s,e){const t=dn(s.i,s.x,s.y),r=dn(e.i,e.x,e.y),n=s.next,o=e.prev;return s.next=e,e.prev=s,t.next=n,n.prev=t,r.next=t,t.prev=r,o.next=r,r.prev=o,r}function Il(s,e,t,r){const n=dn(s,e,t);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function Li(s){s.next.prev=s.prev,s.prev.next=s.next,s.prevZ&&(s.prevZ.nextZ=s.nextZ),s.nextZ&&(s.nextZ.prevZ=s.prevZ)}function dn(s,e,t){return{i:s,x:e,y:t,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function Um(s,e,t,r){let n=0;for(let o=e,c=t-r;o<t;o+=r)n+=(s[c]-s[o])*(s[o+1]+s[c+1]),c=o;return n}const km=wl.default||wl;var He=(s=>(s[s.NONE=0]="NONE",s[s.COLOR=16384]="COLOR",s[s.STENCIL=1024]="STENCIL",s[s.DEPTH=256]="DEPTH",s[s.COLOR_DEPTH=16640]="COLOR_DEPTH",s[s.COLOR_STENCIL=17408]="COLOR_STENCIL",s[s.DEPTH_STENCIL=1280]="DEPTH_STENCIL",s[s.ALL=17664]="ALL",s))(He||{});class Pl{constructor(e){this.items=[],this._name=e}emit(e,t,r,n,o,c,l,d){const{name:f,items:m}=this;for(let g=0,_=m.length;g<_;g++)m[g][f](e,t,r,n,o,c,l,d);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 Bm=["init","destroy","contextChange","resolutionChange","resetState","renderEnd","renderStart","render","update","postrender","prerender"],Rl=class gd extends Le{constructor(e){super(),this.uid=ae("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=[...Bm,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(e={}){const t=e.skipExtensionImports===!0?!0:e.manageImports===!1;await vm(t),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(const r in this._systemsHash)e={...this._systemsHash[r].constructor.defaultOptions,...e};e={...gd.defaultOptions,...e},this._roundPixels=e.roundPixels?1:0;for(let r=0;r<this.runners.init.items.length;r++)await this.runners.init.items[r].init(e);this._initOptions=e}render(e,t){let r=e;if(r instanceof se&&(r={container:r},t&&(H(j,"passing a second argument is deprecated, please use render options instead"),r.target=t.renderTexture)),r.target||(r.target=this.view.renderTarget),r.target===this.view.renderTarget&&(this._lastObjectRendered=r.container,r.clearColor??(r.clearColor=this.background.colorRgba),r.clear??(r.clear=this.background.clearBeforeRender)),r.clearColor){const n=Array.isArray(r.clearColor)&&r.clearColor.length===4;r.clearColor=n?r.clearColor:le.shared.setValue(r.clearColor).toArray()}r.transform||(r.container.updateLocalTransform(),r.transform=r.container.localTransform),r.container.visible&&(r.container.enableRenderGroup(),this.runners.prerender.emit(r),this.runners.renderStart.emit(r),this.runners.render.emit(r),this.runners.renderEnd.emit(r),this.runners.postrender.emit(r))}resize(e,t,r){const n=this.view.resolution;this.view.resize(e,t,r),this.emit("resize",this.view.screen.width,this.view.screen.height,this.view.resolution),r!==void 0&&r!==n&&this.runners.resolutionChange.emit(r)}clear(e={}){const t=this;e.target||(e.target=t.renderTarget.renderTarget),e.clearColor||(e.clearColor=this.background.colorRgba),e.clear??(e.clear=He.ALL);const{clear:r,clearColor:n,target:o}=e;le.shared.setValue(n??this.background.colorRgba),t.renderTarget.clear(o,r,le.shared.toArray())}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 Pl(t)})}_addSystems(e){let t;for(t in e){const r=e[t];this._addSystem(r.value,r.name)}}_addSystem(e,t){const r=new e(this);if(this[t])throw new Error(`Whoops! The name "${t}" is already in use`);this[t]=r,this._systemsHash[t]=r;for(const n in this.runners)this.runners[n].add(r);return this}_addPipes(e,t){const r=t.reduce((n,o)=>(n[o.name]=o.value,n),{});e.forEach(n=>{const o=n.value,c=n.name,l=r[c];this.renderPipes[c]=new o(this,l?new l:null),this.runners.destroy.add(this.renderPipes[c])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e=="object"&&e.releaseGlobalResources)&&ei.release(),Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash=null,this.renderPipes=null}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Tl())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()}};Rl.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};let Lr=Rl,Nr;function Dm(s){return Nr!==void 0||(Nr=(()=>{const e={stencil:!0,failIfMajorPerformanceCaveat:s??Lr.defaultOptions.failIfMajorPerformanceCaveat};try{if(!V.get().getWebGLRenderingContext())return!1;let r=V.get().createCanvas().getContext("webgl",e);const n=!!r?.getContextAttributes()?.stencil;if(r){const o=r.getExtension("WEBGL_lose_context");o&&o.loseContext()}return r=null,n}catch{return!1}})()),Nr}let zr;async function Om(s={}){return zr!==void 0||(zr=await(async()=>{const e=V.get().getNavigator().gpu;if(!e)return!1;try{return await(await e.requestAdapter(s)).requestDevice(),!0}catch{return!1}})()),zr}const Ml=["webgl","webgpu","canvas"];async function Gm(s){let e=[];s.preference?(e.push(s.preference),Ml.forEach(o=>{o!==s.preference&&e.push(o)})):e=Ml.slice();let t,r={};for(let o=0;o<e.length;o++){const c=e[o];if(c==="webgpu"&&await Om()){const{WebGPURenderer:l}=await Promise.resolve().then(()=>Ay);t=l,r={...s,...s.webgpu};break}else if(c==="webgl"&&Dm(s.failIfMajorPerformanceCaveat??Lr.defaultOptions.failIfMajorPerformanceCaveat)){const{WebGLRenderer:l}=await Promise.resolve().then(()=>ay);t=l,r={...s,...s.webgl};break}else if(c==="canvas")throw r={...s},new Error("CanvasRenderer is not yet implemented")}if(delete r.webgpu,delete r.webgl,!t)throw new Error("No available renderer for the current environment");const n=new t;return await n.init(r),n}const Hr="8.14.3";class Fl{static init(){globalThis.__PIXI_APP_INIT__?.(this,Hr)}static destroy(){}}Fl.extension=C.Application;class Ul{constructor(e){this._renderer=e}init(){globalThis.__PIXI_RENDERER_INIT__?.(this._renderer,Hr)}destroy(){this._renderer=null}}Ul.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"initHook",priority:-10};const kl=class Fo{constructor(...e){this.stage=new se,e[0]!==void 0&&H(j,"Application constructor options are deprecated, please use Application.init() instead.")}async init(e){e={...e},this.stage||(this.stage=new se),this.renderer=await Gm(e),Fo._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(j,"Application.view is deprecated, please use Application.canvas instead."),this.renderer.canvas}get screen(){return this.renderer.screen}destroy(e=!1,t=!1){const r=Fo._plugins.slice(0);r.reverse(),r.forEach(n=>{n.destroy.call(this)}),this.stage.destroy(t),this.stage=null,this.renderer.destroy(e),this.renderer=null}};kl._plugins=[];let fn=kl;L.handleByList(C.Application,fn._plugins),L.add(Fl);class Bl{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,r;if(this._resizeTo===globalThis.window)t=globalThis.innerWidth,r=globalThis.innerHeight;else{const{clientWidth:n,clientHeight:o}=this._resizeTo;t=n,r=o}this.renderer.resize(t,r),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}}Bl.extension=C.Application;class Dl{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,ti.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?Ne.shared:new Ne,e.autoStart&&this.start()}static destroy(){if(this._ticker){const e=this._ticker;this.ticker=null,e.destroy()}}}Dl.extension=C.Application;class Ol extends Le{constructor(){super(...arguments),this.chars=Object.create(null),this.lineHeight=0,this.fontFamily="",this.fontMetrics={fontSize:0,ascent:0,descent:0},this.baseLineOffset=0,this.distanceField={type:"none",range:0},this.pages=[],this.applyFillAsTint=!0,this.baseMeasurementFontSize=100,this.baseRenderedFontSize=100}get font(){return H(j,"BitmapFont.font is deprecated, please use BitmapFont.fontFamily instead."),this.fontFamily}get pageTextures(){return H(j,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}get size(){return H(j,"BitmapFont.size is deprecated, please use BitmapFont.fontMetrics.fontSize instead."),this.fontMetrics.fontSize}get distanceFieldRange(){return H(j,"BitmapFont.distanceFieldRange is deprecated, please use BitmapFont.distanceField.range instead."),this.distanceField.range}get distanceFieldType(){return H(j,"BitmapFont.distanceFieldType is deprecated, please use BitmapFont.distanceField.type instead."),this.distanceField.type}destroy(e=!1){this.emit("destroy",this),this.removeAllListeners();for(const t in this.chars)this.chars[t].texture?.destroy();this.chars=null,e&&(this.pages.forEach(t=>t.texture.destroy(!0)),this.pages=null)}}class Lm{constructor(e=0,t=0,r=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=e,this.resetTtl=r,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()){return e.map(t=>[t,this.get(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=[];let t=this.first;for(;t!==null;)e.push(t.key),t=t.next;return e}setWithEvicted(e,t,r=this.resetTtl){let n=null;if(this.has(e))this.set(e,t,!0,r);else{this.max>0&&this.size===this.max&&(n={...this.first},this.evict(!0));let o=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=o:this.last.next=o,this.last=o}return n}set(e,t,r=!1,n=this.resetTtl){let o=this.items[e];return r||o!==void 0?(o.value=t,r===!1&&n&&(o.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.moveToEnd(o)):(this.max>0&&this.size===this.max&&this.evict(!0),o=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=o:this.last.next=o,this.last=o),this}values(e=this.keys()){return e.map(t=>this.get(t))}}function Gl(s=1e3,e=0,t=!1){if(isNaN(s)||s<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 Lm(s,e,t)}const Nm=["serif","sans-serif","monospace","cursive","fantasy","system-ui"];function Wr(s){const e=typeof s.fontSize=="number"?`${s.fontSize}px`:s.fontSize;let t=s.fontFamily;Array.isArray(s.fontFamily)||(t=s.fontFamily.split(","));for(let r=t.length-1;r>=0;r--){let n=t[r].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&!Nm.includes(n)&&(n=`"${n}"`),t[r]=n}return`${s.fontStyle} ${s.fontVariant} ${s.fontWeight} ${e} ${t.join(",")}`}const pn={willReadFrequently:!0},rt=class D{static get experimentalLetterSpacingSupported(){let e=D._experimentalLetterSpacingSupported;if(e===void 0){const t=V.get().getCanvasRenderingContext2D().prototype;e=D._experimentalLetterSpacingSupported="letterSpacing"in t||"textLetterSpacing"in t}return e}constructor(e,t,r,n,o,c,l,d,f){this.text=e,this.style=t,this.width=r,this.height=n,this.lines=o,this.lineWidths=c,this.lineHeight=l,this.maxLineWidth=d,this.fontProperties=f}static measureText(e=" ",t,r=D._canvas,n=t.wordWrap){const o=`${e}-${t.styleKey}-wordWrap-${n}`;if(D._measurementCache.has(o))return D._measurementCache.get(o);const c=Wr(t),l=D.measureFont(c);l.fontSize===0&&(l.fontSize=t.fontSize,l.ascent=t.fontSize);const d=D.__context;d.font=c;const m=(n?D._wordWrap(e,t,r):e).split(/(?:\r\n|\r|\n)/),g=new Array(m.length);let _=0;for(let v=0;v<m.length;v++){const x=D._measureText(m[v],t.letterSpacing,d);g[v]=x,_=Math.max(_,x)}const y=t._stroke?.width||0;let a=_+y;t.dropShadow&&(a+=t.dropShadow.distance);const h=t.lineHeight||l.fontSize;let u=Math.max(h,l.fontSize+y)+(m.length-1)*(h+t.leading);t.dropShadow&&(u+=t.dropShadow.distance);const p=new D(e,t,a,u,m,g,h+t.leading,_,l);return D._measurementCache.set(o,p),p}static _measureText(e,t,r){let n=!1;D.experimentalLetterSpacingSupported&&(D.experimentalLetterSpacing?(r.letterSpacing=`${t}px`,r.textLetterSpacing=`${t}px`,n=!0):(r.letterSpacing="0px",r.textLetterSpacing="0px"));const o=r.measureText(e);let c=o.width;const l=-o.actualBoundingBoxLeft;let f=o.actualBoundingBoxRight-l;if(c>0)if(n)c-=t,f-=t;else{const m=(D.graphemeSegmenter(e).length-1)*t;c+=m,f+=m}return Math.max(c,f)}static _wordWrap(e,t,r=D._canvas){const n=r.getContext("2d",pn);let o=0,c="",l="";const d=Object.create(null),{letterSpacing:f,whiteSpace:m}=t,g=D._collapseSpaces(m),_=D._collapseNewlines(m);let y=!g;const a=t.wordWrapWidth+f,h=D._tokenize(e);for(let u=0;u<h.length;u++){let p=h[u];if(D._isNewline(p)){if(!_){l+=D._addLine(c),y=!g,c="",o=0;continue}p=" "}if(g){const x=D.isBreakingSpace(p),b=D.isBreakingSpace(c[c.length-1]);if(x&&b)continue}const v=D._getFromCache(p,f,d,n);if(v>a)if(c!==""&&(l+=D._addLine(c),c="",o=0),D.canBreakWords(p,t.breakWords)){const x=D.wordWrapSplit(p);for(let b=0;b<x.length;b++){let T=x[b],w=T,S=1;for(;x[b+S];){const A=x[b+S];if(!D.canBreakChars(w,A,p,b,t.breakWords))T+=A;else break;w=A,S++}b+=S-1;const E=D._getFromCache(T,f,d,n);E+o>a&&(l+=D._addLine(c),y=!1,c="",o=0),c+=T,o+=E}}else{c.length>0&&(l+=D._addLine(c),c="",o=0);const x=u===h.length-1;l+=D._addLine(p,!x),y=!1,c="",o=0}else v+o>a&&(y=!1,l+=D._addLine(c),c="",o=0),(c.length>0||!D.isBreakingSpace(p)||y)&&(c+=p,o+=v)}return l+=D._addLine(c,!1),l}static _addLine(e,t=!0){return e=D._trimRight(e),e=t?`${e}
|
|
99
99
|
`:e,e}static _getFromCache(e,t,r,n){let o=r[e];return typeof o!="number"&&(o=D._measureText(e,t,n)+t,r[e]=o),o}static _collapseSpaces(e){return e==="normal"||e==="pre-line"}static _collapseNewlines(e){return e==="normal"}static _trimRight(e){if(typeof e!="string")return"";for(let t=e.length-1;t>=0;t--){const r=e[t];if(!D.isBreakingSpace(r))break;e=e.slice(0,-1)}return e}static _isNewline(e){return typeof e!="string"?!1:D._newlines.includes(e.charCodeAt(0))}static isBreakingSpace(e,t){return typeof e!="string"?!1:D._breakingSpaces.includes(e.charCodeAt(0))}static _tokenize(e){const t=[];let r="";if(typeof e!="string")return t;for(let n=0;n<e.length;n++){const o=e[n],c=e[n+1];if(D.isBreakingSpace(o,c)||D._isNewline(o)){r!==""&&(t.push(r),r=""),o==="\r"&&c===`
|
|
100
100
|
`?(t.push(`\r
|
|
101
|
-
`),n++):t.push(o);continue}r+=o}return r!==""&&t.push(r),t}static canBreakWords(e,t){return t}static canBreakChars(e,t,r,n,o){return!0}static wordWrapSplit(e){return D.graphemeSegmenter(e)}static measureFont(e){if(D._fonts[e])return D._fonts[e];const t=D._context;t.font=e;const r=t.measureText(D.METRICS_STRING+D.BASELINE_SYMBOL),n={ascent:r.actualBoundingBoxAscent,descent:r.actualBoundingBoxDescent,fontSize:r.actualBoundingBoxAscent+r.actualBoundingBoxDescent};return D._fonts[e]=n,n}static clearMetrics(e=""){e?delete D._fonts[e]:D._fonts={}}static get _canvas(){if(!D.__canvas){let e;try{const t=new OffscreenCanvas(0,0);if(t.getContext("2d",pn)?.measureText)return D.__canvas=t,t;e=V.get().createCanvas()}catch{e=V.get().createCanvas()}e.width=e.height=10,D.__canvas=e}return D.__canvas}static get _context(){return D.__context||(D.__context=D._canvas.getContext("2d",pn)),D.__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 s=new Intl.Segmenter;return e=>{const t=s.segment(e),r=[];let n=0;for(const o of t)r[n++]=o.segment;return r}}return s=>[...s]})(),rt.experimentalLetterSpacing=!1,rt._fonts={},rt._newlines=[10,13],rt._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],rt._measurementCache=Gl(1e3);let He=rt;const Ll=[{offset:0,color:"white"},{offset:1,color:"black"}],mn=class Uo{constructor(...e){this.uid=ae("fillGradient"),this._tick=0,this.type="linear",this.colorStops=[];let t=zm(e);t={...t.type==="radial"?Uo.defaultRadialOptions:Uo.defaultLinearOptions,...fa(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(n=>{this.addColorStop(n.offset,n.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:r,y:n}=this.end,o=r-e,c=n-t;const l=o<0||c<0;if(this._wrapMode==="clamp-to-edge"){if(o<0){const u=e;e=r,r=u,o*=-1}if(c<0){const u=t;t=n,n=u,c*=-1}}const d=this.colorStops.length?this.colorStops:Ll,f=this._textureSize,{canvas:m,context:g}=zl(f,1),_=l?g.createLinearGradient(this._textureSize,0,0,0):g.createLinearGradient(0,0,this._textureSize,0);Nl(_,d),g.fillStyle=_,g.fillRect(0,0,f,1),this.texture=new F({source:new ct({resource:m,addressMode:this._wrapMode})});const y=Math.sqrt(o*o+c*c),a=Math.atan2(c,o),h=new B;h.scale(y/f,1),h.rotate(a),h.translate(e,t),this.textureSpace==="local"&&h.scale(f,f),this.transform=h}buildGradient(){this.texture||this._tick++,this.type==="linear"?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;const e=this.colorStops.length?this.colorStops:Ll,t=this._textureSize,{canvas:r,context:n}=zl(t,t),{x:o,y:c}=this.center,{x:l,y:d}=this.outerCenter,f=this.innerRadius,m=this.outerRadius,g=l-m,_=d-m,y=t/(m*2),a=(o-g)*y,h=(c-_)*y,u=n.createRadialGradient(a,h,f*y,(l-g)*y,(d-_)*y,m*y);Nl(u,e),n.fillStyle=e[e.length-1].color,n.fillRect(0,0,t,t),n.fillStyle=u,n.translate(a,h),n.rotate(this.rotation),n.scale(1,this.scale),n.translate(-a,-h),n.fillRect(0,0,t,t),this.texture=new F({source:new ct({resource:r,addressMode:this._wrapMode})});const p=new B;p.scale(1/y,1/y),p.translate(g,_),this.textureSpace==="local"&&p.scale(t,t),this.transform=p}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}`}};mn.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:"local",type:"linear",textureSize:256,wrapMode:"clamp-to-edge"},mn.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,textureSpace:"local",type:"radial",textureSize:256,wrapMode:"clamp-to-edge"};let Ke=mn;function Nl(s,e){for(let t=0;t<e.length;t++){const r=e[t];s.addColorStop(r.offset,r.color)}}function zl(s,e){const t=V.get().createCanvas(s,e),r=t.getContext("2d");return{canvas:t,context:r}}function zm(s){let e=s[0]??{};return(typeof e=="number"||s[1])&&(H("8.5.2","use options object instead"),e={type:"linear",start:{x:s[0],y:s[1]},end:{x:s[2],y:s[3]},textureSpace:s[4],textureSize:s[5]??Ke.defaultLinearOptions.textureSize}),e}const Hl={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 Vr{constructor(e,t){this.uid=ae("fillPattern"),this._tick=0,this.transform=new B,this.texture=e,this.transform.scale(1/e.frame.width,1/e.frame.height),t&&(e.source.style.addressModeU=Hl[t].addressModeU,e.source.style.addressModeV=Hl[t].addressModeV)}setTransform(e){const t=this.texture;this.transform.copyFrom(e),this.transform.invert(),this.transform.scale(1/t.frame.width,1/t.frame.height),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}}var gn,Wl;function Hm(){if(Wl)return gn;Wl=1,gn=t;var s={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},e=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function t(o){var c=[];return o.replace(e,function(l,d,f){var m=d.toLowerCase();for(f=n(f),m=="m"&&f.length>2&&(c.push([d].concat(f.splice(0,2))),m="l",d=d=="m"?"l":"L");;){if(f.length==s[m])return f.unshift(d),c.push(f);if(f.length<s[m])throw new Error("malformed path data");c.push([d].concat(f.splice(0,s[m])))}}),c}var r=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function n(o){var c=o.match(r);return c?c.map(Number):[]}return gn}var Wm=Hm();const Vm=St(Wm);function Ym(s,e){const t=Vm(s),r=[];let n=null,o=0,c=0;for(let l=0;l<t.length;l++){const d=t[l],f=d[0],m=d;switch(f){case"M":o=m[1],c=m[2],e.moveTo(o,c);break;case"m":o+=m[1],c+=m[2],e.moveTo(o,c);break;case"H":o=m[1],e.lineTo(o,c);break;case"h":o+=m[1],e.lineTo(o,c);break;case"V":c=m[1],e.lineTo(o,c);break;case"v":c+=m[1],e.lineTo(o,c);break;case"L":o=m[1],c=m[2],e.lineTo(o,c);break;case"l":o+=m[1],c+=m[2],e.lineTo(o,c);break;case"C":o=m[5],c=m[6],e.bezierCurveTo(m[1],m[2],m[3],m[4],o,c);break;case"c":e.bezierCurveTo(o+m[1],c+m[2],o+m[3],c+m[4],o+m[5],c+m[6]),o+=m[5],c+=m[6];break;case"S":o=m[3],c=m[4],e.bezierCurveToShort(m[1],m[2],o,c);break;case"s":e.bezierCurveToShort(o+m[1],c+m[2],o+m[3],c+m[4]),o+=m[3],c+=m[4];break;case"Q":o=m[3],c=m[4],e.quadraticCurveTo(m[1],m[2],o,c);break;case"q":e.quadraticCurveTo(o+m[1],c+m[2],o+m[3],c+m[4]),o+=m[3],c+=m[4];break;case"T":o=m[1],c=m[2],e.quadraticCurveToShort(o,c);break;case"t":o+=m[1],c+=m[2],e.quadraticCurveToShort(o,c);break;case"A":o=m[6],c=m[7],e.arcToSvg(m[1],m[2],m[3],m[4],m[5],o,c);break;case"a":o+=m[6],c+=m[7],e.arcToSvg(m[1],m[2],m[3],m[4],m[5],o,c);break;case"Z":case"z":e.closePath(),r.length>0&&(n=r.pop(),n?(o=n.startX,c=n.startY):(o=0,c=0)),n=null;break;default:G(`Unknown SVG path command: ${f}`)}f!=="Z"&&f!=="z"&&n===null&&(n={startX:o,startY:c},r.push(n))}return e}class Yr{constructor(e=0,t=0,r=0){this.type="circle",this.x=e,this.y=t,this.radius=r}clone(){return new Yr(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;const r=this.radius*this.radius;let n=this.x-e,o=this.y-t;return n*=n,o*=o,n+o<=r}strokeContains(e,t,r,n=.5){if(this.radius===0)return!1;const o=this.x-e,c=this.y-t,l=this.radius,d=(1-n)*r,f=Math.sqrt(o*o+c*c);return f<=l+d&&f>l-(r-d)}getBounds(e){return e||(e=new z),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 vn{constructor(e=0,t=0,r=0,n=0){this.type="ellipse",this.x=e,this.y=t,this.halfWidth=r,this.halfHeight=n}clone(){return new vn(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let r=(e-this.x)/this.halfWidth,n=(t-this.y)/this.halfHeight;return r*=r,n*=n,r+n<=1}strokeContains(e,t,r,n=.5){const{halfWidth:o,halfHeight:c}=this;if(o<=0||c<=0)return!1;const l=r*(1-n),d=r-l,f=o-d,m=c-d,g=o+l,_=c+l,y=e-this.x,a=t-this.y,h=y*y/(f*f)+a*a/(m*m),u=y*y/(g*g)+a*a/(_*_);return h>1&&u<=1}getBounds(e){return e||(e=new z),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 Xm(s,e,t,r,n,o){const c=s-t,l=e-r,d=n-t,f=o-r,m=c*d+l*f,g=d*d+f*f;let _=-1;g!==0&&(_=m/g);let y,a;_<0?(y=t,a=r):_>1?(y=n,a=o):(y=t+_*d,a=r+_*f);const h=s-y,u=e-a;return h*h+u*u}let $m,qm;class Ni{constructor(...e){this.type="polygon";let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!="number"){const r=[];for(let n=0,o=t.length;n<o;n++)r.push(t[n].x,t[n].y);t=r}this.points=t,this.closePath=!0}isClockwise(){let e=0;const t=this.points,r=t.length;for(let n=0;n<r;n+=2){const o=t[n],c=t[n+1],l=t[(n+2)%r],d=t[(n+3)%r];e+=(l-o)*(d+c)}return e<0}containsPolygon(e){const t=this.getBounds($m),r=e.getBounds(qm);if(!t.containsRect(r))return!1;const n=e.points;for(let o=0;o<n.length;o+=2){const c=n[o],l=n[o+1];if(!this.contains(c,l))return!1}return!0}clone(){const e=this.points.slice(),t=new Ni(e);return t.closePath=this.closePath,t}contains(e,t){let r=!1;const n=this.points.length/2;for(let o=0,c=n-1;o<n;c=o++){const l=this.points[o*2],d=this.points[o*2+1],f=this.points[c*2],m=this.points[c*2+1];d>t!=m>t&&e<(f-l)*((t-d)/(m-d))+l&&(r=!r)}return r}strokeContains(e,t,r,n=.5){const o=r*r,c=o*(1-n),l=o-c,{points:d}=this,f=d.length-(this.closePath?0:2);for(let m=0;m<f;m+=2){const g=d[m],_=d[m+1],y=d[(m+2)%d.length],a=d[(m+3)%d.length],h=Xm(e,t,g,_,y,a),u=Math.sign((y-g)*(t-_)-(a-_)*(e-g));if(h<=(u<0?l:c))return!0}return!1}getBounds(e){e||(e=new z);const t=this.points;let r=1/0,n=-1/0,o=1/0,c=-1/0;for(let l=0,d=t.length;l<d;l+=2){const f=t[l],m=t[l+1];r=f<r?f:r,n=f>n?f:n,o=m<o?m:o,c=m>c?m:c}return e.x=r,e.width=n-r,e.y=o,e.height=c-o,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 Xr=(s,e,t,r,n,o,c)=>{const l=s-t,d=e-r,f=Math.sqrt(l*l+d*d);return f>=n-o&&f<=n+c};class _n{constructor(e=0,t=0,r=0,n=0,o=20){this.type="roundedRectangle",this.x=e,this.y=t,this.width=r,this.height=n,this.radius=o}getBounds(e){return e||(e=new z),e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new _n(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){const r=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+r&&t<=this.y+this.height-r||e>=this.x+r&&e<=this.x+this.width-r)return!0;let n=e-(this.x+r),o=t-(this.y+r);const c=r*r;if(n*n+o*o<=c||(n=e-(this.x+this.width-r),n*n+o*o<=c)||(o=t-(this.y+this.height-r),n*n+o*o<=c)||(n=e-(this.x+r),n*n+o*o<=c))return!0}return!1}strokeContains(e,t,r,n=.5){const{x:o,y:c,width:l,height:d,radius:f}=this,m=r*(1-n),g=r-m,_=o+f,y=c+f,a=l-f*2,h=d-f*2,u=o+l,p=c+d;return(e>=o-m&&e<=o+g||e>=u-g&&e<=u+m)&&t>=y&&t<=y+h||(t>=c-m&&t<=c+g||t>=p-g&&t<=p+m)&&e>=_&&e<=_+a?!0:e<_&&t<y&&Xr(e,t,_,y,f,g,m)||e>u-f&&t<y&&Xr(e,t,u-f,y,f,g,m)||e>u-f&&t>p-f&&Xr(e,t,u-f,p-f,f,g,m)||e<_&&t>p-f&&Xr(e,t,_,p-f,f,g,m)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const Vl={};function yn(s,e,t){let r=2166136261;for(let n=0;n<e;n++)r^=s[n].uid,r=Math.imul(r,16777619),r>>>=0;return Vl[r]||Km(s,e,r,t)}function Km(s,e,t,r){const n={};let o=0;for(let l=0;l<r;l++){const d=l<e?s[l]:F.EMPTY.source;n[o++]=d.source,n[o++]=d.style}const c=new _t(n);return Vl[t]=c,c}class ni{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 xn(s,e){const t=s.byteLength/8|0,r=new Float64Array(s,0,t);new Float64Array(e,0,t).set(r);const o=s.byteLength-t*8;if(o>0){const c=new Uint8Array(s,t*8,o);new Uint8Array(e,t*8,o).set(c)}}const jm={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var pe=(s=>(s[s.DISABLED=0]="DISABLED",s[s.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",s[s.MASK_ACTIVE=2]="MASK_ACTIVE",s[s.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",s[s.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",s[s.NONE=5]="NONE",s))(pe||{});function zi(s,e){return e.alphaMode==="no-premultiply-alpha"&&jm[s]||s}const Zm=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
|
|
101
|
+
`),n++):t.push(o);continue}r+=o}return r!==""&&t.push(r),t}static canBreakWords(e,t){return t}static canBreakChars(e,t,r,n,o){return!0}static wordWrapSplit(e){return D.graphemeSegmenter(e)}static measureFont(e){if(D._fonts[e])return D._fonts[e];const t=D._context;t.font=e;const r=t.measureText(D.METRICS_STRING+D.BASELINE_SYMBOL),n={ascent:r.actualBoundingBoxAscent,descent:r.actualBoundingBoxDescent,fontSize:r.actualBoundingBoxAscent+r.actualBoundingBoxDescent};return D._fonts[e]=n,n}static clearMetrics(e=""){e?delete D._fonts[e]:D._fonts={}}static get _canvas(){if(!D.__canvas){let e;try{const t=new OffscreenCanvas(0,0);if(t.getContext("2d",pn)?.measureText)return D.__canvas=t,t;e=V.get().createCanvas()}catch{e=V.get().createCanvas()}e.width=e.height=10,D.__canvas=e}return D.__canvas}static get _context(){return D.__context||(D.__context=D._canvas.getContext("2d",pn)),D.__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 s=new Intl.Segmenter;return e=>{const t=s.segment(e),r=[];let n=0;for(const o of t)r[n++]=o.segment;return r}}return s=>[...s]})(),rt.experimentalLetterSpacing=!1,rt._fonts={},rt._newlines=[10,13],rt._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288],rt._measurementCache=Gl(1e3);let Be=rt;const Ll=[{offset:0,color:"white"},{offset:1,color:"black"}],mn=class Uo{constructor(...e){this.uid=ae("fillGradient"),this._tick=0,this.type="linear",this.colorStops=[];let t=zm(e);t={...t.type==="radial"?Uo.defaultRadialOptions:Uo.defaultLinearOptions,...fa(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(n=>{this.addColorStop(n.offset,n.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:r,y:n}=this.end,o=r-e,c=n-t;const l=o<0||c<0;if(this._wrapMode==="clamp-to-edge"){if(o<0){const u=e;e=r,r=u,o*=-1}if(c<0){const u=t;t=n,n=u,c*=-1}}const d=this.colorStops.length?this.colorStops:Ll,f=this._textureSize,{canvas:m,context:g}=zl(f,1),_=l?g.createLinearGradient(this._textureSize,0,0,0):g.createLinearGradient(0,0,this._textureSize,0);Nl(_,d),g.fillStyle=_,g.fillRect(0,0,f,1),this.texture=new F({source:new ct({resource:m,addressMode:this._wrapMode})});const y=Math.sqrt(o*o+c*c),a=Math.atan2(c,o),h=new B;h.scale(y/f,1),h.rotate(a),h.translate(e,t),this.textureSpace==="local"&&h.scale(f,f),this.transform=h}buildGradient(){this.texture||this._tick++,this.type==="linear"?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;const e=this.colorStops.length?this.colorStops:Ll,t=this._textureSize,{canvas:r,context:n}=zl(t,t),{x:o,y:c}=this.center,{x:l,y:d}=this.outerCenter,f=this.innerRadius,m=this.outerRadius,g=l-m,_=d-m,y=t/(m*2),a=(o-g)*y,h=(c-_)*y,u=n.createRadialGradient(a,h,f*y,(l-g)*y,(d-_)*y,m*y);Nl(u,e),n.fillStyle=e[e.length-1].color,n.fillRect(0,0,t,t),n.fillStyle=u,n.translate(a,h),n.rotate(this.rotation),n.scale(1,this.scale),n.translate(-a,-h),n.fillRect(0,0,t,t),this.texture=new F({source:new ct({resource:r,addressMode:this._wrapMode})});const p=new B;p.scale(1/y,1/y),p.translate(g,_),this.textureSpace==="local"&&p.scale(t,t),this.transform=p}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}`}};mn.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:"local",type:"linear",textureSize:256,wrapMode:"clamp-to-edge"},mn.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,textureSpace:"local",type:"radial",textureSize:256,wrapMode:"clamp-to-edge"};let Ke=mn;function Nl(s,e){for(let t=0;t<e.length;t++){const r=e[t];s.addColorStop(r.offset,r.color)}}function zl(s,e){const t=V.get().createCanvas(s,e),r=t.getContext("2d");return{canvas:t,context:r}}function zm(s){let e=s[0]??{};return(typeof e=="number"||s[1])&&(H("8.5.2","use options object instead"),e={type:"linear",start:{x:s[0],y:s[1]},end:{x:s[2],y:s[3]},textureSpace:s[4],textureSize:s[5]??Ke.defaultLinearOptions.textureSize}),e}const Hl={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 Vr{constructor(e,t){this.uid=ae("fillPattern"),this._tick=0,this.transform=new B,this.texture=e,this.transform.scale(1/e.frame.width,1/e.frame.height),t&&(e.source.style.addressModeU=Hl[t].addressModeU,e.source.style.addressModeV=Hl[t].addressModeV)}setTransform(e){const t=this.texture;this.transform.copyFrom(e),this.transform.invert(),this.transform.scale(1/t.frame.width,1/t.frame.height),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}}var gn,Wl;function Hm(){if(Wl)return gn;Wl=1,gn=t;var s={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},e=/([astvzqmhlc])([^astvzqmhlc]*)/ig;function t(o){var c=[];return o.replace(e,function(l,d,f){var m=d.toLowerCase();for(f=n(f),m=="m"&&f.length>2&&(c.push([d].concat(f.splice(0,2))),m="l",d=d=="m"?"l":"L");;){if(f.length==s[m])return f.unshift(d),c.push(f);if(f.length<s[m])throw new Error("malformed path data");c.push([d].concat(f.splice(0,s[m])))}}),c}var r=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig;function n(o){var c=o.match(r);return c?c.map(Number):[]}return gn}var Wm=Hm();const Vm=St(Wm);function Ym(s,e){const t=Vm(s),r=[];let n=null,o=0,c=0;for(let l=0;l<t.length;l++){const d=t[l],f=d[0],m=d;switch(f){case"M":o=m[1],c=m[2],e.moveTo(o,c);break;case"m":o+=m[1],c+=m[2],e.moveTo(o,c);break;case"H":o=m[1],e.lineTo(o,c);break;case"h":o+=m[1],e.lineTo(o,c);break;case"V":c=m[1],e.lineTo(o,c);break;case"v":c+=m[1],e.lineTo(o,c);break;case"L":o=m[1],c=m[2],e.lineTo(o,c);break;case"l":o+=m[1],c+=m[2],e.lineTo(o,c);break;case"C":o=m[5],c=m[6],e.bezierCurveTo(m[1],m[2],m[3],m[4],o,c);break;case"c":e.bezierCurveTo(o+m[1],c+m[2],o+m[3],c+m[4],o+m[5],c+m[6]),o+=m[5],c+=m[6];break;case"S":o=m[3],c=m[4],e.bezierCurveToShort(m[1],m[2],o,c);break;case"s":e.bezierCurveToShort(o+m[1],c+m[2],o+m[3],c+m[4]),o+=m[3],c+=m[4];break;case"Q":o=m[3],c=m[4],e.quadraticCurveTo(m[1],m[2],o,c);break;case"q":e.quadraticCurveTo(o+m[1],c+m[2],o+m[3],c+m[4]),o+=m[3],c+=m[4];break;case"T":o=m[1],c=m[2],e.quadraticCurveToShort(o,c);break;case"t":o+=m[1],c+=m[2],e.quadraticCurveToShort(o,c);break;case"A":o=m[6],c=m[7],e.arcToSvg(m[1],m[2],m[3],m[4],m[5],o,c);break;case"a":o+=m[6],c+=m[7],e.arcToSvg(m[1],m[2],m[3],m[4],m[5],o,c);break;case"Z":case"z":e.closePath(),r.length>0&&(n=r.pop(),n?(o=n.startX,c=n.startY):(o=0,c=0)),n=null;break;default:G(`Unknown SVG path command: ${f}`)}f!=="Z"&&f!=="z"&&n===null&&(n={startX:o,startY:c},r.push(n))}return e}class Yr{constructor(e=0,t=0,r=0){this.type="circle",this.x=e,this.y=t,this.radius=r}clone(){return new Yr(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;const r=this.radius*this.radius;let n=this.x-e,o=this.y-t;return n*=n,o*=o,n+o<=r}strokeContains(e,t,r,n=.5){if(this.radius===0)return!1;const o=this.x-e,c=this.y-t,l=this.radius,d=(1-n)*r,f=Math.sqrt(o*o+c*c);return f<=l+d&&f>l-(r-d)}getBounds(e){return e||(e=new z),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 vn{constructor(e=0,t=0,r=0,n=0){this.type="ellipse",this.x=e,this.y=t,this.halfWidth=r,this.halfHeight=n}clone(){return new vn(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let r=(e-this.x)/this.halfWidth,n=(t-this.y)/this.halfHeight;return r*=r,n*=n,r+n<=1}strokeContains(e,t,r,n=.5){const{halfWidth:o,halfHeight:c}=this;if(o<=0||c<=0)return!1;const l=r*(1-n),d=r-l,f=o-d,m=c-d,g=o+l,_=c+l,y=e-this.x,a=t-this.y,h=y*y/(f*f)+a*a/(m*m),u=y*y/(g*g)+a*a/(_*_);return h>1&&u<=1}getBounds(e){return e||(e=new z),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 Xm(s,e,t,r,n,o){const c=s-t,l=e-r,d=n-t,f=o-r,m=c*d+l*f,g=d*d+f*f;let _=-1;g!==0&&(_=m/g);let y,a;_<0?(y=t,a=r):_>1?(y=n,a=o):(y=t+_*d,a=r+_*f);const h=s-y,u=e-a;return h*h+u*u}let $m,qm;class Ni{constructor(...e){this.type="polygon";let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!="number"){const r=[];for(let n=0,o=t.length;n<o;n++)r.push(t[n].x,t[n].y);t=r}this.points=t,this.closePath=!0}isClockwise(){let e=0;const t=this.points,r=t.length;for(let n=0;n<r;n+=2){const o=t[n],c=t[n+1],l=t[(n+2)%r],d=t[(n+3)%r];e+=(l-o)*(d+c)}return e<0}containsPolygon(e){const t=this.getBounds($m),r=e.getBounds(qm);if(!t.containsRect(r))return!1;const n=e.points;for(let o=0;o<n.length;o+=2){const c=n[o],l=n[o+1];if(!this.contains(c,l))return!1}return!0}clone(){const e=this.points.slice(),t=new Ni(e);return t.closePath=this.closePath,t}contains(e,t){let r=!1;const n=this.points.length/2;for(let o=0,c=n-1;o<n;c=o++){const l=this.points[o*2],d=this.points[o*2+1],f=this.points[c*2],m=this.points[c*2+1];d>t!=m>t&&e<(f-l)*((t-d)/(m-d))+l&&(r=!r)}return r}strokeContains(e,t,r,n=.5){const o=r*r,c=o*(1-n),l=o-c,{points:d}=this,f=d.length-(this.closePath?0:2);for(let m=0;m<f;m+=2){const g=d[m],_=d[m+1],y=d[(m+2)%d.length],a=d[(m+3)%d.length],h=Xm(e,t,g,_,y,a),u=Math.sign((y-g)*(t-_)-(a-_)*(e-g));if(h<=(u<0?l:c))return!0}return!1}getBounds(e){e||(e=new z);const t=this.points;let r=1/0,n=-1/0,o=1/0,c=-1/0;for(let l=0,d=t.length;l<d;l+=2){const f=t[l],m=t[l+1];r=f<r?f:r,n=f>n?f:n,o=m<o?m:o,c=m>c?m:c}return e.x=r,e.width=n-r,e.y=o,e.height=c-o,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 Xr=(s,e,t,r,n,o,c)=>{const l=s-t,d=e-r,f=Math.sqrt(l*l+d*d);return f>=n-o&&f<=n+c};class _n{constructor(e=0,t=0,r=0,n=0,o=20){this.type="roundedRectangle",this.x=e,this.y=t,this.width=r,this.height=n,this.radius=o}getBounds(e){return e||(e=new z),e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new _n(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){const r=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+r&&t<=this.y+this.height-r||e>=this.x+r&&e<=this.x+this.width-r)return!0;let n=e-(this.x+r),o=t-(this.y+r);const c=r*r;if(n*n+o*o<=c||(n=e-(this.x+this.width-r),n*n+o*o<=c)||(o=t-(this.y+this.height-r),n*n+o*o<=c)||(n=e-(this.x+r),n*n+o*o<=c))return!0}return!1}strokeContains(e,t,r,n=.5){const{x:o,y:c,width:l,height:d,radius:f}=this,m=r*(1-n),g=r-m,_=o+f,y=c+f,a=l-f*2,h=d-f*2,u=o+l,p=c+d;return(e>=o-m&&e<=o+g||e>=u-g&&e<=u+m)&&t>=y&&t<=y+h||(t>=c-m&&t<=c+g||t>=p-g&&t<=p+m)&&e>=_&&e<=_+a?!0:e<_&&t<y&&Xr(e,t,_,y,f,g,m)||e>u-f&&t<y&&Xr(e,t,u-f,y,f,g,m)||e>u-f&&t>p-f&&Xr(e,t,u-f,p-f,f,g,m)||e<_&&t>p-f&&Xr(e,t,_,p-f,f,g,m)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}}const Vl={};function yn(s,e,t){let r=2166136261;for(let n=0;n<e;n++)r^=s[n].uid,r=Math.imul(r,16777619),r>>>=0;return Vl[r]||Km(s,e,r,t)}function Km(s,e,t,r){const n={};let o=0;for(let l=0;l<r;l++){const d=l<e?s[l]:F.EMPTY.source;n[o++]=d.source,n[o++]=d.style}const c=new _t(n);return Vl[t]=c,c}class ni{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 xn(s,e){const t=s.byteLength/8|0,r=new Float64Array(s,0,t);new Float64Array(e,0,t).set(r);const o=s.byteLength-t*8;if(o>0){const c=new Uint8Array(s,t*8,o);new Uint8Array(e,t*8,o).set(c)}}const jm={normal:"normal-npm",add:"add-npm",screen:"screen-npm"};var pe=(s=>(s[s.DISABLED=0]="DISABLED",s[s.RENDERING_MASK_ADD=1]="RENDERING_MASK_ADD",s[s.MASK_ACTIVE=2]="MASK_ACTIVE",s[s.INVERSE_MASK_ACTIVE=3]="INVERSE_MASK_ACTIVE",s[s.RENDERING_MASK_REMOVE=4]="RENDERING_MASK_REMOVE",s[s.NONE=5]="NONE",s))(pe||{});function zi(s,e){return e.alphaMode==="no-premultiply-alpha"&&jm[s]||s}const Zm=["precision mediump float;","void main(void){","float test = 0.1;","%forloop%","gl_FragColor = vec4(0.0);","}"].join(`
|
|
102
102
|
`);function Jm(s){let e="";for(let t=0;t<s;++t)t>0&&(e+=`
|
|
103
|
-
else `),t<s-1&&(e+=`if(test == ${t}.0){}`);return e}function Yl(s,e){if(s===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const t=e.createShader(e.FRAGMENT_SHADER);try{for(;;){const r=Zm.replace(/%forloop%/gi,Jm(s));if(e.shaderSource(t,r),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))s=s/2|0;else break}}finally{e.deleteShader(t)}return s}let oi=null;function Qm(){if(oi)return oi;const s=gl();return oi=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),oi=Yl(oi,s),s.getExtension("WEBGL_lose_context")?.loseContext(),oi}class eg{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 tg{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new eg,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null}}const Hi=[];let $r=0;ei.register({clear:()=>{if(Hi.length>0)for(const s of Hi)s&&s.destroy();Hi.length=0,$r=0}});function Xl(){return $r>0?Hi[--$r]:new tg}function $l(s){Hi[$r++]=s}let Wi=0;const ql=class vd{constructor(e){this.uid=ae("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],e={...vd.defaultOptions,...e},e.maxTextures||(H("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),e.maxTextures=Qm());const{maxTextures:t,attributesInitialSize:r,indicesInitialSize:n}=e;this.attributeBuffer=new ni(r*4),this.indexBuffer=new Uint16Array(n),this.maxTextures=t}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)$l(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 r=e._batch.textures.ids[t._source.uid];return!r&&r!==0?!1:(e._textureId=r,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 r=Xl(),n=r.textures;n.clear();const o=t[this.elementStart];let c=zi(o.blendMode,o.texture._source),l=o.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);const d=this.attributeBuffer.float32View,f=this.attributeBuffer.uint32View,m=this.indexBuffer;let g=this._batchIndexSize,_=this._batchIndexStart,y="startBatch";const a=this.maxTextures;for(let h=this.elementStart;h<this.elementSize;++h){const u=t[h];t[h]=null;const v=u.texture._source,x=zi(u.blendMode,v),b=c!==x||l!==u.topology;if(v._batchTick===Wi&&!b){u._textureId=v._textureBindLocation,g+=u.indexSize,u.packAsQuad?(this.packQuadAttributes(u,d,f,u._attributeStart,u._textureId),this.packQuadIndex(m,u._indexStart,u._attributeStart/this.vertexSize)):(this.packAttributes(u,d,f,u._attributeStart,u._textureId),this.packIndex(u,m,u._indexStart,u._attributeStart/this.vertexSize)),u._batch=r;continue}v._batchTick=Wi,(n.count>=a||b)&&(this._finishBatch(r,_,g-_,n,c,l,e,y),y="renderBatch",_=g,c=x,l=u.topology,r=Xl(),n=r.textures,n.clear(),++Wi),u._textureId=v._textureBindLocation=n.count,n.ids[v.uid]=n.count,n.textures[n.count++]=v,u._batch=r,g+=u.indexSize,u.packAsQuad?(this.packQuadAttributes(u,d,f,u._attributeStart,u._textureId),this.packQuadIndex(m,u._indexStart,u._attributeStart/this.vertexSize)):(this.packAttributes(u,d,f,u._attributeStart,u._textureId),this.packIndex(u,m,u._indexStart,u._attributeStart/this.vertexSize))}n.count>0&&(this._finishBatch(r,_,g-_,n,c,l,e,y),_=g,++Wi),this.elementStart=this.elementSize,this._batchIndexStart=_,this._batchIndexSize=g}_finishBatch(e,t,r,n,o,c,l,d){e.gpuBindGroup=null,e.bindGroup=null,e.action=d,e.batcher=this,e.textures=n,e.blendMode=o,e.topology=c,e.start=t,e.size=r,++Wi,this.batches[this.batchIndex++]=e,l.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),r=new ni(t);xn(this.attributeBuffer.rawBinaryData,r.rawBinaryData),this.attributeBuffer=r}_resizeIndexBuffer(e){const t=this.indexBuffer;let r=Math.max(e,t.length*1.5);r+=r%2;const n=r>65535?new Uint32Array(r):new Uint16Array(r);if(n.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let o=0;o<t.length;o++)n[o]=t[o];else xn(t.buffer,n.buffer);this.indexBuffer=n}packQuadIndex(e,t,r){e[t]=r+0,e[t+1]=r+1,e[t+2]=r+2,e[t+3]=r+0,e[t+4]=r+2,e[t+5]=r+3}packIndex(e,t,r,n){const o=e.indices,c=e.indexSize,l=e.indexOffset,d=e.attributeOffset;for(let f=0;f<c;f++)t[r++]=n+o[f+l]-d}destroy(e={}){if(this.batches!==null){for(let t=0;t<this.batches.length;t++)$l(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}}};ql.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let ig=ql;var $=(s=>(s[s.MAP_READ=1]="MAP_READ",s[s.MAP_WRITE=2]="MAP_WRITE",s[s.COPY_SRC=4]="COPY_SRC",s[s.COPY_DST=8]="COPY_DST",s[s.INDEX=16]="INDEX",s[s.VERTEX=32]="VERTEX",s[s.UNIFORM=64]="UNIFORM",s[s.STORAGE=128]="STORAGE",s[s.INDIRECT=256]="INDIRECT",s[s.QUERY_RESOLVE=512]="QUERY_RESOLVE",s[s.STATIC=1024]="STATIC",s))($||{});class We extends Ge{constructor(e){let{data:t,size:r}=e;const{usage:n,label:o,shrinkToFit:c}=e;super(),this.uid=ae("buffer"),this._resourceType="buffer",this._resourceId=ae("resource"),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,r??(r=t?.byteLength);const l=!!t;this.descriptor={size:r,usage:n,mappedAtCreation:l,label:o},this.shrinkToFit=c??!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&$.STATIC)}set static(e){e?this.descriptor.usage|=$.STATIC:this.descriptor.usage&=~$.STATIC}setDataWithSize(e,t,r){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._data===e){r&&this.emit("update",this);return}const n=this._data;if(this._data=e,this._dataInt32=null,!n||n.length!==e.length){!this.shrinkToFit&&n&&e.byteLength<n.byteLength?r&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=ae("resource"),this.emit("change",this));return}r&&this.emit("update",this)}update(e){this._updateSize=e??this._updateSize,this._updateID++,this.emit("update",this)}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Kl(s,e){if(!(s instanceof We)){let t=e?$.INDEX:$.VERTEX;s instanceof Array&&(e?(s=new Uint32Array(s),t=$.INDEX|$.COPY_DST):(s=new Float32Array(s),t=$.VERTEX|$.COPY_DST)),s=new We({data:s,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return s}function rg(s,e,t){const r=s.getAttribute(e);if(!r)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const n=r.buffer.data;let o=1/0,c=1/0,l=-1/0,d=-1/0;const f=n.BYTES_PER_ELEMENT,m=(r.offset||0)/f,g=(r.stride||8)/f;for(let _=m;_<n.length;_+=g){const y=n[_],a=n[_+1];y>l&&(l=y),a>d&&(d=a),y<o&&(o=y),a<c&&(c=a)}return t.minX=o,t.minY=c,t.maxX=l,t.maxY=d,t}function sg(s){return(s instanceof We||Array.isArray(s)||s.BYTES_PER_ELEMENT)&&(s={buffer:s}),s.buffer=Kl(s.buffer,!1),s}class Vi extends Ge{constructor(e={}){super(),this.uid=ae("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new Se,this._boundsDirty=!0;const{attributes:t,indexBuffer:r,topology:n}=e;if(this.buffers=[],this.attributes={},t)for(const o in t)this.addAttribute(o,t[o]);this.instanceCount=e.instanceCount??1,r&&this.addIndex(r),this.topology=n||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}getSize(){for(const e in this.attributes){const t=this.attributes[e];return t.buffer.data.length/(t.stride/4||t.size)}return 0}addAttribute(e,t){const r=sg(t);this.buffers.indexOf(r.buffer)===-1&&(this.buffers.push(r.buffer),r.buffer.on("update",this.onBufferUpdate,this),r.buffer.on("change",this.onBufferUpdate,this)),this.attributes[e]=r}addIndex(e){this.indexBuffer=Kl(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,rg(this,"aPosition",this._bounds)):this._bounds}destroy(e=!1){this.emit("destroy",this),this.removeAllListeners(),e&&this.buffers.forEach(t=>t.destroy()),this.indexBuffer?.destroy(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const ng=new Float32Array(1),og=new Uint32Array(1);class ag extends Vi{constructor(){const t=new We({data:ng,label:"attribute-batch-buffer",usage:$.VERTEX|$.COPY_DST,shrinkToFit:!1}),r=new We({data:og,label:"index-batch-buffer",usage:$.INDEX|$.COPY_DST,shrinkToFit:!1}),n=24;super({attributes:{aPosition:{buffer:t,format:"float32x2",stride:n,offset:0},aUV:{buffer:t,format:"float32x2",stride:n,offset:8},aColor:{buffer:t,format:"unorm8x4",stride:n,offset:16},aTextureIdAndRound:{buffer:t,format:"uint16x2",stride:n,offset:20}},indexBuffer:r})}}function jl(s,e,t){if(s)for(const r in s){const n=r.toLocaleLowerCase(),o=e[n];if(o){let c=s[r];r==="header"&&(c=c.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),t&&o.push(`//----${t}----//`),o.push(c)}else G(`${r} placement hook does not exist in shader`)}}const lg=/\{\{(.*?)\}\}/g;function Zl(s){const e={};return(s.match(lg)?.map(r=>r.replace(/[{()}]/g,""))??[]).forEach(r=>{e[r]=[]}),e}function Jl(s,e){let t;const r=/@in\s+([^;]+);/g;for(;(t=r.exec(s))!==null;)e.push(t[1])}function Ql(s,e,t=!1){const r=[];Jl(e,r),s.forEach(l=>{l.header&&Jl(l.header,r)});const n=r;t&&n.sort();const o=n.map((l,d)=>` @location(${d}) ${l},`).join(`
|
|
103
|
+
else `),t<s-1&&(e+=`if(test == ${t}.0){}`);return e}function Yl(s,e){if(s===0)throw new Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");const t=e.createShader(e.FRAGMENT_SHADER);try{for(;;){const r=Zm.replace(/%forloop%/gi,Jm(s));if(e.shaderSource(t,r),e.compileShader(t),!e.getShaderParameter(t,e.COMPILE_STATUS))s=s/2|0;else break}}finally{e.deleteShader(t)}return s}let oi=null;function Qm(){if(oi)return oi;const s=gl();return oi=s.getParameter(s.MAX_TEXTURE_IMAGE_UNITS),oi=Yl(oi,s),s.getExtension("WEBGL_lose_context")?.loseContext(),oi}class eg{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 tg{constructor(){this.renderPipeId="batch",this.action="startBatch",this.start=0,this.size=0,this.textures=new eg,this.blendMode="normal",this.topology="triangle-strip",this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null}}const Hi=[];let $r=0;ei.register({clear:()=>{if(Hi.length>0)for(const s of Hi)s&&s.destroy();Hi.length=0,$r=0}});function Xl(){return $r>0?Hi[--$r]:new tg}function $l(s){Hi[$r++]=s}let Wi=0;const ql=class vd{constructor(e){this.uid=ae("batcher"),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],e={...vd.defaultOptions,...e},e.maxTextures||(H("v8.8.0","maxTextures is a required option for Batcher now, please pass it in the options"),e.maxTextures=Qm());const{maxTextures:t,attributesInitialSize:r,indicesInitialSize:n}=e;this.attributeBuffer=new ni(r*4),this.indexBuffer=new Uint16Array(n),this.maxTextures=t}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)$l(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 r=e._batch.textures.ids[t._source.uid];return!r&&r!==0?!1:(e._textureId=r,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 r=Xl(),n=r.textures;n.clear();const o=t[this.elementStart];let c=zi(o.blendMode,o.texture._source),l=o.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);const d=this.attributeBuffer.float32View,f=this.attributeBuffer.uint32View,m=this.indexBuffer;let g=this._batchIndexSize,_=this._batchIndexStart,y="startBatch";const a=this.maxTextures;for(let h=this.elementStart;h<this.elementSize;++h){const u=t[h];t[h]=null;const v=u.texture._source,x=zi(u.blendMode,v),b=c!==x||l!==u.topology;if(v._batchTick===Wi&&!b){u._textureId=v._textureBindLocation,g+=u.indexSize,u.packAsQuad?(this.packQuadAttributes(u,d,f,u._attributeStart,u._textureId),this.packQuadIndex(m,u._indexStart,u._attributeStart/this.vertexSize)):(this.packAttributes(u,d,f,u._attributeStart,u._textureId),this.packIndex(u,m,u._indexStart,u._attributeStart/this.vertexSize)),u._batch=r;continue}v._batchTick=Wi,(n.count>=a||b)&&(this._finishBatch(r,_,g-_,n,c,l,e,y),y="renderBatch",_=g,c=x,l=u.topology,r=Xl(),n=r.textures,n.clear(),++Wi),u._textureId=v._textureBindLocation=n.count,n.ids[v.uid]=n.count,n.textures[n.count++]=v,u._batch=r,g+=u.indexSize,u.packAsQuad?(this.packQuadAttributes(u,d,f,u._attributeStart,u._textureId),this.packQuadIndex(m,u._indexStart,u._attributeStart/this.vertexSize)):(this.packAttributes(u,d,f,u._attributeStart,u._textureId),this.packIndex(u,m,u._indexStart,u._attributeStart/this.vertexSize))}n.count>0&&(this._finishBatch(r,_,g-_,n,c,l,e,y),_=g,++Wi),this.elementStart=this.elementSize,this._batchIndexStart=_,this._batchIndexSize=g}_finishBatch(e,t,r,n,o,c,l,d){e.gpuBindGroup=null,e.bindGroup=null,e.action=d,e.batcher=this,e.textures=n,e.blendMode=o,e.topology=c,e.start=t,e.size=r,++Wi,this.batches[this.batchIndex++]=e,l.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),r=new ni(t);xn(this.attributeBuffer.rawBinaryData,r.rawBinaryData),this.attributeBuffer=r}_resizeIndexBuffer(e){const t=this.indexBuffer;let r=Math.max(e,t.length*1.5);r+=r%2;const n=r>65535?new Uint32Array(r):new Uint16Array(r);if(n.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let o=0;o<t.length;o++)n[o]=t[o];else xn(t.buffer,n.buffer);this.indexBuffer=n}packQuadIndex(e,t,r){e[t]=r+0,e[t+1]=r+1,e[t+2]=r+2,e[t+3]=r+0,e[t+4]=r+2,e[t+5]=r+3}packIndex(e,t,r,n){const o=e.indices,c=e.indexSize,l=e.indexOffset,d=e.attributeOffset;for(let f=0;f<c;f++)t[r++]=n+o[f+l]-d}destroy(e={}){if(this.batches!==null){for(let t=0;t<this.batches.length;t++)$l(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}}};ql.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};let ig=ql;var $=(s=>(s[s.MAP_READ=1]="MAP_READ",s[s.MAP_WRITE=2]="MAP_WRITE",s[s.COPY_SRC=4]="COPY_SRC",s[s.COPY_DST=8]="COPY_DST",s[s.INDEX=16]="INDEX",s[s.VERTEX=32]="VERTEX",s[s.UNIFORM=64]="UNIFORM",s[s.STORAGE=128]="STORAGE",s[s.INDIRECT=256]="INDIRECT",s[s.QUERY_RESOLVE=512]="QUERY_RESOLVE",s[s.STATIC=1024]="STATIC",s))($||{});class We extends Le{constructor(e){let{data:t,size:r}=e;const{usage:n,label:o,shrinkToFit:c}=e;super(),this.uid=ae("buffer"),this._resourceType="buffer",this._resourceId=ae("resource"),this._touched=0,this._updateID=1,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,r??(r=t?.byteLength);const l=!!t;this.descriptor={size:r,usage:n,mappedAtCreation:l,label:o},this.shrinkToFit=c??!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&$.STATIC)}set static(e){e?this.descriptor.usage|=$.STATIC:this.descriptor.usage&=~$.STATIC}setDataWithSize(e,t,r){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._data===e){r&&this.emit("update",this);return}const n=this._data;if(this._data=e,this._dataInt32=null,!n||n.length!==e.length){!this.shrinkToFit&&n&&e.byteLength<n.byteLength?r&&this.emit("update",this):(this.descriptor.size=e.byteLength,this._resourceId=ae("resource"),this.emit("change",this));return}r&&this.emit("update",this)}update(e){this._updateSize=e??this._updateSize,this._updateID++,this.emit("update",this)}destroy(){this.destroyed=!0,this.emit("destroy",this),this.emit("change",this),this._data=null,this.descriptor=null,this.removeAllListeners()}}function Kl(s,e){if(!(s instanceof We)){let t=e?$.INDEX:$.VERTEX;s instanceof Array&&(e?(s=new Uint32Array(s),t=$.INDEX|$.COPY_DST):(s=new Float32Array(s),t=$.VERTEX|$.COPY_DST)),s=new We({data:s,label:e?"index-mesh-buffer":"vertex-mesh-buffer",usage:t})}return s}function rg(s,e,t){const r=s.getAttribute(e);if(!r)return t.minX=0,t.minY=0,t.maxX=0,t.maxY=0,t;const n=r.buffer.data;let o=1/0,c=1/0,l=-1/0,d=-1/0;const f=n.BYTES_PER_ELEMENT,m=(r.offset||0)/f,g=(r.stride||8)/f;for(let _=m;_<n.length;_+=g){const y=n[_],a=n[_+1];y>l&&(l=y),a>d&&(d=a),y<o&&(o=y),a<c&&(c=a)}return t.minX=o,t.minY=c,t.maxX=l,t.maxY=d,t}function sg(s){return(s instanceof We||Array.isArray(s)||s.BYTES_PER_ELEMENT)&&(s={buffer:s}),s.buffer=Kl(s.buffer,!1),s}class Vi extends Le{constructor(e={}){super(),this.uid=ae("geometry"),this._layoutKey=0,this.instanceCount=1,this._bounds=new Se,this._boundsDirty=!0;const{attributes:t,indexBuffer:r,topology:n}=e;if(this.buffers=[],this.attributes={},t)for(const o in t)this.addAttribute(o,t[o]);this.instanceCount=e.instanceCount??1,r&&this.addIndex(r),this.topology=n||"triangle-list"}onBufferUpdate(){this._boundsDirty=!0,this.emit("update",this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}getSize(){for(const e in this.attributes){const t=this.attributes[e];return t.buffer.data.length/(t.stride/4||t.size)}return 0}addAttribute(e,t){const r=sg(t);this.buffers.indexOf(r.buffer)===-1&&(this.buffers.push(r.buffer),r.buffer.on("update",this.onBufferUpdate,this),r.buffer.on("change",this.onBufferUpdate,this)),this.attributes[e]=r}addIndex(e){this.indexBuffer=Kl(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,rg(this,"aPosition",this._bounds)):this._bounds}destroy(e=!1){this.emit("destroy",this),this.removeAllListeners(),e&&this.buffers.forEach(t=>t.destroy()),this.indexBuffer?.destroy(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}}const ng=new Float32Array(1),og=new Uint32Array(1);class ag extends Vi{constructor(){const t=new We({data:ng,label:"attribute-batch-buffer",usage:$.VERTEX|$.COPY_DST,shrinkToFit:!1}),r=new We({data:og,label:"index-batch-buffer",usage:$.INDEX|$.COPY_DST,shrinkToFit:!1}),n=24;super({attributes:{aPosition:{buffer:t,format:"float32x2",stride:n,offset:0},aUV:{buffer:t,format:"float32x2",stride:n,offset:8},aColor:{buffer:t,format:"unorm8x4",stride:n,offset:16},aTextureIdAndRound:{buffer:t,format:"uint16x2",stride:n,offset:20}},indexBuffer:r})}}function jl(s,e,t){if(s)for(const r in s){const n=r.toLocaleLowerCase(),o=e[n];if(o){let c=s[r];r==="header"&&(c=c.replace(/@in\s+[^;]+;\s*/g,"").replace(/@out\s+[^;]+;\s*/g,"")),t&&o.push(`//----${t}----//`),o.push(c)}else G(`${r} placement hook does not exist in shader`)}}const lg=/\{\{(.*?)\}\}/g;function Zl(s){const e={};return(s.match(lg)?.map(r=>r.replace(/[{()}]/g,""))??[]).forEach(r=>{e[r]=[]}),e}function Jl(s,e){let t;const r=/@in\s+([^;]+);/g;for(;(t=r.exec(s))!==null;)e.push(t[1])}function Ql(s,e,t=!1){const r=[];Jl(e,r),s.forEach(l=>{l.header&&Jl(l.header,r)});const n=r;t&&n.sort();const o=n.map((l,d)=>` @location(${d}) ${l},`).join(`
|
|
104
104
|
`);let c=e.replace(/@in\s+[^;]+;\s*/g,"");return c=c.replace("{{in}}",`
|
|
105
105
|
${o}
|
|
106
106
|
`),c}function ec(s,e){let t;const r=/@out\s+([^;]+);/g;for(;(t=r.exec(s))!==null;)e.push(t[1])}function cg(s){const t=/\b(\w+)\s*:/g.exec(s);return t?t[1]:""}function hg(s){const e=/@.*?\s+/g;return s.replace(e,"")}function ug(s,e){const t=[];ec(e,t),s.forEach(d=>{d.header&&ec(d.header,t)});let r=0;const n=t.sort().map(d=>d.indexOf("builtin")>-1?d:`@location(${r++}) ${d}`).join(`,
|
|
@@ -314,11 +314,11 @@ ${n.join(`
|
|
|
314
314
|
{
|
|
315
315
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
316
316
|
}
|
|
317
|
-
`}},sc={};function In(s){let e=sc[s];if(e)return e;const t=new Int32Array(s);for(let r=0;r<s;r++)t[r]=r;return e=sc[s]=new Ue({uTextures:{value:t,type:"i32",size:s}},{isStatic:!0}),e}class nc extends qe{constructor(e){const t=Xi({name:"batch",bits:[wn,En(e),qi]}),r=Yi({name:"batch",bits:[Tn,Cn(e),$i]});super({glProgram:t,gpuProgram:r,resources:{batchSamplers:In(e)}}),this.maxTextures=e}}let Ki=null;const oc=class _d extends ig{constructor(e){super(e),this.geometry=new ag,this.name=_d.extension.name,this.vertexSize=6,Ki??(Ki=new nc(e.maxTextures)),this.shader=Ki}packAttributes(e,t,r,n,o){const c=o<<16|e.roundPixels&65535,l=e.transform,d=l.a,f=l.b,m=l.c,g=l.d,_=l.tx,y=l.ty,{positions:a,uvs:h}=e,u=e.color,p=e.attributeOffset,v=p+e.attributeSize;for(let x=p;x<v;x++){const b=x*2,T=a[b],w=a[b+1];t[n++]=d*T+m*w+_,t[n++]=g*w+f*T+y,t[n++]=h[b],t[n++]=h[b+1],r[n++]=u,r[n++]=c}}packQuadAttributes(e,t,r,n,o){const c=e.texture,l=e.transform,d=l.a,f=l.b,m=l.c,g=l.d,_=l.tx,y=l.ty,a=e.bounds,h=a.maxX,u=a.minX,p=a.maxY,v=a.minY,x=c.uvs,b=e.color,T=o<<16|e.roundPixels&65535;t[n+0]=d*u+m*v+_,t[n+1]=g*v+f*u+y,t[n+2]=x.x0,t[n+3]=x.y0,r[n+4]=b,r[n+5]=T,t[n+6]=d*h+m*v+_,t[n+7]=g*v+f*h+y,t[n+8]=x.x1,t[n+9]=x.y1,r[n+10]=b,r[n+11]=T,t[n+12]=d*h+m*p+_,t[n+13]=g*p+f*h+y,t[n+14]=x.x2,t[n+15]=x.y2,r[n+16]=b,r[n+17]=T,t[n+18]=d*u+m*p+_,t[n+19]=g*p+f*u+y,t[n+20]=x.x3,t[n+21]=x.y3,r[n+22]=b,r[n+23]=T}_updateMaxTextures(e){this.shader.maxTextures!==e&&(Ki=new nc(e),this.shader=Ki)}destroy(){this.shader=null,super.destroy()}};oc.extension={type:[C.Batcher],name:"default"};let Pn=oc;function Cg(s,e,t,r,n,o,c,l=null){let d=0;t*=e,n*=o;const f=l.a,m=l.b,g=l.c,_=l.d,y=l.tx,a=l.ty;for(;d<c;){const h=s[t],u=s[t+1];r[n]=f*h+g*u+y,r[n+1]=m*h+_*u+a,n+=o,t+=e,d++}}function Ag(s,e,t,r){let n=0;for(e*=t;n<r;)s[e]=0,s[e+1]=0,e+=t,n++}function ac(s,e,t,r,n){const o=e.a,c=e.b,l=e.c,d=e.d,f=e.tx,m=e.ty;t||(t=0),r||(r=2),n||(n=s.length/r-t);let g=t*r;for(let _=0;_<n;_++){const y=s[g],a=s[g+1];s[g]=o*y+l*a+f,s[g+1]=c*y+d*a+m,g+=r}}const Eg=new B;class Rn{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,r=this.renderable;return r?ka(t,r.groupColor)+(this.alpha*r.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||Eg}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 ji={extension:{type:C.ShapeBuilder,name:"circle"},build(s,e){let t,r,n,o,c,l;if(s.type==="circle"){const b=s;if(c=l=b.radius,c<=0)return!1;t=b.x,r=b.y,n=o=0}else if(s.type==="ellipse"){const b=s;if(c=b.halfWidth,l=b.halfHeight,c<=0||l<=0)return!1;t=b.x,r=b.y,n=o=0}else{const b=s,T=b.width/2,w=b.height/2;t=b.x+T,r=b.y+w,c=l=Math.max(0,Math.min(b.radius,Math.min(T,w))),n=T-c,o=w-l}if(n<0||o<0)return!1;const d=Math.ceil(2.3*Math.sqrt(c+l)),f=d*8+(n?4:0)+(o?4:0);if(f===0)return!1;if(d===0)return e[0]=e[6]=t+n,e[1]=e[3]=r+o,e[2]=e[4]=t-n,e[5]=e[7]=r-o,!0;let m=0,g=d*4+(n?2:0)+2,_=g,y=f,a=n+c,h=o,u=t+a,p=t-a,v=r+h;if(e[m++]=u,e[m++]=v,e[--g]=v,e[--g]=p,o){const b=r-h;e[_++]=p,e[_++]=b,e[--y]=b,e[--y]=u}for(let b=1;b<d;b++){const T=Math.PI/2*(b/d),w=n+Math.cos(T)*c,S=o+Math.sin(T)*l,E=t+w,A=t-w,P=r+S,I=r-S;e[m++]=E,e[m++]=P,e[--g]=P,e[--g]=A,e[_++]=A,e[_++]=I,e[--y]=I,e[--y]=E}a=n,h=o+l,u=t+a,p=t-a,v=r+h;const x=r-h;return e[m++]=u,e[m++]=v,e[--y]=x,e[--y]=u,n&&(e[m++]=p,e[m++]=v,e[--y]=x,e[--y]=p),!0},triangulate(s,e,t,r,n,o){if(s.length===0)return;let c=0,l=0;for(let m=0;m<s.length;m+=2)c+=s[m],l+=s[m+1];c/=s.length/2,l/=s.length/2;let d=r;e[d*t]=c,e[d*t+1]=l;const f=d++;for(let m=0;m<s.length;m+=2)e[d*t]=s[m],e[d*t+1]=s[m+1],m>0&&(n[o++]=d,n[o++]=f,n[o++]=d-1),d++;n[o++]=f+1,n[o++]=f,n[o++]=d-1}},Ig={...ji,extension:{...ji.extension,name:"ellipse"}},Pg={...ji,extension:{...ji.extension,name:"roundedRectangle"}},lc=1e-4,cc=1e-4;function Rg(s){const e=s.length;if(e<6)return 1;let t=0;for(let r=0,n=s[e-2],o=s[e-1];r<e;r+=2){const c=s[r],l=s[r+1];t+=(c-n)*(l+o),n=c,o=l}return t<0?-1:1}function hc(s,e,t,r,n,o,c,l){const d=s-t*n,f=e-r*n,m=s+t*o,g=e+r*o;let _,y;c?(_=r,y=-t):(_=-r,y=t);const a=d+_,h=f+y,u=m+_,p=g+y;return l.push(a,h),l.push(u,p),2}function Nt(s,e,t,r,n,o,c,l){const d=t-s,f=r-e;let m=Math.atan2(d,f),g=Math.atan2(n-s,o-e);l&&m<g?m+=Math.PI*2:!l&&m>g&&(g+=Math.PI*2);let _=m;const y=g-m,a=Math.abs(y),h=Math.sqrt(d*d+f*f),u=(15*a*Math.sqrt(h)/Math.PI>>0)+1,p=y/u;if(_+=p,l){c.push(s,e),c.push(t,r);for(let v=1,x=_;v<u;v++,x+=p)c.push(s,e),c.push(s+Math.sin(x)*h,e+Math.cos(x)*h);c.push(s,e),c.push(n,o)}else{c.push(t,r),c.push(s,e);for(let v=1,x=_;v<u;v++,x+=p)c.push(s+Math.sin(x)*h,e+Math.cos(x)*h),c.push(s,e);c.push(n,o),c.push(s,e)}return u*2}function Mg(s,e,t,r,n,o){const c=lc;if(s.length===0)return;const l=e;let d=l.alignment;if(e.alignment!==.5){let N=Rg(s);d=(d-.5)*N+.5}const f=new J(s[0],s[1]),m=new J(s[s.length-2],s[s.length-1]),g=r,_=Math.abs(f.x-m.x)<c&&Math.abs(f.y-m.y)<c;if(g){s=s.slice(),_&&(s.pop(),s.pop(),m.set(s[s.length-2],s[s.length-1]));const N=(f.x+m.x)*.5,ee=(m.y+f.y)*.5;s.unshift(N,ee),s.push(N,ee)}const y=n,a=s.length/2;let h=s.length;const u=y.length/2,p=l.width/2,v=p*p,x=l.miterLimit*l.miterLimit;let b=s[0],T=s[1],w=s[2],S=s[3],E=0,A=0,P=-(T-S),I=b-w,k=0,O=0,X=Math.sqrt(P*P+I*I);P/=X,I/=X,P*=p,I*=p;const ne=d,R=(1-ne)*2,M=ne*2;g||(l.cap==="round"?h+=Nt(b-P*(R-M)*.5,T-I*(R-M)*.5,b-P*R,T-I*R,b+P*M,T+I*M,y,!0)+2:l.cap==="square"&&(h+=hc(b,T,P,I,R,M,!0,y))),y.push(b-P*R,T-I*R),y.push(b+P*M,T+I*M);for(let N=1;N<a-1;++N){b=s[(N-1)*2],T=s[(N-1)*2+1],w=s[N*2],S=s[N*2+1],E=s[(N+1)*2],A=s[(N+1)*2+1],P=-(T-S),I=b-w,X=Math.sqrt(P*P+I*I),P/=X,I/=X,P*=p,I*=p,k=-(S-A),O=w-E,X=Math.sqrt(k*k+O*O),k/=X,O/=X,k*=p,O*=p;const ee=w-b,he=T-S,ye=w-E,U=A-S,Ie=ee*ye+he*U,Y=he*ye-U*ee,Q=Y<0;if(Math.abs(Y)<.001*Math.abs(Ie)){y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),Ie>=0&&(l.join==="round"?h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+4:h+=2,y.push(w-k*M,S-O*M),y.push(w+k*R,S+O*R));continue}const xe=(-P+b)*(-I+S)-(-P+w)*(-I+T),Pe=(-k+E)*(-O+S)-(-k+w)*(-O+A),_i=(ee*Pe-ye*xe)/Y,Ut=(U*xe-he*Pe)/Y,ht=(_i-w)*(_i-w)+(Ut-S)*(Ut-S),Oe=w+(_i-w)*R,nt=S+(Ut-S)*R,Yt=w-(_i-w)*M,Xt=S-(Ut-S)*M,p2=Math.min(ee*ee+he*he,ye*ye+U*U),ad=Q?R:M,m2=p2+ad*ad*v;ht<=m2?l.join==="bevel"||ht/v>x?(Q?(y.push(Oe,nt),y.push(w+P*M,S+I*M),y.push(Oe,nt),y.push(w+k*M,S+O*M)):(y.push(w-P*R,S-I*R),y.push(Yt,Xt),y.push(w-k*R,S-O*R),y.push(Yt,Xt)),h+=2):l.join==="round"?Q?(y.push(Oe,nt),y.push(w+P*M,S+I*M),h+=Nt(w,S,w+P*M,S+I*M,w+k*M,S+O*M,y,!0)+4,y.push(Oe,nt),y.push(w+k*M,S+O*M)):(y.push(w-P*R,S-I*R),y.push(Yt,Xt),h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+4,y.push(w-k*R,S-O*R),y.push(Yt,Xt)):(y.push(Oe,nt),y.push(Yt,Xt)):(y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),l.join==="round"?Q?h+=Nt(w,S,w+P*M,S+I*M,w+k*M,S+O*M,y,!0)+2:h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+2:l.join==="miter"&&ht/v<=x&&(Q?(y.push(Yt,Xt),y.push(Yt,Xt)):(y.push(Oe,nt),y.push(Oe,nt)),h+=2),y.push(w-k*R,S-O*R),y.push(w+k*M,S+O*M),h+=2)}b=s[(a-2)*2],T=s[(a-2)*2+1],w=s[(a-1)*2],S=s[(a-1)*2+1],P=-(T-S),I=b-w,X=Math.sqrt(P*P+I*I),P/=X,I/=X,P*=p,I*=p,y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),g||(l.cap==="round"?h+=Nt(w-P*(R-M)*.5,S-I*(R-M)*.5,w-P*R,S-I*R,w+P*M,S+I*M,y,!1)+2:l.cap==="square"&&(h+=hc(w,S,P,I,R,M,!1,y)));const q=cc*cc;for(let N=u;N<h+u-2;++N)b=y[N*2],T=y[N*2+1],w=y[(N+1)*2],S=y[(N+1)*2+1],E=y[(N+2)*2],A=y[(N+2)*2+1],!(Math.abs(b*(S-A)+w*(A-T)+E*(T-S))<q)&&o.push(N,N+1,N+2)}function Fg(s,e,t,r){const n=lc;if(s.length===0)return;const o=s[0],c=s[1],l=s[s.length-2],d=s[s.length-1],f=e||Math.abs(o-l)<n&&Math.abs(c-d)<n,m=t,g=s.length/2,_=m.length/2;for(let y=0;y<g;y++)m.push(s[y*2]),m.push(s[y*2+1]);for(let y=0;y<g-1;y++)r.push(_+y,_+y+1);f&&r.push(_+g-1,_)}function uc(s,e,t,r,n,o,c){const l=km(s,e,2);if(!l)return;for(let f=0;f<l.length;f+=3)o[c++]=l[f]+n,o[c++]=l[f+1]+n,o[c++]=l[f+2]+n;let d=n*r;for(let f=0;f<s.length;f+=2)t[d]=s[f],t[d+1]=s[f+1],d+=r}const Ug=[],kg={extension:{type:C.ShapeBuilder,name:"polygon"},build(s,e){for(let t=0;t<s.points.length;t++)e[t]=s.points[t];return!0},triangulate(s,e,t,r,n,o){uc(s,Ug,e,t,r,n,o)}},Bg={extension:{type:C.ShapeBuilder,name:"rectangle"},build(s,e){const t=s,r=t.x,n=t.y,o=t.width,c=t.height;return o>0&&c>0?(e[0]=r,e[1]=n,e[2]=r+o,e[3]=n,e[4]=r+o,e[5]=n+c,e[6]=r,e[7]=n+c,!0):!1},triangulate(s,e,t,r,n,o){let c=0;r*=t,e[r+c]=s[0],e[r+c+1]=s[1],c+=t,e[r+c]=s[2],e[r+c+1]=s[3],c+=t,e[r+c]=s[6],e[r+c+1]=s[7],c+=t,e[r+c]=s[4],e[r+c+1]=s[5],c+=t;const l=r/t;n[o++]=l,n[o++]=l+1,n[o++]=l+2,n[o++]=l+1,n[o++]=l+3,n[o++]=l+2}},Dg={extension:{type:C.ShapeBuilder,name:"triangle"},build(s,e){return e[0]=s.x,e[1]=s.y,e[2]=s.x2,e[3]=s.y2,e[4]=s.x3,e[5]=s.y3,!0},triangulate(s,e,t,r,n,o){let c=0;r*=t,e[r+c]=s[0],e[r+c+1]=s[1],c+=t,e[r+c]=s[2],e[r+c+1]=s[3],c+=t,e[r+c]=s[4],e[r+c+1]=s[5];const l=r/t;n[o++]=l,n[o++]=l+1,n[o++]=l+2}},Og=new B,Gg=new z;function Lg(s,e,t,r){const n=e.matrix?s.copyFrom(e.matrix).invert():s.identity();if(e.textureSpace==="local"){const c=t.getBounds(Gg);e.width&&c.pad(e.width);const{x:l,y:d}=c,f=1/c.width,m=1/c.height,g=-l*f,_=-d*m,y=n.a,a=n.b,h=n.c,u=n.d;n.a*=f,n.b*=f,n.c*=m,n.d*=m,n.tx=g*y+_*h+n.tx,n.ty=g*a+_*u+n.ty}else n.translate(e.texture.frame.x,e.texture.frame.y),n.scale(1/e.texture.source.width,1/e.texture.source.height);const o=e.texture.source.style;return!(e.fill instanceof Ke)&&o.addressMode==="clamp-to-edge"&&(o.addressMode="repeat",o.update()),r&&n.append(Og.copyFrom(r).invert()),n}const qr={};L.handleByMap(C.ShapeBuilder,qr),L.add(Bg,kg,Dg,ji,Ig,Pg);const Ng=new z,zg=new B;function Hg(s,e){const{geometryData:t,batches:r}=e;r.length=0,t.indices.length=0,t.vertices.length=0,t.uvs.length=0;for(let n=0;n<s.instructions.length;n++){const o=s.instructions[n];if(o.action==="texture")Wg(o.data,r,t);else if(o.action==="fill"||o.action==="stroke"){const c=o.action==="stroke",l=o.data.path.shapePath,d=o.data.style,f=o.data.hole;c&&f&&dc(f.shapePath,d,!0,r,t),f&&(l.shapePrimitives[l.shapePrimitives.length-1].holes=f.shapePath.shapePrimitives),dc(l,d,c,r,t)}}}function Wg(s,e,t){const r=[],n=qr.rectangle,o=Ng;o.x=s.dx,o.y=s.dy,o.width=s.dw,o.height=s.dh;const c=s.transform;if(!n.build(o,r))return;const{vertices:l,uvs:d,indices:f}=t,m=f.length,g=l.length/2;c&&ac(r,c),n.triangulate(r,l,2,g,f,m);const _=s.image,y=_.uvs;d.push(y.x0,y.y0,y.x1,y.y1,y.x3,y.y3,y.x2,y.y2);const a=me.get(Rn);a.indexOffset=m,a.indexSize=f.length-m,a.attributeOffset=g,a.attributeSize=l.length/2-g,a.baseColor=s.style,a.alpha=s.alpha,a.texture=_,a.geometryData=t,e.push(a)}function dc(s,e,t,r,n){const{vertices:o,uvs:c,indices:l}=n;s.shapePrimitives.forEach(({shape:d,transform:f,holes:m})=>{const g=[],_=qr[d.type];if(!_.build(d,g))return;const y=l.length,a=o.length/2;let h="triangle-list";if(f&&ac(g,f),t){const x=d.closePath??!0,b=e;b.pixelLine?(Fg(g,x,o,l),h="line-list"):Mg(g,b,!1,x,o,l)}else if(m){const x=[],b=g.slice();Vg(m).forEach(w=>{x.push(b.length/2),b.push(...w)}),uc(b,x,o,2,a,l,y)}else _.triangulate(g,o,2,a,l,y);const u=c.length/2,p=e.texture;if(p!==F.WHITE){const x=Lg(zg,e,d,f);Cg(o,2,a,c,u,2,o.length/2-a,x)}else Ag(c,u,2,o.length/2-a);const v=me.get(Rn);v.indexOffset=y,v.indexSize=l.length-y,v.attributeOffset=a,v.attributeSize=o.length/2-a,v.baseColor=e.color,v.alpha=e.alpha,v.texture=p,v.geometryData=n,v.topology=h,r.push(v)})}function Vg(s){const e=[];for(let t=0;t<s.length;t++){const r=s[t].shape,n=[];qr[r.type].build(r,n)&&e.push(n)}return e}class Yg{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}}class Xg{constructor(){this.instructions=new Ga}init(e){const t=e.maxTextures;this.batcher?this.batcher._updateMaxTextures(t):this.batcher=new Pn({maxTextures:t}),this.instructions.reset()}get geometry(){return H(ip,"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 Mn=class ko{constructor(e){this._gpuContextHash={},this._graphicsDataContextHash=Object.create(null),this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuContextHash"),e.renderableGC.addManagedHash(this,"_graphicsDataContextHash")}init(e){ko.defaultOptions.bezierSmoothness=e?.bezierSmoothness??ko.defaultOptions.bezierSmoothness}getContextRenderData(e){return this._graphicsDataContextHash[e.uid]||this._initContextRenderData(e)}updateGpuContext(e){let t=this._gpuContextHash[e.uid]||this._initContext(e);if(e.dirty){t?this._cleanGraphicsContextData(e):t=this._initContext(e),Hg(e,t);const r=e.batchMode;e.customShader||r==="no-batch"?t.isBatchable=!1:r==="auto"?t.isBatchable=t.geometryData.vertices.length<400:t.isBatchable=!0,e.dirty=!1}return t}getGpuContext(e){return this._gpuContextHash[e.uid]||this._initContext(e)}_initContextRenderData(e){const t=me.get(Xg,{maxTextures:this._renderer.limits.maxBatchableTextures}),{batches:r,geometryData:n}=this._gpuContextHash[e.uid],o=n.vertices.length,c=n.indices.length;for(let m=0;m<r.length;m++)r[m].applyTransform=!1;const l=t.batcher;l.ensureAttributeBuffer(o),l.ensureIndexBuffer(c),l.begin();for(let m=0;m<r.length;m++){const g=r[m];l.add(g)}l.finish(t.instructions);const d=l.geometry;d.indexBuffer.setDataWithSize(l.indexBuffer,l.indexSize,!0),d.buffers[0].setDataWithSize(l.attributeBuffer.float32View,l.attributeSize,!0);const f=l.batches;for(let m=0;m<f.length;m++){const g=f[m];g.bindGroup=yn(g.textures.textures,g.textures.count,this._renderer.limits.maxBatchableTextures)}return this._graphicsDataContextHash[e.uid]=t,t}_initContext(e){const t=new Yg;return t.context=e,this._gpuContextHash[e.uid]=t,e.on("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]}onGraphicsContextDestroy(e){this._cleanGraphicsContextData(e),e.off("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]=null}_cleanGraphicsContextData(e){const t=this._gpuContextHash[e.uid];t.isBatchable||this._graphicsDataContextHash[e.uid]&&(me.return(this.getContextRenderData(e)),this._graphicsDataContextHash[e.uid]=null),t.batches&&t.batches.forEach(r=>{me.return(r)})}destroy(){for(const e in this._gpuContextHash)this._gpuContextHash[e]&&this.onGraphicsContextDestroy(this._gpuContextHash[e].context);this._gpuContextHash={},this._graphicsDataContextHash={},this._renderer=null}};Mn.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"graphicsContext"},Mn.defaultOptions={bezierSmoothness:.5};let Fn=Mn;const $g=8,Kr=11920929e-14,qg=1;function fc(s,e,t,r,n,o,c,l,d,f){const g=Math.min(.99,Math.max(0,f??Fn.defaultOptions.bezierSmoothness));let _=(qg-g)/1;return _*=_,Kg(e,t,r,n,o,c,l,d,s,_),s}function Kg(s,e,t,r,n,o,c,l,d,f){Un(s,e,t,r,n,o,c,l,d,f,0),d.push(c,l)}function Un(s,e,t,r,n,o,c,l,d,f,m){if(m>$g)return;const g=(s+t)/2,_=(e+r)/2,y=(t+n)/2,a=(r+o)/2,h=(n+c)/2,u=(o+l)/2,p=(g+y)/2,v=(_+a)/2,x=(y+h)/2,b=(a+u)/2,T=(p+x)/2,w=(v+b)/2;if(m>0){let S=c-s,E=l-e;const A=Math.abs((t-c)*E-(r-l)*S),P=Math.abs((n-c)*E-(o-l)*S);if(A>Kr&&P>Kr){if((A+P)*(A+P)<=f*(S*S+E*E)){d.push(T,w);return}}else if(A>Kr){if(A*A<=f*(S*S+E*E)){d.push(T,w);return}}else if(P>Kr){if(P*P<=f*(S*S+E*E)){d.push(T,w);return}}else if(S=T-(s+c)/2,E=w-(e+l)/2,S*S+E*E<=f){d.push(T,w);return}}Un(s,e,g,_,p,v,T,w,d,f,m+1),Un(T,w,x,b,h,u,c,l,d,f,m+1)}const jg=8,Zg=11920929e-14,Jg=1;function Qg(s,e,t,r,n,o,c,l){const f=Math.min(.99,Math.max(0,l??Fn.defaultOptions.bezierSmoothness));let m=(Jg-f)/1;return m*=m,e0(e,t,r,n,o,c,s,m),s}function e0(s,e,t,r,n,o,c,l){kn(c,s,e,t,r,n,o,l,0),c.push(n,o)}function kn(s,e,t,r,n,o,c,l,d){if(d>jg)return;const f=(e+r)/2,m=(t+n)/2,g=(r+o)/2,_=(n+c)/2,y=(f+g)/2,a=(m+_)/2;let h=o-e,u=c-t;const p=Math.abs((r-o)*u-(n-c)*h);if(p>Zg){if(p*p<=l*(h*h+u*u)){s.push(y,a);return}}else if(h=y-(e+o)/2,u=a-(t+c)/2,h*h+u*u<=l){s.push(y,a);return}kn(s,e,t,f,m,y,a,l,d+1),kn(s,y,a,g,_,o,c,l,d+1)}function pc(s,e,t,r,n,o,c,l){let d=Math.abs(n-o);(!c&&n>o||c&&o>n)&&(d=2*Math.PI-d),l||(l=Math.max(6,Math.floor(6*Math.pow(r,1/3)*(d/Math.PI)))),l=Math.max(l,3);let f=d/l,m=n;f*=c?-1:1;for(let g=0;g<l+1;g++){const _=Math.cos(m),y=Math.sin(m),a=e+_*r,h=t+y*r;s.push(a,h),m+=f}}function t0(s,e,t,r,n,o){const c=s[s.length-2],d=s[s.length-1]-t,f=c-e,m=n-t,g=r-e,_=Math.abs(d*g-f*m);if(_<1e-8||o===0){(s[s.length-2]!==e||s[s.length-1]!==t)&&s.push(e,t);return}const y=d*d+f*f,a=m*m+g*g,h=d*m+f*g,u=o*Math.sqrt(y)/_,p=o*Math.sqrt(a)/_,v=u*h/y,x=p*h/a,b=u*g+p*f,T=u*m+p*d,w=f*(p+v),S=d*(p+v),E=g*(u+x),A=m*(u+x),P=Math.atan2(S-T,w-b),I=Math.atan2(A-T,E-b);pc(s,b+e,T+t,o,P,I,f*m>g*d)}const Zi=Math.PI*2,Bn={centerX:0,centerY:0,ang1:0,ang2:0},Dn=({x:s,y:e},t,r,n,o,c,l,d)=>{s*=t,e*=r;const f=n*s-o*e,m=o*s+n*e;return d.x=f+c,d.y=m+l,d};function i0(s,e){const t=e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),r=e===1.5707963267948966?.551915024494:t,n=Math.cos(s),o=Math.sin(s),c=Math.cos(s+e),l=Math.sin(s+e);return[{x:n-o*r,y:o+n*r},{x:c+l*r,y:l-c*r},{x:c,y:l}]}const mc=(s,e,t,r)=>{const n=s*r-e*t<0?-1:1;let o=s*t+e*r;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},r0=(s,e,t,r,n,o,c,l,d,f,m,g,_)=>{const y=Math.pow(n,2),a=Math.pow(o,2),h=Math.pow(m,2),u=Math.pow(g,2);let p=y*a-y*u-a*h;p<0&&(p=0),p/=y*u+a*h,p=Math.sqrt(p)*(c===l?-1:1);const v=p*n/o*g,x=p*-o/n*m,b=f*v-d*x+(s+t)/2,T=d*v+f*x+(e+r)/2,w=(m-v)/n,S=(g-x)/o,E=(-m-v)/n,A=(-g-x)/o,P=mc(1,0,w,S);let I=mc(w,S,E,A);l===0&&I>0&&(I-=Zi),l===1&&I<0&&(I+=Zi),_.centerX=b,_.centerY=T,_.ang1=P,_.ang2=I};function s0(s,e,t,r,n,o,c,l=0,d=0,f=0){if(o===0||c===0)return;const m=Math.sin(l*Zi/360),g=Math.cos(l*Zi/360),_=g*(e-r)/2+m*(t-n)/2,y=-m*(e-r)/2+g*(t-n)/2;if(_===0&&y===0)return;o=Math.abs(o),c=Math.abs(c);const a=Math.pow(_,2)/Math.pow(o,2)+Math.pow(y,2)/Math.pow(c,2);a>1&&(o*=Math.sqrt(a),c*=Math.sqrt(a)),r0(e,t,r,n,o,c,d,f,m,g,_,y,Bn);let{ang1:h,ang2:u}=Bn;const{centerX:p,centerY:v}=Bn;let x=Math.abs(u)/(Zi/4);Math.abs(1-x)<1e-7&&(x=1);const b=Math.max(Math.ceil(x),1);u/=b;let T=s[s.length-2],w=s[s.length-1];const S={x:0,y:0};for(let E=0;E<b;E++){const A=i0(h,u),{x:P,y:I}=Dn(A[0],o,c,g,m,p,v,S),{x:k,y:O}=Dn(A[1],o,c,g,m,p,v,S),{x:X,y:ne}=Dn(A[2],o,c,g,m,p,v,S);fc(s,T,w,P,I,k,O,X,ne),T=X,w=ne,h+=u}}function n0(s,e,t){const r=(c,l)=>{const d=l.x-c.x,f=l.y-c.y,m=Math.sqrt(d*d+f*f),g=d/m,_=f/m;return{len:m,nx:g,ny:_}},n=(c,l)=>{c===0?s.moveTo(l.x,l.y):s.lineTo(l.x,l.y)};let o=e[e.length-1];for(let c=0;c<e.length;c++){const l=e[c%e.length],d=l.radius??t;if(d<=0){n(c,l),o=l;continue}const f=e[(c+1)%e.length],m=r(l,o),g=r(l,f);if(m.len<1e-4||g.len<1e-4){n(c,l),o=l;continue}let _=Math.asin(m.nx*g.ny-m.ny*g.nx),y=1,a=!1;m.nx*g.nx-m.ny*-g.ny<0?_<0?_=Math.PI+_:(_=Math.PI-_,y=-1,a=!0):_>0&&(y=-1,a=!0);const h=_/2;let u,p=Math.abs(Math.cos(h)*d/Math.sin(h));p>Math.min(m.len/2,g.len/2)?(p=Math.min(m.len/2,g.len/2),u=Math.abs(p*Math.sin(h)/Math.cos(h))):u=d;const v=l.x+g.nx*p+-g.ny*u*y,x=l.y+g.ny*p+g.nx*u*y,b=Math.atan2(m.ny,m.nx)+Math.PI/2*y,T=Math.atan2(g.ny,g.nx)-Math.PI/2*y;c===0&&s.moveTo(v+Math.cos(b)*u,x+Math.sin(b)*u),s.arc(v,x,u,b,T,a),o=l}}function o0(s,e,t,r){const n=(l,d)=>Math.sqrt((l.x-d.x)**2+(l.y-d.y)**2),o=(l,d,f)=>({x:l.x+(d.x-l.x)*f,y:l.y+(d.y-l.y)*f}),c=e.length;for(let l=0;l<c;l++){const d=e[(l+1)%c],f=d.radius??t;if(f<=0){l===0?s.moveTo(d.x,d.y):s.lineTo(d.x,d.y);continue}const m=e[l],g=e[(l+2)%c],_=n(m,d);let y;if(_<1e-4)y=d;else{const u=Math.min(_/2,f);y=o(d,m,u/_)}const a=n(g,d);let h;if(a<1e-4)h=d;else{const u=Math.min(a/2,f);h=o(d,g,u/a)}l===0?s.moveTo(y.x,y.y):s.lineTo(y.x,y.y),s.quadraticCurveTo(d.x,d.y,h.x,h.y,r)}}const a0=new z;class l0{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new Se,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();const r=this._currentPoly.points,n=r[r.length-2],o=r[r.length-1];return(n!==e||o!==t)&&r.push(e,t),this}arc(e,t,r,n,o,c){this._ensurePoly(!1);const l=this._currentPoly.points;return pc(l,e,t,r,n,o,c),this}arcTo(e,t,r,n,o){this._ensurePoly();const c=this._currentPoly.points;return t0(c,e,t,r,n,o),this}arcToSvg(e,t,r,n,o,c,l){const d=this._currentPoly.points;return s0(d,this._currentPoly.lastX,this._currentPoly.lastY,c,l,e,t,r,n,o),this}bezierCurveTo(e,t,r,n,o,c,l){this._ensurePoly();const d=this._currentPoly;return fc(this._currentPoly.points,d.lastX,d.lastY,e,t,r,n,o,c,l),this}quadraticCurveTo(e,t,r,n,o){this._ensurePoly();const c=this._currentPoly;return Qg(this._currentPoly.points,c.lastX,c.lastY,e,t,r,n,o),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));const r=this.shapePrimitives,n=r.length;for(let o=0;o<e.instructions.length;o++){const c=e.instructions[o];this[c.action](...c.data)}if(e.checkForHoles&&r.length-n>1){let o=null;for(let c=n;c<r.length;c++){const l=r[c];if(l.shape.type==="polygon"){const d=l.shape,f=o?.shape;f&&f.containsPolygon(d)?(o.holes||(o.holes=[]),o.holes.push(l),r.copyWithin(c,c+1),r.length--,c--):o=l}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,r,n,o){return this.drawShape(new z(e,t,r,n),o),this}circle(e,t,r,n){return this.drawShape(new Yr(e,t,r),n),this}poly(e,t,r){const n=new Ni(e);return n.closePath=t,this.drawShape(n,r),this}regularPoly(e,t,r,n,o=0,c){n=Math.max(n|0,3);const l=-1*Math.PI/2+o,d=Math.PI*2/n,f=[];for(let m=0;m<n;m++){const g=l-m*d;f.push(e+r*Math.cos(g),t+r*Math.sin(g))}return this.poly(f,!0,c),this}roundPoly(e,t,r,n,o,c=0,l){if(n=Math.max(n|0,3),o<=0)return this.regularPoly(e,t,r,n,c);const d=r*Math.sin(Math.PI/n)-.001;o=Math.min(o,d);const f=-1*Math.PI/2+c,m=Math.PI*2/n,g=(n-2)*Math.PI/n/2;for(let _=0;_<n;_++){const y=_*m+f,a=e+r*Math.cos(y),h=t+r*Math.sin(y),u=y+Math.PI+g,p=y-Math.PI-g,v=a+o*Math.cos(u),x=h+o*Math.sin(u),b=a+o*Math.cos(p),T=h+o*Math.sin(p);_===0?this.moveTo(v,x):this.lineTo(v,x),this.quadraticCurveTo(a,h,b,T,l)}return this.closePath()}roundShape(e,t,r=!1,n){return e.length<3?this:(r?o0(this,e,t,n):n0(this,e,t),this.closePath())}filletRect(e,t,r,n,o){if(o===0)return this.rect(e,t,r,n);const c=Math.min(r,n)/2,l=Math.min(c,Math.max(-c,o)),d=e+r,f=t+n,m=l<0?-l:0,g=Math.abs(l);return this.moveTo(e,t+g).arcTo(e+m,t+m,e+g,t,g).lineTo(d-g,t).arcTo(d-m,t+m,d,t+g,g).lineTo(d,f-g).arcTo(d-m,f-m,e+r-g,f,g).lineTo(e+g,f).arcTo(e+m,f-m,e,f-g,g).closePath()}chamferRect(e,t,r,n,o,c){if(o<=0)return this.rect(e,t,r,n);const l=Math.min(o,Math.min(r,n)/2),d=e+r,f=t+n,m=[e+l,t,d-l,t,d,t+l,d,f-l,d-l,f,e+l,f,e,f-l,e,t+l];for(let g=m.length-1;g>=2;g-=2)m[g]===m[g-2]&&m[g-1]===m[g-3]&&m.splice(g-1,2);return this.poly(m,!0,c)}ellipse(e,t,r,n,o){return this.drawShape(new vn(e,t,r,n),o),this}roundRect(e,t,r,n,o,c){return this.drawShape(new _n(e,t,r,n,o),c),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let r=this._currentPoly;return r&&this.endPoly(),r=new Ni,r.points.push(e,t),this._currentPoly=r,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 Ni,e)){const t=this.shapePrimitives[this.shapePrimitives.length-1];if(t){let r=t.shape.x,n=t.shape.y;if(t.transform&&!t.transform.isIdentity()){const o=t.transform,c=r;r=o.a*r+o.c*n+o.tx,n=o.b*c+o.d*n+o.ty}this._currentPoly.points.push(r,n)}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 r=e.instructions[t];this[r.action](...r.data)}this.finish()}get bounds(){const e=this._bounds;e.clear();const t=this.shapePrimitives;for(let r=0;r<t.length;r++){const n=t[r],o=n.shape.getBounds(a0);n.transform?e.addRect(o,n.transform):e.addRect(o)}return e}}class yt{constructor(e,t=!1){this.instructions=[],this.uid=ae("graphicsPath"),this._dirty=!0,this.checkForHoles=t,typeof e=="string"?Ym(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||(this._shapePath=new l0(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,r,n,o){const c=this.instructions[this.instructions.length-1],l=this.getLastPoint(J.shared);let d=0,f=0;if(!c||c.action!=="bezierCurveTo")d=l.x,f=l.y;else{d=c.data[2],f=c.data[3];const m=l.x,g=l.y;d=m+(m-d),f=g+(g-f)}return this.instructions.push({action:"bezierCurveTo",data:[d,f,e,t,r,n,o]}),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,r){const n=this.instructions[this.instructions.length-1],o=this.getLastPoint(J.shared);let c=0,l=0;if(!n||n.action!=="quadraticCurveTo")c=o.x,l=o.y;else{c=n.data[0],l=n.data[1];const d=o.x,f=o.y;c=d+(d-c),l=f+(f-l)}return this.instructions.push({action:"quadraticCurveTo",data:[c,l,e,t,r]}),this._dirty=!0,this}rect(e,t,r,n,o){return this.instructions.push({action:"rect",data:[e,t,r,n,o]}),this._dirty=!0,this}circle(e,t,r,n){return this.instructions.push({action:"circle",data:[e,t,r,n]}),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,r,n,o,c,l){o||(o=n/2);const d=-1*Math.PI/2+c,f=r*2,m=Math.PI*2/f,g=[];for(let _=0;_<f;_++){const y=_%2?o:n,a=_*m+d;g.push(e+y*Math.cos(a),t+y*Math.sin(a))}return this.poly(g,!0,l),this}clone(e=!1){const t=new yt;if(t.checkForHoles=this.checkForHoles,!e)t.instructions=this.instructions.slice();else for(let r=0;r<this.instructions.length;r++){const n=this.instructions[r];t.instructions.push({action:n.action,data:n.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,r=e.b,n=e.c,o=e.d,c=e.tx,l=e.ty;let d=0,f=0,m=0,g=0,_=0,y=0,a=0,h=0;for(let u=0;u<this.instructions.length;u++){const p=this.instructions[u],v=p.data;switch(p.action){case"moveTo":case"lineTo":d=v[0],f=v[1],v[0]=t*d+n*f+c,v[1]=r*d+o*f+l;break;case"bezierCurveTo":m=v[0],g=v[1],_=v[2],y=v[3],d=v[4],f=v[5],v[0]=t*m+n*g+c,v[1]=r*m+o*g+l,v[2]=t*_+n*y+c,v[3]=r*_+o*y+l,v[4]=t*d+n*f+c,v[5]=r*d+o*f+l;break;case"quadraticCurveTo":m=v[0],g=v[1],d=v[2],f=v[3],v[0]=t*m+n*g+c,v[1]=r*m+o*g+l,v[2]=t*d+n*f+c,v[3]=r*d+o*f+l;break;case"arcToSvg":d=v[5],f=v[6],a=v[0],h=v[1],v[0]=t*a+n*h,v[1]=r*a+o*h,v[5]=t*d+n*f+c,v[6]=r*d+o*f+l;break;case"circle":v[4]=Ji(v[3],e);break;case"rect":v[4]=Ji(v[4],e);break;case"ellipse":v[8]=Ji(v[8],e);break;case"roundRect":v[5]=Ji(v[5],e);break;case"addPath":v[0].transform(e);break;case"poly":v[2]=Ji(v[2],e);break;default:G("unknown transform action",p.action);break}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,r=this.instructions[t];if(!r)return e.x=0,e.y=0,e;for(;r.action==="closePath";){if(t--,t<0)return e.x=0,e.y=0,e;r=this.instructions[t]}switch(r.action){case"moveTo":case"lineTo":e.x=r.data[0],e.y=r.data[1];break;case"quadraticCurveTo":e.x=r.data[2],e.y=r.data[3];break;case"bezierCurveTo":e.x=r.data[4],e.y=r.data[5];break;case"arc":case"arcToSvg":e.x=r.data[5],e.y=r.data[6];break;case"addPath":r.data[0].getLastPoint(e);break}return e}}function Ji(s,e){return s?s.prepend(e):e.clone()}function de(s,e,t){const r=s.getAttribute(e);return r?Number(r):t}function c0(s,e){const t=s.querySelectorAll("defs");for(let r=0;r<t.length;r++){const n=t[r];for(let o=0;o<n.children.length;o++){const c=n.children[o];switch(c.nodeName.toLowerCase()){case"lineargradient":e.defs[c.id]=h0(c);break;case"radialgradient":e.defs[c.id]=u0();break}}}}function h0(s){const e=de(s,"x1",0),t=de(s,"y1",0),r=de(s,"x2",1),n=de(s,"y2",0),o=s.getAttribute("gradientUnits")||"objectBoundingBox",c=new Ke(e,t,r,n,o==="objectBoundingBox"?"local":"global");for(let l=0;l<s.children.length;l++){const d=s.children[l],f=de(d,"offset",0),m=le.shared.setValue(d.getAttribute("stop-color")).toNumber();c.addColorStop(f,m)}return c}function u0(s){return G("[SVG Parser] Radial gradients are not yet supported"),new Ke(0,0,1,0)}function gc(s){const e=s.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return e?e[1]:""}const vc={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 _c(s,e){const t=s.getAttribute("style"),r={},n={},o={strokeStyle:r,fillStyle:n,useFill:!1,useStroke:!1};for(const c in vc){const l=s.getAttribute(c);l&&yc(e,o,c,l.trim())}if(t){const c=t.split(";");for(let l=0;l<c.length;l++){const d=c[l].trim(),[f,m]=d.split(":");vc[f]&&yc(e,o,f,m.trim())}}return{strokeStyle:o.useStroke?r:null,fillStyle:o.useFill?n:null,useFill:o.useFill,useStroke:o.useStroke}}function yc(s,e,t,r){switch(t){case"stroke":if(r!=="none"){if(r.startsWith("url(")){const n=gc(r);e.strokeStyle.fill=s.defs[n]}else e.strokeStyle.color=le.shared.setValue(r).toNumber();e.useStroke=!0}break;case"stroke-width":e.strokeStyle.width=Number(r);break;case"fill":if(r!=="none"){if(r.startsWith("url(")){const n=gc(r);e.fillStyle.fill=s.defs[n]}else e.fillStyle.color=le.shared.setValue(r).toNumber();e.useFill=!0}break;case"fill-opacity":e.fillStyle.alpha=Number(r);break;case"stroke-opacity":e.strokeStyle.alpha=Number(r);break;case"opacity":e.fillStyle.alpha=Number(r),e.strokeStyle.alpha=Number(r);break}}function d0(s){if(s.length<=2)return!0;const e=s.map(l=>l.area).sort((l,d)=>d-l),[t,r]=e,n=e[e.length-1],o=t/r,c=r/n;return!(o>3&&c<2)}function f0(s){return s.split(/(?=[Mm])/).filter(r=>r.trim().length>0)}function p0(s){const e=s.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!e||e.length<4)return 0;const t=e.map(Number),r=[],n=[];for(let m=0;m<t.length;m+=2)m+1<t.length&&(r.push(t[m]),n.push(t[m+1]));if(r.length===0||n.length===0)return 0;const o=Math.min(...r),c=Math.max(...r),l=Math.min(...n),d=Math.max(...n);return(c-o)*(d-l)}function xc(s,e){const t=new yt(s,!1);for(const r of t.instructions)e.instructions.push(r)}function m0(s,e){if(typeof s=="string"){const c=document.createElement("div");c.innerHTML=s.trim(),s=c.querySelector("svg")}const t={context:e,defs:{},path:new yt};c0(s,t);const r=s.children,{fillStyle:n,strokeStyle:o}=_c(s,t);for(let c=0;c<r.length;c++){const l=r[c];l.nodeName.toLowerCase()!=="defs"&&bc(l,t,n,o)}return e}function bc(s,e,t,r){const n=s.children,{fillStyle:o,strokeStyle:c}=_c(s,e);o&&t?t={...t,...o}:o&&(t=o),c&&r?r={...r,...c}:c&&(r=c);const l=!t&&!r;l&&(t={color:0});let d,f,m,g,_,y,a,h,u,p,v,x,b,T,w,S,E;switch(s.nodeName.toLowerCase()){case"path":{T=s.getAttribute("d");const A=s.getAttribute("fill-rule"),P=f0(T),I=A==="evenodd",k=P.length>1;if(I&&k){const X=P.map(R=>({path:R,area:p0(R)}));if(X.sort((R,M)=>M.area-R.area),P.length>3||!d0(X))for(let R=0;R<X.length;R++){const M=X[R],q=R===0;e.context.beginPath();const N=new yt(void 0,!0);xc(M.path,N),e.context.path(N),q?(t&&e.context.fill(t),r&&e.context.stroke(r)):e.context.cut()}else for(let R=0;R<X.length;R++){const M=X[R],q=R%2===1;e.context.beginPath();const N=new yt(void 0,!0);xc(M.path,N),e.context.path(N),q?e.context.cut():(t&&e.context.fill(t),r&&e.context.stroke(r))}}else{const X=A?A==="evenodd":!0;w=new yt(T,X),e.context.path(w),t&&e.context.fill(t),r&&e.context.stroke(r)}break}case"circle":a=de(s,"cx",0),h=de(s,"cy",0),u=de(s,"r",0),e.context.ellipse(a,h,u,u),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"rect":d=de(s,"x",0),f=de(s,"y",0),S=de(s,"width",0),E=de(s,"height",0),p=de(s,"rx",0),v=de(s,"ry",0),p||v?e.context.roundRect(d,f,S,E,p||v):e.context.rect(d,f,S,E),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"ellipse":a=de(s,"cx",0),h=de(s,"cy",0),p=de(s,"rx",0),v=de(s,"ry",0),e.context.beginPath(),e.context.ellipse(a,h,p,v),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"line":m=de(s,"x1",0),g=de(s,"y1",0),_=de(s,"x2",0),y=de(s,"y2",0),e.context.beginPath(),e.context.moveTo(m,g),e.context.lineTo(_,y),r&&e.context.stroke(r);break;case"polygon":b=s.getAttribute("points"),x=b.match(/\d+/g).map(A=>parseInt(A,10)),e.context.poly(x,!0),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"polyline":b=s.getAttribute("points"),x=b.match(/\d+/g).map(A=>parseInt(A,10)),e.context.poly(x,!1),r&&e.context.stroke(r);break;case"g":case"svg":break;default:{G(`[SVG parser] <${s.nodeName}> elements unsupported`);break}}l&&(t=null);for(let A=0;A<n.length;A++)bc(n[A],e,t,r)}function g0(s){return le.isColorLike(s)}function Tc(s){return s instanceof Vr}function wc(s){return s instanceof Ke}function v0(s){return s instanceof F}function _0(s,e,t){const r=le.shared.setValue(e??0);return s.color=r.toNumber(),s.alpha=r.alpha===1?t.alpha:r.alpha,s.texture=F.WHITE,{...t,...s}}function y0(s,e,t){return s.texture=e,{...t,...s}}function Sc(s,e,t){return s.fill=e,s.color=16777215,s.texture=e.texture,s.matrix=e.transform,{...t,...s}}function Cc(s,e,t){return e.buildGradient(),s.fill=e,s.color=16777215,s.texture=e.texture,s.matrix=e.transform,s.textureSpace=e.textureSpace,{...t,...s}}function x0(s,e){const t={...e,...s},r=le.shared.setValue(t.color);return t.alpha*=r.alpha,t.color=r.toNumber(),t}function zt(s,e){if(s==null)return null;const t={},r=s;return g0(s)?_0(t,s,e):v0(s)?y0(t,s,e):Tc(s)?Sc(t,s,e):wc(s)?Cc(t,s,e):r.fill&&Tc(r.fill)?Sc(r,r.fill,e):r.fill&&wc(r.fill)?Cc(r,r.fill,e):x0(r,e)}function jr(s,e){const{width:t,alignment:r,miterLimit:n,cap:o,join:c,pixelLine:l,...d}=e,f=zt(s,d);return f?{width:t,alignment:r,miterLimit:n,cap:o,join:c,pixelLine:l,...f}:null}const b0=new J,Ac=new B,On=class ut extends Ge{constructor(){super(...arguments),this.uid=ae("graphicsContext"),this.dirty=!0,this.batchMode="auto",this.instructions=[],this._activePath=new yt,this._transform=new B,this._fillStyle={...ut.defaultFillStyle},this._strokeStyle={...ut.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new Se,this._boundsDirty=!0}clone(){const e=new ut;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=zt(e,ut.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(e){this._strokeStyle=jr(e,ut.defaultStrokeStyle)}setFillStyle(e){return this._fillStyle=zt(e,ut.defaultFillStyle),this}setStrokeStyle(e){return this._strokeStyle=zt(e,ut.defaultStrokeStyle),this}texture(e,t,r,n,o,c){return this.instructions.push({action:"texture",data:{image:e,dx:r||0,dy:n||0,dw:o||e.frame.width,dh:c||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t?le.shared.setValue(t).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new yt,this}fill(e,t){let r;const n=this.instructions[this.instructions.length-1];return this._tick===0&&n?.action==="stroke"?r=n.data.path:r=this._activePath.clone(),r?(e!=null&&(t!==void 0&&typeof e=="number"&&(H(j,"GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead"),e={color:e,alpha:t}),this._fillStyle=zt(e,ut.defaultFillStyle)),this.instructions.push({action:"fill",data:{style:this.fillStyle,path:r}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){const{x:e,y:t}=this._activePath.getLastPoint(J.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(e){let t;const r=this.instructions[this.instructions.length-1];return this._tick===0&&r?.action==="fill"?t=r.data.path:t=this._activePath.clone(),t?(e!=null&&(this._strokeStyle=jr(e,ut.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],r=this._activePath.clone();if(t&&(t.action==="stroke"||t.action==="fill"))if(t.data.hole)t.data.hole.addPath(r);else{t.data.hole=r;break}}return this._initNextPathLocation(),this}arc(e,t,r,n,o,c){this._tick++;const l=this._transform;return this._activePath.arc(l.a*e+l.c*t+l.tx,l.b*e+l.d*t+l.ty,r,n,o,c),this}arcTo(e,t,r,n,o){this._tick++;const c=this._transform;return this._activePath.arcTo(c.a*e+c.c*t+c.tx,c.b*e+c.d*t+c.ty,c.a*r+c.c*n+c.tx,c.b*r+c.d*n+c.ty,o),this}arcToSvg(e,t,r,n,o,c,l){this._tick++;const d=this._transform;return this._activePath.arcToSvg(e,t,r,n,o,d.a*c+d.c*l+d.tx,d.b*c+d.d*l+d.ty),this}bezierCurveTo(e,t,r,n,o,c,l){this._tick++;const d=this._transform;return this._activePath.bezierCurveTo(d.a*e+d.c*t+d.tx,d.b*e+d.d*t+d.ty,d.a*r+d.c*n+d.tx,d.b*r+d.d*n+d.ty,d.a*o+d.c*c+d.tx,d.b*o+d.d*c+d.ty,l),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,r,n){return this._tick++,this._activePath.ellipse(e,t,r,n,this._transform.clone()),this}circle(e,t,r){return this._tick++,this._activePath.circle(e,t,r,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;const r=this._transform;return this._activePath.lineTo(r.a*e+r.c*t+r.tx,r.b*e+r.d*t+r.ty),this}moveTo(e,t){this._tick++;const r=this._transform,n=this._activePath.instructions,o=r.a*e+r.c*t+r.tx,c=r.b*e+r.d*t+r.ty;return n.length===1&&n[0].action==="moveTo"?(n[0].data[0]=o,n[0].data[1]=c,this):(this._activePath.moveTo(o,c),this)}quadraticCurveTo(e,t,r,n,o){this._tick++;const c=this._transform;return this._activePath.quadraticCurveTo(c.a*e+c.c*t+c.tx,c.b*e+c.d*t+c.ty,c.a*r+c.c*n+c.tx,c.b*r+c.d*n+c.ty,o),this}rect(e,t,r,n){return this._tick++,this._activePath.rect(e,t,r,n,this._transform.clone()),this}roundRect(e,t,r,n,o){return this._tick++,this._activePath.roundRect(e,t,r,n,o,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,r,n,o=0,c){return this._tick++,this._activePath.regularPoly(e,t,r,n,o,c),this}roundPoly(e,t,r,n,o,c){return this._tick++,this._activePath.roundPoly(e,t,r,n,o,c),this}roundShape(e,t,r,n){return this._tick++,this._activePath.roundShape(e,t,r,n),this}filletRect(e,t,r,n,o){return this._tick++,this._activePath.filletRect(e,t,r,n,o),this}chamferRect(e,t,r,n,o,c){return this._tick++,this._activePath.chamferRect(e,t,r,n,o,c),this}star(e,t,r,n,o=0,c=0){return this._tick++,this._activePath.star(e,t,r,n,o,c,this._transform.clone()),this}svg(e){return this._tick++,m0(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,r,n,o,c){return e instanceof B?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,r,n,o,c),this)}transform(e,t,r,n,o,c){return e instanceof B?(this._transform.append(e),this):(Ac.set(e,t,r,n,o,c),this._transform.append(Ac),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&&(this.emit("update",this,16),this.dirty=!0)}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 r=this.instructions[t],n=r.action;if(n==="fill"){const o=r.data;e.addBounds(o.path.bounds)}else if(n==="texture"){const o=r.data;e.addFrame(o.dx,o.dy,o.dx+o.dw,o.dy+o.dh,o.transform)}if(n==="stroke"){const o=r.data,c=o.style.alignment,l=o.style.width*(1-c),d=o.path.bounds;e.addFrame(d.minX-l,d.minY-l,d.maxX+l,d.maxY+l)}}return e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;const t=this.instructions;let r=!1;for(let n=0;n<t.length;n++){const o=t[n],c=o.data,l=c.path;if(!o.action||!l)continue;const d=c.style,f=l.shapePath.shapePrimitives;for(let m=0;m<f.length;m++){const g=f[m].shape;if(!d||!g)continue;const _=f[m].transform,y=_?_.applyInverse(e,b0):e;if(o.action==="fill")r=g.contains(y.x,y.y);else{const h=d;r=g.strokeContains(y.x,y.y,h.width,h.alignment)}const a=c.hole;if(a){const h=a.shapePath?.shapePrimitives;if(h)for(let u=0;u<h.length;u++)h[u].shape.contains(y.x,y.y)&&(r=!1)}if(r)return!0}}return r}destroy(e=!1){if(this._stateStack.length=0,this._transform=null,this.emit("destroy",this),this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const r=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(r)),this._strokeStyle.texture&&(this._strokeStyle.fill&&"uid"in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(r))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};On.defaultFillStyle={color:16777215,alpha:1,texture:F.WHITE,matrix:null,fill:null,textureSpace:"local"},On.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:"butt",join:"miter",texture:F.WHITE,matrix:null,fill:null,textureSpace:"local",pixelLine:!1};let je=On;const Gn=class yi extends Ge{constructor(e={}){super(),this.uid=ae("textStyle"),this._tick=0,T0(e);const t={...yi.defaultTextStyle,...e};for(const r in t){const n=r;this[n]=t[r]}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({...yi.defaultDropShadow,...e}):this._dropShadow=e?this._createProxy({...yi.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({...je.defaultFillStyle,...e},()=>{this._fill=zt({...this._originalFill},je.defaultFillStyle)})),this._fill=zt(e===0?"black":e,je.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...je.defaultStrokeStyle,...e},()=>{this._stroke=jr({...this._originalStroke},je.defaultStrokeStyle)})),this._stroke=jr(e,je.defaultStrokeStyle),this.update())}update(){this._tick++,this.emit("update",this)}reset(){const e=yi.defaultTextStyle;for(const t in e)this[t]=e[t]}get styleKey(){return`${this.uid}-${this._tick}`}clone(){return new yi({align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill,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,textBaseline:this.textBaseline,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0})}_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 r=typeof e=="boolean"?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(r),this._originalFill?.texture&&this._originalFill.texture.destroy(r),this._stroke?.texture&&this._stroke.texture.destroy(r),this._originalStroke?.texture&&this._originalStroke.texture.destroy(r)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(r,n,o)=>(r[n]===o||(r[n]=o,t?.(n,o),this.update()),!0)})}_isFillStyle(e){return(e??null)!==null&&!(le.isColorLike(e)||e instanceof Ke||e instanceof Vr)}};Gn.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5},Gn.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 Be=Gn;function T0(s){const e=s;if(typeof e.dropShadow=="boolean"&&e.dropShadow){const t=Be.defaultDropShadow;s.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(j,"strokeThickness is now a part of stroke");const t=e.stroke;let r={};if(le.isColorLike(t))r.color=t;else if(t instanceof Ke||t instanceof Vr)r.fill=t;else if(Object.hasOwnProperty.call(t,"color")||Object.hasOwnProperty.call(t,"fill"))r=t;else throw new Error("Invalid stroke value.");s.stroke={...r,width:e.strokeThickness}}if(Array.isArray(e.fillGradientStops)){if(H(j,"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&&G("The number of fill colors must match the number of fill gradient stops.");const t=new Ke({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),r=e.fillGradientStops.slice(),n=e.fill.map(o=>le.shared.setValue(o).toNumber());r.forEach((o,c)=>{t.addColorStop(o,n[c])}),s.fill={fill:t}}}class w0{constructor(e){this._canvasPool=Object.create(null),this.canvasOptions=e||{},this.enableFullScreen=!1}_createCanvasAndContext(e,t){const r=V.get().createCanvas();r.width=e,r.height=t;const n=r.getContext("2d");return{canvas:r,context:n}}getOptimalCanvasAndContext(e,t,r=1){e=Math.ceil(e*r-1e-6),t=Math.ceil(t*r-1e-6),e=Jt(e),t=Jt(t);const n=(e<<17)+(t<<1);this._canvasPool[n]||(this._canvasPool[n]=[]);let o=this._canvasPool[n].pop();return o||(o=this._createCanvasAndContext(e,t)),o}returnCanvasAndContext(e){const t=e.canvas,{width:r,height:n}=t,o=(r<<17)+(n<<1);e.context.resetTransform(),e.context.clearRect(0,0,r,n),this._canvasPool[o].push(e)}clear(){this._canvasPool={}}}const xt=new w0;ei.register(xt);const Ec=1e5;function Zr(s,e,t,r=0){if(s.texture===F.WHITE&&!s.fill)return le.shared.setValue(s.color).setAlpha(s.alpha??1).toHexa();if(s.fill){if(s.fill instanceof Vr){const n=s.fill,o=e.createPattern(n.texture.source.resource,"repeat"),c=n.transform.copyTo(B.shared);return c.scale(n.texture.frame.width,n.texture.frame.height),o.setTransform(c),o}else if(s.fill instanceof Ke){const n=s.fill,o=n.type==="linear",c=n.textureSpace==="local";let l=1,d=1;c&&t&&(l=t.width+r,d=t.height+r);let f,m=!1;if(o){const{start:g,end:_}=n;f=e.createLinearGradient(g.x*l,g.y*d,_.x*l,_.y*d),m=Math.abs(_.x-g.x)<Math.abs((_.y-g.y)*.1)}else{const{center:g,innerRadius:_,outerCenter:y,outerRadius:a}=n;f=e.createRadialGradient(g.x*l,g.y*d,_*l,y.x*l,y.y*d,a*l)}if(m&&c&&t){const g=t.lineHeight/d;for(let _=0;_<t.lines.length;_++){const y=(_*t.lineHeight+r/2)/d;n.colorStops.forEach(a=>{const h=y+a.offset*g;f.addColorStop(Math.floor(h*Ec)/Ec,le.shared.setValue(a.color).toHex())})}}else n.colorStops.forEach(g=>{f.addColorStop(g.offset,le.shared.setValue(g.color).toHex())});return f}}else{const n=e.createPattern(s.texture.source.resource,"repeat"),o=s.matrix.copyTo(B.shared);return o.scale(s.texture.frame.width,s.texture.frame.height),n.setTransform(o),n}return G("FillStyle not recognised",s),"red"}const Ic=class yd extends Ol{constructor(e){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentMaxCharHeight=0,this._currentPageIndex=-1,this._skipKerning=!1;const t={...yd.defaultOptions,...e};this._textureSize=t.textureSize,this._mipmap=t.mipmap;const r=t.style.clone();t.overrideFill&&(r._fill.color=16777215,r._fill.alpha=1,r._fill.texture=F.WHITE,r._fill.fill=null),this.applyFillAsTint=t.overrideFill;const n=r.fontSize;r.fontSize=this.baseMeasurementFontSize;const o=Wr(r);t.overrideSize?r._stroke&&(r._stroke.width*=this.baseRenderedFontSize/n):r.fontSize=this.baseRenderedFontSize=n,this._style=r,this._skipKerning=t.skipKerning??!1,this.resolution=t.resolution??1,this._padding=t.padding??4,t.textureStyle&&(this._textureStyle=t.textureStyle instanceof at?t.textureStyle:new at(t.textureStyle)),this.fontMetrics=He.measureFont(o),this.lineHeight=r.lineHeight||this.fontMetrics.fontSize||r.fontSize}ensureCharacters(e){const t=He.graphemeSegmenter(e).filter(u=>!this._currentChars.includes(u)).filter((u,p,v)=>v.indexOf(u)===p);if(!t.length)return;this._currentChars=[...this._currentChars,...t];let r;this._currentPageIndex===-1?r=this._nextPage():r=this.pages[this._currentPageIndex];let{canvas:n,context:o}=r.canvasAndContext,c=r.texture.source;const l=this._style;let d=this._currentX,f=this._currentY,m=this._currentMaxCharHeight;const g=this.baseRenderedFontSize/this.baseMeasurementFontSize,_=this._padding*g;let y=!1;const a=n.width/this.resolution,h=n.height/this.resolution;for(let u=0;u<t.length;u++){const p=t[u],v=He.measureText(p,l,n,!1);v.lineHeight=v.height;const x=v.width*g,b=Math.ceil((l.fontStyle==="italic"?2:1)*x),T=v.height*g,w=b+_*2,S=T+_*2;if(y=!1,p!==`
|
|
318
|
-
`&&p!=="\r"&&p!==" "&&p!==" "&&(y=!0,m=Math.ceil(Math.max(S,m))),d+w>a&&(f+=m,m=S,d=0,f+m>h)){c.update();const A=this._nextPage();n=A.canvasAndContext.canvas,o=A.canvasAndContext.context,c=A.texture.source,d=0,f=0,m=0}const E=x/g-(l.dropShadow?.distance??0)-(l._stroke?.width??0);if(this.chars[p]={id:p.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:E,kerning:{}},y){this._drawGlyph(o,v,d+_,f+_,g,l);const A=c.width*g,P=c.height*g,I=new z(d/A*c.width,f/P*c.height,w/A*c.width,S/P*c.height);this.chars[p].texture=new F({source:c,frame:I}),d+=Math.ceil(w)}}c.update(),this._currentX=d,this._currentY=f,this._currentMaxCharHeight=m,this._skipKerning&&this._applyKerning(t,o)}get pageTextures(){return H(j,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}_applyKerning(e,t){const r=this._measureCache;for(let n=0;n<e.length;n++){const o=e[n];for(let c=0;c<this._currentChars.length;c++){const l=this._currentChars[c];let d=r[o];d||(d=r[o]=t.measureText(o).width);let f=r[l];f||(f=r[l]=t.measureText(l).width);let m=t.measureText(o+l).width,g=m-(d+f);g&&(this.chars[o].kerning[l]=g),m=t.measureText(o+l).width,g=m-(d+f),g&&(this.chars[l].kerning[o]=g)}}}_nextPage(){this._currentPageIndex++;const e=this.resolution,t=xt.getOptimalCanvasAndContext(this._textureSize,this._textureSize,e);this._setupContext(t.context,this._style,e);const r=e*(this.baseRenderedFontSize/this.baseMeasurementFontSize),n=new F({source:new ct({resource:t.canvas,resolution:r,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(n.source.style=this._textureStyle);const o={canvasAndContext:t,texture:n};return this.pages[this._currentPageIndex]=o,o}_setupContext(e,t,r){t.fontSize=this.baseRenderedFontSize,e.scale(r,r),e.font=Wr(t),t.fontSize=this.baseMeasurementFontSize,e.textBaseline=t.textBaseline;const n=t._stroke,o=n?.width??0;if(n&&(e.lineWidth=o,e.lineJoin=n.join,e.miterLimit=n.miterLimit,e.strokeStyle=Zr(n,e)),t._fill&&(e.fillStyle=Zr(t._fill,e)),t.dropShadow){const c=t.dropShadow,l=le.shared.setValue(c.color).toArray(),d=c.blur*r,f=c.distance*r;e.shadowColor=`rgba(${l[0]*255},${l[1]*255},${l[2]*255},${c.alpha})`,e.shadowBlur=d,e.shadowOffsetX=Math.cos(c.angle)*f,e.shadowOffsetY=Math.sin(c.angle)*f}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0}_drawGlyph(e,t,r,n,o,c){const l=t.text,d=t.fontProperties,m=(c._stroke?.width??0)*o,g=r+m/2,_=n-m/2,y=d.descent*o,a=t.lineHeight*o;let h=!1;c.stroke&&m&&(h=!0,e.strokeText(l,g,_+a-y));const{shadowBlur:u,shadowOffsetX:p,shadowOffsetY:v}=e;c._fill&&(h&&(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0),e.fillText(l,g,_+a-y)),h&&(e.shadowBlur=u,e.shadowOffsetX=p,e.shadowOffsetY=v)}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{canvasAndContext:t,texture:r}=this.pages[e];xt.returnCanvasAndContext(t),r.destroy(!0)}this.pages=null}};Ic.defaultOptions={textureSize:512,style:new
|
|
317
|
+
`}},sc={};function In(s){let e=sc[s];if(e)return e;const t=new Int32Array(s);for(let r=0;r<s;r++)t[r]=r;return e=sc[s]=new Ue({uTextures:{value:t,type:"i32",size:s}},{isStatic:!0}),e}class nc extends qe{constructor(e){const t=Xi({name:"batch",bits:[wn,En(e),qi]}),r=Yi({name:"batch",bits:[Tn,Cn(e),$i]});super({glProgram:t,gpuProgram:r,resources:{batchSamplers:In(e)}}),this.maxTextures=e}}let Ki=null;const oc=class _d extends ig{constructor(e){super(e),this.geometry=new ag,this.name=_d.extension.name,this.vertexSize=6,Ki??(Ki=new nc(e.maxTextures)),this.shader=Ki}packAttributes(e,t,r,n,o){const c=o<<16|e.roundPixels&65535,l=e.transform,d=l.a,f=l.b,m=l.c,g=l.d,_=l.tx,y=l.ty,{positions:a,uvs:h}=e,u=e.color,p=e.attributeOffset,v=p+e.attributeSize;for(let x=p;x<v;x++){const b=x*2,T=a[b],w=a[b+1];t[n++]=d*T+m*w+_,t[n++]=g*w+f*T+y,t[n++]=h[b],t[n++]=h[b+1],r[n++]=u,r[n++]=c}}packQuadAttributes(e,t,r,n,o){const c=e.texture,l=e.transform,d=l.a,f=l.b,m=l.c,g=l.d,_=l.tx,y=l.ty,a=e.bounds,h=a.maxX,u=a.minX,p=a.maxY,v=a.minY,x=c.uvs,b=e.color,T=o<<16|e.roundPixels&65535;t[n+0]=d*u+m*v+_,t[n+1]=g*v+f*u+y,t[n+2]=x.x0,t[n+3]=x.y0,r[n+4]=b,r[n+5]=T,t[n+6]=d*h+m*v+_,t[n+7]=g*v+f*h+y,t[n+8]=x.x1,t[n+9]=x.y1,r[n+10]=b,r[n+11]=T,t[n+12]=d*h+m*p+_,t[n+13]=g*p+f*h+y,t[n+14]=x.x2,t[n+15]=x.y2,r[n+16]=b,r[n+17]=T,t[n+18]=d*u+m*p+_,t[n+19]=g*p+f*u+y,t[n+20]=x.x3,t[n+21]=x.y3,r[n+22]=b,r[n+23]=T}_updateMaxTextures(e){this.shader.maxTextures!==e&&(Ki=new nc(e),this.shader=Ki)}destroy(){this.shader=null,super.destroy()}};oc.extension={type:[C.Batcher],name:"default"};let Pn=oc;function Cg(s,e,t,r,n,o,c,l=null){let d=0;t*=e,n*=o;const f=l.a,m=l.b,g=l.c,_=l.d,y=l.tx,a=l.ty;for(;d<c;){const h=s[t],u=s[t+1];r[n]=f*h+g*u+y,r[n+1]=m*h+_*u+a,n+=o,t+=e,d++}}function Ag(s,e,t,r){let n=0;for(e*=t;n<r;)s[e]=0,s[e+1]=0,e+=t,n++}function ac(s,e,t,r,n){const o=e.a,c=e.b,l=e.c,d=e.d,f=e.tx,m=e.ty;t||(t=0),r||(r=2),n||(n=s.length/r-t);let g=t*r;for(let _=0;_<n;_++){const y=s[g],a=s[g+1];s[g]=o*y+l*a+f,s[g+1]=c*y+d*a+m,g+=r}}const Eg=new B;class Rn{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,r=this.renderable;return r?ka(t,r.groupColor)+(this.alpha*r.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||Eg}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 ji={extension:{type:C.ShapeBuilder,name:"circle"},build(s,e){let t,r,n,o,c,l;if(s.type==="circle"){const b=s;if(c=l=b.radius,c<=0)return!1;t=b.x,r=b.y,n=o=0}else if(s.type==="ellipse"){const b=s;if(c=b.halfWidth,l=b.halfHeight,c<=0||l<=0)return!1;t=b.x,r=b.y,n=o=0}else{const b=s,T=b.width/2,w=b.height/2;t=b.x+T,r=b.y+w,c=l=Math.max(0,Math.min(b.radius,Math.min(T,w))),n=T-c,o=w-l}if(n<0||o<0)return!1;const d=Math.ceil(2.3*Math.sqrt(c+l)),f=d*8+(n?4:0)+(o?4:0);if(f===0)return!1;if(d===0)return e[0]=e[6]=t+n,e[1]=e[3]=r+o,e[2]=e[4]=t-n,e[5]=e[7]=r-o,!0;let m=0,g=d*4+(n?2:0)+2,_=g,y=f,a=n+c,h=o,u=t+a,p=t-a,v=r+h;if(e[m++]=u,e[m++]=v,e[--g]=v,e[--g]=p,o){const b=r-h;e[_++]=p,e[_++]=b,e[--y]=b,e[--y]=u}for(let b=1;b<d;b++){const T=Math.PI/2*(b/d),w=n+Math.cos(T)*c,S=o+Math.sin(T)*l,E=t+w,A=t-w,P=r+S,I=r-S;e[m++]=E,e[m++]=P,e[--g]=P,e[--g]=A,e[_++]=A,e[_++]=I,e[--y]=I,e[--y]=E}a=n,h=o+l,u=t+a,p=t-a,v=r+h;const x=r-h;return e[m++]=u,e[m++]=v,e[--y]=x,e[--y]=u,n&&(e[m++]=p,e[m++]=v,e[--y]=x,e[--y]=p),!0},triangulate(s,e,t,r,n,o){if(s.length===0)return;let c=0,l=0;for(let m=0;m<s.length;m+=2)c+=s[m],l+=s[m+1];c/=s.length/2,l/=s.length/2;let d=r;e[d*t]=c,e[d*t+1]=l;const f=d++;for(let m=0;m<s.length;m+=2)e[d*t]=s[m],e[d*t+1]=s[m+1],m>0&&(n[o++]=d,n[o++]=f,n[o++]=d-1),d++;n[o++]=f+1,n[o++]=f,n[o++]=d-1}},Ig={...ji,extension:{...ji.extension,name:"ellipse"}},Pg={...ji,extension:{...ji.extension,name:"roundedRectangle"}},lc=1e-4,cc=1e-4;function Rg(s){const e=s.length;if(e<6)return 1;let t=0;for(let r=0,n=s[e-2],o=s[e-1];r<e;r+=2){const c=s[r],l=s[r+1];t+=(c-n)*(l+o),n=c,o=l}return t<0?-1:1}function hc(s,e,t,r,n,o,c,l){const d=s-t*n,f=e-r*n,m=s+t*o,g=e+r*o;let _,y;c?(_=r,y=-t):(_=-r,y=t);const a=d+_,h=f+y,u=m+_,p=g+y;return l.push(a,h),l.push(u,p),2}function Nt(s,e,t,r,n,o,c,l){const d=t-s,f=r-e;let m=Math.atan2(d,f),g=Math.atan2(n-s,o-e);l&&m<g?m+=Math.PI*2:!l&&m>g&&(g+=Math.PI*2);let _=m;const y=g-m,a=Math.abs(y),h=Math.sqrt(d*d+f*f),u=(15*a*Math.sqrt(h)/Math.PI>>0)+1,p=y/u;if(_+=p,l){c.push(s,e),c.push(t,r);for(let v=1,x=_;v<u;v++,x+=p)c.push(s,e),c.push(s+Math.sin(x)*h,e+Math.cos(x)*h);c.push(s,e),c.push(n,o)}else{c.push(t,r),c.push(s,e);for(let v=1,x=_;v<u;v++,x+=p)c.push(s+Math.sin(x)*h,e+Math.cos(x)*h),c.push(s,e);c.push(n,o),c.push(s,e)}return u*2}function Mg(s,e,t,r,n,o){const c=lc;if(s.length===0)return;const l=e;let d=l.alignment;if(e.alignment!==.5){let N=Rg(s);d=(d-.5)*N+.5}const f=new J(s[0],s[1]),m=new J(s[s.length-2],s[s.length-1]),g=r,_=Math.abs(f.x-m.x)<c&&Math.abs(f.y-m.y)<c;if(g){s=s.slice(),_&&(s.pop(),s.pop(),m.set(s[s.length-2],s[s.length-1]));const N=(f.x+m.x)*.5,ee=(m.y+f.y)*.5;s.unshift(N,ee),s.push(N,ee)}const y=n,a=s.length/2;let h=s.length;const u=y.length/2,p=l.width/2,v=p*p,x=l.miterLimit*l.miterLimit;let b=s[0],T=s[1],w=s[2],S=s[3],E=0,A=0,P=-(T-S),I=b-w,k=0,O=0,X=Math.sqrt(P*P+I*I);P/=X,I/=X,P*=p,I*=p;const ne=d,R=(1-ne)*2,M=ne*2;g||(l.cap==="round"?h+=Nt(b-P*(R-M)*.5,T-I*(R-M)*.5,b-P*R,T-I*R,b+P*M,T+I*M,y,!0)+2:l.cap==="square"&&(h+=hc(b,T,P,I,R,M,!0,y))),y.push(b-P*R,T-I*R),y.push(b+P*M,T+I*M);for(let N=1;N<a-1;++N){b=s[(N-1)*2],T=s[(N-1)*2+1],w=s[N*2],S=s[N*2+1],E=s[(N+1)*2],A=s[(N+1)*2+1],P=-(T-S),I=b-w,X=Math.sqrt(P*P+I*I),P/=X,I/=X,P*=p,I*=p,k=-(S-A),O=w-E,X=Math.sqrt(k*k+O*O),k/=X,O/=X,k*=p,O*=p;const ee=w-b,he=T-S,ye=w-E,U=A-S,Ie=ee*ye+he*U,Y=he*ye-U*ee,Q=Y<0;if(Math.abs(Y)<.001*Math.abs(Ie)){y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),Ie>=0&&(l.join==="round"?h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+4:h+=2,y.push(w-k*M,S-O*M),y.push(w+k*R,S+O*R));continue}const xe=(-P+b)*(-I+S)-(-P+w)*(-I+T),Pe=(-k+E)*(-O+S)-(-k+w)*(-O+A),_i=(ee*Pe-ye*xe)/Y,Ut=(U*xe-he*Pe)/Y,ht=(_i-w)*(_i-w)+(Ut-S)*(Ut-S),Ge=w+(_i-w)*R,nt=S+(Ut-S)*R,Yt=w-(_i-w)*M,Xt=S-(Ut-S)*M,p2=Math.min(ee*ee+he*he,ye*ye+U*U),ad=Q?R:M,m2=p2+ad*ad*v;ht<=m2?l.join==="bevel"||ht/v>x?(Q?(y.push(Ge,nt),y.push(w+P*M,S+I*M),y.push(Ge,nt),y.push(w+k*M,S+O*M)):(y.push(w-P*R,S-I*R),y.push(Yt,Xt),y.push(w-k*R,S-O*R),y.push(Yt,Xt)),h+=2):l.join==="round"?Q?(y.push(Ge,nt),y.push(w+P*M,S+I*M),h+=Nt(w,S,w+P*M,S+I*M,w+k*M,S+O*M,y,!0)+4,y.push(Ge,nt),y.push(w+k*M,S+O*M)):(y.push(w-P*R,S-I*R),y.push(Yt,Xt),h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+4,y.push(w-k*R,S-O*R),y.push(Yt,Xt)):(y.push(Ge,nt),y.push(Yt,Xt)):(y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),l.join==="round"?Q?h+=Nt(w,S,w+P*M,S+I*M,w+k*M,S+O*M,y,!0)+2:h+=Nt(w,S,w-P*R,S-I*R,w-k*R,S-O*R,y,!1)+2:l.join==="miter"&&ht/v<=x&&(Q?(y.push(Yt,Xt),y.push(Yt,Xt)):(y.push(Ge,nt),y.push(Ge,nt)),h+=2),y.push(w-k*R,S-O*R),y.push(w+k*M,S+O*M),h+=2)}b=s[(a-2)*2],T=s[(a-2)*2+1],w=s[(a-1)*2],S=s[(a-1)*2+1],P=-(T-S),I=b-w,X=Math.sqrt(P*P+I*I),P/=X,I/=X,P*=p,I*=p,y.push(w-P*R,S-I*R),y.push(w+P*M,S+I*M),g||(l.cap==="round"?h+=Nt(w-P*(R-M)*.5,S-I*(R-M)*.5,w-P*R,S-I*R,w+P*M,S+I*M,y,!1)+2:l.cap==="square"&&(h+=hc(w,S,P,I,R,M,!1,y)));const q=cc*cc;for(let N=u;N<h+u-2;++N)b=y[N*2],T=y[N*2+1],w=y[(N+1)*2],S=y[(N+1)*2+1],E=y[(N+2)*2],A=y[(N+2)*2+1],!(Math.abs(b*(S-A)+w*(A-T)+E*(T-S))<q)&&o.push(N,N+1,N+2)}function Fg(s,e,t,r){const n=lc;if(s.length===0)return;const o=s[0],c=s[1],l=s[s.length-2],d=s[s.length-1],f=e||Math.abs(o-l)<n&&Math.abs(c-d)<n,m=t,g=s.length/2,_=m.length/2;for(let y=0;y<g;y++)m.push(s[y*2]),m.push(s[y*2+1]);for(let y=0;y<g-1;y++)r.push(_+y,_+y+1);f&&r.push(_+g-1,_)}function uc(s,e,t,r,n,o,c){const l=km(s,e,2);if(!l)return;for(let f=0;f<l.length;f+=3)o[c++]=l[f]+n,o[c++]=l[f+1]+n,o[c++]=l[f+2]+n;let d=n*r;for(let f=0;f<s.length;f+=2)t[d]=s[f],t[d+1]=s[f+1],d+=r}const Ug=[],kg={extension:{type:C.ShapeBuilder,name:"polygon"},build(s,e){for(let t=0;t<s.points.length;t++)e[t]=s.points[t];return!0},triangulate(s,e,t,r,n,o){uc(s,Ug,e,t,r,n,o)}},Bg={extension:{type:C.ShapeBuilder,name:"rectangle"},build(s,e){const t=s,r=t.x,n=t.y,o=t.width,c=t.height;return o>0&&c>0?(e[0]=r,e[1]=n,e[2]=r+o,e[3]=n,e[4]=r+o,e[5]=n+c,e[6]=r,e[7]=n+c,!0):!1},triangulate(s,e,t,r,n,o){let c=0;r*=t,e[r+c]=s[0],e[r+c+1]=s[1],c+=t,e[r+c]=s[2],e[r+c+1]=s[3],c+=t,e[r+c]=s[6],e[r+c+1]=s[7],c+=t,e[r+c]=s[4],e[r+c+1]=s[5],c+=t;const l=r/t;n[o++]=l,n[o++]=l+1,n[o++]=l+2,n[o++]=l+1,n[o++]=l+3,n[o++]=l+2}},Dg={extension:{type:C.ShapeBuilder,name:"triangle"},build(s,e){return e[0]=s.x,e[1]=s.y,e[2]=s.x2,e[3]=s.y2,e[4]=s.x3,e[5]=s.y3,!0},triangulate(s,e,t,r,n,o){let c=0;r*=t,e[r+c]=s[0],e[r+c+1]=s[1],c+=t,e[r+c]=s[2],e[r+c+1]=s[3],c+=t,e[r+c]=s[4],e[r+c+1]=s[5];const l=r/t;n[o++]=l,n[o++]=l+1,n[o++]=l+2}},Og=new B,Gg=new z;function Lg(s,e,t,r){const n=e.matrix?s.copyFrom(e.matrix).invert():s.identity();if(e.textureSpace==="local"){const c=t.getBounds(Gg);e.width&&c.pad(e.width);const{x:l,y:d}=c,f=1/c.width,m=1/c.height,g=-l*f,_=-d*m,y=n.a,a=n.b,h=n.c,u=n.d;n.a*=f,n.b*=f,n.c*=m,n.d*=m,n.tx=g*y+_*h+n.tx,n.ty=g*a+_*u+n.ty}else n.translate(e.texture.frame.x,e.texture.frame.y),n.scale(1/e.texture.source.width,1/e.texture.source.height);const o=e.texture.source.style;return!(e.fill instanceof Ke)&&o.addressMode==="clamp-to-edge"&&(o.addressMode="repeat",o.update()),r&&n.append(Og.copyFrom(r).invert()),n}const qr={};L.handleByMap(C.ShapeBuilder,qr),L.add(Bg,kg,Dg,ji,Ig,Pg);const Ng=new z,zg=new B;function Hg(s,e){const{geometryData:t,batches:r}=e;r.length=0,t.indices.length=0,t.vertices.length=0,t.uvs.length=0;for(let n=0;n<s.instructions.length;n++){const o=s.instructions[n];if(o.action==="texture")Wg(o.data,r,t);else if(o.action==="fill"||o.action==="stroke"){const c=o.action==="stroke",l=o.data.path.shapePath,d=o.data.style,f=o.data.hole;c&&f&&dc(f.shapePath,d,!0,r,t),f&&(l.shapePrimitives[l.shapePrimitives.length-1].holes=f.shapePath.shapePrimitives),dc(l,d,c,r,t)}}}function Wg(s,e,t){const r=[],n=qr.rectangle,o=Ng;o.x=s.dx,o.y=s.dy,o.width=s.dw,o.height=s.dh;const c=s.transform;if(!n.build(o,r))return;const{vertices:l,uvs:d,indices:f}=t,m=f.length,g=l.length/2;c&&ac(r,c),n.triangulate(r,l,2,g,f,m);const _=s.image,y=_.uvs;d.push(y.x0,y.y0,y.x1,y.y1,y.x3,y.y3,y.x2,y.y2);const a=me.get(Rn);a.indexOffset=m,a.indexSize=f.length-m,a.attributeOffset=g,a.attributeSize=l.length/2-g,a.baseColor=s.style,a.alpha=s.alpha,a.texture=_,a.geometryData=t,e.push(a)}function dc(s,e,t,r,n){const{vertices:o,uvs:c,indices:l}=n;s.shapePrimitives.forEach(({shape:d,transform:f,holes:m})=>{const g=[],_=qr[d.type];if(!_.build(d,g))return;const y=l.length,a=o.length/2;let h="triangle-list";if(f&&ac(g,f),t){const x=d.closePath??!0,b=e;b.pixelLine?(Fg(g,x,o,l),h="line-list"):Mg(g,b,!1,x,o,l)}else if(m){const x=[],b=g.slice();Vg(m).forEach(w=>{x.push(b.length/2),b.push(...w)}),uc(b,x,o,2,a,l,y)}else _.triangulate(g,o,2,a,l,y);const u=c.length/2,p=e.texture;if(p!==F.WHITE){const x=Lg(zg,e,d,f);Cg(o,2,a,c,u,2,o.length/2-a,x)}else Ag(c,u,2,o.length/2-a);const v=me.get(Rn);v.indexOffset=y,v.indexSize=l.length-y,v.attributeOffset=a,v.attributeSize=o.length/2-a,v.baseColor=e.color,v.alpha=e.alpha,v.texture=p,v.geometryData=n,v.topology=h,r.push(v)})}function Vg(s){const e=[];for(let t=0;t<s.length;t++){const r=s[t].shape,n=[];qr[r.type].build(r,n)&&e.push(n)}return e}class Yg{constructor(){this.batches=[],this.geometryData={vertices:[],uvs:[],indices:[]}}}class Xg{constructor(){this.instructions=new Ga}init(e){const t=e.maxTextures;this.batcher?this.batcher._updateMaxTextures(t):this.batcher=new Pn({maxTextures:t}),this.instructions.reset()}get geometry(){return H(ip,"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 Mn=class ko{constructor(e){this._gpuContextHash={},this._graphicsDataContextHash=Object.create(null),this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuContextHash"),e.renderableGC.addManagedHash(this,"_graphicsDataContextHash")}init(e){ko.defaultOptions.bezierSmoothness=e?.bezierSmoothness??ko.defaultOptions.bezierSmoothness}getContextRenderData(e){return this._graphicsDataContextHash[e.uid]||this._initContextRenderData(e)}updateGpuContext(e){let t=this._gpuContextHash[e.uid]||this._initContext(e);if(e.dirty){t?this._cleanGraphicsContextData(e):t=this._initContext(e),Hg(e,t);const r=e.batchMode;e.customShader||r==="no-batch"?t.isBatchable=!1:r==="auto"?t.isBatchable=t.geometryData.vertices.length<400:t.isBatchable=!0,e.dirty=!1}return t}getGpuContext(e){return this._gpuContextHash[e.uid]||this._initContext(e)}_initContextRenderData(e){const t=me.get(Xg,{maxTextures:this._renderer.limits.maxBatchableTextures}),{batches:r,geometryData:n}=this._gpuContextHash[e.uid],o=n.vertices.length,c=n.indices.length;for(let m=0;m<r.length;m++)r[m].applyTransform=!1;const l=t.batcher;l.ensureAttributeBuffer(o),l.ensureIndexBuffer(c),l.begin();for(let m=0;m<r.length;m++){const g=r[m];l.add(g)}l.finish(t.instructions);const d=l.geometry;d.indexBuffer.setDataWithSize(l.indexBuffer,l.indexSize,!0),d.buffers[0].setDataWithSize(l.attributeBuffer.float32View,l.attributeSize,!0);const f=l.batches;for(let m=0;m<f.length;m++){const g=f[m];g.bindGroup=yn(g.textures.textures,g.textures.count,this._renderer.limits.maxBatchableTextures)}return this._graphicsDataContextHash[e.uid]=t,t}_initContext(e){const t=new Yg;return t.context=e,this._gpuContextHash[e.uid]=t,e.on("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]}onGraphicsContextDestroy(e){this._cleanGraphicsContextData(e),e.off("destroy",this.onGraphicsContextDestroy,this),this._gpuContextHash[e.uid]=null}_cleanGraphicsContextData(e){const t=this._gpuContextHash[e.uid];t.isBatchable||this._graphicsDataContextHash[e.uid]&&(me.return(this.getContextRenderData(e)),this._graphicsDataContextHash[e.uid]=null),t.batches&&t.batches.forEach(r=>{me.return(r)})}destroy(){for(const e in this._gpuContextHash)this._gpuContextHash[e]&&this.onGraphicsContextDestroy(this._gpuContextHash[e].context);this._gpuContextHash={},this._graphicsDataContextHash={},this._renderer=null}};Mn.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"graphicsContext"},Mn.defaultOptions={bezierSmoothness:.5};let Fn=Mn;const $g=8,Kr=11920929e-14,qg=1;function fc(s,e,t,r,n,o,c,l,d,f){const g=Math.min(.99,Math.max(0,f??Fn.defaultOptions.bezierSmoothness));let _=(qg-g)/1;return _*=_,Kg(e,t,r,n,o,c,l,d,s,_),s}function Kg(s,e,t,r,n,o,c,l,d,f){Un(s,e,t,r,n,o,c,l,d,f,0),d.push(c,l)}function Un(s,e,t,r,n,o,c,l,d,f,m){if(m>$g)return;const g=(s+t)/2,_=(e+r)/2,y=(t+n)/2,a=(r+o)/2,h=(n+c)/2,u=(o+l)/2,p=(g+y)/2,v=(_+a)/2,x=(y+h)/2,b=(a+u)/2,T=(p+x)/2,w=(v+b)/2;if(m>0){let S=c-s,E=l-e;const A=Math.abs((t-c)*E-(r-l)*S),P=Math.abs((n-c)*E-(o-l)*S);if(A>Kr&&P>Kr){if((A+P)*(A+P)<=f*(S*S+E*E)){d.push(T,w);return}}else if(A>Kr){if(A*A<=f*(S*S+E*E)){d.push(T,w);return}}else if(P>Kr){if(P*P<=f*(S*S+E*E)){d.push(T,w);return}}else if(S=T-(s+c)/2,E=w-(e+l)/2,S*S+E*E<=f){d.push(T,w);return}}Un(s,e,g,_,p,v,T,w,d,f,m+1),Un(T,w,x,b,h,u,c,l,d,f,m+1)}const jg=8,Zg=11920929e-14,Jg=1;function Qg(s,e,t,r,n,o,c,l){const f=Math.min(.99,Math.max(0,l??Fn.defaultOptions.bezierSmoothness));let m=(Jg-f)/1;return m*=m,e0(e,t,r,n,o,c,s,m),s}function e0(s,e,t,r,n,o,c,l){kn(c,s,e,t,r,n,o,l,0),c.push(n,o)}function kn(s,e,t,r,n,o,c,l,d){if(d>jg)return;const f=(e+r)/2,m=(t+n)/2,g=(r+o)/2,_=(n+c)/2,y=(f+g)/2,a=(m+_)/2;let h=o-e,u=c-t;const p=Math.abs((r-o)*u-(n-c)*h);if(p>Zg){if(p*p<=l*(h*h+u*u)){s.push(y,a);return}}else if(h=y-(e+o)/2,u=a-(t+c)/2,h*h+u*u<=l){s.push(y,a);return}kn(s,e,t,f,m,y,a,l,d+1),kn(s,y,a,g,_,o,c,l,d+1)}function pc(s,e,t,r,n,o,c,l){let d=Math.abs(n-o);(!c&&n>o||c&&o>n)&&(d=2*Math.PI-d),l||(l=Math.max(6,Math.floor(6*Math.pow(r,1/3)*(d/Math.PI)))),l=Math.max(l,3);let f=d/l,m=n;f*=c?-1:1;for(let g=0;g<l+1;g++){const _=Math.cos(m),y=Math.sin(m),a=e+_*r,h=t+y*r;s.push(a,h),m+=f}}function t0(s,e,t,r,n,o){const c=s[s.length-2],d=s[s.length-1]-t,f=c-e,m=n-t,g=r-e,_=Math.abs(d*g-f*m);if(_<1e-8||o===0){(s[s.length-2]!==e||s[s.length-1]!==t)&&s.push(e,t);return}const y=d*d+f*f,a=m*m+g*g,h=d*m+f*g,u=o*Math.sqrt(y)/_,p=o*Math.sqrt(a)/_,v=u*h/y,x=p*h/a,b=u*g+p*f,T=u*m+p*d,w=f*(p+v),S=d*(p+v),E=g*(u+x),A=m*(u+x),P=Math.atan2(S-T,w-b),I=Math.atan2(A-T,E-b);pc(s,b+e,T+t,o,P,I,f*m>g*d)}const Zi=Math.PI*2,Bn={centerX:0,centerY:0,ang1:0,ang2:0},Dn=({x:s,y:e},t,r,n,o,c,l,d)=>{s*=t,e*=r;const f=n*s-o*e,m=o*s+n*e;return d.x=f+c,d.y=m+l,d};function i0(s,e){const t=e===-1.5707963267948966?-.551915024494:1.3333333333333333*Math.tan(e/4),r=e===1.5707963267948966?.551915024494:t,n=Math.cos(s),o=Math.sin(s),c=Math.cos(s+e),l=Math.sin(s+e);return[{x:n-o*r,y:o+n*r},{x:c+l*r,y:l-c*r},{x:c,y:l}]}const mc=(s,e,t,r)=>{const n=s*r-e*t<0?-1:1;let o=s*t+e*r;return o>1&&(o=1),o<-1&&(o=-1),n*Math.acos(o)},r0=(s,e,t,r,n,o,c,l,d,f,m,g,_)=>{const y=Math.pow(n,2),a=Math.pow(o,2),h=Math.pow(m,2),u=Math.pow(g,2);let p=y*a-y*u-a*h;p<0&&(p=0),p/=y*u+a*h,p=Math.sqrt(p)*(c===l?-1:1);const v=p*n/o*g,x=p*-o/n*m,b=f*v-d*x+(s+t)/2,T=d*v+f*x+(e+r)/2,w=(m-v)/n,S=(g-x)/o,E=(-m-v)/n,A=(-g-x)/o,P=mc(1,0,w,S);let I=mc(w,S,E,A);l===0&&I>0&&(I-=Zi),l===1&&I<0&&(I+=Zi),_.centerX=b,_.centerY=T,_.ang1=P,_.ang2=I};function s0(s,e,t,r,n,o,c,l=0,d=0,f=0){if(o===0||c===0)return;const m=Math.sin(l*Zi/360),g=Math.cos(l*Zi/360),_=g*(e-r)/2+m*(t-n)/2,y=-m*(e-r)/2+g*(t-n)/2;if(_===0&&y===0)return;o=Math.abs(o),c=Math.abs(c);const a=Math.pow(_,2)/Math.pow(o,2)+Math.pow(y,2)/Math.pow(c,2);a>1&&(o*=Math.sqrt(a),c*=Math.sqrt(a)),r0(e,t,r,n,o,c,d,f,m,g,_,y,Bn);let{ang1:h,ang2:u}=Bn;const{centerX:p,centerY:v}=Bn;let x=Math.abs(u)/(Zi/4);Math.abs(1-x)<1e-7&&(x=1);const b=Math.max(Math.ceil(x),1);u/=b;let T=s[s.length-2],w=s[s.length-1];const S={x:0,y:0};for(let E=0;E<b;E++){const A=i0(h,u),{x:P,y:I}=Dn(A[0],o,c,g,m,p,v,S),{x:k,y:O}=Dn(A[1],o,c,g,m,p,v,S),{x:X,y:ne}=Dn(A[2],o,c,g,m,p,v,S);fc(s,T,w,P,I,k,O,X,ne),T=X,w=ne,h+=u}}function n0(s,e,t){const r=(c,l)=>{const d=l.x-c.x,f=l.y-c.y,m=Math.sqrt(d*d+f*f),g=d/m,_=f/m;return{len:m,nx:g,ny:_}},n=(c,l)=>{c===0?s.moveTo(l.x,l.y):s.lineTo(l.x,l.y)};let o=e[e.length-1];for(let c=0;c<e.length;c++){const l=e[c%e.length],d=l.radius??t;if(d<=0){n(c,l),o=l;continue}const f=e[(c+1)%e.length],m=r(l,o),g=r(l,f);if(m.len<1e-4||g.len<1e-4){n(c,l),o=l;continue}let _=Math.asin(m.nx*g.ny-m.ny*g.nx),y=1,a=!1;m.nx*g.nx-m.ny*-g.ny<0?_<0?_=Math.PI+_:(_=Math.PI-_,y=-1,a=!0):_>0&&(y=-1,a=!0);const h=_/2;let u,p=Math.abs(Math.cos(h)*d/Math.sin(h));p>Math.min(m.len/2,g.len/2)?(p=Math.min(m.len/2,g.len/2),u=Math.abs(p*Math.sin(h)/Math.cos(h))):u=d;const v=l.x+g.nx*p+-g.ny*u*y,x=l.y+g.ny*p+g.nx*u*y,b=Math.atan2(m.ny,m.nx)+Math.PI/2*y,T=Math.atan2(g.ny,g.nx)-Math.PI/2*y;c===0&&s.moveTo(v+Math.cos(b)*u,x+Math.sin(b)*u),s.arc(v,x,u,b,T,a),o=l}}function o0(s,e,t,r){const n=(l,d)=>Math.sqrt((l.x-d.x)**2+(l.y-d.y)**2),o=(l,d,f)=>({x:l.x+(d.x-l.x)*f,y:l.y+(d.y-l.y)*f}),c=e.length;for(let l=0;l<c;l++){const d=e[(l+1)%c],f=d.radius??t;if(f<=0){l===0?s.moveTo(d.x,d.y):s.lineTo(d.x,d.y);continue}const m=e[l],g=e[(l+2)%c],_=n(m,d);let y;if(_<1e-4)y=d;else{const u=Math.min(_/2,f);y=o(d,m,u/_)}const a=n(g,d);let h;if(a<1e-4)h=d;else{const u=Math.min(a/2,f);h=o(d,g,u/a)}l===0?s.moveTo(y.x,y.y):s.lineTo(y.x,y.y),s.quadraticCurveTo(d.x,d.y,h.x,h.y,r)}}const a0=new z;class l0{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new Se,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();const r=this._currentPoly.points,n=r[r.length-2],o=r[r.length-1];return(n!==e||o!==t)&&r.push(e,t),this}arc(e,t,r,n,o,c){this._ensurePoly(!1);const l=this._currentPoly.points;return pc(l,e,t,r,n,o,c),this}arcTo(e,t,r,n,o){this._ensurePoly();const c=this._currentPoly.points;return t0(c,e,t,r,n,o),this}arcToSvg(e,t,r,n,o,c,l){const d=this._currentPoly.points;return s0(d,this._currentPoly.lastX,this._currentPoly.lastY,c,l,e,t,r,n,o),this}bezierCurveTo(e,t,r,n,o,c,l){this._ensurePoly();const d=this._currentPoly;return fc(this._currentPoly.points,d.lastX,d.lastY,e,t,r,n,o,c,l),this}quadraticCurveTo(e,t,r,n,o){this._ensurePoly();const c=this._currentPoly;return Qg(this._currentPoly.points,c.lastX,c.lastY,e,t,r,n,o),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));const r=this.shapePrimitives,n=r.length;for(let o=0;o<e.instructions.length;o++){const c=e.instructions[o];this[c.action](...c.data)}if(e.checkForHoles&&r.length-n>1){let o=null;for(let c=n;c<r.length;c++){const l=r[c];if(l.shape.type==="polygon"){const d=l.shape,f=o?.shape;f&&f.containsPolygon(d)?(o.holes||(o.holes=[]),o.holes.push(l),r.copyWithin(c,c+1),r.length--,c--):o=l}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,r,n,o){return this.drawShape(new z(e,t,r,n),o),this}circle(e,t,r,n){return this.drawShape(new Yr(e,t,r),n),this}poly(e,t,r){const n=new Ni(e);return n.closePath=t,this.drawShape(n,r),this}regularPoly(e,t,r,n,o=0,c){n=Math.max(n|0,3);const l=-1*Math.PI/2+o,d=Math.PI*2/n,f=[];for(let m=0;m<n;m++){const g=l-m*d;f.push(e+r*Math.cos(g),t+r*Math.sin(g))}return this.poly(f,!0,c),this}roundPoly(e,t,r,n,o,c=0,l){if(n=Math.max(n|0,3),o<=0)return this.regularPoly(e,t,r,n,c);const d=r*Math.sin(Math.PI/n)-.001;o=Math.min(o,d);const f=-1*Math.PI/2+c,m=Math.PI*2/n,g=(n-2)*Math.PI/n/2;for(let _=0;_<n;_++){const y=_*m+f,a=e+r*Math.cos(y),h=t+r*Math.sin(y),u=y+Math.PI+g,p=y-Math.PI-g,v=a+o*Math.cos(u),x=h+o*Math.sin(u),b=a+o*Math.cos(p),T=h+o*Math.sin(p);_===0?this.moveTo(v,x):this.lineTo(v,x),this.quadraticCurveTo(a,h,b,T,l)}return this.closePath()}roundShape(e,t,r=!1,n){return e.length<3?this:(r?o0(this,e,t,n):n0(this,e,t),this.closePath())}filletRect(e,t,r,n,o){if(o===0)return this.rect(e,t,r,n);const c=Math.min(r,n)/2,l=Math.min(c,Math.max(-c,o)),d=e+r,f=t+n,m=l<0?-l:0,g=Math.abs(l);return this.moveTo(e,t+g).arcTo(e+m,t+m,e+g,t,g).lineTo(d-g,t).arcTo(d-m,t+m,d,t+g,g).lineTo(d,f-g).arcTo(d-m,f-m,e+r-g,f,g).lineTo(e+g,f).arcTo(e+m,f-m,e,f-g,g).closePath()}chamferRect(e,t,r,n,o,c){if(o<=0)return this.rect(e,t,r,n);const l=Math.min(o,Math.min(r,n)/2),d=e+r,f=t+n,m=[e+l,t,d-l,t,d,t+l,d,f-l,d-l,f,e+l,f,e,f-l,e,t+l];for(let g=m.length-1;g>=2;g-=2)m[g]===m[g-2]&&m[g-1]===m[g-3]&&m.splice(g-1,2);return this.poly(m,!0,c)}ellipse(e,t,r,n,o){return this.drawShape(new vn(e,t,r,n),o),this}roundRect(e,t,r,n,o,c){return this.drawShape(new _n(e,t,r,n,o),c),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let r=this._currentPoly;return r&&this.endPoly(),r=new Ni,r.points.push(e,t),this._currentPoly=r,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 Ni,e)){const t=this.shapePrimitives[this.shapePrimitives.length-1];if(t){let r=t.shape.x,n=t.shape.y;if(t.transform&&!t.transform.isIdentity()){const o=t.transform,c=r;r=o.a*r+o.c*n+o.tx,n=o.b*c+o.d*n+o.ty}this._currentPoly.points.push(r,n)}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 r=e.instructions[t];this[r.action](...r.data)}this.finish()}get bounds(){const e=this._bounds;e.clear();const t=this.shapePrimitives;for(let r=0;r<t.length;r++){const n=t[r],o=n.shape.getBounds(a0);n.transform?e.addRect(o,n.transform):e.addRect(o)}return e}}class yt{constructor(e,t=!1){this.instructions=[],this.uid=ae("graphicsPath"),this._dirty=!0,this.checkForHoles=t,typeof e=="string"?Ym(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||(this._shapePath=new l0(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,r,n,o){const c=this.instructions[this.instructions.length-1],l=this.getLastPoint(J.shared);let d=0,f=0;if(!c||c.action!=="bezierCurveTo")d=l.x,f=l.y;else{d=c.data[2],f=c.data[3];const m=l.x,g=l.y;d=m+(m-d),f=g+(g-f)}return this.instructions.push({action:"bezierCurveTo",data:[d,f,e,t,r,n,o]}),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,r){const n=this.instructions[this.instructions.length-1],o=this.getLastPoint(J.shared);let c=0,l=0;if(!n||n.action!=="quadraticCurveTo")c=o.x,l=o.y;else{c=n.data[0],l=n.data[1];const d=o.x,f=o.y;c=d+(d-c),l=f+(f-l)}return this.instructions.push({action:"quadraticCurveTo",data:[c,l,e,t,r]}),this._dirty=!0,this}rect(e,t,r,n,o){return this.instructions.push({action:"rect",data:[e,t,r,n,o]}),this._dirty=!0,this}circle(e,t,r,n){return this.instructions.push({action:"circle",data:[e,t,r,n]}),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,r,n,o,c,l){o||(o=n/2);const d=-1*Math.PI/2+c,f=r*2,m=Math.PI*2/f,g=[];for(let _=0;_<f;_++){const y=_%2?o:n,a=_*m+d;g.push(e+y*Math.cos(a),t+y*Math.sin(a))}return this.poly(g,!0,l),this}clone(e=!1){const t=new yt;if(t.checkForHoles=this.checkForHoles,!e)t.instructions=this.instructions.slice();else for(let r=0;r<this.instructions.length;r++){const n=this.instructions[r];t.instructions.push({action:n.action,data:n.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,r=e.b,n=e.c,o=e.d,c=e.tx,l=e.ty;let d=0,f=0,m=0,g=0,_=0,y=0,a=0,h=0;for(let u=0;u<this.instructions.length;u++){const p=this.instructions[u],v=p.data;switch(p.action){case"moveTo":case"lineTo":d=v[0],f=v[1],v[0]=t*d+n*f+c,v[1]=r*d+o*f+l;break;case"bezierCurveTo":m=v[0],g=v[1],_=v[2],y=v[3],d=v[4],f=v[5],v[0]=t*m+n*g+c,v[1]=r*m+o*g+l,v[2]=t*_+n*y+c,v[3]=r*_+o*y+l,v[4]=t*d+n*f+c,v[5]=r*d+o*f+l;break;case"quadraticCurveTo":m=v[0],g=v[1],d=v[2],f=v[3],v[0]=t*m+n*g+c,v[1]=r*m+o*g+l,v[2]=t*d+n*f+c,v[3]=r*d+o*f+l;break;case"arcToSvg":d=v[5],f=v[6],a=v[0],h=v[1],v[0]=t*a+n*h,v[1]=r*a+o*h,v[5]=t*d+n*f+c,v[6]=r*d+o*f+l;break;case"circle":v[4]=Ji(v[3],e);break;case"rect":v[4]=Ji(v[4],e);break;case"ellipse":v[8]=Ji(v[8],e);break;case"roundRect":v[5]=Ji(v[5],e);break;case"addPath":v[0].transform(e);break;case"poly":v[2]=Ji(v[2],e);break;default:G("unknown transform action",p.action);break}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,r=this.instructions[t];if(!r)return e.x=0,e.y=0,e;for(;r.action==="closePath";){if(t--,t<0)return e.x=0,e.y=0,e;r=this.instructions[t]}switch(r.action){case"moveTo":case"lineTo":e.x=r.data[0],e.y=r.data[1];break;case"quadraticCurveTo":e.x=r.data[2],e.y=r.data[3];break;case"bezierCurveTo":e.x=r.data[4],e.y=r.data[5];break;case"arc":case"arcToSvg":e.x=r.data[5],e.y=r.data[6];break;case"addPath":r.data[0].getLastPoint(e);break}return e}}function Ji(s,e){return s?s.prepend(e):e.clone()}function de(s,e,t){const r=s.getAttribute(e);return r?Number(r):t}function c0(s,e){const t=s.querySelectorAll("defs");for(let r=0;r<t.length;r++){const n=t[r];for(let o=0;o<n.children.length;o++){const c=n.children[o];switch(c.nodeName.toLowerCase()){case"lineargradient":e.defs[c.id]=h0(c);break;case"radialgradient":e.defs[c.id]=u0();break}}}}function h0(s){const e=de(s,"x1",0),t=de(s,"y1",0),r=de(s,"x2",1),n=de(s,"y2",0),o=s.getAttribute("gradientUnits")||"objectBoundingBox",c=new Ke(e,t,r,n,o==="objectBoundingBox"?"local":"global");for(let l=0;l<s.children.length;l++){const d=s.children[l],f=de(d,"offset",0),m=le.shared.setValue(d.getAttribute("stop-color")).toNumber();c.addColorStop(f,m)}return c}function u0(s){return G("[SVG Parser] Radial gradients are not yet supported"),new Ke(0,0,1,0)}function gc(s){const e=s.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return e?e[1]:""}const vc={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 _c(s,e){const t=s.getAttribute("style"),r={},n={},o={strokeStyle:r,fillStyle:n,useFill:!1,useStroke:!1};for(const c in vc){const l=s.getAttribute(c);l&&yc(e,o,c,l.trim())}if(t){const c=t.split(";");for(let l=0;l<c.length;l++){const d=c[l].trim(),[f,m]=d.split(":");vc[f]&&yc(e,o,f,m.trim())}}return{strokeStyle:o.useStroke?r:null,fillStyle:o.useFill?n:null,useFill:o.useFill,useStroke:o.useStroke}}function yc(s,e,t,r){switch(t){case"stroke":if(r!=="none"){if(r.startsWith("url(")){const n=gc(r);e.strokeStyle.fill=s.defs[n]}else e.strokeStyle.color=le.shared.setValue(r).toNumber();e.useStroke=!0}break;case"stroke-width":e.strokeStyle.width=Number(r);break;case"fill":if(r!=="none"){if(r.startsWith("url(")){const n=gc(r);e.fillStyle.fill=s.defs[n]}else e.fillStyle.color=le.shared.setValue(r).toNumber();e.useFill=!0}break;case"fill-opacity":e.fillStyle.alpha=Number(r);break;case"stroke-opacity":e.strokeStyle.alpha=Number(r);break;case"opacity":e.fillStyle.alpha=Number(r),e.strokeStyle.alpha=Number(r);break}}function d0(s){if(s.length<=2)return!0;const e=s.map(l=>l.area).sort((l,d)=>d-l),[t,r]=e,n=e[e.length-1],o=t/r,c=r/n;return!(o>3&&c<2)}function f0(s){return s.split(/(?=[Mm])/).filter(r=>r.trim().length>0)}function p0(s){const e=s.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!e||e.length<4)return 0;const t=e.map(Number),r=[],n=[];for(let m=0;m<t.length;m+=2)m+1<t.length&&(r.push(t[m]),n.push(t[m+1]));if(r.length===0||n.length===0)return 0;const o=Math.min(...r),c=Math.max(...r),l=Math.min(...n),d=Math.max(...n);return(c-o)*(d-l)}function xc(s,e){const t=new yt(s,!1);for(const r of t.instructions)e.instructions.push(r)}function m0(s,e){if(typeof s=="string"){const c=document.createElement("div");c.innerHTML=s.trim(),s=c.querySelector("svg")}const t={context:e,defs:{},path:new yt};c0(s,t);const r=s.children,{fillStyle:n,strokeStyle:o}=_c(s,t);for(let c=0;c<r.length;c++){const l=r[c];l.nodeName.toLowerCase()!=="defs"&&bc(l,t,n,o)}return e}function bc(s,e,t,r){const n=s.children,{fillStyle:o,strokeStyle:c}=_c(s,e);o&&t?t={...t,...o}:o&&(t=o),c&&r?r={...r,...c}:c&&(r=c);const l=!t&&!r;l&&(t={color:0});let d,f,m,g,_,y,a,h,u,p,v,x,b,T,w,S,E;switch(s.nodeName.toLowerCase()){case"path":{T=s.getAttribute("d");const A=s.getAttribute("fill-rule"),P=f0(T),I=A==="evenodd",k=P.length>1;if(I&&k){const X=P.map(R=>({path:R,area:p0(R)}));if(X.sort((R,M)=>M.area-R.area),P.length>3||!d0(X))for(let R=0;R<X.length;R++){const M=X[R],q=R===0;e.context.beginPath();const N=new yt(void 0,!0);xc(M.path,N),e.context.path(N),q?(t&&e.context.fill(t),r&&e.context.stroke(r)):e.context.cut()}else for(let R=0;R<X.length;R++){const M=X[R],q=R%2===1;e.context.beginPath();const N=new yt(void 0,!0);xc(M.path,N),e.context.path(N),q?e.context.cut():(t&&e.context.fill(t),r&&e.context.stroke(r))}}else{const X=A?A==="evenodd":!0;w=new yt(T,X),e.context.path(w),t&&e.context.fill(t),r&&e.context.stroke(r)}break}case"circle":a=de(s,"cx",0),h=de(s,"cy",0),u=de(s,"r",0),e.context.ellipse(a,h,u,u),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"rect":d=de(s,"x",0),f=de(s,"y",0),S=de(s,"width",0),E=de(s,"height",0),p=de(s,"rx",0),v=de(s,"ry",0),p||v?e.context.roundRect(d,f,S,E,p||v):e.context.rect(d,f,S,E),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"ellipse":a=de(s,"cx",0),h=de(s,"cy",0),p=de(s,"rx",0),v=de(s,"ry",0),e.context.beginPath(),e.context.ellipse(a,h,p,v),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"line":m=de(s,"x1",0),g=de(s,"y1",0),_=de(s,"x2",0),y=de(s,"y2",0),e.context.beginPath(),e.context.moveTo(m,g),e.context.lineTo(_,y),r&&e.context.stroke(r);break;case"polygon":b=s.getAttribute("points"),x=b.match(/\d+/g).map(A=>parseInt(A,10)),e.context.poly(x,!0),t&&e.context.fill(t),r&&e.context.stroke(r);break;case"polyline":b=s.getAttribute("points"),x=b.match(/\d+/g).map(A=>parseInt(A,10)),e.context.poly(x,!1),r&&e.context.stroke(r);break;case"g":case"svg":break;default:{G(`[SVG parser] <${s.nodeName}> elements unsupported`);break}}l&&(t=null);for(let A=0;A<n.length;A++)bc(n[A],e,t,r)}function g0(s){return le.isColorLike(s)}function Tc(s){return s instanceof Vr}function wc(s){return s instanceof Ke}function v0(s){return s instanceof F}function _0(s,e,t){const r=le.shared.setValue(e??0);return s.color=r.toNumber(),s.alpha=r.alpha===1?t.alpha:r.alpha,s.texture=F.WHITE,{...t,...s}}function y0(s,e,t){return s.texture=e,{...t,...s}}function Sc(s,e,t){return s.fill=e,s.color=16777215,s.texture=e.texture,s.matrix=e.transform,{...t,...s}}function Cc(s,e,t){return e.buildGradient(),s.fill=e,s.color=16777215,s.texture=e.texture,s.matrix=e.transform,s.textureSpace=e.textureSpace,{...t,...s}}function x0(s,e){const t={...e,...s},r=le.shared.setValue(t.color);return t.alpha*=r.alpha,t.color=r.toNumber(),t}function zt(s,e){if(s==null)return null;const t={},r=s;return g0(s)?_0(t,s,e):v0(s)?y0(t,s,e):Tc(s)?Sc(t,s,e):wc(s)?Cc(t,s,e):r.fill&&Tc(r.fill)?Sc(r,r.fill,e):r.fill&&wc(r.fill)?Cc(r,r.fill,e):x0(r,e)}function jr(s,e){const{width:t,alignment:r,miterLimit:n,cap:o,join:c,pixelLine:l,...d}=e,f=zt(s,d);return f?{width:t,alignment:r,miterLimit:n,cap:o,join:c,pixelLine:l,...f}:null}const b0=new J,Ac=new B,On=class ut extends Le{constructor(){super(...arguments),this.uid=ae("graphicsContext"),this.dirty=!0,this.batchMode="auto",this.instructions=[],this._activePath=new yt,this._transform=new B,this._fillStyle={...ut.defaultFillStyle},this._strokeStyle={...ut.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new Se,this._boundsDirty=!0}clone(){const e=new ut;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=zt(e,ut.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(e){this._strokeStyle=jr(e,ut.defaultStrokeStyle)}setFillStyle(e){return this._fillStyle=zt(e,ut.defaultFillStyle),this}setStrokeStyle(e){return this._strokeStyle=zt(e,ut.defaultStrokeStyle),this}texture(e,t,r,n,o,c){return this.instructions.push({action:"texture",data:{image:e,dx:r||0,dy:n||0,dw:o||e.frame.width,dh:c||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t?le.shared.setValue(t).toNumber():16777215}}),this.onUpdate(),this}beginPath(){return this._activePath=new yt,this}fill(e,t){let r;const n=this.instructions[this.instructions.length-1];return this._tick===0&&n?.action==="stroke"?r=n.data.path:r=this._activePath.clone(),r?(e!=null&&(t!==void 0&&typeof e=="number"&&(H(j,"GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead"),e={color:e,alpha:t}),this._fillStyle=zt(e,ut.defaultFillStyle)),this.instructions.push({action:"fill",data:{style:this.fillStyle,path:r}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0,this):this}_initNextPathLocation(){const{x:e,y:t}=this._activePath.getLastPoint(J.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(e){let t;const r=this.instructions[this.instructions.length-1];return this._tick===0&&r?.action==="fill"?t=r.data.path:t=this._activePath.clone(),t?(e!=null&&(this._strokeStyle=jr(e,ut.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],r=this._activePath.clone();if(t&&(t.action==="stroke"||t.action==="fill"))if(t.data.hole)t.data.hole.addPath(r);else{t.data.hole=r;break}}return this._initNextPathLocation(),this}arc(e,t,r,n,o,c){this._tick++;const l=this._transform;return this._activePath.arc(l.a*e+l.c*t+l.tx,l.b*e+l.d*t+l.ty,r,n,o,c),this}arcTo(e,t,r,n,o){this._tick++;const c=this._transform;return this._activePath.arcTo(c.a*e+c.c*t+c.tx,c.b*e+c.d*t+c.ty,c.a*r+c.c*n+c.tx,c.b*r+c.d*n+c.ty,o),this}arcToSvg(e,t,r,n,o,c,l){this._tick++;const d=this._transform;return this._activePath.arcToSvg(e,t,r,n,o,d.a*c+d.c*l+d.tx,d.b*c+d.d*l+d.ty),this}bezierCurveTo(e,t,r,n,o,c,l){this._tick++;const d=this._transform;return this._activePath.bezierCurveTo(d.a*e+d.c*t+d.tx,d.b*e+d.d*t+d.ty,d.a*r+d.c*n+d.tx,d.b*r+d.d*n+d.ty,d.a*o+d.c*c+d.tx,d.b*o+d.d*c+d.ty,l),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,r,n){return this._tick++,this._activePath.ellipse(e,t,r,n,this._transform.clone()),this}circle(e,t,r){return this._tick++,this._activePath.circle(e,t,r,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;const r=this._transform;return this._activePath.lineTo(r.a*e+r.c*t+r.tx,r.b*e+r.d*t+r.ty),this}moveTo(e,t){this._tick++;const r=this._transform,n=this._activePath.instructions,o=r.a*e+r.c*t+r.tx,c=r.b*e+r.d*t+r.ty;return n.length===1&&n[0].action==="moveTo"?(n[0].data[0]=o,n[0].data[1]=c,this):(this._activePath.moveTo(o,c),this)}quadraticCurveTo(e,t,r,n,o){this._tick++;const c=this._transform;return this._activePath.quadraticCurveTo(c.a*e+c.c*t+c.tx,c.b*e+c.d*t+c.ty,c.a*r+c.c*n+c.tx,c.b*r+c.d*n+c.ty,o),this}rect(e,t,r,n){return this._tick++,this._activePath.rect(e,t,r,n,this._transform.clone()),this}roundRect(e,t,r,n,o){return this._tick++,this._activePath.roundRect(e,t,r,n,o,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,r,n,o=0,c){return this._tick++,this._activePath.regularPoly(e,t,r,n,o,c),this}roundPoly(e,t,r,n,o,c){return this._tick++,this._activePath.roundPoly(e,t,r,n,o,c),this}roundShape(e,t,r,n){return this._tick++,this._activePath.roundShape(e,t,r,n),this}filletRect(e,t,r,n,o){return this._tick++,this._activePath.filletRect(e,t,r,n,o),this}chamferRect(e,t,r,n,o,c){return this._tick++,this._activePath.chamferRect(e,t,r,n,o,c),this}star(e,t,r,n,o=0,c=0){return this._tick++,this._activePath.star(e,t,r,n,o,c,this._transform.clone()),this}svg(e){return this._tick++,m0(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,r,n,o,c){return e instanceof B?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,r,n,o,c),this)}transform(e,t,r,n,o,c){return e instanceof B?(this._transform.append(e),this):(Ac.set(e,t,r,n,o,c),this._transform.append(Ac),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&&(this.emit("update",this,16),this.dirty=!0)}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 r=this.instructions[t],n=r.action;if(n==="fill"){const o=r.data;e.addBounds(o.path.bounds)}else if(n==="texture"){const o=r.data;e.addFrame(o.dx,o.dy,o.dx+o.dw,o.dy+o.dh,o.transform)}if(n==="stroke"){const o=r.data,c=o.style.alignment,l=o.style.width*(1-c),d=o.path.bounds;e.addFrame(d.minX-l,d.minY-l,d.maxX+l,d.maxY+l)}}return e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;const t=this.instructions;let r=!1;for(let n=0;n<t.length;n++){const o=t[n],c=o.data,l=c.path;if(!o.action||!l)continue;const d=c.style,f=l.shapePath.shapePrimitives;for(let m=0;m<f.length;m++){const g=f[m].shape;if(!d||!g)continue;const _=f[m].transform,y=_?_.applyInverse(e,b0):e;if(o.action==="fill")r=g.contains(y.x,y.y);else{const h=d;r=g.strokeContains(y.x,y.y,h.width,h.alignment)}const a=c.hole;if(a){const h=a.shapePath?.shapePrimitives;if(h)for(let u=0;u<h.length;u++)h[u].shape.contains(y.x,y.y)&&(r=!1)}if(r)return!0}}return r}destroy(e=!1){if(this._stateStack.length=0,this._transform=null,this.emit("destroy",this),this.removeAllListeners(),typeof e=="boolean"?e:e?.texture){const r=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(r)),this._strokeStyle.texture&&(this._strokeStyle.fill&&"uid"in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(r))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}};On.defaultFillStyle={color:16777215,alpha:1,texture:F.WHITE,matrix:null,fill:null,textureSpace:"local"},On.defaultStrokeStyle={width:1,color:16777215,alpha:1,alignment:.5,miterLimit:10,cap:"butt",join:"miter",texture:F.WHITE,matrix:null,fill:null,textureSpace:"local",pixelLine:!1};let je=On;const Gn=class yi extends Le{constructor(e={}){super(),this.uid=ae("textStyle"),this._tick=0,T0(e);const t={...yi.defaultTextStyle,...e};for(const r in t){const n=r;this[n]=t[r]}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({...yi.defaultDropShadow,...e}):this._dropShadow=e?this._createProxy({...yi.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({...je.defaultFillStyle,...e},()=>{this._fill=zt({...this._originalFill},je.defaultFillStyle)})),this._fill=zt(e===0?"black":e,je.defaultFillStyle),this.update())}get stroke(){return this._originalStroke}set stroke(e){e!==this._originalStroke&&(this._originalStroke=e,this._isFillStyle(e)&&(this._originalStroke=this._createProxy({...je.defaultStrokeStyle,...e},()=>{this._stroke=jr({...this._originalStroke},je.defaultStrokeStyle)})),this._stroke=jr(e,je.defaultStrokeStyle),this.update())}update(){this._tick++,this.emit("update",this)}reset(){const e=yi.defaultTextStyle;for(const t in e)this[t]=e[t]}get styleKey(){return`${this.uid}-${this._tick}`}clone(){return new yi({align:this.align,breakWords:this.breakWords,dropShadow:this._dropShadow?{...this._dropShadow}:null,fill:this._fill,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,textBaseline:this.textBaseline,whiteSpace:this.whiteSpace,wordWrap:this.wordWrap,wordWrapWidth:this.wordWrapWidth,filters:this._filters?[...this._filters]:void 0})}_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 r=typeof e=="boolean"?e:e?.textureSource;this._fill?.texture&&this._fill.texture.destroy(r),this._originalFill?.texture&&this._originalFill.texture.destroy(r),this._stroke?.texture&&this._stroke.texture.destroy(r),this._originalStroke?.texture&&this._originalStroke.texture.destroy(r)}this._fill=null,this._stroke=null,this.dropShadow=null,this._originalStroke=null,this._originalFill=null}_createProxy(e,t){return new Proxy(e,{set:(r,n,o)=>(r[n]===o||(r[n]=o,t?.(n,o),this.update()),!0)})}_isFillStyle(e){return(e??null)!==null&&!(le.isColorLike(e)||e instanceof Ke||e instanceof Vr)}};Gn.defaultDropShadow={alpha:1,angle:Math.PI/6,blur:0,color:"black",distance:5},Gn.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 De=Gn;function T0(s){const e=s;if(typeof e.dropShadow=="boolean"&&e.dropShadow){const t=De.defaultDropShadow;s.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(j,"strokeThickness is now a part of stroke");const t=e.stroke;let r={};if(le.isColorLike(t))r.color=t;else if(t instanceof Ke||t instanceof Vr)r.fill=t;else if(Object.hasOwnProperty.call(t,"color")||Object.hasOwnProperty.call(t,"fill"))r=t;else throw new Error("Invalid stroke value.");s.stroke={...r,width:e.strokeThickness}}if(Array.isArray(e.fillGradientStops)){if(H(j,"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&&G("The number of fill colors must match the number of fill gradient stops.");const t=new Ke({start:{x:0,y:0},end:{x:0,y:1},textureSpace:"local"}),r=e.fillGradientStops.slice(),n=e.fill.map(o=>le.shared.setValue(o).toNumber());r.forEach((o,c)=>{t.addColorStop(o,n[c])}),s.fill={fill:t}}}class w0{constructor(e){this._canvasPool=Object.create(null),this.canvasOptions=e||{},this.enableFullScreen=!1}_createCanvasAndContext(e,t){const r=V.get().createCanvas();r.width=e,r.height=t;const n=r.getContext("2d");return{canvas:r,context:n}}getOptimalCanvasAndContext(e,t,r=1){e=Math.ceil(e*r-1e-6),t=Math.ceil(t*r-1e-6),e=Jt(e),t=Jt(t);const n=(e<<17)+(t<<1);this._canvasPool[n]||(this._canvasPool[n]=[]);let o=this._canvasPool[n].pop();return o||(o=this._createCanvasAndContext(e,t)),o}returnCanvasAndContext(e){const t=e.canvas,{width:r,height:n}=t,o=(r<<17)+(n<<1);e.context.resetTransform(),e.context.clearRect(0,0,r,n),this._canvasPool[o].push(e)}clear(){this._canvasPool={}}}const xt=new w0;ei.register(xt);const Ec=1e5;function Zr(s,e,t,r=0){if(s.texture===F.WHITE&&!s.fill)return le.shared.setValue(s.color).setAlpha(s.alpha??1).toHexa();if(s.fill){if(s.fill instanceof Vr){const n=s.fill,o=e.createPattern(n.texture.source.resource,"repeat"),c=n.transform.copyTo(B.shared);return c.scale(n.texture.frame.width,n.texture.frame.height),o.setTransform(c),o}else if(s.fill instanceof Ke){const n=s.fill,o=n.type==="linear",c=n.textureSpace==="local";let l=1,d=1;c&&t&&(l=t.width+r,d=t.height+r);let f,m=!1;if(o){const{start:g,end:_}=n;f=e.createLinearGradient(g.x*l,g.y*d,_.x*l,_.y*d),m=Math.abs(_.x-g.x)<Math.abs((_.y-g.y)*.1)}else{const{center:g,innerRadius:_,outerCenter:y,outerRadius:a}=n;f=e.createRadialGradient(g.x*l,g.y*d,_*l,y.x*l,y.y*d,a*l)}if(m&&c&&t){const g=t.lineHeight/d;for(let _=0;_<t.lines.length;_++){const y=(_*t.lineHeight+r/2)/d;n.colorStops.forEach(a=>{const h=y+a.offset*g;f.addColorStop(Math.floor(h*Ec)/Ec,le.shared.setValue(a.color).toHex())})}}else n.colorStops.forEach(g=>{f.addColorStop(g.offset,le.shared.setValue(g.color).toHex())});return f}}else{const n=e.createPattern(s.texture.source.resource,"repeat"),o=s.matrix.copyTo(B.shared);return o.scale(s.texture.frame.width,s.texture.frame.height),n.setTransform(o),n}return G("FillStyle not recognised",s),"red"}const Ic=class yd extends Ol{constructor(e){super(),this.resolution=1,this.pages=[],this._padding=0,this._measureCache=Object.create(null),this._currentChars=[],this._currentX=0,this._currentY=0,this._currentMaxCharHeight=0,this._currentPageIndex=-1,this._skipKerning=!1;const t={...yd.defaultOptions,...e};this._textureSize=t.textureSize,this._mipmap=t.mipmap;const r=t.style.clone();t.overrideFill&&(r._fill.color=16777215,r._fill.alpha=1,r._fill.texture=F.WHITE,r._fill.fill=null),this.applyFillAsTint=t.overrideFill;const n=r.fontSize;r.fontSize=this.baseMeasurementFontSize;const o=Wr(r);t.overrideSize?r._stroke&&(r._stroke.width*=this.baseRenderedFontSize/n):r.fontSize=this.baseRenderedFontSize=n,this._style=r,this._skipKerning=t.skipKerning??!1,this.resolution=t.resolution??1,this._padding=t.padding??4,t.textureStyle&&(this._textureStyle=t.textureStyle instanceof at?t.textureStyle:new at(t.textureStyle)),this.fontMetrics=Be.measureFont(o),this.lineHeight=r.lineHeight||this.fontMetrics.fontSize||r.fontSize}ensureCharacters(e){const t=Be.graphemeSegmenter(e).filter(u=>!this._currentChars.includes(u)).filter((u,p,v)=>v.indexOf(u)===p);if(!t.length)return;this._currentChars=[...this._currentChars,...t];let r;this._currentPageIndex===-1?r=this._nextPage():r=this.pages[this._currentPageIndex];let{canvas:n,context:o}=r.canvasAndContext,c=r.texture.source;const l=this._style;let d=this._currentX,f=this._currentY,m=this._currentMaxCharHeight;const g=this.baseRenderedFontSize/this.baseMeasurementFontSize,_=this._padding*g;let y=!1;const a=n.width/this.resolution,h=n.height/this.resolution;for(let u=0;u<t.length;u++){const p=t[u],v=Be.measureText(p,l,n,!1);v.lineHeight=v.height;const x=v.width*g,b=Math.ceil((l.fontStyle==="italic"?2:1)*x),T=v.height*g,w=b+_*2,S=T+_*2;if(y=!1,p!==`
|
|
318
|
+
`&&p!=="\r"&&p!==" "&&p!==" "&&(y=!0,m=Math.ceil(Math.max(S,m))),d+w>a&&(f+=m,m=S,d=0,f+m>h)){c.update();const A=this._nextPage();n=A.canvasAndContext.canvas,o=A.canvasAndContext.context,c=A.texture.source,d=0,f=0,m=0}const E=x/g-(l.dropShadow?.distance??0)-(l._stroke?.width??0);if(this.chars[p]={id:p.codePointAt(0),xOffset:-this._padding,yOffset:-this._padding,xAdvance:E,kerning:{}},y){this._drawGlyph(o,v,d+_,f+_,g,l);const A=c.width*g,P=c.height*g,I=new z(d/A*c.width,f/P*c.height,w/A*c.width,S/P*c.height);this.chars[p].texture=new F({source:c,frame:I}),d+=Math.ceil(w)}}c.update(),this._currentX=d,this._currentY=f,this._currentMaxCharHeight=m,this._skipKerning&&this._applyKerning(t,o)}get pageTextures(){return H(j,"BitmapFont.pageTextures is deprecated, please use BitmapFont.pages instead."),this.pages}_applyKerning(e,t){const r=this._measureCache;for(let n=0;n<e.length;n++){const o=e[n];for(let c=0;c<this._currentChars.length;c++){const l=this._currentChars[c];let d=r[o];d||(d=r[o]=t.measureText(o).width);let f=r[l];f||(f=r[l]=t.measureText(l).width);let m=t.measureText(o+l).width,g=m-(d+f);g&&(this.chars[o].kerning[l]=g),m=t.measureText(o+l).width,g=m-(d+f),g&&(this.chars[l].kerning[o]=g)}}}_nextPage(){this._currentPageIndex++;const e=this.resolution,t=xt.getOptimalCanvasAndContext(this._textureSize,this._textureSize,e);this._setupContext(t.context,this._style,e);const r=e*(this.baseRenderedFontSize/this.baseMeasurementFontSize),n=new F({source:new ct({resource:t.canvas,resolution:r,alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:this._mipmap})});this._textureStyle&&(n.source.style=this._textureStyle);const o={canvasAndContext:t,texture:n};return this.pages[this._currentPageIndex]=o,o}_setupContext(e,t,r){t.fontSize=this.baseRenderedFontSize,e.scale(r,r),e.font=Wr(t),t.fontSize=this.baseMeasurementFontSize,e.textBaseline=t.textBaseline;const n=t._stroke,o=n?.width??0;if(n&&(e.lineWidth=o,e.lineJoin=n.join,e.miterLimit=n.miterLimit,e.strokeStyle=Zr(n,e)),t._fill&&(e.fillStyle=Zr(t._fill,e)),t.dropShadow){const c=t.dropShadow,l=le.shared.setValue(c.color).toArray(),d=c.blur*r,f=c.distance*r;e.shadowColor=`rgba(${l[0]*255},${l[1]*255},${l[2]*255},${c.alpha})`,e.shadowBlur=d,e.shadowOffsetX=Math.cos(c.angle)*f,e.shadowOffsetY=Math.sin(c.angle)*f}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0}_drawGlyph(e,t,r,n,o,c){const l=t.text,d=t.fontProperties,m=(c._stroke?.width??0)*o,g=r+m/2,_=n-m/2,y=d.descent*o,a=t.lineHeight*o;let h=!1;c.stroke&&m&&(h=!0,e.strokeText(l,g,_+a-y));const{shadowBlur:u,shadowOffsetX:p,shadowOffsetY:v}=e;c._fill&&(h&&(e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0),e.fillText(l,g,_+a-y)),h&&(e.shadowBlur=u,e.shadowOffsetX=p,e.shadowOffsetY=v)}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{canvasAndContext:t,texture:r}=this.pages[e];xt.returnCanvasAndContext(t),r.destroy(!0)}this.pages=null}};Ic.defaultOptions={textureSize:512,style:new De,mipmap:!0};let Pc=Ic;function Ln(s,e,t,r){const n={width:0,height:0,offsetY:0,scale:e.fontSize/t.baseMeasurementFontSize,lines:[{width:0,charPositions:[],spaceWidth:0,spacesIndex:[],chars:[]}]};n.offsetY=t.baseLineOffset;let o=n.lines[0],c=null,l=!0;const d={width:0,start:0,index:0,positions:[],chars:[]},f=t.baseMeasurementFontSize/e.fontSize,m=e.letterSpacing*f,g=e.wordWrapWidth*f,_=e.lineHeight?e.lineHeight*f:t.lineHeight,y=e.wordWrap&&e.breakWords,a=p=>{const v=o.width;for(let x=0;x<d.index;x++){const b=p.positions[x];o.chars.push(p.chars[x]),o.charPositions.push(b+v)}o.width+=p.width,l=!1,d.width=0,d.index=0,d.chars.length=0},h=()=>{let p=o.chars.length-1;if(r){let v=o.chars[p];for(;v===" ";)o.width-=t.chars[v].xAdvance,v=o.chars[--p]}n.width=Math.max(n.width,o.width),o={width:0,charPositions:[],chars:[],spaceWidth:0,spacesIndex:[]},l=!0,n.lines.push(o),n.height+=_},u=p=>p-m>g;for(let p=0;p<s.length+1;p++){let v;const x=p===s.length;x||(v=s[p]);const b=t.chars[v]||t.chars[" "];if(/(?:\s)/.test(v)||v==="\r"||v===`
|
|
319
319
|
`||x){if(!l&&e.wordWrap&&u(o.width+d.width)?(h(),a(d),x||o.charPositions.push(0)):(d.start=o.width,a(d),x||o.charPositions.push(0)),v==="\r"||v===`
|
|
320
|
-
`)h();else if(!x){const E=b.xAdvance+(b.kerning[c]||0)+m;o.width+=E,o.spaceWidth=E,o.spacesIndex.push(o.charPositions.length),o.chars.push(v)}}else{const S=b.kerning[c]||0,E=b.xAdvance+S+m;y&&u(o.width+d.width+E)&&(a(d),h()),d.positions[d.index++]=d.width+S,d.chars.push(v),d.width+=E}c=v}return h(),e.align==="center"?S0(n):e.align==="right"?C0(n):e.align==="justify"&&A0(n),n}function S0(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width/2-t.width/2;for(let n=0;n<t.charPositions.length;n++)t.charPositions[n]+=r}}function C0(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width-t.width;for(let n=0;n<t.charPositions.length;n++)t.charPositions[n]+=r}}function A0(s){const e=s.width;for(let t=0;t<s.lines.length;t++){const r=s.lines[t];let n=0,o=r.spacesIndex[n++],c=0;const l=r.spacesIndex.length,f=(e-r.width)/l;for(let m=0;m<r.charPositions.length;m++)m===o&&(o=r.spacesIndex[n++],c+=f),r.charPositions[m]+=c}}function E0(s){if(s==="")return[];typeof s=="string"&&(s=[s]);const e=[];for(let t=0,r=s.length;t<r;t++){const n=s[t];if(Array.isArray(n)){if(n.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${n.length}.`);if(n[0].length===0||n[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");const o=n[0].charCodeAt(0),c=n[1].charCodeAt(0);if(c<o)throw new Error("[BitmapFont]: Invalid character range.");for(let l=o,d=c;l<=d;l++)e.push(String.fromCharCode(l))}else e.push(...Array.from(n))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}let Jr=0;class I0{constructor(){this.ALPHA=[["a","z"],["A","Z"]," "],this.NUMERIC=[["0","9"]],this.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],this.ASCII=[[" ","~"]],this.defaultOptions={chars:this.ALPHANUMERIC,resolution:1,padding:4,skipKerning:!1,textureStyle:null},this.measureCache=Gl(1e3)}getFont(e,t){let r=`${t.fontFamily}-bitmap`,n=!0;if(t._fill.fill&&!t._stroke?(r+=t._fill.fill.styleKey,n=!1):(t._stroke||t.dropShadow)&&(r=`${t.styleKey}-bitmap`,n=!1),!re.has(r)){const c=Object.create(t);c.lineHeight=0;const l=new Pc({style:c,overrideFill:n,overrideSize:!0,...this.defaultOptions});Jr++,Jr>50&&G("BitmapText",`You have dynamically created ${Jr} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),l.once("destroy",()=>{Jr--,re.remove(r)}),re.set(r,l)}const o=re.get(r);return o.ensureCharacters?.(e),o}getLayout(e,t,r=!0){const n=this.getFont(e,t),o=`${e}-${t.styleKey}-${r}`;if(this.measureCache.has(o))return this.measureCache.get(o);const c=He.graphemeSegmenter(e),l=Ln(c,t,n,r);return this.measureCache.set(o,l),l}measureText(e,t,r=!0){return this.getLayout(e,t,r)}install(...e){let t=e[0];typeof t=="string"&&(t={name:t,style:e[1],chars:e[2]?.chars,resolution:e[2]?.resolution,padding:e[2]?.padding,skipKerning:e[2]?.skipKerning},H(j,"BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));const r=t?.name;if(!r)throw new Error("[BitmapFontManager] Property `name` is required.");t={...this.defaultOptions,...t};const n=t.style,o=n instanceof Be?n:new Be(n),c=t.dynamicFill??this._canUseTintForStyle(o),l=new Pc({style:o,overrideFill:c,skipKerning:t.skipKerning,padding:t.padding,resolution:t.resolution,overrideSize:!1,textureStyle:t.textureStyle}),d=E0(t.chars);return l.ensureCharacters(d.join("")),re.set(`${r}-bitmap`,l),l.once("destroy",()=>re.remove(`${r}-bitmap`)),l}uninstall(e){const t=`${e}-bitmap`,r=re.get(t);r&&r.destroy()}_canUseTintForStyle(e){return!e._stroke&&(!e.dropShadow||e.dropShadow.color===0)&&!e._fill.fill&&e._fill.color===16777215}}const Qi=new I0;class Rc extends Ol{constructor(e,t){super();const{textures:r,data:n}=e;Object.keys(n.pages).forEach(o=>{const c=n.pages[parseInt(o,10)],l=r[c.id];this.pages.push({texture:l})}),Object.keys(n.chars).forEach(o=>{const c=n.chars[o],{frame:l,source:d,rotate:f}=r[c.page],m=ie.transformRectCoords(c,l,f,new z),g=new F({frame:m,orig:new z(0,0,c.width,c.height),source:d,rotate:f});this.chars[o]={id:o.codePointAt(0),xOffset:c.xOffset,yOffset:c.yOffset,xAdvance:c.xAdvance,kerning:c.kerning??{},texture:g}}),this.baseRenderedFontSize=n.fontSize,this.baseMeasurementFontSize=n.fontSize,this.fontMetrics={ascent:0,descent:0,fontSize:n.fontSize},this.baseLineOffset=n.baseLineOffset,this.lineHeight=n.lineHeight,this.fontFamily=n.fontFamily,this.distanceField=n.distanceField??{type:"none",range:0},this.url=t}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{texture:t}=this.pages[e];t.destroy(!0)}this.pages=null}static install(e){Qi.install(e)}static uninstall(e){Qi.uninstall(e)}}const Nn={test(s){return typeof s=="string"&&s.startsWith("info face=")},parse(s){const e=s.match(/^[a-z]+\s+.+$/gm),t={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const g in e){const _=e[g].match(/^[a-z]+/gm)[0],y=e[g].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),a={};for(const h in y){const u=y[h].split("="),p=u[0],v=u[1].replace(/"/gm,""),x=parseFloat(v),b=isNaN(x)?v:x;a[p]=b}t[_].push(a)}const r={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[n]=t.info,[o]=t.common,[c]=t.distanceField??[];c&&(r.distanceField={range:parseInt(c.distanceRange,10),type:c.fieldType}),r.fontSize=parseInt(n.size,10),r.fontFamily=n.face,r.lineHeight=parseInt(o.lineHeight,10);const l=t.page;for(let g=0;g<l.length;g++)r.pages.push({id:parseInt(l[g].id,10)||0,file:l[g].file});const d={};r.baseLineOffset=r.lineHeight-parseInt(o.base,10);const f=t.char;for(let g=0;g<f.length;g++){const _=f[g],y=parseInt(_.id,10);let a=_.letter??_.char??String.fromCharCode(y);a==="space"&&(a=" "),d[y]=a,r.chars[a]={id:y,page:parseInt(_.page,10)||0,x:parseInt(_.x,10),y:parseInt(_.y,10),width:parseInt(_.width,10),height:parseInt(_.height,10),xOffset:parseInt(_.xoffset,10),yOffset:parseInt(_.yoffset,10),xAdvance:parseInt(_.xadvance,10),kerning:{}}}const m=t.kerning||[];for(let g=0;g<m.length;g++){const _=parseInt(m[g].first,10),y=parseInt(m[g].second,10),a=parseInt(m[g].amount,10);r.chars[d[y]].kerning[d[_]]=a}return r}},Mc={test(s){const e=s;return typeof e!="string"&&"getElementsByTagName"in e&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(s){const e={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},t=s.getElementsByTagName("info")[0],r=s.getElementsByTagName("common")[0],n=s.getElementsByTagName("distanceField")[0];n&&(e.distanceField={type:n.getAttribute("fieldType"),range:parseInt(n.getAttribute("distanceRange"),10)});const o=s.getElementsByTagName("page"),c=s.getElementsByTagName("char"),l=s.getElementsByTagName("kerning");e.fontSize=parseInt(t.getAttribute("size"),10),e.fontFamily=t.getAttribute("face"),e.lineHeight=parseInt(r.getAttribute("lineHeight"),10);for(let f=0;f<o.length;f++)e.pages.push({id:parseInt(o[f].getAttribute("id"),10)||0,file:o[f].getAttribute("file")});const d={};e.baseLineOffset=e.lineHeight-parseInt(r.getAttribute("base"),10);for(let f=0;f<c.length;f++){const m=c[f],g=parseInt(m.getAttribute("id"),10);let _=m.getAttribute("letter")??m.getAttribute("char")??String.fromCharCode(g);_==="space"&&(_=" "),d[g]=_,e.chars[_]={id:g,page:parseInt(m.getAttribute("page"),10)||0,x:parseInt(m.getAttribute("x"),10),y:parseInt(m.getAttribute("y"),10),width:parseInt(m.getAttribute("width"),10),height:parseInt(m.getAttribute("height"),10),xOffset:parseInt(m.getAttribute("xoffset"),10),yOffset:parseInt(m.getAttribute("yoffset"),10),xAdvance:parseInt(m.getAttribute("xadvance"),10),kerning:{}}}for(let f=0;f<l.length;f++){const m=parseInt(l[f].getAttribute("first"),10),g=parseInt(l[f].getAttribute("second"),10),_=parseInt(l[f].getAttribute("amount"),10);e.chars[d[g]].kerning[d[m]]=_}return e}},Fc={test(s){return typeof s=="string"&&s.match(/<font(\s|>)/)?Mc.test(V.get().parseXML(s)):!1},parse(s){return Mc.parse(V.get().parseXML(s))}},P0=[".xml",".fnt"],R0={extension:{type:C.CacheParser,name:"cacheBitmapFont"},test:s=>s instanceof Rc,getCacheableAssets(s,e){const t={};return s.forEach(r=>{t[r]=e,t[`${r}-bitmap`]=e}),t[`${e.fontFamily}-bitmap`]=e,t}},M0={extension:{type:C.LoadParser,priority:At.Normal},name:"loadBitmapFont",id:"bitmap-font",test(s){return P0.includes(Ne.extname(s).toLowerCase())},async testParse(s){return Nn.test(s)||Fc.test(s)},async parse(s,e,t){const r=Nn.test(s)?Nn.parse(s):Fc.parse(s),{src:n}=e,{pages:o}=r,c=[],l=r.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let g=0;g<o.length;++g){const _=o[g].file;let y=Ne.join(Ne.dirname(n),_);y=Ks(y,n),c.push({src:y,data:l})}const d=await t.load(c),f=c.map(g=>d[g.src]);return new Rc({data:r,textures:f},n)},async load(s,e){return await(await V.get().fetch(s)).text()},async unload(s,e,t){await Promise.all(s.pages.map(r=>t.unload(r.texture.source._sourceOrigin))),s.destroy()}};class F0{constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let r=0;r<t;r++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const U0={extension:{type:C.CacheParser,name:"cacheTextureArray"},test:s=>Array.isArray(s)&&s.every(e=>e instanceof F),getCacheableAssets:(s,e)=>{const t={};return s.forEach(r=>{e.forEach((n,o)=>{t[r+(o===0?"":o+1)]=n})}),t}};async function Uc(s){if("Image"in globalThis)return new Promise(e=>{const t=new Image;t.onload=()=>{e(!0)},t.onerror=()=>{e(!1)},t.src=s});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const e=await(await fetch(s)).blob();await createImageBitmap(e)}catch{return!1}return!0}return!1}const k0={extension:{type:C.DetectionParser,priority:1},test:async()=>Uc("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async s=>[...s,"avif"],remove:async s=>s.filter(e=>e!=="avif")},kc=["png","jpg","jpeg"],B0={extension:{type:C.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async s=>[...s,...kc],remove:async s=>s.filter(e=>!kc.includes(e))},D0="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function Qr(s){return D0?!1:document.createElement("video").canPlayType(s)!==""}const O0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/mp4"),add:async s=>[...s,"mp4","m4v"],remove:async s=>s.filter(e=>e!=="mp4"&&e!=="m4v")},G0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/ogg"),add:async s=>[...s,"ogv"],remove:async s=>s.filter(e=>e!=="ogv")},L0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/webm"),add:async s=>[...s,"webm"],remove:async s=>s.filter(e=>e!=="webm")},N0={extension:{type:C.DetectionParser,priority:0},test:async()=>Uc("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async s=>[...s,"webp"],remove:async s=>s.filter(e=>e!=="webp")},Bc=class ls{constructor(){this.loadOptions={...ls.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(e,t,r)=>(this._parsersValidated=!1,e[t]=r,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(e,t){const r={promise:null,parser:null};return r.promise=(async()=>{let n=null,o=null;if((t.parser||t.loadParser)&&(o=this._parserHash[t.parser||t.loadParser],t.loadParser&&G(`[Assets] "loadParser" is deprecated, use "parser" instead for ${e}`),o||G(`[Assets] specified load parser "${t.parser||t.loadParser}" not found while loading ${e}`)),!o){for(let c=0;c<this.parsers.length;c++){const l=this.parsers[c];if(l.load&&l.test?.(e,t,this)){o=l;break}}if(!o)return G(`[Assets] ${e} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}n=await o.load(e,t,this),r.parser=o;for(let c=0;c<this.parsers.length;c++){const l=this.parsers[c];l.parse&&l.parse&&await l.testParse?.(n,t,this)&&(n=await l.parse(n,t,this)||n,r.parser=l)}return n})(),r}async load(e,t){this._parsersValidated||this._validateParsers();const r=typeof t=="function"?{...ls.defaultOptions,...this.loadOptions,onProgress:t}:{...ls.defaultOptions,...this.loadOptions,...t||{}},{onProgress:n,onError:o,strategy:c,retryCount:l,retryDelay:d}=r;let f=0;const m={},g=Fr(e),_=Qe(e,h=>({alias:[h],src:h,data:{}})),y=_.reduce((h,u)=>h+(u.progressSize||1),0),a=_.map(async h=>{const u=Ne.toAbsolute(h.src);m[h.src]||(await this._loadAssetWithRetry(u,h,{onProgress:n,onError:o,strategy:c,retryCount:l,retryDelay:d},m),f+=h.progressSize||1,n&&n(f/y))});return await Promise.all(a),g?m[_[0].src]:m}async unload(e){const r=Qe(e,n=>({alias:[n],src:n})).map(async n=>{const o=Ne.toAbsolute(n.src),c=this.promiseCache[o];if(c){const l=await c.promise;delete this.promiseCache[o],await c.parser?.unload?.(l,n,this)}});await Promise.all(r)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(e=>e.name||e.id).reduce((e,t)=>(!t.name&&!t.id?G("[Assets] parser should have an id"):(e[t.name]||e[t.id])&&G(`[Assets] parser id conflict "${t.id}"`),e[t.name]=t,t.id&&(e[t.id]=t),e),{})}async _loadAssetWithRetry(e,t,r,n){let o=0;const{onError:c,strategy:l,retryCount:d,retryDelay:f}=r,m=g=>new Promise(_=>setTimeout(_,g));for(;;)try{this.promiseCache[e]||(this.promiseCache[e]=this._getLoadPromiseAndParser(e,t)),n[t.src]=await this.promiseCache[e].promise;return}catch(g){delete this.promiseCache[e],delete n[t.src],o++;const _=l!=="retry"||o>d;if(l==="retry"&&!_){c&&c(g,t),await m(f);continue}if(l==="skip"){c&&c(g,t);return}throw c&&c(g,t),new Error(`[Loader.load] Failed to load ${e}.
|
|
321
|
-
${g}`)}}};Bc.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let z0=Bc;function ai(s,e){if(Array.isArray(e)){for(const t of e)if(s.startsWith(`data:${t}`))return!0;return!1}return s.startsWith(`data:${e}`)}function li(s,e){const t=s.split("?")[0],r=
|
|
320
|
+
`)h();else if(!x){const E=b.xAdvance+(b.kerning[c]||0)+m;o.width+=E,o.spaceWidth=E,o.spacesIndex.push(o.charPositions.length),o.chars.push(v)}}else{const S=b.kerning[c]||0,E=b.xAdvance+S+m;y&&u(o.width+d.width+E)&&(a(d),h()),d.positions[d.index++]=d.width+S,d.chars.push(v),d.width+=E}c=v}return h(),e.align==="center"?S0(n):e.align==="right"?C0(n):e.align==="justify"&&A0(n),n}function S0(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width/2-t.width/2;for(let n=0;n<t.charPositions.length;n++)t.charPositions[n]+=r}}function C0(s){for(let e=0;e<s.lines.length;e++){const t=s.lines[e],r=s.width-t.width;for(let n=0;n<t.charPositions.length;n++)t.charPositions[n]+=r}}function A0(s){const e=s.width;for(let t=0;t<s.lines.length;t++){const r=s.lines[t];let n=0,o=r.spacesIndex[n++],c=0;const l=r.spacesIndex.length,f=(e-r.width)/l;for(let m=0;m<r.charPositions.length;m++)m===o&&(o=r.spacesIndex[n++],c+=f),r.charPositions[m]+=c}}function E0(s){if(s==="")return[];typeof s=="string"&&(s=[s]);const e=[];for(let t=0,r=s.length;t<r;t++){const n=s[t];if(Array.isArray(n)){if(n.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${n.length}.`);if(n[0].length===0||n[1].length===0)throw new Error("[BitmapFont]: Invalid character delimiter.");const o=n[0].charCodeAt(0),c=n[1].charCodeAt(0);if(c<o)throw new Error("[BitmapFont]: Invalid character range.");for(let l=o,d=c;l<=d;l++)e.push(String.fromCharCode(l))}else e.push(...Array.from(n))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}let Jr=0;class I0{constructor(){this.ALPHA=[["a","z"],["A","Z"]," "],this.NUMERIC=[["0","9"]],this.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],this.ASCII=[[" ","~"]],this.defaultOptions={chars:this.ALPHANUMERIC,resolution:1,padding:4,skipKerning:!1,textureStyle:null},this.measureCache=Gl(1e3)}getFont(e,t){let r=`${t.fontFamily}-bitmap`,n=!0;if(t._fill.fill&&!t._stroke?(r+=t._fill.fill.styleKey,n=!1):(t._stroke||t.dropShadow)&&(r=`${t.styleKey}-bitmap`,n=!1),!re.has(r)){const c=Object.create(t);c.lineHeight=0;const l=new Pc({style:c,overrideFill:n,overrideSize:!0,...this.defaultOptions});Jr++,Jr>50&&G("BitmapText",`You have dynamically created ${Jr} bitmap fonts, this can be inefficient. Try pre installing your font styles using \`BitmapFont.install({name:"style1", style})\``),l.once("destroy",()=>{Jr--,re.remove(r)}),re.set(r,l)}const o=re.get(r);return o.ensureCharacters?.(e),o}getLayout(e,t,r=!0){const n=this.getFont(e,t),o=`${e}-${t.styleKey}-${r}`;if(this.measureCache.has(o))return this.measureCache.get(o);const c=Be.graphemeSegmenter(e),l=Ln(c,t,n,r);return this.measureCache.set(o,l),l}measureText(e,t,r=!0){return this.getLayout(e,t,r)}install(...e){let t=e[0];typeof t=="string"&&(t={name:t,style:e[1],chars:e[2]?.chars,resolution:e[2]?.resolution,padding:e[2]?.padding,skipKerning:e[2]?.skipKerning},H(j,"BitmapFontManager.install(name, style, options) is deprecated, use BitmapFontManager.install({name, style, ...options})"));const r=t?.name;if(!r)throw new Error("[BitmapFontManager] Property `name` is required.");t={...this.defaultOptions,...t};const n=t.style,o=n instanceof De?n:new De(n),c=t.dynamicFill??this._canUseTintForStyle(o),l=new Pc({style:o,overrideFill:c,skipKerning:t.skipKerning,padding:t.padding,resolution:t.resolution,overrideSize:!1,textureStyle:t.textureStyle}),d=E0(t.chars);return l.ensureCharacters(d.join("")),re.set(`${r}-bitmap`,l),l.once("destroy",()=>re.remove(`${r}-bitmap`)),l}uninstall(e){const t=`${e}-bitmap`,r=re.get(t);r&&r.destroy()}_canUseTintForStyle(e){return!e._stroke&&(!e.dropShadow||e.dropShadow.color===0)&&!e._fill.fill&&e._fill.color===16777215}}const Qi=new I0;class Rc extends Ol{constructor(e,t){super();const{textures:r,data:n}=e;Object.keys(n.pages).forEach(o=>{const c=n.pages[parseInt(o,10)],l=r[c.id];this.pages.push({texture:l})}),Object.keys(n.chars).forEach(o=>{const c=n.chars[o],{frame:l,source:d,rotate:f}=r[c.page],m=ie.transformRectCoords(c,l,f,new z),g=new F({frame:m,orig:new z(0,0,c.width,c.height),source:d,rotate:f});this.chars[o]={id:o.codePointAt(0),xOffset:c.xOffset,yOffset:c.yOffset,xAdvance:c.xAdvance,kerning:c.kerning??{},texture:g}}),this.baseRenderedFontSize=n.fontSize,this.baseMeasurementFontSize=n.fontSize,this.fontMetrics={ascent:0,descent:0,fontSize:n.fontSize},this.baseLineOffset=n.baseLineOffset,this.lineHeight=n.lineHeight,this.fontFamily=n.fontFamily,this.distanceField=n.distanceField??{type:"none",range:0},this.url=t}destroy(){super.destroy();for(let e=0;e<this.pages.length;e++){const{texture:t}=this.pages[e];t.destroy(!0)}this.pages=null}static install(e){Qi.install(e)}static uninstall(e){Qi.uninstall(e)}}const Nn={test(s){return typeof s=="string"&&s.startsWith("info face=")},parse(s){const e=s.match(/^[a-z]+\s+.+$/gm),t={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const g in e){const _=e[g].match(/^[a-z]+/gm)[0],y=e[g].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),a={};for(const h in y){const u=y[h].split("="),p=u[0],v=u[1].replace(/"/gm,""),x=parseFloat(v),b=isNaN(x)?v:x;a[p]=b}t[_].push(a)}const r={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},[n]=t.info,[o]=t.common,[c]=t.distanceField??[];c&&(r.distanceField={range:parseInt(c.distanceRange,10),type:c.fieldType}),r.fontSize=parseInt(n.size,10),r.fontFamily=n.face,r.lineHeight=parseInt(o.lineHeight,10);const l=t.page;for(let g=0;g<l.length;g++)r.pages.push({id:parseInt(l[g].id,10)||0,file:l[g].file});const d={};r.baseLineOffset=r.lineHeight-parseInt(o.base,10);const f=t.char;for(let g=0;g<f.length;g++){const _=f[g],y=parseInt(_.id,10);let a=_.letter??_.char??String.fromCharCode(y);a==="space"&&(a=" "),d[y]=a,r.chars[a]={id:y,page:parseInt(_.page,10)||0,x:parseInt(_.x,10),y:parseInt(_.y,10),width:parseInt(_.width,10),height:parseInt(_.height,10),xOffset:parseInt(_.xoffset,10),yOffset:parseInt(_.yoffset,10),xAdvance:parseInt(_.xadvance,10),kerning:{}}}const m=t.kerning||[];for(let g=0;g<m.length;g++){const _=parseInt(m[g].first,10),y=parseInt(m[g].second,10),a=parseInt(m[g].amount,10);r.chars[d[y]].kerning[d[_]]=a}return r}},Mc={test(s){const e=s;return typeof e!="string"&&"getElementsByTagName"in e&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null},parse(s){const e={chars:{},pages:[],lineHeight:0,fontSize:0,fontFamily:"",distanceField:null,baseLineOffset:0},t=s.getElementsByTagName("info")[0],r=s.getElementsByTagName("common")[0],n=s.getElementsByTagName("distanceField")[0];n&&(e.distanceField={type:n.getAttribute("fieldType"),range:parseInt(n.getAttribute("distanceRange"),10)});const o=s.getElementsByTagName("page"),c=s.getElementsByTagName("char"),l=s.getElementsByTagName("kerning");e.fontSize=parseInt(t.getAttribute("size"),10),e.fontFamily=t.getAttribute("face"),e.lineHeight=parseInt(r.getAttribute("lineHeight"),10);for(let f=0;f<o.length;f++)e.pages.push({id:parseInt(o[f].getAttribute("id"),10)||0,file:o[f].getAttribute("file")});const d={};e.baseLineOffset=e.lineHeight-parseInt(r.getAttribute("base"),10);for(let f=0;f<c.length;f++){const m=c[f],g=parseInt(m.getAttribute("id"),10);let _=m.getAttribute("letter")??m.getAttribute("char")??String.fromCharCode(g);_==="space"&&(_=" "),d[g]=_,e.chars[_]={id:g,page:parseInt(m.getAttribute("page"),10)||0,x:parseInt(m.getAttribute("x"),10),y:parseInt(m.getAttribute("y"),10),width:parseInt(m.getAttribute("width"),10),height:parseInt(m.getAttribute("height"),10),xOffset:parseInt(m.getAttribute("xoffset"),10),yOffset:parseInt(m.getAttribute("yoffset"),10),xAdvance:parseInt(m.getAttribute("xadvance"),10),kerning:{}}}for(let f=0;f<l.length;f++){const m=parseInt(l[f].getAttribute("first"),10),g=parseInt(l[f].getAttribute("second"),10),_=parseInt(l[f].getAttribute("amount"),10);e.chars[d[g]].kerning[d[m]]=_}return e}},Fc={test(s){return typeof s=="string"&&s.match(/<font(\s|>)/)?Mc.test(V.get().parseXML(s)):!1},parse(s){return Mc.parse(V.get().parseXML(s))}},P0=[".xml",".fnt"],R0={extension:{type:C.CacheParser,name:"cacheBitmapFont"},test:s=>s instanceof Rc,getCacheableAssets(s,e){const t={};return s.forEach(r=>{t[r]=e,t[`${r}-bitmap`]=e}),t[`${e.fontFamily}-bitmap`]=e,t}},M0={extension:{type:C.LoadParser,priority:At.Normal},name:"loadBitmapFont",id:"bitmap-font",test(s){return P0.includes(ze.extname(s).toLowerCase())},async testParse(s){return Nn.test(s)||Fc.test(s)},async parse(s,e,t){const r=Nn.test(s)?Nn.parse(s):Fc.parse(s),{src:n}=e,{pages:o}=r,c=[],l=r.distanceField?{scaleMode:"linear",alphaMode:"premultiply-alpha-on-upload",autoGenerateMipmaps:!1,resolution:1}:{};for(let g=0;g<o.length;++g){const _=o[g].file;let y=ze.join(ze.dirname(n),_);y=Ks(y,n),c.push({src:y,data:l})}const d=await t.load(c),f=c.map(g=>d[g.src]);return new Rc({data:r,textures:f},n)},async load(s,e){return await(await V.get().fetch(s)).text()},async unload(s,e,t){await Promise.all(s.pages.map(r=>t.unload(r.texture.source._sourceOrigin))),s.destroy()}};class F0{constructor(e,t=!1){this._loader=e,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=t}add(e){e.forEach(t=>{this._assetList.push(t)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const e=[],t=Math.min(this._assetList.length,this._maxConcurrent);for(let r=0;r<t;r++)e.push(this._assetList.pop());await this._loader.load(e),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(e){this._isActive!==e&&(this._isActive=e,e&&!this._isLoading&&this._next())}}const U0={extension:{type:C.CacheParser,name:"cacheTextureArray"},test:s=>Array.isArray(s)&&s.every(e=>e instanceof F),getCacheableAssets:(s,e)=>{const t={};return s.forEach(r=>{e.forEach((n,o)=>{t[r+(o===0?"":o+1)]=n})}),t}};async function Uc(s){if("Image"in globalThis)return new Promise(e=>{const t=new Image;t.onload=()=>{e(!0)},t.onerror=()=>{e(!1)},t.src=s});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const e=await(await fetch(s)).blob();await createImageBitmap(e)}catch{return!1}return!0}return!1}const k0={extension:{type:C.DetectionParser,priority:1},test:async()=>Uc("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async s=>[...s,"avif"],remove:async s=>s.filter(e=>e!=="avif")},kc=["png","jpg","jpeg"],B0={extension:{type:C.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async s=>[...s,...kc],remove:async s=>s.filter(e=>!kc.includes(e))},D0="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function Qr(s){return D0?!1:document.createElement("video").canPlayType(s)!==""}const O0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/mp4"),add:async s=>[...s,"mp4","m4v"],remove:async s=>s.filter(e=>e!=="mp4"&&e!=="m4v")},G0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/ogg"),add:async s=>[...s,"ogv"],remove:async s=>s.filter(e=>e!=="ogv")},L0={extension:{type:C.DetectionParser,priority:0},test:async()=>Qr("video/webm"),add:async s=>[...s,"webm"],remove:async s=>s.filter(e=>e!=="webm")},N0={extension:{type:C.DetectionParser,priority:0},test:async()=>Uc("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async s=>[...s,"webp"],remove:async s=>s.filter(e=>e!=="webp")},Bc=class ls{constructor(){this.loadOptions={...ls.defaultOptions},this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(e,t,r)=>(this._parsersValidated=!1,e[t]=r,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(e,t){const r={promise:null,parser:null};return r.promise=(async()=>{let n=null,o=null;if((t.parser||t.loadParser)&&(o=this._parserHash[t.parser||t.loadParser],t.loadParser&&G(`[Assets] "loadParser" is deprecated, use "parser" instead for ${e}`),o||G(`[Assets] specified load parser "${t.parser||t.loadParser}" not found while loading ${e}`)),!o){for(let c=0;c<this.parsers.length;c++){const l=this.parsers[c];if(l.load&&l.test?.(e,t,this)){o=l;break}}if(!o)return G(`[Assets] ${e} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}n=await o.load(e,t,this),r.parser=o;for(let c=0;c<this.parsers.length;c++){const l=this.parsers[c];l.parse&&l.parse&&await l.testParse?.(n,t,this)&&(n=await l.parse(n,t,this)||n,r.parser=l)}return n})(),r}async load(e,t){this._parsersValidated||this._validateParsers();const r=typeof t=="function"?{...ls.defaultOptions,...this.loadOptions,onProgress:t}:{...ls.defaultOptions,...this.loadOptions,...t||{}},{onProgress:n,onError:o,strategy:c,retryCount:l,retryDelay:d}=r;let f=0;const m={},g=Fr(e),_=Qe(e,h=>({alias:[h],src:h,data:{}})),y=_.reduce((h,u)=>h+(u.progressSize||1),0),a=_.map(async h=>{const u=ze.toAbsolute(h.src);m[h.src]||(await this._loadAssetWithRetry(u,h,{onProgress:n,onError:o,strategy:c,retryCount:l,retryDelay:d},m),f+=h.progressSize||1,n&&n(f/y))});return await Promise.all(a),g?m[_[0].src]:m}async unload(e){const r=Qe(e,n=>({alias:[n],src:n})).map(async n=>{const o=ze.toAbsolute(n.src),c=this.promiseCache[o];if(c){const l=await c.promise;delete this.promiseCache[o],await c.parser?.unload?.(l,n,this)}});await Promise.all(r)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(e=>e.name||e.id).reduce((e,t)=>(!t.name&&!t.id?G("[Assets] parser should have an id"):(e[t.name]||e[t.id])&&G(`[Assets] parser id conflict "${t.id}"`),e[t.name]=t,t.id&&(e[t.id]=t),e),{})}async _loadAssetWithRetry(e,t,r,n){let o=0;const{onError:c,strategy:l,retryCount:d,retryDelay:f}=r,m=g=>new Promise(_=>setTimeout(_,g));for(;;)try{this.promiseCache[e]||(this.promiseCache[e]=this._getLoadPromiseAndParser(e,t)),n[t.src]=await this.promiseCache[e].promise;return}catch(g){delete this.promiseCache[e],delete n[t.src],o++;const _=l!=="retry"||o>d;if(l==="retry"&&!_){c&&c(g,t),await m(f);continue}if(l==="skip"){c&&c(g,t);return}throw c&&c(g,t),new Error(`[Loader.load] Failed to load ${e}.
|
|
321
|
+
${g}`)}}};Bc.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",retryCount:3,retryDelay:250};let z0=Bc;function ai(s,e){if(Array.isArray(e)){for(const t of e)if(s.startsWith(`data:${t}`))return!0;return!1}return s.startsWith(`data:${e}`)}function li(s,e){const t=s.split("?")[0],r=ze.extname(t).toLowerCase();return Array.isArray(e)?e.includes(r):r===e}const H0=".json",W0="application/json",V0={extension:{type:C.LoadParser,priority:At.Low},name:"loadJson",id:"json",test(s){return ai(s,W0)||li(s,H0)},async load(s){return await(await V.get().fetch(s)).json()}},Y0=".txt",X0="text/plain",$0={name:"loadTxt",id:"text",extension:{type:C.LoadParser,priority:At.Low,name:"loadTxt"},test(s){return ai(s,X0)||li(s,Y0)},async load(s){return await(await V.get().fetch(s)).text()}},q0=["normal","bold","100","200","300","400","500","600","700","800","900"],K0=[".ttf",".otf",".woff",".woff2"],j0=["font/ttf","font/otf","font/woff","font/woff2"],Z0=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function J0(s){const e=ze.extname(s),n=ze.basename(s,e).replace(/(-|_)/g," ").toLowerCase().split(" ").map(l=>l.charAt(0).toUpperCase()+l.slice(1));let o=n.length>0;for(const l of n)if(!l.match(Z0)){o=!1;break}let c=n.join(" ");return o||(c=`"${c.replace(/[\\"]/g,"\\$&")}"`),c}const Q0=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function ev(s){return Q0.test(s)?s:encodeURI(s)}const tv={extension:{type:C.LoadParser,priority:At.Low},name:"loadWebFont",id:"web-font",test(s){return ai(s,j0)||li(s,K0)},async load(s,e){const t=V.get().getFontFaceSet();if(t){const r=[],n=e.data?.family??J0(s),o=e.data?.weights?.filter(l=>q0.includes(l))??["normal"],c=e.data??{};for(let l=0;l<o.length;l++){const d=o[l],f=new FontFace(n,`url(${ev(s)})`,{...c,weight:d});await f.load(),t.add(f),r.push(f)}return re.has(`${n}-and-url`)?re.get(`${n}-and-url`).entries.push({url:s,faces:r}):re.set(`${n}-and-url`,{entries:[{url:s,faces:r}]}),r.length===1?r[0]:r}return G("[loadWebFont] FontFace API is not supported. Skipping loading font"),null},unload(s){const e=Array.isArray(s)?s:[s],t=e[0].family,r=re.get(`${t}-and-url`),n=r.entries.find(o=>o.faces.some(c=>e.indexOf(c)!==-1));n.faces=n.faces.filter(o=>e.indexOf(o)===-1),n.faces.length===0&&(r.entries=r.entries.filter(o=>o!==n)),e.forEach(o=>{V.get().getFontFaceSet().delete(o)}),r.entries.length===0&&re.remove(`${t}-and-url`)}};function zn(s,e=1){const t=ii.RETINA_PREFIX?.exec(s);return t?parseFloat(t[1]):e}function Hn(s,e,t){s.label=t,s._sourceOrigin=t;const r=new F({source:s,label:t}),n=()=>{delete e.promiseCache[t],re.has(t)&&re.remove(t)};return r.source.once("destroy",()=>{e.promiseCache[t]&&(G("[Assets] A TextureSource managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the TextureSource."),n())}),r.once("destroy",()=>{s.destroyed||(G("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture."),n())}),r}const iv=".svg",rv="image/svg+xml",sv={extension:{type:C.LoadParser,priority:At.Low,name:"loadSVG"},name:"loadSVG",id:"svg",config:{crossOrigin:"anonymous",parseAsGraphicsContext:!1},test(s){return ai(s,rv)||li(s,iv)},async load(s,e,t){return e.data?.parseAsGraphicsContext??this.config.parseAsGraphicsContext?ov(s):nv(s,e,t,this.config.crossOrigin)},unload(s){s.destroy(!0)}};async function nv(s,e,t,r){const n=await V.get().fetch(s),o=V.get().createImage();o.src=`data:image/svg+xml;charset=utf-8,${encodeURIComponent(await n.text())}`,o.crossOrigin=r,await o.decode();const c=e.data?.width??o.width,l=e.data?.height??o.height,d=e.data?.resolution||zn(s),f=Math.ceil(c*d),m=Math.ceil(l*d),g=V.get().createCanvas(f,m),_=g.getContext("2d");_.imageSmoothingEnabled=!0,_.imageSmoothingQuality="high",_.drawImage(o,0,0,c*d,l*d);const{parseAsGraphicsContext:y,...a}=e.data??{},h=new ct({resource:g,alphaMode:"premultiply-alpha-on-upload",resolution:d,...a});return Hn(h,t,s)}async function ov(s){const t=await(await V.get().fetch(s)).text(),r=new je;return r.svg(t),r}const av=`(function () {
|
|
322
322
|
'use strict';
|
|
323
323
|
|
|
324
324
|
const WHITE_PNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=";
|
|
@@ -368,7 +368,7 @@ ${g}`)}}};Bc.defaultOptions={onProgress:void 0,onError:void 0,strategy:"throw",r
|
|
|
368
368
|
};
|
|
369
369
|
|
|
370
370
|
})();
|
|
371
|
-
`;let hi=null;class Dc{constructor(){hi||(hi=URL.createObjectURL(new Blob([lv],{type:"application/javascript"}))),this.worker=new Worker(hi)}}Dc.revokeObjectURL=function(){hi&&(URL.revokeObjectURL(hi),hi=null)};let Oc=0,Vn;class cv{constructor(){this._initialized=!1,this._createdWorkers=0,this._workerPool=[],this._queue=[],this._resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(e=>{const{worker:t}=new Wn;t.addEventListener("message",r=>{t.terminate(),Wn.revokeObjectURL(),e(r.data)})}),this._isImageBitmapSupported)}loadImageBitmap(e,t){return this._run("loadImageBitmap",[e,t?.data?.alphaMode])}async _initWorkers(){this._initialized||(this._initialized=!0)}_getWorker(){Vn===void 0&&(Vn=navigator.hardwareConcurrency||4);let e=this._workerPool.pop();return!e&&this._createdWorkers<Vn&&(this._createdWorkers++,e=new Dc().worker,e.addEventListener("message",t=>{this._complete(t.data),this._returnWorker(t.target),this._next()})),e}_returnWorker(e){this._workerPool.push(e)}_complete(e){this._resolveHash[e.uuid]&&(e.error!==void 0?this._resolveHash[e.uuid].reject(e.error):this._resolveHash[e.uuid].resolve(e.data),delete this._resolveHash[e.uuid])}async _run(e,t){await this._initWorkers();const r=new Promise((n,o)=>{this._queue.push({id:e,arguments:t,resolve:n,reject:o})});return this._next(),r}_next(){if(!this._queue.length)return;const e=this._getWorker();if(!e)return;const t=this._queue.pop(),r=t.id;this._resolveHash[Oc]={resolve:t.resolve,reject:t.reject},e.postMessage({data:t.arguments,uuid:Oc++,id:r})}reset(){this._workerPool.forEach(e=>e.terminate()),this._workerPool.length=0,Object.values(this._resolveHash).forEach(({reject:e})=>{e?.(new Error("WorkerManager has been reset before completion"))}),this._resolveHash={},this._queue.length=0,this._initialized=!1,this._createdWorkers=0}}const Gc=new cv,hv=[".jpeg",".jpg",".png",".webp",".avif"],uv=["image/jpeg","image/png","image/webp","image/avif"];async function dv(s,e){const t=await V.get().fetch(s);if(!t.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${s}: ${t.status} ${t.statusText}`);const r=await t.blob();return e?.data?.alphaMode==="premultiplied-alpha"?createImageBitmap(r,{premultiplyAlpha:"none"}):createImageBitmap(r)}const Lc={name:"loadTextures",id:"texture",extension:{type:C.LoadParser,priority:At.High,name:"loadTextures"},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(s){return ai(s,uv)||li(s,hv)},async load(s,e,t){let r=null;globalThis.createImageBitmap&&this.config.preferCreateImageBitmap?this.config.preferWorkers&&await Gc.isImageBitmapSupported()?r=await Gc.loadImageBitmap(s,e):r=await dv(s,e):r=await new Promise((o,c)=>{r=V.get().createImage(),r.crossOrigin=this.config.crossOrigin,r.src=s,r.complete?o(r):(r.onload=()=>{o(r)},r.onerror=c)});const n=new ct({resource:r,alphaMode:"premultiply-alpha-on-upload",resolution:e.data?.resolution||zn(s),...e.data});return Hn(n,t,s)},unload(s){s.destroy(!0)}},fv=[".mp4",".m4v",".webm",".ogg",".ogv",".h264",".avi",".mov"];let Yn,Xn;function pv(s,e,t){t===void 0&&!e.startsWith("data:")?s.crossOrigin=gv(e):t!==!1&&(s.crossOrigin=typeof t=="string"?t:"anonymous")}function mv(s){return new Promise((e,t)=>{s.addEventListener("canplaythrough",r),s.addEventListener("error",n),s.load();function r(){o(),e()}function n(c){o(),t(c)}function o(){s.removeEventListener("canplaythrough",r),s.removeEventListener("error",n)}})}function gv(s,e=globalThis.location){if(s.startsWith("data:"))return"";e||(e=globalThis.location);const t=new URL(s,document.baseURI);return t.hostname!==e.hostname||t.port!==e.port||t.protocol!==e.protocol?"anonymous":""}function vv(){const s=[],e=[];for(const t of fv){const r=Ii.MIME_TYPES[t.substring(1)]||`video/${t.substring(1)}`;Qr(r)&&(s.push(t),e.includes(r)||e.push(r))}return{validVideoExtensions:s,validVideoMime:e}}const _v={name:"loadVideo",id:"video",extension:{type:C.LoadParser,name:"loadVideo"},test(s){if(!Yn||!Xn){const{validVideoExtensions:r,validVideoMime:n}=vv();Yn=r,Xn=n}const e=ai(s,Xn),t=li(s,Yn);return e||t},async load(s,e,t){const r={...Ii.defaultOptions,resolution:e.data?.resolution||zn(s),alphaMode:e.data?.alphaMode||await $a(),...e.data},n=document.createElement("video"),o={preload:r.autoLoad!==!1?"auto":void 0,"webkit-playsinline":r.playsinline!==!1?"":void 0,playsinline:r.playsinline!==!1?"":void 0,muted:r.muted===!0?"":void 0,loop:r.loop===!0?"":void 0,autoplay:r.autoPlay!==!1?"":void 0};Object.keys(o).forEach(d=>{const f=o[d];f!==void 0&&n.setAttribute(d,f)}),r.muted===!0&&(n.muted=!0),pv(n,s,r.crossorigin);const c=document.createElement("source");let l;if(r.mime)l=r.mime;else if(s.startsWith("data:"))l=s.slice(5,s.indexOf(";"));else if(!s.startsWith("blob:")){const d=s.split("?")[0].slice(s.lastIndexOf(".")+1).toLowerCase();l=Ii.MIME_TYPES[d]||`video/${d}`}return c.src=s,l&&(c.type=l),new Promise(d=>{const f=async()=>{const m=new Ii({...r,resource:n});n.removeEventListener("canplay",f),e.data.preload&&await mv(n),d(Hn(m,t,s))};r.preload&&!r.autoPlay&&n.load(),n.addEventListener("canplay",f),n.appendChild(c)})},unload(s){s.destroy(!0)}},Nc={extension:{type:C.ResolveParser,name:"resolveTexture"},test:Lc.test,parse:s=>({resolution:parseFloat(ii.RETINA_PREFIX.exec(s)?.[1]??"1"),format:s.split(".").pop(),src:s})},yv={extension:{type:C.ResolveParser,priority:-2,name:"resolveJson"},test:s=>ii.RETINA_PREFIX.test(s)&&s.endsWith(".json"),parse:Nc.parse};class xv{constructor(){this._detections=[],this._initialized=!1,this.resolver=new ii,this.loader=new z0,this.cache=re,this._backgroundLoader=new F0(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(e={}){if(this._initialized){G("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,e.defaultSearchParams&&this.resolver.setDefaultSearchParams(e.defaultSearchParams),e.basePath&&(this.resolver.basePath=e.basePath),e.bundleIdentifier&&this.resolver.setBundleIdentifier(e.bundleIdentifier),e.manifest){let o=e.manifest;typeof o=="string"&&(o=await this.load(o)),this.resolver.addManifest(o)}const t=e.texturePreference?.resolution??1,r=typeof t=="number"?[t]:t,n=await this._detectFormats({preferredFormats:e.texturePreference?.format,skipDetections:e.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:n,resolution:r}}),e.preferences&&this.setPreferences(e.preferences),e.loadOptions&&(this.loader.loadOptions={...this.loader.loadOptions,...e.loadOptions})}add(e){this.resolver.add(e)}async load(e,t){this._initialized||await this.init();const r=Fr(e),n=Qe(e).map(l=>{if(typeof l!="string"){const d=this.resolver.getAlias(l);return d.some(f=>!this.resolver.hasKey(f))&&this.add(l),Array.isArray(d)?d[0]:d}return this.resolver.hasKey(l)||this.add({alias:l,src:l}),l}),o=this.resolver.resolve(n),c=await this._mapLoadToResolve(o,t);return r?c[n[0]]:c}addBundle(e,t){this.resolver.addBundle(e,t)}async loadBundle(e,t){this._initialized||await this.init();let r=!1;typeof e=="string"&&(r=!0,e=[e]);const n=this.resolver.resolveBundle(e),o={},c=Object.keys(n);let l=0;const d=[],f=()=>{t?.(d.reduce((g,_)=>g+_,0)/l)},m=c.map((g,_)=>{const y=n[g],a=Object.values(y),u=[...new Set(a.flat())].reduce((p,v)=>p+(v.progressSize||1),0);return d.push(0),l+=u,this._mapLoadToResolve(y,p=>{d[_]=p*u,f()}).then(p=>{o[g]=p})});return await Promise.all(m),r?o[e[0]]:o}async backgroundLoad(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolve(e);this._backgroundLoader.add(Object.values(t))}async backgroundLoadBundle(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolveBundle(e);Object.values(t).forEach(r=>{this._backgroundLoader.add(Object.values(r))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(e){if(typeof e=="string")return re.get(e);const t={};for(let r=0;r<e.length;r++)t[r]=re.get(e[r]);return t}async _mapLoadToResolve(e,t){const r=[...new Set(Object.values(e))];this._backgroundLoader.active=!1;const n=await this.loader.load(r,t);this._backgroundLoader.active=!0;const o={};return r.forEach(c=>{const l=n[c.src],d=[c.src];c.alias&&d.push(...c.alias),d.forEach(f=>{o[f]=l}),re.set(d,l)}),o}async unload(e){this._initialized||await this.init();const t=Qe(e).map(n=>typeof n!="string"?n.src:n),r=this.resolver.resolve(t);await this._unloadFromResolved(r)}async unloadBundle(e){this._initialized||await this.init(),e=Qe(e);const t=this.resolver.resolveBundle(e),r=Object.keys(t).map(n=>this._unloadFromResolved(t[n]));await Promise.all(r)}async _unloadFromResolved(e){const t=Object.values(e);t.forEach(r=>{re.remove(r.src)}),await this.loader.unload(t)}async _detectFormats(e){let t=[];e.preferredFormats&&(t=Array.isArray(e.preferredFormats)?e.preferredFormats:[e.preferredFormats]);for(const r of e.detections)e.skipDetections||await r.test()?t=await r.add(t):e.skipDetections||(t=await r.remove(t));return t=t.filter((r,n)=>t.indexOf(r)===n),t}get detections(){return this._detections}setPreferences(e){this.loader.parsers.forEach(t=>{t.config&&Object.keys(t.config).filter(r=>r in e).forEach(r=>{t.config[r]=e[r]})})}}const er=new xv;L.handleByList(C.LoadParser,er.loader.parsers).handleByList(C.ResolveParser,er.resolver.parsers).handleByList(C.CacheParser,er.cache.parsers).handleByList(C.DetectionParser,er.detections),L.add(U0,B0,k0,N0,O0,G0,L0,V0,$0,tv,sv,Lc,_v,M0,R0,Nc,yv);const zc={loader:C.LoadParser,resolver:C.ResolveParser,cache:C.CacheParser,detection:C.DetectionParser};L.handle(C.Asset,s=>{const e=s.ref;Object.entries(zc).filter(([t])=>!!e[t]).forEach(([t,r])=>L.add(Object.assign(e[t],{extension:e[t].extension??r})))},s=>{const e=s.ref;Object.keys(zc).filter(t=>!!e[t]).forEach(t=>L.remove(e[t]))});class Hc{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 Qa({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 r=e[t],n=r.element;if(!r.parent||r.globalDisplayStatus<7)n?.remove(),e.splice(t,1),t--;else{this._domElement.contains(n)||(n.style.position="absolute",n.style.pointerEvents="auto",this._domElement.appendChild(n));const o=r.worldTransform,c=r._anchor,l=r.width*c.x,d=r.height*c.y;n.style.transformOrigin=`${l}px ${d}px`,n.style.transform=`matrix(${o.a}, ${o.b}, ${o.c}, ${o.d}, ${o.tx-l}, ${o.ty-d})`,n.style.opacity=r.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}}Hc.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"dom"};class bv{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||(Le.system.add(this._tickerUpdate,this,ti.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(Le.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 bt=new bv;class es extends Ri{constructor(){super(...arguments),this.client=new J,this.movement=new J,this.offset=new J,this.global=new J,this.screen=new J}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,r){return e.worldTransform.applyInverse(r||this.global,t)}getModifierState(e){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(e)}initMouseEvent(e,t,r,n,o,c,l,d,f,m,g,_,y,a,h){throw new Error("Method not implemented.")}}class st extends es{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class ui extends es{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}ui.DOM_DELTA_PIXEL=0,ui.DOM_DELTA_LINE=1,ui.DOM_DELTA_PAGE=2;const Tv=2048,wv=new J,tr=new J;class Sv{constructor(e){this.dispatch=new Ge,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.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)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((r,n)=>r.priority-n.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 r=0,n=t.length;r<n;r++)t[r].fn(e);else G(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){bt.pauseUpdate=!0;const n=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",o=this[n](this.rootTarget,this.rootTarget.eventMode,wv.set(e,t),this.hitTestFn,this.hitPruneFn);return o&&o[0]}propagate(e,t){if(!e.target)return;const r=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let n=0,o=r.length-1;n<o;n++)if(e.currentTarget=r[n],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 n=r.length-2;n>=0;n--)if(e.currentTarget=r[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,r=this._allInteractiveElements){if(r.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const n=Array.isArray(t)?t:[t];for(let o=r.length-1;o>=0;o--)n.forEach(c=>{e.currentTarget=r[o],this.notifyTarget(e,c)})}propagationPath(e){const t=[e];for(let r=0;r<Tv&&e!==this.rootTarget&&e.parent;r++){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,r,n,o,c=!1){let l=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(bt.pauseUpdate=!1),e.interactiveChildren&&e.children){const m=e.children;for(let g=m.length-1;g>=0;g--){const _=m[g],y=this.hitTestMoveRecursive(_,this._isInteractive(t)?t:_.eventMode,r,n,o,c||o(e,r));if(y){if(y.length>0&&!y[y.length-1].parent)continue;const a=e.isInteractive();(y.length>0||a)&&(a&&this._allInteractiveElements.push(e),y.push(e)),this._hitElements.length===0&&(this._hitElements=y),l=!0}}}const d=this._isInteractive(t),f=e.isInteractive();return f&&f&&this._allInteractiveElements.push(e),c||this._hitElements.length>0?null:l?this._hitElements:d&&!o(e,r)&&n(e,r)?f?[e]:[]:null}hitTestRecursive(e,t,r,n,o){if(this._interactivePrune(e)||o(e,r))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(bt.pauseUpdate=!1),e.interactiveChildren&&e.children){const d=e.children,f=r;for(let m=d.length-1;m>=0;m--){const g=d[m],_=this.hitTestRecursive(g,this._isInteractive(t)?t:g.eventMode,f,n,o);if(_){if(_.length>0&&!_[_.length-1].parent)continue;const y=e.isInteractive();return(_.length>0||y)&&_.push(e),_}}}const c=this._isInteractive(t),l=e.isInteractive();return c&&n(e,r)?l?[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,tr),!e.hitArea.contains(tr.x,tr.y)))return!0;if(e.effects&&e.effects.length)for(let r=0;r<e.effects.length;r++){const n=e.effects[r];if(n.containsPoint&&!n.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e?.containsPoint?(e.worldTransform.applyInverse(t,tr),e.containsPoint(tr)):!1}notifyTarget(e,t){if(!e.currentTarget.isInteractive())return;t??(t=e.type);const r=`on${t}`;e.currentTarget[r]?.(e);const n=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,n),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof st)){G("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 n=t.button===2;this.dispatchEvent(t,n?"rightdown":"mousedown")}const r=this.trackingData(e.pointerId);r.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){if(!(e instanceof st)){G("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 r=t.pointerType==="mouse"||t.pointerType==="pen",n=this.trackingData(e.pointerId),o=this.findMountedTarget(n.overTargets);if(n.overTargets?.length>0&&o!==t.target){const d=e.type==="mousemove"?"mouseout":"pointerout",f=this.createPointerEvent(e,d,o);if(this.dispatchEvent(f,"pointerout"),r&&this.dispatchEvent(f,"mouseout"),!t.composedPath().includes(o)){const m=this.createPointerEvent(e,"pointerleave",o);for(m.eventPhase=m.AT_TARGET;m.target&&!t.composedPath().includes(m.target);)m.currentTarget=m.target,this.notifyTarget(m),r&&this.notifyTarget(m,"mouseleave"),m.target=m.target.parent;this.freeEvent(m)}this.freeEvent(f)}if(o!==t.target){const d=e.type==="mousemove"?"mouseover":"pointerover",f=this.clonePointerEvent(t,d);this.dispatchEvent(f,"pointerover"),r&&this.dispatchEvent(f,"mouseover");let m=o?.parent;for(;m&&m!==this.rootTarget.parent&&m!==t.target;)m=m.parent;if(!m||m===this.rootTarget.parent){const _=this.clonePointerEvent(t,"pointerenter");for(_.eventPhase=_.AT_TARGET;_.target&&_.target!==o&&_.target!==this.rootTarget.parent;)_.currentTarget=_.target,this.notifyTarget(_),r&&this.notifyTarget(_,"mouseenter"),_.target=_.target.parent;this.freeEvent(_)}this.freeEvent(f)}const c=[],l=this.enableGlobalMoveEvents??!0;this.moveOnAll?c.push("pointermove"):this.dispatchEvent(t,"pointermove"),l&&c.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?c.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),l&&c.push("globaltouchmove")),r&&(this.moveOnAll?c.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),l&&c.push("globalmousemove"),this.cursor=t.target?.cursor),c.length>0&&this.all(t,c),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),r=this.createPointerEvent(e),n=r.pointerType==="mouse"||r.pointerType==="pen";this.dispatchEvent(r,"pointerover"),n&&this.dispatchEvent(r,"mouseover"),r.pointerType==="mouse"&&(this.cursor=r.target?.cursor);const o=this.clonePointerEvent(r,"pointerenter");for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),n&&this.notifyTarget(o,"mouseenter"),o.target=o.target.parent;t.overTargets=r.composedPath(),this.freeEvent(r),this.freeEvent(o)}mapPointerOut(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const r=e.pointerType==="mouse"||e.pointerType==="pen",n=this.findMountedTarget(t.overTargets),o=this.createPointerEvent(e,"pointerout",n);this.dispatchEvent(o),r&&this.dispatchEvent(o,"mouseout");const c=this.createPointerEvent(e,"pointerleave",n);for(c.eventPhase=c.AT_TARGET;c.target&&c.target!==this.rootTarget.parent;)c.currentTarget=c.target,this.notifyTarget(c),r&&this.notifyTarget(c,"mouseleave"),c.target=c.target.parent;t.overTargets=null,this.freeEvent(o),this.freeEvent(c)}this.cursor=null}mapPointerUp(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),r=this.createPointerEvent(e);if(this.dispatchEvent(r,"pointerup"),r.pointerType==="touch")this.dispatchEvent(r,"touchend");else if(r.pointerType==="mouse"||r.pointerType==="pen"){const l=r.button===2;this.dispatchEvent(r,l?"rightup":"mouseup")}const n=this.trackingData(e.pointerId),o=this.findMountedTarget(n.pressTargetsByButton[e.button]);let c=o;if(o&&!r.composedPath().includes(o)){let l=o;for(;l&&!r.composedPath().includes(l);){if(r.currentTarget=l,this.notifyTarget(r,"pointerupoutside"),r.pointerType==="touch")this.notifyTarget(r,"touchendoutside");else if(r.pointerType==="mouse"||r.pointerType==="pen"){const d=r.button===2;this.notifyTarget(r,d?"rightupoutside":"mouseupoutside")}l=l.parent}delete n.pressTargetsByButton[e.button],c=l}if(c){const l=this.clonePointerEvent(r,"click");l.target=c,l.path=null,n.clicksByButton[e.button]||(n.clicksByButton[e.button]={clickCount:0,target:l.target,timeStamp:t});const d=n.clicksByButton[e.button];if(d.target===l.target&&t-d.timeStamp<200?++d.clickCount:d.clickCount=1,d.target=l.target,d.timeStamp=t,l.detail=d.clickCount,l.pointerType==="mouse"){const f=l.button===2;this.dispatchEvent(l,f?"rightclick":"click")}else l.pointerType==="touch"&&this.dispatchEvent(l,"tap");this.dispatchEvent(l,"pointertap"),this.freeEvent(l)}this.freeEvent(r)}mapPointerUpOutside(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),r=this.findMountedTarget(t.pressTargetsByButton[e.button]),n=this.createPointerEvent(e);if(r){let o=r;for(;o;)n.currentTarget=o,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),o=o.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(n)}mapWheel(e){if(!(e instanceof ui)){G("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let r=1;r<e.length&&e[r].parent===t;r++)t=e[r];return t}createPointerEvent(e,t,r){const n=this.allocateEvent(st);return this.copyPointerData(e,n),this.copyMouseData(e,n),this.copyData(e,n),n.nativeEvent=e.nativeEvent,n.originalEvent=e,n.target=r??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof t=="string"&&(n.type=t),n}createWheelEvent(e){const t=this.allocateEvent(ui);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 r=this.allocateEvent(st);return r.nativeEvent=e.nativeEvent,r.originalEvent=e.originalEvent,this.copyPointerData(e,r),this.copyMouseData(e,r),this.copyData(e,r),r.target=e.target,r.path=e.composedPath().slice(),r.type=t??r.type,r}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof st&&t instanceof st&&(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)}copyMouseData(e,t){e instanceof es&&t instanceof es&&(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 r=e.currentTarget._events[t];if(r)if("fn"in r)r.once&&e.currentTarget.removeListener(t,r.fn,void 0,!0),r.fn.call(r.context,e);else for(let n=0,o=r.length;n<o&&!e.propagationImmediatelyStopped;n++)r[n].once&&e.currentTarget.removeListener(t,r[n].fn,void 0,!0),r[n].fn.call(r[n].context,e)}}const Cv=1,Av={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},$n=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 Sv(null),bt.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new st(null),this._rootWheelEvent=new ui(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...Bo.defaultEventFeatures},{set:(t,r,n)=>(r==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),t[r]=n,!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.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:r}=this.renderer;this.setTargetElement(t),this.resolution=r,Bo._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){bt.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 r=this.cursorStyles[e];if(r)switch(typeof r){case"string":t&&(this.domElement.style.cursor=r);break;case"function":r(e);break;case"object":t&&Object.assign(this.domElement.style,r);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 r=0,n=t.length;r<n;r++){const o=t[r],c=this._bootstrapEvent(this._rootPointerEvent,o);this.rootBoundary.mapEvent(c)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,bt.pointerMoved();const t=this._normalizeToPointerData(e);for(let r=0,n=t.length;r<n;r++){const o=this._bootstrapEvent(this._rootPointerEvent,t[r]);this.rootBoundary.mapEvent(o)}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 r=t!==this.domElement?"outside":"",n=this._normalizeToPointerData(e);for(let o=0,c=n.length;o<c;o++){const l=this._bootstrapEvent(this._rootPointerEvent,n[o]);l.type+=r,this.rootBoundary.mapEvent(l)}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 r=0,n=t.length;r<n;r++){const o=this._bootstrapEvent(this._rootPointerEvent,t[r]);this.rootBoundary.mapEvent(o)}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,bt.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;bt.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._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;bt.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=null,this._eventsAdded=!1}mapPositionToPoint(e,t,r){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},o=1/this.resolution;e.x=(t-n.left)*(this.domElement.width/n.width)*o,e.y=(r-n.top)*(this.domElement.height/n.height)*o}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let r=0,n=e.changedTouches.length;r<n;r++){const o=e.changedTouches[r];typeof o.button>"u"&&(o.button=0),typeof o.buttons>"u"&&(o.buttons=1),typeof o.isPrimary>"u"&&(o.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof o.width>"u"&&(o.width=o.radiusX||1),typeof o.height>"u"&&(o.height=o.radiusY||1),typeof o.tiltX>"u"&&(o.tiltX=0),typeof o.tiltY>"u"&&(o.tiltY=0),typeof o.pointerType>"u"&&(o.pointerType="touch"),typeof o.pointerId>"u"&&(o.pointerId=o.identifier||0),typeof o.pressure>"u"&&(o.pressure=o.force||.5),typeof o.twist>"u"&&(o.twist=0),typeof o.tangentialPressure>"u"&&(o.tangentialPressure=0),typeof o.layerX>"u"&&(o.layerX=o.offsetX=o.clientX),typeof o.layerY>"u"&&(o.layerY=o.offsetY=o.clientY),o.isNormalized=!0,o.type=e.type,t.push(o)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const r=e;typeof r.isPrimary>"u"&&(r.isPrimary=!0),typeof r.width>"u"&&(r.width=1),typeof r.height>"u"&&(r.height=1),typeof r.tiltX>"u"&&(r.tiltX=0),typeof r.tiltY>"u"&&(r.tiltY=0),typeof r.pointerType>"u"&&(r.pointerType="mouse"),typeof r.pointerId>"u"&&(r.pointerId=Cv),typeof r.pressure>"u"&&(r.pressure=.5),typeof r.twist>"u"&&(r.twist=0),typeof r.tangentialPressure>"u"&&(r.tangentialPressure=0),r.isNormalized=!0,t.push(r)}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=Av[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}};$n.extension={name:"events",type:[C.WebGLSystem,C.CanvasSystem,C.WebGPUSystem],priority:-1},$n.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let Wc=$n;const Ev={onclick: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(s){this.eventMode=s?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??Wc.defaultEventMode},set eventMode(s){this._internalEventMode=s},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(s,e,t){const r=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof t=="object"?t.signal:void 0,o=typeof t=="object"?t.once===!0:!1,c=typeof e=="function"?void 0:e;s=r?`${s}capture`:s;const l=typeof e=="function"?e:e.handleEvent,d=this;n&&n.addEventListener("abort",()=>{d.off(s,l,c)}),o?d.once(s,l,c):d.on(s,l,c)},removeEventListener(s,e,t){const r=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof e=="function"?void 0:e;s=r?`${s}capture`:s,e=typeof e=="function"?e:e.handleEvent,this.off(s,e,n)},dispatchEvent(s){if(!(s instanceof Ri))throw new Error("Container cannot propagate events outside of the Federated Events API");return s.defaultPrevented=!1,s.path=null,s.target=this,s.manager.dispatchEvent(s),!s.defaultPrevented}};var Iv=`in vec2 aPosition;
|
|
371
|
+
`;let hi=null;class Dc{constructor(){hi||(hi=URL.createObjectURL(new Blob([lv],{type:"application/javascript"}))),this.worker=new Worker(hi)}}Dc.revokeObjectURL=function(){hi&&(URL.revokeObjectURL(hi),hi=null)};let Oc=0,Vn;class cv{constructor(){this._initialized=!1,this._createdWorkers=0,this._workerPool=[],this._queue=[],this._resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(e=>{const{worker:t}=new Wn;t.addEventListener("message",r=>{t.terminate(),Wn.revokeObjectURL(),e(r.data)})}),this._isImageBitmapSupported)}loadImageBitmap(e,t){return this._run("loadImageBitmap",[e,t?.data?.alphaMode])}async _initWorkers(){this._initialized||(this._initialized=!0)}_getWorker(){Vn===void 0&&(Vn=navigator.hardwareConcurrency||4);let e=this._workerPool.pop();return!e&&this._createdWorkers<Vn&&(this._createdWorkers++,e=new Dc().worker,e.addEventListener("message",t=>{this._complete(t.data),this._returnWorker(t.target),this._next()})),e}_returnWorker(e){this._workerPool.push(e)}_complete(e){this._resolveHash[e.uuid]&&(e.error!==void 0?this._resolveHash[e.uuid].reject(e.error):this._resolveHash[e.uuid].resolve(e.data),delete this._resolveHash[e.uuid])}async _run(e,t){await this._initWorkers();const r=new Promise((n,o)=>{this._queue.push({id:e,arguments:t,resolve:n,reject:o})});return this._next(),r}_next(){if(!this._queue.length)return;const e=this._getWorker();if(!e)return;const t=this._queue.pop(),r=t.id;this._resolveHash[Oc]={resolve:t.resolve,reject:t.reject},e.postMessage({data:t.arguments,uuid:Oc++,id:r})}reset(){this._workerPool.forEach(e=>e.terminate()),this._workerPool.length=0,Object.values(this._resolveHash).forEach(({reject:e})=>{e?.(new Error("WorkerManager has been reset before completion"))}),this._resolveHash={},this._queue.length=0,this._initialized=!1,this._createdWorkers=0}}const Gc=new cv,hv=[".jpeg",".jpg",".png",".webp",".avif"],uv=["image/jpeg","image/png","image/webp","image/avif"];async function dv(s,e){const t=await V.get().fetch(s);if(!t.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${s}: ${t.status} ${t.statusText}`);const r=await t.blob();return e?.data?.alphaMode==="premultiplied-alpha"?createImageBitmap(r,{premultiplyAlpha:"none"}):createImageBitmap(r)}const Lc={name:"loadTextures",id:"texture",extension:{type:C.LoadParser,priority:At.High,name:"loadTextures"},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(s){return ai(s,uv)||li(s,hv)},async load(s,e,t){let r=null;globalThis.createImageBitmap&&this.config.preferCreateImageBitmap?this.config.preferWorkers&&await Gc.isImageBitmapSupported()?r=await Gc.loadImageBitmap(s,e):r=await dv(s,e):r=await new Promise((o,c)=>{r=V.get().createImage(),r.crossOrigin=this.config.crossOrigin,r.src=s,r.complete?o(r):(r.onload=()=>{o(r)},r.onerror=c)});const n=new ct({resource:r,alphaMode:"premultiply-alpha-on-upload",resolution:e.data?.resolution||zn(s),...e.data});return Hn(n,t,s)},unload(s){s.destroy(!0)}},fv=[".mp4",".m4v",".webm",".ogg",".ogv",".h264",".avi",".mov"];let Yn,Xn;function pv(s,e,t){t===void 0&&!e.startsWith("data:")?s.crossOrigin=gv(e):t!==!1&&(s.crossOrigin=typeof t=="string"?t:"anonymous")}function mv(s){return new Promise((e,t)=>{s.addEventListener("canplaythrough",r),s.addEventListener("error",n),s.load();function r(){o(),e()}function n(c){o(),t(c)}function o(){s.removeEventListener("canplaythrough",r),s.removeEventListener("error",n)}})}function gv(s,e=globalThis.location){if(s.startsWith("data:"))return"";e||(e=globalThis.location);const t=new URL(s,document.baseURI);return t.hostname!==e.hostname||t.port!==e.port||t.protocol!==e.protocol?"anonymous":""}function vv(){const s=[],e=[];for(const t of fv){const r=Ii.MIME_TYPES[t.substring(1)]||`video/${t.substring(1)}`;Qr(r)&&(s.push(t),e.includes(r)||e.push(r))}return{validVideoExtensions:s,validVideoMime:e}}const _v={name:"loadVideo",id:"video",extension:{type:C.LoadParser,name:"loadVideo"},test(s){if(!Yn||!Xn){const{validVideoExtensions:r,validVideoMime:n}=vv();Yn=r,Xn=n}const e=ai(s,Xn),t=li(s,Yn);return e||t},async load(s,e,t){const r={...Ii.defaultOptions,resolution:e.data?.resolution||zn(s),alphaMode:e.data?.alphaMode||await $a(),...e.data},n=document.createElement("video"),o={preload:r.autoLoad!==!1?"auto":void 0,"webkit-playsinline":r.playsinline!==!1?"":void 0,playsinline:r.playsinline!==!1?"":void 0,muted:r.muted===!0?"":void 0,loop:r.loop===!0?"":void 0,autoplay:r.autoPlay!==!1?"":void 0};Object.keys(o).forEach(d=>{const f=o[d];f!==void 0&&n.setAttribute(d,f)}),r.muted===!0&&(n.muted=!0),pv(n,s,r.crossorigin);const c=document.createElement("source");let l;if(r.mime)l=r.mime;else if(s.startsWith("data:"))l=s.slice(5,s.indexOf(";"));else if(!s.startsWith("blob:")){const d=s.split("?")[0].slice(s.lastIndexOf(".")+1).toLowerCase();l=Ii.MIME_TYPES[d]||`video/${d}`}return c.src=s,l&&(c.type=l),new Promise(d=>{const f=async()=>{const m=new Ii({...r,resource:n});n.removeEventListener("canplay",f),e.data.preload&&await mv(n),d(Hn(m,t,s))};r.preload&&!r.autoPlay&&n.load(),n.addEventListener("canplay",f),n.appendChild(c)})},unload(s){s.destroy(!0)}},Nc={extension:{type:C.ResolveParser,name:"resolveTexture"},test:Lc.test,parse:s=>({resolution:parseFloat(ii.RETINA_PREFIX.exec(s)?.[1]??"1"),format:s.split(".").pop(),src:s})},yv={extension:{type:C.ResolveParser,priority:-2,name:"resolveJson"},test:s=>ii.RETINA_PREFIX.test(s)&&s.endsWith(".json"),parse:Nc.parse};class xv{constructor(){this._detections=[],this._initialized=!1,this.resolver=new ii,this.loader=new z0,this.cache=re,this._backgroundLoader=new F0(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(e={}){if(this._initialized){G("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,e.defaultSearchParams&&this.resolver.setDefaultSearchParams(e.defaultSearchParams),e.basePath&&(this.resolver.basePath=e.basePath),e.bundleIdentifier&&this.resolver.setBundleIdentifier(e.bundleIdentifier),e.manifest){let o=e.manifest;typeof o=="string"&&(o=await this.load(o)),this.resolver.addManifest(o)}const t=e.texturePreference?.resolution??1,r=typeof t=="number"?[t]:t,n=await this._detectFormats({preferredFormats:e.texturePreference?.format,skipDetections:e.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:n,resolution:r}}),e.preferences&&this.setPreferences(e.preferences),e.loadOptions&&(this.loader.loadOptions={...this.loader.loadOptions,...e.loadOptions})}add(e){this.resolver.add(e)}async load(e,t){this._initialized||await this.init();const r=Fr(e),n=Qe(e).map(l=>{if(typeof l!="string"){const d=this.resolver.getAlias(l);return d.some(f=>!this.resolver.hasKey(f))&&this.add(l),Array.isArray(d)?d[0]:d}return this.resolver.hasKey(l)||this.add({alias:l,src:l}),l}),o=this.resolver.resolve(n),c=await this._mapLoadToResolve(o,t);return r?c[n[0]]:c}addBundle(e,t){this.resolver.addBundle(e,t)}async loadBundle(e,t){this._initialized||await this.init();let r=!1;typeof e=="string"&&(r=!0,e=[e]);const n=this.resolver.resolveBundle(e),o={},c=Object.keys(n);let l=0;const d=[],f=()=>{t?.(d.reduce((g,_)=>g+_,0)/l)},m=c.map((g,_)=>{const y=n[g],a=Object.values(y),u=[...new Set(a.flat())].reduce((p,v)=>p+(v.progressSize||1),0);return d.push(0),l+=u,this._mapLoadToResolve(y,p=>{d[_]=p*u,f()}).then(p=>{o[g]=p})});return await Promise.all(m),r?o[e[0]]:o}async backgroundLoad(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolve(e);this._backgroundLoader.add(Object.values(t))}async backgroundLoadBundle(e){this._initialized||await this.init(),typeof e=="string"&&(e=[e]);const t=this.resolver.resolveBundle(e);Object.values(t).forEach(r=>{this._backgroundLoader.add(Object.values(r))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(e){if(typeof e=="string")return re.get(e);const t={};for(let r=0;r<e.length;r++)t[r]=re.get(e[r]);return t}async _mapLoadToResolve(e,t){const r=[...new Set(Object.values(e))];this._backgroundLoader.active=!1;const n=await this.loader.load(r,t);this._backgroundLoader.active=!0;const o={};return r.forEach(c=>{const l=n[c.src],d=[c.src];c.alias&&d.push(...c.alias),d.forEach(f=>{o[f]=l}),re.set(d,l)}),o}async unload(e){this._initialized||await this.init();const t=Qe(e).map(n=>typeof n!="string"?n.src:n),r=this.resolver.resolve(t);await this._unloadFromResolved(r)}async unloadBundle(e){this._initialized||await this.init(),e=Qe(e);const t=this.resolver.resolveBundle(e),r=Object.keys(t).map(n=>this._unloadFromResolved(t[n]));await Promise.all(r)}async _unloadFromResolved(e){const t=Object.values(e);t.forEach(r=>{re.remove(r.src)}),await this.loader.unload(t)}async _detectFormats(e){let t=[];e.preferredFormats&&(t=Array.isArray(e.preferredFormats)?e.preferredFormats:[e.preferredFormats]);for(const r of e.detections)e.skipDetections||await r.test()?t=await r.add(t):e.skipDetections||(t=await r.remove(t));return t=t.filter((r,n)=>t.indexOf(r)===n),t}get detections(){return this._detections}setPreferences(e){this.loader.parsers.forEach(t=>{t.config&&Object.keys(t.config).filter(r=>r in e).forEach(r=>{t.config[r]=e[r]})})}}const er=new xv;L.handleByList(C.LoadParser,er.loader.parsers).handleByList(C.ResolveParser,er.resolver.parsers).handleByList(C.CacheParser,er.cache.parsers).handleByList(C.DetectionParser,er.detections),L.add(U0,B0,k0,N0,O0,G0,L0,V0,$0,tv,sv,Lc,_v,M0,R0,Nc,yv);const zc={loader:C.LoadParser,resolver:C.ResolveParser,cache:C.CacheParser,detection:C.DetectionParser};L.handle(C.Asset,s=>{const e=s.ref;Object.entries(zc).filter(([t])=>!!e[t]).forEach(([t,r])=>L.add(Object.assign(e[t],{extension:e[t].extension??r})))},s=>{const e=s.ref;Object.keys(zc).filter(t=>!!e[t]).forEach(t=>L.remove(e[t]))});class Hc{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 Qa({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 r=e[t],n=r.element;if(!r.parent||r.globalDisplayStatus<7)n?.remove(),e.splice(t,1),t--;else{this._domElement.contains(n)||(n.style.position="absolute",n.style.pointerEvents="auto",this._domElement.appendChild(n));const o=r.worldTransform,c=r._anchor,l=r.width*c.x,d=r.height*c.y;n.style.transformOrigin=`${l}px ${d}px`,n.style.transform=`matrix(${o.a}, ${o.b}, ${o.c}, ${o.d}, ${o.tx-l}, ${o.ty-d})`,n.style.opacity=r.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}}Hc.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"dom"};class bv{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||(Ne.system.add(this._tickerUpdate,this,ti.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(Ne.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 bt=new bv;class es extends Ri{constructor(){super(...arguments),this.client=new J,this.movement=new J,this.offset=new J,this.global=new J,this.screen=new J}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,r){return e.worldTransform.applyInverse(r||this.global,t)}getModifierState(e){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(e)}initMouseEvent(e,t,r,n,o,c,l,d,f,m,g,_,y,a,h){throw new Error("Method not implemented.")}}class st extends es{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class ui extends es{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}ui.DOM_DELTA_PIXEL=0,ui.DOM_DELTA_LINE=1,ui.DOM_DELTA_PAGE=2;const Tv=2048,wv=new J,tr=new J;class Sv{constructor(e){this.dispatch=new Le,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.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)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((r,n)=>r.priority-n.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 r=0,n=t.length;r<n;r++)t[r].fn(e);else G(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){bt.pauseUpdate=!0;const n=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",o=this[n](this.rootTarget,this.rootTarget.eventMode,wv.set(e,t),this.hitTestFn,this.hitPruneFn);return o&&o[0]}propagate(e,t){if(!e.target)return;const r=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let n=0,o=r.length-1;n<o;n++)if(e.currentTarget=r[n],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 n=r.length-2;n>=0;n--)if(e.currentTarget=r[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,r=this._allInteractiveElements){if(r.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const n=Array.isArray(t)?t:[t];for(let o=r.length-1;o>=0;o--)n.forEach(c=>{e.currentTarget=r[o],this.notifyTarget(e,c)})}propagationPath(e){const t=[e];for(let r=0;r<Tv&&e!==this.rootTarget&&e.parent;r++){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,r,n,o,c=!1){let l=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(bt.pauseUpdate=!1),e.interactiveChildren&&e.children){const m=e.children;for(let g=m.length-1;g>=0;g--){const _=m[g],y=this.hitTestMoveRecursive(_,this._isInteractive(t)?t:_.eventMode,r,n,o,c||o(e,r));if(y){if(y.length>0&&!y[y.length-1].parent)continue;const a=e.isInteractive();(y.length>0||a)&&(a&&this._allInteractiveElements.push(e),y.push(e)),this._hitElements.length===0&&(this._hitElements=y),l=!0}}}const d=this._isInteractive(t),f=e.isInteractive();return f&&f&&this._allInteractiveElements.push(e),c||this._hitElements.length>0?null:l?this._hitElements:d&&!o(e,r)&&n(e,r)?f?[e]:[]:null}hitTestRecursive(e,t,r,n,o){if(this._interactivePrune(e)||o(e,r))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(bt.pauseUpdate=!1),e.interactiveChildren&&e.children){const d=e.children,f=r;for(let m=d.length-1;m>=0;m--){const g=d[m],_=this.hitTestRecursive(g,this._isInteractive(t)?t:g.eventMode,f,n,o);if(_){if(_.length>0&&!_[_.length-1].parent)continue;const y=e.isInteractive();return(_.length>0||y)&&_.push(e),_}}}const c=this._isInteractive(t),l=e.isInteractive();return c&&n(e,r)?l?[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,tr),!e.hitArea.contains(tr.x,tr.y)))return!0;if(e.effects&&e.effects.length)for(let r=0;r<e.effects.length;r++){const n=e.effects[r];if(n.containsPoint&&!n.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e?.containsPoint?(e.worldTransform.applyInverse(t,tr),e.containsPoint(tr)):!1}notifyTarget(e,t){if(!e.currentTarget.isInteractive())return;t??(t=e.type);const r=`on${t}`;e.currentTarget[r]?.(e);const n=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,n),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof st)){G("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 n=t.button===2;this.dispatchEvent(t,n?"rightdown":"mousedown")}const r=this.trackingData(e.pointerId);r.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){if(!(e instanceof st)){G("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 r=t.pointerType==="mouse"||t.pointerType==="pen",n=this.trackingData(e.pointerId),o=this.findMountedTarget(n.overTargets);if(n.overTargets?.length>0&&o!==t.target){const d=e.type==="mousemove"?"mouseout":"pointerout",f=this.createPointerEvent(e,d,o);if(this.dispatchEvent(f,"pointerout"),r&&this.dispatchEvent(f,"mouseout"),!t.composedPath().includes(o)){const m=this.createPointerEvent(e,"pointerleave",o);for(m.eventPhase=m.AT_TARGET;m.target&&!t.composedPath().includes(m.target);)m.currentTarget=m.target,this.notifyTarget(m),r&&this.notifyTarget(m,"mouseleave"),m.target=m.target.parent;this.freeEvent(m)}this.freeEvent(f)}if(o!==t.target){const d=e.type==="mousemove"?"mouseover":"pointerover",f=this.clonePointerEvent(t,d);this.dispatchEvent(f,"pointerover"),r&&this.dispatchEvent(f,"mouseover");let m=o?.parent;for(;m&&m!==this.rootTarget.parent&&m!==t.target;)m=m.parent;if(!m||m===this.rootTarget.parent){const _=this.clonePointerEvent(t,"pointerenter");for(_.eventPhase=_.AT_TARGET;_.target&&_.target!==o&&_.target!==this.rootTarget.parent;)_.currentTarget=_.target,this.notifyTarget(_),r&&this.notifyTarget(_,"mouseenter"),_.target=_.target.parent;this.freeEvent(_)}this.freeEvent(f)}const c=[],l=this.enableGlobalMoveEvents??!0;this.moveOnAll?c.push("pointermove"):this.dispatchEvent(t,"pointermove"),l&&c.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?c.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),l&&c.push("globaltouchmove")),r&&(this.moveOnAll?c.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),l&&c.push("globalmousemove"),this.cursor=t.target?.cursor),c.length>0&&this.all(t,c),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),r=this.createPointerEvent(e),n=r.pointerType==="mouse"||r.pointerType==="pen";this.dispatchEvent(r,"pointerover"),n&&this.dispatchEvent(r,"mouseover"),r.pointerType==="mouse"&&(this.cursor=r.target?.cursor);const o=this.clonePointerEvent(r,"pointerenter");for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),n&&this.notifyTarget(o,"mouseenter"),o.target=o.target.parent;t.overTargets=r.composedPath(),this.freeEvent(r),this.freeEvent(o)}mapPointerOut(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const r=e.pointerType==="mouse"||e.pointerType==="pen",n=this.findMountedTarget(t.overTargets),o=this.createPointerEvent(e,"pointerout",n);this.dispatchEvent(o),r&&this.dispatchEvent(o,"mouseout");const c=this.createPointerEvent(e,"pointerleave",n);for(c.eventPhase=c.AT_TARGET;c.target&&c.target!==this.rootTarget.parent;)c.currentTarget=c.target,this.notifyTarget(c),r&&this.notifyTarget(c,"mouseleave"),c.target=c.target.parent;t.overTargets=null,this.freeEvent(o),this.freeEvent(c)}this.cursor=null}mapPointerUp(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),r=this.createPointerEvent(e);if(this.dispatchEvent(r,"pointerup"),r.pointerType==="touch")this.dispatchEvent(r,"touchend");else if(r.pointerType==="mouse"||r.pointerType==="pen"){const l=r.button===2;this.dispatchEvent(r,l?"rightup":"mouseup")}const n=this.trackingData(e.pointerId),o=this.findMountedTarget(n.pressTargetsByButton[e.button]);let c=o;if(o&&!r.composedPath().includes(o)){let l=o;for(;l&&!r.composedPath().includes(l);){if(r.currentTarget=l,this.notifyTarget(r,"pointerupoutside"),r.pointerType==="touch")this.notifyTarget(r,"touchendoutside");else if(r.pointerType==="mouse"||r.pointerType==="pen"){const d=r.button===2;this.notifyTarget(r,d?"rightupoutside":"mouseupoutside")}l=l.parent}delete n.pressTargetsByButton[e.button],c=l}if(c){const l=this.clonePointerEvent(r,"click");l.target=c,l.path=null,n.clicksByButton[e.button]||(n.clicksByButton[e.button]={clickCount:0,target:l.target,timeStamp:t});const d=n.clicksByButton[e.button];if(d.target===l.target&&t-d.timeStamp<200?++d.clickCount:d.clickCount=1,d.target=l.target,d.timeStamp=t,l.detail=d.clickCount,l.pointerType==="mouse"){const f=l.button===2;this.dispatchEvent(l,f?"rightclick":"click")}else l.pointerType==="touch"&&this.dispatchEvent(l,"tap");this.dispatchEvent(l,"pointertap"),this.freeEvent(l)}this.freeEvent(r)}mapPointerUpOutside(e){if(!(e instanceof st)){G("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),r=this.findMountedTarget(t.pressTargetsByButton[e.button]),n=this.createPointerEvent(e);if(r){let o=r;for(;o;)n.currentTarget=o,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),o=o.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(n)}mapWheel(e){if(!(e instanceof ui)){G("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let r=1;r<e.length&&e[r].parent===t;r++)t=e[r];return t}createPointerEvent(e,t,r){const n=this.allocateEvent(st);return this.copyPointerData(e,n),this.copyMouseData(e,n),this.copyData(e,n),n.nativeEvent=e.nativeEvent,n.originalEvent=e,n.target=r??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof t=="string"&&(n.type=t),n}createWheelEvent(e){const t=this.allocateEvent(ui);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 r=this.allocateEvent(st);return r.nativeEvent=e.nativeEvent,r.originalEvent=e.originalEvent,this.copyPointerData(e,r),this.copyMouseData(e,r),this.copyData(e,r),r.target=e.target,r.path=e.composedPath().slice(),r.type=t??r.type,r}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof st&&t instanceof st&&(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)}copyMouseData(e,t){e instanceof es&&t instanceof es&&(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 r=e.currentTarget._events[t];if(r)if("fn"in r)r.once&&e.currentTarget.removeListener(t,r.fn,void 0,!0),r.fn.call(r.context,e);else for(let n=0,o=r.length;n<o&&!e.propagationImmediatelyStopped;n++)r[n].once&&e.currentTarget.removeListener(t,r[n].fn,void 0,!0),r[n].fn.call(r[n].context,e)}}const Cv=1,Av={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},$n=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 Sv(null),bt.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new st(null),this._rootWheelEvent=new ui(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...Bo.defaultEventFeatures},{set:(t,r,n)=>(r==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),t[r]=n,!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.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:r}=this.renderer;this.setTargetElement(t),this.resolution=r,Bo._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){bt.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 r=this.cursorStyles[e];if(r)switch(typeof r){case"string":t&&(this.domElement.style.cursor=r);break;case"function":r(e);break;case"object":t&&Object.assign(this.domElement.style,r);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 r=0,n=t.length;r<n;r++){const o=t[r],c=this._bootstrapEvent(this._rootPointerEvent,o);this.rootBoundary.mapEvent(c)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,bt.pointerMoved();const t=this._normalizeToPointerData(e);for(let r=0,n=t.length;r<n;r++){const o=this._bootstrapEvent(this._rootPointerEvent,t[r]);this.rootBoundary.mapEvent(o)}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 r=t!==this.domElement?"outside":"",n=this._normalizeToPointerData(e);for(let o=0,c=n.length;o<c;o++){const l=this._bootstrapEvent(this._rootPointerEvent,n[o]);l.type+=r,this.rootBoundary.mapEvent(l)}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 r=0,n=t.length;r<n;r++){const o=this._bootstrapEvent(this._rootPointerEvent,t[r]);this.rootBoundary.mapEvent(o)}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,bt.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;bt.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._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;bt.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=null,this._eventsAdded=!1}mapPositionToPoint(e,t,r){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},o=1/this.resolution;e.x=(t-n.left)*(this.domElement.width/n.width)*o,e.y=(r-n.top)*(this.domElement.height/n.height)*o}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let r=0,n=e.changedTouches.length;r<n;r++){const o=e.changedTouches[r];typeof o.button>"u"&&(o.button=0),typeof o.buttons>"u"&&(o.buttons=1),typeof o.isPrimary>"u"&&(o.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof o.width>"u"&&(o.width=o.radiusX||1),typeof o.height>"u"&&(o.height=o.radiusY||1),typeof o.tiltX>"u"&&(o.tiltX=0),typeof o.tiltY>"u"&&(o.tiltY=0),typeof o.pointerType>"u"&&(o.pointerType="touch"),typeof o.pointerId>"u"&&(o.pointerId=o.identifier||0),typeof o.pressure>"u"&&(o.pressure=o.force||.5),typeof o.twist>"u"&&(o.twist=0),typeof o.tangentialPressure>"u"&&(o.tangentialPressure=0),typeof o.layerX>"u"&&(o.layerX=o.offsetX=o.clientX),typeof o.layerY>"u"&&(o.layerY=o.offsetY=o.clientY),o.isNormalized=!0,o.type=e.type,t.push(o)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const r=e;typeof r.isPrimary>"u"&&(r.isPrimary=!0),typeof r.width>"u"&&(r.width=1),typeof r.height>"u"&&(r.height=1),typeof r.tiltX>"u"&&(r.tiltX=0),typeof r.tiltY>"u"&&(r.tiltY=0),typeof r.pointerType>"u"&&(r.pointerType="mouse"),typeof r.pointerId>"u"&&(r.pointerId=Cv),typeof r.pressure>"u"&&(r.pressure=.5),typeof r.twist>"u"&&(r.twist=0),typeof r.tangentialPressure>"u"&&(r.tangentialPressure=0),r.isNormalized=!0,t.push(r)}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=Av[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}};$n.extension={name:"events",type:[C.WebGLSystem,C.CanvasSystem,C.WebGPUSystem],priority:-1},$n.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let Wc=$n;const Ev={onclick: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(s){this.eventMode=s?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??Wc.defaultEventMode},set eventMode(s){this._internalEventMode=s},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(s,e,t){const r=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof t=="object"?t.signal:void 0,o=typeof t=="object"?t.once===!0:!1,c=typeof e=="function"?void 0:e;s=r?`${s}capture`:s;const l=typeof e=="function"?e:e.handleEvent,d=this;n&&n.addEventListener("abort",()=>{d.off(s,l,c)}),o?d.once(s,l,c):d.on(s,l,c)},removeEventListener(s,e,t){const r=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof e=="function"?void 0:e;s=r?`${s}capture`:s,e=typeof e=="function"?e:e.handleEvent,this.off(s,e,n)},dispatchEvent(s){if(!(s instanceof Ri))throw new Error("Container cannot propagate events outside of the Federated Events API");return s.defaultPrevented=!1,s.path=null,s.target=this,s.manager.dispatchEvent(s),!s.defaultPrevented}};var Iv=`in vec2 aPosition;
|
|
372
372
|
out vec2 vTextureCoord;
|
|
373
373
|
|
|
374
374
|
uniform vec4 uInputSize;
|
|
@@ -619,7 +619,7 @@ fn mainFragment(
|
|
|
619
619
|
|
|
620
620
|
return source * a;
|
|
621
621
|
}
|
|
622
|
-
`;class Dv extends Dr{constructor(e){const{sprite:t,...r}=e,n=new _a(t.texture),o=new Ue({uFilterMatrix:{value:new B,type:"mat3x3<f32>"},uMaskClamp:{value:n.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"}}),c=It.from({vertex:{source:qc,entryPoint:"mainVertex"},fragment:{source:qc,entryPoint:"mainFragment"}}),l=vt.from({vertex:Bv,fragment:kv,name:"mask-filter"});super({...r,gpuProgram:c,glProgram:l,clipToViewport:!1,resources:{filterUniforms:o,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=n}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}apply(e,t,r,n){this._textureMatrix.texture=this.sprite.texture,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=this.sprite.texture.source,e.applyFilter(this,t,r,n)}}class Ce extends Ys{constructor(e){e instanceof je&&(e={context:e});const{context:t,roundPixels:r,...n}=e||{};super({label:"Graphics",...n}),this.renderPipeId="graphics",t?this._context=t:this._context=this._ownedContext=new je,this._context.on("update",this.onViewUpdate,this),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=r??!1}set context(e){e!==this._context&&(this._context.off("update",this.onViewUpdate,this),this._context=e,this._context.on("update",this.onViewUpdate,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._ownedContext=null,this._context=null,super.destroy(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 Ce(this._context.clone()):(this._ownedContext=null,new Ce(this._context))}lineStyle(e,t,r){H(j,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const n={};return e&&(n.width=e),t&&(n.color=t),r&&(n.alpha=r),this.context.strokeStyle=n,this}beginFill(e,t){H(j,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const r={};return e!==void 0&&(r.color=e),t!==void 0&&(r.alpha=t),this.context.fillStyle=r,this}endFill(){H(j,"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!==je.defaultStrokeStyle.width||e.color!==je.defaultStrokeStyle.color||e.alpha!==je.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return H(j,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",e)}drawEllipse(...e){return H(j,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",e)}drawPolygon(...e){return H(j,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",e)}drawRect(...e){return H(j,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",e)}drawRoundedRect(...e){return H(j,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",e)}drawStar(...e){return H(j,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",e)}}const Kc=class xd extends Vi{constructor(...e){let t=e[0]??{};t instanceof Float32Array&&(H(j,"use new MeshGeometry({ positions, uvs, indices }) instead"),t={positions:t,uvs:e[1],indices:e[2]}),t={...xd.defaultOptions,...t};const r=t.positions||new Float32Array([0,0,1,0,1,1,0,1]);let n=t.uvs;n||(t.positions?n=new Float32Array(r.length):n=new Float32Array([0,0,1,0,1,1,0,1]));const o=t.indices||new Uint32Array([0,1,2,0,2,3]),c=t.shrinkBuffersToFit,l=new We({data:r,label:"attribute-mesh-positions",shrinkToFit:c,usage:$.VERTEX|$.COPY_DST}),d=new We({data:n,label:"attribute-mesh-uvs",shrinkToFit:c,usage:$.VERTEX|$.COPY_DST}),f=new We({data:o,label:"index-mesh-buffer",shrinkToFit:c,usage:$.INDEX|$.COPY_DST});super({attributes:{aPosition:{buffer:l,format:"float32x2",stride:8,offset:0},aUV:{buffer:d,format:"float32x2",stride:8,offset:0}},indexBuffer:f,topology:t.topology}),this.batchMode="auto"}get positions(){return this.attributes.aPosition.buffer.data}set positions(e){this.attributes.aPosition.buffer.data=e}get uvs(){return this.attributes.aUV.buffer.data}set uvs(e){this.attributes.aUV.buffer.data=e}get indices(){return this.indexBuffer.data}set indices(e){this.indexBuffer.data=e}};Kc.defaultOptions={topology:"triangle-list",shrinkBuffersToFit:!1};let qn=Kc;class jc extends Ys{constructor(e,t){const{text:r,resolution:n,style:o,anchor:c,width:l,height:d,roundPixels:f,...m}=e;super({...m}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=r??"",this.style=o,this.resolution=n??null,this.allowChildren=!1,this._anchor=new be({_onUpdate:()=>{this.onViewUpdate()}}),c&&(this.anchor=c),this.roundPixels=f??!1,l!==void 0&&(this.width=l),d!==void 0&&(this.height=d)}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,r=this.bounds.height,n=-t*this.anchor.x;let o=0;return e.x>=n&&e.x<=n+t&&(o=-r*this.anchor.y,e.y>=o&&e.y<=o+r)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){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 Zc(s,e){let t=s[0]??{};return(typeof t=="string"||s[1])&&(H(j,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:s[1]}),t}let Ht=null,Tt=null;function Ov(s,e){Ht||(Ht=V.get().createCanvas(256,128),Tt=Ht.getContext("2d",{willReadFrequently:!0}),Tt.globalCompositeOperation="copy",Tt.globalAlpha=1),(Ht.width<s||Ht.height<e)&&(Ht.width=Jt(s),Ht.height=Jt(e))}function Jc(s,e,t){for(let r=0,n=4*t*e;r<e;++r,n+=4)if(s[n+3]!==0)return!1;return!0}function Qc(s,e,t,r,n){const o=4*e;for(let c=r,l=r*o+4*t;c<=n;++c,l+=o)if(s[l+3]!==0)return!1;return!0}function Gv(...s){let e=s[0];e.canvas||(e={canvas:s[0],resolution:s[1]});const{canvas:t}=e,r=Math.min(e.resolution??1,1),n=e.width??t.width,o=e.height??t.height;let c=e.output;if(Ov(n,o),!Tt)throw new TypeError("Failed to get canvas 2D context");Tt.drawImage(t,0,0,n,o,0,0,n*r,o*r);const d=Tt.getImageData(0,0,n,o).data;let f=0,m=0,g=n-1,_=o-1;for(;m<o&&Jc(d,n,m);)++m;if(m===o)return z.EMPTY;for(;Jc(d,n,_);)--_;for(;Qc(d,n,f,m,_);)++f;for(;Qc(d,n,g,m,_);)--g;return++g,++_,Tt.globalCompositeOperation="source-over",Tt.strokeRect(f,m,g-f,_-m),Tt.globalCompositeOperation="copy",c??(c=new z),c.set(f/r,m/r,(g-f)/r,(_-m)/r),c}const eh=new z;class Lv{getCanvasAndContext(e){const{text:t,style:r,resolution:n=1}=e,o=r._getFinalPadding(),c=He.measureText(t||" ",r),l=Math.ceil(Math.ceil(Math.max(1,c.width)+o*2)*n),d=Math.ceil(Math.ceil(Math.max(1,c.height)+o*2)*n),f=xt.getOptimalCanvasAndContext(l,d);this._renderTextToCanvas(t,r,o,n,f);const m=r.trim?Gv({canvas:f.canvas,width:l,height:d,resolution:1,output:eh}):eh.set(0,0,l,d);return{canvasAndContext:f,frame:m}}returnCanvasAndContext(e){xt.returnCanvasAndContext(e)}_renderTextToCanvas(e,t,r,n,o){const{canvas:c,context:l}=o,d=Wr(t),f=He.measureText(e||" ",t),m=f.lines,g=f.lineHeight,_=f.lineWidths,y=f.maxLineWidth,a=f.fontProperties,h=c.height;if(l.resetTransform(),l.scale(n,n),l.textBaseline=t.textBaseline,t._stroke?.width){const x=t._stroke;l.lineWidth=x.width,l.miterLimit=x.miterLimit,l.lineJoin=x.join,l.lineCap=x.cap}l.font=d;let u,p;const v=t.dropShadow?2:1;for(let x=0;x<v;++x){const b=t.dropShadow&&x===0,T=b?Math.ceil(Math.max(1,h)+r*2):0,w=T*n;if(b){l.fillStyle="black",l.strokeStyle="black";const A=t.dropShadow,P=A.color,I=A.alpha;l.shadowColor=le.shared.setValue(P).setAlpha(I).toRgbaString();const k=A.blur*n,O=A.distance*n;l.shadowBlur=k,l.shadowOffsetX=Math.cos(A.angle)*O,l.shadowOffsetY=Math.sin(A.angle)*O+w}else{if(l.fillStyle=t._fill?Zr(t._fill,l,f,r*2):null,t._stroke?.width){const A=t._stroke.width*.5+r*2;l.strokeStyle=Zr(t._stroke,l,f,A)}l.shadowColor="black"}let S=(g-a.fontSize)/2;g-a.fontSize<0&&(S=0);const E=t._stroke?.width??0;for(let A=0;A<m.length;A++)u=E/2,p=E/2+A*g+a.ascent+S,t.align==="right"?u+=y-_[A]:t.align==="center"&&(u+=(y-_[A])/2),t._stroke?.width&&this._drawLetterSpacing(m[A],t,o,u+r,p+r-T,!0),t._fill!==void 0&&this._drawLetterSpacing(m[A],t,o,u+r,p+r-T)}}_drawLetterSpacing(e,t,r,n,o,c=!1){const{context:l}=r,d=t.letterSpacing;let f=!1;if(He.experimentalLetterSpacingSupported&&(He.experimentalLetterSpacing?(l.letterSpacing=`${d}px`,l.textLetterSpacing=`${d}px`,f=!0):(l.letterSpacing="0px",l.textLetterSpacing="0px")),d===0||f){c?l.strokeText(e,n,o):l.fillText(e,n,o);return}let m=n;const g=He.graphemeSegmenter(e);let _=l.measureText(e).width,y=0;for(let a=0;a<g.length;++a){const h=g[a];c?l.strokeText(h,m,o):l.fillText(h,m,o);let u="";for(let p=a+1;p<g.length;++p)u+=g[p];y=l.measureText(u).width,m+=_-y+d,_=y}}}const ir=new Lv;class Nv extends jc{constructor(...e){const t=Zc(e,"Text");super(t,Be),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof at?t.textureStyle:new at(t.textureStyle))}updateBounds(){const e=this._bounds,t=this._anchor;let r=0,n=0;if(this._style.trim){const{frame:o,canvasAndContext:c}=ir.getCanvasAndContext({text:this.text,style:this._style,resolution:1});ir.returnCanvasAndContext(c),r=o.width,n=o.height}else{const o=He.measureText(this._text,this._style);r=o.width,n=o.height}e.minX=-t._x*r,e.maxX=e.minX+r,e.minY=-t._y*n,e.maxY=e.minY+n}}class zv extends jc{constructor(...e){var t;const r=Zc(e,"BitmapText");r.style??(r.style=r.style||{}),(t=r.style).fill??(t.fill=16777215),super(r,Be),this.renderPipeId="bitmapText"}updateBounds(){const e=this._bounds,t=this._anchor,r=Qi.measureText(this.text,this._style),n=r.scale,o=r.offsetY*n;let c=r.width*n,l=r.height*n;const d=this._style._stroke;d&&(c+=d.width,l+=d.width),e.minX=-t._x*c,e.maxX=e.minX+c,e.minY=-t._y*(l+o),e.maxY=e.minY+l}set resolution(e){e!==null&&G("[BitmapText] dynamically updating the resolution is not supported. Resolution should be managed by the BitmapFont.")}get resolution(){return this._resolution}}const th="http://www.w3.org/2000/svg",ih="http://www.w3.org/1999/xhtml";class rh{constructor(){this.svgRoot=document.createElementNS(th,"svg"),this.foreignObject=document.createElementNS(th,"foreignObject"),this.domElement=document.createElementNS(ih,"div"),this.styleElement=document.createElementNS(ih,"style");const{foreignObject:e,svgRoot:t,styleElement:r,domElement:n}=this;e.setAttribute("width","10000"),e.setAttribute("height","10000"),e.style.overflow="hidden",t.appendChild(e),e.appendChild(r),e.appendChild(n),this.image=V.get().createImage()}destroy(){this.svgRoot.remove(),this.foreignObject.remove(),this.styleElement.remove(),this.domElement.remove(),this.image.src="",this.image.remove(),this.svgRoot=null,this.foreignObject=null,this.styleElement=null,this.domElement=null,this.image=null,this.canvasAndContext=null}}let sh;function Hv(s,e,t,r){r||(r=sh||(sh=new rh));const{domElement:n,styleElement:o,svgRoot:c}=r;n.innerHTML=`<style>${e.cssStyle};</style><div style='padding:0'>${s}</div>`,n.setAttribute("style","transform-origin: top left; display: inline-block"),t&&(o.textContent=t),document.body.appendChild(c);const l=n.getBoundingClientRect();c.remove();const d=e.padding*2;return{width:l.width-d,height:l.height-d}}class nh{constructor(){this._tempState=it.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,r){const n=e.renderer,o=this._didUploadHash[r.uid];n.shader.bind(r,o),o||(this._didUploadHash[r.uid]=!0),n.shader.updateUniformGroup(n.globalUniforms.uniformGroup),n.geometry.bind(t,r.glProgram)}execute(e,t){const r=e.renderer;this._tempState.blendMode=t.blendMode,r.state.set(this._tempState);const n=t.textures.textures;for(let o=0;o<t.textures.count;o++)r.texture.bind(n[o],o);r.geometry.draw(t.topology,t.size,t.start)}}nh.extension={type:[C.WebGLPipesAdaptor],name:"batch"};const ts=it.for2d();class oh{start(e,t,r){const n=e.renderer,o=n.encoder,c=r.gpuProgram;this._shader=r,this._geometry=t,o.setGeometry(t,c),ts.blendMode="normal",n.pipeline.getPipeline(t,c,ts);const l=n.globalUniforms.bindGroup;o.resetBindGroup(1),o.setBindGroup(0,l,c)}execute(e,t){const r=this._shader.gpuProgram,n=e.renderer,o=n.encoder;if(!t.bindGroup){const d=t.textures;t.bindGroup=yn(d.textures,d.count,n.limits.maxBatchableTextures)}ts.blendMode=t.blendMode;const c=n.bindGroup.getBindGroup(t.bindGroup,r,1),l=n.pipeline.getPipeline(this._geometry,r,ts,t.topology);t.bindGroup._touch(n.textureGC.count),o.setPipeline(l),o.renderPassEncoder.setBindGroup(1,c),o.renderPassEncoder.drawIndexed(t.size,1,t.start)}}oh.extension={type:[C.WebGPUPipesAdaptor],name:"batch"};const Kn=class bd{constructor(e,t){this.state=it.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init?.(this)}static getBatcher(e){return new this._availableBatchers[e]}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new Pn({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const r in this._activeBatches)this._activeBatches[r].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let r=this._activeBatches[e.batcherName];r||(r=this._activeBatches[e.batcherName]=bd.getBatcher(e.batcherName),r.begin()),this._activeBatch=r}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const r in t){const n=t[r],o=n.geometry;o.indexBuffer.setDataWithSize(n.indexBuffer,n.indexSize,!0),o.buffers[0].setDataWithSize(n.attributeBuffer.float32View,n.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const r in t){const n=t[r],o=n.geometry;n.dirty&&(n.dirty=!1,o.buffers[0].update(n.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,r=t.geometry,n=t.shader;this._adaptor.start(this,r,n)}this._adaptor.execute(this,e)}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};Kn.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"batch"},Kn._availableBatchers=Object.create(null);let ah=Kn;L.handleByMap(C.Batcher,ah._availableBatchers),L.add(Pn);const rr={name:"local-uniform-bit",vertex:{header:`
|
|
622
|
+
`;class Dv extends Dr{constructor(e){const{sprite:t,...r}=e,n=new _a(t.texture),o=new Ue({uFilterMatrix:{value:new B,type:"mat3x3<f32>"},uMaskClamp:{value:n.uClampFrame,type:"vec4<f32>"},uAlpha:{value:1,type:"f32"},uInverse:{value:e.inverse?1:0,type:"f32"}}),c=It.from({vertex:{source:qc,entryPoint:"mainVertex"},fragment:{source:qc,entryPoint:"mainFragment"}}),l=vt.from({vertex:Bv,fragment:kv,name:"mask-filter"});super({...r,gpuProgram:c,glProgram:l,clipToViewport:!1,resources:{filterUniforms:o,uMaskTexture:t.texture.source}}),this.sprite=t,this._textureMatrix=n}set inverse(e){this.resources.filterUniforms.uniforms.uInverse=e?1:0}get inverse(){return this.resources.filterUniforms.uniforms.uInverse===1}apply(e,t,r,n){this._textureMatrix.texture=this.sprite.texture,e.calculateSpriteMatrix(this.resources.filterUniforms.uniforms.uFilterMatrix,this.sprite).prepend(this._textureMatrix.mapCoord),this.resources.uMaskTexture=this.sprite.texture.source,e.applyFilter(this,t,r,n)}}class Ce extends Ys{constructor(e){e instanceof je&&(e={context:e});const{context:t,roundPixels:r,...n}=e||{};super({label:"Graphics",...n}),this.renderPipeId="graphics",t?this._context=t:this._context=this._ownedContext=new je,this._context.on("update",this.onViewUpdate,this),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=r??!1}set context(e){e!==this._context&&(this._context.off("update",this.onViewUpdate,this),this._context=e,this._context.on("update",this.onViewUpdate,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._ownedContext=null,this._context=null,super.destroy(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 Ce(this._context.clone()):(this._ownedContext=null,new Ce(this._context))}lineStyle(e,t,r){H(j,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const n={};return e&&(n.width=e),t&&(n.color=t),r&&(n.alpha=r),this.context.strokeStyle=n,this}beginFill(e,t){H(j,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const r={};return e!==void 0&&(r.color=e),t!==void 0&&(r.alpha=t),this.context.fillStyle=r,this}endFill(){H(j,"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!==je.defaultStrokeStyle.width||e.color!==je.defaultStrokeStyle.color||e.alpha!==je.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return H(j,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",e)}drawEllipse(...e){return H(j,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",e)}drawPolygon(...e){return H(j,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",e)}drawRect(...e){return H(j,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",e)}drawRoundedRect(...e){return H(j,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",e)}drawStar(...e){return H(j,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",e)}}const Kc=class xd extends Vi{constructor(...e){let t=e[0]??{};t instanceof Float32Array&&(H(j,"use new MeshGeometry({ positions, uvs, indices }) instead"),t={positions:t,uvs:e[1],indices:e[2]}),t={...xd.defaultOptions,...t};const r=t.positions||new Float32Array([0,0,1,0,1,1,0,1]);let n=t.uvs;n||(t.positions?n=new Float32Array(r.length):n=new Float32Array([0,0,1,0,1,1,0,1]));const o=t.indices||new Uint32Array([0,1,2,0,2,3]),c=t.shrinkBuffersToFit,l=new We({data:r,label:"attribute-mesh-positions",shrinkToFit:c,usage:$.VERTEX|$.COPY_DST}),d=new We({data:n,label:"attribute-mesh-uvs",shrinkToFit:c,usage:$.VERTEX|$.COPY_DST}),f=new We({data:o,label:"index-mesh-buffer",shrinkToFit:c,usage:$.INDEX|$.COPY_DST});super({attributes:{aPosition:{buffer:l,format:"float32x2",stride:8,offset:0},aUV:{buffer:d,format:"float32x2",stride:8,offset:0}},indexBuffer:f,topology:t.topology}),this.batchMode="auto"}get positions(){return this.attributes.aPosition.buffer.data}set positions(e){this.attributes.aPosition.buffer.data=e}get uvs(){return this.attributes.aUV.buffer.data}set uvs(e){this.attributes.aUV.buffer.data=e}get indices(){return this.indexBuffer.data}set indices(e){this.indexBuffer.data=e}};Kc.defaultOptions={topology:"triangle-list",shrinkBuffersToFit:!1};let qn=Kc;class jc extends Ys{constructor(e,t){const{text:r,resolution:n,style:o,anchor:c,width:l,height:d,roundPixels:f,...m}=e;super({...m}),this.batched=!0,this._resolution=null,this._autoResolution=!0,this._didTextUpdate=!0,this._styleClass=t,this.text=r??"",this.style=o,this.resolution=n??null,this.allowChildren=!1,this._anchor=new be({_onUpdate:()=>{this.onViewUpdate()}}),c&&(this.anchor=c),this.roundPixels=f??!1,l!==void 0&&(this.width=l),d!==void 0&&(this.height=d)}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,r=this.bounds.height,n=-t*this.anchor.x;let o=0;return e.x>=n&&e.x<=n+t&&(o=-r*this.anchor.y,e.y>=o&&e.y<=o+r)}onViewUpdate(){this.didViewUpdate||(this._didTextUpdate=!0),super.onViewUpdate()}destroy(e=!1){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 Zc(s,e){let t=s[0]??{};return(typeof t=="string"||s[1])&&(H(j,`use new ${e}({ text: "hi!", style }) instead`),t={text:t,style:s[1]}),t}let Ht=null,Tt=null;function Ov(s,e){Ht||(Ht=V.get().createCanvas(256,128),Tt=Ht.getContext("2d",{willReadFrequently:!0}),Tt.globalCompositeOperation="copy",Tt.globalAlpha=1),(Ht.width<s||Ht.height<e)&&(Ht.width=Jt(s),Ht.height=Jt(e))}function Jc(s,e,t){for(let r=0,n=4*t*e;r<e;++r,n+=4)if(s[n+3]!==0)return!1;return!0}function Qc(s,e,t,r,n){const o=4*e;for(let c=r,l=r*o+4*t;c<=n;++c,l+=o)if(s[l+3]!==0)return!1;return!0}function Gv(...s){let e=s[0];e.canvas||(e={canvas:s[0],resolution:s[1]});const{canvas:t}=e,r=Math.min(e.resolution??1,1),n=e.width??t.width,o=e.height??t.height;let c=e.output;if(Ov(n,o),!Tt)throw new TypeError("Failed to get canvas 2D context");Tt.drawImage(t,0,0,n,o,0,0,n*r,o*r);const d=Tt.getImageData(0,0,n,o).data;let f=0,m=0,g=n-1,_=o-1;for(;m<o&&Jc(d,n,m);)++m;if(m===o)return z.EMPTY;for(;Jc(d,n,_);)--_;for(;Qc(d,n,f,m,_);)++f;for(;Qc(d,n,g,m,_);)--g;return++g,++_,Tt.globalCompositeOperation="source-over",Tt.strokeRect(f,m,g-f,_-m),Tt.globalCompositeOperation="copy",c??(c=new z),c.set(f/r,m/r,(g-f)/r,(_-m)/r),c}const eh=new z;class Lv{getCanvasAndContext(e){const{text:t,style:r,resolution:n=1}=e,o=r._getFinalPadding(),c=Be.measureText(t||" ",r),l=Math.ceil(Math.ceil(Math.max(1,c.width)+o*2)*n),d=Math.ceil(Math.ceil(Math.max(1,c.height)+o*2)*n),f=xt.getOptimalCanvasAndContext(l,d);this._renderTextToCanvas(t,r,o,n,f);const m=r.trim?Gv({canvas:f.canvas,width:l,height:d,resolution:1,output:eh}):eh.set(0,0,l,d);return{canvasAndContext:f,frame:m}}returnCanvasAndContext(e){xt.returnCanvasAndContext(e)}_renderTextToCanvas(e,t,r,n,o){const{canvas:c,context:l}=o,d=Wr(t),f=Be.measureText(e||" ",t),m=f.lines,g=f.lineHeight,_=f.lineWidths,y=f.maxLineWidth,a=f.fontProperties,h=c.height;if(l.resetTransform(),l.scale(n,n),l.textBaseline=t.textBaseline,t._stroke?.width){const x=t._stroke;l.lineWidth=x.width,l.miterLimit=x.miterLimit,l.lineJoin=x.join,l.lineCap=x.cap}l.font=d;let u,p;const v=t.dropShadow?2:1;for(let x=0;x<v;++x){const b=t.dropShadow&&x===0,T=b?Math.ceil(Math.max(1,h)+r*2):0,w=T*n;if(b){l.fillStyle="black",l.strokeStyle="black";const A=t.dropShadow,P=A.color,I=A.alpha;l.shadowColor=le.shared.setValue(P).setAlpha(I).toRgbaString();const k=A.blur*n,O=A.distance*n;l.shadowBlur=k,l.shadowOffsetX=Math.cos(A.angle)*O,l.shadowOffsetY=Math.sin(A.angle)*O+w}else{if(l.fillStyle=t._fill?Zr(t._fill,l,f,r*2):null,t._stroke?.width){const A=t._stroke.width*.5+r*2;l.strokeStyle=Zr(t._stroke,l,f,A)}l.shadowColor="black"}let S=(g-a.fontSize)/2;g-a.fontSize<0&&(S=0);const E=t._stroke?.width??0;for(let A=0;A<m.length;A++)u=E/2,p=E/2+A*g+a.ascent+S,t.align==="right"?u+=y-_[A]:t.align==="center"&&(u+=(y-_[A])/2),t._stroke?.width&&this._drawLetterSpacing(m[A],t,o,u+r,p+r-T,!0),t._fill!==void 0&&this._drawLetterSpacing(m[A],t,o,u+r,p+r-T)}}_drawLetterSpacing(e,t,r,n,o,c=!1){const{context:l}=r,d=t.letterSpacing;let f=!1;if(Be.experimentalLetterSpacingSupported&&(Be.experimentalLetterSpacing?(l.letterSpacing=`${d}px`,l.textLetterSpacing=`${d}px`,f=!0):(l.letterSpacing="0px",l.textLetterSpacing="0px")),d===0||f){c?l.strokeText(e,n,o):l.fillText(e,n,o);return}let m=n;const g=Be.graphemeSegmenter(e);let _=l.measureText(e).width,y=0;for(let a=0;a<g.length;++a){const h=g[a];c?l.strokeText(h,m,o):l.fillText(h,m,o);let u="";for(let p=a+1;p<g.length;++p)u+=g[p];y=l.measureText(u).width,m+=_-y+d,_=y}}}const ir=new Lv;class Nv extends jc{constructor(...e){const t=Zc(e,"Text");super(t,De),this.renderPipeId="text",t.textureStyle&&(this.textureStyle=t.textureStyle instanceof at?t.textureStyle:new at(t.textureStyle))}updateBounds(){const e=this._bounds,t=this._anchor;let r=0,n=0;if(this._style.trim){const{frame:o,canvasAndContext:c}=ir.getCanvasAndContext({text:this.text,style:this._style,resolution:1});ir.returnCanvasAndContext(c),r=o.width,n=o.height}else{const o=Be.measureText(this._text,this._style);r=o.width,n=o.height}e.minX=-t._x*r,e.maxX=e.minX+r,e.minY=-t._y*n,e.maxY=e.minY+n}}class zv extends jc{constructor(...e){var t;const r=Zc(e,"BitmapText");r.style??(r.style=r.style||{}),(t=r.style).fill??(t.fill=16777215),super(r,De),this.renderPipeId="bitmapText"}updateBounds(){const e=this._bounds,t=this._anchor,r=Qi.measureText(this.text,this._style),n=r.scale,o=r.offsetY*n;let c=r.width*n,l=r.height*n;const d=this._style._stroke;d&&(c+=d.width,l+=d.width),e.minX=-t._x*c,e.maxX=e.minX+c,e.minY=-t._y*(l+o),e.maxY=e.minY+l}set resolution(e){e!==null&&G("[BitmapText] dynamically updating the resolution is not supported. Resolution should be managed by the BitmapFont.")}get resolution(){return this._resolution}}const th="http://www.w3.org/2000/svg",ih="http://www.w3.org/1999/xhtml";class rh{constructor(){this.svgRoot=document.createElementNS(th,"svg"),this.foreignObject=document.createElementNS(th,"foreignObject"),this.domElement=document.createElementNS(ih,"div"),this.styleElement=document.createElementNS(ih,"style");const{foreignObject:e,svgRoot:t,styleElement:r,domElement:n}=this;e.setAttribute("width","10000"),e.setAttribute("height","10000"),e.style.overflow="hidden",t.appendChild(e),e.appendChild(r),e.appendChild(n),this.image=V.get().createImage()}destroy(){this.svgRoot.remove(),this.foreignObject.remove(),this.styleElement.remove(),this.domElement.remove(),this.image.src="",this.image.remove(),this.svgRoot=null,this.foreignObject=null,this.styleElement=null,this.domElement=null,this.image=null,this.canvasAndContext=null}}let sh;function Hv(s,e,t,r){r||(r=sh||(sh=new rh));const{domElement:n,styleElement:o,svgRoot:c}=r;n.innerHTML=`<style>${e.cssStyle};</style><div style='padding:0'>${s}</div>`,n.setAttribute("style","transform-origin: top left; display: inline-block"),t&&(o.textContent=t),document.body.appendChild(c);const l=n.getBoundingClientRect();c.remove();const d=e.padding*2;return{width:l.width-d,height:l.height-d}}class nh{constructor(){this._tempState=it.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,t,r){const n=e.renderer,o=this._didUploadHash[r.uid];n.shader.bind(r,o),o||(this._didUploadHash[r.uid]=!0),n.shader.updateUniformGroup(n.globalUniforms.uniformGroup),n.geometry.bind(t,r.glProgram)}execute(e,t){const r=e.renderer;this._tempState.blendMode=t.blendMode,r.state.set(this._tempState);const n=t.textures.textures;for(let o=0;o<t.textures.count;o++)r.texture.bind(n[o],o);r.geometry.draw(t.topology,t.size,t.start)}}nh.extension={type:[C.WebGLPipesAdaptor],name:"batch"};const ts=it.for2d();class oh{start(e,t,r){const n=e.renderer,o=n.encoder,c=r.gpuProgram;this._shader=r,this._geometry=t,o.setGeometry(t,c),ts.blendMode="normal",n.pipeline.getPipeline(t,c,ts);const l=n.globalUniforms.bindGroup;o.resetBindGroup(1),o.setBindGroup(0,l,c)}execute(e,t){const r=this._shader.gpuProgram,n=e.renderer,o=n.encoder;if(!t.bindGroup){const d=t.textures;t.bindGroup=yn(d.textures,d.count,n.limits.maxBatchableTextures)}ts.blendMode=t.blendMode;const c=n.bindGroup.getBindGroup(t.bindGroup,r,1),l=n.pipeline.getPipeline(this._geometry,r,ts,t.topology);t.bindGroup._touch(n.textureGC.count),o.setPipeline(l),o.renderPassEncoder.setBindGroup(1,c),o.renderPassEncoder.drawIndexed(t.size,1,t.start)}}oh.extension={type:[C.WebGPUPipesAdaptor],name:"batch"};const Kn=class bd{constructor(e,t){this.state=it.for2d(),this._batchersByInstructionSet=Object.create(null),this._activeBatches=Object.create(null),this.renderer=e,this._adaptor=t,this._adaptor.init?.(this)}static getBatcher(e){return new this._availableBatchers[e]}buildStart(e){let t=this._batchersByInstructionSet[e.uid];t||(t=this._batchersByInstructionSet[e.uid]=Object.create(null),t.default||(t.default=new Pn({maxTextures:this.renderer.limits.maxBatchableTextures}))),this._activeBatches=t,this._activeBatch=this._activeBatches.default;for(const r in this._activeBatches)this._activeBatches[r].begin()}addToBatch(e,t){if(this._activeBatch.name!==e.batcherName){this._activeBatch.break(t);let r=this._activeBatches[e.batcherName];r||(r=this._activeBatches[e.batcherName]=bd.getBatcher(e.batcherName),r.begin()),this._activeBatch=r}this._activeBatch.add(e)}break(e){this._activeBatch.break(e)}buildEnd(e){this._activeBatch.break(e);const t=this._activeBatches;for(const r in t){const n=t[r],o=n.geometry;o.indexBuffer.setDataWithSize(n.indexBuffer,n.indexSize,!0),o.buffers[0].setDataWithSize(n.attributeBuffer.float32View,n.attributeSize,!1)}}upload(e){const t=this._batchersByInstructionSet[e.uid];for(const r in t){const n=t[r],o=n.geometry;n.dirty&&(n.dirty=!1,o.buffers[0].update(n.attributeSize*4))}}execute(e){if(e.action==="startBatch"){const t=e.batcher,r=t.geometry,n=t.shader;this._adaptor.start(this,r,n)}this._adaptor.execute(this,e)}destroy(){this.state=null,this.renderer=null,this._adaptor=null;for(const e in this._activeBatches)this._activeBatches[e].destroy();this._activeBatches=null}};Kn.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"batch"},Kn._availableBatchers=Object.create(null);let ah=Kn;L.handleByMap(C.Batcher,ah._availableBatchers),L.add(Pn);const rr={name:"local-uniform-bit",vertex:{header:`
|
|
623
623
|
|
|
624
624
|
struct LocalUniforms {
|
|
625
625
|
uTransformMatrix:mat3x3<f32>,
|
|
@@ -675,7 +675,7 @@ fn mainFragment(
|
|
|
675
675
|
|
|
676
676
|
`,main:`
|
|
677
677
|
outColor = texture(uTexture, vUV);
|
|
678
|
-
`}},Xv=new Se;class $v extends Cr{constructor(){super(),this.filters=[new Dv({sprite:new we(F.EMPTY),inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].sprite=e}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}}class lh{constructor(e){this._activeMaskStage=[],this._renderer=e}push(e,t,r){const n=this._renderer;if(n.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.renderMaskToTexture){const o=e.mask;o.includeInBuild=!0,o.collectRenderables(r,n,null),o.includeInBuild=!1}n.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,r=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const n=me.get($v);if(n.inverse=e.inverse,r){e.mask.mask.measurable=!0;const o=Gs(e.mask.mask,!0,Xv);e.mask.mask.measurable=!1,o.ceil();const c=t.renderTarget.renderTarget.colorTexture.source,l=Te.getOptimalTexture(o.width,o.height,c._resolution,c.antialias);t.renderTarget.push(l,!0),t.globalUniforms.push({offset:o,worldColor:4294967295});const d=n.sprite;d.texture=l,d.worldTransform.tx=o.minX,d.worldTransform.ty=o.minY,this._activeMaskStage.push({filterEffect:n,maskedContainer:e.maskedContainer,filterTexture:l})}else n.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:n,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const n=this._activeMaskStage[this._activeMaskStage.length-1];r&&(t.type===tt.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:n.maskedContainer,filterEffect:n.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const n=this._activeMaskStage.pop();r&&Te.returnTexture(n.filterTexture),me.return(n.filterEffect)}}destroy(){this._renderer=null,this._activeMaskStage=null}}lh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"alphaMask"};class ch{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,r){this._renderer.renderPipes.batch.break(r);const o=this._colorStack;o[this._colorStackIndex]=o[this._colorStackIndex-1]&e.mask;const c=this._colorStack[this._colorStackIndex];c!==this._currentColor&&(this._currentColor=c,r.add({renderPipeId:"colorMask",colorMask:c,canBundle:!1})),this._colorStackIndex++}pop(e,t,r){this._renderer.renderPipes.batch.break(r);const o=this._colorStack;this._colorStackIndex--;const c=o[this._colorStackIndex-1];c!==this._currentColor&&(this._currentColor=c,r.add({renderPipeId:"colorMask",colorMask:c,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}ch.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"colorMask"};class hh{constructor(e){this._maskStackHash={},this._maskHash=new WeakMap,this._renderer=e}push(e,t,r){var n;const o=e,c=this._renderer;c.renderPipes.batch.break(r),c.renderPipes.blendMode.setBlendMode(o.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const l=o.mask;l.includeInBuild=!0,this._maskHash.has(o)||this._maskHash.set(o,{instructionsStart:0,instructionsLength:0});const d=this._maskHash.get(o);d.instructionsStart=r.instructionSize,l.collectRenderables(r,c,null),l.includeInBuild=!1,c.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const f=r.instructionSize-d.instructionsStart-1;d.instructionsLength=f;const m=c.renderTarget.renderTarget.uid;(n=this._maskStackHash)[m]??(n[m]=0)}pop(e,t,r){const n=e,o=this._renderer;o.renderPipes.batch.break(r),o.renderPipes.blendMode.setBlendMode(n.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const c=this._maskHash.get(e);for(let l=0;l<c.instructionsLength;l++)r.instructions[r.instructionSize++]=r.instructions[c.instructionsStart++];r.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){var t;const r=this._renderer,n=r.renderTarget.renderTarget.uid;let o=(t=this._maskStackHash)[n]??(t[n]=0);e.action==="pushMaskBegin"?(r.renderTarget.ensureDepthStencil(),r.stencil.setStencilMode(pe.RENDERING_MASK_ADD,o),o++,r.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?r.stencil.setStencilMode(pe.INVERSE_MASK_ACTIVE,o):r.stencil.setStencilMode(pe.MASK_ACTIVE,o),r.colorMask.setMask(15)):e.action==="popMaskBegin"?(r.colorMask.setMask(0),o!==0?r.stencil.setStencilMode(pe.RENDERING_MASK_REMOVE,o):(r.renderTarget.clear(null,ze.STENCIL),r.stencil.setStencilMode(pe.DISABLED,o)),o--):e.action==="popMaskEnd"&&(e.inverse?r.stencil.setStencilMode(pe.INVERSE_MASK_ACTIVE,o):r.stencil.setStencilMode(pe.MASK_ACTIVE,o),r.colorMask.setMask(15)),this._maskStackHash[n]=o}destroy(){this._renderer=null,this._maskStackHash=null,this._maskHash=null}}hh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"stencilMask"};var is=(s=>(s[s.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",s[s.ARRAY_BUFFER=34962]="ARRAY_BUFFER",s[s.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",s))(is||{});class qv{constructor(e,t){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}}class uh{constructor(e){this._gpuBuffers=Object.create(null),this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_gpuBuffers")}destroy(){this.destroyAll(),this._renderer=null,this._gl=null,this._gpuBuffers={},this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this._gpuBuffers=Object.create(null),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return this._gpuBuffers[e.uid]||this.createGLBuffer(e)}bind(e){const{_gl:t}=this,r=this.getGlBuffer(e);t.bindBuffer(r.type,r.buffer)}bindBufferBase(e,t){const{_gl:r}=this;this._boundBufferBases[t]!==e&&(this._boundBufferBases[t]=e,e._lastBindBaseLocation=t,r.bindBufferBase(r.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 r=0,n=this._nextBindBaseIndex;for(;r<2;){n>=this._maxBindings&&(n=this._minBaseLocation,r++);const o=this._boundBufferBases[n];if(o&&o._lastBindCallId===this._bindCallId){n++;continue}break}return t=n,this._nextBindBaseIndex=n+1,r>=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,r,n){const{_gl:o}=this;r||(r=0),t||(t=0),this._boundBufferBases[t]=null,o.bindBufferRange(o.UNIFORM_BUFFER,t||0,e.buffer,r*256,n||256)}updateBuffer(e){const{_gl:t}=this,r=this.getGlBuffer(e);if(e._updateID===r.updateID)return r;r.updateID=e._updateID,t.bindBuffer(r.type,r.buffer);const n=e.data,o=e.descriptor.usage&$.STATIC?t.STATIC_DRAW:t.DYNAMIC_DRAW;return n?r.byteLength>=n.byteLength?t.bufferSubData(r.type,0,n,0,e._updateSize/n.BYTES_PER_ELEMENT):(r.byteLength=n.byteLength,t.bufferData(r.type,n,o)):(r.byteLength=e.descriptor.size,t.bufferData(r.type,r.byteLength,o)),r}destroyAll(){const e=this._gl;for(const t in this._gpuBuffers)this._gpuBuffers[t]&&e.deleteBuffer(this._gpuBuffers[t].buffer);this._gpuBuffers=Object.create(null)}onBufferDestroy(e,t){if(!this._gpuBuffers[e.uid])return;const r=this._gpuBuffers[e.uid],n=this._gl;t||n.deleteBuffer(r.buffer),e.off("destroy",this.onBufferDestroy,this),this._gpuBuffers[e.uid]=null}createGLBuffer(e){const{_gl:t}=this;let r=is.ARRAY_BUFFER;e.descriptor.usage&$.INDEX?r=is.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&$.UNIFORM&&(r=is.UNIFORM_BUFFER);const n=new qv(t.createBuffer(),r);return this._gpuBuffers[e.uid]=n,e.on("destroy",this.onBufferDestroy,this),n}resetState(){this._boundBufferBases=Object.create(null)}}uh.extension={type:[C.WebGLSystem],name:"buffer"};const Zn=class Td{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={...Td.defaultOptions,...e};let t=this.multiView=e.multiView;if(e.context&&t&&(G("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),t=!1),t?this.canvas=V.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const r=this._renderer.background.alpha<1,n=e.premultipliedAlpha??!0,o=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:r,premultipliedAlpha:n,antialias:o,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&G("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 V.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 r;const n=this.canvas;if(e===2&&(r=n.getContext("webgl2",t)),!r&&(r=n.getContext("webgl",t),!r))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=r,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 r=e.getExtension("WEBGL_provoking_vertex");r&&r.provokingVertexWEBGL(r.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&&G("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const r=this.supports,n=this.webGLVersion===2,o=this.extensions;r.uint32Indices=n||!!o.uint32ElementIndex,r.uniformBufferObject=n,r.vertexArrayObject=n||!!o.vertexArrayObject,r.srgbTextures=n||!!o.srgb,r.nonPowOf2wrapping=n,r.nonPowOf2mipmaps=n,r.msaa=n,r.uint32Indices||G("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};Zn.extension={type:[C.WebGLSystem],name:"context"},Zn.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Kv=Zn;function dh(s,e){for(const t in s.attributes){const r=s.attributes[t],n=e[t];n?(r.format??(r.format=n.format),r.offset??(r.offset=n.offset),r.instance??(r.instance=n.instance)):G(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}jv(s)}function jv(s){const{buffers:e,attributes:t}=s,r={},n={};for(const o in e){const c=e[o];r[c.uid]=0,n[c.uid]=0}for(const o in t){const c=t[o];r[c.buffer.uid]+=Et(c.format).stride}for(const o in t){const c=t[o];c.stride??(c.stride=r[c.buffer.uid]),c.start??(c.start=n[c.buffer.uid]),n[c.buffer.uid]+=Et(c.format).stride}}var Jn=(s=>(s[s.RGBA=6408]="RGBA",s[s.RGB=6407]="RGB",s[s.RG=33319]="RG",s[s.RED=6403]="RED",s[s.RGBA_INTEGER=36249]="RGBA_INTEGER",s[s.RGB_INTEGER=36248]="RGB_INTEGER",s[s.RG_INTEGER=33320]="RG_INTEGER",s[s.RED_INTEGER=36244]="RED_INTEGER",s[s.ALPHA=6406]="ALPHA",s[s.LUMINANCE=6409]="LUMINANCE",s[s.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",s[s.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",s[s.DEPTH_STENCIL=34041]="DEPTH_STENCIL",s))(Jn||{}),fh=(s=>(s[s.TEXTURE_2D=3553]="TEXTURE_2D",s[s.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",s[s.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",s[s.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",s[s.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",s[s.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",s[s.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",s[s.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",s[s.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",s))(fh||{}),Z=(s=>(s[s.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",s[s.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",s[s.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",s[s.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",s[s.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",s[s.UNSIGNED_INT=5125]="UNSIGNED_INT",s[s.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",s[s.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",s[s.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",s[s.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",s[s.BYTE=5120]="BYTE",s[s.SHORT=5122]="SHORT",s[s.INT=5124]="INT",s[s.FLOAT=5126]="FLOAT",s[s.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",s[s.HALF_FLOAT=36193]="HALF_FLOAT",s))(Z||{});const ph={uint8x2:Z.UNSIGNED_BYTE,uint8x4:Z.UNSIGNED_BYTE,sint8x2:Z.BYTE,sint8x4:Z.BYTE,unorm8x2:Z.UNSIGNED_BYTE,unorm8x4:Z.UNSIGNED_BYTE,snorm8x2:Z.BYTE,snorm8x4:Z.BYTE,uint16x2:Z.UNSIGNED_SHORT,uint16x4:Z.UNSIGNED_SHORT,sint16x2:Z.SHORT,sint16x4:Z.SHORT,unorm16x2:Z.UNSIGNED_SHORT,unorm16x4:Z.UNSIGNED_SHORT,snorm16x2:Z.SHORT,snorm16x4:Z.SHORT,float16x2:Z.HALF_FLOAT,float16x4:Z.HALF_FLOAT,float32:Z.FLOAT,float32x2:Z.FLOAT,float32x3:Z.FLOAT,float32x4:Z.FLOAT,uint32:Z.UNSIGNED_INT,uint32x2:Z.UNSIGNED_INT,uint32x3:Z.UNSIGNED_INT,uint32x4:Z.UNSIGNED_INT,sint32:Z.INT,sint32x2:Z.INT,sint32x3:Z.INT,sint32x4:Z.INT};function Zv(s){return ph[s]??ph.float32}const Jv={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class mh{constructor(e){this._geometryVaoHash=Object.create(null),this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._renderer.renderableGC.addManagedHash(this,"_geometryVaoHash")}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");const t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=n=>t.bindVertexArrayOES(n),e.deleteVertexArray=n=>t.deleteVertexArrayOES(n));const r=this._renderer.context.extensions.vertexAttribDivisorANGLE;r&&(e.drawArraysInstanced=(n,o,c,l)=>{r.drawArraysInstancedANGLE(n,o,c,l)},e.drawElementsInstanced=(n,o,c,l,d)=>{r.drawElementsInstancedANGLE(n,o,c,l,d)},e.vertexAttribDivisor=(n,o)=>r.vertexAttribDivisorANGLE(n,o)),this._activeGeometry=null,this._activeVao=null,this._geometryVaoHash=Object.create(null)}bind(e,t){const r=this.gl;this._activeGeometry=e;const n=this.getVao(e,t);this._activeVao!==n&&(this._activeVao=n,r.bindVertexArray(n)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,t=this._renderer.buffer;for(let r=0;r<e.buffers.length;r++){const n=e.buffers[r];t.updateBuffer(n)}}checkCompatibility(e,t){const r=e.attributes,n=t._attributeData;for(const o in n)if(!r[o])throw new Error(`shader and geometry incompatible, geometry missing the "${o}" attribute`)}getSignature(e,t){const r=e.attributes,n=t._attributeData,o=["g",e.uid];for(const c in r)n[c]&&o.push(c,n[c].location);return o.join("-")}getVao(e,t){return this._geometryVaoHash[e.uid]?.[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,r=!0){const n=this._renderer.gl,o=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);const c=this.getSignature(e,t);this._geometryVaoHash[e.uid]||(this._geometryVaoHash[e.uid]=Object.create(null),e.on("destroy",this.onGeometryDestroy,this));const l=this._geometryVaoHash[e.uid];let d=l[c];if(d)return l[t._key]=d,d;dh(e,t._attributeData);const f=e.buffers;d=n.createVertexArray(),n.bindVertexArray(d);for(let m=0;m<f.length;m++){const g=f[m];o.bind(g)}return this.activateVao(e,t),l[t._key]=d,l[c]=d,n.bindVertexArray(null),d}onGeometryDestroy(e,t){const r=this._geometryVaoHash[e.uid],n=this.gl;if(r){if(t)for(const o in r)this._activeVao!==r[o]&&this.unbind(),n.deleteVertexArray(r[o]);this._geometryVaoHash[e.uid]=null}}destroyAll(e=!1){const t=this.gl;for(const r in this._geometryVaoHash){if(e)for(const n in this._geometryVaoHash[r]){const o=this._geometryVaoHash[r];this._activeVao!==o&&this.unbind(),t.deleteVertexArray(o[n])}this._geometryVaoHash[r]=null}}activateVao(e,t){const r=this._renderer.gl,n=this._renderer.buffer,o=e.attributes;e.indexBuffer&&n.bind(e.indexBuffer);let c=null;for(const l in o){const d=o[l],f=d.buffer,m=n.getGlBuffer(f),g=t._attributeData[l];if(g){c!==m&&(n.bind(f),c=m);const _=g.location;r.enableVertexAttribArray(_);const y=Et(d.format),a=Zv(d.format);if(g.format?.substring(1,4)==="int"?r.vertexAttribIPointer(_,y.size,a,d.stride,d.offset):r.vertexAttribPointer(_,y.size,a,y.normalised,d.stride,d.offset),d.instance)if(this.hasInstance){const h=d.divisor??1;r.vertexAttribDivisor(_,h)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,t,r,n){const{gl:o}=this._renderer,c=this._activeGeometry,l=Jv[e||c.topology];if(n??(n=c.instanceCount),c.indexBuffer){const d=c.indexBuffer.data.BYTES_PER_ELEMENT,f=d===2?o.UNSIGNED_SHORT:o.UNSIGNED_INT;n!==1?o.drawElementsInstanced(l,t||c.indexBuffer.data.length,f,(r||0)*d,n):o.drawElements(l,t||c.indexBuffer.data.length,f,(r||0)*d)}else n!==1?o.drawArraysInstanced(l,r||0,t||c.getSize(),n):o.drawArrays(l,r||0,t||c.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null,this._geometryVaoHash={}}}mh.extension={type:[C.WebGLSystem],name:"geometry"};const Qv=new Vi({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),Qn=class wd{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:t,antialias:r}={...wd.defaultOptions,...e};this.useBackBuffer=t,this._antialias=r,this._renderer.context.supports.msaa||(G("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=it.for2d();const n=new vt({vertex:`
|
|
678
|
+
`}},Xv=new Se;class $v extends Cr{constructor(){super(),this.filters=[new Dv({sprite:new we(F.EMPTY),inverse:!1,resolution:"inherit",antialias:"inherit"})]}get sprite(){return this.filters[0].sprite}set sprite(e){this.filters[0].sprite=e}get inverse(){return this.filters[0].inverse}set inverse(e){this.filters[0].inverse=e}}class lh{constructor(e){this._activeMaskStage=[],this._renderer=e}push(e,t,r){const n=this._renderer;if(n.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1,maskedContainer:t}),e.inverse=t._maskOptions.inverse,e.renderMaskToTexture){const o=e.mask;o.includeInBuild=!0,o.collectRenderables(r,n,null),o.includeInBuild=!1}n.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"pushMaskEnd",mask:e,maskedContainer:t,inverse:t._maskOptions.inverse,canBundle:!1})}pop(e,t,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"alphaMask",action:"popMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1})}execute(e){const t=this._renderer,r=e.mask.renderMaskToTexture;if(e.action==="pushMaskBegin"){const n=me.get($v);if(n.inverse=e.inverse,r){e.mask.mask.measurable=!0;const o=Gs(e.mask.mask,!0,Xv);e.mask.mask.measurable=!1,o.ceil();const c=t.renderTarget.renderTarget.colorTexture.source,l=Te.getOptimalTexture(o.width,o.height,c._resolution,c.antialias);t.renderTarget.push(l,!0),t.globalUniforms.push({offset:o,worldColor:4294967295});const d=n.sprite;d.texture=l,d.worldTransform.tx=o.minX,d.worldTransform.ty=o.minY,this._activeMaskStage.push({filterEffect:n,maskedContainer:e.maskedContainer,filterTexture:l})}else n.sprite=e.mask.mask,this._activeMaskStage.push({filterEffect:n,maskedContainer:e.maskedContainer})}else if(e.action==="pushMaskEnd"){const n=this._activeMaskStage[this._activeMaskStage.length-1];r&&(t.type===tt.WEBGL&&t.renderTarget.finishRenderPass(),t.renderTarget.pop(),t.globalUniforms.pop()),t.filter.push({renderPipeId:"filter",action:"pushFilter",container:n.maskedContainer,filterEffect:n.filterEffect,canBundle:!1})}else if(e.action==="popMaskEnd"){t.filter.pop();const n=this._activeMaskStage.pop();r&&Te.returnTexture(n.filterTexture),me.return(n.filterEffect)}}destroy(){this._renderer=null,this._activeMaskStage=null}}lh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"alphaMask"};class ch{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,r){this._renderer.renderPipes.batch.break(r);const o=this._colorStack;o[this._colorStackIndex]=o[this._colorStackIndex-1]&e.mask;const c=this._colorStack[this._colorStackIndex];c!==this._currentColor&&(this._currentColor=c,r.add({renderPipeId:"colorMask",colorMask:c,canBundle:!1})),this._colorStackIndex++}pop(e,t,r){this._renderer.renderPipes.batch.break(r);const o=this._colorStack;this._colorStackIndex--;const c=o[this._colorStackIndex-1];c!==this._currentColor&&(this._currentColor=c,r.add({renderPipeId:"colorMask",colorMask:c,canBundle:!1}))}execute(e){this._renderer.colorMask.setMask(e.colorMask)}destroy(){this._renderer=null,this._colorStack=null}}ch.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"colorMask"};class hh{constructor(e){this._maskStackHash={},this._maskHash=new WeakMap,this._renderer=e}push(e,t,r){var n;const o=e,c=this._renderer;c.renderPipes.batch.break(r),c.renderPipes.blendMode.setBlendMode(o.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const l=o.mask;l.includeInBuild=!0,this._maskHash.has(o)||this._maskHash.set(o,{instructionsStart:0,instructionsLength:0});const d=this._maskHash.get(o);d.instructionsStart=r.instructionSize,l.collectRenderables(r,c,null),l.includeInBuild=!1,c.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"pushMaskEnd",mask:e,inverse:t._maskOptions.inverse,canBundle:!1});const f=r.instructionSize-d.instructionsStart-1;d.instructionsLength=f;const m=c.renderTarget.renderTarget.uid;(n=this._maskStackHash)[m]??(n[m]=0)}pop(e,t,r){const n=e,o=this._renderer;o.renderPipes.batch.break(r),o.renderPipes.blendMode.setBlendMode(n.mask,"none",r),r.add({renderPipeId:"stencilMask",action:"popMaskBegin",inverse:t._maskOptions.inverse,canBundle:!1});const c=this._maskHash.get(e);for(let l=0;l<c.instructionsLength;l++)r.instructions[r.instructionSize++]=r.instructions[c.instructionsStart++];r.add({renderPipeId:"stencilMask",action:"popMaskEnd",canBundle:!1})}execute(e){var t;const r=this._renderer,n=r.renderTarget.renderTarget.uid;let o=(t=this._maskStackHash)[n]??(t[n]=0);e.action==="pushMaskBegin"?(r.renderTarget.ensureDepthStencil(),r.stencil.setStencilMode(pe.RENDERING_MASK_ADD,o),o++,r.colorMask.setMask(0)):e.action==="pushMaskEnd"?(e.inverse?r.stencil.setStencilMode(pe.INVERSE_MASK_ACTIVE,o):r.stencil.setStencilMode(pe.MASK_ACTIVE,o),r.colorMask.setMask(15)):e.action==="popMaskBegin"?(r.colorMask.setMask(0),o!==0?r.stencil.setStencilMode(pe.RENDERING_MASK_REMOVE,o):(r.renderTarget.clear(null,He.STENCIL),r.stencil.setStencilMode(pe.DISABLED,o)),o--):e.action==="popMaskEnd"&&(e.inverse?r.stencil.setStencilMode(pe.INVERSE_MASK_ACTIVE,o):r.stencil.setStencilMode(pe.MASK_ACTIVE,o),r.colorMask.setMask(15)),this._maskStackHash[n]=o}destroy(){this._renderer=null,this._maskStackHash=null,this._maskHash=null}}hh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"stencilMask"};var is=(s=>(s[s.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",s[s.ARRAY_BUFFER=34962]="ARRAY_BUFFER",s[s.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",s))(is||{});class qv{constructor(e,t){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=t}}class uh{constructor(e){this._gpuBuffers=Object.create(null),this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_gpuBuffers")}destroy(){this.destroyAll(),this._renderer=null,this._gl=null,this._gpuBuffers={},this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this._gpuBuffers=Object.create(null),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return this._gpuBuffers[e.uid]||this.createGLBuffer(e)}bind(e){const{_gl:t}=this,r=this.getGlBuffer(e);t.bindBuffer(r.type,r.buffer)}bindBufferBase(e,t){const{_gl:r}=this;this._boundBufferBases[t]!==e&&(this._boundBufferBases[t]=e,e._lastBindBaseLocation=t,r.bindBufferBase(r.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 r=0,n=this._nextBindBaseIndex;for(;r<2;){n>=this._maxBindings&&(n=this._minBaseLocation,r++);const o=this._boundBufferBases[n];if(o&&o._lastBindCallId===this._bindCallId){n++;continue}break}return t=n,this._nextBindBaseIndex=n+1,r>=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,r,n){const{_gl:o}=this;r||(r=0),t||(t=0),this._boundBufferBases[t]=null,o.bindBufferRange(o.UNIFORM_BUFFER,t||0,e.buffer,r*256,n||256)}updateBuffer(e){const{_gl:t}=this,r=this.getGlBuffer(e);if(e._updateID===r.updateID)return r;r.updateID=e._updateID,t.bindBuffer(r.type,r.buffer);const n=e.data,o=e.descriptor.usage&$.STATIC?t.STATIC_DRAW:t.DYNAMIC_DRAW;return n?r.byteLength>=n.byteLength?t.bufferSubData(r.type,0,n,0,e._updateSize/n.BYTES_PER_ELEMENT):(r.byteLength=n.byteLength,t.bufferData(r.type,n,o)):(r.byteLength=e.descriptor.size,t.bufferData(r.type,r.byteLength,o)),r}destroyAll(){const e=this._gl;for(const t in this._gpuBuffers)this._gpuBuffers[t]&&e.deleteBuffer(this._gpuBuffers[t].buffer);this._gpuBuffers=Object.create(null)}onBufferDestroy(e,t){if(!this._gpuBuffers[e.uid])return;const r=this._gpuBuffers[e.uid],n=this._gl;t||n.deleteBuffer(r.buffer),e.off("destroy",this.onBufferDestroy,this),this._gpuBuffers[e.uid]=null}createGLBuffer(e){const{_gl:t}=this;let r=is.ARRAY_BUFFER;e.descriptor.usage&$.INDEX?r=is.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&$.UNIFORM&&(r=is.UNIFORM_BUFFER);const n=new qv(t.createBuffer(),r);return this._gpuBuffers[e.uid]=n,e.on("destroy",this.onBufferDestroy,this),n}resetState(){this._boundBufferBases=Object.create(null)}}uh.extension={type:[C.WebGLSystem],name:"buffer"};const Zn=class Td{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={...Td.defaultOptions,...e};let t=this.multiView=e.multiView;if(e.context&&t&&(G("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),t=!1),t?this.canvas=V.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const r=this._renderer.background.alpha<1,n=e.premultipliedAlpha??!0,o=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:r,premultipliedAlpha:n,antialias:o,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&G("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 V.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 r;const n=this.canvas;if(e===2&&(r=n.getContext("webgl2",t)),!r&&(r=n.getContext("webgl",t),!r))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=r,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 r=e.getExtension("WEBGL_provoking_vertex");r&&r.provokingVertexWEBGL(r.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&&G("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const r=this.supports,n=this.webGLVersion===2,o=this.extensions;r.uint32Indices=n||!!o.uint32ElementIndex,r.uniformBufferObject=n,r.vertexArrayObject=n||!!o.vertexArrayObject,r.srgbTextures=n||!!o.srgb,r.nonPowOf2wrapping=n,r.nonPowOf2mipmaps=n,r.msaa=n,r.uint32Indices||G("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};Zn.extension={type:[C.WebGLSystem],name:"context"},Zn.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Kv=Zn;function dh(s,e){for(const t in s.attributes){const r=s.attributes[t],n=e[t];n?(r.format??(r.format=n.format),r.offset??(r.offset=n.offset),r.instance??(r.instance=n.instance)):G(`Attribute ${t} is not present in the shader, but is present in the geometry. Unable to infer attribute details.`)}jv(s)}function jv(s){const{buffers:e,attributes:t}=s,r={},n={};for(const o in e){const c=e[o];r[c.uid]=0,n[c.uid]=0}for(const o in t){const c=t[o];r[c.buffer.uid]+=Et(c.format).stride}for(const o in t){const c=t[o];c.stride??(c.stride=r[c.buffer.uid]),c.start??(c.start=n[c.buffer.uid]),n[c.buffer.uid]+=Et(c.format).stride}}var Jn=(s=>(s[s.RGBA=6408]="RGBA",s[s.RGB=6407]="RGB",s[s.RG=33319]="RG",s[s.RED=6403]="RED",s[s.RGBA_INTEGER=36249]="RGBA_INTEGER",s[s.RGB_INTEGER=36248]="RGB_INTEGER",s[s.RG_INTEGER=33320]="RG_INTEGER",s[s.RED_INTEGER=36244]="RED_INTEGER",s[s.ALPHA=6406]="ALPHA",s[s.LUMINANCE=6409]="LUMINANCE",s[s.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",s[s.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",s[s.DEPTH_STENCIL=34041]="DEPTH_STENCIL",s))(Jn||{}),fh=(s=>(s[s.TEXTURE_2D=3553]="TEXTURE_2D",s[s.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",s[s.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",s[s.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",s[s.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",s[s.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",s[s.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",s[s.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",s[s.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",s))(fh||{}),Z=(s=>(s[s.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",s[s.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",s[s.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",s[s.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",s[s.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",s[s.UNSIGNED_INT=5125]="UNSIGNED_INT",s[s.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",s[s.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",s[s.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",s[s.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",s[s.BYTE=5120]="BYTE",s[s.SHORT=5122]="SHORT",s[s.INT=5124]="INT",s[s.FLOAT=5126]="FLOAT",s[s.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",s[s.HALF_FLOAT=36193]="HALF_FLOAT",s))(Z||{});const ph={uint8x2:Z.UNSIGNED_BYTE,uint8x4:Z.UNSIGNED_BYTE,sint8x2:Z.BYTE,sint8x4:Z.BYTE,unorm8x2:Z.UNSIGNED_BYTE,unorm8x4:Z.UNSIGNED_BYTE,snorm8x2:Z.BYTE,snorm8x4:Z.BYTE,uint16x2:Z.UNSIGNED_SHORT,uint16x4:Z.UNSIGNED_SHORT,sint16x2:Z.SHORT,sint16x4:Z.SHORT,unorm16x2:Z.UNSIGNED_SHORT,unorm16x4:Z.UNSIGNED_SHORT,snorm16x2:Z.SHORT,snorm16x4:Z.SHORT,float16x2:Z.HALF_FLOAT,float16x4:Z.HALF_FLOAT,float32:Z.FLOAT,float32x2:Z.FLOAT,float32x3:Z.FLOAT,float32x4:Z.FLOAT,uint32:Z.UNSIGNED_INT,uint32x2:Z.UNSIGNED_INT,uint32x3:Z.UNSIGNED_INT,uint32x4:Z.UNSIGNED_INT,sint32:Z.INT,sint32x2:Z.INT,sint32x3:Z.INT,sint32x4:Z.INT};function Zv(s){return ph[s]??ph.float32}const Jv={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class mh{constructor(e){this._geometryVaoHash=Object.create(null),this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._renderer.renderableGC.addManagedHash(this,"_geometryVaoHash")}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");const t=this._renderer.context.extensions.vertexArrayObject;t&&(e.createVertexArray=()=>t.createVertexArrayOES(),e.bindVertexArray=n=>t.bindVertexArrayOES(n),e.deleteVertexArray=n=>t.deleteVertexArrayOES(n));const r=this._renderer.context.extensions.vertexAttribDivisorANGLE;r&&(e.drawArraysInstanced=(n,o,c,l)=>{r.drawArraysInstancedANGLE(n,o,c,l)},e.drawElementsInstanced=(n,o,c,l,d)=>{r.drawElementsInstancedANGLE(n,o,c,l,d)},e.vertexAttribDivisor=(n,o)=>r.vertexAttribDivisorANGLE(n,o)),this._activeGeometry=null,this._activeVao=null,this._geometryVaoHash=Object.create(null)}bind(e,t){const r=this.gl;this._activeGeometry=e;const n=this.getVao(e,t);this._activeVao!==n&&(this._activeVao=n,r.bindVertexArray(n)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,t=this._renderer.buffer;for(let r=0;r<e.buffers.length;r++){const n=e.buffers[r];t.updateBuffer(n)}}checkCompatibility(e,t){const r=e.attributes,n=t._attributeData;for(const o in n)if(!r[o])throw new Error(`shader and geometry incompatible, geometry missing the "${o}" attribute`)}getSignature(e,t){const r=e.attributes,n=t._attributeData,o=["g",e.uid];for(const c in r)n[c]&&o.push(c,n[c].location);return o.join("-")}getVao(e,t){return this._geometryVaoHash[e.uid]?.[t._key]||this.initGeometryVao(e,t)}initGeometryVao(e,t,r=!0){const n=this._renderer.gl,o=this._renderer.buffer;this._renderer.shader._getProgramData(t),this.checkCompatibility(e,t);const c=this.getSignature(e,t);this._geometryVaoHash[e.uid]||(this._geometryVaoHash[e.uid]=Object.create(null),e.on("destroy",this.onGeometryDestroy,this));const l=this._geometryVaoHash[e.uid];let d=l[c];if(d)return l[t._key]=d,d;dh(e,t._attributeData);const f=e.buffers;d=n.createVertexArray(),n.bindVertexArray(d);for(let m=0;m<f.length;m++){const g=f[m];o.bind(g)}return this.activateVao(e,t),l[t._key]=d,l[c]=d,n.bindVertexArray(null),d}onGeometryDestroy(e,t){const r=this._geometryVaoHash[e.uid],n=this.gl;if(r){if(t)for(const o in r)this._activeVao!==r[o]&&this.unbind(),n.deleteVertexArray(r[o]);this._geometryVaoHash[e.uid]=null}}destroyAll(e=!1){const t=this.gl;for(const r in this._geometryVaoHash){if(e)for(const n in this._geometryVaoHash[r]){const o=this._geometryVaoHash[r];this._activeVao!==o&&this.unbind(),t.deleteVertexArray(o[n])}this._geometryVaoHash[r]=null}}activateVao(e,t){const r=this._renderer.gl,n=this._renderer.buffer,o=e.attributes;e.indexBuffer&&n.bind(e.indexBuffer);let c=null;for(const l in o){const d=o[l],f=d.buffer,m=n.getGlBuffer(f),g=t._attributeData[l];if(g){c!==m&&(n.bind(f),c=m);const _=g.location;r.enableVertexAttribArray(_);const y=Et(d.format),a=Zv(d.format);if(g.format?.substring(1,4)==="int"?r.vertexAttribIPointer(_,y.size,a,d.stride,d.offset):r.vertexAttribPointer(_,y.size,a,y.normalised,d.stride,d.offset),d.instance)if(this.hasInstance){const h=d.divisor??1;r.vertexAttribDivisor(_,h)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,t,r,n){const{gl:o}=this._renderer,c=this._activeGeometry,l=Jv[e||c.topology];if(n??(n=c.instanceCount),c.indexBuffer){const d=c.indexBuffer.data.BYTES_PER_ELEMENT,f=d===2?o.UNSIGNED_SHORT:o.UNSIGNED_INT;n!==1?o.drawElementsInstanced(l,t||c.indexBuffer.data.length,f,(r||0)*d,n):o.drawElements(l,t||c.indexBuffer.data.length,f,(r||0)*d)}else n!==1?o.drawArraysInstanced(l,r||0,t||c.getSize(),n):o.drawArrays(l,r||0,t||c.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null,this._geometryVaoHash={}}}mh.extension={type:[C.WebGLSystem],name:"geometry"};const Qv=new Vi({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),Qn=class wd{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:t,antialias:r}={...wd.defaultOptions,...e};this.useBackBuffer=t,this._antialias=r,this._renderer.context.supports.msaa||(G("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=it.for2d();const n=new vt({vertex:`
|
|
679
679
|
attribute vec2 aPosition;
|
|
680
680
|
out vec2 vUv;
|
|
681
681
|
|
|
@@ -838,7 +838,7 @@ fn mainFragment(
|
|
|
838
838
|
}
|
|
839
839
|
${n!==0?`arrayOffset += ${n};`:""}
|
|
840
840
|
}
|
|
841
|
-
`}function n_(s){return Th(s,"uboStd40",s_,wh)}class Sh extends xh{constructor(){super({createUboElements:i_,generateUboSync:n_})}}Sh.extension={type:[C.WebGLSystem],name:"ubo"};class o_{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new z}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new z}copyToTexture(e,t,r,n,o){const c=this._renderTargetSystem,l=this._renderer,d=c.getGpuRenderTarget(e),f=l.gl;return this.finishRenderPass(e),f.bindFramebuffer(f.FRAMEBUFFER,d.resolveTargetFramebuffer),l.texture.bind(t,0),f.copyTexSubImage2D(f.TEXTURE_2D,0,o.x,o.y,r.x,r.y,n.width,n.height),t}startRenderPass(e,t=!0,r,n){const o=this._renderTargetSystem,c=e.colorTexture,l=o.getGpuRenderTarget(e);let d=n.y;e.isRoot&&(d=c.pixelHeight-n.height),e.colorTextures.forEach(g=>{this._renderer.texture.unbind(g)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,l.framebuffer);const m=this._viewPortCache;(m.x!==n.x||m.y!==d||m.width!==n.width||m.height!==n.height)&&(m.x=n.x,m.y=d,m.width=n.width,m.height=n.height,f.viewport(n.x,d,n.width,n.height)),!l.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(l),this.clear(e,t,r)}finishRenderPass(e){const r=this._renderTargetSystem.getGpuRenderTarget(e);if(!r.msaa)return;const n=this._renderer.gl;n.bindFramebuffer(n.FRAMEBUFFER,r.resolveTargetFramebuffer),n.bindFramebuffer(n.READ_FRAMEBUFFER,r.framebuffer),n.blitFramebuffer(0,0,r.width,r.height,0,0,r.width,r.height,n.COLOR_BUFFER_BIT,n.NEAREST),n.bindFramebuffer(n.FRAMEBUFFER,r.framebuffer)}initGpuRenderTarget(e){const r=this._renderer.gl,n=new t_;return e.colorTexture instanceof mt?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),n.framebuffer=null,n):(this._initColor(e,n),r.bindFramebuffer(r.FRAMEBUFFER,null),n)}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(r=>{t.deleteRenderbuffer(r)}),e.msaaRenderBuffer=null}clear(e,t,r){if(!t)return;const n=this._renderTargetSystem;typeof t=="boolean"&&(t=t?ze.ALL:ze.NONE);const o=this._renderer.gl;if(t&ze.COLOR){r??(r=n.defaultClearColor);const c=this._clearColorCache,l=r;(c[0]!==l[0]||c[1]!==l[1]||c[2]!==l[2]||c[3]!==l[3])&&(c[0]=l[0],c[1]=l[1],c[2]=l[2],c[3]=l[3],o.clearColor(l[0],l[1],l[2],l[3]))}o.clear(t)}resizeGpuRenderTarget(e){if(e.isRoot)return;const r=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,r),(e.stencil||e.depth)&&this._resizeStencil(r)}_initColor(e,t){const r=this._renderer,n=r.gl,o=n.createFramebuffer();if(t.resolveTargetFramebuffer=o,n.bindFramebuffer(n.FRAMEBUFFER,o),t.width=e.colorTexture.source.pixelWidth,t.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((c,l)=>{const d=c.source;d.antialias&&(r.context.supports.msaa?t.msaa=!0:G("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),r.texture.bindSource(d,0);const m=r.texture.getGlSource(d).texture;n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+l,3553,m,0)}),t.msaa){const c=n.createFramebuffer();t.framebuffer=c,n.bindFramebuffer(n.FRAMEBUFFER,c),e.colorTextures.forEach((l,d)=>{const f=n.createRenderbuffer();t.msaaRenderBuffer[d]=f})}else t.framebuffer=o;this._resizeColor(e,t)}_resizeColor(e,t){const r=e.colorTexture.source;if(t.width=r.pixelWidth,t.height=r.pixelHeight,e.colorTextures.forEach((n,o)=>{o!==0&&n.source.resize(r.width,r.height,r._resolution)}),t.msaa){const n=this._renderer,o=n.gl,c=t.framebuffer;o.bindFramebuffer(o.FRAMEBUFFER,c),e.colorTextures.forEach((l,d)=>{const f=l.source;n.texture.bindSource(f,0);const g=n.texture.getGlSource(f).internalFormat,_=t.msaaRenderBuffer[d];o.bindRenderbuffer(o.RENDERBUFFER,_),o.renderbufferStorageMultisample(o.RENDERBUFFER,4,g,f.pixelWidth,f.pixelHeight),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+d,o.RENDERBUFFER,_)})}}_initStencil(e){if(e.framebuffer===null)return;const t=this._renderer.gl,r=t.createRenderbuffer();e.depthStencilRenderBuffer=r,t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,r),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){const t=e.colorTexture.resource;this._renderer.context.multiView&&mt.test(t)&&this._renderer.context.ensureCanvasSize(t)}postrender(e){if(this._renderer.context.multiView&&mt.test(e.colorTexture.resource)){const t=this._renderer.context.canvas,r=e.colorTexture;r.context2D.drawImage(t,0,r.pixelHeight-t.height)}}}function a_(s,e,t,r,n,o){const c=o?1:-1;return s.identity(),s.a=1/r*2,s.d=c*(1/n*2),s.tx=-1-e*s.a,s.ty=-c-t*s.d,s}const fi=new Map;ei.register(fi);function Ch(s,e){if(!fi.has(s)){const t=new F({source:new mt({resource:s,...e})}),r=()=>{fi.get(s)===t&&fi.delete(s)};t.once("destroy",r),t.source.once("destroy",r),fi.set(s,t)}return fi.get(s)}function l_(s){const e=s.colorTexture.source.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}const Ah=class Sd{constructor(e={}){if(this.uid=ae("renderTarget"),this.colorTextures=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,e={...Sd.defaultOptions,...e},this.stencil=e.stencil,this.depth=e.depth,this.isRoot=e.isRoot,typeof e.colorTextures=="number"){this._managedColorTextures=!0;for(let t=0;t<e.colorTextures;t++)this.colorTextures.push(new ge({width:e.width,height:e.height,resolution:e.resolution,antialias:e.antialias}))}else{this.colorTextures=[...e.colorTextures.map(r=>r.source)];const t=this.colorTexture.source;this.resize(t.width,t.height,t._resolution)}this.colorTexture.source.on("resize",this.onSourceResize,this),(e.depthStencilTexture||this.stencil)&&(e.depthStencilTexture instanceof F||e.depthStencilTexture instanceof ge?this.depthStencilTexture=e.depthStencilTexture.source:this.ensureDepthStencilTexture())}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.colorTexture.source.width}get height(){return this.colorTexture.source.height}get pixelWidth(){return this.colorTexture.source.pixelWidth}get pixelHeight(){return this.colorTexture.source.pixelHeight}get resolution(){return this.colorTexture.source._resolution}get colorTexture(){return this.colorTextures[0]}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this.depthStencilTexture||(this.depthStencilTexture=new ge({width:this.width,height:this.height,resolution:this.resolution,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1}))}resize(e,t,r=this.resolution,n=!1){this.dirtyId++,this.colorTextures.forEach((o,c)=>{n&&c===0||o.source.resize(e,t,r)}),this.depthStencilTexture&&this.depthStencilTexture.source.resize(e,t,r)}destroy(){this.colorTexture.source.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorTextures.forEach(e=>{e.destroy()}),this.depthStencilTexture&&(this.depthStencilTexture.destroy(),delete this.depthStencilTexture)}};Ah.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let eo=Ah;class Eh{constructor(e){this.rootViewPort=new z,this.viewport=new z,this.onRenderTargetChange=new Pl("onRenderTargetChange"),this.projectionMatrix=new B,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuRenderTargetHash")}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart({target:e,clear:t,clearColor:r,frame:n}){this._renderTargetStack.length=0,this.push(e,t,r,n),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=l_(this.rootRenderTarget),this.adaptor.prerender?.(this.rootRenderTarget)}postrender(){this.adaptor.postrender?.(this.rootRenderTarget)}bind(e,t=!0,r,n){const o=this.getRenderTarget(e),c=this.renderTarget!==o;this.renderTarget=o,this.renderSurface=e;const l=this.getGpuRenderTarget(o);(o.pixelWidth!==l.width||o.pixelHeight!==l.height)&&(this.adaptor.resizeGpuRenderTarget(o),l.width=o.pixelWidth,l.height=o.pixelHeight);const d=o.colorTexture,f=this.viewport,m=d.pixelWidth,g=d.pixelHeight;if(!n&&e instanceof F&&(n=e.frame),n){const _=d._resolution;f.x=n.x*_+.5|0,f.y=n.y*_+.5|0,f.width=n.width*_+.5|0,f.height=n.height*_+.5|0}else f.x=0,f.y=0,f.width=m,f.height=g;return a_(this.projectionMatrix,0,0,f.width/d.resolution,f.height/d.resolution,!o.isRoot),this.adaptor.startRenderPass(o,t,r,f),c&&this.onRenderTargetChange.emit(o),o}clear(e,t=ze.ALL,r){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,r,this.viewport))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=ze.ALL,r,n){const o=this.bind(e,t,r,n);return this._renderTargetStack.push({renderTarget:o,frame:n}),o}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];this.bind(e.renderTarget,!1,null,e.frame)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,r,n,o){r.x<0&&(n.width+=r.x,o.x-=r.x,r.x=0),r.y<0&&(n.height+=r.y,o.y-=r.y,r.y=0);const{pixelWidth:c,pixelHeight:l}=e;return n.width=Math.min(n.width,c-r.x),n.height=Math.min(n.height,l-r.y),this.adaptor.copyToTexture(e,t,r,n,o)}ensureDepthStencil(){this.renderTarget.stencil||(this.renderTarget.stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport))}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t&&e.destroy()}),this._renderSurfaceToRenderTargetHash.clear(),this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;return mt.test(e)&&(e=Ch(e).source),e instanceof eo?t=e:e instanceof ge&&(t=new eo({colorTextures:[e]}),e.source instanceof mt&&(t.isRoot=!0),e.once("destroy",()=>{t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e);const r=this._gpuRenderTargetHash[t.uid];r&&(this._gpuRenderTargetHash[t.uid]=null,this.adaptor.destroyGpuRenderTarget(r))})),this._renderSurfaceToRenderTargetHash.set(e,t),t}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this.renderSurface=null}}class Ih extends Eh{constructor(e){super(e),this.adaptor=new o_,this.adaptor.init(e,this)}}Ih.extension={type:[C.WebGLSystem],name:"renderTarget"};class to extends Ge{constructor({buffer:e,offset:t,size:r}){super(),this.uid=ae("buffer"),this._resourceType="bufferResource",this._touched=0,this._resourceId=ae("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=e,this.offset=t|0,this.size=r,this.buffer.on("change",this.onBufferChange,this)}onBufferChange(){this._resourceId=ae("resource"),this.emit("change",this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}function c_(s,e){const t=[],r=[`
|
|
841
|
+
`}function n_(s){return Th(s,"uboStd40",s_,wh)}class Sh extends xh{constructor(){super({createUboElements:i_,generateUboSync:n_})}}Sh.extension={type:[C.WebGLSystem],name:"ubo"};class o_{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new z}init(e,t){this._renderer=e,this._renderTargetSystem=t,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new z}copyToTexture(e,t,r,n,o){const c=this._renderTargetSystem,l=this._renderer,d=c.getGpuRenderTarget(e),f=l.gl;return this.finishRenderPass(e),f.bindFramebuffer(f.FRAMEBUFFER,d.resolveTargetFramebuffer),l.texture.bind(t,0),f.copyTexSubImage2D(f.TEXTURE_2D,0,o.x,o.y,r.x,r.y,n.width,n.height),t}startRenderPass(e,t=!0,r,n){const o=this._renderTargetSystem,c=e.colorTexture,l=o.getGpuRenderTarget(e);let d=n.y;e.isRoot&&(d=c.pixelHeight-n.height),e.colorTextures.forEach(g=>{this._renderer.texture.unbind(g)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,l.framebuffer);const m=this._viewPortCache;(m.x!==n.x||m.y!==d||m.width!==n.width||m.height!==n.height)&&(m.x=n.x,m.y=d,m.width=n.width,m.height=n.height,f.viewport(n.x,d,n.width,n.height)),!l.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(l),this.clear(e,t,r)}finishRenderPass(e){const r=this._renderTargetSystem.getGpuRenderTarget(e);if(!r.msaa)return;const n=this._renderer.gl;n.bindFramebuffer(n.FRAMEBUFFER,r.resolveTargetFramebuffer),n.bindFramebuffer(n.READ_FRAMEBUFFER,r.framebuffer),n.blitFramebuffer(0,0,r.width,r.height,0,0,r.width,r.height,n.COLOR_BUFFER_BIT,n.NEAREST),n.bindFramebuffer(n.FRAMEBUFFER,r.framebuffer)}initGpuRenderTarget(e){const r=this._renderer.gl,n=new t_;return e.colorTexture instanceof mt?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),n.framebuffer=null,n):(this._initColor(e,n),r.bindFramebuffer(r.FRAMEBUFFER,null),n)}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(r=>{t.deleteRenderbuffer(r)}),e.msaaRenderBuffer=null}clear(e,t,r){if(!t)return;const n=this._renderTargetSystem;typeof t=="boolean"&&(t=t?He.ALL:He.NONE);const o=this._renderer.gl;if(t&He.COLOR){r??(r=n.defaultClearColor);const c=this._clearColorCache,l=r;(c[0]!==l[0]||c[1]!==l[1]||c[2]!==l[2]||c[3]!==l[3])&&(c[0]=l[0],c[1]=l[1],c[2]=l[2],c[3]=l[3],o.clearColor(l[0],l[1],l[2],l[3]))}o.clear(t)}resizeGpuRenderTarget(e){if(e.isRoot)return;const r=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,r),(e.stencil||e.depth)&&this._resizeStencil(r)}_initColor(e,t){const r=this._renderer,n=r.gl,o=n.createFramebuffer();if(t.resolveTargetFramebuffer=o,n.bindFramebuffer(n.FRAMEBUFFER,o),t.width=e.colorTexture.source.pixelWidth,t.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((c,l)=>{const d=c.source;d.antialias&&(r.context.supports.msaa?t.msaa=!0:G("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),r.texture.bindSource(d,0);const m=r.texture.getGlSource(d).texture;n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0+l,3553,m,0)}),t.msaa){const c=n.createFramebuffer();t.framebuffer=c,n.bindFramebuffer(n.FRAMEBUFFER,c),e.colorTextures.forEach((l,d)=>{const f=n.createRenderbuffer();t.msaaRenderBuffer[d]=f})}else t.framebuffer=o;this._resizeColor(e,t)}_resizeColor(e,t){const r=e.colorTexture.source;if(t.width=r.pixelWidth,t.height=r.pixelHeight,e.colorTextures.forEach((n,o)=>{o!==0&&n.source.resize(r.width,r.height,r._resolution)}),t.msaa){const n=this._renderer,o=n.gl,c=t.framebuffer;o.bindFramebuffer(o.FRAMEBUFFER,c),e.colorTextures.forEach((l,d)=>{const f=l.source;n.texture.bindSource(f,0);const g=n.texture.getGlSource(f).internalFormat,_=t.msaaRenderBuffer[d];o.bindRenderbuffer(o.RENDERBUFFER,_),o.renderbufferStorageMultisample(o.RENDERBUFFER,4,g,f.pixelWidth,f.pixelHeight),o.framebufferRenderbuffer(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0+d,o.RENDERBUFFER,_)})}}_initStencil(e){if(e.framebuffer===null)return;const t=this._renderer.gl,r=t.createRenderbuffer();e.depthStencilRenderBuffer=r,t.bindRenderbuffer(t.RENDERBUFFER,r),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,r),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){const t=e.colorTexture.resource;this._renderer.context.multiView&&mt.test(t)&&this._renderer.context.ensureCanvasSize(t)}postrender(e){if(this._renderer.context.multiView&&mt.test(e.colorTexture.resource)){const t=this._renderer.context.canvas,r=e.colorTexture;r.context2D.drawImage(t,0,r.pixelHeight-t.height)}}}function a_(s,e,t,r,n,o){const c=o?1:-1;return s.identity(),s.a=1/r*2,s.d=c*(1/n*2),s.tx=-1-e*s.a,s.ty=-c-t*s.d,s}const fi=new Map;ei.register(fi);function Ch(s,e){if(!fi.has(s)){const t=new F({source:new mt({resource:s,...e})}),r=()=>{fi.get(s)===t&&fi.delete(s)};t.once("destroy",r),t.source.once("destroy",r),fi.set(s,t)}return fi.get(s)}function l_(s){const e=s.colorTexture.source.resource;return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement&&document.body.contains(e)}const Ah=class Sd{constructor(e={}){if(this.uid=ae("renderTarget"),this.colorTextures=[],this.dirtyId=0,this.isRoot=!1,this._size=new Float32Array(2),this._managedColorTextures=!1,e={...Sd.defaultOptions,...e},this.stencil=e.stencil,this.depth=e.depth,this.isRoot=e.isRoot,typeof e.colorTextures=="number"){this._managedColorTextures=!0;for(let t=0;t<e.colorTextures;t++)this.colorTextures.push(new ge({width:e.width,height:e.height,resolution:e.resolution,antialias:e.antialias}))}else{this.colorTextures=[...e.colorTextures.map(r=>r.source)];const t=this.colorTexture.source;this.resize(t.width,t.height,t._resolution)}this.colorTexture.source.on("resize",this.onSourceResize,this),(e.depthStencilTexture||this.stencil)&&(e.depthStencilTexture instanceof F||e.depthStencilTexture instanceof ge?this.depthStencilTexture=e.depthStencilTexture.source:this.ensureDepthStencilTexture())}get size(){const e=this._size;return e[0]=this.pixelWidth,e[1]=this.pixelHeight,e}get width(){return this.colorTexture.source.width}get height(){return this.colorTexture.source.height}get pixelWidth(){return this.colorTexture.source.pixelWidth}get pixelHeight(){return this.colorTexture.source.pixelHeight}get resolution(){return this.colorTexture.source._resolution}get colorTexture(){return this.colorTextures[0]}onSourceResize(e){this.resize(e.width,e.height,e._resolution,!0)}ensureDepthStencilTexture(){this.depthStencilTexture||(this.depthStencilTexture=new ge({width:this.width,height:this.height,resolution:this.resolution,format:"depth24plus-stencil8",autoGenerateMipmaps:!1,antialias:!1,mipLevelCount:1}))}resize(e,t,r=this.resolution,n=!1){this.dirtyId++,this.colorTextures.forEach((o,c)=>{n&&c===0||o.source.resize(e,t,r)}),this.depthStencilTexture&&this.depthStencilTexture.source.resize(e,t,r)}destroy(){this.colorTexture.source.off("resize",this.onSourceResize,this),this._managedColorTextures&&this.colorTextures.forEach(e=>{e.destroy()}),this.depthStencilTexture&&(this.depthStencilTexture.destroy(),delete this.depthStencilTexture)}};Ah.defaultOptions={width:0,height:0,resolution:1,colorTextures:1,stencil:!1,depth:!1,antialias:!1,isRoot:!1};let eo=Ah;class Eh{constructor(e){this.rootViewPort=new z,this.viewport=new z,this.onRenderTargetChange=new Pl("onRenderTargetChange"),this.projectionMatrix=new B,this.defaultClearColor=[0,0,0,0],this._renderSurfaceToRenderTargetHash=new Map,this._gpuRenderTargetHash=Object.create(null),this._renderTargetStack=[],this._renderer=e,e.renderableGC.addManagedHash(this,"_gpuRenderTargetHash")}finishRenderPass(){this.adaptor.finishRenderPass(this.renderTarget)}renderStart({target:e,clear:t,clearColor:r,frame:n}){this._renderTargetStack.length=0,this.push(e,t,r,n),this.rootViewPort.copyFrom(this.viewport),this.rootRenderTarget=this.renderTarget,this.renderingToScreen=l_(this.rootRenderTarget),this.adaptor.prerender?.(this.rootRenderTarget)}postrender(){this.adaptor.postrender?.(this.rootRenderTarget)}bind(e,t=!0,r,n){const o=this.getRenderTarget(e),c=this.renderTarget!==o;this.renderTarget=o,this.renderSurface=e;const l=this.getGpuRenderTarget(o);(o.pixelWidth!==l.width||o.pixelHeight!==l.height)&&(this.adaptor.resizeGpuRenderTarget(o),l.width=o.pixelWidth,l.height=o.pixelHeight);const d=o.colorTexture,f=this.viewport,m=d.pixelWidth,g=d.pixelHeight;if(!n&&e instanceof F&&(n=e.frame),n){const _=d._resolution;f.x=n.x*_+.5|0,f.y=n.y*_+.5|0,f.width=n.width*_+.5|0,f.height=n.height*_+.5|0}else f.x=0,f.y=0,f.width=m,f.height=g;return a_(this.projectionMatrix,0,0,f.width/d.resolution,f.height/d.resolution,!o.isRoot),this.adaptor.startRenderPass(o,t,r,f),c&&this.onRenderTargetChange.emit(o),o}clear(e,t=He.ALL,r){t&&(e&&(e=this.getRenderTarget(e)),this.adaptor.clear(e||this.renderTarget,t,r,this.viewport))}contextChange(){this._gpuRenderTargetHash=Object.create(null)}push(e,t=He.ALL,r,n){const o=this.bind(e,t,r,n);return this._renderTargetStack.push({renderTarget:o,frame:n}),o}pop(){this._renderTargetStack.pop();const e=this._renderTargetStack[this._renderTargetStack.length-1];this.bind(e.renderTarget,!1,null,e.frame)}getRenderTarget(e){return e.isTexture&&(e=e.source),this._renderSurfaceToRenderTargetHash.get(e)??this._initRenderTarget(e)}copyToTexture(e,t,r,n,o){r.x<0&&(n.width+=r.x,o.x-=r.x,r.x=0),r.y<0&&(n.height+=r.y,o.y-=r.y,r.y=0);const{pixelWidth:c,pixelHeight:l}=e;return n.width=Math.min(n.width,c-r.x),n.height=Math.min(n.height,l-r.y),this.adaptor.copyToTexture(e,t,r,n,o)}ensureDepthStencil(){this.renderTarget.stencil||(this.renderTarget.stencil=!0,this.adaptor.startRenderPass(this.renderTarget,!1,null,this.viewport))}destroy(){this._renderer=null,this._renderSurfaceToRenderTargetHash.forEach((e,t)=>{e!==t&&e.destroy()}),this._renderSurfaceToRenderTargetHash.clear(),this._gpuRenderTargetHash=Object.create(null)}_initRenderTarget(e){let t=null;return mt.test(e)&&(e=Ch(e).source),e instanceof eo?t=e:e instanceof ge&&(t=new eo({colorTextures:[e]}),e.source instanceof mt&&(t.isRoot=!0),e.once("destroy",()=>{t.destroy(),this._renderSurfaceToRenderTargetHash.delete(e);const r=this._gpuRenderTargetHash[t.uid];r&&(this._gpuRenderTargetHash[t.uid]=null,this.adaptor.destroyGpuRenderTarget(r))})),this._renderSurfaceToRenderTargetHash.set(e,t),t}getGpuRenderTarget(e){return this._gpuRenderTargetHash[e.uid]||(this._gpuRenderTargetHash[e.uid]=this.adaptor.initGpuRenderTarget(e))}resetState(){this.renderTarget=null,this.renderSurface=null}}class Ih extends Eh{constructor(e){super(e),this.adaptor=new o_,this.adaptor.init(e,this)}}Ih.extension={type:[C.WebGLSystem],name:"renderTarget"};class to extends Le{constructor({buffer:e,offset:t,size:r}){super(),this.uid=ae("buffer"),this._resourceType="bufferResource",this._touched=0,this._resourceId=ae("resource"),this._bufferResource=!0,this.destroyed=!1,this.buffer=e,this.offset=t|0,this.size=r,this.buffer.on("change",this.onBufferChange,this)}onBufferChange(){this._resourceId=ae("resource"),this.emit("change",this)}destroy(e=!1){this.destroyed=!0,e&&this.buffer.destroy(),this.emit("change",this),this.buffer=null,this.removeAllListeners()}}function c_(s,e){const t=[],r=[`
|
|
842
842
|
var g = s.groups;
|
|
843
843
|
var sS = r.shader;
|
|
844
844
|
var p = s.glProgram;
|
|
@@ -958,7 +958,7 @@ fn mainFragment(
|
|
|
958
958
|
cv = cu.value;
|
|
959
959
|
v = uv["${r}"];
|
|
960
960
|
${l};`)}}return new Function("ud","uv","renderer","syncData",t.join(`
|
|
961
|
-
`))}class Bh{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,t,r){const n=this._renderer.shader._getProgramData(t);(!e.isStatic||e._dirtyId!==n.uniformDirtyGroups[e.uid])&&(n.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,t)(n.uniformData,e.uniforms,this._renderer,r))}_getUniformSyncFunction(e,t){return this._uniformGroupSyncHash[e._signature]?.[t._key]||this._createUniformSyncFunction(e,t)}_createUniformSyncFunction(e,t){const r=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),n=this._getSignature(e,t._uniformData,"u");return this._cache[n]||(this._cache[n]=this._generateUniformsSync(e,t._uniformData)),r[t._key]=this._cache[n],r[t._key]}_generateUniformsSync(e,t){return x_(e,t)}_getSignature(e,t,r){const n=e.uniforms,o=[`${r}-`];for(const c in n)o.push(c),t[c]&&o.push(t[c].type);return o.join("-")}destroy(){this._renderer=null,this._cache=null}}Bh.extension={type:[C.WebGLSystem],name:"uniformGroup"};function b_(s){const e={};if(e.normal=[s.ONE,s.ONE_MINUS_SRC_ALPHA],e.add=[s.ONE,s.ONE],e.multiply=[s.DST_COLOR,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.screen=[s.ONE,s.ONE_MINUS_SRC_COLOR,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[s.SRC_ALPHA,s.ONE,s.ONE,s.ONE],e["screen-npm"]=[s.SRC_ALPHA,s.ONE_MINUS_SRC_COLOR,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.erase=[s.ZERO,s.ONE_MINUS_SRC_ALPHA],!(s instanceof V.get().getWebGLRenderingContext()))e.min=[s.ONE,s.ONE,s.ONE,s.ONE,s.MIN,s.MIN],e.max=[s.ONE,s.ONE,s.ONE,s.ONE,s.MAX,s.MAX];else{const r=s.getExtension("EXT_blend_minmax");r&&(e.min=[s.ONE,s.ONE,s.ONE,s.ONE,r.MIN_EXT,r.MIN_EXT],e.max=[s.ONE,s.ONE,s.ONE,s.ONE,r.MAX_EXT,r.MAX_EXT])}return e}const T_=0,w_=1,S_=2,C_=3,A_=4,E_=5,Dh=class Do{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[T_]=this.setBlend,this.map[w_]=this.setOffset,this.map[S_]=this.setCullFace,this.map[C_]=this.setDepthTest,this.map[A_]=this.setFrontFace,this.map[E_]=this.setDepthMask,this.checks=[],this.defaultState=it.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=b_(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let t=this.stateId^e.data,r=0;for(;t;)t&1&&this.map[r].call(this,!!(e.data&1<<r)),t>>=1,r++;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(Do._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(Do._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)}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],r=this.gl;t.length===2?r.blendFunc(t[0],t[1]):r.blendFuncSeparate(t[0],t[1],t[2],t[3]),t.length===6?(this._blendEq=!0,r.blendEquationSeparate(t[4],t[5])):this._blendEq&&(this._blendEq=!1,r.blendEquationSeparate(r.FUNC_ADD,r.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 r=this.checks.indexOf(e);t&&r===-1?this.checks.push(e):!t&&r!==-1&&this.checks.splice(r,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}};Dh.extension={type:[C.WebGLSystem],name:"state"};let I_=Dh;class P_{constructor(e){this.target=fh.TEXTURE_2D,this.texture=e,this.width=-1,this.height=-1,this.type=Z.UNSIGNED_BYTE,this.internalFormat=Jn.RGBA,this.format=Jn.RGBA,this.samplerType=0}}const R_={id:"buffer",upload(s,e,t){e.width===s.width||e.height===s.height?t.texSubImage2D(t.TEXTURE_2D,0,0,0,s.width,s.height,e.format,e.type,s.resource):t.texImage2D(e.target,0,e.internalFormat,s.width,s.height,0,e.format,e.type,s.resource),e.width=s.width,e.height=s.height}},M_={"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},F_={id:"compressed",upload(s,e,t){t.pixelStorei(t.UNPACK_ALIGNMENT,4);let r=s.pixelWidth,n=s.pixelHeight;const o=!!M_[s.format];for(let c=0;c<s.resource.length;c++){const l=s.resource[c];o?t.compressedTexImage2D(t.TEXTURE_2D,c,e.internalFormat,r,n,0,l):t.texImage2D(t.TEXTURE_2D,c,e.internalFormat,r,n,0,e.format,e.type,l),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}}},Oh={id:"image",upload(s,e,t,r){const n=e.width,o=e.height,c=s.pixelWidth,l=s.pixelHeight,d=s.resourceWidth,f=s.resourceHeight;d<c||f<l?((n!==c||o!==l)&&t.texImage2D(e.target,0,e.internalFormat,c,l,0,e.format,e.type,null),r===2?t.texSubImage2D(t.TEXTURE_2D,0,0,0,d,f,e.format,e.type,s.resource):t.texSubImage2D(t.TEXTURE_2D,0,0,0,e.format,e.type,s.resource)):n===c&&o===l?t.texSubImage2D(t.TEXTURE_2D,0,0,0,e.format,e.type,s.resource):r===2?t.texImage2D(e.target,0,e.internalFormat,c,l,0,e.format,e.type,s.resource):t.texImage2D(e.target,0,e.internalFormat,e.format,e.type,s.resource),e.width=c,e.height=l}},U_={id:"video",upload(s,e,t,r){if(!s.isValid){t.texImage2D(e.target,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Oh.upload(s,e,t,r)}},Gh={linear:9729,nearest:9728},k_={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},ro={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},B_={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Lh(s,e,t,r,n,o,c,l){const d=o;if(!l||s.addressModeU!=="repeat"||s.addressModeV!=="repeat"||s.addressModeW!=="repeat"){const f=ro[c?"clamp-to-edge":s.addressModeU],m=ro[c?"clamp-to-edge":s.addressModeV],g=ro[c?"clamp-to-edge":s.addressModeW];e[n](d,e.TEXTURE_WRAP_S,f),e[n](d,e.TEXTURE_WRAP_T,m),e.TEXTURE_WRAP_R&&e[n](d,e.TEXTURE_WRAP_R,g)}if((!l||s.magFilter!=="linear")&&e[n](d,e.TEXTURE_MAG_FILTER,Gh[s.magFilter]),t){if(!l||s.mipmapFilter!=="linear"){const f=k_[s.minFilter][s.mipmapFilter];e[n](d,e.TEXTURE_MIN_FILTER,f)}}else e[n](d,e.TEXTURE_MIN_FILTER,Gh[s.minFilter]);if(r&&s.maxAnisotropy>1){const f=Math.min(s.maxAnisotropy,e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[n](d,r.TEXTURE_MAX_ANISOTROPY_EXT,f)}s.compare&&e[n](d,e.TEXTURE_COMPARE_FUNC,B_[s.compare])}function D_(s){return{r8unorm:s.RED,r8snorm:s.RED,r8uint:s.RED,r8sint:s.RED,r16uint:s.RED,r16sint:s.RED,r16float:s.RED,rg8unorm:s.RG,rg8snorm:s.RG,rg8uint:s.RG,rg8sint:s.RG,r32uint:s.RED,r32sint:s.RED,r32float:s.RED,rg16uint:s.RG,rg16sint:s.RG,rg16float:s.RG,rgba8unorm:s.RGBA,"rgba8unorm-srgb":s.RGBA,rgba8snorm:s.RGBA,rgba8uint:s.RGBA,rgba8sint:s.RGBA,bgra8unorm:s.RGBA,"bgra8unorm-srgb":s.RGBA,rgb9e5ufloat:s.RGB,rgb10a2unorm:s.RGBA,rg11b10ufloat:s.RGB,rg32uint:s.RG,rg32sint:s.RG,rg32float:s.RG,rgba16uint:s.RGBA,rgba16sint:s.RGBA,rgba16float:s.RGBA,rgba32uint:s.RGBA,rgba32sint:s.RGBA,rgba32float:s.RGBA,stencil8:s.STENCIL_INDEX8,depth16unorm:s.DEPTH_COMPONENT,depth24plus:s.DEPTH_COMPONENT,"depth24plus-stencil8":s.DEPTH_STENCIL,depth32float:s.DEPTH_COMPONENT,"depth32float-stencil8":s.DEPTH_STENCIL}}function O_(s,e){let t={},r=s.RGBA;return s instanceof V.get().getWebGLRenderingContext()?e.srgb&&(t={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(t={"rgba8unorm-srgb":s.SRGB8_ALPHA8,"bgra8unorm-srgb":s.SRGB8_ALPHA8},r=s.RGBA8),{r8unorm:s.R8,r8snorm:s.R8_SNORM,r8uint:s.R8UI,r8sint:s.R8I,r16uint:s.R16UI,r16sint:s.R16I,r16float:s.R16F,rg8unorm:s.RG8,rg8snorm:s.RG8_SNORM,rg8uint:s.RG8UI,rg8sint:s.RG8I,r32uint:s.R32UI,r32sint:s.R32I,r32float:s.R32F,rg16uint:s.RG16UI,rg16sint:s.RG16I,rg16float:s.RG16F,rgba8unorm:s.RGBA,...t,rgba8snorm:s.RGBA8_SNORM,rgba8uint:s.RGBA8UI,rgba8sint:s.RGBA8I,bgra8unorm:r,rgb9e5ufloat:s.RGB9_E5,rgb10a2unorm:s.RGB10_A2,rg11b10ufloat:s.R11F_G11F_B10F,rg32uint:s.RG32UI,rg32sint:s.RG32I,rg32float:s.RG32F,rgba16uint:s.RGBA16UI,rgba16sint:s.RGBA16I,rgba16float:s.RGBA16F,rgba32uint:s.RGBA32UI,rgba32sint:s.RGBA32I,rgba32float:s.RGBA32F,stencil8:s.STENCIL_INDEX8,depth16unorm:s.DEPTH_COMPONENT16,depth24plus:s.DEPTH_COMPONENT24,"depth24plus-stencil8":s.DEPTH24_STENCIL8,depth32float:s.DEPTH_COMPONENT32F,"depth32float-stencil8":s.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 G_(s){return{r8unorm:s.UNSIGNED_BYTE,r8snorm:s.BYTE,r8uint:s.UNSIGNED_BYTE,r8sint:s.BYTE,r16uint:s.UNSIGNED_SHORT,r16sint:s.SHORT,r16float:s.HALF_FLOAT,rg8unorm:s.UNSIGNED_BYTE,rg8snorm:s.BYTE,rg8uint:s.UNSIGNED_BYTE,rg8sint:s.BYTE,r32uint:s.UNSIGNED_INT,r32sint:s.INT,r32float:s.FLOAT,rg16uint:s.UNSIGNED_SHORT,rg16sint:s.SHORT,rg16float:s.HALF_FLOAT,rgba8unorm:s.UNSIGNED_BYTE,"rgba8unorm-srgb":s.UNSIGNED_BYTE,rgba8snorm:s.BYTE,rgba8uint:s.UNSIGNED_BYTE,rgba8sint:s.BYTE,bgra8unorm:s.UNSIGNED_BYTE,"bgra8unorm-srgb":s.UNSIGNED_BYTE,rgb9e5ufloat:s.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:s.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:s.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:s.UNSIGNED_INT,rg32sint:s.INT,rg32float:s.FLOAT,rgba16uint:s.UNSIGNED_SHORT,rgba16sint:s.SHORT,rgba16float:s.HALF_FLOAT,rgba32uint:s.UNSIGNED_INT,rgba32sint:s.INT,rgba32float:s.FLOAT,stencil8:s.UNSIGNED_BYTE,depth16unorm:s.UNSIGNED_SHORT,depth24plus:s.UNSIGNED_INT,"depth24plus-stencil8":s.UNSIGNED_INT_24_8,depth32float:s.FLOAT,"depth32float-stencil8":s.FLOAT_32_UNSIGNED_INT_24_8_REV}}const L_=4;class Nh{constructor(e){this.managedTextures=[],this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._uploads={image:Oh,buffer:R_,video:U_,compressed:F_},this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_glTextures"),this._renderer.renderableGC.addManagedHash(this,"_glSamplers")}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=O_(e,this._renderer.context.extensions),this._mapFormatToType=G_(e),this._mapFormatToFormat=D_(e)),this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let t=0;t<16;t++)this.bind(F.EMPTY,t)}initSource(e){this.bind(e)}bind(e,t=0){const r=e.source;e?(this.bindSource(r,t),this._useSeparateSamplers&&this._bindSampler(r.style,t)):(this.bindSource(null,t),this._useSeparateSamplers&&this._bindSampler(null,t))}bindSource(e,t=0){const r=this._gl;if(e._touched=this._renderer.textureGC.count,this._boundTextures[t]!==e){this._boundTextures[t]=e,this._activateLocation(t),e||(e=F.EMPTY.source);const n=this.getGlSource(e);r.bindTexture(n.target,n.texture)}}_bindSampler(e,t=0){const r=this._gl;if(!e){this._boundSamplers[t]=null,r.bindSampler(t,null);return}const n=this._getGlSampler(e);this._boundSamplers[t]!==n&&(this._boundSamplers[t]=n,r.bindSampler(t,n))}unbind(e){const t=e.source,r=this._boundTextures,n=this._gl;for(let o=0;o<r.length;o++)if(r[o]===t){this._activateLocation(o);const c=this.getGlSource(t);n.bindTexture(c.target,null),r[o]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const t=this._gl,r=new P_(t.createTexture());if(r.type=this._mapFormatToType[e.format],r.internalFormat=this._mapFormatToInternalFormat[e.format],r.format=this._mapFormatToFormat[e.format],e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const n=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(n))+1}return this._glTextures[e.uid]=r,this.managedTextures.includes(e)||(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("destroy",this.onSourceDestroy,this),e.on("unload",this.onSourceUnload,this),e.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(e)),this.onSourceUpdate(e),this.updateStyle(e,!1),r}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,t){const r=this._gl,n=this.getGlSource(e);r.bindTexture(r.TEXTURE_2D,n.texture),this._boundTextures[this._activeTextureLocation]=e,Lh(e.style,r,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",r.TEXTURE_2D,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,t)}onSourceUnload(e){const t=this._glTextures[e.uid];t&&(this.unbind(e),this._glTextures[e.uid]=null,this._gl.deleteTexture(t.texture))}onSourceUpdate(e){const t=this._gl,r=this.getGlSource(e);t.bindTexture(t.TEXTURE_2D,r.texture),this._boundTextures[this._activeTextureLocation]=e;const n=e.alphaMode==="premultiply-alpha-on-upload";this._premultiplyAlpha!==n&&(this._premultiplyAlpha=n,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n)),this._uploads[e.uploadMethodId]?this._uploads[e.uploadMethodId].upload(e,r,t,this._renderer.context.webGLVersion):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.pixelWidth,e.pixelHeight,0,t.RGBA,t.UNSIGNED_BYTE,null),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,t=!0){t&&this.bindSource(e,0);const r=this.getGlSource(e);this._gl.generateMipmap(r.target)}onSourceDestroy(e){e.off("destroy",this.onSourceDestroy,this),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("unload",this.onSourceUnload,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(e),1),this.onSourceUnload(e)}_initSampler(e){const t=this._gl,r=this._gl.createSampler();return this._glSamplers[e._resourceId]=r,Lh(e,t,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",r,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return this._glTextures[e.uid]||this._initSource(e)}generateCanvas(e){const{pixels:t,width:r,height:n}=this.getPixels(e),o=V.get().createCanvas();o.width=r,o.height=n;const c=o.getContext("2d");if(c){const l=c.createImageData(r,n);l.data.set(t),c.putImageData(l,0,0)}return o}getPixels(e){const t=e.source.resolution,r=e.frame,n=Math.max(Math.round(r.width*t),1),o=Math.max(Math.round(r.height*t),1),c=new Uint8Array(L_*n*o),l=this._renderer,d=l.renderTarget.getRenderTarget(e),f=l.renderTarget.getGpuRenderTarget(d),m=l.gl;return m.bindFramebuffer(m.FRAMEBUFFER,f.resolveTargetFramebuffer),m.readPixels(Math.round(r.x*t),Math.round(r.y*t),n,o,m.RGBA,m.UNSIGNED_BYTE,c),{pixels:new Uint8ClampedArray(c.buffer),width:n,height:o}}destroy(){this.managedTextures.slice().forEach(e=>this.onSourceDestroy(e)),this.managedTextures=null,this._glTextures=null,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(){this._activeTextureLocation=-1,this._boundTextures.fill(F.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Nh.extension={type:[C.WebGLSystem],name:"texture"};class zh{contextChange(e){const t=new Ue({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new B,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),r=e.limits.maxBatchableTextures,n=Xi({name:"graphics",bits:[wn,En(r),jn,qi]});this.shader=new qe({glProgram:n,resources:{localUniforms:t,batchSamplers:In(r)}})}execute(e,t){const r=t.context,n=r.customShader||this.shader,o=e.renderer,c=o.graphicsContext,{batcher:l,instructions:d}=c.getContextRenderData(r);n.groups[0]=o.globalUniforms.bindGroup,o.state.set(e.state),o.shader.bind(n),o.geometry.bind(l.geometry,n.glProgram);const f=d.instructions;for(let m=0;m<d.instructionSize;m++){const g=f[m];if(g.size){for(let _=0;_<g.textures.count;_++)o.texture.bind(g.textures.textures[_],_);o.geometry.draw(g.topology,g.size,g.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}zh.extension={type:[C.WebGLPipesAdaptor],name:"graphics"};class Hh{init(){const e=Xi({name:"mesh",bits:[jn,Yv,qi]});this._shader=new qe({glProgram:e,resources:{uTexture:F.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new B}}}})}execute(e,t){const r=e.renderer;let n=t._shader;if(n){if(!n.glProgram){G("Mesh shader has no glProgram",t.shader);return}}else{n=this._shader;const o=t.texture,c=o.source;n.resources.uTexture=c,n.resources.uSampler=c.style,n.resources.textureUniforms.uniforms.uTextureMatrix=o.textureMatrix.mapCoord}n.groups[100]=r.globalUniforms.bindGroup,n.groups[101]=e.localUniformsBindGroup,r.encoder.draw({geometry:t._geometry,shader:n,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Hh.extension={type:[C.WebGLPipesAdaptor],name:"mesh"};class Wh{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}}Wh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"customRender"};class ns{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(){}}function so(s,e){const t=s.instructionSet,r=t.instructions;for(let n=0;n<t.instructionSize;n++){const o=r[n];e[o.renderPipeId].execute(o)}}const N_=new B;class Vh{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&&(me.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const r=e._batchableRenderGroup??(e._batchableRenderGroup=me.get(ns));r.renderable=e.root,r.transform=e.root.relativeGroupTransform,r.texture=e.texture,r.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(r,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=N_.identity().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push(e.texture,!0,null,e.texture.frame),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),so(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}),so(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Vh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"renderGroup"};function no(s,e){e||(e=0);for(let t=e;t<s.length&&s[t];t++)s[t]=null}const z_=new se,Yh=Ei|Rr|Vs;function Xh(s,e=!1){H_(s);const t=s.childrenToUpdate,r=s.updateTick++;for(const n in t){const o=Number(n),c=t[n],l=c.list,d=c.index;for(let f=0;f<d;f++){const m=l[f];m.parentRenderGroup===s&&m.relativeRenderGroupDepth===o&&$h(m,r,0)}no(l,d),c.index=0}if(e)for(let n=0;n<s.renderGroupChildren.length;n++)Xh(s.renderGroupChildren[n],e)}function H_(s){const e=s.root;let t;if(s.renderGroupParent){const r=s.renderGroupParent;s.worldTransform.appendFrom(e.relativeGroupTransform,r.worldTransform),s.worldColor=Ar(e.groupColor,r.worldColor),t=e.groupAlpha*r.worldAlpha}else s.worldTransform.copyFrom(e.localTransform),s.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,s.worldAlpha=t,s.worldColorAlpha=s.worldColor+((t*255|0)<<24)}function $h(s,e,t){if(e===s.updateTick)return;s.updateTick=e,s.didChange=!1;const r=s.localTransform;s.updateLocalTransform();const n=s.parent;if(n&&!n.renderGroup?(t|=s._updateFlags,s.relativeGroupTransform.appendFrom(r,n.relativeGroupTransform),t&Yh&&qh(s,n,t)):(t=s._updateFlags,s.relativeGroupTransform.copyFrom(r),t&Yh&&qh(s,z_,t)),!s.renderGroup){const o=s.children,c=o.length;for(let f=0;f<c;f++)$h(o[f],e,t);const l=s.parentRenderGroup,d=s;d.renderPipeId&&!l.structureDidChange&&l.updateRenderable(d)}}function qh(s,e,t){if(t&Rr){s.groupColor=Ar(s.localColor,e.groupColor);let r=s.localAlpha*e.groupAlpha;r=r<0?0:r>1?1:r,s.groupAlpha=r,s.groupColorAlpha=s.groupColor+((r*255|0)<<24)}t&Vs&&(s.groupBlendMode=s.localBlendMode==="inherit"?e.groupBlendMode:s.localBlendMode),t&Ei&&(s.globalDisplayStatus=s.localDisplayStatus&e.globalDisplayStatus),s._updateFlags=0}function W_(s,e){const{list:t}=s.childrenRenderablesToUpdate;let r=!1;for(let n=0;n<s.childrenRenderablesToUpdate.index;n++){const o=t[n];if(r=e[o.renderPipeId].validateRenderable(o),r)break}return s.structureDidChange=r,r}const V_=new B;class Kh{constructor(e){this._renderer=e}render({container:e,transform:t}){const r=e.parent,n=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const o=this._renderer,c=V_;t&&(c.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const l=o.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),o.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),so(e.renderGroup,l),l.uniformBatch&&l.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(c),e.parent=r,e.renderGroup.renderGroupParent=n}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let r=e.renderGroupChildren.length-1;r>=0;r--)this._updateCachedRenderGroups(e.renderGroupChildren[r],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const r=e.root.getLocalBounds();r.ceil();const n=e.texture;e.texture&&Te.returnTexture(e.texture,!0);const o=this._renderer,c=e.textureOptions.resolution||o.view.resolution,l=e.textureOptions.antialias??o.view.antialias,d=e.textureOptions.scaleMode??"linear",f=Te.getOptimalTexture(r.width,r.height,c,l);f._source.style=new at({scaleMode:d}),e.texture=f,e._textureBounds||(e._textureBounds=new Se),e._textureBounds.copyFrom(r),n!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(Te.returnTexture(e.texture,!0),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,r=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=r,e.structureDidChange?no(e.childrenRenderablesToUpdate.list,0):W_(e,r),Xh(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 n=0;n<e.renderGroupChildren.length;n++)this._updateRenderGroups(e.renderGroupChildren[n])}_updateRenderables(e){const{list:t,index:r}=e.childrenRenderablesToUpdate;for(let n=0;n<r;n++){const o=t[n];o.didViewUpdate&&e.updateRenderable(o)}no(t,r)}_buildInstructions(e,t){const r=e.root,n=e.instructionSet;n.reset();const o=t.renderPipes?t:t.batch.renderer,c=o.renderPipes;c.batch.buildStart(n),c.blendMode.buildStart(),c.colorMask.buildStart(),r.sortableChildren&&r.sortChildren(),r.collectRenderablesWithEffects(n,o,null),c.batch.buildEnd(n),c.blendMode.buildEnd(n)}}Kh.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"renderGroup"};class jh{constructor(e){this._renderer=e}addRenderable(e,t){const r=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,r),this._renderer.renderPipes.batch.addToBatch(r,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 ns;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}}jh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"sprite"};const oo=class Cd{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new le(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...Cd.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&&G("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(){}};oo.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"background",priority:0},oo.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let Y_=oo;const sr={};L.handle(C.BlendMode,s=>{if(!s.name)throw new Error("BlendMode extension must have a name property");sr[s.name]=s.ref},s=>{delete sr[s.name]});class Zh{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,r){this._blendModeStack.push(t),this.setBlendMode(e,t,r)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,r){const n=e instanceof zs;if(this._activeBlendMode===t){this._isAdvanced&&e&&!n&&this._renderableList?.push(e);return}this._isAdvanced&&this._endAdvancedBlendMode(r),this._activeBlendMode=t,e&&(this._isAdvanced=!!sr[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,r))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const r=this._activeBlendMode;if(!sr[r]){G(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const n=this._ensureFilterEffect(r),o=e instanceof zs,c={renderPipeId:"filter",action:"pushFilter",filterEffect:n,renderables:o?null:[e],container:o?e.root:null,canBundle:!1};this._renderableList=c.renderables,t.add(c)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new Cr,t.filters=[new sr[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}}Zh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"blendMode"};const ao={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},lo=class Ad{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof se||e instanceof F?{target:e,...t}:{...t,...e}}async image(e){const t=V.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Ad.defaultImageOptions);const{format:t,quality:r}=e,n=this.canvas(e);if(n.toBlob!==void 0)return new Promise((o,c)=>{n.toBlob(l=>{if(!l){c(new Error("ICanvas.toBlob failed!"));return}const d=new FileReader;d.onload=()=>o(d.result),d.onerror=c,d.readAsDataURL(l)},ao[t],r)});if(n.toDataURL!==void 0)return n.toDataURL(ao[t],r);if(n.convertToBlob!==void 0){const o=await n.convertToBlob({type:ao[t],quality:r});return new Promise((c,l)=>{const d=new FileReader;d.onload=()=>c(d.result),d.onerror=l,d.readAsDataURL(o)})}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,r=this._renderer;if(t instanceof F)return r.texture.generateCanvas(t);const n=r.textureGenerator.generateTexture(e),o=r.texture.generateCanvas(n);return n.destroy(!0),o}pixels(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer,n=t instanceof F?t:r.textureGenerator.generateTexture(e),o=r.texture.getPixels(n);return t instanceof se&&n.destroy(!0),o}texture(e){return e=this._normalizeOptions(e),e.target instanceof F?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),r=document.createElement("a");r.download=e.filename??"image.png",r.href=t.toDataURL("image/png"),document.body.appendChild(r),r.click(),document.body.removeChild(r)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const r=this.canvas(e),n=r.toDataURL();console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);const o=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${n}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",o)}destroy(){this._renderer=null}};lo.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"extract"},lo.defaultImageOptions={format:"png",quality:1};let X_=lo;class Ae extends F{static create(e){return new Ae({source:new ge(e)})}resize(e,t,r){return this.source.resize(e,t,r),this}}const $_=new z,q_=new Se,K_=[0,0,0,0];class Jh{constructor(e){this._renderer=e}generateTexture(e){e instanceof se&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,r=e.antialias||this._renderer.view.antialias,n=e.target;let o=e.clearColor;o?o=Array.isArray(o)&&o.length===4?o:le.shared.setValue(o).toArray():o=K_;const c=e.frame?.copyTo($_)||Ns(n,q_).rectangle;c.width=Math.max(c.width,1/t)|0,c.height=Math.max(c.height,1/t)|0;const l=Ae.create({...e.textureSourceOptions,width:c.width,height:c.height,resolution:t,antialias:r}),d=B.shared.translate(-c.x,-c.y);return this._renderer.render({container:n,transform:d,target:l,clearColor:o}),l.source.updateMipmaps(),l}destroy(){this._renderer=null}}Jh.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"textureGenerator"};function nr(s,e,t){const r=(s>>24&255)/255;e[t++]=(s&255)/255*r,e[t++]=(s>>8&255)/255*r,e[t++]=(s>>16&255)/255*r,e[t++]=r}class Qh{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:r,worldColor:n,offset:o}){const c=this._renderer.renderTarget.renderTarget,l=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new B,worldColor:4294967295,offset:new J},d={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||c.size,worldTransformMatrix:r||l.worldTransformMatrix,worldColor:n||l.worldColor,offset:o||l.offset,bindGroup:null},f=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(f);const m=f.uniforms;m.uProjectionMatrix=d.projectionMatrix,m.uResolution=d.resolution,m.uWorldTransformMatrix.copyFrom(d.worldTransformMatrix),m.uWorldTransformMatrix.tx-=d.offset.x,m.uWorldTransformMatrix.ty-=d.offset.y,nr(d.worldColor,m.uWorldColorAlpha,0),f.update();let g;this._renderer.renderPipes.uniformBatch?g=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(f,!1):(g=this._bindGroupPool.pop()||new _t,this._activeBindGroups.push(g),g.setResource(f,0)),d.bindGroup=g,this._currentGlobalUniformData=d}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===tt.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 Ue({uProjectionMatrix:{value:new B,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new B,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}}Qh.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"globalUniforms"};let j_=1;class eu{constructor(){this._tasks=[],this._offset=0}init(){Le.system.add(this._update,this)}repeat(e,t,r=!0){const n=j_++;let o=0;return r&&(this._offset+=1e3,o=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:o,last:performance.now(),repeat:!0,id:n}),n}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 r=this._tasks[t];if(e-r.offset-r.last>=r.duration){const n=e-r.start;r.func(n),r.last=e}}}destroy(){Le.system.remove(this._update,this),this._tasks.length=0}}eu.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"scheduler",priority:0};let tu=!1;function Z_(s){if(!tu){if(V.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${Hr} (${s}) http://www.pixijs.com/
|
|
961
|
+
`))}class Bh{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,t,r){const n=this._renderer.shader._getProgramData(t);(!e.isStatic||e._dirtyId!==n.uniformDirtyGroups[e.uid])&&(n.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,t)(n.uniformData,e.uniforms,this._renderer,r))}_getUniformSyncFunction(e,t){return this._uniformGroupSyncHash[e._signature]?.[t._key]||this._createUniformSyncFunction(e,t)}_createUniformSyncFunction(e,t){const r=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),n=this._getSignature(e,t._uniformData,"u");return this._cache[n]||(this._cache[n]=this._generateUniformsSync(e,t._uniformData)),r[t._key]=this._cache[n],r[t._key]}_generateUniformsSync(e,t){return x_(e,t)}_getSignature(e,t,r){const n=e.uniforms,o=[`${r}-`];for(const c in n)o.push(c),t[c]&&o.push(t[c].type);return o.join("-")}destroy(){this._renderer=null,this._cache=null}}Bh.extension={type:[C.WebGLSystem],name:"uniformGroup"};function b_(s){const e={};if(e.normal=[s.ONE,s.ONE_MINUS_SRC_ALPHA],e.add=[s.ONE,s.ONE],e.multiply=[s.DST_COLOR,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.screen=[s.ONE,s.ONE_MINUS_SRC_COLOR,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA,s.ONE,s.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[s.SRC_ALPHA,s.ONE,s.ONE,s.ONE],e["screen-npm"]=[s.SRC_ALPHA,s.ONE_MINUS_SRC_COLOR,s.ONE,s.ONE_MINUS_SRC_ALPHA],e.erase=[s.ZERO,s.ONE_MINUS_SRC_ALPHA],!(s instanceof V.get().getWebGLRenderingContext()))e.min=[s.ONE,s.ONE,s.ONE,s.ONE,s.MIN,s.MIN],e.max=[s.ONE,s.ONE,s.ONE,s.ONE,s.MAX,s.MAX];else{const r=s.getExtension("EXT_blend_minmax");r&&(e.min=[s.ONE,s.ONE,s.ONE,s.ONE,r.MIN_EXT,r.MIN_EXT],e.max=[s.ONE,s.ONE,s.ONE,s.ONE,r.MAX_EXT,r.MAX_EXT])}return e}const T_=0,w_=1,S_=2,C_=3,A_=4,E_=5,Dh=class Do{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[T_]=this.setBlend,this.map[w_]=this.setOffset,this.map[S_]=this.setCullFace,this.map[C_]=this.setDepthTest,this.map[A_]=this.setFrontFace,this.map[E_]=this.setDepthMask,this.checks=[],this.defaultState=it.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=b_(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let t=this.stateId^e.data,r=0;for(;t;)t&1&&this.map[r].call(this,!!(e.data&1<<r)),t>>=1,r++;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(Do._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(Do._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)}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],r=this.gl;t.length===2?r.blendFunc(t[0],t[1]):r.blendFuncSeparate(t[0],t[1],t[2],t[3]),t.length===6?(this._blendEq=!0,r.blendEquationSeparate(t[4],t[5])):this._blendEq&&(this._blendEq=!1,r.blendEquationSeparate(r.FUNC_ADD,r.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 r=this.checks.indexOf(e);t&&r===-1?this.checks.push(e):!t&&r!==-1&&this.checks.splice(r,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}};Dh.extension={type:[C.WebGLSystem],name:"state"};let I_=Dh;class P_{constructor(e){this.target=fh.TEXTURE_2D,this.texture=e,this.width=-1,this.height=-1,this.type=Z.UNSIGNED_BYTE,this.internalFormat=Jn.RGBA,this.format=Jn.RGBA,this.samplerType=0}}const R_={id:"buffer",upload(s,e,t){e.width===s.width||e.height===s.height?t.texSubImage2D(t.TEXTURE_2D,0,0,0,s.width,s.height,e.format,e.type,s.resource):t.texImage2D(e.target,0,e.internalFormat,s.width,s.height,0,e.format,e.type,s.resource),e.width=s.width,e.height=s.height}},M_={"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},F_={id:"compressed",upload(s,e,t){t.pixelStorei(t.UNPACK_ALIGNMENT,4);let r=s.pixelWidth,n=s.pixelHeight;const o=!!M_[s.format];for(let c=0;c<s.resource.length;c++){const l=s.resource[c];o?t.compressedTexImage2D(t.TEXTURE_2D,c,e.internalFormat,r,n,0,l):t.texImage2D(t.TEXTURE_2D,c,e.internalFormat,r,n,0,e.format,e.type,l),r=Math.max(r>>1,1),n=Math.max(n>>1,1)}}},Oh={id:"image",upload(s,e,t,r){const n=e.width,o=e.height,c=s.pixelWidth,l=s.pixelHeight,d=s.resourceWidth,f=s.resourceHeight;d<c||f<l?((n!==c||o!==l)&&t.texImage2D(e.target,0,e.internalFormat,c,l,0,e.format,e.type,null),r===2?t.texSubImage2D(t.TEXTURE_2D,0,0,0,d,f,e.format,e.type,s.resource):t.texSubImage2D(t.TEXTURE_2D,0,0,0,e.format,e.type,s.resource)):n===c&&o===l?t.texSubImage2D(t.TEXTURE_2D,0,0,0,e.format,e.type,s.resource):r===2?t.texImage2D(e.target,0,e.internalFormat,c,l,0,e.format,e.type,s.resource):t.texImage2D(e.target,0,e.internalFormat,e.format,e.type,s.resource),e.width=c,e.height=l}},U_={id:"video",upload(s,e,t,r){if(!s.isValid){t.texImage2D(e.target,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Oh.upload(s,e,t,r)}},Gh={linear:9729,nearest:9728},k_={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},ro={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},B_={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Lh(s,e,t,r,n,o,c,l){const d=o;if(!l||s.addressModeU!=="repeat"||s.addressModeV!=="repeat"||s.addressModeW!=="repeat"){const f=ro[c?"clamp-to-edge":s.addressModeU],m=ro[c?"clamp-to-edge":s.addressModeV],g=ro[c?"clamp-to-edge":s.addressModeW];e[n](d,e.TEXTURE_WRAP_S,f),e[n](d,e.TEXTURE_WRAP_T,m),e.TEXTURE_WRAP_R&&e[n](d,e.TEXTURE_WRAP_R,g)}if((!l||s.magFilter!=="linear")&&e[n](d,e.TEXTURE_MAG_FILTER,Gh[s.magFilter]),t){if(!l||s.mipmapFilter!=="linear"){const f=k_[s.minFilter][s.mipmapFilter];e[n](d,e.TEXTURE_MIN_FILTER,f)}}else e[n](d,e.TEXTURE_MIN_FILTER,Gh[s.minFilter]);if(r&&s.maxAnisotropy>1){const f=Math.min(s.maxAnisotropy,e.getParameter(r.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[n](d,r.TEXTURE_MAX_ANISOTROPY_EXT,f)}s.compare&&e[n](d,e.TEXTURE_COMPARE_FUNC,B_[s.compare])}function D_(s){return{r8unorm:s.RED,r8snorm:s.RED,r8uint:s.RED,r8sint:s.RED,r16uint:s.RED,r16sint:s.RED,r16float:s.RED,rg8unorm:s.RG,rg8snorm:s.RG,rg8uint:s.RG,rg8sint:s.RG,r32uint:s.RED,r32sint:s.RED,r32float:s.RED,rg16uint:s.RG,rg16sint:s.RG,rg16float:s.RG,rgba8unorm:s.RGBA,"rgba8unorm-srgb":s.RGBA,rgba8snorm:s.RGBA,rgba8uint:s.RGBA,rgba8sint:s.RGBA,bgra8unorm:s.RGBA,"bgra8unorm-srgb":s.RGBA,rgb9e5ufloat:s.RGB,rgb10a2unorm:s.RGBA,rg11b10ufloat:s.RGB,rg32uint:s.RG,rg32sint:s.RG,rg32float:s.RG,rgba16uint:s.RGBA,rgba16sint:s.RGBA,rgba16float:s.RGBA,rgba32uint:s.RGBA,rgba32sint:s.RGBA,rgba32float:s.RGBA,stencil8:s.STENCIL_INDEX8,depth16unorm:s.DEPTH_COMPONENT,depth24plus:s.DEPTH_COMPONENT,"depth24plus-stencil8":s.DEPTH_STENCIL,depth32float:s.DEPTH_COMPONENT,"depth32float-stencil8":s.DEPTH_STENCIL}}function O_(s,e){let t={},r=s.RGBA;return s instanceof V.get().getWebGLRenderingContext()?e.srgb&&(t={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(t={"rgba8unorm-srgb":s.SRGB8_ALPHA8,"bgra8unorm-srgb":s.SRGB8_ALPHA8},r=s.RGBA8),{r8unorm:s.R8,r8snorm:s.R8_SNORM,r8uint:s.R8UI,r8sint:s.R8I,r16uint:s.R16UI,r16sint:s.R16I,r16float:s.R16F,rg8unorm:s.RG8,rg8snorm:s.RG8_SNORM,rg8uint:s.RG8UI,rg8sint:s.RG8I,r32uint:s.R32UI,r32sint:s.R32I,r32float:s.R32F,rg16uint:s.RG16UI,rg16sint:s.RG16I,rg16float:s.RG16F,rgba8unorm:s.RGBA,...t,rgba8snorm:s.RGBA8_SNORM,rgba8uint:s.RGBA8UI,rgba8sint:s.RGBA8I,bgra8unorm:r,rgb9e5ufloat:s.RGB9_E5,rgb10a2unorm:s.RGB10_A2,rg11b10ufloat:s.R11F_G11F_B10F,rg32uint:s.RG32UI,rg32sint:s.RG32I,rg32float:s.RG32F,rgba16uint:s.RGBA16UI,rgba16sint:s.RGBA16I,rgba16float:s.RGBA16F,rgba32uint:s.RGBA32UI,rgba32sint:s.RGBA32I,rgba32float:s.RGBA32F,stencil8:s.STENCIL_INDEX8,depth16unorm:s.DEPTH_COMPONENT16,depth24plus:s.DEPTH_COMPONENT24,"depth24plus-stencil8":s.DEPTH24_STENCIL8,depth32float:s.DEPTH_COMPONENT32F,"depth32float-stencil8":s.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 G_(s){return{r8unorm:s.UNSIGNED_BYTE,r8snorm:s.BYTE,r8uint:s.UNSIGNED_BYTE,r8sint:s.BYTE,r16uint:s.UNSIGNED_SHORT,r16sint:s.SHORT,r16float:s.HALF_FLOAT,rg8unorm:s.UNSIGNED_BYTE,rg8snorm:s.BYTE,rg8uint:s.UNSIGNED_BYTE,rg8sint:s.BYTE,r32uint:s.UNSIGNED_INT,r32sint:s.INT,r32float:s.FLOAT,rg16uint:s.UNSIGNED_SHORT,rg16sint:s.SHORT,rg16float:s.HALF_FLOAT,rgba8unorm:s.UNSIGNED_BYTE,"rgba8unorm-srgb":s.UNSIGNED_BYTE,rgba8snorm:s.BYTE,rgba8uint:s.UNSIGNED_BYTE,rgba8sint:s.BYTE,bgra8unorm:s.UNSIGNED_BYTE,"bgra8unorm-srgb":s.UNSIGNED_BYTE,rgb9e5ufloat:s.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:s.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:s.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:s.UNSIGNED_INT,rg32sint:s.INT,rg32float:s.FLOAT,rgba16uint:s.UNSIGNED_SHORT,rgba16sint:s.SHORT,rgba16float:s.HALF_FLOAT,rgba32uint:s.UNSIGNED_INT,rgba32sint:s.INT,rgba32float:s.FLOAT,stencil8:s.UNSIGNED_BYTE,depth16unorm:s.UNSIGNED_SHORT,depth24plus:s.UNSIGNED_INT,"depth24plus-stencil8":s.UNSIGNED_INT_24_8,depth32float:s.FLOAT,"depth32float-stencil8":s.FLOAT_32_UNSIGNED_INT_24_8_REV}}const L_=4;class Nh{constructor(e){this.managedTextures=[],this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._uploads={image:Oh,buffer:R_,video:U_,compressed:F_},this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_glTextures"),this._renderer.renderableGC.addManagedHash(this,"_glSamplers")}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=O_(e,this._renderer.context.extensions),this._mapFormatToType=G_(e),this._mapFormatToFormat=D_(e)),this._glTextures=Object.create(null),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let t=0;t<16;t++)this.bind(F.EMPTY,t)}initSource(e){this.bind(e)}bind(e,t=0){const r=e.source;e?(this.bindSource(r,t),this._useSeparateSamplers&&this._bindSampler(r.style,t)):(this.bindSource(null,t),this._useSeparateSamplers&&this._bindSampler(null,t))}bindSource(e,t=0){const r=this._gl;if(e._touched=this._renderer.textureGC.count,this._boundTextures[t]!==e){this._boundTextures[t]=e,this._activateLocation(t),e||(e=F.EMPTY.source);const n=this.getGlSource(e);r.bindTexture(n.target,n.texture)}}_bindSampler(e,t=0){const r=this._gl;if(!e){this._boundSamplers[t]=null,r.bindSampler(t,null);return}const n=this._getGlSampler(e);this._boundSamplers[t]!==n&&(this._boundSamplers[t]=n,r.bindSampler(t,n))}unbind(e){const t=e.source,r=this._boundTextures,n=this._gl;for(let o=0;o<r.length;o++)if(r[o]===t){this._activateLocation(o);const c=this.getGlSource(t);n.bindTexture(c.target,null),r[o]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const t=this._gl,r=new P_(t.createTexture());if(r.type=this._mapFormatToType[e.format],r.internalFormat=this._mapFormatToInternalFormat[e.format],r.format=this._mapFormatToFormat[e.format],e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const n=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(n))+1}return this._glTextures[e.uid]=r,this.managedTextures.includes(e)||(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("destroy",this.onSourceDestroy,this),e.on("unload",this.onSourceUnload,this),e.on("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.push(e)),this.onSourceUpdate(e),this.updateStyle(e,!1),r}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,t){const r=this._gl,n=this.getGlSource(e);r.bindTexture(r.TEXTURE_2D,n.texture),this._boundTextures[this._activeTextureLocation]=e,Lh(e.style,r,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",r.TEXTURE_2D,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,t)}onSourceUnload(e){const t=this._glTextures[e.uid];t&&(this.unbind(e),this._glTextures[e.uid]=null,this._gl.deleteTexture(t.texture))}onSourceUpdate(e){const t=this._gl,r=this.getGlSource(e);t.bindTexture(t.TEXTURE_2D,r.texture),this._boundTextures[this._activeTextureLocation]=e;const n=e.alphaMode==="premultiply-alpha-on-upload";this._premultiplyAlpha!==n&&(this._premultiplyAlpha=n,t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,n)),this._uploads[e.uploadMethodId]?this._uploads[e.uploadMethodId].upload(e,r,t,this._renderer.context.webGLVersion):t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e.pixelWidth,e.pixelHeight,0,t.RGBA,t.UNSIGNED_BYTE,null),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,t=!0){t&&this.bindSource(e,0);const r=this.getGlSource(e);this._gl.generateMipmap(r.target)}onSourceDestroy(e){e.off("destroy",this.onSourceDestroy,this),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("unload",this.onSourceUnload,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this),this.managedTextures.splice(this.managedTextures.indexOf(e),1),this.onSourceUnload(e)}_initSampler(e){const t=this._gl,r=this._gl.createSampler();return this._glSamplers[e._resourceId]=r,Lh(e,t,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",r,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return this._glTextures[e.uid]||this._initSource(e)}generateCanvas(e){const{pixels:t,width:r,height:n}=this.getPixels(e),o=V.get().createCanvas();o.width=r,o.height=n;const c=o.getContext("2d");if(c){const l=c.createImageData(r,n);l.data.set(t),c.putImageData(l,0,0)}return o}getPixels(e){const t=e.source.resolution,r=e.frame,n=Math.max(Math.round(r.width*t),1),o=Math.max(Math.round(r.height*t),1),c=new Uint8Array(L_*n*o),l=this._renderer,d=l.renderTarget.getRenderTarget(e),f=l.renderTarget.getGpuRenderTarget(d),m=l.gl;return m.bindFramebuffer(m.FRAMEBUFFER,f.resolveTargetFramebuffer),m.readPixels(Math.round(r.x*t),Math.round(r.y*t),n,o,m.RGBA,m.UNSIGNED_BYTE,c),{pixels:new Uint8ClampedArray(c.buffer),width:n,height:o}}destroy(){this.managedTextures.slice().forEach(e=>this.onSourceDestroy(e)),this.managedTextures=null,this._glTextures=null,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(){this._activeTextureLocation=-1,this._boundTextures.fill(F.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Nh.extension={type:[C.WebGLSystem],name:"texture"};class zh{contextChange(e){const t=new Ue({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new B,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),r=e.limits.maxBatchableTextures,n=Xi({name:"graphics",bits:[wn,En(r),jn,qi]});this.shader=new qe({glProgram:n,resources:{localUniforms:t,batchSamplers:In(r)}})}execute(e,t){const r=t.context,n=r.customShader||this.shader,o=e.renderer,c=o.graphicsContext,{batcher:l,instructions:d}=c.getContextRenderData(r);n.groups[0]=o.globalUniforms.bindGroup,o.state.set(e.state),o.shader.bind(n),o.geometry.bind(l.geometry,n.glProgram);const f=d.instructions;for(let m=0;m<d.instructionSize;m++){const g=f[m];if(g.size){for(let _=0;_<g.textures.count;_++)o.texture.bind(g.textures.textures[_],_);o.geometry.draw(g.topology,g.size,g.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}zh.extension={type:[C.WebGLPipesAdaptor],name:"graphics"};class Hh{init(){const e=Xi({name:"mesh",bits:[jn,Yv,qi]});this._shader=new qe({glProgram:e,resources:{uTexture:F.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new B}}}})}execute(e,t){const r=e.renderer;let n=t._shader;if(n){if(!n.glProgram){G("Mesh shader has no glProgram",t.shader);return}}else{n=this._shader;const o=t.texture,c=o.source;n.resources.uTexture=c,n.resources.uSampler=c.style,n.resources.textureUniforms.uniforms.uTextureMatrix=o.textureMatrix.mapCoord}n.groups[100]=r.globalUniforms.bindGroup,n.groups[101]=e.localUniformsBindGroup,r.encoder.draw({geometry:t._geometry,shader:n,state:t.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Hh.extension={type:[C.WebGLPipesAdaptor],name:"mesh"};class Wh{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}}Wh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"customRender"};class ns{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(){}}function so(s,e){const t=s.instructionSet,r=t.instructions;for(let n=0;n<t.instructionSize;n++){const o=r[n];e[o.renderPipeId].execute(o)}}const N_=new B;class Vh{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&&(me.return(e._batchableRenderGroup),e._batchableRenderGroup=null),t.add(e)}_addRenderableCacheAsTexture(e,t){const r=e._batchableRenderGroup??(e._batchableRenderGroup=me.get(ns));r.renderable=e.root,r.transform=e.root.relativeGroupTransform,r.texture=e.texture,r.bounds=e._textureBounds,t.add(e),this._renderer.renderPipes.blendMode.pushBlendMode(e,e.root.groupBlendMode,t),this._renderer.renderPipes.batch.addToBatch(r,t),this._renderer.renderPipes.blendMode.popBlendMode(t)}_executeCacheAsTexture(e){if(e.textureNeedsUpdate){e.textureNeedsUpdate=!1;const t=N_.identity().translate(-e._textureBounds.x,-e._textureBounds.y);this._renderer.renderTarget.push(e.texture,!0,null,e.texture.frame),this._renderer.globalUniforms.push({worldTransformMatrix:t,worldColor:4294967295,offset:{x:0,y:0}}),so(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}),so(e,this._renderer.renderPipes),this._renderer.globalUniforms.pop()}}Vh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"renderGroup"};function no(s,e){e||(e=0);for(let t=e;t<s.length&&s[t];t++)s[t]=null}const z_=new se,Yh=Ei|Rr|Vs;function Xh(s,e=!1){H_(s);const t=s.childrenToUpdate,r=s.updateTick++;for(const n in t){const o=Number(n),c=t[n],l=c.list,d=c.index;for(let f=0;f<d;f++){const m=l[f];m.parentRenderGroup===s&&m.relativeRenderGroupDepth===o&&$h(m,r,0)}no(l,d),c.index=0}if(e)for(let n=0;n<s.renderGroupChildren.length;n++)Xh(s.renderGroupChildren[n],e)}function H_(s){const e=s.root;let t;if(s.renderGroupParent){const r=s.renderGroupParent;s.worldTransform.appendFrom(e.relativeGroupTransform,r.worldTransform),s.worldColor=Ar(e.groupColor,r.worldColor),t=e.groupAlpha*r.worldAlpha}else s.worldTransform.copyFrom(e.localTransform),s.worldColor=e.localColor,t=e.localAlpha;t=t<0?0:t>1?1:t,s.worldAlpha=t,s.worldColorAlpha=s.worldColor+((t*255|0)<<24)}function $h(s,e,t){if(e===s.updateTick)return;s.updateTick=e,s.didChange=!1;const r=s.localTransform;s.updateLocalTransform();const n=s.parent;if(n&&!n.renderGroup?(t|=s._updateFlags,s.relativeGroupTransform.appendFrom(r,n.relativeGroupTransform),t&Yh&&qh(s,n,t)):(t=s._updateFlags,s.relativeGroupTransform.copyFrom(r),t&Yh&&qh(s,z_,t)),!s.renderGroup){const o=s.children,c=o.length;for(let f=0;f<c;f++)$h(o[f],e,t);const l=s.parentRenderGroup,d=s;d.renderPipeId&&!l.structureDidChange&&l.updateRenderable(d)}}function qh(s,e,t){if(t&Rr){s.groupColor=Ar(s.localColor,e.groupColor);let r=s.localAlpha*e.groupAlpha;r=r<0?0:r>1?1:r,s.groupAlpha=r,s.groupColorAlpha=s.groupColor+((r*255|0)<<24)}t&Vs&&(s.groupBlendMode=s.localBlendMode==="inherit"?e.groupBlendMode:s.localBlendMode),t&Ei&&(s.globalDisplayStatus=s.localDisplayStatus&e.globalDisplayStatus),s._updateFlags=0}function W_(s,e){const{list:t}=s.childrenRenderablesToUpdate;let r=!1;for(let n=0;n<s.childrenRenderablesToUpdate.index;n++){const o=t[n];if(r=e[o.renderPipeId].validateRenderable(o),r)break}return s.structureDidChange=r,r}const V_=new B;class Kh{constructor(e){this._renderer=e}render({container:e,transform:t}){const r=e.parent,n=e.renderGroup.renderGroupParent;e.parent=null,e.renderGroup.renderGroupParent=null;const o=this._renderer,c=V_;t&&(c.copyFrom(e.renderGroup.localTransform),e.renderGroup.localTransform.copyFrom(t));const l=o.renderPipes;this._updateCachedRenderGroups(e.renderGroup,null),this._updateRenderGroups(e.renderGroup),o.globalUniforms.start({worldTransformMatrix:t?e.renderGroup.localTransform:e.renderGroup.worldTransform,worldColor:e.renderGroup.worldColorAlpha}),so(e.renderGroup,l),l.uniformBatch&&l.uniformBatch.renderEnd(),t&&e.renderGroup.localTransform.copyFrom(c),e.parent=r,e.renderGroup.renderGroupParent=n}destroy(){this._renderer=null}_updateCachedRenderGroups(e,t){if(e._parentCacheAsTextureRenderGroup=t,e.isCachedAsTexture){if(!e.textureNeedsUpdate)return;t=e}for(let r=e.renderGroupChildren.length-1;r>=0;r--)this._updateCachedRenderGroups(e.renderGroupChildren[r],t);if(e.invalidateMatrices(),e.isCachedAsTexture){if(e.textureNeedsUpdate){const r=e.root.getLocalBounds();r.ceil();const n=e.texture;e.texture&&Te.returnTexture(e.texture,!0);const o=this._renderer,c=e.textureOptions.resolution||o.view.resolution,l=e.textureOptions.antialias??o.view.antialias,d=e.textureOptions.scaleMode??"linear",f=Te.getOptimalTexture(r.width,r.height,c,l);f._source.style=new at({scaleMode:d}),e.texture=f,e._textureBounds||(e._textureBounds=new Se),e._textureBounds.copyFrom(r),n!==e.texture&&e.renderGroupParent&&(e.renderGroupParent.structureDidChange=!0)}}else e.texture&&(Te.returnTexture(e.texture,!0),e.texture=null)}_updateRenderGroups(e){const t=this._renderer,r=t.renderPipes;if(e.runOnRender(t),e.instructionSet.renderPipes=r,e.structureDidChange?no(e.childrenRenderablesToUpdate.list,0):W_(e,r),Xh(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 n=0;n<e.renderGroupChildren.length;n++)this._updateRenderGroups(e.renderGroupChildren[n])}_updateRenderables(e){const{list:t,index:r}=e.childrenRenderablesToUpdate;for(let n=0;n<r;n++){const o=t[n];o.didViewUpdate&&e.updateRenderable(o)}no(t,r)}_buildInstructions(e,t){const r=e.root,n=e.instructionSet;n.reset();const o=t.renderPipes?t:t.batch.renderer,c=o.renderPipes;c.batch.buildStart(n),c.blendMode.buildStart(),c.colorMask.buildStart(),r.sortableChildren&&r.sortChildren(),r.collectRenderablesWithEffects(n,o,null),c.batch.buildEnd(n),c.blendMode.buildEnd(n)}}Kh.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"renderGroup"};class jh{constructor(e){this._renderer=e}addRenderable(e,t){const r=this._getGpuSprite(e);e.didViewUpdate&&this._updateBatchableSprite(e,r),this._renderer.renderPipes.batch.addToBatch(r,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 ns;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}}jh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"sprite"};const oo=class Cd{constructor(){this.clearBeforeRender=!0,this._backgroundColor=new le(0),this.color=this._backgroundColor,this.alpha=1}init(e){e={...Cd.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&&G("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(){}};oo.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"background",priority:0},oo.defaultOptions={backgroundAlpha:1,backgroundColor:0,clearBeforeRender:!0};let Y_=oo;const sr={};L.handle(C.BlendMode,s=>{if(!s.name)throw new Error("BlendMode extension must have a name property");sr[s.name]=s.ref},s=>{delete sr[s.name]});class Zh{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,r){this._blendModeStack.push(t),this.setBlendMode(e,t,r)}popBlendMode(e){this._blendModeStack.pop();const t=this._blendModeStack[this._activeBlendMode.length-1]??"normal";this.setBlendMode(null,t,e)}setBlendMode(e,t,r){const n=e instanceof zs;if(this._activeBlendMode===t){this._isAdvanced&&e&&!n&&this._renderableList?.push(e);return}this._isAdvanced&&this._endAdvancedBlendMode(r),this._activeBlendMode=t,e&&(this._isAdvanced=!!sr[t],this._isAdvanced&&this._beginAdvancedBlendMode(e,r))}_beginAdvancedBlendMode(e,t){this._renderer.renderPipes.batch.break(t);const r=this._activeBlendMode;if(!sr[r]){G(`Unable to assign BlendMode: '${r}'. You may want to include: import 'pixi.js/advanced-blend-modes'`);return}const n=this._ensureFilterEffect(r),o=e instanceof zs,c={renderPipeId:"filter",action:"pushFilter",filterEffect:n,renderables:o?null:[e],container:o?e.root:null,canBundle:!1};this._renderableList=c.renderables,t.add(c)}_ensureFilterEffect(e){let t=this._filterHash[e];return t||(t=this._filterHash[e]=new Cr,t.filters=[new sr[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}}Zh.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"blendMode"};const ao={png:"image/png",jpg:"image/jpeg",webp:"image/webp"},lo=class Ad{constructor(e){this._renderer=e}_normalizeOptions(e,t={}){return e instanceof se||e instanceof F?{target:e,...t}:{...t,...e}}async image(e){const t=V.get().createImage();return t.src=await this.base64(e),t}async base64(e){e=this._normalizeOptions(e,Ad.defaultImageOptions);const{format:t,quality:r}=e,n=this.canvas(e);if(n.toBlob!==void 0)return new Promise((o,c)=>{n.toBlob(l=>{if(!l){c(new Error("ICanvas.toBlob failed!"));return}const d=new FileReader;d.onload=()=>o(d.result),d.onerror=c,d.readAsDataURL(l)},ao[t],r)});if(n.toDataURL!==void 0)return n.toDataURL(ao[t],r);if(n.convertToBlob!==void 0){const o=await n.convertToBlob({type:ao[t],quality:r});return new Promise((c,l)=>{const d=new FileReader;d.onload=()=>c(d.result),d.onerror=l,d.readAsDataURL(o)})}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,r=this._renderer;if(t instanceof F)return r.texture.generateCanvas(t);const n=r.textureGenerator.generateTexture(e),o=r.texture.generateCanvas(n);return n.destroy(!0),o}pixels(e){e=this._normalizeOptions(e);const t=e.target,r=this._renderer,n=t instanceof F?t:r.textureGenerator.generateTexture(e),o=r.texture.getPixels(n);return t instanceof se&&n.destroy(!0),o}texture(e){return e=this._normalizeOptions(e),e.target instanceof F?e.target:this._renderer.textureGenerator.generateTexture(e)}download(e){e=this._normalizeOptions(e);const t=this.canvas(e),r=document.createElement("a");r.download=e.filename??"image.png",r.href=t.toDataURL("image/png"),document.body.appendChild(r),r.click(),document.body.removeChild(r)}log(e){const t=e.width??200;e=this._normalizeOptions(e);const r=this.canvas(e),n=r.toDataURL();console.log(`[Pixi Texture] ${r.width}px ${r.height}px`);const o=["font-size: 1px;",`padding: ${t}px 300px;`,`background: url(${n}) no-repeat;`,"background-size: contain;"].join(" ");console.log("%c ",o)}destroy(){this._renderer=null}};lo.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"extract"},lo.defaultImageOptions={format:"png",quality:1};let X_=lo;class Ae extends F{static create(e){return new Ae({source:new ge(e)})}resize(e,t,r){return this.source.resize(e,t,r),this}}const $_=new z,q_=new Se,K_=[0,0,0,0];class Jh{constructor(e){this._renderer=e}generateTexture(e){e instanceof se&&(e={target:e,frame:void 0,textureSourceOptions:{},resolution:void 0});const t=e.resolution||this._renderer.resolution,r=e.antialias||this._renderer.view.antialias,n=e.target;let o=e.clearColor;o?o=Array.isArray(o)&&o.length===4?o:le.shared.setValue(o).toArray():o=K_;const c=e.frame?.copyTo($_)||Ns(n,q_).rectangle;c.width=Math.max(c.width,1/t)|0,c.height=Math.max(c.height,1/t)|0;const l=Ae.create({...e.textureSourceOptions,width:c.width,height:c.height,resolution:t,antialias:r}),d=B.shared.translate(-c.x,-c.y);return this._renderer.render({container:n,transform:d,target:l,clearColor:o}),l.source.updateMipmaps(),l}destroy(){this._renderer=null}}Jh.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"textureGenerator"};function nr(s,e,t){const r=(s>>24&255)/255;e[t++]=(s&255)/255*r,e[t++]=(s>>8&255)/255*r,e[t++]=(s>>16&255)/255*r,e[t++]=r}class Qh{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:r,worldColor:n,offset:o}){const c=this._renderer.renderTarget.renderTarget,l=this._stackIndex?this._globalUniformDataStack[this._stackIndex-1]:{worldTransformMatrix:new B,worldColor:4294967295,offset:new J},d={projectionMatrix:t||this._renderer.renderTarget.projectionMatrix,resolution:e||c.size,worldTransformMatrix:r||l.worldTransformMatrix,worldColor:n||l.worldColor,offset:o||l.offset,bindGroup:null},f=this._uniformsPool.pop()||this._createUniforms();this._activeUniforms.push(f);const m=f.uniforms;m.uProjectionMatrix=d.projectionMatrix,m.uResolution=d.resolution,m.uWorldTransformMatrix.copyFrom(d.worldTransformMatrix),m.uWorldTransformMatrix.tx-=d.offset.x,m.uWorldTransformMatrix.ty-=d.offset.y,nr(d.worldColor,m.uWorldColorAlpha,0),f.update();let g;this._renderer.renderPipes.uniformBatch?g=this._renderer.renderPipes.uniformBatch.getUniformBindGroup(f,!1):(g=this._bindGroupPool.pop()||new _t,this._activeBindGroups.push(g),g.setResource(f,0)),d.bindGroup=g,this._currentGlobalUniformData=d}push(e){this.bind(e),this._globalUniformDataStack[this._stackIndex++]=this._currentGlobalUniformData}pop(){this._currentGlobalUniformData=this._globalUniformDataStack[--this._stackIndex-1],this._renderer.type===tt.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 Ue({uProjectionMatrix:{value:new B,type:"mat3x3<f32>"},uWorldTransformMatrix:{value:new B,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}}Qh.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"globalUniforms"};let j_=1;class eu{constructor(){this._tasks=[],this._offset=0}init(){Ne.system.add(this._update,this)}repeat(e,t,r=!0){const n=j_++;let o=0;return r&&(this._offset+=1e3,o=this._offset),this._tasks.push({func:e,duration:t,start:performance.now(),offset:o,last:performance.now(),repeat:!0,id:n}),n}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 r=this._tasks[t];if(e-r.offset-r.last>=r.duration){const n=e-r.start;r.func(n),r.last=e}}}destroy(){Ne.system.remove(this._update,this),this._tasks.length=0}}eu.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"scheduler",priority:0};let tu=!1;function Z_(s){if(!tu){if(V.get().getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){const e=[`%c %c %c %c %c PixiJS %c v${Hr} (${s}) http://www.pixijs.com/
|
|
962
962
|
|
|
963
963
|
`,"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 ${Hr} - ${s} - http://www.pixijs.com/`);tu=!0}}class co{constructor(e){this._renderer=e}init(e){if(e.hello){let t=this._renderer.name;this._renderer.type===tt.WEBGL&&(t+=` ${this._renderer.context.webGLVersion}`),Z_(t)}}}co.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"hello",priority:-2},co.defaultOptions={hello:!1};function J_(s){let e=!1;for(const r in s)if(s[r]==null){e=!0;break}if(!e)return s;const t=Object.create(null);for(const r in s){const n=s[r];n&&(t[r]=n)}return t}function Q_(s){let e=0;for(let t=0;t<s.length;t++)s[t]==null?e++:s[t-e]=s[t];return s.length-=e,s}let ey=0;const ho=class Ed{constructor(e){this._managedRenderables=[],this._managedHashes=[],this._managedArrays=[],this._renderer=e}init(e){e={...Ed.defaultOptions,...e},this.maxUnusedTime=e.renderableGCMaxUnusedTime,this._frequency=e.renderableGCFrequency,this.enabled=e.renderableGCActive}get enabled(){return!!this._handler}set enabled(e){this.enabled!==e&&(e?(this._handler=this._renderer.scheduler.repeat(()=>this.run(),this._frequency,!1),this._hashHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedHashes)t.context[t.hash]=J_(t.context[t.hash])},this._frequency),this._arrayHandler=this._renderer.scheduler.repeat(()=>{for(const t of this._managedArrays)Q_(t.context[t.hash])},this._frequency)):(this._renderer.scheduler.cancel(this._handler),this._renderer.scheduler.cancel(this._hashHandler),this._renderer.scheduler.cancel(this._arrayHandler)))}addManagedHash(e,t){this._managedHashes.push({context:e,hash:t})}addManagedArray(e,t){this._managedArrays.push({context:e,hash:t})}prerender({container:e}){this._now=performance.now(),e.renderGroup.gcTick=ey++,this._updateInstructionGCTick(e.renderGroup,e.renderGroup.gcTick)}addRenderable(e){this.enabled&&(e._lastUsed===-1&&(this._managedRenderables.push(e),e.once("destroyed",this._removeRenderable,this)),e._lastUsed=this._now)}run(){const e=this._now,t=this._managedRenderables,r=this._renderer.renderPipes;let n=0;for(let o=0;o<t.length;o++){const c=t[o];if(c===null){n++;continue}const l=c.renderGroup??c.parentRenderGroup,d=l?.instructionSet?.gcTick??-1;if((l?.gcTick??0)===d&&(c._lastUsed=e),e-c._lastUsed>this.maxUnusedTime){if(!c.destroyed){const f=r;l&&(l.structureDidChange=!0),f[c.renderPipeId].destroyRenderable(c)}c._lastUsed=-1,n++,c.off("destroyed",this._removeRenderable,this)}else t[o-n]=c}t.length-=n}destroy(){this.enabled=!1,this._renderer=null,this._managedRenderables.length=0,this._managedHashes.length=0,this._managedArrays.length=0}_removeRenderable(e){const t=this._managedRenderables.indexOf(e);t>=0&&(e.off("destroyed",this._removeRenderable,this),this._managedRenderables[t]=null)}_updateInstructionGCTick(e,t){e.instructionSet.gcTick=t;for(const r of e.renderGroupChildren)this._updateInstructionGCTick(r,t)}};ho.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"renderableGC",priority:0},ho.defaultOptions={renderableGCActive:!0,renderableGCMaxUnusedTime:6e4,renderableGCFrequency:3e4};let ty=ho;const uo=class Id{constructor(e){this._renderer=e,this.count=0,this.checkCount=0}init(e){e={...Id.defaultOptions,...e},this.checkCountMax=e.textureGCCheckCountMax,this.maxIdle=e.textureGCAMaxIdle??e.textureGCMaxIdle,this.active=e.textureGCActive}postrender(){this._renderer.renderingToScreen&&(this.count++,this.active&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const e=this._renderer.texture.managedTextures;for(let t=0;t<e.length;t++){const r=e[t];r.autoGarbageCollect&&r.resource&&r._touched>-1&&this.count-r._touched>this.maxIdle&&(r._touched=-1,r.unload())}}destroy(){this._renderer=null}};uo.extension={type:[C.WebGLSystem,C.WebGPUSystem],name:"textureGC"},uo.defaultOptions={textureGCActive:!0,textureGCAMaxIdle:null,textureGCMaxIdle:3600,textureGCCheckCountMax:600};let iy=uo;const fo=class Pd{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)}init(e){e={...Pd.defaultOptions,...e},e.view&&(H(j,"ViewSystem.view has been renamed to ViewSystem.canvas"),e.canvas=e.view),this.screen=new z(0,0,e.width,e.height),this.canvas=e.canvas||V.get().createCanvas(),this.antialias=!!e.antialias,this.texture=Ch(this.canvas,e),this.renderTarget=new eo({colorTextures:[this.texture],depth:!!e.depth,isRoot:!0}),this.texture.source.transparent=e.backgroundAlpha<1,this.resolution=e.resolution}resize(e,t,r){this.texture.source.resize(e,t,r),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.destroy()}};fo.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"view",priority:0},fo.defaultOptions={width:800,height:600,autoDensity:!1,antialias:!1};const iu=[Y_,Qh,co,fo,Kh,iy,Jh,X_,Ul,ty,eu],ru=[Zh,ah,jh,Vh,lh,hh,ch,Wh],ry=[...iu,Sh,e_,Kv,_h,uh,Nh,Ih,mh,Bh,kh,vh,I_,yh,gh],sy=[...ru],ny=[nh,Hh,zh],su=[],nu=[],ou=[];L.handleByNamedList(C.WebGLSystem,su),L.handleByNamedList(C.WebGLPipes,nu),L.handleByNamedList(C.WebGLPipesAdaptor,ou),L.add(...ry,...sy,...ny);class oy extends Lr{constructor(){const e={name:"webgl",type:tt.WEBGL,systems:su,renderPipes:nu,renderPipeAdaptors:ou};super(e)}}const ay=Object.freeze(Object.defineProperty({__proto__:null,WebGLRenderer:oy},Symbol.toStringTag,{value:"Module"}));class au{constructor(e){this._hash=Object.create(null),this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_hash")}contextChange(e){this._gpu=e}getBindGroup(e,t,r){return e._updateKey(),this._hash[e._key]||this._createBindGroup(e,t,r)}_createBindGroup(e,t,r){const n=this._gpu.device,o=t.layout[r],c=[],l=this._renderer;for(const m in o){const g=e.resources[m]??e.resources[o[m]];let _;if(g._resourceType==="uniformGroup"){const y=g;l.ubo.updateUniformGroup(y);const a=y.buffer;_={buffer:l.buffer.getGPUBuffer(a),offset:0,size:a.descriptor.size}}else if(g._resourceType==="buffer"){const y=g;_={buffer:l.buffer.getGPUBuffer(y),offset:0,size:y.descriptor.size}}else if(g._resourceType==="bufferResource"){const y=g;_={buffer:l.buffer.getGPUBuffer(y.buffer),offset:y.offset,size:y.size}}else if(g._resourceType==="textureSampler"){const y=g;_=l.texture.getGpuSampler(y)}else if(g._resourceType==="textureSource"){const y=g;_=l.texture.getGpuSource(y).createView({})}c.push({binding:o[m],resource:_})}const d=l.shader.getProgramData(t).bindGroups[r],f=n.createBindGroup({layout:d,entries:c});return this._hash[e._key]=f,f}destroy(){for(const e of Object.keys(this._hash))this._hash[e]=null;this._hash=null,this._renderer=null}}au.extension={type:[C.WebGPUSystem],name:"bindGroup"};class lu{constructor(e){this._gpuBuffers=Object.create(null),e.renderableGC.addManagedHash(this,"_gpuBuffers")}contextChange(e){this._gpu=e}getGPUBuffer(e){return this._gpuBuffers[e.uid]||this.createGPUBuffer(e)}updateBuffer(e){const t=this._gpuBuffers[e.uid]||this.createGPUBuffer(e),r=e.data;return e._updateID&&r&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,0,r.buffer,0,(e._updateSize||r.byteLength)+3&-4)),t}destroyAll(){for(const e in this._gpuBuffers)this._gpuBuffers[e]?.destroy();this._gpuBuffers={}}createGPUBuffer(e){this._gpuBuffers[e.uid]||(e.on("update",this.updateBuffer,this),e.on("change",this.onBufferChange,this),e.on("destroy",this.onBufferDestroy,this));const t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e.data&&(xn(e.data.buffer,t.getMappedRange()),t.unmap()),this._gpuBuffers[e.uid]=t,t}onBufferChange(e){this._gpuBuffers[e.uid].destroy(),e._updateID=0,this._gpuBuffers[e.uid]=this.createGPUBuffer(e)}onBufferDestroy(e){this._destroyBuffer(e)}destroy(){this.destroyAll(),this._gpuBuffers={}}_destroyBuffer(e){if(e.off("update",this.updateBuffer,this),e.off("change",this.onBufferChange,this),e.off("destroy",this.onBufferDestroy,this),!this._gpuBuffers[e.uid])return;this._gpuBuffers[e.uid].destroy(),this._gpuBuffers[e.uid]=null}}lu.extension={type:[C.WebGPUSystem],name:"buffer"};class ly{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 r=t+e*4;if(r=Math.ceil(r/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,r>this.data.length*4)throw new Error("UniformBufferBatch: ubo batch got too big");return this.byteIndex=r,t}addGroup(e){const t=this.addEmptyGroup(e.length);for(let r=0;r<e.length;r++)this.data[t/4+r]=e[r];return t}destroy(){this.data=null}}class cu{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}}cu.extension={type:[C.WebGPUSystem],name:"colorMask"};class po{constructor(e){this._renderer=e}async init(e){return this._initPromise?this._initPromise:(this._initPromise=(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(t=>{this.gpu=t,this._renderer.runners.contextChange.emit(this.gpu)}),this._initPromise)}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){const t=await V.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter}),r=["texture-compression-bc","texture-compression-astc","texture-compression-etc2"].filter(o=>t.features.has(o)),n=await t.requestDevice({requiredFeatures:r});return{adapter:t,device:n}}destroy(){this.gpu=null,this._renderer=null}}po.extension={type:[C.WebGPUSystem],name:"device"},po.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};class hu{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){this.endRenderPass(),this._clearCache(),this.renderPassEncoder=this.commandEncoder.beginRenderPass(e.descriptor)}endRenderPass(){this.renderPassEncoder&&this.renderPassEncoder.end(),this.renderPassEncoder=null}setViewport(e){this.renderPassEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setPipelineFromGeometryProgramAndState(e,t,r,n){const o=this._renderer.pipeline.getPipeline(e,t,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){this._boundBindGroup[e]=null}setBindGroup(e,t,r){if(this._boundBindGroup[e]===t)return;this._boundBindGroup[e]=t,t._touch(this._renderer.textureGC.count);const n=this._renderer.bindGroup.getBindGroup(t,r,e);this.renderPassEncoder.setBindGroup(e,n)}setGeometry(e,t){const r=this._renderer.pipeline.getBufferNamesToBind(e,t);for(const n in r)this._setVertexBuffer(parseInt(n,10),e.attributes[r[n]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){for(const r in e.groups){const n=e.groups[r];t||this._syncBindGroup(n),this.setBindGroup(r,n,e.gpuProgram)}}_syncBindGroup(e){for(const t in e.resources){const r=e.resources[t];r.isUniformGroup&&this._renderer.ubo.updateUniformGroup(r)}}draw(e){const{geometry:t,shader:r,state:n,topology:o,size:c,start:l,instanceCount:d,skipSync:f}=e;this.setPipelineFromGeometryProgramAndState(t,r.gpuProgram,n,o),this.setGeometry(t,r.gpuProgram),this._setShaderBindGroups(r,f),t.indexBuffer?this.renderPassEncoder.drawIndexed(c||t.indexBuffer.data.length,d??t.instanceCount,l||0):this.renderPassEncoder.draw(c||t.getSize(),d??t.instanceCount,l||0)}finishRenderPass(){this.renderPassEncoder&&(this.renderPassEncoder.end(),this.renderPassEncoder=null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}restoreRenderPass(){const e=this._renderer.renderTarget.adaptor.getDescriptor(this._renderer.renderTarget.renderTarget,!1,[0,0,0,1]);this.renderPassEncoder=this.commandEncoder.beginRenderPass(e);const t=this._boundPipeline,r={...this._boundVertexBuffer},n=this._boundIndexBuffer,o={...this._boundBindGroup};this._clearCache();const c=this._renderer.renderTarget.viewport;this.renderPassEncoder.setViewport(c.x,c.y,c.width,c.height,0,1),this.setPipeline(t);for(const l in r)this._setVertexBuffer(l,r[l]);for(const l in o)this.setBindGroup(l,o[l],null);this._setIndexBuffer(n)}_clearCache(){for(let e=0;e<16;e++)this._boundBindGroup[e]=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}contextChange(e){this._gpu=e}}hu.extension={type:[C.WebGPUSystem],name:"encoder",priority:1};class uu{constructor(e){this._renderer=e}contextChange(){this.maxTextures=this._renderer.device.gpu.device.limits.maxSampledTexturesPerShaderStage,this.maxBatchableTextures=this.maxTextures}destroy(){}}uu.extension={type:[C.WebGPUSystem],name:"limits"};class du{constructor(e){this._renderTargetStencilState=Object.create(null),this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){let t=this._renderTargetStencilState[e.uid];t||(t=this._renderTargetStencilState[e.uid]={stencilMode:pe.DISABLED,stencilReference:0}),this._activeRenderTarget=e,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){const r=this._renderTargetStencilState[this._activeRenderTarget.uid];r.stencilMode=e,r.stencilReference=t;const n=this._renderer;n.pipeline.setStencilMode(e),n.encoder.renderPassEncoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._renderTargetStencilState=null}}du.extension={type:[C.WebGPUSystem],name:"stencil"};const os={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 cy(s){const e=s.map(r=>({data:r,offset:0,size:0}));let t=0;for(let r=0;r<e.length;r++){const n=e[r];let o=os[n.data.type].size;const c=os[n.data.type].align;if(!os[n.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${n.data.type}`);n.data.size>1&&(o=Math.max(o,c)*n.data.size),t=Math.ceil(t/c)*c,n.size=o,n.offset=t,t+=o}return t=Math.ceil(t/16)*16,{uboElements:e,size:t}}function hy(s,e){const{size:t,align:r}=os[s.data.type],n=(r-t)/4,o=s.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
|
|
964
964
|
v = uv.${s.data.name};
|
|
@@ -976,7 +976,7 @@ fn mainFragment(
|
|
|
976
976
|
}
|
|
977
977
|
${n!==0?`arrayOffset += ${n};`:""}
|
|
978
978
|
}
|
|
979
|
-
`}function uy(s){return Th(s,"uboWgsl",hy,r_)}class fu extends xh{constructor(){super({createUboElements:cy,generateUboSync:uy})}}fu.extension={type:[C.WebGPUSystem],name:"ubo"};const Mt=128;class pu{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_bindGroupHash"),this._batchBuffer=new ly({minUniformOffsetAlignment:Mt});const t=256/Mt;for(let r=0;r<t;r++){let n=$.UNIFORM|$.COPY_DST;r===0&&(n|=$.COPY_SRC),this._buffers.push(new We({data:this._batchBuffer.data,usage:n}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){for(const e in this._bindGroupHash)this._bindGroupHash[e]=null;this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const r=e.buffer.data,n=this._batchBuffer.addEmptyGroup(r.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,n/4),this._bindGroupHash[e.uid]=this._getBindGroup(n/Mt),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,r=this._batchBuffer.addGroup(t);return this._getBufferResource(r/Mt)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/Mt)}getArrayBufferResource(e){const r=this._batchBuffer.addGroup(e)/Mt;return this._getBufferResource(r)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new to({buffer:t,offset:(e/2|0)*256,size:Mt})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new _t({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 r=this._renderer.gpu.device.createCommandEncoder();for(let n=1;n<this._buffers.length;n++){const o=this._buffers[n];r.copyBufferToBuffer(e.getGPUBuffer(t),Mt,e.getGPUBuffer(o),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([r.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._bindGroupHash=null,this._renderer=null}}pu.extension={type:[C.WebGPUPipes],name:"uniformBatch"};const dy={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4};function fy(s,e,t,r,n){return s<<24|e<<16|t<<10|r<<5|n}function py(s,e,t,r){return t<<6|s<<3|r<<1|e}class mu{constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=Object.create(null),this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._renderer=e}contextChange(e){this._gpu=e,this.setStencilMode(pe.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){this._multisampleCount=e.msaaSamples,this._depthStencilAttachment=e.descriptor.depthStencilAttachment?1:0,this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=Rt[e],this._updatePipeHash())}setPipeline(e,t,r,n){const o=this.getPipeline(e,t,r);n.setPipeline(o)}getPipeline(e,t,r,n){e._layoutKey||(dh(e,t.attributeData),this._generateBufferKey(e)),n||(n=e.topology);const o=fy(e._layoutKey,t._layoutKey,r.data,r._blendModeId,dy[n]);return this._pipeCache[o]?this._pipeCache[o]:(this._pipeCache[o]=this._createPipeline(e,t,r,n),this._pipeCache[o])}_createPipeline(e,t,r,n){const o=this._gpu.device,c=this._createVertexBufferLayouts(e,t),l=this._renderer.state.getColorTargets(r);l[0].writeMask=this._stencilMode===pe.RENDERING_MASK_ADD?0:this._colorMask;const d=this._renderer.shader.getProgramData(t).pipeline,f={vertex:{module:this._getModule(t.vertex.source),entryPoint:t.vertex.entryPoint,buffers:c},fragment:{module:this._getModule(t.fragment.source),entryPoint:t.fragment.entryPoint,targets:l},primitive:{topology:n,cullMode:r.cullMode},layout:d,multisample:{count:this._multisampleCount},label:"PIXI Pipeline"};return this._depthStencilAttachment&&(f.depthStencil={...this._stencilState,format:"depth24plus-stencil8",depthWriteEnabled:r.depthTest,depthCompare:r.depthTest?"less":"always"}),o.createRenderPipeline(f)}_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 r=0;const n=Object.keys(e.attributes).sort();for(let c=0;c<n.length;c++){const l=e.attributes[n[c]];t[r++]=l.offset,t[r++]=l.format,t[r++]=l.stride,t[r++]=l.instance}const o=t.join("|");return e._layoutKey=Mi(o,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let r=0;const n=Object.keys(e.attributeData).sort();for(let c=0;c<n.length;c++){const l=e.attributeData[n[c]];t[r++]=l.location}const o=t.join("|");return e._attributeLocationsKey=Mi(o,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[r])return this._bindingNamesCache[r];const n=this._createVertexBufferLayouts(e,t),o=Object.create(null),c=t.attributeData;for(let l=0;l<n.length;l++){const f=Object.values(n[l].attributes)[0].shaderLocation;for(const m in c)if(c[m].location===f){o[l]=m;break}}return this._bindingNamesCache[r]=o,o}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[r])return this._bufferLayoutsCache[r];const n=[];return e.buffers.forEach(o=>{const c={arrayStride:0,stepMode:"vertex",attributes:[]},l=c.attributes;for(const d in t.attributeData){const f=e.attributes[d];(f.divisor??1)!==1&&G(`Attribute ${d} has an invalid divisor value of '${f.divisor}'. WebGPU only supports a divisor value of 1`),f.buffer===o&&(c.arrayStride=f.stride,c.stepMode=f.instance?"instance":"vertex",l.push({shaderLocation:t.attributeData[d].location,offset:f.offset,format:f.format}))}l.length&&n.push(c)}),this._bufferLayoutsCache[r]=n,n}_updatePipeHash(){const e=py(this._stencilMode,this._multisampleCount,this._colorMask,this._depthStencilAttachment);this._pipeStateCaches[e]||(this._pipeStateCaches[e]=Object.create(null)),this._pipeCache=this._pipeStateCaches[e]}destroy(){this._renderer=null,this._bufferLayoutsCache=null}}mu.extension={type:[C.WebGPUSystem],name:"pipeline"};class my{constructor(){this.contexts=[],this.msaaTextures=[],this.msaaSamples=1}}class gy{init(e,t){this._renderer=e,this._renderTargetSystem=t}copyToTexture(e,t,r,n,o){const c=this._renderer,l=this._getGpuColorTexture(e),d=c.texture.getGpuSource(t.source);return c.encoder.commandEncoder.copyTextureToTexture({texture:l,origin:r},{texture:d,origin:o},n),t}startRenderPass(e,t=!0,r,n){const c=this._renderTargetSystem.getGpuRenderTarget(e),l=this.getDescriptor(e,t,r);c.descriptor=l,this._renderer.pipeline.setRenderTarget(c),this._renderer.encoder.beginRenderPass(c),this._renderer.encoder.setViewport(n)}finishRenderPass(){this._renderer.encoder.endRenderPass()}_getGpuColorTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);return t.contexts[0]?t.contexts[0].getCurrentTexture():this._renderer.texture.getGpuSource(e.colorTextures[0].source)}getDescriptor(e,t,r){typeof t=="boolean"&&(t=t?ze.ALL:ze.NONE);const n=this._renderTargetSystem,o=n.getGpuRenderTarget(e),c=e.colorTextures.map((f,m)=>{const g=o.contexts[m];let _,y;g?_=g.getCurrentTexture().createView():_=this._renderer.texture.getGpuSource(f).createView({mipLevelCount:1}),o.msaaTextures[m]&&(y=_,_=this._renderer.texture.getTextureView(o.msaaTextures[m]));const a=t&ze.COLOR?"clear":"load";return r??(r=n.defaultClearColor),{view:_,resolveTarget:y,clearValue:r,storeOp:"store",loadOp:a}});let l;if((e.stencil||e.depth)&&!e.depthStencilTexture&&(e.ensureDepthStencilTexture(),e.depthStencilTexture.source.sampleCount=o.msaa?4:1),e.depthStencilTexture){const f=t&ze.STENCIL?"clear":"load",m=t&ze.DEPTH?"clear":"load";l={view:this._renderer.texture.getGpuSource(e.depthStencilTexture.source).createView(),stencilStoreOp:"store",stencilLoadOp:f,depthClearValue:1,depthLoadOp:m,depthStoreOp:"store"}}return{colorAttachments:c,depthStencilAttachment:l}}clear(e,t=!0,r,n){if(!t)return;const{gpu:o,encoder:c}=this._renderer,l=o.device;if(c.commandEncoder===null){const f=l.createCommandEncoder(),m=this.getDescriptor(e,t,r),g=f.beginRenderPass(m);g.setViewport(n.x,n.y,n.width,n.height,0,1),g.end();const _=f.finish();l.queue.submit([_])}else this.startRenderPass(e,t,r,n)}initGpuRenderTarget(e){e.isRoot=!0;const t=new my;return e.colorTextures.forEach((r,n)=>{if(r instanceof mt){const o=r.resource.getContext("webgpu"),c=r.transparent?"premultiplied":"opaque";try{o.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:"bgra8unorm",alphaMode:c})}catch(l){console.error(l)}t.contexts[n]=o}if(t.msaa=r.source.antialias,r.source.antialias){const o=new ge({width:0,height:0,sampleCount:4});t.msaaTextures[n]=o}}),t.msaa&&(t.msaaSamples=4,e.depthStencilTexture&&(e.depthStencilTexture.source.sampleCount=4)),t}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);e.depthStencilTexture&&t.msaa&&(e.depthStencilTexture.source.sampleCount=4)}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorTextures.forEach((r,n)=>{t.msaaTextures[n]?.resize(r.source.width,r.source.height,r.source._resolution)})}}class gu extends Eh{constructor(e){super(e),this.adaptor=new gy,this.adaptor.init(e,this)}}gu.extension={type:[C.WebGPUSystem],name:"renderTarget"};class vu{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,r=e.gpuLayout.map(o=>t.createBindGroupLayout({entries:o})),n={bindGroupLayouts:r};return this._gpuProgramData[e._layoutKey]={bindGroups:r,pipeline:t.createPipelineLayout(n)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}vu.extension={type:[C.WebGPUSystem],name:"shader"};const De={};De.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}},De.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}},De.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}},De.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}},De.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}},De.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}},De["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}},De["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}},De["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}},De.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}},De.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}},De.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class _u{constructor(){this.defaultState=new it,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e){return[{format:"bgra8unorm",writeMask:0,blend:De[e.blendMode]||De.normal}]}destroy(){this.gpu=null}}_u.extension={type:[C.WebGPUSystem],name:"state"};const vy={type:"image",upload(s,e,t){const r=s.resource,n=(s.pixelWidth|0)*(s.pixelHeight|0),o=r.byteLength/n;t.device.queue.writeTexture({texture:e},r,{offset:0,rowsPerImage:s.pixelHeight,bytesPerRow:s.pixelWidth*o},{width:s.pixelWidth,height:s.pixelHeight,depthOrArrayLayers:1})}},yu={"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}},_y={blockBytes:4,blockWidth:1,blockHeight:1},yy={type:"compressed",upload(s,e,t){let r=s.pixelWidth,n=s.pixelHeight;const o=yu[s.format]||_y;for(let c=0;c<s.resource.length;c++){const l=s.resource[c],d=Math.ceil(r/o.blockWidth)*o.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:c},l,{offset:0,bytesPerRow:d},{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)}}},xu={type:"image",upload(s,e,t){const r=s.resource;if(!r)return;if(globalThis.HTMLImageElement&&r instanceof HTMLImageElement){const l=V.get().createCanvas(r.width,r.height);l.getContext("2d").drawImage(r,0,0,r.width,r.height),s.resource=l,G("ImageSource: Image element passed, converting to canvas and replacing resource.")}const n=Math.min(e.width,s.resourceWidth||s.pixelWidth),o=Math.min(e.height,s.resourceHeight||s.pixelHeight),c=s.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:r},{texture:e,premultipliedAlpha:c},{width:n,height:o})}},xy={type:"video",upload(s,e,t){xu.upload(s,e,t)}};class by{constructor(e){this.device=e,this.sampler=e.createSampler({minFilter:"linear"}),this.pipelines={}}_getMipmapPipeline(e){let t=this.pipelines[e];return t||(this.mipmapShaderModule||(this.mipmapShaderModule=this.device.createShaderModule({code:`
|
|
979
|
+
`}function uy(s){return Th(s,"uboWgsl",hy,r_)}class fu extends xh{constructor(){super({createUboElements:cy,generateUboSync:uy})}}fu.extension={type:[C.WebGPUSystem],name:"ubo"};const Mt=128;class pu{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._renderer.renderableGC.addManagedHash(this,"_bindGroupHash"),this._batchBuffer=new ly({minUniformOffsetAlignment:Mt});const t=256/Mt;for(let r=0;r<t;r++){let n=$.UNIFORM|$.COPY_DST;r===0&&(n|=$.COPY_SRC),this._buffers.push(new We({data:this._batchBuffer.data,usage:n}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){for(const e in this._bindGroupHash)this._bindGroupHash[e]=null;this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const r=e.buffer.data,n=this._batchBuffer.addEmptyGroup(r.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,n/4),this._bindGroupHash[e.uid]=this._getBindGroup(n/Mt),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,r=this._batchBuffer.addGroup(t);return this._getBufferResource(r/Mt)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/Mt)}getArrayBufferResource(e){const r=this._batchBuffer.addGroup(e)/Mt;return this._getBufferResource(r)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new to({buffer:t,offset:(e/2|0)*256,size:Mt})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new _t({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 r=this._renderer.gpu.device.createCommandEncoder();for(let n=1;n<this._buffers.length;n++){const o=this._buffers[n];r.copyBufferToBuffer(e.getGPUBuffer(t),Mt,e.getGPUBuffer(o),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([r.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._bindGroupHash=null,this._renderer=null}}pu.extension={type:[C.WebGPUPipes],name:"uniformBatch"};const dy={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4};function fy(s,e,t,r,n){return s<<24|e<<16|t<<10|r<<5|n}function py(s,e,t,r){return t<<6|s<<3|r<<1|e}class mu{constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=Object.create(null),this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._renderer=e}contextChange(e){this._gpu=e,this.setStencilMode(pe.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){this._multisampleCount=e.msaaSamples,this._depthStencilAttachment=e.descriptor.depthStencilAttachment?1:0,this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=Rt[e],this._updatePipeHash())}setPipeline(e,t,r,n){const o=this.getPipeline(e,t,r);n.setPipeline(o)}getPipeline(e,t,r,n){e._layoutKey||(dh(e,t.attributeData),this._generateBufferKey(e)),n||(n=e.topology);const o=fy(e._layoutKey,t._layoutKey,r.data,r._blendModeId,dy[n]);return this._pipeCache[o]?this._pipeCache[o]:(this._pipeCache[o]=this._createPipeline(e,t,r,n),this._pipeCache[o])}_createPipeline(e,t,r,n){const o=this._gpu.device,c=this._createVertexBufferLayouts(e,t),l=this._renderer.state.getColorTargets(r);l[0].writeMask=this._stencilMode===pe.RENDERING_MASK_ADD?0:this._colorMask;const d=this._renderer.shader.getProgramData(t).pipeline,f={vertex:{module:this._getModule(t.vertex.source),entryPoint:t.vertex.entryPoint,buffers:c},fragment:{module:this._getModule(t.fragment.source),entryPoint:t.fragment.entryPoint,targets:l},primitive:{topology:n,cullMode:r.cullMode},layout:d,multisample:{count:this._multisampleCount},label:"PIXI Pipeline"};return this._depthStencilAttachment&&(f.depthStencil={...this._stencilState,format:"depth24plus-stencil8",depthWriteEnabled:r.depthTest,depthCompare:r.depthTest?"less":"always"}),o.createRenderPipeline(f)}_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 r=0;const n=Object.keys(e.attributes).sort();for(let c=0;c<n.length;c++){const l=e.attributes[n[c]];t[r++]=l.offset,t[r++]=l.format,t[r++]=l.stride,t[r++]=l.instance}const o=t.join("|");return e._layoutKey=Mi(o,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let r=0;const n=Object.keys(e.attributeData).sort();for(let c=0;c<n.length;c++){const l=e.attributeData[n[c]];t[r++]=l.location}const o=t.join("|");return e._attributeLocationsKey=Mi(o,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[r])return this._bindingNamesCache[r];const n=this._createVertexBufferLayouts(e,t),o=Object.create(null),c=t.attributeData;for(let l=0;l<n.length;l++){const f=Object.values(n[l].attributes)[0].shaderLocation;for(const m in c)if(c[m].location===f){o[l]=m;break}}return this._bindingNamesCache[r]=o,o}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[r])return this._bufferLayoutsCache[r];const n=[];return e.buffers.forEach(o=>{const c={arrayStride:0,stepMode:"vertex",attributes:[]},l=c.attributes;for(const d in t.attributeData){const f=e.attributes[d];(f.divisor??1)!==1&&G(`Attribute ${d} has an invalid divisor value of '${f.divisor}'. WebGPU only supports a divisor value of 1`),f.buffer===o&&(c.arrayStride=f.stride,c.stepMode=f.instance?"instance":"vertex",l.push({shaderLocation:t.attributeData[d].location,offset:f.offset,format:f.format}))}l.length&&n.push(c)}),this._bufferLayoutsCache[r]=n,n}_updatePipeHash(){const e=py(this._stencilMode,this._multisampleCount,this._colorMask,this._depthStencilAttachment);this._pipeStateCaches[e]||(this._pipeStateCaches[e]=Object.create(null)),this._pipeCache=this._pipeStateCaches[e]}destroy(){this._renderer=null,this._bufferLayoutsCache=null}}mu.extension={type:[C.WebGPUSystem],name:"pipeline"};class my{constructor(){this.contexts=[],this.msaaTextures=[],this.msaaSamples=1}}class gy{init(e,t){this._renderer=e,this._renderTargetSystem=t}copyToTexture(e,t,r,n,o){const c=this._renderer,l=this._getGpuColorTexture(e),d=c.texture.getGpuSource(t.source);return c.encoder.commandEncoder.copyTextureToTexture({texture:l,origin:r},{texture:d,origin:o},n),t}startRenderPass(e,t=!0,r,n){const c=this._renderTargetSystem.getGpuRenderTarget(e),l=this.getDescriptor(e,t,r);c.descriptor=l,this._renderer.pipeline.setRenderTarget(c),this._renderer.encoder.beginRenderPass(c),this._renderer.encoder.setViewport(n)}finishRenderPass(){this._renderer.encoder.endRenderPass()}_getGpuColorTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);return t.contexts[0]?t.contexts[0].getCurrentTexture():this._renderer.texture.getGpuSource(e.colorTextures[0].source)}getDescriptor(e,t,r){typeof t=="boolean"&&(t=t?He.ALL:He.NONE);const n=this._renderTargetSystem,o=n.getGpuRenderTarget(e),c=e.colorTextures.map((f,m)=>{const g=o.contexts[m];let _,y;g?_=g.getCurrentTexture().createView():_=this._renderer.texture.getGpuSource(f).createView({mipLevelCount:1}),o.msaaTextures[m]&&(y=_,_=this._renderer.texture.getTextureView(o.msaaTextures[m]));const a=t&He.COLOR?"clear":"load";return r??(r=n.defaultClearColor),{view:_,resolveTarget:y,clearValue:r,storeOp:"store",loadOp:a}});let l;if((e.stencil||e.depth)&&!e.depthStencilTexture&&(e.ensureDepthStencilTexture(),e.depthStencilTexture.source.sampleCount=o.msaa?4:1),e.depthStencilTexture){const f=t&He.STENCIL?"clear":"load",m=t&He.DEPTH?"clear":"load";l={view:this._renderer.texture.getGpuSource(e.depthStencilTexture.source).createView(),stencilStoreOp:"store",stencilLoadOp:f,depthClearValue:1,depthLoadOp:m,depthStoreOp:"store"}}return{colorAttachments:c,depthStencilAttachment:l}}clear(e,t=!0,r,n){if(!t)return;const{gpu:o,encoder:c}=this._renderer,l=o.device;if(c.commandEncoder===null){const f=l.createCommandEncoder(),m=this.getDescriptor(e,t,r),g=f.beginRenderPass(m);g.setViewport(n.x,n.y,n.width,n.height,0,1),g.end();const _=f.finish();l.queue.submit([_])}else this.startRenderPass(e,t,r,n)}initGpuRenderTarget(e){e.isRoot=!0;const t=new my;return e.colorTextures.forEach((r,n)=>{if(r instanceof mt){const o=r.resource.getContext("webgpu"),c=r.transparent?"premultiplied":"opaque";try{o.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:"bgra8unorm",alphaMode:c})}catch(l){console.error(l)}t.contexts[n]=o}if(t.msaa=r.source.antialias,r.source.antialias){const o=new ge({width:0,height:0,sampleCount:4});t.msaaTextures[n]=o}}),t.msaa&&(t.msaaSamples=4,e.depthStencilTexture&&(e.depthStencilTexture.source.sampleCount=4)),t}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);e.depthStencilTexture&&t.msaa&&(e.depthStencilTexture.source.sampleCount=4)}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorTextures.forEach((r,n)=>{t.msaaTextures[n]?.resize(r.source.width,r.source.height,r.source._resolution)})}}class gu extends Eh{constructor(e){super(e),this.adaptor=new gy,this.adaptor.init(e,this)}}gu.extension={type:[C.WebGPUSystem],name:"renderTarget"};class vu{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,r=e.gpuLayout.map(o=>t.createBindGroupLayout({entries:o})),n={bindGroupLayouts:r};return this._gpuProgramData[e._layoutKey]={bindGroups:r,pipeline:t.createPipelineLayout(n)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}vu.extension={type:[C.WebGPUSystem],name:"shader"};const Oe={};Oe.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}},Oe.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}},Oe.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}},Oe.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}},Oe.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}},Oe.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}},Oe["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}},Oe["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}},Oe["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}},Oe.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}},Oe.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}},Oe.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class _u{constructor(){this.defaultState=new it,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e){return[{format:"bgra8unorm",writeMask:0,blend:Oe[e.blendMode]||Oe.normal}]}destroy(){this.gpu=null}}_u.extension={type:[C.WebGPUSystem],name:"state"};const vy={type:"image",upload(s,e,t){const r=s.resource,n=(s.pixelWidth|0)*(s.pixelHeight|0),o=r.byteLength/n;t.device.queue.writeTexture({texture:e},r,{offset:0,rowsPerImage:s.pixelHeight,bytesPerRow:s.pixelWidth*o},{width:s.pixelWidth,height:s.pixelHeight,depthOrArrayLayers:1})}},yu={"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}},_y={blockBytes:4,blockWidth:1,blockHeight:1},yy={type:"compressed",upload(s,e,t){let r=s.pixelWidth,n=s.pixelHeight;const o=yu[s.format]||_y;for(let c=0;c<s.resource.length;c++){const l=s.resource[c],d=Math.ceil(r/o.blockWidth)*o.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:c},l,{offset:0,bytesPerRow:d},{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)}}},xu={type:"image",upload(s,e,t){const r=s.resource;if(!r)return;if(globalThis.HTMLImageElement&&r instanceof HTMLImageElement){const l=V.get().createCanvas(r.width,r.height);l.getContext("2d").drawImage(r,0,0,r.width,r.height),s.resource=l,G("ImageSource: Image element passed, converting to canvas and replacing resource.")}const n=Math.min(e.width,s.resourceWidth||s.pixelWidth),o=Math.min(e.height,s.resourceHeight||s.pixelHeight),c=s.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:r},{texture:e,premultipliedAlpha:c},{width:n,height:o})}},xy={type:"video",upload(s,e,t){xu.upload(s,e,t)}};class by{constructor(e){this.device=e,this.sampler=e.createSampler({minFilter:"linear"}),this.pipelines={}}_getMipmapPipeline(e){let t=this.pipelines[e];return t||(this.mipmapShaderModule||(this.mipmapShaderModule=this.device.createShaderModule({code:`
|
|
980
980
|
var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
|
|
981
981
|
vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
|
|
982
982
|
|
|
@@ -1285,14 +1285,14 @@ fn mainFragment(
|
|
|
1285
1285
|
|
|
1286
1286
|
return coverage;
|
|
1287
1287
|
}
|
|
1288
|
-
`}};let _o,yo;class Zy extends qe{constructor(e){const t=new Ue({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new B,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}});_o??(_o=Yi({name:"sdf-shader",bits:[Tn,Cn(e),$y,Ky,$i]})),yo??(yo=Xi({name:"sdf-shader",bits:[wn,En(e),qy,jy,qi]})),super({glProgram:yo,gpuProgram:_o,resources:{localUniforms:t,batchSamplers:In(e)}})}}class Jy extends Ce{destroy(){this.context.customShader&&this.context.customShader.destroy(),super.destroy()}}class Nu{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuBitmapText(e);return this._renderer.renderPipes.graphics.validateRenderable(t)}addRenderable(e,t){const r=this._getGpuBitmapText(e);zu(e,r),e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,r)),this._renderer.renderPipes.graphics.addRenderable(r,t),r.context.customShader&&this._updateDistanceField(e)}updateRenderable(e){const t=this._getGpuBitmapText(e);zu(e,t),this._renderer.renderPipes.graphics.updateRenderable(t),t.context.customShader&&this._updateDistanceField(e)}_updateContext(e,t){const{context:r}=t,n=Qi.getFont(e.text,e._style);r.clear(),n.distanceField.type!=="none"&&(r.customShader||(r.customShader=new Zy(this._renderer.limits.maxBatchableTextures)));const o=
|
|
1288
|
+
`}};let _o,yo;class Zy extends qe{constructor(e){const t=new Ue({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new B,type:"mat3x3<f32>"},uDistance:{value:4,type:"f32"},uRound:{value:0,type:"f32"}});_o??(_o=Yi({name:"sdf-shader",bits:[Tn,Cn(e),$y,Ky,$i]})),yo??(yo=Xi({name:"sdf-shader",bits:[wn,En(e),qy,jy,qi]})),super({glProgram:yo,gpuProgram:_o,resources:{localUniforms:t,batchSamplers:In(e)}})}}class Jy extends Ce{destroy(){this.context.customShader&&this.context.customShader.destroy(),super.destroy()}}class Nu{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuBitmapText(e);return this._renderer.renderPipes.graphics.validateRenderable(t)}addRenderable(e,t){const r=this._getGpuBitmapText(e);zu(e,r),e._didTextUpdate&&(e._didTextUpdate=!1,this._updateContext(e,r)),this._renderer.renderPipes.graphics.addRenderable(r,t),r.context.customShader&&this._updateDistanceField(e)}updateRenderable(e){const t=this._getGpuBitmapText(e);zu(e,t),this._renderer.renderPipes.graphics.updateRenderable(t),t.context.customShader&&this._updateDistanceField(e)}_updateContext(e,t){const{context:r}=t,n=Qi.getFont(e.text,e._style);r.clear(),n.distanceField.type!=="none"&&(r.customShader||(r.customShader=new Zy(this._renderer.limits.maxBatchableTextures)));const o=Be.graphemeSegmenter(e.text),c=e._style;let l=n.baseLineOffset;const d=Ln(o,c,n,!0),f=c.padding,m=d.scale;let g=d.width,_=d.height+d.offsetY;c._stroke&&(g+=c._stroke.width/m,_+=c._stroke.width/m),r.translate(-e._anchor._x*g-f,-e._anchor._y*_-f).scale(m,m);const y=n.applyFillAsTint?c._fill.color:16777215;let a=n.fontMetrics.fontSize,h=n.lineHeight;c.lineHeight&&(a=c.fontSize/m,h=c.lineHeight/m);let u=(h-a)/2;u-n.baseLineOffset<0&&(u=0);for(let p=0;p<d.lines.length;p++){const v=d.lines[p];for(let x=0;x<v.charPositions.length;x++){const b=v.chars[x],T=n.chars[b];if(T?.texture){const w=T.texture;r.texture(w,y||"black",Math.round(v.charPositions[x]+T.xOffset),Math.round(l+T.yOffset+u),w.orig.width,w.orig.height)}}l+=h}}_getGpuBitmapText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new Jy;return e._gpuData[this._renderer.uid]=t,this._updateContext(e,t),t}_updateDistanceField(e){const t=this._getGpuBitmapText(e).context,r=e._style.fontFamily,n=re.get(`${r}-bitmap`),{a:o,b:c,c:l,d}=e.groupTransform,f=Math.sqrt(o*o+c*c),m=Math.sqrt(l*l+d*d),g=(Math.abs(f)+Math.abs(m))/2,_=n.baseRenderedFontSize/e._style.fontSize,y=g*n.distanceField.range*(1/_);t.customShader.resources.localUniforms.uniforms.uDistance=y}destroy(){this._renderer=null}}Nu.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"bitmapText"};function zu(s,e){e.groupTransform=s.groupTransform,e.groupColorAlpha=s.groupColorAlpha,e.groupColor=s.groupColor,e.groupBlendMode=s.groupBlendMode,e.globalDisplayStatus=s.globalDisplayStatus,e.groupTransform=s.groupTransform,e.localDisplayStatus=s.localDisplayStatus,e.groupAlpha=s.groupAlpha,e._roundPixels=s._roundPixels}function Qy(s){const{text:e,style:t,chars:r}=s,n=t,o=Qi.getFont(e,n),c=Be.graphemeSegmenter(e),l=Ln(c,n,o,!0),d=l.scale,f=[],m=[],g=[],_=t.lineHeight?t.lineHeight:o.lineHeight*d;let y=0;for(const a of l.lines){if(a.chars.length===0)continue;const h=new se({label:"line"});h.y=y,g.push(h);let u=new se({label:"word"}),p=0;for(let v=0;v<a.chars.length;v++){const x=a.chars[v];if(!x||!o.chars[x])continue;const T=x===" ",w=v===a.chars.length-1;let S;r.length>0?(S=r.shift(),S.text=x,S.style=n,S.label=`char-${x}`,S.x=a.charPositions[v]*d-a.charPositions[p]*d):S=new zv({text:x,style:n,label:`char-${x}`,x:a.charPositions[v]*d-a.charPositions[p]*d}),T||(f.push(S),u.addChild(S)),(T||w)&&u.children.length>0&&(u.x=a.charPositions[p]*d,m.push(u),h.addChild(u),u=new se({label:"word"}),p=v+1)}y+=_}return{chars:f,lines:g,words:m}}class ex extends ns{constructor(e){super(),this.generatingTexture=!1,this.currentKey="--",this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){const e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){const{htmlText:e}=this._renderer;e.getReferenceCount(this.currentKey)===null?e.returnTexturePromise(this.texturePromise):e.decreaseReferenceCount(this.currentKey),this._renderer.runners.resolutionChange.remove(this),this.texturePromise=null,this._renderer=null}}function xo(s,e){const{texture:t,bounds:r}=s,n=e._style._getFinalPadding();ya(r,e._anchor,t);const o=e._anchor._x*n*2,c=e._anchor._y*n*2;r.minX-=n-o,r.minY-=n-c,r.maxX-=n-o,r.maxY-=n-c}class Hu{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e.styleKey;return t.currentKey!==r}addRenderable(e,t){const r=this._getGpuText(e);if(e._didTextUpdate){const n=e._autoResolution?this._renderer.resolution:e.resolution;(r.currentKey!==e.styleKey||e.resolution!==n)&&this._updateGpuText(e).catch(o=>{console.error(o)}),e._didTextUpdate=!1,xo(r,e)}this._renderer.renderPipes.batch.addToBatch(r,t)}updateRenderable(e){const t=this._getGpuText(e);t._batcher.updateElement(t)}async _updateGpuText(e){e._didTextUpdate=!1;const t=this._getGpuText(e);if(t.generatingTexture)return;const r=t.texturePromise;t.texturePromise=null,t.generatingTexture=!0,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution;let n=this._renderer.htmlText.getTexturePromise(e);r&&(n=n.finally(()=>{this._renderer.htmlText.decreaseReferenceCount(t.currentKey),this._renderer.htmlText.returnTexturePromise(r)})),t.texturePromise=n,t.currentKey=e.styleKey,t.texture=await n;const o=e.renderGroup||e.parentRenderGroup;o&&(o.structureDidChange=!0),t.generatingTexture=!1,xo(t,e)}_getGpuText(e){return e._gpuData[this._renderer.uid]||this.initGpuText(e)}initGpuText(e){const t=new ex(this._renderer);return t.renderable=e,t.transform=e.groupTransform,t.texture=F.EMPTY,t.bounds={minX:0,maxX:1,minY:0,maxY:0},t.roundPixels=this._renderer._roundPixels|e._roundPixels,e._resolution=e._autoResolution?this._renderer.resolution:e.resolution,e._gpuData[this._renderer.uid]=t,t}destroy(){this._renderer=null}}Hu.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"htmlText"};function tx(){const{userAgent:s}=V.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(s)}const ix=new Se;function Wu(s,e,t,r){const n=ix;n.minX=0,n.minY=0,n.maxX=s.width/r|0,n.maxY=s.height/r|0;const o=Te.getOptimalTexture(n.width,n.height,r,!1);return o.source.uploadMethodId="image",o.source.resource=s,o.source.alphaMode="premultiply-alpha-on-upload",o.frame.width=e/r,o.frame.height=t/r,o.source.emit("update",o.source),o.updateUvs(),o}function rx(s,e){const t=e.fontFamily,r=[],n={},o=/font-family:([^;"\s]+)/g,c=s.match(o);function l(d){n[d]||(r.push(d),n[d]=!0)}if(Array.isArray(t))for(let d=0;d<t.length;d++)l(t[d]);else l(t);c&&c.forEach(d=>{const f=d.split(":")[1].trim();l(f)});for(const d in e.tagStyles){const f=e.tagStyles[d].fontFamily;l(f)}return r}async function sx(s){const t=await(await V.get().fetch(s)).blob(),r=new FileReader;return await new Promise((o,c)=>{r.onloadend=()=>o(r.result),r.onerror=c,r.readAsDataURL(t)})}async function nx(s,e){const t=await sx(e);return`@font-face {
|
|
1289
1289
|
font-family: "${s.fontFamily}";
|
|
1290
1290
|
font-weight: ${s.fontWeight};
|
|
1291
1291
|
font-style: ${s.fontStyle};
|
|
1292
1292
|
src: url('${t}');
|
|
1293
1293
|
}`}const bo=new Map;async function ox(s){const e=s.filter(t=>re.has(`${t}-and-url`)).map(t=>{if(!bo.has(t)){const{entries:r}=re.get(`${t}-and-url`),n=[];r.forEach(o=>{const c=o.url,d=o.faces.map(f=>({weight:f.weight,style:f.style}));n.push(...d.map(f=>nx({fontWeight:f.weight,fontStyle:f.style,fontFamily:t},c)))}),bo.set(t,Promise.all(n).then(o=>o.join(`
|
|
1294
1294
|
`)))}return bo.get(t)});return(await Promise.all(e)).join(`
|
|
1295
|
-
`)}function ax(s,e,t,r,n){const{domElement:o,styleElement:c,svgRoot:l}=n;o.innerHTML=`<style>${e.cssStyle}</style><div style='padding:0;'>${s}</div>`,o.setAttribute("style",`transform: scale(${t});transform-origin: top left; display: inline-block`),c.textContent=r;const{width:d,height:f}=n.image;return l.setAttribute("width",d.toString()),l.setAttribute("height",f.toString()),new XMLSerializer().serializeToString(l)}function lx(s,e){const t=xt.getOptimalCanvasAndContext(s.width,s.height,e),{context:r}=t;return r.clearRect(0,0,s.width,s.height),r.drawImage(s,0,0),t}function cx(s,e,t){return new Promise(async r=>{t&&await new Promise(n=>setTimeout(n,100)),s.onload=()=>{r()},s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`,s.crossOrigin="anonymous"})}class Vu{constructor(e){this._activeTextures={},this._renderer=e,this._createCanvas=e.type===tt.WEBGPU}getTexture(e){return this.getTexturePromise(e)}getManagedTexture(e){const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].promise;const r=this._buildTexturePromise(e).then(n=>(this._activeTextures[t].texture=n,n));return this._activeTextures[t]={texture:null,promise:r,usageCount:1},r}getReferenceCount(e){return this._activeTextures[e]?.usageCount??null}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(t.texture?this._cleanUp(t.texture):t.promise.then(r=>{t.texture=r,this._cleanUp(t.texture)}).catch(()=>{G("HTMLTextSystem: Failed to clean texture")}),this._activeTextures[e]=null))}getTexturePromise(e){return this._buildTexturePromise(e)}async _buildTexturePromise(e){const{text:t,style:r,resolution:n,textureStyle:o}=e,c=me.get(rh),l=rx(t,r),d=await ox(l),f=Hv(t,r,d,c),m=Math.ceil(Math.ceil(Math.max(1,f.width)+r.padding*2)*n),g=Math.ceil(Math.ceil(Math.max(1,f.height)+r.padding*2)*n),_=c.image,y=2;_.width=(m|0)+y,_.height=(g|0)+y;const a=ax(t,r,n,d,c);await cx(_,a,tx()&&l.length>0);const h=_;let u;this._createCanvas&&(u=lx(_,n));const p=Wu(u?u.canvas:h,_.width-y,_.height-y,n);return o&&(p.source.style=o),this._createCanvas&&(this._renderer.texture.initSource(p.source),xt.returnCanvasAndContext(u)),me.return(c),p}returnTexturePromise(e){e.then(t=>{this._cleanUp(t)}).catch(()=>{G("HTMLTextSystem: Failed to clean texture")})}_cleanUp(e){Te.returnTexture(e,!0),e.source.resource=null,e.source.uploadMethodId="unknown"}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexturePromise(this._activeTextures[e].promise);this._activeTextures=null}}Vu.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"htmlText"};class hx extends se{constructor(e){const{text:t,style:r,autoSplit:n,lineAnchor:o,wordAnchor:c,charAnchor:l,...d}=e;super(d),this._dirty=!1,this._canReuseChars=!1,this.chars=[],this.words=[],this.lines=[],this._originalText=t,this._autoSplit=n,this._lineAnchor=o,this._wordAnchor=c,this._charAnchor=l,this.style=r}split(){const e=this.splitFn();this.chars=e.chars,this.words=e.words,this.lines=e.lines,this.addChild(...this.lines),this.charAnchor=this._charAnchor,this.wordAnchor=this._wordAnchor,this.lineAnchor=this._lineAnchor,this._dirty=!1,this._canReuseChars=!0}get text(){return this._originalText}set text(e){this._originalText=e,this.lines.forEach(t=>t.destroy({children:!0})),this.lines.length=0,this.words.length=0,this.chars.length=0,this._canReuseChars=!1,this.onTextUpdate()}_setOrigin(e,t,r){let n;typeof e=="number"?n={x:e,y:e}:n={x:e.x,y:e.y},t.forEach(o=>{const c=o.getLocalBounds(),l=c.minX+c.width*n.x,d=c.minY+c.height*n.y;o.origin.set(l,d)}),this[r]=e}get lineAnchor(){return this._lineAnchor}set lineAnchor(e){this._setOrigin(e,this.lines,"_lineAnchor")}get wordAnchor(){return this._wordAnchor}set wordAnchor(e){this._setOrigin(e,this.words,"_wordAnchor")}get charAnchor(){return this._charAnchor}set charAnchor(e){this._setOrigin(e,this.chars,"_charAnchor")}get style(){return this._style}set style(e){e||(e={}),this._style=new Be(e),this.words.forEach(t=>t.destroy()),this.words.length=0,this.lines.forEach(t=>t.destroy()),this.lines.length=0,this._canReuseChars=!0,this.onTextUpdate()}onTextUpdate(){this._dirty=!0,this._autoSplit&&this.split()}destroy(e){super.destroy(e),this.chars=[],this.words=[],this.lines=[],(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._originalText=""}}const Yu=class cs extends hx{constructor(e){const t={...cs.defaultOptions,...e};super(t)}static from(e,t){const r={...cs.defaultOptions,...t,text:e.text,style:new Be(e.style)};return new cs({...r})}splitFn(){return Qy({text:this._originalText,style:this._style,chars:this._canReuseChars?this.chars:[]})}};Yu.defaultOptions={autoSplit:!0,lineAnchor:0,wordAnchor:0,charAnchor:0};let ux=Yu;class dx extends ns{constructor(e){super(),this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){const e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){const{canvasText:e}=this._renderer;e.getReferenceCount(this.currentKey)>0?e.decreaseReferenceCount(this.currentKey):this.texture&&e.returnTexture(this.texture),this._renderer.runners.resolutionChange.remove(this),this._renderer=null}}class Xu{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e.styleKey;return t.currentKey!==r?!0:e._didTextUpdate}addRenderable(e,t){const r=this._getGpuText(e);if(e._didTextUpdate){const n=e._autoResolution?this._renderer.resolution:e.resolution;(r.currentKey!==e.styleKey||e.resolution!==n)&&this._updateGpuText(e),e._didTextUpdate=!1,xo(r,e)}this._renderer.renderPipes.batch.addToBatch(r,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 dx(this._renderer);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,t}destroy(){this._renderer=null}}Xu.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"text"};class $u{constructor(e){this._activeTextures={},this._renderer=e}getTexture(e,t,r,n){typeof e=="string"&&(H("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:r,resolution:t}),e.style instanceof Be||(e.style=new Be(e.style)),e.textureStyle instanceof at||(e.textureStyle=new at(e.textureStyle)),typeof e.text!="string"&&(e.text=e.text.toString());const{text:o,style:c,textureStyle:l}=e,d=e.resolution??this._renderer.resolution,{frame:f,canvasAndContext:m}=ir.getCanvasAndContext({text:o,style:c,resolution:d}),g=Wu(m.canvas,f.width,f.height,d);if(l&&(g.source.style=l),c.trim&&(f.pad(c.padding),g.frame.copyFrom(f),g.frame.scale(1/d),g.updateUvs()),c.filters){const _=this._applyFilters(g,c.filters);return this.returnTexture(g),ir.returnCanvasAndContext(m),_}return this._renderer.texture.initSource(g._source),ir.returnCanvasAndContext(m),g}returnTexture(e){const t=e.source;t.resource=null,t.uploadMethodId="unknown",t.alphaMode="no-premultiply-alpha",Te.returnTexture(e,!0)}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 r=this.getTexture({text:e.text,style:e.style,resolution:e._resolution,textureStyle:e.textureStyle});return this._activeTextures[t]={texture:r,usageCount:1},r}decreaseReferenceCount(e){const t=this._activeTextures[e];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 r=this._renderer.renderTarget.renderTarget,n=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind(r,!1),n}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexture(this._activeTextures[e].texture);this._activeTextures=null}}$u.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"canvasText"},L.add(Xf,$f);function Ee(s){if(s!=null){if(typeof s=="number")return s;if(typeof s=="string"){if(s==="transparent")return;if(s.startsWith("#")){const t=parseInt(s.slice(1),16);if(!isNaN(t))return t}if(s.startsWith("0x")){const t=parseInt(s,16);if(!isNaN(t))return t}const e=parseInt(s,16);if(!isNaN(e))return e;try{return new le(s).toNumber()}catch{return}}}}const qu=s=>s==="transparent",Vt=(s,e=16777215)=>qu(s)?{color:e,alpha:0}:{color:Ee(s)??e,alpha:1};class Ft extends kt{type="Caption";ready;_meta={duration:1/0,width:0,height:0};get meta(){return{...this._meta}}text;get style(){if(!this.originalOpts)return{};const e=this.originalOpts;return{fontSize:e.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,color:e.fill,align:e.align,textCase:e.textCase,stroke:e.stroke?typeof e.stroke=="object"?{color:e.stroke.color,width:e.stroke.width}:{color:e.stroke,width:e.strokeWidth??0}:void 0,shadow:e.dropShadow?{color:e.dropShadow.color??"#000000",alpha:e.dropShadow.alpha??.5,blur:e.dropShadow.blur??4,distance:e.dropShadow.distance??0,angle:e.dropShadow.angle??0}:void 0}}bottomOffset;get textCase(){return this.originalOpts?.textCase||"none"}set textCase(e){this.updateStyle({textCase:e})}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];opts;pixiTextContainer=null;renderTexture=null;wordTexts=[];extraPadding=0;textStyle;externalRenderer=null;pixiApp=null;originalOpts=null;constructor(e,t={},r){super(),this.text=e,this.originalOpts={...t},this.externalRenderer=r??null,this.opts={fontSize:t.fontSize??30,fontFamily:t.fontFamily??"Arial",fontUrl:t.fontUrl??"",fontWeight:t.fontWeight??"normal",fontStyle:t.fontStyle??"normal",fill:t.fill??"#ffffff",strokeWidth:t.strokeWidth??0,align:t.align??"center",wordWrapWidth:t.wordWrapWidth??0,wordWrap:t.wordWrap??!1,lineHeight:t.lineHeight??1,letterSpacing:t.letterSpacing??0,textCase:t.textCase??"none",videoWidth:t.caption?.positioning?.videoWidth??t.videoWidth??1280,videoHeight:t.caption?.positioning?.videoHeight??t.videoHeight??720,bottomOffset:t.caption?.positioning?.bottomOffset??t.bottomOffset??30,keyword:t.caption?.colors?.keyword??t.colors?.keyword??"#ffff00",background:t.caption?.colors?.background??t.colors?.background??"#000000",active:t.caption?.colors?.active??t.colors?.active??"#ffffff",activeFill:t.caption?.colors?.activeFill??t.colors?.activeFill??"#00ff00",appeared:t.caption?.colors?.appeared??t.colors?.appeared??"#ffffff",words:t.caption?.words??t.words??[],preserveKeywordColor:t.caption?.preserveKeywordColor??t.preserveKeywordColor??!1};const n={fontSize:this.opts.fontSize,fontFamily:this.opts.fontFamily,fontWeight:this.opts.fontWeight,fontStyle:this.opts.fontStyle,align:this.opts.align};if(t.fill&&typeof t.fill=="object"&&t.fill.type==="gradient"){const l=new Ke(t.fill.x0,t.fill.y0,t.fill.x1,t.fill.y1);t.fill.colors.forEach(({ratio:d,color:f})=>{const m=typeof f=="number"?f:Ee(f)??16777215;l.addColorStop(d,m)}),n.fill={fill:l}}else{let l;t.fill==="transparent"?l=16777215:(typeof t.fill=="string"||typeof t.fill=="number")&&(l=Ee(t.fill)),n.fill=l??16777215}const o=l=>l==="transparent";if(t.stroke&&typeof t.stroke=="object"&&"color"in t.stroke){if(!o(t.stroke.color)){const l=Ee(t.stroke.color);l!==void 0&&(n.stroke={color:l,width:t.stroke.width},t.stroke.join&&(n.stroke.join=t.stroke.join))}}else if(!o(t.stroke)){const l=Ee(t.stroke);l!==void 0?n.stroke={color:l,width:this.opts.strokeWidth??0}:this.opts.strokeWidth&&this.opts.strokeWidth>0&&(n.stroke={color:0,width:this.opts.strokeWidth})}if(t.dropShadow){const l=Ee(t.dropShadow.color);l!==void 0&&(n.dropShadow={color:l,alpha:t.dropShadow.alpha??.5,blur:t.dropShadow.blur??4,angle:t.dropShadow.angle??Math.PI/6,distance:t.dropShadow.distance??2})}const c=new Be(n);this.textStyle=c,this.ready=(async()=>{await this.refreshCaptions();const l={...this._meta};return W.info("CaptionClip ready:",l),l})()}async updateStyle(e){this.originalOpts||(this.originalOpts={}),this.originalOpts={...this.originalOpts,...e},e.fontSize!==void 0&&(this.opts.fontSize=e.fontSize),e.fontFamily!==void 0&&(this.opts.fontFamily=e.fontFamily),e.fontWeight!==void 0&&(this.opts.fontWeight=e.fontWeight),e.fontStyle!==void 0&&(this.opts.fontStyle=e.fontStyle),e.fill!==void 0&&(this.opts.fill=e.fill),e.align!==void 0&&(this.opts.align=e.align),e.letterSpacing!==void 0&&(this.opts.letterSpacing=e.letterSpacing),e.lineHeight!==void 0&&(this.opts.lineHeight=e.lineHeight),e.textCase!==void 0&&(this.opts.textCase=e.textCase);const t={fontSize:this.opts.fontSize,fontFamily:this.opts.fontFamily,fontWeight:this.opts.fontWeight,fontStyle:this.opts.fontStyle,align:this.opts.align};if(this.opts.fill&&typeof this.opts.fill=="object"&&this.opts.fill.type==="gradient"){const r=new Ke(this.opts.fill.x0,this.opts.fill.y0,this.opts.fill.x1,this.opts.fill.y1);this.opts.fill.colors.forEach(({ratio:n,color:o})=>{const c=typeof o=="number"?o:Ee(o)??16777215;r.addColorStop(n,c)}),t.fill={fill:r}}else{const r=typeof this.opts.fill=="string"||typeof this.opts.fill=="number"?Ee(this.opts.fill):void 0;t.fill=r??16777215}if(e.stroke!==void 0||e.strokeWidth!==void 0)if(this.originalOpts.stroke&&typeof this.originalOpts.stroke=="object"&&"color"in this.originalOpts.stroke){const r=Ee(this.originalOpts.stroke.color);r!==void 0&&(t.stroke={color:r,width:this.originalOpts.stroke.width},this.originalOpts.stroke.join&&(t.stroke.join=this.originalOpts.stroke.join))}else{const r=Ee(this.originalOpts.stroke),n=e.strokeWidth??this.originalOpts.strokeWidth??0;r!==void 0?t.stroke={color:r,width:n}:n>0&&(t.stroke={color:0,width:n})}this.textStyle=new Be(t),await this.refreshCaptions()}async refreshCaptions(){this.pixiTextContainer?(this.pixiTextContainer.children.forEach(p=>{p instanceof Ce&&p.label}),this.pixiTextContainer.removeChildren()):this.pixiTextContainer=new se;const e=this.textStyle;let t=0,r=0,n=0;const o=this.opts.textCase;this.wordTexts=this.opts.words.map(p=>{let v=p.text;o==="uppercase"?v=v.toUpperCase():o==="lowercase"?v=v.toLowerCase():o==="title"&&(v=v.replace(/\w\S*/g,E=>E.charAt(0).toUpperCase()+E.substring(1).toLowerCase()));const x=new ux({text:v,style:e});x.x=t,x.y=0;const b=x.getLocalBounds(),T=Math.ceil(b.width||x.width),w=Math.ceil(b.height||x.height);r=Math.max(r,w),t+=T+5,n=t-5,this.pixiTextContainer.addChild(x);const S=Ee(this.opts.fill);return x.tint=S??16777215,x});const c=n,l=r,d=new Ce;d.label="containerBackground";const f=this.opts.background==="transparent",m=f?0:Ee(this.opts.background),g=f?0:1,_=15;d.roundRect(0,0,c+_*2,l+_*2,10),d.fill({color:m,alpha:g}),this.wordTexts.forEach(p=>{this.extraPadding=0,p.pivot.y=0,p.pivot.x=0,p.y=_-this.extraPadding,p.x+=_}),this.pixiTextContainer.addChildAt(d,0),this.renderTexture&&this.renderTexture.destroy(!0),this.renderTexture=Ae.create({width:c+_*2,height:l+_*2}),this._meta.width=c+_*2,this._meta.height=l+_*2,this._meta.duration=1/0;const a=this.opts.videoWidth,h=this.opts.videoHeight,u=this.opts.bottomOffset;this.width=this.width===0?this._meta.width:this.width,this.height=this.height===0?this._meta.height:this.height,this.top=h-this.height-u,this.left=(a-this.width)/2}lastLoggedTime=-1;updateState(e){const t=e/1e3,r=Math.floor(e/1e6);r!==this.lastLoggedTime&&(this.lastLoggedTime=r),this.opts.words.forEach((n,o)=>{const c=t>=n.from&&t<=n.to,l=t>n.to,d=n.isKeyWord&&!qu(this.opts.keyword);let f=16777215,m=1;n.isKeyWord&&c&&d?{color:f,alpha:m}=Vt(this.opts.keyword):c?{color:f,alpha:m}=Vt(this.opts.active):l&&this.opts.preserveKeywordColor&&d?{color:f,alpha:m}=Vt(this.opts.keyword):l?{color:f,alpha:m}=Vt(this.opts.appeared):{color:f,alpha:m}=Vt(this.opts.fill);const g=this.wordTexts[o];if(!g){console.warn(`¡WARNING: SplitBitmapText was not found for word "${n.text}"!`);return}g.children.forEach(y=>{y.label!=="bgRect"&&(y.tint=f,y.alpha=m)});const _=g.getChildByLabel("bgRect");if(c){const{color:y,alpha:a}=Vt(this.opts.activeFill,16753920),h=10,u=g.getLocalBounds(),p=16,v=_??new Ce;v.label="bgRect",v.clear(),v.roundRect(u.x-h/2,u.y-h/2+this.extraPadding,u.width+h,u.height+h,p),v.fill({color:y,alpha:a}),v.tint=16777215,_||g.addChildAt(v,0)}else _&&(g.removeChild(_),_.destroy())})}async getTexture(){if(this.pixiTextContainer==null||this.renderTexture==null)return console.log("[CaptionClip] getTexture returning null - container or texture not ready"),null;try{return(await this.getRenderer()).render({container:this.pixiTextContainer,target:this.renderTexture}),this.renderTexture}catch(e){return console.error("[CaptionClip] Error in getTexture:",e),null}}setRenderer(e){this.externalRenderer=e}async getRenderer(){if(this.externalRenderer!=null)return this.externalRenderer;if(this.pixiApp?.renderer==null)throw new Error("CaptionClip: No renderer available. Provide a renderer via setRenderer().");return this.pixiApp.renderer}async tick(e){if(await this.ready,this.pixiTextContainer==null||this.renderTexture==null)throw new Error("CaptionClip not initialized");this.updateState(e);const t=await this.getRenderer();t.render({container:this.pixiTextContainer,target:this.renderTexture});const r=this.renderTexture.source?.resource?.source;let n;if(r instanceof HTMLCanvasElement)n=await createImageBitmap(r);else if(r instanceof OffscreenCanvas)n=await createImageBitmap(r);else{const c=t.extract.canvas(this.renderTexture);if(c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas)n=await createImageBitmap(c);else throw new Error("Unable to extract canvas from render texture")}return{video:n,state:"success"}}async split(e){await this.ready;const t=await this.clone(),r=await this.clone();return[t,r]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=this.originalOpts||{},t=new Ft(this.text,e);return this.copyStateTo(t),t.id=this.id,t.effects=[...this.effects],t}destroy(){if(!this.destroyed){W.info("CaptionClip destroy");try{this.wordTexts.forEach(e=>{e!=null&&!e.destroyed&&e.destroy({children:!0})})}catch{}finally{this.wordTexts=[]}try{this.pixiTextContainer!=null&&this.pixiTextContainer.destroyed!==!0&&this.pixiTextContainer.destroy({children:!0})}catch{}finally{this.pixiTextContainer=null}try{this.renderTexture!=null&&this.renderTexture.destroyed!==!0&&this.renderTexture.destroy(!0)}catch{}finally{this.renderTexture=null}if(this.externalRenderer=null,this.pixiApp!=null)try{const e=this.pixiApp;e.destroyed!==!0&&e.renderer!=null&&this.pixiApp.destroy(!0,{children:!0,texture:!0})}catch{}finally{this.pixiApp=null}super.destroy()}}toJSON(e=!1){const t=super.toJSON(e),r={};if(this.originalOpts){const g=this.originalOpts;g.fontSize!==void 0&&(r.fontSize=g.fontSize),g.fontFamily!==void 0&&(r.fontFamily=g.fontFamily),g.fontWeight!==void 0&&(r.fontWeight=g.fontWeight),g.fontStyle!==void 0&&(r.fontStyle=g.fontStyle),g.fill!==void 0&&(r.color=g.fill),g.align!==void 0&&(r.align=g.align),g.textCase!==void 0&&(r.textCase=g.textCase),g.fontUrl!==void 0&&(r.fontUrl=g.fontUrl),g.stroke&&(typeof g.stroke=="object"?r.stroke={color:g.stroke.color,width:g.stroke.width}:r.stroke={color:g.stroke,width:g.strokeWidth??0}),g.dropShadow&&(r.shadow={color:g.dropShadow.color??"#000000",alpha:g.dropShadow.alpha??.5,blur:g.dropShadow.blur??4,distance:g.dropShadow.distance??0,angle:g.dropShadow.angle??0})}const n={};this.opts.words&&this.opts.words.length>0&&(n.words=this.opts.words);const o={},c=this.originalOpts?.caption?.colors??this.originalOpts?.colors;c?.appeared!==void 0&&(o.appeared=c.appeared),c?.active!==void 0&&(o.active=c.active),c?.activeFill!==void 0&&(o.activeFill=c.activeFill),c?.background!==void 0&&(o.background=c.background),c?.keyword!==void 0&&(o.keyword=c.keyword);let l;this.originalOpts?.caption?.preserveKeywordColor!==void 0?l=this.originalOpts.caption.preserveKeywordColor:this.originalOpts?.preserveKeywordColor!==void 0&&(l=this.originalOpts.preserveKeywordColor),Object.keys(o).length>0&&(n.colors=o),l!==void 0&&(n.preserveKeywordColor=l);const d={};this.bottomOffset!==void 0&&(d.bottomOffset=this.bottomOffset);const f=this.originalOpts?.caption?.positioning?.videoWidth??this.originalOpts?.videoWidth,m=this.originalOpts?.caption?.positioning?.videoHeight??this.originalOpts?.videoHeight;return f!==void 0&&(d.videoWidth=f),m!==void 0&&(d.videoHeight=m),Object.keys(d).length>0&&(n.positioning=d),{...t,type:"Caption",text:this.text,style:r,caption:Object.keys(n).length>0?n:void 0,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Caption")throw new Error(`Expected Caption, got ${e.type}`);const t=e.text||"",r=e.style||{},n={};r.fontSize!==void 0&&(n.fontSize=r.fontSize),r.fontFamily!==void 0&&(n.fontFamily=r.fontFamily),r.fontWeight!==void 0&&(n.fontWeight=r.fontWeight),r.fontStyle!==void 0&&(n.fontStyle=r.fontStyle),r.color!==void 0&&(n.fill=r.color),r.align!==void 0&&(n.align=r.align),r.textCase!==void 0&&(n.textCase=r.textCase),r.fontUrl!==void 0?n.fontUrl=r.fontUrl:e.fontUrl!==void 0&&(n.fontUrl=e.fontUrl),r.stroke&&(n.stroke=r.stroke.color,n.strokeWidth=r.stroke.width),r.shadow&&(n.dropShadow={color:r.shadow.color,alpha:r.shadow.alpha,blur:r.shadow.blur,distance:r.shadow.distance,angle:r.shadow.angle}),e.caption?n.caption=e.caption:(e.bottomOffset!==void 0&&(n.bottomOffset=e.bottomOffset),e.words!==void 0&&(n.words=e.words),(e.appearedColor!==void 0||e.activeColor!==void 0||e.activeFillColor!==void 0||e.backgroundColor!==void 0||e.isKeyWordColor!==void 0)&&(n.colors={},e.appearedColor!==void 0&&(n.colors.appeared=e.appearedColor),e.activeColor!==void 0&&(n.colors.active=e.activeColor),e.activeFillColor!==void 0&&(n.colors.activeFill=e.activeFillColor),e.backgroundColor!==void 0&&(n.colors.background=e.backgroundColor),e.isKeyWordColor!==void 0&&(n.colors.keyword=e.isKeyWordColor)),e.preservedColorKeyWord!==void 0&&(n.preserveKeywordColor=e.preservedColorKeyWord),e.videoWidth!==void 0&&(n.videoWidth=e.videoWidth),e.videoHeight!==void 0&&(n.videoHeight=e.videoHeight));const o=new Ft(t,n);return o.left=e.left,o.top=e.top,o.width=e.width,o.height=e.height,o.angle=e.angle,o.display.from=e.display.from,o.display.to=e.display.to,o.duration=e.duration,o.playbackRate=e.playbackRate,o.zIndex=e.zIndex,o.opacity=e.opacity,o.flip=e.flip,e.animation&&o.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(o.id=e.id),e.effects&&(o.effects=e.effects),await o.ready,o}}class ve extends kt{type="Image";ready;_meta={duration:0,width:0,height:0};get meta(){return{...this._meta}}img=null;pixiTexture=null;frames=[];id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];static async fromUrl(e,t){const r=await er.load(e),n=r.source?.resource?.source;let o;try{if(n instanceof HTMLCanvasElement||n instanceof OffscreenCanvas)o=await createImageBitmap(n);else if(n instanceof HTMLImageElement){const l=new OffscreenCanvas(n.width,n.height),d=l.getContext("2d");if(d==null)throw new Error("Failed to create 2d context");d.drawImage(n,0,0),o=await createImageBitmap(l)}else if(n instanceof ImageBitmap)o=await createImageBitmap(n);else{const l=await fetch(e);if(!l.ok)throw new Error(`Failed to fetch image: ${l.status} ${l.statusText}`);const d=await l.blob();o=await createImageBitmap(d)}}catch{const d=await fetch(e);if(!d.ok)throw new Error(`Failed to fetch image: ${d.status} ${d.statusText}`);const f=await d.blob();o=await createImageBitmap(f)}const c=new ve(o,t||e);return c.pixiTexture=r,c}getTexture(){return this.pixiTexture}constructor(e,t){super(),this.src=t!==void 0?t:"";const r=n=>{this.img=n,this._meta.width=n.width,this._meta.height=n.height,this._meta.duration=1/0;const o={...this._meta};return this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration===0&&o.duration!==1/0&&(this.duration=o.duration,this.display.to=this.display.from+this.duration),o};if(e instanceof ReadableStream)this.ready=new Response(e).blob().then(n=>createImageBitmap(n)).then(r);else if(e instanceof ImageBitmap)this.ready=Promise.resolve(r(e));else if(Array.isArray(e)&&e.every(n=>n instanceof VideoFrame)){this.frames=e;const n=this.frames[0];if(n==null)throw Error("The frame count must be greater than 0");this._meta={width:n.displayWidth,height:n.displayHeight,duration:this.frames.reduce((c,l)=>c+(l.duration??0),0)};const o={...this._meta,duration:1/0};this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration===0&&o.duration!==1/0&&(this.duration=o.duration,this.display.to=this.display.from+this.duration),this.ready=Promise.resolve(o)}else if("type"in e)this.ready=this.initAnimateImg(e.stream,e.type).then(()=>{const n={width:this._meta.width,height:this._meta.height,duration:1/0};return this.width=this.width===0?n.width:this.width,this.height=this.height===0?n.height:this.height,this.duration===0&&n.duration!==1/0&&(this.duration=n.duration,this.display.to=this.display.from+this.duration),n});else throw Error("Illegal arguments")}async initAnimateImg(e,t){this.frames=await zf(e,t);const r=this.frames[0];if(r==null)throw Error("No frame available in gif");this._meta={duration:this.frames.reduce((n,o)=>n+(o.duration??0),0),width:r.codedWidth,height:r.codedHeight},W.info("ImageClip ready:",this._meta)}tickInterceptor=async(e,t)=>t;async tick(e){if(this.img!=null)return await this.tickInterceptor(e,{video:await createImageBitmap(this.img),state:"success"});const t=e%this._meta.duration;return await this.tickInterceptor(e,{video:(this.frames.find(r=>t>=r.timestamp&&t<=r.timestamp+(r.duration??0))??this.frames[0]).clone(),state:"success"})}async split(e){if(await this.ready,this.img!=null)return[new ve(await createImageBitmap(this.img),this.src),new ve(await createImageBitmap(this.img),this.src)];let t=-1;for(let o=0;o<this.frames.length;o++){const c=this.frames[o];if(!(e>c.timestamp)){t=o;break}}if(t===-1)throw Error("Not found frame by time");const r=this.frames.slice(0,t).map(o=>new VideoFrame(o)),n=this.frames.slice(t).map(o=>new VideoFrame(o,{timestamp:o.timestamp-e}));return[new ve(r,this.src),new ve(n,this.src)]}async clone(){await this.ready;const e=this.img==null?this.frames.map(r=>r.clone()):await createImageBitmap(this.img),t=new ve(e,this.src);return t.tickInterceptor=this.tickInterceptor,this.copyStateTo(t),t.id=this.id,t.effects=[...this.effects],t.transition=this.transition,t}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}destroy(){W.info("ImageClip destroy"),this.img?.close(),this.frames.forEach(e=>e.close()),this.pixiTexture=null,super.destroy()}toJSON(e=!1){return{...super.toJSON(e),type:"Image",id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Image")throw new Error(`Expected Image, got ${e.type}`);if(!e.src||e.src.trim()==="")throw new Error("ImageClip requires a valid source URL. Generated clips (like text-to-image) cannot be loaded from JSON without their source data.");let t;try{const r=await fetch(e.src);if(!r.ok)throw new Error(`Failed to fetch image from ${e.src}: ${r.status} ${r.statusText}. Make sure the file exists in the public directory.`);const n=await r.blob();if(!n.type.startsWith("image/"))throw new Error(`Invalid image format: ${n.type}. Expected an image file.`);t=new ve(await createImageBitmap(n),e.src)}catch(r){throw r instanceof Error&&r.message.includes("could not be decoded")?new Error(`Failed to decode image from ${e.src}. The image may be corrupted, in an unsupported format, or there may be CORS issues.`):r}return await t.ready,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),e.effects&&(t.effects=e.effects),e.transition&&(t.transition=e.transition),t}async scaleToFit(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.min(e/r,t/n);this.width=r*o,this.height=n*o}async scaleToFill(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.max(e/r,t/n);this.width=r*o,this.height=n*o}centerInScene(e,t){this.left=(e-this.width)/2,this.top=(t-this.height)/2}}function To(s,e){const t=e.videoTracks[0],r={};if(t!=null){const o=fx(s.getTrackById(t.id))?.buffer,{descKey:c,type:l}=t.codec.startsWith("avc1")?{descKey:"avcDecoderConfigRecord",type:"avc1"}:t.codec.startsWith("hvc1")?{descKey:"hevcDecoderConfigRecord",type:"hvc1"}:{descKey:"",type:""};c!==""&&(r.videoTrackConf={timescale:t.timescale,duration:t.duration,width:t.video.width,height:t.video.height,brands:e.brands,type:l,[c]:o}),r.videoDecoderConf={codec:t.codec,codedHeight:t.video.height,codedWidth:t.video.width,description:o}}const n=e.audioTracks[0];if(n!=null){const o=px(s),c=o==null?{}:mx(o);r.audioTrackConf={timescale:n.timescale,samplerate:c.sampleRate??n.audio.sample_rate,channel_count:c.numberOfChannels??n.audio.channel_count,hdlr:"soun",type:n.codec.startsWith("mp4a")?"mp4a":n.codec,description:o},r.audioDecoderConf={codec:c.codec??oe.codec,numberOfChannels:c.numberOfChannels??n.audio.channel_count,sampleRate:c.sampleRate??n.audio.sample_rate}}return r}function fx(s){for(const e of s.mdia.minf.stbl.stsd.entries){const t=e.avcC??e.hvcC??e.av1C??e.vpcC;if(t!=null){const r=new ke.DataStream(void 0,0,ke.DataStream.BIG_ENDIAN);return t.write(r),new Uint8Array(r.buffer.slice(8))}}}function px(s,e="mp4a"){return s.moov?.traks.map(r=>r.mdia.minf.stbl.stsd.entries).flat().find(({type:r})=>r===e)?.esds}function mx(s){let e="mp4a";const t=s.esd.descs[0];if(t==null)return{};e+="."+t.oti.toString(16);const r=t.descs[0];if(r==null)return e.endsWith("40")&&(e+=".2"),{codec:e};const n=(r.data[0]&248)>>3;e+="."+n;const[o,c]=r.data,l=((o&7)<<1)+(c>>7),d=(c&127)>>3;return{codec:e,sampleRate:[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][l],numberOfChannels:d}}async function gx(s,e,t){const r=ke.createFile(!1);r.onReady=o=>{e({mp4boxFile:r,info:o});const c=o.videoTracks[0]?.id;c!=null&&r.setExtractionOptions(c,"video",{nbSamples:100});const l=o.audioTracks[0]?.id;l!=null&&r.setExtractionOptions(l,"audio",{nbSamples:100}),r.start()},r.onSamples=t,await n();async function n(){let o=0;const c=30*1024*1024;for(;;){const l=await s.read(c,{at:o});if(l.byteLength===0)break;l.fileStart=o;const d=r.appendBuffer(l);if(d==null)break;o=d}r.stop()}}function vx(s){if(s?.length!==9)return{};const e=new Int32Array(s.buffer),t=e[0]/65536,r=e[1]/65536,n=e[3]/65536,o=e[4]/65536,c=e[6]/65536,l=e[7]/65536,d=e[8]/(1<<30),f=Math.sqrt(t*t+n*n),m=Math.sqrt(r*r+o*o),g=Math.atan2(n,t),_=g*180/Math.PI;return{scaleX:f,scaleY:m,rotationRad:g,rotationDeg:_,translateX:c,translateY:l,perspective:d}}function _x(s,e,t){const r=(Math.round(t/90)*90+360)%360;if(r===0)return d=>d;const n=r===90||r===270?e:s,o=r===90||r===270?s:e,c=new OffscreenCanvas(n,o),l=c.getContext("2d");return l.translate(n/2,o/2),l.rotate(-r*Math.PI/180),l.translate(-s/2,-e/2),d=>{if(d==null)return null;l.drawImage(d,0,0);const f=new VideoFrame(c,{timestamp:d.timestamp,duration:d.duration??void 0});return d.close(),f}}let wo=0;function So(s){return s.kind==="file"&&s.createReader instanceof Function}class fe extends kt{type="Video";insId=wo++;logger=W.create(`VideoClip id:${this.insId},`);ready;_meta={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};get meta(){return{...this._meta}}localFile;headerBoxPos=[];async getFileHeaderBinData(){await this.ready;const e=await this.localFile.getOriginFile();if(e==null)throw Error("VideoClip localFile is not origin file");return await new Blob(this.headerBoxPos.map(({start:t,size:r})=>e.slice(t,t+r))).arrayBuffer()}parsedMatrix={perspective:1,rotationRad:0,rotationDeg:0,scaleX:1,scaleY:1,translateX:0,translateY:0};vfRotater=e=>e;videoSamples=[];audioSamples=[];videoFrameFinder=null;audioFrameFinder=null;decoderConf={video:null,audio:null};opts={audio:!0};audio=!0;id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];static async fromUrl(e,t={}){const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch video from ${e}: ${r.status} ${r.statusText}`);const n=new fe(r.body,{},e);return await n.ready,t.x!==void 0&&(n.left=t.x),t.y!==void 0&&(n.top=t.y),t.width!==void 0&&(n.width=t.width),t.height!==void 0&&(n.height=t.height),n}constructor(e,t={},r){if(super(),this.src=r!==void 0?r:"",!(e instanceof ReadableStream)&&!So(e)&&!Array.isArray(e.videoSamples))throw Error("Illegal argument");this.opts={audio:!0,...t},this.audio=typeof this.opts.audio=="boolean"?this.opts.audio:!0,this.volume=typeof t.audio=="object"&&"volume"in t.audio?t.audio.volume:t.volume??1;const n=async o=>(await Ti(this.localFile,o),this.localFile);this.localFile=So(e)?e:"localFile"in e?e.localFile:vs(),this.ready=(e instanceof ReadableStream?n(e).then(o=>Ku(o,this.opts)):So(e)?Ku(e,this.opts):Promise.resolve(e)).then(async({videoSamples:o,audioSamples:c,decoderConf:l,headerBoxPos:d,parsedMatrix:f})=>{this.videoSamples=o,this.audioSamples=c,this.decoderConf=l,this.headerBoxPos=d,this.parsedMatrix=f;const{videoFrameFinder:m,audioFrameFinder:g}=xx({video:l.video==null?null:{...l.video,hardwareAcceleration:this.opts.__unsafe_hardwareAcceleration__},audio:l.audio},await this.localFile.createReader(),o,c,this.opts.audio!==!1?this.volume:0);this.videoFrameFinder=m,this.audioFrameFinder=g;const{codedWidth:_,codedHeight:y}=l.video??{};_&&y&&(this.vfRotater=_x(_,y,f.rotationDeg)),this._meta=yx(l,o,c,f.rotationDeg),this.logger.info("VideoClip meta:",this._meta);const a={...this._meta};this.width=this.width===0?a.width:this.width,this.height=this.height===0?a.height:this.height,this.trim.to=this.trim.to===0?a.duration:this.trim.to;const h=(this.trim.to-this.trim.from)/this.playbackRate;return this.duration=this.duration===0?h:this.duration,this.display.to=this.display.from+this.duration,this.on("propsChange",u=>{u.volume!==void 0&&this.audioFrameFinder&&this.audioFrameFinder.setVolume(u.volume)}),a})}tickInterceptor=async(e,t)=>t;async tick(e){const t=e+this.trim.from;if(t>=this.trim.to||t>=this._meta.duration)return await this.tickInterceptor(e,{audio:await this.audioFrameFinder?.find(t)??[],state:"done"});const[r,n]=await Promise.all([this.audioFrameFinder?.find(t)??[],this.videoFrameFinder?.find(t).then(this.vfRotater)]);return n==null?await this.tickInterceptor(e,{audio:r,state:"success"}):await this.tickInterceptor(e,{video:n,audio:r,state:"success"})}async split(e){if(await this.ready,e<=0||e>=this._meta.duration)throw Error("time out of bounds");const[t,r]=Ex(this.videoSamples,e),[n,o]=Ix(this.audioSamples,e),c=new fe({localFile:this.localFile,videoSamples:t??[],audioSamples:n??[],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src),l=new fe({localFile:this.localFile,videoSamples:r??[],audioSamples:o??[],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);return await Promise.all([c.ready,l.ready]),[c,l]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=new fe({localFile:this.localFile,videoSamples:[...this.videoSamples],audioSamples:[...this.audioSamples],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);return await e.ready,e.tickInterceptor=this.tickInterceptor,this.copyStateTo(e),e.id=this.id,e.effects=[...this.effects],e}async splitTrack(){await this.ready;const e=[];if(this.videoSamples.length>0){const t=new fe({localFile:this.localFile,videoSamples:[...this.videoSamples],audioSamples:[],decoderConf:{video:this.decoderConf.video,audio:null},headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);await t.ready,t.tickInterceptor=this.tickInterceptor,e.push(t)}if(this.audioSamples.length>0){const t=new fe({localFile:this.localFile,videoSamples:[],audioSamples:[...this.audioSamples],decoderConf:{audio:this.decoderConf.audio,video:null},headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);await t.ready,t.tickInterceptor=this.tickInterceptor,e.push(t)}return e}destroy(){this.destroyed||(this.destroyed=!0,this.logger.info("VideoClip destroy"),super.destroy(),this.videoFrameFinder?.destroy(),this.audioFrameFinder?.destroy())}toJSON(e=!1){return{...super.toJSON(e),type:"Video",audio:this.audio,volume:this.volume,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Video")throw new Error(`Expected Video, got ${e.type}`);const t=await fetch(e.src);if(!t.ok)throw new Error(`Failed to fetch video from ${e.src}: ${t.status} ${t.statusText}. Make sure the file exists in the public directory.`);const r=e.audio!==void 0?{audio:e.audio,volume:e.volume}:{volume:e.volume},n=new fe(t.body,r,e.src);return await n.ready,n.left=e.left,n.top=e.top,n.width=e.width,n.height=e.height,n.angle=e.angle,n.display.from=e.display.from,n.display.to=e.display.to,n.duration=e.duration,n.playbackRate=e.playbackRate,n.zIndex=e.zIndex,n.opacity=e.opacity,n.flip=e.flip,e.animation&&n.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(n.id=e.id),e.effects&&(n.effects=e.effects),e.transition&&(n.transition=e.transition),e.trim&&(n.trim.from=e.trim.from<1e6?e.trim.from*1e6:e.trim.from,n.trim.to=e.trim.to<1e6?e.trim.to*1e6:e.trim.to),e.volume!==void 0&&(n.volume=e.volume),n}async createPlaybackElement(){await this.ready;const t=this.localFile;if(!t||typeof t.getOriginFile!="function")throw new Error("VideoClip does not have a local file for playback");const r=await t.getOriginFile();if(!r)throw new Error("Failed to get origin file from VideoClip");const n=URL.createObjectURL(r),o=document.createElement("video");return o.crossOrigin="anonymous",o.muted=!0,o.autoplay=!1,o.playsInline=!0,o.preload="auto",o.loop=!1,o.src=n,await new Promise((c,l)=>{const d=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",f),o.pause(),o.currentTime=0,c()},f=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",f),l(new Error("Failed to load video"))};o.addEventListener("loadeddata",d,{once:!0}),o.addEventListener("error",f,{once:!0}),o.load()}),{element:o,objectUrl:n}}async play(e,t){const r=e,n=t+this.trim.from/1e6;if(Math.abs(r.currentTime-n)>.1&&(r.currentTime=n),r.muted=!1,r.paused)try{await r.play()}catch{try{await r.play()}catch(c){console.warn("Failed to play video:",c)}}}pause(e){const t=e;t.pause(),t.muted=!0}async seek(e,t){const r=e,n=t+this.trim.from/1e6;return r.pause(),r.currentTime=n,new Promise(o=>{if(Math.abs(r.currentTime-t)<.01){o();return}const c=()=>{r.removeEventListener("seeked",c),o()};r.addEventListener("seeked",c,{once:!0}),setTimeout(()=>{r.removeEventListener("seeked",c),o()},500)})}syncPlayback(e,t,r){const n=e,o=(this.trim.to-this.trim.from)/1e6,c=r>=0&&r<o,l=r+this.trim.from/1e6;n.volume=this.volume,t&&c?n.paused?this.play(n,r).catch(console.warn):(n.muted&&(n.muted=!1),(n.ended||n.currentTime>=this.trim.to/1e6)&&(n.currentTime=l,n.play().catch(console.warn))):(n.paused||n.pause(),n.muted=!0,c&&Math.abs(n.currentTime-l)>.1&&(n.currentTime=l))}cleanupPlayback(e,t){const r=e;r.pause(),r.removeAttribute("src"),r.load(),t&&URL.revokeObjectURL(t)}async scaleToFit(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.min(e/r,t/n);this.width=r*o,this.height=n*o}async scaleToFill(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.max(e/r,t/n);this.width=r*o,this.height=n*o}centerInScene(e,t){this.left=(e-this.width)/2,this.top=(t-this.height)/2}}function yx(s,e,t,r){const n={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};if(s.video!=null&&e.length>0){n.width=s.video.codedWidth??0,n.height=s.video.codedHeight??0;const l=(Math.round(r/90)*90+360)%360;(l===90||l===270)&&([n.width,n.height]=[n.height,n.width])}s.audio!=null&&t.length>0&&(n.audioSampleRate=oe.sampleRate,n.audioChanCount=oe.channelCount);let o=0,c=0;if(e.length>0)for(let l=e.length-1;l>=0;l--){const d=e[l];if(!d.deleted){o=d.cts+d.duration;break}}if(t.length>0){const l=t.at(-1);c=l.cts+l.duration}return n.duration=Math.max(o,c),n}function xx(s,e,t,r,n){return{audioFrameFinder:n===0||s.audio==null||r.length===0?null:new wx(e,r,s.audio,{volume:n,targetSampleRate:oe.sampleRate}),videoFrameFinder:s.video==null||t.length===0?null:new bx(e,t,s.video)}}async function Ku(s,e={}){let t=null;const r={video:null,audio:null};let n=[],o=[],c=[];const l={perspective:1,rotationRad:0,rotationDeg:0,scaleX:1,scaleY:1,translateX:0,translateY:0};let d=-1,f=-1;const m=await s.createReader();await gx(m,async _=>{t=_.info;const y=_.mp4boxFile.ftyp;c.push({start:y.start,size:y.size});const a=_.mp4boxFile.moov;c.push({start:a.start,size:a.size}),Object.assign(l,vx(t.videoTracks[0]?.matrix));let{videoDecoderConf:h,audioDecoderConf:u}=To(_.mp4boxFile,_.info);if(r.video=h??null,r.audio=u??null,h==null&&u==null&&W.error("VideoClip no video and audio track"),u!=null){const{supported:p}=await AudioDecoder.isConfigSupported(u);p||W.error(`VideoClip audio codec is not supported: ${u.codec}`)}if(h!=null){const{supported:p}=await VideoDecoder.isConfigSupported(h);p||W.error(`VideoClip video codec is not supported: ${h.codec}`)}W.info("mp4BoxFile moov ready",{..._.info,tracks:null,videoTracks:null,audioTracks:null},r)},(_,y,a)=>{if(y==="video"){d===-1&&(d=a[0].dts);for(const h of a)n.push(ju(h,d,"video"))}else if(y==="audio"&&e.audio){f===-1&&(f=a[0].dts);for(const h of a)o.push(ju(h,f,"audio"))}}),await m.close();const g=n.at(-1)??o.at(-1);if(t==null)throw Error("VideoClip stream is done, but not emit ready");if(g==null)throw Error("VideoClip stream not contain any sample");return Co(n),W.info("mp4 stream parsed"),{videoSamples:n,audioSamples:o,decoderConf:r,headerBoxPos:c,parsedMatrix:l}}function ju(s,e=0,t){let r=s.offset;const n=t==="video"&&s.is_sync?Rx(s.data,s.description.type):-1;let o=s.size;return n>0&&(r+=n,o-=n),{...s,is_idr:n>=0,offset:r,size:o,cts:(s.cts-e)/s.timescale*1e6,dts:(s.dts-e)/s.timescale*1e6,duration:s.duration/s.timescale*1e6,timescale:1e6,data:t==="video"?null:s.data}}class bx{constructor(e,t,r){this.localFileReader=e,this.samples=t,this.conf=r}decoder=null;timestamp=0;curAborter={abort:!1,st:performance.now()};find=async e=>{(this.decoder==null||this.decoder.state==="closed"||e<=this.timestamp||e-this.timestamp>3e6)&&this.reset(e),this.curAborter.abort=!0,this.timestamp=e,this.curAborter={abort:!1,st:performance.now()};const t=await this.parseFrame(e,this.decoder,this.curAborter);return this.sleepCnt=0,t};lastVfDur=0;downgradeSoftDecode=!1;videoDecCursorIdx=0;videoFrames=[];outputFrameCnt=0;inputChunkCnt=0;sleepCnt=0;predecodeErr=!1;parseFrame=async(e,t,r)=>{if(t==null||t.state==="closed"||r.abort)return null;if(this.videoFrames.length>0){const n=this.videoFrames[0];return e<n.timestamp?null:(this.videoFrames.shift(),e>n.timestamp+(n.duration??0)?(n.close(),await this.parseFrame(e,t,r)):(!this.predecodeErr&&this.videoFrames.length<10&&this.startDecode(t).catch(o=>{throw this.predecodeErr=!0,this.reset(e),o}),n))}if(this.decoding||this.outputFrameCnt<this.inputChunkCnt&&t.decodeQueueSize>0){if(performance.now()-r.st>6e3)throw Error(`VideoClip.tick video timeout, ${JSON.stringify(this.getState())}`);this.sleepCnt+=1,await ws(15)}else{if(this.videoDecCursorIdx>=this.samples.length)return null;try{await this.startDecode(t)}catch(n){throw this.reset(e),n}}return await this.parseFrame(e,t,r)};decoding=!1;startDecode=async e=>{if(this.decoding||e.decodeQueueSize>600)return;let t=this.videoDecCursorIdx+1;if(t>this.samples.length)return;this.decoding=!0;let r=!1;for(;t<this.samples.length;t++){const n=this.samples[t];if(!r&&!n.deleted&&(r=!0),n.is_idr)break}if(r){const n=this.samples.slice(this.videoDecCursorIdx,t);if(n[0]?.is_idr!==!0)W.warn("First sample not idr frame");else{const o=performance.now(),c=await Ax(n,this.localFileReader),l=performance.now()-o;if(l>1e3){const d=n[0],f=n.at(-1),m=f.offset+f.size-d.offset;W.warn(`Read video samples time cost: ${Math.round(l)}ms, file chunk size: ${m}`)}if(e.state==="closed")return;this.lastVfDur=c[0]?.duration??0,Px(e,c,{onDecodingError:d=>{if(this.downgradeSoftDecode)throw d;this.outputFrameCnt===0&&(this.downgradeSoftDecode=!0,W.warn("Downgrade to software decode"),this.reset())}}),this.inputChunkCnt+=c.length}}this.videoDecCursorIdx=t,this.decoding=!1};reset=e=>{if(this.decoding=!1,this.videoFrames.forEach(r=>r.close()),this.videoFrames=[],e==null||e===0)this.videoDecCursorIdx=0;else{let r=0;for(let n=0;n<this.samples.length;n++){const o=this.samples[n];if(o.is_idr&&(r=n),!(o.cts<e)){this.videoDecCursorIdx=r;break}}}this.inputChunkCnt=0,this.outputFrameCnt=0,this.decoder?.state!=="closed"&&this.decoder?.close();const t={...this.conf,...this.downgradeSoftDecode?{hardwareAcceleration:"prefer-software"}:{}};this.decoder=new VideoDecoder({output:r=>{if(this.outputFrameCnt+=1,r.timestamp===-1){r.close();return}let n=r;r.duration==null&&(n=new VideoFrame(r,{duration:this.lastVfDur}),r.close()),this.videoFrames.push(n)},error:r=>{if(r.message.includes("Codec reclaimed due to inactivity")){this.decoder=null,W.warn(r.message);return}const n=`VideoFinder VideoDecoder err: ${r.message}, config: ${JSON.stringify(t)}, state: ${JSON.stringify(this.getState())}`;throw W.error(n),Error(n)}}),this.decoder.configure(t)};getState=()=>({time:this.timestamp,decState:this.decoder?.state,decQSize:this.decoder?.decodeQueueSize,decCursorIdx:this.videoDecCursorIdx,sampleLen:this.samples.length,inputCnt:this.inputChunkCnt,outputCnt:this.outputFrameCnt,cacheFrameLen:this.videoFrames.length,softDecode:this.downgradeSoftDecode,clipIdCnt:wo,sleepCnt:this.sleepCnt,memInfo:Ju()});destroy=()=>{this.decoder?.state!=="closed"&&this.decoder?.close(),this.decoder=null,this.curAborter.abort=!0,this.videoFrames.forEach(e=>e.close()),this.videoFrames=[],this.localFileReader.close()}}function Tx(s,e){for(let t=0;t<e.length;t++){const r=e[t];if(s>=r.cts&&s<r.cts+r.duration)return t;if(r.cts>s)break}return 0}class wx{constructor(e,t,r,n){this.localFileReader=e,this.samples=t,this.conf=r,this.volume=n.volume,this.sampleRate=n.targetSampleRate}volume=1;sampleRate;setVolume(e){this.volume=e,this.reset()}decoder=null;curAborter={abort:!1,st:performance.now()};find=async e=>{const t=e<=this.timestamp||e-this.timestamp>1e5;(this.decoder==null||this.decoder.state==="closed"||t)&&this.reset(),t&&(this.timestamp=e,this.decCursorIdx=Tx(e,this.samples)),this.curAborter.abort=!0;const r=e-this.timestamp;this.timestamp=e,this.curAborter={abort:!1,st:performance.now()};const n=await this.parseFrame(Math.ceil(r*(this.sampleRate/1e6)),this.decoder,this.curAborter);return this.sleepCnt=0,n};timestamp=0;decCursorIdx=0;pcmData={frameCnt:0,data:[]};sleepCnt=0;parseFrame=async(e,t=null,r)=>{if(t==null||r.abort||t.state==="closed"||e===0)return[];const n=this.pcmData.frameCnt-e;if(n>0)return n<oe.sampleRate/10&&this.startDecode(t),Zu(this.pcmData,e);if(t.decoding){if(performance.now()-r.st>3e3)throw r.abort=!0,Error(`VideoClip.tick audio timeout, ${JSON.stringify(this.getState())}`);this.sleepCnt+=1,await ws(15)}else{if(this.decCursorIdx>=this.samples.length-1)return Zu(this.pcmData,this.pcmData.frameCnt);this.startDecode(t)}return this.parseFrame(e,t,r)};startDecode=e=>{if(e.decodeQueueSize>10)return;const r=[];let n=this.decCursorIdx;for(;n<this.samples.length;){const o=this.samples[n];if(n+=1,!o.deleted&&(r.push(o),r.length>=10))break}this.decCursorIdx=n,e.decode(r.map(o=>new EncodedAudioChunk({type:"key",timestamp:o.cts,duration:o.duration,data:o.data})))};reset=()=>{this.timestamp=0,this.decCursorIdx=0,this.pcmData={frameCnt:0,data:[]},this.decoder?.close(),this.decoder=Sx(this.conf,{resampleRate:oe.sampleRate,volume:this.volume},e=>{this.pcmData.data.push(e),this.pcmData.frameCnt+=e[0].length})};getState=()=>({time:this.timestamp,decState:this.decoder?.state,decQSize:this.decoder?.decodeQueueSize,decCursorIdx:this.decCursorIdx,sampleLen:this.samples.length,pcmLen:this.pcmData.frameCnt,clipIdCnt:wo,sleepCnt:this.sleepCnt,memInfo:Ju()});destroy=()=>{this.decoder=null,this.curAborter.abort=!0,this.pcmData={frameCnt:0,data:[]},this.localFileReader.close()}}function Sx(s,e,t){let r=0,n=0;const o=m=>{if(n+=1,m.length!==0){if(e.volume!==1)for(const g of m)for(let _=0;_<g.length;_++)g[_]*=e.volume;m.length===1&&(m=[m[0],m[0]]),t(m)}},c=Cx(o),l=e.resampleRate!==s.sampleRate;let d=new AudioDecoder({output:m=>{const g=ia(m);l?c(()=>bf(g,m.sampleRate,{rate:e.resampleRate,chanCount:m.numberOfChannels})):o(g),m.close()},error:m=>{m.message.includes("Codec reclaimed due to inactivity")||f("VideoClip AudioDecoder err",m)}});d.configure(s);function f(m,g){const _=`${m}: ${g.message}, state: ${JSON.stringify({qSize:d.decodeQueueSize,state:d.state,inputCnt:r,outputCnt:n})}`;throw W.error(_),Error(_)}return{decode(m){r+=m.length;try{for(const g of m)d.decode(g)}catch(g){f("decode audio chunk error",g)}},close(){d.state!=="closed"&&d.close()},get decoding(){return r>n&&d.decodeQueueSize>0},get state(){return d.state},get decodeQueueSize(){return d.decodeQueueSize}}}function Cx(s){const e=[];let t=0;function r(c,l){e[l]=c,n()}function n(){const c=e[t];c!=null&&(s(c),t+=1,n())}let o=0;return c=>{const l=o;o+=1,c().then(d=>r(d,l)).catch(d=>r(d,l))}}function Zu(s,e){const t=[new Float32Array(e),new Float32Array(e)];let r=0,n=0;for(;n<s.data.length;){const[o,c]=s.data[n];if(r+o.length>e){const l=e-r;t[0].set(o.subarray(0,l),r),t[1].set(c.subarray(0,l),r),s.data[n][0]=o.subarray(l,o.length),s.data[n][1]=c.subarray(l,c.length);break}else t[0].set(o,r),t[1].set(c,r),r+=o.length,n++}return s.data=s.data.slice(n),s.frameCnt-=e,t}async function Ax(s,e){const t=s[0],r=s.at(-1);if(r==null)return[];const n=r.offset+r.size-t.offset;if(n<3e7){const o=new Uint8Array(await e.read(n,{at:t.offset}));return s.map(c=>{const l=c.offset-t.offset;return new EncodedVideoChunk({type:c.is_sync?"key":"delta",timestamp:c.cts,duration:c.duration,data:o.subarray(l,l+c.size)})})}return await Promise.all(s.map(async o=>new EncodedVideoChunk({type:o.is_sync?"key":"delta",timestamp:o.cts,duration:o.duration,data:await e.read(o.size,{at:o.offset})})))}function Ex(s,e){if(s.length===0)return[];let t=0,r=0,n=-1;for(let d=0;d<s.length;d++){const f=s[d];if(n===-1&&e<f.cts&&(n=d-1),f.is_idr)if(n===-1)t=d;else{r=d;break}}const o=s[n];if(o==null)throw Error("Not found video sample by time");const c=s.slice(0,r===0?s.length:r).map(d=>({...d}));for(let d=t;d<c.length;d++){const f=c[d];e<f.cts&&(f.deleted=!0,f.cts=-1)}Co(c);const l=s.slice(o.is_idr?n:t).map(d=>({...d,cts:d.cts-e}));for(const d of l)d.cts<0&&(d.deleted=!0,d.cts=-1);return Co(l),[c,l]}function Ix(s,e){if(s.length===0)return[];let t=-1;for(let o=0;o<s.length;o++){const c=s[o];if(!(e>c.cts)){t=o;break}}if(t===-1)throw Error("Not found audio sample by time");const r=s.slice(0,t).map(o=>({...o})),n=s.slice(t).map(o=>({...o,cts:o.cts-e}));return[r,n]}function Px(s,e,t){if(s.state==="configured"){for(let r=0;r<e.length;r++)s.decode(e[r]);s.flush().catch(r=>{if(!(r instanceof Error))throw r;if(r.message.includes("Decoding error")&&t.onDecodingError!=null){t.onDecodingError(r);return}if(!r.message.includes("Aborted due to close"))throw r})}}function Rx(s,e){if(e!=="avc1"&&e!=="hvc1")return 0;const t=new DataView(s.buffer);for(let r=0;r<s.byteLength-4;){if(e==="avc1"){const n=t.getUint8(r+4)&31;if(n===5||n===7||n===8)return r}else if(e==="hvc1"){const n=t.getUint8(r+4)>>1&63;if(n===19||n===20||n===32||n===33||n===34)return r}r+=t.getUint32(r)+4}return-1}function Co(s){let e=0,t=null;for(const r of s)if(!r.deleted){if(r.is_sync&&(e+=1),e>=2)break;(t==null||r.cts<t.cts)&&(t=r)}t!=null&&t.cts<2e5&&(t.duration+=t.cts,t.cts=0)}function Ju(){try{const s=performance.memory;return{jsHeapSizeLimit:s.jsHeapSizeLimit,totalJSHeapSize:s.totalJSHeapSize,usedJSHeapSize:s.usedJSHeapSize,percentUsed:(s.usedJSHeapSize/s.jsHeapSizeLimit).toFixed(3),percentTotal:(s.totalJSHeapSize/s.jsHeapSizeLimit).toFixed(3)}}catch{return{}}}class Ze extends kt{type="Text";ready;_meta={duration:1/0,width:0,height:0};get meta(){return{...this._meta}}get width(){return this._width}set width(e){this.width!==e&&(this._width=e,this.refreshText(),this.emit("propsChange",{width:e}))}get height(){return this._height}set height(e){this.height!==e&&(this._height=e,this.refreshText(),this.emit("propsChange",{height:e}))}_text="";get text(){return this._text}set text(e){this._text!==e&&(this._text=e,this.originalOpts&&this.textStyle&&this.refreshText())}get style(){return{fontSize:this.originalOpts.fontSize,fontFamily:this.originalOpts.fontFamily,fontWeight:this.originalOpts.fontWeight,fontStyle:this.originalOpts.fontStyle,fill:this.originalOpts.fill,align:this.originalOpts.align,stroke:this.originalOpts.stroke?typeof this.originalOpts.stroke=="object"?{color:this.originalOpts.stroke.color,width:this.originalOpts.stroke.width,join:this.originalOpts.stroke.join,cap:this.originalOpts.stroke.cap,miterLimit:this.originalOpts.stroke.miterLimit}:{color:this.originalOpts.stroke,width:this.originalOpts.strokeWidth??0}:void 0,dropShadow:this.originalOpts.dropShadow?{color:this.originalOpts.dropShadow.color??"#000000",alpha:this.originalOpts.dropShadow.alpha??.5,blur:this.originalOpts.dropShadow.blur??4,distance:this.originalOpts.dropShadow.distance??0,angle:this.originalOpts.dropShadow.angle??0}:void 0,wordWrap:this.originalOpts.wordWrap,wordWrapWidth:this.originalOpts.wordWrapWidth,lineHeight:this.originalOpts.lineHeight,letterSpacing:this.originalOpts.letterSpacing,textCase:this.originalOpts.textCase,textDecoration:this.originalOpts.textDecoration}}set style(e){this.updateStyle(e)}get textAlign(){return this.originalOpts.align||this.originalOpts.textAlign||"left"}set textAlign(e){this.updateStyle({align:e})}get verticalAlign(){return this.originalOpts.verticalAlign||this.originalOpts.textDecoration||"top"}set verticalAlign(e){["underline","overline","strikethrough","line-through"].includes(e)?(this.updateStyle({textDecoration:e==="strikethrough"?"line-through":e}),this.originalOpts.verticalAlign=e):this.updateStyle({verticalAlign:e})}get textCase(){return this.originalOpts.textCase||"none"}set textCase(e){this.updateStyle({textCase:e})}pixiText=null;textStyle;renderTexture=null;externalRenderer=null;pixiApp=null;originalOpts;id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];constructor(e,t={},r){super(),this.originalOpts={...t},this.text=e,this.externalRenderer=r??null,console.log("[TextClip] Constructor:",{opts:t});const n=this.createStyleFromOpts(t),o=new Be(n);this.textStyle=o,this.ready=(async()=>{await this.refreshText();const c={...this._meta};return W.info("TextClip ready:",c),c})()}setRenderer(e){this.externalRenderer=e,console.log("SET RENDERER",e)}async getRenderer(){if(this.externalRenderer!=null)return this.externalRenderer;if(this.pixiApp?.renderer==null)throw new Error("TextClip: Failed to create renderer. Please provide a renderer via constructor or setRenderer() method.");return this.pixiApp.renderer}async getTexture(){return this.pixiText==null||this.renderTexture==null?null:((await this.getRenderer()).render({container:this.pixiText,target:this.renderTexture}),this.renderTexture)}async tick(e){if(await this.ready,this.pixiText==null||this.renderTexture==null)throw new Error("TextClip not initialized");if(this.renderTexture.width<=0||this.renderTexture.height<=0)throw new Error(`Invalid RenderTexture dimensions: ${this.renderTexture.width}x${this.renderTexture.height}`);(await this.getRenderer()).render({container:this.pixiText,target:this.renderTexture});const r=this.renderTexture.source?.resource?.source;let n;if(r instanceof HTMLCanvasElement)n=await createImageBitmap(r);else if(r instanceof OffscreenCanvas)n=await createImageBitmap(r);else{const l=(await this.getRenderer()).extract.canvas(this.renderTexture);if(l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas)n=await createImageBitmap(l);else{const d=this.renderTexture.width,f=this.renderTexture.height;throw new OffscreenCanvas(d,f).getContext("2d")==null?new Error("Failed to create 2d context for fallback rendering"):new Error("Unable to extract canvas from render texture")}}return{video:n,state:"success"}}async split(e){await this.ready;const t=await this.clone(),r=await this.clone();return[t,r]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=this.textStyle,t=this.originalOpts||{},r=c=>{if(c!=null){if(typeof c=="number")return c;if(c instanceof le)return c.toNumber()}},n={fontSize:t.fontSize??e.fontSize,fontFamily:t.fontFamily??(Array.isArray(e.fontFamily)?e.fontFamily[0]:typeof e.fontFamily=="string"?e.fontFamily:"Roboto"),fontWeight:t.fontWeight??e.fontWeight,fontStyle:t.fontStyle??e.fontStyle,align:t.align??(e.align==="justify"?"left":e.align),textCase:t.textCase,textDecoration:t.textDecoration};if(t.fill&&typeof t.fill=="object"&&"type"in t.fill&&t.fill.type==="gradient")n.fill=t.fill;else{const c=r(e.fill);n.fill=c??16777215}if(t.stroke&&typeof t.stroke=="object"&&"color"in t.stroke)n.stroke=t.stroke;else{const c=r(e.stroke);c!==void 0&&(n.stroke=c),n.strokeWidth=t.strokeWidth??e.strokeThickness??0}if(t.dropShadow)n.dropShadow=t.dropShadow;else if(e.dropShadow){const c=e.dropShadow,l=r(c.color);l!==void 0&&(n.dropShadow={color:l,alpha:c.alpha,blur:c.blur,angle:c.angle,distance:c.distance})}if(t.wordWrap!==void 0?(n.wordWrap=t.wordWrap,n.wordWrapWidth=t.wordWrapWidth):e.wordWrap&&(n.wordWrap=e.wordWrap,n.wordWrapWidth=e.wordWrapWidth),t.lineHeight!==void 0)n.lineHeight=t.lineHeight;else if(e.lineHeight!==void 0){const c=n.fontSize??e.fontSize??40;n.lineHeight=e.lineHeight/c}t.letterSpacing!==void 0?n.letterSpacing=t.letterSpacing:e.letterSpacing!==void 0&&(n.letterSpacing=e.letterSpacing);const o=new Ze(this.text,n);return await o.ready,this.copyStateTo(o),o.id=this.id,o.effects=[...this.effects],o}async updateStyle(e){this.originalOpts={...this.originalOpts,...e};const t=this.createStyleFromOpts(this.originalOpts),r=new Be(t);this.textStyle=r,await this.refreshText()}async refreshText(){const e=this.textStyle;let t=this.text;const r=this.originalOpts.textCase;r==="uppercase"?t=t.toUpperCase():r==="lowercase"?t=t.toLowerCase():r==="title"&&(t=t.replace(/\w\S*/g,y=>y.charAt(0).toUpperCase()+y.substring(1).toLowerCase())),this.pixiText?(this.pixiText.text=t,this.pixiText.style=e,this.pixiText.children.forEach(y=>{y instanceof Ce&&y.destroy()}),this.pixiText.removeChildren()):this.pixiText=new Nv({text:t,style:e});const n=this.originalOpts.textDecoration||this.originalOpts.verticalAlign;if(n&&n!=="none"&&["underline","overline","strikethrough","line-through"].includes(n)){const y=n==="strikethrough"?"line-through":n,a=He.measureText(t,e),h=e.fontSize??40,u=Math.max(1,h/12);let p=16777215;typeof e.fill=="number"?p=e.fill:e.fill&&typeof e.fill=="object"&&"fill"in e.fill&&(p=16777215);const v=new Ce,x=e.lineHeight??a.lineHeight;for(let b=0;b<a.lines.length;b++){const T=a.lineWidths[b];let w=0;e.align==="center"?w=(a.maxLineWidth-T)/2:e.align==="right"&&(w=a.maxLineWidth-T);const S=b*x;let E=0;y==="underline"?E=x:y==="line-through"?E=x/2:y==="overline"&&(E=0);const A=S+E;v.rect(w,A,T,u),v.fill(p)}this.pixiText.addChild(v)}const o=this.pixiText.getLocalBounds(),c=Math.ceil(o.width||this.pixiText.width||1),l=Math.ceil(o.height||this.pixiText.height||1);let d=Math.max(1,c);e.wordWrap&&e.wordWrapWidth>0&&(d=Math.max(d,e.wordWrapWidth));const f=Math.max(d,this.width||0),m=Math.max(l,this.height||0),g=this.textAlign;g==="center"?this.pixiText.x=(f-c)/2:g==="right"?this.pixiText.x=f-c:this.pixiText.x=0;const _=this.originalOpts.verticalAlign||"top";_==="center"?this.pixiText.y=(m-l)/2:_==="bottom"?this.pixiText.y=m-l:this.pixiText.y=0,this.renderTexture&&this.renderTexture.destroy(!0),this.renderTexture=Ae.create({width:f,height:m}),this._meta.width=f,this._meta.height=m,this._width=f,this._height=m,this.duration===0&&this._meta.duration!==1/0&&(this.duration=this._meta.duration,this.display.to=this.display.from+this.duration)}createStyleFromOpts(e){const t=e.fontSize??40,r=e.lineHeight??1,n={fontSize:t,fontFamily:e.fontFamily??"Roboto",fontWeight:e.fontWeight??"normal",fontStyle:e.fontStyle??"normal",align:e.align??"left",wordWrap:e.wordWrap??!1,wordWrapWidth:e.wordWrapWidth??100,lineHeight:t*r,letterSpacing:e.letterSpacing??0};if(e.fill&&typeof e.fill=="object"&&e.fill.type==="gradient"){const o=new Ke(e.fill.x0,e.fill.y0,e.fill.x1,e.fill.y1);e.fill.colors.forEach(({ratio:c,color:l})=>{const d=typeof l=="number"?l:Ee(l)??16777215;o.addColorStop(c,d)}),n.fill={fill:o}}else{const{color:o,alpha:c}=Vt(e.fill);n.fill=o,c<1&&(n.fillAlpha=c)}if(e.stroke&&typeof e.stroke=="object"&&"color"in e.stroke){const o=Ee(e.stroke.color);o!==void 0&&(n.stroke={color:o,width:e.stroke.width},e.stroke.join&&(n.stroke.join=e.stroke.join),e.stroke.cap&&(n.stroke.cap=e.stroke.cap),e.stroke.miterLimit&&(n.stroke.miterLimit=e.stroke.miterLimit))}else{const o=Ee(e.stroke),c=e.strokeWidth??0;o!==void 0&&c>0?n.stroke={color:o,width:c}:e.strokeWidth&&e.strokeWidth>0&&(n.stroke={color:0,width:e.strokeWidth})}if(e.dropShadow){const o=Ee(e.dropShadow.color);o!==void 0&&(n.dropShadow={color:o,alpha:e.dropShadow.alpha??.5,blur:e.dropShadow.blur??4,angle:e.dropShadow.angle??Math.PI/6,distance:e.dropShadow.distance??2})}return n}destroy(){if(!this.destroyed){W.info("TextClip destroy");try{this.pixiText!=null&&this.pixiText.destroyed!==!0&&this.pixiText.destroy({children:!0})}catch{}finally{this.pixiText=null}try{this.renderTexture!=null&&this.renderTexture.destroyed!==!0&&this.renderTexture.destroy(!0)}catch{}finally{this.renderTexture=null}if(this.externalRenderer=null,this.pixiApp!=null)try{const e=this.pixiApp;e.destroyed!==!0&&e.renderer!=null&&this.pixiApp.destroy(!0,{children:!0,texture:!0})}catch{}finally{this.pixiApp=null}super.destroy()}}toJSON(e=!1){const t=super.toJSON(e),r={};return this.originalOpts.fontSize!==void 0&&(r.fontSize=this.originalOpts.fontSize),this.originalOpts.fontFamily!==void 0&&(r.fontFamily=this.originalOpts.fontFamily),this.originalOpts.fontWeight!==void 0&&(r.fontWeight=this.originalOpts.fontWeight),this.originalOpts.fontStyle!==void 0&&(r.fontStyle=this.originalOpts.fontStyle),this.originalOpts.fill!==void 0&&(r.color=this.originalOpts.fill),this.originalOpts.align!==void 0&&(r.align=this.originalOpts.align),this.originalOpts.wordWrap!==void 0&&(r.wordWrap=this.originalOpts.wordWrap),this.originalOpts.wordWrapWidth!==void 0&&(r.wordWrapWidth=this.originalOpts.wordWrapWidth),this.originalOpts.lineHeight!==void 0&&(r.lineHeight=this.originalOpts.lineHeight),this.originalOpts.letterSpacing!==void 0&&(r.letterSpacing=this.originalOpts.letterSpacing),this.originalOpts.stroke&&(typeof this.originalOpts.stroke=="object"?r.stroke={color:this.originalOpts.stroke.color,width:this.originalOpts.stroke.width,join:this.originalOpts.stroke.join,cap:this.originalOpts.stroke.cap,miterLimit:this.originalOpts.stroke.miterLimit}:r.stroke={color:this.originalOpts.stroke,width:this.originalOpts.strokeWidth??0}),this.originalOpts.dropShadow&&(r.shadow={color:this.originalOpts.dropShadow.color??"#000000",alpha:this.originalOpts.dropShadow.alpha??.5,blur:this.originalOpts.dropShadow.blur??4,distance:this.originalOpts.dropShadow.distance??0,angle:this.originalOpts.dropShadow.angle??0}),{...t,type:"Text",text:this.text,style:r,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Text")throw new Error(`Expected Text, got ${e.type}`);const t=e.text||"",r=e.style||{},n={};r.fontSize!==void 0&&(n.fontSize=r.fontSize),r.fontFamily!==void 0&&(n.fontFamily=r.fontFamily),r.fontWeight!==void 0&&(n.fontWeight=r.fontWeight),r.fontStyle!==void 0&&(n.fontStyle=r.fontStyle),r.color!==void 0&&(n.fill=r.color),r.align!==void 0&&(n.align=r.align),r.wordWrap!==void 0&&(n.wordWrap=r.wordWrap),r.wordWrapWidth!==void 0&&(n.wordWrapWidth=r.wordWrapWidth),r.lineHeight!==void 0&&(n.lineHeight=r.lineHeight),r.letterSpacing!==void 0&&(n.letterSpacing=r.letterSpacing),r.stroke&&(r.stroke.join||r.stroke.cap||r.stroke.miterLimit!==void 0?n.stroke={color:r.stroke.color,width:r.stroke.width,join:r.stroke.join,cap:r.stroke.cap,miterLimit:r.stroke.miterLimit}:(n.stroke=r.stroke.color,n.strokeWidth=r.stroke.width)),r.shadow&&(n.dropShadow={color:r.shadow.color,alpha:r.shadow.alpha,blur:r.shadow.blur,distance:r.shadow.distance,angle:r.shadow.angle});const o=new Ze(t,n);return o.left=e.left,o.top=e.top,o.width=e.width,o.height=e.height,o.angle=e.angle,o.display.from=e.display.from,o.display.to=e.display.to,o.duration=e.duration,o.playbackRate=e.playbackRate,o.zIndex=e.zIndex,o.opacity=e.opacity,o.flip=e.flip,e.animation&&o.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(o.id=e.id),e.effects&&(o.effects=e.effects),await o.ready,o}}class Je extends kt{type="Effect";ready;_meta={duration:5e6,width:0,height:0};get meta(){return{...this._meta}}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effect;constructor(e){super(),this.effect={id:`eff_${Date.now()}`,key:e,name:e},this.ready=Promise.resolve(this._meta),this.duration=this._meta.duration}async clone(){const e=new Je(this.effect.key);return this.copyStateTo(e),e.id=this.id,e}async tick(e){return{video:void 0,state:"success"}}async split(e){const t=await this.clone(),r=await this.clone();return[t,r]}toJSON(e=!1){return{...super.toJSON(e),type:"Effect",effect:this.effect,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Effect")throw new Error(`Expected Effect, got ${e.type}`);const t=new Je(e.effect.key);return t.effect=e.effect,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),await t.ready,t}}class pi extends kt{type="Transition";ready;_meta={duration:2e6,width:0,height:0};get meta(){return{...this._meta}}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;transitionEffect;fromClipId=null;toClipId=null;constructor(e){super(),this.transitionEffect={id:`trans_${Date.now()}`,key:e,name:e},this.ready=Promise.resolve(this._meta),this.duration=this._meta.duration}async clone(){const e=new pi(this.transitionEffect.key);return this.copyStateTo(e),e.fromClipId=this.fromClipId,e.toClipId=this.toClipId,e}async tick(e){return{video:void 0,state:"success"}}async split(e){const t=await this.clone(),r=await this.clone();return[t,r]}toJSON(e=!1){return{...super.toJSON(e),type:"Transition",transitionEffect:this.transitionEffect,fromClipId:this.fromClipId,toClipId:this.toClipId,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Transition")throw new Error(`Expected Transition, got ${e.type}`);const t=new pi(e.transitionEffect.key);return t.transitionEffect=e.transitionEffect,t.fromClipId=e.fromClipId||null,t.toClipId=e.toClipId||null,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),await t.ready,t}}class Qu{readable;writable;inputBufOffset=0;constructor(){const e=ke.createFile();let t=!1;this.readable=new ReadableStream({start:r=>{e.onReady=o=>{const c=o.videoTracks[0]?.id;c!=null&&e.setExtractionOptions(c,"video",{nbSamples:100});const l=o.audioTracks[0]?.id;l!=null&&e.setExtractionOptions(l,"audio",{nbSamples:100}),r.enqueue({chunkType:"ready",data:{info:o,file:e}}),e.start()};const n={};e.onSamples=(o,c,l)=>{r.enqueue({chunkType:"samples",data:{id:o,type:c,samples:l.map(d=>({...d}))}}),n[o]=(n[o]??0)+l.length,e.releaseUsedSamples(o,n[o])},e.onFlush=()=>{r.close()}},cancel:()=>{e.stop(),t=!0}},{highWaterMark:50}),this.writable=new WritableStream({write:async r=>{if(t){this.writable.abort();return}const n=r.buffer;n.fileStart=this.inputBufOffset,this.inputBufOffset+=n.byteLength,e.appendBuffer(n)},close:()=>{e.flush(),e.stop(),e.onFlush?.()}})}}function Mx(s){let e=0;const t=s.boxes,r=[];let n=0;async function o(){const a=y(t,e);e=t.length,r.forEach(({track:h,id:u})=>{const p=h.samples.at(-1);p!=null&&(n=Math.max(n,p.cts+p.duration)),s.releaseUsedSamples(u,h.samples.length),h.samples=[]}),s.mdats=[],s.moofs=[],a!=null&&await m?.write(a)}let c=[];function l(){if(c.length>0)return!0;const a=t.findIndex(h=>h.type==="moov");if(a===-1)return!1;if(c=t.slice(0,a+1),e=a+1,r.length===0)for(let h=1;;h+=1){const u=s.getTrackById(h);if(u==null)break;r.push({track:u,id:h})}return!0}let d=0;const f=vs();let m=null;const g=(async()=>{m=await f.createWriter(),d=self.setInterval(()=>{l()&&o()},100)})();let _=!1;return async()=>{if(_)throw Error("File exported");if(_=!0,await g,clearInterval(d),!l()||m==null)return null;s.flush(),await o(),await m?.close();const a=c.find(p=>p.type==="moov");if(a==null)return null;a.mvhd.duration=n;const h=vs(),u=y(c,0);return await Ti(h,u.slice()),await Ti(h,f,{overwrite:!1}),await h.stream()};function y(a,h){if(h>=a.length)return null;const u=new ke.DataStream;u.endianness=ke.DataStream.BIG_ENDIAN;for(let p=h;p<a.length;p++)a[p]!==null&&(a[p].write(u),delete a[p]);return new Uint8Array(u.buffer).slice()}}function Fx(s){const e=new ArrayBuffer(s.byteLength);s.copyTo(e);const t=s.timestamp;return{duration:s.duration??0,dts:t,cts:t,is_sync:s.type==="key",data:e}}async function ed(s){const e=ke.createFile(),t=Mx(e);await Ux(s,e);const r=await t();if(r==null)throw Error("Can not generate file from streams");return r}async function Ux(s,e){let t=0,r=0,n=0,o=0,c=0,l=0,d=null,f=null;for(const m of s){let g=null,_=null,y=null,a=null;if(await new Promise(async h=>{Zo(m.pipeThrough(new Qu),{onDone:h,onChunk:async({chunkType:u,data:p})=>{if(u==="ready"){const{videoTrackConf:v,audioTrackConf:x}=To(p.file,p.info);t===0&&v!=null&&(t=e.addTrack(v)),o===0&&x!=null&&(o=e.addTrack(x))}else if(u==="samples"){const{type:v,samples:x}=p,b=v==="video"?t:o,T=v==="video"?r:c,w=v==="video"?n:l;x.forEach(E=>{let A,P;v==="video"?(g===null&&(g=E.dts,_=E.cts),A=E.dts-g,P=E.cts-(_??0)):(y===null&&(y=E.dts,a=E.cts),A=E.dts-y,P=E.cts-(a??0)),e.addSample(b,E.data,{duration:E.duration,dts:A+T,cts:P+w,is_sync:E.is_sync})});const S=x.at(-1);if(S==null)return;v==="video"?d=S:v==="audio"&&(f=S)}}})}),d!=null&&g!==null&&_!==null){const h=d.dts-g+d.duration,u=d.cts-_+d.duration;r+=h,n+=u}if(f!=null&&d!=null){const h=f.timescale/d.timescale;c=Math.round(r*h),l=Math.round(n*h)}}}async function kx(s){return await ed([s])}function Bx(s){let e=[];const t=new AudioDecoder({output:r=>{e.push(r)},error:W.error});return t.configure(s),{decode:async r=>{r.forEach(o=>{t.decode(new EncodedAudioChunk({type:o.is_sync?"key":"delta",timestamp:1e6*o.cts/o.timescale,duration:1e6*o.duration/o.timescale,data:o.data}))}),await t.flush();const n=e;return e=[],n},close:()=>{t.close()}}}function Dx(s,e){const t={codec:s.codec,sampleRate:s.sampleRate,numberOfChannels:s.numberOfChannels},r=new AudioEncoder({output:c=>{e(Fx(c))},error:c=>{W.error("AudioEncoder error:",c,", config:",t)}});r.configure(t);let n=null;function o(c,l){return new AudioData({timestamp:l,numberOfChannels:s.numberOfChannels,numberOfFrames:c.length/s.numberOfChannels,sampleRate:s.sampleRate,format:"f32-planar",data:new Float32Array(c)})}return{encode:async(c,l)=>{n!=null&&r.encode(o(n.data,n.ts)),n={data:c,ts:l}},stop:async()=>{n!=null&&(Ox(n.data,s.numberOfChannels,s.sampleRate),r.encode(o(n.data,n.ts)),n=null),await r.flush(),r.close()}}}function Ox(s,e,t){const r=s.length-1,n=Math.min(t/2,r);for(let o=0;o<n;o++)for(let c=1;c<=e;c++)s[Math.floor(r/c)-o]*=o/n}function Gx(s,e){W.info("mixinMP4AndAudio, opts:",{volume:e.volume,loop:e.loop});const t=ke.createFile(),{stream:r,stop:n}=Jo(t,500);let o=null,c=null,l=[],d=0,f=0,m=0,g=!0,_=oe.sampleRate;Zo(s.pipeThrough(new Qu),{onDone:async()=>{await c?.stop(),o?.close(),n()},onChunk:async({chunkType:u,data:p})=>{if(u==="ready"){const{videoTrackConf:v,audioTrackConf:x,audioDecoderConf:b}=To(p.file,p.info);d===0&&v!=null&&(d=t.addTrack(v));const T=x??{timescale:1e6,samplerate:_,channel_count:oe.channelCount,hdlr:"soun",name:"SoundHandler",type:"mp4a"};f===0&&(f=t.addTrack(T),_=x?.samplerate??_,g=x!=null);const w=new AudioContext({sampleRate:_});l=bs(await w.decodeAudioData(await new Response(e.stream).arrayBuffer())),b!=null&&(o=Bx(b)),c=Dx(b??{codec:T.type==="mp4a"?oe.codec:T.type,numberOfChannels:T.channel_count,sampleRate:T.samplerate},S=>t.addSample(f,S.data,S))}else if(u==="samples"){const{id:v,type:x,samples:b}=p;if(x==="video"){b.forEach(T=>t.addSample(v,T.data,T)),g||await a(b);return}x==="audio"&&await h(b)}}});function y(u){const p=l.map(v=>e.loop?Ts(v,m,m+u):v.slice(m,m+u));if(m+=u,e.volume!==1)for(const v of p)for(let x=0;x<v.length;x++)v[x]*=e.volume;return p}async function a(u){const p=u[0],v=u[u.length-1],x=Math.floor((v.cts+v.duration-p.cts)/p.timescale*_),b=ra([y(x)]);b.length!==0&&c?.encode(b,p.cts/p.timescale*1e6)}async function h(u){if(o==null)return;const p=(await o.decode(u)).map(ia),v=ta(p),x=y(v[0].length),b=u[0];c?.encode(ra([v,x]),b.cts/b.timescale*1e6)}return r}const Lx=`
|
|
1295
|
+
`)}function ax(s,e,t,r,n){const{domElement:o,styleElement:c,svgRoot:l}=n;o.innerHTML=`<style>${e.cssStyle}</style><div style='padding:0;'>${s}</div>`,o.setAttribute("style",`transform: scale(${t});transform-origin: top left; display: inline-block`),c.textContent=r;const{width:d,height:f}=n.image;return l.setAttribute("width",d.toString()),l.setAttribute("height",f.toString()),new XMLSerializer().serializeToString(l)}function lx(s,e){const t=xt.getOptimalCanvasAndContext(s.width,s.height,e),{context:r}=t;return r.clearRect(0,0,s.width,s.height),r.drawImage(s,0,0),t}function cx(s,e,t){return new Promise(async r=>{t&&await new Promise(n=>setTimeout(n,100)),s.onload=()=>{r()},s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(e)}`,s.crossOrigin="anonymous"})}class Vu{constructor(e){this._activeTextures={},this._renderer=e,this._createCanvas=e.type===tt.WEBGPU}getTexture(e){return this.getTexturePromise(e)}getManagedTexture(e){const t=e.styleKey;if(this._activeTextures[t])return this._increaseReferenceCount(t),this._activeTextures[t].promise;const r=this._buildTexturePromise(e).then(n=>(this._activeTextures[t].texture=n,n));return this._activeTextures[t]={texture:null,promise:r,usageCount:1},r}getReferenceCount(e){return this._activeTextures[e]?.usageCount??null}_increaseReferenceCount(e){this._activeTextures[e].usageCount++}decreaseReferenceCount(e){const t=this._activeTextures[e];t&&(t.usageCount--,t.usageCount===0&&(t.texture?this._cleanUp(t.texture):t.promise.then(r=>{t.texture=r,this._cleanUp(t.texture)}).catch(()=>{G("HTMLTextSystem: Failed to clean texture")}),this._activeTextures[e]=null))}getTexturePromise(e){return this._buildTexturePromise(e)}async _buildTexturePromise(e){const{text:t,style:r,resolution:n,textureStyle:o}=e,c=me.get(rh),l=rx(t,r),d=await ox(l),f=Hv(t,r,d,c),m=Math.ceil(Math.ceil(Math.max(1,f.width)+r.padding*2)*n),g=Math.ceil(Math.ceil(Math.max(1,f.height)+r.padding*2)*n),_=c.image,y=2;_.width=(m|0)+y,_.height=(g|0)+y;const a=ax(t,r,n,d,c);await cx(_,a,tx()&&l.length>0);const h=_;let u;this._createCanvas&&(u=lx(_,n));const p=Wu(u?u.canvas:h,_.width-y,_.height-y,n);return o&&(p.source.style=o),this._createCanvas&&(this._renderer.texture.initSource(p.source),xt.returnCanvasAndContext(u)),me.return(c),p}returnTexturePromise(e){e.then(t=>{this._cleanUp(t)}).catch(()=>{G("HTMLTextSystem: Failed to clean texture")})}_cleanUp(e){Te.returnTexture(e,!0),e.source.resource=null,e.source.uploadMethodId="unknown"}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexturePromise(this._activeTextures[e].promise);this._activeTextures=null}}Vu.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"htmlText"};class hx extends se{constructor(e){const{text:t,style:r,autoSplit:n,lineAnchor:o,wordAnchor:c,charAnchor:l,...d}=e;super(d),this._dirty=!1,this._canReuseChars=!1,this.chars=[],this.words=[],this.lines=[],this._originalText=t,this._autoSplit=n,this._lineAnchor=o,this._wordAnchor=c,this._charAnchor=l,this.style=r}split(){const e=this.splitFn();this.chars=e.chars,this.words=e.words,this.lines=e.lines,this.addChild(...this.lines),this.charAnchor=this._charAnchor,this.wordAnchor=this._wordAnchor,this.lineAnchor=this._lineAnchor,this._dirty=!1,this._canReuseChars=!0}get text(){return this._originalText}set text(e){this._originalText=e,this.lines.forEach(t=>t.destroy({children:!0})),this.lines.length=0,this.words.length=0,this.chars.length=0,this._canReuseChars=!1,this.onTextUpdate()}_setOrigin(e,t,r){let n;typeof e=="number"?n={x:e,y:e}:n={x:e.x,y:e.y},t.forEach(o=>{const c=o.getLocalBounds(),l=c.minX+c.width*n.x,d=c.minY+c.height*n.y;o.origin.set(l,d)}),this[r]=e}get lineAnchor(){return this._lineAnchor}set lineAnchor(e){this._setOrigin(e,this.lines,"_lineAnchor")}get wordAnchor(){return this._wordAnchor}set wordAnchor(e){this._setOrigin(e,this.words,"_wordAnchor")}get charAnchor(){return this._charAnchor}set charAnchor(e){this._setOrigin(e,this.chars,"_charAnchor")}get style(){return this._style}set style(e){e||(e={}),this._style=new De(e),this.words.forEach(t=>t.destroy()),this.words.length=0,this.lines.forEach(t=>t.destroy()),this.lines.length=0,this._canReuseChars=!0,this.onTextUpdate()}onTextUpdate(){this._dirty=!0,this._autoSplit&&this.split()}destroy(e){super.destroy(e),this.chars=[],this.words=[],this.lines=[],(typeof e=="boolean"?e:e?.style)&&this._style.destroy(e),this._style=null,this._originalText=""}}const Yu=class cs extends hx{constructor(e){const t={...cs.defaultOptions,...e};super(t)}static from(e,t){const r={...cs.defaultOptions,...t,text:e.text,style:new De(e.style)};return new cs({...r})}splitFn(){return Qy({text:this._originalText,style:this._style,chars:this._canReuseChars?this.chars:[]})}};Yu.defaultOptions={autoSplit:!0,lineAnchor:0,wordAnchor:0,charAnchor:0};let ux=Yu;class dx extends ns{constructor(e){super(),this._renderer=e,e.runners.resolutionChange.add(this)}resolutionChange(){const e=this.renderable;e._autoResolution&&e.onViewUpdate()}destroy(){const{canvasText:e}=this._renderer;e.getReferenceCount(this.currentKey)>0?e.decreaseReferenceCount(this.currentKey):this.texture&&e.returnTexture(this.texture),this._renderer.runners.resolutionChange.remove(this),this._renderer=null}}class Xu{constructor(e){this._renderer=e}validateRenderable(e){const t=this._getGpuText(e),r=e.styleKey;return t.currentKey!==r?!0:e._didTextUpdate}addRenderable(e,t){const r=this._getGpuText(e);if(e._didTextUpdate){const n=e._autoResolution?this._renderer.resolution:e.resolution;(r.currentKey!==e.styleKey||e.resolution!==n)&&this._updateGpuText(e),e._didTextUpdate=!1,xo(r,e)}this._renderer.renderPipes.batch.addToBatch(r,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 dx(this._renderer);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,t}destroy(){this._renderer=null}}Xu.extension={type:[C.WebGLPipes,C.WebGPUPipes,C.CanvasPipes],name:"text"};class $u{constructor(e){this._activeTextures={},this._renderer=e}getTexture(e,t,r,n){typeof e=="string"&&(H("8.0.0","CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"),e={text:e,style:r,resolution:t}),e.style instanceof De||(e.style=new De(e.style)),e.textureStyle instanceof at||(e.textureStyle=new at(e.textureStyle)),typeof e.text!="string"&&(e.text=e.text.toString());const{text:o,style:c,textureStyle:l}=e,d=e.resolution??this._renderer.resolution,{frame:f,canvasAndContext:m}=ir.getCanvasAndContext({text:o,style:c,resolution:d}),g=Wu(m.canvas,f.width,f.height,d);if(l&&(g.source.style=l),c.trim&&(f.pad(c.padding),g.frame.copyFrom(f),g.frame.scale(1/d),g.updateUvs()),c.filters){const _=this._applyFilters(g,c.filters);return this.returnTexture(g),ir.returnCanvasAndContext(m),_}return this._renderer.texture.initSource(g._source),ir.returnCanvasAndContext(m),g}returnTexture(e){const t=e.source;t.resource=null,t.uploadMethodId="unknown",t.alphaMode="no-premultiply-alpha",Te.returnTexture(e,!0)}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 r=this.getTexture({text:e.text,style:e.style,resolution:e._resolution,textureStyle:e.textureStyle});return this._activeTextures[t]={texture:r,usageCount:1},r}decreaseReferenceCount(e){const t=this._activeTextures[e];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 r=this._renderer.renderTarget.renderTarget,n=this._renderer.filter.generateFilteredTexture({texture:e,filters:t});return this._renderer.renderTarget.bind(r,!1),n}destroy(){this._renderer=null;for(const e in this._activeTextures)this._activeTextures[e]&&this.returnTexture(this._activeTextures[e].texture);this._activeTextures=null}}$u.extension={type:[C.WebGLSystem,C.WebGPUSystem,C.CanvasSystem],name:"canvasText"},L.add(Xf,$f);function Ee(s){if(s!=null){if(typeof s=="number")return s;if(typeof s=="string"){if(s==="transparent")return;if(s.startsWith("#")){const t=parseInt(s.slice(1),16);if(!isNaN(t))return t}if(s.startsWith("0x")){const t=parseInt(s,16);if(!isNaN(t))return t}const e=parseInt(s,16);if(!isNaN(e))return e;try{return new le(s).toNumber()}catch{return}}}}const qu=s=>s==="transparent",Vt=(s,e=16777215)=>qu(s)?{color:e,alpha:0}:{color:Ee(s)??e,alpha:1};class Ft extends kt{type="Caption";ready;_meta={duration:1/0,width:0,height:0};get meta(){return{...this._meta}}text;get style(){if(!this.originalOpts)return{};const e=this.originalOpts;return{fontSize:e.fontSize,fontFamily:e.fontFamily,fontWeight:e.fontWeight,fontStyle:e.fontStyle,color:e.fill,align:e.align,textCase:e.textCase,stroke:e.stroke?typeof e.stroke=="object"?{color:e.stroke.color,width:e.stroke.width}:{color:e.stroke,width:e.strokeWidth??0}:void 0,shadow:e.dropShadow?{color:e.dropShadow.color??"#000000",alpha:e.dropShadow.alpha??.5,blur:e.dropShadow.blur??4,distance:e.dropShadow.distance??0,angle:e.dropShadow.angle??0}:void 0}}bottomOffset;get textCase(){return this.originalOpts?.textCase||"none"}set textCase(e){this.updateStyle({textCase:e})}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];opts;pixiTextContainer=null;renderTexture=null;wordTexts=[];extraPadding=0;textStyle;externalRenderer=null;pixiApp=null;originalOpts=null;constructor(e,t={},r){super(),this.text=e,this.originalOpts={...t},this.externalRenderer=r??null,this.opts={fontSize:t.fontSize??30,fontFamily:t.fontFamily??"Arial",fontUrl:t.fontUrl??"",fontWeight:t.fontWeight??"normal",fontStyle:t.fontStyle??"normal",fill:t.fill??"#ffffff",strokeWidth:t.strokeWidth??0,align:t.align??"center",wordWrapWidth:t.wordWrapWidth??0,wordWrap:t.wordWrap??!1,lineHeight:t.lineHeight??1,letterSpacing:t.letterSpacing??0,textCase:t.textCase??"none",videoWidth:t.caption?.positioning?.videoWidth??t.videoWidth??1280,videoHeight:t.caption?.positioning?.videoHeight??t.videoHeight??720,bottomOffset:t.caption?.positioning?.bottomOffset??t.bottomOffset??30,keyword:t.caption?.colors?.keyword??t.colors?.keyword??"#ffff00",background:t.caption?.colors?.background??t.colors?.background??"#000000",active:t.caption?.colors?.active??t.colors?.active??"#ffffff",activeFill:t.caption?.colors?.activeFill??t.colors?.activeFill??"#00ff00",appeared:t.caption?.colors?.appeared??t.colors?.appeared??"#ffffff",words:t.caption?.words??t.words??[],preserveKeywordColor:t.caption?.preserveKeywordColor??t.preserveKeywordColor??!1};const n={fontSize:this.opts.fontSize,fontFamily:this.opts.fontFamily,fontWeight:this.opts.fontWeight,fontStyle:this.opts.fontStyle,align:this.opts.align};if(t.fill&&typeof t.fill=="object"&&t.fill.type==="gradient"){const l=new Ke(t.fill.x0,t.fill.y0,t.fill.x1,t.fill.y1);t.fill.colors.forEach(({ratio:d,color:f})=>{const m=typeof f=="number"?f:Ee(f)??16777215;l.addColorStop(d,m)}),n.fill={fill:l}}else{let l;t.fill==="transparent"?l=16777215:(typeof t.fill=="string"||typeof t.fill=="number")&&(l=Ee(t.fill)),n.fill=l??16777215}const o=l=>l==="transparent";if(t.stroke&&typeof t.stroke=="object"&&"color"in t.stroke){if(!o(t.stroke.color)){const l=Ee(t.stroke.color);l!==void 0&&(n.stroke={color:l,width:t.stroke.width},t.stroke.join&&(n.stroke.join=t.stroke.join))}}else if(!o(t.stroke)){const l=Ee(t.stroke);l!==void 0?n.stroke={color:l,width:this.opts.strokeWidth??0}:this.opts.strokeWidth&&this.opts.strokeWidth>0&&(n.stroke={color:0,width:this.opts.strokeWidth})}if(t.dropShadow){const l=Ee(t.dropShadow.color);l!==void 0&&(n.dropShadow={color:l,alpha:t.dropShadow.alpha??.5,blur:t.dropShadow.blur??4,angle:t.dropShadow.angle??Math.PI/6,distance:t.dropShadow.distance??2})}const c=new De(n);this.textStyle=c,this.ready=(async()=>{await this.refreshCaptions();const l={...this._meta};return W.info("CaptionClip ready:",l),l})()}async updateStyle(e){this.originalOpts||(this.originalOpts={}),this.originalOpts={...this.originalOpts,...e},e.fontSize!==void 0&&(this.opts.fontSize=e.fontSize),e.fontFamily!==void 0&&(this.opts.fontFamily=e.fontFamily),e.fontWeight!==void 0&&(this.opts.fontWeight=e.fontWeight),e.fontStyle!==void 0&&(this.opts.fontStyle=e.fontStyle),e.fill!==void 0&&(this.opts.fill=e.fill),e.align!==void 0&&(this.opts.align=e.align),e.letterSpacing!==void 0&&(this.opts.letterSpacing=e.letterSpacing),e.lineHeight!==void 0&&(this.opts.lineHeight=e.lineHeight),e.textCase!==void 0&&(this.opts.textCase=e.textCase);const t={fontSize:this.opts.fontSize,fontFamily:this.opts.fontFamily,fontWeight:this.opts.fontWeight,fontStyle:this.opts.fontStyle,align:this.opts.align};if(this.opts.fill&&typeof this.opts.fill=="object"&&this.opts.fill.type==="gradient"){const r=new Ke(this.opts.fill.x0,this.opts.fill.y0,this.opts.fill.x1,this.opts.fill.y1);this.opts.fill.colors.forEach(({ratio:n,color:o})=>{const c=typeof o=="number"?o:Ee(o)??16777215;r.addColorStop(n,c)}),t.fill={fill:r}}else{const r=typeof this.opts.fill=="string"||typeof this.opts.fill=="number"?Ee(this.opts.fill):void 0;t.fill=r??16777215}if(e.stroke!==void 0||e.strokeWidth!==void 0)if(this.originalOpts.stroke&&typeof this.originalOpts.stroke=="object"&&"color"in this.originalOpts.stroke){const r=Ee(this.originalOpts.stroke.color);r!==void 0&&(t.stroke={color:r,width:this.originalOpts.stroke.width},this.originalOpts.stroke.join&&(t.stroke.join=this.originalOpts.stroke.join))}else{const r=Ee(this.originalOpts.stroke),n=e.strokeWidth??this.originalOpts.strokeWidth??0;r!==void 0?t.stroke={color:r,width:n}:n>0&&(t.stroke={color:0,width:n})}this.textStyle=new De(t),await this.refreshCaptions()}async refreshCaptions(){this.pixiTextContainer?(this.pixiTextContainer.children.forEach(p=>{p instanceof Ce&&p.label}),this.pixiTextContainer.removeChildren()):this.pixiTextContainer=new se;const e=this.textStyle;let t=0,r=0,n=0;const o=this.opts.textCase;this.wordTexts=this.opts.words.map(p=>{let v=p.text;o==="uppercase"?v=v.toUpperCase():o==="lowercase"?v=v.toLowerCase():o==="title"&&(v=v.replace(/\w\S*/g,A=>A.charAt(0).toUpperCase()+A.substring(1).toLowerCase()));const x=new ux({text:v,style:e});x.x=t,x.y=0;const b=x.getLocalBounds(),T=Math.ceil(b.width||x.width),w=Math.ceil(b.height||x.height);r=Math.max(r,w);const S=Be.measureText(" ",this.textStyle);t+=T+S.width,n=t-S.width,this.pixiTextContainer.addChild(x);const E=Ee(this.opts.fill);return x.tint=E??16777215,x});const c=n,l=r,d=new Ce;d.label="containerBackground";const f=this.opts.background==="transparent",m=f?0:Ee(this.opts.background),g=f?0:1,_=15;d.roundRect(0,0,c+_*2,l+_*2,10),d.fill({color:m,alpha:g}),this.wordTexts.forEach(p=>{this.extraPadding=0,p.pivot.y=0,p.pivot.x=0,p.y=_-this.extraPadding,p.x+=_}),this.pixiTextContainer.addChildAt(d,0),this.renderTexture&&this.renderTexture.destroy(!0),this.renderTexture=Ae.create({width:c+_*2,height:l+_*2}),this._meta.width=c+_*2,this._meta.height=l+_*2,this._meta.duration=1/0;const a=this.opts.videoWidth,h=this.opts.videoHeight,u=this.opts.bottomOffset;this.width=this.width===0?this._meta.width:this.width,this.height=this.height===0?this._meta.height:this.height,this.top=h-this.height-u,this.left=(a-this.width)/2}lastLoggedTime=-1;updateState(e){const t=e/1e3,r=Math.floor(e/1e6);r!==this.lastLoggedTime&&(this.lastLoggedTime=r),this.opts.words.forEach((n,o)=>{const c=t>=n.from&&t<=n.to,l=t>n.to,d=n.isKeyWord&&!qu(this.opts.keyword);let f=16777215,m=1;n.isKeyWord&&c&&d?{color:f,alpha:m}=Vt(this.opts.keyword):c?{color:f,alpha:m}=Vt(this.opts.active):l&&this.opts.preserveKeywordColor&&d?{color:f,alpha:m}=Vt(this.opts.keyword):l?{color:f,alpha:m}=Vt(this.opts.appeared):{color:f,alpha:m}=Vt(this.opts.fill);const g=this.wordTexts[o];if(!g){console.warn(`¡WARNING: SplitBitmapText was not found for word "${n.text}"!`);return}g.children.forEach(y=>{y.label!=="bgRect"&&(y.tint=f,y.alpha=m)});const _=g.getChildByLabel("bgRect");if(c){const{color:y,alpha:a}=Vt(this.opts.activeFill,16753920),h=10;_&&(_.visible=!1);const u=g.getLocalBounds();_&&(_.visible=!0);const p=16,v=_??new Ce;v.label="bgRect",v.clear(),v.roundRect(u.x-h/2,u.y-h/2+this.extraPadding,u.width+h,u.height+h,p),v.fill({color:y,alpha:a}),v.tint=16777215,_||g.addChildAt(v,0)}else _&&(g.removeChild(_),_.destroy())})}async getTexture(){if(this.pixiTextContainer==null||this.renderTexture==null)return console.log("[CaptionClip] getTexture returning null - container or texture not ready"),null;try{return(await this.getRenderer()).render({container:this.pixiTextContainer,target:this.renderTexture}),this.renderTexture}catch(e){return console.error("[CaptionClip] Error in getTexture:",e),null}}setRenderer(e){this.externalRenderer=e}async getRenderer(){if(this.externalRenderer!=null)return this.externalRenderer;if(this.pixiApp?.renderer==null)throw new Error("CaptionClip: No renderer available. Provide a renderer via setRenderer().");return this.pixiApp.renderer}async tick(e){if(await this.ready,this.pixiTextContainer==null||this.renderTexture==null)throw new Error("CaptionClip not initialized");this.updateState(e);const t=await this.getRenderer();t.render({container:this.pixiTextContainer,target:this.renderTexture});const r=this.renderTexture.source?.resource?.source;let n;if(r instanceof HTMLCanvasElement)n=await createImageBitmap(r);else if(r instanceof OffscreenCanvas)n=await createImageBitmap(r);else{const c=t.extract.canvas(this.renderTexture);if(c instanceof HTMLCanvasElement||c instanceof OffscreenCanvas)n=await createImageBitmap(c);else throw new Error("Unable to extract canvas from render texture")}return{video:n,state:"success"}}async split(e){await this.ready;const t=await this.clone(),r=await this.clone();return[t,r]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=this.originalOpts||{},t=new Ft(this.text,e);return this.copyStateTo(t),t.id=this.id,t.effects=[...this.effects],t}destroy(){if(!this.destroyed){W.info("CaptionClip destroy");try{this.wordTexts.forEach(e=>{e!=null&&!e.destroyed&&e.destroy({children:!0})})}catch{}finally{this.wordTexts=[]}try{this.pixiTextContainer!=null&&this.pixiTextContainer.destroyed!==!0&&this.pixiTextContainer.destroy({children:!0})}catch{}finally{this.pixiTextContainer=null}try{this.renderTexture!=null&&this.renderTexture.destroyed!==!0&&this.renderTexture.destroy(!0)}catch{}finally{this.renderTexture=null}if(this.externalRenderer=null,this.pixiApp!=null)try{const e=this.pixiApp;e.destroyed!==!0&&e.renderer!=null&&this.pixiApp.destroy(!0,{children:!0,texture:!0})}catch{}finally{this.pixiApp=null}super.destroy()}}toJSON(e=!1){const t=super.toJSON(e),r={};if(this.originalOpts){const g=this.originalOpts;g.fontSize!==void 0&&(r.fontSize=g.fontSize),g.fontFamily!==void 0&&(r.fontFamily=g.fontFamily),g.fontWeight!==void 0&&(r.fontWeight=g.fontWeight),g.fontStyle!==void 0&&(r.fontStyle=g.fontStyle),g.fill!==void 0&&(r.color=g.fill),g.align!==void 0&&(r.align=g.align),g.textCase!==void 0&&(r.textCase=g.textCase),g.fontUrl!==void 0&&(r.fontUrl=g.fontUrl),g.stroke&&(typeof g.stroke=="object"?r.stroke={color:g.stroke.color,width:g.stroke.width}:r.stroke={color:g.stroke,width:g.strokeWidth??0}),g.dropShadow&&(r.shadow={color:g.dropShadow.color??"#000000",alpha:g.dropShadow.alpha??.5,blur:g.dropShadow.blur??4,distance:g.dropShadow.distance??0,angle:g.dropShadow.angle??0})}const n={};this.opts.words&&this.opts.words.length>0&&(n.words=this.opts.words);const o={},c=this.originalOpts?.caption?.colors??this.originalOpts?.colors;c?.appeared!==void 0&&(o.appeared=c.appeared),c?.active!==void 0&&(o.active=c.active),c?.activeFill!==void 0&&(o.activeFill=c.activeFill),c?.background!==void 0&&(o.background=c.background),c?.keyword!==void 0&&(o.keyword=c.keyword);let l;this.originalOpts?.caption?.preserveKeywordColor!==void 0?l=this.originalOpts.caption.preserveKeywordColor:this.originalOpts?.preserveKeywordColor!==void 0&&(l=this.originalOpts.preserveKeywordColor),Object.keys(o).length>0&&(n.colors=o),l!==void 0&&(n.preserveKeywordColor=l);const d={};this.bottomOffset!==void 0&&(d.bottomOffset=this.bottomOffset);const f=this.originalOpts?.caption?.positioning?.videoWidth??this.originalOpts?.videoWidth,m=this.originalOpts?.caption?.positioning?.videoHeight??this.originalOpts?.videoHeight;return f!==void 0&&(d.videoWidth=f),m!==void 0&&(d.videoHeight=m),Object.keys(d).length>0&&(n.positioning=d),{...t,type:"Caption",text:this.text,style:r,caption:Object.keys(n).length>0?n:void 0,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Caption")throw new Error(`Expected Caption, got ${e.type}`);const t=e.text||"",r=e.style||{},n={};r.fontSize!==void 0&&(n.fontSize=r.fontSize),r.fontFamily!==void 0&&(n.fontFamily=r.fontFamily),r.fontWeight!==void 0&&(n.fontWeight=r.fontWeight),r.fontStyle!==void 0&&(n.fontStyle=r.fontStyle),r.color!==void 0&&(n.fill=r.color),r.align!==void 0&&(n.align=r.align),r.textCase!==void 0&&(n.textCase=r.textCase),r.fontUrl!==void 0?n.fontUrl=r.fontUrl:e.fontUrl!==void 0&&(n.fontUrl=e.fontUrl),r.stroke&&(n.stroke=r.stroke.color,n.strokeWidth=r.stroke.width),r.shadow&&(n.dropShadow={color:r.shadow.color,alpha:r.shadow.alpha,blur:r.shadow.blur,distance:r.shadow.distance,angle:r.shadow.angle}),e.caption?n.caption=e.caption:(e.bottomOffset!==void 0&&(n.bottomOffset=e.bottomOffset),e.words!==void 0&&(n.words=e.words),(e.appearedColor!==void 0||e.activeColor!==void 0||e.activeFillColor!==void 0||e.backgroundColor!==void 0||e.isKeyWordColor!==void 0)&&(n.colors={},e.appearedColor!==void 0&&(n.colors.appeared=e.appearedColor),e.activeColor!==void 0&&(n.colors.active=e.activeColor),e.activeFillColor!==void 0&&(n.colors.activeFill=e.activeFillColor),e.backgroundColor!==void 0&&(n.colors.background=e.backgroundColor),e.isKeyWordColor!==void 0&&(n.colors.keyword=e.isKeyWordColor)),e.preservedColorKeyWord!==void 0&&(n.preserveKeywordColor=e.preservedColorKeyWord),e.videoWidth!==void 0&&(n.videoWidth=e.videoWidth),e.videoHeight!==void 0&&(n.videoHeight=e.videoHeight));const o=new Ft(t,n);return o.left=e.left,o.top=e.top,o.width=e.width,o.height=e.height,o.angle=e.angle,o.display.from=e.display.from,o.display.to=e.display.to,o.duration=e.duration,o.playbackRate=e.playbackRate,o.zIndex=e.zIndex,o.opacity=e.opacity,o.flip=e.flip,e.animation&&o.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(o.id=e.id),e.effects&&(o.effects=e.effects),await o.ready,o}}class ve extends kt{type="Image";ready;_meta={duration:0,width:0,height:0};get meta(){return{...this._meta}}img=null;pixiTexture=null;frames=[];id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];static async fromUrl(e,t){const r=await er.load(e),n=r.source?.resource?.source;let o;try{if(n instanceof HTMLCanvasElement||n instanceof OffscreenCanvas)o=await createImageBitmap(n);else if(n instanceof HTMLImageElement){const l=new OffscreenCanvas(n.width,n.height),d=l.getContext("2d");if(d==null)throw new Error("Failed to create 2d context");d.drawImage(n,0,0),o=await createImageBitmap(l)}else if(n instanceof ImageBitmap)o=await createImageBitmap(n);else{const l=await fetch(e);if(!l.ok)throw new Error(`Failed to fetch image: ${l.status} ${l.statusText}`);const d=await l.blob();o=await createImageBitmap(d)}}catch{const d=await fetch(e);if(!d.ok)throw new Error(`Failed to fetch image: ${d.status} ${d.statusText}`);const f=await d.blob();o=await createImageBitmap(f)}const c=new ve(o,t||e);return c.pixiTexture=r,c}getTexture(){return this.pixiTexture}constructor(e,t){super(),this.src=t!==void 0?t:"";const r=n=>{this.img=n,this._meta.width=n.width,this._meta.height=n.height,this._meta.duration=1/0;const o={...this._meta};return this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration===0&&o.duration!==1/0&&(this.duration=o.duration,this.display.to=this.display.from+this.duration),o};if(e instanceof ReadableStream)this.ready=new Response(e).blob().then(n=>createImageBitmap(n)).then(r);else if(e instanceof ImageBitmap)this.ready=Promise.resolve(r(e));else if(Array.isArray(e)&&e.every(n=>n instanceof VideoFrame)){this.frames=e;const n=this.frames[0];if(n==null)throw Error("The frame count must be greater than 0");this._meta={width:n.displayWidth,height:n.displayHeight,duration:this.frames.reduce((c,l)=>c+(l.duration??0),0)};const o={...this._meta,duration:1/0};this.width=this.width===0?o.width:this.width,this.height=this.height===0?o.height:this.height,this.duration===0&&o.duration!==1/0&&(this.duration=o.duration,this.display.to=this.display.from+this.duration),this.ready=Promise.resolve(o)}else if("type"in e)this.ready=this.initAnimateImg(e.stream,e.type).then(()=>{const n={width:this._meta.width,height:this._meta.height,duration:1/0};return this.width=this.width===0?n.width:this.width,this.height=this.height===0?n.height:this.height,this.duration===0&&n.duration!==1/0&&(this.duration=n.duration,this.display.to=this.display.from+this.duration),n});else throw Error("Illegal arguments")}async initAnimateImg(e,t){this.frames=await zf(e,t);const r=this.frames[0];if(r==null)throw Error("No frame available in gif");this._meta={duration:this.frames.reduce((n,o)=>n+(o.duration??0),0),width:r.codedWidth,height:r.codedHeight},W.info("ImageClip ready:",this._meta)}tickInterceptor=async(e,t)=>t;async tick(e){if(this.img!=null)return await this.tickInterceptor(e,{video:await createImageBitmap(this.img),state:"success"});const t=e%this._meta.duration;return await this.tickInterceptor(e,{video:(this.frames.find(r=>t>=r.timestamp&&t<=r.timestamp+(r.duration??0))??this.frames[0]).clone(),state:"success"})}async split(e){if(await this.ready,this.img!=null)return[new ve(await createImageBitmap(this.img),this.src),new ve(await createImageBitmap(this.img),this.src)];let t=-1;for(let o=0;o<this.frames.length;o++){const c=this.frames[o];if(!(e>c.timestamp)){t=o;break}}if(t===-1)throw Error("Not found frame by time");const r=this.frames.slice(0,t).map(o=>new VideoFrame(o)),n=this.frames.slice(t).map(o=>new VideoFrame(o,{timestamp:o.timestamp-e}));return[new ve(r,this.src),new ve(n,this.src)]}async clone(){await this.ready;const e=this.img==null?this.frames.map(r=>r.clone()):await createImageBitmap(this.img),t=new ve(e,this.src);return t.tickInterceptor=this.tickInterceptor,this.copyStateTo(t),t.id=this.id,t.effects=[...this.effects],t.transition=this.transition,t}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}destroy(){W.info("ImageClip destroy"),this.img?.close(),this.frames.forEach(e=>e.close()),this.pixiTexture=null,super.destroy()}toJSON(e=!1){return{...super.toJSON(e),type:"Image",id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Image")throw new Error(`Expected Image, got ${e.type}`);if(!e.src||e.src.trim()==="")throw new Error("ImageClip requires a valid source URL. Generated clips (like text-to-image) cannot be loaded from JSON without their source data.");let t;try{const r=await fetch(e.src);if(!r.ok)throw new Error(`Failed to fetch image from ${e.src}: ${r.status} ${r.statusText}. Make sure the file exists in the public directory.`);const n=await r.blob();if(!n.type.startsWith("image/"))throw new Error(`Invalid image format: ${n.type}. Expected an image file.`);t=new ve(await createImageBitmap(n),e.src)}catch(r){throw r instanceof Error&&r.message.includes("could not be decoded")?new Error(`Failed to decode image from ${e.src}. The image may be corrupted, in an unsupported format, or there may be CORS issues.`):r}return await t.ready,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),e.effects&&(t.effects=e.effects),e.transition&&(t.transition=e.transition),t}async scaleToFit(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.min(e/r,t/n);this.width=r*o,this.height=n*o}async scaleToFill(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.max(e/r,t/n);this.width=r*o,this.height=n*o}centerInScene(e,t){this.left=(e-this.width)/2,this.top=(t-this.height)/2}}function To(s,e){const t=e.videoTracks[0],r={};if(t!=null){const o=fx(s.getTrackById(t.id))?.buffer,{descKey:c,type:l}=t.codec.startsWith("avc1")?{descKey:"avcDecoderConfigRecord",type:"avc1"}:t.codec.startsWith("hvc1")?{descKey:"hevcDecoderConfigRecord",type:"hvc1"}:{descKey:"",type:""};c!==""&&(r.videoTrackConf={timescale:t.timescale,duration:t.duration,width:t.video.width,height:t.video.height,brands:e.brands,type:l,[c]:o}),r.videoDecoderConf={codec:t.codec,codedHeight:t.video.height,codedWidth:t.video.width,description:o}}const n=e.audioTracks[0];if(n!=null){const o=px(s),c=o==null?{}:mx(o);r.audioTrackConf={timescale:n.timescale,samplerate:c.sampleRate??n.audio.sample_rate,channel_count:c.numberOfChannels??n.audio.channel_count,hdlr:"soun",type:n.codec.startsWith("mp4a")?"mp4a":n.codec,description:o},r.audioDecoderConf={codec:c.codec??oe.codec,numberOfChannels:c.numberOfChannels??n.audio.channel_count,sampleRate:c.sampleRate??n.audio.sample_rate}}return r}function fx(s){for(const e of s.mdia.minf.stbl.stsd.entries){const t=e.avcC??e.hvcC??e.av1C??e.vpcC;if(t!=null){const r=new ke.DataStream(void 0,0,ke.DataStream.BIG_ENDIAN);return t.write(r),new Uint8Array(r.buffer.slice(8))}}}function px(s,e="mp4a"){return s.moov?.traks.map(r=>r.mdia.minf.stbl.stsd.entries).flat().find(({type:r})=>r===e)?.esds}function mx(s){let e="mp4a";const t=s.esd.descs[0];if(t==null)return{};e+="."+t.oti.toString(16);const r=t.descs[0];if(r==null)return e.endsWith("40")&&(e+=".2"),{codec:e};const n=(r.data[0]&248)>>3;e+="."+n;const[o,c]=r.data,l=((o&7)<<1)+(c>>7),d=(c&127)>>3;return{codec:e,sampleRate:[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350][l],numberOfChannels:d}}async function gx(s,e,t){const r=ke.createFile(!1);r.onReady=o=>{e({mp4boxFile:r,info:o});const c=o.videoTracks[0]?.id;c!=null&&r.setExtractionOptions(c,"video",{nbSamples:100});const l=o.audioTracks[0]?.id;l!=null&&r.setExtractionOptions(l,"audio",{nbSamples:100}),r.start()},r.onSamples=t,await n();async function n(){let o=0;const c=30*1024*1024;for(;;){const l=await s.read(c,{at:o});if(l.byteLength===0)break;l.fileStart=o;const d=r.appendBuffer(l);if(d==null)break;o=d}r.stop()}}function vx(s){if(s?.length!==9)return{};const e=new Int32Array(s.buffer),t=e[0]/65536,r=e[1]/65536,n=e[3]/65536,o=e[4]/65536,c=e[6]/65536,l=e[7]/65536,d=e[8]/(1<<30),f=Math.sqrt(t*t+n*n),m=Math.sqrt(r*r+o*o),g=Math.atan2(n,t),_=g*180/Math.PI;return{scaleX:f,scaleY:m,rotationRad:g,rotationDeg:_,translateX:c,translateY:l,perspective:d}}function _x(s,e,t){const r=(Math.round(t/90)*90+360)%360;if(r===0)return d=>d;const n=r===90||r===270?e:s,o=r===90||r===270?s:e,c=new OffscreenCanvas(n,o),l=c.getContext("2d");return l.translate(n/2,o/2),l.rotate(-r*Math.PI/180),l.translate(-s/2,-e/2),d=>{if(d==null)return null;l.drawImage(d,0,0);const f=new VideoFrame(c,{timestamp:d.timestamp,duration:d.duration??void 0});return d.close(),f}}let wo=0;function So(s){return s.kind==="file"&&s.createReader instanceof Function}class fe extends kt{type="Video";insId=wo++;logger=W.create(`VideoClip id:${this.insId},`);ready;_meta={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};get meta(){return{...this._meta}}localFile;headerBoxPos=[];async getFileHeaderBinData(){await this.ready;const e=await this.localFile.getOriginFile();if(e==null)throw Error("VideoClip localFile is not origin file");return await new Blob(this.headerBoxPos.map(({start:t,size:r})=>e.slice(t,t+r))).arrayBuffer()}parsedMatrix={perspective:1,rotationRad:0,rotationDeg:0,scaleX:1,scaleY:1,translateX:0,translateY:0};vfRotater=e=>e;videoSamples=[];audioSamples=[];videoFrameFinder=null;audioFrameFinder=null;decoderConf={video:null,audio:null};opts={audio:!0};audio=!0;id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];static async fromUrl(e,t={}){const r=await fetch(e);if(!r.ok)throw new Error(`Failed to fetch video from ${e}: ${r.status} ${r.statusText}`);const n=new fe(r.body,{},e);return await n.ready,t.x!==void 0&&(n.left=t.x),t.y!==void 0&&(n.top=t.y),t.width!==void 0&&(n.width=t.width),t.height!==void 0&&(n.height=t.height),n}constructor(e,t={},r){if(super(),this.src=r!==void 0?r:"",!(e instanceof ReadableStream)&&!So(e)&&!Array.isArray(e.videoSamples))throw Error("Illegal argument");this.opts={audio:!0,...t},this.audio=typeof this.opts.audio=="boolean"?this.opts.audio:!0,this.volume=typeof t.audio=="object"&&"volume"in t.audio?t.audio.volume:t.volume??1;const n=async o=>(await Ti(this.localFile,o),this.localFile);this.localFile=So(e)?e:"localFile"in e?e.localFile:vs(),this.ready=(e instanceof ReadableStream?n(e).then(o=>Ku(o,this.opts)):So(e)?Ku(e,this.opts):Promise.resolve(e)).then(async({videoSamples:o,audioSamples:c,decoderConf:l,headerBoxPos:d,parsedMatrix:f})=>{this.videoSamples=o,this.audioSamples=c,this.decoderConf=l,this.headerBoxPos=d,this.parsedMatrix=f;const{videoFrameFinder:m,audioFrameFinder:g}=xx({video:l.video==null?null:{...l.video,hardwareAcceleration:this.opts.__unsafe_hardwareAcceleration__},audio:l.audio},await this.localFile.createReader(),o,c,this.opts.audio!==!1?this.volume:0);this.videoFrameFinder=m,this.audioFrameFinder=g;const{codedWidth:_,codedHeight:y}=l.video??{};_&&y&&(this.vfRotater=_x(_,y,f.rotationDeg)),this._meta=yx(l,o,c,f.rotationDeg),this.logger.info("VideoClip meta:",this._meta);const a={...this._meta};this.width=this.width===0?a.width:this.width,this.height=this.height===0?a.height:this.height,this.trim.to=this.trim.to===0?a.duration:this.trim.to;const h=(this.trim.to-this.trim.from)/this.playbackRate;return this.duration=this.duration===0?h:this.duration,this.display.to=this.display.from+this.duration,this.on("propsChange",u=>{u.volume!==void 0&&this.audioFrameFinder&&this.audioFrameFinder.setVolume(u.volume)}),a})}tickInterceptor=async(e,t)=>t;async tick(e){const t=e+this.trim.from;if(t>=this.trim.to||t>=this._meta.duration)return await this.tickInterceptor(e,{audio:await this.audioFrameFinder?.find(t)??[],state:"done"});const[r,n]=await Promise.all([this.audioFrameFinder?.find(t)??[],this.videoFrameFinder?.find(t).then(this.vfRotater)]);return n==null?await this.tickInterceptor(e,{audio:r,state:"success"}):await this.tickInterceptor(e,{video:n,audio:r,state:"success"})}async split(e){if(await this.ready,e<=0||e>=this._meta.duration)throw Error("time out of bounds");const[t,r]=Ex(this.videoSamples,e),[n,o]=Ix(this.audioSamples,e),c=new fe({localFile:this.localFile,videoSamples:t??[],audioSamples:n??[],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src),l=new fe({localFile:this.localFile,videoSamples:r??[],audioSamples:o??[],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);return await Promise.all([c.ready,l.ready]),[c,l]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=new fe({localFile:this.localFile,videoSamples:[...this.videoSamples],audioSamples:[...this.audioSamples],decoderConf:this.decoderConf,headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);return await e.ready,e.tickInterceptor=this.tickInterceptor,this.copyStateTo(e),e.id=this.id,e.effects=[...this.effects],e}async splitTrack(){await this.ready;const e=[];if(this.videoSamples.length>0){const t=new fe({localFile:this.localFile,videoSamples:[...this.videoSamples],audioSamples:[],decoderConf:{video:this.decoderConf.video,audio:null},headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);await t.ready,t.tickInterceptor=this.tickInterceptor,e.push(t)}if(this.audioSamples.length>0){const t=new fe({localFile:this.localFile,videoSamples:[],audioSamples:[...this.audioSamples],decoderConf:{audio:this.decoderConf.audio,video:null},headerBoxPos:this.headerBoxPos,parsedMatrix:this.parsedMatrix},this.opts,this.src);await t.ready,t.tickInterceptor=this.tickInterceptor,e.push(t)}return e}destroy(){this.destroyed||(this.destroyed=!0,this.logger.info("VideoClip destroy"),super.destroy(),this.videoFrameFinder?.destroy(),this.audioFrameFinder?.destroy())}toJSON(e=!1){return{...super.toJSON(e),type:"Video",audio:this.audio,volume:this.volume,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Video")throw new Error(`Expected Video, got ${e.type}`);const t=await fetch(e.src);if(!t.ok)throw new Error(`Failed to fetch video from ${e.src}: ${t.status} ${t.statusText}. Make sure the file exists in the public directory.`);const r=e.audio!==void 0?{audio:e.audio,volume:e.volume}:{volume:e.volume},n=new fe(t.body,r,e.src);return await n.ready,n.left=e.left,n.top=e.top,n.width=e.width,n.height=e.height,n.angle=e.angle,n.display.from=e.display.from,n.display.to=e.display.to,n.duration=e.duration,n.playbackRate=e.playbackRate,n.zIndex=e.zIndex,n.opacity=e.opacity,n.flip=e.flip,e.animation&&n.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(n.id=e.id),e.effects&&(n.effects=e.effects),e.transition&&(n.transition=e.transition),e.trim&&(n.trim.from=e.trim.from<1e6?e.trim.from*1e6:e.trim.from,n.trim.to=e.trim.to<1e6?e.trim.to*1e6:e.trim.to),e.volume!==void 0&&(n.volume=e.volume),n}async createPlaybackElement(){await this.ready;const t=this.localFile;if(!t||typeof t.getOriginFile!="function")throw new Error("VideoClip does not have a local file for playback");const r=await t.getOriginFile();if(!r)throw new Error("Failed to get origin file from VideoClip");const n=URL.createObjectURL(r),o=document.createElement("video");return o.crossOrigin="anonymous",o.muted=!0,o.autoplay=!1,o.playsInline=!0,o.preload="auto",o.loop=!1,o.src=n,await new Promise((c,l)=>{const d=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",f),o.pause(),o.currentTime=0,c()},f=()=>{o.removeEventListener("loadeddata",d),o.removeEventListener("error",f),l(new Error("Failed to load video"))};o.addEventListener("loadeddata",d,{once:!0}),o.addEventListener("error",f,{once:!0}),o.load()}),{element:o,objectUrl:n}}async play(e,t){const r=e,n=t+this.trim.from/1e6;if(Math.abs(r.currentTime-n)>.1&&(r.currentTime=n),r.muted=!1,r.paused)try{await r.play()}catch{try{await r.play()}catch(c){console.warn("Failed to play video:",c)}}}pause(e){const t=e;t.pause(),t.muted=!0}async seek(e,t){const r=e,n=t+this.trim.from/1e6;return r.pause(),r.currentTime=n,new Promise(o=>{if(Math.abs(r.currentTime-t)<.01){o();return}const c=()=>{r.removeEventListener("seeked",c),o()};r.addEventListener("seeked",c,{once:!0}),setTimeout(()=>{r.removeEventListener("seeked",c),o()},500)})}syncPlayback(e,t,r){const n=e,o=(this.trim.to-this.trim.from)/1e6,c=r>=0&&r<o,l=r+this.trim.from/1e6;n.volume=this.volume,t&&c?n.paused?this.play(n,r).catch(console.warn):(n.muted&&(n.muted=!1),(n.ended||n.currentTime>=this.trim.to/1e6)&&(n.currentTime=l,n.play().catch(console.warn))):(n.paused||n.pause(),n.muted=!0,c&&Math.abs(n.currentTime-l)>.1&&(n.currentTime=l))}cleanupPlayback(e,t){const r=e;r.pause(),r.removeAttribute("src"),r.load(),t&&URL.revokeObjectURL(t)}async scaleToFit(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.min(e/r,t/n);this.width=r*o,this.height=n*o}async scaleToFill(e,t){await this.ready;const{width:r,height:n}=this.meta;if(r===0||n===0)return;const o=Math.max(e/r,t/n);this.width=r*o,this.height=n*o}centerInScene(e,t){this.left=(e-this.width)/2,this.top=(t-this.height)/2}}function yx(s,e,t,r){const n={duration:0,width:0,height:0,audioSampleRate:0,audioChanCount:0};if(s.video!=null&&e.length>0){n.width=s.video.codedWidth??0,n.height=s.video.codedHeight??0;const l=(Math.round(r/90)*90+360)%360;(l===90||l===270)&&([n.width,n.height]=[n.height,n.width])}s.audio!=null&&t.length>0&&(n.audioSampleRate=oe.sampleRate,n.audioChanCount=oe.channelCount);let o=0,c=0;if(e.length>0)for(let l=e.length-1;l>=0;l--){const d=e[l];if(!d.deleted){o=d.cts+d.duration;break}}if(t.length>0){const l=t.at(-1);c=l.cts+l.duration}return n.duration=Math.max(o,c),n}function xx(s,e,t,r,n){return{audioFrameFinder:n===0||s.audio==null||r.length===0?null:new wx(e,r,s.audio,{volume:n,targetSampleRate:oe.sampleRate}),videoFrameFinder:s.video==null||t.length===0?null:new bx(e,t,s.video)}}async function Ku(s,e={}){let t=null;const r={video:null,audio:null};let n=[],o=[],c=[];const l={perspective:1,rotationRad:0,rotationDeg:0,scaleX:1,scaleY:1,translateX:0,translateY:0};let d=-1,f=-1;const m=await s.createReader();await gx(m,async _=>{t=_.info;const y=_.mp4boxFile.ftyp;c.push({start:y.start,size:y.size});const a=_.mp4boxFile.moov;c.push({start:a.start,size:a.size}),Object.assign(l,vx(t.videoTracks[0]?.matrix));let{videoDecoderConf:h,audioDecoderConf:u}=To(_.mp4boxFile,_.info);if(r.video=h??null,r.audio=u??null,h==null&&u==null&&W.error("VideoClip no video and audio track"),u!=null){const{supported:p}=await AudioDecoder.isConfigSupported(u);p||W.error(`VideoClip audio codec is not supported: ${u.codec}`)}if(h!=null){const{supported:p}=await VideoDecoder.isConfigSupported(h);p||W.error(`VideoClip video codec is not supported: ${h.codec}`)}W.info("mp4BoxFile moov ready",{..._.info,tracks:null,videoTracks:null,audioTracks:null},r)},(_,y,a)=>{if(y==="video"){d===-1&&(d=a[0].dts);for(const h of a)n.push(ju(h,d,"video"))}else if(y==="audio"&&e.audio){f===-1&&(f=a[0].dts);for(const h of a)o.push(ju(h,f,"audio"))}}),await m.close();const g=n.at(-1)??o.at(-1);if(t==null)throw Error("VideoClip stream is done, but not emit ready");if(g==null)throw Error("VideoClip stream not contain any sample");return Co(n),W.info("mp4 stream parsed"),{videoSamples:n,audioSamples:o,decoderConf:r,headerBoxPos:c,parsedMatrix:l}}function ju(s,e=0,t){let r=s.offset;const n=t==="video"&&s.is_sync?Rx(s.data,s.description.type):-1;let o=s.size;return n>0&&(r+=n,o-=n),{...s,is_idr:n>=0,offset:r,size:o,cts:(s.cts-e)/s.timescale*1e6,dts:(s.dts-e)/s.timescale*1e6,duration:s.duration/s.timescale*1e6,timescale:1e6,data:t==="video"?null:s.data}}class bx{constructor(e,t,r){this.localFileReader=e,this.samples=t,this.conf=r}decoder=null;timestamp=0;curAborter={abort:!1,st:performance.now()};find=async e=>{(this.decoder==null||this.decoder.state==="closed"||e<=this.timestamp||e-this.timestamp>3e6)&&this.reset(e),this.curAborter.abort=!0,this.timestamp=e,this.curAborter={abort:!1,st:performance.now()};const t=await this.parseFrame(e,this.decoder,this.curAborter);return this.sleepCnt=0,t};lastVfDur=0;downgradeSoftDecode=!1;videoDecCursorIdx=0;videoFrames=[];outputFrameCnt=0;inputChunkCnt=0;sleepCnt=0;predecodeErr=!1;parseFrame=async(e,t,r)=>{if(t==null||t.state==="closed"||r.abort)return null;if(this.videoFrames.length>0){const n=this.videoFrames[0];return e<n.timestamp?null:(this.videoFrames.shift(),e>n.timestamp+(n.duration??0)?(n.close(),await this.parseFrame(e,t,r)):(!this.predecodeErr&&this.videoFrames.length<10&&this.startDecode(t).catch(o=>{throw this.predecodeErr=!0,this.reset(e),o}),n))}if(this.decoding||this.outputFrameCnt<this.inputChunkCnt&&t.decodeQueueSize>0){if(performance.now()-r.st>6e3)throw Error(`VideoClip.tick video timeout, ${JSON.stringify(this.getState())}`);this.sleepCnt+=1,await ws(15)}else{if(this.videoDecCursorIdx>=this.samples.length)return null;try{await this.startDecode(t)}catch(n){throw this.reset(e),n}}return await this.parseFrame(e,t,r)};decoding=!1;startDecode=async e=>{if(this.decoding||e.decodeQueueSize>600)return;let t=this.videoDecCursorIdx+1;if(t>this.samples.length)return;this.decoding=!0;let r=!1;for(;t<this.samples.length;t++){const n=this.samples[t];if(!r&&!n.deleted&&(r=!0),n.is_idr)break}if(r){const n=this.samples.slice(this.videoDecCursorIdx,t);if(n[0]?.is_idr!==!0)W.warn("First sample not idr frame");else{const o=performance.now(),c=await Ax(n,this.localFileReader),l=performance.now()-o;if(l>1e3){const d=n[0],f=n.at(-1),m=f.offset+f.size-d.offset;W.warn(`Read video samples time cost: ${Math.round(l)}ms, file chunk size: ${m}`)}if(e.state==="closed")return;this.lastVfDur=c[0]?.duration??0,Px(e,c,{onDecodingError:d=>{if(this.downgradeSoftDecode)throw d;this.outputFrameCnt===0&&(this.downgradeSoftDecode=!0,W.warn("Downgrade to software decode"),this.reset())}}),this.inputChunkCnt+=c.length}}this.videoDecCursorIdx=t,this.decoding=!1};reset=e=>{if(this.decoding=!1,this.videoFrames.forEach(r=>r.close()),this.videoFrames=[],e==null||e===0)this.videoDecCursorIdx=0;else{let r=0;for(let n=0;n<this.samples.length;n++){const o=this.samples[n];if(o.is_idr&&(r=n),!(o.cts<e)){this.videoDecCursorIdx=r;break}}}this.inputChunkCnt=0,this.outputFrameCnt=0,this.decoder?.state!=="closed"&&this.decoder?.close();const t={...this.conf,...this.downgradeSoftDecode?{hardwareAcceleration:"prefer-software"}:{}};this.decoder=new VideoDecoder({output:r=>{if(this.outputFrameCnt+=1,r.timestamp===-1){r.close();return}let n=r;r.duration==null&&(n=new VideoFrame(r,{duration:this.lastVfDur}),r.close()),this.videoFrames.push(n)},error:r=>{if(r.message.includes("Codec reclaimed due to inactivity")){this.decoder=null,W.warn(r.message);return}const n=`VideoFinder VideoDecoder err: ${r.message}, config: ${JSON.stringify(t)}, state: ${JSON.stringify(this.getState())}`;throw W.error(n),Error(n)}}),this.decoder.configure(t)};getState=()=>({time:this.timestamp,decState:this.decoder?.state,decQSize:this.decoder?.decodeQueueSize,decCursorIdx:this.videoDecCursorIdx,sampleLen:this.samples.length,inputCnt:this.inputChunkCnt,outputCnt:this.outputFrameCnt,cacheFrameLen:this.videoFrames.length,softDecode:this.downgradeSoftDecode,clipIdCnt:wo,sleepCnt:this.sleepCnt,memInfo:Ju()});destroy=()=>{this.decoder?.state!=="closed"&&this.decoder?.close(),this.decoder=null,this.curAborter.abort=!0,this.videoFrames.forEach(e=>e.close()),this.videoFrames=[],this.localFileReader.close()}}function Tx(s,e){for(let t=0;t<e.length;t++){const r=e[t];if(s>=r.cts&&s<r.cts+r.duration)return t;if(r.cts>s)break}return 0}class wx{constructor(e,t,r,n){this.localFileReader=e,this.samples=t,this.conf=r,this.volume=n.volume,this.sampleRate=n.targetSampleRate}volume=1;sampleRate;setVolume(e){this.volume=e,this.reset()}decoder=null;curAborter={abort:!1,st:performance.now()};find=async e=>{const t=e<=this.timestamp||e-this.timestamp>1e5;(this.decoder==null||this.decoder.state==="closed"||t)&&this.reset(),t&&(this.timestamp=e,this.decCursorIdx=Tx(e,this.samples)),this.curAborter.abort=!0;const r=e-this.timestamp;this.timestamp=e,this.curAborter={abort:!1,st:performance.now()};const n=await this.parseFrame(Math.ceil(r*(this.sampleRate/1e6)),this.decoder,this.curAborter);return this.sleepCnt=0,n};timestamp=0;decCursorIdx=0;pcmData={frameCnt:0,data:[]};sleepCnt=0;parseFrame=async(e,t=null,r)=>{if(t==null||r.abort||t.state==="closed"||e===0)return[];const n=this.pcmData.frameCnt-e;if(n>0)return n<oe.sampleRate/10&&this.startDecode(t),Zu(this.pcmData,e);if(t.decoding){if(performance.now()-r.st>3e3)throw r.abort=!0,Error(`VideoClip.tick audio timeout, ${JSON.stringify(this.getState())}`);this.sleepCnt+=1,await ws(15)}else{if(this.decCursorIdx>=this.samples.length-1)return Zu(this.pcmData,this.pcmData.frameCnt);this.startDecode(t)}return this.parseFrame(e,t,r)};startDecode=e=>{if(e.decodeQueueSize>10)return;const r=[];let n=this.decCursorIdx;for(;n<this.samples.length;){const o=this.samples[n];if(n+=1,!o.deleted&&(r.push(o),r.length>=10))break}this.decCursorIdx=n,e.decode(r.map(o=>new EncodedAudioChunk({type:"key",timestamp:o.cts,duration:o.duration,data:o.data})))};reset=()=>{this.timestamp=0,this.decCursorIdx=0,this.pcmData={frameCnt:0,data:[]},this.decoder?.close(),this.decoder=Sx(this.conf,{resampleRate:oe.sampleRate,volume:this.volume},e=>{this.pcmData.data.push(e),this.pcmData.frameCnt+=e[0].length})};getState=()=>({time:this.timestamp,decState:this.decoder?.state,decQSize:this.decoder?.decodeQueueSize,decCursorIdx:this.decCursorIdx,sampleLen:this.samples.length,pcmLen:this.pcmData.frameCnt,clipIdCnt:wo,sleepCnt:this.sleepCnt,memInfo:Ju()});destroy=()=>{this.decoder=null,this.curAborter.abort=!0,this.pcmData={frameCnt:0,data:[]},this.localFileReader.close()}}function Sx(s,e,t){let r=0,n=0;const o=m=>{if(n+=1,m.length!==0){if(e.volume!==1)for(const g of m)for(let _=0;_<g.length;_++)g[_]*=e.volume;m.length===1&&(m=[m[0],m[0]]),t(m)}},c=Cx(o),l=e.resampleRate!==s.sampleRate;let d=new AudioDecoder({output:m=>{const g=ia(m);l?c(()=>bf(g,m.sampleRate,{rate:e.resampleRate,chanCount:m.numberOfChannels})):o(g),m.close()},error:m=>{m.message.includes("Codec reclaimed due to inactivity")||f("VideoClip AudioDecoder err",m)}});d.configure(s);function f(m,g){const _=`${m}: ${g.message}, state: ${JSON.stringify({qSize:d.decodeQueueSize,state:d.state,inputCnt:r,outputCnt:n})}`;throw W.error(_),Error(_)}return{decode(m){r+=m.length;try{for(const g of m)d.decode(g)}catch(g){f("decode audio chunk error",g)}},close(){d.state!=="closed"&&d.close()},get decoding(){return r>n&&d.decodeQueueSize>0},get state(){return d.state},get decodeQueueSize(){return d.decodeQueueSize}}}function Cx(s){const e=[];let t=0;function r(c,l){e[l]=c,n()}function n(){const c=e[t];c!=null&&(s(c),t+=1,n())}let o=0;return c=>{const l=o;o+=1,c().then(d=>r(d,l)).catch(d=>r(d,l))}}function Zu(s,e){const t=[new Float32Array(e),new Float32Array(e)];let r=0,n=0;for(;n<s.data.length;){const[o,c]=s.data[n];if(r+o.length>e){const l=e-r;t[0].set(o.subarray(0,l),r),t[1].set(c.subarray(0,l),r),s.data[n][0]=o.subarray(l,o.length),s.data[n][1]=c.subarray(l,c.length);break}else t[0].set(o,r),t[1].set(c,r),r+=o.length,n++}return s.data=s.data.slice(n),s.frameCnt-=e,t}async function Ax(s,e){const t=s[0],r=s.at(-1);if(r==null)return[];const n=r.offset+r.size-t.offset;if(n<3e7){const o=new Uint8Array(await e.read(n,{at:t.offset}));return s.map(c=>{const l=c.offset-t.offset;return new EncodedVideoChunk({type:c.is_sync?"key":"delta",timestamp:c.cts,duration:c.duration,data:o.subarray(l,l+c.size)})})}return await Promise.all(s.map(async o=>new EncodedVideoChunk({type:o.is_sync?"key":"delta",timestamp:o.cts,duration:o.duration,data:await e.read(o.size,{at:o.offset})})))}function Ex(s,e){if(s.length===0)return[];let t=0,r=0,n=-1;for(let d=0;d<s.length;d++){const f=s[d];if(n===-1&&e<f.cts&&(n=d-1),f.is_idr)if(n===-1)t=d;else{r=d;break}}const o=s[n];if(o==null)throw Error("Not found video sample by time");const c=s.slice(0,r===0?s.length:r).map(d=>({...d}));for(let d=t;d<c.length;d++){const f=c[d];e<f.cts&&(f.deleted=!0,f.cts=-1)}Co(c);const l=s.slice(o.is_idr?n:t).map(d=>({...d,cts:d.cts-e}));for(const d of l)d.cts<0&&(d.deleted=!0,d.cts=-1);return Co(l),[c,l]}function Ix(s,e){if(s.length===0)return[];let t=-1;for(let o=0;o<s.length;o++){const c=s[o];if(!(e>c.cts)){t=o;break}}if(t===-1)throw Error("Not found audio sample by time");const r=s.slice(0,t).map(o=>({...o})),n=s.slice(t).map(o=>({...o,cts:o.cts-e}));return[r,n]}function Px(s,e,t){if(s.state==="configured"){for(let r=0;r<e.length;r++)s.decode(e[r]);s.flush().catch(r=>{if(!(r instanceof Error))throw r;if(r.message.includes("Decoding error")&&t.onDecodingError!=null){t.onDecodingError(r);return}if(!r.message.includes("Aborted due to close"))throw r})}}function Rx(s,e){if(e!=="avc1"&&e!=="hvc1")return 0;const t=new DataView(s.buffer);for(let r=0;r<s.byteLength-4;){if(e==="avc1"){const n=t.getUint8(r+4)&31;if(n===5||n===7||n===8)return r}else if(e==="hvc1"){const n=t.getUint8(r+4)>>1&63;if(n===19||n===20||n===32||n===33||n===34)return r}r+=t.getUint32(r)+4}return-1}function Co(s){let e=0,t=null;for(const r of s)if(!r.deleted){if(r.is_sync&&(e+=1),e>=2)break;(t==null||r.cts<t.cts)&&(t=r)}t!=null&&t.cts<2e5&&(t.duration+=t.cts,t.cts=0)}function Ju(){try{const s=performance.memory;return{jsHeapSizeLimit:s.jsHeapSizeLimit,totalJSHeapSize:s.totalJSHeapSize,usedJSHeapSize:s.usedJSHeapSize,percentUsed:(s.usedJSHeapSize/s.jsHeapSizeLimit).toFixed(3),percentTotal:(s.totalJSHeapSize/s.jsHeapSizeLimit).toFixed(3)}}catch{return{}}}class Ze extends kt{type="Text";ready;_meta={duration:1/0,width:0,height:0};get meta(){return{...this._meta}}get width(){return this._width}set width(e){this.width!==e&&(this._width=e,this.refreshText(),this.emit("propsChange",{width:e}))}get height(){return this._height}set height(e){this.height!==e&&(this._height=e,this.refreshText(),this.emit("propsChange",{height:e}))}_text="";get text(){return this._text}set text(e){this._text!==e&&(this._text=e,this.originalOpts&&this.textStyle&&this.refreshText())}get style(){return{fontSize:this.originalOpts.fontSize,fontFamily:this.originalOpts.fontFamily,fontWeight:this.originalOpts.fontWeight,fontStyle:this.originalOpts.fontStyle,fill:this.originalOpts.fill,align:this.originalOpts.align,stroke:this.originalOpts.stroke?typeof this.originalOpts.stroke=="object"?{color:this.originalOpts.stroke.color,width:this.originalOpts.stroke.width,join:this.originalOpts.stroke.join,cap:this.originalOpts.stroke.cap,miterLimit:this.originalOpts.stroke.miterLimit}:{color:this.originalOpts.stroke,width:this.originalOpts.strokeWidth??0}:void 0,dropShadow:this.originalOpts.dropShadow?{color:this.originalOpts.dropShadow.color??"#000000",alpha:this.originalOpts.dropShadow.alpha??.5,blur:this.originalOpts.dropShadow.blur??4,distance:this.originalOpts.dropShadow.distance??0,angle:this.originalOpts.dropShadow.angle??0}:void 0,wordWrap:this.originalOpts.wordWrap,wordWrapWidth:this.originalOpts.wordWrapWidth,lineHeight:this.originalOpts.lineHeight,letterSpacing:this.originalOpts.letterSpacing,textCase:this.originalOpts.textCase,textDecoration:this.originalOpts.textDecoration}}set style(e){this.updateStyle(e)}get textAlign(){return this.originalOpts.align||this.originalOpts.textAlign||"left"}set textAlign(e){this.updateStyle({align:e})}get verticalAlign(){return this.originalOpts.verticalAlign||this.originalOpts.textDecoration||"top"}set verticalAlign(e){["underline","overline","strikethrough","line-through"].includes(e)?(this.updateStyle({textDecoration:e==="strikethrough"?"line-through":e}),this.originalOpts.verticalAlign=e):this.updateStyle({verticalAlign:e})}get textCase(){return this.originalOpts.textCase||"none"}set textCase(e){this.updateStyle({textCase:e})}pixiText=null;textStyle;renderTexture=null;externalRenderer=null;pixiApp=null;originalOpts;id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effects=[];constructor(e,t={},r){super(),this.originalOpts={...t},this.text=e,this.externalRenderer=r??null,console.log("[TextClip] Constructor:",{opts:t});const n=this.createStyleFromOpts(t),o=new De(n);this.textStyle=o,this.ready=(async()=>{await this.refreshText();const c={...this._meta};return W.info("TextClip ready:",c),c})()}setRenderer(e){this.externalRenderer=e,console.log("SET RENDERER",e)}async getRenderer(){if(this.externalRenderer!=null)return this.externalRenderer;if(this.pixiApp?.renderer==null)throw new Error("TextClip: Failed to create renderer. Please provide a renderer via constructor or setRenderer() method.");return this.pixiApp.renderer}async getTexture(){return this.pixiText==null||this.renderTexture==null?null:((await this.getRenderer()).render({container:this.pixiText,target:this.renderTexture}),this.renderTexture)}async tick(e){if(await this.ready,this.pixiText==null||this.renderTexture==null)throw new Error("TextClip not initialized");if(this.renderTexture.width<=0||this.renderTexture.height<=0)throw new Error(`Invalid RenderTexture dimensions: ${this.renderTexture.width}x${this.renderTexture.height}`);(await this.getRenderer()).render({container:this.pixiText,target:this.renderTexture});const r=this.renderTexture.source?.resource?.source;let n;if(r instanceof HTMLCanvasElement)n=await createImageBitmap(r);else if(r instanceof OffscreenCanvas)n=await createImageBitmap(r);else{const l=(await this.getRenderer()).extract.canvas(this.renderTexture);if(l instanceof HTMLCanvasElement||l instanceof OffscreenCanvas)n=await createImageBitmap(l);else{const d=this.renderTexture.width,f=this.renderTexture.height;throw new OffscreenCanvas(d,f).getContext("2d")==null?new Error("Failed to create 2d context for fallback rendering"):new Error("Unable to extract canvas from render texture")}}return{video:n,state:"success"}}async split(e){await this.ready;const t=await this.clone(),r=await this.clone();return[t,r]}addEffect(e){this.effects.push(e)}editEffect(e,t){const r=this.effects.find(n=>n.id===e);r&&Object.assign(r,t)}removeEffect(e){const t=this.effects.findIndex(r=>r.id===e);t!==-1&&this.effects.splice(t,1)}async clone(){await this.ready;const e=this.textStyle,t=this.originalOpts||{},r=c=>{if(c!=null){if(typeof c=="number")return c;if(c instanceof le)return c.toNumber()}},n={fontSize:t.fontSize??e.fontSize,fontFamily:t.fontFamily??(Array.isArray(e.fontFamily)?e.fontFamily[0]:typeof e.fontFamily=="string"?e.fontFamily:"Roboto"),fontWeight:t.fontWeight??e.fontWeight,fontStyle:t.fontStyle??e.fontStyle,align:t.align??(e.align==="justify"?"left":e.align),textCase:t.textCase,textDecoration:t.textDecoration};if(t.fill&&typeof t.fill=="object"&&"type"in t.fill&&t.fill.type==="gradient")n.fill=t.fill;else{const c=r(e.fill);n.fill=c??16777215}if(t.stroke&&typeof t.stroke=="object"&&"color"in t.stroke)n.stroke=t.stroke;else{const c=r(e.stroke);c!==void 0&&(n.stroke=c),n.strokeWidth=t.strokeWidth??e.strokeThickness??0}if(t.dropShadow)n.dropShadow=t.dropShadow;else if(e.dropShadow){const c=e.dropShadow,l=r(c.color);l!==void 0&&(n.dropShadow={color:l,alpha:c.alpha,blur:c.blur,angle:c.angle,distance:c.distance})}if(t.wordWrap!==void 0?(n.wordWrap=t.wordWrap,n.wordWrapWidth=t.wordWrapWidth):e.wordWrap&&(n.wordWrap=e.wordWrap,n.wordWrapWidth=e.wordWrapWidth),t.lineHeight!==void 0)n.lineHeight=t.lineHeight;else if(e.lineHeight!==void 0){const c=n.fontSize??e.fontSize??40;n.lineHeight=e.lineHeight/c}t.letterSpacing!==void 0?n.letterSpacing=t.letterSpacing:e.letterSpacing!==void 0&&(n.letterSpacing=e.letterSpacing);const o=new Ze(this.text,n);return await o.ready,this.copyStateTo(o),o.id=this.id,o.effects=[...this.effects],o}async updateStyle(e){this.originalOpts={...this.originalOpts,...e};const t=this.createStyleFromOpts(this.originalOpts),r=new De(t);this.textStyle=r,await this.refreshText()}async refreshText(){const e=this.textStyle;let t=this.text;const r=this.originalOpts.textCase;r==="uppercase"?t=t.toUpperCase():r==="lowercase"?t=t.toLowerCase():r==="title"&&(t=t.replace(/\w\S*/g,y=>y.charAt(0).toUpperCase()+y.substring(1).toLowerCase())),this.pixiText?(this.pixiText.text=t,this.pixiText.style=e,this.pixiText.children.forEach(y=>{y instanceof Ce&&y.destroy()}),this.pixiText.removeChildren()):this.pixiText=new Nv({text:t,style:e});const n=this.originalOpts.textDecoration||this.originalOpts.verticalAlign;if(n&&n!=="none"&&["underline","overline","strikethrough","line-through"].includes(n)){const y=n==="strikethrough"?"line-through":n,a=Be.measureText(t,e),h=e.fontSize??40,u=Math.max(1,h/12);let p=16777215;typeof e.fill=="number"?p=e.fill:e.fill&&typeof e.fill=="object"&&"fill"in e.fill&&(p=16777215);const v=new Ce,x=e.lineHeight??a.lineHeight;for(let b=0;b<a.lines.length;b++){const T=a.lineWidths[b];let w=0;e.align==="center"?w=(a.maxLineWidth-T)/2:e.align==="right"&&(w=a.maxLineWidth-T);const S=b*x;let E=0;y==="underline"?E=x:y==="line-through"?E=x/2:y==="overline"&&(E=0);const A=S+E;v.rect(w,A,T,u),v.fill(p)}this.pixiText.addChild(v)}const o=this.pixiText.getLocalBounds(),c=Math.ceil(o.width||this.pixiText.width||1),l=Math.ceil(o.height||this.pixiText.height||1);let d=Math.max(1,c);e.wordWrap&&e.wordWrapWidth>0&&(d=Math.max(d,e.wordWrapWidth));const f=Math.max(d,this.width||0),m=Math.max(l,this.height||0),g=this.textAlign;g==="center"?this.pixiText.x=(f-c)/2:g==="right"?this.pixiText.x=f-c:this.pixiText.x=0;const _=this.originalOpts.verticalAlign||"top";_==="center"?this.pixiText.y=(m-l)/2:_==="bottom"?this.pixiText.y=m-l:this.pixiText.y=0,this.renderTexture&&this.renderTexture.destroy(!0),this.renderTexture=Ae.create({width:f,height:m}),this._meta.width=f,this._meta.height=m,this._width=f,this._height=m,this.duration===0&&this._meta.duration!==1/0&&(this.duration=this._meta.duration,this.display.to=this.display.from+this.duration)}createStyleFromOpts(e){const t=e.fontSize??40,r=e.lineHeight??1,n={fontSize:t,fontFamily:e.fontFamily??"Roboto",fontWeight:e.fontWeight??"normal",fontStyle:e.fontStyle??"normal",align:e.align??"left",wordWrap:e.wordWrap??!1,wordWrapWidth:e.wordWrapWidth??100,lineHeight:t*r,letterSpacing:e.letterSpacing??0};if(e.fill&&typeof e.fill=="object"&&e.fill.type==="gradient"){const o=new Ke(e.fill.x0,e.fill.y0,e.fill.x1,e.fill.y1);e.fill.colors.forEach(({ratio:c,color:l})=>{const d=typeof l=="number"?l:Ee(l)??16777215;o.addColorStop(c,d)}),n.fill={fill:o}}else{const{color:o,alpha:c}=Vt(e.fill);n.fill=o,c<1&&(n.fillAlpha=c)}if(e.stroke&&typeof e.stroke=="object"&&"color"in e.stroke){const o=Ee(e.stroke.color);o!==void 0&&(n.stroke={color:o,width:e.stroke.width},e.stroke.join&&(n.stroke.join=e.stroke.join),e.stroke.cap&&(n.stroke.cap=e.stroke.cap),e.stroke.miterLimit&&(n.stroke.miterLimit=e.stroke.miterLimit))}else{const o=Ee(e.stroke),c=e.strokeWidth??0;o!==void 0&&c>0?n.stroke={color:o,width:c}:e.strokeWidth&&e.strokeWidth>0&&(n.stroke={color:0,width:e.strokeWidth})}if(e.dropShadow){const o=Ee(e.dropShadow.color);o!==void 0&&(n.dropShadow={color:o,alpha:e.dropShadow.alpha??.5,blur:e.dropShadow.blur??4,angle:e.dropShadow.angle??Math.PI/6,distance:e.dropShadow.distance??2})}return n}destroy(){if(!this.destroyed){W.info("TextClip destroy");try{this.pixiText!=null&&this.pixiText.destroyed!==!0&&this.pixiText.destroy({children:!0})}catch{}finally{this.pixiText=null}try{this.renderTexture!=null&&this.renderTexture.destroyed!==!0&&this.renderTexture.destroy(!0)}catch{}finally{this.renderTexture=null}if(this.externalRenderer=null,this.pixiApp!=null)try{const e=this.pixiApp;e.destroyed!==!0&&e.renderer!=null&&this.pixiApp.destroy(!0,{children:!0,texture:!0})}catch{}finally{this.pixiApp=null}super.destroy()}}toJSON(e=!1){const t=super.toJSON(e),r={};return this.originalOpts.fontSize!==void 0&&(r.fontSize=this.originalOpts.fontSize),this.originalOpts.fontFamily!==void 0&&(r.fontFamily=this.originalOpts.fontFamily),this.originalOpts.fontWeight!==void 0&&(r.fontWeight=this.originalOpts.fontWeight),this.originalOpts.fontStyle!==void 0&&(r.fontStyle=this.originalOpts.fontStyle),this.originalOpts.fill!==void 0&&(r.color=this.originalOpts.fill),this.originalOpts.align!==void 0&&(r.align=this.originalOpts.align),this.originalOpts.wordWrap!==void 0&&(r.wordWrap=this.originalOpts.wordWrap),this.originalOpts.wordWrapWidth!==void 0&&(r.wordWrapWidth=this.originalOpts.wordWrapWidth),this.originalOpts.lineHeight!==void 0&&(r.lineHeight=this.originalOpts.lineHeight),this.originalOpts.letterSpacing!==void 0&&(r.letterSpacing=this.originalOpts.letterSpacing),this.originalOpts.stroke&&(typeof this.originalOpts.stroke=="object"?r.stroke={color:this.originalOpts.stroke.color,width:this.originalOpts.stroke.width,join:this.originalOpts.stroke.join,cap:this.originalOpts.stroke.cap,miterLimit:this.originalOpts.stroke.miterLimit}:r.stroke={color:this.originalOpts.stroke,width:this.originalOpts.strokeWidth??0}),this.originalOpts.dropShadow&&(r.shadow={color:this.originalOpts.dropShadow.color??"#000000",alpha:this.originalOpts.dropShadow.alpha??.5,blur:this.originalOpts.dropShadow.blur??4,distance:this.originalOpts.dropShadow.distance??0,angle:this.originalOpts.dropShadow.angle??0}),{...t,type:"Text",text:this.text,style:r,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Text")throw new Error(`Expected Text, got ${e.type}`);const t=e.text||"",r=e.style||{},n={};r.fontSize!==void 0&&(n.fontSize=r.fontSize),r.fontFamily!==void 0&&(n.fontFamily=r.fontFamily),r.fontWeight!==void 0&&(n.fontWeight=r.fontWeight),r.fontStyle!==void 0&&(n.fontStyle=r.fontStyle),r.color!==void 0&&(n.fill=r.color),r.align!==void 0&&(n.align=r.align),r.wordWrap!==void 0&&(n.wordWrap=r.wordWrap),r.wordWrapWidth!==void 0&&(n.wordWrapWidth=r.wordWrapWidth),r.lineHeight!==void 0&&(n.lineHeight=r.lineHeight),r.letterSpacing!==void 0&&(n.letterSpacing=r.letterSpacing),r.stroke&&(r.stroke.join||r.stroke.cap||r.stroke.miterLimit!==void 0?n.stroke={color:r.stroke.color,width:r.stroke.width,join:r.stroke.join,cap:r.stroke.cap,miterLimit:r.stroke.miterLimit}:(n.stroke=r.stroke.color,n.strokeWidth=r.stroke.width)),r.shadow&&(n.dropShadow={color:r.shadow.color,alpha:r.shadow.alpha,blur:r.shadow.blur,distance:r.shadow.distance,angle:r.shadow.angle});const o=new Ze(t,n);return o.left=e.left,o.top=e.top,o.width=e.width,o.height=e.height,o.angle=e.angle,o.display.from=e.display.from,o.display.to=e.display.to,o.duration=e.duration,o.playbackRate=e.playbackRate,o.zIndex=e.zIndex,o.opacity=e.opacity,o.flip=e.flip,e.animation&&o.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(o.id=e.id),e.effects&&(o.effects=e.effects),await o.ready,o}}class Je extends kt{type="Effect";ready;_meta={duration:5e6,width:0,height:0};get meta(){return{...this._meta}}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;effect;constructor(e){super(),this.effect={id:`eff_${Date.now()}`,key:e,name:e},this.ready=Promise.resolve(this._meta),this.duration=this._meta.duration}async clone(){const e=new Je(this.effect.key);return this.copyStateTo(e),e.id=this.id,e}async tick(e){return{video:void 0,state:"success"}}async split(e){const t=await this.clone(),r=await this.clone();return[t,r]}toJSON(e=!1){return{...super.toJSON(e),type:"Effect",effect:this.effect,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Effect")throw new Error(`Expected Effect, got ${e.type}`);const t=new Je(e.effect.key);return t.effect=e.effect,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),await t.ready,t}}class pi extends kt{type="Transition";ready;_meta={duration:2e6,width:0,height:0};get meta(){return{...this._meta}}id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;transitionEffect;fromClipId=null;toClipId=null;constructor(e){super(),this.transitionEffect={id:`trans_${Date.now()}`,key:e,name:e},this.ready=Promise.resolve(this._meta),this.duration=this._meta.duration}async clone(){const e=new pi(this.transitionEffect.key);return this.copyStateTo(e),e.fromClipId=this.fromClipId,e.toClipId=this.toClipId,e}async tick(e){return{video:void 0,state:"success"}}async split(e){const t=await this.clone(),r=await this.clone();return[t,r]}toJSON(e=!1){return{...super.toJSON(e),type:"Transition",transitionEffect:this.transitionEffect,fromClipId:this.fromClipId,toClipId:this.toClipId,id:this.id,effects:this.effects}}static async fromObject(e){if(e.type!=="Transition")throw new Error(`Expected Transition, got ${e.type}`);const t=new pi(e.transitionEffect.key);return t.transitionEffect=e.transitionEffect,t.fromClipId=e.fromClipId||null,t.toClipId=e.toClipId||null,t.left=e.left,t.top=e.top,t.width=e.width,t.height=e.height,t.angle=e.angle,t.display.from=e.display.from,t.display.to=e.display.to,t.duration=e.duration,t.playbackRate=e.playbackRate,t.zIndex=e.zIndex,t.opacity=e.opacity,t.flip=e.flip,e.animation&&t.setAnimation(e.animation.keyFrames,e.animation.opts),e.id&&(t.id=e.id),await t.ready,t}}class Qu{readable;writable;inputBufOffset=0;constructor(){const e=ke.createFile();let t=!1;this.readable=new ReadableStream({start:r=>{e.onReady=o=>{const c=o.videoTracks[0]?.id;c!=null&&e.setExtractionOptions(c,"video",{nbSamples:100});const l=o.audioTracks[0]?.id;l!=null&&e.setExtractionOptions(l,"audio",{nbSamples:100}),r.enqueue({chunkType:"ready",data:{info:o,file:e}}),e.start()};const n={};e.onSamples=(o,c,l)=>{r.enqueue({chunkType:"samples",data:{id:o,type:c,samples:l.map(d=>({...d}))}}),n[o]=(n[o]??0)+l.length,e.releaseUsedSamples(o,n[o])},e.onFlush=()=>{r.close()}},cancel:()=>{e.stop(),t=!0}},{highWaterMark:50}),this.writable=new WritableStream({write:async r=>{if(t){this.writable.abort();return}const n=r.buffer;n.fileStart=this.inputBufOffset,this.inputBufOffset+=n.byteLength,e.appendBuffer(n)},close:()=>{e.flush(),e.stop(),e.onFlush?.()}})}}function Mx(s){let e=0;const t=s.boxes,r=[];let n=0;async function o(){const a=y(t,e);e=t.length,r.forEach(({track:h,id:u})=>{const p=h.samples.at(-1);p!=null&&(n=Math.max(n,p.cts+p.duration)),s.releaseUsedSamples(u,h.samples.length),h.samples=[]}),s.mdats=[],s.moofs=[],a!=null&&await m?.write(a)}let c=[];function l(){if(c.length>0)return!0;const a=t.findIndex(h=>h.type==="moov");if(a===-1)return!1;if(c=t.slice(0,a+1),e=a+1,r.length===0)for(let h=1;;h+=1){const u=s.getTrackById(h);if(u==null)break;r.push({track:u,id:h})}return!0}let d=0;const f=vs();let m=null;const g=(async()=>{m=await f.createWriter(),d=self.setInterval(()=>{l()&&o()},100)})();let _=!1;return async()=>{if(_)throw Error("File exported");if(_=!0,await g,clearInterval(d),!l()||m==null)return null;s.flush(),await o(),await m?.close();const a=c.find(p=>p.type==="moov");if(a==null)return null;a.mvhd.duration=n;const h=vs(),u=y(c,0);return await Ti(h,u.slice()),await Ti(h,f,{overwrite:!1}),await h.stream()};function y(a,h){if(h>=a.length)return null;const u=new ke.DataStream;u.endianness=ke.DataStream.BIG_ENDIAN;for(let p=h;p<a.length;p++)a[p]!==null&&(a[p].write(u),delete a[p]);return new Uint8Array(u.buffer).slice()}}function Fx(s){const e=new ArrayBuffer(s.byteLength);s.copyTo(e);const t=s.timestamp;return{duration:s.duration??0,dts:t,cts:t,is_sync:s.type==="key",data:e}}async function ed(s){const e=ke.createFile(),t=Mx(e);await Ux(s,e);const r=await t();if(r==null)throw Error("Can not generate file from streams");return r}async function Ux(s,e){let t=0,r=0,n=0,o=0,c=0,l=0,d=null,f=null;for(const m of s){let g=null,_=null,y=null,a=null;if(await new Promise(async h=>{Zo(m.pipeThrough(new Qu),{onDone:h,onChunk:async({chunkType:u,data:p})=>{if(u==="ready"){const{videoTrackConf:v,audioTrackConf:x}=To(p.file,p.info);t===0&&v!=null&&(t=e.addTrack(v)),o===0&&x!=null&&(o=e.addTrack(x))}else if(u==="samples"){const{type:v,samples:x}=p,b=v==="video"?t:o,T=v==="video"?r:c,w=v==="video"?n:l;x.forEach(E=>{let A,P;v==="video"?(g===null&&(g=E.dts,_=E.cts),A=E.dts-g,P=E.cts-(_??0)):(y===null&&(y=E.dts,a=E.cts),A=E.dts-y,P=E.cts-(a??0)),e.addSample(b,E.data,{duration:E.duration,dts:A+T,cts:P+w,is_sync:E.is_sync})});const S=x.at(-1);if(S==null)return;v==="video"?d=S:v==="audio"&&(f=S)}}})}),d!=null&&g!==null&&_!==null){const h=d.dts-g+d.duration,u=d.cts-_+d.duration;r+=h,n+=u}if(f!=null&&d!=null){const h=f.timescale/d.timescale;c=Math.round(r*h),l=Math.round(n*h)}}}async function kx(s){return await ed([s])}function Bx(s){let e=[];const t=new AudioDecoder({output:r=>{e.push(r)},error:W.error});return t.configure(s),{decode:async r=>{r.forEach(o=>{t.decode(new EncodedAudioChunk({type:o.is_sync?"key":"delta",timestamp:1e6*o.cts/o.timescale,duration:1e6*o.duration/o.timescale,data:o.data}))}),await t.flush();const n=e;return e=[],n},close:()=>{t.close()}}}function Dx(s,e){const t={codec:s.codec,sampleRate:s.sampleRate,numberOfChannels:s.numberOfChannels},r=new AudioEncoder({output:c=>{e(Fx(c))},error:c=>{W.error("AudioEncoder error:",c,", config:",t)}});r.configure(t);let n=null;function o(c,l){return new AudioData({timestamp:l,numberOfChannels:s.numberOfChannels,numberOfFrames:c.length/s.numberOfChannels,sampleRate:s.sampleRate,format:"f32-planar",data:new Float32Array(c)})}return{encode:async(c,l)=>{n!=null&&r.encode(o(n.data,n.ts)),n={data:c,ts:l}},stop:async()=>{n!=null&&(Ox(n.data,s.numberOfChannels,s.sampleRate),r.encode(o(n.data,n.ts)),n=null),await r.flush(),r.close()}}}function Ox(s,e,t){const r=s.length-1,n=Math.min(t/2,r);for(let o=0;o<n;o++)for(let c=1;c<=e;c++)s[Math.floor(r/c)-o]*=o/n}function Gx(s,e){W.info("mixinMP4AndAudio, opts:",{volume:e.volume,loop:e.loop});const t=ke.createFile(),{stream:r,stop:n}=Jo(t,500);let o=null,c=null,l=[],d=0,f=0,m=0,g=!0,_=oe.sampleRate;Zo(s.pipeThrough(new Qu),{onDone:async()=>{await c?.stop(),o?.close(),n()},onChunk:async({chunkType:u,data:p})=>{if(u==="ready"){const{videoTrackConf:v,audioTrackConf:x,audioDecoderConf:b}=To(p.file,p.info);d===0&&v!=null&&(d=t.addTrack(v));const T=x??{timescale:1e6,samplerate:_,channel_count:oe.channelCount,hdlr:"soun",name:"SoundHandler",type:"mp4a"};f===0&&(f=t.addTrack(T),_=x?.samplerate??_,g=x!=null);const w=new AudioContext({sampleRate:_});l=bs(await w.decodeAudioData(await new Response(e.stream).arrayBuffer())),b!=null&&(o=Bx(b)),c=Dx(b??{codec:T.type==="mp4a"?oe.codec:T.type,numberOfChannels:T.channel_count,sampleRate:T.samplerate},S=>t.addSample(f,S.data,S))}else if(u==="samples"){const{id:v,type:x,samples:b}=p;if(x==="video"){b.forEach(T=>t.addSample(v,T.data,T)),g||await a(b);return}x==="audio"&&await h(b)}}});function y(u){const p=l.map(v=>e.loop?Ts(v,m,m+u):v.slice(m,m+u));if(m+=u,e.volume!==1)for(const v of p)for(let x=0;x<v.length;x++)v[x]*=e.volume;return p}async function a(u){const p=u[0],v=u[u.length-1],x=Math.floor((v.cts+v.duration-p.cts)/p.timescale*_),b=ra([y(x)]);b.length!==0&&c?.encode(b,p.cts/p.timescale*1e6)}async function h(u){if(o==null)return;const p=(await o.decode(u)).map(ia),v=ta(p),x=y(v[0].length),b=u[0];c?.encode(ra([v,x]),b.cts/b.timescale*1e6)}return r}const Lx=`
|
|
1296
1296
|
in vec2 aPosition;
|
|
1297
1297
|
out vec2 vTextureCoord;
|
|
1298
1298
|
|
|
@@ -7667,4 +7667,4 @@ vec4 transition(vec2 uv) {
|
|
|
7667
7667
|
bool nextImage = distance(fract(uv * dots), vec2(0.5, 0.5)) < ( progress / distance(uv, center));
|
|
7668
7668
|
return nextImage ? getToColor(uv) : getFromColor(uv);
|
|
7669
7669
|
}
|
|
7670
|
-
`,t2={radialSwipe:{label:"Radial Swipe",fragment:ab}},gi={...mi.reduce((s,e)=>(s[e.name]={label:e.name,fragment:e.glsl,uniforms:e.defaultParams,previewDynamic:`transition: ${e.name}`},s),{}),...t2},i2=Object.entries(gi).map(([s,e])=>({key:s,label:e.label,previewStatic:`https://cdn.subgen.co/previews/static/transition_${s}_static.webp`,previewDynamic:`https://cdn.subgen.co/previews/dynamic/transition_${s}_dynamic.webp`}));function Po({name:s,renderer:e}){let t=mi.find(Y=>Y.name===s);if(!t){const Y=Object.keys(gi).find(Q=>Q.toLowerCase()===s.toLowerCase());Y&&(t=gi[Y])}if(t||(t=mi.find(Y=>Y.name.toLowerCase()===s.toLowerCase())),!t){const Y=[s,s.toLowerCase(),s.charAt(0).toUpperCase()+s.slice(1).toLowerCase(),s.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,""),s.replace(/_/g,"")];for(const Q of Y){if(t=mi.find(Pe=>Pe.name.toLowerCase()===Q.toLowerCase()),t)break;const xe=Object.keys(gi).find(Pe=>Pe.toLowerCase()===Q.toLowerCase());if(xe){t=gi[xe];break}}}if(!t){const Y=mi.length,Q=mi.slice(0,5).map(Pe=>Pe.name).join(", "),xe=Object.keys(gi).slice(0,3).join(", ");throw console.error(`Transition not found: "${s}". Available in gl-transitions (${Y} total):`,Q+"..."),console.error("Available locally:",xe+"..."),new Error(`Transition "${s}" not found in gl-transitions library or local definitions`)}const r=new we(F.WHITE),n=Ae.create({width:e.width,height:e.height}),o=new ct({}),c=new ct({}),l=t.name==="displacement"||s.toLowerCase()==="displacement"||t.label==="displacement",d=l?new ct({}):void 0;let f=null;if(l){f=document.createElement("canvas"),f.width=256,f.height=256;const Y=f.getContext("2d");if(Y){const Q=Y.createImageData(256,256);for(let xe=0;xe<Q.data.length;xe+=4){const Pe=Math.random();Q.data[xe]=Pe*255,Q.data[xe+1]=Pe*255,Q.data[xe+2]=Pe*255,Q.data[xe+3]=255}Y.putImageData(Q,0,0)}}let m=t.glsl||t.fragment;if(!m)throw new Error(`Transition "${s}" has no glsl or fragment code`);let g={...ce.basics,...ce.custom(t)};Object.entries(g).forEach(([,Y])=>{Y.type==="int<f32>"&&(Y.type="i32",typeof Y.value=="number"&&(Y.value=Math.trunc(Y.value))),Y.type==="ivec2<f32>"&&(Y.type="vec2<f32>")}),console.log("Making transition",s),console.log("Transition glsl",m);const _=t.name==="GridFlip"||s.toLowerCase()==="gridflip"||t.label==="gridflip",y=t.name==="circle"||s.toLowerCase()==="circle"||t.label==="circle",a=t.name==="directional"||s.toLowerCase()==="directional"||t.label==="directional",h=t.name==="UndulatingBurnOut"||s.toLowerCase()==="undulatingburnout"||t.label==="undulatingBurnOut",u=t.name==="SquaresWire"||s.toLowerCase()==="squareswire"||t.label==="squaresWire",p=t.name==="rotate_scale_fade"||s.toLowerCase()==="rotatescalefade"||t.label==="rotateScaleFade",v=t.name==="RandomSquares"||s.toLowerCase()==="randomsquares"||t.label==="randomSquares",x=t.name==="polar_function"||s.toLowerCase()==="polar_function"||t.label==="polar_function",b=t.name==="pixelate"||s.toLowerCase()==="pixelate"||t.label==="pixelate",T=t.name==="perlin"||s.toLowerCase()==="perlin"||t.label==="perlin",w=t.name==="luma"||s.toLowerCase()==="luma"||t.label==="luma",S=t.name==="luminance_melt"||s.toLowerCase()==="luminance_melt"||s.toLowerCase()==="luminancemelt"||t.label==="luminance_melt",E=t.name==="hexagonalize"||s.toLowerCase()==="hexagonalize"||t.label==="hexagonalize",A=t.name==="heart"||s.toLowerCase()==="heart"||t.label==="heart",P=t.name==="displacement"||s.toLowerCase()==="displacement"||t.label==="displacement",I=t.name==="directionalwipe"||s.toLowerCase()==="directionalwipe"||s.toLowerCase()==="directional_wipe"||t.label==="directionalwipe",k=t.name==="directionalwarp"||s.toLowerCase()==="directionalwarp"||s.toLowerCase()==="directional_warp"||t.label==="directionalwarp",O=t.name==="crosshatch"||s.toLowerCase()==="crosshatch"||t.label==="crosshatch",X=t.name==="circleopen"||s.toLowerCase()==="circleopen"||s.toLowerCase()==="circle_open"||t.label==="circleopen",ne=t.name==="cannabisleaf"||s.toLowerCase()==="cannabisleaf"||s.toLowerCase()==="cannabis_leaf"||t.label==="cannabisleaf",R=t.name==="StereoViewer"||s.toLowerCase()==="stereoviewer"||s.toLowerCase()==="stereo_viewer"||t.label==="StereoViewer",M=t.name==="GlitchDisplace"||s.toLowerCase()==="glitchDisplace"||t.label==="GlitchDisplace",q=t.name==="CrossZoom"||s.toLowerCase()==="crosszoom"||t.label==="CrossZoom",N=t.name==="CrazyParametricFun"||s.toLowerCase()==="crazyparametricfun"||t.label==="CrazyParametricFun",ee=t.name==="BowTieHorizontal"||s.toLowerCase()==="bowtiehorizontal"||t.label==="BowTieHorizontal",he=t.name==="PolkaDotsCurtain"||s.toLowerCase()==="polkadotscurtain"||t.label==="PolkaDotsCurtain",ye=t.name==="Pixelize"||s.toLowerCase()==="pixelize"||t.label==="Pixelize";_&&(m=lb,g={...ce.basics,...cb}),y&&(m=hb,g={...ce.basics,...sd}),a&&(m=ub,g={...ce.basics,...db}),h&&(m=fb,g={...ce.basics,...pb}),u&&(m=mb,g={...ce.basics,...gb}),p&&(m=vb,g={...ce.basics,..._b}),v&&(m=yb,g={...ce.basics,...xb}),x&&(m=bb,g={...ce.basics,...Tb}),b&&(m=td,g={...ce.basics,...id}),T&&(m=Cb,g={...ce.basics,...Ab}),w&&(m=Eb,g={...ce.basics,...Ib}),S&&(m=Pb,g={...ce.basics,...Rb}),E&&(m=Mb,g={...ce.basics,...Fb}),A&&(m=Ub,g={...ce.basics,...kb}),P&&(m=Bb,g={...ce.basics,...Db}),I&&(m=Ob,g={...ce.basics,...Gb}),k&&(m=Lb,g={...ce.basics,...Nb}),O&&(m=zb,g={...ce.basics,...Hb}),X&&(m=Wb,g={...ce.basics,...sd}),ne&&(m=Vb,g={...ce.basics,...Yb}),R&&(m=Xb,g={...ce.basics,...$b}),M&&(m=qb),q&&(m=Kb,g={...ce.basics,...jb}),N&&(m=Zb,g={...ce.basics,...Jb}),ee&&(m=Qb),he&&(m=e2),ye&&(m=wb,g={...ce.basics,...Sb});const U={from:o,to:c,uniforms:g};l&&d&&(U.displacementMap=d,f&&(d.resource=f,d.update()));const Ie=new Dr({glProgram:new vt({vertex:sb,fragment:ob(m)}),resources:U});return r.filters=[Ie],{render({width:Y,height:Q,from:xe,to:Pe,progress:_i}){if((r.width!==Y||r.height!==Q)&&(r.setSize({width:Y,height:Q}),n.resize(Y,Q)),xe instanceof F?Ie.resources.from=xe.source:(o.resource=xe,o.update(),Ie.resources.from=o),Pe instanceof F?Ie.resources.to=Pe.source:(c.resource=Pe,c.update(),Ie.resources.to=c),l&&d&&f){if(f.width!==Y||f.height!==Q){f.width=Y,f.height=Q;const Ut=f.getContext("2d");if(Ut){const ht=Ut.createImageData(Y,Q);for(let Oe=0;Oe<ht.data.length;Oe+=4){const nt=Math.random();ht.data[Oe]=nt*255,ht.data[Oe+1]=nt*255,ht.data[Oe+2]=nt*255,ht.data[Oe+3]=255}Ut.putImageData(ht,0,0)}}d.resource=f,d.update()}return Ie.resources.uniforms.uniforms.progress=_i,e.render({container:r,target:n,clear:!1,width:Y,height:Q}),n},destroy(){n.destroy(),r.destroy({children:!0})}}}let r2=0;async function nd(s){s()>50&&(await ws(15),await nd(s))}class s2{static async isSupported(e={}){return(self.OffscreenCanvas!=null&&self.VideoEncoder!=null&&self.VideoDecoder!=null&&self.VideoFrame!=null&&self.AudioEncoder!=null&&self.AudioDecoder!=null&&self.AudioData!=null&&((await self.VideoEncoder.isConfigSupported({codec:e.videoCodec??"avc1.42E032",width:e.width??1920,height:e.height??1080,bitrate:e.bitrate??7e6})).supported??!1)&&(await self.AudioEncoder.isConfigSupported({codec:(await aa()).codec,sampleRate:oe.sampleRate,numberOfChannels:oe.channelCount})).supported)??!1}logger=W.create(`id:${r2++},`);destroyed=!1;sprites=[];canvas;pixiApp=null;stopOutput=null;opts;hasVideoTrack;evtTool=new Yo;on=this.evtTool.on;constructor(e={}){const{width:t=0,height:r=0}=e;this.canvas=new OffscreenCanvas(t,r),this.opts=Object.assign({bgColor:"#000",width:0,height:0,videoCodec:"avc1.42E032",audio:!0,bitrate:5e6,fps:30,metaDataTags:null},e),this.hasVideoTrack=t*r>0,aa().catch(n=>{this.logger.warn("Failed to detect audio codec:",n)})}async initPixiApp(){const{width:e,height:t}=this.opts;if(this.pixiApp=new fn,console.log("PIXI APP 000",this.pixiApp),await this.pixiApp.init({canvas:this.canvas,width:e,height:t,backgroundColor:0,antialias:!1,autoDensity:!1,resolution:1,preference:"webgl"}),this.pixiApp.renderer==null||this.pixiApp.stage==null)throw new Error("Pixi.js Application failed to initialize properly");try{const r=this.pixiApp;r.ticker&&typeof r.ticker.stop=="function"&&r.ticker.stop()}catch{}}async addSprite(e,t={}){const r={rect:{x:e.left,y:e.top,w:e.width,h:e.height},display:{...e.display},duration:e.duration,playbackRate:e.playbackRate,zIndex:e.zIndex};this.logger.info("Compositor add clip",r);const n=await e.clone();console.log("PIXI APP 111",this.pixiApp),this.pixiApp!=null&&this.pixiApp.renderer!=null&&typeof n.setRenderer=="function"&&n.setRenderer(this.pixiApp.renderer),this.logger.info("Compositor add clip ready"),this.sprites.push(Object.assign(n,{main:t.main??!1,expired:!1})),this.sprites.sort((o,c)=>o.zIndex-c.zIndex)}initMuxer(e){const{fps:t,width:r,height:n,videoCodec:o,bitrate:c,audio:l,metaDataTags:d}=this.opts,f=this.sprites.some(_=>_.width>0&&_.height>0),m=this.hasVideoTrack&&f;return Jd({video:m?{width:r,height:n,expectFPS:t,codec:o,bitrate:c,__unsafe_hardwareAcceleration__:this.opts.__unsafe_hardwareAcceleration__}:null,audio:l===!1?null:{codec:oe.codecType,sampleRate:oe.sampleRate,channelCount:oe.channelCount},duration:e,metaDataTags:d})}output(e={}){if(this.sprites.length===0)throw Error("No sprite added");const t=this.sprites.find(g=>g.main),n=this.sprites.map(g=>g.display.from+g.duration).filter(g=>g!==1/0),o=e.maxTime??(t!=null?t.display.from+t.duration:n.length>0?Math.max(...n):1/0);if(o===1/0||o<=0)throw Error("Unable to determine the end time, please specify a main sprite, or limit the duration of ImageClip, AudioClip");o===-1&&this.logger.warn("Unable to determine the end time, process value don't update"),this.logger.info(`start combinate video, maxTime:${o}`);const c=this.initMuxer(o);let l=performance.now();const d=this.runEncoding(c,o,{onProgress:g=>{this.logger.debug("OutputProgress:",g),this.evtTool.emit("OutputProgress",g)},onEnded:async()=>{await c.flush(),this.logger.info("===== output ended =====, cost:",performance.now()-l),this.evtTool.emit("OutputProgress",1),this.destroy()},onError:g=>{this.evtTool.emit("error",g),m(g),this.destroy()}});this.stopOutput=()=>{d(),c.close(),m()};const{stream:f,stop:m}=Jo(c.mp4file,500,this.destroy);return f}destroy(){if(!this.destroyed&&(this.destroyed=!0,this.stopOutput?.(),this.evtTool.destroy(),this.pixiApp!=null))try{const e=this.pixiApp;if(e.destroyed===!0){this.pixiApp=null;return}if(e.ticker&&typeof e.ticker.stop=="function")try{e.ticker.stop()}catch{}if(e.renderer!=null){const t=e.renderer.gl;if(t&&t.isContextLost()){this.pixiApp=null;return}this.pixiApp.destroy()}}catch(e){console.warn("Error while destroying Pixi application:",e)}finally{this.pixiApp=null}}runEncoding(e,t,{onProgress:r,onEnded:n,onError:o}){let c=0;const l={aborted:!1};let d=null,f=null;const m=async()=>{const{fps:y,bgColor:a,audio:h}=this.opts,u=Math.round(1e6/y),p=this.sprites.some(b=>b.width>0&&b.height>0);f=n2({pixiApp:this.pixiApp,sprites:this.sprites,aborter:l});const v=o2({muxer:e,canvas:this.canvas,outputAudio:h,hasVideoTrack:this.hasVideoTrack&&p,timeSlice:u,fps:y});let x=0;for(;;){if(d!=null)return;if(l.aborted||t!==-1&&x>t||this.sprites.length===0){g(),await n();return}c=x/t;const{audios:b,mainSprDone:T,hasVideo:w}=await f.render(x);if(T){g(),await n();return}if(l.aborted)return;this.hasVideoTrack&&w&&await new Promise(S=>requestAnimationFrame(S)),v(x,b,w),x+=u,await nd(e.getEncodeQueueSize)}},g=()=>{l.aborted||(l.aborted=!0,clearInterval(_),f?.cleanup(),this.sprites.forEach(y=>{y.destroy()}))};m().catch(y=>{d=y,this.logger.error(y),g(),o(y)});const _=setInterval(()=>{r(c)},500);return g}exportToJSON(){const e=this.sprites.map(r=>ar(r,r.main)),t=[];return this.sprites.forEach(r=>{if(r.transition){const n=this.sprites.filter(o=>o.id!==r.id&&o.zIndex===r.zIndex&&o.display.from<r.display.from&&(o instanceof fe||o instanceof ve)).sort((o,c)=>c.display.to-o.display.to)[0];n&&t.push({key:r.transition.name,duration:r.transition.duration,clips:[n.id,r.id]})}}),{clips:e,transition:t.length>0?t:void 0,settings:{width:this.opts.width,height:this.opts.height,fps:this.opts.fps,bgColor:this.opts.bgColor,videoCodec:this.opts.videoCodec,bitrate:this.opts.bitrate,audio:this.opts.audio,metaDataTags:this.opts.metaDataTags}}}async loadFromJSON(e){this.sprites.forEach(r=>{r.destroy()}),this.sprites=[],e.settings&&(e.settings.width!==void 0&&(this.opts.width=e.settings.width),e.settings.height!==void 0&&(this.opts.height=e.settings.height),e.settings.fps!==void 0&&(this.opts.fps=e.settings.fps),e.settings.bgColor!==void 0&&(this.opts.bgColor=e.settings.bgColor),e.settings.videoCodec!==void 0&&(this.opts.videoCodec=e.settings.videoCodec),e.settings.bitrate!==void 0&&(this.opts.bitrate=e.settings.bitrate),e.settings.audio!==void 0&&(this.opts.audio=e.settings.audio===!1?!1:void 0),e.settings.metaDataTags!==void 0&&(this.opts.metaDataTags=e.settings.metaDataTags));for(const r of e.clips){const n=await lr(r);await this.addSprite(n,{main:r.main||!1})}const t=e.transition||e.transitions;if(t){console.log(`[Compositor] Restoring ${t.length} transitions`);for(const r of t){const n=r.clips[1],o=this.sprites.find(c=>c.id===n);o?(console.log(`[Compositor] Applying transition ${r.key} to clip ${n}`),o.transition={name:r.key,duration:r.duration,prevClipId:r.clips[0]}):console.warn(`[Compositor] Could not find target clip ${n} for transition ${r.key}`)}}else console.log("[Compositor] No transition data found in JSON")}}function n2(s){const{pixiApp:e,sprites:t,aborter:r}=s,n=e!=null,o=new Map,c=new Map,l=new Map,d=Ae.create({width:e?.renderer.width||0,height:e?.renderer.height||0}),f=Ae.create({width:e?.renderer.width||0,height:e?.renderer.height||0}),m=new Ce().rect(0,0,e?.renderer.width||0,e?.renderer.height||0).fill({color:0}),g=new Map,_=T=>t.filter(w=>w.id!==T.id&&w.zIndex===T.zIndex&&w.display.from<T.display.from&&(w instanceof fe||w instanceof ve)).sort((w,S)=>S.display.to-w.display.to)[0]||null,y=async(T,w)=>{let S=null;if(T.transition?.prevClipId&&(S=t.find(I=>I.id===T.transition.prevClipId)||null),S||(S=_(T)),!S)return null;const E=S.duration>0?S.duration:0,A=Math.max(0,Math.min(w-S.display.from,E)),{video:P}=await S.getFrame(A);return P},a=(T,w,S)=>{if(!e)return;e.renderer.render({container:m,target:S,clear:!0});const E=new we(w instanceof F?w:F.from(w));E.x=T.center.x,E.y=T.center.y,E.anchor.set(.5,.5);const A=E.texture.width||1,P=E.texture.height||1,I=T.width&&T.width!==0?Math.abs(T.width)/A:1,k=T.height&&T.height!==0?Math.abs(T.height)/P:1;T.flip==="horizontal"?(E.scale.x=-I,E.scale.y=k):T.flip==="vertical"?(E.scale.x=I,E.scale.y=-k):(E.scale.x=I,E.scale.y=k),E.rotation=(T.flip==null?1:-1)*T.angle,E.alpha=T.opacity,e.renderer.render({container:E,target:S,clear:!1}),w instanceof F||E.texture.destroy(!0),E.destroy()};let h=null,u=null,p=null;n&&e!=null&&(h=new se,u=new se,p=new se,u.sortableChildren=!0,p.sortableChildren=!0,e.stage.addChild(u),e.stage.addChild(p),h.visible=!1,e.stage.addChild(h));const v=[...t].sort((T,w)=>T.zIndex-w.zIndex);return{render:async T=>{const w=[];let S=!1,E=!1;for(const A of l.values())A.visible=!1;for(const A of v){if(r.aborted)break;if(T<A.display.from||A.expired){if(n&&e!=null){const ne=o.get(A);ne&&await ne.updateFrame(null)}continue}const P=T-A.display.from,I=P*A.playbackRate;A.animate(I);const{video:k,audio:O,done:X}=await A.getFrame(P);if(w.push(O),n&&e!=null&&u!=null){if((A instanceof fe||A instanceof ve)&&A.transition&&P>=0&&P<=A.transition.duration){const M=await y(A,T),{video:q}=await A.getFrame(P);if(M&&q){const N=P/A.transition.duration,ee=_(A);ee?a(ee,M,d):e.renderer.render({container:m,target:d,clear:!0}),a(A,q,f);let he=c.get(A.id);he||(he=Po({name:A.transition.name,renderer:e.renderer}),c.set(A.id,he));const ye=he.render({width:e.renderer.width,height:e.renderer.height,from:d,to:f,progress:N});let U=l.get(A.id);U||(U=new we,U.label=`TransitionSprite_${A.id}`,l.set(A.id,U),u.addChild(U)),U.texture=ye,U.visible=!0,U.x=0,U.y=0,U.width=e.renderer.width,U.height=e.renderer.height,U.anchor.set(0,0),U.zIndex=A.zIndex,E=!0;const Ie=o.get(A);if(Ie){const Y=Ie.getSprite();Y&&(Y.visible=!1)}if(ee){const Y=o.get(ee);if(Y){const Q=Y.getSprite();Q&&(Q.visible=!1)}}continue}}let R=o.get(A);R==null&&k!=null&&(R=new or(e,A,u),o.set(A,R)),R!=null&&(k!=null?(E=!0,await R.updateFrame(k)):await R.updateFrame(null)),R?.updateTransforms()}if(A.duration>0&&T>A.display.from+A.duration||X){if(A.main&&(S=!0),A.expired=!0,n){const ne=o.get(A);if(ne!=null){const R=ne.getSprite();R&&(R.visible=!1)}}}else if(n){const ne=o.get(A);ne?.updateTransforms()}}if(n&&e!=null&&h!=null&&u!=null&&p!=null){let A=null;for(const P of t)if(P instanceof Je&&T>=P.display.from&&T<P.display.from+P.duration){A={id:P.id,key:P.effect.key,startTime:P.display.from,duration:P.duration};break}if(!A)for(const P of t){if(P.effects&&P.effects.length>0){for(const I of P.effects)if(T>=I.startTime&&T<I.startTime+I.duration){A=I;break}}if(A)break}p.removeChildren();for(const P of o.values()){const I=P.getSprite();I&&I.parent!==u&&(I.parent&&I.parent.removeChild(I),u.addChild(I))}if(A){const{key:P,startTime:I,duration:k,id:O}=A,X=T-I,ne=k>0?Math.min(Math.max(X/k,0),1):0,R=t.some(M=>M.id===O&&M instanceof Je);for(const M of t){let q=!1;if(R?q=M.id!==O&&!(M instanceof Je):q=!!M.effects&&M.effects.some(N=>N.id===O),q){const N=o.get(M);if(N){const ee=N.getSprite();ee&&(ee.parent&&ee.parent.removeChild(ee),h.addChild(ee))}}}if(h.children.length>0){let M=g.get(O);if(!M)try{const q=Eo({name:P,renderer:e.renderer});q&&q.filter&&(M={filter:q.filter,render:q.render},g.set(O,M))}catch(q){console.warn("Failed to create effect",P,q)}if(M){const{filter:q,render:N}=M;q.resources&&q.resources.effectUniforms&&(q.resources.effectUniforms.uniforms.uTime=ne);const ee=e.renderer.width,he=e.renderer.height,ye=Ae.create({width:ee,height:he});if(h.visible=!0,e.renderer.render({container:h,target:ye,clear:!0}),h.visible=!1,N){const U=N({canvasTexture:ye,progress:ne,width:ee,height:he}),Ie=new we(U);Ie.width=ee,Ie.height=he,p.addChild(Ie)}}}}}return n&&e!=null&&e.render(),{audios:w,mainSprDone:S,hasVideo:E}},cleanup:()=>{d&&d.destroy(!0),f&&f.destroy(!0),m&&m.destroy(!0);for(const T of l.values())T.destroy();l.clear(),c.clear(),h&&h.destroy({children:!0}),u&&u.destroy({children:!0}),p&&p.destroy({children:!0}),o.forEach(T=>{T.destroy()}),o.clear()}}}function o2(s){const{canvas:e,outputAudio:t,muxer:r,hasVideoTrack:n,timeSlice:o}=s;let c=0;const l=Math.floor(3*s.fps),d=a2(1024);return(f,m,g)=>{if(t!==!1)for(const _ of d(f,m))r.encodeAudio(_);if(n&&g)try{const _=new VideoFrame(e,{duration:o,timestamp:f});r.encodeVideo(_,{keyFrame:c%l===0}),c+=1}catch(_){console.warn("Failed to create VideoFrame from canvas, skipping frame:",_)}}}function a2(s){const e=s*oe.channelCount,t=new Float32Array(e*3);let r=0,n=0;const o=s/oe.sampleRate*1e6,c=new Float32Array(e),l=d=>{let f=0;const m=Math.floor(r/e),g=[];for(let _=0;_<m;_++)g.push(new AudioData({timestamp:n,numberOfChannels:oe.channelCount,numberOfFrames:s,sampleRate:oe.sampleRate,format:"f32",data:t.subarray(f,f+e)})),f+=e,n+=o;for(t.set(t.subarray(f,r),0),r-=f;d-n>o;)g.push(new AudioData({timestamp:n,numberOfChannels:oe.channelCount,numberOfFrames:s,sampleRate:oe.sampleRate,format:"f32",data:c})),n+=o;return g};return(d,f)=>{const m=Math.max(...f.map(g=>g[0]?.length??0));for(let g=0;g<m;g++){let _=0,y=0;for(let a=0;a<f.length;a++){const h=f[a][0]?.[g]??0,u=f[a][1]?.[g]??h;_+=h,y+=u}t[r]=_,t[r+1]=y,r+=2}return l(d)}}class l2 extends Ce{constructor(){super(),this.eventMode="static",this.cursor="move"}draw(e,t=1){const n=1*t;this.clear(),this.setStrokeStyle({width:n,color:5620223}).rect(e.x,e.y,e.width,e.height).stroke(),this.hitArea=e}}class wt extends Ce{#e=!1;handle;cursor;callbacks;constructor(e,t,r){super(),this.handle=e,this.cursor=t,this.callbacks=r,this.eventMode="static",this.#o(),this.on("pointerdown",this.#t),this.on("globalpointermove",this.#r),this.on("pointerup",this.#l),this.on("pointerupoutside",this.#l)}#o(){this.clear(),this.handle==="rot"?(this.circle(0,0,10),this.fill({color:"#ffffff"}),this.stroke({width:1,color:13421772}),this.moveTo(0,-5),this.arc(0,0,5,-Math.PI/2,Math.PI,!1),this.stroke({width:1,color:0}),this.moveTo(0,-8),this.lineTo(-3,-5),this.lineTo(0,-2),this.stroke({width:1,color:0,cap:"round",join:"round"}),this.hitArea=new Yr(0,0,24)):(this.rect(-5,-5,10,10),this.fill({color:"#ffffff"}),this.stroke({width:1,color:5620223}),this.hitArea=new z(-15,-15,30,30))}#t=e=>{this.#e=!0,this.cursor="grabbing",this.callbacks.beginDrag(this.handle,e.global),e.stopPropagation()};#r=e=>{this.#e&&(this.callbacks.updateDrag(this.handle,e.global),e.stopPropagation())};#l=e=>{this.#e&&(this.#e=!1,this.cursor="pointer",this.callbacks.endDrag(),e.stopPropagation())}}const od={delta:new B};class c2 extends se{group;wireframe=new l2;isDragging=!1;lastPointer=new J;activeHandle=null;#e;#o=new Map;#t=new J;#r=0;#l=0;#a=new z;#i=new J;#c=new z;#s=1;#n=1;opts;constructor(e){super(),this.opts=e,this.group=e.group,this.eventMode="static";const t={beginDrag:(r,n)=>this.#_(r,n),updateDrag:(r,n)=>this.#y(r,n),endDrag:()=>this.#f()};this.#e={tl:new wt("tl","nwse-resize",t),tr:new wt("tr","nesw-resize",t),bl:new wt("bl","nesw-resize",t),br:new wt("br","nwse-resize",t),ml:new wt("ml","ew-resize",t),mr:new wt("mr","ew-resize",t),mt:new wt("mt","ns-resize",t),mb:new wt("mb","ns-resize",t),rot:new wt("rot","crosshair",{beginDrag:(r,n)=>this.#b(n),updateDrag:(r,n)=>this.#T(n),endDrag:()=>this.#f()})},this.addChild(this.wireframe,...Object.values(this.#e)),this.#m(),Le.shared.addOnce(()=>this.#h())}#m(){this.on("pointerdown",this.#g),this.on("pointerup",this.#d),this.on("pointerupoutside",this.#d),this.on("globalpointermove",this.#v)}#h(){if(this.group.length===1){const e=this.group[0],t=e.getBounds();this.#t.set(t.x+t.width/2,t.y+t.height/2),this.#r=e.rotation;let r,n;if(this.opts.clip)r=this.opts.clip.width,n=this.opts.clip.height;else{const o=e.getLocalBounds();r=o.width,n=o.height}this.#c.copyFrom(new z(-r/2,-n/2,r,n))}else{const e=this.#w();this.#t.set(e.x+e.width/2,e.y+e.height/2);let t=e.width,r=e.height;if(this.parent){const o=new J(e.x,e.y),c=new J(e.x+e.width,e.y+e.height),l=this.parent.toLocal(o),d=this.parent.toLocal(c);t=Math.abs(d.x-l.x),r=Math.abs(d.y-l.y)}const n=new z(-t/2,-r/2,t,r);this.#c.copyFrom(n)}this.#u()}updateBounds(){this.#h()}#g=e=>{this.#h(),this.isDragging=!0,this.lastPointer.copyFrom(e.global),this.cursor="grabbing"};#d=()=>{this.isDragging&&this.emit("transformEnd"),this.isDragging=!1,this.activeHandle=null,this.cursor="default"};#v=e=>{if(!this.isDragging||this.activeHandle||!this.parent)return;const t=this.parent.toLocal(this.lastPointer),r=this.parent.toLocal(e.global),n=r.x-t.x,o=r.y-t.y;for(const d of this.group)d.x+=n,d.y+=o;const c=e.global.x-this.lastPointer.x,l=e.global.y-this.lastPointer.y;this.#t.x+=c,this.#t.y+=l,this.lastPointer.copyFrom(e.global),this.#u()};#_(e,t){this.#h(),this.isDragging=!0,this.activeHandle=e,console.log("[Transformer] #beginHandleDrag called, activeHandle:",this.activeHandle),this.#o.clear();for(const r of this.group)this.#o.set(r,r.localTransform.clone());this.rotation=this.#r,this.#a.copyFrom(this.#c),this.#S(e)}#y(e,t){this.#x(e,t)}async#x(e,t){const r=this.#i,n=this.#C(e,this.toLocal(t),r),o=n.width/this.#a.width,c=n.height/this.#a.height,l=this.toGlobal(r);if(this.opts.clip&&this.opts.clip.constructor.name==="TextClip"){const f=n.width;console.log("[Transformer] TextClip scaling:",{handle:e,originalWidth:this.#a.width,newWidth:f,sx:o,sy:c}),this.emit("textClipResize",{handle:e,newWidth:f,newHeight:n.height,pivotWorld:l,proposed:n})}else this.#p(this.#A(l,this.#r,o,c));this.#c.copyFrom(n),this.#u()}#b(e){this.#h(),this.isDragging=!0,this.activeHandle="rot",this.#o.clear();for(const t of this.group)this.#o.set(t,t.localTransform.clone());this.#l=Math.atan2(e.y-this.#t.y,e.x-this.#t.x)}#T(e){const r=Math.atan2(e.y-this.#t.y,e.x-this.#t.x)-this.#l,n=this.#r+r;this.#p(this.#E(this.#t,r)),this.rotation=n,this.#u(n)}#f(){console.log("[Transformer] #endDrag called, activeHandle:",this.activeHandle),this.isDragging=!1,this.#r=this.rotation,this.activeHandle=null,this.#u(this.#r),this.emit("transformEnd")}#w(){let e=1/0,t=1/0,r=-1/0,n=-1/0;for(const o of this.group){const c=o.getBounds();e=Math.min(e,c.x),t=Math.min(t,c.y),r=Math.max(r,c.x+c.width),n=Math.max(n,c.y+c.height)}return new z(e,t,r-e,n-t)}#u(e=this.#r){this.parent&&this.position.copyFrom(this.parent.toLocal(this.#t)),this.rotation=e;const r=1/((this.parent?Math.abs(this.parent.worldTransform.a):1)||1),n=this.#c;this.wireframe.draw(n,r);const o=n.x+n.width/2,c=n.y+n.height/2,l=[this.#e.tl,this.#e.tr,this.#e.bl,this.#e.br,this.#e.ml,this.#e.mr,this.#e.mt,this.#e.mb,this.#e.rot];for(const d of l)d.scale.set(r);this.#e.tl.position.set(n.x,n.y),this.#e.tr.position.set(n.x+n.width,n.y),this.#e.bl.position.set(n.x,n.y+n.height),this.#e.br.position.set(n.x+n.width,n.y+n.height),this.#e.ml.position.set(n.x,c),this.#e.mr.position.set(n.x+n.width,c),this.#e.mt.position.set(o,n.y),this.#e.mb.position.set(o,n.y+n.height),this.#e.rot.position.set(o,n.y-30*r)}#S(e){const t=this.#a;if(this.opts.centeredScaling){this.#i.set(t.x+t.width/2,t.y+t.height/2);return}e==="tl"?this.#i.set(t.x+t.width,t.y+t.height):e==="tr"?this.#i.set(t.x,t.y+t.height):e==="bl"?this.#i.set(t.x+t.width,t.y):e==="br"?this.#i.set(t.x,t.y):e==="ml"?this.#i.set(t.x+t.width,t.y+t.height/2):e==="mr"?this.#i.set(t.x,t.y+t.height/2):e==="mt"?this.#i.set(t.x+t.width/2,t.y+t.height):e==="mb"&&this.#i.set(t.x+t.width/2,t.y)}#C(e,t,r){if(this.opts.centeredScaling){const o=Math.max(this.#s,Math.abs(t.x-r.x)*2),c=Math.max(this.#n,Math.abs(t.y-r.y)*2);return new z(r.x-o/2,r.y-c/2,o,c)}if(e==="tl"){const o=Math.min(t.x,r.x-this.#s),c=Math.min(t.y,r.y-this.#n);return new z(o,c,r.x-o,r.y-c)}if(e==="tr"){const o=Math.max(t.x,r.x+this.#s),c=Math.min(t.y,r.y-this.#n);return new z(r.x,c,o-r.x,r.y-c)}if(e==="bl"){const o=Math.min(t.x,r.x-this.#s),c=Math.max(t.y,r.y+this.#n);return new z(o,r.y,r.x-o,c-r.y)}if(e==="br"){const o=Math.max(t.x,r.x+this.#s),c=Math.max(t.y,r.y+this.#n);return new z(r.x,r.y,o-r.x,c-r.y)}const n=this.#a;if(e==="ml"){const o=Math.min(t.x,r.x-this.#s);return new z(o,n.y,r.x-o,n.height)}if(e==="mr"){const o=Math.max(t.x,r.x+this.#s);return new z(r.x,n.y,o-r.x,n.height)}if(e==="mt"){const o=Math.min(t.y,r.y-this.#n);return new z(n.x,o,n.width,r.y-o)}if(e==="mb"){const o=Math.max(t.y,r.y+this.#n);return new z(n.x,r.y,n.width,o-r.y)}return new z(r.x,r.y,this.#s,this.#n)}#A(e,t,r,n){return od.delta.identity().translate(-e.x,-e.y).rotate(-t).scale(r,n).rotate(t).translate(e.x,e.y)}#E(e,t){return od.delta.identity().translate(-e.x,-e.y).rotate(t).translate(e.x,e.y)}#p(e){for(const t of this.group){const r=this.#o.get(t),n=t.parent;if(!r||!n)continue;const o=n.worldTransform.clone().invert(),c=n.worldTransform.clone().append(r),l=e.clone().append(c),d=o.clone().append(l);t.setFromMatrix(d)}}}class h2 extends oa{pixiApp=null;tracks=[];clips=[];spriteRenderers=new Map;artboard=null;clipContainer=null;artboardMask=null;artboardBg=null;activeTransformer=null;selectedClips=new Set;interactiveClips=new Set;playbackElements=new Map;videoSprites=new Map;clipListeners=new Map;isPlaying=!1;currentTime=0;playStartTime=0;playStartTimestamp=0;rafId=null;maxDuration=0;opts;destroyed=!1;globalEffects=new Map;activeGlobalEffect=null;currentGlobalEffectSprite=null;effectFilters=new Map;transitionRenderers=new Map;transitionSprites=new Map;transFromTexture=null;transToTexture=null;transBgGraphics=null;clipsNormalContainer=null;clipsEffectContainer=null;videoTextureCache=new WeakMap;lastFromFrame=null;lastToFrame=null;hexToNumber(e){const t=e.startsWith("#")?e.slice(1):e;return parseInt(t,16)}ready;constructor(e){super(),this.opts={fps:30,bgColor:"#000000",interactivity:!0,...e},this.ready=this.initPixiApp()}async initPixiApp(){if(this.destroyed)return;const e=this.opts.canvas||document.createElement("canvas");e.width=this.opts.width,e.height=this.opts.height,console.log("Initializing Pixi.js Application...",{width:this.opts.width,height:this.opts.height});const t=new fn,r=e.parentElement||window;await t.init({canvas:e,resizeTo:r,backgroundColor:this.hexToNumber(this.opts.bgColor),antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),this.pixiApp=t,t.stage.eventMode="static",t.stage.hitArea=t.screen,t.stage.on("pointerdown",n=>{n.target===t.stage&&this.deselectClip()}),this.artboard=new se,this.artboard.label="ArtboardRoot",t.stage.addChild(this.artboard),this.artboardBg=new Ce,this.artboardBg.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}),this.artboard.addChild(this.artboardBg),this.clipContainer=new se,this.clipContainer.label="ClipContainer",this.artboard.addChild(this.clipContainer),this.artboardMask=new Ce,this.artboardMask.rect(0,0,this.opts.width,this.opts.height).fill({color:16777215}),this.clipContainer.addChild(this.artboardMask),this.clipContainer.mask=this.artboardMask,this.clipsEffectContainer=new se,this.clipsEffectContainer.label="ClipsEffect",this.clipsEffectContainer.visible=!1,this.clipsEffectContainer.zIndex=1,this.clipsEffectContainer.sortableChildren=!0,this.clipContainer.addChild(this.clipsEffectContainer),this.clipsNormalContainer=new se,this.clipsNormalContainer.label="ClipsNormal",this.clipsNormalContainer.zIndex=10,this.clipsNormalContainer.sortableChildren=!0,this.clipContainer.addChild(this.clipsNormalContainer),this.transFromTexture=Ae.create({width:this.opts.width,height:this.opts.height}),this.transToTexture=Ae.create({width:this.opts.width,height:this.opts.height}),this.transBgGraphics=new Ce,this.transBgGraphics.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}),this.clipContainer.sortableChildren=!0,this.updateArtboardLayout(),t.renderer.on("resize",()=>{this.handleResize()})}getOptions(){return this.opts}updateDimensions(e,t){this.opts.width=e,this.opts.height=t,this.artboardBg&&this.artboardBg.clear().rect(0,0,e,t).fill({color:3355443}),this.artboardMask&&this.artboardMask.clear().rect(0,0,e,t).fill({color:16777215}),this.transFromTexture&&this.transFromTexture.resize(e,t),this.transToTexture&&this.transToTexture.resize(e,t),this.transBgGraphics&&this.transBgGraphics.clear().rect(0,0,e,t).fill({color:3355443}),this.updateArtboardLayout(),this.updateFrame(this.currentTime)}handleResize=()=>{this.destroyed||!this.pixiApp||this.updateArtboardLayout()};updateArtboardLayout(){if(!this.pixiApp||!this.artboard)return;const e=this.pixiApp.canvas.width,t=this.pixiApp.canvas.height,r=this.opts.width,n=this.opts.height,o=this.pixiApp.canvas.parentElement?.clientWidth||e,c=this.pixiApp.canvas.parentElement?.clientHeight||t,l=o/r,d=c/n,f=Math.min(l,d);this.artboard.scale.set(f),this.artboard.x=(o-r*f)/2,this.artboard.y=(c-n*f)/2}getCanvas(){if(this.opts.canvas)return this.opts.canvas;if(this.pixiApp?.canvas)return this.pixiApp.canvas;throw new Error("Canvas not initialized yet. Wait for initPixiApp to complete.")}async addMedia(e){if(this.destroyed)return;const t=this.opts.width,r=this.opts.height;t&&r&&(typeof e.scaleToFit=="function"&&await e.scaleToFit(t,r),typeof e.centerInScene=="function"&&e.centerInScene(t,r));const n=e.duration>0?e.duration:5e6;e.duration<=0&&(e.duration=n);const o=this.tracks.filter(d=>["media","video","image","Video","Image"].includes(d.type)),c=o.find(d=>d.clipIds.length>0)||o[0];let l;if(c){l=c.id;const d=n;for(const f of c.clipIds){const m=this.getClipById(f);if(m){const g=m.display.from+d,_=m.display.to+d;await this.updateClip(f,{display:{from:g,to:_}})}}}e.display.from=0,e.display.to=n,await this.addClip(e,{trackId:l}),await this.seek(0)}async addTransition(e,t=2e6,r,n){if(this.destroyed)return;console.log("transitionKey",e);let o=null,c=null;if(r&&n&&(o=this.getClipById(r)??null,c=this.getClipById(n)??null,!o||!c)){console.warn("[Studio] Invalid fromClipId or toClipId",{fromClipId:r,toClipId:n});return}if(!c){const y=this.tracks.filter(a=>["media","video","image","Video","Image"].includes(a.type)||a.clipIds.length>1);for(const a of y){const h=a.clipIds.map(u=>this.getClipById(u)).filter(u=>!!u&&u.type!=="Transition").sort((u,p)=>u.display.from-p.display.from);for(let u=0;u<h.length-1;u++){const p=h[u],v=h[u+1];if(Math.abs(v.display.from-p.display.to)<1e5){o=p,c=v;break}}if(o&&c)break}}if(c&&!o){const y=this.findTrackIdByClipId(c.id);if(y){const a=this.tracks.find(h=>h.id===y);if(a){const h=a.clipIds.map(p=>this.getClipById(p)).filter(p=>!!p&&p.type!=="Transition").sort((p,v)=>p.display.from-v.display.from),u=h.findIndex(p=>p.id===c.id);u>0&&(o=h[u-1])}}}if(!o||!c){console.warn("[Studio] Unable to resolve Clip A and Clip B for transition");return}const l=t,d=c.display.from-l/2,f=d+l,m={key:e,name:e,duration:l,fromClipId:o.id,toClipId:c.id,start:Math.max(0,d),end:f},g=this.findTrackIdByClipId(c.id);if(g){const y=this.tracks.find(a=>a.id===g);if(y){const a=y.clipIds.map(h=>this.getClipById(h)).filter(h=>{if(!h||h.type!=="Transition")return!1;const u=h;return u.fromClipId===o.id&&u.toClipId===c.id});for(const h of a)await this.removeClip(h)}}this.transitionRenderers.has(o.id)&&(this.transitionRenderers.get(o.id)?.destroy(),this.transitionRenderers.delete(o.id)),this.transitionRenderers.has(c.id)&&(this.transitionRenderers.get(c.id)?.destroy(),this.transitionRenderers.delete(c.id)),"transition"in o&&(o.transition={...m}),"transition"in c&&(c.transition={...m});const _=new pi(e);_.duration=l,_.fromClipId=Math.max(0,d)===0?null:o.id,_.toClipId=c.id,_.fromClipId===null&&o&&(_.fromClipId=o.id),_.display.from=Math.max(0,d),_.display.to=f,await this.addClip(_,{trackId:g}),this.seek(this.currentTime)}findTrackIdByClipId(e){for(const t of this.tracks)if(t.clipIds.includes(e))return t.id}async addClip(e,t){let r,n;if(t&&(typeof t=="string"||t instanceof File||t instanceof Blob))r=t;else if(typeof t=="object"&&t!==null&&!("size"in t)){const d=t;r=d.audioSource,n=d.trackId}if(this.destroyed)return;if(this.pixiApp==null)throw new Error("Failed to initialize Pixi.js Application");const o=async()=>{await this.updateFrame(this.currentTime),this.activeTransformer!=null&&this.selectedClips.has(e)&&typeof this.activeTransformer.updateBounds=="function"&&this.activeTransformer.updateBounds()};e.on("propsChange",o),this.clipListeners.set(e,o),this.pixiApp!=null&&typeof e.setRenderer=="function"&&e.setRenderer(this.pixiApp.renderer);const c=await e.ready;if(e.id||(e.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),this.clips.includes(e)||this.clips.push(e),n){const d=this.tracks.find(f=>f.id===n);d?d.clipIds.includes(e.id)||d.clipIds.push(e.id):this.tracks.unshift({id:n,name:`Track ${this.tracks.length+1}`,type:e.type,clipIds:[e.id]})}else{const d=`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;this.tracks.unshift({id:d,name:`Track ${this.tracks.length+1}`,type:e.type,clipIds:[e.id]})}const l=e.duration>0?e.duration:c.duration;if(l===1/0||isNaN(l))await this.recalculateMaxDuration();else{const d=e.display.from+l;d>0&&(this.maxDuration=Math.max(this.maxDuration,d))}if(await this.setupPlaybackForClip(e,r),c.width>0&&c.height>0)if(e instanceof fe){if(e.tickInterceptor!=null){const d=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,d)}}else{const d=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,d)}await this.updateFrame(this.currentTime),this.opts.interactivity&&this.setupSpriteInteractivity(e),this.emit("clip:added",{clip:e,trackId:n||this.tracks.find(d=>d.clipIds.includes(e.id))?.id||""})}addTrack(e){const t={id:e.id||`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:e.name,type:e.type,clipIds:[]};return this.tracks.push(t),this.emit("track:added",{track:t}),t}async setTracks(e){this.tracks=e,await this.recalculateMaxDuration(),await this.updateFrame(this.currentTime)}async removeTrack(e){const t=this.tracks.findIndex(o=>o.id===e);if(t===-1)return;const n=[...this.tracks[t].clipIds];for(const o of n){const c=this.clips.find(l=>l.id===o);c&&await this.removeClip(c)}this.tracks.splice(t,1),this.emit("track:removed",{trackId:e}),await this.recalculateMaxDuration()}getClipById(e){return this.clips.find(t=>t.id===e)}async updateClip(e,t){const r=this.clips.find(n=>n.id===e);if(!r){console.warn(`[Studio] updateClip: Clip not found with id ${e}`);return}if(r instanceof Ze&&(await r.updateStyle(t),"style"in t&&delete t.style),Object.assign(r,t),t.display&&!t.duration?r.duration=t.display.to-t.display.from:t.duration&&(!t.display||!t.display.to)&&(r.display||(r.display={from:0,to:t.duration}),r.display.to=r.display.from+t.duration),t.display&&t.duration){const n=t.display.to-t.display.from;n!==t.duration&&(r.duration=n)}else r.display&&(r.display.to=r.display.from+r.duration);await this.recalculateMaxDuration(),this.emit("clip:updated",{clip:r}),await this.updateFrame(this.currentTime)}getTracks(){return this.tracks}getClip(e){return this.clips.find(t=>t.id===e)}setupSpriteInteractivity(e){if(this.interactiveClips.has(e))return;const t=this.spriteRenderers.get(e);if(t==null)return;const r=t.getSprite();r!=null&&(r.eventMode="static",r.cursor="pointer",r.on("pointerdown",n=>{n.stopPropagation(),this.selectClip(e,n.shiftKey)}),this.interactiveClips.add(e))}async setupPlaybackForClip(e,t){if(this.pixiApp!=null){if(!this.isPlaybackCapable(e)){if(this.pixiApp!=null&&(await e.ready).width>0&&(await e.ready).height>0){const r=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,r)}return}try{const r=e;if(e instanceof Me&&t&&typeof t!="string"){const c=URL.createObjectURL(t);e.src=c}const{element:n,objectUrl:o}=await r.createPlaybackElement();if(e instanceof fe){const c=F.from(n),l=new we(c);l.visible=!1,this.clipsNormalContainer&&this.clipsNormalContainer.addChild(l),this.videoSprites.set(e,l)}this.playbackElements.set(e,{element:n,objectUrl:o})}catch(r){if(console.warn(`Failed to setup playback for ${e.constructor.name}, falling back to PixiSpriteRenderer:`,r),this.pixiApp!=null){const n=await e.ready;if(n.width>0&&n.height>0){const o=new or(this.pixiApp,e,this.artboard);this.spriteRenderers.set(e,o)}}}}}isPlaybackCapable(e){return"createPlaybackElement"in e&&"play"in e&&"pause"in e&&"seek"in e&&"syncPlayback"in e&&"cleanupPlayback"in e}async removeClip(e){const t=this.clips.findIndex(l=>l===e);if(t===-1)return;this.selectedClips.has(e)&&this.deselectClip(),this.clips.splice(t,1);for(const l of this.tracks){const d=l.clipIds.indexOf(e.id);d!==-1&&l.clipIds.splice(d,1)}this.interactiveClips.delete(e);const r=this.clipListeners.get(e);r&&(e.off("propsChange",r),this.clipListeners.delete(e));const n=this.spriteRenderers.get(e);n!=null&&(n.destroy(),this.spriteRenderers.delete(e));const o=this.playbackElements.get(e);o!=null&&(this.isPlaybackCapable(e)&&e.cleanupPlayback(o.element,o.objectUrl),this.playbackElements.delete(e));const c=this.videoSprites.get(e);c!=null&&this.pixiApp!=null&&(this.artboard?.removeChild(c),c.destroy(),this.videoSprites.delete(e)),await this.recalculateMaxDuration(),this.emit("clip:removed",{clipId:e.id})}async removeClipById(e){const t=this.clips.find(r=>r.id===e);t&&await this.removeClip(t)}async deleteSelected(){const e=Array.from(this.selectedClips);if(e.length!==0)for(const t of e)await this.removeClip(t)}async duplicateSelected(){const e=Array.from(this.selectedClips);if(e.length===0)return;const t=[];for(const r of e){const n=this.findTrackIdByClipId(r.id);if(!n)continue;const o=this.tracks.find(m=>m.id===n);if(!o)continue;const c=ar(r,!1),l=await lr(c);l.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const d=`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=`${o.name} (Copy)`;this.addTrack({id:d,name:f,type:o.type}),await this.addClip(l,{trackId:d}),t.push(l.id)}t.length>0&&this.selectClipsByIds(t)}async splitSelected(e){const t=Array.from(this.selectedClips);if(t.length!==1){console.warn("[Studio] Split requires exactly one selected clip");return}const r=t[0],n=e??this.currentTime;if(n<=r.display.from||r.display.to>0&&n>=r.display.to){console.warn("[Studio] Split time is outside clip bounds");return}const o=ar(r,!1),c=n-r.display.from,l=r.playbackRate||1,d=c*l,f={duration:c,display:{from:r.display.from,to:n}};r.trim&&(f.trim={from:r.trim.from,to:r.trim.from+d}),await this.updateClip(r.id,f);const m={...o};m.display={from:n,to:o.display.to},m.duration=o.duration-c,m.trim&&(m.trim={from:m.trim.from+d,to:m.trim.to});const g=await lr(m);g.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const _=this.findTrackIdByClipId(r.id);_&&(await this.addClip(g,{trackId:_}),this.selectClipsByIds([g.id]))}async trimSelected(e){const t=Array.from(this.selectedClips);if(t.length!==1){console.warn("[Studio] Trim requires exactly one selected clip");return}const r=t[0];console.log("[Studio] Trimming clip:",{clipId:r.id,currentDisplay:r.display,currentDuration:r.duration,currentTrim:r.trim,trimFromSeconds:e});const n=e*1e6,o=r.playbackRate||1,c=n*o;if(n>=r.duration){console.warn("[Studio] Trim amount exceeds clip duration");return}const l=r.duration-n,d=r.display.from+n,f=r.display.to,m={duration:l,display:{from:d,to:f}};if(r.trim)m.trim={from:r.trim.from+c,to:r.trim.to};else{const g=r.sourceDuration||r.duration;m.trim={from:c,to:g}}console.log("[Studio] Trim updates:",m),await this.updateClip(r.id,m),console.log("[Studio] Clip after trim:",{display:r.display,duration:r.duration,trim:r.trim})}async updateSelected(e){const t=Array.from(this.selectedClips);if(t.length!==0)for(const r of t)await this.updateClip(r.id,e)}clear(){this.deselectClip(),this.interactiveClips.clear(),this.effectFilters.clear(),this.globalEffects.clear(),this.spriteRenderers.forEach(e=>{e.destroy()}),this.spriteRenderers.clear();for(const[e,t]of this.playbackElements.entries())this.isPlaybackCapable(e)&&e.cleanupPlayback(t.element,t.objectUrl);this.playbackElements.clear();for(const e of this.videoSprites.values())e.destroy();this.videoSprites.clear(),this.transitionRenderers.clear(),this.transFromTexture&&(this.transFromTexture.destroy(!0),this.transFromTexture=null),this.transToTexture&&(this.transToTexture.destroy(!0),this.transToTexture=null),this.transBgGraphics&&(this.transBgGraphics.destroy(!0),this.transBgGraphics=null);for(const e of this.transitionSprites.values())e.parent&&e.parent.removeChild(e),e.destroy();this.transitionSprites.clear(),this.tracks=[],this.clips=[],this.maxDuration=0,this.currentTime=0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null),this.emit("reset")}async play(){if(!(this.isPlaying||this.destroyed)){if(this.maxDuration<=0||this.maxDuration===1/0||isNaN(this.maxDuration)){console.warn("Cannot play: invalid duration",this.maxDuration);return}this.isPlaying||(this.isPlaying=!0),this.playStartTime=this.currentTime,this.playStartTimestamp=performance.now();for(const[e,{element:t}]of this.playbackElements.entries()){if(!(this.currentTime>=e.display.from&&(e.display.to===0||this.currentTime<=e.display.to))){this.isPlaybackCapable(e)&&e.pause(t);continue}const n=(this.currentTime-e.display.from)/1e6;this.isPlaybackCapable(e)&&await e.play(t,n)}this.renderLoop(),this.emit("play",{isPlaying:!0})}}pause(){this.isPlaying=!1,this.rafId!=null&&(cancelAnimationFrame(this.rafId),this.rafId=null);for(const[e,{element:t}]of this.playbackElements.entries())this.isPlaybackCapable(e)&&e.pause(t);this.emit("pause",{isPlaying:!1})}async stop(){this.pause(),await this.seek(0)}async seek(e){if(this.destroyed)return;const t=this.isPlaying;this.playStartTime=Math.max(0,Math.min(e,this.maxDuration)),this.playStartTimestamp=performance.now(),this.currentTime=this.playStartTime;for(const[r,{element:n}]of this.playbackElements.entries()){if(!(this.currentTime>=r.display.from&&(r.display.to===0||this.currentTime<=r.display.to))){this.isPlaybackCapable(r)&&r.pause(n);continue}const c=(this.currentTime-r.display.from)/1e6;this.isPlaybackCapable(r)&&await r.seek(n,c)}if(await this.updateFrame(this.currentTime),t){this.isPlaying=!0;for(const[r,{element:n}]of this.playbackElements.entries()){if(!(this.currentTime>=r.display.from&&(r.display.to===0||this.currentTime<=r.display.to)))continue;const c=(this.currentTime-r.display.from)/1e6;this.isPlaybackCapable(r)&&await r.play(n,c)}}}getCurrentTime(){return this.currentTime}getMaxDuration(){return this.maxDuration===1/0||isNaN(this.maxDuration)||this.maxDuration<=0?0:this.maxDuration}getIsPlaying(){return this.isPlaying}getSelectedClips(){return Array.from(this.selectedClips)}async renderLoop(){if(!this.isPlaying||this.destroyed||this.pixiApp==null)return;if(this.maxDuration<=0||this.maxDuration===1/0||isNaN(this.maxDuration)){this.pause();return}const e=async()=>{if(!this.isPlaying||this.destroyed||this.pixiApp==null)return;if(this.currentTime>=this.maxDuration){this.currentTime=this.maxDuration,this.pause();return}const r=(performance.now()-this.playStartTimestamp)*1e3;this.currentTime=Math.min(this.playStartTime+r,this.maxDuration),this.emit("currentTime",{currentTime:this.currentTime});try{await this.updateFrame(this.currentTime)}catch(n){console.warn("Error updating frame:",n)}this.isPlaying&&(this.rafId=requestAnimationFrame(e))};e()}getVideoTexture(e){let t=this.videoTextureCache.get(e);return t||(t=F.from(e),this.videoTextureCache.set(e,t)),t}async updateFrame(e){if(this.destroyed||this.pixiApp==null)return;this.updateActiveGlobalEffect(e);const t=new Set,r=this.tracks.length;for(const o of this.clips){const c=this.getTrackIndex(o.id);if(c!==-1){const l=(r-c)*10;o.zIndex=l;const d=this.spriteRenderers.get(o);if(d){const f=d.getSprite();f&&(f.zIndex=l)}}}const n=[...this.clips].sort((o,c)=>o.zIndex-c.zIndex);for(const o of n){if(e<o.display.from){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}if(o.display.to>0&&e>o.display.to){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}const c=e-o.display.from,l=c*o.playbackRate;o.animate(l);const d=await o.ready,f=o.duration||d.duration;if(f>0&&c>f){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}const m=this.playbackElements.get(o),g=o instanceof fe||o instanceof ve,_=o.transition?o.transition.start:0,y=o.transition?o.transition.end:0;if(g&&o.transition&&e>=_&&e<=y){this.transFromTexture||(this.transFromTexture=Ae.create({width:this.opts.width,height:this.opts.height})),this.transToTexture||(this.transToTexture=Ae.create({width:this.opts.width,height:this.opts.height})),this.transBgGraphics||(this.transBgGraphics=new Ce,this.transBgGraphics.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}));const h=this.getClipById(o.transition.fromClipId),u=this.getClipById(o.transition.toClipId);let p=null,v=null;if(h){const x=Math.max(0,e-h.display.from),{video:b}=await h.getFrame(x);b instanceof HTMLVideoElement?p=this.getVideoTexture(b):p=b,p&&(this.lastFromFrame=p)}if(u){const x=Math.max(0,e-u.display.from),{video:b}=await u.getFrame(x);b instanceof HTMLVideoElement?v=this.getVideoTexture(b):v=b,v&&(this.lastToFrame=v)}if(p||(p=this.lastFromFrame),v||(v=this.lastToFrame),!p||!v)continue;if(p&&v&&this.pixiApp&&this.transFromTexture&&this.transToTexture){const x=(e-_)/o.transition.duration;h&&p&&this.renderClipToTransitionTexture(h,p,this.transFromTexture),u&&v&&this.renderClipToTransitionTexture(u,v,this.transToTexture);let b=this.transitionRenderers.get(o.id);if(!b)try{b=Po({name:o.transition.name,renderer:this.pixiApp.renderer}),this.transitionRenderers.set(o.id,b)}catch(T){console.error("[Studio] Failed to create transition renderer:",T)}if(b){const T=b.render({width:this.opts.width,height:this.opts.height,from:this.transFromTexture,to:this.transToTexture,progress:x});let w=this.transitionSprites.get(o.id);w||(w=new we,w.label=`TransitionSprite_${o.id}`,this.transitionSprites.set(o.id,w),this.clipsNormalContainer&&this.clipsNormalContainer.addChild(w)),w.texture=T,w.visible=!0,w.x=0,w.y=0,w.width=this.opts.width,w.height=this.opts.height,w.anchor.set(0,0),w.zIndex=o.zIndex,t.add(o.id);const S=this.spriteRenderers.get(o);if(S?.getSprite()&&(S.getSprite().visible=!1),h){const E=this.spriteRenderers.get(h);E?.getSprite()&&(E.getSprite().visible=!1)}continue}}}if(m!=null&&this.isPlaybackCapable(o)){const h=c/1e6;if(o.syncPlayback(m.element,this.isPlaying,h),o instanceof fe){const u=this.videoSprites.get(o);if(u!=null){const p=o.meta.duration/1e6;if(this.spriteRenderers.has(o))u.visible=!1;else{u.visible=h>=0&&h<p,u.visible&&tb(o,u);continue}}}else continue}const a=this.spriteRenderers.get(o);if(a!=null){const h=this.selectedClips.has(o);if(o instanceof ve){const p=o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms();continue}}if(o instanceof Ze){const p=await o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms();continue}}if(o instanceof Ft){o.updateState(c);const p=await o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms(),this.opts.interactivity&&this.setupSpriteInteractivity(o);continue}else console.log("[Studio] CaptionClip texture is null, falling back to traditional path")}const{video:u}=await o.getFrame(c);await a.updateFrame(u),h||a.updateTransforms(),this.opts.interactivity&&this.setupSpriteInteractivity(o)}}if(this.activeGlobalEffect&&this.clipsNormalContainer&&this.clipsEffectContainer){const{startTime:o,duration:c}=this.activeGlobalEffect,l=e-o,d=Math.min(Math.max(l/c,0),1);if(d>0&&d<1){try{for(const m of this.clips)this.moveClipToEffectContainer(m,!1);const f=this.clips.some(m=>m.id===this.activeGlobalEffect.id&&m instanceof Je);for(const m of this.clips){let g=!1;if(f){const _=this.activeGlobalEffect.trackIndex??-1,y=this.getTrackIndex(m.id);g=m.id!==this.activeGlobalEffect.id&&!(m instanceof Je)&&y>_}else{const _=m.effects;g=Array.isArray(_)&&_.some(y=>y&&y.id===this.activeGlobalEffect.id)}g&&this.moveClipToEffectContainer(m,!0)}}catch(f){console.warn("Failed to reparent clips for effect; falling back to full-scene render",f)}this.clipsNormalContainer.visible=!0,await this.applyGlobalEffectIfNeeded(e)}else{for(const f of this.clips)try{this.moveClipToEffectContainer(f,!1)}catch{}this.clipsNormalContainer.visible=!0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null)}}else if(this.clipsNormalContainer){for(const o of this.clips)try{this.moveClipToEffectContainer(o,!1)}catch{}this.clipsNormalContainer.visible=!0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null)}for(const[o,c]of this.transitionSprites.entries())t.has(o)||(c.visible=!1);this.pixiApp!=null&&this.pixiApp.render()}async recalculateMaxDuration(){this.maxDuration=0;for(const e of this.clips){const t=await e.ready,r=e.duration>0?e.duration:t.duration,n=e.display.from+r;n!==1/0&&!isNaN(n)&&n>0&&(this.maxDuration=Math.max(this.maxDuration,n))}}moveClipToEffectContainer(e,t=!0){if(!this.clipsNormalContainer||!this.clipsEffectContainer)return;const r=t?this.clipsEffectContainer:this.clipsNormalContainer,n=this.spriteRenderers.get(e);if(n){const c=n.getSprite();if(c&&c.parent!==r){try{c.parent&&c.parent.removeChild&&c.parent.removeChild(c)}catch(l){console.warn("moveClipToEffectContainer: could not remove sprite from parent",l)}r.addChild(c)}}const o=this.transitionSprites.get(e.id);if(o&&o.parent!==r){try{o.parent&&o.parent.removeChild&&o.parent.removeChild(o)}catch(c){console.warn("moveClipToEffectContainer: could not remove transSprite from parent",c)}r.addChild(o)}}applyGlobalEffect(e,t,r){const n=t.id||`${e}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o={id:n,key:e,startTime:t.startTime,duration:t.duration??1e6};for(const c of r)c instanceof ve&&c.addEffect(o),c instanceof fe&&c.addEffect(o),c instanceof Ze&&c.addEffect(o),c instanceof Ft&&c.addEffect(o);return this.globalEffects.set(n,o),n}getTrackIndex(e){return this.tracks.findIndex(t=>t.clipIds.includes(e))}async getTransitionFromFrame(e,t){let r=null;if(e.transition?.prevClipId&&(r=this.clips.find(l=>l.id===e.transition.prevClipId)||null),r||(r=this.getPreviousClipOnTrack(e)),!r)return null;const n=r.duration>0?r.duration:0,o=Math.max(0,Math.min(t-r.display.from,n)),{video:c}=await r.getFrame(o);return c}getPreviousClipOnTrack(e){const t=this.getTrackIndex(e.id);return t===-1?null:this.clips.filter(r=>r.id!==e.id&&this.getTrackIndex(r.id)===t&&r.display.from<e.display.from&&(r instanceof fe||r instanceof ve)).sort((r,n)=>n.display.to-r.display.to)[0]||null}renderClipToTransitionTexture(e,t,r){if(!this.pixiApp||!this.transBgGraphics)return;this.pixiApp.renderer.render({container:this.transBgGraphics,target:r,clear:!0});const n=new we(t instanceof F?t:F.from(t));n.x=e.center.x,n.y=e.center.y,n.anchor.set(.5,.5);const o=n.texture.width||1,c=n.texture.height||1,l=e.width&&e.width!==0?Math.abs(e.width)/o:1,d=e.height&&e.height!==0?Math.abs(e.height)/c:1;e.flip==="horizontal"?(n.scale.x=-l,n.scale.y=d):e.flip==="vertical"?(n.scale.x=l,n.scale.y=-d):(n.scale.x=l,n.scale.y=d),n.rotation=(e.flip==null?1:-1)*e.angle,n.alpha=e.opacity,this.pixiApp.renderer.render({container:n,target:r,clear:!1}),t instanceof F||n.texture.destroy(!0),n.destroy()}removeGlobalEffect(e){this.globalEffects.delete(e)}clearGlobalEffects(){this.globalEffects.clear()}updateActiveGlobalEffect(e){let t=null;for(const r of this.clips)if(r instanceof Je&&e>=r.display.from&&(r.display.to===0||e<=r.display.to)){t={id:r.id,key:r.effect.key,startTime:r.display.from,duration:r.duration>0?r.duration:r.display.to-r.display.from,trackIndex:this.getTrackIndex(r.id)};break}if(!t)for(const r of this.globalEffects.values()){const n=r.startTime+r.duration;if(e>=r.startTime&&e<n){t={id:r.id,key:r.key,startTime:r.startTime,duration:r.duration,trackIndex:-1};break}}this.activeGlobalEffect=t}async applyGlobalEffectIfNeeded(e){if(this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null),!this.activeGlobalEffect||!this.pixiApp||!this.clipContainer||!this.artboard||!this.clipsNormalContainer||!this.clipsEffectContainer)return;const{key:t,startTime:r,duration:n}=this.activeGlobalEffect,o=e-r,c=Math.min(Math.max(o/n,0),1);if(c<=0||c>=1)return;this.clipsEffectContainer.visible=!0;let l=this.effectFilters.get(t);if(!l)try{if(l=Eo({name:t.toLowerCase(),renderer:this.pixiApp.renderer}),l)this.effectFilters.set(t,l);else return}catch(y){console.error(y);return}const d=this.opts.width,f=this.opts.height,m=Ae.create({width:d,height:f});this.pixiApp.renderer.render({container:this.clipsEffectContainer,target:m,clear:!0}),this.clipsEffectContainer.visible=!1;const g=l.render({canvasTexture:m,progress:c,width:d,height:f}),_=new we(g);_.x=0,_.y=0,_.width=d,_.height=f,_.scale.set(1),_.zIndex=5,this.clipContainer.addChild(_),this.currentGlobalEffectSprite=_,m.destroy(!0)}destroy(){if(!this.destroyed){window.removeEventListener("resize",this.handleResize),this.destroyed=!0,this.stop(),this.clear(),this.transitionRenderers.clear(),this.transFromTexture&&(this.transFromTexture.destroy(!0),this.transFromTexture=null),this.transToTexture&&(this.transToTexture.destroy(!0),this.transToTexture=null),this.transBgGraphics&&(this.transBgGraphics.destroy(!0),this.transBgGraphics=null);for(const e of this.transitionSprites.values())e.destroy();this.transitionSprites.clear(),this.pixiApp&&(this.pixiApp.destroy(!0,{children:!0,texture:!0}),this.pixiApp=null)}}selectClip(e,t=!1){if(!(this.destroyed||this.pixiApp==null)){if(t||this.deselectClip(),t&&this.selectedClips.has(e)){this.selectedClips.delete(e),this.activeTransformer!=null&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.selectedClips.size>0&&this.createTransformer(),this.emit("selection:updated",{selected:Array.from(this.selectedClips)});return}this.selectedClips.add(e),this.activeTransformer!=null&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.createTransformer(),t?this.emit("selection:updated",{selected:Array.from(this.selectedClips)}):this.emit("selection:created",{selected:Array.from(this.selectedClips)})}}createTransformer(){if(this.destroyed||this.artboard==null||this.selectedClips.size===0)return;const e=[];let t=null;for(const n of this.selectedClips){const o=this.spriteRenderers.get(n);if(o==null)continue;const c=o.getSprite();c!=null&&(e.push(c),this.selectedClips.size===1&&(t=n))}if(e.length===0){console.warn("Cannot create transformer: no sprites found");return}this.activeTransformer=new c2({group:e,clip:t});let r=null;this.activeTransformer.on("transforming",()=>{r===null&&(r=requestAnimationFrame(()=>{r=null,this.syncSelectedClipsTransformsRealtime()}))}),this.activeTransformer.on("textClipResize",n=>{this.textClipResizedWidth=n.newWidth}),this.activeTransformer.on("transformEnd",()=>{r!==null&&(cancelAnimationFrame(r),r=null),this.syncSelectedClipsTransforms()}),this.artboard.addChild(this.activeTransformer)}isUpdatingTextClipRealtime=!1;textClipResizedWidth=null;async syncSelectedClipsTransformsRealtime(){if(!(this.selectedClips.size===0||this.activeTransformer==null)&&!this.isUpdatingTextClipRealtime){this.isUpdatingTextClipRealtime=!0;try{if(this.activeTransformer.activeHandle!=="mr")return;for(const t of this.selectedClips){if(!(t instanceof Ze))continue;const r=this.spriteRenderers.get(t);if(r==null)continue;const n=r.getSprite();if(n==null||n.texture==null)continue;const o=Math.abs(n.scale.x);if(o===1)continue;const c=t.left,l=t.top,d=n.texture.width,f=o*d;await t.updateStyle({wordWrap:!0,wordWrapWidth:f});const m=await t.getTexture();m&&(await r.updateFrame(m),n.scale.set(1,1),t.left=c,t.top=l,n.x=t.left+t.width/2,n.y=t.top+t.height/2)}}finally{this.isUpdatingTextClipRealtime=!1}}}async syncSelectedClipsTransforms(){if(!(this.selectedClips.size===0||this.activeTransformer==null)){for(const e of this.selectedClips){const t=this.spriteRenderers.get(e);if(t==null)continue;const r=t.getSprite();if(r==null||r.texture==null)continue;const n=r.texture.width,o=r.texture.height,c=Math.abs(r.scale.x)*n,l=Math.abs(r.scale.y)*o,d=e instanceof Ze&&this.textClipResizedWidth!==null?this.textClipResizedWidth:c,f=r.x-d/2,m=r.y-l/2;if(e instanceof Ze&&this.textClipResizedWidth!==null){await e.updateStyle({wordWrap:!0,wordWrapWidth:d});const g=await e.getTexture();g&&(await t.updateFrame(g),e.width=d,e.height=g.height,this.textClipResizedWidth=null,e.left=r.x-e.width/2,e.top=r.y-e.height/2,r.scale.set(1,1))}else e.left=f,e.top=m,e.width=c,e.height=l,e.angle=r.angle}this.activeTransformer!=null&&this.activeTransformer.updateBounds();for(const e of this.selectedClips){const t=this.spriteRenderers.get(e);t?.updateTransforms()}}}syncSpriteToClipProperties(e){const t=this.spriteRenderers.get(e);if(t!=null){const r=t.getSprite();if(r!=null&&r.texture!=null){const n=r.texture.width,o=r.texture.height,c=Math.abs(r.scale.x)*n,l=Math.abs(r.scale.y)*o,d=r.x-c/2,f=r.y-l/2;e.left=d,e.top=f,e.width=c,e.height=l,e.angle=r.angle,t.updateTransforms()}}}setSelection(e){if(!(this.destroyed||this.pixiApp==null)&&!(this.selectedClips.size===e.length&&e.every(t=>this.selectedClips.has(t)))){for(const t of this.selectedClips)this.syncSpriteToClipProperties(t);this.activeTransformer&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.selectedClips.clear();for(const t of e)this.selectedClips.add(t);this.selectedClips.size>0?(this.createTransformer(),this.emit("selection:updated",{selected:Array.from(this.selectedClips)})):this.emit("selection:cleared",{deselected:[]})}}selectClipsByIds(e){const t=this.clips.filter(r=>e.includes(r.id));this.setSelection(t)}deselectClip(){if(this.selectedClips.size>0)for(const t of this.selectedClips)this.syncSpriteToClipProperties(t);this.activeTransformer!=null&&(this.activeTransformer.parent!=null&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null);const e=Array.from(this.selectedClips);this.selectedClips.clear(),e.length>0&&this.emit("selection:cleared",{deselected:e})}exportToJSON(){const e=this.clips.map(n=>ar(n,!1)),t=this.tracks.map(n=>({id:n.id,name:n.name,type:n.type,clipIds:n.clipIds})),r=[];return this.clips.forEach(n=>{if(n.transition){const o=this.tracks.find(c=>c.clipIds.includes(n.id));if(o){const c=o.clipIds.indexOf(n.id);if(c>0){const l=o.clipIds[c-1];r.push({key:n.transition.name,duration:n.transition.duration,clips:[l,n.id]})}}}}),{tracks:t,clips:e,transition:r.length>0?r:void 0,settings:{width:this.opts.width,height:this.opts.height,fps:this.opts.fps,bgColor:this.opts.bgColor}}}async loadFromJSON(e){if(this.clear(),e.settings){const r=e.settings.width&&e.settings.width!==this.opts.width||e.settings.height&&e.settings.height!==this.opts.height;if(e.settings.width&&(this.opts.width=e.settings.width),e.settings.height&&(this.opts.height=e.settings.height),e.settings.fps&&(this.opts.fps=e.settings.fps),e.settings.bgColor&&(this.opts.bgColor=e.settings.bgColor),r&&this.pixiApp!=null){const n=this.opts.width,o=this.opts.height;this.pixiApp.renderer.resize(n,o),this.opts.canvas&&(this.opts.canvas.width=n,this.opts.canvas.height=o)}}if(e.clips){const r=new Map;if(e.tracks){for(const n of e.tracks)if(n.clipIds)for(const o of n.clipIds)r.set(o,n.id)}if(e.tracks)for(const n of e.tracks)this.tracks.push({id:n.id,name:n.name,type:n.type,clipIds:[]});for(const n of e.clips){let o=n.id?r.get(n.id):void 0;if(!o&&n.type==="Transition"){const c=n,l=c.toClipId||c.fromClipId;l&&(o=r.get(l))}await this.loadClipIntoTrack(n,o)}}for(const r of this.clips){const n=r.effects;if(Array.isArray(n))for(const o of n)this.globalEffects.has(o.id)||this.globalEffects.set(o.id,{id:o.id,key:o.key,startTime:o.startTime,duration:o.duration})}const t=e.transition||e.transitions;if(t)for(const r of t){const n=r.clips[0],o=r.clips[1],c=this.getClipById(n),l=this.getClipById(o);if(c&&l){const d=this.clips.find(y=>y.type==="Transition"&&y.fromClipId===n&&y.toClipId===o),f=r.duration;let m,g;if(d)m=d.display.from,g=d.display.to;else{const y=l.display.from;m=Math.max(0,y-f/2),g=m+f}const _={key:r.key,name:r.key,duration:f,fromClipId:n,toClipId:o,start:m,end:g};"transition"in c&&(c.transition=_),"transition"in l&&(l.transition=_)}else console.warn(`[Studio] Could not find clips for transition ${r.key}: from=${n}, to=${o}`)}else console.log("[Studio] No transition data found in JSON");try{await this.updateFrame(this.currentTime)}catch(r){console.error("[Studio] Failed to update initial frame:",r)}}async loadClipIntoTrack(e,t){if(e.type!=="Text"&&e.type!=="Caption"&&e.type!=="Effect"&&e.type!=="Transition"&&(!e.src||e.src.trim()==="")){console.warn(`Skipping clip ${e.type} with empty source`);return}try{const r=await lr(e),n=r instanceof Me?e.src:void 0;await this.addClip(r,{trackId:t,audioSource:n}),(r instanceof fe||r instanceof ve)&&(!e.width||!e.height)&&(await r.scaleToFit(this.opts.width,this.opts.height),r.centerInScene(this.opts.width,this.opts.height))}catch(r){console.warn(`Failed to load clip of type ${e.type}:`,r)}}}class vi{static instance;fonts=new Map;constructor(){}static getInstance(){return vi.instance||(vi.instance=new vi),vi.instance}async addFont(e){if(!this.fonts.has(e.name))try{const r=await new FontFace(e.name,`url(${e.url})`).load();document.fonts.add(r),this.fonts.set(e.name,r)}catch(t){console.error(`Failed to load font ${e.name}:`,t)}}async loadFonts(e){await Promise.all(e.map(t=>this.addFont(t)))}removeFont(e){const t=this.fonts.get(e);t&&(document.fonts.delete(t),this.fonts.delete(e))}clear(){this.fonts.forEach(e=>{document.fonts.delete(e)}),this.fonts.clear()}getLoadedFonts(){return Array.from(this.fonts.keys())}}const u2=vi.getInstance();L.add(Qp),L.mixin(se,em),L.add(Bl),L.add(Dl),L.add(Wc),L.mixin(se,Ev),L.add(Hc),L.add(Eu),L.add(Fn),L.add(Ru),L.add(Bu),L.add(Du),L.add($u),L.add(Xu),L.add(Nu),L.add(Vu),L.add(Hu),L.add(Lu),L.add(Gu),L.add($c),L.add(Yc);const d2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),f2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));te.AudioClip=Me,te.CaptionClip=Ft,te.Compositor=s2,te.EffectClip=Je,te.GL_EFFECT_OPTIONS=eb,te.GL_TRANSITION_OPTIONS=i2,te.ImageClip=ve,te.Log=W,te.MP4Clip=fe,te.Studio=h2,te.TextClip=Ze,te.TransitionClip=pi,te.VideoClip=fe,te.clipToJSON=ar,te.createChromakey=Df,te.fastConcatMP4=ed,te.fixFMP4Duration=kx,te.fontManager=u2,te.jsonToClip=lr,te.makeEffect=Eo,te.makeTransition=Po,te.mixinMP4AndAudio=Gx,te.renderTxt2ImgBitmap=Nf,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|
|
7670
|
+
`,t2={radialSwipe:{label:"Radial Swipe",fragment:ab}},gi={...mi.reduce((s,e)=>(s[e.name]={label:e.name,fragment:e.glsl,uniforms:e.defaultParams,previewDynamic:`transition: ${e.name}`},s),{}),...t2},i2=Object.entries(gi).map(([s,e])=>({key:s,label:e.label,previewStatic:`https://cdn.subgen.co/previews/static/transition_${s}_static.webp`,previewDynamic:`https://cdn.subgen.co/previews/dynamic/transition_${s}_dynamic.webp`}));function Po({name:s,renderer:e}){let t=mi.find(Y=>Y.name===s);if(!t){const Y=Object.keys(gi).find(Q=>Q.toLowerCase()===s.toLowerCase());Y&&(t=gi[Y])}if(t||(t=mi.find(Y=>Y.name.toLowerCase()===s.toLowerCase())),!t){const Y=[s,s.toLowerCase(),s.charAt(0).toUpperCase()+s.slice(1).toLowerCase(),s.replace(/([A-Z])/g,"_$1").toLowerCase().replace(/^_/,""),s.replace(/_/g,"")];for(const Q of Y){if(t=mi.find(Pe=>Pe.name.toLowerCase()===Q.toLowerCase()),t)break;const xe=Object.keys(gi).find(Pe=>Pe.toLowerCase()===Q.toLowerCase());if(xe){t=gi[xe];break}}}if(!t){const Y=mi.length,Q=mi.slice(0,5).map(Pe=>Pe.name).join(", "),xe=Object.keys(gi).slice(0,3).join(", ");throw console.error(`Transition not found: "${s}". Available in gl-transitions (${Y} total):`,Q+"..."),console.error("Available locally:",xe+"..."),new Error(`Transition "${s}" not found in gl-transitions library or local definitions`)}const r=new we(F.WHITE),n=Ae.create({width:e.width,height:e.height}),o=new ct({}),c=new ct({}),l=t.name==="displacement"||s.toLowerCase()==="displacement"||t.label==="displacement",d=l?new ct({}):void 0;let f=null;if(l){f=document.createElement("canvas"),f.width=256,f.height=256;const Y=f.getContext("2d");if(Y){const Q=Y.createImageData(256,256);for(let xe=0;xe<Q.data.length;xe+=4){const Pe=Math.random();Q.data[xe]=Pe*255,Q.data[xe+1]=Pe*255,Q.data[xe+2]=Pe*255,Q.data[xe+3]=255}Y.putImageData(Q,0,0)}}let m=t.glsl||t.fragment;if(!m)throw new Error(`Transition "${s}" has no glsl or fragment code`);let g={...ce.basics,...ce.custom(t)};Object.entries(g).forEach(([,Y])=>{Y.type==="int<f32>"&&(Y.type="i32",typeof Y.value=="number"&&(Y.value=Math.trunc(Y.value))),Y.type==="ivec2<f32>"&&(Y.type="vec2<f32>")}),console.log("Making transition",s),console.log("Transition glsl",m);const _=t.name==="GridFlip"||s.toLowerCase()==="gridflip"||t.label==="gridflip",y=t.name==="circle"||s.toLowerCase()==="circle"||t.label==="circle",a=t.name==="directional"||s.toLowerCase()==="directional"||t.label==="directional",h=t.name==="UndulatingBurnOut"||s.toLowerCase()==="undulatingburnout"||t.label==="undulatingBurnOut",u=t.name==="SquaresWire"||s.toLowerCase()==="squareswire"||t.label==="squaresWire",p=t.name==="rotate_scale_fade"||s.toLowerCase()==="rotatescalefade"||t.label==="rotateScaleFade",v=t.name==="RandomSquares"||s.toLowerCase()==="randomsquares"||t.label==="randomSquares",x=t.name==="polar_function"||s.toLowerCase()==="polar_function"||t.label==="polar_function",b=t.name==="pixelate"||s.toLowerCase()==="pixelate"||t.label==="pixelate",T=t.name==="perlin"||s.toLowerCase()==="perlin"||t.label==="perlin",w=t.name==="luma"||s.toLowerCase()==="luma"||t.label==="luma",S=t.name==="luminance_melt"||s.toLowerCase()==="luminance_melt"||s.toLowerCase()==="luminancemelt"||t.label==="luminance_melt",E=t.name==="hexagonalize"||s.toLowerCase()==="hexagonalize"||t.label==="hexagonalize",A=t.name==="heart"||s.toLowerCase()==="heart"||t.label==="heart",P=t.name==="displacement"||s.toLowerCase()==="displacement"||t.label==="displacement",I=t.name==="directionalwipe"||s.toLowerCase()==="directionalwipe"||s.toLowerCase()==="directional_wipe"||t.label==="directionalwipe",k=t.name==="directionalwarp"||s.toLowerCase()==="directionalwarp"||s.toLowerCase()==="directional_warp"||t.label==="directionalwarp",O=t.name==="crosshatch"||s.toLowerCase()==="crosshatch"||t.label==="crosshatch",X=t.name==="circleopen"||s.toLowerCase()==="circleopen"||s.toLowerCase()==="circle_open"||t.label==="circleopen",ne=t.name==="cannabisleaf"||s.toLowerCase()==="cannabisleaf"||s.toLowerCase()==="cannabis_leaf"||t.label==="cannabisleaf",R=t.name==="StereoViewer"||s.toLowerCase()==="stereoviewer"||s.toLowerCase()==="stereo_viewer"||t.label==="StereoViewer",M=t.name==="GlitchDisplace"||s.toLowerCase()==="glitchDisplace"||t.label==="GlitchDisplace",q=t.name==="CrossZoom"||s.toLowerCase()==="crosszoom"||t.label==="CrossZoom",N=t.name==="CrazyParametricFun"||s.toLowerCase()==="crazyparametricfun"||t.label==="CrazyParametricFun",ee=t.name==="BowTieHorizontal"||s.toLowerCase()==="bowtiehorizontal"||t.label==="BowTieHorizontal",he=t.name==="PolkaDotsCurtain"||s.toLowerCase()==="polkadotscurtain"||t.label==="PolkaDotsCurtain",ye=t.name==="Pixelize"||s.toLowerCase()==="pixelize"||t.label==="Pixelize";_&&(m=lb,g={...ce.basics,...cb}),y&&(m=hb,g={...ce.basics,...sd}),a&&(m=ub,g={...ce.basics,...db}),h&&(m=fb,g={...ce.basics,...pb}),u&&(m=mb,g={...ce.basics,...gb}),p&&(m=vb,g={...ce.basics,..._b}),v&&(m=yb,g={...ce.basics,...xb}),x&&(m=bb,g={...ce.basics,...Tb}),b&&(m=td,g={...ce.basics,...id}),T&&(m=Cb,g={...ce.basics,...Ab}),w&&(m=Eb,g={...ce.basics,...Ib}),S&&(m=Pb,g={...ce.basics,...Rb}),E&&(m=Mb,g={...ce.basics,...Fb}),A&&(m=Ub,g={...ce.basics,...kb}),P&&(m=Bb,g={...ce.basics,...Db}),I&&(m=Ob,g={...ce.basics,...Gb}),k&&(m=Lb,g={...ce.basics,...Nb}),O&&(m=zb,g={...ce.basics,...Hb}),X&&(m=Wb,g={...ce.basics,...sd}),ne&&(m=Vb,g={...ce.basics,...Yb}),R&&(m=Xb,g={...ce.basics,...$b}),M&&(m=qb),q&&(m=Kb,g={...ce.basics,...jb}),N&&(m=Zb,g={...ce.basics,...Jb}),ee&&(m=Qb),he&&(m=e2),ye&&(m=wb,g={...ce.basics,...Sb});const U={from:o,to:c,uniforms:g};l&&d&&(U.displacementMap=d,f&&(d.resource=f,d.update()));const Ie=new Dr({glProgram:new vt({vertex:sb,fragment:ob(m)}),resources:U});return r.filters=[Ie],{render({width:Y,height:Q,from:xe,to:Pe,progress:_i}){if((r.width!==Y||r.height!==Q)&&(r.setSize({width:Y,height:Q}),n.resize(Y,Q)),xe instanceof F?Ie.resources.from=xe.source:(o.resource=xe,o.update(),Ie.resources.from=o),Pe instanceof F?Ie.resources.to=Pe.source:(c.resource=Pe,c.update(),Ie.resources.to=c),l&&d&&f){if(f.width!==Y||f.height!==Q){f.width=Y,f.height=Q;const Ut=f.getContext("2d");if(Ut){const ht=Ut.createImageData(Y,Q);for(let Ge=0;Ge<ht.data.length;Ge+=4){const nt=Math.random();ht.data[Ge]=nt*255,ht.data[Ge+1]=nt*255,ht.data[Ge+2]=nt*255,ht.data[Ge+3]=255}Ut.putImageData(ht,0,0)}}d.resource=f,d.update()}return Ie.resources.uniforms.uniforms.progress=_i,e.render({container:r,target:n,clear:!1,width:Y,height:Q}),n},destroy(){n.destroy(),r.destroy({children:!0})}}}let r2=0;async function nd(s){s()>50&&(await ws(15),await nd(s))}class s2{static async isSupported(e={}){return(self.OffscreenCanvas!=null&&self.VideoEncoder!=null&&self.VideoDecoder!=null&&self.VideoFrame!=null&&self.AudioEncoder!=null&&self.AudioDecoder!=null&&self.AudioData!=null&&((await self.VideoEncoder.isConfigSupported({codec:e.videoCodec??"avc1.42E032",width:e.width??1920,height:e.height??1080,bitrate:e.bitrate??7e6})).supported??!1)&&(await self.AudioEncoder.isConfigSupported({codec:(await aa()).codec,sampleRate:oe.sampleRate,numberOfChannels:oe.channelCount})).supported)??!1}logger=W.create(`id:${r2++},`);destroyed=!1;sprites=[];canvas;pixiApp=null;stopOutput=null;opts;hasVideoTrack;evtTool=new Yo;on=this.evtTool.on;constructor(e={}){const{width:t=0,height:r=0}=e;this.canvas=new OffscreenCanvas(t,r),this.opts=Object.assign({bgColor:"#000",width:0,height:0,videoCodec:"avc1.42E032",audio:!0,bitrate:5e6,fps:30,metaDataTags:null},e),this.hasVideoTrack=t*r>0,aa().catch(n=>{this.logger.warn("Failed to detect audio codec:",n)})}async initPixiApp(){const{width:e,height:t}=this.opts;if(this.pixiApp=new fn,console.log("PIXI APP 000",this.pixiApp),await this.pixiApp.init({canvas:this.canvas,width:e,height:t,backgroundColor:0,antialias:!1,autoDensity:!1,resolution:1,preference:"webgl"}),this.pixiApp.renderer==null||this.pixiApp.stage==null)throw new Error("Pixi.js Application failed to initialize properly");try{const r=this.pixiApp;r.ticker&&typeof r.ticker.stop=="function"&&r.ticker.stop()}catch{}}async addSprite(e,t={}){const r={rect:{x:e.left,y:e.top,w:e.width,h:e.height},display:{...e.display},duration:e.duration,playbackRate:e.playbackRate,zIndex:e.zIndex};this.logger.info("Compositor add clip",r);const n=await e.clone();console.log("PIXI APP 111",this.pixiApp),this.pixiApp!=null&&this.pixiApp.renderer!=null&&typeof n.setRenderer=="function"&&n.setRenderer(this.pixiApp.renderer),this.logger.info("Compositor add clip ready"),this.sprites.push(Object.assign(n,{main:t.main??!1,expired:!1})),this.sprites.sort((o,c)=>o.zIndex-c.zIndex)}initMuxer(e){const{fps:t,width:r,height:n,videoCodec:o,bitrate:c,audio:l,metaDataTags:d}=this.opts,f=this.sprites.some(_=>_.width>0&&_.height>0),m=this.hasVideoTrack&&f;return Jd({video:m?{width:r,height:n,expectFPS:t,codec:o,bitrate:c,__unsafe_hardwareAcceleration__:this.opts.__unsafe_hardwareAcceleration__}:null,audio:l===!1?null:{codec:oe.codecType,sampleRate:oe.sampleRate,channelCount:oe.channelCount},duration:e,metaDataTags:d})}output(e={}){if(this.sprites.length===0)throw Error("No sprite added");const t=this.sprites.find(g=>g.main),n=this.sprites.map(g=>g.display.from+g.duration).filter(g=>g!==1/0),o=e.maxTime??(t!=null?t.display.from+t.duration:n.length>0?Math.max(...n):1/0);if(o===1/0||o<=0)throw Error("Unable to determine the end time, please specify a main sprite, or limit the duration of ImageClip, AudioClip");o===-1&&this.logger.warn("Unable to determine the end time, process value don't update"),this.logger.info(`start combinate video, maxTime:${o}`);const c=this.initMuxer(o);let l=performance.now();const d=this.runEncoding(c,o,{onProgress:g=>{this.logger.debug("OutputProgress:",g),this.evtTool.emit("OutputProgress",g)},onEnded:async()=>{await c.flush(),this.logger.info("===== output ended =====, cost:",performance.now()-l),this.evtTool.emit("OutputProgress",1),this.destroy()},onError:g=>{this.evtTool.emit("error",g),m(g),this.destroy()}});this.stopOutput=()=>{d(),c.close(),m()};const{stream:f,stop:m}=Jo(c.mp4file,500,this.destroy);return f}destroy(){if(!this.destroyed&&(this.destroyed=!0,this.stopOutput?.(),this.evtTool.destroy(),this.pixiApp!=null))try{const e=this.pixiApp;if(e.destroyed===!0){this.pixiApp=null;return}if(e.ticker&&typeof e.ticker.stop=="function")try{e.ticker.stop()}catch{}if(e.renderer!=null){const t=e.renderer.gl;if(t&&t.isContextLost()){this.pixiApp=null;return}this.pixiApp.destroy()}}catch(e){console.warn("Error while destroying Pixi application:",e)}finally{this.pixiApp=null}}runEncoding(e,t,{onProgress:r,onEnded:n,onError:o}){let c=0;const l={aborted:!1};let d=null,f=null;const m=async()=>{const{fps:y,bgColor:a,audio:h}=this.opts,u=Math.round(1e6/y),p=this.sprites.some(b=>b.width>0&&b.height>0);f=n2({pixiApp:this.pixiApp,sprites:this.sprites,aborter:l});const v=o2({muxer:e,canvas:this.canvas,outputAudio:h,hasVideoTrack:this.hasVideoTrack&&p,timeSlice:u,fps:y});let x=0;for(;;){if(d!=null)return;if(l.aborted||t!==-1&&x>t||this.sprites.length===0){g(),await n();return}c=x/t;const{audios:b,mainSprDone:T,hasVideo:w}=await f.render(x);if(T){g(),await n();return}if(l.aborted)return;this.hasVideoTrack&&w&&await new Promise(S=>requestAnimationFrame(S)),v(x,b,w),x+=u,await nd(e.getEncodeQueueSize)}},g=()=>{l.aborted||(l.aborted=!0,clearInterval(_),f?.cleanup(),this.sprites.forEach(y=>{y.destroy()}))};m().catch(y=>{d=y,this.logger.error(y),g(),o(y)});const _=setInterval(()=>{r(c)},500);return g}exportToJSON(){const e=this.sprites.map(r=>ar(r,r.main)),t=[];return this.sprites.forEach(r=>{if(r.transition){const n=this.sprites.filter(o=>o.id!==r.id&&o.zIndex===r.zIndex&&o.display.from<r.display.from&&(o instanceof fe||o instanceof ve)).sort((o,c)=>c.display.to-o.display.to)[0];n&&t.push({key:r.transition.name,duration:r.transition.duration,clips:[n.id,r.id]})}}),{clips:e,transition:t.length>0?t:void 0,settings:{width:this.opts.width,height:this.opts.height,fps:this.opts.fps,bgColor:this.opts.bgColor,videoCodec:this.opts.videoCodec,bitrate:this.opts.bitrate,audio:this.opts.audio,metaDataTags:this.opts.metaDataTags}}}async loadFromJSON(e){this.sprites.forEach(r=>{r.destroy()}),this.sprites=[],e.settings&&(e.settings.width!==void 0&&(this.opts.width=e.settings.width),e.settings.height!==void 0&&(this.opts.height=e.settings.height),e.settings.fps!==void 0&&(this.opts.fps=e.settings.fps),e.settings.bgColor!==void 0&&(this.opts.bgColor=e.settings.bgColor),e.settings.videoCodec!==void 0&&(this.opts.videoCodec=e.settings.videoCodec),e.settings.bitrate!==void 0&&(this.opts.bitrate=e.settings.bitrate),e.settings.audio!==void 0&&(this.opts.audio=e.settings.audio===!1?!1:void 0),e.settings.metaDataTags!==void 0&&(this.opts.metaDataTags=e.settings.metaDataTags));for(const r of e.clips){const n=await lr(r);await this.addSprite(n,{main:r.main||!1})}const t=e.transition||e.transitions;if(t){console.log(`[Compositor] Restoring ${t.length} transitions`);for(const r of t){const n=r.clips[1],o=this.sprites.find(c=>c.id===n);o?(console.log(`[Compositor] Applying transition ${r.key} to clip ${n}`),o.transition={name:r.key,duration:r.duration,prevClipId:r.clips[0]}):console.warn(`[Compositor] Could not find target clip ${n} for transition ${r.key}`)}}else console.log("[Compositor] No transition data found in JSON")}}function n2(s){const{pixiApp:e,sprites:t,aborter:r}=s,n=e!=null,o=new Map,c=new Map,l=new Map,d=Ae.create({width:e?.renderer.width||0,height:e?.renderer.height||0}),f=Ae.create({width:e?.renderer.width||0,height:e?.renderer.height||0}),m=new Ce().rect(0,0,e?.renderer.width||0,e?.renderer.height||0).fill({color:0}),g=new Map,_=T=>t.filter(w=>w.id!==T.id&&w.zIndex===T.zIndex&&w.display.from<T.display.from&&(w instanceof fe||w instanceof ve)).sort((w,S)=>S.display.to-w.display.to)[0]||null,y=async(T,w)=>{let S=null;if(T.transition?.prevClipId&&(S=t.find(I=>I.id===T.transition.prevClipId)||null),S||(S=_(T)),!S)return null;const E=S.duration>0?S.duration:0,A=Math.max(0,Math.min(w-S.display.from,E)),{video:P}=await S.getFrame(A);return P},a=(T,w,S)=>{if(!e)return;e.renderer.render({container:m,target:S,clear:!0});const E=new we(w instanceof F?w:F.from(w));E.x=T.center.x,E.y=T.center.y,E.anchor.set(.5,.5);const A=E.texture.width||1,P=E.texture.height||1,I=T.width&&T.width!==0?Math.abs(T.width)/A:1,k=T.height&&T.height!==0?Math.abs(T.height)/P:1;T.flip==="horizontal"?(E.scale.x=-I,E.scale.y=k):T.flip==="vertical"?(E.scale.x=I,E.scale.y=-k):(E.scale.x=I,E.scale.y=k),E.rotation=(T.flip==null?1:-1)*T.angle,E.alpha=T.opacity,e.renderer.render({container:E,target:S,clear:!1}),w instanceof F||E.texture.destroy(!0),E.destroy()};let h=null,u=null,p=null;n&&e!=null&&(h=new se,u=new se,p=new se,u.sortableChildren=!0,p.sortableChildren=!0,e.stage.addChild(u),e.stage.addChild(p),h.visible=!1,e.stage.addChild(h));const v=[...t].sort((T,w)=>T.zIndex-w.zIndex);return{render:async T=>{const w=[];let S=!1,E=!1;for(const A of l.values())A.visible=!1;for(const A of v){if(r.aborted)break;if(T<A.display.from||A.expired){if(n&&e!=null){const ne=o.get(A);ne&&await ne.updateFrame(null)}continue}const P=T-A.display.from,I=P*A.playbackRate;A.animate(I);const{video:k,audio:O,done:X}=await A.getFrame(P);if(w.push(O),n&&e!=null&&u!=null){if((A instanceof fe||A instanceof ve)&&A.transition&&P>=0&&P<=A.transition.duration){const M=await y(A,T),{video:q}=await A.getFrame(P);if(M&&q){const N=P/A.transition.duration,ee=_(A);ee?a(ee,M,d):e.renderer.render({container:m,target:d,clear:!0}),a(A,q,f);let he=c.get(A.id);he||(he=Po({name:A.transition.name,renderer:e.renderer}),c.set(A.id,he));const ye=he.render({width:e.renderer.width,height:e.renderer.height,from:d,to:f,progress:N});let U=l.get(A.id);U||(U=new we,U.label=`TransitionSprite_${A.id}`,l.set(A.id,U),u.addChild(U)),U.texture=ye,U.visible=!0,U.x=0,U.y=0,U.width=e.renderer.width,U.height=e.renderer.height,U.anchor.set(0,0),U.zIndex=A.zIndex,E=!0;const Ie=o.get(A);if(Ie){const Y=Ie.getSprite();Y&&(Y.visible=!1)}if(ee){const Y=o.get(ee);if(Y){const Q=Y.getSprite();Q&&(Q.visible=!1)}}continue}}let R=o.get(A);R==null&&k!=null&&(R=new or(e,A,u),o.set(A,R)),R!=null&&(k!=null?(E=!0,await R.updateFrame(k)):await R.updateFrame(null)),R?.updateTransforms()}if(A.duration>0&&T>A.display.from+A.duration||X){if(A.main&&(S=!0),A.expired=!0,n){const ne=o.get(A);if(ne!=null){const R=ne.getSprite();R&&(R.visible=!1)}}}else if(n){const ne=o.get(A);ne?.updateTransforms()}}if(n&&e!=null&&h!=null&&u!=null&&p!=null){let A=null;for(const P of t)if(P instanceof Je&&T>=P.display.from&&T<P.display.from+P.duration){A={id:P.id,key:P.effect.key,startTime:P.display.from,duration:P.duration};break}if(!A)for(const P of t){if(P.effects&&P.effects.length>0){for(const I of P.effects)if(T>=I.startTime&&T<I.startTime+I.duration){A=I;break}}if(A)break}p.removeChildren();for(const P of o.values()){const I=P.getSprite();I&&I.parent!==u&&(I.parent&&I.parent.removeChild(I),u.addChild(I))}if(A){const{key:P,startTime:I,duration:k,id:O}=A,X=T-I,ne=k>0?Math.min(Math.max(X/k,0),1):0,R=t.some(M=>M.id===O&&M instanceof Je);for(const M of t){let q=!1;if(R?q=M.id!==O&&!(M instanceof Je):q=!!M.effects&&M.effects.some(N=>N.id===O),q){const N=o.get(M);if(N){const ee=N.getSprite();ee&&(ee.parent&&ee.parent.removeChild(ee),h.addChild(ee))}}}if(h.children.length>0){let M=g.get(O);if(!M)try{const q=Eo({name:P,renderer:e.renderer});q&&q.filter&&(M={filter:q.filter,render:q.render},g.set(O,M))}catch(q){console.warn("Failed to create effect",P,q)}if(M){const{filter:q,render:N}=M;q.resources&&q.resources.effectUniforms&&(q.resources.effectUniforms.uniforms.uTime=ne);const ee=e.renderer.width,he=e.renderer.height,ye=Ae.create({width:ee,height:he});if(h.visible=!0,e.renderer.render({container:h,target:ye,clear:!0}),h.visible=!1,N){const U=N({canvasTexture:ye,progress:ne,width:ee,height:he}),Ie=new we(U);Ie.width=ee,Ie.height=he,p.addChild(Ie)}}}}}return n&&e!=null&&e.render(),{audios:w,mainSprDone:S,hasVideo:E}},cleanup:()=>{d&&d.destroy(!0),f&&f.destroy(!0),m&&m.destroy(!0);for(const T of l.values())T.destroy();l.clear(),c.clear(),h&&h.destroy({children:!0}),u&&u.destroy({children:!0}),p&&p.destroy({children:!0}),o.forEach(T=>{T.destroy()}),o.clear()}}}function o2(s){const{canvas:e,outputAudio:t,muxer:r,hasVideoTrack:n,timeSlice:o}=s;let c=0;const l=Math.floor(3*s.fps),d=a2(1024);return(f,m,g)=>{if(t!==!1)for(const _ of d(f,m))r.encodeAudio(_);if(n&&g)try{const _=new VideoFrame(e,{duration:o,timestamp:f});r.encodeVideo(_,{keyFrame:c%l===0}),c+=1}catch(_){console.warn("Failed to create VideoFrame from canvas, skipping frame:",_)}}}function a2(s){const e=s*oe.channelCount,t=new Float32Array(e*3);let r=0,n=0;const o=s/oe.sampleRate*1e6,c=new Float32Array(e),l=d=>{let f=0;const m=Math.floor(r/e),g=[];for(let _=0;_<m;_++)g.push(new AudioData({timestamp:n,numberOfChannels:oe.channelCount,numberOfFrames:s,sampleRate:oe.sampleRate,format:"f32",data:t.subarray(f,f+e)})),f+=e,n+=o;for(t.set(t.subarray(f,r),0),r-=f;d-n>o;)g.push(new AudioData({timestamp:n,numberOfChannels:oe.channelCount,numberOfFrames:s,sampleRate:oe.sampleRate,format:"f32",data:c})),n+=o;return g};return(d,f)=>{const m=Math.max(...f.map(g=>g[0]?.length??0));for(let g=0;g<m;g++){let _=0,y=0;for(let a=0;a<f.length;a++){const h=f[a][0]?.[g]??0,u=f[a][1]?.[g]??h;_+=h,y+=u}t[r]=_,t[r+1]=y,r+=2}return l(d)}}class l2 extends Ce{constructor(){super(),this.eventMode="static",this.cursor="move"}draw(e,t=1){const n=1*t;this.clear(),this.setStrokeStyle({width:n,color:5620223}).rect(e.x,e.y,e.width,e.height).stroke(),this.hitArea=e}}class wt extends Ce{#e=!1;handle;cursor;callbacks;constructor(e,t,r){super(),this.handle=e,this.cursor=t,this.callbacks=r,this.eventMode="static",this.#o(),this.on("pointerdown",this.#t),this.on("globalpointermove",this.#r),this.on("pointerup",this.#l),this.on("pointerupoutside",this.#l)}#o(){this.clear(),this.handle==="rot"?(this.circle(0,0,10),this.fill({color:"#ffffff"}),this.stroke({width:1,color:13421772}),this.moveTo(0,-5),this.arc(0,0,5,-Math.PI/2,Math.PI,!1),this.stroke({width:1,color:0}),this.moveTo(0,-8),this.lineTo(-3,-5),this.lineTo(0,-2),this.stroke({width:1,color:0,cap:"round",join:"round"}),this.hitArea=new Yr(0,0,24)):(this.rect(-5,-5,10,10),this.fill({color:"#ffffff"}),this.stroke({width:1,color:5620223}),this.hitArea=new z(-15,-15,30,30))}#t=e=>{this.#e=!0,this.cursor="grabbing",this.callbacks.beginDrag(this.handle,e.global),e.stopPropagation()};#r=e=>{this.#e&&(this.callbacks.updateDrag(this.handle,e.global),e.stopPropagation())};#l=e=>{this.#e&&(this.#e=!1,this.cursor="pointer",this.callbacks.endDrag(),e.stopPropagation())}}const od={delta:new B};class c2 extends se{group;wireframe=new l2;isDragging=!1;lastPointer=new J;activeHandle=null;#e;#o=new Map;#t=new J;#r=0;#l=0;#a=new z;#i=new J;#c=new z;#s=1;#n=1;opts;constructor(e){super(),this.opts=e,this.group=e.group,this.eventMode="static";const t={beginDrag:(r,n)=>this.#_(r,n),updateDrag:(r,n)=>this.#y(r,n),endDrag:()=>this.#f()};this.#e={tl:new wt("tl","nwse-resize",t),tr:new wt("tr","nesw-resize",t),bl:new wt("bl","nesw-resize",t),br:new wt("br","nwse-resize",t),ml:new wt("ml","ew-resize",t),mr:new wt("mr","ew-resize",t),mt:new wt("mt","ns-resize",t),mb:new wt("mb","ns-resize",t),rot:new wt("rot","crosshair",{beginDrag:(r,n)=>this.#b(n),updateDrag:(r,n)=>this.#T(n),endDrag:()=>this.#f()})},this.addChild(this.wireframe,...Object.values(this.#e)),this.#m(),Ne.shared.addOnce(()=>this.#h())}#m(){this.on("pointerdown",this.#g),this.on("pointerup",this.#d),this.on("pointerupoutside",this.#d),this.on("globalpointermove",this.#v)}#h(){if(this.group.length===1){const e=this.group[0],t=e.getBounds();this.#t.set(t.x+t.width/2,t.y+t.height/2),this.#r=e.rotation;let r,n;if(this.opts.clip)r=this.opts.clip.width,n=this.opts.clip.height;else{const o=e.getLocalBounds();r=o.width,n=o.height}this.#c.copyFrom(new z(-r/2,-n/2,r,n))}else{const e=this.#w();this.#t.set(e.x+e.width/2,e.y+e.height/2);let t=e.width,r=e.height;if(this.parent){const o=new J(e.x,e.y),c=new J(e.x+e.width,e.y+e.height),l=this.parent.toLocal(o),d=this.parent.toLocal(c);t=Math.abs(d.x-l.x),r=Math.abs(d.y-l.y)}const n=new z(-t/2,-r/2,t,r);this.#c.copyFrom(n)}this.#u()}updateBounds(){this.#h()}#g=e=>{this.#h(),this.isDragging=!0,this.lastPointer.copyFrom(e.global),this.cursor="grabbing"};#d=()=>{this.isDragging&&this.emit("transformEnd"),this.isDragging=!1,this.activeHandle=null,this.cursor="default"};#v=e=>{if(!this.isDragging||this.activeHandle||!this.parent)return;const t=this.parent.toLocal(this.lastPointer),r=this.parent.toLocal(e.global),n=r.x-t.x,o=r.y-t.y;for(const d of this.group)d.x+=n,d.y+=o;const c=e.global.x-this.lastPointer.x,l=e.global.y-this.lastPointer.y;this.#t.x+=c,this.#t.y+=l,this.lastPointer.copyFrom(e.global),this.#u()};#_(e,t){this.#h(),this.isDragging=!0,this.activeHandle=e,console.log("[Transformer] #beginHandleDrag called, activeHandle:",this.activeHandle),this.#o.clear();for(const r of this.group)this.#o.set(r,r.localTransform.clone());this.rotation=this.#r,this.#a.copyFrom(this.#c),this.#S(e)}#y(e,t){this.#x(e,t)}async#x(e,t){const r=this.#i,n=this.#C(e,this.toLocal(t),r),o=n.width/this.#a.width,c=n.height/this.#a.height,l=this.toGlobal(r);if(this.opts.clip&&this.opts.clip.constructor.name==="TextClip"){const f=n.width;console.log("[Transformer] TextClip scaling:",{handle:e,originalWidth:this.#a.width,newWidth:f,sx:o,sy:c}),this.emit("textClipResize",{handle:e,newWidth:f,newHeight:n.height,pivotWorld:l,proposed:n})}else this.#p(this.#A(l,this.#r,o,c));this.#c.copyFrom(n),this.#u()}#b(e){this.#h(),this.isDragging=!0,this.activeHandle="rot",this.#o.clear();for(const t of this.group)this.#o.set(t,t.localTransform.clone());this.#l=Math.atan2(e.y-this.#t.y,e.x-this.#t.x)}#T(e){const r=Math.atan2(e.y-this.#t.y,e.x-this.#t.x)-this.#l,n=this.#r+r;this.#p(this.#E(this.#t,r)),this.rotation=n,this.#u(n)}#f(){console.log("[Transformer] #endDrag called, activeHandle:",this.activeHandle),this.isDragging=!1,this.#r=this.rotation,this.activeHandle=null,this.#u(this.#r),this.emit("transformEnd")}#w(){let e=1/0,t=1/0,r=-1/0,n=-1/0;for(const o of this.group){const c=o.getBounds();e=Math.min(e,c.x),t=Math.min(t,c.y),r=Math.max(r,c.x+c.width),n=Math.max(n,c.y+c.height)}return new z(e,t,r-e,n-t)}#u(e=this.#r){this.parent&&this.position.copyFrom(this.parent.toLocal(this.#t)),this.rotation=e;const r=1/((this.parent?Math.abs(this.parent.worldTransform.a):1)||1),n=this.#c;this.wireframe.draw(n,r);const o=n.x+n.width/2,c=n.y+n.height/2,l=[this.#e.tl,this.#e.tr,this.#e.bl,this.#e.br,this.#e.ml,this.#e.mr,this.#e.mt,this.#e.mb,this.#e.rot];for(const d of l)d.scale.set(r);this.#e.tl.position.set(n.x,n.y),this.#e.tr.position.set(n.x+n.width,n.y),this.#e.bl.position.set(n.x,n.y+n.height),this.#e.br.position.set(n.x+n.width,n.y+n.height),this.#e.ml.position.set(n.x,c),this.#e.mr.position.set(n.x+n.width,c),this.#e.mt.position.set(o,n.y),this.#e.mb.position.set(o,n.y+n.height),this.#e.rot.position.set(o,n.y-30*r)}#S(e){const t=this.#a;if(this.opts.centeredScaling){this.#i.set(t.x+t.width/2,t.y+t.height/2);return}e==="tl"?this.#i.set(t.x+t.width,t.y+t.height):e==="tr"?this.#i.set(t.x,t.y+t.height):e==="bl"?this.#i.set(t.x+t.width,t.y):e==="br"?this.#i.set(t.x,t.y):e==="ml"?this.#i.set(t.x+t.width,t.y+t.height/2):e==="mr"?this.#i.set(t.x,t.y+t.height/2):e==="mt"?this.#i.set(t.x+t.width/2,t.y+t.height):e==="mb"&&this.#i.set(t.x+t.width/2,t.y)}#C(e,t,r){if(this.opts.centeredScaling){const o=Math.max(this.#s,Math.abs(t.x-r.x)*2),c=Math.max(this.#n,Math.abs(t.y-r.y)*2);return new z(r.x-o/2,r.y-c/2,o,c)}if(e==="tl"){const o=Math.min(t.x,r.x-this.#s),c=Math.min(t.y,r.y-this.#n);return new z(o,c,r.x-o,r.y-c)}if(e==="tr"){const o=Math.max(t.x,r.x+this.#s),c=Math.min(t.y,r.y-this.#n);return new z(r.x,c,o-r.x,r.y-c)}if(e==="bl"){const o=Math.min(t.x,r.x-this.#s),c=Math.max(t.y,r.y+this.#n);return new z(o,r.y,r.x-o,c-r.y)}if(e==="br"){const o=Math.max(t.x,r.x+this.#s),c=Math.max(t.y,r.y+this.#n);return new z(r.x,r.y,o-r.x,c-r.y)}const n=this.#a;if(e==="ml"){const o=Math.min(t.x,r.x-this.#s);return new z(o,n.y,r.x-o,n.height)}if(e==="mr"){const o=Math.max(t.x,r.x+this.#s);return new z(r.x,n.y,o-r.x,n.height)}if(e==="mt"){const o=Math.min(t.y,r.y-this.#n);return new z(n.x,o,n.width,r.y-o)}if(e==="mb"){const o=Math.max(t.y,r.y+this.#n);return new z(n.x,r.y,n.width,o-r.y)}return new z(r.x,r.y,this.#s,this.#n)}#A(e,t,r,n){return od.delta.identity().translate(-e.x,-e.y).rotate(-t).scale(r,n).rotate(t).translate(e.x,e.y)}#E(e,t){return od.delta.identity().translate(-e.x,-e.y).rotate(t).translate(e.x,e.y)}#p(e){for(const t of this.group){const r=this.#o.get(t),n=t.parent;if(!r||!n)continue;const o=n.worldTransform.clone().invert(),c=n.worldTransform.clone().append(r),l=e.clone().append(c),d=o.clone().append(l);t.setFromMatrix(d)}}}class h2 extends oa{pixiApp=null;tracks=[];clips=[];spriteRenderers=new Map;artboard=null;clipContainer=null;artboardMask=null;artboardBg=null;activeTransformer=null;selectedClips=new Set;interactiveClips=new Set;playbackElements=new Map;videoSprites=new Map;clipListeners=new Map;isPlaying=!1;currentTime=0;playStartTime=0;playStartTimestamp=0;rafId=null;maxDuration=0;opts;destroyed=!1;globalEffects=new Map;activeGlobalEffect=null;currentGlobalEffectSprite=null;effectFilters=new Map;transitionRenderers=new Map;transitionSprites=new Map;transFromTexture=null;transToTexture=null;transBgGraphics=null;clipsNormalContainer=null;clipsEffectContainer=null;videoTextureCache=new WeakMap;lastFromFrame=null;lastToFrame=null;hexToNumber(e){const t=e.startsWith("#")?e.slice(1):e;return parseInt(t,16)}ready;constructor(e){super(),this.opts={fps:30,bgColor:"#000000",interactivity:!0,...e},this.ready=this.initPixiApp()}async initPixiApp(){if(this.destroyed)return;const e=this.opts.canvas||document.createElement("canvas");e.width=this.opts.width,e.height=this.opts.height,console.log("Initializing Pixi.js Application...",{width:this.opts.width,height:this.opts.height});const t=new fn,r=e.parentElement||window;await t.init({canvas:e,resizeTo:r,backgroundColor:this.hexToNumber(this.opts.bgColor),antialias:!0,resolution:window.devicePixelRatio||1,autoDensity:!0}),this.pixiApp=t,t.stage.eventMode="static",t.stage.hitArea=t.screen,t.stage.on("pointerdown",n=>{n.target===t.stage&&this.deselectClip()}),this.artboard=new se,this.artboard.label="ArtboardRoot",t.stage.addChild(this.artboard),this.artboardBg=new Ce,this.artboardBg.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}),this.artboard.addChild(this.artboardBg),this.clipContainer=new se,this.clipContainer.label="ClipContainer",this.artboard.addChild(this.clipContainer),this.artboardMask=new Ce,this.artboardMask.rect(0,0,this.opts.width,this.opts.height).fill({color:16777215}),this.clipContainer.addChild(this.artboardMask),this.clipContainer.mask=this.artboardMask,this.clipsEffectContainer=new se,this.clipsEffectContainer.label="ClipsEffect",this.clipsEffectContainer.visible=!1,this.clipsEffectContainer.zIndex=1,this.clipsEffectContainer.sortableChildren=!0,this.clipContainer.addChild(this.clipsEffectContainer),this.clipsNormalContainer=new se,this.clipsNormalContainer.label="ClipsNormal",this.clipsNormalContainer.zIndex=10,this.clipsNormalContainer.sortableChildren=!0,this.clipContainer.addChild(this.clipsNormalContainer),this.transFromTexture=Ae.create({width:this.opts.width,height:this.opts.height}),this.transToTexture=Ae.create({width:this.opts.width,height:this.opts.height}),this.transBgGraphics=new Ce,this.transBgGraphics.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}),this.clipContainer.sortableChildren=!0,this.updateArtboardLayout(),t.renderer.on("resize",()=>{this.handleResize()})}getOptions(){return this.opts}updateDimensions(e,t){this.opts.width=e,this.opts.height=t,this.artboardBg&&this.artboardBg.clear().rect(0,0,e,t).fill({color:3355443}),this.artboardMask&&this.artboardMask.clear().rect(0,0,e,t).fill({color:16777215}),this.transFromTexture&&this.transFromTexture.resize(e,t),this.transToTexture&&this.transToTexture.resize(e,t),this.transBgGraphics&&this.transBgGraphics.clear().rect(0,0,e,t).fill({color:3355443}),this.updateArtboardLayout(),this.updateFrame(this.currentTime)}handleResize=()=>{this.destroyed||!this.pixiApp||this.updateArtboardLayout()};updateArtboardLayout(){if(!this.pixiApp||!this.artboard)return;const e=this.pixiApp.canvas.width,t=this.pixiApp.canvas.height,r=this.opts.width,n=this.opts.height,o=this.pixiApp.canvas.parentElement?.clientWidth||e,c=this.pixiApp.canvas.parentElement?.clientHeight||t,l=o/r,d=c/n,f=Math.min(l,d);this.artboard.scale.set(f),this.artboard.x=(o-r*f)/2,this.artboard.y=(c-n*f)/2}getCanvas(){if(this.opts.canvas)return this.opts.canvas;if(this.pixiApp?.canvas)return this.pixiApp.canvas;throw new Error("Canvas not initialized yet. Wait for initPixiApp to complete.")}async addMedia(e){if(this.destroyed)return;const t=this.opts.width,r=this.opts.height;t&&r&&(typeof e.scaleToFit=="function"&&await e.scaleToFit(t,r),typeof e.centerInScene=="function"&&e.centerInScene(t,r));const n=e.duration>0?e.duration:5e6;e.duration<=0&&(e.duration=n);const o=this.tracks.filter(d=>["media","video","image","Video","Image"].includes(d.type)),c=o.find(d=>d.clipIds.length>0)||o[0];let l;if(c){l=c.id;const d=n;for(const f of c.clipIds){const m=this.getClipById(f);if(m){const g=m.display.from+d,_=m.display.to+d;await this.updateClip(f,{display:{from:g,to:_}})}}}e.display.from=0,e.display.to=n,await this.addClip(e,{trackId:l}),await this.seek(0)}async addTransition(e,t=2e6,r,n){if(this.destroyed)return;console.log("transitionKey",e);let o=null,c=null;if(r&&n&&(o=this.getClipById(r)??null,c=this.getClipById(n)??null,!o||!c)){console.warn("[Studio] Invalid fromClipId or toClipId",{fromClipId:r,toClipId:n});return}if(!c){const y=this.tracks.filter(a=>["media","video","image","Video","Image"].includes(a.type)||a.clipIds.length>1);for(const a of y){const h=a.clipIds.map(u=>this.getClipById(u)).filter(u=>!!u&&u.type!=="Transition").sort((u,p)=>u.display.from-p.display.from);for(let u=0;u<h.length-1;u++){const p=h[u],v=h[u+1];if(Math.abs(v.display.from-p.display.to)<1e5){o=p,c=v;break}}if(o&&c)break}}if(c&&!o){const y=this.findTrackIdByClipId(c.id);if(y){const a=this.tracks.find(h=>h.id===y);if(a){const h=a.clipIds.map(p=>this.getClipById(p)).filter(p=>!!p&&p.type!=="Transition").sort((p,v)=>p.display.from-v.display.from),u=h.findIndex(p=>p.id===c.id);u>0&&(o=h[u-1])}}}if(!o||!c){console.warn("[Studio] Unable to resolve Clip A and Clip B for transition");return}const l=t,d=c.display.from-l/2,f=d+l,m={key:e,name:e,duration:l,fromClipId:o.id,toClipId:c.id,start:Math.max(0,d),end:f},g=this.findTrackIdByClipId(c.id);if(g){const y=this.tracks.find(a=>a.id===g);if(y){const a=y.clipIds.map(h=>this.getClipById(h)).filter(h=>{if(!h||h.type!=="Transition")return!1;const u=h;return u.fromClipId===o.id&&u.toClipId===c.id});for(const h of a)await this.removeClip(h)}}this.transitionRenderers.has(o.id)&&(this.transitionRenderers.get(o.id)?.destroy(),this.transitionRenderers.delete(o.id)),this.transitionRenderers.has(c.id)&&(this.transitionRenderers.get(c.id)?.destroy(),this.transitionRenderers.delete(c.id)),"transition"in o&&(o.transition={...m}),"transition"in c&&(c.transition={...m});const _=new pi(e);_.duration=l,_.fromClipId=Math.max(0,d)===0?null:o.id,_.toClipId=c.id,_.fromClipId===null&&o&&(_.fromClipId=o.id),_.display.from=Math.max(0,d),_.display.to=f,await this.addClip(_,{trackId:g}),this.seek(this.currentTime)}findTrackIdByClipId(e){for(const t of this.tracks)if(t.clipIds.includes(e))return t.id}async addClip(e,t){let r,n;if(t&&(typeof t=="string"||t instanceof File||t instanceof Blob))r=t;else if(typeof t=="object"&&t!==null&&!("size"in t)){const d=t;r=d.audioSource,n=d.trackId}if(this.destroyed)return;if(this.pixiApp==null)throw new Error("Failed to initialize Pixi.js Application");const o=async()=>{await this.updateFrame(this.currentTime),this.activeTransformer!=null&&this.selectedClips.has(e)&&typeof this.activeTransformer.updateBounds=="function"&&this.activeTransformer.updateBounds()};e.on("propsChange",o),this.clipListeners.set(e,o),this.pixiApp!=null&&typeof e.setRenderer=="function"&&e.setRenderer(this.pixiApp.renderer);const c=await e.ready;if(e.id||(e.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`),this.clips.includes(e)||this.clips.push(e),n){const d=this.tracks.find(f=>f.id===n);d?d.clipIds.includes(e.id)||d.clipIds.push(e.id):this.tracks.unshift({id:n,name:`Track ${this.tracks.length+1}`,type:e.type,clipIds:[e.id]})}else{const d=`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;this.tracks.unshift({id:d,name:`Track ${this.tracks.length+1}`,type:e.type,clipIds:[e.id]})}const l=e.duration>0?e.duration:c.duration;if(l===1/0||isNaN(l))await this.recalculateMaxDuration();else{const d=e.display.from+l;d>0&&(this.maxDuration=Math.max(this.maxDuration,d))}if(await this.setupPlaybackForClip(e,r),c.width>0&&c.height>0)if(e instanceof fe){if(e.tickInterceptor!=null){const d=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,d)}}else{const d=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,d)}await this.updateFrame(this.currentTime),this.opts.interactivity&&this.setupSpriteInteractivity(e),this.emit("clip:added",{clip:e,trackId:n||this.tracks.find(d=>d.clipIds.includes(e.id))?.id||""})}addTrack(e){const t={id:e.id||`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,name:e.name,type:e.type,clipIds:[]};return this.tracks.push(t),this.emit("track:added",{track:t}),t}async setTracks(e){this.tracks=e,await this.recalculateMaxDuration(),await this.updateFrame(this.currentTime)}async removeTrack(e){const t=this.tracks.findIndex(o=>o.id===e);if(t===-1)return;const n=[...this.tracks[t].clipIds];for(const o of n){const c=this.clips.find(l=>l.id===o);c&&await this.removeClip(c)}this.tracks.splice(t,1),this.emit("track:removed",{trackId:e}),await this.recalculateMaxDuration()}getClipById(e){return this.clips.find(t=>t.id===e)}async updateClip(e,t){const r=this.clips.find(n=>n.id===e);if(!r){console.warn(`[Studio] updateClip: Clip not found with id ${e}`);return}if(r instanceof Ze&&(await r.updateStyle(t),"style"in t&&delete t.style),Object.assign(r,t),t.display&&!t.duration?r.duration=t.display.to-t.display.from:t.duration&&(!t.display||!t.display.to)&&(r.display||(r.display={from:0,to:t.duration}),r.display.to=r.display.from+t.duration),t.display&&t.duration){const n=t.display.to-t.display.from;n!==t.duration&&(r.duration=n)}else r.display&&(r.display.to=r.display.from+r.duration);await this.recalculateMaxDuration(),this.emit("clip:updated",{clip:r}),await this.updateFrame(this.currentTime)}getTracks(){return this.tracks}getClip(e){return this.clips.find(t=>t.id===e)}setupSpriteInteractivity(e){if(this.interactiveClips.has(e))return;const t=this.spriteRenderers.get(e);if(t==null)return;const r=t.getSprite();r!=null&&(r.eventMode="static",r.cursor="pointer",r.on("pointerdown",n=>{n.stopPropagation(),this.selectClip(e,n.shiftKey)}),this.interactiveClips.add(e))}async setupPlaybackForClip(e,t){if(this.pixiApp!=null){if(!this.isPlaybackCapable(e)){if(this.pixiApp!=null&&(await e.ready).width>0&&(await e.ready).height>0){const r=new or(this.pixiApp,e,this.clipsNormalContainer);this.spriteRenderers.set(e,r)}return}try{const r=e;if(e instanceof Me&&t&&typeof t!="string"){const c=URL.createObjectURL(t);e.src=c}const{element:n,objectUrl:o}=await r.createPlaybackElement();if(e instanceof fe){const c=F.from(n),l=new we(c);l.visible=!1,this.clipsNormalContainer&&this.clipsNormalContainer.addChild(l),this.videoSprites.set(e,l)}this.playbackElements.set(e,{element:n,objectUrl:o})}catch(r){if(console.warn(`Failed to setup playback for ${e.constructor.name}, falling back to PixiSpriteRenderer:`,r),this.pixiApp!=null){const n=await e.ready;if(n.width>0&&n.height>0){const o=new or(this.pixiApp,e,this.artboard);this.spriteRenderers.set(e,o)}}}}}isPlaybackCapable(e){return"createPlaybackElement"in e&&"play"in e&&"pause"in e&&"seek"in e&&"syncPlayback"in e&&"cleanupPlayback"in e}async removeClip(e){const t=this.clips.findIndex(l=>l===e);if(t===-1)return;this.selectedClips.has(e)&&this.deselectClip(),this.clips.splice(t,1);for(const l of this.tracks){const d=l.clipIds.indexOf(e.id);d!==-1&&l.clipIds.splice(d,1)}this.interactiveClips.delete(e);const r=this.clipListeners.get(e);r&&(e.off("propsChange",r),this.clipListeners.delete(e));const n=this.spriteRenderers.get(e);n!=null&&(n.destroy(),this.spriteRenderers.delete(e));const o=this.playbackElements.get(e);o!=null&&(this.isPlaybackCapable(e)&&e.cleanupPlayback(o.element,o.objectUrl),this.playbackElements.delete(e));const c=this.videoSprites.get(e);c!=null&&this.pixiApp!=null&&(this.artboard?.removeChild(c),c.destroy(),this.videoSprites.delete(e)),await this.recalculateMaxDuration(),this.emit("clip:removed",{clipId:e.id})}async removeClipById(e){const t=this.clips.find(r=>r.id===e);t&&await this.removeClip(t)}async deleteSelected(){const e=Array.from(this.selectedClips);if(e.length!==0)for(const t of e)await this.removeClip(t)}async duplicateSelected(){const e=Array.from(this.selectedClips);if(e.length===0)return;const t=[];for(const r of e){const n=this.findTrackIdByClipId(r.id);if(!n)continue;const o=this.tracks.find(m=>m.id===n);if(!o)continue;const c=ar(r,!1),l=await lr(c);l.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const d=`track_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,f=`${o.name} (Copy)`;this.addTrack({id:d,name:f,type:o.type}),await this.addClip(l,{trackId:d}),t.push(l.id)}t.length>0&&this.selectClipsByIds(t)}async splitSelected(e){const t=Array.from(this.selectedClips);if(t.length!==1){console.warn("[Studio] Split requires exactly one selected clip");return}const r=t[0],n=e??this.currentTime;if(n<=r.display.from||r.display.to>0&&n>=r.display.to){console.warn("[Studio] Split time is outside clip bounds");return}const o=ar(r,!1),c=n-r.display.from,l=r.playbackRate||1,d=c*l,f={duration:c,display:{from:r.display.from,to:n}};r.trim&&(f.trim={from:r.trim.from,to:r.trim.from+d}),await this.updateClip(r.id,f);const m={...o};m.display={from:n,to:o.display.to},m.duration=o.duration-c,m.trim&&(m.trim={from:m.trim.from+d,to:m.trim.to});const g=await lr(m);g.id=`clip_${Date.now()}_${Math.random().toString(36).substr(2,9)}`;const _=this.findTrackIdByClipId(r.id);_&&(await this.addClip(g,{trackId:_}),this.selectClipsByIds([g.id]))}async trimSelected(e){const t=Array.from(this.selectedClips);if(t.length!==1){console.warn("[Studio] Trim requires exactly one selected clip");return}const r=t[0];console.log("[Studio] Trimming clip:",{clipId:r.id,currentDisplay:r.display,currentDuration:r.duration,currentTrim:r.trim,trimFromSeconds:e});const n=e*1e6,o=r.playbackRate||1,c=n*o;if(n>=r.duration){console.warn("[Studio] Trim amount exceeds clip duration");return}const l=r.duration-n,d=r.display.from+n,f=r.display.to,m={duration:l,display:{from:d,to:f}};if(r.trim)m.trim={from:r.trim.from+c,to:r.trim.to};else{const g=r.sourceDuration||r.duration;m.trim={from:c,to:g}}console.log("[Studio] Trim updates:",m),await this.updateClip(r.id,m),console.log("[Studio] Clip after trim:",{display:r.display,duration:r.duration,trim:r.trim})}async updateSelected(e){const t=Array.from(this.selectedClips);if(t.length!==0)for(const r of t)await this.updateClip(r.id,e)}clear(){this.deselectClip(),this.interactiveClips.clear(),this.effectFilters.clear(),this.globalEffects.clear(),this.spriteRenderers.forEach(e=>{e.destroy()}),this.spriteRenderers.clear();for(const[e,t]of this.playbackElements.entries())this.isPlaybackCapable(e)&&e.cleanupPlayback(t.element,t.objectUrl);this.playbackElements.clear();for(const e of this.videoSprites.values())e.destroy();this.videoSprites.clear(),this.transitionRenderers.clear(),this.transFromTexture&&(this.transFromTexture.destroy(!0),this.transFromTexture=null),this.transToTexture&&(this.transToTexture.destroy(!0),this.transToTexture=null),this.transBgGraphics&&(this.transBgGraphics.destroy(!0),this.transBgGraphics=null);for(const e of this.transitionSprites.values())e.parent&&e.parent.removeChild(e),e.destroy();this.transitionSprites.clear(),this.tracks=[],this.clips=[],this.maxDuration=0,this.currentTime=0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null),this.emit("reset")}async play(){if(!(this.isPlaying||this.destroyed)){if(this.maxDuration<=0||this.maxDuration===1/0||isNaN(this.maxDuration)){console.warn("Cannot play: invalid duration",this.maxDuration);return}this.isPlaying||(this.isPlaying=!0),this.playStartTime=this.currentTime,this.playStartTimestamp=performance.now();for(const[e,{element:t}]of this.playbackElements.entries()){if(!(this.currentTime>=e.display.from&&(e.display.to===0||this.currentTime<=e.display.to))){this.isPlaybackCapable(e)&&e.pause(t);continue}const n=(this.currentTime-e.display.from)/1e6;this.isPlaybackCapable(e)&&await e.play(t,n)}this.renderLoop(),this.emit("play",{isPlaying:!0})}}pause(){this.isPlaying=!1,this.rafId!=null&&(cancelAnimationFrame(this.rafId),this.rafId=null);for(const[e,{element:t}]of this.playbackElements.entries())this.isPlaybackCapable(e)&&e.pause(t);this.emit("pause",{isPlaying:!1})}async stop(){this.pause(),await this.seek(0)}async seek(e){if(this.destroyed)return;const t=this.isPlaying;this.playStartTime=Math.max(0,Math.min(e,this.maxDuration)),this.playStartTimestamp=performance.now(),this.currentTime=this.playStartTime;for(const[r,{element:n}]of this.playbackElements.entries()){if(!(this.currentTime>=r.display.from&&(r.display.to===0||this.currentTime<=r.display.to))){this.isPlaybackCapable(r)&&r.pause(n);continue}const c=(this.currentTime-r.display.from)/1e6;this.isPlaybackCapable(r)&&await r.seek(n,c)}if(await this.updateFrame(this.currentTime),t){this.isPlaying=!0;for(const[r,{element:n}]of this.playbackElements.entries()){if(!(this.currentTime>=r.display.from&&(r.display.to===0||this.currentTime<=r.display.to)))continue;const c=(this.currentTime-r.display.from)/1e6;this.isPlaybackCapable(r)&&await r.play(n,c)}}}getCurrentTime(){return this.currentTime}getMaxDuration(){return this.maxDuration===1/0||isNaN(this.maxDuration)||this.maxDuration<=0?0:this.maxDuration}getIsPlaying(){return this.isPlaying}getSelectedClips(){return Array.from(this.selectedClips)}async renderLoop(){if(!this.isPlaying||this.destroyed||this.pixiApp==null)return;if(this.maxDuration<=0||this.maxDuration===1/0||isNaN(this.maxDuration)){this.pause();return}const e=async()=>{if(!this.isPlaying||this.destroyed||this.pixiApp==null)return;if(this.currentTime>=this.maxDuration){this.currentTime=this.maxDuration,this.pause();return}const r=(performance.now()-this.playStartTimestamp)*1e3;this.currentTime=Math.min(this.playStartTime+r,this.maxDuration),this.emit("currentTime",{currentTime:this.currentTime});try{await this.updateFrame(this.currentTime)}catch(n){console.warn("Error updating frame:",n)}this.isPlaying&&(this.rafId=requestAnimationFrame(e))};e()}getVideoTexture(e){let t=this.videoTextureCache.get(e);return t||(t=F.from(e),this.videoTextureCache.set(e,t)),t}async updateFrame(e){if(this.destroyed||this.pixiApp==null)return;this.updateActiveGlobalEffect(e);const t=new Set,r=this.tracks.length;for(const o of this.clips){const c=this.getTrackIndex(o.id);if(c!==-1){const l=(r-c)*10;o.zIndex=l;const d=this.spriteRenderers.get(o);if(d){const f=d.getSprite();f&&(f.zIndex=l)}}}const n=[...this.clips].sort((o,c)=>o.zIndex-c.zIndex);for(const o of n){if(e<o.display.from){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}if(o.display.to>0&&e>o.display.to){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}const c=e-o.display.from,l=c*o.playbackRate;o.animate(l);const d=await o.ready,f=o.duration||d.duration;if(f>0&&c>f){const h=this.spriteRenderers.get(o);h!=null&&await h.updateFrame(null);const u=this.playbackElements.get(o);u!=null&&this.isPlaybackCapable(o)&&o.pause(u.element);continue}const m=this.playbackElements.get(o),g=o instanceof fe||o instanceof ve,_=o.transition?o.transition.start:0,y=o.transition?o.transition.end:0;if(g&&o.transition&&e>=_&&e<=y){this.transFromTexture||(this.transFromTexture=Ae.create({width:this.opts.width,height:this.opts.height})),this.transToTexture||(this.transToTexture=Ae.create({width:this.opts.width,height:this.opts.height})),this.transBgGraphics||(this.transBgGraphics=new Ce,this.transBgGraphics.rect(0,0,this.opts.width,this.opts.height).fill({color:3355443}));const h=this.getClipById(o.transition.fromClipId),u=this.getClipById(o.transition.toClipId);let p=null,v=null;if(h){const x=Math.max(0,e-h.display.from),{video:b}=await h.getFrame(x);b instanceof HTMLVideoElement?p=this.getVideoTexture(b):p=b,p&&(this.lastFromFrame=p)}if(u){const x=Math.max(0,e-u.display.from),{video:b}=await u.getFrame(x);b instanceof HTMLVideoElement?v=this.getVideoTexture(b):v=b,v&&(this.lastToFrame=v)}if(p||(p=this.lastFromFrame),v||(v=this.lastToFrame),!p||!v)continue;if(p&&v&&this.pixiApp&&this.transFromTexture&&this.transToTexture){const x=(e-_)/o.transition.duration;h&&p&&this.renderClipToTransitionTexture(h,p,this.transFromTexture),u&&v&&this.renderClipToTransitionTexture(u,v,this.transToTexture);let b=this.transitionRenderers.get(o.id);if(!b)try{b=Po({name:o.transition.name,renderer:this.pixiApp.renderer}),this.transitionRenderers.set(o.id,b)}catch(T){console.error("[Studio] Failed to create transition renderer:",T)}if(b){const T=b.render({width:this.opts.width,height:this.opts.height,from:this.transFromTexture,to:this.transToTexture,progress:x});let w=this.transitionSprites.get(o.id);w||(w=new we,w.label=`TransitionSprite_${o.id}`,this.transitionSprites.set(o.id,w),this.clipsNormalContainer&&this.clipsNormalContainer.addChild(w)),w.texture=T,w.visible=!0,w.x=0,w.y=0,w.width=this.opts.width,w.height=this.opts.height,w.anchor.set(0,0),w.zIndex=o.zIndex,t.add(o.id);const S=this.spriteRenderers.get(o);if(S?.getSprite()&&(S.getSprite().visible=!1),h){const E=this.spriteRenderers.get(h);E?.getSprite()&&(E.getSprite().visible=!1)}continue}}}if(m!=null&&this.isPlaybackCapable(o)){const h=c/1e6;if(o.syncPlayback(m.element,this.isPlaying,h),o instanceof fe){const u=this.videoSprites.get(o);if(u!=null){const p=o.meta.duration/1e6;if(this.spriteRenderers.has(o))u.visible=!1;else{u.visible=h>=0&&h<p,u.visible&&tb(o,u);continue}}}else continue}const a=this.spriteRenderers.get(o);if(a!=null){const h=this.selectedClips.has(o);if(o instanceof ve){const p=o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms();continue}}if(o instanceof Ze){const p=await o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms();continue}}if(o instanceof Ft){o.updateState(c);const p=await o.getTexture();if(p!=null){await a.updateFrame(p),h||a.updateTransforms(),this.opts.interactivity&&this.setupSpriteInteractivity(o);continue}else console.log("[Studio] CaptionClip texture is null, falling back to traditional path")}const{video:u}=await o.getFrame(c);await a.updateFrame(u),h||a.updateTransforms(),this.opts.interactivity&&this.setupSpriteInteractivity(o)}}if(this.activeGlobalEffect&&this.clipsNormalContainer&&this.clipsEffectContainer){const{startTime:o,duration:c}=this.activeGlobalEffect,l=e-o,d=Math.min(Math.max(l/c,0),1);if(d>0&&d<1){try{for(const m of this.clips)this.moveClipToEffectContainer(m,!1);const f=this.clips.some(m=>m.id===this.activeGlobalEffect.id&&m instanceof Je);for(const m of this.clips){let g=!1;if(f){const _=this.activeGlobalEffect.trackIndex??-1,y=this.getTrackIndex(m.id);g=m.id!==this.activeGlobalEffect.id&&!(m instanceof Je)&&y>_}else{const _=m.effects;g=Array.isArray(_)&&_.some(y=>y&&y.id===this.activeGlobalEffect.id)}g&&this.moveClipToEffectContainer(m,!0)}}catch(f){console.warn("Failed to reparent clips for effect; falling back to full-scene render",f)}this.clipsNormalContainer.visible=!0,await this.applyGlobalEffectIfNeeded(e)}else{for(const f of this.clips)try{this.moveClipToEffectContainer(f,!1)}catch{}this.clipsNormalContainer.visible=!0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null)}}else if(this.clipsNormalContainer){for(const o of this.clips)try{this.moveClipToEffectContainer(o,!1)}catch{}this.clipsNormalContainer.visible=!0,this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null)}for(const[o,c]of this.transitionSprites.entries())t.has(o)||(c.visible=!1);this.pixiApp!=null&&this.pixiApp.render()}async recalculateMaxDuration(){this.maxDuration=0;for(const e of this.clips){const t=await e.ready,r=e.duration>0?e.duration:t.duration,n=e.display.from+r;n!==1/0&&!isNaN(n)&&n>0&&(this.maxDuration=Math.max(this.maxDuration,n))}}moveClipToEffectContainer(e,t=!0){if(!this.clipsNormalContainer||!this.clipsEffectContainer)return;const r=t?this.clipsEffectContainer:this.clipsNormalContainer,n=this.spriteRenderers.get(e);if(n){const c=n.getSprite();if(c&&c.parent!==r){try{c.parent&&c.parent.removeChild&&c.parent.removeChild(c)}catch(l){console.warn("moveClipToEffectContainer: could not remove sprite from parent",l)}r.addChild(c)}}const o=this.transitionSprites.get(e.id);if(o&&o.parent!==r){try{o.parent&&o.parent.removeChild&&o.parent.removeChild(o)}catch(c){console.warn("moveClipToEffectContainer: could not remove transSprite from parent",c)}r.addChild(o)}}applyGlobalEffect(e,t,r){const n=t.id||`${e}_${Date.now()}_${Math.random().toString(36).substr(2,9)}`,o={id:n,key:e,startTime:t.startTime,duration:t.duration??1e6};for(const c of r)c instanceof ve&&c.addEffect(o),c instanceof fe&&c.addEffect(o),c instanceof Ze&&c.addEffect(o),c instanceof Ft&&c.addEffect(o);return this.globalEffects.set(n,o),n}getTrackIndex(e){return this.tracks.findIndex(t=>t.clipIds.includes(e))}async getTransitionFromFrame(e,t){let r=null;if(e.transition?.prevClipId&&(r=this.clips.find(l=>l.id===e.transition.prevClipId)||null),r||(r=this.getPreviousClipOnTrack(e)),!r)return null;const n=r.duration>0?r.duration:0,o=Math.max(0,Math.min(t-r.display.from,n)),{video:c}=await r.getFrame(o);return c}getPreviousClipOnTrack(e){const t=this.getTrackIndex(e.id);return t===-1?null:this.clips.filter(r=>r.id!==e.id&&this.getTrackIndex(r.id)===t&&r.display.from<e.display.from&&(r instanceof fe||r instanceof ve)).sort((r,n)=>n.display.to-r.display.to)[0]||null}renderClipToTransitionTexture(e,t,r){if(!this.pixiApp||!this.transBgGraphics)return;this.pixiApp.renderer.render({container:this.transBgGraphics,target:r,clear:!0});const n=new we(t instanceof F?t:F.from(t));n.x=e.center.x,n.y=e.center.y,n.anchor.set(.5,.5);const o=n.texture.width||1,c=n.texture.height||1,l=e.width&&e.width!==0?Math.abs(e.width)/o:1,d=e.height&&e.height!==0?Math.abs(e.height)/c:1;e.flip==="horizontal"?(n.scale.x=-l,n.scale.y=d):e.flip==="vertical"?(n.scale.x=l,n.scale.y=-d):(n.scale.x=l,n.scale.y=d),n.rotation=(e.flip==null?1:-1)*e.angle,n.alpha=e.opacity,this.pixiApp.renderer.render({container:n,target:r,clear:!1}),t instanceof F||n.texture.destroy(!0),n.destroy()}removeGlobalEffect(e){this.globalEffects.delete(e)}clearGlobalEffects(){this.globalEffects.clear()}updateActiveGlobalEffect(e){let t=null;for(const r of this.clips)if(r instanceof Je&&e>=r.display.from&&(r.display.to===0||e<=r.display.to)){t={id:r.id,key:r.effect.key,startTime:r.display.from,duration:r.duration>0?r.duration:r.display.to-r.display.from,trackIndex:this.getTrackIndex(r.id)};break}if(!t)for(const r of this.globalEffects.values()){const n=r.startTime+r.duration;if(e>=r.startTime&&e<n){t={id:r.id,key:r.key,startTime:r.startTime,duration:r.duration,trackIndex:-1};break}}this.activeGlobalEffect=t}async applyGlobalEffectIfNeeded(e){if(this.currentGlobalEffectSprite&&(this.currentGlobalEffectSprite.parent&&this.currentGlobalEffectSprite.parent.removeChild(this.currentGlobalEffectSprite),this.currentGlobalEffectSprite.destroy(),this.currentGlobalEffectSprite=null),!this.activeGlobalEffect||!this.pixiApp||!this.clipContainer||!this.artboard||!this.clipsNormalContainer||!this.clipsEffectContainer)return;const{key:t,startTime:r,duration:n}=this.activeGlobalEffect,o=e-r,c=Math.min(Math.max(o/n,0),1);if(c<=0||c>=1)return;this.clipsEffectContainer.visible=!0;let l=this.effectFilters.get(t);if(!l)try{if(l=Eo({name:t.toLowerCase(),renderer:this.pixiApp.renderer}),l)this.effectFilters.set(t,l);else return}catch(y){console.error(y);return}const d=this.opts.width,f=this.opts.height,m=Ae.create({width:d,height:f});this.pixiApp.renderer.render({container:this.clipsEffectContainer,target:m,clear:!0}),this.clipsEffectContainer.visible=!1;const g=l.render({canvasTexture:m,progress:c,width:d,height:f}),_=new we(g);_.x=0,_.y=0,_.width=d,_.height=f,_.scale.set(1),_.zIndex=5,this.clipContainer.addChild(_),this.currentGlobalEffectSprite=_,m.destroy(!0)}destroy(){if(!this.destroyed){window.removeEventListener("resize",this.handleResize),this.destroyed=!0,this.stop(),this.clear(),this.transitionRenderers.clear(),this.transFromTexture&&(this.transFromTexture.destroy(!0),this.transFromTexture=null),this.transToTexture&&(this.transToTexture.destroy(!0),this.transToTexture=null),this.transBgGraphics&&(this.transBgGraphics.destroy(!0),this.transBgGraphics=null);for(const e of this.transitionSprites.values())e.destroy();this.transitionSprites.clear(),this.pixiApp&&(this.pixiApp.destroy(!0,{children:!0,texture:!0}),this.pixiApp=null)}}selectClip(e,t=!1){if(!(this.destroyed||this.pixiApp==null)){if(t||this.deselectClip(),t&&this.selectedClips.has(e)){this.selectedClips.delete(e),this.activeTransformer!=null&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.selectedClips.size>0&&this.createTransformer(),this.emit("selection:updated",{selected:Array.from(this.selectedClips)});return}this.selectedClips.add(e),this.activeTransformer!=null&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.createTransformer(),t?this.emit("selection:updated",{selected:Array.from(this.selectedClips)}):this.emit("selection:created",{selected:Array.from(this.selectedClips)})}}createTransformer(){if(this.destroyed||this.artboard==null||this.selectedClips.size===0)return;const e=[];let t=null;for(const n of this.selectedClips){const o=this.spriteRenderers.get(n);if(o==null)continue;const c=o.getSprite();c!=null&&(e.push(c),this.selectedClips.size===1&&(t=n))}if(e.length===0){console.warn("Cannot create transformer: no sprites found");return}this.activeTransformer=new c2({group:e,clip:t});let r=null;this.activeTransformer.on("transforming",()=>{r===null&&(r=requestAnimationFrame(()=>{r=null,this.syncSelectedClipsTransformsRealtime()}))}),this.activeTransformer.on("textClipResize",n=>{this.textClipResizedWidth=n.newWidth}),this.activeTransformer.on("transformEnd",()=>{r!==null&&(cancelAnimationFrame(r),r=null),this.syncSelectedClipsTransforms()}),this.artboard.addChild(this.activeTransformer)}isUpdatingTextClipRealtime=!1;textClipResizedWidth=null;async syncSelectedClipsTransformsRealtime(){if(!(this.selectedClips.size===0||this.activeTransformer==null)&&!this.isUpdatingTextClipRealtime){this.isUpdatingTextClipRealtime=!0;try{if(this.activeTransformer.activeHandle!=="mr")return;for(const t of this.selectedClips){if(!(t instanceof Ze))continue;const r=this.spriteRenderers.get(t);if(r==null)continue;const n=r.getSprite();if(n==null||n.texture==null)continue;const o=Math.abs(n.scale.x);if(o===1)continue;const c=t.left,l=t.top,d=n.texture.width,f=o*d;await t.updateStyle({wordWrap:!0,wordWrapWidth:f});const m=await t.getTexture();m&&(await r.updateFrame(m),n.scale.set(1,1),t.left=c,t.top=l,n.x=t.left+t.width/2,n.y=t.top+t.height/2)}}finally{this.isUpdatingTextClipRealtime=!1}}}async syncSelectedClipsTransforms(){if(!(this.selectedClips.size===0||this.activeTransformer==null)){for(const e of this.selectedClips){const t=this.spriteRenderers.get(e);if(t==null)continue;const r=t.getSprite();if(r==null||r.texture==null)continue;const n=r.texture.width,o=r.texture.height,c=Math.abs(r.scale.x)*n,l=Math.abs(r.scale.y)*o,d=e instanceof Ze&&this.textClipResizedWidth!==null?this.textClipResizedWidth:c,f=r.x-d/2,m=r.y-l/2;if(e instanceof Ze&&this.textClipResizedWidth!==null){await e.updateStyle({wordWrap:!0,wordWrapWidth:d});const g=await e.getTexture();g&&(await t.updateFrame(g),e.width=d,e.height=g.height,this.textClipResizedWidth=null,e.left=r.x-e.width/2,e.top=r.y-e.height/2,r.scale.set(1,1))}else e.left=f,e.top=m,e.width=c,e.height=l,e.angle=r.angle}this.activeTransformer!=null&&this.activeTransformer.updateBounds();for(const e of this.selectedClips){const t=this.spriteRenderers.get(e);t?.updateTransforms()}}}syncSpriteToClipProperties(e){const t=this.spriteRenderers.get(e);if(t!=null){const r=t.getSprite();if(r!=null&&r.texture!=null){const n=r.texture.width,o=r.texture.height,c=Math.abs(r.scale.x)*n,l=Math.abs(r.scale.y)*o,d=r.x-c/2,f=r.y-l/2;e.left=d,e.top=f,e.width=c,e.height=l,e.angle=r.angle,t.updateTransforms()}}}setSelection(e){if(!(this.destroyed||this.pixiApp==null)&&!(this.selectedClips.size===e.length&&e.every(t=>this.selectedClips.has(t)))){for(const t of this.selectedClips)this.syncSpriteToClipProperties(t);this.activeTransformer&&(this.activeTransformer.parent&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null),this.selectedClips.clear();for(const t of e)this.selectedClips.add(t);this.selectedClips.size>0?(this.createTransformer(),this.emit("selection:updated",{selected:Array.from(this.selectedClips)})):this.emit("selection:cleared",{deselected:[]})}}selectClipsByIds(e){const t=this.clips.filter(r=>e.includes(r.id));this.setSelection(t)}deselectClip(){if(this.selectedClips.size>0)for(const t of this.selectedClips)this.syncSpriteToClipProperties(t);this.activeTransformer!=null&&(this.activeTransformer.parent!=null&&this.activeTransformer.parent.removeChild(this.activeTransformer),this.activeTransformer.destroy(),this.activeTransformer=null);const e=Array.from(this.selectedClips);this.selectedClips.clear(),e.length>0&&this.emit("selection:cleared",{deselected:e})}exportToJSON(){const e=this.clips.map(n=>ar(n,!1)),t=this.tracks.map(n=>({id:n.id,name:n.name,type:n.type,clipIds:n.clipIds})),r=[];return this.clips.forEach(n=>{if(n.transition){const o=this.tracks.find(c=>c.clipIds.includes(n.id));if(o){const c=o.clipIds.indexOf(n.id);if(c>0){const l=o.clipIds[c-1];r.push({key:n.transition.name,duration:n.transition.duration,clips:[l,n.id]})}}}}),{tracks:t,clips:e,transition:r.length>0?r:void 0,settings:{width:this.opts.width,height:this.opts.height,fps:this.opts.fps,bgColor:this.opts.bgColor}}}async loadFromJSON(e){if(this.clear(),e.settings){const r=e.settings.width&&e.settings.width!==this.opts.width||e.settings.height&&e.settings.height!==this.opts.height;if(e.settings.width&&(this.opts.width=e.settings.width),e.settings.height&&(this.opts.height=e.settings.height),e.settings.fps&&(this.opts.fps=e.settings.fps),e.settings.bgColor&&(this.opts.bgColor=e.settings.bgColor),r&&this.pixiApp!=null){const n=this.opts.width,o=this.opts.height;this.pixiApp.renderer.resize(n,o),this.opts.canvas&&(this.opts.canvas.width=n,this.opts.canvas.height=o)}}if(e.clips){const r=new Map;if(e.tracks){for(const n of e.tracks)if(n.clipIds)for(const o of n.clipIds)r.set(o,n.id)}if(e.tracks)for(const n of e.tracks)this.tracks.push({id:n.id,name:n.name,type:n.type,clipIds:[]});for(const n of e.clips){let o=n.id?r.get(n.id):void 0;if(!o&&n.type==="Transition"){const c=n,l=c.toClipId||c.fromClipId;l&&(o=r.get(l))}await this.loadClipIntoTrack(n,o)}}for(const r of this.clips){const n=r.effects;if(Array.isArray(n))for(const o of n)this.globalEffects.has(o.id)||this.globalEffects.set(o.id,{id:o.id,key:o.key,startTime:o.startTime,duration:o.duration})}const t=e.transition||e.transitions;if(t)for(const r of t){const n=r.clips[0],o=r.clips[1],c=this.getClipById(n),l=this.getClipById(o);if(c&&l){const d=this.clips.find(y=>y.type==="Transition"&&y.fromClipId===n&&y.toClipId===o),f=r.duration;let m,g;if(d)m=d.display.from,g=d.display.to;else{const y=l.display.from;m=Math.max(0,y-f/2),g=m+f}const _={key:r.key,name:r.key,duration:f,fromClipId:n,toClipId:o,start:m,end:g};"transition"in c&&(c.transition=_),"transition"in l&&(l.transition=_)}else console.warn(`[Studio] Could not find clips for transition ${r.key}: from=${n}, to=${o}`)}else console.log("[Studio] No transition data found in JSON");try{await this.updateFrame(this.currentTime)}catch(r){console.error("[Studio] Failed to update initial frame:",r)}}async loadClipIntoTrack(e,t){if(e.type!=="Text"&&e.type!=="Caption"&&e.type!=="Effect"&&e.type!=="Transition"&&(!e.src||e.src.trim()==="")){console.warn(`Skipping clip ${e.type} with empty source`);return}try{const r=await lr(e),n=r instanceof Me?e.src:void 0;await this.addClip(r,{trackId:t,audioSource:n}),(r instanceof fe||r instanceof ve)&&(!e.width||!e.height)&&(await r.scaleToFit(this.opts.width,this.opts.height),r.centerInScene(this.opts.width,this.opts.height))}catch(r){console.warn(`Failed to load clip of type ${e.type}:`,r)}}}class vi{static instance;fonts=new Map;constructor(){}static getInstance(){return vi.instance||(vi.instance=new vi),vi.instance}async addFont(e){if(!this.fonts.has(e.name))try{const r=await new FontFace(e.name,`url(${e.url})`).load();document.fonts.add(r),this.fonts.set(e.name,r)}catch(t){console.error(`Failed to load font ${e.name}:`,t)}}async loadFonts(e){await Promise.all(e.map(t=>this.addFont(t)))}removeFont(e){const t=this.fonts.get(e);t&&(document.fonts.delete(t),this.fonts.delete(e))}clear(){this.fonts.forEach(e=>{document.fonts.delete(e)}),this.fonts.clear()}getLoadedFonts(){return Array.from(this.fonts.keys())}}const u2=vi.getInstance();L.add(Qp),L.mixin(se,em),L.add(Bl),L.add(Dl),L.add(Wc),L.mixin(se,Ev),L.add(Hc),L.add(Eu),L.add(Fn),L.add(Ru),L.add(Bu),L.add(Du),L.add($u),L.add(Xu),L.add(Nu),L.add(Vu),L.add(Hu),L.add(Lu),L.add(Gu),L.add($c),L.add(Yc);const d2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"})),f2=Object.freeze(Object.defineProperty({__proto__:null},Symbol.toStringTag,{value:"Module"}));te.AudioClip=Me,te.CaptionClip=Ft,te.Compositor=s2,te.EffectClip=Je,te.GL_EFFECT_OPTIONS=eb,te.GL_TRANSITION_OPTIONS=i2,te.ImageClip=ve,te.Log=W,te.MP4Clip=fe,te.Studio=h2,te.TextClip=Ze,te.TransitionClip=pi,te.VideoClip=fe,te.clipToJSON=ar,te.createChromakey=Df,te.fastConcatMP4=ed,te.fixFMP4Duration=kx,te.fontManager=u2,te.jsonToClip=lr,te.makeEffect=Eo,te.makeTransition=Po,te.mixinMP4AndAudio=Gx,te.renderTxt2ImgBitmap=Nf,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
|