@vectojs/core 0.1.0 → 0.2.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/dist/animation/drivers.d.ts +48 -0
- package/dist/animation/easing.d.ts +16 -0
- package/dist/{chunk-53DAQC3U.js → chunk-W3SFIVXO.js} +356 -60
- package/dist/{chunk-M2IZPGOL.mjs → chunk-Y2N7TGEH.mjs} +303 -7
- package/dist/components/GridTextEntity.d.ts +15 -0
- package/dist/components/SplineEntity.d.ts +144 -0
- package/dist/components/TextEntity.d.ts +35 -0
- package/dist/index.d.ts +26 -577
- package/dist/index.js +60 -78
- package/dist/index.mjs +15 -33
- package/dist/{layout.d.mts → layout/LayoutEngine.d.ts} +15 -70
- package/dist/layout/LayoutWorker.d.ts +23 -0
- package/dist/layout/LayoutWorkerManager.d.ts +22 -0
- package/dist/layout/LayoutWorkerSource.d.ts +1 -0
- package/dist/layout/index.d.ts +3 -0
- package/dist/layout/measure.d.ts +20 -0
- package/dist/math/SpatialHashGrid.d.ts +53 -0
- package/dist/math/SpringPhysics.d.ts +13 -0
- package/dist/renderer/CanvasRenderer.d.ts +81 -0
- package/dist/renderer/IRenderer.d.ts +178 -0
- package/dist/renderer/SVGRenderer.d.ts +69 -0
- package/dist/renderer/WebGLPointRenderer.d.ts +62 -0
- package/dist/renderer/WebGPUParticleSystemManager.d.ts +14 -0
- package/dist/renderer/colorParse.d.ts +17 -0
- package/dist/renderer/index.d.ts +6 -0
- package/dist/text/ArabicShaper.d.ts +10 -0
- package/dist/text/BidiResolver.d.ts +6 -0
- package/dist/{text.d.ts → text/MSDFFont.d.ts} +10 -82
- package/dist/text/MSDFTextEntity.d.ts +30 -0
- package/dist/text/SVGEntity.d.ts +22 -0
- package/dist/text/index.d.ts +5 -0
- package/dist/text.js +2 -2
- package/dist/text.mjs +1 -1
- package/dist/tree/ComputeParticleEntity.d.ts +118 -0
- package/dist/tree/DOMPortalEntity.d.ts +18 -0
- package/dist/{Entity-D-rfAFCf.d.mts → tree/Entity.d.ts} +59 -197
- package/dist/tree/Scene.d.ts +295 -0
- package/package.json +5 -5
- package/dist/Entity-D-rfAFCf.d.ts +0 -572
- package/dist/index-ByBDSmMK.d.mts +0 -365
- package/dist/index-C3Fd_XmG.d.ts +0 -365
- package/dist/index.d.mts +0 -577
- package/dist/layout.d.ts +0 -319
- package/dist/renderer.d.mts +0 -2
- package/dist/renderer.d.ts +0 -2
- package/dist/text.d.mts +0 -201
package/dist/layout.d.ts
DELETED
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map from a single grapheme character to its pre-measured glyph metrics.
|
|
3
|
-
*
|
|
4
|
-
* Each entry provides the glyph's pixel `width` at `baseSize`, and an `ast`
|
|
5
|
-
* property holding the raw vector path data used by the renderer.
|
|
6
|
-
*/
|
|
7
|
-
interface GlyphAtlas {
|
|
8
|
-
[char: string]: {
|
|
9
|
-
width: number;
|
|
10
|
-
baseSize: number;
|
|
11
|
-
ast: any;
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Resolves the pixel advance width of a single grapheme at a given font size,
|
|
16
|
-
* for glyphs not present in a pre-baked {@link GlyphAtlas}.
|
|
17
|
-
*
|
|
18
|
-
* Implemented by {@link createCanvasMeasurer} (canvas `measureText`), but kept
|
|
19
|
-
* abstract so callers can supply their own metrics source.
|
|
20
|
-
*/
|
|
21
|
-
interface GlyphMeasurer {
|
|
22
|
-
measure(char: string, fontSize: number): number;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Per-run inline style for rich text ({@link LayoutEngine.prepareRich}). All
|
|
26
|
-
* fields are optional and inherited from the call's base style when omitted.
|
|
27
|
-
*/
|
|
28
|
-
interface TextStyle {
|
|
29
|
-
/** Font size in px for this run; overrides the base size (affects width + line height). */
|
|
30
|
-
fontSize?: number;
|
|
31
|
-
/** Fill color, e.g. `'#38bdf8'`. */
|
|
32
|
-
color?: string;
|
|
33
|
-
/** Bold weight (rendering only; width still measured at base metrics). */
|
|
34
|
-
bold?: boolean;
|
|
35
|
-
/** Italic slant (rendering only). */
|
|
36
|
-
italic?: boolean;
|
|
37
|
-
/** Hyperlink destination; carried through to the positioned nodes for hit-testing / a11y. */
|
|
38
|
-
href?: string;
|
|
39
|
-
}
|
|
40
|
-
/** A run of text sharing one {@link TextStyle}, the input unit of {@link LayoutEngine.prepareRich}. */
|
|
41
|
-
interface StyledSpan {
|
|
42
|
-
text: string;
|
|
43
|
-
style?: TextStyle;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A single positioned glyph produced by {@link LayoutEngine.layoutText}.
|
|
47
|
-
*/
|
|
48
|
-
interface LayoutNode {
|
|
49
|
-
char: string;
|
|
50
|
-
x: number;
|
|
51
|
-
y: number;
|
|
52
|
-
width: number;
|
|
53
|
-
height: number;
|
|
54
|
-
/** Inline style carried from rich text; `undefined` for plain (single-style) layout. */
|
|
55
|
-
style?: TextStyle;
|
|
56
|
-
sourceIndex?: number;
|
|
57
|
-
sourceLength?: number;
|
|
58
|
-
isRTL?: boolean;
|
|
59
|
-
combining?: string[];
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* The complete output of a text layout pass — an ordered list of positioned
|
|
63
|
-
* glyphs and the total bounding-box dimensions.
|
|
64
|
-
*/
|
|
65
|
-
interface LayoutResult {
|
|
66
|
-
nodes: LayoutNode[];
|
|
67
|
-
totalWidth: number;
|
|
68
|
-
totalHeight: number;
|
|
69
|
-
fallbackToCanvas?: boolean;
|
|
70
|
-
}
|
|
71
|
-
/** A single measured grapheme (the "cold" half of the cold/hot split). */
|
|
72
|
-
interface PreparedGlyph {
|
|
73
|
-
char: string;
|
|
74
|
-
/** Advance width at the prepared `fontSize`. */
|
|
75
|
-
width: number;
|
|
76
|
-
/** Inline style (rich text only); drives per-glyph size, color and baseline. */
|
|
77
|
-
style?: TextStyle;
|
|
78
|
-
level: number;
|
|
79
|
-
sourceIndex: number;
|
|
80
|
-
sourceLength: number;
|
|
81
|
-
combining?: string[];
|
|
82
|
-
}
|
|
83
|
-
/** A measured word/segment, ready to be placed without re-measuring. */
|
|
84
|
-
interface PreparedWord {
|
|
85
|
-
glyphs: PreparedGlyph[];
|
|
86
|
-
/** Sum of glyph advances — used for word-level wrap decisions. */
|
|
87
|
-
width: number;
|
|
88
|
-
isWordLike: boolean | undefined;
|
|
89
|
-
/** Pre-computed `word.trim().length === 0`. */
|
|
90
|
-
isWhitespace: boolean;
|
|
91
|
-
}
|
|
92
|
-
/** A measured paragraph; `isEmpty` marks a blank line (forced newline). */
|
|
93
|
-
interface PreparedParagraph {
|
|
94
|
-
words: PreparedWord[];
|
|
95
|
-
isEmpty: boolean;
|
|
96
|
-
fallbackToCanvas?: boolean;
|
|
97
|
-
baseLevel?: number;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* The result of the **cold** measurement pass ({@link LayoutEngine.prepare}):
|
|
101
|
-
* segmented + measured text that is independent of layout constraints
|
|
102
|
-
* (`maxWidth`/`maxHeight`/exclusion masks). Reuse it across cheap **hot**
|
|
103
|
-
* re-layouts ({@link LayoutEngine.layoutPrepared}) on resize / reposition,
|
|
104
|
-
* avoiding the per-frame `Intl.Segmenter` + measurement cost.
|
|
105
|
-
*/
|
|
106
|
-
interface PreparedText {
|
|
107
|
-
paragraphs: PreparedParagraph[];
|
|
108
|
-
fontSize: number;
|
|
109
|
-
fallbackToCanvas?: boolean;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* A rectangular region (in the text's local coordinate space) that text must
|
|
113
|
-
* flow around — the v1 of text flow exclusion shapes. A left/right rect acts
|
|
114
|
-
* like a CSS float; a centered rect splits the affected lines in two.
|
|
115
|
-
*/
|
|
116
|
-
interface ExclusionRect {
|
|
117
|
-
x: number;
|
|
118
|
-
y: number;
|
|
119
|
-
width: number;
|
|
120
|
-
height: number;
|
|
121
|
-
}
|
|
122
|
-
/** A free horizontal interval `[x0, x1)` available for text on one line. */
|
|
123
|
-
interface LineSegment {
|
|
124
|
-
x0: number;
|
|
125
|
-
x1: number;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* The free horizontal segments left in `[0, maxWidth]` for a line whose box
|
|
129
|
-
* spans the vertical band `[top, bottom)`, after subtracting every
|
|
130
|
-
* {@link ExclusionRect} that overlaps that band. Returns the full width when
|
|
131
|
-
* nothing overlaps, and `[]` when an exclusion (or union of them) spans the
|
|
132
|
-
* whole width. Pure — the testable core of exclusion flow.
|
|
133
|
-
*
|
|
134
|
-
* Time O(n log n) in the number of overlapping exclusions; space O(n).
|
|
135
|
-
*/
|
|
136
|
-
declare function computeLineSegments(top: number, bottom: number, maxWidth: number, exclusions: ExclusionRect[]): LineSegment[];
|
|
137
|
-
/**
|
|
138
|
-
* VectoJS Global Layout Engine (Intl.Segmenter)
|
|
139
|
-
* Advanced Typography Engine supporting CJK, Emoji, and Western Graphemes
|
|
140
|
-
*/
|
|
141
|
-
declare class LayoutEngine {
|
|
142
|
-
maxWidth: number;
|
|
143
|
-
maxHeight: number;
|
|
144
|
-
preserveLeadingSpaces: boolean;
|
|
145
|
-
private wordSegmenter;
|
|
146
|
-
private charSegmenter;
|
|
147
|
-
private wordCache;
|
|
148
|
-
private graphemeCache;
|
|
149
|
-
private paragraphCache;
|
|
150
|
-
private richParagraphCache;
|
|
151
|
-
private lastAtlas;
|
|
152
|
-
private measurer;
|
|
153
|
-
constructor(maxWidth: number, maxHeight: number, measurer?: GlyphMeasurer | null);
|
|
154
|
-
private getWordSegments;
|
|
155
|
-
/**
|
|
156
|
-
* Resolve a grapheme's advance width at `fontSize`, in priority order:
|
|
157
|
-
* pre-baked atlas entry → injected {@link GlyphMeasurer} → `0.5em` fallback.
|
|
158
|
-
*/
|
|
159
|
-
private glyphWidth;
|
|
160
|
-
private getGraphemes;
|
|
161
|
-
/**
|
|
162
|
-
* Lay out a Unicode string into a list of positioned {@link LayoutNode} glyphs.
|
|
163
|
-
*
|
|
164
|
-
* Uses `Intl.Segmenter` to correctly handle CJK, emoji, and Western word
|
|
165
|
-
* boundaries. An optional `exclusionMask` callback allows glyphs to flow
|
|
166
|
-
* around arbitrary shapes (e.g. physics bodies or video regions).
|
|
167
|
-
*
|
|
168
|
-
* @param text - The raw text string to lay out (newlines force paragraph breaks).
|
|
169
|
-
* @param fontAtlas - Pre-measured glyph metrics keyed by grapheme character.
|
|
170
|
-
* @param fontSize - Target font size in pixels (default: `32`).
|
|
171
|
-
* @param exclusionMask - Optional callback returning `true` when a candidate
|
|
172
|
-
* glyph bounding box overlaps a forbidden region; the engine skips that
|
|
173
|
-
* position and advances horizontally.
|
|
174
|
-
* @returns A {@link LayoutResult} with all positioned glyph nodes and total dimensions.
|
|
175
|
-
* @example
|
|
176
|
-
* const result = engine.layoutText('Hello 世界', atlas, 24);
|
|
177
|
-
* result.nodes.forEach(n => console.log(n.char, n.x, n.y));
|
|
178
|
-
*/
|
|
179
|
-
layoutText(text: string, fontAtlas: GlyphAtlas, fontSize?: number, exclusionMask?: (x: number, y: number, w: number, h: number) => boolean): LayoutResult;
|
|
180
|
-
/**
|
|
181
|
-
* **Cold pass.** Segment and measure `text` once into a reusable
|
|
182
|
-
* {@link PreparedText}. Runs `Intl.Segmenter` (word + grapheme) and resolves
|
|
183
|
-
* each grapheme's advance width — the expensive work. The result is
|
|
184
|
-
* independent of `maxWidth`/`maxHeight`/exclusion masks, so it can be re-laid
|
|
185
|
-
* out cheaply by {@link layoutPrepared} on resize / reposition / animation.
|
|
186
|
-
*
|
|
187
|
-
* @param text - The raw text string (newlines force paragraph breaks).
|
|
188
|
-
* @param fontAtlas - Pre-measured glyph metrics keyed by grapheme character.
|
|
189
|
-
* @param fontSize - Target font size in pixels (default: `32`).
|
|
190
|
-
*/
|
|
191
|
-
prepare(text: string, fontAtlas: GlyphAtlas, fontSize?: number): PreparedText;
|
|
192
|
-
/**
|
|
193
|
-
* **Cold pass for rich text.** Like {@link prepare}, but takes an array of
|
|
194
|
-
* {@link StyledSpan}s so different inline runs (bold / italic / color / size /
|
|
195
|
-
* links) compose on the same wrapped lines. Each grapheme carries the
|
|
196
|
-
* (base-merged) style of the span it came from — so a style change *mid-word*
|
|
197
|
-
* (e.g. `He` + **`llo`**) is honored. Run `fontSize` affects measured width and
|
|
198
|
-
* line height; the rest is rendering metadata carried through to the nodes.
|
|
199
|
-
*
|
|
200
|
-
* The result feeds the same {@link layoutPrepared} as plain text.
|
|
201
|
-
*
|
|
202
|
-
* @param spans - The styled runs, in document order.
|
|
203
|
-
* @param fontAtlas - Pre-measured glyph metrics keyed by grapheme character.
|
|
204
|
-
* @param baseFontSize - Size for runs without an explicit `fontSize` (default 32).
|
|
205
|
-
* @param baseStyle - Style inherited by every run (each run's own style wins).
|
|
206
|
-
*/
|
|
207
|
-
prepareRich(spans: StyledSpan[], fontAtlas: GlyphAtlas, baseFontSize?: number, baseStyle?: TextStyle): PreparedText;
|
|
208
|
-
/**
|
|
209
|
-
* **Hot pass.** Place an already-measured {@link PreparedText} into positioned
|
|
210
|
-
* glyphs. Does only wrap/positioning arithmetic — no `Intl.Segmenter`, no
|
|
211
|
-
* re-measurement — so it is cheap enough to call every frame or on every
|
|
212
|
-
* resize. Reads the engine's current `maxWidth`/`maxHeight`, so changing those
|
|
213
|
-
* and re-calling reflows the same prepared text.
|
|
214
|
-
*
|
|
215
|
-
* @param prepared - Output of {@link prepare}.
|
|
216
|
-
* @param exclusionMask - Optional per-glyph collision callback (see {@link layoutText}).
|
|
217
|
-
* @param exclusions - Optional rect regions text flows around (exclusion shapes); each
|
|
218
|
-
* line is split into the free x-segments left after subtracting them. Omitting
|
|
219
|
-
* it (or passing `[]`) leaves the single-column path byte-for-byte unchanged.
|
|
220
|
-
*/
|
|
221
|
-
layoutPrepared(prepared: PreparedText, exclusionMask?: (x: number, y: number, w: number, h: number) => boolean, exclusions?: ExclusionRect[]): LayoutResult;
|
|
222
|
-
/**
|
|
223
|
-
* Lay out a Unicode string directly into a pre-allocated {@link LayoutResultBuffer}.
|
|
224
|
-
*
|
|
225
|
-
* Avoids GC allocations by writing results directly to flat typed arrays in the buffer.
|
|
226
|
-
*
|
|
227
|
-
* @param text - The raw text string to lay out.
|
|
228
|
-
* @param fontAtlas - Pre-measured glyph metrics keyed by grapheme character.
|
|
229
|
-
* @param fontSize - Target font size in pixels.
|
|
230
|
-
* @param buffer - The pre-allocated buffer to write layout results into.
|
|
231
|
-
* @param exclusionMask - Optional collision-detection callback.
|
|
232
|
-
*/
|
|
233
|
-
layoutTextIntoBuffer(text: string, fontAtlas: GlyphAtlas, fontSize: number, buffer: LayoutResultBuffer, exclusionMask?: (x: number, y: number, w: number, h: number) => boolean): void;
|
|
234
|
-
/**
|
|
235
|
-
* **Hot pass, zero-GC variant.** Place an already-measured {@link PreparedText}
|
|
236
|
-
* directly into a pre-allocated {@link LayoutResultBuffer}. Like
|
|
237
|
-
* {@link layoutPrepared} but writes flat typed arrays instead of allocating
|
|
238
|
-
* {@link LayoutNode} objects — the per-frame path for large dynamic scenes.
|
|
239
|
-
*/
|
|
240
|
-
layoutPreparedIntoBuffer(prepared: PreparedText, buffer: LayoutResultBuffer, exclusionMask?: (x: number, y: number, w: number, h: number) => boolean): void;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Pre-allocated buffer for zero-GC layout results.
|
|
244
|
-
* Reuse a single instance across frames by calling reset() before each layout pass.
|
|
245
|
-
*/
|
|
246
|
-
declare class LayoutResultBuffer {
|
|
247
|
-
static readonly CAPACITY = 16384;
|
|
248
|
-
/** X positions of each glyph. */
|
|
249
|
-
xs: Float32Array;
|
|
250
|
-
/** Y positions of each glyph. */
|
|
251
|
-
ys: Float32Array;
|
|
252
|
-
/** Widths of each glyph. */
|
|
253
|
-
ws: Float32Array;
|
|
254
|
-
/** Heights of each glyph. */
|
|
255
|
-
hs: Float32Array;
|
|
256
|
-
/** Character for each glyph slot. */
|
|
257
|
-
chars: string[];
|
|
258
|
-
/** Number of valid glyphs written in this buffer. */
|
|
259
|
-
count: number;
|
|
260
|
-
/** Reset the buffer for reuse. Does NOT free memory. */
|
|
261
|
-
reset(): void;
|
|
262
|
-
/** Convert to the standard LayoutResult format (allocates — use sparingly). */
|
|
263
|
-
toLayoutResult(): LayoutResult;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Create a {@link GlyphMeasurer} backed by a single lazily-created offscreen
|
|
268
|
-
* Canvas 2D context.
|
|
269
|
-
*
|
|
270
|
-
* Each grapheme is measured once at `baseSize` and cached; because canvas
|
|
271
|
-
* `measureText` advance width is linear in font size, later queries at any
|
|
272
|
-
* `fontSize` are derived by pure arithmetic (no re-measure). This gives the
|
|
273
|
-
* {@link LayoutEngine} real per-glyph metrics for text that has no pre-baked
|
|
274
|
-
* vector atlas, fixing the coarse `0.5em` line-breaking fallback.
|
|
275
|
-
*
|
|
276
|
-
* Returns `null` in DOM-free environments (SSR, workers without a canvas) so
|
|
277
|
-
* callers stay portable and the engine keeps its `0.5em` fallback.
|
|
278
|
-
*
|
|
279
|
-
* @param fontFamily - CSS font family used for measurement; should match what
|
|
280
|
-
* the renderer actually draws (e.g. `TextEntity` falls back to `sans-serif`).
|
|
281
|
-
* @param baseSize - Pixel size at which each glyph is measured and cached.
|
|
282
|
-
* @returns A measurer, or `null` when no Canvas 2D context is available.
|
|
283
|
-
*/
|
|
284
|
-
declare function createCanvasMeasurer(fontFamily?: string, baseSize?: number): GlyphMeasurer | null;
|
|
285
|
-
|
|
286
|
-
interface LayoutWorkerResponse {
|
|
287
|
-
id: string;
|
|
288
|
-
seqId: number;
|
|
289
|
-
width: number;
|
|
290
|
-
height: number;
|
|
291
|
-
codePoints: Uint32Array;
|
|
292
|
-
xCoords: Float32Array;
|
|
293
|
-
yCoords: Float32Array;
|
|
294
|
-
packedStyles: Uint32Array;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
declare class LayoutWorkerManager {
|
|
298
|
-
private static instance;
|
|
299
|
-
private worker;
|
|
300
|
-
private registeredFonts;
|
|
301
|
-
private pendingCallbacks;
|
|
302
|
-
private seqIdCounter;
|
|
303
|
-
private debounceTimers;
|
|
304
|
-
private constructor();
|
|
305
|
-
static getInstance(): LayoutWorkerManager;
|
|
306
|
-
queueLayout(entityId: string, text: string, options: {
|
|
307
|
-
fontId: string;
|
|
308
|
-
fontSize: number;
|
|
309
|
-
maxWidth: number;
|
|
310
|
-
maxHeight: number;
|
|
311
|
-
fontData?: any;
|
|
312
|
-
lineHeight?: number;
|
|
313
|
-
letterSpacing?: number;
|
|
314
|
-
callback: (res: LayoutWorkerResponse) => void;
|
|
315
|
-
}): void;
|
|
316
|
-
cancelLayout(entityId: string): void;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export { type ExclusionRect, type GlyphAtlas, type GlyphMeasurer, LayoutEngine, type LayoutNode, type LayoutResult, LayoutResultBuffer, LayoutWorkerManager, type LineSegment, type PreparedGlyph, type PreparedParagraph, type PreparedText, type PreparedWord, type StyledSpan, type TextStyle, computeLineSegments, createCanvasMeasurer };
|
package/dist/renderer.d.mts
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export { C as CanvasRenderer, k as PointRenderer, R as RGBA, S as SVGLinearGradient, l as SVGRenderer, W as WebGPUParticleSystemManager, m as createWebGLPointRenderer, p as parseColorToRGBA } from './index-ByBDSmMK.mjs';
|
|
2
|
-
export { I as IRenderer } from './Entity-D-rfAFCf.mjs';
|
package/dist/renderer.d.ts
DELETED
package/dist/text.d.mts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { E as Entity, I as IRenderer } from './Entity-D-rfAFCf.mjs';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* MSDF (Multi-channel Signed Distance Field) font support.
|
|
5
|
-
*
|
|
6
|
-
* Parses the `msdf-atlas-gen` JSON layout — the de-facto MSDF format produced by
|
|
7
|
-
* Chlumsky's `msdf-atlas-gen` / `msdfgen` — and lays a string out into textured
|
|
8
|
-
* quads positioned in CSS pixels with atlas UVs. Pair {@link MSDFFont.layout}
|
|
9
|
-
* with the WebGL backend's `setMSDFTexture` + `addGlyph` to render GPU text that
|
|
10
|
-
* stays crisp at any scale (and supports outline/glow in the shader).
|
|
11
|
-
*
|
|
12
|
-
* Geometry conventions match the renderer: local space is y-down, top-left
|
|
13
|
-
* origin; UVs use v=0 at the top of the atlas image (atlas uploaded without a
|
|
14
|
-
* Y-flip, the same as `setTexture`/`addSprite`).
|
|
15
|
-
*/
|
|
16
|
-
/** Atlas section of an `msdf-atlas-gen` JSON file. */
|
|
17
|
-
interface MSDFAtlasInfo {
|
|
18
|
-
/** Field type, e.g. `'msdf'` | `'mtsdf'` | `'sdf'`. */
|
|
19
|
-
type: string;
|
|
20
|
-
/** Distance field range in atlas pixels — drives the shader's edge sharpness. */
|
|
21
|
-
distanceRange: number;
|
|
22
|
-
/** Glyph size the atlas was rasterized at (em → px), informational. */
|
|
23
|
-
size: number;
|
|
24
|
-
/** Atlas image width in pixels. */
|
|
25
|
-
width: number;
|
|
26
|
-
/** Atlas image height in pixels. */
|
|
27
|
-
height: number;
|
|
28
|
-
/** Whether `atlasBounds` are measured from the image bottom or top. */
|
|
29
|
-
yOrigin: 'bottom' | 'top';
|
|
30
|
-
}
|
|
31
|
-
/** Font-wide metrics in em units. */
|
|
32
|
-
interface MSDFMetrics {
|
|
33
|
-
emSize: number;
|
|
34
|
-
/** Line advance in em (multiply by font size for px). */
|
|
35
|
-
lineHeight: number;
|
|
36
|
-
/** Distance from baseline to the top of the line in em (positive, up). */
|
|
37
|
-
ascender: number;
|
|
38
|
-
/** Distance from baseline to the bottom in em (negative, down). */
|
|
39
|
-
descender: number;
|
|
40
|
-
underlineY?: number;
|
|
41
|
-
underlineThickness?: number;
|
|
42
|
-
}
|
|
43
|
-
/** Em-unit / atlas-pixel rectangle as emitted by `msdf-atlas-gen`. */
|
|
44
|
-
interface MSDFBounds {
|
|
45
|
-
left: number;
|
|
46
|
-
bottom: number;
|
|
47
|
-
right: number;
|
|
48
|
-
top: number;
|
|
49
|
-
}
|
|
50
|
-
/** One glyph's metrics. Whitespace has `advance` but no plane/atlas bounds. */
|
|
51
|
-
interface MSDFGlyphDef {
|
|
52
|
-
unicode: number;
|
|
53
|
-
/** Horizontal advance in em units. */
|
|
54
|
-
advance: number;
|
|
55
|
-
/** Quad position relative to the baseline, em units, y-up. */
|
|
56
|
-
planeBounds?: MSDFBounds;
|
|
57
|
-
/** Source rectangle in the atlas, pixels. */
|
|
58
|
-
atlasBounds?: MSDFBounds;
|
|
59
|
-
}
|
|
60
|
-
/** Kerning pair adjustment in em units. */
|
|
61
|
-
interface MSDFKerning {
|
|
62
|
-
unicode1: number;
|
|
63
|
-
unicode2: number;
|
|
64
|
-
advance: number;
|
|
65
|
-
}
|
|
66
|
-
/** A parsed `msdf-atlas-gen` JSON document. */
|
|
67
|
-
interface MSDFFontData {
|
|
68
|
-
atlas: MSDFAtlasInfo;
|
|
69
|
-
metrics: MSDFMetrics;
|
|
70
|
-
glyphs: MSDFGlyphDef[];
|
|
71
|
-
kerning?: MSDFKerning[];
|
|
72
|
-
}
|
|
73
|
-
/** A glyph positioned for rendering: a CSS-pixel quad + atlas UVs (0..1). */
|
|
74
|
-
interface PositionedGlyph {
|
|
75
|
-
/** Source character (may be a surrogate-pair astral codepoint). */
|
|
76
|
-
char: string;
|
|
77
|
-
/** Quad top-left in local CSS pixels (y-down). */
|
|
78
|
-
x: number;
|
|
79
|
-
y: number;
|
|
80
|
-
/** Quad size in CSS pixels. */
|
|
81
|
-
w: number;
|
|
82
|
-
h: number;
|
|
83
|
-
/** Atlas UVs: `(u0,v0)` top-left, `(u1,v1)` bottom-right; v=0 is the atlas top. */
|
|
84
|
-
u0: number;
|
|
85
|
-
v0: number;
|
|
86
|
-
u1: number;
|
|
87
|
-
v1: number;
|
|
88
|
-
}
|
|
89
|
-
/** Result of {@link MSDFFont.layout}. */
|
|
90
|
-
interface MSDFLayoutResult {
|
|
91
|
-
glyphs: PositionedGlyph[];
|
|
92
|
-
/** Total pen advance of the widest line in CSS pixels. */
|
|
93
|
-
width: number;
|
|
94
|
-
/** `lineCount × lineHeight × fontSize` in CSS pixels. */
|
|
95
|
-
height: number;
|
|
96
|
-
}
|
|
97
|
-
/** Options for {@link MSDFFont.layout}. */
|
|
98
|
-
interface MSDFLayoutOptions {
|
|
99
|
-
/** Pen origin x (left of the first glyph), CSS pixels. Default 0. */
|
|
100
|
-
x?: number;
|
|
101
|
-
/** Text-block top y (baseline of line 0 = `y + ascender×size`). Default 0. */
|
|
102
|
-
y?: number;
|
|
103
|
-
/** Extra advance added after every glyph, CSS pixels. Default 0. */
|
|
104
|
-
letterSpacing?: number;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* A loaded MSDF font. Construct from parsed {@link MSDFFontData}, or use
|
|
108
|
-
* {@link MSDFFont.parse} to read the JSON string straight from `msdf-atlas-gen`.
|
|
109
|
-
*/
|
|
110
|
-
declare class MSDFFont {
|
|
111
|
-
private static idCounter;
|
|
112
|
-
readonly id: string;
|
|
113
|
-
readonly data: MSDFFontData;
|
|
114
|
-
private readonly byCode;
|
|
115
|
-
private readonly kern;
|
|
116
|
-
constructor(data: MSDFFontData);
|
|
117
|
-
/** Parse the `msdf-atlas-gen` JSON (string or already-parsed object). */
|
|
118
|
-
static parse(json: string | MSDFFontData): MSDFFont;
|
|
119
|
-
/** Get a glyph's definition by its unicode value in O(1) time. */
|
|
120
|
-
getGlyph(unicode: number): MSDFGlyphDef | undefined;
|
|
121
|
-
/** Distance field range in atlas pixels (for the shader's `u_distanceRange`). */
|
|
122
|
-
get distanceRange(): number;
|
|
123
|
-
get atlasWidth(): number;
|
|
124
|
-
get atlasHeight(): number;
|
|
125
|
-
/**
|
|
126
|
-
* Lay `text` out at `fontSizePx`. Returns positioned quads (skipping glyphs the
|
|
127
|
-
* font doesn't contain), the widest line's advance, and the total block height.
|
|
128
|
-
* Honors `\n`, kerning pairs, and `letterSpacing`.
|
|
129
|
-
*/
|
|
130
|
-
layout(text: string, fontSizePx: number, opts?: MSDFLayoutOptions): MSDFLayoutResult;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
interface MSDFTextEntityOptions {
|
|
134
|
-
font: MSDFFont;
|
|
135
|
-
texture: TexImageSource;
|
|
136
|
-
fallbackFont?: string;
|
|
137
|
-
fontSize?: number;
|
|
138
|
-
color?: string;
|
|
139
|
-
lineHeight?: number;
|
|
140
|
-
letterSpacing?: number;
|
|
141
|
-
}
|
|
142
|
-
declare class MSDFTextEntity extends Entity {
|
|
143
|
-
private font;
|
|
144
|
-
private texture;
|
|
145
|
-
private fallbackFont;
|
|
146
|
-
private fontSize;
|
|
147
|
-
color: string;
|
|
148
|
-
private letterSpacing;
|
|
149
|
-
private lineHeight?;
|
|
150
|
-
private text;
|
|
151
|
-
private lastRenderedSeqId;
|
|
152
|
-
private rgbColorCache;
|
|
153
|
-
private fontStringCache;
|
|
154
|
-
private layoutResult;
|
|
155
|
-
constructor(text: string, options: MSDFTextEntityOptions);
|
|
156
|
-
setText(text: string): void;
|
|
157
|
-
isPointInside(globalX: number, globalY: number): boolean;
|
|
158
|
-
render(renderer: any): void;
|
|
159
|
-
destroy(): void;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
declare class SVGEntity extends Entity {
|
|
163
|
-
private svgSource;
|
|
164
|
-
private imageBitmap;
|
|
165
|
-
private imageElement;
|
|
166
|
-
private blobURL;
|
|
167
|
-
private currentImg;
|
|
168
|
-
private lodTimeout;
|
|
169
|
-
private cachedDoc;
|
|
170
|
-
private baseWidth;
|
|
171
|
-
private baseHeight;
|
|
172
|
-
private lastRasterizedScale;
|
|
173
|
-
private targetScale;
|
|
174
|
-
constructor(svgSource: string, id?: string);
|
|
175
|
-
setSVGSource(svgSource: string): void;
|
|
176
|
-
private parseSVGDimensions;
|
|
177
|
-
private triggerRasterization;
|
|
178
|
-
isPointInside(globalX: number, globalY: number): boolean;
|
|
179
|
-
render(r: IRenderer): void;
|
|
180
|
-
destroy(): void;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
interface ShapedResult {
|
|
184
|
-
shapedText: string;
|
|
185
|
-
indexMap: Int32Array;
|
|
186
|
-
}
|
|
187
|
-
declare class ArabicShaper {
|
|
188
|
-
private static MAPPINGS;
|
|
189
|
-
private static isHarakat;
|
|
190
|
-
private static getJoiningType;
|
|
191
|
-
static shapeArabic(text: string): ShapedResult;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
declare class BidiResolver {
|
|
195
|
-
private static getDirectionClass;
|
|
196
|
-
static getBaseLevel(text: string): number;
|
|
197
|
-
static resolveLevels(text: string): Uint8Array;
|
|
198
|
-
static reorderVisual(nodes: any[], baseLevel: number): void;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export { ArabicShaper, BidiResolver, type MSDFAtlasInfo, type MSDFBounds, MSDFFont, type MSDFFontData, type MSDFGlyphDef, type MSDFKerning, type MSDFLayoutOptions, type MSDFLayoutResult, type MSDFMetrics, MSDFTextEntity, type MSDFTextEntityOptions, type PositionedGlyph, SVGEntity, type ShapedResult };
|