modern-canvas 0.12.2 → 0.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -10094,9 +10094,9 @@ class BaseElement2DText extends CoreObject {
10094
10094
  this.parent = parent;
10095
10095
  this.base = new modernText.Text();
10096
10096
  this.base.setPropertyAccessor(this);
10097
+ this.update();
10097
10098
  }
10098
10099
  base;
10099
- measureResult;
10100
10100
  _texture = new CanvasTexture();
10101
10101
  _textureMap = /* @__PURE__ */ new Map();
10102
10102
  setProperties(properties) {
@@ -10187,10 +10187,6 @@ class BaseElement2DText extends CoreObject {
10187
10187
  this.update();
10188
10188
  return this.base.measure();
10189
10189
  }
10190
- updateMeasure() {
10191
- this.measureResult = this.measure();
10192
- return this;
10193
- }
10194
10190
  isValid() {
10195
10191
  return Boolean(
10196
10192
  this.enabled && !/^\s*$/.test(this.base.toString())
@@ -10496,6 +10492,7 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10496
10492
  if (textStyles.has(key) || layoutStyle.has(key)) {
10497
10493
  if (this.text.isValid()) {
10498
10494
  this.text.update();
10495
+ this.requestRedraw();
10499
10496
  }
10500
10497
  }
10501
10498
  }
package/dist/index.d.cts CHANGED
@@ -2104,7 +2104,6 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measureDom: Text['measureDom'];
2105
2105
  fonts: Text['fonts'];
2106
2106
  readonly base: Text;
2107
- measureResult?: MeasureResult;
2108
2107
  protected _texture: CanvasTexture;
2109
2108
  protected _textureMap: Map<string, {
2110
2109
  texture: Texture2D | undefined;
@@ -2119,7 +2118,6 @@ declare class BaseElement2DText extends CoreObject {
2119
2118
  protected _loadTexture(fill: NormalizedFill, box: any): Promise<Texture2D | undefined>;
2120
2119
  setContent(content: TextContent): void;
2121
2120
  measure(): MeasureResult;
2122
- updateMeasure(): this;
2123
2121
  isValid(): boolean;
2124
2122
  protected _createVertTransform(): Transform2D | undefined;
2125
2123
  useTextureDraw(): boolean;
package/dist/index.d.mts CHANGED
@@ -2104,7 +2104,6 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measureDom: Text['measureDom'];
2105
2105
  fonts: Text['fonts'];
2106
2106
  readonly base: Text;
2107
- measureResult?: MeasureResult;
2108
2107
  protected _texture: CanvasTexture;
2109
2108
  protected _textureMap: Map<string, {
2110
2109
  texture: Texture2D | undefined;
@@ -2119,7 +2118,6 @@ declare class BaseElement2DText extends CoreObject {
2119
2118
  protected _loadTexture(fill: NormalizedFill, box: any): Promise<Texture2D | undefined>;
2120
2119
  setContent(content: TextContent): void;
2121
2120
  measure(): MeasureResult;
2122
- updateMeasure(): this;
2123
2121
  isValid(): boolean;
2124
2122
  protected _createVertTransform(): Transform2D | undefined;
2125
2123
  useTextureDraw(): boolean;
package/dist/index.d.ts CHANGED
@@ -2104,7 +2104,6 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measureDom: Text['measureDom'];
2105
2105
  fonts: Text['fonts'];
2106
2106
  readonly base: Text;
2107
- measureResult?: MeasureResult;
2108
2107
  protected _texture: CanvasTexture;
2109
2108
  protected _textureMap: Map<string, {
2110
2109
  texture: Texture2D | undefined;
@@ -2119,7 +2118,6 @@ declare class BaseElement2DText extends CoreObject {
2119
2118
  protected _loadTexture(fill: NormalizedFill, box: any): Promise<Texture2D | undefined>;
2120
2119
  setContent(content: TextContent): void;
2121
2120
  measure(): MeasureResult;
2122
- updateMeasure(): this;
2123
2121
  isValid(): boolean;
2124
2122
  protected _createVertTransform(): Transform2D | undefined;
2125
2123
  useTextureDraw(): boolean;
package/dist/index.js CHANGED
@@ -954,7 +954,7 @@ void main() {
954
954
  gl_FragColor = color;
955
955
  }`})),ai([_()],f.ZoomBlurEffect.prototype,"center",2),ai([_({fallback:20})],f.ZoomBlurEffect.prototype,"innerRadius",2),ai([_({fallback:-1})],f.ZoomBlurEffect.prototype,"radius",2),ai([_({fallback:.1})],f.ZoomBlurEffect.prototype,"strength",2),f.ZoomBlurEffect=ai([X("ZoomBlurEffect")],f.ZoomBlurEffect);function rs(s,e){let t=!1;const{left:r=0,top:i=0,width:n,height:o}=e,a=new ke().translate(-r,-i).scale(1/n,1/o);if(s.cropRect){const{left:l=0,top:c=0,right:h=0,bottom:u=0}=s.cropRect;a.scale(Math.abs(1-(l+h)),Math.abs(1-(c+u))).translate(l,c),t=!0}if(s.tile){const{translateX:l=0,translateY:c=0,scaleX:h=1,scaleY:u=1}=s.tile;a.translate(-l/n,-c/o).scale(1/h,1/u),t=!0}else if(s.stretchRect){const{left:l=0,top:c=0,right:h=0,bottom:u=0}=s.stretchRect;a.scale(Math.abs(1-(-l+-h)),Math.abs(1-(-c+-u))).translate(-l,-c),t=!0}return{disableWrapMode:t,uvTransform:a}}var eg=Object.defineProperty,st=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&eg(e,t,i),i};class Oe extends xt{constructor(e){super(),this.parent=e}_texture;_animatedTexture;_setProperties(e){return super.setProperties(e)}setProperties(e){return this._setProperties(K(e)?void 0:ct(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"color":case"cropRect":case"stretchRect":case"dpi":case"rotateWithShape":case"tile":case"opacity":case"enabled":this.parent.requestRedraw();break;case"image":case"linearGradient":case"radialGradient":this._updateTexture();break}}async loadTexture(){this.linearGradient||this.radialGradient?this._texture=new zr(this.linearGradient??this.radialGradient,this.parent.size.width,this.parent.size.height):K(this.image)||(this.parent.tree?.log(`load image ${this.image}`),this.image.split("?")[0].endsWith(".gif")?this._animatedTexture=await Ke.gif.load(this.image):this._texture=await Ke.texture.load(this.image))}async _updateTexture(){await this.loadTexture(),this.parent.requestRedraw()}isValid(){return!!(this.enabled&&(this._texture||this._animatedTexture||this.color))}draw(){const e=this.parent.context,{uvTransform:t,disableWrapMode:r}=rs(this,{width:this.parent.size.width,height:this.parent.size.height});e.uvTransform=t,e.fillStyle=this._animatedTexture?.currentFrame.texture??this._texture??this.color,e.fill({disableWrapMode:r})}_getFrameCurrentTime(){const e=this._animatedTexture?.duration??0;if(!e)return 0;const t=this.parent._currentTime;return t<0?0:t%e}updateFrameIndex(){if(!this._animatedTexture)return this;const e=this._getFrameCurrentTime(),t=this._animatedTexture.frames,r=t.length;if(r<=1&&this._animatedTexture.frameIndex===0)return this;let i=r-1;for(let n=0,o=0;o<r;o++)if(n+=t[o].duration??0,n>=e){i=o;break}return this._animatedTexture.frameIndex!==i&&(this._animatedTexture.frameIndex=i,this.parent.requestRedraw()),this}}st([_({fallback:!0})],Oe.prototype,"enabled"),st([_()],Oe.prototype,"color"),st([_()],Oe.prototype,"image"),st([_()],Oe.prototype,"linearGradient"),st([_()],Oe.prototype,"radialGradient"),st([_()],Oe.prototype,"cropRect"),st([_()],Oe.prototype,"stretchRect"),st([_()],Oe.prototype,"dpi"),st([_()],Oe.prototype,"rotateWithShape"),st([_()],Oe.prototype,"tile"),st([_()],Oe.prototype,"opacity");var tg=Object.defineProperty,rg=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&tg(e,t,i),i};class Dn extends Oe{setProperties(e){return super._setProperties(K(e)?void 0:Yc(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"fillWithShape":this.parent.requestRedraw();break}}}rg([_()],Dn.prototype,"fillWithShape");var ig=Object.defineProperty,sg=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&ig(e,t,i),i};class In extends Oe{setProperties(e){return super._setProperties(K(e)?void 0:Kc(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"fillWithShape":this.parent.requestRedraw();break}}}sg([_()],In.prototype,"fillWithShape");var ng=Object.defineProperty,li=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&ng(e,t,i),i};class tr extends Oe{setProperties(e){return super._setProperties(K(e)?void 0:bi(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"width":case"style":case"lineCap":case"lineJoin":case"enabled":this.parent.requestRedraw();break}}isValid(){return!!(this.enabled&&(this.width||this.color||super.isValid()))}draw(){const e=this.parent.context,{uvTransform:t,disableWrapMode:r}=rs(this,{width:this.parent.size.width,height:this.parent.size.height});e.lineWidth=this.width||1,e.uvTransform=t,e.strokeStyle=this._texture??this.color,e.lineCap=this.lineCap,e.lineJoin=this.lineJoin,e.stroke({disableWrapMode:r})}}li([_({fallback:"#00000000"})],tr.prototype,"color"),li([_({fallback:0})],tr.prototype,"width"),li([_({fallback:"solid"})],tr.prototype,"style"),li([_({fallback:"butt"})],tr.prototype,"lineCap"),li([_({fallback:"miter"})],tr.prototype,"lineJoin");var og=Object.defineProperty,ci=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&og(e,t,i),i};class rr extends xt{constructor(e){super(),this.parent=e}setProperties(e){return super.setProperties(K(e)?void 0:Zc(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"color":case"blur":case"offsetX":case"offsetY":this.updateEffect();break}}updateEffect(){const e="__$shadow";let t=this.parent.getNode(e);this.blur||this.offsetX||this.offsetY?(t||(t=new f.DropShadowEffect({name:e}),this.parent.appendChild(t,"back")),t.setProperties(this.getProperties())):t&&this.parent.removeChild(t)}}ci([_({fallback:!0})],rr.prototype,"enabled"),ci([_({fallback:"#000000FF"})],rr.prototype,"color"),ci([_({fallback:0})],rr.prototype,"blur"),ci([_({fallback:0})],rr.prototype,"offsetY"),ci([_({fallback:0})],rr.prototype,"offsetX");var ag=Object.defineProperty,hi=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&ag(e,t,i),i};class ir extends xt{constructor(e){super(),this.parent=e,this._updatePath2DSet()}_path2DSet=new Tt;setProperties(e){return super.setProperties(K(e)?void 0:Qc(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"svg":case"paths":case"viewBox":case"enabled":this._updatePath2DSet(),this.parent.requestRedraw();break}}_updatePath2DSet(){let e;if(this.svg){const o=Gs(this.svg);this._path2DSet=Ws(o),e=this._path2DSet.viewBox}else this.paths?.forEach((o,a)=>{const{data:l,...c}=o,h=new ge;h.style=c,h.addData(l),this._path2DSet.paths[a]=h});if(!e){const o=this._path2DSet.getBoundingBox();e=o?[o.x,o.y,o.width||1,o.height||1]:[0,0,1,1]}const[t,r,i,n]=e;this._path2DSet.paths.forEach(o=>{o.applyTransform(new _e().translate(-t,-r).scale(1/i,1/n))})}draw(e=!1){if(!e&&this.enabled&&this._path2DSet.paths.length){const t=this.parent.context,{width:r,height:i}=this.parent.size;this._path2DSet.paths.forEach(n=>{t.addPath(n.clone().applyTransform(new _e().scale(r,i)))})}else this._drawRect()}_drawRect(){const e=this.parent.context,{width:t,height:r}=this.parent.size,{borderRadius:i}=this.parent.style;t&&r&&(i?e.roundRect(0,0,t,r,i):e.rect(0,0,t,r))}}hi([_({fallback:!0})],ir.prototype,"enabled"),hi([_()],ir.prototype,"preset"),hi([_()],ir.prototype,"svg"),hi([_()],ir.prototype,"viewBox"),hi([_()],ir.prototype,"paths");class ui extends Pt{constructor(e){super(),this.setProperties(e)}}const $l=Po();for(const s in $l){const e=$l[s];mi(ui,s,{fallback:e})}function Rn(s,e,t){if(typeof e=="string"&&e.startsWith("linear-gradient")){const{x0:r,y0:i,x1:n,y1:o,stops:a}=lg(e,t.left,t.top,t.width,t.height),l=s.createLinearGradient(r,i,n,o);return a.forEach(c=>l.addColorStop(c.offset,c.color)),l}return e}function is(s,e,t){s?.color&&(s.color=Rn(t,s.color,e)),s?.backgroundColor&&(s.backgroundColor=Rn(t,s.backgroundColor,e)),s?.textStrokeColor&&(s.textStrokeColor=Rn(t,s.textStrokeColor,e))}function lg(s,e,t,r,i){const n=s.match(/linear-gradient\((.+)\)$/)?.[1]??"",o=n.split(",")[0],a=o.includes("deg")?o:"0deg",l=n.replace(a,"").matchAll(/(#|rgba|rgb)(.+?) ([\d.]+%)/gi),h=(Number(a.replace("deg",""))||0)*Math.PI/180,u=r*Math.sin(h),d=i*Math.cos(h);return{x0:e+r/2-u,y0:t+i/2+d,x1:e+r/2+u,y1:t+i/2-d,stops:Array.from(l).map(g=>{let p=g[2];return p.startsWith("(")?p=p.split(",").length>3?`rgba${p}`:`rgb${p}`:p=`#${p}`,{offset:Number(g[3].replace("%",""))/100,color:p}})}}function Pr(s){const{ctx:e,path:t,fontSize:r,clipRect:i}=s;e.save(),e.beginPath();const n=t.style,o={...n,fill:s.color??n.fill,stroke:s.textStrokeColor??n.stroke,strokeWidth:s.textStrokeWidth?s.textStrokeWidth*r:n.strokeWidth,strokeLinecap:"round",strokeLinejoin:"round",shadowOffsetX:(s.shadowOffsetX??0)*r,shadowOffsetY:(s.shadowOffsetY??0)*r,shadowBlur:(s.shadowBlur??0)*r,shadowColor:s.shadowColor};i&&(e.rect(i.left,i.top,i.width,i.height),e.clip(),e.beginPath()),t.drawTo(e,o),e.restore()}function cg(s,e,t){const{left:r,top:i,width:n,height:o}=t,a=s.canvas;a.dataset.viewBox=`${r} ${i} ${n} ${o}`,a.dataset.pixelRatio=String(e);const l=n,c=o;a.width=Math.max(1,Math.ceil(l*e)),a.height=Math.max(1,Math.ceil(c*e)),a.style.width=`${l}px`,a.style.height=`${c}px`,s.clearRect(0,0,a.width,a.height),s.scale(e,e),s.translate(-r,-i)}function hg(s,e){const{paragraphs:t,computedStyle:r,glyphBox:i}=e;is(r,i,s),t.forEach(n=>{is(n.computedStyle,n.lineBox,s),n.fragments.forEach(o=>{is(o.computedStyle,o.inlineBox,s)})})}const ug=new Set(["©","®","÷"]),fg=new Set(["—","…","“","”","﹏","﹋","﹌","‘","’","˜"]),dg={1:"italic",32:"bold"},pg={1:"italic",2:"bold"},zl={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5};class Vl{constructor(e,t,r){this.content=e,this.index=t,this.parent=r}path=new ge().setMeta(this);lineBox=new Z;inlineBox=new Z;glyphBox;advanceWidth=0;advanceHeight=0;underlinePosition=0;underlineThickness=0;strikeoutPosition=0;strikeoutSize=0;ascender=0;descender=0;typoAscender=0;typoDescender=0;typoLineGap=0;winAscent=0;winDescent=0;xHeight=0;capHeight=0;baseline=0;centerDiviation=0;fontStyle;get compatibleGlyphBox(){const e=this.computedStyle.fontSize*.8;return this.glyphBox??(this.isVertical?new Z(this.lineBox.left+this.lineBox.width/2-e/2,this.lineBox.top,e,this.lineBox.height):new Z(this.lineBox.left,this.lineBox.top+this.lineBox.height/2-e/2,this.lineBox.width,e))}get center(){return this.compatibleGlyphBox.center}get computedFill(){return this.parent.computedFill}get computedOutline(){return this.parent.computedOutline}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(e){const t=this.computedStyle.fontFamily,r=e??Tn;let n=(t?r.get(t):r.fallbackFont)?.getSFNT();return n?.textToGlyphIndexes(this.content).includes(0)&&(n=r.fallbackFont?.getSFNT()),n}updateGlyph(e=this._getFontSFNT()){if(!e)return this;const{hhea:t,os2:r,post:i,head:n}=e,o=n.unitsPerEm,a=t.ascent,l=t.descent,{content:c,computedStyle:h,isVertical:u}=this,{fontSize:d}=h,g=o/d,p=e.getAdvanceWidth(c,d),y=(a+Math.abs(l))/g,m=a/g;return this.advanceWidth=p,this.advanceHeight=y,this.inlineBox.width=u?y:p,this.inlineBox.height=u?p:y,this.underlinePosition=(a-i.underlinePosition)/g,this.underlineThickness=i.underlineThickness/g,this.strikeoutPosition=(a-r.yStrikeoutPosition)/g,this.strikeoutSize=r.yStrikeoutSize/g,this.ascender=a/g,this.descender=l/g,this.typoAscender=r.sTypoAscender/g,this.typoDescender=r.sTypoDescender/g,this.typoLineGap=r.sTypoLineGap/g,this.winAscent=r.usWinAscent/g,this.winDescent=r.usWinDescent/g,this.xHeight=r.sxHeight/g,this.capHeight=r.sCapHeight/g,this.baseline=m,this.centerDiviation=y/2-m,this.fontStyle=dg[r.fsSelection]??pg[n.macStyle],this}update(e){const t=this._getFontSFNT(e);if(!t)return this;this.updateGlyph(t);const{isVertical:r,content:i,computedStyle:n,baseline:o,inlineBox:a,ascender:l,descender:c,typoAscender:h,fontStyle:u,advanceWidth:d,advanceHeight:g}=this,{left:p,top:y}=a,m=n.fontStyle==="italic"&&u!=="italic";let P=p,E=y+o,b;const S=new ge().setMeta(this);if(r&&(P+=(g-d)/2,Math.abs(d-g)>.1&&(E-=(l-h)/(l+Math.abs(c))*g),b=void 0),r&&!ug.has(i)&&(i.codePointAt(0)<=256||fg.has(i))){S.addCommands(t.getPathCommands(i,P,y+o-(g-d)/2,n.fontSize));const x={y:y-(g-d)/2+g/2,x:P+d/2};m&&this._italic(S,r?{x:x.x,y:y-(g-d)/2+o}:void 0),S.rotate(90,x)}else b!==void 0?(S.addCommands(t.glyphs.get(b).getPathCommands(P,E,n.fontSize)),m&&this._italic(S,r?{x:P+d/2,y:y+h/(l+Math.abs(c))*g}:void 0)):(S.addCommands(t.getPathCommands(i,P,E,n.fontSize)),m&&this._italic(S,r?{x:P+g/2,y:E}:void 0));const w=n.fontWeight??400;return w in zl&&(w===700||w==="bold")&&u!=="bold"&&S.bold(zl[w]*n.fontSize*.05),S.style={fill:this.computedFill??n.color,fillRule:"nonzero",stroke:this.computedOutline??(n.textStrokeWidth?n.textStrokeColor:"none"),strokeWidth:n.textStrokeWidth?n.textStrokeWidth*n.fontSize*.03:0},this.path=S,this.glyphBox=this.getGlyphBoundingBox(),this}_italic(e,t){e.skew(-.24,0,t||{y:this.inlineBox.top+this.baseline,x:this.inlineBox.left+this.inlineBox.width/2})}getGlyphMinMax(e,t,r){if(this.path.curves[0]?.curves.length)return this.path.getMinMax(e,t,r)}getGlyphBoundingBox(e){const t=this.getGlyphMinMax(void 0,void 0,e);if(!t)return;const{min:r,max:i}=t;return new Z(r.x,r.y,i.x-r.x,i.y-r.y)}drawTo(e,t={}){const r=this.computedStyle,i={ctx:e,path:this.path,fontSize:r.fontSize,color:r.color,...t};if(this.glyphBox)Pr(i);else{e.save(),e.beginPath();const n=this.path.style,o={...n,fill:i.color??n.fill,stroke:i.textStrokeColor??n.stroke,strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize:n.strokeWidth,shadowOffsetX:(i.shadowOffsetX??0)*i.fontSize,shadowOffsetY:(i.shadowOffsetY??0)*i.fontSize,shadowBlur:(i.shadowBlur??0)*i.fontSize,shadowColor:i.shadowColor};zs(e,o),e.font=`${i.fontSize}px ${i.fontFamily}`,this.isVertical?(e.textBaseline="middle",e.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.inlineBox.height/2)):(e.textBaseline="alphabetic",e.fillText(this.content,this.inlineBox.left,this.inlineBox.top+this.baseline)),e.restore()}}}function Gl(){const s=new Map;async function e(r){if(!s.has(r)){s.set(r,r);try{s.set(r,await fetch(r).then(i=>i.text()))}catch(i){console.warn(i),s.delete(r)}}}function t(r){return r.startsWith("http://")||r.startsWith("https://")||r.startsWith("blob://")}return{loaded:s,needsLoad:t,load:e}}function jl(s){const e=new Map;function t(r){let i=e.get(r);if(!i){const n=Gs(s.needsLoad(r)?s.loaded.get(r)??r:r),o=Ws(n);i={dom:n,pathSet:o},e.set(r,i)}return i}return{parsed:e,parse:t}}function Un(s,e){return typeof s=="number"?s:s.endsWith("%")?(s=s.substring(0,s.length-1),Math.ceil(Number(s)/100*e.total)):s.endsWith("rem")?(s=s.substring(0,s.length-3),Number(s)*e.fontSize):s.endsWith("em")?(s=s.substring(0,s.length-2),Number(s)*e.fontSize):Number(s)}function Bn(s){return K(s)?{}:s}function gg(s,e){const t=Object.keys(s),r=Object.keys(e);return Array.from(new Set([...t,...r])).every(n=>Cr(s[n],e[n]))}function Cr(s,e){const t=typeof s;return t===typeof e?t==="object"?gg(s,e):s===e:!1}function Ln(s){if(!s)return s;const e={};for(const t in s)s[t]!==""&&s[t]!==void 0&&(e[t]=s[t]);return e}class mg{constructor(e,t={},r,i){this.content=e,this.style=t,this.index=r,this.parent=i,this.updateComputedStyle().initCharacters()}inlineBox=new Z;fill;outline;get computedFill(){return this.fill??this.parent.computedFill}get computedOutline(){return this.outline??this.parent.computedOutline}get computedContent(){const e=this.computedStyle;return e.textTransform==="uppercase"?this.content.toUpperCase():e.textTransform==="lowercase"?this.content.toLowerCase():this.content}updateComputedStyle(){return this.computedStyle={...this.parent.computedStyle,...Ln(this.style)},this}initCharacters(){const e=[];let t=0;for(const r of this.computedContent)e.push(new Vl(r,t++,this));return this.characters=e,this}}class yg{constructor(e,t,r){this.style=e,this.index=t,this.parent=r,this.updateComputedStyle()}lineBox=new Z;fragments=[];fill;outline;get computedFill(){return this.fill??this.parent.fill}get computedOutline(){return this.outline??this.parent.outline}updateComputedStyle(){return this.computedStyle={...Ln(this.parent.computedStyle),...Ln(this.style)},this}}function km(s){return s}class ss{static notZeroStyles=new Set(["width","height"]);static pxStyles=new Set(["width","height","fontSize","letterSpacing","textStrokeWidth","textIndent","shadowOffsetX","shadowOffsetY","shadowBlur","margin","marginLeft","marginTop","marginRight","marginBottom","padding","paddingLeft","paddingTop","paddingRight","paddingBottom"]);_toDomStyle(e){const t={};for(const r in e){const i=e[r];ss.notZeroStyles.has(r)&&i===0||(typeof i=="number"&&ss.pxStyles.has(r)?t[r]=`${i}px`:t[r]=i)}return t}createDom(e,t){const r=document.createElement("section"),i={...t},n=t.writingMode.includes("horizontal");switch(t.textAlign){case"start":case"left":i.justifyContent="flex-start";break;case"center":i.justifyContent="center";break;case"end":case"right":i.justifyContent="flex-end";break}switch(t.verticalAlign){case"top":i.alignItems="flex-start";break;case"middle":i.alignItems="center";break;case"bottom":i.alignItems="flex-end";break}const o=!!(i.justifyContent||i.alignItems);Object.assign(r.style,{...this._toDomStyle({...i,boxSizing:i.boxSizing??"border-box",display:i.display??(o?"inline-flex":void 0),width:i.width??"max-content",height:i.height??"max-content"}),whiteSpace:"pre-wrap",wordBreak:"break-all"});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}),e.forEach(l=>{const c=document.createElement("li");Object.assign(c.style,{verticalAlign:"inherit",...this._toDomStyle(l.style)}),l.fragments.forEach(h=>{const u=document.createElement("span");Object.assign(u.style,{verticalAlign:"inherit",...this._toDomStyle(h.style)}),u.appendChild(document.createTextNode(h.content)),c.appendChild(u)}),a.appendChild(c)}),r.appendChild(a),r}measureDomText(e){const t=document.createRange();t.selectNodeContents(e);const r=e.data??"";let i=0;return Array.from(r).map(n=>{const o=i+=r.substring(i).indexOf(n),a=o+n.length;i+=n.length,t.setStart(e,Math.max(o,0)),t.setEnd(e,a);const l=t.getClientRects?.()??[t.getBoundingClientRect()];let c=l[l.length-1];l.length>1&&c.width<2&&(c=l[l.length-2]);const h=t.toString();if(h!==""&&c&&c.width+c.height!==0)return{content:h,top:c.top,left:c.left,height:c.height,width:c.width}}).filter(Boolean)}measureDom(e){const t=[],r=[],i=[];return e.querySelectorAll("li").forEach((n,o)=>{const a=n.getBoundingClientRect();t.push({paragraphIndex:o,left:a.left,top:a.top,width:a.width,height:a.height}),n.querySelectorAll(":scope > *").forEach((l,c)=>{const h=l.getBoundingClientRect();r.push({paragraphIndex:o,fragmentIndex:c,left:h.left,top:h.top,width:h.width,height:h.height});let u=0;!l.children.length&&l.firstChild instanceof window.Text?this.measureDomText(l.firstChild).forEach(d=>{i.push({...d,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:c,characterIndex:u++,textWidth:-1,textHeight:-1})}):l.querySelectorAll(":scope > *").forEach(d=>{d.firstChild instanceof window.Text&&this.measureDomText(d.firstChild).forEach(g=>{i.push({...g,newParagraphIndex:-1,paragraphIndex:o,fragmentIndex:c,characterIndex:u++,textWidth:-1,textHeight:-1})})})})}),{paragraphs:t,fragments:r,characters:i}}measureParagraphDom(e,t){const r=t.getBoundingClientRect(),i=this.measureDom(t);i.paragraphs.forEach(a=>{const l=e[a.paragraphIndex];l.lineBox.left=a.left-r.left,l.lineBox.top=a.top-r.top,l.lineBox.width=a.width,l.lineBox.height=a.height}),i.fragments.forEach(a=>{const l=e[a.paragraphIndex].fragments[a.fragmentIndex];l.inlineBox.left=a.left-r.left,l.inlineBox.top=a.top-r.top,l.inlineBox.width=a.width,l.inlineBox.height=a.height});const n=[];let o=0;return i.characters.forEach(a=>{const{paragraphIndex:l,fragmentIndex:c,characterIndex:h}=a;n.push({...a,newParagraphIndex:l,left:a.left-r.left,top:a.top-r.top});const u=e[l].fragments[c].characters[h],{fontHeight:d,isVertical:g}=u,p=n[o];u.inlineBox.left=p.left,u.inlineBox.top=p.top,u.inlineBox.width=p.width,u.inlineBox.height=p.height,g?(u.lineBox.left=p.left+(p.width-d)/2,u.lineBox.top=p.top,u.lineBox.width=d,u.lineBox.height=p.height):(u.lineBox.left=p.left,u.lineBox.top=p.top+(p.height-d)/2,u.lineBox.width=p.width,u.lineBox.height=d),o++}),{paragraphs:e,boundingBox:new Z(0,0,r.width,r.height)}}measure(e,t,r){let i;r||(r=this.createDom(e,t),Object.assign(r.style,{position:"fixed",visibility:"hidden"}),document.body.appendChild(r),i=()=>r?.parentNode?.removeChild(r));const n=this.measureParagraphDom(e,r);return i?.(),n}}function vg(){const s=new Tt,e=Gl(),t=jl(e);return{name:"background",pathSet:s,load:async r=>{const{backgroundImage:i}=r.computedStyle;i&&e.needsLoad(i)&&await e.load(i)},update:r=>{s.paths.length=0;const{computedStyle:i,lineBox:n,isVertical:o}=r,{backgroundImage:a,backgroundSize:l,backgroundColormap:c}=i;if(K(a))return;const{pathSet:h}=t.parse(a),u=h.getBoundingBox(!0);let d,g,p,y;o?{x:g,y:d,width:y,height:p}=n:{x:d,y:g,width:p,height:y}=n;const m=Bn(c??"none"),P=h.paths.map(w=>{const x=w.clone();return x.style.fill&&x.style.fill in m&&(x.style.fill=m[x.style.fill]),x.style.stroke&&x.style.stroke in m&&(x.style.stroke=m[x.style.stroke]),x});let E,b;if(l==="rigid"){E=Math.max(r.fontSize*5/u.width),b=E;const w=new k;w.x=u.width-p/E,w.y=u.height-y/b,P.forEach(x=>{x.applyTransform(T=>{const C=T.x>u.left+u.width/2,L=T.y>u.top+u.height/2;C&&(T.x-=w.x),L&&(T.y-=w.y)})})}else E=p/u.width,b=y/u.height;const S=new _e;S.translate(-u.x,-u.y),S.scale(E,b),o&&(S.translate(-p/2,-y/2),S.rotate(-Math.PI/2),S.translate(y/2,p/2)),S.translate(d,g),P.forEach(w=>{w.applyTransform(x=>{x.applyMatrix3(S)})}),s.paths.push(...P)},renderOrder:-2,render:(r,i)=>{const{boundingBox:n,computedStyle:o}=i;K(o.backgroundColor)||(r.fillStyle=o.backgroundColor,r.fillRect(...n.array)),s.paths.forEach(a=>{if(Pr({ctx:r,path:a,fontSize:o.fontSize}),i.debug){const l=new Tt([a]).getBoundingBox();l&&r.strokeRect(l.x,l.y,l.width,l.height)}}),i.paragraphs.forEach(a=>{const{lineBox:l,style:c}=a;K(c.backgroundColor)||(r.fillStyle=c.backgroundColor,r.fillRect(...l.array)),a.fragments.forEach(h=>{const{inlineBox:u,style:d}=h;K(d.backgroundColor)||(r.fillStyle=d.backgroundColor,r.fillRect(...u.array))})})}}}function Fn(s){const{highlight:e,highlightImage:t,highlightReferImage:r,highlightColormap:i,highlightLine:n,highlightSize:o,highlightThickness:a}=s;return{image:e?.image??t??"none",referImage:e?.referImage??r??"none",colormap:e?.colormap??i??"none",line:e?.line??n??"none",size:e?.size??o??"cover",thickness:e?.thickness??a??"100%"}}function _g(){const s=new Tt,e=[],t=Gl(),r=jl(t);return{name:"highlight",pathSet:s,load:async i=>{const n=new Set;i.forEachCharacter(o=>{const{computedStyle:a}=o,{image:l,referImage:c}=Fn(a);l&&t.needsLoad(l)&&n.add(l),c&&t.needsLoad(c)&&n.add(c)}),await Promise.all(Array.from(n).map(o=>t.load(o)))},update:i=>{e.length=0,s.paths.length=0;let n=[],o,a;i.forEachCharacter(l=>{const{computedStyle:c}=l,h=Fn(c),{image:u,colormap:d,line:g,size:p,thickness:y}=h;if(K(u))o?.length&&(o=[],n.push(o));else{const{inlineBox:m,isVertical:P}=l,{fontSize:E}=c;(!a||Cr(a.image,u)&&Cr(a.colormap,d)&&Cr(a.line,g)&&Cr(a.size,p)&&Cr(a.thickness,y))&&o?.length&&(P?o[0].inlineBox.left===m.left:o[0].inlineBox.top===m.top)&&o[0].fontSize===E?o.push(l):(o=[],o.push(l),n.push(o))}a=h}),n=n.filter(l=>l.length);for(let l=0;l<n.length;l++){const c=n[l],h=c[0],u=Z.from(...c.map(O=>O.compatibleGlyphBox));if(!u.height||!u.width)continue;const{computedStyle:d,isVertical:g,inlineBox:p,compatibleGlyphBox:y,strikeoutPosition:m,underlinePosition:P}=h,{fontSize:E}=d,{image:b,referImage:S,colormap:w,line:x,size:T,thickness:C}=Fn(d),L=Un(C,{fontSize:E,total:u.width})/u.width,G=Bn(w),{pathSet:U,dom:R}=r.parse(b),z=U.getBoundingBox(!0),B=E/z.width*2,D=new Z().copy(u);g&&(D.width=u.height,D.height=u.width,D.left=u.left+u.width);const H=Math.floor(D.width);let I=H;T!=="cover"&&(I=Un(T,{fontSize:E,total:u.width})||H,D.width=I);const F=!K(S)&&K(x);if(F)z.copy(r.parse(S).pathSet.getBoundingBox(!0));else{let O;if(K(x))if(z.width/z.height>4){O="underline";const $=R.getAttribute("viewBox");if($){const[A,M,N,V]=$.split(" ").map(J=>Number(J)),Y=M+V/2;z.y<Y&&z.y+z.height>Y?O="line-through":z.y+z.height<Y?O="overline":O="underline"}}else O="outline";else O=x;switch(O){case"outline":{const $=D.width*.2,A=D.height*.2;g?(D.x-=A/2,D.y-=$/2,D.x-=D.height):(D.x-=$/2,D.y-=A/2),D.width+=$,D.height+=A;break}case"overline":D.height=z.height*B,g?D.x=p.left+p.width:D.y=p.top;break;case"line-through":D.height=z.height*B,g?D.x=p.left+p.width-m+D.height/2:D.y=p.top+m-D.height/2;break;case"underline":D.height=z.height*B,g?D.x=y.left+y.width-P:D.y=p.top+P;break}}const j=new _e;if(j.translate(-z.x,-z.y),j.scale(D.width/z.width,D.height/z.height),g){const O=D.width/2,$=D.height/2;F||j.translate(-O,-$),j.rotate(-Math.PI/2),F||j.translate($,O)}j.translate(D.x,D.y);for(let O=0;O<Math.ceil(H/I);O++){const $=j.clone();g?$.translate(0,O*D.width):$.translate(O*D.width,0),U.paths.forEach(A=>{const M=A.clone().applyTransform($);M.style.strokeWidth&&(M.style.strokeWidth*=B*L),M.style.strokeMiterlimit&&(M.style.strokeMiterlimit*=B),M.style.strokeDashoffset&&(M.style.strokeDashoffset*=B),M.style.strokeDasharray&&(M.style.strokeDasharray=M.style.strokeDasharray.map(N=>N*B)),M.style.fill&&M.style.fill in G&&(M.style.fill=G[M.style.fill]),M.style.stroke&&M.style.stroke in G&&(M.style.stroke=G[M.style.stroke]),s.paths.push(M),H!==I&&(g?e[s.paths.length-1]=new Z(u.left-u.width*2,u.top,u.width*4,u.height):e[s.paths.length-1]=new Z(u.left,u.top-u.height*2,u.width,u.height*4))})}}},renderOrder:-1,getBoundingBox:()=>{const i=[];return s.paths.forEach((n,o)=>{const a=e[o];let l=n.getBoundingBox();if(a){const c=Math.max(l.x,a.x),h=Math.max(l.y,a.y),u=Math.min(l.right,a.right),d=Math.min(l.bottom,a.bottom);l=new Z(c,h,u-c,d-h)}i.push(l)}),Z.from(...i)},render:(i,n)=>{s.paths.forEach((o,a)=>{if(Pr({ctx:i,path:o,fontSize:n.computedStyle.fontSize,clipRect:e[a]}),n.debug){const l=new Tt([o]).getBoundingBox();l&&i.strokeRect(l.x,l.y,l.width,l.height)}})}}}function bg(s,e){return`<svg width="${s*2}" height="${s*2}" xmlns="http://www.w3.org/2000/svg">
956
956
  <circle cx="${s}" cy="${s}" r="${s}" fill="${e}" />
957
- </svg>`}function wg(){const s=new Tt;return{name:"listStyle",pathSet:s,update:e=>{s.paths.length=0;const{paragraphs:t,isVertical:r,fontSize:i}=e,n=i*.45;t.forEach(o=>{const{computedStyle:a}=o,{color:l,listStyleImage:c,listStyleColormap:h,listStyleSize:u,listStyleType:d}=a,g=Bn(h);let p=u,y;if(!K(c))y=c;else if(!K(d)){const x=i*.38/2;switch(p=p==="cover"?x*2:p,d){case"disc":y=bg(x,String(l));break}}if(!y)return;const m=Ws(y),P=m.getBoundingBox(),E=o.fragments[0]?.characters[0];if(!E)return;const{inlineBox:b}=E,S=p==="cover"?1:Un(p,{total:i,fontSize:i})/i,w=new _e;if(r){const x=i/P.height*S;w.translate(-P.left,-P.top).rotate(Math.PI/2).scale(x,x).translate(b.left+(b.width-P.height*x)/2,b.top-n)}else{const x=i/P.height*S;w.translate(-P.left,-P.top).scale(x,x).translate(b.left-P.width*x-n,b.top+(b.height-P.height*x)/2)}s.paths.push(...m.paths.map(x=>{const T=x.clone();return T.applyTransform(w),T.style.fill&&T.style.fill in g&&(T.style.fill=g[T.style.fill]),T.style.stroke&&T.style.stroke in g&&(T.style.stroke=g[T.style.stroke]),T}))})}}}function xg(){return{name:"outline"}}const $t=new k,Tr=new _e,zt=new _e;function Pg(){const s=new Tt;return{name:"render",pathSet:s,update:e=>{s.paths.length=0;const{paragraphs:t}=e;t.forEach(r=>{r.fragments.forEach(i=>{i.characters.forEach(n=>{s.paths.push(n.path)})})})},getBoundingBox:e=>{const{characters:t,fontSize:r,effects:i}=e,n=[];return t.forEach(o=>{i?.forEach(a=>{if(!o.glyphBox)return;const l=o.glyphBox.clone(),c=Nn(e,a);$t.set(l.left,l.top),$t.applyMatrix3(c),l.left=$t.x,l.top=$t.y,$t.set(l.right,l.bottom),$t.applyMatrix3(c),l.width=$t.x-l.left,l.height=$t.y-l.top;const h=(a.shadowOffsetX??0)*r,u=(a.shadowOffsetY??0)*r,d=Math.max(.1,a.textStrokeWidth??0)*r;l.left+=h-d,l.top+=u-d,l.width+=d*2,l.height+=d*2,n.push(l)})}),n.length?Z.from(...n):void 0},render:(e,t)=>{const{paragraphs:r,glyphBox:i,effects:n}=t;n?n.forEach(o=>{is(o,i,e),e.save();const[a,l,c,h,u,d]=Nn(t,o).transpose().elements;e.transform(a,h,l,u,c,d),t.forEachCharacter(g=>{g.drawTo(e,o)}),e.restore()}):r.forEach(o=>{o.fragments.forEach(a=>{a.characters.forEach(l=>{l.drawTo(e)})})}),t.debug&&r.forEach(o=>{e.strokeRect(o.lineBox.x,o.lineBox.y,o.lineBox.width,o.lineBox.height)})}}}function Nn(s,e){const{fontSize:t,glyphBox:r}=s,i=(e.translateX??0)*t,n=(e.translateY??0)*t,o=Math.PI*2,a=(e.skewX??0)/360*o,l=(e.skewY??0)/360*o,{left:c,top:h,width:u,height:d}=r,g=c+u/2,p=h+d/2;return Tr.identity(),zt.makeTranslation(i,n),Tr.multiply(zt),zt.makeTranslation(g,p),Tr.multiply(zt),zt.set(1,Math.tan(a),0,Math.tan(l),1,0,0,0,1),Tr.multiply(zt),zt.makeTranslation(-g,-p),Tr.multiply(zt),Tr.clone()}function Cg(){const s=new Tt;return{name:"textDecoration",pathSet:s,update:e=>{s.paths.length=0;const t=[];let r,i;e.forEachCharacter(n=>{const{computedStyle:o,isVertical:a,inlineBox:l,underlinePosition:c,underlineThickness:h,strikeoutPosition:u,strikeoutSize:d}=n,{color:g,textDecoration:p,writingMode:y}=o;if(K(p))i=void 0;else{let m=!1;if(i?.textDecoration===p&&i?.writingMode===y&&i?.color===g&&(a?r[0].inlineBox.left===l.left:r[0].inlineBox.top===l.top))switch(p){case"underline":r[0].underlinePosition===c&&r[0].underlineThickness===h&&(m=!0);break;case"line-through":r[0].strikeoutPosition===u&&r[0].strikeoutSize===d&&(m=!0);break}m?r.push(n):(r=[],r.push(n),t.push(r)),i=o}}),t.forEach(n=>{const{computedStyle:o,isVertical:a,underlinePosition:l,underlineThickness:c,strikeoutPosition:h,strikeoutSize:u}=n[0],{color:d,textDecoration:g}=o,p=Z.from(...n.map(T=>T.inlineBox)),{left:y,top:m,width:P,height:E}=p;let b=a?y+P:m;const S=a?-1:1;let w=0;switch(g){case"overline":w=c*2;break;case"underline":b+=S*l,w=c*2;break;case"line-through":b+=S*h,w=u*2;break}b-=w;let x;a?x=new ge([{type:"M",x:b,y:m},{type:"L",x:b,y:m+E},{type:"L",x:b+w,y:m+E},{type:"L",x:b+w,y:m},{type:"Z"}],{fill:d}):x=new ge([{type:"M",x:y,y:b},{type:"L",x:y+P,y:b},{type:"L",x:y+P,y:b+w},{type:"L",x:y,y:b+w},{type:"Z"}],{fill:d}),s.paths.push(x)})},render:(e,t)=>{const{effects:r,computedStyle:i}=t;r?r.forEach(n=>{e.save();const[o,a,l,c,h,u]=Nn(t,n).transpose().elements;e.transform(o,c,a,h,l,u),s.paths.forEach(d=>{Pr({ctx:e,path:d,fontSize:i.fontSize,...n})}),e.restore()}):s.paths.forEach(n=>{Pr({ctx:e,path:n,fontSize:i.fontSize})})}}}var Tg=Object.defineProperty,Vt=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Tg(e,t,i),i};const Wl=Po();class kt extends bs{needsUpdate=!0;computedStyle={...Wl};paragraphs=[];lineBox=new Z;rawGlyphBox=new Z;glyphBox=new Z;pathBox=new Z;boundingBox=new Z;measurer=new ss;plugins=new Map;pathSets=[];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))}constructor(e={}){super(),this.set(e)}set(e={}){const{content:t,effects:r,style:i,measureDom:n,fonts:o,fill:a,outline:l}=To(e);this.debug=e.debug??!1,this.content=t,this.effects=r,this.style=i,this.measureDom=n,this.fonts=o,this.fill=a,this.outline=l,this.use(vg()).use(xg()).use(wg()).use(Cg()).use(_g()).use(Pg()),(e.plugins??[]).forEach(c=>{this.use(c)}),this.updateParagraphs()}use(e){return this.plugins.set(e.name,e),this}forEachCharacter(e){return this.paragraphs.forEach((t,r)=>{t.fragments.forEach((i,n)=>{i.characters.forEach((o,a)=>{e(o,{paragraphIndex:r,fragmentIndex:n,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(e=>e.load?.(this)))}updateParagraphs(){this.computedStyle={...Wl,...this.style};const{content:e}=this,t=[];return e.forEach((r,i)=>{const{fragments:n,fill:o,outline:a,...l}=r,c=new yg(l,i,this);c.fill=o,c.outline=a,n.forEach((h,u)=>{const{content:d,fill:g,outline:p,...y}=h;if(d!==void 0){const m=new mg(d,y,u,c);c.fragments.push(m),m.fill=g,m.outline=p}}),t.push(c)}),this.paragraphs=t,this}createDom(){return this.updateParagraphs(),this.measurer.createDom(this.paragraphs,this.computedStyle)}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 r=this.measurer.measure(this.paragraphs,this.computedStyle,e);this.paragraphs=r.paragraphs,this.lineBox=r.boundingBox,this.characters.forEach(i=>{i.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((i,n)=>(i.updateOrder??0)-(n.updateOrder??0)).forEach(i=>{i.update?.(this)}),this.pathSets.length=0,Array.from(this.plugins.values()).sort((i,n)=>(i.renderOrder??0)-(n.renderOrder??0)).forEach(i=>{i.pathSet?.paths.length&&this.pathSets.push(i.pathSet)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const i in t)r[i]=this[i],this[i]=t[i];return this.emit("measure",{text:this,result:r}),r}getGlyphBox(){const e=k.MAX,t=k.MIN;return this.characters.forEach(r=>{if(!r.getGlyphMinMax(e,t)){const{inlineBox:i}=r,{left:n,top:o,width:a,height:l}=i,c=new k(n,o),h=new k(n+a,o+l);e.min(c,h),t.max(c,h)}}),new Z(e.x,e.y,t.x-e.x,t.y-e.y)}updatePathBox(){return this.pathBox=Z.from(this.glyphBox,...Array.from(this.plugins.values()).map(e=>e.getBoundingBox?e.getBoundingBox(this):e.pathSet?.getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){return this.boundingBox=Z.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(e=this.measureDom){this.needsUpdate=!1;const t=this.measure(e);for(const r in t)this[r]=t[r];return this.emit("update",{text:this}),this}render(e){const{view:t,pixelRatio:r=2}=e,i=t.getContext("2d");i&&(this.needsUpdate&&this.update(),cg(i,r,this.boundingBox),hg(i,this),Array.from(this.plugins.values()).sort((n,o)=>(n.renderOrder??0)-(o.renderOrder??0)).forEach(n=>{if(n.render)n.render?.(i,this);else if(n.pathSet){const o=this.computedStyle;n.pathSet.paths.forEach(a=>{Pr({ctx:i,path:a,fontSize:o.fontSize})})}}),this.emit("render",{text:this,view:t,pixelRatio:r}),e.onContext?.(i))}toString(){return this.content.flatMap(e=>e.fragments.map(t=>t.content)).join("")}}Vt([_({internal:!0})],kt.prototype,"debug"),Vt([_()],kt.prototype,"content"),Vt([_()],kt.prototype,"style"),Vt([_()],kt.prototype,"effects"),Vt([_()],kt.prototype,"fill"),Vt([_()],kt.prototype,"outline"),Vt([_({internal:!0})],kt.prototype,"measureDom"),Vt([_({internal:!0})],kt.prototype,"fonts");var Sg=Object.defineProperty,Gt=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Sg(e,t,i),i};class vt extends xt{constructor(e){super(),this.parent=e,this.base=new kt,this.base.setPropertyAccessor(this)}base;measureResult;_texture=new Ui;_textureMap=new Map;setProperties(e){return super.setProperties(K(e)?void 0:To(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"enabled":this.parent.requestRedraw();break;case"effects":case"measureDom":case"fonts":this.update(),this.parent.requestRedraw();break;case"fill":case"outline":case"content":this.update(),this._updateTextureMap(),this.parent.requestRedraw();break}}update(){this.base.fonts=this.base.fonts??this.parent.tree?.fonts,this.base.update()}_updateTextureMap(){this._textureMap.clear();const e=[];if(this.base.paragraphs.forEach((t,r)=>{const i=[];if(t.fragments.forEach((n,o)=>{if(n.characters.length){const a=Z.from(...n.characters.map(l=>l.compatibleGlyphBox));this._updateTexture(`${r}.${o}.fill`,n.fill,a),this._updateTexture(`${r}.${o}.outline`,n.outline,a),i.push(a)}}),i.length){const n=Z.from(...i);this._updateTexture(`${r}.fill`,t.fill,n),this._updateTexture(`${r}.outline`,t.outline,n),e.push(n)}}),e.length){const t=Z.from(...e);this._updateTexture("fill",this.fill,t),this._updateTexture("outline",this.outline,t)}}async _updateTexture(e,t,r){t&&Object.keys(t).length>0&&(this._textureMap.set(e,{texture:await this._loadTexture(t,r),box:r}),this.parent.requestRedraw())}async _loadTexture(e,t){return e.linearGradient||e.radialGradient?new zr(e.linearGradient??e.radialGradient,t.width,t.height):K(e.image)?void 0:(this.parent.tree?.log(`load image ${e.image}`),await Ke.texture.load(e.image))}setContent(e){this.content=Ps(e)}measure(){return this.update(),this.base.measure()}updateMeasure(){return this.measureResult=this.measure(),this}isValid(){return!!(this.enabled&&!/^\s*$/.test(this.base.toString()))}_createVertTransform(){const e=this.parent;if(e.scale.x>0&&e.scale.y>0)return;const t=e.scale.x*e.scale.y,r=e.getTransformOrigin();return new ke().translate(-r.x,-r.y).scale(t>0?1:-1,1).translate(r.x,r.y)}useTextureDraw(){return!!this.effects?.length||this.content.some(e=>e.fragments.some(t=>!!t.highlightImage))}_pathDraw(e){this.base.pathSets.forEach(t=>{t.paths.forEach(r=>{const i=r.getMeta();if(i instanceof Vl){const n=i.parent.index,o=i.parent.parent.index;if(r.style.fill&&!K(r.style.fill))if(typeof r.style.fill=="object"){const a=r.style.fill,l=this._textureMap.get(`${o}.${n}.fill`)??this._textureMap.get(`${o}.fill`)??this._textureMap.get("fill");if(a.enabled!==!1&&(l||a.color)){const{uvTransform:c,disableWrapMode:h}=rs(a,l?.box??{width:this.parent.size.width,height:this.parent.size.height});e.addPath(r),e.style={...r.style},e.uvTransform=c,e.fillStyle=l?.texture??a.color,e.vertTransform=this._createVertTransform(),e.fill({disableWrapMode:h})}}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.fill();if(r.style.stroke&&!K(r.style.stroke))if(typeof r.style.stroke=="object"){const a=r.style.stroke,l=this._textureMap.get(`${o}.${n}.outline`)??this._textureMap.get(`${o}.outline`)??this._textureMap.get("outline");if(a.enabled!==!1&&(l||a.color)&&(a.width===void 0||a.width)){const{uvTransform:c,disableWrapMode:h}=rs(a,l?.box??{width:this.parent.size.width,height:this.parent.size.height});e.addPath(r),e.style={...r.style},e.lineWidth=a.width||1,e.uvTransform=c,e.strokeStyle=l?.texture??a.color,e.lineCap=a.lineCap,e.lineJoin=a.lineJoin,e.vertTransform=this._createVertTransform(),e.stroke({disableWrapMode:h})}}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.stroke()}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.fill()})})}_textureDraw(e){this._texture.width=Math.round(this.base.boundingBox.width),this._texture.height=Math.round(this.base.boundingBox.height),this.base.render({view:this._texture.source}),e.fillStyle=this._texture,e.vertTransform=this._createVertTransform(),e.fill()}draw(){const e=this.parent.context;this.useTextureDraw()?this._textureDraw(e):this._pathDraw(e)}}Gt([_({fallback:!0})],vt.prototype,"enabled"),Gt([_({fallback:()=>[]})],vt.prototype,"content"),Gt([_({alias:"parent.style.json"})],vt.prototype,"style"),Gt([_()],vt.prototype,"effects"),Gt([_()],vt.prototype,"fill"),Gt([_()],vt.prototype,"outline"),Gt([_({alias:"base.measureDom"})],vt.prototype,"measureDom"),Gt([_({alias:"base.fonts"})],vt.prototype,"fonts");var Eg=Object.getOwnPropertyDescriptor,Mg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Eg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};const Ag=new Set(Object.keys(wo())),Og=new Set(Object.keys(xo()));f.BaseElement2D=class extends f.Node2D{size=new de().on("update",()=>{this.updateGlobalTransform(),this.requestRedraw()});get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}_background=new Dn(this);get background(){return this._background}set background(e){this._background.resetProperties().setProperties(e)}_shape=new ir(this);get shape(){return this._shape}set shape(e){this._shape.resetProperties().setProperties(e)}_fill=new Oe(this);get fill(){return this._fill}set fill(e){this._fill.resetProperties().setProperties(e)}_outline=new tr(this);get outline(){return this._outline}set outline(e){this._outline.resetProperties().setProperties(e)}_foreground=new In(this);get foreground(){return this._foreground}set foreground(e){this._foreground.resetProperties().setProperties(e)}_text=new vt(this);get text(){return this._text}set text(e){this._text.resetProperties().setProperties(e)}_shadow=new rr(this);get shadow(){return this._shadow}set shadow(e){this._shadow.resetProperties().setProperties(e)}constructor(e,t=[]){super(),this._updateStyleProperty=this._updateStyleProperty.bind(this),this.style=new ui,this.setProperties(e).append(t)}setProperties(e){if(e){const{style:t,text:r,shape:i,background:n,fill:o,outline:a,foreground:l,shadow:c,...h}=e;t&&this.style.setProperties(t),n&&this.background.setProperties(n),i&&this.shape.setProperties(i),o&&this.fill.setProperties(o),a&&this.outline.setProperties(a),r&&this.text.setProperties(r),l&&this.foreground.setProperties(l),c&&this.shadow.setProperties(c),super.setProperties(h)}return this}_updateStyleProperty(e,t,r){switch(e){case"rotate":this.rotation=this.style.rotate*Xo;break;case"scaleX":this.scale.x=this.style.scaleX,this.text.isValid()&&(t^r)<0&&this.requestRedraw();break;case"scaleY":this.scale.y=this.style.scaleY,this.text.isValid()&&(t^r)<0&&this.requestRedraw();break;case"skewX":this.skew.x=this.style.skewX;break;case"skewY":this.skew.y=this.style.skewY;break;case"transform":case"transformOrigin":this.updateGlobalTransform();break;case"opacity":this.opacity=this.style.opacity;break;case"visibility":this.visible=this.style.visibility==="visible";break;case"filter":this.requestRepaint();break;case"maskImage":this._updateMaskImage();break;case"backgroundColor":this.background.color=this.style.backgroundColor;break;case"backgroundImage":this.background.image=this.style.backgroundImage;break;case"borderStyle":case"outlineStyle":this.outline.style=t;break;case"borderWidth":case"outlineWidth":this.outline.width=t;break;case"borderColor":case"outlineColor":this.outline.color=t;break;case"borderRadius":default:this.requestRedraw();break}(Og.has(e)||Ag.has(e))&&this.text.isValid()&&this.text.update()}_process(e){this.foreground.updateFrameIndex(),this.fill.updateFrameIndex(),this.outline.updateFrameIndex(),this.background.updateFrameIndex(),super._process(e)}_updateMaskImage(){const e="__$style.maskImage",t=this.style.maskImage;if(t&&t!=="none"){const r=this.getNode(e);r?r.src=t:this.appendChild(new f.MaskEffect({name:e,src:t}),"back")}else{const r=this.getNode(e);r&&this.removeChild(r)}}getTransformOrigin(){const{width:e,height:t}=this.size,[r,i]=ml(this.style.transformOrigin);return new de(r*e,i*t)}updateTransform(e){const{width:t,height:r}=this.size;super.updateTransform(i=>{gl(this.style.transform??"",t,r,i),e?.(i)})}updateGlobalTransform(){super.updateGlobalTransform(),this._updateOverflow()}_relayout(e){return super._relayout(e).map(t=>({...t,dimension:this.size.toFloat32Array()}))}getRect(){return this.getGlobalAabb()}_getPointArray(){const{width:e,height:t}=this.size,r=0,i=0,n=r+e,o=i+t;return[{x:r,y:i},{x:r,y:o},{x:n,y:i},{x:n,y:o}]}getAabb(){return new It(this._getPointArray().map(e=>this.transform.apply(e)))}getGlobalAabb(){return new It(this._getPointArray().map(e=>this.globalTransform.apply(e)))}getObb(){const e=this.getTransformOrigin(),t=this.transform.apply(e).sub(e);return{rect:new It(this._getPointArray().map(r=>(r.x+=t.x,r.y+=t.y,r))),rotation:this.rotation}}getGlobalObb(){const e=this.getTransformOrigin(),t=this.globalTransform.apply(e).sub(e);return{rect:new It(this._getPointArray().map(r=>(r.x+=t.x,r.y+=t.y,r))),rotation:this.globalRotation}}_updateOverflow(){this.style.overflow==="hidden"?this.mask=this.getRect().toJSON():this.mask=void 0}_draw(){super._draw(),this._background.isValid()&&(this._tree?.log(this.name,"background drawing"),this._shape.draw(!this._background.fillWithShape),this._background.draw()),this._fill.isValid()&&(this._tree?.log(this.name,"fill drawing"),this._shape.draw(),this._fill.draw()),this._outline.isValid()&&(this._tree?.log(this.name,"outline drawing"),this._shape.draw(),this._outline.draw()),this._foreground.isValid()&&(this._tree?.log(this.name,"foreground drawing"),this._shape.draw(!this._foreground.fillWithShape),this._foreground.draw()),this._text.isValid()&&(this._tree?.log(this.name,"text drawing"),this._text.useTextureDraw()&&this._shape.draw(!0),this._text.draw()),this._drawContent()}_drawContent(){}_repaint(e){return super._repaint(e).map(t=>({...t}))}canPointerEvents(){return this.style.pointerEvents!=="none"}input(e,t){const r=this.getChildren(!0);for(let i=r.length-1;i>=0;i--)r[i].input(e,t);this.isVisibleInTree()&&this._input(e,t)}_positionInput(e,t){const{width:r,height:i}=this.size;return e.x>=0&&e.x<r&&e.y>=0&&e.y<i}_input(e,t){switch(t){case"pointerdown":case"pointermove":case"pointerup":{if(this.canPointerEvents()){const{screenX:r,screenY:i}=e;if(r&&i){const n=new de(r,i),o=this.getViewport();o&&o.toCanvasGlobal(n,n),this.toLocal(n,n),this._positionInput(n,t)&&(e.target||(e.target=this),this.emit(t,e))}}break}}}toJSON(){const e=t=>Object.keys(t).length>0?t:void 0;return Ve({...super.toJSON(),style:e(this.style.toJSON()),background:e(this.background.toJSON()),shape:e(this.shape.toJSON()),fill:e(this.fill.toJSON()),outline:e(this.outline.toJSON()),text:e(this.text.toJSON()),foreground:e(this.foreground.toJSON()),shadow:e(this.shadow.toJSON())})}},f.BaseElement2D=Mg([X("BaseElement2D")],f.BaseElement2D);class $n extends ui{constructor(e){super(),this.setProperties(e)}}const ql={left:0,top:0,width:0,height:0};for(const s in ql)mi($n,s,{fallback:ql[s]});class Xl extends ui{constructor(e){super(),this.setProperties(e)}}var kg=Object.getOwnPropertyDescriptor,Dg=(s,e,t,r)=>{for(var i=r>1?void 0:r?kg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};f.Element2D=class extends f.BaseElement2D{get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}constructor(e,t=[]){super(),this.style=new $n,this.setProperties(e).append(t)}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"left":this.position.x=Number(t);break;case"top":this.position.y=Number(t);break;case"width":this.size.width=Number(t);break;case"height":this.size.height=Number(t);break}switch(e){case"width":case"height":this.mask instanceof f.BaseElement2D&&(this.mask.size.width=this.size.width,this.mask.size.height=this.size.height);break}}},f.Element2D=Dg([X("Element2D")],f.Element2D);const fe={left:0,top:1,right:2,bottom:3,start:4,end:5,horizontal:6,vertical:7,all:8},Hl={column:0,row:1,all:2},sr={auto:0,"flex-start":1,center:2,"flex-end":3,stretch:4,baseline:5,"space-between":6,"space-around":7,"space-evenly":8},zn={flex:0,none:1,contents:2},ns={inherit:0,ltr:1,rtl:2},Vn={column:0,"column-reverse":1,row:2,"row-reverse":3},Gn={"no-wrap":0,wrap:1,"Wrap-reverse":2},jn={"flex-start":0,center:1,"flex-end":2,"space-between":3,"space-around":4,"space-evenly":5},Wn={visible:0,hidden:1,scroll:2},qn={static:0,relative:1,absolute:2},Xn={"border-box":0,"content-box":1};class os{constructor(e){this._element=e}static _yoga;static async load(){const{loadYoga:e}=await import("yoga-layout/load");this._yoga=await e()}_node=os._yoga.Node.create();get _style(){return this._element.style}get offsetLeft(){return this._node.getComputedLeft()}get offsetTop(){return this._node.getComputedTop()}get offsetWidth(){return this._node.getComputedWidth()}get offsetHeight(){return this._node.getComputedHeight()}calculateLayout(e,t,r){return this._node.calculateLayout(e,t,r)}getComputedLayout(){return this._node.getComputedLayout()}updateStyleProperty(e,t,r){switch(e){case"alignContent":this._node.setAlignContent(t?sr[t]:sr["flex-start"]);break;case"alignItems":this._node.setAlignItems(t?sr[t]:sr["flex-start"]);break;case"alignSelf":this._node.setAlignSelf(t?sr[t]:sr["flex-start"]);break;case"aspectRatio":this._node.setAspectRatio(t);break;case"borderTop":this._node.setBorder(fe.top,this._style.borderWidth);break;case"borderBottom":this._node.setBorder(fe.bottom,this._style.borderWidth);break;case"borderLeft":this._node.setBorder(fe.left,this._style.borderWidth);break;case"borderRight":this._node.setBorder(fe.right,this._style.borderWidth);break;case"border":this._node.setBorder(fe.all,this._style.borderWidth);break;case"direction":this._node.setDirection(t?ns[t]:ns.inherit);break;case"display":this._node.setDisplay(t?zn[t]:zn.flex);break;case"flex":this._node.setFlex(this._style.flex);break;case"flexBasis":this._node.setFlexBasis(this._style.flexBasis);break;case"flexDirection":this._node.setFlexDirection(t?Vn[t]:Vn.row);break;case"flexGrow":this._node.setFlexGrow(this._style.flexGrow);break;case"flexShrink":this._node.setFlexShrink(this._style.flexShrink);break;case"flexWrap":this._node.setFlexWrap(t?Gn[t]:Gn.wrap);break;case"height":this._node.setHeight(this._style.height);break;case"justifyContent":this._node.setJustifyContent(t?jn[t]:jn["flex-start"]);break;case"gap":t!==void 0&&this._node.setGap(Hl.all,t);break;case"marginTop":this._node.setMargin(fe.top,t);break;case"marginBottom":this._node.setMargin(fe.bottom,t);break;case"marginLeft":this._node.setMargin(fe.left,t);break;case"marginRight":this._node.setMargin(fe.right,t);break;case"margin":this._node.setMargin(fe.all,t);break;case"maxHeight":this._node.setMaxHeight(t);break;case"maxWidth":this._node.setMaxWidth(t);break;case"minHeight":this._node.setMinHeight(this._style.minHeight);break;case"minWidth":this._node.setMinWidth(this._style.minWidth);break;case"overflow":this._node.setOverflow(t?Wn[t]:Wn.visible);break;case"paddingTop":this._node.setPadding(fe.top,this._style.paddingTop);break;case"paddingBottom":this._node.setPadding(fe.bottom,this._style.paddingBottom);break;case"paddingLeft":this._node.setPadding(fe.left,this._style.paddingLeft);break;case"paddingRight":this._node.setPadding(fe.right,this._style.paddingRight);break;case"padding":this._node.setPadding(fe.all,this._style.padding);break;case"top":this._node.setPosition(fe.top,this._style.top);break;case"bottom":this._node.setPosition(fe.bottom,this._style.bottom);break;case"left":this._node.setPosition(fe.left,this._style.left);break;case"right":this._node.setPosition(fe.right,this._style.right);break;case"position":this._node.setPositionType(t?qn[t]:qn.static);break;case"boxSizing":this._node.setBoxSizing(t?Xn[t]:Xn["content-box"]);break;case"width":this._node.setWidth(this._style.width);break}}}var Ig=Object.getOwnPropertyDescriptor,Rg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Ig(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};f.FlexElement2D=class extends f.BaseElement2D{get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}_layout=new os(this);get offsetLeft(){return this._layout.offsetLeft}get offsetTop(){return this._layout.offsetTop}get offsetWidth(){return this._layout.offsetWidth}get offsetHeight(){return this._layout.offsetHeight}constructor(e,t=[]){super(),this.style=new Xl,this.setProperties(e).append(t)}_parented(e){super._parented(e),e._layout&&this._layout._node&&e._layout._node.insertChild(this._layout._node,e._layout._node.getChildCount())}_unparented(e){super._unparented(e),e._layout?._node&&e._layout._node.removeChild(this._layout._node)}_updateStyleProperty(e,t,r){super._updateStyleProperty(e,t,r),this._layout.updateStyleProperty(e,t,r),this._layout._node.isDirty()&&this.requestRelayout()}updateTransform(){this.calculateLayout(void 0,void 0,ns.ltr);const{left:e,top:t,width:r,height:i}=this._layout.getComputedLayout();this.position.x=e,this.position.y=t,this.size.x=r,this.size.y=i,super.updateTransform()}calculateLayout(e,t,r){const i=this.getParent();i?._layout?.calculateLayout?i?._layout.calculateLayout(e,t,r):this._layout.calculateLayout(e,t,r)}},f.FlexElement2D=Rg([X("FlexElement2D")],f.FlexElement2D);var Ug=Object.defineProperty,Bg=Object.getOwnPropertyDescriptor,fi=(s,e,t,r)=>{for(var i=r>1?void 0:r?Bg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Ug(e,t,i),i};f.Image2D=class extends f.Element2D{get currentFrameTexture(){return this.texture?.frames[this._frameIndex]?.texture}get textureDuration(){return this.texture?.duration??0}get naturalWidth(){return this.currentFrameTexture?.realWidth??0}get naturalHeight(){return this.currentFrameTexture?.realHeight??0}get complete(){return this._complete}_frameIndex=0;_complete=!1;_wait=Promise.resolve();constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._wait=this._load(t);break;case"srcRect":this.requestRedraw();break}}decode(){return this._wait}setResource(e){let t;if(e instanceof Ri?t=e:t=new Ri(e),this.texture=t.updateDuration(),this.currentFrameTexture&&(!this.style.width||!this.style.height)){const r=this.currentFrameTexture;this.style.width=r.realWidth,this.style.height=r.realHeight}return this}async _load(e){if(this._complete=!1,e)try{this.setResource(this.gif||e?.includes(".gif")?await Ke.gif.load(e):await Ke.texture.load(e)),this.requestRedraw(),this.emit("load")}catch(t){console.warn(t),this.emit("error",t)}else this.texture=void 0;this._complete=!0}_getFrameCurrentTime(){const e=this.textureDuration;if(!e||!this._tree)return 0;const t=this._currentTime;return t<0?0:t%e}_updateFrameIndex(){if(!this.texture)return this;const e=this._getFrameCurrentTime(),t=this.texture.frames,r=t.length;if(r<=1&&this._frameIndex===0)return this;let i=r-1;for(let n=0,o=0;o<r;o++)if(n+=t[o].duration??0,n>=e){i=o;break}return this._frameIndex!==i&&(this._frameIndex=i,this.requestRedraw()),this}_process(e){this._updateFrameIndex(),super._process(e)}_drawContent(){const e=this.currentFrameTexture;if(e?.isValid()){const{left:t=0,top:r=0,right:i=0,bottom:n=0}=this.srcRect??{},{width:o,height:a}=this.size;this.context.fillStyle=e;const l=Math.abs(1+(t+i))*o,c=Math.abs(1+(r+n))*a,h=1/l,u=1/c,d=t*o*h,g=r*a*u;this.context.uvTransform=new ke().scale(h,u).translate(d,g),this.shape.draw(),this.context.fill()}}_repaint(e){return super._repaint(e).map(t=>({...t,disableWrapMode:!0}))}},fi([_({internal:!0})],f.Image2D.prototype,"texture",2),fi([_({fallback:""})],f.Image2D.prototype,"src",2),fi([_()],f.Image2D.prototype,"srcRect",2),fi([_({fallback:!1})],f.Image2D.prototype,"gif",2),f.Image2D=fi([X("Image2D")],f.Image2D);class Hn extends f.Element2D{texture;constructor(e,t=[]){super(),this.setProperties(e).append(t)}_drawContent(){this.texture?.isValid()&&(this.shape.draw(!0),this.context.fillStyle=this.texture,this.context.fill())}}var Lg=Object.defineProperty,Fg=Object.getOwnPropertyDescriptor,Yl=(s,e,t,r)=>{for(var i=r>1?void 0:r?Fg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Lg(e,t,i),i};f.Lottie2D=class extends Hn{texture=new Ui;animation;constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._load();break}}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"width":this.texture.width=this.style.width;break;case"height":this.texture.height=this.style.height;break}}async _load(){this.animation=await Ke.lottie.load(this.src,this.texture.source),this.duration=this.animation.getDuration(!1)*1e3,this.texture.requestUpload(),this.requestRedraw()}_process(e){this.animation?.goToAndStop(this.currentTime,!1),this.texture.requestUpload(),this.requestRedraw(),super._process(e)}},Yl([_({fallback:""})],f.Lottie2D.prototype,"src",2),f.Lottie2D=Yl([X("Lottie2D")],f.Lottie2D);var Ng=Object.defineProperty,$g=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Ng(e,t,i),i};class Kl extends f.Element2D{constructor(e,t=[]){super(),this.setProperties(e).append(t)}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"width":case"height":this.requestRedraw();break}}_drawCircle(e,t){this.context.arc(e,t,this.handleSize,0,Math.PI*2,!0),this.context.fillStyle=le.WHITE,this.context.fill(),this.context.arc(e,t,this.handleSize,0,Math.PI*2,!0),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_drawEllipse(e,t){this.context.roundRect(e-this.handleSize,t-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.fillStyle=le.WHITE,this.context.fill(),this.context.roundRect(e-this.handleSize,t-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:e,height:t}=this.getRect();this.context.rect(0,0,e,t),this.context.strokeStyle="#00FF00",this.context.stroke(),this._drawCircle(0,0),this._drawCircle(e,t),this._drawCircle(0,t),this._drawEllipse(0,t/2),this._drawCircle(e,0),this._drawEllipse(e,t/2)}}$g([_({fallback:6})],Kl.prototype,"handleSize");var zg=Object.defineProperty,Vg=Object.getOwnPropertyDescriptor,Zl=(s,e,t,r)=>{for(var i=r>1?void 0:r?Vg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&zg(e,t,i),i};f.Video2D=class extends Hn{get videoDuration(){return(this.texture?.duration??0)*1e3}_wait=Promise.resolve();constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._wait=this._load(t);break}}waitLoad(){return this._wait}async _load(e){this.texture=await Ke.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 r=t.duration;e=r?e%(r*1e3):0,!t.isPlaying&&!t.seeking&&(e=~~e/1e3,t.currentTime!==e&&(t.currentTime=e))}_process(e){this._updateVideoCurrentTime(),super._process(e)}},Zl([_({fallback:""})],f.Video2D.prototype,"src",2),f.Video2D=Zl([X("Video2D")],f.Video2D);var Gg=Object.defineProperty,jg=Object.getOwnPropertyDescriptor,as=(s,e,t,r)=>{for(var i=r>1?void 0:r?jg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Gg(e,t,i),i};const Jl=s=>s,Ql=Sr(.25,.1,.25,1),ec=Sr(.42,0,1,1),tc=Sr(0,0,.58,1),rc=Sr(.42,0,.58,1);function Sr(s,e,t,r){const n=3*s-3*t+1,o=3*t-6*s,a=3*s,l=3*e-3*r+1,c=3*r-6*e,h=3*e,u=y=>(3*n*y+2*o)*y+a,d=y=>((n*y+o)*y+a)*y,g=y=>((l*y+c)*y+h)*y;function p(y){let m=y,P,E;for(let w=0;w<8;w++){if(E=d(m)-y,Math.abs(E)<1e-6)return m;if(P=u(m),Math.abs(P)<1e-6)break;m-=E/P}let b=1,S=0;for(m=y;b>S;){if(E=d(m)-y,Math.abs(E)<1e-6)return m;E>0?b=m:S=m,m=(b+S)/2}return m}return y=>g(p(y))}const ls={linear:Jl,ease:Ql,easeIn:ec,easeOut:tc,easeInOut:rc};f.Animation=class extends f.TimelineNode{_keyframes=[];_isFirstUpdatePosition=!1;_cachedProps=new ho;_stoped=!1;constructor(e,t=[]){super(),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,r){switch(super._updateProperty(e,t,r),e){case"effectMode":case"keyframes":this._updateKeyframes();break}}_getTargets(){let e;switch(this.effectMode){case"sibling":e=this.getParent()?.getChildren(!0).filter(t=>t instanceof f.CanvasItem)??[];break;case"parent":default:e=[this.getParent()].filter(Boolean);break}return e.map(t=>t.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",...c}=t[o];e.push({offset:a,easing:this._parseEasing(l),props:c})}const r=e[0],i=e[e.length-1];r&&r.offset!==0&&e.unshift({offset:0,easing:this._parseEasing("linear"),props:{}}),i&&i.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,r=this.currentTimeProgress;e.forEach((i,n)=>{const o=t===1?r:ut(Math.max(0,r-t*n)/t,0,1),a=this._cachedProps.get(i);if(!a)return;const l=this._parseKeyframes(o,a);l?.length&&this._commitStyle(o,i,a,l[0],l[1])})}_updateCachedProps(){this.cancel(),this._getTargets().forEach(e=>{const t=new Map,r=this._keyframes;for(let i=r.length,n=0;n<i;n++)Object.keys(r[n].props).forEach(o=>{t.set(o,e[o])});this._cachedProps.set(e,t)})}_parseEasing(e){if(!e)return ls.linear;if(e in ls)return ls[e];const t=e.replace(/cubic-bezier\((.+)\)/,"$1").split(",").map(r=>Number(r));return Sr(t[0],t[1],t[2],t[3])}_parseKeyframes(e,t){let r;const i=this._keyframes;for(let n=i.length,o=0;o<n;o++){const a=i[o],{offset:l,easing:c}=a,h={...a.props};if(r&&e<=l){const{offset:u,easing:d}=r,g={...r.props};return t.forEach((p,y)=>{(!(y in g)||g[y]===null)&&(g[y]=p),(!(y in h)||h[y]===null)&&(h[y]=p)}),[{offset:u,easing:d,props:g},{offset:l,easing:c,props:h}]}r=a}return null}_commitStyle(e,t,r,i,n){const{offset:o,easing:a,props:l}=i,{offset:c,props:h}=n,u=c-o,d=a((e-o)/u),g={width:t.width,height:t.height,fontSize:t.fontSize};r.forEach((p,y)=>{t[y]=this._getDiffValue(y,l[y],h[y],d,g)})}_getDiffValue(e,t,r,i,n){let o,a;if(t==="none"&&(t=void 0),r==="none"&&(r=void 0),t===void 0||r===void 0)if(t!==void 0)o=Or(e,String(t),n),a=Ss(o);else if(r!==void 0)a=Or(e,String(r),n),o=Ss(a);else return;else o=Or(e,String(t),n),a=Or(e,String(r),n);if(Array.isArray(o)&&Array.isArray(a)){const l=new Set,c={},h={};o.forEach(({name:d,args:g})=>{c[d]=g,l.add(d)}),a.forEach(({name:d,args:g})=>{h[d]=g,l.add(d)});let u="";return l.forEach(d=>{const g=Math.max(c[d]?.length??0,h[d]?.length??0),p=c[d],y=h[d];u+=`${d}(${Array.from({length:g},(m,P)=>{const E=p?.[P],b=y?.[P],S=E?.normalizedIntValue??0,w=b?.normalizedIntValue??0;return Number.isNaN(S)||Number.isNaN(w)?b?.value??0:he(S,w,i)}).join(", ")}) `}),u}else if(!Array.isArray(o)&&!Array.isArray(a))return Number.isNaN(o.normalizedIntValue)||Number.isNaN(a.normalizedIntValue)?a.value:he(o.normalizedIntValue,a.normalizedIntValue,i)}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=>{this._cachedProps.get(e)?.forEach((t,r)=>{e[r]=t}),this._cachedProps.delete(e)})}},as([_({fallback:"parent"})],f.Animation.prototype,"effectMode",2),as([_({default:()=>[]})],f.Animation.prototype,"keyframes",2),as([_()],f.Animation.prototype,"easing",2),f.Animation=as([X("Animation",{renderMode:"disabled",processMode:"pausable",processSortMode:"parent_before",duration:2e3})],f.Animation);class cs extends Dt{static _instance;static get instance(){return this._instance||(this._instance=new cs),this._instance}playbackRate=1;muted=!1;volume=1;paused=!1;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}}class di extends Dt{static PADDING=.1;_source=null;_audio=null;_end=0;_pausedReal=!1;_duration=0;_start=0;_playing=!1;get progress(){return(this._source?.currentTime??0)/this._duration}_paused=!1;get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_muted=!1;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 r=e.volume*(e.muted?0:1),i=t.volume*(t.muted?0:1),n=this._volume*(this._muted?0:1);this._source.volume=n*r*i,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:r=0}=e;r&&console.assert(r>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&&r!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=t,this._end=r||this._duration,this._start=Math.max(0,this._start-di.PADDING),this._end=Math.min(this._end+di.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=t,this._source.onloadedmetadata=null,this.emit("progress",t,this._duration),Ce.on(this._onUpdate))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate=()=>{this._source&&(this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete())};_onComplete(){Ce.off(this._onUpdate),this._stop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){Ce.off(this._onUpdate),super.destroy();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)}}class ic{constructor(e){this.parent=e}source=new globalThis.Audio;_src="";get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}get duration(){return this.source.duration}get isPlayable(){return!!this.source&&this.source.readyState===4}get context(){return cs.instance}async load(){return new Promise(e=>{this.source.onload=()=>e(this),this.source.src=this._src,this.source.load()})}createSound(){return new di}}class Yn extends Dt{constructor(e,t){super(),this._input=e,this._output=t}_processers=[];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(r=>{t?t.connect(r.destination):this._input.connect(r.destination),t=r}),t.connect(this._output)}}get destination(){return this._input}}class Wg{constructor(e,t=null){this.destination=e,this.source=t}connect(e){this.source?.connect(e)}disconnect(){this.source?.disconnect()}}function qg(){if(Ms)return new AudioContext;if(As){const s=globalThis.webkitAudioContext;return new s}else throw new Error("Failed to createAudioContext")}function Xg(s,e,t){if(Os)return new OfflineAudioContext(s,e,t);if(Io){const r=globalThis.webkitOfflineAudioContext;return new r(s,e,t)}else throw new Error("Failed to createOfflineAudioContext")}class jt extends Yn{static _instance;static get instance(){return this._instance||(this._instance=new jt),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)}_context;_offlineContext;get audioContext(){return this._context}get offlineContext(){return this._offlineContext}_locked;muted=!1;volume=1;playbackRate=1;autoPause=!0;_paused=!1;_pausedOnBlur=!1;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}_compressor;_analyser;constructor(){const e=qg(),t=Xg(1,2,Os?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),r=e.createDynamicsCompressor(),i=e.createAnalyser();i.connect(r),r.connect(e.destination),super(i,r),this._context=e,this._offlineContext=t,this._compressor=r,this._analyser=i,this._locked=e.state==="suspended"&&(wt||Do),Dr&&(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))}_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()))}_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))};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,r)=>{const i=o=>{r(new Error(o?.message||"Unable to decode file"))},n=this._offlineContext.decodeAudioData(e,t,i);n&&n.catch(i)})}setParamValue(e,t){e.setValueAtTime?e.setValueAtTime(t,this._context.currentTime):e.value=t}}class sc extends Dt{_audio=null;_sourceNode=null;_gain=null;_progress=0;get progress(){return this._progress}_pausedReal=!1;_paused=!1;get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh(),this._update(!0))}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_muted=!1;get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}_duration=0;_end=0;_elapsed=0;_lastUpdate=this._now();_processors=[];init(e){return this._audio=e,e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this}_now(){return this._audio?.context.audioContext.currentTime??0}play(e={}){if(!this._audio)return;const{end:t=0,start:r=0}=e;t&&console.assert(t>r,"End time is before start time"),this._end=t,this._elapsed=r,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:i,gain:n}=this._audio.cloneSource();this._sourceNode=i,this._gain=n,this.refresh(),i.onended=this._onComplete.bind(this),this._duration=i.buffer?.duration??0,this._lastUpdate=this._now(),this._loop?(i.loopStart=r,i.loopEnd=t,i.start(0,r)):t?i.start(0,r,t-r):i.start(0,r),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(),r=t-this._lastUpdate;if(r>0||e){this._elapsed+=r*this._sourceNode.playbackRate.value,this._lastUpdate=t;const i=this._duration;let n;if(this._sourceNode.loopStart){const o=this._sourceNode.loopEnd-this._sourceNode.loopStart;n=(this._sourceNode.loopStart+this._elapsed%o)/i}else n=this._elapsed%i/i;this._progress=n,this.emit("progress",n,i)}}}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))}_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)};_updateListener=()=>this._update();_enableTicker(e){Ce.off(this._updateListener),e&&Ce.on(this._updateListener)}destroy(){super.destroy(),this._stop(),this._gain?.disconnect(),this._gain=null,this._audio?.context.off("refresh",this.refresh),this._audio?.context.off("refreshPaused",this.refreshPaused),this._audio=null,this._processors.forEach(e=>e.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 nc extends Yn{constructor(e){const t=jt.audioContext,r=t.createBufferSource(),i=t.createGain(),n=t.createAnalyser();r.connect(n),n.connect(i),i.connect(jt.instance.destination),super(n,i),this.parent=e,this._sourceNode=r,this.gain=i,this.analyser=n}_sourceBuffer;_sourceNode;_sourceLoad;gain;analyser;get context(){return jt.instance}get isPlayable(){return!!this._sourceNode.buffer}get duration(){return this._sourceNode.buffer?.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(r=>r.arrayBuffer()).then(r=>this._decode(r)).finally(()=>t(this))})}_decode(e){return Promise.resolve(e instanceof AudioBuffer?e:jt.decode(e)).then(t=>(this.parent.isLoaded=!0,this.buffer=t,t))}cloneSource(){const e=this.context,t=this._sourceNode,r=e.audioContext.createBufferSource(),i=e.audioContext.createGain();return r.buffer=t.buffer,r.loop=t.loop,e.setParamValue(r.playbackRate,t.playbackRate.value),r.connect(i),i.connect(this.destination),{source:r,gain:i}}createSound(){return new sc}}var Hg=Object.defineProperty,Yg=Object.getOwnPropertyDescriptor,Kg=(s,e,t)=>e in s?Hg(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Zg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Yg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i},Jg=(s,e,t)=>Kg(s,e+"",t);f.Audio=class extends f.TimelineNode{_sounds=[];_platformAudio=Ro?new nc(this):new ic(this);get platformAudio(){return this._platformAudio}_src;get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}isLoaded=!1;get isPlayable(){return this.isLoaded&&this._platformAudio.isPlayable}get audioDuration(){return this._platformAudio.duration*1e3}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_muted=!1;get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}_isPlaying=!1;get isPlaying(){return this._isPlaying}multiple=!1;start=0;end=0;constructor(e=""){super(),this.src=e}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),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",()=>{e.complete?.(),this._onComplete(t)}),t.once("stop",()=>this._onComplete(t));const r=(e?.start??this.start)/1e3,i=(e?.end??this.end)/1e3;return t.play({...e,start:r,end:i}),t}_removeSounds(){for(let e=this._sounds.length-1;e>=0;e--)this._recycleSound(this._sounds[e]);this._sounds.length=0}_createSound(){return f.Audio._soundPool.length>0?f.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()}_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)};_recycleSound(e){e.destroy(),f.Audio._soundPool.includes(e)||f.Audio._soundPool.push(e)}_prevTime=0;_timer=0;_process(e){if(super._process(e),this.canProcess()){const t=this._tree?.timeline.currentTime??0;t-this._prevTime>0&&(this._timer||(this._setTimeStop(),this.play({start:this.start+(t-this.delay)%this.duration})),this._isPlaying&&this._setTimeStop()),this._prevTime=t}}_setTimeStop(){this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this.stop(),this._timer=0},100)}},Jg(f.Audio,"_soundPool",[]),f.Audio=Zg([X("Audio")],f.Audio);class Qg extends f.Node2D{}var em=Object.defineProperty,tm=Object.getOwnPropertyDescriptor,hs=(s,e,t,r)=>{for(var i=r>1?void 0:r?tm(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&em(e,t,i),i};f.AudioWaveform=class extends f.Element2D{_audioBuffer;_src=Dr?new le(document.createElement("canvas")):void 0;_needsUpdateTexture=!1;constructor(e={}){super(),this.setProperties(e)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),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=>jt.decode(t)).then(t=>{this._audioBuffer=t,this.syncTexture(!0)})}syncTexture(e=!1){const t=this._audioBuffer;if(!t||!e&&!this._needsUpdateTexture)return;this._needsUpdateTexture=!1;const r=this._src?.source;if(!r)return;const{width:i=0,height:n=0}=this.style;r.width=i,r.height=n;const o=r.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/i),c=n/2;for(let h=1,u=-1,d=0;d<i;d++){for(let g=0;g<l;g++){const p=a[d*l+g];p<h&&(h=p),p>u&&(u=p)}if(!this.gap||d%(this.gap*2)===0){const g=d,p=(1+h)*c,y=this.gap||1,m=Math.max(1,(u-h)*c);o.fillRect(g,p,y,m),h=1,u=-1}}this._src?.requestUpload(),this.requestRedraw()}_process(e){this.syncTexture(),super._process(e)}_drawSrc(){const e=this._src;e?.isValid()&&(this.context.fillStyle=e,this.context.uvTransform=new ke().scale(1/this.style.width,1/this.style.height))}},hs([_()],f.AudioWaveform.prototype,"src",2),hs([_({fallback:0})],f.AudioWaveform.prototype,"gap",2),hs([_({fallback:"#000000"})],f.AudioWaveform.prototype,"color",2),f.AudioWaveform=hs([X("AudioWaveform")],f.AudioWaveform);var rm=Object.defineProperty,im=Object.getOwnPropertyDescriptor,sm=(s,e,t)=>e in s?rm(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,nm=(s,e,t,r)=>{for(var i=r>1?void 0:r?im(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i},om=(s,e,t)=>sm(s,e+"",t);f.KawaseTransition=class extends f.Transition{blur=10;quality=10;apply(e,t){const r=this.currentTimeProgress;let i,n;r<.5?(i=0,n=(.5-r)/.5):(i=1,n=(r-.5)/.5);const o=this.blur,a=this.quality,l=t.width,c=t.height,h=[],u=[o];if(o>0){let P=o;const E=o/a;for(let b=1;b<a;b++)P-=E,u.push(P)}const d=1/l,g=1/c,p=[];let y;const m=a-1;for(let P=0;P<m;P++)y=u[P]+.5,p[0]=y*d,p[1]=y*g,h.push({offset:p});y=u[m]+.5,p[0]=y*d,p[1]=y*g,h.push({offset:p}),h.forEach(P=>{Q.draw(e,f.KawaseTransition.material,{sampler:i,progress:n,...P})})}},om(f.KawaseTransition,"material",new re({vert:`attribute vec2 position;
957
+ </svg>`}function wg(){const s=new Tt;return{name:"listStyle",pathSet:s,update:e=>{s.paths.length=0;const{paragraphs:t,isVertical:r,fontSize:i}=e,n=i*.45;t.forEach(o=>{const{computedStyle:a}=o,{color:l,listStyleImage:c,listStyleColormap:h,listStyleSize:u,listStyleType:d}=a,g=Bn(h);let p=u,y;if(!K(c))y=c;else if(!K(d)){const x=i*.38/2;switch(p=p==="cover"?x*2:p,d){case"disc":y=bg(x,String(l));break}}if(!y)return;const m=Ws(y),P=m.getBoundingBox(),E=o.fragments[0]?.characters[0];if(!E)return;const{inlineBox:b}=E,S=p==="cover"?1:Un(p,{total:i,fontSize:i})/i,w=new _e;if(r){const x=i/P.height*S;w.translate(-P.left,-P.top).rotate(Math.PI/2).scale(x,x).translate(b.left+(b.width-P.height*x)/2,b.top-n)}else{const x=i/P.height*S;w.translate(-P.left,-P.top).scale(x,x).translate(b.left-P.width*x-n,b.top+(b.height-P.height*x)/2)}s.paths.push(...m.paths.map(x=>{const T=x.clone();return T.applyTransform(w),T.style.fill&&T.style.fill in g&&(T.style.fill=g[T.style.fill]),T.style.stroke&&T.style.stroke in g&&(T.style.stroke=g[T.style.stroke]),T}))})}}}function xg(){return{name:"outline"}}const $t=new k,Tr=new _e,zt=new _e;function Pg(){const s=new Tt;return{name:"render",pathSet:s,update:e=>{s.paths.length=0;const{paragraphs:t}=e;t.forEach(r=>{r.fragments.forEach(i=>{i.characters.forEach(n=>{s.paths.push(n.path)})})})},getBoundingBox:e=>{const{characters:t,fontSize:r,effects:i}=e,n=[];return t.forEach(o=>{i?.forEach(a=>{if(!o.glyphBox)return;const l=o.glyphBox.clone(),c=Nn(e,a);$t.set(l.left,l.top),$t.applyMatrix3(c),l.left=$t.x,l.top=$t.y,$t.set(l.right,l.bottom),$t.applyMatrix3(c),l.width=$t.x-l.left,l.height=$t.y-l.top;const h=(a.shadowOffsetX??0)*r,u=(a.shadowOffsetY??0)*r,d=Math.max(.1,a.textStrokeWidth??0)*r;l.left+=h-d,l.top+=u-d,l.width+=d*2,l.height+=d*2,n.push(l)})}),n.length?Z.from(...n):void 0},render:(e,t)=>{const{paragraphs:r,glyphBox:i,effects:n}=t;n?n.forEach(o=>{is(o,i,e),e.save();const[a,l,c,h,u,d]=Nn(t,o).transpose().elements;e.transform(a,h,l,u,c,d),t.forEachCharacter(g=>{g.drawTo(e,o)}),e.restore()}):r.forEach(o=>{o.fragments.forEach(a=>{a.characters.forEach(l=>{l.drawTo(e)})})}),t.debug&&r.forEach(o=>{e.strokeRect(o.lineBox.x,o.lineBox.y,o.lineBox.width,o.lineBox.height)})}}}function Nn(s,e){const{fontSize:t,glyphBox:r}=s,i=(e.translateX??0)*t,n=(e.translateY??0)*t,o=Math.PI*2,a=(e.skewX??0)/360*o,l=(e.skewY??0)/360*o,{left:c,top:h,width:u,height:d}=r,g=c+u/2,p=h+d/2;return Tr.identity(),zt.makeTranslation(i,n),Tr.multiply(zt),zt.makeTranslation(g,p),Tr.multiply(zt),zt.set(1,Math.tan(a),0,Math.tan(l),1,0,0,0,1),Tr.multiply(zt),zt.makeTranslation(-g,-p),Tr.multiply(zt),Tr.clone()}function Cg(){const s=new Tt;return{name:"textDecoration",pathSet:s,update:e=>{s.paths.length=0;const t=[];let r,i;e.forEachCharacter(n=>{const{computedStyle:o,isVertical:a,inlineBox:l,underlinePosition:c,underlineThickness:h,strikeoutPosition:u,strikeoutSize:d}=n,{color:g,textDecoration:p,writingMode:y}=o;if(K(p))i=void 0;else{let m=!1;if(i?.textDecoration===p&&i?.writingMode===y&&i?.color===g&&(a?r[0].inlineBox.left===l.left:r[0].inlineBox.top===l.top))switch(p){case"underline":r[0].underlinePosition===c&&r[0].underlineThickness===h&&(m=!0);break;case"line-through":r[0].strikeoutPosition===u&&r[0].strikeoutSize===d&&(m=!0);break}m?r.push(n):(r=[],r.push(n),t.push(r)),i=o}}),t.forEach(n=>{const{computedStyle:o,isVertical:a,underlinePosition:l,underlineThickness:c,strikeoutPosition:h,strikeoutSize:u}=n[0],{color:d,textDecoration:g}=o,p=Z.from(...n.map(T=>T.inlineBox)),{left:y,top:m,width:P,height:E}=p;let b=a?y+P:m;const S=a?-1:1;let w=0;switch(g){case"overline":w=c*2;break;case"underline":b+=S*l,w=c*2;break;case"line-through":b+=S*h,w=u*2;break}b-=w;let x;a?x=new ge([{type:"M",x:b,y:m},{type:"L",x:b,y:m+E},{type:"L",x:b+w,y:m+E},{type:"L",x:b+w,y:m},{type:"Z"}],{fill:d}):x=new ge([{type:"M",x:y,y:b},{type:"L",x:y+P,y:b},{type:"L",x:y+P,y:b+w},{type:"L",x:y,y:b+w},{type:"Z"}],{fill:d}),s.paths.push(x)})},render:(e,t)=>{const{effects:r,computedStyle:i}=t;r?r.forEach(n=>{e.save();const[o,a,l,c,h,u]=Nn(t,n).transpose().elements;e.transform(o,c,a,h,l,u),s.paths.forEach(d=>{Pr({ctx:e,path:d,fontSize:i.fontSize,...n})}),e.restore()}):s.paths.forEach(n=>{Pr({ctx:e,path:n,fontSize:i.fontSize})})}}}var Tg=Object.defineProperty,Vt=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Tg(e,t,i),i};const Wl=Po();class kt extends bs{needsUpdate=!0;computedStyle={...Wl};paragraphs=[];lineBox=new Z;rawGlyphBox=new Z;glyphBox=new Z;pathBox=new Z;boundingBox=new Z;measurer=new ss;plugins=new Map;pathSets=[];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))}constructor(e={}){super(),this.set(e)}set(e={}){const{content:t,effects:r,style:i,measureDom:n,fonts:o,fill:a,outline:l}=To(e);this.debug=e.debug??!1,this.content=t,this.effects=r,this.style=i,this.measureDom=n,this.fonts=o,this.fill=a,this.outline=l,this.use(vg()).use(xg()).use(wg()).use(Cg()).use(_g()).use(Pg()),(e.plugins??[]).forEach(c=>{this.use(c)}),this.updateParagraphs()}use(e){return this.plugins.set(e.name,e),this}forEachCharacter(e){return this.paragraphs.forEach((t,r)=>{t.fragments.forEach((i,n)=>{i.characters.forEach((o,a)=>{e(o,{paragraphIndex:r,fragmentIndex:n,characterIndex:a})})})}),this}async load(){await Promise.all(Array.from(this.plugins.values()).map(e=>e.load?.(this)))}updateParagraphs(){this.computedStyle={...Wl,...this.style};const{content:e}=this,t=[];return e.forEach((r,i)=>{const{fragments:n,fill:o,outline:a,...l}=r,c=new yg(l,i,this);c.fill=o,c.outline=a,n.forEach((h,u)=>{const{content:d,fill:g,outline:p,...y}=h;if(d!==void 0){const m=new mg(d,y,u,c);c.fragments.push(m),m.fill=g,m.outline=p}}),t.push(c)}),this.paragraphs=t,this}createDom(){return this.updateParagraphs(),this.measurer.createDom(this.paragraphs,this.computedStyle)}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 r=this.measurer.measure(this.paragraphs,this.computedStyle,e);this.paragraphs=r.paragraphs,this.lineBox=r.boundingBox,this.characters.forEach(i=>{i.update(this.fonts)}),this.rawGlyphBox=this.getGlyphBox(),Array.from(this.plugins.values()).sort((i,n)=>(i.updateOrder??0)-(n.updateOrder??0)).forEach(i=>{i.update?.(this)}),this.pathSets.length=0,Array.from(this.plugins.values()).sort((i,n)=>(i.renderOrder??0)-(n.renderOrder??0)).forEach(i=>{i.pathSet?.paths.length&&this.pathSets.push(i.pathSet)}),this.glyphBox=this.getGlyphBox(),this.updatePathBox().updateBoundingBox();for(const i in t)r[i]=this[i],this[i]=t[i];return this.emit("measure",{text:this,result:r}),r}getGlyphBox(){const e=k.MAX,t=k.MIN;return this.characters.forEach(r=>{if(!r.getGlyphMinMax(e,t)){const{inlineBox:i}=r,{left:n,top:o,width:a,height:l}=i,c=new k(n,o),h=new k(n+a,o+l);e.min(c,h),t.max(c,h)}}),new Z(e.x,e.y,t.x-e.x,t.y-e.y)}updatePathBox(){return this.pathBox=Z.from(this.glyphBox,...Array.from(this.plugins.values()).map(e=>e.getBoundingBox?e.getBoundingBox(this):e.pathSet?.getBoundingBox()).filter(Boolean)),this}updateBoundingBox(){return this.boundingBox=Z.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(e=this.measureDom){this.needsUpdate=!1;const t=this.measure(e);for(const r in t)this[r]=t[r];return this.emit("update",{text:this}),this}render(e){const{view:t,pixelRatio:r=2}=e,i=t.getContext("2d");i&&(this.needsUpdate&&this.update(),cg(i,r,this.boundingBox),hg(i,this),Array.from(this.plugins.values()).sort((n,o)=>(n.renderOrder??0)-(o.renderOrder??0)).forEach(n=>{if(n.render)n.render?.(i,this);else if(n.pathSet){const o=this.computedStyle;n.pathSet.paths.forEach(a=>{Pr({ctx:i,path:a,fontSize:o.fontSize})})}}),this.emit("render",{text:this,view:t,pixelRatio:r}),e.onContext?.(i))}toString(){return this.content.flatMap(e=>e.fragments.map(t=>t.content)).join("")}}Vt([_({internal:!0})],kt.prototype,"debug"),Vt([_()],kt.prototype,"content"),Vt([_()],kt.prototype,"style"),Vt([_()],kt.prototype,"effects"),Vt([_()],kt.prototype,"fill"),Vt([_()],kt.prototype,"outline"),Vt([_({internal:!0})],kt.prototype,"measureDom"),Vt([_({internal:!0})],kt.prototype,"fonts");var Sg=Object.defineProperty,Gt=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Sg(e,t,i),i};class vt extends xt{constructor(e){super(),this.parent=e,this.base=new kt,this.base.setPropertyAccessor(this),this.update()}base;_texture=new Ui;_textureMap=new Map;setProperties(e){return super.setProperties(K(e)?void 0:To(e))}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"enabled":this.parent.requestRedraw();break;case"effects":case"measureDom":case"fonts":this.update(),this.parent.requestRedraw();break;case"fill":case"outline":case"content":this.update(),this._updateTextureMap(),this.parent.requestRedraw();break}}update(){this.base.fonts=this.base.fonts??this.parent.tree?.fonts,this.base.update()}_updateTextureMap(){this._textureMap.clear();const e=[];if(this.base.paragraphs.forEach((t,r)=>{const i=[];if(t.fragments.forEach((n,o)=>{if(n.characters.length){const a=Z.from(...n.characters.map(l=>l.compatibleGlyphBox));this._updateTexture(`${r}.${o}.fill`,n.fill,a),this._updateTexture(`${r}.${o}.outline`,n.outline,a),i.push(a)}}),i.length){const n=Z.from(...i);this._updateTexture(`${r}.fill`,t.fill,n),this._updateTexture(`${r}.outline`,t.outline,n),e.push(n)}}),e.length){const t=Z.from(...e);this._updateTexture("fill",this.fill,t),this._updateTexture("outline",this.outline,t)}}async _updateTexture(e,t,r){t&&Object.keys(t).length>0&&(this._textureMap.set(e,{texture:await this._loadTexture(t,r),box:r}),this.parent.requestRedraw())}async _loadTexture(e,t){return e.linearGradient||e.radialGradient?new zr(e.linearGradient??e.radialGradient,t.width,t.height):K(e.image)?void 0:(this.parent.tree?.log(`load image ${e.image}`),await Ke.texture.load(e.image))}setContent(e){this.content=Ps(e)}measure(){return this.update(),this.base.measure()}isValid(){return!!(this.enabled&&!/^\s*$/.test(this.base.toString()))}_createVertTransform(){const e=this.parent;if(e.scale.x>0&&e.scale.y>0)return;const t=e.scale.x*e.scale.y,r=e.getTransformOrigin();return new ke().translate(-r.x,-r.y).scale(t>0?1:-1,1).translate(r.x,r.y)}useTextureDraw(){return!!this.effects?.length||this.content.some(e=>e.fragments.some(t=>!!t.highlightImage))}_pathDraw(e){this.base.pathSets.forEach(t=>{t.paths.forEach(r=>{const i=r.getMeta();if(i instanceof Vl){const n=i.parent.index,o=i.parent.parent.index;if(r.style.fill&&!K(r.style.fill))if(typeof r.style.fill=="object"){const a=r.style.fill,l=this._textureMap.get(`${o}.${n}.fill`)??this._textureMap.get(`${o}.fill`)??this._textureMap.get("fill");if(a.enabled!==!1&&(l||a.color)){const{uvTransform:c,disableWrapMode:h}=rs(a,l?.box??{width:this.parent.size.width,height:this.parent.size.height});e.addPath(r),e.style={...r.style},e.uvTransform=c,e.fillStyle=l?.texture??a.color,e.vertTransform=this._createVertTransform(),e.fill({disableWrapMode:h})}}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.fill();if(r.style.stroke&&!K(r.style.stroke))if(typeof r.style.stroke=="object"){const a=r.style.stroke,l=this._textureMap.get(`${o}.${n}.outline`)??this._textureMap.get(`${o}.outline`)??this._textureMap.get("outline");if(a.enabled!==!1&&(l||a.color)&&(a.width===void 0||a.width)){const{uvTransform:c,disableWrapMode:h}=rs(a,l?.box??{width:this.parent.size.width,height:this.parent.size.height});e.addPath(r),e.style={...r.style},e.lineWidth=a.width||1,e.uvTransform=c,e.strokeStyle=l?.texture??a.color,e.lineCap=a.lineCap,e.lineJoin=a.lineJoin,e.vertTransform=this._createVertTransform(),e.stroke({disableWrapMode:h})}}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.stroke()}else e.addPath(r),e.style={...r.style},e.vertTransform=this._createVertTransform(),e.fill()})})}_textureDraw(e){this._texture.width=Math.round(this.base.boundingBox.width),this._texture.height=Math.round(this.base.boundingBox.height),this.base.render({view:this._texture.source}),e.fillStyle=this._texture,e.vertTransform=this._createVertTransform(),e.fill()}draw(){const e=this.parent.context;this.useTextureDraw()?this._textureDraw(e):this._pathDraw(e)}}Gt([_({fallback:!0})],vt.prototype,"enabled"),Gt([_({fallback:()=>[]})],vt.prototype,"content"),Gt([_({alias:"parent.style.json"})],vt.prototype,"style"),Gt([_()],vt.prototype,"effects"),Gt([_()],vt.prototype,"fill"),Gt([_()],vt.prototype,"outline"),Gt([_({alias:"base.measureDom"})],vt.prototype,"measureDom"),Gt([_({alias:"base.fonts"})],vt.prototype,"fonts");var Eg=Object.getOwnPropertyDescriptor,Mg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Eg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};const Ag=new Set(Object.keys(wo())),Og=new Set(Object.keys(xo()));f.BaseElement2D=class extends f.Node2D{size=new de().on("update",()=>{this.updateGlobalTransform(),this.requestRedraw()});get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}_background=new Dn(this);get background(){return this._background}set background(e){this._background.resetProperties().setProperties(e)}_shape=new ir(this);get shape(){return this._shape}set shape(e){this._shape.resetProperties().setProperties(e)}_fill=new Oe(this);get fill(){return this._fill}set fill(e){this._fill.resetProperties().setProperties(e)}_outline=new tr(this);get outline(){return this._outline}set outline(e){this._outline.resetProperties().setProperties(e)}_foreground=new In(this);get foreground(){return this._foreground}set foreground(e){this._foreground.resetProperties().setProperties(e)}_text=new vt(this);get text(){return this._text}set text(e){this._text.resetProperties().setProperties(e)}_shadow=new rr(this);get shadow(){return this._shadow}set shadow(e){this._shadow.resetProperties().setProperties(e)}constructor(e,t=[]){super(),this._updateStyleProperty=this._updateStyleProperty.bind(this),this.style=new ui,this.setProperties(e).append(t)}setProperties(e){if(e){const{style:t,text:r,shape:i,background:n,fill:o,outline:a,foreground:l,shadow:c,...h}=e;t&&this.style.setProperties(t),n&&this.background.setProperties(n),i&&this.shape.setProperties(i),o&&this.fill.setProperties(o),a&&this.outline.setProperties(a),r&&this.text.setProperties(r),l&&this.foreground.setProperties(l),c&&this.shadow.setProperties(c),super.setProperties(h)}return this}_updateStyleProperty(e,t,r){switch(e){case"rotate":this.rotation=this.style.rotate*Xo;break;case"scaleX":this.scale.x=this.style.scaleX,this.text.isValid()&&(t^r)<0&&this.requestRedraw();break;case"scaleY":this.scale.y=this.style.scaleY,this.text.isValid()&&(t^r)<0&&this.requestRedraw();break;case"skewX":this.skew.x=this.style.skewX;break;case"skewY":this.skew.y=this.style.skewY;break;case"transform":case"transformOrigin":this.updateGlobalTransform();break;case"opacity":this.opacity=this.style.opacity;break;case"visibility":this.visible=this.style.visibility==="visible";break;case"filter":this.requestRepaint();break;case"maskImage":this._updateMaskImage();break;case"backgroundColor":this.background.color=this.style.backgroundColor;break;case"backgroundImage":this.background.image=this.style.backgroundImage;break;case"borderStyle":case"outlineStyle":this.outline.style=t;break;case"borderWidth":case"outlineWidth":this.outline.width=t;break;case"borderColor":case"outlineColor":this.outline.color=t;break;case"borderRadius":default:this.requestRedraw();break}(Og.has(e)||Ag.has(e))&&this.text.isValid()&&(this.text.update(),this.requestRedraw())}_process(e){this.foreground.updateFrameIndex(),this.fill.updateFrameIndex(),this.outline.updateFrameIndex(),this.background.updateFrameIndex(),super._process(e)}_updateMaskImage(){const e="__$style.maskImage",t=this.style.maskImage;if(t&&t!=="none"){const r=this.getNode(e);r?r.src=t:this.appendChild(new f.MaskEffect({name:e,src:t}),"back")}else{const r=this.getNode(e);r&&this.removeChild(r)}}getTransformOrigin(){const{width:e,height:t}=this.size,[r,i]=ml(this.style.transformOrigin);return new de(r*e,i*t)}updateTransform(e){const{width:t,height:r}=this.size;super.updateTransform(i=>{gl(this.style.transform??"",t,r,i),e?.(i)})}updateGlobalTransform(){super.updateGlobalTransform(),this._updateOverflow()}_relayout(e){return super._relayout(e).map(t=>({...t,dimension:this.size.toFloat32Array()}))}getRect(){return this.getGlobalAabb()}_getPointArray(){const{width:e,height:t}=this.size,r=0,i=0,n=r+e,o=i+t;return[{x:r,y:i},{x:r,y:o},{x:n,y:i},{x:n,y:o}]}getAabb(){return new It(this._getPointArray().map(e=>this.transform.apply(e)))}getGlobalAabb(){return new It(this._getPointArray().map(e=>this.globalTransform.apply(e)))}getObb(){const e=this.getTransformOrigin(),t=this.transform.apply(e).sub(e);return{rect:new It(this._getPointArray().map(r=>(r.x+=t.x,r.y+=t.y,r))),rotation:this.rotation}}getGlobalObb(){const e=this.getTransformOrigin(),t=this.globalTransform.apply(e).sub(e);return{rect:new It(this._getPointArray().map(r=>(r.x+=t.x,r.y+=t.y,r))),rotation:this.globalRotation}}_updateOverflow(){this.style.overflow==="hidden"?this.mask=this.getRect().toJSON():this.mask=void 0}_draw(){super._draw(),this._background.isValid()&&(this._tree?.log(this.name,"background drawing"),this._shape.draw(!this._background.fillWithShape),this._background.draw()),this._fill.isValid()&&(this._tree?.log(this.name,"fill drawing"),this._shape.draw(),this._fill.draw()),this._outline.isValid()&&(this._tree?.log(this.name,"outline drawing"),this._shape.draw(),this._outline.draw()),this._foreground.isValid()&&(this._tree?.log(this.name,"foreground drawing"),this._shape.draw(!this._foreground.fillWithShape),this._foreground.draw()),this._text.isValid()&&(this._tree?.log(this.name,"text drawing"),this._text.useTextureDraw()&&this._shape.draw(!0),this._text.draw()),this._drawContent()}_drawContent(){}_repaint(e){return super._repaint(e).map(t=>({...t}))}canPointerEvents(){return this.style.pointerEvents!=="none"}input(e,t){const r=this.getChildren(!0);for(let i=r.length-1;i>=0;i--)r[i].input(e,t);this.isVisibleInTree()&&this._input(e,t)}_positionInput(e,t){const{width:r,height:i}=this.size;return e.x>=0&&e.x<r&&e.y>=0&&e.y<i}_input(e,t){switch(t){case"pointerdown":case"pointermove":case"pointerup":{if(this.canPointerEvents()){const{screenX:r,screenY:i}=e;if(r&&i){const n=new de(r,i),o=this.getViewport();o&&o.toCanvasGlobal(n,n),this.toLocal(n,n),this._positionInput(n,t)&&(e.target||(e.target=this),this.emit(t,e))}}break}}}toJSON(){const e=t=>Object.keys(t).length>0?t:void 0;return Ve({...super.toJSON(),style:e(this.style.toJSON()),background:e(this.background.toJSON()),shape:e(this.shape.toJSON()),fill:e(this.fill.toJSON()),outline:e(this.outline.toJSON()),text:e(this.text.toJSON()),foreground:e(this.foreground.toJSON()),shadow:e(this.shadow.toJSON())})}},f.BaseElement2D=Mg([X("BaseElement2D")],f.BaseElement2D);class $n extends ui{constructor(e){super(),this.setProperties(e)}}const ql={left:0,top:0,width:0,height:0};for(const s in ql)mi($n,s,{fallback:ql[s]});class Xl extends ui{constructor(e){super(),this.setProperties(e)}}var kg=Object.getOwnPropertyDescriptor,Dg=(s,e,t,r)=>{for(var i=r>1?void 0:r?kg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};f.Element2D=class extends f.BaseElement2D{get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}constructor(e,t=[]){super(),this.style=new $n,this.setProperties(e).append(t)}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"left":this.position.x=Number(t);break;case"top":this.position.y=Number(t);break;case"width":this.size.width=Number(t);break;case"height":this.size.height=Number(t);break}switch(e){case"width":case"height":this.mask instanceof f.BaseElement2D&&(this.mask.size.width=this.size.width,this.mask.size.height=this.size.height);break}}},f.Element2D=Dg([X("Element2D")],f.Element2D);const fe={left:0,top:1,right:2,bottom:3,start:4,end:5,horizontal:6,vertical:7,all:8},Hl={column:0,row:1,all:2},sr={auto:0,"flex-start":1,center:2,"flex-end":3,stretch:4,baseline:5,"space-between":6,"space-around":7,"space-evenly":8},zn={flex:0,none:1,contents:2},ns={inherit:0,ltr:1,rtl:2},Vn={column:0,"column-reverse":1,row:2,"row-reverse":3},Gn={"no-wrap":0,wrap:1,"Wrap-reverse":2},jn={"flex-start":0,center:1,"flex-end":2,"space-between":3,"space-around":4,"space-evenly":5},Wn={visible:0,hidden:1,scroll:2},qn={static:0,relative:1,absolute:2},Xn={"border-box":0,"content-box":1};class os{constructor(e){this._element=e}static _yoga;static async load(){const{loadYoga:e}=await import("yoga-layout/load");this._yoga=await e()}_node=os._yoga.Node.create();get _style(){return this._element.style}get offsetLeft(){return this._node.getComputedLeft()}get offsetTop(){return this._node.getComputedTop()}get offsetWidth(){return this._node.getComputedWidth()}get offsetHeight(){return this._node.getComputedHeight()}calculateLayout(e,t,r){return this._node.calculateLayout(e,t,r)}getComputedLayout(){return this._node.getComputedLayout()}updateStyleProperty(e,t,r){switch(e){case"alignContent":this._node.setAlignContent(t?sr[t]:sr["flex-start"]);break;case"alignItems":this._node.setAlignItems(t?sr[t]:sr["flex-start"]);break;case"alignSelf":this._node.setAlignSelf(t?sr[t]:sr["flex-start"]);break;case"aspectRatio":this._node.setAspectRatio(t);break;case"borderTop":this._node.setBorder(fe.top,this._style.borderWidth);break;case"borderBottom":this._node.setBorder(fe.bottom,this._style.borderWidth);break;case"borderLeft":this._node.setBorder(fe.left,this._style.borderWidth);break;case"borderRight":this._node.setBorder(fe.right,this._style.borderWidth);break;case"border":this._node.setBorder(fe.all,this._style.borderWidth);break;case"direction":this._node.setDirection(t?ns[t]:ns.inherit);break;case"display":this._node.setDisplay(t?zn[t]:zn.flex);break;case"flex":this._node.setFlex(this._style.flex);break;case"flexBasis":this._node.setFlexBasis(this._style.flexBasis);break;case"flexDirection":this._node.setFlexDirection(t?Vn[t]:Vn.row);break;case"flexGrow":this._node.setFlexGrow(this._style.flexGrow);break;case"flexShrink":this._node.setFlexShrink(this._style.flexShrink);break;case"flexWrap":this._node.setFlexWrap(t?Gn[t]:Gn.wrap);break;case"height":this._node.setHeight(this._style.height);break;case"justifyContent":this._node.setJustifyContent(t?jn[t]:jn["flex-start"]);break;case"gap":t!==void 0&&this._node.setGap(Hl.all,t);break;case"marginTop":this._node.setMargin(fe.top,t);break;case"marginBottom":this._node.setMargin(fe.bottom,t);break;case"marginLeft":this._node.setMargin(fe.left,t);break;case"marginRight":this._node.setMargin(fe.right,t);break;case"margin":this._node.setMargin(fe.all,t);break;case"maxHeight":this._node.setMaxHeight(t);break;case"maxWidth":this._node.setMaxWidth(t);break;case"minHeight":this._node.setMinHeight(this._style.minHeight);break;case"minWidth":this._node.setMinWidth(this._style.minWidth);break;case"overflow":this._node.setOverflow(t?Wn[t]:Wn.visible);break;case"paddingTop":this._node.setPadding(fe.top,this._style.paddingTop);break;case"paddingBottom":this._node.setPadding(fe.bottom,this._style.paddingBottom);break;case"paddingLeft":this._node.setPadding(fe.left,this._style.paddingLeft);break;case"paddingRight":this._node.setPadding(fe.right,this._style.paddingRight);break;case"padding":this._node.setPadding(fe.all,this._style.padding);break;case"top":this._node.setPosition(fe.top,this._style.top);break;case"bottom":this._node.setPosition(fe.bottom,this._style.bottom);break;case"left":this._node.setPosition(fe.left,this._style.left);break;case"right":this._node.setPosition(fe.right,this._style.right);break;case"position":this._node.setPositionType(t?qn[t]:qn.static);break;case"boxSizing":this._node.setBoxSizing(t?Xn[t]:Xn["content-box"]);break;case"width":this._node.setWidth(this._style.width);break}}}var Ig=Object.getOwnPropertyDescriptor,Rg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Ig(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i};f.FlexElement2D=class extends f.BaseElement2D{get style(){return this._style}set style(e){const t=(...r)=>{this.emit("updateStyleProperty",r[0],r[1],r[2]),this._updateStyleProperty(r[0],r[1],r[2])};e.on("updateProperty",t),this._style?.off("updateProperty",t),this._style=e}_layout=new os(this);get offsetLeft(){return this._layout.offsetLeft}get offsetTop(){return this._layout.offsetTop}get offsetWidth(){return this._layout.offsetWidth}get offsetHeight(){return this._layout.offsetHeight}constructor(e,t=[]){super(),this.style=new Xl,this.setProperties(e).append(t)}_parented(e){super._parented(e),e._layout&&this._layout._node&&e._layout._node.insertChild(this._layout._node,e._layout._node.getChildCount())}_unparented(e){super._unparented(e),e._layout?._node&&e._layout._node.removeChild(this._layout._node)}_updateStyleProperty(e,t,r){super._updateStyleProperty(e,t,r),this._layout.updateStyleProperty(e,t,r),this._layout._node.isDirty()&&this.requestRelayout()}updateTransform(){this.calculateLayout(void 0,void 0,ns.ltr);const{left:e,top:t,width:r,height:i}=this._layout.getComputedLayout();this.position.x=e,this.position.y=t,this.size.x=r,this.size.y=i,super.updateTransform()}calculateLayout(e,t,r){const i=this.getParent();i?._layout?.calculateLayout?i?._layout.calculateLayout(e,t,r):this._layout.calculateLayout(e,t,r)}},f.FlexElement2D=Rg([X("FlexElement2D")],f.FlexElement2D);var Ug=Object.defineProperty,Bg=Object.getOwnPropertyDescriptor,fi=(s,e,t,r)=>{for(var i=r>1?void 0:r?Bg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Ug(e,t,i),i};f.Image2D=class extends f.Element2D{get currentFrameTexture(){return this.texture?.frames[this._frameIndex]?.texture}get textureDuration(){return this.texture?.duration??0}get naturalWidth(){return this.currentFrameTexture?.realWidth??0}get naturalHeight(){return this.currentFrameTexture?.realHeight??0}get complete(){return this._complete}_frameIndex=0;_complete=!1;_wait=Promise.resolve();constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._wait=this._load(t);break;case"srcRect":this.requestRedraw();break}}decode(){return this._wait}setResource(e){let t;if(e instanceof Ri?t=e:t=new Ri(e),this.texture=t.updateDuration(),this.currentFrameTexture&&(!this.style.width||!this.style.height)){const r=this.currentFrameTexture;this.style.width=r.realWidth,this.style.height=r.realHeight}return this}async _load(e){if(this._complete=!1,e)try{this.setResource(this.gif||e?.includes(".gif")?await Ke.gif.load(e):await Ke.texture.load(e)),this.requestRedraw(),this.emit("load")}catch(t){console.warn(t),this.emit("error",t)}else this.texture=void 0;this._complete=!0}_getFrameCurrentTime(){const e=this.textureDuration;if(!e||!this._tree)return 0;const t=this._currentTime;return t<0?0:t%e}_updateFrameIndex(){if(!this.texture)return this;const e=this._getFrameCurrentTime(),t=this.texture.frames,r=t.length;if(r<=1&&this._frameIndex===0)return this;let i=r-1;for(let n=0,o=0;o<r;o++)if(n+=t[o].duration??0,n>=e){i=o;break}return this._frameIndex!==i&&(this._frameIndex=i,this.requestRedraw()),this}_process(e){this._updateFrameIndex(),super._process(e)}_drawContent(){const e=this.currentFrameTexture;if(e?.isValid()){const{left:t=0,top:r=0,right:i=0,bottom:n=0}=this.srcRect??{},{width:o,height:a}=this.size;this.context.fillStyle=e;const l=Math.abs(1+(t+i))*o,c=Math.abs(1+(r+n))*a,h=1/l,u=1/c,d=t*o*h,g=r*a*u;this.context.uvTransform=new ke().scale(h,u).translate(d,g),this.shape.draw(),this.context.fill()}}_repaint(e){return super._repaint(e).map(t=>({...t,disableWrapMode:!0}))}},fi([_({internal:!0})],f.Image2D.prototype,"texture",2),fi([_({fallback:""})],f.Image2D.prototype,"src",2),fi([_()],f.Image2D.prototype,"srcRect",2),fi([_({fallback:!1})],f.Image2D.prototype,"gif",2),f.Image2D=fi([X("Image2D")],f.Image2D);class Hn extends f.Element2D{texture;constructor(e,t=[]){super(),this.setProperties(e).append(t)}_drawContent(){this.texture?.isValid()&&(this.shape.draw(!0),this.context.fillStyle=this.texture,this.context.fill())}}var Lg=Object.defineProperty,Fg=Object.getOwnPropertyDescriptor,Yl=(s,e,t,r)=>{for(var i=r>1?void 0:r?Fg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Lg(e,t,i),i};f.Lottie2D=class extends Hn{texture=new Ui;animation;constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._load();break}}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"width":this.texture.width=this.style.width;break;case"height":this.texture.height=this.style.height;break}}async _load(){this.animation=await Ke.lottie.load(this.src,this.texture.source),this.duration=this.animation.getDuration(!1)*1e3,this.texture.requestUpload(),this.requestRedraw()}_process(e){this.animation?.goToAndStop(this.currentTime,!1),this.texture.requestUpload(),this.requestRedraw(),super._process(e)}},Yl([_({fallback:""})],f.Lottie2D.prototype,"src",2),f.Lottie2D=Yl([X("Lottie2D")],f.Lottie2D);var Ng=Object.defineProperty,$g=(s,e,t,r)=>{for(var i=void 0,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(e,t,i)||i);return i&&Ng(e,t,i),i};class Kl extends f.Element2D{constructor(e,t=[]){super(),this.setProperties(e).append(t)}_updateStyleProperty(e,t,r){switch(super._updateStyleProperty(e,t,r),e){case"width":case"height":this.requestRedraw();break}}_drawCircle(e,t){this.context.arc(e,t,this.handleSize,0,Math.PI*2,!0),this.context.fillStyle=le.WHITE,this.context.fill(),this.context.arc(e,t,this.handleSize,0,Math.PI*2,!0),this.context.strokeStyle="rgba(0, 0, 0, 0.2)",this.context.stroke()}_drawEllipse(e,t){this.context.roundRect(e-this.handleSize,t-this.handleSize*2,this.handleSize*2,this.handleSize*4,this.handleSize),this.context.fillStyle=le.WHITE,this.context.fill(),this.context.roundRect(e-this.handleSize,t-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:e,height:t}=this.getRect();this.context.rect(0,0,e,t),this.context.strokeStyle="#00FF00",this.context.stroke(),this._drawCircle(0,0),this._drawCircle(e,t),this._drawCircle(0,t),this._drawEllipse(0,t/2),this._drawCircle(e,0),this._drawEllipse(e,t/2)}}$g([_({fallback:6})],Kl.prototype,"handleSize");var zg=Object.defineProperty,Vg=Object.getOwnPropertyDescriptor,Zl=(s,e,t,r)=>{for(var i=r>1?void 0:r?Vg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&zg(e,t,i),i};f.Video2D=class extends Hn{get videoDuration(){return(this.texture?.duration??0)*1e3}_wait=Promise.resolve();constructor(e,t=[]){super(),this.setProperties(e),this.append(t)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),e){case"src":this._wait=this._load(t);break}}waitLoad(){return this._wait}async _load(e){this.texture=await Ke.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 r=t.duration;e=r?e%(r*1e3):0,!t.isPlaying&&!t.seeking&&(e=~~e/1e3,t.currentTime!==e&&(t.currentTime=e))}_process(e){this._updateVideoCurrentTime(),super._process(e)}},Zl([_({fallback:""})],f.Video2D.prototype,"src",2),f.Video2D=Zl([X("Video2D")],f.Video2D);var Gg=Object.defineProperty,jg=Object.getOwnPropertyDescriptor,as=(s,e,t,r)=>{for(var i=r>1?void 0:r?jg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&Gg(e,t,i),i};const Jl=s=>s,Ql=Sr(.25,.1,.25,1),ec=Sr(.42,0,1,1),tc=Sr(0,0,.58,1),rc=Sr(.42,0,.58,1);function Sr(s,e,t,r){const n=3*s-3*t+1,o=3*t-6*s,a=3*s,l=3*e-3*r+1,c=3*r-6*e,h=3*e,u=y=>(3*n*y+2*o)*y+a,d=y=>((n*y+o)*y+a)*y,g=y=>((l*y+c)*y+h)*y;function p(y){let m=y,P,E;for(let w=0;w<8;w++){if(E=d(m)-y,Math.abs(E)<1e-6)return m;if(P=u(m),Math.abs(P)<1e-6)break;m-=E/P}let b=1,S=0;for(m=y;b>S;){if(E=d(m)-y,Math.abs(E)<1e-6)return m;E>0?b=m:S=m,m=(b+S)/2}return m}return y=>g(p(y))}const ls={linear:Jl,ease:Ql,easeIn:ec,easeOut:tc,easeInOut:rc};f.Animation=class extends f.TimelineNode{_keyframes=[];_isFirstUpdatePosition=!1;_cachedProps=new ho;_stoped=!1;constructor(e,t=[]){super(),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,r){switch(super._updateProperty(e,t,r),e){case"effectMode":case"keyframes":this._updateKeyframes();break}}_getTargets(){let e;switch(this.effectMode){case"sibling":e=this.getParent()?.getChildren(!0).filter(t=>t instanceof f.CanvasItem)??[];break;case"parent":default:e=[this.getParent()].filter(Boolean);break}return e.map(t=>t.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",...c}=t[o];e.push({offset:a,easing:this._parseEasing(l),props:c})}const r=e[0],i=e[e.length-1];r&&r.offset!==0&&e.unshift({offset:0,easing:this._parseEasing("linear"),props:{}}),i&&i.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,r=this.currentTimeProgress;e.forEach((i,n)=>{const o=t===1?r:ut(Math.max(0,r-t*n)/t,0,1),a=this._cachedProps.get(i);if(!a)return;const l=this._parseKeyframes(o,a);l?.length&&this._commitStyle(o,i,a,l[0],l[1])})}_updateCachedProps(){this.cancel(),this._getTargets().forEach(e=>{const t=new Map,r=this._keyframes;for(let i=r.length,n=0;n<i;n++)Object.keys(r[n].props).forEach(o=>{t.set(o,e[o])});this._cachedProps.set(e,t)})}_parseEasing(e){if(!e)return ls.linear;if(e in ls)return ls[e];const t=e.replace(/cubic-bezier\((.+)\)/,"$1").split(",").map(r=>Number(r));return Sr(t[0],t[1],t[2],t[3])}_parseKeyframes(e,t){let r;const i=this._keyframes;for(let n=i.length,o=0;o<n;o++){const a=i[o],{offset:l,easing:c}=a,h={...a.props};if(r&&e<=l){const{offset:u,easing:d}=r,g={...r.props};return t.forEach((p,y)=>{(!(y in g)||g[y]===null)&&(g[y]=p),(!(y in h)||h[y]===null)&&(h[y]=p)}),[{offset:u,easing:d,props:g},{offset:l,easing:c,props:h}]}r=a}return null}_commitStyle(e,t,r,i,n){const{offset:o,easing:a,props:l}=i,{offset:c,props:h}=n,u=c-o,d=a((e-o)/u),g={width:t.width,height:t.height,fontSize:t.fontSize};r.forEach((p,y)=>{t[y]=this._getDiffValue(y,l[y],h[y],d,g)})}_getDiffValue(e,t,r,i,n){let o,a;if(t==="none"&&(t=void 0),r==="none"&&(r=void 0),t===void 0||r===void 0)if(t!==void 0)o=Or(e,String(t),n),a=Ss(o);else if(r!==void 0)a=Or(e,String(r),n),o=Ss(a);else return;else o=Or(e,String(t),n),a=Or(e,String(r),n);if(Array.isArray(o)&&Array.isArray(a)){const l=new Set,c={},h={};o.forEach(({name:d,args:g})=>{c[d]=g,l.add(d)}),a.forEach(({name:d,args:g})=>{h[d]=g,l.add(d)});let u="";return l.forEach(d=>{const g=Math.max(c[d]?.length??0,h[d]?.length??0),p=c[d],y=h[d];u+=`${d}(${Array.from({length:g},(m,P)=>{const E=p?.[P],b=y?.[P],S=E?.normalizedIntValue??0,w=b?.normalizedIntValue??0;return Number.isNaN(S)||Number.isNaN(w)?b?.value??0:he(S,w,i)}).join(", ")}) `}),u}else if(!Array.isArray(o)&&!Array.isArray(a))return Number.isNaN(o.normalizedIntValue)||Number.isNaN(a.normalizedIntValue)?a.value:he(o.normalizedIntValue,a.normalizedIntValue,i)}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=>{this._cachedProps.get(e)?.forEach((t,r)=>{e[r]=t}),this._cachedProps.delete(e)})}},as([_({fallback:"parent"})],f.Animation.prototype,"effectMode",2),as([_({default:()=>[]})],f.Animation.prototype,"keyframes",2),as([_()],f.Animation.prototype,"easing",2),f.Animation=as([X("Animation",{renderMode:"disabled",processMode:"pausable",processSortMode:"parent_before",duration:2e3})],f.Animation);class cs extends Dt{static _instance;static get instance(){return this._instance||(this._instance=new cs),this._instance}playbackRate=1;muted=!1;volume=1;paused=!1;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}}class di extends Dt{static PADDING=.1;_source=null;_audio=null;_end=0;_pausedReal=!1;_duration=0;_start=0;_playing=!1;get progress(){return(this._source?.currentTime??0)/this._duration}_paused=!1;get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_muted=!1;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 r=e.volume*(e.muted?0:1),i=t.volume*(t.muted?0:1),n=this._volume*(this._muted?0:1);this._source.volume=n*r*i,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:r=0}=e;r&&console.assert(r>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&&r!==null&&(console.warn('Looping not support when specifying an "end" time'),this.loop=!1),this._start=t,this._end=r||this._duration,this._start=Math.max(0,this._start-di.PADDING),this._end=Math.min(this._end+di.PADDING,this._duration),this._source.onloadedmetadata=()=>{this._source&&(this._source.currentTime=t,this._source.onloadedmetadata=null,this.emit("progress",t,this._duration),Ce.on(this._onUpdate))},this._source.onended=this._onComplete.bind(this),this._source.play(),this.emit("start")}_onUpdate=()=>{this._source&&(this.emit("progress",this.progress,this._duration),this._source.currentTime>=this._end&&!this._source.loop&&this._onComplete())};_onComplete(){Ce.off(this._onUpdate),this._stop(),this.emit("progress",1,this._duration),this.emit("end",this)}destroy(){Ce.off(this._onUpdate),super.destroy();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)}}class ic{constructor(e){this.parent=e}source=new globalThis.Audio;_src="";get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}get duration(){return this.source.duration}get isPlayable(){return!!this.source&&this.source.readyState===4}get context(){return cs.instance}async load(){return new Promise(e=>{this.source.onload=()=>e(this),this.source.src=this._src,this.source.load()})}createSound(){return new di}}class Yn extends Dt{constructor(e,t){super(),this._input=e,this._output=t}_processers=[];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(r=>{t?t.connect(r.destination):this._input.connect(r.destination),t=r}),t.connect(this._output)}}get destination(){return this._input}}class Wg{constructor(e,t=null){this.destination=e,this.source=t}connect(e){this.source?.connect(e)}disconnect(){this.source?.disconnect()}}function qg(){if(Ms)return new AudioContext;if(As){const s=globalThis.webkitAudioContext;return new s}else throw new Error("Failed to createAudioContext")}function Xg(s,e,t){if(Os)return new OfflineAudioContext(s,e,t);if(Io){const r=globalThis.webkitOfflineAudioContext;return new r(s,e,t)}else throw new Error("Failed to createOfflineAudioContext")}class jt extends Yn{static _instance;static get instance(){return this._instance||(this._instance=new jt),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)}_context;_offlineContext;get audioContext(){return this._context}get offlineContext(){return this._offlineContext}_locked;muted=!1;volume=1;playbackRate=1;autoPause=!0;_paused=!1;_pausedOnBlur=!1;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}_compressor;_analyser;constructor(){const e=qg(),t=Xg(1,2,Os?Math.max(8e3,Math.min(96e3,e.sampleRate)):44100),r=e.createDynamicsCompressor(),i=e.createAnalyser();i.connect(r),r.connect(e.destination),super(i,r),this._context=e,this._offlineContext=t,this._compressor=r,this._analyser=i,this._locked=e.state==="suspended"&&(wt||Do),Dr&&(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))}_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()))}_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))};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,r)=>{const i=o=>{r(new Error(o?.message||"Unable to decode file"))},n=this._offlineContext.decodeAudioData(e,t,i);n&&n.catch(i)})}setParamValue(e,t){e.setValueAtTime?e.setValueAtTime(t,this._context.currentTime):e.value=t}}class sc extends Dt{_audio=null;_sourceNode=null;_gain=null;_progress=0;get progress(){return this._progress}_pausedReal=!1;_paused=!1;get paused(){return this._paused}set paused(e){this._paused!==e&&(this._paused=e,this.refreshPaused())}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh(),this._update(!0))}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_muted=!1;get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}_duration=0;_end=0;_elapsed=0;_lastUpdate=this._now();_processors=[];init(e){return this._audio=e,e.context.on("refresh",this.refresh),e.context.on("refreshPaused",this.refreshPaused),this}_now(){return this._audio?.context.audioContext.currentTime??0}play(e={}){if(!this._audio)return;const{end:t=0,start:r=0}=e;t&&console.assert(t>r,"End time is before start time"),this._end=t,this._elapsed=r,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:i,gain:n}=this._audio.cloneSource();this._sourceNode=i,this._gain=n,this.refresh(),i.onended=this._onComplete.bind(this),this._duration=i.buffer?.duration??0,this._lastUpdate=this._now(),this._loop?(i.loopStart=r,i.loopEnd=t,i.start(0,r)):t?i.start(0,r,t-r):i.start(0,r),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(),r=t-this._lastUpdate;if(r>0||e){this._elapsed+=r*this._sourceNode.playbackRate.value,this._lastUpdate=t;const i=this._duration;let n;if(this._sourceNode.loopStart){const o=this._sourceNode.loopEnd-this._sourceNode.loopStart;n=(this._sourceNode.loopStart+this._elapsed%o)/i}else n=this._elapsed%i/i;this._progress=n,this.emit("progress",n,i)}}}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))}_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)};_updateListener=()=>this._update();_enableTicker(e){Ce.off(this._updateListener),e&&Ce.on(this._updateListener)}destroy(){super.destroy(),this._stop(),this._gain?.disconnect(),this._gain=null,this._audio?.context.off("refresh",this.refresh),this._audio?.context.off("refreshPaused",this.refreshPaused),this._audio=null,this._processors.forEach(e=>e.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 nc extends Yn{constructor(e){const t=jt.audioContext,r=t.createBufferSource(),i=t.createGain(),n=t.createAnalyser();r.connect(n),n.connect(i),i.connect(jt.instance.destination),super(n,i),this.parent=e,this._sourceNode=r,this.gain=i,this.analyser=n}_sourceBuffer;_sourceNode;_sourceLoad;gain;analyser;get context(){return jt.instance}get isPlayable(){return!!this._sourceNode.buffer}get duration(){return this._sourceNode.buffer?.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(r=>r.arrayBuffer()).then(r=>this._decode(r)).finally(()=>t(this))})}_decode(e){return Promise.resolve(e instanceof AudioBuffer?e:jt.decode(e)).then(t=>(this.parent.isLoaded=!0,this.buffer=t,t))}cloneSource(){const e=this.context,t=this._sourceNode,r=e.audioContext.createBufferSource(),i=e.audioContext.createGain();return r.buffer=t.buffer,r.loop=t.loop,e.setParamValue(r.playbackRate,t.playbackRate.value),r.connect(i),i.connect(this.destination),{source:r,gain:i}}createSound(){return new sc}}var Hg=Object.defineProperty,Yg=Object.getOwnPropertyDescriptor,Kg=(s,e,t)=>e in s?Hg(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,Zg=(s,e,t,r)=>{for(var i=r>1?void 0:r?Yg(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i},Jg=(s,e,t)=>Kg(s,e+"",t);f.Audio=class extends f.TimelineNode{_sounds=[];_platformAudio=Ro?new nc(this):new ic(this);get platformAudio(){return this._platformAudio}_src;get src(){return this._src}set src(e){this._src!==e&&(this._src=e,this.load())}isLoaded=!1;get isPlayable(){return this.isLoaded&&this._platformAudio.isPlayable}get audioDuration(){return this._platformAudio.duration*1e3}_volume=1;get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this.refresh())}_muted=!1;get muted(){return this._muted}set muted(e){this._muted!==e&&(this._muted=e,this.refresh())}_loop=!1;get loop(){return this._loop}set loop(e){this._loop!==e&&(this._loop=e,this.refresh())}_playbackRate=1;get playbackRate(){return this._playbackRate}set playbackRate(e){this._playbackRate!==e&&(this._playbackRate=e,this.refresh())}_isPlaying=!1;get isPlaying(){return this._isPlaying}multiple=!1;start=0;end=0;constructor(e=""){super(),this.src=e}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),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",()=>{e.complete?.(),this._onComplete(t)}),t.once("stop",()=>this._onComplete(t));const r=(e?.start??this.start)/1e3,i=(e?.end??this.end)/1e3;return t.play({...e,start:r,end:i}),t}_removeSounds(){for(let e=this._sounds.length-1;e>=0;e--)this._recycleSound(this._sounds[e]);this._sounds.length=0}_createSound(){return f.Audio._soundPool.length>0?f.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()}_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)};_recycleSound(e){e.destroy(),f.Audio._soundPool.includes(e)||f.Audio._soundPool.push(e)}_prevTime=0;_timer=0;_process(e){if(super._process(e),this.canProcess()){const t=this._tree?.timeline.currentTime??0;t-this._prevTime>0&&(this._timer||(this._setTimeStop(),this.play({start:this.start+(t-this.delay)%this.duration})),this._isPlaying&&this._setTimeStop()),this._prevTime=t}}_setTimeStop(){this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this.stop(),this._timer=0},100)}},Jg(f.Audio,"_soundPool",[]),f.Audio=Zg([X("Audio")],f.Audio);class Qg extends f.Node2D{}var em=Object.defineProperty,tm=Object.getOwnPropertyDescriptor,hs=(s,e,t,r)=>{for(var i=r>1?void 0:r?tm(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=(r?o(e,t,i):o(i))||i);return r&&i&&em(e,t,i),i};f.AudioWaveform=class extends f.Element2D{_audioBuffer;_src=Dr?new le(document.createElement("canvas")):void 0;_needsUpdateTexture=!1;constructor(e={}){super(),this.setProperties(e)}_updateProperty(e,t,r){switch(super._updateProperty(e,t,r),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=>jt.decode(t)).then(t=>{this._audioBuffer=t,this.syncTexture(!0)})}syncTexture(e=!1){const t=this._audioBuffer;if(!t||!e&&!this._needsUpdateTexture)return;this._needsUpdateTexture=!1;const r=this._src?.source;if(!r)return;const{width:i=0,height:n=0}=this.style;r.width=i,r.height=n;const o=r.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/i),c=n/2;for(let h=1,u=-1,d=0;d<i;d++){for(let g=0;g<l;g++){const p=a[d*l+g];p<h&&(h=p),p>u&&(u=p)}if(!this.gap||d%(this.gap*2)===0){const g=d,p=(1+h)*c,y=this.gap||1,m=Math.max(1,(u-h)*c);o.fillRect(g,p,y,m),h=1,u=-1}}this._src?.requestUpload(),this.requestRedraw()}_process(e){this.syncTexture(),super._process(e)}_drawSrc(){const e=this._src;e?.isValid()&&(this.context.fillStyle=e,this.context.uvTransform=new ke().scale(1/this.style.width,1/this.style.height))}},hs([_()],f.AudioWaveform.prototype,"src",2),hs([_({fallback:0})],f.AudioWaveform.prototype,"gap",2),hs([_({fallback:"#000000"})],f.AudioWaveform.prototype,"color",2),f.AudioWaveform=hs([X("AudioWaveform")],f.AudioWaveform);var rm=Object.defineProperty,im=Object.getOwnPropertyDescriptor,sm=(s,e,t)=>e in s?rm(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,nm=(s,e,t,r)=>{for(var i=r>1?void 0:r?im(e,t):e,n=s.length-1,o;n>=0;n--)(o=s[n])&&(i=o(i)||i);return i},om=(s,e,t)=>sm(s,e+"",t);f.KawaseTransition=class extends f.Transition{blur=10;quality=10;apply(e,t){const r=this.currentTimeProgress;let i,n;r<.5?(i=0,n=(.5-r)/.5):(i=1,n=(r-.5)/.5);const o=this.blur,a=this.quality,l=t.width,c=t.height,h=[],u=[o];if(o>0){let P=o;const E=o/a;for(let b=1;b<a;b++)P-=E,u.push(P)}const d=1/l,g=1/c,p=[];let y;const m=a-1;for(let P=0;P<m;P++)y=u[P]+.5,p[0]=y*d,p[1]=y*g,h.push({offset:p});y=u[m]+.5,p[0]=y*d,p[1]=y*g,h.push({offset:p}),h.forEach(P=>{Q.draw(e,f.KawaseTransition.material,{sampler:i,progress:n,...P})})}},om(f.KawaseTransition,"material",new re({vert:`attribute vec2 position;
958
958
  attribute vec2 uv;
959
959
  varying vec2 vUv;
960
960
  void main() {
package/dist/index.mjs CHANGED
@@ -10088,9 +10088,9 @@ class BaseElement2DText extends CoreObject {
10088
10088
  this.parent = parent;
10089
10089
  this.base = new Text();
10090
10090
  this.base.setPropertyAccessor(this);
10091
+ this.update();
10091
10092
  }
10092
10093
  base;
10093
- measureResult;
10094
10094
  _texture = new CanvasTexture();
10095
10095
  _textureMap = /* @__PURE__ */ new Map();
10096
10096
  setProperties(properties) {
@@ -10181,10 +10181,6 @@ class BaseElement2DText extends CoreObject {
10181
10181
  this.update();
10182
10182
  return this.base.measure();
10183
10183
  }
10184
- updateMeasure() {
10185
- this.measureResult = this.measure();
10186
- return this;
10187
- }
10188
10184
  isValid() {
10189
10185
  return Boolean(
10190
10186
  this.enabled && !/^\s*$/.test(this.base.toString())
@@ -10490,6 +10486,7 @@ let BaseElement2D = class extends Node2D {
10490
10486
  if (textStyles.has(key) || layoutStyle.has(key)) {
10491
10487
  if (this.text.isValid()) {
10492
10488
  this.text.update();
10489
+ this.requestRedraw();
10493
10490
  }
10494
10491
  }
10495
10492
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.12.2",
4
+ "version": "0.12.3",
5
5
  "packageManager": "pnpm@10.18.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",