modern-text 2.0.0 → 2.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,10 +1,10 @@
1
- import { T as Text } from './shared/modern-text.ChzjFjsk.mjs';
2
- export { C as Canvas2DRenderer, a as Character, D as DomMeasurer, F as FontMeasurer, b as Fragment, P as Paragraph, c as backgroundPlugin, d as createSvgLoader, e as createSvgParser, g as getEffectTransform2D, f as getHighlightStyle, h as highlightPlugin, i as isEqualObject, j as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, k as parseTransformOrigin, m as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, n as textDefaultStyle } from './shared/modern-text.ChzjFjsk.mjs';
1
+ import { T as Text } from './shared/modern-text.EUexrM_5.mjs';
2
+ export { C as Canvas2DRenderer, a as Character, D as DomMeasurer, F as FontMeasurer, b as Fragment, P as Paragraph, c as backgroundPlugin, d as createSvgLoader, e as createSvgParser, g as getEffectTransform2D, f as getHighlightStyle, h as highlightPlugin, i as isEqualObject, j as isEqualValue, l as listStylePlugin, o as outlinePlugin, p as parseColormap, k as parseTransformOrigin, m as parseValueNumber, r as renderPlugin, t as textDecorationPlugin, n as textDefaultStyle } from './shared/modern-text.EUexrM_5.mjs';
3
3
  export { d as defineDeformation, a as definePlugin, b as deformationPlugin, g as getDeformationNames, r as removeDeformation } from './shared/modern-text.JF1ny7A-.mjs';
4
4
  export { C as CircleCurve, E as EllipseCurve, H as HeartCurve, P as PolygonCurve, R as RectangularCurve } from './shared/modern-text.fT17R5HY.mjs';
5
+ import 'modern-font';
5
6
  import 'modern-idoc';
6
7
  import 'modern-path2d';
7
- import 'modern-font';
8
8
 
9
9
  function measureText(options, load) {
10
10
  const text = new Text(options);
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const modernFont = require('modern-font');
3
4
  const modernIdoc = require('modern-idoc');
4
5
  const modernPath2d = require('modern-path2d');
5
- const modernFont = require('modern-font');
6
6
  const deformation = require('./modern-text.B2xfrqDc.cjs');
7
7
 
8
8
  function createSvgLoader() {
@@ -2187,7 +2187,35 @@ class Text extends modernIdoc.Reactivable {
2187
2187
  }
2188
2188
  async load() {
2189
2189
  this._update();
2190
- await Promise.all(Array.from(this.plugins.values()).map((p) => p.load?.(this)));
2190
+ await Promise.all([
2191
+ this._decodeFonts(),
2192
+ ...Array.from(this.plugins.values()).map((p) => p.load?.(this))
2193
+ ]);
2194
+ }
2195
+ /**
2196
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
2197
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
2198
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
2199
+ * never stalls the main thread inflating WOFF tables on first glyph access.
2200
+ *
2201
+ * No-op for already-decoded fonts and for formats without async decoding.
2202
+ */
2203
+ async _decodeFonts() {
2204
+ const fonts = this.fonts ?? modernFont.fonts;
2205
+ const entries = /* @__PURE__ */ new Set();
2206
+ for (const character of this.characters) {
2207
+ const family = character.computedStyle.fontFamily;
2208
+ if (family) {
2209
+ entries.add(fonts.get(family));
2210
+ }
2211
+ }
2212
+ entries.add(fonts.fallbackFont);
2213
+ await Promise.all(Array.from(entries, async (entry) => {
2214
+ const font = entry?.getFont();
2215
+ if (font && typeof font.createSFNTAsync === "function" && !font._sfnt) {
2216
+ font._sfnt = await font.createSFNTAsync();
2217
+ }
2218
+ }));
2191
2219
  }
2192
2220
  _update() {
2193
2221
  this.computedStyle = { ...textDefaultStyle, ...this.style };
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -279,6 +279,15 @@ declare class Text$1 extends Reactivable {
279
279
  characterIndex: number;
280
280
  }) => void): this;
281
281
  load(): Promise<void>;
282
+ /**
283
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
284
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
285
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
286
+ * never stalls the main thread inflating WOFF tables on first glyph access.
287
+ *
288
+ * No-op for already-decoded fonts and for formats without async decoding.
289
+ */
290
+ protected _decodeFonts(): Promise<void>;
282
291
  protected _update(): this;
283
292
  createDom(): HTMLElement;
284
293
  measure(dom?: HTMLElement | undefined): MeasureResult;
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.cjs';
2
+ import { a as Character } from './modern-text.C6VOXPvn.mjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -1,6 +1,6 @@
1
+ import { fonts } from 'modern-font';
1
2
  import { isNone, isGradient, normalizeGradient, clearUndef, Reactivable, normalizeText, getDefaultStyle, property } from 'modern-idoc';
2
3
  import { svgToDom, svgToPath2DSet, Path2DSet, Transform2D, setCanvasContext, Path2D, BoundingBox, Vector2 } from 'modern-path2d';
3
- import { fonts } from 'modern-font';
4
4
  import { a as definePlugin, b as deformationPlugin } from './modern-text.JF1ny7A-.mjs';
5
5
 
6
6
  function createSvgLoader() {
@@ -2185,7 +2185,35 @@ class Text extends Reactivable {
2185
2185
  }
2186
2186
  async load() {
2187
2187
  this._update();
2188
- await Promise.all(Array.from(this.plugins.values()).map((p) => p.load?.(this)));
2188
+ await Promise.all([
2189
+ this._decodeFonts(),
2190
+ ...Array.from(this.plugins.values()).map((p) => p.load?.(this))
2191
+ ]);
2192
+ }
2193
+ /**
2194
+ * Eagerly decode the fonts this text uses, off the main thread — WOFF tables
2195
+ * are decompressed via modern-font's async `createSFNTAsync` (fflate async).
2196
+ * This warms the SFNT cache so the synchronous `measure()` / `render()` pass
2197
+ * never stalls the main thread inflating WOFF tables on first glyph access.
2198
+ *
2199
+ * No-op for already-decoded fonts and for formats without async decoding.
2200
+ */
2201
+ async _decodeFonts() {
2202
+ const fonts$1 = this.fonts ?? fonts;
2203
+ const entries = /* @__PURE__ */ new Set();
2204
+ for (const character of this.characters) {
2205
+ const family = character.computedStyle.fontFamily;
2206
+ if (family) {
2207
+ entries.add(fonts$1.get(family));
2208
+ }
2209
+ }
2210
+ entries.add(fonts$1.fallbackFont);
2211
+ await Promise.all(Array.from(entries, async (entry) => {
2212
+ const font = entry?.getFont();
2213
+ if (font && typeof font.createSFNTAsync === "function" && !font._sfnt) {
2214
+ font._sfnt = await font.createSFNTAsync();
2215
+ }
2216
+ }));
2189
2217
  }
2190
2218
  _update() {
2191
2219
  this.computedStyle = { ...textDefaultStyle, ...this.style };
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.mjs';
2
+ import { a as Character } from './modern-text.C6VOXPvn.cjs';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -1,5 +1,5 @@
1
1
  import { Vector2Like, BoundingBox, Vector2 } from 'modern-path2d';
2
- import { a as Character } from './modern-text.D4WopQCu.js';
2
+ import { a as Character } from './modern-text.C6VOXPvn.js';
3
3
 
4
4
  /** 逐字沿形状排布所需的曲线最小接口(实现了这三个方法即可当作变形曲线) */
5
5
  interface DeformationCurve {
@@ -2,9 +2,9 @@
2
2
 
3
3
  const diff = require('diff');
4
4
  const modernIdoc = require('modern-idoc');
5
- const Text = require('../shared/modern-text.CBgc-cQ1.cjs');
6
- require('modern-path2d');
5
+ const Text = require('../shared/modern-text.9z5yZjKR.cjs');
7
6
  require('modern-font');
7
+ require('modern-path2d');
8
8
  require('../shared/modern-text.B2xfrqDc.cjs');
9
9
 
10
10
  var __defProp = Object.defineProperty;
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.cjs';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.cjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.mjs';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.mjs';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { PropertyAccessor, NormalizedTextContent } from 'modern-idoc';
2
- import { T as Text } from '../shared/modern-text.D4WopQCu.js';
2
+ import { T as Text } from '../shared/modern-text.C6VOXPvn.js';
3
3
  import 'modern-path2d';
4
4
  import 'modern-font';
5
5
 
@@ -1,8 +1,8 @@
1
1
  import { diffChars } from 'diff';
2
2
  import { isCRLF, textContentToString, normalizeCRLF, normalizeTextContent, property } from 'modern-idoc';
3
- import { T as Text } from '../shared/modern-text.ChzjFjsk.mjs';
4
- import 'modern-path2d';
3
+ import { T as Text } from '../shared/modern-text.EUexrM_5.mjs';
5
4
  import 'modern-font';
5
+ import 'modern-path2d';
6
6
  import '../shared/modern-text.JF1ny7A-.mjs';
7
7
 
8
8
  var __defProp = Object.defineProperty;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-text",
3
3
  "type": "module",
4
- "version": "2.0.0",
4
+ "version": "2.0.2",
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",
@@ -62,7 +62,7 @@
62
62
  "diff": "^9.0.0",
63
63
  "modern-font": "^0.6.0",
64
64
  "modern-idoc": "^0.11.5",
65
- "modern-path2d": "^1.6.0"
65
+ "modern-path2d": "^1.7.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@antfu/eslint-config": "^9.0.0",