modern-canvas 0.4.18 → 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
@@ -9790,6 +9790,7 @@ exports.Text2D = class Text2D extends TextureRect2D {
9790
9790
  fonts;
9791
9791
  texture = new CanvasTexture();
9792
9792
  text = new modernText.Text();
9793
+ measureResult;
9793
9794
  _subTextsCount = 0;
9794
9795
  constructor(properties, children = []) {
9795
9796
  super();
@@ -9823,7 +9824,17 @@ exports.Text2D = class Text2D extends TextureRect2D {
9823
9824
  this.text.requestUpdate();
9824
9825
  }
9825
9826
  _updateStyleProperty(key, value, oldValue) {
9826
- 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
+ }
9827
9838
  switch (key) {
9828
9839
  case "width":
9829
9840
  if (this.split) {
@@ -9845,10 +9856,9 @@ exports.Text2D = class Text2D extends TextureRect2D {
9845
9856
  }
9846
9857
  _updateSubTexts() {
9847
9858
  const subTexts = this._getSubTexts();
9848
- const result = this.measure();
9849
9859
  let i = 0;
9850
9860
  if (this.split) {
9851
- result.paragraphs.forEach((p) => {
9861
+ this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
9852
9862
  p.fragments.forEach((f) => {
9853
9863
  f.characters.forEach((c) => {
9854
9864
  const child = subTexts[i];
@@ -9864,21 +9874,26 @@ exports.Text2D = class Text2D extends TextureRect2D {
9864
9874
  }
9865
9875
  measure() {
9866
9876
  this._updateText();
9867
- const result = this.text.measure();
9868
- if (!this.style.width)
9869
- this.style.width = result.boundingBox.width;
9870
- if (!this.style.height)
9871
- this.style.height = result.boundingBox.height;
9872
- 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;
9873
9889
  }
9874
9890
  _updateSplit() {
9875
9891
  if (this._subTextsCount) {
9876
9892
  this.getChildren("front").forEach((child) => this.removeChild(child));
9877
9893
  this._subTextsCount = 0;
9878
9894
  }
9879
- const result = this.measure();
9880
9895
  if (this.split) {
9881
- result.paragraphs.forEach((p) => {
9896
+ this.measureResult?.paragraphs.forEach((p) => {
9882
9897
  p.fragments.forEach((f) => {
9883
9898
  f.characters.forEach((c) => {
9884
9899
  this.appendChild(
@@ -9901,13 +9916,16 @@ exports.Text2D = class Text2D extends TextureRect2D {
9901
9916
  });
9902
9917
  }
9903
9918
  }
9919
+ _redraw() {
9920
+ this.updateMeasure();
9921
+ return super._redraw();
9922
+ }
9904
9923
  _drawContent() {
9905
9924
  if (!this.split) {
9906
9925
  const onText2DRender = this.getChildren()?.find((child) => "onText2DRender" in child)?.onText2DRender;
9907
9926
  if (onText2DRender) {
9908
9927
  onText2DRender();
9909
9928
  } else {
9910
- this._updateText();
9911
9929
  this.text.render({
9912
9930
  pixelRatio: this.texture.pixelRatio,
9913
9931
  view: this.texture.source
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
 
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
 
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
 
package/dist/index.js CHANGED
@@ -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)}_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;
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
@@ -9784,6 +9784,7 @@ let Text2D = class extends TextureRect2D {
9784
9784
  fonts;
9785
9785
  texture = new CanvasTexture();
9786
9786
  text = new Text();
9787
+ measureResult;
9787
9788
  _subTextsCount = 0;
9788
9789
  constructor(properties, children = []) {
9789
9790
  super();
@@ -9817,7 +9818,17 @@ let Text2D = class extends TextureRect2D {
9817
9818
  this.text.requestUpdate();
9818
9819
  }
9819
9820
  _updateStyleProperty(key, value, oldValue) {
9820
- 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
+ }
9821
9832
  switch (key) {
9822
9833
  case "width":
9823
9834
  if (this.split) {
@@ -9839,10 +9850,9 @@ let Text2D = class extends TextureRect2D {
9839
9850
  }
9840
9851
  _updateSubTexts() {
9841
9852
  const subTexts = this._getSubTexts();
9842
- const result = this.measure();
9843
9853
  let i = 0;
9844
9854
  if (this.split) {
9845
- result.paragraphs.forEach((p) => {
9855
+ this.updateMeasure().measureResult?.paragraphs.forEach((p) => {
9846
9856
  p.fragments.forEach((f) => {
9847
9857
  f.characters.forEach((c) => {
9848
9858
  const child = subTexts[i];
@@ -9858,21 +9868,26 @@ let Text2D = class extends TextureRect2D {
9858
9868
  }
9859
9869
  measure() {
9860
9870
  this._updateText();
9861
- const result = this.text.measure();
9862
- if (!this.style.width)
9863
- this.style.width = result.boundingBox.width;
9864
- if (!this.style.height)
9865
- this.style.height = result.boundingBox.height;
9866
- 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;
9867
9883
  }
9868
9884
  _updateSplit() {
9869
9885
  if (this._subTextsCount) {
9870
9886
  this.getChildren("front").forEach((child) => this.removeChild(child));
9871
9887
  this._subTextsCount = 0;
9872
9888
  }
9873
- const result = this.measure();
9874
9889
  if (this.split) {
9875
- result.paragraphs.forEach((p) => {
9890
+ this.measureResult?.paragraphs.forEach((p) => {
9876
9891
  p.fragments.forEach((f) => {
9877
9892
  f.characters.forEach((c) => {
9878
9893
  this.appendChild(
@@ -9895,13 +9910,16 @@ let Text2D = class extends TextureRect2D {
9895
9910
  });
9896
9911
  }
9897
9912
  }
9913
+ _redraw() {
9914
+ this.updateMeasure();
9915
+ return super._redraw();
9916
+ }
9898
9917
  _drawContent() {
9899
9918
  if (!this.split) {
9900
9919
  const onText2DRender = this.getChildren()?.find((child) => "onText2DRender" in child)?.onText2DRender;
9901
9920
  if (onText2DRender) {
9902
9921
  onText2DRender();
9903
9922
  } else {
9904
- this._updateText();
9905
9923
  this.text.render({
9906
9924
  pixelRatio: this.texture.pixelRatio,
9907
9925
  view: this.texture.source
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.18",
4
+ "version": "0.4.19",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",