modern-text 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { c as DeformationPreset } from '../shared/modern-text.BD7PBYt7.cjs';
1
+ import { c as DeformationPreset } from '../shared/modern-text.c9v5Qvut.cjs';
2
2
  import 'modern-path2d';
3
- import '../shared/modern-text.D4WopQCu.cjs';
3
+ import '../shared/modern-text.C6VOXPvn.cjs';
4
4
  import 'modern-idoc';
5
5
  import 'modern-font';
6
6
 
@@ -1,6 +1,6 @@
1
- import { c as DeformationPreset } from '../shared/modern-text.CYa4lfoG.mjs';
1
+ import { c as DeformationPreset } from '../shared/modern-text.DYc0f8rj.mjs';
2
2
  import 'modern-path2d';
3
- import '../shared/modern-text.D4WopQCu.mjs';
3
+ import '../shared/modern-text.C6VOXPvn.mjs';
4
4
  import 'modern-idoc';
5
5
  import 'modern-font';
6
6
 
@@ -1,6 +1,6 @@
1
- import { c as DeformationPreset } from '../shared/modern-text.BxijkspX.js';
1
+ import { c as DeformationPreset } from '../shared/modern-text.i19sSLm-.js';
2
2
  import 'modern-path2d';
3
- import '../shared/modern-text.D4WopQCu.js';
3
+ import '../shared/modern-text.C6VOXPvn.js';
4
4
  import 'modern-idoc';
5
5
  import 'modern-font';
6
6
 
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const Text = require('./shared/modern-text.CBgc-cQ1.cjs');
3
+ const Text = require('./shared/modern-text.9z5yZjKR.cjs');
4
4
  const deformation = require('./shared/modern-text.B2xfrqDc.cjs');
5
5
  const curves = require('./shared/modern-text.MC5bIC9E.cjs');
6
+ require('modern-font');
6
7
  require('modern-idoc');
7
8
  require('modern-path2d');
8
- require('modern-font');
9
9
 
10
10
  function measureText(options, load) {
11
11
  const text = new Text.Text(options);
package/dist/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
- import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.D4WopQCu.cjs';
2
- export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.D4WopQCu.cjs';
1
+ import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.C6VOXPvn.cjs';
2
+ export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.C6VOXPvn.cjs';
3
3
  import { Fonts } from 'modern-font';
4
4
  import { FullStyle, NormalizedStyle, NormalizedHighlight, NormalizedEffect } from 'modern-idoc';
5
5
  import { BoundingBox, Vector2, Path2DSet, Transform2D } from 'modern-path2d';
6
- import { c as DeformationPreset } from './shared/modern-text.BD7PBYt7.cjs';
7
- export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.BD7PBYt7.cjs';
6
+ import { c as DeformationPreset } from './shared/modern-text.c9v5Qvut.cjs';
7
+ export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.c9v5Qvut.cjs';
8
8
 
9
9
  declare function definePlugin(options: Plugin): Plugin;
10
10
 
package/dist/index.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.D4WopQCu.mjs';
2
- export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.D4WopQCu.mjs';
1
+ import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.C6VOXPvn.mjs';
2
+ export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.C6VOXPvn.mjs';
3
3
  import { Fonts } from 'modern-font';
4
4
  import { FullStyle, NormalizedStyle, NormalizedHighlight, NormalizedEffect } from 'modern-idoc';
5
5
  import { BoundingBox, Vector2, Path2DSet, Transform2D } from 'modern-path2d';
6
- import { c as DeformationPreset } from './shared/modern-text.CYa4lfoG.mjs';
7
- export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.CYa4lfoG.mjs';
6
+ import { c as DeformationPreset } from './shared/modern-text.DYc0f8rj.mjs';
7
+ export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.DYc0f8rj.mjs';
8
8
 
9
9
  declare function definePlugin(options: Plugin): Plugin;
10
10
 
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.D4WopQCu.js';
2
- export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.D4WopQCu.js';
1
+ import { i as Plugin, k as TextMeasurer, P as Paragraph, M as MeasureDomResult, a as Character, O as Options, c as MeasureResult, R as RenderOptions, T as Text } from './shared/modern-text.C6VOXPvn.js';
2
+ export { C as Canvas2DRenderer, D as DomMeasurer, b as DrawShapePathsOptions, F as Fragment, d as MeasuredCharacter, e as MeasuredCharacterRect, f as MeasuredFragment, g as MeasuredParagraph, h as MeasurerKind, j as TextEvents, t as textDefaultStyle } from './shared/modern-text.C6VOXPvn.js';
3
3
  import { Fonts } from 'modern-font';
4
4
  import { FullStyle, NormalizedStyle, NormalizedHighlight, NormalizedEffect } from 'modern-idoc';
5
5
  import { BoundingBox, Vector2, Path2DSet, Transform2D } from 'modern-path2d';
6
- import { c as DeformationPreset } from './shared/modern-text.BxijkspX.js';
7
- export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.BxijkspX.js';
6
+ import { c as DeformationPreset } from './shared/modern-text.i19sSLm-.js';
7
+ export { B as BendContext, a as BendPreset, C as CurvePreset, D as DeformationCharInfo, b as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.i19sSLm-.js';
8
8
 
9
9
  declare function definePlugin(options: Plugin): Plugin;
10
10
 
package/dist/index.js CHANGED
@@ -33,4 +33,4 @@ ${this.paths.map(e=>e.toSvgPathString()).join(``)}
33
33
  }`)),document.head.appendChild(n)}return this}_parseUrls(e){let t=[...new Set([...e.split(`,`),e])];return[...new Set(t.map(e=>this.familyToUrl.get(e.trim())??this.familyToUrl.get(e)??e))]}get(e){let t;return e&&(t=this._parseUrls(e).reduce((e,t)=>e||this.loaded.get(t),void 0)),t??this.fallbackFont}set(e,t){return this.familyToUrl.set(e,t.src),this.loaded.set(t.src,t),this}delete(e){return this._parseUrls(e).forEach(e=>{this.familyToUrl.delete(e),this.loaded.delete(e)}),this}clear(){return this.familyToUrl.clear(),this.loading.clear(),this.loaded.clear(),this}_parseFamilies(e){return e?(Array.isArray(e)?e:[e]).flatMap(e=>e.split(`,`).map(e=>e.trim())):[]}async load(e,t={}){let{cancelOther:n,injectStyleTag:r=!1,injectFontFace:i=!1,...a}=t,o,s;typeof e==`string`?o=e:{src:o,family:s}=e;let c=this._parseFamilies(s);if(this.loaded.has(o))return n&&(this.loading.forEach(e=>e.cancel()),this.loading.clear()),u(this.loaded.get(o));let l=this.loading.get(o);return l||(l=this._createRequest(o,a),this.loading.set(o,l)),n&&this.loading.forEach((e,t)=>{e!==l&&(e.cancel(),this.loading.delete(t))}),l.when.then(e=>{let n;return this.loaded.has(o)?n=u(this.loaded.get(o)):(n=d(e),t.noAdd||this.loaded.set(o,n)),Promise.all(Array.from(n.familySet,async t=>{if(this.familyToUrl.set(t,o),typeof document<`u`&&(i&&await this.injectFontFace(t,e),r&&this.injectStyleTag(t,o),i||r))return await document.fonts.load(`14px "${t}"`)})).then(()=>n)}).catch(e=>{if(e instanceof DOMException&&e.message===`The user aborted a request.`)return d();throw e}).finally(()=>{this.loading.delete(o)});function u(e){return c.forEach(t=>{e.familySet.add(t)}),e}function d(e=new ArrayBuffer(0)){let t;function n(){return t||=e.byteLength?Ys(e,!1):void 0,t}function r(){let e=n();if(e instanceof Fs||e instanceof qs)return e.sfnt}return{src:o,family:s,buffer:e,familySet:new Set(c),getFont:n,getSFNT:r}}}async waitUntilLoad(){await Promise.all(Array.from(this.loading.values(),e=>e.when))}},Zs=new Set([`©`,`®`,`÷`]),Qs=new Set([`—`,`…`,`“`,`”`,`﹏`,`﹋`,`﹌`,`‘`,`’`,`˜`]),$s={1:`italic`,32:`bold`},ec={1:`italic`,2:`bold`},tc={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5},nc=class{content;index;parent;path=new Mr().setMeta(this);lineBox=new W;inlineBox=new W;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(){let e=this.computedStyle.fontSize*.8;return this.glyphBox??(this.isVertical?new W(this.lineBox.left+this.lineBox.width/2-e/2,this.lineBox.top,e,this.lineBox.height):new W(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}constructor(e,t,n){this.content=e,this.index=t,this.parent=n}_getFontSFNT(e){let t=this.computedStyle.fontFamily,n=e??Xs,r=(t?n.get(t):n.fallbackFont)?.getSFNT();return r?.textToGlyphIndexes(this.content).includes(0)&&(r=n.fallbackFont?.getSFNT()),r}updateGlyph(e=this._getFontSFNT()){if(!e)return this;let{hhea:t,os2:n,post:r,head:i}=e,a=i.unitsPerEm,o=t.ascent,s=t.descent,{content:c,computedStyle:l}=this,{fontSize:u}=l,d=a/u,f=e.getAdvanceWidth(c,u),p=(o+Math.abs(s))/d,m=o/d;return this.advanceWidth=f,this.advanceHeight=p,this.underlinePosition=(o-r.underlinePosition)/d,this.underlineThickness=r.underlineThickness/d,this.strikeoutPosition=(o-n.yStrikeoutPosition)/d,this.strikeoutSize=n.yStrikeoutSize/d,this.ascender=o/d,this.descender=s/d,this.typoAscender=n.sTypoAscender/d,this.typoDescender=n.sTypoDescender/d,this.typoLineGap=n.sTypoLineGap/d,this.winAscent=n.usWinAscent/d,this.winDescent=n.usWinDescent/d,this.xHeight=n.version>1?n.sxHeight/d:0,this.capHeight=n.version>1?n.sCapHeight/d:0,this.baseline=m,this.centerDiviation=p/2-m,this.fontStyle=$s[n.fsSelection]??ec[i.macStyle],this}measureGlyph(e){return this.updateGlyph(this._getFontSFNT(e))}update(e){let t=this._getFontSFNT(e);if(!t)return this;this.updateGlyph(t);let{isVertical:n,content:r,computedStyle:i,baseline:a,inlineBox:o,ascender:s,descender:c,typoAscender:l,fontStyle:u,advanceWidth:d,advanceHeight:f}=this,{left:p,top:m}=o,h=i.fontStyle===`italic`&&u!==`italic`,g=p,_=m+a,v,y=new Mr().setMeta(this);if(n&&(g+=(f-d)/2,Math.abs(d-f)>.1&&(_-=(s-l)/(s+Math.abs(c))*f),v=void 0),n&&!Zs.has(r)&&(r.codePointAt(0)<=256||Qs.has(r))){y.addCommands(t.getPathCommands(r,g,m+a-(f-d)/2,i.fontSize));let e={y:m-(f-d)/2+f/2,x:g+d/2};h&&this._italic(y,{x:e.x,y:m-(f-d)/2+a}),y.rotate(Math.PI/2,e)}else v===void 0?(y.addCommands(t.getPathCommands(r,g,_,i.fontSize)),h&&this._italic(y,n?{x:g+f/2,y:_}:void 0)):(y.addCommands(t.glyphs.get(v).getPathCommands(g,_,i.fontSize)),h&&this._italic(y,n?{x:g+d/2,y:m+l/(s+Math.abs(c))*f}:void 0));let b=i.fontWeight??400;return b in tc&&(b===700||b===`bold`)&&u!==`bold`&&y.bold(tc[b]*i.fontSize*.05),y.style=A({fill:i.color,fillRule:`nonzero`,stroke:i.textStrokeWidth?i.textStrokeColor:void 0,strokeWidth:i.textStrokeWidth?i.textStrokeWidth*i.fontSize*.03:void 0}),this.path=y,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,n){if(this.path.curves[0]?.curves.length)return this.path.getMinMax(e,t,n)}getGlyphBoundingBox(e){let t=this.getGlyphMinMax(void 0,void 0,e);if(!t)return;let{min:n,max:r}=t;return new W(n.x,n.y,r.x-n.x,r.y-n.y)}},rc=class{content;style;fill;outline;index;parent;inlineBox=new W;get computedContent(){let e=this.computedStyle;return e.textTransform===`uppercase`?this.content.toUpperCase():e.textTransform===`lowercase`?this.content.toLowerCase():this.content}constructor(e,t={},n,r,i,a){this.content=e,this.style=t,this.fill=n,this.outline=r,this.index=i,this.parent=a,this.update().initCharacters()}update(){this.computedStyle={...this.parent.computedStyle,...A(this.style)};let e=this.fill??this.parent.computedFill;this.computedFill=e?A(e):void 0;let t=this.outline??this.parent.computedOutline;return this.computedOutline=t?A(t):void 0,this}initCharacters(){let e=[],t=0;for(let n of this.computedContent)e.push(new nc(n,t++,this));return this.characters=e,this}},ic=class{style;index;parent;lineBox=new W;fragments=[];fill;outline;constructor(e,t,n){this.style=e,this.index=t,this.parent=n,this.update()}update(){this.computedStyle={...A(this.parent.computedStyle),...A(this.style)};let e=this.fill??this.parent.computedFill;this.computedFill=e?A(e):void 0;let t=this.outline??this.parent.computedOutline;return this.computedOutline=t?A(t):void 0,this}};function ac(e){return e}var oc;function sc(){if(oc?.isConnected)return oc;let e=document.createElement(`div`);return e.dataset.modernText=`measurer`,Object.assign(e.style,{position:`fixed`,left:`0`,top:`0`,visibility:`hidden`,pointerEvents:`none`}),document.body.appendChild(e),oc=e,e}var cc=class e{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`]);_styleCache=new WeakMap;_mountedDom;_mountedSignature;_toDomStyle(t){let n=this._styleCache.get(t);if(n)return n;let r={},{notZeroStyles:i,pxStyles:a}=e;for(let e in t){let n=t[e];i.has(e)&&n===0||(r[e]=typeof n==`number`&&a.has(e)?`${n}px`:n)}return this._styleCache.set(t,r),r}_resolveRootStyles(e){let t={...e},n=e.writingMode.includes(`horizontal`);switch(e.textAlign){case`start`:case`left`:t.justifyContent=`flex-start`;break;case`center`:t.justifyContent=`center`;break;case`end`:case`right`:t.justifyContent=`flex-end`;break}switch(e.verticalAlign){case`top`:t.alignItems=`flex-start`;break;case`middle`:t.alignItems=`center`;break;case`bottom`:t.alignItems=`flex-end`;break}let r=!!(t.justifyContent||t.alignItems);return{section:{...this._toDomStyle({...t,boxSizing:t.boxSizing??`border-box`,display:t.display??(r?`inline-flex`:void 0),width:t.width??`max-content`,height:t.height??`max-content`}),whiteSpace:`pre-wrap`,wordBreak:`break-all`},ul:{verticalAlign:`inherit`,listStyleType:`inherit`,padding:`0`,margin:`0`,width:r&&n?`100%`:void 0,height:r&&!n?`100%`:void 0}}}_applyRootStyle(e,t,n){let r=this._resolveRootStyles(n);e.removeAttribute(`style`),Object.assign(e.style,r.section),t.removeAttribute(`style`),Object.assign(t.style,r.ul)}_applyLiStyle(e,t){e.removeAttribute(`style`),e.style.verticalAlign=`inherit`,Object.assign(e.style,this._toDomStyle(t.style))}_applySpanStyle(e,t){e.removeAttribute(`style`),e.style.verticalAlign=`inherit`,Object.assign(e.style,this._toDomStyle(t.style))}_applyFragmentContent(e,t){let n=e.firstChild;n?n.data!==t.content&&(n.data=t.content):e.appendChild(document.createTextNode(t.content))}_hide(e){e.style.visibility=`hidden`}_signature(e){let t=`${e.length}`;for(let n=0;n<e.length;n++)t+=`:${e[n].fragments.length}`;return t}createDom(e,t){let n=document.createElement(`section`),r=document.createElement(`ul`);return this._applyRootStyle(n,r,t),e.forEach(e=>{let t=document.createElement(`li`);this._applyLiStyle(t,e),e.fragments.forEach(e=>{let n=document.createElement(`span`);this._applySpanStyle(n,e),this._applyFragmentContent(n,e),t.appendChild(n)}),r.appendChild(t)}),n.appendChild(r),n}_patchDom(e,t,n,r){let i=e.firstChild;this._applyRootStyle(e,i,n),r&&this._hide(e);let a=i.children;for(let e=0;e<t.length;e++){let n=a[e];this._applyLiStyle(n,t[e]);let r=t[e].fragments,i=n.children;for(let e=0;e<r.length;e++){let t=i[e];this._applySpanStyle(t,r[e]),this._applyFragmentContent(t,r[e])}}}measureDomText(e){let t=e.data??``,n=[];if(!t.length)return n;let r=document.createRange(),i=0;for(;i<t.length;){let a=t.codePointAt(i),o=i+(a>65535?2:1);r.setStart(e,i),r.setEnd(e,o);let s=r.getClientRects?.(),c;s&&s.length?(c=s[s.length-1],s.length>1&&c.width<2&&(c=s[s.length-2])):c=r.getBoundingClientRect(),c&&c.width+c.height!==0&&n.push({content:t.slice(i,o),top:c.top,left:c.left,width:c.width,height:c.height}),i=o}return n}measureDom(e){let t=[],n=[],r=[];return e.querySelectorAll(`li`).forEach((e,i)=>{let a=e.getBoundingClientRect();t.push({paragraphIndex:i,left:a.x,top:a.y,width:a.width,height:a.height}),e.querySelectorAll(`:scope > *`).forEach((e,t)=>{let a=e.getBoundingClientRect();n.push({paragraphIndex:i,fragmentIndex:t,left:a.x,top:a.y,width:a.width,height:a.height});let o=0,s=e=>{this.measureDomText(e).forEach(e=>{r.push({...e,newParagraphIndex:-1,paragraphIndex:i,fragmentIndex:t,characterIndex:o++,textWidth:-1,textHeight:-1})})};!e.children.length&&e.firstChild instanceof window.Text?s(e.firstChild):e.querySelectorAll(`:scope > *`).forEach(e=>{e.firstChild instanceof window.Text&&s(e.firstChild)})})}),{paragraphs:t,fragments:n,characters:r}}measureParagraphDom(e,t){let n=t.getBoundingClientRect(),r=this.measureDom(t);r.paragraphs.forEach(t=>{let r=e[t.paragraphIndex].lineBox;r.left=t.left-n.left,r.top=t.top-n.top,r.width=t.width,r.height=t.height}),r.fragments.forEach(t=>{let r=e[t.paragraphIndex].fragments[t.fragmentIndex].inlineBox;r.left=t.left-n.left,r.top=t.top-n.top,r.width=t.width,r.height=t.height});let i=[];return r.characters.forEach(t=>{let{paragraphIndex:r,fragmentIndex:a,characterIndex:o}=t,s=t.left-n.left,c=t.top-n.top;i.push({...t,newParagraphIndex:r,left:s,top:c});let{fontHeight:l,isVertical:u,inlineBox:d,lineBox:f}=e[r].fragments[a].characters[o];d.left=s,d.top=c,d.width=t.width,d.height=t.height,u?(f.left=s+(t.width-l)/2,f.top=c,f.width=l,f.height=t.height):(f.left=s,f.top=c+(t.height-l)/2,f.width=t.width,f.height=l)}),{paragraphs:e,boundingBox:new W(0,0,n.width,n.height)}}measure(e,t,n){return this.measureParagraphDom(e,n??this._mount(e,t))}_mount(e,t){let n=this._signature(e);if(this._mountedDom?.isConnected&&this._mountedSignature===n)return this._patchDom(this._mountedDom,e,t,!0),this._mountedDom;this._unmount();let r=this.createDom(e,t);return this._hide(r),sc().appendChild(r),this._mountedDom=r,this._mountedSignature=n,r}_unmount(){this._mountedDom?.parentNode?.removeChild(this._mountedDom),this._mountedDom=void 0,this._mountedSignature=void 0}dispose(){this._unmount()}};function lc(e,t,n){return e[`${t}${n}`]??e[t]??0}var uc=class{measure(e,t,n,r){let i=r??Xs;for(let t of e)for(let e of t.fragments)for(let t of e.characters)t.measureGlyph(i);return t.writingMode.includes(`vertical`)?this._measureVertical(e,t):this._measureHorizontal(e,t)}_rootPadding(e){return{top:lc(e,`padding`,`Top`),right:lc(e,`padding`,`Right`),bottom:lc(e,`padding`,`Bottom`),left:lc(e,`padding`,`Left`)}}_measureHorizontal(e,t){let n=this._rootPadding(t),r=typeof t.width==`number`,i=r?t.width-n.left-n.right:1/0,a=n.top,o=n.left;for(let t of e){let e=t.computedStyle,r=t.style,s=lc(r,`margin`,`Top`),c=lc(r,`margin`,`Bottom`),l=lc(r,`margin`,`Left`),u=lc(r,`margin`,`Right`),d=lc(r,`padding`,`Top`),f=lc(r,`padding`,`Bottom`),p=lc(r,`padding`,`Left`),m=lc(r,`padding`,`Right`),h=n.left+l+p,g=i===1/0?1/0:i-l-u-p-m;a+=s+d;let _=a,v=h,y=this._breakLines(t,g),b=e.textAlign,x=e.textIndent??0;for(let t=0;t<y.length;t++){let n=y[t],r=t===0?x:0,i=e.fontSize*e.lineHeight,o=0;for(let e of n)e.fontHeight>i&&(i=e.fontHeight),o+=this._advance(e);let s=h+r;if(g!==1/0){let e=g-r-o;b===`center`?s+=e/2:(b===`end`||b===`right`)&&(s+=e)}for(let e of n){let t=e.advanceWidth,n=e.advanceHeight,r=e.fontHeight;e.inlineBox.left=s,e.inlineBox.top=a+(i-n)/2,e.inlineBox.width=t,e.inlineBox.height=n,e.lineBox.left=s,e.lineBox.top=e.inlineBox.top+(n-r)/2,e.lineBox.width=t,e.lineBox.height=r,s+=this._advance(e)}s>v&&(v=s),a+=i}v>o&&(o=v);for(let e of t.fragments)this._unionInto(e.inlineBox,e.characters.map(e=>e.inlineBox));t.lineBox.left=h,t.lineBox.top=_,t.lineBox.width=g===1/0?v-h:g,t.lineBox.height=a-_,a+=f+c}let s=a+n.bottom,c=r?t.width:o+n.right,l=typeof t.height==`number`?t.height:s;if(typeof t.height==`number`){let n=l-s,r=t.verticalAlign,i=r===`middle`?n/2:r===`bottom`?n:0;i&&this._shiftAll(e,i)}return{paragraphs:e,boundingBox:new W(0,0,c,l)}}_measureVertical(e,t){let n=this._rootPadding(t),r=typeof t.height==`number`,i=r?t.height-n.top-n.bottom:1/0,a=[];for(let t of e){let e=t.computedStyle.fontSize*t.computedStyle.lineHeight;for(let n of this._breakLines(t,i)){let t=e;for(let e of n)e.fontHeight>t&&(t=e.fontHeight);a.push({chars:n,thickness:t})}}let o=a.reduce((e,t)=>e+t.thickness,0),s=typeof t.width==`number`,c=s?Math.max(t.width-n.left-n.right,o):o,l=n.left+c,u=n.top;for(let e of a){l-=e.thickness;let t=l,r=n.top;for(let n of e.chars){let i=n.advanceWidth,a=n.advanceHeight,o=n.fontHeight;n.inlineBox.top=r,n.inlineBox.height=i,n.inlineBox.width=a,n.inlineBox.left=t+(e.thickness-a)/2,n.lineBox.left=n.inlineBox.left+(a-o)/2,n.lineBox.top=r,n.lineBox.width=o,n.lineBox.height=i,r+=this._advance(n)}r>u&&(u=r)}for(let t of e){for(let e of t.fragments)this._unionInto(e.inlineBox,e.characters.map(e=>e.inlineBox));this._unionInto(t.lineBox,t.fragments.flatMap(e=>e.characters.map(e=>e.inlineBox)))}return{paragraphs:e,boundingBox:new W(0,0,s?t.width:c+n.left+n.right,r?t.height:u+n.bottom)}}_advance(e){return e.advanceWidth+(e.computedStyle.letterSpacing??0)}_breakLines(e,t){let n=[],r=[],i=0,a=()=>{n.push(r),r=[],i=0};for(let n of e.fragments)for(let e of n.characters){if(e.content===`
34
34
  `||e.content===`\r`){a();continue}t!==1/0&&r.length>0&&i+e.advanceWidth>t&&a(),r.push(e),i+=this._advance(e)}return a(),n}_unionInto(e,t){let n=t.filter(e=>e.width!==0||e.height!==0);if(!n.length)return;let r=W.from(...n);e.left=r.left,e.top=r.top,e.width=r.width,e.height=r.height}_shiftAll(e,t){for(let n of e){n.lineBox.top+=t;for(let e of n.fragments){e.inlineBox.top+=t;for(let n of e.characters)n.inlineBox.top+=t,n.lineBox.top+=t}}}dispose(){}};function dc(){let e=new Nr,t=Pr(),n=Fr(t);return{name:`background`,pathSet:e,context:{loader:t,parser:n},load:async e=>{let{backgroundImage:n}=e.computedStyle;n&&t.needsLoad(n)&&await t.load(n)},update:t=>{e.paths.length=0;let{computedStyle:r,lineBox:i,isVertical:a}=t,{backgroundImage:o,backgroundSize:s,backgroundColormap:c}=r;if(O(o))return;let{pathSet:l}=n.parse(o),u=l.getBoundingBox(!0)??new W,d,f,p,m;a?{x:f,y:d,width:m,height:p}=i:{x:d,y:f,width:p,height:m}=i;let h=zr(c??`none`),g=l.paths.map(e=>{let t=e.clone();return t.style.fill&&t.style.fill in h&&(t.style.fill=h[t.style.fill]),t.style.stroke&&t.style.stroke in h&&(t.style.stroke=h[t.style.stroke]),t}),_,v;if(s===`rigid`){_=t.fontSize*5/u.width,v=_;let e=new U;e.x=u.width-p/_,e.y=u.height-m/v,g.forEach(t=>{t.applyTransform(t=>{let n=t.x>u.left+u.width/2,r=t.y>u.top+u.height/2;n&&(t.x-=e.x),r&&(t.y-=e.y)})})}else _=p/u.width,v=m/u.height;let y=new Mn;y.translate(-u.x,-u.y),y.scale(_,v),a&&(y.translate(-p/2,-m/2),y.rotate(Math.PI/2),y.translate(m/2,p/2)),y.translate(d,f),g.forEach(e=>{e.applyTransform(y)}),e.paths.push(...g)},renderOrder:-2,render:t=>{let{text:n,context:r}=t,{lineBox:i,computedStyle:a}=n;O(a.backgroundColor)||(r.fillStyle=a.backgroundColor,r.fillRect(...i.array)),e.paths.forEach(e=>{if(t.drawPath(e),n.debug){let t=new Nr([e]).getBoundingBox();t&&r.strokeRect(t.x,t.y,t.width,t.height)}}),n.paragraphs.forEach(e=>{let{lineBox:t,style:n}=e;O(n.backgroundColor)||(r.fillStyle=n.backgroundColor,r.fillRect(...t.array)),e.fragments.forEach(e=>{let{inlineBox:t,style:n}=e;O(n.backgroundColor)||(r.fillStyle=n.backgroundColor,r.fillRect(...t.array))})})}}}function fc(e,t){let{x:n,y:r}=t;if(e instanceof Dr){let{p1:t,cp:i,p2:a}=e,o=n!==void 0&&Math.abs(Math.sign(t.x-n)+Math.sign(i.x-n)+Math.sign(a.x-n))===1,s=r!==void 0&&Math.abs(Math.sign(t.y-r)+Math.sign(i.y-r)+Math.sign(a.y-r))===1,c,l,u,d;if(o&&(c=t.x-2*i.x+a.x,l=2*(-t.x+i.x),u=t.x-n),s&&(c=t.y-2*i.y+a.y,l=2*(-t.y+i.y),u=t.y-r),(o||s)&&(d=l*l-4*c*u,d>0)){let e=Math.sqrt(d),n=[(-l+e)/2/c,(-l-e)/2/c].find(e=>e>0&&e<1);if(n){let e=U.lerp(t,i,n),r=U.lerp(i,a,n),o=U.lerp(e,r,n);return[new Dr(t,e,o),new Dr(o.clone(),r,a)]}}}else if(e instanceof wr){let{p1:t,cp1:i,cp2:a,p2:o}=e,{min:s,max:c}=e.getMinMax(),l=n!==void 0&&(s.x-n)*(c.x-n)<0,u=r!==void 0&&(s.y-r)*(c.y-r)<0;if(l||u){n=.5*t.x+.5*i.x,r=.5*t.y+.5*i.y;let e=new U(n,r);n=.25*t.x+.5*i.x+.25*a.x,r=.25*t.y+.5*i.y+.25*a.y;let s=new U(n,r);n=.125*t.x+.375*i.x+.375*a.x+.125*o.x,r=.125*t.y+.375*i.y+.375*a.y+.125*o.y;let c=new U(n,r);n=.25*i.x+.5*a.x+.25*o.x,r=.25*i.y+.5*a.y+.25*o.y;let l=new U(n,r);n=.5*a.x+.5*o.x,r=.5*a.y+.5*o.y;let u=new U(n,r);return[new wr(t,e,s,c),new wr(c.clone(),l,u,o)]}}else if(e instanceof Sr){let{p1:t,p2:i}=e,a=n!==void 0&&(t.x-n)*(i.x-n)<0,o=r!==void 0&&(t.y-r)*(i.y-r)<0;if(a&&(r=t.y+(i.y-t.y)/(i.x-t.x)*(n-t.x)),o&&(n=t.x+(i.x-t.x)/(i.y-t.y)*(r-t.y)),a||o)return[new Sr(t,new U(n,r)),new Sr(new U(n,r),i)]}return[e]}var pc=class{get boundingBox(){return this.text.lineBox}get paragraphs(){return this.text.paragraphs}get isHorizontal(){return this.text.computedStyle.writingMode.startsWith(`horizontal`)}get baseWidth(){return this.isHorizontal?this.boundingBox.width:this.boundingBox.height}get baseHeight(){return this.isHorizontal?this.boundingBox.height:this.boundingBox.width}get characters(){return this.paragraphs.flatMap(e=>e.fragments.flatMap(e=>e.characters))}constructor({text:e,intensities:t=[],maxFontSize:n=100}){this.text=e,this.intensities=t.map(e=>e/100),this.lineHeight=n}_breakLine(){let e=!this.isHorizontal,{left:t,top:n,bottom:r,right:i}=this.boundingBox,a=.5*(t+i),o=.5*(n+r);this.characters.forEach(t=>{t.glyphBox&&t.path.curves.forEach(t=>{t.curves=t.curves.flatMap(t=>fc(t,e?{y:o}:{x:a}))})})}_makeTheJointSmooth(){this.characters.forEach(e=>{e.glyphBox&&e.path.getFlatCurves().forEach(e=>{if(e instanceof Dr&&e.isFromLine){let{p1:t,cp:n,p2:r}=e;n.x=2*n.x-.5*(t.x+r.x),n.y=2*n.y-.5*(t.y+r.y)}})})}_lineToQuadraticBezier(){this.characters.forEach(e=>{e.glyphBox&&e.path.curves.forEach(e=>{e.curves=e.curves.map(e=>{if(e instanceof Sr&&e.getLength()>5){let{p1:t,p2:n}=e,r=new Dr(t.clone(),new U(.5*(t.x+n.x),.5*(t.y+n.y)),n.clone());return r.isFromLine=!0,r}return e})})})}_transform(e,t,n){let r=this.text.plugins.get(`highlight`),i=n?.(),a=0,o=this.characters.filter(e=>e.glyphBox).length;this.paragraphs.forEach((n,s)=>{n.fragments.forEach((n,c)=>{n.characters.forEach((n,l)=>{if(!n.glyphBox)return;let u=t?.({paragraphIndex:s,fragmentIndex:c,characterIndex:l,character:n},i);if(n.path.getControlPointRefs().forEach(t=>{let[n,r]=e(t,u);t.set(n,r)}),t&&r?.pathSet?.paths){let t=r.pathSet.paths.length/o,n=a*t;for(let i=0;i<t;i++)r?.pathSet?.paths[n+i]?.getControlPointRefs().forEach(t=>{let[n,r]=e(t,u);t.set(n,r)});a++}})})}),this.paragraphs.forEach(e=>{e.fragments.forEach(e=>{e.characters.forEach(e=>{e.glyphBox=e.getGlyphBoundingBox(),e.glyphBox&&(e.inlineBox=e.glyphBox)})})}),t||r?.pathSet?.paths?.forEach(t=>{t.getControlPointRefs().forEach(t=>{let[n,r]=e(t);t.set(n,r)})})}},mc=class extends pc{preset;constructor(e,t){super(e),this.preset=t}deform(){Math.hypot(...this.intensities)&&(this._lineToQuadraticBezier(),this._bend(),this._makeTheJointSmooth())}_bend(){let{boundingBox:e,baseWidth:t,baseHeight:n,preset:r}=this,i=this.lineHeight*2/Math.sin(this.intensities[0]*Math.PI*.5),a=r.vertical===void 0||r.vertical===`auto`?!this.isHorizontal:r.vertical,{left:o,top:s,width:c,height:l}=e,u=(a?l:c)/2/i,d={x:o+c/2,y:s+l/2},f,p={x:d.x,y:d.y};a?(f=0,p.x-=n/2/Math.tan(u)+Math.sign(u)*c/2):(f=1.5*Math.PI,p.y+=t/2/Math.tan(u)+Math.sign(u)*l/2);let m=r.transform({lineHeight:i,size:u,center:d,centerDist:p,centerDistAngle:f,width:c,height:l,isHorizontal:this.isHorizontal});this._transform(m)}},hc=class{arcLengthDivisions=200;_cacheArcLengths;_needsUpdate=!1;getPointAt(e,t=new U){return this.getPoint(this.getUToTMapping(e),t)}getLength(){let e=this.getLengths();return e[e.length-1]}getLengths(e=this.arcLengthDivisions){if(this._cacheArcLengths&&this._cacheArcLengths.length===e+1&&!this._needsUpdate)return this._cacheArcLengths;this._needsUpdate=!1;let t=[0],n=this.getPoint(0),r=0;for(let i=1;i<=e;i++){let a=this.getPoint(i/e);r+=a.distanceTo(n),t.push(r),n=a}return this._cacheArcLengths=t,t}getUToTMapping(e,t){let n=this.getLengths(),r=n.length,i=t===void 0?e*n[r-1]:t,a=0,o=r-1,s=0;for(;a<=o;){s=Math.floor(a+(o-a)/2);let e=n[s]-i;if(e<0)a=s+1;else if(e>0)o=s-1;else{o=s;break}}if(s=o,n[s]===i)return s/(r-1);let c=n[s],l=n[s+1]-c,u=(i-c)/l;return(s+u)/(r-1)}getTangent(e,t=new U){let n=1e-4,r=Math.max(0,e-n),i=Math.min(1,e+n);return t.copyFrom(this.getPoint(i).sub(this.getPoint(r)).normalize())}getNormal(e,t=new U){return this.getTangent(e,t),t.set(-t.y,t.x).normalize()}},gc=class extends hc{curveT=0;getPoint(e,t=new U){return this.getCurve(e).getPoint(this.curveT,t)}getPointAt(e,t=new U){return this.getPoint(e,t)}getTangent(e,t=new U){return this.getCurve(e).getTangent(this.curveT,t)}getNormal(e,t=new U){return this.getCurve(e).getNormal(this.curveT,t)}},_c=class extends hc{start;end;constructor(e,t){super(),this.start=e,this.end=t}getPoint(e,t=new U){return e===1?t.copyFrom(this.end):t.copyFrom(this.end).sub(this.start).scale(e).add(this.start),t}getPointAt(e,t=new U){return this.getPoint(e,t)}getTangent(e,t=new U){return t.subVectors(this.end,this.start).normalize()}},vc=class extends hc{center;radius;start;end;constructor(e,t,n=0,r=Math.PI*2){super(),this.center=e,this.radius=t,this.start=n,this.end=r}getPoint(e,t=new U){return t.copyFrom(this.center).add(this.getNormal(e).scale(this.radius))}getTangent(e,t=new U){let{x:n,y:r}=this.getNormal(e);return t.set(-r,n)}getNormal(e,t=new U){let{start:n,end:r}=this,i=e*(r-n)+n-.5*Math.PI;return t.set(Math.cos(i),Math.sin(i))}},yc=class extends hc{center;radiusX;radiusY;rotation;startAngle;endAngle;clockwise;constructor(e=new U,t=1,n=1,r=0,i=0,a=Math.PI*2,o=!1){super(),this.center=e,this.radiusX=t,this.radiusY=n,this.rotation=r,this.startAngle=i,this.endAngle=a,this.clockwise=o}getPoint(e,t=new U){let n=Math.PI*2,r=this.endAngle-this.startAngle,i=Math.abs(r)<2**-52;for(;r<0;)r+=n;for(;r>n;)r-=n;r<2**-52&&(r=i?0:n),this.clockwise&&!i&&(r=r===n?-n:r-n);let a=this.startAngle+e*r,o=this.center.x+this.radiusX*Math.cos(a),s=this.center.y+this.radiusY*Math.sin(a);if(this.rotation!==0){let e=Math.cos(this.rotation),t=Math.sin(this.rotation),n=o-this.center.x,r=s-this.center.y;o=n*e-r*t+this.center.x,s=n*t+r*e+this.center.y}return t.set(o,s)}},bc=class extends gc{center;size;start;end;curves=[];constructor(e,t,n=0,r=1){super(),this.center=e,this.size=t,this.start=n,this.end=r,this.update()}update(){let{x:e,y:t}=this.center,n=new U(e+.5*this.size,t-.5*this.size),r=new U(e-.5*this.size,t-.5*this.size),i=new U(e,t+.5*this.size),a=new vc(n,Math.SQRT1_2*this.size,-.25*Math.PI,.75*Math.PI),o=new vc(r,Math.SQRT1_2*this.size,-.75*Math.PI,.25*Math.PI),s=new vc(i,.5*Math.SQRT1_2*this.size,.75*Math.PI,1.25*Math.PI),c=new U(e,t+this.size),l=new U(e+this.size,t),u=U.lerp(l,c,.75),d=new U(e-this.size,t),f=U.lerp(d,c,.75),p=new _c(l,u),m=new _c(f,d);return this.curves=[a,p,s,m,o],this}getCurve(e){let t=(e*(this.end-this.start)+this.start)%1;t<0&&(t+=1),t*=9*Math.PI/8+1.5;let n=.5*Math.PI,r;return t<n?(r=0,this.curveT=t/n):t<n+.75?(r=1,this.curveT=(t-n)/.75):t<5*Math.PI/8+.75?(r=2,this.curveT=(t-n-.75)/(Math.PI/8)):t<5*Math.PI/8+1.5?(r=3,this.curveT=(t-5*Math.PI/8-.75)/.75):(r=4,this.curveT=(t-5*Math.PI/8-1.5)/n),this.curves[r]}},xc=class extends gc{center;radius;number;start;end;curves=[];points=[];constructor(e,t=0,n=0,r=0,i=1){super(),this.center=e,this.radius=t,this.number=n,this.start=r,this.end=i,this.update()}update(){for(let e=0;e<this.number;e++){let t=e*2*Math.PI/this.number;t-=.5*Math.PI,this.points.push(new U(this.radius*Math.cos(t),this.radius*Math.sin(t)).add(this.center))}for(let e=0;e<this.number;e++)this.curves.push(new _c(this.points[e],this.points[(e+1)%this.number]));return this}getCurve(e){let t=(e*(this.end-this.start)+this.start)%1;t<0&&(t+=1);let n=t*this.number,r=Math.floor(n);return this.curveT=n-r,this.curves[r]}},Sc=class extends gc{center;rx;aspectRatio;start;end;curves=[];constructor(e,t,n=1,r=0,i=1){super(),this.center=e,this.rx=t,this.aspectRatio=n,this.start=r,this.end=i,this.update()}update(){let{x:e,y:t}=this.center,n=this.rx,r=this.rx/this.aspectRatio,i=[new U(e-n,t-r),new U(e+n,t-r),new U(e+n,t+r),new U(e-n,t+r)];for(let e=0;e<4;e++)this.curves.push(new _c(i[e].clone(),i[(e+1)%4].clone()));return this}getCurve(e){let t=(e*(this.end-this.start)+this.start)%1;t<0&&(t+=1),t*=(1+this.aspectRatio)*2;let n;return t<this.aspectRatio?(n=0,this.curveT=t/this.aspectRatio):t<this.aspectRatio+1?(n=1,this.curveT=t-this.aspectRatio):t<2*this.aspectRatio+1?(n=2,this.curveT=(t-this.aspectRatio-1)/this.aspectRatio):(n=3,this.curveT=t-2*this.aspectRatio-1),this.curves[n]}},Cc=class extends pc{preset;constructor(e,t){super(e),this.preset=t}deform(){if(!Math.hypot(...this.intensities))return;let{preset:e}=this;e.breakLine&&this._breakLine(),e.lineToQuad&&this._lineToQuadraticBezier();let[t,n]=this.intensities,r=this._createFFDControlPoints(e.hBlocks,e.vBlocks);e.build(r,{a:t,b:n,baseWidth:this.baseWidth,baseHeight:this.baseHeight,lineHeight:this.lineHeight,adjust:(e,t,n)=>this._adjustControlPoints(e,{x:t,y:n})}),e.bezier?(this._calculateForBezierFFD(r,e.hBlocks,e.vBlocks),this._makeTheJointSmooth()):this._calculateForLinearFFD(r,e.hBlocks,e.vBlocks)}_calculateForFFD(e,t,n,r){let{left:i,top:a,right:o,width:s,height:c}=this.boundingBox;this._transform(this.isHorizontal?o=>{let l=(o.x-i)/s,u=(o.y-a)/c,[d,f]=[0,0];for(let i=0;i<n+2;i++){let a=e(n,i,l);for(let n=0;n<r+2;n++){let o=e(r,n,u),s=t[i*(r+2)+n];d+=a*o*s.x,f+=a*o*s.y}}return[d,f]}:i=>{let l=(o-i.x)/s,u=(i.y-a)/c,[d,f]=[0,0];for(let i=0;i<n+2;i++){let a=e(n,i,u);for(let n=0;n<r+2;n++){let o=e(r,n,l),s=t[i*(r+2)+n];d+=a*o*s.x,f+=a*o*s.y}}return[d,f]})}_createFFDControlPoints(e,t){let{left:n,top:r,right:i,width:a,height:o}=this.boundingBox,s=[];if(this.isHorizontal){let i=a/(e+1),c=o/(t+1);for(let a=0;a<e+2;a++)for(let e=0;e<t+2;e++)s.push(new U(n+a*i,r+e*c))}else{let n=a/(t+1),c=o/(e+1);for(let a=0;a<e+2;a++)for(let e=0;e<t+2;e++)s.push(new U(i-e*n,r+a*c))}return s}_adjustControlPoints(e,t){this.isHorizontal?(e.x+=t.x,e.y+=t.y):(e.x-=t.y,e.y+=t.x)}_factorialForFFD(e){let t=1;for(let n=2;n<=e;n++)t*=n;return t}_combineForFFD(e,t){return this._factorialForFFD(e)/this._factorialForFFD(e-t)/this._factorialForFFD(t)}_calculateForBezierFFD(e,t,n){this._calculateForFFD((e,t,n)=>this._combineForFFD(e+1,t)*(1-n)**(e+1-t)*n**t,e,t,n)}_linearBasis(e,t,n){let r=t<n*e?t+1-n*e:n*e-t+1;return Math.max(0,r)}_calculateForLinearFFD(e,t,n){this._calculateForFFD((e,t,n)=>this._linearBasis(e+1,t,n),e,t,n)}},wc=class extends pc{preset;constructor(e,t){super(e),this.preset=t}_context(){return{intensities:this.intensities,baseWidth:this.baseWidth,lineHeight:this.lineHeight,isHorizontal:this.isHorizontal,boundingBox:this.boundingBox}}deform(){if(!Math.hypot(...this.intensities))return;let{preset:e}=this,t=this._context();if(e.engine===`offset`)this._transform(e.point,e.perChar?n=>e.perChar(t,n):void 0);else{let n=e.followTangent??!0,{funcPerChar:r,funcPerPoint:i}=this._getPerCharAndPointFunc(n);this._transform(i,r,()=>{let{width:n,height:r,left:i,top:a}=this.boundingBox;return{width:n,height:r,left:i,top:a,curve:e.makeCurve(t),isHorizontal:this.isHorizontal,needExpandAlongNormal:e.expandAlongNormal??!1}})}}_getPerCharAndPointFunc(e=!1){let t,n;return e?(n=this._resetPointPos,t=this._calculateNewCenter):(n=this._resetPointPosWithoutRotate,t=this._calculateNewCenterWithoutRotate),{funcPerPoint:n,funcPerChar:t}}_calculateNewCenter({character:e},t){let{width:n,height:r,left:i,top:a,curve:o,isHorizontal:s,needExpandAlongNormal:c=!1}=t,{center:l,centerDiviation:u}=e,d=s?(l.x-i)/n:(l.y-a)/r,f=s?new U(0,l.y-a):new U(l.x-i,0);if(c){let e=o.getNormal(d);f.x+=e.x*-u,f.y+=e.y*-u}let p=o.getPointAt(d).add(f),m=o.getTangent(d);return{cos:m.x,sin:m.y,newCenter:p,center:l}}_calculateNewCenterWithoutRotate({character:e},t){let{width:n,height:r,left:i,top:a,curve:o,isHorizontal:s}=t,{center:c}=e,l=s?(c.x-i)/n:(c.y-a)/r,u=s?new U(0,c.y-a):new U(c.x-i,0);return{newCenter:o.getPointAt(l).add(u),center:c}}_resetPointPos(e,t){let{cos:n=1,sin:r=0,center:i,newCenter:a}=t,o=e.x-i.x,s=e.y-i.y;return[a.x+o*n-s*r,a.y+o*r+s*n]}_resetPointPosWithoutRotate(e,t){let{center:n,newCenter:r}=t;return[e.x-n.x+r.x,e.y-n.y+r.y]}},Tc=new Map;function Ec(e,t){Tc.set(e,t)}function Dc(e){Tc.delete(e)}function Oc(){return[...Tc.keys()]}function kc(){return ac({name:`deformation`,updateOrder:2,update:e=>{let t=e.deformation,n=t?.type;if(O(n)||!n)return;let r=Tc.get(n);if(!r)return;let i={text:e,intensities:t.intensities??r.defaultIntensities,maxFontSize:t.maxFontSize},a;switch(r.engine){case`ffd`:a=new Cc(i,r);break;case`bend`:a=new mc(i,r);break;case`curve`:case`offset`:a=new wc(i,r);break}a.deform();let o=e.getGlyphBox();e.rawGlyphBox=o,e.glyphBox=o,e.lineBox=o}})}function Ac(e){let{highlight:t,highlightImage:n,highlightReferImage:r,highlightColormap:i,highlightLine:a,highlightSize:o,highlightThickness:s}=e;return{image:t?.image??n??`none`,referImage:t?.referImage??r??`none`,colormap:t?.colormap??i??`none`,line:t?.line??a??`none`,size:t?.size??o??`cover`,thickness:t?.thickness??s??`100%`}}function jc(){let e=new Nr,t=[],n=Pr(),r=Fr(n);return ac({name:`highlight`,pathSet:e,context:{clipRects:t,loader:n,parser:r},load:async e=>{let t=new Set;e.forEachCharacter(e=>{let{computedStyle:r}=e,{image:i,referImage:a}=Ac(r);i&&n.needsLoad(i)&&t.add(i),a&&n.needsLoad(a)&&t.add(a)}),await Promise.all(Array.from(t).map(e=>n.load(e)))},update:n=>{t.length=0,e.paths.length=0;let i=[],a,o;n.forEachCharacter(e=>{let{computedStyle:t}=e,n=Ac(t),{image:r,colormap:s,line:c,size:l,thickness:u}=n;if(O(r))a?.length&&(a=[],i.push(a));else{let{inlineBox:n,isVertical:d}=e,{fontSize:f}=t;(!o||Vr(o.image,r)&&Vr(o.colormap,s)&&Vr(o.line,c)&&Vr(o.size,l)&&Vr(o.thickness,u))&&a?.length&&(d?a[0].inlineBox.left===n.left:a[0].inlineBox.top===n.top)&&a[0].fontSize===f?a.push(e):(a=[],a.push(e),i.push(a))}o=n}),i=i.filter(e=>e.length);for(let n=0;n<i.length;n++){let a=i[n],o=a[0],s=W.from(...a.map(e=>e.compatibleGlyphBox));if(!s.height||!s.width)continue;let{computedStyle:c,isVertical:l,inlineBox:u,compatibleGlyphBox:d,strikeoutPosition:f,underlinePosition:p}=o,{fontSize:m}=c,{image:h,referImage:g,colormap:_,line:v,size:y,thickness:b}=Ac(c),x=Rr(b,{fontSize:m,total:s.width})/s.width,S=zr(_),{pathSet:C,dom:w}=r.parse(h),T=C.getBoundingBox(!0)??new W,E=m/T.width*2,D=new W().copy(s);l&&(D.width=s.height,D.height=s.width,D.left=s.left+s.width);let k=Math.floor(D.width),A=k;y!==`cover`&&(A=Rr(y,{fontSize:m,total:s.width})||k,D.width=A);let j=!O(g)&&O(v);if(j)T.copy(r.parse(g).pathSet.getBoundingBox(!0)??new W);else{let e;if(O(v))if(T.width/T.height>4){e=`underline`;let t=w.getAttribute(`viewBox`);if(t){let[n,r,i,a]=t.split(` `).map(e=>Number(e)),o=r+a/2;e=T.y<o&&T.y+T.height>o?`line-through`:T.y+T.height<o?`overline`:`underline`}}else e=`outline`;else e=v;switch(e){case`outline`:{let e=D.width*.2,t=D.height*.2;l?(D.x-=t/2,D.y-=e/2,D.x-=D.height):(D.x-=e/2,D.y-=t/2),D.width+=e,D.height+=t;break}case`overline`:D.height=T.height*E,l?D.x=u.left+u.width:D.y=u.top;break;case`line-through`:D.height=T.height*E,l?D.x=u.left+u.width-f+D.height/2:D.y=u.top+f-D.height/2;break;case`underline`:D.height=T.height*E,l?D.x=d.left+d.width-p:D.y=u.top+p;break}}let M=new Mn;if(M.translate(-T.x,-T.y),M.scale(D.width/T.width,D.height/T.height),l){let e=D.width/2,t=D.height/2;j||M.translate(-e,-t),M.rotate(Math.PI/2),j||M.translate(t,e)}M.translate(D.x,D.y);for(let n=0;n<Math.ceil(k/A);n++){let r=M.clone();l?r.translate(0,n*D.width):r.translate(n*D.width,0),C.paths.forEach(n=>{let i=n.clone().applyTransform(r);i.style.strokeWidth&&(i.style.strokeWidth*=E*x),i.style.strokeMiterlimit&&(i.style.strokeMiterlimit*=E),i.style.strokeDashoffset&&(i.style.strokeDashoffset*=E),i.style.strokeDasharray&&(i.style.strokeDasharray=i.style.strokeDasharray.map(e=>e*E)),i.style.fill&&i.style.fill in S&&(i.style.fill=S[i.style.fill]),i.style.stroke&&i.style.stroke in S&&(i.style.stroke=S[i.style.stroke]),e.paths.push(i),k!==A&&(l?t[e.paths.length-1]=new W(s.left-s.width*2,s.top,s.width*4,s.height):t[e.paths.length-1]=new W(s.left,s.top-s.height*2,s.width,s.height*4))})}}},renderOrder:-1,getBoundingBox:()=>{let n=[];return e.paths.forEach((e,r)=>{let i=t[r],a=e.getBoundingBox();if(i){let e=Math.max(a.x,i.x),t=Math.max(a.y,i.y),n=Math.min(a.right,i.right),r=Math.min(a.bottom,i.bottom);a=new W(e,t,n-e,r-t)}n.push(a)}),n.length?W.from(...n):void 0},render:n=>{let{text:r,context:i}=n;e.paths.forEach((e,a)=>{if(n.drawPath(e,{clipRect:t[a]}),r.debug){let t=new Nr([e]).getBoundingBox();t&&i.strokeRect(t.x,t.y,t.width,t.height)}})}})}function Mc(e,t){return`<svg width="${e*2}" height="${e*2}" xmlns="http://www.w3.org/2000/svg">
35
35
  <circle cx="${e}" cy="${e}" r="${e}" fill="${t}" />
36
- </svg>`}function Nc(){let e=new Nr;return ac({name:`listStyle`,pathSet:e,update:t=>{e.paths.length=0;let{paragraphs:n,isVertical:r,fontSize:i}=t,a=i*.45;n.forEach(t=>{let{computedStyle:n}=t,{color:o,listStyleImage:s,listStyleColormap:c,listStyleSize:l,listStyleType:u}=n,d=zr(c),f=l,p;if(!O(s))p=s;else if(!O(u)){let e=i*.38/2;switch(f=f===`cover`?e*2:f,u){case`disc`:p=Mc(e,String(o));break}}if(!p)return;let m=lr(p),h=m.getBoundingBox()??new W,g=t.fragments[0]?.characters[0];if(!g)return;let{inlineBox:_}=g,v=f===`cover`?1:Rr(f,{total:i,fontSize:i})/i,y=new Mn;if(r){let e=i/h.height*v;y.translate(-h.left,-h.top).rotate(-Math.PI/2).scale(e,e).translate(_.left+(_.width-h.height*e)/2,_.top-a)}else{let e=i/h.height*v;y.translate(-h.left,-h.top).scale(e,e).translate(_.left-h.width*e-a,_.top+(_.height-h.height*e)/2)}e.paths.push(...m.paths.map(e=>{let t=e.clone();return t.applyTransform(y),t.style.fill&&t.style.fill in d&&(t.style.fill=d[t.style.fill]),t.style.stroke&&t.style.stroke in d&&(t.style.stroke=d[t.style.stroke]),t}))})}})}function Pc(){return{name:`outline`}}function Fc(){let e=new Nr;return ac({name:`render`,pathSet:e,update:t=>{e.paths.length=0;let{paragraphs:n}=t;n.forEach(t=>{t.fragments.forEach(t=>{t.characters.forEach(t=>{e.paths.push(t.path)})})})},getBoundingBox:e=>{let{characters:t,computedEffects:n,fontSize:r}=e,i=[];return n.forEach(n=>{let a=Ir(e,n);t.forEach(e=>{if(!e.glyphBox)return;let t=e.glyphBox.clone(),o=a.apply({x:t.left,y:t.top}),s=a.apply({x:t.right,y:t.top}),c=a.apply({x:t.right,y:t.bottom}),l=a.apply({x:t.left,y:t.bottom}),u=Math.min(o.x,s.x,c.x,l.x),d=Math.min(o.y,s.y,c.y,l.y),f=Math.max(o.x,s.x,c.x,l.x),p=Math.max(o.y,s.y,c.y,l.y);if(t.left=u,t.top=d,t.width=f-u,t.height=p-d,n.shadow?.enabled){let e=(n.shadow.offsetX??0)*r,i=(n.shadow.offsetY??0)*r,a=(n.shadow.blur??0)*r,o=t.left+Math.min(0,e-a),s=t.top+Math.min(0,i-a),c=t.left+t.width+Math.max(0,e+a),l=t.top+t.height+Math.max(0,i+a);t.left=o,t.top=s,t.width=c-o,t.height=l-s}if(n.outline?.enabled){let e=Math.max(.1,n.outline.width??0);t.left-=e,t.top-=e,t.width+=e*2,t.height+=e*2}i.push(t)})}),i.length?W.from(...i):void 0},render:e=>{let{text:t,context:n}=e,{paragraphs:r,glyphBox:i,computedEffects:a}=t;r.length&&(a.length?a.forEach(r=>{if(e.uploadColor(i,r),n.save(),e.transformEffect(r),r.shadow?.enabled){let n={...r,shadow:{...r.shadow,enabled:!1}};e.drawWithShadow(r.shadow,()=>{t.forEachCharacter(t=>{e.drawCharacter(t,n)})})}else t.forEachCharacter(t=>{e.drawCharacter(t,r)});n.restore()}):r.forEach(t=>{t.fragments.forEach(t=>{t.characters.forEach(t=>{e.drawCharacter(t)})})}),t.debug&&r.forEach(e=>{n.strokeRect(e.lineBox.x,e.lineBox.y,e.lineBox.width,e.lineBox.height)}))}})}function Ic(){let e=new Nr;return ac({name:`textDecoration`,pathSet:e,update:t=>{e.paths.length=0;let n=[],r,i;t.forEachCharacter(e=>{let{computedStyle:t,isVertical:a,inlineBox:o,underlinePosition:s,underlineThickness:c,strikeoutPosition:l,strikeoutSize:u}=e,{color:d,textDecoration:f,writingMode:p}=t;if(O(f))i=void 0;else{let m=!1;if(i?.textDecoration===f&&i?.writingMode===p&&i?.color===d&&(a?r[0].inlineBox.left===o.left:r[0].inlineBox.top===o.top))switch(f){case`underline`:r[0].underlinePosition===s&&r[0].underlineThickness===c&&(m=!0);break;case`line-through`:r[0].strikeoutPosition===l&&r[0].strikeoutSize===u&&(m=!0);break}m?r.push(e):(r=[],r.push(e),n.push(r)),i=t}}),n.forEach(t=>{let{computedStyle:n,isVertical:r,underlinePosition:i,underlineThickness:a,strikeoutPosition:o,strikeoutSize:s}=t[0],{color:c,textDecoration:l}=n,{left:u,top:d,width:f,height:p}=W.from(...t.map(e=>e.inlineBox)),m=r?u+f:d,h=r?-1:1,g=0;switch(l){case`overline`:g=a*2;break;case`underline`:m+=h*i,g=a*2;break;case`line-through`:m+=h*o,g=s*2;break}m-=g;let _;_=r?new Mr([{type:`M`,x:m,y:d},{type:`L`,x:m,y:d+p},{type:`L`,x:m+g,y:d+p},{type:`L`,x:m+g,y:d},{type:`Z`}],{fill:c}):new Mr([{type:`M`,x:u,y:m},{type:`L`,x:u+f,y:m},{type:`L`,x:u+f,y:m+g},{type:`L`,x:u,y:m+g},{type:`Z`}],{fill:c}),e.paths.push(_)})},render:t=>{let{text:n,context:r}=t,{computedEffects:i}=n;i.length?i.forEach(n=>{r.save(),t.transformEffect(n),e.paths.forEach(e=>{t.drawPath(e,t.effectToPathStyle(n))}),r.restore()}):e.paths.forEach(e=>{t.drawPath(e)})}})}function Lc(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function Rc(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var zc,Bc=et(),Vc=class extends ae{needsUpdate=!0;computedStyle={...Bc};computedFill;computedOutline;computedEffects=[];inlineBox=new W;lineBox=new W;rawGlyphBox=new W;glyphBox=new W;pathBox=new W;boundingBox=new W;measurer=new cc;plugins=new Map;pathSets=[];_paragraphs=[];_cachedCharacters;_pluginsByUpdateOrder=[];_pluginsByRenderOrder=[];_renderer;_rendererCtx;get paragraphs(){return this._paragraphs}set paragraphs(e){this._paragraphs=e,this._cachedCharacters=void 0}get fontSize(){return this.computedStyle.fontSize}get defaultFamily(){return this.fonts?.fallbackFont?.familySet.values().next().value??`sans-serif`}get isVertical(){return this.computedStyle.writingMode.includes(`vertical`)}get characters(){if(this._cachedCharacters)return this._cachedCharacters;let e=[],t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++){let n=r[t].characters;for(let t=0;t<n.length;t++)e.push(n[t])}}return this._cachedCharacters=e,e}constructor(e={}){super(),this.set(e)}set(e={}){let{content:t,effects:n,style:r,measureDom:i,fonts:a,fill:o,outline:s,deformation:c}=lt(e);if(e.measurer&&typeof e.measurer!=`string`)this.measurer=e.measurer;else{let t=e.measurer??(a?`font`:`dom`);this.measurer=t===`font`?new uc:new cc}this.debug=e.debug??!1,this.content=t,this.effects=n,this.style=r,this.measureDom=i,this.fonts=a,this.fill=o,this.outline=s,this.deformation=c,this.use(dc()).use(Pc()).use(Nc()).use(Ic()).use(jc()).use(Fc()).use(kc()),(e.plugins??[]).forEach(e=>{this.use(e)}),this._update()}use(e){return this.plugins.set(e.name,e),this._resortPlugins(),this}_resortPlugins(){this._pluginsByUpdateOrder=[...this.plugins.values()].sort((e,t)=>(e.updateOrder??0)-(t.updateOrder??0)),this._pluginsByRenderOrder=[...this.plugins.values()].sort((e,t)=>(e.renderOrder??0)-(t.renderOrder??0))}forEachCharacter(e){let t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++){let i=r[t].characters;for(let r=0;r<i.length;r++)e(i[r],{paragraphIndex:n,fragmentIndex:t,characterIndex:r})}}return this}async load(){this._update(),await Promise.all(Array.from(this.plugins.values()).map(e=>e.load?.(this)))}_update(){this.computedStyle={...Bc,...this.style},this.computedFill=this.fill?{...this.fill}:void 0,this.computedOutline=this.outline?{...this.outline}:void 0,this.computedEffects=this.effects?.map(e=>e)??[];let e=[];return this.content.forEach((t,n)=>{let{fragments:r,fill:i,outline:a,...o}=t,s=new ic(o,n,this);s.fill=i,s.outline=a,r.forEach((e,t)=>{let{content:n,fill:r,outline:i,...a}=e;n!==void 0&&s.fragments.push(new rc(n,a,r,i,t,s))}),e.push(s)}),this.paragraphs=e,this}createDom(){if(this._update(),!this.measurer.createDom)throw Error(`current measurer does not support createDom()`);return this.measurer.createDom(this.paragraphs,this.computedStyle)}measure(e=this.measureDom){let t={paragraphs:this.paragraphs,inlineBox:this.inlineBox,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this._update();let n=this.measurer.measure(this.paragraphs,this.computedStyle,e,this.fonts);this.paragraphs=n.paragraphs,this.lineBox=n.boundingBox;let r=this.characters;for(let e=0;e<r.length;e++)r[e].update(this.fonts);let i=this.getGlyphBox();this.rawGlyphBox=i,this.glyphBox=i;let a=this._pluginsByUpdateOrder;for(let e=0;e<a.length;e++)a[e].update?.(this);let o=this._pluginsByRenderOrder;this.pathSets.length=0;for(let e=0;e<o.length;e++){let t=o[e];t.pathSet?.paths.length&&this.pathSets.push(t.pathSet)}this._updateInlineBox()._updatePathBox()._updateBoundingBox();for(let e in t){let r=this[e];this[e]=t[e],n[e]=r}return this.emit(`measure`,{text:this,result:n}),n}getGlyphBox(){let e=U.MAX,t=U.MIN,n=this.characters;for(let r=0;r<n.length;r++){let i=n[r];if(i.getGlyphMinMax(e,t))continue;let{left:a,top:o,width:s,height:c}=i.inlineBox,l=new U(a,o),u=new U(a+s,o+c);e.clampMin(l,u),t.clampMax(l,u)}return e.x===-(2**53-1)||e.y===-(2**53-1)||t.x===2**53-1||t.y===2**53-1?new W(0,0,0,0):new W(e.x,e.y,t.x-e.x,t.y-e.y)}_updateInlineBox(){let e=[],t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++)e.push(r[t].inlineBox)}return this.inlineBox=W.from(...e),this}_updatePathBox(){let e=[this.glyphBox];for(let t of this.plugins.values()){let n=t.getBoundingBox?t.getBoundingBox(this):t.pathSet?.getBoundingBox();n&&e.push(n)}return this.pathBox=W.from(...e),this}_updateBoundingBox(){return this.boundingBox=W.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(e=this.measureDom){return this.needsUpdate=!1,Object.assign(this,this.measure(e)),this.emit(`update`,{text:this}),this}_getRenderer(e){return(!this._renderer||this._rendererCtx!==e)&&(this._renderer=new Hr(this,e),this._rendererCtx=e),this._renderer}render(e){let{view:t,pixelRatio:n=2}=e,r=t.getContext(`2d`);if(!r)return;this.needsUpdate&&this.update();let i=this._getRenderer(r);i.pixelRatio=n,i.setup();let a=this._pluginsByRenderOrder;for(let e=0;e<a.length;e++){let t=a[e];if(t.render)t.render(i);else if(t.pathSet){let e=t.pathSet.paths;for(let t=0;t<e.length;t++)i.drawPath(e[t])}}this.emit(`render`,{text:this,view:t,pixelRatio:n}),e.onContext?.(r)}dispose(){this.measurer.dispose?.(),this._renderer=void 0,this._rendererCtx=void 0}toString(){return this.content.flatMap(e=>e.fragments.map(e=>e.content)).join(``)}};Rc([ie({internal:!0}),Lc(`design:type`,Boolean)],Vc.prototype,`debug`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`content`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`style`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`effects`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`fill`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`outline`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`deformation`,void 0),Rc([ie({internal:!0}),Lc(`design:type`,typeof(zc=typeof HTMLElement<`u`&&HTMLElement)==`function`?zc:Object)],Vc.prototype,`measureDom`,void 0),Rc([ie({internal:!0}),Lc(`design:type`,Object)],Vc.prototype,`fonts`,void 0);function Hc(e,t){let n=new Vc(e);return t?n.load().then(()=>n.measure()):n.measure()}function Uc(e,t){let n=new Vc(e);return t?n.load().then(()=>n.render(e)):n.render(e)}e.Canvas2DRenderer=Hr,e.Character=nc,e.CircleCurve=vc,e.DomMeasurer=cc,e.EllipseCurve=yc,e.FontMeasurer=uc,e.Fragment=rc,e.HeartCurve=bc,e.Paragraph=ic,e.PolygonCurve=xc,e.RectangularCurve=Sc,e.Text=Vc,e.backgroundPlugin=dc,e.createSvgLoader=Pr,e.createSvgParser=Fr,e.defineDeformation=Ec,e.definePlugin=ac,e.deformationPlugin=kc,e.getDeformationNames=Oc,e.getEffectTransform2D=Ir,e.getHighlightStyle=Ac,e.highlightPlugin=jc,e.isEqualObject=Br,e.isEqualValue=Vr,e.listStylePlugin=Nc,e.measureText=Hc,e.outlinePlugin=Pc,e.parseColormap=zr,e.parseTransformOrigin=Lr,e.parseValueNumber=Rr,e.removeDeformation=Dc,e.renderPlugin=Fc,e.renderText=Uc,e.textDecorationPlugin=Ic,e.textDefaultStyle=Bc});
36
+ </svg>`}function Nc(){let e=new Nr;return ac({name:`listStyle`,pathSet:e,update:t=>{e.paths.length=0;let{paragraphs:n,isVertical:r,fontSize:i}=t,a=i*.45;n.forEach(t=>{let{computedStyle:n}=t,{color:o,listStyleImage:s,listStyleColormap:c,listStyleSize:l,listStyleType:u}=n,d=zr(c),f=l,p;if(!O(s))p=s;else if(!O(u)){let e=i*.38/2;switch(f=f===`cover`?e*2:f,u){case`disc`:p=Mc(e,String(o));break}}if(!p)return;let m=lr(p),h=m.getBoundingBox()??new W,g=t.fragments[0]?.characters[0];if(!g)return;let{inlineBox:_}=g,v=f===`cover`?1:Rr(f,{total:i,fontSize:i})/i,y=new Mn;if(r){let e=i/h.height*v;y.translate(-h.left,-h.top).rotate(-Math.PI/2).scale(e,e).translate(_.left+(_.width-h.height*e)/2,_.top-a)}else{let e=i/h.height*v;y.translate(-h.left,-h.top).scale(e,e).translate(_.left-h.width*e-a,_.top+(_.height-h.height*e)/2)}e.paths.push(...m.paths.map(e=>{let t=e.clone();return t.applyTransform(y),t.style.fill&&t.style.fill in d&&(t.style.fill=d[t.style.fill]),t.style.stroke&&t.style.stroke in d&&(t.style.stroke=d[t.style.stroke]),t}))})}})}function Pc(){return{name:`outline`}}function Fc(){let e=new Nr;return ac({name:`render`,pathSet:e,update:t=>{e.paths.length=0;let{paragraphs:n}=t;n.forEach(t=>{t.fragments.forEach(t=>{t.characters.forEach(t=>{e.paths.push(t.path)})})})},getBoundingBox:e=>{let{characters:t,computedEffects:n,fontSize:r}=e,i=[];return n.forEach(n=>{let a=Ir(e,n);t.forEach(e=>{if(!e.glyphBox)return;let t=e.glyphBox.clone(),o=a.apply({x:t.left,y:t.top}),s=a.apply({x:t.right,y:t.top}),c=a.apply({x:t.right,y:t.bottom}),l=a.apply({x:t.left,y:t.bottom}),u=Math.min(o.x,s.x,c.x,l.x),d=Math.min(o.y,s.y,c.y,l.y),f=Math.max(o.x,s.x,c.x,l.x),p=Math.max(o.y,s.y,c.y,l.y);if(t.left=u,t.top=d,t.width=f-u,t.height=p-d,n.shadow?.enabled){let e=(n.shadow.offsetX??0)*r,i=(n.shadow.offsetY??0)*r,a=(n.shadow.blur??0)*r,o=t.left+Math.min(0,e-a),s=t.top+Math.min(0,i-a),c=t.left+t.width+Math.max(0,e+a),l=t.top+t.height+Math.max(0,i+a);t.left=o,t.top=s,t.width=c-o,t.height=l-s}if(n.outline?.enabled){let e=Math.max(.1,n.outline.width??0);t.left-=e,t.top-=e,t.width+=e*2,t.height+=e*2}i.push(t)})}),i.length?W.from(...i):void 0},render:e=>{let{text:t,context:n}=e,{paragraphs:r,glyphBox:i,computedEffects:a}=t;r.length&&(a.length?a.forEach(r=>{if(e.uploadColor(i,r),n.save(),e.transformEffect(r),r.shadow?.enabled){let n={...r,shadow:{...r.shadow,enabled:!1}};e.drawWithShadow(r.shadow,()=>{t.forEachCharacter(t=>{e.drawCharacter(t,n)})})}else t.forEachCharacter(t=>{e.drawCharacter(t,r)});n.restore()}):r.forEach(t=>{t.fragments.forEach(t=>{t.characters.forEach(t=>{e.drawCharacter(t)})})}),t.debug&&r.forEach(e=>{n.strokeRect(e.lineBox.x,e.lineBox.y,e.lineBox.width,e.lineBox.height)}))}})}function Ic(){let e=new Nr;return ac({name:`textDecoration`,pathSet:e,update:t=>{e.paths.length=0;let n=[],r,i;t.forEachCharacter(e=>{let{computedStyle:t,isVertical:a,inlineBox:o,underlinePosition:s,underlineThickness:c,strikeoutPosition:l,strikeoutSize:u}=e,{color:d,textDecoration:f,writingMode:p}=t;if(O(f))i=void 0;else{let m=!1;if(i?.textDecoration===f&&i?.writingMode===p&&i?.color===d&&(a?r[0].inlineBox.left===o.left:r[0].inlineBox.top===o.top))switch(f){case`underline`:r[0].underlinePosition===s&&r[0].underlineThickness===c&&(m=!0);break;case`line-through`:r[0].strikeoutPosition===l&&r[0].strikeoutSize===u&&(m=!0);break}m?r.push(e):(r=[],r.push(e),n.push(r)),i=t}}),n.forEach(t=>{let{computedStyle:n,isVertical:r,underlinePosition:i,underlineThickness:a,strikeoutPosition:o,strikeoutSize:s}=t[0],{color:c,textDecoration:l}=n,{left:u,top:d,width:f,height:p}=W.from(...t.map(e=>e.inlineBox)),m=r?u+f:d,h=r?-1:1,g=0;switch(l){case`overline`:g=a*2;break;case`underline`:m+=h*i,g=a*2;break;case`line-through`:m+=h*o,g=s*2;break}m-=g;let _;_=r?new Mr([{type:`M`,x:m,y:d},{type:`L`,x:m,y:d+p},{type:`L`,x:m+g,y:d+p},{type:`L`,x:m+g,y:d},{type:`Z`}],{fill:c}):new Mr([{type:`M`,x:u,y:m},{type:`L`,x:u+f,y:m},{type:`L`,x:u+f,y:m+g},{type:`L`,x:u,y:m+g},{type:`Z`}],{fill:c}),e.paths.push(_)})},render:t=>{let{text:n,context:r}=t,{computedEffects:i}=n;i.length?i.forEach(n=>{r.save(),t.transformEffect(n),e.paths.forEach(e=>{t.drawPath(e,t.effectToPathStyle(n))}),r.restore()}):e.paths.forEach(e=>{t.drawPath(e)})}})}function Lc(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function Rc(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var zc,Bc=et(),Vc=class extends ae{needsUpdate=!0;computedStyle={...Bc};computedFill;computedOutline;computedEffects=[];inlineBox=new W;lineBox=new W;rawGlyphBox=new W;glyphBox=new W;pathBox=new W;boundingBox=new W;measurer=new cc;plugins=new Map;pathSets=[];_paragraphs=[];_cachedCharacters;_pluginsByUpdateOrder=[];_pluginsByRenderOrder=[];_renderer;_rendererCtx;get paragraphs(){return this._paragraphs}set paragraphs(e){this._paragraphs=e,this._cachedCharacters=void 0}get fontSize(){return this.computedStyle.fontSize}get defaultFamily(){return this.fonts?.fallbackFont?.familySet.values().next().value??`sans-serif`}get isVertical(){return this.computedStyle.writingMode.includes(`vertical`)}get characters(){if(this._cachedCharacters)return this._cachedCharacters;let e=[],t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++){let n=r[t].characters;for(let t=0;t<n.length;t++)e.push(n[t])}}return this._cachedCharacters=e,e}constructor(e={}){super(),this.set(e)}set(e={}){let{content:t,effects:n,style:r,measureDom:i,fonts:a,fill:o,outline:s,deformation:c}=lt(e);if(e.measurer&&typeof e.measurer!=`string`)this.measurer=e.measurer;else{let t=e.measurer??(a?`font`:`dom`);this.measurer=t===`font`?new uc:new cc}this.debug=e.debug??!1,this.content=t,this.effects=n,this.style=r,this.measureDom=i,this.fonts=a,this.fill=o,this.outline=s,this.deformation=c,this.use(dc()).use(Pc()).use(Nc()).use(Ic()).use(jc()).use(Fc()).use(kc()),(e.plugins??[]).forEach(e=>{this.use(e)}),this._update()}use(e){return this.plugins.set(e.name,e),this._resortPlugins(),this}_resortPlugins(){this._pluginsByUpdateOrder=[...this.plugins.values()].sort((e,t)=>(e.updateOrder??0)-(t.updateOrder??0)),this._pluginsByRenderOrder=[...this.plugins.values()].sort((e,t)=>(e.renderOrder??0)-(t.renderOrder??0))}forEachCharacter(e){let t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++){let i=r[t].characters;for(let r=0;r<i.length;r++)e(i[r],{paragraphIndex:n,fragmentIndex:t,characterIndex:r})}}return this}async load(){this._update(),await Promise.all([this._decodeFonts(),...Array.from(this.plugins.values()).map(e=>e.load?.(this))])}async _decodeFonts(){let e=this.fonts??Xs,t=new Set;for(let n of this.characters){let r=n.computedStyle.fontFamily;r&&t.add(e.get(r))}t.add(e.fallbackFont),await Promise.all(Array.from(t,async e=>{let t=e?.getFont();t&&typeof t.createSFNTAsync==`function`&&!t._sfnt&&(t._sfnt=await t.createSFNTAsync())}))}_update(){this.computedStyle={...Bc,...this.style},this.computedFill=this.fill?{...this.fill}:void 0,this.computedOutline=this.outline?{...this.outline}:void 0,this.computedEffects=this.effects?.map(e=>e)??[];let e=[];return this.content.forEach((t,n)=>{let{fragments:r,fill:i,outline:a,...o}=t,s=new ic(o,n,this);s.fill=i,s.outline=a,r.forEach((e,t)=>{let{content:n,fill:r,outline:i,...a}=e;n!==void 0&&s.fragments.push(new rc(n,a,r,i,t,s))}),e.push(s)}),this.paragraphs=e,this}createDom(){if(this._update(),!this.measurer.createDom)throw Error(`current measurer does not support createDom()`);return this.measurer.createDom(this.paragraphs,this.computedStyle)}measure(e=this.measureDom){let t={paragraphs:this.paragraphs,inlineBox:this.inlineBox,lineBox:this.lineBox,rawGlyphBox:this.rawGlyphBox,glyphBox:this.glyphBox,pathBox:this.pathBox,boundingBox:this.boundingBox};this._update();let n=this.measurer.measure(this.paragraphs,this.computedStyle,e,this.fonts);this.paragraphs=n.paragraphs,this.lineBox=n.boundingBox;let r=this.characters;for(let e=0;e<r.length;e++)r[e].update(this.fonts);let i=this.getGlyphBox();this.rawGlyphBox=i,this.glyphBox=i;let a=this._pluginsByUpdateOrder;for(let e=0;e<a.length;e++)a[e].update?.(this);let o=this._pluginsByRenderOrder;this.pathSets.length=0;for(let e=0;e<o.length;e++){let t=o[e];t.pathSet?.paths.length&&this.pathSets.push(t.pathSet)}this._updateInlineBox()._updatePathBox()._updateBoundingBox();for(let e in t){let r=this[e];this[e]=t[e],n[e]=r}return this.emit(`measure`,{text:this,result:n}),n}getGlyphBox(){let e=U.MAX,t=U.MIN,n=this.characters;for(let r=0;r<n.length;r++){let i=n[r];if(i.getGlyphMinMax(e,t))continue;let{left:a,top:o,width:s,height:c}=i.inlineBox,l=new U(a,o),u=new U(a+s,o+c);e.clampMin(l,u),t.clampMax(l,u)}return e.x===-(2**53-1)||e.y===-(2**53-1)||t.x===2**53-1||t.y===2**53-1?new W(0,0,0,0):new W(e.x,e.y,t.x-e.x,t.y-e.y)}_updateInlineBox(){let e=[],t=this._paragraphs;for(let n=0;n<t.length;n++){let r=t[n].fragments;for(let t=0;t<r.length;t++)e.push(r[t].inlineBox)}return this.inlineBox=W.from(...e),this}_updatePathBox(){let e=[this.glyphBox];for(let t of this.plugins.values()){let n=t.getBoundingBox?t.getBoundingBox(this):t.pathSet?.getBoundingBox();n&&e.push(n)}return this.pathBox=W.from(...e),this}_updateBoundingBox(){return this.boundingBox=W.from(this.rawGlyphBox,this.lineBox,this.pathBox),this}requestUpdate(){return this.needsUpdate=!0,this}update(e=this.measureDom){return this.needsUpdate=!1,Object.assign(this,this.measure(e)),this.emit(`update`,{text:this}),this}_getRenderer(e){return(!this._renderer||this._rendererCtx!==e)&&(this._renderer=new Hr(this,e),this._rendererCtx=e),this._renderer}render(e){let{view:t,pixelRatio:n=2}=e,r=t.getContext(`2d`);if(!r)return;this.needsUpdate&&this.update();let i=this._getRenderer(r);i.pixelRatio=n,i.setup();let a=this._pluginsByRenderOrder;for(let e=0;e<a.length;e++){let t=a[e];if(t.render)t.render(i);else if(t.pathSet){let e=t.pathSet.paths;for(let t=0;t<e.length;t++)i.drawPath(e[t])}}this.emit(`render`,{text:this,view:t,pixelRatio:n}),e.onContext?.(r)}dispose(){this.measurer.dispose?.(),this._renderer=void 0,this._rendererCtx=void 0}toString(){return this.content.flatMap(e=>e.fragments.map(e=>e.content)).join(``)}};Rc([ie({internal:!0}),Lc(`design:type`,Boolean)],Vc.prototype,`debug`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`content`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`style`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`effects`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`fill`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`outline`,void 0),Rc([ie(),Lc(`design:type`,Object)],Vc.prototype,`deformation`,void 0),Rc([ie({internal:!0}),Lc(`design:type`,typeof(zc=typeof HTMLElement<`u`&&HTMLElement)==`function`?zc:Object)],Vc.prototype,`measureDom`,void 0),Rc([ie({internal:!0}),Lc(`design:type`,Object)],Vc.prototype,`fonts`,void 0);function Hc(e,t){let n=new Vc(e);return t?n.load().then(()=>n.measure()):n.measure()}function Uc(e,t){let n=new Vc(e);return t?n.load().then(()=>n.render(e)):n.render(e)}e.Canvas2DRenderer=Hr,e.Character=nc,e.CircleCurve=vc,e.DomMeasurer=cc,e.EllipseCurve=yc,e.FontMeasurer=uc,e.Fragment=rc,e.HeartCurve=bc,e.Paragraph=ic,e.PolygonCurve=xc,e.RectangularCurve=Sc,e.Text=Vc,e.backgroundPlugin=dc,e.createSvgLoader=Pr,e.createSvgParser=Fr,e.defineDeformation=Ec,e.definePlugin=ac,e.deformationPlugin=kc,e.getDeformationNames=Oc,e.getEffectTransform2D=Ir,e.getHighlightStyle=Ac,e.highlightPlugin=jc,e.isEqualObject=Br,e.isEqualValue=Vr,e.listStylePlugin=Nc,e.measureText=Hc,e.outlinePlugin=Pc,e.parseColormap=zr,e.parseTransformOrigin=Lr,e.parseValueNumber=Rr,e.removeDeformation=Dc,e.renderPlugin=Fc,e.renderText=Uc,e.textDecorationPlugin=Ic,e.textDefaultStyle=Bc});
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { T as Text } from './shared/modern-text.ChzjFjsk.mjs';
2
- export { C as Canvas2DRenderer, a as Character, D as DomMeasurer, F as FontMeasurer, b as Fragment, P as Paragraph, c as backgroundPlugin, d as createSvgLoader, e as createSvgParser, g as getEffectTransform2D, f as getHighlightStyle, h as highlightPlugin, i as isEqualObject, j as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, k as parseTransformOrigin, m as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, n as textDefaultStyle } from './shared/modern-text.ChzjFjsk.mjs';
1
+ import { T as Text } from './shared/modern-text.EUexrM_5.mjs';
2
+ export { C as Canvas2DRenderer, a as Character, D as DomMeasurer, F as FontMeasurer, b as Fragment, P as Paragraph, c as backgroundPlugin, d as createSvgLoader, e as createSvgParser, g as getEffectTransform2D, f as getHighlightStyle, h as highlightPlugin, i as isEqualObject, j as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, k as parseTransformOrigin, m as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, n as textDefaultStyle } from './shared/modern-text.EUexrM_5.mjs';
3
3
  export { d as defineDeformation, a as definePlugin, b as deformationPlugin, g as getDeformationNames, r as removeDeformation } from './shared/modern-text.JF1ny7A-.mjs';
4
4
  export { C as CircleCurve, E as EllipseCurve, H as HeartCurve, P as PolygonCurve, R as RectangularCurve } from './shared/modern-text.fT17R5HY.mjs';
5
+ import 'modern-font';
5
6
  import 'modern-idoc';
6
7
  import 'modern-path2d';
7
- import 'modern-font';
8
8
 
9
9
  function measureText(options, load) {
10
10
  const text = new Text(options);
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const modernFont = require('modern-font');
3
4
  const modernIdoc = require('modern-idoc');
4
5
  const modernPath2d = require('modern-path2d');
5
- const modernFont = require('modern-font');
6
6
  const deformation = require('./modern-text.B2xfrqDc.cjs');
7
7
 
8
8
  function createSvgLoader() {
@@ -2187,7 +2187,35 @@ class Text extends modernIdoc.Reactivable {
2187
2187
  }
2188
2188
  async load() {
2189
2189
  this._update();
2190
- await Promise.all(Array.from(this.plugins.values()).map((p) => p.load?.(this)));
2190
+ await Promise.all([
2191
+ this._decodeFonts(),
2192
+ ...Array.from(this.plugins.values()).map((p) => p.load?.(this))
2193
+ ]);
2194
+ }
2195
+ /**
2196
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
2197
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
2198
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
2199
+ * never stalls the main thread inflating WOFF tables on first glyph access.
2200
+ *
2201
+ * No-op for already-decoded fonts and for formats without async decoding.
2202
+ */
2203
+ async _decodeFonts() {
2204
+ const fonts = this.fonts ?? modernFont.fonts;
2205
+ const entries = /* @__PURE__ */ new Set();
2206
+ for (const character of this.characters) {
2207
+ const family = character.computedStyle.fontFamily;
2208
+ if (family) {
2209
+ entries.add(fonts.get(family));
2210
+ }
2211
+ }
2212
+ entries.add(fonts.fallbackFont);
2213
+ await Promise.all(Array.from(entries, async (entry) => {
2214
+ const font = entry?.getFont();
2215
+ if (font && typeof font.createSFNTAsync === "function" && !font._sfnt) {
2216
+ font._sfnt = await font.createSFNTAsync();
2217
+ }
2218
+ }));
2191
2219
  }
2192
2220
  _update() {
2193
2221
  this.computedStyle = { ...textDefaultStyle, ...this.style };
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.cjs';
2
+ import { a as Character } from './modern-text.C6VOXPvn.mjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -1,6 +1,6 @@
1
+ import { fonts } from 'modern-font';
1
2
  import { isNone, isGradient, normalizeGradient, clearUndef, Reactivable, normalizeText, getDefaultStyle, property } from 'modern-idoc';
2
3
  import { svgToDom, svgToPath2DSet, Path2DSet, Transform2D, setCanvasContext, Path2D, BoundingBox, Vector2 } from 'modern-path2d';
3
- import { fonts } from 'modern-font';
4
4
  import { a as definePlugin, b as deformationPlugin } from './modern-text.JF1ny7A-.mjs';
5
5
 
6
6
  function createSvgLoader() {
@@ -2185,7 +2185,35 @@ class Text extends Reactivable {
2185
2185
  }
2186
2186
  async load() {
2187
2187
  this._update();
2188
- await Promise.all(Array.from(this.plugins.values()).map((p) => p.load?.(this)));
2188
+ await Promise.all([
2189
+ this._decodeFonts(),
2190
+ ...Array.from(this.plugins.values()).map((p) => p.load?.(this))
2191
+ ]);
2192
+ }
2193
+ /**
2194
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
2195
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
2196
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
2197
+ * never stalls the main thread inflating WOFF tables on first glyph access.
2198
+ *
2199
+ * No-op for already-decoded fonts and for formats without async decoding.
2200
+ */
2201
+ async _decodeFonts() {
2202
+ const fonts$1 = this.fonts ?? fonts;
2203
+ const entries = /* @__PURE__ */ new Set();
2204
+ for (const character of this.characters) {
2205
+ const family = character.computedStyle.fontFamily;
2206
+ if (family) {
2207
+ entries.add(fonts$1.get(family));
2208
+ }
2209
+ }
2210
+ entries.add(fonts$1.fallbackFont);
2211
+ await Promise.all(Array.from(entries, async (entry) => {
2212
+ const font = entry?.getFont();
2213
+ if (font && typeof font.createSFNTAsync === "function" && !font._sfnt) {
2214
+ font._sfnt = await font.createSFNTAsync();
2215
+ }
2216
+ }));
2189
2217
  }
2190
2218
  _update() {
2191
2219
  this.computedStyle = { ...textDefaultStyle, ...this.style };
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.mjs';
2
+ import { a as Character } from './modern-text.C6VOXPvn.cjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.js';
2
+ import { a as Character } from './modern-text.C6VOXPvn.js';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -2,9 +2,9 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.CBgc-cQ1.cjs');
6
- require('modern-path2d');
5
+ const Text = require('../shared/modern-text.9z5yZjKR.cjs');
7
6
  require('modern-font');
7
+ require('modern-path2d');
8
8
  require('../shared/modern-text.B2xfrqDc.cjs');
9
9
 
10
10
  var __defProp = Object.defineProperty;
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.cjs';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.cjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.mjs';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.mjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.js';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.js';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,8 +1,8 @@
1
1
  import { diffChars } from 'diff';
2
2
  import { isCRLF, textContentToString, normalizeCRLF, normalizeTextContent, property } from 'modern-idoc';
3
- import { T as Text } from '../shared/modern-text.ChzjFjsk.mjs';
4
- import 'modern-path2d';
3
+ import { T as Text } from '../shared/modern-text.EUexrM_5.mjs';
5
4
  import 'modern-font';
5
+ import 'modern-path2d';
6
6
  import '../shared/modern-text.JF1ny7A-.mjs';
7
7
 
8
8
  var __defProp = Object.defineProperty;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "packageManager": "pnpm@10.18.1",
6
6
  "description": "Measure and render text in a way that describes the DOM.",
7
7
  "author": "wxm",