modern-text 1.12.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.
@@ -57,6 +57,16 @@ declare class Character {
57
57
  constructor(content: string, index: number, parent: Fragment);
58
58
  protected _getFontSFNT(fonts?: Fonts): SFNT | undefined;
59
59
  updateGlyph(sfnt?: SFNT | undefined): this;
60
+ /**
61
+ * Populate glyph metrics only (advance width/height, ascender/descender,
62
+ * baseline, …) without building the glyph `path` or touching boxes.
63
+ *
64
+ * The DOM {@link DomMeasurer} never needs this — it reads positions back from the
65
+ * browser. A pure-JS measurer (e.g. `FontMeasurer`) must know advances *before*
66
+ * it can place characters, so it calls this ahead of layout. `update()` later
67
+ * recomputes the same metrics while building the path, so this is idempotent.
68
+ */
69
+ measureGlyph(fonts?: Fonts): this;
60
70
  update(fonts?: Fonts): this;
61
71
  protected _italic(path: Path2D, startPoint?: Vector2Like): void;
62
72
  getGlyphMinMax(min?: Vector2, max?: Vector2, withStyle?: boolean): {
@@ -66,24 +76,6 @@ declare class Character {
66
76
  getGlyphBoundingBox(withStyle?: boolean): BoundingBox | undefined;
67
77
  }
68
78
 
69
- interface Plugin {
70
- name: string;
71
- pathSet?: Path2DSet;
72
- getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
73
- update?: (text: Text$1) => void;
74
- updateOrder?: number;
75
- render?: (renderer: Canvas2DRenderer) => void;
76
- renderOrder?: number;
77
- load?: (text: Text$1) => Promise<void>;
78
- context?: Record<string, any>;
79
- }
80
- interface Options extends TextObject {
81
- debug?: boolean;
82
- measureDom?: HTMLElement;
83
- fonts?: Fonts;
84
- plugins?: Plugin[];
85
- }
86
-
87
79
  interface MeasuredParagraph {
88
80
  paragraphIndex: number;
89
81
  left: number;
@@ -127,7 +119,7 @@ interface RootDomStyles {
127
119
  section: Record<string, any>;
128
120
  ul: Record<string, any>;
129
121
  }
130
- declare class Measurer {
122
+ declare class DomMeasurer {
131
123
  static notZeroStyles: Set<string>;
132
124
  static pxStyles: Set<string>;
133
125
  protected _styleCache: WeakMap<object, Record<string, any>>;
@@ -166,6 +158,47 @@ declare class Measurer {
166
158
  dispose(): void;
167
159
  }
168
160
 
161
+ interface Plugin {
162
+ name: string;
163
+ pathSet?: Path2DSet;
164
+ getBoundingBox?: (text: Text$1) => BoundingBox | undefined;
165
+ update?: (text: Text$1) => void;
166
+ updateOrder?: number;
167
+ render?: (renderer: Canvas2DRenderer) => void;
168
+ renderOrder?: number;
169
+ load?: (text: Text$1) => Promise<void>;
170
+ context?: Record<string, any>;
171
+ }
172
+ /**
173
+ * Pluggable layout backend. Implementations fill the four-level boxes
174
+ * (`character.inlineBox`/`lineBox`, `fragment.inlineBox`, `paragraph.lineBox`)
175
+ * in place and return the overall bounding box.
176
+ *
177
+ * - `DomMeasurer` — DOM-based, uses the browser as ground truth (default).
178
+ * - `FontMeasurer` — pure-JS, DOM-free; needs `fonts` to resolve glyph advances.
179
+ *
180
+ * `fonts` is passed positionally by `Text.measure()`; DOM-based measurers ignore
181
+ * it (a method may safely declare fewer parameters than the interface).
182
+ */
183
+ interface TextMeasurer {
184
+ measure: (paragraphs: Paragraph[], rootStyle: FullStyle, dom?: HTMLElement, fonts?: Fonts) => MeasureDomResult;
185
+ createDom?: (paragraphs: Paragraph[], rootStyle: FullStyle) => HTMLElement;
186
+ dispose?: () => void;
187
+ }
188
+ /** Built-in layout backends. `'font'` → `FontMeasurer`, `'dom'` → `DomMeasurer`. */
189
+ type MeasurerKind = 'dom' | 'font';
190
+ interface Options extends TextObject {
191
+ debug?: boolean;
192
+ measureDom?: HTMLElement;
193
+ fonts?: Fonts;
194
+ plugins?: Plugin[];
195
+ /**
196
+ * Layout backend: `'font'` (pure-JS) or `'dom'` (browser), or a custom
197
+ * `TextMeasurer`. Defaults to `'font'` when `fonts` are provided, else `'dom'`.
198
+ */
199
+ measurer?: MeasurerKind | TextMeasurer;
200
+ }
201
+
169
202
  interface RenderOptions {
170
203
  view: HTMLCanvasElement;
171
204
  pixelRatio?: number;
@@ -221,7 +254,7 @@ declare class Text$1 extends Reactivable {
221
254
  glyphBox: BoundingBox;
222
255
  pathBox: BoundingBox;
223
256
  boundingBox: BoundingBox;
224
- measurer: Measurer;
257
+ measurer: TextMeasurer;
225
258
  plugins: Map<string, Plugin>;
226
259
  pathSets: Path2DSet[];
227
260
  protected _paragraphs: Paragraph[];
@@ -246,6 +279,15 @@ declare class Text$1 extends Reactivable {
246
279
  characterIndex: number;
247
280
  }) => void): this;
248
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>;
249
291
  protected _update(): this;
250
292
  createDom(): HTMLElement;
251
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -304,5 +346,5 @@ declare class Canvas2DRenderer {
304
346
  drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
305
347
  }
306
348
 
307
- export { Canvas2DRenderer as C, Fragment as F, Paragraph as P, Text$1 as T, Character as a, Measurer as g, textDefaultStyle as t };
308
- export type { DrawShapePathsOptions as D, MeasureDomResult as M, Options as O, RenderOptions as R, MeasureResult as b, MeasuredCharacter as c, MeasuredCharacterRect as d, MeasuredFragment as e, MeasuredParagraph as f, Plugin as h, TextEvents as i };
349
+ export { Canvas2DRenderer as C, DomMeasurer as D, Fragment as F, Paragraph as P, Text$1 as T, Character as a, textDefaultStyle as t };
350
+ export type { MeasureDomResult as M, Options as O, RenderOptions as R, DrawShapePathsOptions as b, MeasureResult as c, MeasuredCharacter as d, MeasuredCharacterRect as e, MeasuredFragment as f, MeasuredParagraph as g, MeasurerKind as h, Plugin as i, TextEvents as j, TextMeasurer as k };
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.C8g4NZgY.cjs';
2
+ import { a as Character } from './modern-text.C6VOXPvn.mjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -1,7 +1,7 @@
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
4
  import { a as definePlugin, b as deformationPlugin } from './modern-text.JF1ny7A-.mjs';
4
- import { fonts } from 'modern-font';
5
5
 
6
6
  function createSvgLoader() {
7
7
  const loaded = /* @__PURE__ */ new Map();
@@ -529,6 +529,18 @@ class Character {
529
529
  this.fontStyle = fsSelectionMap[os2.fsSelection] ?? macStyleMap[head.macStyle];
530
530
  return this;
531
531
  }
532
+ /**
533
+ * Populate glyph metrics only (advance width/height, ascender/descender,
534
+ * baseline, …) without building the glyph `path` or touching boxes.
535
+ *
536
+ * The DOM {@link DomMeasurer} never needs this — it reads positions back from the
537
+ * browser. A pure-JS measurer (e.g. `FontMeasurer`) must know advances *before*
538
+ * it can place characters, so it calls this ahead of layout. `update()` later
539
+ * recomputes the same metrics while building the path, so this is idempotent.
540
+ */
541
+ measureGlyph(fonts) {
542
+ return this.updateGlyph(this._getFontSFNT(fonts));
543
+ }
532
544
  update(fonts) {
533
545
  const sfnt = this._getFontSFNT(fonts);
534
546
  if (!sfnt) {
@@ -721,7 +733,7 @@ function getSharedContainer() {
721
733
  sharedContainer = container;
722
734
  return container;
723
735
  }
724
- class Measurer {
736
+ class DomMeasurer {
725
737
  static notZeroStyles = /* @__PURE__ */ new Set([
726
738
  "width",
727
739
  "height"
@@ -756,7 +768,7 @@ class Measurer {
756
768
  return cached;
757
769
  }
758
770
  const domStyle = {};
759
- const { notZeroStyles, pxStyles } = Measurer;
771
+ const { notZeroStyles, pxStyles } = DomMeasurer;
760
772
  for (const key in style) {
761
773
  const value = style[key];
762
774
  if (notZeroStyles.has(key) && value === 0) {
@@ -1065,6 +1077,253 @@ class Measurer {
1065
1077
  }
1066
1078
  }
1067
1079
 
1080
+ function side(style, name, edge) {
1081
+ return style[`${name}${edge}`] ?? style[name] ?? 0;
1082
+ }
1083
+ class FontMeasurer {
1084
+ measure(paragraphs, rootStyle, _dom, fonts$1) {
1085
+ const _fonts = fonts$1 ?? fonts;
1086
+ for (const paragraph of paragraphs) {
1087
+ for (const fragment of paragraph.fragments) {
1088
+ for (const character of fragment.characters) {
1089
+ character.measureGlyph(_fonts);
1090
+ }
1091
+ }
1092
+ }
1093
+ return rootStyle.writingMode.includes("vertical") ? this._measureVertical(paragraphs, rootStyle) : this._measureHorizontal(paragraphs, rootStyle);
1094
+ }
1095
+ _rootPadding(rootStyle) {
1096
+ return {
1097
+ top: side(rootStyle, "padding", "Top"),
1098
+ right: side(rootStyle, "padding", "Right"),
1099
+ bottom: side(rootStyle, "padding", "Bottom"),
1100
+ left: side(rootStyle, "padding", "Left")
1101
+ };
1102
+ }
1103
+ _measureHorizontal(paragraphs, rootStyle) {
1104
+ const rootPad = this._rootPadding(rootStyle);
1105
+ const hasWidth = typeof rootStyle.width === "number";
1106
+ const availWidth = hasWidth ? rootStyle.width - rootPad.left - rootPad.right : Infinity;
1107
+ let y = rootPad.top;
1108
+ let maxRight = rootPad.left;
1109
+ for (const paragraph of paragraphs) {
1110
+ const pStyle = paragraph.computedStyle;
1111
+ const pBox = paragraph.style;
1112
+ const mTop = side(pBox, "margin", "Top");
1113
+ const mBottom = side(pBox, "margin", "Bottom");
1114
+ const mLeft = side(pBox, "margin", "Left");
1115
+ const mRight = side(pBox, "margin", "Right");
1116
+ const pTop = side(pBox, "padding", "Top");
1117
+ const pBottom = side(pBox, "padding", "Bottom");
1118
+ const pLeft = side(pBox, "padding", "Left");
1119
+ const pRight = side(pBox, "padding", "Right");
1120
+ const liLeft = rootPad.left + mLeft + pLeft;
1121
+ const liAvail = availWidth === Infinity ? Infinity : availWidth - mLeft - mRight - pLeft - pRight;
1122
+ y += mTop + pTop;
1123
+ const paraTop = y;
1124
+ let paraRight = liLeft;
1125
+ const lines = this._breakLines(paragraph, liAvail);
1126
+ const align = pStyle.textAlign;
1127
+ const indent = pStyle.textIndent ?? 0;
1128
+ for (let i = 0; i < lines.length; i++) {
1129
+ const line = lines[i];
1130
+ const lineIndent = i === 0 ? indent : 0;
1131
+ let lineHeight = pStyle.fontSize * pStyle.lineHeight;
1132
+ let contentWidth = 0;
1133
+ for (const c of line) {
1134
+ if (c.fontHeight > lineHeight) {
1135
+ lineHeight = c.fontHeight;
1136
+ }
1137
+ contentWidth += this._advance(c);
1138
+ }
1139
+ let x = liLeft + lineIndent;
1140
+ if (liAvail !== Infinity) {
1141
+ const slack = liAvail - lineIndent - contentWidth;
1142
+ if (align === "center") {
1143
+ x += slack / 2;
1144
+ } else if (align === "end" || align === "right") {
1145
+ x += slack;
1146
+ }
1147
+ }
1148
+ for (const c of line) {
1149
+ const adv = c.advanceWidth;
1150
+ const contentHeight = c.advanceHeight;
1151
+ const fontHeight = c.fontHeight;
1152
+ c.inlineBox.left = x;
1153
+ c.inlineBox.top = y + (lineHeight - contentHeight) / 2;
1154
+ c.inlineBox.width = adv;
1155
+ c.inlineBox.height = contentHeight;
1156
+ c.lineBox.left = x;
1157
+ c.lineBox.top = c.inlineBox.top + (contentHeight - fontHeight) / 2;
1158
+ c.lineBox.width = adv;
1159
+ c.lineBox.height = fontHeight;
1160
+ x += this._advance(c);
1161
+ }
1162
+ if (x > paraRight) {
1163
+ paraRight = x;
1164
+ }
1165
+ y += lineHeight;
1166
+ }
1167
+ if (paraRight > maxRight) {
1168
+ maxRight = paraRight;
1169
+ }
1170
+ for (const fragment of paragraph.fragments) {
1171
+ this._unionInto(fragment.inlineBox, fragment.characters.map((c) => c.inlineBox));
1172
+ }
1173
+ paragraph.lineBox.left = liLeft;
1174
+ paragraph.lineBox.top = paraTop;
1175
+ paragraph.lineBox.width = liAvail === Infinity ? paraRight - liLeft : liAvail;
1176
+ paragraph.lineBox.height = y - paraTop;
1177
+ y += pBottom + mBottom;
1178
+ }
1179
+ const contentBottom = y + rootPad.bottom;
1180
+ const totalWidth = hasWidth ? rootStyle.width : maxRight + rootPad.right;
1181
+ const totalHeight = typeof rootStyle.height === "number" ? rootStyle.height : contentBottom;
1182
+ if (typeof rootStyle.height === "number") {
1183
+ const slack = totalHeight - contentBottom;
1184
+ const va = rootStyle.verticalAlign;
1185
+ const dy = va === "middle" ? slack / 2 : va === "bottom" ? slack : 0;
1186
+ if (dy) {
1187
+ this._shiftAll(paragraphs, dy);
1188
+ }
1189
+ }
1190
+ return {
1191
+ paragraphs,
1192
+ boundingBox: new BoundingBox(0, 0, totalWidth, totalHeight)
1193
+ };
1194
+ }
1195
+ /**
1196
+ * Vertical writing-mode (`vertical-rl`): columns stack right-to-left, glyphs
1197
+ * flow top→bottom. It is the horizontal layout with the inline and block axes
1198
+ * swapped — the inline (down-column) advance is `advanceWidth` (CJK upright = em;
1199
+ * Latin is rotated, so its advance ≈ its width), the cross-axis content box is
1200
+ * `advanceHeight`, and the column thickness is `fontHeight`. The lineBox is
1201
+ * derived exactly as DomMeasurer.measureParagraphDom's vertical branch, so it
1202
+ * stays accurate even though inlineBox carries the content-box rounding residual.
1203
+ *
1204
+ * v1: `vertical-rl` only; no per-paragraph margin/padding or block alignment.
1205
+ */
1206
+ _measureVertical(paragraphs, rootStyle) {
1207
+ const rootPad = this._rootPadding(rootStyle);
1208
+ const hasHeight = typeof rootStyle.height === "number";
1209
+ const availHeight = hasHeight ? rootStyle.height - rootPad.top - rootPad.bottom : Infinity;
1210
+ const columns = [];
1211
+ for (const paragraph of paragraphs) {
1212
+ const strut = paragraph.computedStyle.fontSize * paragraph.computedStyle.lineHeight;
1213
+ for (const line of this._breakLines(paragraph, availHeight)) {
1214
+ let thickness = strut;
1215
+ for (const c of line) {
1216
+ if (c.fontHeight > thickness) {
1217
+ thickness = c.fontHeight;
1218
+ }
1219
+ }
1220
+ columns.push({ chars: line, thickness });
1221
+ }
1222
+ }
1223
+ const totalThickness = columns.reduce((sum, c) => sum + c.thickness, 0);
1224
+ const hasWidth = typeof rootStyle.width === "number";
1225
+ const blockWidth = hasWidth ? Math.max(rootStyle.width - rootPad.left - rootPad.right, totalThickness) : totalThickness;
1226
+ let xRight = rootPad.left + blockWidth;
1227
+ let maxBottom = rootPad.top;
1228
+ for (const column of columns) {
1229
+ xRight -= column.thickness;
1230
+ const colLeft = xRight;
1231
+ let y = rootPad.top;
1232
+ for (const c of column.chars) {
1233
+ const advance = c.advanceWidth;
1234
+ const contentWidth = c.advanceHeight;
1235
+ const fontHeight = c.fontHeight;
1236
+ c.inlineBox.top = y;
1237
+ c.inlineBox.height = advance;
1238
+ c.inlineBox.width = contentWidth;
1239
+ c.inlineBox.left = colLeft + (column.thickness - contentWidth) / 2;
1240
+ c.lineBox.left = c.inlineBox.left + (contentWidth - fontHeight) / 2;
1241
+ c.lineBox.top = y;
1242
+ c.lineBox.width = fontHeight;
1243
+ c.lineBox.height = advance;
1244
+ y += this._advance(c);
1245
+ }
1246
+ if (y > maxBottom) {
1247
+ maxBottom = y;
1248
+ }
1249
+ }
1250
+ for (const paragraph of paragraphs) {
1251
+ for (const fragment of paragraph.fragments) {
1252
+ this._unionInto(fragment.inlineBox, fragment.characters.map((c) => c.inlineBox));
1253
+ }
1254
+ this._unionInto(
1255
+ paragraph.lineBox,
1256
+ paragraph.fragments.flatMap((f) => f.characters.map((c) => c.inlineBox))
1257
+ );
1258
+ }
1259
+ const totalWidth = hasWidth ? rootStyle.width : blockWidth + rootPad.left + rootPad.right;
1260
+ const totalHeight = hasHeight ? rootStyle.height : maxBottom + rootPad.bottom;
1261
+ return {
1262
+ paragraphs,
1263
+ boundingBox: new BoundingBox(0, 0, totalWidth, totalHeight)
1264
+ };
1265
+ }
1266
+ /** Advance step including CSS letter-spacing (px). */
1267
+ _advance(character) {
1268
+ return character.advanceWidth + (character.computedStyle.letterSpacing ?? 0);
1269
+ }
1270
+ /**
1271
+ * Break a paragraph's characters into visual lines.
1272
+ * v1: `word-break: break-all` (break before any character that would overflow)
1273
+ * plus explicit `\n`/`\r` hard breaks. The newline itself occupies no line box.
1274
+ */
1275
+ _breakLines(paragraph, avail) {
1276
+ const lines = [];
1277
+ let current = [];
1278
+ let width = 0;
1279
+ const flush = () => {
1280
+ lines.push(current);
1281
+ current = [];
1282
+ width = 0;
1283
+ };
1284
+ for (const fragment of paragraph.fragments) {
1285
+ for (const c of fragment.characters) {
1286
+ if (c.content === "\n" || c.content === "\r") {
1287
+ flush();
1288
+ continue;
1289
+ }
1290
+ if (avail !== Infinity && current.length > 0 && width + c.advanceWidth > avail) {
1291
+ flush();
1292
+ }
1293
+ current.push(c);
1294
+ width += this._advance(c);
1295
+ }
1296
+ }
1297
+ flush();
1298
+ return lines;
1299
+ }
1300
+ _unionInto(target, boxes) {
1301
+ const used = boxes.filter((b) => b.width !== 0 || b.height !== 0);
1302
+ if (!used.length) {
1303
+ return;
1304
+ }
1305
+ const u = BoundingBox.from(...used);
1306
+ target.left = u.left;
1307
+ target.top = u.top;
1308
+ target.width = u.width;
1309
+ target.height = u.height;
1310
+ }
1311
+ _shiftAll(paragraphs, dy) {
1312
+ for (const paragraph of paragraphs) {
1313
+ paragraph.lineBox.top += dy;
1314
+ for (const fragment of paragraph.fragments) {
1315
+ fragment.inlineBox.top += dy;
1316
+ for (const character of fragment.characters) {
1317
+ character.inlineBox.top += dy;
1318
+ character.lineBox.top += dy;
1319
+ }
1320
+ }
1321
+ }
1322
+ }
1323
+ dispose() {
1324
+ }
1325
+ }
1326
+
1068
1327
  function backgroundPlugin() {
1069
1328
  const pathSet = new Path2DSet();
1070
1329
  const loader = createSvgLoader();
@@ -1823,7 +2082,7 @@ class Text extends Reactivable {
1823
2082
  glyphBox = new BoundingBox();
1824
2083
  pathBox = new BoundingBox();
1825
2084
  boundingBox = new BoundingBox();
1826
- measurer = new Measurer();
2085
+ measurer = new DomMeasurer();
1827
2086
  plugins = /* @__PURE__ */ new Map();
1828
2087
  pathSets = [];
1829
2088
  _paragraphs = [];
@@ -1881,6 +2140,12 @@ class Text extends Reactivable {
1881
2140
  outline,
1882
2141
  deformation
1883
2142
  } = normalizeText(options);
2143
+ if (options.measurer && typeof options.measurer !== "string") {
2144
+ this.measurer = options.measurer;
2145
+ } else {
2146
+ const kind = options.measurer ?? (fonts ? "font" : "dom");
2147
+ this.measurer = kind === "font" ? new FontMeasurer() : new DomMeasurer();
2148
+ }
1884
2149
  this.debug = options.debug ?? false;
1885
2150
  this.content = content;
1886
2151
  this.effects = effects;
@@ -1920,7 +2185,35 @@ class Text extends Reactivable {
1920
2185
  }
1921
2186
  async load() {
1922
2187
  this._update();
1923
- 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
+ }));
1924
2217
  }
1925
2218
  _update() {
1926
2219
  this.computedStyle = { ...textDefaultStyle, ...this.style };
@@ -1955,6 +2248,9 @@ class Text extends Reactivable {
1955
2248
  }
1956
2249
  createDom() {
1957
2250
  this._update();
2251
+ if (!this.measurer.createDom) {
2252
+ throw new Error("current measurer does not support createDom()");
2253
+ }
1958
2254
  return this.measurer.createDom(this.paragraphs, this.computedStyle);
1959
2255
  }
1960
2256
  measure(dom = this.measureDom) {
@@ -1968,7 +2264,7 @@ class Text extends Reactivable {
1968
2264
  boundingBox: this.boundingBox
1969
2265
  };
1970
2266
  this._update();
1971
- const result = this.measurer.measure(this.paragraphs, this.computedStyle, dom);
2267
+ const result = this.measurer.measure(this.paragraphs, this.computedStyle, dom, this.fonts);
1972
2268
  this.paragraphs = result.paragraphs;
1973
2269
  this.lineBox = result.boundingBox;
1974
2270
  const characters = this.characters;
@@ -2100,7 +2396,7 @@ class Text extends Reactivable {
2100
2396
  options.onContext?.(ctx);
2101
2397
  }
2102
2398
  dispose() {
2103
- this.measurer.dispose();
2399
+ this.measurer.dispose?.();
2104
2400
  this._renderer = void 0;
2105
2401
  this._rendererCtx = void 0;
2106
2402
  }
@@ -2136,4 +2432,4 @@ __decorateClass([
2136
2432
  property({ internal: true })
2137
2433
  ], Text.prototype, "fonts");
2138
2434
 
2139
- export { Canvas2DRenderer as C, Fragment as F, Measurer as M, Paragraph as P, Text as T, Character as a, backgroundPlugin as b, createSvgLoader as c, createSvgParser as d, getHighlightStyle as e, isEqualValue as f, getEffectTransform2D as g, highlightPlugin as h, isEqualObject as i, parseTransformOrigin as j, parseValueNumber as k, listStylePlugin as l, textDefaultStyle as m, outlinePlugin as o, parseColormap as p, renderPlugin as r, textDecorationPlugin as t };
2435
+ export { Canvas2DRenderer as C, DomMeasurer as D, FontMeasurer as F, Paragraph as P, Text as T, Character as a, Fragment as b, backgroundPlugin as c, createSvgLoader as d, createSvgParser as e, getHighlightStyle as f, getEffectTransform2D as g, highlightPlugin as h, isEqualObject as i, isEqualValue as j, parseTransformOrigin as k, listStylePlugin as l, parseValueNumber as m, textDefaultStyle as n, outlinePlugin as o, parseColormap as p, renderPlugin as r, textDecorationPlugin as t };
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.C8g4NZgY.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.C8g4NZgY.js';
2
+ import { a as Character } from './modern-text.C6VOXPvn.js';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -2,10 +2,10 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.DR1hbjgA.cjs');
5
+ const Text = require('../shared/modern-text.9z5yZjKR.cjs');
6
+ require('modern-font');
6
7
  require('modern-path2d');
7
8
  require('../shared/modern-text.B2xfrqDc.cjs');
8
- require('modern-font');
9
9
 
10
10
  var __defProp = Object.defineProperty;
11
11
  var __decorateClass = (decorators, target, key, kind) => {
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.C8g4NZgY.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.C8g4NZgY.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.C8g4NZgY.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,9 +1,9 @@
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.CrFHIJtB.mjs';
3
+ import { T as Text } from '../shared/modern-text.EUexrM_5.mjs';
4
+ import 'modern-font';
4
5
  import 'modern-path2d';
5
6
  import '../shared/modern-text.JF1ny7A-.mjs';
6
- import 'modern-font';
7
7
 
8
8
  var __defProp = Object.defineProperty;
9
9
  var __decorateClass = (decorators, target, key, kind) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "1.12.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",
@@ -60,19 +60,19 @@
60
60
  },
61
61
  "dependencies": {
62
62
  "diff": "^9.0.0",
63
- "modern-font": "^0.5.0",
63
+ "modern-font": "^0.6.0",
64
64
  "modern-idoc": "^0.11.5",
65
65
  "modern-path2d": "^1.6.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@antfu/eslint-config": "^9.0.0",
69
- "@types/node": "^25.8.0",
69
+ "@types/node": "^25.9.1",
70
70
  "bumpp": "^11.1.0",
71
71
  "conventional-changelog-cli": "^5.0.0",
72
- "eslint": "^10.3.0",
72
+ "eslint": "^10.4.0",
73
73
  "typescript": "^6.0.3",
74
74
  "unbuild": "^3.6.1",
75
- "vite": "^8.0.13",
76
- "vitest": "^4.1.6"
75
+ "vite": "^8.0.14",
76
+ "vitest": "^4.1.7"
77
77
  }
78
78
  }