@navaramap/font 0.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/src/types.ts ADDED
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Pixel size at which COLRv1 color glyphs are rasterized into the color atlas.
3
+ * Must match `COLOR_GLYPH_PX_SIZE` in `crates/navara_wasm_font_worker/src/color_raster.rs`.
4
+ */
5
+ export const COLOR_GLYPH_PX_SIZE = 64.0;
6
+
7
+ /**
8
+ * Pixel range over which a quality's atlas distance field ramps from
9
+ * "outside" to "inside" (i.e. the value covered by `d - 0.5` in the shader).
10
+ * Converts an outline-thickness expressed in pixels into a delta on the
11
+ * sampled distance value.
12
+ *
13
+ * SDF: `SDF_RADIUS` (35) in `crates/navara_wasm_font_worker/src/atlas.rs`.
14
+ * MSDF: `MSDF_RANGE_PX` (8) in `crates/navara_wasm_font_worker/src/msdf.rs`.
15
+ */
16
+ export const atlasRangePx = (highQuality: boolean): number =>
17
+ highQuality ? 8.0 : 35.0;
18
+
19
+ /** Glyph metrics from either the SDF or the color atlas. */
20
+ export type GlyphMetrics = {
21
+ glyphId: number;
22
+ /** Unique font index within the atlas (distinguishes glyphs from different fonts). */
23
+ fontIndex: number;
24
+ /** Pre-computed composite key (font_index, glyph_id) from WASM. */
25
+ compositeKey: bigint;
26
+ atlasX: number;
27
+ atlasY: number;
28
+ atlasW: number;
29
+ atlasH: number;
30
+ bearingX: number;
31
+ bearingY: number;
32
+ /** True when this glyph lives in the COLRv1 color atlas (RGBA) rather than the SDF atlas (R8). */
33
+ isColor: boolean;
34
+ };
35
+
36
+ /**
37
+ * Per-glyph character class used for line breaking during layout.
38
+ * Must match the `CHAR_CLASS_*` constants in
39
+ * `crates/navara_wasm_font_worker/src/shaping.rs`.
40
+ */
41
+ export const GlyphCharClass = {
42
+ Normal: 0,
43
+ /** Breakable whitespace: a line may wrap here, dropping the glyph. */
44
+ Whitespace: 1,
45
+ /** Synthetic hard-break marker (zero advance, no atlas entry). */
46
+ Newline: 2,
47
+ /** CJK-style character: a line may break after this glyph. */
48
+ Ideographic: 3,
49
+ } as const;
50
+
51
+ /** A single shaped glyph with positioning info. */
52
+ export type ShapedGlyph = {
53
+ glyphId: number;
54
+ /** Unique font index within the atlas (distinguishes glyphs from different fonts). */
55
+ fontIndex: number;
56
+ /** Pre-computed composite key (font_index, glyph_id) from WASM. */
57
+ compositeKey: bigint;
58
+ xAdvance: number;
59
+ yAdvance: number;
60
+ xOffset: number;
61
+ yOffset: number;
62
+ /** One of `GlyphCharClass` (line-break info). */
63
+ charClass: number;
64
+ };
65
+
66
+ /** Result from shaping text: glyph positions + atlas metrics. */
67
+ export type ShapeTextResult = {
68
+ glyphs: ShapedGlyph[];
69
+ metrics: GlyphMetrics[];
70
+ /** Font units per em (needed for converting font-unit to pixel space) */
71
+ unitsPerEm: number;
72
+ /** Ascender in font units (hhea), for multi-line layout. */
73
+ ascender: number;
74
+ /** Descender in font units (hhea, negative below baseline). */
75
+ descender: number;
76
+ /** Extra line gap in font units (hhea). */
77
+ lineGap: number;
78
+ /** FontManager-internal: the atlas generation these metrics were built
79
+ * under. When the atlas evicts glyphs its generation bumps, marking older
80
+ * cached results stale so they are re-shaped on next use. Unset on results
81
+ * fresh from the worker; the FontManager stamps it when caching. */
82
+ _generation?: number;
83
+ };
84
+
85
+ /** SDF/MSDF atlas texture data.
86
+ *
87
+ * `channels` selects the GPU texture format:
88
+ * - 1 → R8 (single-channel SDF, sampled as `.r`).
89
+ * - 4 → RGBA8. Either MTSDF (three MSDF channels + true SDF in alpha,
90
+ * sampled as `median(.rgb)` in the fragment shader) or the COLRv1 color
91
+ * atlas — distinguished by which atlas slot the data was placed in, not
92
+ * by `channels`.
93
+ *
94
+ * 3-channel MSDF (RGB8) isn't used: three.js dropped `RGBFormat` in r137,
95
+ * and the worker emits MTSDF (4 channels) for the high-quality path.
96
+ */
97
+ export type FontAtlasData = {
98
+ data: Uint8Array;
99
+ width: number;
100
+ height: number;
101
+ channels: number;
102
+ };
103
+
104
+ export type BatchPrepareTextResult = {
105
+ results: { text: string; shapeResult: ShapeTextResult | null }[];
106
+ /** Snapshot of the SDF atlas, if any glyphs were added during the batch. */
107
+ atlas: FontAtlasData | null;
108
+ /** Snapshot of the COLRv1 color atlas (RGBA), if any color glyphs were added during the batch. */
109
+ colorAtlas: FontAtlasData | null;
110
+ /** The atlas key used for this batch (family name or font URL). */
111
+ atlasKey: string;
112
+ /** True if any glyph was evicted during this batch. The reused rects mean
113
+ * cached shape results for this atlas may be stale, so the FontManager bumps
114
+ * the atlas generation to force a re-shape on next use. Optional only so
115
+ * callers needn't construct it (the worker always sends it). */
116
+ evicted?: boolean;
117
+ };
118
+
119
+ /** Snapshot of the font worker's WASM heap and font-cache memory usage. */
120
+ export type FontWorkerMemoryStats = {
121
+ /** Total WASM linear memory of the font worker (never shrinks). */
122
+ heapBytes: number;
123
+ fontCount: number;
124
+ atlasCount: number;
125
+ glyphCount: number;
126
+ /** Raw font file bytes held by the cache. */
127
+ fontBytes: number;
128
+ /** Monochrome (SDF/MSDF) atlas pixel bytes. */
129
+ atlasBytes: number;
130
+ /** COLRv1 color atlas pixel bytes. */
131
+ colorAtlasBytes: number;
132
+ /** Configured cache budget; undefined when unlimited. */
133
+ budgetBytes?: number;
134
+ };
135
+
136
+ /** Inclusive codepoint range covered by a font face. */
137
+ export type UnicodeRange = {
138
+ from: number;
139
+ to: number;
140
+ };
141
+
142
+ export type FontFace = {
143
+ unicodeRanges: UnicodeRange[];
144
+ url: string;
145
+ };
146
+
147
+ export type FontFamily = {
148
+ family: string;
149
+ faces: FontFace[];
150
+ };
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />