modern-text 1.12.0 → 2.0.0
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/README.md +283 -22
- 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 +3 -2
- package/dist/index.d.cts +67 -8
- package/dist/index.d.mts +67 -8
- package/dist/index.d.ts +67 -8
- package/dist/index.js +4 -3
- package/dist/index.mjs +2 -2
- package/dist/shared/{modern-text.d-RdVkZg.d.cts → modern-text.BD7PBYt7.d.cts} +1 -1
- package/dist/shared/{modern-text.Bo2MzSls.d.ts → modern-text.BxijkspX.d.ts} +1 -1
- package/dist/shared/{modern-text.DR1hbjgA.cjs → modern-text.CBgc-cQ1.cjs} +276 -7
- package/dist/shared/{modern-text.w5MRHZDB.d.mts → modern-text.CYa4lfoG.d.mts} +1 -1
- package/dist/shared/{modern-text.CrFHIJtB.mjs → modern-text.ChzjFjsk.mjs} +275 -7
- package/dist/shared/{modern-text.C8g4NZgY.d.cts → modern-text.D4WopQCu.d.cts} +55 -22
- package/dist/shared/{modern-text.C8g4NZgY.d.mts → modern-text.D4WopQCu.d.mts} +55 -22
- package/dist/shared/{modern-text.C8g4NZgY.d.ts → modern-text.D4WopQCu.d.ts} +55 -22
- package/dist/web-components/index.cjs +2 -2
- 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 +2 -2
- package/package.json +6 -6
|
@@ -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
|
|
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:
|
|
257
|
+
measurer: TextMeasurer;
|
|
225
258
|
plugins: Map<string, Plugin>;
|
|
226
259
|
pathSets: Path2DSet[];
|
|
227
260
|
protected _paragraphs: Paragraph[];
|
|
@@ -304,5 +337,5 @@ declare class Canvas2DRenderer {
|
|
|
304
337
|
drawCharacter: (character: Character, effect?: NormalizedEffect) => void;
|
|
305
338
|
}
|
|
306
339
|
|
|
307
|
-
export { Canvas2DRenderer as C, Fragment as F, Paragraph as P, Text$1 as T, Character as a,
|
|
308
|
-
export type {
|
|
340
|
+
export { Canvas2DRenderer as C, DomMeasurer as D, Fragment as F, Paragraph as P, Text$1 as T, Character as a, textDefaultStyle as t };
|
|
341
|
+
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 };
|
|
@@ -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.
|
|
5
|
+
const Text = require('../shared/modern-text.CBgc-cQ1.cjs');
|
|
6
6
|
require('modern-path2d');
|
|
7
|
-
require('../shared/modern-text.B2xfrqDc.cjs');
|
|
8
7
|
require('modern-font');
|
|
8
|
+
require('../shared/modern-text.B2xfrqDc.cjs');
|
|
9
9
|
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
11
11
|
var __decorateClass = (decorators, target, key, kind) => {
|
|
@@ -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.
|
|
3
|
+
import { T as Text } from '../shared/modern-text.ChzjFjsk.mjs';
|
|
4
4
|
import 'modern-path2d';
|
|
5
|
-
import '../shared/modern-text.JF1ny7A-.mjs';
|
|
6
5
|
import 'modern-font';
|
|
6
|
+
import '../shared/modern-text.JF1ny7A-.mjs';
|
|
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": "
|
|
4
|
+
"version": "2.0.0",
|
|
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.
|
|
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.
|
|
69
|
+
"@types/node": "^25.9.1",
|
|
70
70
|
"bumpp": "^11.1.0",
|
|
71
71
|
"conventional-changelog-cli": "^5.0.0",
|
|
72
|
-
"eslint": "^10.
|
|
72
|
+
"eslint": "^10.4.0",
|
|
73
73
|
"typescript": "^6.0.3",
|
|
74
74
|
"unbuild": "^3.6.1",
|
|
75
|
-
"vite": "^8.0.
|
|
76
|
-
"vitest": "^4.1.
|
|
75
|
+
"vite": "^8.0.14",
|
|
76
|
+
"vitest": "^4.1.7"
|
|
77
77
|
}
|
|
78
78
|
}
|