modern-text 2.1.3 → 2.1.4
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/deformations/index.d.cts +2 -2
- package/dist/deformations/index.d.mts +2 -2
- package/dist/deformations/index.d.ts +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/shared/{modern-text.DENkEKJN.d.cts → modern-text.Byk6gnkH.d.cts} +10 -1
- package/dist/shared/{modern-text.DENkEKJN.d.mts → modern-text.Byk6gnkH.d.mts} +10 -1
- package/dist/shared/{modern-text.DENkEKJN.d.ts → modern-text.Byk6gnkH.d.ts} +10 -1
- package/dist/shared/{modern-text.D8v3zJdm.cjs → modern-text.CJSp_eBm.cjs} +52 -4
- package/dist/shared/{modern-text.CjkLMv3V.d.cts → modern-text.DwLgm6ho.d.mts} +1 -1
- package/dist/shared/{modern-text.C6Cwc-zm.mjs → modern-text.Dz4np_87.mjs} +52 -4
- package/dist/shared/{modern-text.1LMQ6ZWb.d.ts → modern-text.kLi3S9Iu.d.ts} +1 -1
- package/dist/shared/{modern-text.Cv-GZog_.d.mts → modern-text.xspsgB0_.d.cts} +1 -1
- package/dist/web-components/index.cjs +1 -1
- package/dist/web-components/index.d.cts +1 -1
- package/dist/web-components/index.d.mts +1 -1
- package/dist/web-components/index.d.ts +1 -1
- package/dist/web-components/index.mjs +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as DeformationPreset } from '../shared/modern-text.
|
|
1
|
+
import { D as DeformationPreset } from '../shared/modern-text.xspsgB0_.cjs';
|
|
2
2
|
import 'modern-path2d';
|
|
3
|
-
import '../shared/modern-text.
|
|
3
|
+
import '../shared/modern-text.Byk6gnkH.cjs';
|
|
4
4
|
import 'modern-idoc';
|
|
5
5
|
import 'modern-font';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as DeformationPreset } from '../shared/modern-text.
|
|
1
|
+
import { D as DeformationPreset } from '../shared/modern-text.DwLgm6ho.mjs';
|
|
2
2
|
import 'modern-path2d';
|
|
3
|
-
import '../shared/modern-text.
|
|
3
|
+
import '../shared/modern-text.Byk6gnkH.mjs';
|
|
4
4
|
import 'modern-idoc';
|
|
5
5
|
import 'modern-font';
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { D as DeformationPreset } from '../shared/modern-text.
|
|
1
|
+
import { D as DeformationPreset } from '../shared/modern-text.kLi3S9Iu.js';
|
|
2
2
|
import 'modern-path2d';
|
|
3
|
-
import '../shared/modern-text.
|
|
3
|
+
import '../shared/modern-text.Byk6gnkH.js';
|
|
4
4
|
import 'modern-idoc';
|
|
5
5
|
import 'modern-font';
|
|
6
6
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const Text = require('./shared/modern-text.
|
|
3
|
+
const Text = require('./shared/modern-text.CJSp_eBm.cjs');
|
|
4
4
|
const deformation = require('./shared/modern-text.B1qEGvHu.cjs');
|
|
5
5
|
const curves = require('./shared/modern-text.MC5bIC9E.cjs');
|
|
6
6
|
require('modern-font');
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.
|
|
2
|
-
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.
|
|
1
|
+
import { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.Byk6gnkH.cjs';
|
|
2
|
+
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.Byk6gnkH.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 { D as DeformationPreset } from './shared/modern-text.
|
|
7
|
-
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.
|
|
6
|
+
import { D as DeformationPreset } from './shared/modern-text.xspsgB0_.cjs';
|
|
7
|
+
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.xspsgB0_.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 { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.
|
|
2
|
-
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.
|
|
1
|
+
import { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.Byk6gnkH.mjs';
|
|
2
|
+
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.Byk6gnkH.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 { D as DeformationPreset } from './shared/modern-text.
|
|
7
|
-
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.
|
|
6
|
+
import { D as DeformationPreset } from './shared/modern-text.DwLgm6ho.mjs';
|
|
7
|
+
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.DwLgm6ho.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 { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.
|
|
2
|
-
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.
|
|
1
|
+
import { P as Plugin, T as TextMeasurer, a as Paragraph, M as MeasurerResult, C as Character, O as Options, b as MeasureResult, R as RenderOptions, c as Text } from './shared/modern-text.Byk6gnkH.js';
|
|
2
|
+
export { d as Canvas2DRenderer, D as DrawShapePathsOptions, F as Fragment, e as TextEvents, t as textDefaultStyle } from './shared/modern-text.Byk6gnkH.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 { D as DeformationPreset } from './shared/modern-text.
|
|
7
|
-
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.
|
|
6
|
+
import { D as DeformationPreset } from './shared/modern-text.kLi3S9Iu.js';
|
|
7
|
+
export { B as BendContext, a as BendPreset, C as CurvePreset, b as DeformationCharInfo, c as DeformationCurve, F as FfdContext, d as FfdPreset, O as OffsetPreset, V as VerbatimContext } from './shared/modern-text.kLi3S9Iu.js';
|
|
8
8
|
|
|
9
9
|
declare function definePlugin(options: Plugin): Plugin;
|
|
10
10
|
|
package/dist/index.js
CHANGED
|
@@ -34,4 +34,4 @@ ${this.paths.map(e=>e.toSvgPathString()).join(``)}
|
|
|
34
34
|
}`)),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=this._createLoadedFont(o,c,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(()=>(this._emitLoad(n),n))}).catch(e=>{if(e instanceof DOMException&&e.message===`The user aborted a request.`)return this._createLoadedFont(o,c);throw e}).finally(()=>{this.loading.delete(o)});function u(e){return c.forEach(t=>{e.familySet.add(t)}),e}}_createLoadedFont(e,t,n=new ArrayBuffer(0)){let r;function i(){return r||=n.byteLength?Zc(n,!1):void 0,r}function a(){let e=i();if(e instanceof Lc||e instanceof Yc)return e.sfnt}return{src:e,family:t.length===1?t[0]:t,buffer:n,familySet:new Set(t),getFont:i,getSFNT:a}}async waitUntilLoad(){await Promise.all(Array.from(this.loading.values(),e=>e.when))}},$c=new Set([`©`,`®`,`÷`]),el=new Set([`—`,`…`,`“`,`”`,`﹏`,`﹋`,`﹌`,`‘`,`’`,`˜`]),tl={1:`italic`,32:`bold`},nl={1:`italic`,2:`bold`},rl={100:-.2,200:-.1,300:0,400:0,normal:0,500:.1,600:.2,700:.3,bold:.3,800:.4,900:.5},il=4096,al=new Map;function ol(e,t){al.set(e,t),al.size>il&&al.delete(al.keys().next().value)}var sl=0,cl=new WeakMap;function ll(e){let t=cl.get(e);return t===void 0&&(t=++sl,cl.set(e,t)),t}var ul=256,dl=new Map;function fl(e,t){let n=`${ll(e)}|${t}`,r=dl.get(n);if(r)return r;let{hhea:i,os2:a,post:o,head:s}=e,c=s.unitsPerEm,l=i.ascent,u=i.descent,d=c/t,f=(l+Math.abs(u))/d,p=l/d,m={sfnt:e,unitsPerEm:c,advanceHeight:f,baseline:p,ascender:l/d,descender:u/d,underlinePosition:(l-o.underlinePosition)/d,underlineThickness:o.underlineThickness/d,strikeoutPosition:(l-a.yStrikeoutPosition)/d,strikeoutSize:a.yStrikeoutSize/d,typoAscender:a.sTypoAscender/d,typoDescender:a.sTypoDescender/d,typoLineGap:a.sTypoLineGap/d,winAscent:a.usWinAscent/d,winDescent:a.usWinDescent/d,xHeight:a.version>1?a.sxHeight/d:0,capHeight:a.version>1?a.sCapHeight/d:0,centerDiviation:f/2-p,fontStyle:tl[a.fsSelection]??nl[s.macStyle]};return dl.size>=ul&&dl.delete(dl.keys().next().value),dl.set(n,m),m}var pl=class{content;index;parent;_path;_lazyPath;get path(){if(this._path)return this._path;let e=this._lazyPath;if(e){let{x:t,y:n}=e,r=e.tmpl.path.clone().setMeta(this);return r.applyTransform(e=>{e.x+=t,e.y+=n}),r.style=e.style,this._path=r,this._lazyPath=void 0,r}let t=new Mi().setMeta(this);return this._path=t,t}set path(e){this._path=e,this._lazyPath=void 0}inlineBox=new W;get lineBox(){let e=this.inlineBox,t=this.fontHeight;return this.isVertical?new W(e.left+(e.width-t)/2,e.top,t,e.height):new W(e.left,e.top+(e.height-t)/2,e.width,t)}glyphBox;advanceWidth=0;kerningBefore=0;_glyphIndex;_metrics;get advanceHeight(){return this._metrics?.advanceHeight??0}get baseline(){return this._metrics?.baseline??0}get ascender(){return this._metrics?.ascender??0}get descender(){return this._metrics?.descender??0}get underlinePosition(){return this._metrics?.underlinePosition??0}get underlineThickness(){return this._metrics?.underlineThickness??0}get strikeoutPosition(){return this._metrics?.strikeoutPosition??0}get strikeoutSize(){return this._metrics?.strikeoutSize??0}get typoAscender(){return this._metrics?.typoAscender??0}get typoDescender(){return this._metrics?.typoDescender??0}get typoLineGap(){return this._metrics?.typoLineGap??0}get winAscent(){return this._metrics?.winAscent??0}get winDescent(){return this._metrics?.winDescent??0}get xHeight(){return this._metrics?.xHeight??0}get capHeight(){return this._metrics?.capHeight??0}get centerDiviation(){return this._metrics?.centerDiviation??0}get fontStyle(){return this._metrics?.fontStyle}translateY(e){e&&(this.inlineBox.top+=e,this.glyphBox&&(this.glyphBox.top+=e),this._lazyPath?this._lazyPath.y+=e:this._path&&this._path.applyTransform(t=>{t.y+=e}))}get compatibleGlyphBox(){if(this.glyphBox)return this.glyphBox;let e=this.computedStyle.fontSize*.8,t=this.lineBox;return this.isVertical?new W(t.left+t.width/2-e/2,t.top,e,t.height):new W(t.left,t.top+t.height/2-e/2,t.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??Qc,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{content:t,computedStyle:n}=this,r=n.fontSize;return this._metrics=fl(e,r),this.advanceWidth=e.getAdvanceWidth(t,r),this._glyphIndex=e.textToGlyphIndexes(t)[0],this}computeKerningBefore(e){let t=this._metrics;if(!e||!t||e._metrics?.sfnt!==t.sfnt||e._glyphIndex===void 0||this._glyphIndex===void 0)return 0;let n=t.sfnt.getKerningValue(e._glyphIndex,this._glyphIndex);return n?n*this.computedStyle.fontSize/t.unitsPerEm:0}measureGlyph(e){return this.updateGlyph(this._getFontSFNT(e))}update(e){let t=this._getFontSFNT(e);if(!t)return this;this.updateGlyph(t);let n=this.computedStyle,r=n.fontStyle===`italic`&&this.fontStyle!==`italic`;if(!this.isVertical&&!r&&!n.textStrokeWidth)return this._updateFromCache(t,n),this;let{isVertical:i,content:a,baseline:o,inlineBox:s,ascender:c,descender:l,typoAscender:u,fontStyle:d,advanceWidth:f,advanceHeight:p}=this,{left:m,top:h}=s,g=m,_=h+o,v,y=new Mi().setMeta(this);if(i&&(g+=(p-f)/2,Math.abs(f-p)>.1&&(_-=(c-u)/(c+Math.abs(l))*p),v=void 0),i&&!$c.has(a)&&(a.codePointAt(0)<=256||el.has(a))){y.addCommands(t.getPathCommands(a,g,h+o-(p-f)/2,n.fontSize));let e={y:h-(p-f)/2+p/2,x:g+f/2};r&&this._italic(y,{x:e.x,y:h-(p-f)/2+o}),y.rotate(Math.PI/2,e)}else v===void 0?(y.addCommands(t.getPathCommands(a,g,_,n.fontSize)),r&&this._italic(y,i?{x:g+p/2,y:_}:void 0)):(y.addCommands(t.glyphs.get(v).getPathCommands(g,_,n.fontSize)),r&&this._italic(y,i?{x:g+f/2,y:h+u/(c+Math.abs(l))*p}:void 0));let b=n.fontWeight??400;return b in rl&&(b===700||b===`bold`)&&d!==`bold`&&y.bold(rl[b]*n.fontSize*.05),y.style=B({fill:n.color,fillRule:`nonzero`,stroke:n.textStrokeWidth?n.textStrokeColor:void 0,strokeWidth:n.textStrokeWidth?n.textStrokeWidth*n.fontSize*.03:void 0}),this.path=y,this.glyphBox=this.getGlyphBoundingBox(),this}_updateFromCache(e,t){let n=this.content,r=t.fontSize,i=this.inlineBox.left,a=this.inlineBox.top+this.baseline,o=t.fontWeight??400,s=o in rl&&(o===700||o===`bold`)&&this.fontStyle!==`bold`?rl[o]*r*.05:0,c=`${n}|${ll(e)}|${r}|${s}`,l=al.get(c);if(!l){let t=new Mi;t.addCommands(e.getPathCommands(n,0,0,r)),s&&t.bold(s);let i;if(t.curves[0]?.curves.length){let{min:e,max:n}=t.getMinMax(void 0,void 0,!0);i=new W(e.x,e.y,n.x-e.x,n.y-e.y)}l={path:t,glyphBox:i},ol(c,l)}this._path=void 0,this._lazyPath={tmpl:l,x:i,y:a,style:B({fill:t.color,fillRule:`nonzero`})},this.glyphBox=l.glyphBox?new W(l.glyphBox.left+i,l.glyphBox.top+a,l.glyphBox.width,l.glyphBox.height):void 0}_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===void 0&&this._lazyPath!==void 0){let n=this.glyphBox;if(!n)return;let r=new U(n.left,n.top),i=new U(n.left+n.width,n.top+n.height),a=e??new U(2**53-1,2**53-1),o=t??new U(-(2**53-1),-(2**53-1));return a.clampMin(r,i),o.clampMax(r,i),{min:a,max:o}}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)}},ml=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,...B(this.style)};let e=this.fill??this.parent.computedFill;this.computedFill=e?B(e):void 0;let t=this.outline??this.parent.computedOutline;return this.computedOutline=t?B(t):void 0,this}initCharacters(){let e=[],t=0;for(let n of this.computedContent)e.push(new pl(n,t++,this));return this.characters=e,this}},hl=class{style;index;parent;lineBox=new W;fragments=[];fill;outline;_layoutDirty=!0;_layoutTop=0;_layoutHeight=0;_layoutRight=0;_glyphBox;_layoutValid=!1;constructor(e,t,n){this.style=e,this.index=t,this.parent=n,this.update()}update(){this.computedStyle={...B(this.parent.computedStyle),...B(this.style)};let e=this.fill??this.parent.computedFill;this.computedFill=e?B(e):void 0;let t=this.outline??this.parent.computedOutline;return this.computedOutline=t?B(t):void 0,this}};function gl(e){return e}function _l(e,t,n){return e[`${t}${n}`]??e[t]??0}var vl=class{measure(e,t,n,r){let i=r??Qc;for(let t of e)if(t._layoutDirty)for(let e of t.fragments)for(let t of e.characters)t.measureGlyph(i);return t.writingMode.includes(`vertical`)||this._applyKerning(e),t.writingMode.includes(`vertical`)?this._measureVertical(e,t):this._measureHorizontal(e,t)}_rootPadding(e){return{top:_l(e,`padding`,`Top`),right:_l(e,`padding`,`Right`),bottom:_l(e,`padding`,`Bottom`),left:_l(e,`padding`,`Left`)}}_measureHorizontal(e,t){let n=this._rootPadding(t),r=typeof t.width==`number`,i=t.textWrap===`nowrap`,a=r&&!i?t.width-n.left-n.right:1/0,o=n.top,s=n.left;for(let t of e){let e=t.computedStyle,r=t.style,i=_l(r,`margin`,`Top`),c=_l(r,`margin`,`Bottom`),l=_l(r,`margin`,`Left`),u=_l(r,`margin`,`Right`),d=_l(r,`padding`,`Top`),f=_l(r,`padding`,`Bottom`),p=_l(r,`padding`,`Left`),m=_l(r,`padding`,`Right`),h=n.left+l+p,g=a===1/0?1/0:a-l-u-p-m;o+=i+d;let _=o,v=h;if(!t._layoutDirty){let e=_-t._layoutTop;if(e){for(let n of t.fragments){for(let t of n.characters)t.translateY(e);n.inlineBox.top+=e}t.lineBox.top+=e,t._glyphBox&&(t._glyphBox.top+=e)}t._layoutTop=_,v=t._layoutRight,o=_+t.lineBox.height,v>s&&(s=v),o+=f+c;continue}let y=this._breakLines(t,g),b=e.textAlign,x=e.textIndent??0,S=!1,C=!1;for(let t=0;t<y.length;t++){let n=y[t],r=t===0?x:0,i=e.fontSize*e.lineHeight,a=0,s=!0;for(let e of n)e.fontHeight>i&&(i=e.fontHeight),s||(a+=e.kerningBefore),s=!1,a+=this._advance(e);let c=h+r;if(g!==1/0){let e=g-r-a;b===`center`?c+=e/2:(b===`end`||b===`right`)&&(c+=e)}let l=!0;for(let e of n){S=!0,e.advanceWidth>0&&(C=!0),l||(c+=e.kerningBefore),l=!1;let t=e.advanceWidth,n=e.advanceHeight;e.inlineBox.left=c,e.inlineBox.top=o+(i-n)/2,e.inlineBox.width=t,e.inlineBox.height=n,c+=this._advance(e)}c>v&&(v=c),o+=i}v>s&&(s=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=o-_,t._layoutTop=_,t._layoutHeight=t.lineBox.height,t._layoutRight=v,t._glyphBox=void 0,t._layoutValid=!S||C,o+=f+c}let c=o+n.bottom,l=r?t.width:s+n.right,u=typeof t.height==`number`?t.height:c;if(typeof t.height==`number`){let n=u-c,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,l,u)}}_measureVertical(e,t){let n=this._rootPadding(t),r=typeof t.height==`number`,i=t.textWrap===`nowrap`,a=r&&!i?t.height-n.top-n.bottom:1/0,o=[];for(let t of e){let e=t.computedStyle.fontSize*t.computedStyle.lineHeight;for(let n of this._breakLines(t,a)){let t=e;for(let e of n)e.fontHeight>t&&(t=e.fontHeight);o.push({chars:n,thickness:t})}}let s=o.reduce((e,t)=>e+t.thickness,0),c=typeof t.width==`number`,l=c?Math.max(t.width-n.left-n.right,s):s,u=n.left+l,d=n.top;for(let e of o){u-=e.thickness;let t=u,r=n.top;for(let n of e.chars){let i=n.advanceWidth,a=n.advanceHeight;n.inlineBox.top=r,n.inlineBox.height=i,n.inlineBox.width=a,n.inlineBox.left=t+(e.thickness-a)/2,r+=this._advance(n)}r>d&&(d=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,c?t.width:l+n.left+n.right,r?t.height:d+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===`
|
|
35
35
|
`||e.content===`\r`){a();continue}let n=r.length>0?e.kerningBefore:0;t!==1/0&&r.length>0&&i+n+e.advanceWidth>t&&a(),r.length>0&&(i+=e.kerningBefore),r.push(e),i+=this._advance(e)}return a(),n}_applyKerning(e){for(let t of e){if(!t._layoutDirty)continue;let e;for(let n of t.fragments)for(let t of n.characters)t.kerningBefore=t.computeKerningBefore(e),e=t}}_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}}}dispose(){}};function yl(){let e=new Ni,t=Pi(),n=Fi(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(L(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=zi(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 jr;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;L(a.backgroundColor)||(r.fillStyle=a.backgroundColor,r.fillRect(...i.array)),e.paths.forEach(e=>{if(t.drawPath(e),n.debug){let t=new Ni([e]).getBoundingBox();t&&r.strokeRect(t.x,t.y,t.width,t.height)}}),n.paragraphs.forEach(e=>{let{lineBox:t,style:n}=e;L(n.backgroundColor)||(r.fillStyle=n.backgroundColor,r.fillRect(...t.array)),e.fragments.forEach(e=>{let{inlineBox:t,style:n}=e;L(n.backgroundColor)||(r.fillStyle=n.backgroundColor,r.fillRect(...t.array))})})}}}function bl(e,t){let{x:n,y:r}=t;if(e instanceof Di){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 Di(t,e,o),new Di(o.clone(),r,a)]}}}else if(e instanceof wi){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 wi(t,e,s,c),new wi(c.clone(),l,u,o)]}}else if(e instanceof Si){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 Si(t,new U(n,r)),new Si(new U(n,r),i)]}return[e]}var xl=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}){this.text=e,this.intensities=t.map(e=>e/100),this.lineHeight=this._maxFontSize()||n||100}_maxFontSize(){let e=0;return this.characters.forEach(t=>{t.glyphBox&&(e=Math.max(e,t.fontSize))}),e}_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=>bl(t,e?{y:o}:{x:a}))})})}_makeTheJointSmooth(){this.characters.forEach(e=>{e.glyphBox&&e.path.getFlatCurves().forEach(e=>{if(e instanceof Di&&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 Si&&e.getLength()>this.lineHeight*.05){let{p1:t,p2:n}=e,r=new Di(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()})})}),t||r?.pathSet?.paths?.forEach(t=>{t.getControlPointRefs().forEach(t=>{let[n,r]=e(t);t.set(n,r)})})}},Sl=class extends xl{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)}},Cl=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()}},wl=class extends Cl{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)}},Tl=class extends Cl{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()}},El=class extends Cl{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))}},Dl=class extends Cl{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)}},Ol=class extends wl{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 El(n,Math.SQRT1_2*this.size,-.25*Math.PI,.75*Math.PI),o=new El(r,Math.SQRT1_2*this.size,-.75*Math.PI,.25*Math.PI),s=new El(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 Tl(l,u),m=new Tl(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]}},kl=class extends wl{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 Tl(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]}},Al=class extends wl{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 Tl(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]}},jl=class extends xl{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=0,n=0]=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)}},Ml=class extends xl{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]}},Nl=new Map;function Pl(e,t){Nl.set(e,t)}function Fl(e){Nl.delete(e)}function Il(){return[...Nl.keys()]}function Ll(){return gl({name:`deformation`,updateOrder:2,update:e=>{let t=e.deformation,n=t?.type;if(L(n)||!n)return;let r=Nl.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 jl(i,r);break;case`bend`:a=new Sl(i,r);break;case`curve`:case`offset`:a=new Ml(i,r);break}e.forEachCharacter(t=>t.update(e.fonts)),a.deform();let o=e.getGlyphBox(),s=o.left,c=o.top;if(s||c){let t=e.plugins.get(`highlight`);for(let t of e.characters)t.glyphBox&&=(t.path.getControlPointRefs().forEach(e=>{e.set(e.x-s,e.y-c)}),t.getGlyphBoundingBox());t?.pathSet?.paths?.forEach(e=>{e.getControlPointRefs().forEach(e=>{e.set(e.x-s,e.y-c)})}),o=e.getGlyphBox()}e.rawGlyphBox=o,e.glyphBox=o,e.lineBox=o}})}function Rl(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 zl(){let e=new Ni,t=[],n=Pi(),r=Fi(n);return gl({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}=Rl(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=Rl(t),{image:r,colormap:s,line:c,size:l,thickness:u}=n;if(L(r))a?.length&&(a=[],i.push(a));else{let{inlineBox:n,isVertical:d}=e,{fontSize:f}=t;(!o||Vi(o.image,r)&&Vi(o.colormap,s)&&Vi(o.line,c)&&Vi(o.size,l)&&Vi(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}=Rl(c),x=Ri(b,{fontSize:m,total:s.width})/s.width,S=zi(_),{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 O=Math.floor(D.width),k=O;y!==`cover`&&(k=Ri(y,{fontSize:m,total:s.width})||O,D.width=k);let A=!L(g)&&L(v);if(A)T.copy(r.parse(g).pathSet.getBoundingBox(!0)??new W);else{let e;if(L(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 j=new jr;if(j.translate(-T.x,-T.y),j.scale(D.width/T.width,D.height/T.height),l){let e=D.width/2,t=D.height/2;A||j.translate(-e,-t),j.rotate(Math.PI/2),A||j.translate(t,e)}j.translate(D.x,D.y);for(let n=0;n<Math.ceil(O/k);n++){let r=j.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),O!==k&&(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 Ni([e]).getBoundingBox();t&&i.strokeRect(t.x,t.y,t.width,t.height)}})}})}function Bl(e,t){return`<svg width="${e*2}" height="${e*2}" xmlns="http://www.w3.org/2000/svg">
|
|
36
36
|
<circle cx="${e}" cy="${e}" r="${e}" fill="${t}" />
|
|
37
|
-
</svg>`}function Vl(){let e=new Ni;return gl({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=zi(c),f=l,p;if(!L(s))p=s;else if(!L(u)){let e=i*.38/2;switch(f=f===`cover`?e*2:f,u){case`disc`:p=Bl(e,String(o));break}}if(!p)return;let m=ci(p),h=m.getBoundingBox()??new W,g=t.fragments[0]?.characters[0];if(!g)return;let{inlineBox:_}=g,v=f===`cover`?1:Ri(f,{total:i,fontSize:i})/i,y=new jr;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 Hl(){return{name:`outline`}}function Ul(){let e=new Ni,t=[],n=[];return Object.defineProperty(e,"paths",{configurable:!0,enumerable:!0,get(){return n===null&&(n=t.map(e=>e.path)),n},set(e){n=e}}),gl({name:`render`,pathSet:e,update:r=>{let i=[],{paragraphs:a}=r;a.forEach(e=>{e.fragments.forEach(e=>{e.characters.forEach(e=>{i.push(e)})})}),t=i,n=null,e._lazyCount=i.length},getBoundingBox:e=>{let{characters:t,computedEffects:n,fontSize:r}=e,i=[];return n.forEach(n=>{let a=Ii(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 Wl(){let e=new Ni;return gl({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(L(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 Mi([{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 Mi([{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 Gl(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function Kl(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 ql=pt(),Jl=class extends he{needsUpdate=!0;computedStyle={...ql};computedFill;computedOutline;computedEffects=[];inlineBox=new W;lineBox=new W;rawGlyphBox=new W;glyphBox=new W;pathBox=new W;boundingBox=new W;measurer=new vl;plugins=new Map;pathSets=[];_paragraphs=[];_cachedCharacters;incrementalLayout=!0;_prevParagraphs=[];_prevContentKeys=[];_prevStyleKey=``;_prevFonts;_prevFontsSet=!1;_pendingContentKeys=[];_pendingStyleKey=``;_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}=St(e);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(yl()).use(Hl()).use(Vl()).use(Wl()).use(zl()).use(Ul()).use(Ll()),(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();let[e]=await Promise.all([this._decodeFonts(),...Array.from(this.plugins.values()).map(e=>e.load?.(this))]);e>0&&(this._prevParagraphs=[])}async _decodeFonts(){let e=this.fonts??Qc,t=new Set;for(let n of this.characters){let r=n.computedStyle.fontFamily;r&&t.add(e.get(r))}return t.add(e.fallbackFont),(await Promise.all(Array.from(t,async e=>{let t=e?.getFont();return t&&typeof t.createSFNTAsync==`function`&&!t._sfnt?(t._sfnt=await t.createSFNTAsync(),1):0}))).reduce((e,t)=>e+t,0)}_normalizeComputedStyle(e){let t=e;for(let e in ql){let n=ql[e];if(typeof n!=`number`)continue;let r=t[e];if(typeof r==`number`)Number.isFinite(r)||(t[e]=n);else{let i=Number.parseFloat(r);t[e]=Number.isFinite(i)?i:n}}return e}_buildParagraph(e,t){let{fragments:n,fill:r,outline:i,...a}=e,o=new hl(a,t,this);return o.fill=r,o.outline=i,n.forEach((e,t)=>{let{content:n,fill:r,outline:i,...a}=e;n!==void 0&&o.fragments.push(new ml(n,a,r,i,t,o))}),o}_canReuseLayout(e){if(!this.incrementalLayout||!this._prevParagraphs.length||e!==this._prevStyleKey||!this._prevFontsSet||this.fonts!==this._prevFonts)return!1;let t=this.computedStyle;return!(t.writingMode.includes(`vertical`)||typeof t.height==`number`&&(t.verticalAlign===`middle`||t.verticalAlign===`bottom`))}_update(){this.computedStyle=this._normalizeComputedStyle({...ql,...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=JSON.stringify([this.style,this.fill,this.outline,this.effects,this.deformation]),t=this._canReuseLayout(e),n=this.content,r=Array.from({length:n.length}),i=Array.from({length:n.length});for(let e=0;e<n.length;e++){let a=JSON.stringify(n[e]);r[e]=a;let o=this._prevParagraphs[e];if(t&&o&&o._layoutValid&&this._prevContentKeys[e]===a)o._layoutDirty=!1,i[e]=o;else{let t=this._buildParagraph(n[e],e);t._layoutDirty=!0,i[e]=t}}return this.paragraphs=i,this._pendingContentKeys=r,this._pendingStyleKey=e,this}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.paragraphs;for(let e=0;e<r.length;e++){let t=r[e];if(t._layoutDirty)for(let e of t.fragments){let t=e.characters;for(let e=0;e<t.length;e++)t[e].update(this.fonts)}}let i=this._computeGlyphBox();this.rawGlyphBox=i,this.glyphBox=i,this._prevParagraphs=this.paragraphs,this._prevContentKeys=this._pendingContentKeys,this._prevStyleKey=this._pendingStyleKey,this._prevFonts=this.fonts,this._prevFontsSet=!0;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].pathSet,n=t?._lazyCount??t?.paths.length;t&&n&&this.pathSets.push(t)}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)}_paragraphGlyphBox(e){let t=U.MAX,n=U.MIN,r=e.fragments;for(let e=0;e<r.length;e++){let i=r[e].characters;for(let e=0;e<i.length;e++){let r=i[e];if(r.getGlyphMinMax(t,n))continue;let{left:a,top:o,width:s,height:c}=r.inlineBox;t.clampMin(new U(a,o),new U(a+s,o+c)),n.clampMax(new U(a,o),new U(a+s,o+c))}}if(!(!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(n.x)||!Number.isFinite(n.y)))return new W(t.x,t.y,n.x-t.x,n.y-t.y)}_computeGlyphBox(){let e=this.paragraphs,t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r._glyphBox;(r._layoutDirty||!i)&&(i=this._paragraphGlyphBox(r),r._glyphBox=i),i&&t.push(i)}return t.length?W.from(...t):new W(0,0,0,0)}_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 Hi(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.region=e.region,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(``)}};Kl([me({internal:!0}),Gl(`design:type`,Boolean)],Jl.prototype,`debug`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`content`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`style`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`effects`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`fill`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`outline`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`deformation`,void 0),Kl([me({internal:!0}),Gl(`design:type`,typeof HTMLElement>`u`?Object:HTMLElement)],Jl.prototype,`measureDom`,void 0),Kl([me({internal:!0}),Gl(`design:type`,Object)],Jl.prototype,`fonts`,void 0);function Yl(e,t){let n=new Jl(e);return t?n.load().then(()=>n.measure()):n.measure()}function Xl(e,t){let n=new Jl(e);return t?n.load().then(()=>n.render(e)):n.render(e)}e.Canvas2DRenderer=Hi,e.Character=pl,e.CircleCurve=El,e.EllipseCurve=Dl,e.Fragment=ml,e.HeartCurve=Ol,e.Measurer=vl,e.Paragraph=hl,e.PolygonCurve=kl,e.RectangularCurve=Al,e.Text=Jl,e.backgroundPlugin=yl,e.createSvgLoader=Pi,e.createSvgParser=Fi,e.defineDeformation=Pl,e.definePlugin=gl,e.deformationPlugin=Ll,e.getDeformationNames=Il,e.getEffectTransform2D=Ii,e.getHighlightStyle=Rl,e.highlightPlugin=zl,e.isEqualObject=Bi,e.isEqualValue=Vi,e.listStylePlugin=Vl,e.measureText=Yl,e.outlinePlugin=Hl,e.parseColormap=zi,e.parseTransformOrigin=Li,e.parseValueNumber=Ri,e.removeDeformation=Fl,e.renderPlugin=Ul,e.renderText=Xl,e.textDecorationPlugin=Wl,e.textDefaultStyle=ql});
|
|
37
|
+
</svg>`}function Vl(){let e=new Ni;return gl({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=zi(c),f=l,p;if(!L(s))p=s;else if(!L(u)){let e=i*.38/2;switch(f=f===`cover`?e*2:f,u){case`disc`:p=Bl(e,String(o));break}}if(!p)return;let m=ci(p),h=m.getBoundingBox()??new W,g=t.fragments[0]?.characters[0];if(!g)return;let{inlineBox:_}=g,v=f===`cover`?1:Ri(f,{total:i,fontSize:i})/i,y=new jr;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 Hl(){return{name:`outline`}}function Ul(){let e=new Ni,t=[],n=[];return Object.defineProperty(e,"paths",{configurable:!0,enumerable:!0,get(){return n===null&&(n=t.map(e=>e.path)),n},set(e){n=e}}),gl({name:`render`,pathSet:e,update:r=>{let i=[],{paragraphs:a}=r;a.forEach(e=>{e.fragments.forEach(e=>{e.characters.forEach(e=>{i.push(e)})})}),t=i,n=null,e._lazyCount=i.length},getBoundingBox:e=>{let{characters:t,computedEffects:n,fontSize:r}=e,i=[];return n.forEach(n=>{let a=Ii(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 Wl(){let e=new Ni;return gl({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(L(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 Mi([{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 Mi([{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 Gl(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function Kl(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 ql=pt(),Jl=class extends he{needsUpdate=!0;computedStyle={...ql};computedFill;computedOutline;computedEffects=[];inlineBox=new W;lineBox=new W;rawGlyphBox=new W;glyphBox=new W;pathBox=new W;boundingBox=new W;measurer=new vl;plugins=new Map;pathSets=[];_paragraphs=[];_cachedCharacters;incrementalLayout=!0;_prevParagraphs=[];_prevContentKeys=[];_prevStyleKey=``;_prevFonts;_prevFontsSet=!1;_prevFontSig=``;_pendingFontSig=``;_pendingContentKeys=[];_pendingStyleKey=``;_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}=St(e);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(yl()).use(Hl()).use(Vl()).use(Wl()).use(zl()).use(Ul()).use(Ll()),(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();let[e]=await Promise.all([this._decodeFonts(),...Array.from(this.plugins.values()).map(e=>e.load?.(this))]);e>0&&(this._prevParagraphs=[])}async _decodeFonts(){let e=this.fonts??Qc,t=new Set;for(let n of this.characters){let r=n.computedStyle.fontFamily;r&&t.add(e.get(r))}return t.add(e.fallbackFont),(await Promise.all(Array.from(t,async e=>{let t=e?.getFont();return t&&typeof t.createSFNTAsync==`function`&&!t._sfnt?(t._sfnt=await t.createSFNTAsync(),1):0}))).reduce((e,t)=>e+t,0)}_normalizeComputedStyle(e){let t=e;for(let e in ql){let n=ql[e];if(typeof n!=`number`)continue;let r=t[e];if(typeof r==`number`)Number.isFinite(r)||(t[e]=n);else{let i=Number.parseFloat(r);t[e]=Number.isFinite(i)?i:n}}return e}_buildParagraph(e,t){let{fragments:n,fill:r,outline:i,...a}=e,o=new hl(a,t,this);return o.fill=r,o.outline=i,n.forEach((e,t)=>{let{content:n,fill:r,outline:i,...a}=e;n!==void 0&&o.fragments.push(new ml(n,a,r,i,t,o))}),o}_computeFontSig(){let e=this.fonts;if(!e?.get)return``;let t=new Set,n=this.computedStyle?.fontFamily;n&&t.add(String(n));for(let e of this.content){let n=e?.fontFamily;n&&t.add(String(n));let r=e?.fragments;if(Array.isArray(r))for(let e of r){let n=e?.fontFamily;n&&t.add(String(n))}}let r=``;for(let n of t)r+=`${n}#${e.get(n)?.src??``};`;return r}_canReuseLayout(e,t){if(!this.incrementalLayout||!this._prevParagraphs.length||e!==this._prevStyleKey||!this._prevFontsSet||this.fonts!==this._prevFonts||t!==this._prevFontSig)return!1;let n=this.computedStyle;return!(n.writingMode.includes(`vertical`)||typeof n.height==`number`&&(n.verticalAlign===`middle`||n.verticalAlign===`bottom`))}_update(){this.computedStyle=this._normalizeComputedStyle({...ql,...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=JSON.stringify([this.style,this.fill,this.outline,this.effects,this.deformation]),t=this._computeFontSig();this._pendingFontSig=t;let n=this._canReuseLayout(e,t),r=this.content,i=Array.from({length:r.length}),a=Array.from({length:r.length});for(let e=0;e<r.length;e++){let t=JSON.stringify(r[e]);i[e]=t;let o=this._prevParagraphs[e];if(n&&o&&o._layoutValid&&this._prevContentKeys[e]===t)o._layoutDirty=!1,a[e]=o;else{let t=this._buildParagraph(r[e],e);t._layoutDirty=!0,a[e]=t}}return this.paragraphs=a,this._pendingContentKeys=i,this._pendingStyleKey=e,this}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.paragraphs;for(let e=0;e<r.length;e++){let t=r[e];if(t._layoutDirty)for(let e of t.fragments){let t=e.characters;for(let e=0;e<t.length;e++)t[e].update(this.fonts)}}let i=this._computeGlyphBox();this.rawGlyphBox=i,this.glyphBox=i,this._prevParagraphs=this.paragraphs,this._prevContentKeys=this._pendingContentKeys,this._prevStyleKey=this._pendingStyleKey,this._prevFonts=this.fonts,this._prevFontsSet=!0,this._prevFontSig=this._pendingFontSig;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].pathSet,n=t?._lazyCount??t?.paths.length;t&&n&&this.pathSets.push(t)}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)}_paragraphGlyphBox(e){let t=U.MAX,n=U.MIN,r=e.fragments;for(let e=0;e<r.length;e++){let i=r[e].characters;for(let e=0;e<i.length;e++){let r=i[e];if(r.getGlyphMinMax(t,n))continue;let{left:a,top:o,width:s,height:c}=r.inlineBox;t.clampMin(new U(a,o),new U(a+s,o+c)),n.clampMax(new U(a,o),new U(a+s,o+c))}}if(!(!Number.isFinite(t.x)||!Number.isFinite(t.y)||!Number.isFinite(n.x)||!Number.isFinite(n.y)))return new W(t.x,t.y,n.x-t.x,n.y-t.y)}_computeGlyphBox(){let e=this.paragraphs,t=[];for(let n=0;n<e.length;n++){let r=e[n],i=r._glyphBox;(r._layoutDirty||!i)&&(i=this._paragraphGlyphBox(r),r._glyphBox=i),i&&t.push(i)}return t.length?W.from(...t):new W(0,0,0,0)}_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 Hi(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.region=e.region,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(``)}};Kl([me({internal:!0}),Gl(`design:type`,Boolean)],Jl.prototype,`debug`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`content`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`style`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`effects`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`fill`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`outline`,void 0),Kl([me(),Gl(`design:type`,Object)],Jl.prototype,`deformation`,void 0),Kl([me({internal:!0}),Gl(`design:type`,typeof HTMLElement>`u`?Object:HTMLElement)],Jl.prototype,`measureDom`,void 0),Kl([me({internal:!0}),Gl(`design:type`,Object)],Jl.prototype,`fonts`,void 0);function Yl(e,t){let n=new Jl(e);return t?n.load().then(()=>n.measure()):n.measure()}function Xl(e,t){let n=new Jl(e);return t?n.load().then(()=>n.render(e)):n.render(e)}e.Canvas2DRenderer=Hi,e.Character=pl,e.CircleCurve=El,e.EllipseCurve=Dl,e.Fragment=ml,e.HeartCurve=Ol,e.Measurer=vl,e.Paragraph=hl,e.PolygonCurve=kl,e.RectangularCurve=Al,e.Text=Jl,e.backgroundPlugin=yl,e.createSvgLoader=Pi,e.createSvgParser=Fi,e.defineDeformation=Pl,e.definePlugin=gl,e.deformationPlugin=Ll,e.getDeformationNames=Il,e.getEffectTransform2D=Ii,e.getHighlightStyle=Rl,e.highlightPlugin=zl,e.isEqualObject=Bi,e.isEqualValue=Vi,e.listStylePlugin=Vl,e.measureText=Yl,e.outlinePlugin=Hl,e.parseColormap=zi,e.parseTransformOrigin=Li,e.parseValueNumber=Ri,e.removeDeformation=Fl,e.renderPlugin=Ul,e.renderText=Xl,e.textDecorationPlugin=Wl,e.textDefaultStyle=ql});
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as Text } from './shared/modern-text.
|
|
2
|
-
export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, c as createSvgLoader, d as createSvgParser, g as getEffectTransform2D, e as getHighlightStyle, h as highlightPlugin, i as isEqualObject, f as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, j as parseTransformOrigin, k as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, m as textDefaultStyle } from './shared/modern-text.
|
|
1
|
+
import { T as Text } from './shared/modern-text.Dz4np_87.mjs';
|
|
2
|
+
export { C as Canvas2DRenderer, a as Character, F as Fragment, M as Measurer, P as Paragraph, b as backgroundPlugin, c as createSvgLoader, d as createSvgParser, g as getEffectTransform2D, e as getHighlightStyle, h as highlightPlugin, i as isEqualObject, f as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, j as parseTransformOrigin, k as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, m as textDefaultStyle } from './shared/modern-text.Dz4np_87.mjs';
|
|
3
3
|
export { d as defineDeformation, a as definePlugin, b as deformationPlugin, g as getDeformationNames, r as removeDeformation } from './shared/modern-text.Cvc61q2w.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
5
|
import 'modern-font';
|
|
@@ -262,6 +262,8 @@ declare class Text extends Reactivable {
|
|
|
262
262
|
protected _prevStyleKey: string;
|
|
263
263
|
protected _prevFonts: unknown;
|
|
264
264
|
protected _prevFontsSet: boolean;
|
|
265
|
+
protected _prevFontSig: string;
|
|
266
|
+
protected _pendingFontSig: string;
|
|
265
267
|
protected _pendingContentKeys: string[];
|
|
266
268
|
protected _pendingStyleKey: string;
|
|
267
269
|
protected _pluginsByUpdateOrder: Plugin[];
|
|
@@ -307,7 +309,14 @@ declare class Text extends Reactivable {
|
|
|
307
309
|
*/
|
|
308
310
|
protected _normalizeComputedStyle(style: FullStyle): FullStyle;
|
|
309
311
|
protected _buildParagraph(p: NormalizedText['content'][number], pIndex: number): Paragraph;
|
|
310
|
-
|
|
312
|
+
/**
|
|
313
|
+
* 本文本「已用字体族 → 当前解析到的字体源」的签名。
|
|
314
|
+
* 遍历根/段落/片段声明的 fontFamily,各取 `fonts.get(family)?.src`(modern-font 里每个已加载字体/兜底
|
|
315
|
+
* 字体的唯一源标识)拼成签名。某族未加载时 `get` 返回兜底字体(其 src 如 modern-font:embedded-fallback),
|
|
316
|
+
* 加载完成后返回该字体(src=字体 URL)→ src 变化 → 签名变化,据此可靠感知「字体到位」并作废增量复用。
|
|
317
|
+
*/
|
|
318
|
+
protected _computeFontSig(): string;
|
|
319
|
+
protected _canReuseLayout(styleKey: string, fontSig: string): boolean;
|
|
311
320
|
protected _update(): this;
|
|
312
321
|
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
313
322
|
getGlyphBox(): BoundingBox;
|
|
@@ -262,6 +262,8 @@ declare class Text extends Reactivable {
|
|
|
262
262
|
protected _prevStyleKey: string;
|
|
263
263
|
protected _prevFonts: unknown;
|
|
264
264
|
protected _prevFontsSet: boolean;
|
|
265
|
+
protected _prevFontSig: string;
|
|
266
|
+
protected _pendingFontSig: string;
|
|
265
267
|
protected _pendingContentKeys: string[];
|
|
266
268
|
protected _pendingStyleKey: string;
|
|
267
269
|
protected _pluginsByUpdateOrder: Plugin[];
|
|
@@ -307,7 +309,14 @@ declare class Text extends Reactivable {
|
|
|
307
309
|
*/
|
|
308
310
|
protected _normalizeComputedStyle(style: FullStyle): FullStyle;
|
|
309
311
|
protected _buildParagraph(p: NormalizedText['content'][number], pIndex: number): Paragraph;
|
|
310
|
-
|
|
312
|
+
/**
|
|
313
|
+
* 本文本「已用字体族 → 当前解析到的字体源」的签名。
|
|
314
|
+
* 遍历根/段落/片段声明的 fontFamily,各取 `fonts.get(family)?.src`(modern-font 里每个已加载字体/兜底
|
|
315
|
+
* 字体的唯一源标识)拼成签名。某族未加载时 `get` 返回兜底字体(其 src 如 modern-font:embedded-fallback),
|
|
316
|
+
* 加载完成后返回该字体(src=字体 URL)→ src 变化 → 签名变化,据此可靠感知「字体到位」并作废增量复用。
|
|
317
|
+
*/
|
|
318
|
+
protected _computeFontSig(): string;
|
|
319
|
+
protected _canReuseLayout(styleKey: string, fontSig: string): boolean;
|
|
311
320
|
protected _update(): this;
|
|
312
321
|
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
313
322
|
getGlyphBox(): BoundingBox;
|
|
@@ -262,6 +262,8 @@ declare class Text extends Reactivable {
|
|
|
262
262
|
protected _prevStyleKey: string;
|
|
263
263
|
protected _prevFonts: unknown;
|
|
264
264
|
protected _prevFontsSet: boolean;
|
|
265
|
+
protected _prevFontSig: string;
|
|
266
|
+
protected _pendingFontSig: string;
|
|
265
267
|
protected _pendingContentKeys: string[];
|
|
266
268
|
protected _pendingStyleKey: string;
|
|
267
269
|
protected _pluginsByUpdateOrder: Plugin[];
|
|
@@ -307,7 +309,14 @@ declare class Text extends Reactivable {
|
|
|
307
309
|
*/
|
|
308
310
|
protected _normalizeComputedStyle(style: FullStyle): FullStyle;
|
|
309
311
|
protected _buildParagraph(p: NormalizedText['content'][number], pIndex: number): Paragraph;
|
|
310
|
-
|
|
312
|
+
/**
|
|
313
|
+
* 本文本「已用字体族 → 当前解析到的字体源」的签名。
|
|
314
|
+
* 遍历根/段落/片段声明的 fontFamily,各取 `fonts.get(family)?.src`(modern-font 里每个已加载字体/兜底
|
|
315
|
+
* 字体的唯一源标识)拼成签名。某族未加载时 `get` 返回兜底字体(其 src 如 modern-font:embedded-fallback),
|
|
316
|
+
* 加载完成后返回该字体(src=字体 URL)→ src 变化 → 签名变化,据此可靠感知「字体到位」并作废增量复用。
|
|
317
|
+
*/
|
|
318
|
+
protected _computeFontSig(): string;
|
|
319
|
+
protected _canReuseLayout(styleKey: string, fontSig: string): boolean;
|
|
311
320
|
protected _update(): this;
|
|
312
321
|
measure(dom?: HTMLElement | undefined): MeasureResult;
|
|
313
322
|
getGlyphBox(): BoundingBox;
|
|
@@ -2026,6 +2026,11 @@ class Text extends modernIdoc.Reactivable {
|
|
|
2026
2026
|
// (否则会复用「fonts 未就绪」时测得的零宽字形)。
|
|
2027
2027
|
_prevFonts;
|
|
2028
2028
|
_prevFontsSet = false;
|
|
2029
|
+
// 字体解析签名(见 _computeFontSig):Fonts 容器引用不变、但某字体族从 fallback 变为已加载时,
|
|
2030
|
+
// 其解析结果会变 → 签名变 → 作废增量复用。修复「字体异步加载完文字不重排、须手动激活才生效」的根因
|
|
2031
|
+
// (原先只比较 fonts 容器引用,往同一实例新增字体时引用不变,永远测不出字体到位)。
|
|
2032
|
+
_prevFontSig = "";
|
|
2033
|
+
_pendingFontSig = "";
|
|
2029
2034
|
// _update 计算出的待提交快照;仅在 measure() 真正完成测量后才提交到 _prev*(见 measure),
|
|
2030
2035
|
// 否则构造函数里的 _update(只建树不测量)会让首测误把未测量段当作可复用。
|
|
2031
2036
|
_pendingContentKeys = [];
|
|
@@ -2204,9 +2209,46 @@ class Text extends modernIdoc.Reactivable {
|
|
|
2204
2209
|
});
|
|
2205
2210
|
return paragraph;
|
|
2206
2211
|
}
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2212
|
+
/**
|
|
2213
|
+
* 本文本「已用字体族 → 当前解析到的字体源」的签名。
|
|
2214
|
+
* 遍历根/段落/片段声明的 fontFamily,各取 `fonts.get(family)?.src`(modern-font 里每个已加载字体/兜底
|
|
2215
|
+
* 字体的唯一源标识)拼成签名。某族未加载时 `get` 返回兜底字体(其 src 如 modern-font:embedded-fallback),
|
|
2216
|
+
* 加载完成后返回该字体(src=字体 URL)→ src 变化 → 签名变化,据此可靠感知「字体到位」并作废增量复用。
|
|
2217
|
+
*/
|
|
2218
|
+
_computeFontSig() {
|
|
2219
|
+
const fonts = this.fonts;
|
|
2220
|
+
if (!fonts?.get) {
|
|
2221
|
+
return "";
|
|
2222
|
+
}
|
|
2223
|
+
const families = /* @__PURE__ */ new Set();
|
|
2224
|
+
const rootFamily = this.computedStyle?.fontFamily;
|
|
2225
|
+
if (rootFamily) {
|
|
2226
|
+
families.add(String(rootFamily));
|
|
2227
|
+
}
|
|
2228
|
+
for (const para of this.content) {
|
|
2229
|
+
const pFamily = para?.fontFamily;
|
|
2230
|
+
if (pFamily) {
|
|
2231
|
+
families.add(String(pFamily));
|
|
2232
|
+
}
|
|
2233
|
+
const fragments = para?.fragments;
|
|
2234
|
+
if (Array.isArray(fragments)) {
|
|
2235
|
+
for (const frag of fragments) {
|
|
2236
|
+
const fFamily = frag?.fontFamily;
|
|
2237
|
+
if (fFamily) {
|
|
2238
|
+
families.add(String(fFamily));
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
}
|
|
2243
|
+
let sig = "";
|
|
2244
|
+
for (const family of families) {
|
|
2245
|
+
sig += `${family}#${fonts.get(family)?.src ?? ""};`;
|
|
2246
|
+
}
|
|
2247
|
+
return sig;
|
|
2248
|
+
}
|
|
2249
|
+
// 仅当根级样式/填充/描边/特效/形变未变、字体解析结果未变、且非竖排、非块级垂直对齐位移时,才允许复用未变段落
|
|
2250
|
+
// (这些会改变各段 computedStyle、字形度量或全局位移,复用会得到错误结果)。
|
|
2251
|
+
_canReuseLayout(styleKey, fontSig) {
|
|
2210
2252
|
if (!this.incrementalLayout || !this._prevParagraphs.length) {
|
|
2211
2253
|
return false;
|
|
2212
2254
|
}
|
|
@@ -2216,6 +2258,9 @@ class Text extends modernIdoc.Reactivable {
|
|
|
2216
2258
|
if (!this._prevFontsSet || this.fonts !== this._prevFonts) {
|
|
2217
2259
|
return false;
|
|
2218
2260
|
}
|
|
2261
|
+
if (fontSig !== this._prevFontSig) {
|
|
2262
|
+
return false;
|
|
2263
|
+
}
|
|
2219
2264
|
const cs = this.computedStyle;
|
|
2220
2265
|
if (cs.writingMode.includes("vertical")) {
|
|
2221
2266
|
return false;
|
|
@@ -2231,7 +2276,9 @@ class Text extends modernIdoc.Reactivable {
|
|
|
2231
2276
|
this.computedOutline = this.outline ? { ...this.outline } : void 0;
|
|
2232
2277
|
this.computedEffects = this.effects?.map((v) => v) ?? [];
|
|
2233
2278
|
const styleKey = JSON.stringify([this.style, this.fill, this.outline, this.effects, this.deformation]);
|
|
2234
|
-
const
|
|
2279
|
+
const fontSig = this._computeFontSig();
|
|
2280
|
+
this._pendingFontSig = fontSig;
|
|
2281
|
+
const reuse = this._canReuseLayout(styleKey, fontSig);
|
|
2235
2282
|
const content = this.content;
|
|
2236
2283
|
const contentKeys = Array.from({ length: content.length });
|
|
2237
2284
|
const paragraphs = Array.from({ length: content.length });
|
|
@@ -2288,6 +2335,7 @@ class Text extends modernIdoc.Reactivable {
|
|
|
2288
2335
|
this._prevStyleKey = this._pendingStyleKey;
|
|
2289
2336
|
this._prevFonts = this.fonts;
|
|
2290
2337
|
this._prevFontsSet = true;
|
|
2338
|
+
this._prevFontSig = this._pendingFontSig;
|
|
2291
2339
|
const updatePlugins = this._pluginsByUpdateOrder;
|
|
2292
2340
|
for (let i = 0; i < updatePlugins.length; i++) {
|
|
2293
2341
|
updatePlugins[i].update?.(this);
|
|
@@ -2024,6 +2024,11 @@ class Text extends Reactivable {
|
|
|
2024
2024
|
// (否则会复用「fonts 未就绪」时测得的零宽字形)。
|
|
2025
2025
|
_prevFonts;
|
|
2026
2026
|
_prevFontsSet = false;
|
|
2027
|
+
// 字体解析签名(见 _computeFontSig):Fonts 容器引用不变、但某字体族从 fallback 变为已加载时,
|
|
2028
|
+
// 其解析结果会变 → 签名变 → 作废增量复用。修复「字体异步加载完文字不重排、须手动激活才生效」的根因
|
|
2029
|
+
// (原先只比较 fonts 容器引用,往同一实例新增字体时引用不变,永远测不出字体到位)。
|
|
2030
|
+
_prevFontSig = "";
|
|
2031
|
+
_pendingFontSig = "";
|
|
2027
2032
|
// _update 计算出的待提交快照;仅在 measure() 真正完成测量后才提交到 _prev*(见 measure),
|
|
2028
2033
|
// 否则构造函数里的 _update(只建树不测量)会让首测误把未测量段当作可复用。
|
|
2029
2034
|
_pendingContentKeys = [];
|
|
@@ -2202,9 +2207,46 @@ class Text extends Reactivable {
|
|
|
2202
2207
|
});
|
|
2203
2208
|
return paragraph;
|
|
2204
2209
|
}
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2210
|
+
/**
|
|
2211
|
+
* 本文本「已用字体族 → 当前解析到的字体源」的签名。
|
|
2212
|
+
* 遍历根/段落/片段声明的 fontFamily,各取 `fonts.get(family)?.src`(modern-font 里每个已加载字体/兜底
|
|
2213
|
+
* 字体的唯一源标识)拼成签名。某族未加载时 `get` 返回兜底字体(其 src 如 modern-font:embedded-fallback),
|
|
2214
|
+
* 加载完成后返回该字体(src=字体 URL)→ src 变化 → 签名变化,据此可靠感知「字体到位」并作废增量复用。
|
|
2215
|
+
*/
|
|
2216
|
+
_computeFontSig() {
|
|
2217
|
+
const fonts = this.fonts;
|
|
2218
|
+
if (!fonts?.get) {
|
|
2219
|
+
return "";
|
|
2220
|
+
}
|
|
2221
|
+
const families = /* @__PURE__ */ new Set();
|
|
2222
|
+
const rootFamily = this.computedStyle?.fontFamily;
|
|
2223
|
+
if (rootFamily) {
|
|
2224
|
+
families.add(String(rootFamily));
|
|
2225
|
+
}
|
|
2226
|
+
for (const para of this.content) {
|
|
2227
|
+
const pFamily = para?.fontFamily;
|
|
2228
|
+
if (pFamily) {
|
|
2229
|
+
families.add(String(pFamily));
|
|
2230
|
+
}
|
|
2231
|
+
const fragments = para?.fragments;
|
|
2232
|
+
if (Array.isArray(fragments)) {
|
|
2233
|
+
for (const frag of fragments) {
|
|
2234
|
+
const fFamily = frag?.fontFamily;
|
|
2235
|
+
if (fFamily) {
|
|
2236
|
+
families.add(String(fFamily));
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
let sig = "";
|
|
2242
|
+
for (const family of families) {
|
|
2243
|
+
sig += `${family}#${fonts.get(family)?.src ?? ""};`;
|
|
2244
|
+
}
|
|
2245
|
+
return sig;
|
|
2246
|
+
}
|
|
2247
|
+
// 仅当根级样式/填充/描边/特效/形变未变、字体解析结果未变、且非竖排、非块级垂直对齐位移时,才允许复用未变段落
|
|
2248
|
+
// (这些会改变各段 computedStyle、字形度量或全局位移,复用会得到错误结果)。
|
|
2249
|
+
_canReuseLayout(styleKey, fontSig) {
|
|
2208
2250
|
if (!this.incrementalLayout || !this._prevParagraphs.length) {
|
|
2209
2251
|
return false;
|
|
2210
2252
|
}
|
|
@@ -2214,6 +2256,9 @@ class Text extends Reactivable {
|
|
|
2214
2256
|
if (!this._prevFontsSet || this.fonts !== this._prevFonts) {
|
|
2215
2257
|
return false;
|
|
2216
2258
|
}
|
|
2259
|
+
if (fontSig !== this._prevFontSig) {
|
|
2260
|
+
return false;
|
|
2261
|
+
}
|
|
2217
2262
|
const cs = this.computedStyle;
|
|
2218
2263
|
if (cs.writingMode.includes("vertical")) {
|
|
2219
2264
|
return false;
|
|
@@ -2229,7 +2274,9 @@ class Text extends Reactivable {
|
|
|
2229
2274
|
this.computedOutline = this.outline ? { ...this.outline } : void 0;
|
|
2230
2275
|
this.computedEffects = this.effects?.map((v) => v) ?? [];
|
|
2231
2276
|
const styleKey = JSON.stringify([this.style, this.fill, this.outline, this.effects, this.deformation]);
|
|
2232
|
-
const
|
|
2277
|
+
const fontSig = this._computeFontSig();
|
|
2278
|
+
this._pendingFontSig = fontSig;
|
|
2279
|
+
const reuse = this._canReuseLayout(styleKey, fontSig);
|
|
2233
2280
|
const content = this.content;
|
|
2234
2281
|
const contentKeys = Array.from({ length: content.length });
|
|
2235
2282
|
const paragraphs = Array.from({ length: content.length });
|
|
@@ -2286,6 +2333,7 @@ class Text extends Reactivable {
|
|
|
2286
2333
|
this._prevStyleKey = this._pendingStyleKey;
|
|
2287
2334
|
this._prevFonts = this.fonts;
|
|
2288
2335
|
this._prevFontsSet = true;
|
|
2336
|
+
this._prevFontSig = this._pendingFontSig;
|
|
2289
2337
|
const updatePlugins = this._pluginsByUpdateOrder;
|
|
2290
2338
|
for (let i = 0; i < updatePlugins.length; i++) {
|
|
2291
2339
|
updatePlugins[i].update?.(this);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const diff = require('diff');
|
|
4
4
|
const modernIdoc = require('modern-idoc');
|
|
5
|
-
const Text = require('../shared/modern-text.
|
|
5
|
+
const Text = require('../shared/modern-text.CJSp_eBm.cjs');
|
|
6
6
|
require('modern-font');
|
|
7
7
|
require('modern-path2d');
|
|
8
8
|
require('../shared/modern-text.B1qEGvHu.cjs');
|
|
@@ -1,6 +1,6 @@
|
|
|
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.
|
|
3
|
+
import { T as Text } from '../shared/modern-text.Dz4np_87.mjs';
|
|
4
4
|
import 'modern-font';
|
|
5
5
|
import 'modern-path2d';
|
|
6
6
|
import '../shared/modern-text.Cvc61q2w.mjs';
|