@vyaz/core 0.0.4 → 0.0.6
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 +156 -0
- package/dist/compile/DocumentCompiler.d.ts +40 -0
- package/dist/index.browser.d.ts +28 -0
- package/dist/index.browser.js +18 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +11 -147930
- package/dist/layout/AutoFitEngine.d.ts +44 -0
- package/dist/layout/LineBoxValidator.d.ts +25 -0
- package/dist/layout/ParagraphLayoutEngine.d.ts +46 -0
- package/dist/layout/PositioningEngine.d.ts +68 -0
- package/dist/layout/TextFrameLayoutEngine.d.ts +50 -0
- package/dist/layout/estimateWidth.d.ts +36 -0
- package/dist/measure/FontEngine.d.ts +47 -0
- package/dist/measure/FontMetricsProvider.d.ts +49 -0
- package/dist/measure/FontNotFoundError.d.ts +6 -0
- package/dist/measure/SystemFontRegistry.d.ts +46 -0
- package/dist/measure/canvas-polyfill.d.ts +30 -0
- package/dist/types/Document.d.ts +593 -0
- package/dist/types/FontTypes.d.ts +61 -0
- package/dist/types/LayoutTypes.d.ts +128 -0
- package/dist/utils/env.d.ts +11 -0
- package/dist/utils/font.d.ts +16 -0
- package/dist/utils/groupLinesByParagraph.d.ts +44 -0
- package/dist/utils/list.d.ts +41 -0
- package/dist/utils/textTransform.d.ts +32 -0
- package/package.json +30 -13
- package/src/compile/DocumentCompiler.ts +0 -136
- package/src/index.ts +0 -80
- package/src/layout/AutoFitEngine.ts +0 -101
- package/src/layout/LineBoxValidator.ts +0 -162
- package/src/layout/ParagraphLayoutEngine.ts +0 -202
- package/src/layout/PositioningEngine.ts +0 -401
- package/src/layout/TextFrameLayoutEngine.ts +0 -91
- package/src/measure/FontMetricsProvider.ts +0 -226
- package/src/measure/FontNotFoundError.ts +0 -16
- package/src/measure/SystemFontRegistry.ts +0 -151
- package/src/measure/canvas-polyfill.d.ts +0 -6
- package/src/measure/canvas-polyfill.ts +0 -235
- package/src/measure/fontkit.d.ts +0 -44
- package/src/types/Document.ts +0 -540
- package/src/types/FontTypes.ts +0 -74
- package/src/types/LayoutTypes.ts +0 -141
package/src/types/Document.ts
DELETED
|
@@ -1,540 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Document.ts — Input types (Logical level).
|
|
3
|
-
*
|
|
4
|
-
* Hierarchy: TextFrame → Paragraph[] → TextRun[]
|
|
5
|
-
*
|
|
6
|
-
* TextFrame is the root container (a text box on canvas).
|
|
7
|
-
* Paragraph is the block-level unit (paragraph with spacing, alignment).
|
|
8
|
-
* TextRun is the inline-level unit (a styled text fragment).
|
|
9
|
-
*
|
|
10
|
-
* Based on W3C CSS Text, CSS Writing Modes, CSS Multi-column specs.
|
|
11
|
-
*
|
|
12
|
-
* @see {@link https://www.w3.org/TR/css-text-3/ | CSS Text Module Level 3}
|
|
13
|
-
* @see {@link https://www.w3.org/TR/css-writing-modes-3/ | CSS Writing Modes Level 3}
|
|
14
|
-
* @see {@link https://www.w3.org/TR/css-multicol-1/ | CSS Multi-column Layout Level 1}
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// ── Union types ─────────────────────────────────────────────────────────
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Block flow direction (writing mode).
|
|
21
|
-
*
|
|
22
|
-
* Determines how lines stack relative to each other:
|
|
23
|
-
* - `horizontal-tb`: lines flow horizontally top-to-bottom (Latin, Cyrillic, default).
|
|
24
|
-
* - `vertical-rl`: lines flow vertically right-to-left (traditional CJK).
|
|
25
|
-
* - `vertical-lr`: lines flow vertically left-to-right (Mongolian, some UI scenarios).
|
|
26
|
-
*
|
|
27
|
-
* **Layout impact:**
|
|
28
|
-
* Under `horizontal-tb`, `wrap` clips by **width**, `autofit` shrinks by **height**.
|
|
29
|
-
* Under `vertical-*`, `wrap` clips by **height**, `autofit` shrinks by **width**
|
|
30
|
-
* (width and height swap roles).
|
|
31
|
-
*
|
|
32
|
-
* @see {@link https://www.w3.org/TR/css-writing-modes-3/#block-flow | CSS Writing Modes: block flow}
|
|
33
|
-
*/
|
|
34
|
-
export type WritingMode = 'horizontal-tb' | 'vertical-rl' | 'vertical-lr';
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Character orientation inside a vertical line.
|
|
38
|
-
*
|
|
39
|
-
* Only applies when `writingMode !== 'horizontal-tb'`:
|
|
40
|
-
* - `mixed`: Latin digits/letters are rotated 90°, CJK glyphs remain upright.
|
|
41
|
-
* - `upright`: **all** characters stand upright (stacked vertically).
|
|
42
|
-
* - `sideways`: the whole text block is rotated 90° (like a rotated box).
|
|
43
|
-
*
|
|
44
|
-
* @see {@link https://www.w3.org/TR/css-writing-modes-3/#text-orientation | CSS Writing Modes: text-orientation}
|
|
45
|
-
*/
|
|
46
|
-
export type TextOrientation = 'mixed' | 'upright' | 'sideways';
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Horizontal text alignment within a line.
|
|
50
|
-
*
|
|
51
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#text-align-property | CSS Text: text-align}
|
|
52
|
-
*/
|
|
53
|
-
export type TextAlignment = 'left' | 'center' | 'right' | 'justify';
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Alignment of the **last** line in a justified paragraph.
|
|
57
|
-
*
|
|
58
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#text-align-last-property | CSS Text: text-align-last}
|
|
59
|
-
* @todo Not yet implemented in the layout engine.
|
|
60
|
-
*/
|
|
61
|
-
export type TextAlignLast = 'auto' | 'start' | 'end' | 'left' | 'right' | 'center' | 'justify';
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Word-break rules (how to break lines within words).
|
|
65
|
-
*
|
|
66
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#word-break-property | CSS Text: word-break}
|
|
67
|
-
* @todo Not yet implemented in the layout engine.
|
|
68
|
-
*/
|
|
69
|
-
export type WordBreak = 'normal' | 'break-all' | 'keep-all' | 'break-word';
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Strictness of line-break rules (mainly for CJK).
|
|
73
|
-
*
|
|
74
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#line-break-property | CSS Text: line-break}
|
|
75
|
-
* @todo Not yet implemented in the layout engine.
|
|
76
|
-
*/
|
|
77
|
-
export type LineBreak = 'auto' | 'loose' | 'normal' | 'strict' | 'anywhere';
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Overflow wrap behavior (whether long words can break).
|
|
81
|
-
*
|
|
82
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#overflow-wrap-property | CSS Text: overflow-wrap}
|
|
83
|
-
* @todo Not yet implemented in the layout engine.
|
|
84
|
-
*/
|
|
85
|
-
export type OverflowWrap = 'normal' | 'break-word' | 'anywhere';
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Text decoration line style.
|
|
89
|
-
*
|
|
90
|
-
* @see {@link https://www.w3.org/TR/css-text-decor-3/#text-decoration-style-property | CSS Text Decoration: text-decoration-style}
|
|
91
|
-
* @todo Not yet implemented in the layout engine.
|
|
92
|
-
*/
|
|
93
|
-
export type TextDecorationStyle = 'solid' | 'double' | 'dotted' | 'dashed' | 'wavy';
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Text case transform.
|
|
97
|
-
*
|
|
98
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#text-transform-property | CSS Text: text-transform}
|
|
99
|
-
* @todo Not yet implemented in the layout engine.
|
|
100
|
-
*/
|
|
101
|
-
export type TextTransform = 'none' | 'uppercase' | 'lowercase' | 'capitalize';
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Dominant baseline used for vertical alignment within a line.
|
|
105
|
-
*
|
|
106
|
-
* @see {@link https://www.w3.org/TR/css-inline-3/#dominant-baseline-property | CSS Inline Layout: dominant-baseline}
|
|
107
|
-
* @todo Not yet implemented in the layout engine.
|
|
108
|
-
*/
|
|
109
|
-
export type DominantBaseline = 'auto' | 'text-bottom' | 'alphabetic' | 'ideographic' | 'middle' | 'central' | 'mathematical' | 'hanging' | 'text-top';
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Edge used to measure the line box height (font metric edge).
|
|
113
|
-
*
|
|
114
|
-
* @see {@link https://www.w3.org/TR/css-inline-3/#line-fit-edge | CSS Inline Layout: line-fit-edge}
|
|
115
|
-
* @todo Not yet implemented in the layout engine.
|
|
116
|
-
*/
|
|
117
|
-
export type LineFitEdge = 'leading' | 'text' | 'cap' | 'ex' | 'ideographic' | 'ideographic-ink' | 'alphabetic';
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Vertical alignment of the whole text block inside the frame.
|
|
121
|
-
*
|
|
122
|
-
* - `top`: text starts at the top edge.
|
|
123
|
-
* - `middle`: text is centered vertically.
|
|
124
|
-
* - `bottom`: text sits at the bottom edge.
|
|
125
|
-
*/
|
|
126
|
-
export type VerticalAlignment = 'top' | 'middle' | 'bottom';
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Subscript / superscript script mode.
|
|
130
|
-
*
|
|
131
|
-
* - `normal`: no script shift.
|
|
132
|
-
* - `sub`: subscript (lowered, smaller).
|
|
133
|
-
* - `super`: superscript (raised, smaller).
|
|
134
|
-
*/
|
|
135
|
-
export type ScriptType = 'normal' | 'sub' | 'super';
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* CSS `white-space` equivalent.
|
|
139
|
-
*
|
|
140
|
-
* Controls how whitespace and line breaks are handled inside a paragraph.
|
|
141
|
-
*
|
|
142
|
-
* @see {@link https://www.w3.org/TR/css-text-3/#white-space-property | CSS Text: white-space}
|
|
143
|
-
*/
|
|
144
|
-
export type WhiteSpace = 'normal' | 'nowrap' | 'pre';
|
|
145
|
-
|
|
146
|
-
// ── Autofit ─────────────────────────────────────────────────────────────
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Configuration for automatic font-size reduction (autofit).
|
|
150
|
-
*
|
|
151
|
-
* When `enabled` is true, the layout engine will scale down the font size
|
|
152
|
-
* of **all** runs proportionally so the text fits inside the frame's
|
|
153
|
-
* `width` × `height`. The scaling stops at `minFontSize`.
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```ts
|
|
157
|
-
* { enabled: true, minFontSize: 10, maxFontSize: 24, baseFontSize: 18 }
|
|
158
|
-
* ```
|
|
159
|
-
*
|
|
160
|
-
* @see {@link TextFrame.autofit}
|
|
161
|
-
*/
|
|
162
|
-
export interface AutofitConfig {
|
|
163
|
-
/** Whether autofit is active. */
|
|
164
|
-
enabled: boolean;
|
|
165
|
-
/**
|
|
166
|
-
* Minimum font size in px.
|
|
167
|
-
* The engine will never shrink text below this threshold.
|
|
168
|
-
*/
|
|
169
|
-
minFontSize?: number;
|
|
170
|
-
/**
|
|
171
|
-
* Maximum font size in px.
|
|
172
|
-
* The engine will never grow text above this threshold.
|
|
173
|
-
*/
|
|
174
|
-
maxFontSize?: number;
|
|
175
|
-
/**
|
|
176
|
-
* Base font size used as a reference when `TextRun.fontSize`
|
|
177
|
-
* is interpreted as a relative scale factor.
|
|
178
|
-
*
|
|
179
|
-
* @todo Currently `TextRun.fontSize` is absolute px.
|
|
180
|
-
* In future it may be a ratio relative to this base.
|
|
181
|
-
*/
|
|
182
|
-
baseFontSize?: number;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// ── TextRun (inline-level) ──────────────────────────────────────────────
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* A single inline run of styled text.
|
|
189
|
-
*
|
|
190
|
-
* This replaces the earlier `TextRunNode` + `TextStyleNode` pair;
|
|
191
|
-
* all style properties are **flattened** directly onto the run.
|
|
192
|
-
*
|
|
193
|
-
* Each run represents a continuous piece of text with uniform styling.
|
|
194
|
-
* Consecutive runs with different styles are split by the input parser.
|
|
195
|
-
*
|
|
196
|
-
* @example
|
|
197
|
-
* ```ts
|
|
198
|
-
* { text: "Hello", fontFamily: "Arial", fontSize: 16, fontWeight: "bold", color: "#000" }
|
|
199
|
-
* ```
|
|
200
|
-
*/
|
|
201
|
-
export interface TextRun {
|
|
202
|
-
/**
|
|
203
|
-
* Run kind:
|
|
204
|
-
* - `'text'` — plain text (the most common case).
|
|
205
|
-
* - `'inline-box'` — an inline widget placeholder (`\uFFFC`).
|
|
206
|
-
*/
|
|
207
|
-
type: 'text' | 'inline-box';
|
|
208
|
-
/** The text content of this run (or `\uFFFC` for inline-box). */
|
|
209
|
-
text: string;
|
|
210
|
-
/**
|
|
211
|
-
* Inline widget data (only when `type === 'inline-box'`).
|
|
212
|
-
* Represents an embedded object (image, icon, etc.) that sits
|
|
213
|
-
* inside the text flow.
|
|
214
|
-
*/
|
|
215
|
-
inlineWidget?: InlineWidget;
|
|
216
|
-
|
|
217
|
-
// ── Flattened style ───────────────────────────────────────────────
|
|
218
|
-
|
|
219
|
-
/** Font family name (e.g. `"Arial"`, `"Times New Roman"`). */
|
|
220
|
-
fontFamily: string;
|
|
221
|
-
/** Font size in px. */
|
|
222
|
-
fontSize: number;
|
|
223
|
-
/** Font weight: `'normal'`, `'bold'`, or a numeric CSS weight (100–900). */
|
|
224
|
-
fontWeight: 'normal' | 'bold' | number;
|
|
225
|
-
/** Font style. */
|
|
226
|
-
fontStyle: 'normal' | 'italic';
|
|
227
|
-
/** Text color in any CSS-compatible format (hex, rgb, named). */
|
|
228
|
-
color: string;
|
|
229
|
-
/** Background color (optional). */
|
|
230
|
-
backgroundColor?: string;
|
|
231
|
-
/** Letter-spacing (tracking) in px. `0` means default. */
|
|
232
|
-
letterSpacing?: number;
|
|
233
|
-
/** Subscript / superscript override. */
|
|
234
|
-
script?: ScriptType;
|
|
235
|
-
|
|
236
|
-
// ── Text decoration ───────────────────────────────────────────────
|
|
237
|
-
|
|
238
|
-
/** Underline decoration. */
|
|
239
|
-
underline?: boolean;
|
|
240
|
-
/** Strikethrough decoration. */
|
|
241
|
-
strikethrough?: boolean;
|
|
242
|
-
/** Overline decoration. @todo Not yet implemented. */
|
|
243
|
-
overline?: boolean;
|
|
244
|
-
/** Underline / overline / strikethrough line style. @todo Not yet implemented. */
|
|
245
|
-
textDecorationStyle?: TextDecorationStyle;
|
|
246
|
-
/** Underline / overline / strikethrough line color. @todo Not yet implemented. */
|
|
247
|
-
textDecorationColor?: string;
|
|
248
|
-
|
|
249
|
-
// ── Text transform ────────────────────────────────────────────────
|
|
250
|
-
|
|
251
|
-
/** Case transform (uppercase, lowercase, capitalize). @todo Not yet implemented. */
|
|
252
|
-
textTransform?: TextTransform;
|
|
253
|
-
/** Force full-width characters (CJK). @todo Not yet implemented. */
|
|
254
|
-
fullWidth?: boolean;
|
|
255
|
-
/** Convert small kana to full-size kana. @todo Not yet implemented. */
|
|
256
|
-
fullSizeKana?: boolean;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Data for an inline widget (embedded object inside text flow).
|
|
261
|
-
*
|
|
262
|
-
* Inline widgets behave like a single character glyph with a fixed
|
|
263
|
-
* width and height. They sit on the baseline by default.
|
|
264
|
-
*
|
|
265
|
-
* @example
|
|
266
|
-
* An inline icon (24×24 px) embedded in a sentence:
|
|
267
|
-
* ```ts
|
|
268
|
-
* { width: 24, height: 24, baselineOffset: 0 }
|
|
269
|
-
* ```
|
|
270
|
-
*/
|
|
271
|
-
export interface InlineWidget {
|
|
272
|
-
/** Width of the widget in px. */
|
|
273
|
-
width: number;
|
|
274
|
-
/** Height of the widget in px. */
|
|
275
|
-
height: number;
|
|
276
|
-
/**
|
|
277
|
-
* Offset from the baseline (in px).
|
|
278
|
-
* Positive = widget descends below the baseline.
|
|
279
|
-
* Negative = widget ascends above the baseline.
|
|
280
|
-
*/
|
|
281
|
-
baselineOffset?: number;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// ── Paragraph (block-level) ─────────────────────────────────────────────
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Block-level style for a paragraph.
|
|
288
|
-
*
|
|
289
|
-
* Controls alignment, spacing, indentation,
|
|
290
|
-
* and line-breaking rules for all runs inside the paragraph.
|
|
291
|
-
*
|
|
292
|
-
* @see {@link https://www.w3.org/TR/css-text-3/ | CSS Text Module Level 3}
|
|
293
|
-
*/
|
|
294
|
-
export interface ParagraphStyle {
|
|
295
|
-
/** Horizontal text alignment. */
|
|
296
|
-
alignment: TextAlignment;
|
|
297
|
-
/**
|
|
298
|
-
* Line height as a **multiplier** relative to the font size.
|
|
299
|
-
* E.g. `1.4` means 1.4× the computed font height.
|
|
300
|
-
*
|
|
301
|
-
* @todo Support for absolute px values via a `lineHeightUnit` field.
|
|
302
|
-
*/
|
|
303
|
-
lineHeight: number;
|
|
304
|
-
/** Space **before** this paragraph (top margin) in px. */
|
|
305
|
-
spaceBefore: number;
|
|
306
|
-
/** Space **after** this paragraph (bottom margin) in px. */
|
|
307
|
-
spaceAfter: number;
|
|
308
|
-
/**
|
|
309
|
-
* Left indent (first-line indent / "red line") in px.
|
|
310
|
-
* Applies only to the first line of the paragraph.
|
|
311
|
-
*
|
|
312
|
-
* @todo Rename or alias as `textIndent` for consistency with CSS.
|
|
313
|
-
*/
|
|
314
|
-
indent?: number;
|
|
315
|
-
/** Left margin for the whole paragraph in px. */
|
|
316
|
-
leftIndent?: number;
|
|
317
|
-
/** Right margin for the whole paragraph in px. */
|
|
318
|
-
rightIndent?: number;
|
|
319
|
-
/**
|
|
320
|
-
* Indentation of the first line in px.
|
|
321
|
-
* If set, overrides the generic `indent` for the first line.
|
|
322
|
-
*
|
|
323
|
-
* @todo Not yet implemented in the layout engine.
|
|
324
|
-
*/
|
|
325
|
-
textIndent?: number;
|
|
326
|
-
/** Letter-spacing (tracking) for the whole paragraph in px. */
|
|
327
|
-
letterSpacing?: number;
|
|
328
|
-
/**
|
|
329
|
-
* Alignment of the **last** line of a justified paragraph.
|
|
330
|
-
* @todo Not yet implemented.
|
|
331
|
-
*/
|
|
332
|
-
textAlignLast?: TextAlignLast;
|
|
333
|
-
/**
|
|
334
|
-
* Word-break rules (CJK / non-CJK).
|
|
335
|
-
* @todo Not yet implemented.
|
|
336
|
-
*/
|
|
337
|
-
wordBreak?: WordBreak;
|
|
338
|
-
/**
|
|
339
|
-
* Line-break strictness (CJK).
|
|
340
|
-
* @todo Not yet implemented.
|
|
341
|
-
*/
|
|
342
|
-
lineBreak?: LineBreak;
|
|
343
|
-
/**
|
|
344
|
-
* Overflow-wrap / word-wrap behaviour.
|
|
345
|
-
* @todo Not yet implemented.
|
|
346
|
-
*/
|
|
347
|
-
overflowWrap?: OverflowWrap;
|
|
348
|
-
/**
|
|
349
|
-
* Whether hyphenation is allowed.
|
|
350
|
-
* @todo Not yet implemented.
|
|
351
|
-
*/
|
|
352
|
-
hyphens?: boolean;
|
|
353
|
-
/**
|
|
354
|
-
* CSS `white-space` behaviour:
|
|
355
|
-
* - `'normal'`: collapse whitespace, auto-wrap.
|
|
356
|
-
* - `'nowrap'`: collapse whitespace, no wrap.
|
|
357
|
-
* - `'pre'`: preserve whitespace, wrap on newline only.
|
|
358
|
-
*/
|
|
359
|
-
whiteSpace?: WhiteSpace;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* A single paragraph (block-level text container).
|
|
364
|
-
*
|
|
365
|
-
* Contains one or more `TextRun` children that form the paragraph content.
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
* ```ts
|
|
369
|
-
* {
|
|
370
|
-
* id: "p-1",
|
|
371
|
-
* style: { alignment: "left", lineHeight: 1.4, spaceBefore: 0, spaceAfter: 12 },
|
|
372
|
-
* children: [
|
|
373
|
-
* { text: "Hello ", fontFamily: "Arial", fontSize: 16, fontWeight: "bold", color: "#000" },
|
|
374
|
-
* { text: "world!", fontFamily: "Arial", fontSize: 16, fontWeight: "normal", color: "#333" },
|
|
375
|
-
* ]
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
export interface Paragraph {
|
|
380
|
-
/** Unique identifier for this paragraph (optional, for debugging). */
|
|
381
|
-
id?: string;
|
|
382
|
-
/** Block-level paragraph style. */
|
|
383
|
-
style: ParagraphStyle;
|
|
384
|
-
/** Inline-level text runs forming the paragraph. */
|
|
385
|
-
children: TextRun[];
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// ── Multi-column config ─────────────────────────────────────────────────
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* Configuration for multi-column layout (flowing columns).
|
|
392
|
-
*
|
|
393
|
-
* Follows the CSS Multi-column Layout model:
|
|
394
|
-
* the **parent** frame holds a single flow of paragraphs;
|
|
395
|
-
* the layout engine automatically breaks the content into columns
|
|
396
|
-
* based on `columnCount` and `columnGap`.
|
|
397
|
-
*
|
|
398
|
-
* Columns are **not** independent containers with their own paragraphs.
|
|
399
|
-
* If you need independent columns (each with separate content),
|
|
400
|
-
* use multiple `TextFrame` instances placed side-by-side.
|
|
401
|
-
*
|
|
402
|
-
* @see {@link https://www.w3.org/TR/css-multicol-1/ | CSS Multi-column Layout Level 1}
|
|
403
|
-
* @todo Not yet implemented in the layout engine.
|
|
404
|
-
*/
|
|
405
|
-
export interface MultiColumnConfig {
|
|
406
|
-
/** Number of columns (like CSS `column-count`). */
|
|
407
|
-
count: number;
|
|
408
|
-
/** Gap between columns in px (like CSS `column-gap`). */
|
|
409
|
-
gap: number;
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
// ── TextFrame (root container) ──────────────────────────────────────────
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* Root text container — a text box on a canvas.
|
|
416
|
-
*
|
|
417
|
-
* This replaces the earlier `RichTextDocument`.
|
|
418
|
-
* It holds geometry, text flow settings, and the paragraph array.
|
|
419
|
-
*
|
|
420
|
-
* **Wrap & Autofit interaction:**
|
|
421
|
-
* - When `wrap` is `true`, the layout engine breaks lines at `width`.
|
|
422
|
-
* - When `autofit.enabled` is `true`, the engine shrinks the font
|
|
423
|
-
* proportionally to fit the text inside `width` × `height`.
|
|
424
|
-
*
|
|
425
|
-
* @example
|
|
426
|
-
* ```ts
|
|
427
|
-
* {
|
|
428
|
-
* width: 600,
|
|
429
|
-
* height: 400,
|
|
430
|
-
* wrap: true,
|
|
431
|
-
* autofit: { enabled: true, minFontSize: 10, maxFontSize: 24 },
|
|
432
|
-
* writingMode: "horizontal-tb",
|
|
433
|
-
* verticalAlignment: "top",
|
|
434
|
-
* paragraphs: [ /* ... *\/ ]
|
|
435
|
-
* }
|
|
436
|
-
* ```
|
|
437
|
-
*/
|
|
438
|
-
export interface TextFrame {
|
|
439
|
-
/**
|
|
440
|
-
* Container width in px.
|
|
441
|
-
*
|
|
442
|
-
* When set — text wraps by this width (if `wrap=true`). Used as the inline-size
|
|
443
|
-
* for horizontal-tb writing mode. When `undefined` — auto (fit-content).
|
|
444
|
-
*/
|
|
445
|
-
width?: number;
|
|
446
|
-
/**
|
|
447
|
-
* Container height in px.
|
|
448
|
-
*
|
|
449
|
-
* When set — may clip content or trigger autofit. When `undefined` — auto
|
|
450
|
-
* (content determines height, `contentHeight` from the layout result).
|
|
451
|
-
*/
|
|
452
|
-
height?: number;
|
|
453
|
-
/**
|
|
454
|
-
* Whether line wrapping is enabled.
|
|
455
|
-
* `true` = lines break when they exceed `width` (or `height` in vertical mode).
|
|
456
|
-
* `false` = text overflows (may be clipped or trigger autofit).
|
|
457
|
-
*/
|
|
458
|
-
wrap: boolean;
|
|
459
|
-
/** Autofit (auto font-size reduction) configuration. */
|
|
460
|
-
autofit?: AutofitConfig;
|
|
461
|
-
/**
|
|
462
|
-
* Writing mode (block flow direction).
|
|
463
|
-
* Defaults to `'horizontal-tb'` when absent.
|
|
464
|
-
*/
|
|
465
|
-
writingMode?: WritingMode;
|
|
466
|
-
/**
|
|
467
|
-
* Character orientation in vertical mode.
|
|
468
|
-
* Ignored when `writingMode === 'horizontal-tb'`.
|
|
469
|
-
*/
|
|
470
|
-
textOrientation?: TextOrientation;
|
|
471
|
-
/**
|
|
472
|
-
* Base text direction (important for bidi).
|
|
473
|
-
* `'ltr'` = left-to-right, `'rtl'` = right-to-left.
|
|
474
|
-
*/
|
|
475
|
-
direction?: 'ltr' | 'rtl';
|
|
476
|
-
/** Vertical alignment of the content block inside the frame. */
|
|
477
|
-
verticalAlignment?: VerticalAlignment;
|
|
478
|
-
/**
|
|
479
|
-
* Dominant baseline for inline alignment.
|
|
480
|
-
* @todo Not yet implemented.
|
|
481
|
-
*/
|
|
482
|
-
dominantBaseline?: DominantBaseline;
|
|
483
|
-
/**
|
|
484
|
-
* Font metric edge used for line box height.
|
|
485
|
-
* @todo Not yet implemented.
|
|
486
|
-
*/
|
|
487
|
-
lineFitEdge?: LineFitEdge;
|
|
488
|
-
/**
|
|
489
|
-
* Inner padding of the frame.
|
|
490
|
-
* Text layout starts at `x + padding.left`, `y + padding.top`.
|
|
491
|
-
*/
|
|
492
|
-
padding?: {
|
|
493
|
-
/** Top padding in px. */
|
|
494
|
-
top: number;
|
|
495
|
-
/** Right padding in px. */
|
|
496
|
-
right: number;
|
|
497
|
-
/** Bottom padding in px. */
|
|
498
|
-
bottom: number;
|
|
499
|
-
/** Left padding in px. */
|
|
500
|
-
left: number;
|
|
501
|
-
};
|
|
502
|
-
/**
|
|
503
|
-
* Multi-column layout configuration.
|
|
504
|
-
* When set, paragraphs are automatically broken into columns.
|
|
505
|
-
* @todo Not yet implemented.
|
|
506
|
-
*/
|
|
507
|
-
columns?: MultiColumnConfig;
|
|
508
|
-
/** Paragraphs forming the text content. */
|
|
509
|
-
paragraphs: Paragraph[];
|
|
510
|
-
/**
|
|
511
|
-
* Default style inherited by all `TextRun` children.
|
|
512
|
-
* Any field omitted in a `TextRun` will fall back to this value.
|
|
513
|
-
*/
|
|
514
|
-
defaultStyle?: Partial<Omit<TextRun, 'text' | 'type' | 'inlineWidget'>>;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// ── Default values ──────────────────────────────────────────────────────
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Default paragraph style used when a `Paragraph` omits its `style` field.
|
|
521
|
-
*/
|
|
522
|
-
export const DEFAULT_PARAGRAPH_STYLE: ParagraphStyle = {
|
|
523
|
-
alignment: 'left',
|
|
524
|
-
lineHeight: 1.15,
|
|
525
|
-
spaceBefore: 0,
|
|
526
|
-
spaceAfter: 0,
|
|
527
|
-
whiteSpace: 'normal',
|
|
528
|
-
};
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* Default text style used when a `TextRun` omits style fields
|
|
532
|
-
* and no `defaultStyle` is set on the `TextFrame`.
|
|
533
|
-
*/
|
|
534
|
-
export const DEFAULT_TEXT_STYLE: Partial<TextRun> = {
|
|
535
|
-
fontFamily: 'Arial',
|
|
536
|
-
fontSize: 12,
|
|
537
|
-
fontWeight: 'normal',
|
|
538
|
-
fontStyle: 'normal',
|
|
539
|
-
color: '#000000',
|
|
540
|
-
};
|
package/src/types/FontTypes.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FontTypes.ts — font metric type definitions.
|
|
3
|
-
*
|
|
4
|
-
* Isomorphic layer: works both in browser (Canvas TextMetrics) and Node.js (fontkit).
|
|
5
|
-
*
|
|
6
|
-
* Two modes:
|
|
7
|
-
* 'browser' — uses hhea.ascender/descender (canvas fallback)
|
|
8
|
-
* 'office' — uses OS/2.usWinAscent/usWinDescent (MS Office compatible)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/** Physical font metrics (in pixels for a given fontSize) */
|
|
12
|
-
export interface FontMetrics {
|
|
13
|
-
/** Rise above baseline */
|
|
14
|
-
ascent: number;
|
|
15
|
-
/** Descent below baseline (positive number!) */
|
|
16
|
-
descent: number;
|
|
17
|
-
/** Cap height */
|
|
18
|
-
capHeight: number;
|
|
19
|
-
/** Original font UPM (for reference) */
|
|
20
|
-
unitsPerEm: number;
|
|
21
|
-
/**
|
|
22
|
-
* Which font table was used for ascent/descent:
|
|
23
|
-
* 'hhea' — hhea.ascender/descender (browser mode)
|
|
24
|
-
* 'OS/2' — OS/2.usWinAscent/usWinDescent (Office mode)
|
|
25
|
-
* 'canvas' — canvas.measureText (browser fallback)
|
|
26
|
-
* 'fallback' — empirical formula
|
|
27
|
-
*/
|
|
28
|
-
sourceTable?: 'hhea' | 'OS/2' | 'canvas' | 'fallback';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Metrics provider — isomorphic interface */
|
|
32
|
-
export interface IFontMetricsProvider {
|
|
33
|
-
/**
|
|
34
|
-
* Set measurement mode.
|
|
35
|
-
* 'browser' — hhea.ascender/descender (default)
|
|
36
|
-
* 'office' — OS/2.usWinAscent/usWinDescent
|
|
37
|
-
*/
|
|
38
|
-
setMode(mode: 'browser' | 'office'): void;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Get current mode.
|
|
42
|
-
*/
|
|
43
|
-
getMode(): 'browser' | 'office';
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Register a binary font for use with fontkit.
|
|
47
|
-
* In browser — no-op (fonts are registered via CSS @font-face).
|
|
48
|
-
*
|
|
49
|
-
* @param sourcePath — path to .ttf/.otf file for optional @napi-rs/canvas.registerFont()
|
|
50
|
-
*/
|
|
51
|
-
registerFont(
|
|
52
|
-
family: string,
|
|
53
|
-
options: { weight?: string; style?: string },
|
|
54
|
-
source: string | Buffer,
|
|
55
|
-
sourcePath?: string,
|
|
56
|
-
): void;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Get metrics for a given family and size.
|
|
60
|
-
*/
|
|
61
|
-
getMetrics(
|
|
62
|
-
fontFamily: string,
|
|
63
|
-
fontSize: number,
|
|
64
|
-
weight?: string,
|
|
65
|
-
style?: string,
|
|
66
|
-
): FontMetrics;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Glyph-level data for a single glyph (per-character tracking/highlighting) */
|
|
70
|
-
export interface GlyphData {
|
|
71
|
-
char: string; // character
|
|
72
|
-
advance: number; // advance width in px
|
|
73
|
-
x: number; // position relative to line start
|
|
74
|
-
}
|