modern-canvas 0.4.17 → 0.4.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -5658,13 +5658,14 @@ exports.Node = class Node extends CoreObject {
5658
5658
  setParent(parent) {
5659
5659
  if (!this._parent?.is(parent)) {
5660
5660
  const oldParent = this._parent;
5661
+ if (oldParent) {
5662
+ this.emit("unparented", oldParent);
5663
+ }
5661
5664
  this._parent = parent;
5662
- this.setTree(parent?._tree);
5663
5665
  if (parent) {
5664
5666
  this.emit("parented", parent);
5665
- } else if (oldParent) {
5666
- this.emit("unparented", oldParent);
5667
5667
  }
5668
+ this.setTree(parent?._tree);
5668
5669
  }
5669
5670
  return this;
5670
5671
  }
@@ -9789,6 +9790,7 @@ exports.Text2D = class Text2D extends TextureRect2D {
9789
9790
  fonts;
9790
9791
  texture = new CanvasTexture();
9791
9792
  text = new modernText.Text();
9793
+ measureResult;
9792
9794
  _subTextsCount = 0;
9793
9795
  constructor(properties, children = []) {
9794
9796
  super();
@@ -9822,7 +9824,17 @@ exports.Text2D = class Text2D extends TextureRect2D {
9822
9824
  this.text.requestUpdate();
9823
9825
  }
9824
9826
  _updateStyleProperty(key, value, oldValue) {
9825
- super._updateStyleProperty(key, value, oldValue);
9827
+ switch (key) {
9828
+ case "left":
9829
+ case "top":
9830
+ case "width":
9831
+ case "height":
9832
+ this.requestRedraw();
9833
+ break;
9834
+ default:
9835
+ super._updateStyleProperty(key, value, oldValue);
9836
+ break;
9837
+ }
9826
9838
  switch (key) {
9827
9839
  case "width":
9828
9840
  if (this.split) {
@@ -9844,10 +9856,9 @@ exports.Text2D = class Text2D extends TextureRect2D {
9844
9856
  }
9845
9857
  _updateSubTexts() {
9846
9858
  const subTexts = this._getSubTexts();
9847
- const result = this.measure();
9848
9859
  let i = 0;
9849
9860
  if (this.split) {
9850
- result.paragraphs.forEach((p) => {
9861
+ this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
9851
9862
  p.fragments.forEach((f) => {
9852
9863
  f.characters.forEach((c) => {
9853
9864
  const child = subTexts[i];
@@ -9863,21 +9874,26 @@ exports.Text2D = class Text2D extends TextureRect2D {
9863
9874
  }
9864
9875
  measure() {
9865
9876
  this._updateText();
9866
- const result = this.text.measure();
9867
- if (!this.style.width)
9868
- this.style.width = result.boundingBox.width;
9869
- if (!this.style.height)
9870
- this.style.height = result.boundingBox.height;
9871
- return result;
9877
+ return this.text.measure();
9878
+ }
9879
+ updateMeasure() {
9880
+ this.measureResult = this.measure();
9881
+ const textWidth = this.measureResult.boundingBox.width;
9882
+ const textHeight = this.measureResult.boundingBox.height;
9883
+ const { left, top, width, height = textHeight } = this.style;
9884
+ this.position.x = left + Math.min(0, ((width || textWidth) - textWidth) / 2);
9885
+ this.position.y = top + Math.min(0, ((height || textHeight) - textHeight) / 2);
9886
+ this.size.width = textWidth;
9887
+ this.size.height = textHeight;
9888
+ return this;
9872
9889
  }
9873
9890
  _updateSplit() {
9874
9891
  if (this._subTextsCount) {
9875
9892
  this.getChildren("front").forEach((child) => this.removeChild(child));
9876
9893
  this._subTextsCount = 0;
9877
9894
  }
9878
- const result = this.measure();
9879
9895
  if (this.split) {
9880
- result.paragraphs.forEach((p) => {
9896
+ this.measureResult?.paragraphs.forEach((p) => {
9881
9897
  p.fragments.forEach((f) => {
9882
9898
  f.characters.forEach((c) => {
9883
9899
  this.appendChild(
@@ -9900,13 +9916,16 @@ exports.Text2D = class Text2D extends TextureRect2D {
9900
9916
  });
9901
9917
  }
9902
9918
  }
9919
+ _redraw() {
9920
+ this.updateMeasure();
9921
+ return super._redraw();
9922
+ }
9903
9923
  _drawContent() {
9904
9924
  if (!this.split) {
9905
9925
  const onText2DRender = this.getChildren()?.find((child) => "onText2DRender" in child)?.onText2DRender;
9906
9926
  if (onText2DRender) {
9907
9927
  onText2DRender();
9908
9928
  } else {
9909
- this._updateText();
9910
9929
  this.text.render({
9911
9930
  pixelRatio: this.texture.pixelRatio,
9912
9931
  view: this.texture.source
@@ -10136,10 +10155,12 @@ exports.Animation = class Animation extends exports.TimelineNode {
10136
10155
  super();
10137
10156
  this.setProperties(properties).append(children);
10138
10157
  }
10139
- _treeEnter(_tree) {
10158
+ _parented(parent) {
10159
+ super._parented(parent);
10140
10160
  this._updateCachedProps();
10141
10161
  }
10142
- _treeExit(_oldTree) {
10162
+ _unparented(oldParent) {
10163
+ super._unparented(oldParent);
10143
10164
  this.cancel();
10144
10165
  }
10145
10166
  _process() {
package/dist/index.d.cts CHANGED
@@ -2132,6 +2132,7 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2132
2132
  fonts?: TextOptions['fonts'];
2133
2133
  texture: CanvasTexture;
2134
2134
  text: Text;
2135
+ measureResult?: MeasureResult;
2135
2136
  protected _subTextsCount: number;
2136
2137
  constructor(properties?: Partial<Text2DProperties>, children?: Node[]);
2137
2138
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
@@ -2140,7 +2141,9 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2140
2141
  protected _getSubTexts(): Text2D[];
2141
2142
  protected _updateSubTexts(): void;
2142
2143
  measure(): MeasureResult;
2144
+ updateMeasure(): this;
2143
2145
  protected _updateSplit(): void;
2146
+ protected _redraw(): CanvasBatchable[];
2144
2147
  protected _drawContent(): void;
2145
2148
  }
2146
2149
 
@@ -2211,8 +2214,8 @@ declare class Animation extends TimelineNode {
2211
2214
  protected _cachedProps: RawWeakMap<any, Map<string, any>>;
2212
2215
  protected _stoped: boolean;
2213
2216
  constructor(properties?: Partial<AnimationProperties>, children?: Node[]);
2214
- protected _treeEnter(_tree: SceneTree): void;
2215
- protected _treeExit(_oldTree: SceneTree): void;
2217
+ protected _parented(parent: Node): void;
2218
+ protected _unparented(oldParent: Node): void;
2216
2219
  protected _process(): void;
2217
2220
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
2218
2221
  protected _getTargets(): any[];
package/dist/index.d.mts CHANGED
@@ -2132,6 +2132,7 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2132
2132
  fonts?: TextOptions['fonts'];
2133
2133
  texture: CanvasTexture;
2134
2134
  text: Text;
2135
+ measureResult?: MeasureResult;
2135
2136
  protected _subTextsCount: number;
2136
2137
  constructor(properties?: Partial<Text2DProperties>, children?: Node[]);
2137
2138
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
@@ -2140,7 +2141,9 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2140
2141
  protected _getSubTexts(): Text2D[];
2141
2142
  protected _updateSubTexts(): void;
2142
2143
  measure(): MeasureResult;
2144
+ updateMeasure(): this;
2143
2145
  protected _updateSplit(): void;
2146
+ protected _redraw(): CanvasBatchable[];
2144
2147
  protected _drawContent(): void;
2145
2148
  }
2146
2149
 
@@ -2211,8 +2214,8 @@ declare class Animation extends TimelineNode {
2211
2214
  protected _cachedProps: RawWeakMap<any, Map<string, any>>;
2212
2215
  protected _stoped: boolean;
2213
2216
  constructor(properties?: Partial<AnimationProperties>, children?: Node[]);
2214
- protected _treeEnter(_tree: SceneTree): void;
2215
- protected _treeExit(_oldTree: SceneTree): void;
2217
+ protected _parented(parent: Node): void;
2218
+ protected _unparented(oldParent: Node): void;
2216
2219
  protected _process(): void;
2217
2220
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
2218
2221
  protected _getTargets(): any[];
package/dist/index.d.ts CHANGED
@@ -2132,6 +2132,7 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2132
2132
  fonts?: TextOptions['fonts'];
2133
2133
  texture: CanvasTexture;
2134
2134
  text: Text;
2135
+ measureResult?: MeasureResult;
2135
2136
  protected _subTextsCount: number;
2136
2137
  constructor(properties?: Partial<Text2DProperties>, children?: Node[]);
2137
2138
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
@@ -2140,7 +2141,9 @@ declare class Text2D extends TextureRect2D<CanvasTexture> {
2140
2141
  protected _getSubTexts(): Text2D[];
2141
2142
  protected _updateSubTexts(): void;
2142
2143
  measure(): MeasureResult;
2144
+ updateMeasure(): this;
2143
2145
  protected _updateSplit(): void;
2146
+ protected _redraw(): CanvasBatchable[];
2144
2147
  protected _drawContent(): void;
2145
2148
  }
2146
2149
 
@@ -2211,8 +2214,8 @@ declare class Animation extends TimelineNode {
2211
2214
  protected _cachedProps: RawWeakMap<any, Map<string, any>>;
2212
2215
  protected _stoped: boolean;
2213
2216
  constructor(properties?: Partial<AnimationProperties>, children?: Node[]);
2214
- protected _treeEnter(_tree: SceneTree): void;
2215
- protected _treeExit(_oldTree: SceneTree): void;
2217
+ protected _parented(parent: Node): void;
2218
+ protected _unparented(oldParent: Node): void;
2216
2219
  protected _process(): void;
2217
2220
  protected _updateProperty(key: PropertyKey, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
2218
2221
  protected _getTargets(): any[];
package/dist/index.js CHANGED
@@ -110,7 +110,7 @@ uniform sampler2D sampler;
110
110
  uniform vec4 tint;
111
111
  void main(void) {
112
112
  gl_FragColor = texture2D(sampler, vUv) * tint;
113
- }`,uniforms:{sampler:0,projectionMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),modelViewMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),tint:new Float32Array([1,1,1,1])}})}}c(kA,"_instance");class fe extends $i{static get instance(){return this._instance??(this._instance=new this)}static draw(A,e=kA.instance,t){this.instance.draw(A,e,t)}constructor(){super({vertexAttributes:{position:new lt({buffer:new Kt({data:new Float32Array([-1,-1,1,-1,1,1,-1,1]),dynamic:!1}),size:2,normalized:!1,type:"float"}),uv:new lt({buffer:new Kt({data:new Float32Array([0,0,1,0,1,1,0,1]),dynamic:!1}),size:2,normalized:!1,type:"float"})},indexBuffer:new RA({data:new Uint16Array([0,1,2,0,2,3]),dynamic:!1})})}}c(fe,"_instance");class Rg extends $i{constructor(){const e=new Kt({data:new Float32Array,dynamic:!0}),t=new Kt({data:new Float32Array,dynamic:!0});super({vertexAttributes:{position:new lt({buffer:e,size:2,normalized:!1,type:"float"}),uv:new lt({buffer:t,size:2,normalized:!1,type:"float"})},indexBuffer:new RA({data:new Uint16Array,dynamic:!0})});c(this,"positionBuffer");c(this,"uvBuffer");this.positionBuffer=e,this.uvBuffer=t}}var kg=Object.defineProperty,UA=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&kg(A,e,i),i};class ve extends Ht{constructor(e){super();c(this,"_isPowerOfTwo",!1);c(this,"_needsUpload",!1);this.source=e,this._updateSize()}static get EMPTY(){return new this({width:1,height:1,pixels:null})}static get WHITE(){return new this({width:1,height:1,pixels:new Uint8Array([255,255,255,255])})}static get BLACK(){return new this({width:1,height:1,pixels:new Uint8Array([0,0,0,255])})}static get RED(){return new this({width:1,height:1,pixels:new Uint8Array([255,0,0,255])})}static get GREEN(){return new this({width:1,height:1,pixels:new Uint8Array([0,255,0,255])})}static get BLUE(){return new this({width:1,height:1,pixels:new Uint8Array([0,0,255,255])})}get valid(){return!!(this.width&&this.height)}get realWidth(){return Math.round(this.width*this.pixelRatio)}get realHeight(){return Math.round(this.height*this.pixelRatio)}_glTextureOptions(e,t){let i=this.wrapMode;return e.version===1&&!this._isPowerOfTwo&&(i="clamp_to_edge"),{value:this.source,target:"texture_2d",location:0,filterMode:this.filterMode,wrapMode:i,...t}}_glTexture(e,t){return e.getRelated(this,()=>e.texture.create(this._glTextureOptions(e,t)))}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"width":case"height":this._updatePOT();break;case"source":this._updateSize();break;case"filterMode":case"wrapMode":case"pixelRatio":this.requestUpload();break}}_updatePOT(){this._isPowerOfTwo=es(this.realWidth)&&es(this.realHeight),this.requestUpload()}_updateSize(){const e=this.source;"pixels"in e?(this.width=e.width/this.pixelRatio,this.height=e.height/this.pixelRatio):(this.width=Number(e.naturalWidth||e.videoWidth||e.width||0)/this.pixelRatio,this.height=Number(e.naturalHeight||e.videoHeight||e.height||0)/this.pixelRatio),this.requestUpload()}requestUpload(){this._needsUpload=!0}upload(e,t){return this._needsUpload&&this.valid?(this._needsUpload=!1,e.texture.update(this._glTexture(e,t),this._glTextureOptions(e,t)),!0):!1}activate(e,t=0){return this.valid?(e.texture.bind({target:"texture_2d",value:this._glTexture(e,{location:t}),location:t}),this.upload(e,{location:t}),!0):!1}inactivate(e){e.texture.unbind(this._glTexture(e))}free(){Gn&&this.source instanceof ImageBitmap&&this.source.close()}}UA([Ee()],ve.prototype,"source"),UA([U({default:0})],ve.prototype,"width"),UA([U({default:0})],ve.prototype,"height"),UA([U({default:"linear"})],ve.prototype,"filterMode"),UA([U({default:"clamp_to_edge"})],ve.prototype,"wrapMode"),UA([U({default:1})],ve.prototype,"pixelRatio");class tr extends Ht{constructor(e){super();c(this,"frames");let t;if(Array.isArray(e))t=e;else if(e instanceof ve)t=[{texture:e,duration:0}];else throw new TypeError("Failed new AnimatedTexture");this.frames=t,this.updateDuration()}updateDuration(){return this.duration=this.frames.reduce((e,t)=>t.duration+e,0),this}free(){this.frames.forEach(e=>{e.texture.free()})}}var Ug=Object.defineProperty,Pg=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&Ug(A,e,i),i};class gi extends ve{constructor(A=document.createElement("canvas")){super(A)}_updateProperty(A,e,t,i){switch(A){case"width":this.source.width=Math.max(1,Math.ceil(e*this.pixelRatio));break;case"height":this.source.height=Math.max(1,Math.ceil(e*this.pixelRatio));break}super._updateProperty(A,e,t,i)}}Pg([U({default:2})],gi.prototype,"pixelRatio");class Cs extends ve{constructor(A){const e=new Zt(A);super({width:1,height:1,pixels:new Uint8Array([e.r8,e.g8,e.b8,e.a8])})}}function Ng(r){return{autoLoad:!!((r==null?void 0:r.autoLoad)??!0),useBitmap:!!((r==null?void 0:r.useBitmap)??!0)&&As,crossorigin:(r==null?void 0:r.crossorigin)??null}}class Fg extends ve{constructor(e,t){const i=Ng(t);super(e);c(this,"bitmap");c(this,"useBitmap");c(this,"preserveBitmap",!1);c(this,"_loadSource");c(this,"_loadBitmap");const s=e.src,n=s.includes(".svg")||s.startsWith("data:image/svg+xml");this.useBitmap=i.useBitmap&&!n,i.autoLoad&&this.load()}async load(){return this._loadSource||(this._loadSource=new Promise(e=>{this._loadSource=void 0;const t=this.source,i=()=>{t.onload=null,t.onerror=null},s=()=>{i(),this.requestUpload(),this.useBitmap?this.genBitmap().finally(()=>e(this)):e(this)},n=o=>{i(),console.warn(`Failed to load ImageTexture, src: ${t.src}`,o),this.emit("error",o),e(this)};t.complete&&t.src?s():(t.onload=s,t.onerror=n)})),this._loadSource}genBitmap(){if(this._loadBitmap)return this._loadBitmap;if(this.bitmap||!As)return Promise.resolve(this);const e=this.source,t=!e.crossOrigin||e.crossOrigin==="anonymous";return this._loadBitmap=fetch(e.src,{mode:t?"cors":"no-cors"}).then(i=>i.blob()).then(i=>createImageBitmap(i,0,0,e.width,e.height,{premultiplyAlpha:"premultiply"})).then(i=>(this.bitmap=i,this.requestUpload(),this._loadBitmap=void 0,this)).catch(i=>(console.warn("Failed to genBitmap",i),this)),this._loadBitmap}_glTextureOptions(e){return{...super._glTextureOptions(e),value:this.bitmap??this.source}}upload(e){if(this.useBitmap){if(!this.bitmap)return this.genBitmap(),!1}else{const i=this.source;if(ni&&i instanceof HTMLImageElement&&(!i.complete||i.naturalWidth===0))return!1}const t=super.upload(e);return this.preserveBitmap&&this.bitmap&&(this.bitmap.close(),this.bitmap=void 0),t}}class Qs extends ve{constructor(A,e=1,t=1){const i={width:e,height:t,pixels:null};A&&(ArrayBuffer.isView(A)?i.pixels=new Uint8Array(A.buffer):i.pixels=new Uint8Array(A)),super(i)}_updateProperty(A,e,t,i){switch(A){case"width":this.source.width=Math.round(e*this.pixelRatio);break;case"height":this.source.height=Math.round(e*this.pixelRatio);break}super._updateProperty(A,e,t,i)}}var Tg=Object.defineProperty,Lo=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&Tg(A,e,i),i};function Lg(r){return{autoLoad:!!((r==null?void 0:r.autoLoad)??!0),autoPlay:!!((r==null?void 0:r.autoPlay)??!1),fps:Number((r==null?void 0:r.fps)??0),crossorigin:(r==null?void 0:r.crossorigin)??null,loop:!!((r==null?void 0:r.loop)??!1),muted:!!((r==null?void 0:r.muted)??!1),playsinline:!!((r==null?void 0:r.playsinline)??!0)}}const ys=(DA=class extends ve{constructor(e,t){const i=Lg(t);if(!Wn(e)){typeof e=="string"&&(e=[e]);const s=e[0].src||e[0],n=document.createElement("video");i.autoLoad&&n.setAttribute("preload","auto"),i.playsinline&&(n.setAttribute("webkit-playsinline",""),n.setAttribute("playsinline","")),i.muted&&(n.setAttribute("muted",""),n.muted=!0),i.loop&&n.setAttribute("loop",""),i.autoPlay&&n.setAttribute("autoplay",""),jn(n,s,i.crossorigin);for(let o=0;o<e.length;++o){let{src:a,mime:l}=e[o];if(a=a||e[o],a.startsWith("data:"))l=a.slice(5,a.indexOf(";"));else if(!a.startsWith("blob:")){const h=a.split("?").shift().toLowerCase(),f=h.slice(h.lastIndexOf(".")+1);l=l||DA.mimeTypes.get(f)||`video/${f}`}const g=document.createElement("source");g.src=a,l&&(g.type=l),n.appendChild(g)}e=n}super(e);c(this,"_spf",0);c(this,"_autoPlay",!1);c(this,"_sourceLoad");c(this,"_nextTime",0);c(this,"_connected",!1);c(this,"_requestId");c(this,"_resolve");c(this,"_reject");c(this,"_onPlayStart",()=>{this.valid||this._onCanPlay(),this._setupAutoUpdate()});c(this,"_onPlayStop",()=>{this._setupAutoUpdate()});c(this,"_onCanPlay",()=>{const e=this.source;e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlay);const t=this.valid;this._nextTime=0,this._updateSize(),this.requestUpload(),this._nextTime=0,!t&&this._resolve&&(this._resolve(this),this._sourceLoad=void 0,this._resolve=void 0,this._reject=void 0),this.isPlaying?this._onPlayStart():this._autoPlay&&e.play()});c(this,"_onError",e=>{this.source.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=void 0,this._resolve=void 0)});c(this,"_onSeeked",()=>{this.autoUpdate&&!this.isPlaying&&(this._nextTime=0,this.requestUpload(),this._nextTime=0)});c(this,"_videoFrameRequestCallback",()=>{this.requestUpload(),this._requestId=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)});c(this,"requestUpload",()=>{const e=Math.floor(xe.elapsed*this.source.playbackRate);this._nextTime-=e,(!this._spf||this._nextTime<=0)&&(super.requestUpload(),this._nextTime=this._spf||0)});this.fps=i.fps,this._autoPlay=i.autoPlay,i.autoPlay&&this.load(),this._setupAutoUpdate()}get isReady(){return this.source.readyState>2}get isPlaying(){return!this.source.paused&&!this.source.ended&&this.isReady}get duration(){return this.source.duration}get seeking(){return this.source.seeking}get currentTime(){return this.source.currentTime}set currentTime(e){this.source.currentTime=e}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"fps":this._spf=t?Math.floor(1e3/t):0,this._setupAutoUpdate();break;case"autoUpdate":this._setupAutoUpdate();break}}_setupAutoUpdate(){this.autoUpdate&&this.isPlaying?!this.fps&&this.source.requestVideoFrameCallback?(this._connected&&(xe.off(this.requestUpload),this._connected=!1,this._nextTime=0),this._requestId===void 0&&(this._requestId=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._requestId!==void 0&&(this.source.cancelVideoFrameCallback(this._requestId),this._requestId=void 0),this._connected||(xe.on(this.requestUpload),this._connected=!0,this._nextTime=0)):(this._requestId!==void 0&&(this.source.cancelVideoFrameCallback(this._requestId),this._requestId=void 0),this._connected&&(xe.off(this.requestUpload),this._connected=!1,this._nextTime=0))}async load(){if(!this._sourceLoad){const e=this.source;(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.isReady?this._onCanPlay():(e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlay),e.addEventListener("error",this._onError,!0)),this._sourceLoad=new Promise((t,i)=>{this.valid?(this._sourceLoad=void 0,t(this)):(this._resolve=t,this._reject=i,e.load())})}return this._sourceLoad}free(){this._setupAutoUpdate();const e=this.source;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._onCanPlay),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load())}},c(DA,"mimeTypes",new Map(Object.entries({ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"}))),DA);Lo([Ee({default:!0})],ys.prototype,"autoUpdate"),Lo([Ee({default:0})],ys.prototype,"fps");let Go=ys;class ms extends Qs{}var Gg=Object.defineProperty,Og=Object.getOwnPropertyDescriptor,BA=(r,A,e,t)=>{for(var i=t>1?void 0:t?Og(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Gg(A,e,i),i};const Oo={};function Hg(r){let A=Oo[r]??0;return A++,Oo[r]=A,A}u.Node=class extends qi{constructor(e,t=[]){super();c(this,"_readyed",!1);c(this,"_tree");c(this,"_parent");c(this,"_children",[]);c(this,"_meta",new Map);this._onTreeEnter=this._onTreeEnter.bind(this),this._onTreeExit=this._onTreeExit.bind(this),this._onParented=this._onParented.bind(this),this._onUnparented=this._onUnparented.bind(this),this._onReady=this._onReady.bind(this),this._onProcess=this._onProcess.bind(this),this.setProperties({name:`${this.tag}:${Hg(this.tag)}`,...e}).append(t),this.on("treeEnter",this._onTreeEnter).on("treeExit",this._onTreeExit).on("parented",this._onParented).on("unparented",this._onUnparented).on("ready",this._onReady).on("process",this._onProcess)}getName(){return this.name}setName(e){return this.name=e,this}get tree(){return this.getTree()}set tree(e){this.setTree(e)}getTree(){return this._tree}getViewport(){var e;return(e=this._tree)==null?void 0:e.getCurrentViewport()}getWindow(){var e;return(e=this._tree)==null?void 0:e.root}isInsideTree(){return!!this._tree}setTree(e){const t=this._tree;if(!(e!=null&&e.is(t))){t&&this.emit("treeExit",t),this._tree=e,e&&this.emit("treeEnter",e);for(let i=this._children.length,s=0;s<i;s++){const n=this._children[s];!e&&this.emit("childExitingTree",n),n.setTree(e),e&&this.emit("childEnteredTree",n)}e&&(this.emit("treePostEnter",e),this._readyed||(this._readyed=!0,this.emit("ready")))}return this}get parent(){return this._parent}set parent(e){this.setParent(e)}hasParent(){return!!this._parent}getParent(){return this._parent}setParent(e){var t;if(!((t=this._parent)!=null&&t.is(e))){const i=this._parent;this._parent=e,this.setTree(e==null?void 0:e._tree),e?this.emit("parented",e):i&&this.emit("unparented",i)}return this}get siblingIndex(){return this.getIndex()}set siblingIndex(e){var t;(t=this._parent)==null||t.moveChild(this,e)}get previousSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[this.getIndex()-1]}get nextSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[this.getIndex()+1]}get firstSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[0]}get lastSibling(){var t;const e=(t=this._parent)==null?void 0:t.getChildren();return e?e[e.length-1]:void 0}hasMeta(e){return this._meta.has(e)}getMeta(e,t){return this._meta.get(e)??t}setMeta(e,t){this._meta.set(e,t)}deleteMeta(e){this._meta.delete(e)}clearMeta(){this._meta.clear()}canProcess(){var e;if(!this._tree)return!1;switch(this.processMode){case"inherit":return((e=this._parent)==null?void 0:e.canProcess())??!0;case"pausable":return!this._tree.processPaused;case"when_paused":return this._tree.processPaused;case"always":return!0;case"disabled":default:return!1}}canRender(){var e;if(!this._tree)return!1;switch(this.renderMode){case"inherit":return((e=this._parent)==null?void 0:e.canRender())??!0;case"always":return!0;case"disabled":default:return!1}}_update(e){var t;(t=this._tree)==null||t.log(this.name,"updating"),super._update(e)}_updateProperty(e,t,i,s){var n;(n=this._tree)==null||n.log(this.name,`updating [${String(e)}]`),super._updateProperty(e,t,i,s)}_onTreeEnter(e){this._treeEnter(e),this.emit("treeEntered",e)}_onTreeExit(e){this.emit("treeExiting",e),this._treeExit(e),this.emit("treeExited",e)}_onParented(e){this._parented(e)}_onUnparented(e){this._unparented(e)}_onReady(){this._ready()}_onProcess(e=0){const t=this._tree,i=this.canRender(),s=this.canProcess(),n=[],o=[];for(let l=this._children.length,g=0;g<l;g++){const h=this._children[g];switch(h.processSortMode){case"default":o.push(h);break;case"parent_before":n.push(h);break}}n.forEach(l=>{l.emit("process",e)}),s&&(t==null||t.emit("nodeProcessing",this),this.emit("processing",e),this._process(e));let a;if(i){const l=t.renderStack.push(this);a=t.renderStack.currentCall,t.renderStack.currentCall=l}if(this.mask instanceof u.Node)this.getNode("__$mask")||(this.mask.processMode="disabled",this.appendChild(this.mask,"front"));else{const l=this.getNode("__$mask");l&&this.removeChild(l)}o.forEach(l=>{l.emit("process",e)}),i&&(t.renderStack.currentCall=a),s&&(this.emit("processed",e),t==null||t.emit("nodeProcessed",this))}render(e,t){const i=this.mask;i&&(e.flush(),e.mask.push(this,i)),this._render(e),t==null||t(),i&&(e.flush(),e.mask.pop(this))}input(e,t){for(let i=this._children.length-1;i>=0;i--)this._children[i].input(e,t);this._input(e,t)}getChildren(e=!1){switch(e){case!0:return this._children;case!1:return this._children.filter(t=>t.internalMode==="default");default:return this._children.filter(t=>t.internalMode===e)}}getIndex(e=!1){var t;return((t=this._parent)==null?void 0:t.getChildren(e).indexOf(this))??0}getNode(e){return this._children.find(t=>t.name===e)}removeNode(e){var t;(t=this.getNode(e))==null||t.remove()}addSibling(e){return this.is(e)||!this.hasParent()||e.hasParent()?this:(e.internalMode=this.internalMode,this._parent.moveChild(e,this.getIndex(!0)+1),this)}prepend(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{this.moveChild(i,0)})}append(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{this.appendChild(i)})}before(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{var s;(s=this._parent)==null||s.moveChild(i,this.getIndex(!0))})}after(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{var s;(s=this._parent)==null||s.moveChild(i,this.getIndex(!0)+1)})}insertBefore(e,t){return!t.hasParent()||!this.is(t.parent)||this.moveChild(e,t.getIndex(!0)),e}appendChild(e,t=e.internalMode){if(this.is(e)||e.hasParent())return e;switch(t){case"default":case"front":{const i=t==="default"?"back":"front",s=this._children.findIndex(n=>n.internalMode===i);s>-1?this._children.splice(s,0,e):this._children.push(e);break}case"back":this._children.push(e);break}return e.internalMode=t,e.setParent(this),this.emit("appendChild",e),e}moveChild(e,t,i=e.internalMode){if(this.is(e)||e.hasParent()&&!this.is(e.parent))return this;e.internalMode=i;const s=this._children.indexOf(e);let n=this._children.findIndex(l=>{switch(i){case"default":return l.internalMode!=="front";case"back":return l.internalMode==="back";case"front":default:return!0}});n=n>-1?n:Math.max(0,this._children.length-1);let o=this._children.slice(n).findIndex(l=>{switch(i){case"front":return l.internalMode!=="front";case"default":return l.internalMode==="back";case"back":default:return!1}});o=o>-1?n+o:Math.max(0,this._children.length);const a=bt(n,t>-1?t:o,o);return a!==s&&(s>-1&&this._children.splice(s,1),e.setParent(this),a>-1&&a<this._children.length?this._children.splice(a,0,e):this._children.push(e),s>-1?this.emit("moveChild",e,a,s):this.emit("appendChild",e)),this}removeChild(e){const t=e.getIndex(!0);return this.is(e.parent)&&t>-1&&(this._children.splice(t,1),e.setParent(void 0),this.emit("removeChild",e,t)),e}removeChildren(){this.getChildren().forEach(e=>this.removeChild(e))}remove(){var e;(e=this._parent)==null||e.removeChild(this)}forEach(e){return this.getChildren().forEach(e),this}deepForEach(e){return this.getChildren().forEach(t=>{e(t),t.deepForEach(e)}),this}_ready(){}_treeEnter(e){}_treeExit(e){}_parented(e){}_unparented(e){}_process(e){}_input(e,t){}_render(e){}clone(){return new this.constructor(this.toJSON().props,this.getChildren(!0))}toJSON(){return{tag:this.tag,props:{name:this.name,...super.toJSON()},meta:Object.fromEntries(this._meta.entries()),children:this.getChildren().map(e=>e.toJSON())}}static parse(e){if(Array.isArray(e))return e.map(a=>this.parse(a));const{tag:t,props:i,children:s}=e,n=zi.get(t)??u.Node,o=new n(i);return s==null||s.forEach(a=>o.appendChild(this.parse(a))),o}},BA([Ee()],u.Node.prototype,"name",2),BA([U()],u.Node.prototype,"mask",2),BA([U({default:"inherit"})],u.Node.prototype,"processMode",2),BA([U({default:"default"})],u.Node.prototype,"processSortMode",2),BA([U({default:"inherit"})],u.Node.prototype,"renderMode",2),BA([U({default:"default"})],u.Node.prototype,"internalMode",2),u.Node=BA([re("Node")],u.Node);var Jg=Object.defineProperty,Kg=Object.getOwnPropertyDescriptor,hi=(r,A,e,t)=>{for(var i=t>1?void 0:t?Kg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Jg(A,e,i),i};u.TimelineNode=class extends u.Node{constructor(e,t=[]){super();c(this,"computedDuration",0);c(this,"_currentTime",0);c(this,"_startTime",0);this.setProperties(e).append(t)}get timeline(){var e;return(e=this._tree)==null?void 0:e.timeline}get timelineCurrentTime(){var e;return((e=this.timeline)==null?void 0:e.currentTime)??0}get parentStartTime(){var e;return((e=this._parent)==null?void 0:e.startTime)??0}get currentTime(){return bt(0,this._currentTime,this.computedDuration)}get startTime(){return this._startTime}set startTime(e){this.delay=e-this.parentStartTime,this._updateCurrentTime(!0)}get endTime(){return this._startTime+this.computedDuration}get currentTimeProgress(){return this.computedDuration?bt(0,this._currentTime/this.computedDuration,1):0}isInsideTimeRange(){const e=this._currentTime;return this.computedDuration?e>=0&&e<=this.computedDuration:e>=0}_updateCurrentTime(e=!1){if(e||!this.paused){const t=this._parent;this._startTime=this.delay+this.parentStartTime,this.computedDuration=t!=null&&t.computedDuration?Math.min(this._startTime+this.duration,t.endTime)-this._startTime:this.duration,this._currentTime=this.timelineCurrentTime-this._startTime,this.emit("updateCurrentTime",this._currentTime),this.insideTimeRange=this.isInsideTimeRange()}}_process(e){super._process(e),this._updateCurrentTime()}},hi([U({default:0})],u.TimelineNode.prototype,"delay",2),hi([U({default:0})],u.TimelineNode.prototype,"duration",2),hi([U({default:!1})],u.TimelineNode.prototype,"paused",2),hi([Ee()],u.TimelineNode.prototype,"insideTimeRange",2),u.TimelineNode=hi([re("TimelineNode")],u.TimelineNode);var Yg=Object.defineProperty,Wg=Object.getOwnPropertyDescriptor,ci=(r,A,e,t)=>{for(var i=t>1?void 0:t?Wg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Yg(A,e,i),i};u.Viewport=class extends u.Node{constructor(e=!1){super();c(this,"_projection",new Io);c(this,"_framebufferIndex",0);c(this,"_framebuffers",[{texture:new ms,needsUpload:!1},{texture:new ms,needsUpload:!1}]);this.flipY=e,this._projection.flipY(e)}get valid(){return!!(this.width&&this.height)}get framebuffer(){return this._framebuffers[this._framebufferIndex]}get texture(){return this.framebuffer.texture}_glFramebufferOptions(e){const{width:t,height:i}=this,{pixelRatio:s}=e;return this._framebuffers.forEach(n=>{const o=n.texture;o.pixelRatio=s,o.width=t,o.height=i,o.upload(e)}),{width:t,height:i,colorTextures:[this.texture._glTexture(e)]}}_glFramebuffer(e){return e.getRelated(this.framebuffer,()=>e.framebuffer.create(this._glFramebufferOptions(e)))}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"x":case"y":this.requestUpload(),this._projection.translate(this.x,this.y),this.emit("updateRect");break;case"width":case"height":this.requestUpload(),this._projection.resize(this.width,this.height),this.emit("updateRect");break}}requestUpload(){this._framebuffers.forEach(e=>e.needsUpload=!0)}resize(e,t){this.width=e,this.height=t}upload(e){const t=this.framebuffer;return t.needsUpload&&this.valid?(t.needsUpload=!1,e.framebuffer.update(this._glFramebuffer(e),this._glFramebufferOptions(e)),!0):!1}activate(e){var t;return this.valid?(e.flush(),(t=this._tree)==null||t.setCurrentViewport(this),this.upload(e),e.framebuffer.bind(this._glFramebuffer(e)),!0):!1}redraw(e,t){if(this.valid){e.flush();const i=this.framebuffer.texture;return this._framebufferIndex=(this._framebufferIndex+1)%this._framebuffers.length,this.activate(e),e.clear(),i.activate(e,0),t(),!0}return!1}activateWithCopy(e,t){this.resize(t.width,t.height),this.activate(e)&&(e.clear(),t.texture.activate(e,0),fe.draw(e,kA.instance,{sampler:0}))}render(e,t){var s,n;const i=(s=this._tree)==null?void 0:s.getCurrentViewport();this.activate(e),e.clear(),super.render(e,t),e.flush(),i?i.activate(e):(e.framebuffer.bind(null),(n=this._tree)==null||n.setCurrentViewport(void 0))}getRect(){return new Bs(this.x,this.y,this.width,this.height)}toProjectionArray(e=!1){return this._projection.toArray(e)}},ci([U({default:0})],u.Viewport.prototype,"x",2),ci([U({default:0})],u.Viewport.prototype,"y",2),ci([U({default:0})],u.Viewport.prototype,"width",2),ci([U({default:0})],u.Viewport.prototype,"height",2),u.Viewport=ci([re("Viewport")],u.Viewport);var Vg=Object.defineProperty,zg=Object.getOwnPropertyDescriptor,ui=(r,A,e,t)=>{for(var i=t>1?void 0:t?zg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Vg(A,e,i),i};u.Effect=class extends u.TimelineNode{constructor(e,t=[]){super();c(this,"viewport1",new u.Viewport);c(this,"viewport2",new u.Viewport);c(this,"_renderId",0);c(this,"_renderViewport");c(this,"_previousSibling");c(this,"_nextSibling");this._onProcessing=this._onProcessing.bind(this),this._onNodeProcessed=this._onNodeProcessed.bind(this),this.setProperties(e).append(t)}get _effectMode(){return this.effectMode??"parent"}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"glsl":{const n=new er(t);!this.effectMode&&n.has.transition&&(this.effectMode="transition"),this.material=n;break}case"glslSrc":{t?Nt.text.load(t).then(n=>this.glsl=n):this.glsl="";break}}}_treeEnter(e){e.on("processing",this._onProcessing),e.on("nodeProcessed",this._onNodeProcessed),this.viewport1.setTree(e),this.viewport2.setTree(e)}_treeExit(e){e.off("processing",this._onProcessing),e.off("nodeProcessed",this._onNodeProcessed),this.viewport1.setTree(void 0),this.viewport2.setTree(void 0)}_onProcessing(){if(this.canProcess())switch(this._updateCurrentTime(),this._effectMode){case"transition":this._previousSibling=this.previousSibling,this._nextSibling=this.nextSibling;break;default:this._previousSibling=void 0,this._nextSibling=void 0;break}}_onNodeProcessed(e){var i;if(!this.canProcess()||!this.isInsideTimeRange())return;const t=(i=this._tree)==null?void 0:i.renderStack;if(t)switch(this._effectMode){case"transition":e.is(this._previousSibling)?(this._previousSibling=void 0,t.push(this)):e.is(this._nextSibling)&&(this._nextSibling=void 0,t.push(this));break}}_processParent(){var o,a;const e=(o=this._tree)==null?void 0:o.renderStack;if(!e)return;const t=(a=e.currentCall)==null?void 0:a.parentCall;if(!t)return;const i=t.calls;let s,n;i.forEach((l,g)=>{var h;(l.renderable.is(this._parent)||(h=l.renderable.parent)!=null&&h.is(this._parent))&&(s=s??g,n=g)}),!(s===void 0||n===void 0)&&(i.splice(n+1,0,e.createCall(this)),i.splice(s,0,e.createCall(this)))}_processChildren(){var e;this._children.length&&(super.emit("process"),(e=this._tree)==null||e.renderStack.push(this))}_onProcess(e=0){if(this.canProcess())switch(this._renderId=0,this._effectMode){case"before":super._onProcess(e);break;case"parent":this._processParent();break;case"children":this._processChildren();break}}_renderBefore(e){var i;const t=(i=this._tree)==null?void 0:i.getCurrentViewport();t&&this.apply(e,t,{redraw:!0})}_renderTransition(e){var t;if(this._renderId%2===0)this._renderViewport=(t=this._tree)==null?void 0:t.getCurrentViewport(),this._renderViewport&&(this.viewport1.activateWithCopy(e,this._renderViewport),this.viewport2.resize(this._renderViewport.width,this._renderViewport.height)),this.viewport2.activate(e),e.clear();else{const i=this._renderViewport;this._renderViewport=void 0,i&&(i.activate(e),e.clear(),this.viewport1.texture.activate(e,0),this.viewport2.texture.activate(e,1),this.apply(e,i,{from:this.viewport1,to:this.viewport2}),e.texture.unbind(0),e.texture.unbind(1))}}_renderParentOrChildren(e){var t;if(this._renderId%2===0)this._renderViewport=(t=this._tree)==null?void 0:t.getCurrentViewport(),this._renderViewport&&this.viewport1.resize(this._renderViewport.width,this._renderViewport.height),this.viewport1.activate(e),e.clear();else{const i=this._renderViewport;this._renderViewport=void 0,i&&(this.viewport1.activate(e),this.apply(e,this.viewport1,{redraw:!0,target:this._effectMode==="parent"?this._parent??void 0:void 0,targetArea:this._parseTargetArea()}),i.activate(e),this.viewport1.texture.activate(e,0),fe.draw(e))}}_parseTargetArea(){if(this._effectMode==="parent"&&this._parent&&"getRect"in this._parent){const e=this._parent.getRect();if(e)return[e.left/this.viewport1.width,e.top/this.viewport1.height,e.width/this.viewport1.width,e.height/this.viewport1.height]}}_render(e){switch(this._effectMode){case"before":this._renderBefore(e);break;case"transition":this._renderTransition(e);break;case"parent":case"children":default:this._renderParentOrChildren(e);break}this._renderId++}apply(e,t,i){this.material&&(i!=null&&i.redraw?t.redraw(e,()=>{fe.draw(e,this.material,{from:0,to:1,progress:this.currentTimeProgress,ratio:t.width/t.height})}):fe.draw(e,this.material,{from:0,to:1,progress:this.currentTimeProgress,ratio:i!=null&&i.from?i.from.width/i.from.height:0}))}},ui([Ee()],u.Effect.prototype,"material",2),ui([U()],u.Effect.prototype,"effectMode",2),ui([U({default:""})],u.Effect.prototype,"glsl",2),ui([U({default:""})],u.Effect.prototype,"glslSrc",2),u.Effect=ui([re("Effect")],u.Effect);var Ho=Object.defineProperty,qg=Object.getOwnPropertyDescriptor,Xg=(r,A,e)=>A in r?Ho(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,ws=(r,A,e,t)=>{for(var i=t>1?void 0:t?qg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Ho(A,e,i),i},Jo=(r,A,e)=>Xg(r,typeof A!="symbol"?A+"":A,e);const jg=`attribute vec2 position;
113
+ }`,uniforms:{sampler:0,projectionMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),modelViewMatrix:new Float32Array([1,0,0,0,1,0,0,0,1]),tint:new Float32Array([1,1,1,1])}})}}c(kA,"_instance");class fe extends $i{static get instance(){return this._instance??(this._instance=new this)}static draw(A,e=kA.instance,t){this.instance.draw(A,e,t)}constructor(){super({vertexAttributes:{position:new lt({buffer:new Kt({data:new Float32Array([-1,-1,1,-1,1,1,-1,1]),dynamic:!1}),size:2,normalized:!1,type:"float"}),uv:new lt({buffer:new Kt({data:new Float32Array([0,0,1,0,1,1,0,1]),dynamic:!1}),size:2,normalized:!1,type:"float"})},indexBuffer:new RA({data:new Uint16Array([0,1,2,0,2,3]),dynamic:!1})})}}c(fe,"_instance");class Rg extends $i{constructor(){const e=new Kt({data:new Float32Array,dynamic:!0}),t=new Kt({data:new Float32Array,dynamic:!0});super({vertexAttributes:{position:new lt({buffer:e,size:2,normalized:!1,type:"float"}),uv:new lt({buffer:t,size:2,normalized:!1,type:"float"})},indexBuffer:new RA({data:new Uint16Array,dynamic:!0})});c(this,"positionBuffer");c(this,"uvBuffer");this.positionBuffer=e,this.uvBuffer=t}}var kg=Object.defineProperty,UA=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&kg(A,e,i),i};class ve extends Ht{constructor(e){super();c(this,"_isPowerOfTwo",!1);c(this,"_needsUpload",!1);this.source=e,this._updateSize()}static get EMPTY(){return new this({width:1,height:1,pixels:null})}static get WHITE(){return new this({width:1,height:1,pixels:new Uint8Array([255,255,255,255])})}static get BLACK(){return new this({width:1,height:1,pixels:new Uint8Array([0,0,0,255])})}static get RED(){return new this({width:1,height:1,pixels:new Uint8Array([255,0,0,255])})}static get GREEN(){return new this({width:1,height:1,pixels:new Uint8Array([0,255,0,255])})}static get BLUE(){return new this({width:1,height:1,pixels:new Uint8Array([0,0,255,255])})}get valid(){return!!(this.width&&this.height)}get realWidth(){return Math.round(this.width*this.pixelRatio)}get realHeight(){return Math.round(this.height*this.pixelRatio)}_glTextureOptions(e,t){let i=this.wrapMode;return e.version===1&&!this._isPowerOfTwo&&(i="clamp_to_edge"),{value:this.source,target:"texture_2d",location:0,filterMode:this.filterMode,wrapMode:i,...t}}_glTexture(e,t){return e.getRelated(this,()=>e.texture.create(this._glTextureOptions(e,t)))}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"width":case"height":this._updatePOT();break;case"source":this._updateSize();break;case"filterMode":case"wrapMode":case"pixelRatio":this.requestUpload();break}}_updatePOT(){this._isPowerOfTwo=es(this.realWidth)&&es(this.realHeight),this.requestUpload()}_updateSize(){const e=this.source;"pixels"in e?(this.width=e.width/this.pixelRatio,this.height=e.height/this.pixelRatio):(this.width=Number(e.naturalWidth||e.videoWidth||e.width||0)/this.pixelRatio,this.height=Number(e.naturalHeight||e.videoHeight||e.height||0)/this.pixelRatio),this.requestUpload()}requestUpload(){this._needsUpload=!0}upload(e,t){return this._needsUpload&&this.valid?(this._needsUpload=!1,e.texture.update(this._glTexture(e,t),this._glTextureOptions(e,t)),!0):!1}activate(e,t=0){return this.valid?(e.texture.bind({target:"texture_2d",value:this._glTexture(e,{location:t}),location:t}),this.upload(e,{location:t}),!0):!1}inactivate(e){e.texture.unbind(this._glTexture(e))}free(){Gn&&this.source instanceof ImageBitmap&&this.source.close()}}UA([Ee()],ve.prototype,"source"),UA([U({default:0})],ve.prototype,"width"),UA([U({default:0})],ve.prototype,"height"),UA([U({default:"linear"})],ve.prototype,"filterMode"),UA([U({default:"clamp_to_edge"})],ve.prototype,"wrapMode"),UA([U({default:1})],ve.prototype,"pixelRatio");class tr extends Ht{constructor(e){super();c(this,"frames");let t;if(Array.isArray(e))t=e;else if(e instanceof ve)t=[{texture:e,duration:0}];else throw new TypeError("Failed new AnimatedTexture");this.frames=t,this.updateDuration()}updateDuration(){return this.duration=this.frames.reduce((e,t)=>t.duration+e,0),this}free(){this.frames.forEach(e=>{e.texture.free()})}}var Ug=Object.defineProperty,Pg=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&Ug(A,e,i),i};class gi extends ve{constructor(A=document.createElement("canvas")){super(A)}_updateProperty(A,e,t,i){switch(A){case"width":this.source.width=Math.max(1,Math.ceil(e*this.pixelRatio));break;case"height":this.source.height=Math.max(1,Math.ceil(e*this.pixelRatio));break}super._updateProperty(A,e,t,i)}}Pg([U({default:2})],gi.prototype,"pixelRatio");class Cs extends ve{constructor(A){const e=new Zt(A);super({width:1,height:1,pixels:new Uint8Array([e.r8,e.g8,e.b8,e.a8])})}}function Ng(r){return{autoLoad:!!((r==null?void 0:r.autoLoad)??!0),useBitmap:!!((r==null?void 0:r.useBitmap)??!0)&&As,crossorigin:(r==null?void 0:r.crossorigin)??null}}class Fg extends ve{constructor(e,t){const i=Ng(t);super(e);c(this,"bitmap");c(this,"useBitmap");c(this,"preserveBitmap",!1);c(this,"_loadSource");c(this,"_loadBitmap");const s=e.src,n=s.includes(".svg")||s.startsWith("data:image/svg+xml");this.useBitmap=i.useBitmap&&!n,i.autoLoad&&this.load()}async load(){return this._loadSource||(this._loadSource=new Promise(e=>{this._loadSource=void 0;const t=this.source,i=()=>{t.onload=null,t.onerror=null},s=()=>{i(),this.requestUpload(),this.useBitmap?this.genBitmap().finally(()=>e(this)):e(this)},n=o=>{i(),console.warn(`Failed to load ImageTexture, src: ${t.src}`,o),this.emit("error",o),e(this)};t.complete&&t.src?s():(t.onload=s,t.onerror=n)})),this._loadSource}genBitmap(){if(this._loadBitmap)return this._loadBitmap;if(this.bitmap||!As)return Promise.resolve(this);const e=this.source,t=!e.crossOrigin||e.crossOrigin==="anonymous";return this._loadBitmap=fetch(e.src,{mode:t?"cors":"no-cors"}).then(i=>i.blob()).then(i=>createImageBitmap(i,0,0,e.width,e.height,{premultiplyAlpha:"premultiply"})).then(i=>(this.bitmap=i,this.requestUpload(),this._loadBitmap=void 0,this)).catch(i=>(console.warn("Failed to genBitmap",i),this)),this._loadBitmap}_glTextureOptions(e){return{...super._glTextureOptions(e),value:this.bitmap??this.source}}upload(e){if(this.useBitmap){if(!this.bitmap)return this.genBitmap(),!1}else{const i=this.source;if(ni&&i instanceof HTMLImageElement&&(!i.complete||i.naturalWidth===0))return!1}const t=super.upload(e);return this.preserveBitmap&&this.bitmap&&(this.bitmap.close(),this.bitmap=void 0),t}}class Qs extends ve{constructor(A,e=1,t=1){const i={width:e,height:t,pixels:null};A&&(ArrayBuffer.isView(A)?i.pixels=new Uint8Array(A.buffer):i.pixels=new Uint8Array(A)),super(i)}_updateProperty(A,e,t,i){switch(A){case"width":this.source.width=Math.round(e*this.pixelRatio);break;case"height":this.source.height=Math.round(e*this.pixelRatio);break}super._updateProperty(A,e,t,i)}}var Tg=Object.defineProperty,Lo=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&Tg(A,e,i),i};function Lg(r){return{autoLoad:!!((r==null?void 0:r.autoLoad)??!0),autoPlay:!!((r==null?void 0:r.autoPlay)??!1),fps:Number((r==null?void 0:r.fps)??0),crossorigin:(r==null?void 0:r.crossorigin)??null,loop:!!((r==null?void 0:r.loop)??!1),muted:!!((r==null?void 0:r.muted)??!1),playsinline:!!((r==null?void 0:r.playsinline)??!0)}}const ys=(DA=class extends ve{constructor(e,t){const i=Lg(t);if(!Wn(e)){typeof e=="string"&&(e=[e]);const s=e[0].src||e[0],n=document.createElement("video");i.autoLoad&&n.setAttribute("preload","auto"),i.playsinline&&(n.setAttribute("webkit-playsinline",""),n.setAttribute("playsinline","")),i.muted&&(n.setAttribute("muted",""),n.muted=!0),i.loop&&n.setAttribute("loop",""),i.autoPlay&&n.setAttribute("autoplay",""),jn(n,s,i.crossorigin);for(let o=0;o<e.length;++o){let{src:a,mime:l}=e[o];if(a=a||e[o],a.startsWith("data:"))l=a.slice(5,a.indexOf(";"));else if(!a.startsWith("blob:")){const h=a.split("?").shift().toLowerCase(),f=h.slice(h.lastIndexOf(".")+1);l=l||DA.mimeTypes.get(f)||`video/${f}`}const g=document.createElement("source");g.src=a,l&&(g.type=l),n.appendChild(g)}e=n}super(e);c(this,"_spf",0);c(this,"_autoPlay",!1);c(this,"_sourceLoad");c(this,"_nextTime",0);c(this,"_connected",!1);c(this,"_requestId");c(this,"_resolve");c(this,"_reject");c(this,"_onPlayStart",()=>{this.valid||this._onCanPlay(),this._setupAutoUpdate()});c(this,"_onPlayStop",()=>{this._setupAutoUpdate()});c(this,"_onCanPlay",()=>{const e=this.source;e.removeEventListener("canplay",this._onCanPlay),e.removeEventListener("canplaythrough",this._onCanPlay);const t=this.valid;this._nextTime=0,this._updateSize(),this.requestUpload(),this._nextTime=0,!t&&this._resolve&&(this._resolve(this),this._sourceLoad=void 0,this._resolve=void 0,this._reject=void 0),this.isPlaying?this._onPlayStart():this._autoPlay&&e.play()});c(this,"_onError",e=>{this.source.removeEventListener("error",this._onError,!0),this.emit("error",e),this._reject&&(this._reject(e),this._reject=void 0,this._resolve=void 0)});c(this,"_onSeeked",()=>{this.autoUpdate&&!this.isPlaying&&(this._nextTime=0,this.requestUpload(),this._nextTime=0)});c(this,"_videoFrameRequestCallback",()=>{this.requestUpload(),this._requestId=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)});c(this,"requestUpload",()=>{const e=Math.floor(xe.elapsed*this.source.playbackRate);this._nextTime-=e,(!this._spf||this._nextTime<=0)&&(super.requestUpload(),this._nextTime=this._spf||0)});this.fps=i.fps,this._autoPlay=i.autoPlay,i.autoPlay&&this.load(),this._setupAutoUpdate()}get isReady(){return this.source.readyState>2}get isPlaying(){return!this.source.paused&&!this.source.ended&&this.isReady}get duration(){return this.source.duration}get seeking(){return this.source.seeking}get currentTime(){return this.source.currentTime}set currentTime(e){this.source.currentTime=e}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"fps":this._spf=t?Math.floor(1e3/t):0,this._setupAutoUpdate();break;case"autoUpdate":this._setupAutoUpdate();break}}_setupAutoUpdate(){this.autoUpdate&&this.isPlaying?!this.fps&&this.source.requestVideoFrameCallback?(this._connected&&(xe.off(this.requestUpload),this._connected=!1,this._nextTime=0),this._requestId===void 0&&(this._requestId=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._requestId!==void 0&&(this.source.cancelVideoFrameCallback(this._requestId),this._requestId=void 0),this._connected||(xe.on(this.requestUpload),this._connected=!0,this._nextTime=0)):(this._requestId!==void 0&&(this.source.cancelVideoFrameCallback(this._requestId),this._requestId=void 0),this._connected&&(xe.off(this.requestUpload),this._connected=!1,this._nextTime=0))}async load(){if(!this._sourceLoad){const e=this.source;(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.isReady?this._onCanPlay():(e.addEventListener("canplay",this._onCanPlay),e.addEventListener("canplaythrough",this._onCanPlay),e.addEventListener("error",this._onError,!0)),this._sourceLoad=new Promise((t,i)=>{this.valid?(this._sourceLoad=void 0,t(this)):(this._resolve=t,this._reject=i,e.load())})}return this._sourceLoad}free(){this._setupAutoUpdate();const e=this.source;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._onCanPlay),e.removeEventListener("error",this._onError,!0),e.pause(),e.src="",e.load())}},c(DA,"mimeTypes",new Map(Object.entries({ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"}))),DA);Lo([Ee({default:!0})],ys.prototype,"autoUpdate"),Lo([Ee({default:0})],ys.prototype,"fps");let Go=ys;class ms extends Qs{}var Gg=Object.defineProperty,Og=Object.getOwnPropertyDescriptor,BA=(r,A,e,t)=>{for(var i=t>1?void 0:t?Og(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Gg(A,e,i),i};const Oo={};function Hg(r){let A=Oo[r]??0;return A++,Oo[r]=A,A}u.Node=class extends qi{constructor(e,t=[]){super();c(this,"_readyed",!1);c(this,"_tree");c(this,"_parent");c(this,"_children",[]);c(this,"_meta",new Map);this._onTreeEnter=this._onTreeEnter.bind(this),this._onTreeExit=this._onTreeExit.bind(this),this._onParented=this._onParented.bind(this),this._onUnparented=this._onUnparented.bind(this),this._onReady=this._onReady.bind(this),this._onProcess=this._onProcess.bind(this),this.setProperties({name:`${this.tag}:${Hg(this.tag)}`,...e}).append(t),this.on("treeEnter",this._onTreeEnter).on("treeExit",this._onTreeExit).on("parented",this._onParented).on("unparented",this._onUnparented).on("ready",this._onReady).on("process",this._onProcess)}getName(){return this.name}setName(e){return this.name=e,this}get tree(){return this.getTree()}set tree(e){this.setTree(e)}getTree(){return this._tree}getViewport(){var e;return(e=this._tree)==null?void 0:e.getCurrentViewport()}getWindow(){var e;return(e=this._tree)==null?void 0:e.root}isInsideTree(){return!!this._tree}setTree(e){const t=this._tree;if(!(e!=null&&e.is(t))){t&&this.emit("treeExit",t),this._tree=e,e&&this.emit("treeEnter",e);for(let i=this._children.length,s=0;s<i;s++){const n=this._children[s];!e&&this.emit("childExitingTree",n),n.setTree(e),e&&this.emit("childEnteredTree",n)}e&&(this.emit("treePostEnter",e),this._readyed||(this._readyed=!0,this.emit("ready")))}return this}get parent(){return this._parent}set parent(e){this.setParent(e)}hasParent(){return!!this._parent}getParent(){return this._parent}setParent(e){var t;if(!((t=this._parent)!=null&&t.is(e))){const i=this._parent;i&&this.emit("unparented",i),this._parent=e,e&&this.emit("parented",e),this.setTree(e==null?void 0:e._tree)}return this}get siblingIndex(){return this.getIndex()}set siblingIndex(e){var t;(t=this._parent)==null||t.moveChild(this,e)}get previousSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[this.getIndex()-1]}get nextSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[this.getIndex()+1]}get firstSibling(){var e;return(e=this._parent)==null?void 0:e.getChildren()[0]}get lastSibling(){var t;const e=(t=this._parent)==null?void 0:t.getChildren();return e?e[e.length-1]:void 0}hasMeta(e){return this._meta.has(e)}getMeta(e,t){return this._meta.get(e)??t}setMeta(e,t){this._meta.set(e,t)}deleteMeta(e){this._meta.delete(e)}clearMeta(){this._meta.clear()}canProcess(){var e;if(!this._tree)return!1;switch(this.processMode){case"inherit":return((e=this._parent)==null?void 0:e.canProcess())??!0;case"pausable":return!this._tree.processPaused;case"when_paused":return this._tree.processPaused;case"always":return!0;case"disabled":default:return!1}}canRender(){var e;if(!this._tree)return!1;switch(this.renderMode){case"inherit":return((e=this._parent)==null?void 0:e.canRender())??!0;case"always":return!0;case"disabled":default:return!1}}_update(e){var t;(t=this._tree)==null||t.log(this.name,"updating"),super._update(e)}_updateProperty(e,t,i,s){var n;(n=this._tree)==null||n.log(this.name,`updating [${String(e)}]`),super._updateProperty(e,t,i,s)}_onTreeEnter(e){this._treeEnter(e),this.emit("treeEntered",e)}_onTreeExit(e){this.emit("treeExiting",e),this._treeExit(e),this.emit("treeExited",e)}_onParented(e){this._parented(e)}_onUnparented(e){this._unparented(e)}_onReady(){this._ready()}_onProcess(e=0){const t=this._tree,i=this.canRender(),s=this.canProcess(),n=[],o=[];for(let l=this._children.length,g=0;g<l;g++){const h=this._children[g];switch(h.processSortMode){case"default":o.push(h);break;case"parent_before":n.push(h);break}}n.forEach(l=>{l.emit("process",e)}),s&&(t==null||t.emit("nodeProcessing",this),this.emit("processing",e),this._process(e));let a;if(i){const l=t.renderStack.push(this);a=t.renderStack.currentCall,t.renderStack.currentCall=l}if(this.mask instanceof u.Node)this.getNode("__$mask")||(this.mask.processMode="disabled",this.appendChild(this.mask,"front"));else{const l=this.getNode("__$mask");l&&this.removeChild(l)}o.forEach(l=>{l.emit("process",e)}),i&&(t.renderStack.currentCall=a),s&&(this.emit("processed",e),t==null||t.emit("nodeProcessed",this))}render(e,t){const i=this.mask;i&&(e.flush(),e.mask.push(this,i)),this._render(e),t==null||t(),i&&(e.flush(),e.mask.pop(this))}input(e,t){for(let i=this._children.length-1;i>=0;i--)this._children[i].input(e,t);this._input(e,t)}getChildren(e=!1){switch(e){case!0:return this._children;case!1:return this._children.filter(t=>t.internalMode==="default");default:return this._children.filter(t=>t.internalMode===e)}}getIndex(e=!1){var t;return((t=this._parent)==null?void 0:t.getChildren(e).indexOf(this))??0}getNode(e){return this._children.find(t=>t.name===e)}removeNode(e){var t;(t=this.getNode(e))==null||t.remove()}addSibling(e){return this.is(e)||!this.hasParent()||e.hasParent()?this:(e.internalMode=this.internalMode,this._parent.moveChild(e,this.getIndex(!0)+1),this)}prepend(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{this.moveChild(i,0)})}append(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{this.appendChild(i)})}before(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{var s;(s=this._parent)==null||s.moveChild(i,this.getIndex(!0))})}after(...e){let t;Array.isArray(e[0])?t=e[0]:t=e,t.forEach(i=>{var s;(s=this._parent)==null||s.moveChild(i,this.getIndex(!0)+1)})}insertBefore(e,t){return!t.hasParent()||!this.is(t.parent)||this.moveChild(e,t.getIndex(!0)),e}appendChild(e,t=e.internalMode){if(this.is(e)||e.hasParent())return e;switch(t){case"default":case"front":{const i=t==="default"?"back":"front",s=this._children.findIndex(n=>n.internalMode===i);s>-1?this._children.splice(s,0,e):this._children.push(e);break}case"back":this._children.push(e);break}return e.internalMode=t,e.setParent(this),this.emit("appendChild",e),e}moveChild(e,t,i=e.internalMode){if(this.is(e)||e.hasParent()&&!this.is(e.parent))return this;e.internalMode=i;const s=this._children.indexOf(e);let n=this._children.findIndex(l=>{switch(i){case"default":return l.internalMode!=="front";case"back":return l.internalMode==="back";case"front":default:return!0}});n=n>-1?n:Math.max(0,this._children.length-1);let o=this._children.slice(n).findIndex(l=>{switch(i){case"front":return l.internalMode!=="front";case"default":return l.internalMode==="back";case"back":default:return!1}});o=o>-1?n+o:Math.max(0,this._children.length);const a=bt(n,t>-1?t:o,o);return a!==s&&(s>-1&&this._children.splice(s,1),e.setParent(this),a>-1&&a<this._children.length?this._children.splice(a,0,e):this._children.push(e),s>-1?this.emit("moveChild",e,a,s):this.emit("appendChild",e)),this}removeChild(e){const t=e.getIndex(!0);return this.is(e.parent)&&t>-1&&(this._children.splice(t,1),e.setParent(void 0),this.emit("removeChild",e,t)),e}removeChildren(){this.getChildren().forEach(e=>this.removeChild(e))}remove(){var e;(e=this._parent)==null||e.removeChild(this)}forEach(e){return this.getChildren().forEach(e),this}deepForEach(e){return this.getChildren().forEach(t=>{e(t),t.deepForEach(e)}),this}_ready(){}_treeEnter(e){}_treeExit(e){}_parented(e){}_unparented(e){}_process(e){}_input(e,t){}_render(e){}clone(){return new this.constructor(this.toJSON().props,this.getChildren(!0))}toJSON(){return{tag:this.tag,props:{name:this.name,...super.toJSON()},meta:Object.fromEntries(this._meta.entries()),children:this.getChildren().map(e=>e.toJSON())}}static parse(e){if(Array.isArray(e))return e.map(a=>this.parse(a));const{tag:t,props:i,children:s}=e,n=zi.get(t)??u.Node,o=new n(i);return s==null||s.forEach(a=>o.appendChild(this.parse(a))),o}},BA([Ee()],u.Node.prototype,"name",2),BA([U()],u.Node.prototype,"mask",2),BA([U({default:"inherit"})],u.Node.prototype,"processMode",2),BA([U({default:"default"})],u.Node.prototype,"processSortMode",2),BA([U({default:"inherit"})],u.Node.prototype,"renderMode",2),BA([U({default:"default"})],u.Node.prototype,"internalMode",2),u.Node=BA([re("Node")],u.Node);var Jg=Object.defineProperty,Kg=Object.getOwnPropertyDescriptor,hi=(r,A,e,t)=>{for(var i=t>1?void 0:t?Kg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Jg(A,e,i),i};u.TimelineNode=class extends u.Node{constructor(e,t=[]){super();c(this,"computedDuration",0);c(this,"_currentTime",0);c(this,"_startTime",0);this.setProperties(e).append(t)}get timeline(){var e;return(e=this._tree)==null?void 0:e.timeline}get timelineCurrentTime(){var e;return((e=this.timeline)==null?void 0:e.currentTime)??0}get parentStartTime(){var e;return((e=this._parent)==null?void 0:e.startTime)??0}get currentTime(){return bt(0,this._currentTime,this.computedDuration)}get startTime(){return this._startTime}set startTime(e){this.delay=e-this.parentStartTime,this._updateCurrentTime(!0)}get endTime(){return this._startTime+this.computedDuration}get currentTimeProgress(){return this.computedDuration?bt(0,this._currentTime/this.computedDuration,1):0}isInsideTimeRange(){const e=this._currentTime;return this.computedDuration?e>=0&&e<=this.computedDuration:e>=0}_updateCurrentTime(e=!1){if(e||!this.paused){const t=this._parent;this._startTime=this.delay+this.parentStartTime,this.computedDuration=t!=null&&t.computedDuration?Math.min(this._startTime+this.duration,t.endTime)-this._startTime:this.duration,this._currentTime=this.timelineCurrentTime-this._startTime,this.emit("updateCurrentTime",this._currentTime),this.insideTimeRange=this.isInsideTimeRange()}}_process(e){super._process(e),this._updateCurrentTime()}},hi([U({default:0})],u.TimelineNode.prototype,"delay",2),hi([U({default:0})],u.TimelineNode.prototype,"duration",2),hi([U({default:!1})],u.TimelineNode.prototype,"paused",2),hi([Ee()],u.TimelineNode.prototype,"insideTimeRange",2),u.TimelineNode=hi([re("TimelineNode")],u.TimelineNode);var Yg=Object.defineProperty,Wg=Object.getOwnPropertyDescriptor,ci=(r,A,e,t)=>{for(var i=t>1?void 0:t?Wg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Yg(A,e,i),i};u.Viewport=class extends u.Node{constructor(e=!1){super();c(this,"_projection",new Io);c(this,"_framebufferIndex",0);c(this,"_framebuffers",[{texture:new ms,needsUpload:!1},{texture:new ms,needsUpload:!1}]);this.flipY=e,this._projection.flipY(e)}get valid(){return!!(this.width&&this.height)}get framebuffer(){return this._framebuffers[this._framebufferIndex]}get texture(){return this.framebuffer.texture}_glFramebufferOptions(e){const{width:t,height:i}=this,{pixelRatio:s}=e;return this._framebuffers.forEach(n=>{const o=n.texture;o.pixelRatio=s,o.width=t,o.height=i,o.upload(e)}),{width:t,height:i,colorTextures:[this.texture._glTexture(e)]}}_glFramebuffer(e){return e.getRelated(this.framebuffer,()=>e.framebuffer.create(this._glFramebufferOptions(e)))}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"x":case"y":this.requestUpload(),this._projection.translate(this.x,this.y),this.emit("updateRect");break;case"width":case"height":this.requestUpload(),this._projection.resize(this.width,this.height),this.emit("updateRect");break}}requestUpload(){this._framebuffers.forEach(e=>e.needsUpload=!0)}resize(e,t){this.width=e,this.height=t}upload(e){const t=this.framebuffer;return t.needsUpload&&this.valid?(t.needsUpload=!1,e.framebuffer.update(this._glFramebuffer(e),this._glFramebufferOptions(e)),!0):!1}activate(e){var t;return this.valid?(e.flush(),(t=this._tree)==null||t.setCurrentViewport(this),this.upload(e),e.framebuffer.bind(this._glFramebuffer(e)),!0):!1}redraw(e,t){if(this.valid){e.flush();const i=this.framebuffer.texture;return this._framebufferIndex=(this._framebufferIndex+1)%this._framebuffers.length,this.activate(e),e.clear(),i.activate(e,0),t(),!0}return!1}activateWithCopy(e,t){this.resize(t.width,t.height),this.activate(e)&&(e.clear(),t.texture.activate(e,0),fe.draw(e,kA.instance,{sampler:0}))}render(e,t){var s,n;const i=(s=this._tree)==null?void 0:s.getCurrentViewport();this.activate(e),e.clear(),super.render(e,t),e.flush(),i?i.activate(e):(e.framebuffer.bind(null),(n=this._tree)==null||n.setCurrentViewport(void 0))}getRect(){return new Bs(this.x,this.y,this.width,this.height)}toProjectionArray(e=!1){return this._projection.toArray(e)}},ci([U({default:0})],u.Viewport.prototype,"x",2),ci([U({default:0})],u.Viewport.prototype,"y",2),ci([U({default:0})],u.Viewport.prototype,"width",2),ci([U({default:0})],u.Viewport.prototype,"height",2),u.Viewport=ci([re("Viewport")],u.Viewport);var Vg=Object.defineProperty,zg=Object.getOwnPropertyDescriptor,ui=(r,A,e,t)=>{for(var i=t>1?void 0:t?zg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Vg(A,e,i),i};u.Effect=class extends u.TimelineNode{constructor(e,t=[]){super();c(this,"viewport1",new u.Viewport);c(this,"viewport2",new u.Viewport);c(this,"_renderId",0);c(this,"_renderViewport");c(this,"_previousSibling");c(this,"_nextSibling");this._onProcessing=this._onProcessing.bind(this),this._onNodeProcessed=this._onNodeProcessed.bind(this),this.setProperties(e).append(t)}get _effectMode(){return this.effectMode??"parent"}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"glsl":{const n=new er(t);!this.effectMode&&n.has.transition&&(this.effectMode="transition"),this.material=n;break}case"glslSrc":{t?Nt.text.load(t).then(n=>this.glsl=n):this.glsl="";break}}}_treeEnter(e){e.on("processing",this._onProcessing),e.on("nodeProcessed",this._onNodeProcessed),this.viewport1.setTree(e),this.viewport2.setTree(e)}_treeExit(e){e.off("processing",this._onProcessing),e.off("nodeProcessed",this._onNodeProcessed),this.viewport1.setTree(void 0),this.viewport2.setTree(void 0)}_onProcessing(){if(this.canProcess())switch(this._updateCurrentTime(),this._effectMode){case"transition":this._previousSibling=this.previousSibling,this._nextSibling=this.nextSibling;break;default:this._previousSibling=void 0,this._nextSibling=void 0;break}}_onNodeProcessed(e){var i;if(!this.canProcess()||!this.isInsideTimeRange())return;const t=(i=this._tree)==null?void 0:i.renderStack;if(t)switch(this._effectMode){case"transition":e.is(this._previousSibling)?(this._previousSibling=void 0,t.push(this)):e.is(this._nextSibling)&&(this._nextSibling=void 0,t.push(this));break}}_processParent(){var o,a;const e=(o=this._tree)==null?void 0:o.renderStack;if(!e)return;const t=(a=e.currentCall)==null?void 0:a.parentCall;if(!t)return;const i=t.calls;let s,n;i.forEach((l,g)=>{var h;(l.renderable.is(this._parent)||(h=l.renderable.parent)!=null&&h.is(this._parent))&&(s=s??g,n=g)}),!(s===void 0||n===void 0)&&(i.splice(n+1,0,e.createCall(this)),i.splice(s,0,e.createCall(this)))}_processChildren(){var e;this._children.length&&(super.emit("process"),(e=this._tree)==null||e.renderStack.push(this))}_onProcess(e=0){if(this.canProcess())switch(this._renderId=0,this._effectMode){case"before":super._onProcess(e);break;case"parent":this._processParent();break;case"children":this._processChildren();break}}_renderBefore(e){var i;const t=(i=this._tree)==null?void 0:i.getCurrentViewport();t&&this.apply(e,t,{redraw:!0})}_renderTransition(e){var t;if(this._renderId%2===0)this._renderViewport=(t=this._tree)==null?void 0:t.getCurrentViewport(),this._renderViewport&&(this.viewport1.activateWithCopy(e,this._renderViewport),this.viewport2.resize(this._renderViewport.width,this._renderViewport.height)),this.viewport2.activate(e),e.clear();else{const i=this._renderViewport;this._renderViewport=void 0,i&&(i.activate(e),e.clear(),this.viewport1.texture.activate(e,0),this.viewport2.texture.activate(e,1),this.apply(e,i,{from:this.viewport1,to:this.viewport2}),e.texture.unbind(0),e.texture.unbind(1))}}_renderParentOrChildren(e){var t;if(this._renderId%2===0)this._renderViewport=(t=this._tree)==null?void 0:t.getCurrentViewport(),this._renderViewport&&this.viewport1.resize(this._renderViewport.width,this._renderViewport.height),this.viewport1.activate(e),e.clear();else{const i=this._renderViewport;this._renderViewport=void 0,i&&(this.viewport1.activate(e),this.apply(e,this.viewport1,{redraw:!0,target:this._effectMode==="parent"?this._parent??void 0:void 0,targetArea:this._parseTargetArea()}),i.activate(e),this.viewport1.texture.activate(e,0),fe.draw(e))}}_parseTargetArea(){if(this._effectMode==="parent"&&this._parent&&"getRect"in this._parent){const e=this._parent.getRect();if(e)return[e.left/this.viewport1.width,e.top/this.viewport1.height,e.width/this.viewport1.width,e.height/this.viewport1.height]}}_render(e){switch(this._effectMode){case"before":this._renderBefore(e);break;case"transition":this._renderTransition(e);break;case"parent":case"children":default:this._renderParentOrChildren(e);break}this._renderId++}apply(e,t,i){this.material&&(i!=null&&i.redraw?t.redraw(e,()=>{fe.draw(e,this.material,{from:0,to:1,progress:this.currentTimeProgress,ratio:t.width/t.height})}):fe.draw(e,this.material,{from:0,to:1,progress:this.currentTimeProgress,ratio:i!=null&&i.from?i.from.width/i.from.height:0}))}},ui([Ee()],u.Effect.prototype,"material",2),ui([U()],u.Effect.prototype,"effectMode",2),ui([U({default:""})],u.Effect.prototype,"glsl",2),ui([U({default:""})],u.Effect.prototype,"glslSrc",2),u.Effect=ui([re("Effect")],u.Effect);var Ho=Object.defineProperty,qg=Object.getOwnPropertyDescriptor,Xg=(r,A,e)=>A in r?Ho(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,ws=(r,A,e,t)=>{for(var i=t>1?void 0:t?qg(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Ho(A,e,i),i},Jo=(r,A,e)=>Xg(r,typeof A!="symbol"?A+"":A,e);const jg=`attribute vec2 position;
114
114
  attribute vec2 uv;
115
115
  varying vec2 vUv[9];
116
116
  uniform float strength;
@@ -773,7 +773,7 @@ void main() {
773
773
  src: url(${e});
774
774
  }`)),document.head.appendChild(t),this}_parseUrls(A){const e=Array.from(new Set([...A.split(","),A]));return Array.from(new Set(e.map(t=>this.familyToUrl.get(t.trim())??this.familyToUrl.get(t)??t)))}get(A){let e;return A&&(e=this._parseUrls(A).reduce((i,s)=>i||this.loaded.get(s),void 0)),e??this.fallbackFont}set(A,e){return this.familyToUrl.set(A,e.src),this.loaded.set(e.src,e),this}delete(A){return this._parseUrls(A).forEach(e=>{this.familyToUrl.delete(e),this.loaded.delete(e)}),this}clear(){return this.familyToUrl.clear(),this.loading.clear(),this.loaded.clear(),this}async load(A,e={}){const{cancelOther:t,injectFontFace:i=!0,injectStyleTag:s=!0,...n}=e,{src:o}=A;if(this.loaded.has(o))return t&&(this.loading.forEach(f=>f.cancel()),this.loading.clear()),g(this.loaded.get(o));let a=this.loading.get(o);return a||(a=this._createRequest(o,n),this.loading.set(o,a)),t&&this.loading.forEach((f,I)=>{f!==a&&(f.cancel(),this.loading.delete(I))}),a.when.then(f=>{if(this.loaded.has(o))return g(this.loaded.get(o));{const I=h(f);return e.noAdd||this.loaded.set(A.src,I),I.familySet.forEach(d=>{this.familyToUrl.set(d,o),typeof document<"u"&&(i&&this.injectFontFace(d,f),s&&this.injectStyleTag(d,o))}),I}}).catch(f=>{if(f instanceof DOMException&&f.message==="The user aborted a request.")return h();throw f}).finally(()=>{this.loading.delete(o)});function l(){return A.family?Array.isArray(A.family)?A.family:[A.family]:[]}function g(f){return l().forEach(I=>{f.familySet.add(I)}),f}function h(f=new ArrayBuffer(0)){let I;function d(){return I||(I=f.byteLength?ul(f,!1):void 0),I}function C(){const B=d();if(B instanceof Et||B instanceof br)return B.sfnt}return{...A,buffer:f,familySet:new Set(l()),getFont:d,getSFNT:C}}}async waitUntilLoad(){await Promise.all(Array.from(this.loading.values()).map(A=>A.when))}};c(Gr,"defaultRequestInit",{cache:"force-cache"});let xr=Gr;const fl=new xr,ed=Object.freeze(Object.defineProperty({__proto__:null,BaseFont:dr,get Cff(){return yA},get Cmap(){return qA},CmapSubtableFormat0:An,CmapSubtableFormat12:on,CmapSubtableFormat14:Fi,CmapSubtableFormat2:Ui,CmapSubtableFormat4:nn,CmapSubtableFormat6:wA,FontDataObject:ht,FontDataView:Fe,Fonts:xr,get Glyf(){return yr},Glyph:$s,GlyphSet:en,get Gpos(){return gn},get Gsub(){return Vt},get Head(){return Me},get Hhea(){return Ke},get Hmtx(){return mr},get Kern(){return hn},get Loca(){return wr},get Maxp(){return Le},get Name(){return XA},get Os2(){return ie},get Post(){return Bt},SFNT:QA,TTF:Et,TableDirectory:VA,get Vhea(){return Ye},get Vmtx(){return _r},WOFF:br,WOFFTableDirectoryEntry:_A,createCmapSegments:sn,dataTypeToByteLength:Mi,defineColumn:y,defineSFNTTable:Je,fonts:fl,parseFont:ul,parseSFNTFont:cl},Symbol.toStringTag,{value:"Module"}));function un(r,A,e){if(typeof A=="string"&&A.startsWith("linear-gradient")){const{x0:t,y0:i,x1:s,y1:n,stops:o}=td(A,e.left,e.top,e.width,e.height),a=r.createLinearGradient(t,i,s,n);return o.forEach(l=>a.addColorStop(l.offset,l.color)),a}return A}function Sr(r,A,e){r!=null&&r.color&&(r.color=un(e,r.color,A)),r!=null&&r.backgroundColor&&(r.backgroundColor=un(e,r.backgroundColor,A)),r!=null&&r.textStrokeColor&&(r.textStrokeColor=un(e,r.textStrokeColor,A))}function td(r,A,e,t,i){var I;const s=((I=r.match(/linear-gradient\((.+)\)$/))==null?void 0:I[1])??"",n=s.split(",")[0],o=n.includes("deg")?n:"0deg",a=s.replace(o,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+%)/gi),g=(Number(o.replace("deg",""))||0)*Math.PI/180,h=t*Math.sin(g),f=i*Math.cos(g);return{x0:A+t/2-h,y0:e+i/2+f,x1:A+t/2+h,y1:e+i/2-f,stops:Array.from(a).map(d=>{let C=d[2];return C.startsWith("(")?C=C.split(",").length>3?`rgba${C}`:`rgb${C}`:C=`#${C}`,{offset:Number(d[3].replace("%",""))/100,color:C}})}}function Gi(r){const{ctx:A,path:e,fontSize:t,clipRect:i}=r;A.save(),A.beginPath();const s=e.style,n={...s,fill:r.color??s.fill,stroke:r.textStrokeColor??s.stroke,strokeWidth:r.textStrokeWidth?r.textStrokeWidth*t:s.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round",shadowOffsetX:(r.shadowOffsetX??0)*t,shadowOffsetY:(r.shadowOffsetY??0)*t,shadowBlur:(r.shadowBlur??0)*t,shadowColor:r.shadowColor};i&&(A.rect(i.left,i.top,i.width,i.height),A.clip(),A.beginPath()),e.drawTo(A,n),A.restore()}function Ad(r,A,e){const{left:t,top:i,width:s,height:n}=e,o=r.canvas;o.dataset.viewBox=`${t} ${i} ${s} ${n}`,o.dataset.pixelRatio=String(A);const a=s,l=n;o.width=Math.max(1,Math.ceil(a*A)),o.height=Math.max(1,Math.ceil(l*A)),o.style.width=`${a}px`,o.style.height=`${l}px`,r.clearRect(0,0,o.width,o.height),r.scale(A,A),r.translate(-t,-i)}function id(r,A){const{paragraphs:e,computedStyle:t,glyphBox:i}=A;Sr(t,i,r),e.forEach(s=>{Sr(s.computedStyle,s.lineBox,r),s.fragments.forEach(n=>{Sr(n.computedStyle,n.inlineBox,r)})})}const rd=new Set(["©","®","÷"]),sd=new Set(["—","…","“","”","﹏","﹋","﹌","‘","’","˜"]),nd={1:"italic",32:"bold"},od={1:"italic",2:"bold"},dl={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5};class ad{constructor(A,e,t){c(this,"path",new He);c(this,"lineBox",new ce);c(this,"inlineBox",new ce);c(this,"glyphBox");c(this,"advanceWidth",0);c(this,"advanceHeight",0);c(this,"underlinePosition",0);c(this,"underlineThickness",0);c(this,"strikeoutPosition",0);c(this,"strikeoutSize",0);c(this,"ascender",0);c(this,"descender",0);c(this,"typoAscender",0);c(this,"typoDescender",0);c(this,"typoLineGap",0);c(this,"winAscent",0);c(this,"winDescent",0);c(this,"xHeight",0);c(this,"capHeight",0);c(this,"baseline",0);c(this,"centerDiviation",0);c(this,"fontStyle");this.content=A,this.index=e,this.parent=t}get center(){var A;return(A=this.glyphBox)==null?void 0:A.center}get computedStyle(){return this.parent.computedStyle}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get fontSize(){return this.computedStyle.fontSize}get fontHeight(){return this.fontSize*this.computedStyle.lineHeight}_getFontSFNT(A){const e=this.computedStyle.fontFamily,t=A??fl,i=e?t.get(e):t.fallbackFont;return i==null?void 0:i.getSFNT()}updateGlyph(A=this._getFontSFNT()){if(!A)return this;const{hhea:e,os2:t,post:i,head:s}=A,n=s.unitsPerEm,o=e.ascent,a=e.descent,{content:l,computedStyle:g,isVertical:h}=this,{fontSize:f}=g,I=n/f,d=A.getAdvanceWidth(l,f),C=(o+Math.abs(a))/I,B=o/I;return this.advanceWidth=d,this.advanceHeight=C,this.inlineBox.width=h?C:d,this.inlineBox.height=h?d:C,this.underlinePosition=(o-i.underlinePosition)/I,this.underlineThickness=i.underlineThickness/I,this.strikeoutPosition=(o-t.yStrikeoutPosition)/I,this.strikeoutSize=t.yStrikeoutSize/I,this.ascender=o/I,this.descender=a/I,this.typoAscender=t.sTypoAscender/I,this.typoDescender=t.sTypoDescender/I,this.typoLineGap=t.sTypoLineGap/I,this.winAscent=t.usWinAscent/I,this.winDescent=t.usWinDescent/I,this.xHeight=t.sxHeight/I,this.capHeight=t.sCapHeight/I,this.baseline=B,this.centerDiviation=C/2-B,this.fontStyle=nd[t.fsSelection]??od[s.macStyle],this}update(A){const e=this._getFontSFNT(A);if(!e)return this;this.updateGlyph(e);const{isVertical:t,content:i,computedStyle:s,baseline:n,inlineBox:o,ascender:a,descender:l,typoAscender:g,fontStyle:h,advanceWidth:f,advanceHeight:I}=this,{left:d,top:C}=o,B=s.fontStyle==="italic"&&h!=="italic";let R=d,S=C+n,_;const M=new He;if(t&&(R+=(I-f)/2,Math.abs(f-I)>.1&&(S-=(a-g)/(a+Math.abs(l))*I),_=void 0),t&&!rd.has(i)&&(i.codePointAt(0)<=256||sd.has(i))){M.addCommands(e.getPathCommands(i,R,C+n-(I-f)/2,s.fontSize));const v={y:C-(I-f)/2+I/2,x:R+f/2};B&&this._italic(M,t?{x:v.x,y:C-(I-f)/2+n}:void 0),M.rotate(90,v)}else _!==void 0?(M.addCommands(e.glyphs.get(_).getPathCommands(R,S,s.fontSize)),B&&this._italic(M,t?{x:R+f/2,y:C+g/(a+Math.abs(l))*I}:void 0)):(M.addCommands(e.getPathCommands(i,R,S,s.fontSize)),B&&this._italic(M,t?{x:R+I/2,y:S}:void 0));const w=s.fontWeight??400;return w in dl&&(w===700||w==="bold")&&h!=="bold"&&M.bold(dl[w]*s.fontSize*.05),M.style={fill:s.color,stroke:s.textStrokeWidth?s.textStrokeColor:"none",strokeWidth:s.textStrokeWidth?s.textStrokeWidth*s.fontSize*.03:0},this.path=M,this.glyphBox=this.getGlyphBoundingBox(),this}_italic(A,e){A.skew(-.24,0,e||{y:this.inlineBox.top+this.baseline,x:this.inlineBox.left+this.inlineBox.width/2})}getGlyphMinMax(A,e,t){var i;if((i=this.path.curves[0])!=null&&i.curves.length)return this.path.getMinMax(A,e,t)}getGlyphBoundingBox(A){const e=this.getGlyphMinMax(void 0,void 0,A);if(!e)return;const{min:t,max:i}=e;return new ce(t.x,t.y,i.x-t.x,i.y-t.y)}drawTo(A,e={}){const t=this.computedStyle,i={ctx:A,path:this.path,fontSize:t.fontSize,color:t.color,...e};if(this.glyphBox)Gi(i);else{A.save(),A.beginPath();const s=this.path.style,n={...s,fill:i.color??s.fill,stroke:i.textStrokeColor??s.stroke,strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize:s.strokeWidth,shadowOffsetX:(i.shadowOffsetX??0)*i.fontSize,shadowOffsetY:(i.shadowOffsetY??0)*i.fontSize,shadowBlur:(i.shadowBlur??0)*i.fontSize,shadowColor:i.shadowColor};Ms(A,n),A.font=`${i.fontSize}px ${i.fontFamily}`,this.isVertical?(A.textBaseline="middle",A.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.inlineBox.height/2)):(A.textBaseline="alphabetic",A.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.baseline)),A.restore()}}}function fn(r,A){return typeof r=="number"?r:r.endsWith("%")?(r=r.substring(0,r.length-1),Math.ceil(Number(r)/100*A.total)):r.endsWith("rem")?(r=r.substring(0,r.length-3),Number(r)*A.fontSize):r.endsWith("em")?(r=r.substring(0,r.length-2),Number(r)*A.fontSize):Number(r)}function Il(r){const A=nA(r)?{}:r;return Object.keys(A).reduce((e,t)=>{let i=A[t];const s=Bl(t),n=Bl(i);return s&&(t=s),n&&(i=n),e[t]=i,e},{})}function nA(r){return!r||r==="none"}function ld(r,A){const e=Object.keys(r),t=Object.keys(A);return Array.from(new Set([...e,...t])).every(s=>jA(r[s],A[s]))}function jA(r,A){const e=typeof r;return e===typeof A?e==="object"?ld(r,A):r===A:!1}function Bl(r){const A=r.startsWith("#")?r.slice(1):r;if(!/^(?:[0-9A-F]{3}|[0-9A-F]{6})$/i.test(A))return null;const t=A.length===3?A.split("").map(o=>o+o).join(""):A,i=Number.parseInt(t.slice(0,2),16),s=Number.parseInt(t.slice(2,4),16),n=Number.parseInt(t.slice(4,6),16);return`rgb(${i}, ${s}, ${n})`}function dn(r){if(!r)return r;const A={};for(const e in r)r[e]!==""&&r[e]!==void 0&&(A[e]=r[e]);return A}function In(r){return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("blob://")}class gd{constructor(A,e={},t){c(this,"inlineBox",new ce);this.content=A,this.style=e,this.parent=t,this.updateComputedStyle().initCharacters()}get computedContent(){const A=this.computedStyle;return A.textTransform==="uppercase"?this.content.toUpperCase():A.textTransform==="lowercase"?this.content.toLowerCase():this.content}updateComputedStyle(){return this.computedStyle={...this.parent.computedStyle,...dn(this.style)},this}initCharacters(){const A=[];let e=0;for(const t of this.computedContent)A.push(new ad(t,e++,this));return this.characters=A,this}}class Oi{constructor(A,e){c(this,"lineBox",new ce);c(this,"fragments",[]);this.style=A,this.parentStyle=e,this.updateComputedStyle()}updateComputedStyle(){return this.computedStyle={...dn(this.parentStyle),...dn(this.style)},this}addFragment(A,e){const t=new gd(A,e,this);return this.fragments.push(t),t}}function jI(r){return r}const ti=class ti{_styleToDomStyle(A){const e={};for(const t in A){const i=A[t];ti.notZeroStyles.has(t)&&i===0||(typeof i=="number"&&ti.pxStyles.has(t)?e[t]=`${i}px`:e[t]=i)}return e}createParagraphDom(A,e){const t=document.createDocumentFragment(),i=document.createElement("section"),s={...e},n=e.writingMode.includes("horizontal");switch(e.textAlign){case"start":case"left":s.justifyContent="flex-start";break;case"center":s.justifyContent="center";break;case"end":case"right":s.justifyContent="flex-end";break}switch(e.verticalAlign){case"top":s.alignItems="flex-start";break;case"middle":s.alignItems="center";break;case"bottom":s.alignItems="flex-end";break}const o=!!(s.justifyContent||s.alignItems);Object.assign(i.style,{...this._styleToDomStyle({...s,boxSizing:s.boxSizing??"border-box",display:s.display??(o?"inline-flex":void 0),width:s.width??"max-content",height:s.height??"max-content"}),whiteSpace:"pre-wrap",wordBreak:"break-all",position:"fixed",visibility:"hidden"});const a=document.createElement("ul");return Object.assign(a.style,{verticalAlign:"inherit",listStyleType:"inherit",padding:"0",margin:"0",width:o&&n?"100%":void 0,height:o&&!n?"100%":void 0}),A.forEach(l=>{const g=document.createElement("li");Object.assign(g.style,{verticalAlign:"inherit",...this._styleToDomStyle(l.style)}),l.fragments.forEach(h=>{const f=document.createElement("span");Object.assign(f.style,{verticalAlign:"inherit",...this._styleToDomStyle(h.style)}),f.appendChild(document.createTextNode(h.content)),g.appendChild(f)}),a.appendChild(g)}),i.appendChild(a),t.appendChild(i),document.body.appendChild(t),{dom:i,destory:()=>{var l;return(l=i.parentNode)==null?void 0:l.removeChild(i)}}}measureDomText(A){const e=document.createRange();e.selectNodeContents(A);const t=A.data??"";let i=0;return Array.from(t).map(s=>{var h;const n=i+=t.substring(i).indexOf(s),o=n+s.length;i+=s.length,e.setStart(A,Math.max(n,0)),e.setEnd(A,o);const a=((h=e.getClientRects)==null?void 0:h.call(e))??[e.getBoundingClientRect()];let l=a[a.length-1];a.length>1&&l.width<2&&(l=a[a.length-2]);const g=e.toString();if(g!==""&&l&&l.width+l.height!==0)return{content:g,top:l.top,left:l.left,height:l.height,width:l.width}}).filter(Boolean)}measureDom(A){const e=[],t=[],i=[];return A.querySelectorAll("li").forEach((s,n)=>{const o=s.getBoundingClientRect();e.push({paragraphIndex:n,left:o.left,top:o.top,width:o.width,height:o.height}),s.querySelectorAll(":scope > *").forEach((a,l)=>{const g=a.getBoundingClientRect();t.push({paragraphIndex:n,fragmentIndex:l,left:g.left,top:g.top,width:g.width,height:g.height});let h=0;!a.children.length&&a.firstChild instanceof window.Text?this.measureDomText(a.firstChild).forEach(f=>{i.push({...f,newParagraphIndex:-1,paragraphIndex:n,fragmentIndex:l,characterIndex:h++,textWidth:-1,textHeight:-1})}):a.querySelectorAll(":scope > *").forEach(f=>{f.firstChild instanceof window.Text&&this.measureDomText(f.firstChild).forEach(I=>{i.push({...I,newParagraphIndex:-1,paragraphIndex:n,fragmentIndex:l,characterIndex:h++,textWidth:-1,textHeight:-1})})})})}),{paragraphs:e,fragments:t,characters:i}}measureParagraphDom(A,e){const t=e.getBoundingClientRect(),i=this.measureDom(e);i.paragraphs.forEach(o=>{const a=A[o.paragraphIndex];a.lineBox.left=o.left-t.left,a.lineBox.top=o.top-t.top,a.lineBox.width=o.width,a.lineBox.height=o.height}),i.fragments.forEach(o=>{const a=A[o.paragraphIndex].fragments[o.fragmentIndex];a.inlineBox.left=o.left-t.left,a.inlineBox.top=o.top-t.top,a.inlineBox.width=o.width,a.inlineBox.height=o.height});const s=[];let n=0;return i.characters.forEach(o=>{const{paragraphIndex:a,fragmentIndex:l,characterIndex:g}=o;s.push({...o,newParagraphIndex:a,left:o.left-t.left,top:o.top-t.top});const h=A[a].fragments[l].characters[g],{fontHeight:f,isVertical:I}=h,d=s[n];h.inlineBox.left=d.left,h.inlineBox.top=d.top,h.inlineBox.width=d.width,h.inlineBox.height=d.height,I?(h.lineBox.left=d.left+(d.width-f)/2,h.lineBox.top=d.top,h.lineBox.width=f,h.lineBox.height=d.height):(h.lineBox.left=d.left,h.lineBox.top=d.top+(d.height-f)/2,h.lineBox.width=d.width,h.lineBox.height=f),n++}),{paragraphs:A,boundingBox:new ce(0,0,t.width,t.height)}}measure(A,e,t){let i;t||({dom:t,destory:i}=this.createParagraphDom(A,e));const s=this.measureParagraphDom(A,t);return i==null||i(),s}};c(ti,"notZeroStyles",new Set(["width","height"])),c(ti,"pxStyles",new Set(["width","height","fontSize","letterSpacing","textStrokeWidth","textIndent","shadowOffsetX","shadowOffsetY","shadowBlur","marginLeft","marginTop","marginRight","marginBottom","paddingLeft","paddingTop","paddingRight","paddingBottom"]));let Bn=ti;class hd{constructor(){c(this,"eventListeners",new Map)}addEventListener(A,e,t){const i={value:e,options:t},s=this.eventListeners.get(A);return s?Array.isArray(s)?s.push(i):this.eventListeners.set(A,[s,i]):this.eventListeners.set(A,i),this}removeEventListener(A,e,t){var s,n;if(!e)return this.eventListeners.delete(A),this;const i=this.eventListeners.get(A);if(!i)return this;if(Array.isArray(i)){const o=[];for(let a=0,l=i.length;a<l;a++){const g=i[a];(g.value!==e||typeof t=="object"&&(t!=null&&t.once)&&(typeof g.options=="boolean"||!((s=g.options)!=null&&s.once)))&&o.push(g)}o.length?this.eventListeners.set(A,o.length===1?o[0]:o):this.eventListeners.delete(A)}else i.value===e&&(typeof t=="boolean"||!(t!=null&&t.once)||typeof i.options=="boolean"||(n=i.options)!=null&&n.once)&&this.eventListeners.delete(A);return this}removeAllListeners(){return this.eventListeners.clear(),this}hasEventListener(A){return this.eventListeners.has(A)}dispatchEvent(A,e){var i,s;const t=this.eventListeners.get(A);if(t){if(Array.isArray(t))for(let n=t.length,o=0;o<n;o++){const a=t[o];typeof a.options=="object"&&((i=a.options)!=null&&i.once)&&this.off(A,a.value,a.options),a.value.apply(this,[e])}else typeof t.options=="object"&&((s=t.options)!=null&&s.once)&&this.off(A,t.value,t.options),t.value.apply(this,[e]);return!0}else return!1}on(A,e,t){return this.addEventListener(A,e,t)}once(A,e){return this.addEventListener(A,e,{once:!0})}off(A,e,t){return this.removeEventListener(A,e,t)}emit(A,e){this.dispatchEvent(A,e)}}function cd(){return{name:"background"}}function En(r){const{highlight:A,highlightImage:e,highlightReferImage:t,highlightColormap:i,highlightLine:s,highlightSize:n,highlightThickness:o}=r;return{image:(A==null?void 0:A.image)??e??"none",referImage:(A==null?void 0:A.referImage)??t??"none",colormap:(A==null?void 0:A.colormap)??i??"none",line:(A==null?void 0:A.line)??s??"none",size:(A==null?void 0:A.size)??n??"cover",thickness:(A==null?void 0:A.thickness)??o??"100%"}}function ud(){const r=[],A=[],e=new Map,t=new Map;async function i(n){if(!e.has(n)){e.set(n,n);try{e.set(n,await fetch(n).then(o=>o.text()))}catch(o){console.warn(o),e.delete(n)}}}function s(n){let o=t.get(n);if(!o){const a=va(In(n)?e.get(n)??n:n),l=Sa(a);o={dom:a,pathSet:l},t.set(n,o)}return o}return{name:"highlight",paths:r,load:async n=>{const o=new Set;n.forEachCharacter(a=>{const{computedStyle:l}=a,{image:g,referImage:h}=En(l);In(g)&&o.add(g),In(h)&&o.add(h)}),await Promise.all(Array.from(o).map(a=>i(a)))},update:n=>{A.length=0,r.length=0;let o=[],a,l;n.forEachCharacter(g=>{const{computedStyle:h}=g,f=En(h),{image:I,colormap:d,line:C,size:B,thickness:R}=f;if(nA(I))a!=null&&a.length&&(a=[],o.push(a));else{const{inlineBox:S,isVertical:_}=g,{fontSize:M}=h;(!l||jA(l.image,I)&&jA(l.colormap,d)&&jA(l.line,C)&&jA(l.size,B)&&jA(l.thickness,R))&&(a!=null&&a.length)&&(_?a[0].inlineBox.left===S.left:a[0].inlineBox.top===S.top)&&a[0].fontSize===M?a.push(g):(a=[],a.push(g),o.push(a))}l=f}),o=o.filter(g=>g.length);for(let g=0;g<o.length;g++){const h=o[g],f=h[0],I=ce.from(...h.filter(H=>H.glyphBox).map(H=>H.glyphBox)),{computedStyle:d}=f,{fontSize:C,writingMode:B}=d,{image:R,referImage:S,colormap:_,line:M,size:w,thickness:v}=En(d),D=B.includes("vertical"),x=fn(v,{fontSize:C,total:I.width})/I.width,L=Il(_),{pathSet:j,dom:Y}=s(R),T=j.getBoundingBox(!0),$=C/T.width*2,P=new ce().copy(I);D&&(P.width=I.height,P.height=I.width,P.left=I.left+I.width);const X=Math.floor(P.width);let ee=X;if(w!=="cover"&&(ee=fn(w,{fontSize:C,total:I.width})||X,P.width=ee),!nA(S)&&nA(M)){const H=s(S).pathSet.getBoundingBox(!0);T.copy(H)}else{let H;if(nA(M))if(T.width/T.height>4){H="underline";const ne=Y.getAttribute("viewBox");if(ne){const[q,W,oe,te]=ne.split(" ").map(Ae=>Number(Ae)),ae=W+te/2;T.y<ae&&T.y+T.height>ae?H="line-through":T.y+T.height<ae?H="overline":H="underline"}}else H="outline";else H=M;switch(H){case"outline":{const ne=P.width*.2,q=P.height*.2;P.width+=ne,P.height+=q,D?(P.x-=q/2,P.y-=ne/2,P.x+=P.height):(P.x-=ne/2,P.y-=q/2);break}case"overline":P.height=T.height*$,D?P.x=f.inlineBox.left+f.inlineBox.width:P.y=f.inlineBox.top;break;case"line-through":P.height=T.height*$,D?P.x=f.inlineBox.left+f.inlineBox.width-f.strikeoutPosition+P.height/2:P.y=f.inlineBox.top+f.strikeoutPosition-P.height/2;break;case"underline":P.height=T.height*$,D?P.x=f.inlineBox.left+f.inlineBox.width-f.underlinePosition:P.y=f.inlineBox.top+f.underlinePosition;break}}const J=new ot().translate(-T.x,-T.y).scale(P.width/T.width,P.height/T.height);D&&J.rotate(-Math.PI/2),J.translate(P.x,P.y);for(let H=0;H<Math.ceil(X/ee);H++){const ne=J.clone();D?ne.translate(0,H*P.width):ne.translate(H*P.width,0),j.paths.forEach(q=>{const W=q.clone().applyTransform(ne);W.style.strokeWidth&&(W.style.strokeWidth*=$*x),W.style.strokeMiterlimit&&(W.style.strokeMiterlimit*=$),W.style.strokeDashoffset&&(W.style.strokeDashoffset*=$),W.style.strokeDasharray&&(W.style.strokeDasharray=W.style.strokeDasharray.map(oe=>oe*$)),W.style.fill&&W.style.fill in L&&(W.style.fill=L[W.style.fill]),W.style.stroke&&W.style.stroke in L&&(W.style.stroke=L[W.style.stroke]),r.push(W),X!==ee&&(D?A[r.length-1]=new ce(I.left-I.width*2,I.top,I.width*4,I.height):A[r.length-1]=new ce(I.left,I.top-I.height*2,I.width,I.height*4))})}}},renderOrder:-1,render:(n,o)=>{r.forEach((a,l)=>{if(Gi({ctx:n,path:a,fontSize:o.computedStyle.fontSize,clipRect:A[l]}),o.debug){const g=new Ts([a]).getBoundingBox();g&&n.strokeRect(g.x,g.y,g.width,g.height)}})}}}function fd(r,A){return`<svg width="${r*2}" height="${r*2}" xmlns="http://www.w3.org/2000/svg">
775
775
  <circle cx="${r}" cy="${r}" r="${r}" fill="${A}" />
776
- </svg>`}function dd(){const r=[];return{name:"listStyle",paths:r,update:A=>{r.length=0;const{paragraphs:e,isVertical:t,fontSize:i}=A,s=i*.45;e.forEach(n=>{const{computedStyle:o}=n,{color:a,listStyleImage:l,listStyleColormap:g,listStyleSize:h,listStyleType:f}=o,I=Il(g);let d=h,C;if(!nA(l))C=l;else if(!nA(f)){const _=i*.38/2;switch(d=d==="cover"?_*2:d,f){case"disc":C=fd(_,String(a));break}}if(!C)return;const B=Sa(C),R=B.getBoundingBox();let S;n.fragments.forEach(_=>{_.characters.forEach(M=>{const{inlineBox:w}=M;if(t?(S==null?void 0:S.inlineBox.left)!==w.left:(S==null?void 0:S.inlineBox.top)!==w.top){S=M;const v=d==="cover"?1:fn(d,{total:i,fontSize:i})/i,D=new ot;if(t){const x=i/R.height*v;D.translate(-R.left,-R.top).rotate(Math.PI/2).scale(x,x).translate(w.left+(w.width-R.height*x)/2,w.top-s)}else{const x=i/R.height*v;D.translate(-R.left,-R.top).scale(x,x).translate(w.left-R.width*x-s,w.top+(w.height-R.height*x)/2)}r.push(...B.paths.map(x=>{const L=x.clone();return L.applyTransform(D),L.style.fill&&L.style.fill in I&&(L.style.fill=I[L.style.fill]),L.style.stroke&&L.style.stroke in I&&(L.style.stroke=I[L.style.stroke]),L}))}})})})}}}function Id(){return{name:"outline"}}const oA=new G,ZA=new ot,aA=new ot;function Bd(){return{name:"render",getBoundingBox:r=>{const{characters:A,fontSize:e,effects:t}=r,i=[];return A.forEach(s=>{t==null||t.forEach(n=>{if(!s.glyphBox)return;const o=s.glyphBox.clone(),a=pn(r,n);oA.set(o.left,o.top),oA.applyMatrix3(a),o.left=oA.x,o.top=oA.y,oA.set(o.right,o.bottom),oA.applyMatrix3(a),o.width=oA.x-o.left,o.height=oA.y-o.top;const l=(n.shadowOffsetX??0)*e,g=(n.shadowOffsetY??0)*e,h=Math.max(.1,n.textStrokeWidth??0)*e;o.left+=l-h,o.top+=g-h,o.width+=h*2,o.height+=h*2,i.push(o)})}),i.length?ce.from(...i):void 0},render:(r,A)=>{const{paragraphs:e,glyphBox:t,effects:i,style:s}=A;function n(o,a){r.fillStyle=o,r.fillRect(a.left,a.top,a.width,a.height)}s!=null&&s.backgroundColor&&n(s.backgroundColor,new ce(0,0,r.canvas.width,r.canvas.height)),e.forEach(o=>{var a;(a=o.style)!=null&&a.backgroundColor&&n(o.style.backgroundColor,o.lineBox)}),i?i.forEach(o=>{Sr(o,t,r),r.save();const[a,l,g,h,f,I]=pn(A,o).transpose().elements;r.transform(a,h,l,f,g,I),A.forEachCharacter(d=>{var C;(C=d.parent.style)!=null&&C.backgroundColor&&n(d.parent.style.backgroundColor,d.inlineBox),d.drawTo(r,o)}),r.restore()}):e.forEach(o=>{o.fragments.forEach(a=>{var l;(l=a.style)!=null&&l.backgroundColor&&n(a.computedStyle.backgroundColor,a.inlineBox),a.characters.forEach(g=>{g.drawTo(r)})})}),A.debug&&e.forEach(o=>{r.strokeRect(o.lineBox.x,o.lineBox.y,o.lineBox.width,o.lineBox.height)})}}}function pn(r,A){const{fontSize:e,glyphBox:t}=r,i=(A.translateX??0)*e,s=(A.translateY??0)*e,n=Math.PI*2,o=(A.skewX??0)/360*n,a=(A.skewY??0)/360*n,{left:l,top:g,width:h,height:f}=t,I=l+h/2,d=g+f/2;return ZA.identity(),aA.makeTranslation(i,s),ZA.multiply(aA),aA.makeTranslation(I,d),ZA.multiply(aA),aA.set(1,Math.tan(o),0,Math.tan(a),1,0,0,0,1),ZA.multiply(aA),aA.makeTranslation(-I,-d),ZA.multiply(aA),ZA.clone()}function Ed(){const r=[];return{name:"textDecoration",paths:r,update:A=>{r.length=0;const e=[];let t,i;A.forEachCharacter(s=>{const{computedStyle:n,isVertical:o,inlineBox:a,underlinePosition:l,underlineThickness:g,strikeoutPosition:h,strikeoutSize:f}=s,{color:I,textDecoration:d,writingMode:C}=n;if(nA(d))i=void 0;else{let B=!1;if((i==null?void 0:i.textDecoration)===d&&(i==null?void 0:i.writingMode)===C&&(i==null?void 0:i.color)===I&&(o?t[0].inlineBox.left===a.left:t[0].inlineBox.top===a.top))switch(d){case"underline":t[0].underlinePosition===l&&t[0].underlineThickness===g&&(B=!0);break;case"line-through":t[0].strikeoutPosition===h&&t[0].strikeoutSize===f&&(B=!0);break}B?t.push(s):(t=[],t.push(s),e.push(t)),i=n}}),e.forEach(s=>{const{computedStyle:n,isVertical:o,underlinePosition:a,underlineThickness:l,strikeoutPosition:g,strikeoutSize:h}=s[0],{color:f,textDecoration:I}=n,{left:d,top:C,width:B,height:R}=ce.from(...s.map(v=>v.inlineBox));let S=o?d+B:C;const _=o?-1:1;let M=0;switch(I){case"overline":M=l*2;break;case"underline":S+=_*a,M=l*2;break;case"line-through":S+=_*g,M=h*2;break}S-=M;let w;o?w=new He([{type:"M",x:S,y:C},{type:"L",x:S,y:C+R},{type:"L",x:S+M,y:C+R},{type:"L",x:S+M,y:C},{type:"Z"}],{fill:f}):w=new He([{type:"M",x:d,y:S},{type:"L",x:d+B,y:S},{type:"L",x:d+B,y:S+M},{type:"L",x:d,y:S+M},{type:"Z"}],{fill:f}),r.push(w)})},render:(A,e)=>{const{effects:t,computedStyle:i}=e;t?t.forEach(s=>{A.save();const[n,o,a,l,g,h]=pn(e,s).transpose().elements;A.transform(n,l,o,g,a,h),r.forEach(f=>{Gi({ctx:A,path:f,fontSize:i.fontSize,...s})}),A.restore()}):r.forEach(s=>{Gi({ctx:A,path:s,fontSize:i.fontSize})})}}}const Cn=ka();class pd extends hd{constructor(e={}){super();c(this,"debug");c(this,"content");c(this,"style");c(this,"effects");c(this,"measureDom");c(this,"needsUpdate",!0);c(this,"computedStyle",{...Cn});c(this,"paragraphs",[]);c(this,"lineBox",new ce);c(this,"rawGlyphBox",new ce);c(this,"glyphBox",new ce);c(this,"pathBox",new ce);c(this,"boundingBox",new ce);c(this,"measurer",new Bn);c(this,"plugins",new Map);c(this,"fonts");this.debug=e.debug??!1,this.content=e.content??"",this.style=e.style??{},this.measureDom=e.measureDom,this.effects=e.effects,this.fonts=e.fonts,this.use(cd()).use(Id()).use(dd()).use(Ed()).use(ud()).use(Bd()),this.updateParagraphs()}get fontSize(){return this.computedStyle.fontSize}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get characters(){return this.paragraphs.flatMap(e=>e.fragments.flatMap(t=>t.characters))}use(e){return this.plugins.set(e.name,e),this}forEachCharacter(e){return this.paragraphs.forEach((t,i)=>{t.fragments.forEach((s,n)=>{s.characters.forEach((o,a)=>{e(o,{paragraphIndex:i,fragmentIndex:n,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(e=>{var t;return(t=e.load)==null?void 0:t.call(e,this)}))}updateParagraphs(){this.computedStyle={...Cn,...this.style};let{content:e,computedStyle:t}=this;const i=[];if(typeof e=="string"){const s=new Oi({},t);s.addFragment(e),i.push(s)}else{e=Array.isArray(e)?e:[e];for(const s of e)if(typeof s=="string"){const n=new Oi({},t);n.addFragment(s),i.push(n)}else if(Array.isArray(s)){const n=new Oi({},t);s.forEach(o=>{if(typeof o=="string")n.addFragment(o);else{const{content:a,...l}=o;a!==void 0&&n.addFragment(a,l)}}),i.push(n)}else if("fragments"in s){const{fragments:n,...o}=s,a=new Oi(o,t);n.forEach(l=>{const{content:g,...h}=l;g!==void 0&&a.addFragment(g,h)}),i.push(a)}else if("content"in s){const{content:n,...o}=s;if(n!==void 0){const a=new Oi(o,t);a.addFragment(n),i.push(a)}}}return this.paragraphs=i,this}measure(e=this.measureDom){const t={paragraphs:this.paragraphs,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this.updateParagraphs();const i=this.measurer.measure(this.paragraphs,this.computedStyle,e);this.paragraphs=i.paragraphs,this.lineBox=i.boundingBox,this.characters.forEach(s=>{s.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((s,n)=>(s.updateOrder??0)-(n.updateOrder??0)).forEach(s=>{var n;(n=s.update)==null||n.call(s,this)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const s in t)i[s]=this[s],this[s]=t[s];return this.emit("measure",{text:this,result:i}),i}getGlyphBox(){const e=G.MAX,t=G.MIN;return this.characters.forEach(i=>{if(!i.getGlyphMinMax(e,t)){const{inlineBox:s}=i,n=new G(s.left,s.top),o=new G(s.left+s.width,s.top+s.height);e.min(n,o),t.max(n,o)}}),new ce(e.x,e.y,t.x-e.x,t.y-e.y)}updatePathBox(){return this.pathBox=ce.from(this.glyphBox,...Array.from(this.plugins.values()).map(e=>e.getBoundingBox?e.getBoundingBox(this):new Ts(e.paths??[]).getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){const{lineBox:e,rawGlyphBox:t,pathBox:i}=this,s=Math.min(i.left,i.left+e.left-t.left),n=Math.min(i.top,i.top+e.top-t.top),o=Math.max(i.right,i.right+e.right-t.right),a=Math.max(i.bottom,i.bottom+e.bottom-t.bottom);return this.boundingBox=new ce(s,n,o-s,a-n),this}requestUpdate(){return this.needsUpdate=!0,this}update(){const e=this.measure();for(const t in e)this[t]=e[t];return this.emit("update",{text:this}),this.needsUpdate=!1,this}render(e){const{view:t,pixelRatio:i=2}=e,s=t.getContext("2d");s&&(this.needsUpdate&&this.update(),Ad(s,i,this.boundingBox),id(s,this),Array.from(this.plugins.values()).sort((n,o)=>(n.renderOrder??0)-(o.renderOrder??0)).forEach(n=>{var o;if(n.render)(o=n.render)==null||o.call(n,s,this);else if(n.paths){const a=this.computedStyle;n.paths.forEach(l=>{Gi({ctx:s,path:l,fontSize:a.fontSize})})}}),this.emit("render",{text:this,view:t,pixelRatio:i}))}}var Cd=Object.defineProperty,Qd=Object.getOwnPropertyDescriptor,$A=(r,A,e,t)=>{for(var i=t>1?void 0:t?Qd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Cd(A,e,i),i};const yd=new Set(Object.keys(Cn));u.Text2D=class extends hr{constructor(e,t=[]){super();c(this,"effects");c(this,"measureDom");c(this,"fonts");c(this,"texture",new gi);c(this,"text",new pd);c(this,"_subTextsCount",0);this.setProperties(e),this.append(t)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"content":case"effects":case"measureDom":case"fonts":case"split":this._updateSplit(),this.requestRedraw();break}this._subTextsCount&&e==="effects"&&this._getSubTexts().forEach(n=>{n.setProperties({[e]:t})})}_updateText(){this.text.style=this.style.toJSON(),this.text.content=this.content??"",this.text.effects=this.effects,this.text.fonts=this.fonts,this.text.measureDom=this.measureDom,this.text.requestUpdate()}_updateStyleProperty(e,t,i){switch(super._updateStyleProperty(e,t,i),e){case"width":this.split&&this._updateSubTexts();break}typeof e=="string"&&yd.has(e)&&(this._subTextsCount&&e!=="width"&&e!=="height"&&this._getSubTexts().forEach(s=>{s.style.setProperties({[e]:t})}),this.requestRedraw())}_getSubTexts(){return this.getChildren("front").filter(e=>e instanceof u.Text2D)}_updateSubTexts(){const e=this._getSubTexts(),t=this.measure();let i=0;this.split&&t.paragraphs.forEach(s=>{s.fragments.forEach(n=>{n.characters.forEach(o=>{const a=e[i];a&&(a.style.left=o.inlineBox.left,a.style.top=o.inlineBox.top),i++})})})}measure(){this._updateText();const e=this.text.measure();return this.style.width||(this.style.width=e.boundingBox.width),this.style.height||(this.style.height=e.boundingBox.height),e}_updateSplit(){this._subTextsCount&&(this.getChildren("front").forEach(t=>this.removeChild(t)),this._subTextsCount=0);const e=this.measure();this.split&&e.paragraphs.forEach(t=>{t.fragments.forEach(i=>{i.characters.forEach(s=>{this.appendChild(new u.Text2D({content:s.content,style:{...s.computedStyle,left:s.inlineBox.x,top:s.inlineBox.y,width:0,height:0,effects:this.effects}}),"front"),this._subTextsCount++})})})}_drawContent(){var e,t;if(!this.split){const i=(t=(e=this.getChildren())==null?void 0:e.find(s=>"onText2DRender"in s))==null?void 0:t.onText2DRender;i?i():(this._updateText(),this.text.render({pixelRatio:this.texture.pixelRatio,view:this.texture.source})),this.texture.requestUpload(),super._drawContent()}}},$A([U({default:!1})],u.Text2D.prototype,"split",2),$A([U({default:""})],u.Text2D.prototype,"content",2),$A([U()],u.Text2D.prototype,"effects",2),$A([Ee()],u.Text2D.prototype,"measureDom",2),$A([Ee()],u.Text2D.prototype,"fonts",2),u.Text2D=$A([re("Text2D")],u.Text2D);var md=Object.defineProperty,wd=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&md(A,e,i),i};class Qn extends u.Element2D{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":this.requestRedraw();break}}_drawCircle(A,e){this.context.arc(A,e,this.handleSize,0,Math.PI*2,!0),this.context.fillStyle=ve.WHITE,this.context.fill(),this.context.arc(A,e,this.handleSize,0,Math.PI*2,!0),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_drawEllipse(A,e){this.context.roundRect(A-this.handleSize,e-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.fillStyle=ve.WHITE,this.context.fill(),this.context.roundRect(A-this.handleSize,e-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_draw(){const{width:A,height:e}=this.getRect();this.context.rect(0,0,A,e),this.context.strokeStyle="#00FF00",this.context.stroke(),this._drawCircle(0,0),this._drawCircle(A,e),this._drawCircle(0,e),this._drawEllipse(0,e/2),this._drawCircle(A,0),this._drawEllipse(A,e/2)}}wd([U({default:6})],Qn.prototype,"handleSize");var vd=Object.defineProperty,_d=Object.getOwnPropertyDescriptor,El=(r,A,e,t)=>{for(var i=t>1?void 0:t?_d(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&vd(A,e,i),i};u.Video2D=class extends hr{constructor(e,t=[]){super();c(this,"_wait",Promise.resolve());this.setProperties(e),this.append(t)}get videoDuration(){var e;return(((e=this.texture)==null?void 0:e.duration)??0)*1e3}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"src":this._wait=this._load(t);break}}waitLoad(){return this._wait}async _load(e){this.texture=await Nt.video.load(e),(!this.style.width||!this.style.height)&&(this.style.width=this.texture.width,this.style.height=this.texture.height),this.requestRedraw()}_updateVideoCurrentTime(){let e=this._currentTime;if(e<0)return;const t=this.texture;if(!t)return;const i=t.duration;e=i?e%(i*1e3):0,!t.isPlaying&&!t.seeking&&(e=~~e/1e3,t.currentTime!==e&&(t.currentTime=e))}_process(e){this._updateVideoCurrentTime(),super._process(e)}},El([U({default:""})],u.Video2D.prototype,"src",2),u.Video2D=El([re("Video2D")],u.Video2D);var Dd=Object.defineProperty,bd=Object.getOwnPropertyDescriptor,Hi=(r,A,e,t)=>{for(var i=t>1?void 0:t?bd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Dd(A,e,i),i};const pl=r=>r,Cl=ei(.25,.1,.25,1),Ql=ei(.42,0,1,1),yl=ei(0,0,.58,1),ml=ei(.42,0,.58,1);function ei(r,A,e,t){const s=3*r-3*e+1,n=3*e-6*r,o=3*r,a=3*A-3*t+1,l=3*t-6*A,g=3*A,h=C=>(3*s*C+2*n)*C+o,f=C=>((s*C+n)*C+o)*C,I=C=>((a*C+l)*C+g)*C;function d(C){let B=C,R,S;for(let w=0;w<8;w++){if(S=f(B)-C,Math.abs(S)<1e-6)return B;if(R=h(B),Math.abs(R)<1e-6)break;B-=S/R}let _=1,M=0;for(B=C;_>M;){if(S=f(B)-C,Math.abs(S)<1e-6)return B;S>0?_=B:M=B,B=(_+M)/2}return B}return C=>I(d(C))}const Mr={linear:pl,ease:Cl,easeIn:Ql,easeOut:yl,easeInOut:ml};u.Animation=class extends u.TimelineNode{constructor(e,t=[]){super();c(this,"easing");c(this,"_keyframes",[]);c(this,"_isFirstUpdatePosition",!1);c(this,"_cachedProps",new SA);c(this,"_stoped",!1);this.setProperties(e).append(t)}_treeEnter(e){this._updateCachedProps()}_treeExit(e){this.cancel()}_process(){this.canProcess()&&this.commitStyles()}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"effectMode":case"keyframes":this._updateKeyframes();break}}_getTargets(){var t;let e;switch(this.effectMode){case"sibling":e=((t=this.getParent())==null?void 0:t.getChildren(!0).filter(i=>i instanceof u.CanvasItem))??[];break;case"parent":default:e=[this.getParent()].filter(Boolean);break}return e.map(i=>i.style)}_updateKeyframes(){const e=[],t=this.keyframes;for(let n=t.length,o=0;o<n;o++){const{offset:a=o===0?0:o/(n-1),easing:l="linear",...g}=t[o];e.push({offset:a,easing:this._parseEasing(l),props:g})}const i=e[0],s=e[e.length-1];i&&i.offset!==0&&e.unshift({offset:0,easing:this._parseEasing("linear"),props:{}}),s&&s.offset!==1&&e.push({offset:1,easing:this._parseEasing("linear"),props:{}}),this._keyframes=e,this._updateCachedProps()}commitStyles(){if(!this.keyframes.length)return;if(this._updateCurrentTime(),this.isInsideTimeRange())this._isFirstUpdatePosition||(this._isFirstUpdatePosition=!0,this._updateCachedProps());else{if(!this._isFirstUpdatePosition)return;this._isFirstUpdatePosition=!1}const e=this._getTargets(),t=1/e.length,i=this.currentTimeProgress;e.forEach((s,n)=>{const o=t===1?i:bt(0,Math.max(0,i-t*n)/t,1),a=this._cachedProps.get(s);if(!a)return;const l=this._parseKeyframes(o,a);l!=null&&l.length&&this._commitStyle(o,s,a,l[0],l[1])})}_updateCachedProps(){this.cancel(),this._getTargets().forEach(e=>{const t=new Map,i=this._keyframes;for(let s=i.length,n=0;n<s;n++)Object.keys(i[n].props).forEach(o=>{t.set(o,e[o])});this._cachedProps.set(e,t)})}_parseEasing(e){if(!e)return Mr.linear;if(e in Mr)return Mr[e];const t=e.replace(/cubic-bezier\((.+)\)/,"$1").split(",").map(i=>Number(i));return ei(t[0],t[1],t[2],t[3])}_parseKeyframes(e,t){let i;const s=this._keyframes;for(let n=s.length,o=0;o<n;o++){const a=s[o],{offset:l,easing:g}=a,h={...a.props};if(i&&e<=l){const{offset:f,easing:I}=i,d={...i.props};return t.forEach((C,B)=>{(!(B in d)||d[B]===null)&&(d[B]=C),(!(B in h)||h[B]===null)&&(h[B]=C)}),[{offset:f,easing:I,props:d},{offset:l,easing:g,props:h}]}i=a}return null}_commitStyle(e,t,i,s,n){const{offset:o,easing:a,props:l}=s,{offset:g,props:h}=n,f=g-o,I=a((e-o)/f),d={width:t.width,height:t.height,fontSize:t.fontSize};i.forEach((C,B)=>{t[B]=this._getDiffValue(B,l[B],h[B],I,d)})}_getDiffValue(e,t,i,s,n){let o,a;if(t==="none"&&(t=void 0),i==="none"&&(i=void 0),t===void 0||i===void 0)if(t!==void 0)o=ri(e,String(t),n),a=ts(o);else if(i!==void 0)a=ri(e,String(i),n),o=ts(a);else return;else o=ri(e,String(t),n),a=ri(e,String(i),n);if(Array.isArray(o)&&Array.isArray(a)){const l=new Set,g={},h={};o.forEach(({name:I,args:d})=>{g[I]=d,l.add(I)}),a.forEach(({name:I,args:d})=>{h[I]=d,l.add(I)});let f="";return l.forEach(I=>{var R,S;const d=Math.max(((R=g[I])==null?void 0:R.length)??0,((S=h[I])==null?void 0:S.length)??0),C=g[I],B=h[I];f+=`${I}(${Array.from({length:d},(_,M)=>{const w=C==null?void 0:C[M],v=B==null?void 0:B[M],D=(w==null?void 0:w.normalizedIntValue)??0,x=(v==null?void 0:v.normalizedIntValue)??0;return Number.isNaN(D)||Number.isNaN(x)?(v==null?void 0:v.value)??0:Se(D,x,s)}).join(", ")}) `}),f}else if(!Array.isArray(o)&&!Array.isArray(a))return Number.isNaN(o.normalizedIntValue)||Number.isNaN(a.normalizedIntValue)?a.value:Se(o.normalizedIntValue,a.normalizedIntValue,s)}isPlaying(){return!this.paused&&this.isInsideTimeRange()}play(){return this._stoped?(this._stoped=!1,this.startTime=this.timelineCurrentTime):this.startTime=this.timelineCurrentTime-this.currentTime,this.paused=!1,!0}pause(){return this.paused=!0,!0}stop(){return this._stoped=!0,this.paused=!0,this._currentTime=0,!0}cancel(){this._getTargets().forEach(e=>{var t;(t=this._cachedProps.get(e))==null||t.forEach((i,s)=>{e[s]=i}),this._cachedProps.delete(e)})}},Hi([U({default:"parent"})],u.Animation.prototype,"effectMode",2),Hi([U({default:!1})],u.Animation.prototype,"loop",2),Hi([U({default:[]})],u.Animation.prototype,"keyframes",2),Hi([U()],u.Animation.prototype,"easing",2),u.Animation=Hi([re("Animation",{renderMode:"disabled",processMode:"pausable",processSortMode:"parent_before",duration:2e3})],u.Animation);const Or=class Or extends Ot{constructor(){super(...arguments);c(this,"playbackRate",1);c(this,"muted",!1);c(this,"volume",1);c(this,"paused",!1)}static get instance(){return this._instance||(this._instance=new Or),this._instance}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get processors(){return console.warn("HTML Audio does not support processors"),[]}set processors(e){console.warn("HTML Audio does not support processors")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}free(){this.removeAllListeners()}};c(Or,"_instance");let Rr=Or;const Ki=class Ki extends Ot{constructor(){super(...arguments);c(this,"_source",null);c(this,"_audio",null);c(this,"_end",0);c(this,"_pausedReal",!1);c(this,"_duration",0);c(this,"_start",0);c(this,"_playing",!1);c(this,"_paused",!1);c(this,"_playbackRate",1);c(this,"_volume",1);c(this,"_loop",!1);c(this,"_muted",!1);c(this,"_onUpdate",()=>{this._source&&(this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete())})}get progress(){var e;return(((e=this._source)==null?void 0:e.currentTime)??0)/this._duration}get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}set(e,t){if(this[e]===void 0)throw new Error(`Property with name ${e} does not exist.`);switch(e){case"playbackRate":this.playbackRate=t;break;case"volume":this.volume=t;break;case"paused":this.paused=t;break;case"loop":this.loop=t;break;case"muted":this.muted=t;break}return this}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(e){this._playing=!1,this._duration=e.source.duration;const t=this._source=e.source.cloneNode(!1);return t.src=e.parent.src,t.onplay=this._onPlay.bind(this),t.onpause=this._onPause.bind(this),e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this._audio=e,this}_stop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._stop(),this._source&&this.emit("stop")}get processors(){return console.warn("HTML Audio does not support processors"),[]}set processors(e){console.warn("HTML Audio does not support processors")}refresh(){if(!this._audio||!this._source)return;const e=this._audio.context,t=this._audio.parent;this._source.loop=this._loop||t.loop;const i=e.volume*(e.muted?0:1),s=t.volume*(t.muted?0:1),n=this._volume*(this._muted?0:1);this._source.volume=n*i*s,this._source.playbackRate=this._playbackRate*e.playbackRate*t.playbackRate}refreshPaused(){if(!this._source||!this._audio)return;const e=this._paused||this._audio.parent.paused||this._audio.context.paused;e!==this._pausedReal&&(this._pausedReal=e,e?(this._stop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,playbackRate:this._playbackRate,loop:this._loop})),this.emit("pause",e))}play(e={}){if(!this._source)return;const{start:t=0,end:i=0}=e;i&&console.assert(i>t,"End time is before start time"),e.playbackRate!==void 0&&(this._playbackRate=e.playbackRate),e.volume!==void 0&&(this._volume=e.volume),e.loop!==void 0&&(this._loop=e.loop),e.muted!==void 0&&(this._muted=e.muted),this.refresh(),this.loop&&i!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=t,this._end=i||this._duration,this._start=Math.max(0,this._start-Ki.PADDING),this._end=Math.min(this._end+Ki.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=t,this._source.onloadedmetadata=null,this.emit("progress",t,this._duration),xe.on(this._onUpdate))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onComplete(){xe.off(this._onUpdate),this._stop(),this.emit("progress",1,this._duration),this.emit("end",this)}free(){xe.off(this._onUpdate),this.removeAllListeners();const e=this._source;e&&(e.onended=null,e.onplay=null,e.onpause=null,this._stop()),this._source=null,this._playbackRate=1,this._volume=1,this._loop=!1,this._end=0,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._audio&&(this._audio.context.off("refresh",this.refresh),this._audio.context.off("refreshPaused",this.refreshPaused),this._audio=null)}};c(Ki,"PADDING",.1);let kr=Ki;class wl{constructor(A){c(this,"source",new globalThis.Audio);c(this,"_src","");this.parent=A}get src(){return this._src}set src(A){this._src!==A&&(this._src=A,this.load())}get duration(){return this.source.duration}get isPlayable(){return!!this.source&&this.source.readyState===4}get context(){return Rr.instance}async load(){return new Promise(A=>{this.source.onload=()=>A(this),this.source.src=this._src,this.source.load()})}createSound(){return new kr}}class yn extends Ot{constructor(e,t){super();c(this,"_processers",[]);this._input=e,this._output=t}get processors(){return this._processers}set processors(e){if(this._processers.forEach(t=>t.disconnect()),this._processers.length=0,this._input.connect(this._output),e.length){this._processers=e.slice(0),this._input.disconnect();let t;e.forEach(i=>{t?t.connect(i.destination):this._input.connect(i.destination),t=i}),t.connect(this._output)}}get destination(){return this._input}}class xd{constructor(A,e=null){this.destination=A,this.source=e}connect(A){var e;(e=this.source)==null||e.connect(A)}disconnect(){var A;(A=this.source)==null||A.disconnect()}}function Sd(){if(is)return new AudioContext;if(rs){const r=globalThis.webkitAudioContext;return new r}else throw new Error("Failed to createAudioContext")}function Md(r,A,e){if(ss)return new OfflineAudioContext(r,A,e);if(Kn){const t=globalThis.webkitOfflineAudioContext;return new t(r,A,e)}else throw new Error("Failed to createOfflineAudioContext")}const Hr=class Hr extends yn{constructor(){const e=Sd(),t=Md(1,2,ss?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),i=e.createDynamicsCompressor(),s=e.createAnalyser();s.connect(i),i.connect(e.destination);super(s,i);c(this,"_context");c(this,"_offlineContext");c(this,"_locked");c(this,"muted",!1);c(this,"volume",1);c(this,"playbackRate",1);c(this,"autoPause",!0);c(this,"_paused",!1);c(this,"_pausedOnBlur",!1);c(this,"_compressor");c(this,"_analyser");c(this,"_unlock",()=>{this._locked&&(this.playEmptySound(),this._context.state==="running"&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._locked=!1))});this._context=e,this._offlineContext=t,this._compressor=i,this._analyser=s,this._locked=e.state==="suspended"&&(Gt||Jn),ni&&(this._locked&&(this._unlock(),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0)),globalThis.addEventListener("focus",this._onFocus),globalThis.addEventListener("blur",this._onBlur))}static get instance(){return this._instance||(this._instance=new Hr),this._instance}static get audioContext(){return this.instance.audioContext}static get offlineContext(){return this.instance.offlineContext}static setParamValue(e,t){this.instance.setParamValue(e,t)}static decode(e){return this.instance.decode(e)}get audioContext(){return this._context}get offlineContext(){return this._offlineContext}get paused(){return this._paused}set paused(e){e&&this._context.state==="running"?this._context.suspend():!e&&this._context.state==="suspended"&&this._context.resume(),this._paused=e}_onFocus(){if(!this.autoPause)return;const e=this._context.state;(e==="suspended"||e==="interrupted"||!this._locked)&&(this.paused=this._pausedOnBlur,this.refreshPaused())}_onBlur(){this.autoPause&&(this._locked||(this._pausedOnBlur=this._paused,this.paused=!0,this.refreshPaused()))}playEmptySound(){const e=this._context.createBufferSource();e.buffer=this._context.createBuffer(1,1,22050),e.connect(this._context.destination),e.start(0,0,0),e.context.state==="suspended"&&e.context.resume()}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(e){return new Promise((t,i)=>{const s=o=>{i(new Error((o==null?void 0:o.message)||"Unable to decode file"))},n=this._offlineContext.decodeAudioData(e,t,s);n&&n.catch(s)})}setParamValue(e,t){e.setValueAtTime?e.setValueAtTime(t,this._context.currentTime):e.value=t}};c(Hr,"_instance");let lA=Hr;class vl extends Ot{constructor(){super(...arguments);c(this,"_audio",null);c(this,"_sourceNode",null);c(this,"_gain",null);c(this,"_progress",0);c(this,"_pausedReal",!1);c(this,"_paused",!1);c(this,"_volume",1);c(this,"_playbackRate",1);c(this,"_loop",!1);c(this,"_muted",!1);c(this,"_duration",0);c(this,"_end",0);c(this,"_elapsed",0);c(this,"_lastUpdate",this._now());c(this,"_processors",[]);c(this,"_onComplete",()=>{if(this._sourceNode){this._enableTicker(!1),this._sourceNode.onended=null,this._sourceNode.disconnect();try{this._sourceNode.buffer=null}catch(e){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",e)}}this._sourceNode=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)});c(this,"_updateListener",()=>this._update())}get progress(){return this._progress}get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh(),this._update(!0))}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}init(e){return this._audio=e,e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this}_now(){var e;return((e=this._audio)==null?void 0:e.context.audioContext.currentTime)??0}play(e={}){var o;if(!this._audio)return;const{end:t=0,start:i=0}=e;t&&console.assert(t>i,"End time is before start time"),this._end=t,this._elapsed=i,e.volume!==void 0&&(this._volume=e.volume),e.playbackRate!==void 0&&(this._playbackRate=e.playbackRate),e.muted!==void 0&&(this._muted=e.muted),e.loop!==void 0&&(this._loop=e.loop),e.processors!==void 0&&(this._processors=e.processors),this._paused=!1;const{source:s,gain:n}=this._audio.cloneSource();this._sourceNode=s,this._gain=n,this.refresh(),s.onended=this._onComplete.bind(this),this._duration=((o=s.buffer)==null?void 0:o.duration)??0,this._lastUpdate=this._now(),this._loop?(s.loopStart=i,s.loopEnd=t,s.start(0,i)):t?s.start(0,i,t-i):s.start(0,i),this.emit("start"),this._update(!0),this._enableTicker(!0)}_stop(){if(this._sourceNode){this._enableTicker(!1),this._sourceNode.onended=null,this._sourceNode.stop(0),this._sourceNode.disconnect();try{this._sourceNode.buffer=null}catch(e){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",e)}this._sourceNode=null}}stop(){this._sourceNode&&(this._stop(),this.emit("stop"))}_update(e=!1){if(this._sourceNode){const t=this._now(),i=t-this._lastUpdate;if(i>0||e){this._elapsed+=i*this._sourceNode.playbackRate.value,this._lastUpdate=t;const s=this._duration;let n;if(this._sourceNode.loopStart){const o=this._sourceNode.loopEnd-this._sourceNode.loopStart;n=(this._sourceNode.loopStart+this._elapsed%o)/s}else n=this._elapsed%s/s;this._progress=n,this.emit("progress",n,s)}}}refresh(){if(!this._audio||!this._sourceNode)return;const e=this._audio.context,t=this._audio.parent;this._sourceNode.loop=this._loop||t.loop,e.setParamValue(this._gain.gain,this._volume*(this._muted?0:1)*t.volume*(t.muted?0:1)*e.volume*(e.muted?0:1)),e.setParamValue(this._sourceNode.playbackRate,this._playbackRate*t.playbackRate*e.playbackRate),this.applyProcessors()}applyProcessors(){if(this._sourceNode&&this._processors.length){this._sourceNode.disconnect();let e=this._sourceNode;this._processors.forEach(t=>{e.connect(t.destination),e=t}),e.connect(this._gain)}}refreshPaused(){if(!this._audio)return;const e=this._paused||this._audio.parent.paused||this._audio.context.paused;e!==this._pausedReal&&(this._pausedReal=e,e?(this._stop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,playbackRate:this._playbackRate,loop:this._loop,volume:this._volume})),this.emit("pause",e))}_enableTicker(e){xe.off(this._updateListener),e&&xe.on(this._updateListener)}free(){var e,t,i;this.removeAllListeners(),this._stop(),(e=this._gain)==null||e.disconnect(),this._gain=null,(t=this._audio)==null||t.context.off("refresh",this.refresh),(i=this._audio)==null||i.context.off("refreshPaused",this.refreshPaused),this._audio=null,this._processors.forEach(s=>s.disconnect()),this._processors.length=0,this._end=0,this._playbackRate=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}}class _l extends yn{constructor(e){const t=lA.audioContext,i=t.createBufferSource(),s=t.createGain(),n=t.createAnalyser();i.connect(n),n.connect(s),s.connect(lA.instance.destination);super(n,s);c(this,"_sourceBuffer");c(this,"_sourceNode");c(this,"_sourceLoad");c(this,"gain");c(this,"analyser");this.parent=e,this._sourceNode=i,this.gain=s,this.analyser=n}get context(){return lA.instance}get isPlayable(){return!!this._sourceNode.buffer}get duration(){var e;return((e=this._sourceNode.buffer)==null?void 0:e.duration)??0}get buffer(){return this._sourceNode.buffer}set buffer(e){this._sourceNode.buffer=e}async load(){return this._sourceLoad||(this._sourceLoad=new Promise(e=>{this._sourceBuffer?this._decode(this._sourceBuffer).then(()=>e(this)):this.parent.src?this._loadUrl(this.parent.src).then(()=>e(this)):e(this)})),this._sourceLoad}_loadUrl(e){return new Promise(t=>{fetch(e).then(i=>i.arrayBuffer()).then(i=>this._decode(i)).finally(()=>t(this))})}_decode(e){return Promise.resolve(e instanceof AudioBuffer?e:lA.decode(e)).then(t=>(this.parent.isLoaded=!0,this.buffer=t,t))}cloneSource(){const e=this.context,t=this._sourceNode,i=e.audioContext.createBufferSource(),s=e.audioContext.createGain();return i.buffer=t.buffer,i.loop=t.loop,e.setParamValue(i.playbackRate,t.playbackRate.value),i.connect(s),s.connect(this.destination),{source:i,gain:s}}createSound(){return new vl}}var Rd=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Ud=(r,A,e)=>A in r?Rd(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,Pd=(r,A,e,t)=>{for(var i=t>1?void 0:t?kd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i},Nd=(r,A,e)=>Ud(r,A+"",e);u.Audio=class extends u.TimelineNode{constructor(e=""){super();c(this,"_sounds",[]);c(this,"_platformAudio",Yn?new _l(this):new wl(this));c(this,"_src");c(this,"isLoaded",!1);c(this,"_volume",1);c(this,"_muted",!1);c(this,"_loop",!1);c(this,"_playbackRate",1);c(this,"_isPlaying",!1);c(this,"multiple",!1);c(this,"start",0);c(this,"end",0);c(this,"_onComplete",e=>{if(this._sounds){const t=this._sounds.indexOf(e);t>-1&&this._sounds.splice(t,1),this._isPlaying=this._sounds.length>0}this._recycleSound(e)});c(this,"_prevTime",0);c(this,"_timer",0);this.src=e}get platformAudio(){return this._platformAudio}get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}get isPlayable(){return this.isLoaded&&this._platformAudio.isPlayable}get audioDuration(){return this._platformAudio.duration*1e3}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}get isPlaying(){return this._isPlaying}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"paused":this.refreshPaused();break}}async load(){return await this._platformAudio.load(),this}pause(){return this._isPlaying=!1,this.paused=!0,this}resume(){return this._isPlaying=this._sounds.length>0,this.paused=!1,this}stop(){if(!this.isPlayable)return this;this._isPlaying=!1;for(let e=this._sounds.length-1;e>=0;e--)this._sounds[e].stop();return this}play(e={}){if(!this.isLoaded)return;this.multiple||this._removeSounds(),this._isPlaying=!0;const t=this._createSound();this._sounds.push(t),t.once("end",()=>{var n;(n=e.complete)==null||n.call(e),this._onComplete(t)}),t.once("stop",()=>this._onComplete(t));const i=((e==null?void 0:e.start)??this.start)/1e3,s=((e==null?void 0:e.end)??this.end)/1e3;return t.play({...e,start:i,end:s}),t}_removeSounds(){for(let e=this._sounds.length-1;e>=0;e--)this._recycleSound(this._sounds[e]);this._sounds.length=0}_createSound(){return u.Audio._soundPool.length>0?u.Audio._soundPool.pop().init(this._platformAudio):this._platformAudio.createSound().init(this._platformAudio)}refresh(){for(let e=this._sounds.length,t=0;t<e;t++)this._sounds[t].refresh()}refreshPaused(){for(let e=this._sounds.length,t=0;t<e;t++)this._sounds[t].refreshPaused()}_recycleSound(e){e.free(),u.Audio._soundPool.includes(e)||u.Audio._soundPool.push(e)}_process(e){var t;if(super._process(e),this.canProcess()){const i=((t=this._tree)==null?void 0:t.timeline.currentTime)??0;i-this._prevTime>0&&(this._timer||(this._setTimeStop(),this.play({start:this.start+(i-this.delay)%this.duration})),this._isPlaying&&this._setTimeStop()),this._prevTime=i}}_setTimeStop(){this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this.stop(),this._timer=0},100)}},Nd(u.Audio,"_soundPool",[]),u.Audio=Pd([re("Audio")],u.Audio);class Fd extends u.Node2D{}var Td=Object.defineProperty,Ld=Object.getOwnPropertyDescriptor,Ur=(r,A,e,t)=>{for(var i=t>1?void 0:t?Ld(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Td(A,e,i),i};u.AudioWaveform=class extends u.Element2D{constructor(e={}){super();c(this,"src");c(this,"gap",0);c(this,"color","#000000");c(this,"_audioBuffer");c(this,"_src",ni?new ve(document.createElement("canvas")):void 0);c(this,"_needsUpdateTexture",!1);this.setProperties(e)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"src":this._loadSrc(t);break;case"gap":case"color":case"width":case"height":this._needsUpdateTexture=!0;break}}async _loadSrc(e){await globalThis.fetch(e).then(t=>t.arrayBuffer()).then(t=>lA.decode(t)).then(t=>{this._audioBuffer=t,this.syncTexture(!0)})}syncTexture(e=!1){var h,f;const t=this._audioBuffer;if(!t||!e&&!this._needsUpdateTexture)return;this._needsUpdateTexture=!1;const i=(h=this._src)==null?void 0:h.source;if(!i)return;const{width:s=0,height:n=0}=this.style;i.width=s,i.height=n;const o=i.getContext("2d");if(!o){console.warn("Failed to getContext('2d') in syncTexture");return}o.fillStyle=this.color;const a=t.getChannelData(0),l=Math.ceil(a.length/s),g=n/2;for(let I=1,d=-1,C=0;C<s;C++){for(let B=0;B<l;B++){const R=a[C*l+B];R<I&&(I=R),R>d&&(d=R)}if(!this.gap||C%(this.gap*2)===0){const B=C,R=(1+I)*g,S=this.gap||1,_=Math.max(1,(d-I)*g);o.fillRect(B,R,S,_),I=1,d=-1}}(f=this._src)==null||f.requestUpload(),this.requestRedraw()}_process(e){this.syncTexture(),super._process(e)}_drawSrc(){const e=this._src;e!=null&&e.valid&&(this.context.fillStyle=e,this.context.textureTransform=new Qt().scale(1/this.style.width,1/this.style.height))}},Ur([U()],u.AudioWaveform.prototype,"src",2),Ur([U()],u.AudioWaveform.prototype,"gap",2),Ur([U()],u.AudioWaveform.prototype,"color",2),u.AudioWaveform=Ur([re("AudioWaveform")],u.AudioWaveform);var Gd=Object.getOwnPropertyDescriptor,Od=(r,A,e,t)=>{for(var i=t>1?void 0:t?Gd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.Control=class extends u.Element2D{constructor(A,e=[]){super(),this._parentUpdateRect=this._parentUpdateRect.bind(this),this.setProperties(A),this.append(e)}_parented(A){super._parented(A),A.on("updateRect",this._parentUpdateRect)}_unparented(A){super._unparented(A),A.off("updateRect",this._parentUpdateRect)}_parentUpdateRect(){const A=this._parent.getRect();this.style.left=A.left,this.style.top=A.top,this.style.width=A.width,this.style.height=A.height}_input(A,e){super._input(A,e),this._guiInput(A,e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":case"left":case"top":this.emit("updateRect");break}}_guiInput(A,e){}},u.Control=Od([re("Control")],u.Control);var Hd=Object.defineProperty,Jd=Object.getOwnPropertyDescriptor,gA=(r,A,e,t)=>{for(var i=t>1?void 0:t?Jd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Hd(A,e,i),i};u.Range=class extends u.Control{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateProperty(A,e,t,i){switch(super._updateProperty(A,e,t,i),A){case"allowGreater":case"allowLesser":case"page":case"minValue":case"maxValue":case"step":case"value":this.requestRedraw();break}}},gA([U({default:!1})],u.Range.prototype,"allowGreater",2),gA([U({default:!1})],u.Range.prototype,"allowLesser",2),gA([U({default:1})],u.Range.prototype,"page",2),gA([U({default:0})],u.Range.prototype,"minValue",2),gA([U({default:100})],u.Range.prototype,"maxValue",2),gA([U({default:.01})],u.Range.prototype,"step",2),gA([U({default:0})],u.Range.prototype,"value",2),u.Range=gA([re("Range")],u.Range);var Kd=Object.defineProperty,Yd=Object.getOwnPropertyDescriptor,Pt=(r,A,e,t)=>{for(var i=t>1?void 0:t?Yd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Kd(A,e,i),i};u.Ruler=class extends u.Control{constructor(e,t=[]){super();c(this,"texture",new gi);this.setProperties(e),this.append(t)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"offsetX":case"offsetY":case"thickness":case"markHeight":case"color":case"markBackgroundColor":case"markColor":case"gap":case"scale":this.requestRedraw();break}}_updateStyleProperty(e,t,i,s){switch(super._updateStyleProperty(e,t,i,s),e){case"width":case"height":this.texture[e]=t,this.requestRedraw();break}}_drawTexture(){const{width:e,height:t}=this.size,{offsetX:i,offsetY:s,thickness:n,markHeight:o,markBackgroundColor:a,markColor:l,color:g,gap:h,gapScale:f}=this,d=this.texture.source.getContext("2d");d.reset(),d.scale(this.texture.pixelRatio,this.texture.pixelRatio);const C=Math.round(i),B=Math.round(s);d.beginPath(),d.fillStyle=a||"#EEE",d.fillRect(0,0,e,n),d.fillRect(0,0,n,t),d.fill(),d.strokeStyle=l||"#000",d.moveTo(n,0),d.lineTo(n,t),d.moveTo(0,n),d.lineTo(e,n),d.stroke();const R=h,S=h*f;let _,M,w,v,D;for(R>=S?(_=R/S,M=Math.floor(_)*R/20,w=R/20*Math.floor(_)/_):(_=S/R,M=Math.floor(R/20/_),M>=2?M=Math.floor(M/2)*2:M=1,w=M*_),d.fillStyle=d.strokeStyle,v=C,D=0;v<e;D++,v+=w)d.moveTo(v,n-(D%5?o:2*o)),d.lineTo(v,n);for(v=C,D=0;v>n;D++,v-=w)d.moveTo(v,n-(D%5?o:2*o)),d.lineTo(v,n);let x=0;for(v=B,D=0;v>n;D++,v-=w)d.moveTo(n-(D%5?o:2*o),v),d.lineTo(n,v);for(v=B,D=0;v<t;D++,v+=w)d.moveTo(n-(D%5?o:2*o),v),d.lineTo(n,v);for(d.save(),d.fillStyle=g,d.scale(.8,.8),x=n-8,v=C,D=0;v<e;D++,v+=w)D%10===0&&d.fillText(String(Math.ceil(M*D)),v*1.25-3,x*1.25);for(v=C,D=0;v>n;D++,v-=w)D%10===0&&d.fillText(String(Math.ceil(-M*D)),v*1.25-3,x*1.25);for(x=0,v=B,D=0;v>n;D++,v-=w)D%10===0&&d.fillText(String(Math.ceil(M*D)),x*1.25,v*1.25+3);for(v=B,D=0;v<t;D++,v+=w)D%10===0&&d.fillText(String(Math.ceil(-M*D)),x*1.25,v*1.25+3);d.restore(),d.stroke(),this.texture.requestUpload()}_draw(){this._drawTexture();const e=this.texture;e!=null&&e.valid&&(this.context.fillStyle=e,this.context.textureTransform=new Qt().scale(1/this.size.width,1/this.size.height),this.context.rect(0,0,e.width,e.height),this.context.fill())}},Pt([U({default:0})],u.Ruler.prototype,"offsetX",2),Pt([U({default:0})],u.Ruler.prototype,"offsetY",2),Pt([U({default:20})],u.Ruler.prototype,"thickness",2),Pt([U({default:3})],u.Ruler.prototype,"markHeight",2),Pt([U({default:"#b2b6bc"})],u.Ruler.prototype,"color",2),Pt([U({default:"#f9f9fa"})],u.Ruler.prototype,"markBackgroundColor",2),Pt([U({default:"#b2b6bc"})],u.Ruler.prototype,"markColor",2),Pt([U({default:300})],u.Ruler.prototype,"gap",2),Pt([U({default:1})],u.Ruler.prototype,"gapScale",2),u.Ruler=Pt([re("Ruler")],u.Ruler);var Wd=Object.defineProperty,Vd=Object.getOwnPropertyDescriptor,Dl=(r,A,e,t)=>{for(var i=t>1?void 0:t?Vd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Wd(A,e,i),i};u.ScrollBar=class extends u.Range{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":case"left":case"top":this.requestRedraw();break}}_rect(){const{size:A,position:e}=this;let t,i,s,n,o;return this.direction==="vertical"?(s=10,n=A.height*(this.page/(this.maxValue-this.minValue)),t=e.left+A.width-s,i=A.height*(this.value/(this.maxValue-this.minValue)),o=s/2):(s=A.width*(this.page/(this.maxValue-this.minValue)),n=10,t=A.width*(this.value/(this.maxValue-this.minValue)),i=e.top+A.height-n,o=n/2),{left:t,top:i,width:s,height:n,radii:o}}_draw(){const{left:A,top:e,width:t,height:i,radii:s}=this._rect();this.context.roundRect(A,e,t,i,s),this.context.fillStyle=34,this.context.fill()}_pointerInput(A,e){var a,l;const{left:t,top:i,width:s,height:n}=this._rect(),o=A.x>=t&&A.x<t+s&&A.y>=i&&A.y<i+n;switch(e){case"pointerdown":case"pointermove":o?(a=this._tree)==null||a.input.setCursor("pointer"):(l=this._tree)==null||l.input.setCursor(void 0);break}return!1}},Dl([U({default:"vertical"})],u.ScrollBar.prototype,"direction",2),u.ScrollBar=Dl([re("ScrollBar")],u.ScrollBar);var zd=Object.getOwnPropertyDescriptor,qd=(r,A,e,t)=>{for(var i=t>1?void 0:t?zd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.XScrollBar=class extends u.ScrollBar{constructor(A,e=[]){super(),this.setProperties(A).append(e)}},u.XScrollBar=qd([re("XScrollBar",{direction:"horizontal"})],u.XScrollBar);var Xd=Object.getOwnPropertyDescriptor,jd=(r,A,e,t)=>{for(var i=t>1?void 0:t?Xd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.YScrollBar=class extends u.ScrollBar{constructor(A,e=[]){super(),this.setProperties(A).append(e)}},u.YScrollBar=jd([re("YScrollBar",{direction:"vertical"})],u.YScrollBar);var Zd=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,Pr=(r,A,e,t)=>{for(var i=t>1?void 0:t?$d(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Zd(A,e,i),i};u.Scaler=class extends u.Node{get target(){var A;if((A=this.parent)!=null&&A.style)return this.parent}constructor(A,e=[]){super(),this.setProperties(A),this.append(e)}_updateProperty(A,e,t,i){switch(super._updateProperty(A,e,t,i),A){case"value":case"min":case"max":{this.value=bt(this.minValue,this.value,this.maxValue),this._updateScale();break}}}_updateScale(){const A=this.target;A&&(A.style.scaleX=this.value,A.style.scaleY=this.value,this.emit("updateScale",this.value))}_onWheel(A){if(!this.target)return;if(A.preventDefault(),!(A.wheelDeltaY?Math.abs(Math.abs(A.wheelDeltaY)-Math.abs(3*A.deltaY))<3:A.deltaMode===0)&&A.ctrlKey){A.preventDefault();let i=A.deltaY/(A.ctrlKey?1:100);i*=-.015,this.value+=i}}_input(A,e){switch(super._input(A,e),e){case"wheel":this._onWheel(A);break}}},Pr([U({default:1})],u.Scaler.prototype,"value",2),Pr([U({default:.05})],u.Scaler.prototype,"minValue",2),Pr([U({default:10})],u.Scaler.prototype,"maxValue",2),u.Scaler=Pr([re("Scaler",{processMode:"disabled",renderMode:"disabled"})],u.Scaler);var eI=Object.defineProperty,tI=Object.getOwnPropertyDescriptor,AI=(r,A,e)=>A in r?eI(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,iI=(r,A,e,t)=>{for(var i=t>1?void 0:t?tI(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i},rI=(r,A,e)=>AI(r,A+"",e);u.KawaseTransition=class extends u.Transition{constructor(){super(...arguments);c(this,"blur",10);c(this,"quality",10)}apply(e,t){const i=this.currentTimeProgress;let s,n;i<.5?(s=0,n=(.5-i)/.5):(s=1,n=(i-.5)/.5);const o=this.blur,a=this.quality,l=t.width,g=t.height,h=[],f=[o];if(o>0){let S=o;const _=o/a;for(let M=1;M<a;M++)S-=_,f.push(S)}const I=1/l,d=1/g,C=[];let B;const R=a-1;for(let S=0;S<R;S++)B=f[S]+.5,C[0]=B*I,C[1]=B*d,h.push({offset:C});B=f[R]+.5,C[0]=B*I,C[1]=B*d,h.push({offset:C}),h.forEach(S=>{fe.draw(e,u.KawaseTransition.material,{sampler:s,progress:n,...S})})}},rI(u.KawaseTransition,"material",new Qe({vert:`attribute vec2 position;
776
+ </svg>`}function dd(){const r=[];return{name:"listStyle",paths:r,update:A=>{r.length=0;const{paragraphs:e,isVertical:t,fontSize:i}=A,s=i*.45;e.forEach(n=>{const{computedStyle:o}=n,{color:a,listStyleImage:l,listStyleColormap:g,listStyleSize:h,listStyleType:f}=o,I=Il(g);let d=h,C;if(!nA(l))C=l;else if(!nA(f)){const _=i*.38/2;switch(d=d==="cover"?_*2:d,f){case"disc":C=fd(_,String(a));break}}if(!C)return;const B=Sa(C),R=B.getBoundingBox();let S;n.fragments.forEach(_=>{_.characters.forEach(M=>{const{inlineBox:w}=M;if(t?(S==null?void 0:S.inlineBox.left)!==w.left:(S==null?void 0:S.inlineBox.top)!==w.top){S=M;const v=d==="cover"?1:fn(d,{total:i,fontSize:i})/i,D=new ot;if(t){const x=i/R.height*v;D.translate(-R.left,-R.top).rotate(Math.PI/2).scale(x,x).translate(w.left+(w.width-R.height*x)/2,w.top-s)}else{const x=i/R.height*v;D.translate(-R.left,-R.top).scale(x,x).translate(w.left-R.width*x-s,w.top+(w.height-R.height*x)/2)}r.push(...B.paths.map(x=>{const L=x.clone();return L.applyTransform(D),L.style.fill&&L.style.fill in I&&(L.style.fill=I[L.style.fill]),L.style.stroke&&L.style.stroke in I&&(L.style.stroke=I[L.style.stroke]),L}))}})})})}}}function Id(){return{name:"outline"}}const oA=new G,ZA=new ot,aA=new ot;function Bd(){return{name:"render",getBoundingBox:r=>{const{characters:A,fontSize:e,effects:t}=r,i=[];return A.forEach(s=>{t==null||t.forEach(n=>{if(!s.glyphBox)return;const o=s.glyphBox.clone(),a=pn(r,n);oA.set(o.left,o.top),oA.applyMatrix3(a),o.left=oA.x,o.top=oA.y,oA.set(o.right,o.bottom),oA.applyMatrix3(a),o.width=oA.x-o.left,o.height=oA.y-o.top;const l=(n.shadowOffsetX??0)*e,g=(n.shadowOffsetY??0)*e,h=Math.max(.1,n.textStrokeWidth??0)*e;o.left+=l-h,o.top+=g-h,o.width+=h*2,o.height+=h*2,i.push(o)})}),i.length?ce.from(...i):void 0},render:(r,A)=>{const{paragraphs:e,glyphBox:t,effects:i,style:s}=A;function n(o,a){r.fillStyle=o,r.fillRect(a.left,a.top,a.width,a.height)}s!=null&&s.backgroundColor&&n(s.backgroundColor,new ce(0,0,r.canvas.width,r.canvas.height)),e.forEach(o=>{var a;(a=o.style)!=null&&a.backgroundColor&&n(o.style.backgroundColor,o.lineBox)}),i?i.forEach(o=>{Sr(o,t,r),r.save();const[a,l,g,h,f,I]=pn(A,o).transpose().elements;r.transform(a,h,l,f,g,I),A.forEachCharacter(d=>{var C;(C=d.parent.style)!=null&&C.backgroundColor&&n(d.parent.style.backgroundColor,d.inlineBox),d.drawTo(r,o)}),r.restore()}):e.forEach(o=>{o.fragments.forEach(a=>{var l;(l=a.style)!=null&&l.backgroundColor&&n(a.computedStyle.backgroundColor,a.inlineBox),a.characters.forEach(g=>{g.drawTo(r)})})}),A.debug&&e.forEach(o=>{r.strokeRect(o.lineBox.x,o.lineBox.y,o.lineBox.width,o.lineBox.height)})}}}function pn(r,A){const{fontSize:e,glyphBox:t}=r,i=(A.translateX??0)*e,s=(A.translateY??0)*e,n=Math.PI*2,o=(A.skewX??0)/360*n,a=(A.skewY??0)/360*n,{left:l,top:g,width:h,height:f}=t,I=l+h/2,d=g+f/2;return ZA.identity(),aA.makeTranslation(i,s),ZA.multiply(aA),aA.makeTranslation(I,d),ZA.multiply(aA),aA.set(1,Math.tan(o),0,Math.tan(a),1,0,0,0,1),ZA.multiply(aA),aA.makeTranslation(-I,-d),ZA.multiply(aA),ZA.clone()}function Ed(){const r=[];return{name:"textDecoration",paths:r,update:A=>{r.length=0;const e=[];let t,i;A.forEachCharacter(s=>{const{computedStyle:n,isVertical:o,inlineBox:a,underlinePosition:l,underlineThickness:g,strikeoutPosition:h,strikeoutSize:f}=s,{color:I,textDecoration:d,writingMode:C}=n;if(nA(d))i=void 0;else{let B=!1;if((i==null?void 0:i.textDecoration)===d&&(i==null?void 0:i.writingMode)===C&&(i==null?void 0:i.color)===I&&(o?t[0].inlineBox.left===a.left:t[0].inlineBox.top===a.top))switch(d){case"underline":t[0].underlinePosition===l&&t[0].underlineThickness===g&&(B=!0);break;case"line-through":t[0].strikeoutPosition===h&&t[0].strikeoutSize===f&&(B=!0);break}B?t.push(s):(t=[],t.push(s),e.push(t)),i=n}}),e.forEach(s=>{const{computedStyle:n,isVertical:o,underlinePosition:a,underlineThickness:l,strikeoutPosition:g,strikeoutSize:h}=s[0],{color:f,textDecoration:I}=n,{left:d,top:C,width:B,height:R}=ce.from(...s.map(v=>v.inlineBox));let S=o?d+B:C;const _=o?-1:1;let M=0;switch(I){case"overline":M=l*2;break;case"underline":S+=_*a,M=l*2;break;case"line-through":S+=_*g,M=h*2;break}S-=M;let w;o?w=new He([{type:"M",x:S,y:C},{type:"L",x:S,y:C+R},{type:"L",x:S+M,y:C+R},{type:"L",x:S+M,y:C},{type:"Z"}],{fill:f}):w=new He([{type:"M",x:d,y:S},{type:"L",x:d+B,y:S},{type:"L",x:d+B,y:S+M},{type:"L",x:d,y:S+M},{type:"Z"}],{fill:f}),r.push(w)})},render:(A,e)=>{const{effects:t,computedStyle:i}=e;t?t.forEach(s=>{A.save();const[n,o,a,l,g,h]=pn(e,s).transpose().elements;A.transform(n,l,o,g,a,h),r.forEach(f=>{Gi({ctx:A,path:f,fontSize:i.fontSize,...s})}),A.restore()}):r.forEach(s=>{Gi({ctx:A,path:s,fontSize:i.fontSize})})}}}const Cn=ka();class pd extends hd{constructor(e={}){super();c(this,"debug");c(this,"content");c(this,"style");c(this,"effects");c(this,"measureDom");c(this,"needsUpdate",!0);c(this,"computedStyle",{...Cn});c(this,"paragraphs",[]);c(this,"lineBox",new ce);c(this,"rawGlyphBox",new ce);c(this,"glyphBox",new ce);c(this,"pathBox",new ce);c(this,"boundingBox",new ce);c(this,"measurer",new Bn);c(this,"plugins",new Map);c(this,"fonts");this.debug=e.debug??!1,this.content=e.content??"",this.style=e.style??{},this.measureDom=e.measureDom,this.effects=e.effects,this.fonts=e.fonts,this.use(cd()).use(Id()).use(dd()).use(Ed()).use(ud()).use(Bd()),this.updateParagraphs()}get fontSize(){return this.computedStyle.fontSize}get isVertical(){return this.computedStyle.writingMode.includes("vertical")}get characters(){return this.paragraphs.flatMap(e=>e.fragments.flatMap(t=>t.characters))}use(e){return this.plugins.set(e.name,e),this}forEachCharacter(e){return this.paragraphs.forEach((t,i)=>{t.fragments.forEach((s,n)=>{s.characters.forEach((o,a)=>{e(o,{paragraphIndex:i,fragmentIndex:n,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(e=>{var t;return(t=e.load)==null?void 0:t.call(e,this)}))}updateParagraphs(){this.computedStyle={...Cn,...this.style};let{content:e,computedStyle:t}=this;const i=[];if(typeof e=="string"){const s=new Oi({},t);s.addFragment(e),i.push(s)}else{e=Array.isArray(e)?e:[e];for(const s of e)if(typeof s=="string"){const n=new Oi({},t);n.addFragment(s),i.push(n)}else if(Array.isArray(s)){const n=new Oi({},t);s.forEach(o=>{if(typeof o=="string")n.addFragment(o);else{const{content:a,...l}=o;a!==void 0&&n.addFragment(a,l)}}),i.push(n)}else if("fragments"in s){const{fragments:n,...o}=s,a=new Oi(o,t);n.forEach(l=>{const{content:g,...h}=l;g!==void 0&&a.addFragment(g,h)}),i.push(a)}else if("content"in s){const{content:n,...o}=s;if(n!==void 0){const a=new Oi(o,t);a.addFragment(n),i.push(a)}}}return this.paragraphs=i,this}measure(e=this.measureDom){const t={paragraphs:this.paragraphs,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this.updateParagraphs();const i=this.measurer.measure(this.paragraphs,this.computedStyle,e);this.paragraphs=i.paragraphs,this.lineBox=i.boundingBox,this.characters.forEach(s=>{s.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((s,n)=>(s.updateOrder??0)-(n.updateOrder??0)).forEach(s=>{var n;(n=s.update)==null||n.call(s,this)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const s in t)i[s]=this[s],this[s]=t[s];return this.emit("measure",{text:this,result:i}),i}getGlyphBox(){const e=G.MAX,t=G.MIN;return this.characters.forEach(i=>{if(!i.getGlyphMinMax(e,t)){const{inlineBox:s}=i,n=new G(s.left,s.top),o=new G(s.left+s.width,s.top+s.height);e.min(n,o),t.max(n,o)}}),new ce(e.x,e.y,t.x-e.x,t.y-e.y)}updatePathBox(){return this.pathBox=ce.from(this.glyphBox,...Array.from(this.plugins.values()).map(e=>e.getBoundingBox?e.getBoundingBox(this):new Ts(e.paths??[]).getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){const{lineBox:e,rawGlyphBox:t,pathBox:i}=this,s=Math.min(i.left,i.left+e.left-t.left),n=Math.min(i.top,i.top+e.top-t.top),o=Math.max(i.right,i.right+e.right-t.right),a=Math.max(i.bottom,i.bottom+e.bottom-t.bottom);return this.boundingBox=new ce(s,n,o-s,a-n),this}requestUpdate(){return this.needsUpdate=!0,this}update(){const e=this.measure();for(const t in e)this[t]=e[t];return this.emit("update",{text:this}),this.needsUpdate=!1,this}render(e){const{view:t,pixelRatio:i=2}=e,s=t.getContext("2d");s&&(this.needsUpdate&&this.update(),Ad(s,i,this.boundingBox),id(s,this),Array.from(this.plugins.values()).sort((n,o)=>(n.renderOrder??0)-(o.renderOrder??0)).forEach(n=>{var o;if(n.render)(o=n.render)==null||o.call(n,s,this);else if(n.paths){const a=this.computedStyle;n.paths.forEach(l=>{Gi({ctx:s,path:l,fontSize:a.fontSize})})}}),this.emit("render",{text:this,view:t,pixelRatio:i}))}}var Cd=Object.defineProperty,Qd=Object.getOwnPropertyDescriptor,$A=(r,A,e,t)=>{for(var i=t>1?void 0:t?Qd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Cd(A,e,i),i};const yd=new Set(Object.keys(Cn));u.Text2D=class extends hr{constructor(e,t=[]){super();c(this,"effects");c(this,"measureDom");c(this,"fonts");c(this,"texture",new gi);c(this,"text",new pd);c(this,"measureResult");c(this,"_subTextsCount",0);this.setProperties(e),this.append(t)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"content":case"effects":case"measureDom":case"fonts":case"split":this._updateSplit(),this.requestRedraw();break}this._subTextsCount&&e==="effects"&&this._getSubTexts().forEach(n=>{n.setProperties({[e]:t})})}_updateText(){this.text.style=this.style.toJSON(),this.text.content=this.content??"",this.text.effects=this.effects,this.text.fonts=this.fonts,this.text.measureDom=this.measureDom,this.text.requestUpdate()}_updateStyleProperty(e,t,i){switch(e){case"left":case"top":case"width":case"height":this.requestRedraw();break;default:super._updateStyleProperty(e,t,i);break}switch(e){case"width":this.split&&this._updateSubTexts();break}typeof e=="string"&&yd.has(e)&&(this._subTextsCount&&e!=="width"&&e!=="height"&&this._getSubTexts().forEach(s=>{s.style.setProperties({[e]:t})}),this.requestRedraw())}_getSubTexts(){return this.getChildren("front").filter(e=>e instanceof u.Text2D)}_updateSubTexts(){var i;const e=this._getSubTexts();let t=0;this.split&&((i=this.updateMeasure().measureResult)==null||i.paragraphs.forEach(s=>{s.fragments.forEach(n=>{n.characters.forEach(o=>{const a=e[t];a&&(a.style.left=o.inlineBox.left,a.style.top=o.inlineBox.top),t++})})}))}measure(){return this._updateText(),this.text.measure()}updateMeasure(){this.measureResult=this.measure();const e=this.measureResult.boundingBox.width,t=this.measureResult.boundingBox.height,{left:i,top:s,width:n,height:o=t}=this.style;return this.position.x=i+Math.min(0,((n||e)-e)/2),this.position.y=s+Math.min(0,((o||t)-t)/2),this.size.width=e,this.size.height=t,this}_updateSplit(){var e;this._subTextsCount&&(this.getChildren("front").forEach(t=>this.removeChild(t)),this._subTextsCount=0),this.split&&((e=this.measureResult)==null||e.paragraphs.forEach(t=>{t.fragments.forEach(i=>{i.characters.forEach(s=>{this.appendChild(new u.Text2D({content:s.content,style:{...s.computedStyle,left:s.inlineBox.x,top:s.inlineBox.y,width:0,height:0,effects:this.effects}}),"front"),this._subTextsCount++})})}))}_redraw(){return this.updateMeasure(),super._redraw()}_drawContent(){var e,t;if(!this.split){const i=(t=(e=this.getChildren())==null?void 0:e.find(s=>"onText2DRender"in s))==null?void 0:t.onText2DRender;i?i():this.text.render({pixelRatio:this.texture.pixelRatio,view:this.texture.source}),this.texture.requestUpload(),super._drawContent()}}},$A([U({default:!1})],u.Text2D.prototype,"split",2),$A([U({default:""})],u.Text2D.prototype,"content",2),$A([U()],u.Text2D.prototype,"effects",2),$A([Ee()],u.Text2D.prototype,"measureDom",2),$A([Ee()],u.Text2D.prototype,"fonts",2),u.Text2D=$A([re("Text2D")],u.Text2D);var md=Object.defineProperty,wd=(r,A,e,t)=>{for(var i=void 0,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(A,e,i)||i);return i&&md(A,e,i),i};class Qn extends u.Element2D{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":this.requestRedraw();break}}_drawCircle(A,e){this.context.arc(A,e,this.handleSize,0,Math.PI*2,!0),this.context.fillStyle=ve.WHITE,this.context.fill(),this.context.arc(A,e,this.handleSize,0,Math.PI*2,!0),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_drawEllipse(A,e){this.context.roundRect(A-this.handleSize,e-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.fillStyle=ve.WHITE,this.context.fill(),this.context.roundRect(A-this.handleSize,e-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_draw(){const{width:A,height:e}=this.getRect();this.context.rect(0,0,A,e),this.context.strokeStyle="#00FF00",this.context.stroke(),this._drawCircle(0,0),this._drawCircle(A,e),this._drawCircle(0,e),this._drawEllipse(0,e/2),this._drawCircle(A,0),this._drawEllipse(A,e/2)}}wd([U({default:6})],Qn.prototype,"handleSize");var vd=Object.defineProperty,_d=Object.getOwnPropertyDescriptor,El=(r,A,e,t)=>{for(var i=t>1?void 0:t?_d(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&vd(A,e,i),i};u.Video2D=class extends hr{constructor(e,t=[]){super();c(this,"_wait",Promise.resolve());this.setProperties(e),this.append(t)}get videoDuration(){var e;return(((e=this.texture)==null?void 0:e.duration)??0)*1e3}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"src":this._wait=this._load(t);break}}waitLoad(){return this._wait}async _load(e){this.texture=await Nt.video.load(e),(!this.style.width||!this.style.height)&&(this.style.width=this.texture.width,this.style.height=this.texture.height),this.requestRedraw()}_updateVideoCurrentTime(){let e=this._currentTime;if(e<0)return;const t=this.texture;if(!t)return;const i=t.duration;e=i?e%(i*1e3):0,!t.isPlaying&&!t.seeking&&(e=~~e/1e3,t.currentTime!==e&&(t.currentTime=e))}_process(e){this._updateVideoCurrentTime(),super._process(e)}},El([U({default:""})],u.Video2D.prototype,"src",2),u.Video2D=El([re("Video2D")],u.Video2D);var Dd=Object.defineProperty,bd=Object.getOwnPropertyDescriptor,Hi=(r,A,e,t)=>{for(var i=t>1?void 0:t?bd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Dd(A,e,i),i};const pl=r=>r,Cl=ei(.25,.1,.25,1),Ql=ei(.42,0,1,1),yl=ei(0,0,.58,1),ml=ei(.42,0,.58,1);function ei(r,A,e,t){const s=3*r-3*e+1,n=3*e-6*r,o=3*r,a=3*A-3*t+1,l=3*t-6*A,g=3*A,h=C=>(3*s*C+2*n)*C+o,f=C=>((s*C+n)*C+o)*C,I=C=>((a*C+l)*C+g)*C;function d(C){let B=C,R,S;for(let w=0;w<8;w++){if(S=f(B)-C,Math.abs(S)<1e-6)return B;if(R=h(B),Math.abs(R)<1e-6)break;B-=S/R}let _=1,M=0;for(B=C;_>M;){if(S=f(B)-C,Math.abs(S)<1e-6)return B;S>0?_=B:M=B,B=(_+M)/2}return B}return C=>I(d(C))}const Mr={linear:pl,ease:Cl,easeIn:Ql,easeOut:yl,easeInOut:ml};u.Animation=class extends u.TimelineNode{constructor(e,t=[]){super();c(this,"easing");c(this,"_keyframes",[]);c(this,"_isFirstUpdatePosition",!1);c(this,"_cachedProps",new SA);c(this,"_stoped",!1);this.setProperties(e).append(t)}_parented(e){super._parented(e),this._updateCachedProps()}_unparented(e){super._unparented(e),this.cancel()}_process(){this.canProcess()&&this.commitStyles()}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"effectMode":case"keyframes":this._updateKeyframes();break}}_getTargets(){var t;let e;switch(this.effectMode){case"sibling":e=((t=this.getParent())==null?void 0:t.getChildren(!0).filter(i=>i instanceof u.CanvasItem))??[];break;case"parent":default:e=[this.getParent()].filter(Boolean);break}return e.map(i=>i.style)}_updateKeyframes(){const e=[],t=this.keyframes;for(let n=t.length,o=0;o<n;o++){const{offset:a=o===0?0:o/(n-1),easing:l="linear",...g}=t[o];e.push({offset:a,easing:this._parseEasing(l),props:g})}const i=e[0],s=e[e.length-1];i&&i.offset!==0&&e.unshift({offset:0,easing:this._parseEasing("linear"),props:{}}),s&&s.offset!==1&&e.push({offset:1,easing:this._parseEasing("linear"),props:{}}),this._keyframes=e,this._updateCachedProps()}commitStyles(){if(!this.keyframes.length)return;if(this._updateCurrentTime(),this.isInsideTimeRange())this._isFirstUpdatePosition||(this._isFirstUpdatePosition=!0,this._updateCachedProps());else{if(!this._isFirstUpdatePosition)return;this._isFirstUpdatePosition=!1}const e=this._getTargets(),t=1/e.length,i=this.currentTimeProgress;e.forEach((s,n)=>{const o=t===1?i:bt(0,Math.max(0,i-t*n)/t,1),a=this._cachedProps.get(s);if(!a)return;const l=this._parseKeyframes(o,a);l!=null&&l.length&&this._commitStyle(o,s,a,l[0],l[1])})}_updateCachedProps(){this.cancel(),this._getTargets().forEach(e=>{const t=new Map,i=this._keyframes;for(let s=i.length,n=0;n<s;n++)Object.keys(i[n].props).forEach(o=>{t.set(o,e[o])});this._cachedProps.set(e,t)})}_parseEasing(e){if(!e)return Mr.linear;if(e in Mr)return Mr[e];const t=e.replace(/cubic-bezier\((.+)\)/,"$1").split(",").map(i=>Number(i));return ei(t[0],t[1],t[2],t[3])}_parseKeyframes(e,t){let i;const s=this._keyframes;for(let n=s.length,o=0;o<n;o++){const a=s[o],{offset:l,easing:g}=a,h={...a.props};if(i&&e<=l){const{offset:f,easing:I}=i,d={...i.props};return t.forEach((C,B)=>{(!(B in d)||d[B]===null)&&(d[B]=C),(!(B in h)||h[B]===null)&&(h[B]=C)}),[{offset:f,easing:I,props:d},{offset:l,easing:g,props:h}]}i=a}return null}_commitStyle(e,t,i,s,n){const{offset:o,easing:a,props:l}=s,{offset:g,props:h}=n,f=g-o,I=a((e-o)/f),d={width:t.width,height:t.height,fontSize:t.fontSize};i.forEach((C,B)=>{t[B]=this._getDiffValue(B,l[B],h[B],I,d)})}_getDiffValue(e,t,i,s,n){let o,a;if(t==="none"&&(t=void 0),i==="none"&&(i=void 0),t===void 0||i===void 0)if(t!==void 0)o=ri(e,String(t),n),a=ts(o);else if(i!==void 0)a=ri(e,String(i),n),o=ts(a);else return;else o=ri(e,String(t),n),a=ri(e,String(i),n);if(Array.isArray(o)&&Array.isArray(a)){const l=new Set,g={},h={};o.forEach(({name:I,args:d})=>{g[I]=d,l.add(I)}),a.forEach(({name:I,args:d})=>{h[I]=d,l.add(I)});let f="";return l.forEach(I=>{var R,S;const d=Math.max(((R=g[I])==null?void 0:R.length)??0,((S=h[I])==null?void 0:S.length)??0),C=g[I],B=h[I];f+=`${I}(${Array.from({length:d},(_,M)=>{const w=C==null?void 0:C[M],v=B==null?void 0:B[M],D=(w==null?void 0:w.normalizedIntValue)??0,x=(v==null?void 0:v.normalizedIntValue)??0;return Number.isNaN(D)||Number.isNaN(x)?(v==null?void 0:v.value)??0:Se(D,x,s)}).join(", ")}) `}),f}else if(!Array.isArray(o)&&!Array.isArray(a))return Number.isNaN(o.normalizedIntValue)||Number.isNaN(a.normalizedIntValue)?a.value:Se(o.normalizedIntValue,a.normalizedIntValue,s)}isPlaying(){return!this.paused&&this.isInsideTimeRange()}play(){return this._stoped?(this._stoped=!1,this.startTime=this.timelineCurrentTime):this.startTime=this.timelineCurrentTime-this.currentTime,this.paused=!1,!0}pause(){return this.paused=!0,!0}stop(){return this._stoped=!0,this.paused=!0,this._currentTime=0,!0}cancel(){this._getTargets().forEach(e=>{var t;(t=this._cachedProps.get(e))==null||t.forEach((i,s)=>{e[s]=i}),this._cachedProps.delete(e)})}},Hi([U({default:"parent"})],u.Animation.prototype,"effectMode",2),Hi([U({default:!1})],u.Animation.prototype,"loop",2),Hi([U({default:[]})],u.Animation.prototype,"keyframes",2),Hi([U()],u.Animation.prototype,"easing",2),u.Animation=Hi([re("Animation",{renderMode:"disabled",processMode:"pausable",processSortMode:"parent_before",duration:2e3})],u.Animation);const Or=class Or extends Ot{constructor(){super(...arguments);c(this,"playbackRate",1);c(this,"muted",!1);c(this,"volume",1);c(this,"paused",!1)}static get instance(){return this._instance||(this._instance=new Or),this._instance}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}get processors(){return console.warn("HTML Audio does not support processors"),[]}set processors(e){console.warn("HTML Audio does not support processors")}get audioContext(){return console.warn("HTML Audio does not support audioContext"),null}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this.paused}free(){this.removeAllListeners()}};c(Or,"_instance");let Rr=Or;const Ki=class Ki extends Ot{constructor(){super(...arguments);c(this,"_source",null);c(this,"_audio",null);c(this,"_end",0);c(this,"_pausedReal",!1);c(this,"_duration",0);c(this,"_start",0);c(this,"_playing",!1);c(this,"_paused",!1);c(this,"_playbackRate",1);c(this,"_volume",1);c(this,"_loop",!1);c(this,"_muted",!1);c(this,"_onUpdate",()=>{this._source&&(this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete())})}get progress(){var e;return(((e=this._source)==null?void 0:e.currentTime)??0)/this._duration}get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}set(e,t){if(this[e]===void 0)throw new Error(`Property with name ${e} does not exist.`);switch(e){case"playbackRate":this.playbackRate=t;break;case"volume":this.volume=t;break;case"paused":this.paused=t;break;case"loop":this.loop=t;break;case"muted":this.muted=t;break}return this}_onPlay(){this._playing=!0}_onPause(){this._playing=!1}init(e){this._playing=!1,this._duration=e.source.duration;const t=this._source=e.source.cloneNode(!1);return t.src=e.parent.src,t.onplay=this._onPlay.bind(this),t.onpause=this._onPause.bind(this),e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this._audio=e,this}_stop(){this._source&&this._playing&&(this._source.onended=null,this._source.pause())}stop(){this._stop(),this._source&&this.emit("stop")}get processors(){return console.warn("HTML Audio does not support processors"),[]}set processors(e){console.warn("HTML Audio does not support processors")}refresh(){if(!this._audio||!this._source)return;const e=this._audio.context,t=this._audio.parent;this._source.loop=this._loop||t.loop;const i=e.volume*(e.muted?0:1),s=t.volume*(t.muted?0:1),n=this._volume*(this._muted?0:1);this._source.volume=n*i*s,this._source.playbackRate=this._playbackRate*e.playbackRate*t.playbackRate}refreshPaused(){if(!this._source||!this._audio)return;const e=this._paused||this._audio.parent.paused||this._audio.context.paused;e!==this._pausedReal&&(this._pausedReal=e,e?(this._stop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._source.currentTime,end:this._end,volume:this._volume,playbackRate:this._playbackRate,loop:this._loop})),this.emit("pause",e))}play(e={}){if(!this._source)return;const{start:t=0,end:i=0}=e;i&&console.assert(i>t,"End time is before start time"),e.playbackRate!==void 0&&(this._playbackRate=e.playbackRate),e.volume!==void 0&&(this._volume=e.volume),e.loop!==void 0&&(this._loop=e.loop),e.muted!==void 0&&(this._muted=e.muted),this.refresh(),this.loop&&i!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=t,this._end=i||this._duration,this._start=Math.max(0,this._start-Ki.PADDING),this._end=Math.min(this._end+Ki.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=t,this._source.onloadedmetadata=null,this.emit("progress",t,this._duration),xe.on(this._onUpdate))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onComplete(){xe.off(this._onUpdate),this._stop(),this.emit("progress",1,this._duration),this.emit("end",this)}free(){xe.off(this._onUpdate),this.removeAllListeners();const e=this._source;e&&(e.onended=null,e.onplay=null,e.onpause=null,this._stop()),this._source=null,this._playbackRate=1,this._volume=1,this._loop=!1,this._end=0,this._start=0,this._duration=0,this._playing=!1,this._pausedReal=!1,this._paused=!1,this._muted=!1,this._audio&&(this._audio.context.off("refresh",this.refresh),this._audio.context.off("refreshPaused",this.refreshPaused),this._audio=null)}};c(Ki,"PADDING",.1);let kr=Ki;class wl{constructor(A){c(this,"source",new globalThis.Audio);c(this,"_src","");this.parent=A}get src(){return this._src}set src(A){this._src!==A&&(this._src=A,this.load())}get duration(){return this.source.duration}get isPlayable(){return!!this.source&&this.source.readyState===4}get context(){return Rr.instance}async load(){return new Promise(A=>{this.source.onload=()=>A(this),this.source.src=this._src,this.source.load()})}createSound(){return new kr}}class yn extends Ot{constructor(e,t){super();c(this,"_processers",[]);this._input=e,this._output=t}get processors(){return this._processers}set processors(e){if(this._processers.forEach(t=>t.disconnect()),this._processers.length=0,this._input.connect(this._output),e.length){this._processers=e.slice(0),this._input.disconnect();let t;e.forEach(i=>{t?t.connect(i.destination):this._input.connect(i.destination),t=i}),t.connect(this._output)}}get destination(){return this._input}}class xd{constructor(A,e=null){this.destination=A,this.source=e}connect(A){var e;(e=this.source)==null||e.connect(A)}disconnect(){var A;(A=this.source)==null||A.disconnect()}}function Sd(){if(is)return new AudioContext;if(rs){const r=globalThis.webkitAudioContext;return new r}else throw new Error("Failed to createAudioContext")}function Md(r,A,e){if(ss)return new OfflineAudioContext(r,A,e);if(Kn){const t=globalThis.webkitOfflineAudioContext;return new t(r,A,e)}else throw new Error("Failed to createOfflineAudioContext")}const Hr=class Hr extends yn{constructor(){const e=Sd(),t=Md(1,2,ss?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),i=e.createDynamicsCompressor(),s=e.createAnalyser();s.connect(i),i.connect(e.destination);super(s,i);c(this,"_context");c(this,"_offlineContext");c(this,"_locked");c(this,"muted",!1);c(this,"volume",1);c(this,"playbackRate",1);c(this,"autoPause",!0);c(this,"_paused",!1);c(this,"_pausedOnBlur",!1);c(this,"_compressor");c(this,"_analyser");c(this,"_unlock",()=>{this._locked&&(this.playEmptySound(),this._context.state==="running"&&(document.removeEventListener("mousedown",this._unlock,!0),document.removeEventListener("touchend",this._unlock,!0),document.removeEventListener("touchstart",this._unlock,!0),this._locked=!1))});this._context=e,this._offlineContext=t,this._compressor=i,this._analyser=s,this._locked=e.state==="suspended"&&(Gt||Jn),ni&&(this._locked&&(this._unlock(),document.addEventListener("mousedown",this._unlock,!0),document.addEventListener("touchstart",this._unlock,!0),document.addEventListener("touchend",this._unlock,!0)),globalThis.addEventListener("focus",this._onFocus),globalThis.addEventListener("blur",this._onBlur))}static get instance(){return this._instance||(this._instance=new Hr),this._instance}static get audioContext(){return this.instance.audioContext}static get offlineContext(){return this.instance.offlineContext}static setParamValue(e,t){this.instance.setParamValue(e,t)}static decode(e){return this.instance.decode(e)}get audioContext(){return this._context}get offlineContext(){return this._offlineContext}get paused(){return this._paused}set paused(e){e&&this._context.state==="running"?this._context.suspend():!e&&this._context.state==="suspended"&&this._context.resume(),this._paused=e}_onFocus(){if(!this.autoPause)return;const e=this._context.state;(e==="suspended"||e==="interrupted"||!this._locked)&&(this.paused=this._pausedOnBlur,this.refreshPaused())}_onBlur(){this.autoPause&&(this._locked||(this._pausedOnBlur=this._paused,this.paused=!0,this.refreshPaused()))}playEmptySound(){const e=this._context.createBufferSource();e.buffer=this._context.createBuffer(1,1,22050),e.connect(this._context.destination),e.start(0,0,0),e.context.state==="suspended"&&e.context.resume()}refresh(){this.emit("refresh")}refreshPaused(){this.emit("refreshPaused")}toggleMute(){return this.muted=!this.muted,this.refresh(),this.muted}togglePause(){return this.paused=!this.paused,this.refreshPaused(),this._paused}decode(e){return new Promise((t,i)=>{const s=o=>{i(new Error((o==null?void 0:o.message)||"Unable to decode file"))},n=this._offlineContext.decodeAudioData(e,t,s);n&&n.catch(s)})}setParamValue(e,t){e.setValueAtTime?e.setValueAtTime(t,this._context.currentTime):e.value=t}};c(Hr,"_instance");let lA=Hr;class vl extends Ot{constructor(){super(...arguments);c(this,"_audio",null);c(this,"_sourceNode",null);c(this,"_gain",null);c(this,"_progress",0);c(this,"_pausedReal",!1);c(this,"_paused",!1);c(this,"_volume",1);c(this,"_playbackRate",1);c(this,"_loop",!1);c(this,"_muted",!1);c(this,"_duration",0);c(this,"_end",0);c(this,"_elapsed",0);c(this,"_lastUpdate",this._now());c(this,"_processors",[]);c(this,"_onComplete",()=>{if(this._sourceNode){this._enableTicker(!1),this._sourceNode.onended=null,this._sourceNode.disconnect();try{this._sourceNode.buffer=null}catch(e){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",e)}}this._sourceNode=null,this._progress=1,this.emit("progress",1,this._duration),this.emit("end",this)});c(this,"_updateListener",()=>this._update())}get progress(){return this._progress}get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh(),this._update(!0))}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}init(e){return this._audio=e,e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this}_now(){var e;return((e=this._audio)==null?void 0:e.context.audioContext.currentTime)??0}play(e={}){var o;if(!this._audio)return;const{end:t=0,start:i=0}=e;t&&console.assert(t>i,"End time is before start time"),this._end=t,this._elapsed=i,e.volume!==void 0&&(this._volume=e.volume),e.playbackRate!==void 0&&(this._playbackRate=e.playbackRate),e.muted!==void 0&&(this._muted=e.muted),e.loop!==void 0&&(this._loop=e.loop),e.processors!==void 0&&(this._processors=e.processors),this._paused=!1;const{source:s,gain:n}=this._audio.cloneSource();this._sourceNode=s,this._gain=n,this.refresh(),s.onended=this._onComplete.bind(this),this._duration=((o=s.buffer)==null?void 0:o.duration)??0,this._lastUpdate=this._now(),this._loop?(s.loopStart=i,s.loopEnd=t,s.start(0,i)):t?s.start(0,i,t-i):s.start(0,i),this.emit("start"),this._update(!0),this._enableTicker(!0)}_stop(){if(this._sourceNode){this._enableTicker(!1),this._sourceNode.onended=null,this._sourceNode.stop(0),this._sourceNode.disconnect();try{this._sourceNode.buffer=null}catch(e){console.warn("Failed to set AudioBufferSourceNode.buffer to null:",e)}this._sourceNode=null}}stop(){this._sourceNode&&(this._stop(),this.emit("stop"))}_update(e=!1){if(this._sourceNode){const t=this._now(),i=t-this._lastUpdate;if(i>0||e){this._elapsed+=i*this._sourceNode.playbackRate.value,this._lastUpdate=t;const s=this._duration;let n;if(this._sourceNode.loopStart){const o=this._sourceNode.loopEnd-this._sourceNode.loopStart;n=(this._sourceNode.loopStart+this._elapsed%o)/s}else n=this._elapsed%s/s;this._progress=n,this.emit("progress",n,s)}}}refresh(){if(!this._audio||!this._sourceNode)return;const e=this._audio.context,t=this._audio.parent;this._sourceNode.loop=this._loop||t.loop,e.setParamValue(this._gain.gain,this._volume*(this._muted?0:1)*t.volume*(t.muted?0:1)*e.volume*(e.muted?0:1)),e.setParamValue(this._sourceNode.playbackRate,this._playbackRate*t.playbackRate*e.playbackRate),this.applyProcessors()}applyProcessors(){if(this._sourceNode&&this._processors.length){this._sourceNode.disconnect();let e=this._sourceNode;this._processors.forEach(t=>{e.connect(t.destination),e=t}),e.connect(this._gain)}}refreshPaused(){if(!this._audio)return;const e=this._paused||this._audio.parent.paused||this._audio.context.paused;e!==this._pausedReal&&(this._pausedReal=e,e?(this._stop(),this.emit("paused")):(this.emit("resumed"),this.play({start:this._elapsed%this._duration,end:this._end,playbackRate:this._playbackRate,loop:this._loop,volume:this._volume})),this.emit("pause",e))}_enableTicker(e){xe.off(this._updateListener),e&&xe.on(this._updateListener)}free(){var e,t,i;this.removeAllListeners(),this._stop(),(e=this._gain)==null||e.disconnect(),this._gain=null,(t=this._audio)==null||t.context.off("refresh",this.refresh),(i=this._audio)==null||i.context.off("refreshPaused",this.refreshPaused),this._audio=null,this._processors.forEach(s=>s.disconnect()),this._processors.length=0,this._end=0,this._playbackRate=1,this._volume=1,this._loop=!1,this._elapsed=0,this._duration=0,this._paused=!1,this._muted=!1,this._pausedReal=!1}}class _l extends yn{constructor(e){const t=lA.audioContext,i=t.createBufferSource(),s=t.createGain(),n=t.createAnalyser();i.connect(n),n.connect(s),s.connect(lA.instance.destination);super(n,s);c(this,"_sourceBuffer");c(this,"_sourceNode");c(this,"_sourceLoad");c(this,"gain");c(this,"analyser");this.parent=e,this._sourceNode=i,this.gain=s,this.analyser=n}get context(){return lA.instance}get isPlayable(){return!!this._sourceNode.buffer}get duration(){var e;return((e=this._sourceNode.buffer)==null?void 0:e.duration)??0}get buffer(){return this._sourceNode.buffer}set buffer(e){this._sourceNode.buffer=e}async load(){return this._sourceLoad||(this._sourceLoad=new Promise(e=>{this._sourceBuffer?this._decode(this._sourceBuffer).then(()=>e(this)):this.parent.src?this._loadUrl(this.parent.src).then(()=>e(this)):e(this)})),this._sourceLoad}_loadUrl(e){return new Promise(t=>{fetch(e).then(i=>i.arrayBuffer()).then(i=>this._decode(i)).finally(()=>t(this))})}_decode(e){return Promise.resolve(e instanceof AudioBuffer?e:lA.decode(e)).then(t=>(this.parent.isLoaded=!0,this.buffer=t,t))}cloneSource(){const e=this.context,t=this._sourceNode,i=e.audioContext.createBufferSource(),s=e.audioContext.createGain();return i.buffer=t.buffer,i.loop=t.loop,e.setParamValue(i.playbackRate,t.playbackRate.value),i.connect(s),s.connect(this.destination),{source:i,gain:s}}createSound(){return new vl}}var Rd=Object.defineProperty,kd=Object.getOwnPropertyDescriptor,Ud=(r,A,e)=>A in r?Rd(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,Pd=(r,A,e,t)=>{for(var i=t>1?void 0:t?kd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i},Nd=(r,A,e)=>Ud(r,A+"",e);u.Audio=class extends u.TimelineNode{constructor(e=""){super();c(this,"_sounds",[]);c(this,"_platformAudio",Yn?new _l(this):new wl(this));c(this,"_src");c(this,"isLoaded",!1);c(this,"_volume",1);c(this,"_muted",!1);c(this,"_loop",!1);c(this,"_playbackRate",1);c(this,"_isPlaying",!1);c(this,"multiple",!1);c(this,"start",0);c(this,"end",0);c(this,"_onComplete",e=>{if(this._sounds){const t=this._sounds.indexOf(e);t>-1&&this._sounds.splice(t,1),this._isPlaying=this._sounds.length>0}this._recycleSound(e)});c(this,"_prevTime",0);c(this,"_timer",0);this.src=e}get platformAudio(){return this._platformAudio}get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}get isPlayable(){return this.isLoaded&&this._platformAudio.isPlayable}get audioDuration(){return this._platformAudio.duration*1e3}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}get isPlaying(){return this._isPlaying}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"paused":this.refreshPaused();break}}async load(){return await this._platformAudio.load(),this}pause(){return this._isPlaying=!1,this.paused=!0,this}resume(){return this._isPlaying=this._sounds.length>0,this.paused=!1,this}stop(){if(!this.isPlayable)return this;this._isPlaying=!1;for(let e=this._sounds.length-1;e>=0;e--)this._sounds[e].stop();return this}play(e={}){if(!this.isLoaded)return;this.multiple||this._removeSounds(),this._isPlaying=!0;const t=this._createSound();this._sounds.push(t),t.once("end",()=>{var n;(n=e.complete)==null||n.call(e),this._onComplete(t)}),t.once("stop",()=>this._onComplete(t));const i=((e==null?void 0:e.start)??this.start)/1e3,s=((e==null?void 0:e.end)??this.end)/1e3;return t.play({...e,start:i,end:s}),t}_removeSounds(){for(let e=this._sounds.length-1;e>=0;e--)this._recycleSound(this._sounds[e]);this._sounds.length=0}_createSound(){return u.Audio._soundPool.length>0?u.Audio._soundPool.pop().init(this._platformAudio):this._platformAudio.createSound().init(this._platformAudio)}refresh(){for(let e=this._sounds.length,t=0;t<e;t++)this._sounds[t].refresh()}refreshPaused(){for(let e=this._sounds.length,t=0;t<e;t++)this._sounds[t].refreshPaused()}_recycleSound(e){e.free(),u.Audio._soundPool.includes(e)||u.Audio._soundPool.push(e)}_process(e){var t;if(super._process(e),this.canProcess()){const i=((t=this._tree)==null?void 0:t.timeline.currentTime)??0;i-this._prevTime>0&&(this._timer||(this._setTimeStop(),this.play({start:this.start+(i-this.delay)%this.duration})),this._isPlaying&&this._setTimeStop()),this._prevTime=i}}_setTimeStop(){this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this.stop(),this._timer=0},100)}},Nd(u.Audio,"_soundPool",[]),u.Audio=Pd([re("Audio")],u.Audio);class Fd extends u.Node2D{}var Td=Object.defineProperty,Ld=Object.getOwnPropertyDescriptor,Ur=(r,A,e,t)=>{for(var i=t>1?void 0:t?Ld(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Td(A,e,i),i};u.AudioWaveform=class extends u.Element2D{constructor(e={}){super();c(this,"src");c(this,"gap",0);c(this,"color","#000000");c(this,"_audioBuffer");c(this,"_src",ni?new ve(document.createElement("canvas")):void 0);c(this,"_needsUpdateTexture",!1);this.setProperties(e)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"src":this._loadSrc(t);break;case"gap":case"color":case"width":case"height":this._needsUpdateTexture=!0;break}}async _loadSrc(e){await globalThis.fetch(e).then(t=>t.arrayBuffer()).then(t=>lA.decode(t)).then(t=>{this._audioBuffer=t,this.syncTexture(!0)})}syncTexture(e=!1){var h,f;const t=this._audioBuffer;if(!t||!e&&!this._needsUpdateTexture)return;this._needsUpdateTexture=!1;const i=(h=this._src)==null?void 0:h.source;if(!i)return;const{width:s=0,height:n=0}=this.style;i.width=s,i.height=n;const o=i.getContext("2d");if(!o){console.warn("Failed to getContext('2d') in syncTexture");return}o.fillStyle=this.color;const a=t.getChannelData(0),l=Math.ceil(a.length/s),g=n/2;for(let I=1,d=-1,C=0;C<s;C++){for(let B=0;B<l;B++){const R=a[C*l+B];R<I&&(I=R),R>d&&(d=R)}if(!this.gap||C%(this.gap*2)===0){const B=C,R=(1+I)*g,S=this.gap||1,_=Math.max(1,(d-I)*g);o.fillRect(B,R,S,_),I=1,d=-1}}(f=this._src)==null||f.requestUpload(),this.requestRedraw()}_process(e){this.syncTexture(),super._process(e)}_drawSrc(){const e=this._src;e!=null&&e.valid&&(this.context.fillStyle=e,this.context.textureTransform=new Qt().scale(1/this.style.width,1/this.style.height))}},Ur([U()],u.AudioWaveform.prototype,"src",2),Ur([U()],u.AudioWaveform.prototype,"gap",2),Ur([U()],u.AudioWaveform.prototype,"color",2),u.AudioWaveform=Ur([re("AudioWaveform")],u.AudioWaveform);var Gd=Object.getOwnPropertyDescriptor,Od=(r,A,e,t)=>{for(var i=t>1?void 0:t?Gd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.Control=class extends u.Element2D{constructor(A,e=[]){super(),this._parentUpdateRect=this._parentUpdateRect.bind(this),this.setProperties(A),this.append(e)}_parented(A){super._parented(A),A.on("updateRect",this._parentUpdateRect)}_unparented(A){super._unparented(A),A.off("updateRect",this._parentUpdateRect)}_parentUpdateRect(){const A=this._parent.getRect();this.style.left=A.left,this.style.top=A.top,this.style.width=A.width,this.style.height=A.height}_input(A,e){super._input(A,e),this._guiInput(A,e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":case"left":case"top":this.emit("updateRect");break}}_guiInput(A,e){}},u.Control=Od([re("Control")],u.Control);var Hd=Object.defineProperty,Jd=Object.getOwnPropertyDescriptor,gA=(r,A,e,t)=>{for(var i=t>1?void 0:t?Jd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Hd(A,e,i),i};u.Range=class extends u.Control{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateProperty(A,e,t,i){switch(super._updateProperty(A,e,t,i),A){case"allowGreater":case"allowLesser":case"page":case"minValue":case"maxValue":case"step":case"value":this.requestRedraw();break}}},gA([U({default:!1})],u.Range.prototype,"allowGreater",2),gA([U({default:!1})],u.Range.prototype,"allowLesser",2),gA([U({default:1})],u.Range.prototype,"page",2),gA([U({default:0})],u.Range.prototype,"minValue",2),gA([U({default:100})],u.Range.prototype,"maxValue",2),gA([U({default:.01})],u.Range.prototype,"step",2),gA([U({default:0})],u.Range.prototype,"value",2),u.Range=gA([re("Range")],u.Range);var Kd=Object.defineProperty,Yd=Object.getOwnPropertyDescriptor,Pt=(r,A,e,t)=>{for(var i=t>1?void 0:t?Yd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Kd(A,e,i),i};u.Ruler=class extends u.Control{constructor(e,t=[]){super();c(this,"texture",new gi);this.setProperties(e),this.append(t)}_updateProperty(e,t,i,s){switch(super._updateProperty(e,t,i,s),e){case"offsetX":case"offsetY":case"thickness":case"markHeight":case"color":case"markBackgroundColor":case"markColor":case"gap":case"scale":this.requestRedraw();break}}_updateStyleProperty(e,t,i,s){switch(super._updateStyleProperty(e,t,i,s),e){case"width":case"height":this.texture[e]=t,this.requestRedraw();break}}_drawTexture(){const{width:e,height:t}=this.size,{offsetX:i,offsetY:s,thickness:n,markHeight:o,markBackgroundColor:a,markColor:l,color:g,gap:h,gapScale:f}=this,d=this.texture.source.getContext("2d");d.reset(),d.scale(this.texture.pixelRatio,this.texture.pixelRatio);const C=Math.round(i),B=Math.round(s);d.beginPath(),d.fillStyle=a||"#EEE",d.fillRect(0,0,e,n),d.fillRect(0,0,n,t),d.fill(),d.strokeStyle=l||"#000",d.moveTo(n,0),d.lineTo(n,t),d.moveTo(0,n),d.lineTo(e,n),d.stroke();const R=h,S=h*f;let _,M,w,v,D;for(R>=S?(_=R/S,M=Math.floor(_)*R/20,w=R/20*Math.floor(_)/_):(_=S/R,M=Math.floor(R/20/_),M>=2?M=Math.floor(M/2)*2:M=1,w=M*_),d.fillStyle=d.strokeStyle,v=C,D=0;v<e;D++,v+=w)d.moveTo(v,n-(D%5?o:2*o)),d.lineTo(v,n);for(v=C,D=0;v>n;D++,v-=w)d.moveTo(v,n-(D%5?o:2*o)),d.lineTo(v,n);let x=0;for(v=B,D=0;v>n;D++,v-=w)d.moveTo(n-(D%5?o:2*o),v),d.lineTo(n,v);for(v=B,D=0;v<t;D++,v+=w)d.moveTo(n-(D%5?o:2*o),v),d.lineTo(n,v);for(d.save(),d.fillStyle=g,d.scale(.8,.8),x=n-8,v=C,D=0;v<e;D++,v+=w)D%10===0&&d.fillText(String(Math.ceil(M*D)),v*1.25-3,x*1.25);for(v=C,D=0;v>n;D++,v-=w)D%10===0&&d.fillText(String(Math.ceil(-M*D)),v*1.25-3,x*1.25);for(x=0,v=B,D=0;v>n;D++,v-=w)D%10===0&&d.fillText(String(Math.ceil(M*D)),x*1.25,v*1.25+3);for(v=B,D=0;v<t;D++,v+=w)D%10===0&&d.fillText(String(Math.ceil(-M*D)),x*1.25,v*1.25+3);d.restore(),d.stroke(),this.texture.requestUpload()}_draw(){this._drawTexture();const e=this.texture;e!=null&&e.valid&&(this.context.fillStyle=e,this.context.textureTransform=new Qt().scale(1/this.size.width,1/this.size.height),this.context.rect(0,0,e.width,e.height),this.context.fill())}},Pt([U({default:0})],u.Ruler.prototype,"offsetX",2),Pt([U({default:0})],u.Ruler.prototype,"offsetY",2),Pt([U({default:20})],u.Ruler.prototype,"thickness",2),Pt([U({default:3})],u.Ruler.prototype,"markHeight",2),Pt([U({default:"#b2b6bc"})],u.Ruler.prototype,"color",2),Pt([U({default:"#f9f9fa"})],u.Ruler.prototype,"markBackgroundColor",2),Pt([U({default:"#b2b6bc"})],u.Ruler.prototype,"markColor",2),Pt([U({default:300})],u.Ruler.prototype,"gap",2),Pt([U({default:1})],u.Ruler.prototype,"gapScale",2),u.Ruler=Pt([re("Ruler")],u.Ruler);var Wd=Object.defineProperty,Vd=Object.getOwnPropertyDescriptor,Dl=(r,A,e,t)=>{for(var i=t>1?void 0:t?Vd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Wd(A,e,i),i};u.ScrollBar=class extends u.Range{constructor(A,e=[]){super(),this.setProperties(A).append(e)}_updateStyleProperty(A,e,t,i){switch(super._updateStyleProperty(A,e,t,i),A){case"width":case"height":case"left":case"top":this.requestRedraw();break}}_rect(){const{size:A,position:e}=this;let t,i,s,n,o;return this.direction==="vertical"?(s=10,n=A.height*(this.page/(this.maxValue-this.minValue)),t=e.left+A.width-s,i=A.height*(this.value/(this.maxValue-this.minValue)),o=s/2):(s=A.width*(this.page/(this.maxValue-this.minValue)),n=10,t=A.width*(this.value/(this.maxValue-this.minValue)),i=e.top+A.height-n,o=n/2),{left:t,top:i,width:s,height:n,radii:o}}_draw(){const{left:A,top:e,width:t,height:i,radii:s}=this._rect();this.context.roundRect(A,e,t,i,s),this.context.fillStyle=34,this.context.fill()}_pointerInput(A,e){var a,l;const{left:t,top:i,width:s,height:n}=this._rect(),o=A.x>=t&&A.x<t+s&&A.y>=i&&A.y<i+n;switch(e){case"pointerdown":case"pointermove":o?(a=this._tree)==null||a.input.setCursor("pointer"):(l=this._tree)==null||l.input.setCursor(void 0);break}return!1}},Dl([U({default:"vertical"})],u.ScrollBar.prototype,"direction",2),u.ScrollBar=Dl([re("ScrollBar")],u.ScrollBar);var zd=Object.getOwnPropertyDescriptor,qd=(r,A,e,t)=>{for(var i=t>1?void 0:t?zd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.XScrollBar=class extends u.ScrollBar{constructor(A,e=[]){super(),this.setProperties(A).append(e)}},u.XScrollBar=qd([re("XScrollBar",{direction:"horizontal"})],u.XScrollBar);var Xd=Object.getOwnPropertyDescriptor,jd=(r,A,e,t)=>{for(var i=t>1?void 0:t?Xd(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i};u.YScrollBar=class extends u.ScrollBar{constructor(A,e=[]){super(),this.setProperties(A).append(e)}},u.YScrollBar=jd([re("YScrollBar",{direction:"vertical"})],u.YScrollBar);var Zd=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,Pr=(r,A,e,t)=>{for(var i=t>1?void 0:t?$d(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=(t?n(A,e,i):n(i))||i);return t&&i&&Zd(A,e,i),i};u.Scaler=class extends u.Node{get target(){var A;if((A=this.parent)!=null&&A.style)return this.parent}constructor(A,e=[]){super(),this.setProperties(A),this.append(e)}_updateProperty(A,e,t,i){switch(super._updateProperty(A,e,t,i),A){case"value":case"min":case"max":{this.value=bt(this.minValue,this.value,this.maxValue),this._updateScale();break}}}_updateScale(){const A=this.target;A&&(A.style.scaleX=this.value,A.style.scaleY=this.value,this.emit("updateScale",this.value))}_onWheel(A){if(!this.target)return;if(A.preventDefault(),!(A.wheelDeltaY?Math.abs(Math.abs(A.wheelDeltaY)-Math.abs(3*A.deltaY))<3:A.deltaMode===0)&&A.ctrlKey){A.preventDefault();let i=A.deltaY/(A.ctrlKey?1:100);i*=-.015,this.value+=i}}_input(A,e){switch(super._input(A,e),e){case"wheel":this._onWheel(A);break}}},Pr([U({default:1})],u.Scaler.prototype,"value",2),Pr([U({default:.05})],u.Scaler.prototype,"minValue",2),Pr([U({default:10})],u.Scaler.prototype,"maxValue",2),u.Scaler=Pr([re("Scaler",{processMode:"disabled",renderMode:"disabled"})],u.Scaler);var eI=Object.defineProperty,tI=Object.getOwnPropertyDescriptor,AI=(r,A,e)=>A in r?eI(r,A,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[A]=e,iI=(r,A,e,t)=>{for(var i=t>1?void 0:t?tI(A,e):A,s=r.length-1,n;s>=0;s--)(n=r[s])&&(i=n(i)||i);return i},rI=(r,A,e)=>AI(r,A+"",e);u.KawaseTransition=class extends u.Transition{constructor(){super(...arguments);c(this,"blur",10);c(this,"quality",10)}apply(e,t){const i=this.currentTimeProgress;let s,n;i<.5?(s=0,n=(.5-i)/.5):(s=1,n=(i-.5)/.5);const o=this.blur,a=this.quality,l=t.width,g=t.height,h=[],f=[o];if(o>0){let S=o;const _=o/a;for(let M=1;M<a;M++)S-=_,f.push(S)}const I=1/l,d=1/g,C=[];let B;const R=a-1;for(let S=0;S<R;S++)B=f[S]+.5,C[0]=B*I,C[1]=B*d,h.push({offset:C});B=f[R]+.5,C[0]=B*I,C[1]=B*d,h.push({offset:C}),h.forEach(S=>{fe.draw(e,u.KawaseTransition.material,{sampler:s,progress:n,...S})})}},rI(u.KawaseTransition,"material",new Qe({vert:`attribute vec2 position;
777
777
  attribute vec2 uv;
778
778
  varying vec2 vUv;
779
779
  void main() {
package/dist/index.mjs CHANGED
@@ -5652,13 +5652,14 @@ let Node = class extends CoreObject {
5652
5652
  setParent(parent) {
5653
5653
  if (!this._parent?.is(parent)) {
5654
5654
  const oldParent = this._parent;
5655
+ if (oldParent) {
5656
+ this.emit("unparented", oldParent);
5657
+ }
5655
5658
  this._parent = parent;
5656
- this.setTree(parent?._tree);
5657
5659
  if (parent) {
5658
5660
  this.emit("parented", parent);
5659
- } else if (oldParent) {
5660
- this.emit("unparented", oldParent);
5661
5661
  }
5662
+ this.setTree(parent?._tree);
5662
5663
  }
5663
5664
  return this;
5664
5665
  }
@@ -9783,6 +9784,7 @@ let Text2D = class extends TextureRect2D {
9783
9784
  fonts;
9784
9785
  texture = new CanvasTexture();
9785
9786
  text = new Text();
9787
+ measureResult;
9786
9788
  _subTextsCount = 0;
9787
9789
  constructor(properties, children = []) {
9788
9790
  super();
@@ -9816,7 +9818,17 @@ let Text2D = class extends TextureRect2D {
9816
9818
  this.text.requestUpdate();
9817
9819
  }
9818
9820
  _updateStyleProperty(key, value, oldValue) {
9819
- super._updateStyleProperty(key, value, oldValue);
9821
+ switch (key) {
9822
+ case "left":
9823
+ case "top":
9824
+ case "width":
9825
+ case "height":
9826
+ this.requestRedraw();
9827
+ break;
9828
+ default:
9829
+ super._updateStyleProperty(key, value, oldValue);
9830
+ break;
9831
+ }
9820
9832
  switch (key) {
9821
9833
  case "width":
9822
9834
  if (this.split) {
@@ -9838,10 +9850,9 @@ let Text2D = class extends TextureRect2D {
9838
9850
  }
9839
9851
  _updateSubTexts() {
9840
9852
  const subTexts = this._getSubTexts();
9841
- const result = this.measure();
9842
9853
  let i = 0;
9843
9854
  if (this.split) {
9844
- result.paragraphs.forEach((p) => {
9855
+ this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
9845
9856
  p.fragments.forEach((f) => {
9846
9857
  f.characters.forEach((c) => {
9847
9858
  const child = subTexts[i];
@@ -9857,21 +9868,26 @@ let Text2D = class extends TextureRect2D {
9857
9868
  }
9858
9869
  measure() {
9859
9870
  this._updateText();
9860
- const result = this.text.measure();
9861
- if (!this.style.width)
9862
- this.style.width = result.boundingBox.width;
9863
- if (!this.style.height)
9864
- this.style.height = result.boundingBox.height;
9865
- return result;
9871
+ return this.text.measure();
9872
+ }
9873
+ updateMeasure() {
9874
+ this.measureResult = this.measure();
9875
+ const textWidth = this.measureResult.boundingBox.width;
9876
+ const textHeight = this.measureResult.boundingBox.height;
9877
+ const { left, top, width, height = textHeight } = this.style;
9878
+ this.position.x = left + Math.min(0, ((width || textWidth) - textWidth) / 2);
9879
+ this.position.y = top + Math.min(0, ((height || textHeight) - textHeight) / 2);
9880
+ this.size.width = textWidth;
9881
+ this.size.height = textHeight;
9882
+ return this;
9866
9883
  }
9867
9884
  _updateSplit() {
9868
9885
  if (this._subTextsCount) {
9869
9886
  this.getChildren("front").forEach((child) => this.removeChild(child));
9870
9887
  this._subTextsCount = 0;
9871
9888
  }
9872
- const result = this.measure();
9873
9889
  if (this.split) {
9874
- result.paragraphs.forEach((p) => {
9890
+ this.measureResult?.paragraphs.forEach((p) => {
9875
9891
  p.fragments.forEach((f) => {
9876
9892
  f.characters.forEach((c) => {
9877
9893
  this.appendChild(
@@ -9894,13 +9910,16 @@ let Text2D = class extends TextureRect2D {
9894
9910
  });
9895
9911
  }
9896
9912
  }
9913
+ _redraw() {
9914
+ this.updateMeasure();
9915
+ return super._redraw();
9916
+ }
9897
9917
  _drawContent() {
9898
9918
  if (!this.split) {
9899
9919
  const onText2DRender = this.getChildren()?.find((child) => "onText2DRender" in child)?.onText2DRender;
9900
9920
  if (onText2DRender) {
9901
9921
  onText2DRender();
9902
9922
  } else {
9903
- this._updateText();
9904
9923
  this.text.render({
9905
9924
  pixelRatio: this.texture.pixelRatio,
9906
9925
  view: this.texture.source
@@ -10130,10 +10149,12 @@ let Animation = class extends TimelineNode {
10130
10149
  super();
10131
10150
  this.setProperties(properties).append(children);
10132
10151
  }
10133
- _treeEnter(_tree) {
10152
+ _parented(parent) {
10153
+ super._parented(parent);
10134
10154
  this._updateCachedProps();
10135
10155
  }
10136
- _treeExit(_oldTree) {
10156
+ _unparented(oldParent) {
10157
+ super._unparented(oldParent);
10137
10158
  this.cancel();
10138
10159
  }
10139
10160
  _process() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.17",
4
+ "version": "0.4.19",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",