claude-exode-mcp 7.5.8 → 7.5.10

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.
Files changed (57) hide show
  1. package/fonts/featured/anybody.json.gz +0 -0
  2. package/fonts/featured/big-shoulders.json.gz +0 -0
  3. package/fonts/featured/fraunces.json.gz +0 -0
  4. package/fonts/featured/index.json +247 -0
  5. package/fonts/featured/recursive.json.gz +0 -0
  6. package/fonts/featured/roboto-flex.json.gz +0 -0
  7. package/index.d.ts +1 -1
  8. package/index.js +9 -4
  9. package/package.json +6 -2
  10. package/render-runtime/exode-runtime.js +31 -26
  11. package/skills/creative-motion/references/gotchas.md +8 -0
  12. package/src/buildKit.d.ts.map +1 -1
  13. package/src/buildKit.js +10 -1
  14. package/src/buildKit.js.map +1 -1
  15. package/src/buildKit.ts +10 -1
  16. package/src/fontCatalog.d.ts +23 -0
  17. package/src/fontCatalog.d.ts.map +1 -0
  18. package/src/fontCatalog.js +81 -0
  19. package/src/fontCatalog.js.map +1 -0
  20. package/src/fontCatalog.ts +72 -0
  21. package/src/fonts/embedFonts.d.ts +5 -0
  22. package/src/fonts/embedFonts.d.ts.map +1 -0
  23. package/src/fonts/embedFonts.js +125 -0
  24. package/src/fonts/embedFonts.js.map +1 -0
  25. package/src/fonts/embedFonts.ts +122 -0
  26. package/src/fonts/exodeFonts.d.ts +130 -0
  27. package/src/fonts/exodeFonts.d.ts.map +1 -0
  28. package/src/fonts/exodeFonts.js +882 -0
  29. package/src/fonts/exodeFonts.js.map +1 -0
  30. package/src/fonts/exodeFonts.ts +902 -0
  31. package/src/fonts/extractFont.d.ts +50 -0
  32. package/src/fonts/extractFont.d.ts.map +1 -0
  33. package/src/fonts/extractFont.js +362 -0
  34. package/src/fonts/extractFont.js.map +1 -0
  35. package/src/fonts/extractFont.ts +362 -0
  36. package/src/fonts/sansGenerator.d.ts +172 -0
  37. package/src/fonts/sansGenerator.d.ts.map +1 -0
  38. package/src/fonts/sansGenerator.js +799 -0
  39. package/src/fonts/sansGenerator.js.map +1 -0
  40. package/src/fonts/sansGenerator.ts +821 -0
  41. package/src/handlers/artboardHandlers.d.ts.map +1 -1
  42. package/src/handlers/artboardHandlers.js +15 -0
  43. package/src/handlers/artboardHandlers.js.map +1 -1
  44. package/src/handlers/artboardHandlers.ts +11 -0
  45. package/src/handlers/fontHandlers.d.ts +137 -0
  46. package/src/handlers/fontHandlers.d.ts.map +1 -0
  47. package/src/handlers/fontHandlers.js +137 -0
  48. package/src/handlers/fontHandlers.js.map +1 -0
  49. package/src/handlers/fontHandlers.ts +133 -0
  50. package/src/render/videoRenderer.d.ts.map +1 -1
  51. package/src/render/videoRenderer.js +3 -1
  52. package/src/render/videoRenderer.js.map +1 -1
  53. package/src/render/videoRenderer.ts +3 -1
  54. package/src/utils.d.ts.map +1 -1
  55. package/src/utils.js +6 -0
  56. package/src/utils.js.map +1 -1
  57. package/src/utils.ts +3 -0
@@ -0,0 +1,902 @@
1
+ // @ts-nocheck
2
+ // GENERATED by scripts/sync-exode-fonts.mjs from packages/react/src/exodeFonts.ts. Edit there, then re-run.
3
+ // Exode fonts: variable fonts that ship inside a .exode file and animate.
4
+ //
5
+ // A font is stored as "masters": every glyph's outline at the default instance plus,
6
+ // for each exposed axis, the change in every point at a few stop values on that axis.
7
+ // Drawing an instance = default + the interpolated change of each axis, so any axis
8
+ // can be keyframed or bound to an input and redrawn every frame.
9
+ //
10
+ // The axis values travel in the font family string ("Roboto Flex@wght=700;wdth=120"),
11
+ // so every caller that sets ctx.font keeps working. installExodeFontHooks() patches
12
+ // measureText / fillText / strokeText: when ctx.font names a registered Exode font the
13
+ // glyphs are drawn as paths, otherwise the browser's own text drawing runs unchanged.
14
+ // Run after editing it: node scripts/sync-exode-fonts.mjs
15
+
16
+ export interface ExodeFontAxis {
17
+ tag: string;
18
+ name: string;
19
+ min: number;
20
+ default: number;
21
+ max: number;
22
+ }
23
+
24
+ export interface ExodeFontGlyph {
25
+ /** One letter per path command: M L Q C Z. */
26
+ c: string;
27
+ /** Default-instance coordinates (font units), zigzag varints of the change from the previous x / y. */
28
+ p: string;
29
+ /** Default advance width (font units). */
30
+ a: number;
31
+ /** Per exposed axis, one entry per stop: zigzag varints of every coordinate change then the advance change ('' = no change). */
32
+ v?: Record<string, string[]>;
33
+ /** Per interacting axis group ("wdth|wght", "opsz|wght|SOFT"), the change left after the single axes and smaller groups, on the grid of the group's stops (row-major). */
34
+ x?: Record<string, string[]>;
35
+ }
36
+
37
+ export interface ExodeFontAsset {
38
+ format: 'exode-font@1';
39
+ id: string;
40
+ family: string;
41
+ source?: 'featured' | 'library' | 'upload' | 'creator';
42
+ libraryId?: string;
43
+ version?: number;
44
+ /** Content revision: changes whenever the outlines change (Font Studio edits), so embedded copies refresh. */
45
+ rev?: string;
46
+ /** Font Studio fonts keep their recipe so any file using them can reopen them in Studio. */
47
+ studio?: { params: Record<string, number>; axes: string[]; edits?: Record<string, { d: number[]; adv?: number }> };
48
+ license?: string;
49
+ designer?: string;
50
+ upm: number;
51
+ ascender: number;
52
+ descender: number;
53
+ lineGap: number;
54
+ capHeight: number;
55
+ xHeight: number;
56
+ /** Every axis the source font has. */
57
+ axes: ExodeFontAxis[];
58
+ /** Exposed axes → sorted stop values (the default is always one of them). */
59
+ stops: Record<string, number[]>;
60
+ /** Axis groups that change the outline together beyond the sum of their parts ("wdth|wght"). */
61
+ pairs?: string[];
62
+ /** Keyed by character. */
63
+ glyphs: Record<string, ExodeFontGlyph>;
64
+ /** Pair kerning at the default instance, keyed by the two characters. */
65
+ kern?: Record<string, number>;
66
+ }
67
+
68
+ // ---------------------------------------------------------------------------
69
+ // Codec: zigzag varints in base64. Shared by the editor's extractor.
70
+
71
+ const B64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
72
+ const B64_INDEX = (() => {
73
+ const t = new Int16Array(128).fill(-1);
74
+ for (let i = 0; i < 64; i++) t[B64.charCodeAt(i)] = i;
75
+ return t;
76
+ })();
77
+
78
+ function bytesToBase64(bytes: number[]): string {
79
+ let out = '';
80
+ for (let i = 0; i < bytes.length; i += 3) {
81
+ const n = (bytes[i] << 16) | ((bytes[i + 1] ?? 0) << 8) | (bytes[i + 2] ?? 0);
82
+ out += B64[(n >> 18) & 63] + B64[(n >> 12) & 63];
83
+ out += i + 1 < bytes.length ? B64[(n >> 6) & 63] : '=';
84
+ out += i + 2 < bytes.length ? B64[n & 63] : '=';
85
+ }
86
+ return out;
87
+ }
88
+
89
+ function base64ToBytes(s: string): Uint8Array {
90
+ const clean = s.replace(/=+$/, '');
91
+ const out = new Uint8Array(Math.floor((clean.length * 3) / 4));
92
+ let o = 0, buf = 0, bits = 0;
93
+ for (let i = 0; i < clean.length; i++) {
94
+ buf = (buf << 6) | B64_INDEX[clean.charCodeAt(i)];
95
+ bits += 6;
96
+ if (bits >= 8) {
97
+ bits -= 8;
98
+ out[o++] = (buf >> bits) & 255;
99
+ }
100
+ }
101
+ return out;
102
+ }
103
+
104
+ export function encodeInts(values: number[]): string {
105
+ const bytes: number[] = [];
106
+ for (const raw of values) {
107
+ const v = Math.round(raw);
108
+ let z = v >= 0 ? v * 2 : -v * 2 - 1;
109
+ while (z >= 128) {
110
+ bytes.push((z % 128) | 128);
111
+ z = Math.floor(z / 128);
112
+ }
113
+ bytes.push(z);
114
+ }
115
+ return bytesToBase64(bytes);
116
+ }
117
+
118
+ export function decodeInts(s: string): number[] {
119
+ const bytes = base64ToBytes(s);
120
+ const out: number[] = [];
121
+ let z = 0, mul = 1;
122
+ for (let i = 0; i < bytes.length; i++) {
123
+ const b = bytes[i];
124
+ z += (b & 127) * mul;
125
+ if (b & 128) {
126
+ mul *= 128;
127
+ } else {
128
+ out.push(z % 2 ? -(z + 1) / 2 : z / 2);
129
+ z = 0;
130
+ mul = 1;
131
+ }
132
+ }
133
+ return out;
134
+ }
135
+
136
+ /** Coordinates are stored as the change from the previous x (or y): small numbers, short varints. */
137
+ export function encodeCoords(coords: number[]): string {
138
+ const d: number[] = [];
139
+ let px = 0, py = 0;
140
+ for (let i = 0; i < coords.length; i += 2) {
141
+ const x = Math.round(coords[i]), y = Math.round(coords[i + 1]);
142
+ d.push(x - px, y - py);
143
+ px = x;
144
+ py = y;
145
+ }
146
+ return encodeInts(d);
147
+ }
148
+
149
+ export function decodeCoords(s: string): number[] {
150
+ const d = decodeInts(s);
151
+ let px = 0, py = 0;
152
+ for (let i = 0; i < d.length; i += 2) {
153
+ px += d[i];
154
+ py += d[i + 1];
155
+ d[i] = px;
156
+ d[i + 1] = py;
157
+ }
158
+ return d;
159
+ }
160
+
161
+ /** Number of coordinate pairs each path command uses. */
162
+ export const COMMAND_POINTS: Record<string, number> = { M: 1, L: 1, Q: 2, C: 3, Z: 0 };
163
+
164
+ // ---------------------------------------------------------------------------
165
+ // Registry
166
+
167
+ interface DecodedGlyph {
168
+ cmds: string;
169
+ base: Float64Array;
170
+ adv: number;
171
+ /** tag → per stop: coordinate deltas followed by the advance delta (null = none). */
172
+ deltas: Record<string, (Float64Array | null)[]>;
173
+ groupDeltas: Record<string, (Float64Array | null)[]>;
174
+ }
175
+
176
+ interface GlyphInstance {
177
+ path: Path2D | null;
178
+ coords: Float64Array;
179
+ adv: number;
180
+ xMin: number;
181
+ xMax: number;
182
+ yMin: number;
183
+ yMax: number;
184
+ }
185
+
186
+ interface RegisteredFont {
187
+ asset: ExodeFontAsset;
188
+ glyphs: Map<string, DecodedGlyph | null>;
189
+ instances: Map<string, GlyphInstance>;
190
+ }
191
+
192
+ const registry = new Map<string, RegisteredFont>();
193
+ const resolveCache = new Map<string, ResolvedFont | null>();
194
+ const listeners = new Set<() => void>();
195
+ let registryVersion = 0;
196
+
197
+ const normalizeFamily = (family: string) => family.trim().replace(/^['"]|['"]$/g, '').toLowerCase();
198
+
199
+ /** Register (or replace) a font. Returns true when the registry changed. */
200
+ export function registerExodeFont(asset: ExodeFontAsset): boolean {
201
+ if (!asset || asset.format !== 'exode-font@1' || !asset.family || !asset.glyphs) return false;
202
+ const key = normalizeFamily(asset.family);
203
+ const existing = registry.get(key);
204
+ if (existing && existing.asset === asset) return false;
205
+ // Keep a richer copy (more exposed axes) over a trimmed one embedded in a file.
206
+ if (existing && existing.asset.id === asset.id && (existing.asset.version ?? 0) === (asset.version ?? 0)
207
+ && (existing.asset.rev ?? '') === (asset.rev ?? '')
208
+ && Object.keys(existing.asset.stops).length > Object.keys(asset.stops).length
209
+ && Object.keys(asset.stops).every(t => t in existing.asset.stops)) {
210
+ return false;
211
+ }
212
+ registry.set(key, { asset, glyphs: new Map(), instances: new Map() });
213
+ resolveCache.clear();
214
+ registryVersion++;
215
+ listeners.forEach(l => { try { l(); } catch { /* listener errors never break drawing */ } });
216
+ return true;
217
+ }
218
+
219
+ export function registerExodeFonts(assets: ExodeFontAsset[] | undefined | null): boolean {
220
+ let changed = false;
221
+ (assets || []).forEach(a => { if (registerExodeFont(a)) changed = true; });
222
+ return changed;
223
+ }
224
+
225
+ /** Register every font embedded in a file: the active screen plus any other screens it carries. */
226
+ export function registerFontsFromFile(data: any): boolean {
227
+ if (!data) return false;
228
+ let changed = registerExodeFonts(data.fonts);
229
+ if (Array.isArray(data.screens)) data.screens.forEach((s: any) => { if (registerExodeFonts(s?.fonts)) changed = true; });
230
+ return changed;
231
+ }
232
+
233
+ export function unregisterExodeFont(family: string) {
234
+ if (registry.delete(normalizeFamily(family))) {
235
+ resolveCache.clear();
236
+ registryVersion++;
237
+ listeners.forEach(l => { try { l(); } catch { /* ignore */ } });
238
+ }
239
+ }
240
+
241
+ export function getExodeFont(family: string | undefined | null): ExodeFontAsset | null {
242
+ if (!family) return null;
243
+ return registry.get(normalizeFamily(splitFamilyAxes(family).family))?.asset ?? null;
244
+ }
245
+
246
+ export function isExodeFont(family: string | undefined | null): boolean {
247
+ return getExodeFont(family) !== null;
248
+ }
249
+
250
+ export function listExodeFonts(): ExodeFontAsset[] {
251
+ return Array.from(registry.values()).map(r => r.asset);
252
+ }
253
+
254
+ export function getExodeFontRegistryVersion() {
255
+ return registryVersion;
256
+ }
257
+
258
+ export function onExodeFontsChanged(listener: () => void): () => void {
259
+ listeners.add(listener);
260
+ return () => { listeners.delete(listener); };
261
+ }
262
+
263
+ // ---------------------------------------------------------------------------
264
+ // Family strings carry axis values: "Roboto Flex@wght=700;wdth=120". No commas: some callers
265
+ // (Fabric) only quote a family name when it has none, and a comma would split the font list.
266
+
267
+ export function splitFamilyAxes(family: string): { family: string; axes: Record<string, number>; fx?: FontFx } {
268
+ let clean = family.trim().replace(/^['"]|['"]$/g, '');
269
+ const bar = clean.indexOf('|');
270
+ const fx = bar >= 0 ? parseFx(clean.slice(bar + 1)) : undefined;
271
+ if (bar >= 0) clean = clean.slice(0, bar);
272
+ const at = clean.indexOf('@');
273
+ if (at < 0) return { family: clean, axes: {}, fx };
274
+ const axes: Record<string, number> = {};
275
+ clean.slice(at + 1).split(/[;,]/).forEach(part => {
276
+ const [tag, val] = part.split('=');
277
+ const n = parseFloat(val);
278
+ if (tag && Number.isFinite(n)) axes[tag.trim()] = n;
279
+ });
280
+ return { family: clean.slice(0, at), axes, fx };
281
+ }
282
+
283
+ /**
284
+ * The family string to draw a text object with. Plain families come back unchanged;
285
+ * Exode fonts get their axis values appended so canvas callers carry them along.
286
+ */
287
+ export function familyWithAxes(family: string, axes?: Record<string, any> | null, fx?: FontFx | null): string {
288
+ if (!family || (!axes && !fx)) return family;
289
+ const font = getExodeFont(family);
290
+ if (!font) return family;
291
+ const parts: string[] = [];
292
+ for (const tag of Object.keys(axes || {}).sort()) {
293
+ const v = Number(axes![tag]);
294
+ if (!Number.isFinite(v) || !(tag in font.stops)) continue;
295
+ parts.push(`${tag}=${Math.round(v * 100) / 100}`);
296
+ }
297
+ const fxStr = fx ? fxToString(fx) : '';
298
+ if (!parts.length && !fxStr) return family;
299
+ return `${splitFamilyAxes(family).family}${parts.length ? `@${parts.join(';')}` : ''}${fxStr ? `|${fxStr}` : ''}`;
300
+ }
301
+
302
+ // ---------------------------------------------------------------------------
303
+ // Type effects: 3D extrusion, liquid and shape warps, drawn with the glyph paths.
304
+
305
+ export interface FontFx {
306
+ /** 3D extrusion: depth (% of the font size), angle (deg, 0 = right, 90 = down), side colour, how much the side darkens toward the back (0–1). */
307
+ d3?: { on?: boolean; depth: number; angle: number; color: string; shade?: number };
308
+ /** Liquid: wobble amount and drips (% of size), phase (turns) and auto speed (turns per second, runtime). */
309
+ liquid?: { on?: boolean; amount: number; drip: number; phase?: number; speed?: number };
310
+ /** Shape warp: arc bends the line round a circle, wave ripples it, bulge swells its middle. amount −100…100. */
311
+ shape?: { on?: boolean; kind: 'arc' | 'wave' | 'bulge'; amount: number; length?: number; phase?: number };
312
+ }
313
+
314
+ const num = (v: any, d = 0) => (Number.isFinite(Number(v)) ? Math.round(Number(v) * 100) / 100 : d);
315
+ const hex6 = (c: string) => (String(c || '').replace('#', '').match(/^[0-9a-fA-F]{6}$/) ? String(c).replace('#', '') : '333333');
316
+
317
+ /** "3d:40:45:333333:0.5;lq:30:20:0:0;sh:arc:40:100:0" (no commas: some callers split font lists on them). */
318
+ export function fxToString(fx: FontFx): string {
319
+ const parts: string[] = [];
320
+ if (fx.d3 && fx.d3.on !== false && fx.d3.depth) parts.push(`3d:${num(fx.d3.depth)}:${num(fx.d3.angle, 45)}:${hex6(fx.d3.color)}:${num(fx.d3.shade, 0.4)}`);
321
+ if (fx.liquid && fx.liquid.on !== false && (fx.liquid.amount || fx.liquid.drip)) parts.push(`lq:${num(fx.liquid.amount)}:${num(fx.liquid.drip)}:${num(fx.liquid.phase)}:${num(fx.liquid.speed)}`);
322
+ if (fx.shape && fx.shape.on !== false && fx.shape.amount) parts.push(`sh:${fx.shape.kind || 'arc'}:${num(fx.shape.amount)}:${num(fx.shape.length, 100)}:${num(fx.shape.phase)}`);
323
+ return parts.join(';');
324
+ }
325
+
326
+ export function parseFx(str: string): FontFx | undefined {
327
+ const fx: FontFx = {};
328
+ str.split(';').forEach(part => {
329
+ const [k, ...v] = part.split(':');
330
+ if (k === '3d') fx.d3 = { depth: num(v[0]), angle: num(v[1], 45), color: `#${hex6(v[2])}`, shade: num(v[3], 0.4) };
331
+ else if (k === 'lq') fx.liquid = { amount: num(v[0]), drip: num(v[1]), phase: num(v[2]), speed: num(v[3]) };
332
+ else if (k === 'sh') fx.shape = { kind: (['arc', 'wave', 'bulge'].includes(v[0]) ? v[0] : 'arc') as any, amount: num(v[1]), length: num(v[2], 100), phase: num(v[3]) };
333
+ });
334
+ return fx.d3 || fx.liquid || fx.shape ? fx : undefined;
335
+ }
336
+
337
+ // ---------------------------------------------------------------------------
338
+ // Resolving ctx.font
339
+
340
+ interface ResolvedFont {
341
+ font: RegisteredFont;
342
+ size: number;
343
+ values: Record<string, number>;
344
+ signature: string;
345
+ italic: boolean;
346
+ /** True when the font has no slant/italic axis, so italics are drawn sheared. */
347
+ syntheticItalic: boolean;
348
+ fx?: FontFx;
349
+ }
350
+
351
+ const WEIGHT_WORDS: Record<string, number> = { normal: 400, bold: 700, lighter: 300, bolder: 700 };
352
+
353
+ function splitFontList(list: string): string[] {
354
+ const out: string[] = [];
355
+ let cur = '', quote = '';
356
+ for (const ch of list) {
357
+ if (quote) {
358
+ if (ch === quote) quote = '';
359
+ else cur += ch;
360
+ } else if (ch === '"' || ch === "'") {
361
+ quote = ch;
362
+ } else if (ch === ',') {
363
+ out.push(cur.trim());
364
+ cur = '';
365
+ } else {
366
+ cur += ch;
367
+ }
368
+ }
369
+ if (cur.trim()) out.push(cur.trim());
370
+ return out;
371
+ }
372
+
373
+ function resolveFont(fontString: string): ResolvedFont | null {
374
+ if (registry.size === 0) return null;
375
+ const cached = resolveCache.get(fontString);
376
+ if (cached !== undefined) return cached;
377
+ let result: ResolvedFont | null = null;
378
+ const m = /(?:^|\s)(\d*\.?\d+)px(?:\s*\/\s*\S+)?\s+(.+)$/.exec(fontString);
379
+ if (m) {
380
+ const first = splitFontList(m[2])[0] || '';
381
+ const { family, axes, fx } = splitFamilyAxes(first);
382
+ const reg = registry.get(normalizeFamily(family));
383
+ if (reg) {
384
+ const prefix = fontString.slice(0, m.index).toLowerCase().split(/\s+/);
385
+ let weight = 400, italic = false;
386
+ prefix.forEach(tok => {
387
+ if (tok === 'italic' || tok === 'oblique') italic = true;
388
+ else if (/^\d+$/.test(tok)) weight = parseInt(tok, 10);
389
+ else if (tok in WEIGHT_WORDS) weight = WEIGHT_WORDS[tok];
390
+ });
391
+ const size = parseFloat(m[1]);
392
+ const values: Record<string, number> = {};
393
+ const asset = reg.asset;
394
+ for (const tag of Object.keys(asset.stops)) {
395
+ const axis = asset.axes.find(a => a.tag === tag);
396
+ if (!axis) continue;
397
+ let v = axes[tag];
398
+ if (v === undefined) {
399
+ if (tag === 'wght') v = weight;
400
+ else if (tag === 'opsz') v = size; // like CSS font-optical-sizing: auto
401
+ else if (tag === 'ital' && italic) v = 1;
402
+ else if (tag === 'slnt' && italic) v = axis.min;
403
+ else v = axis.default;
404
+ }
405
+ values[tag] = Math.min(axis.max, Math.max(axis.min, v));
406
+ }
407
+ const hasItalicAxis = 'ital' in asset.stops || 'slnt' in asset.stops;
408
+ const signature = Object.keys(values).sort().map(t => `${t}${Math.round(values[t] * 100) / 100}`).join('|');
409
+ result = { font: reg, size, values, signature, italic, syntheticItalic: italic && !hasItalicAxis, fx };
410
+ }
411
+ }
412
+ resolveCache.set(fontString, result);
413
+ if (resolveCache.size > 2000) resolveCache.clear();
414
+ return result;
415
+ }
416
+
417
+ // ---------------------------------------------------------------------------
418
+ // Glyph instances
419
+
420
+ function decodeGlyph(reg: RegisteredFont, ch: string): DecodedGlyph | null {
421
+ if (reg.glyphs.has(ch)) return reg.glyphs.get(ch)!;
422
+ const raw = reg.asset.glyphs[ch];
423
+ let g: DecodedGlyph | null = null;
424
+ if (raw) {
425
+ const unpack = (rec?: Record<string, string[]>) => {
426
+ const out: Record<string, (Float64Array | null)[]> = {};
427
+ if (rec) for (const key of Object.keys(rec)) out[key] = rec[key].map(s => (s ? Float64Array.from(decodeInts(s)) : null));
428
+ return out;
429
+ };
430
+ g = { cmds: raw.c, base: Float64Array.from(decodeCoords(raw.p)), adv: raw.a, deltas: unpack(raw.v), groupDeltas: unpack(raw.x) };
431
+ }
432
+ reg.glyphs.set(ch, g);
433
+ return g;
434
+ }
435
+
436
+ function axisDelta(stops: number[], perStop: (Float64Array | null)[], value: number, out: Float64Array, len: number) {
437
+ if (!stops || stops.length < 2) return;
438
+ const [i, t] = stopCell(stops, value);
439
+ const d0 = perStop[i], d1 = perStop[i + 1];
440
+ if (!d0 && !d1) return;
441
+ for (let k = 0; k < len; k++) {
442
+ out[k] += (d0 ? d0[k] : 0) * (1 - t) + (d1 ? d1[k] : 0) * t;
443
+ }
444
+ }
445
+
446
+ function stopCell(stops: number[], value: number): [number, number] {
447
+ let i = 0;
448
+ while (i < stops.length - 2 && value > stops[i + 1]) i++;
449
+ const s0 = stops[i], s1 = stops[i + 1];
450
+ return [i, s1 === s0 ? 0 : Math.min(1, Math.max(0, (value - s0) / (s1 - s0)))];
451
+ }
452
+
453
+ /** Multilinear blend of an axis group's correction grid (row-major over each axis's stops). */
454
+ function groupDelta(stopsList: number[][], grid: (Float64Array | null)[], values: number[], out: Float64Array, len: number) {
455
+ const dims = stopsList.length;
456
+ const cells: [number, number][] = [];
457
+ for (let d = 0; d < dims; d++) {
458
+ if (!stopsList[d] || stopsList[d].length < 2) return;
459
+ cells.push(stopCell(stopsList[d], values[d]));
460
+ }
461
+ for (let corner = 0; corner < 1 << dims; corner++) {
462
+ let index = 0, w = 1;
463
+ for (let d = 0; d < dims; d++) {
464
+ const up = (corner >> d) & 1;
465
+ const [i, t] = cells[d];
466
+ index = index * stopsList[d].length + i + up;
467
+ w *= up ? t : 1 - t;
468
+ }
469
+ const delta = grid[index];
470
+ if (!delta || w === 0) continue;
471
+ for (let k = 0; k < len; k++) out[k] += delta[k] * w;
472
+ }
473
+ }
474
+
475
+ function buildPath(cmds: string, c: Float64Array): Path2D | null {
476
+ if (typeof Path2D === 'undefined') return null;
477
+ const p = new Path2D();
478
+ let k = 0;
479
+ for (let i = 0; i < cmds.length; i++) {
480
+ switch (cmds[i]) {
481
+ case 'M': p.moveTo(c[k], c[k + 1]); k += 2; break;
482
+ case 'L': p.lineTo(c[k], c[k + 1]); k += 2; break;
483
+ case 'Q': p.quadraticCurveTo(c[k], c[k + 1], c[k + 2], c[k + 3]); k += 4; break;
484
+ case 'C': p.bezierCurveTo(c[k], c[k + 1], c[k + 2], c[k + 3], c[k + 4], c[k + 5]); k += 6; break;
485
+ case 'Z': p.closePath(); break;
486
+ }
487
+ }
488
+ return p;
489
+ }
490
+
491
+ function glyphInstance(r: ResolvedFont, ch: string): GlyphInstance | null {
492
+ const key = `${ch}\u0000${r.signature}`;
493
+ const hit = r.font.instances.get(key);
494
+ if (hit) return hit;
495
+ const g = decodeGlyph(r.font, ch);
496
+ if (!g) return null;
497
+ const len = g.base.length;
498
+ const acc = new Float64Array(len + 1);
499
+ const stops = r.font.asset.stops;
500
+ for (const tag of Object.keys(g.deltas)) {
501
+ const v = r.values[tag];
502
+ if (v === undefined) continue;
503
+ axisDelta(stops[tag], g.deltas[tag], v, acc, len + 1);
504
+ }
505
+ for (const group of Object.keys(g.groupDeltas)) {
506
+ const tags = group.split('|');
507
+ if (tags.some(t => r.values[t] === undefined)) continue;
508
+ groupDelta(tags.map(t => stops[t]), g.groupDeltas[group], tags.map(t => r.values[t]), acc, len + 1);
509
+ }
510
+ const coords = new Float64Array(len);
511
+ let xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity;
512
+ for (let k = 0; k < len; k += 2) {
513
+ const x = g.base[k] + acc[k], y = g.base[k + 1] + acc[k + 1];
514
+ coords[k] = x;
515
+ coords[k + 1] = y;
516
+ if (x < xMin) xMin = x;
517
+ if (x > xMax) xMax = x;
518
+ if (y < yMin) yMin = y;
519
+ if (y > yMax) yMax = y;
520
+ }
521
+ if (len === 0) { xMin = xMax = yMin = yMax = 0; }
522
+ const inst: GlyphInstance = { path: buildPath(g.cmds, coords), coords, adv: g.adv + acc[len], xMin, xMax, yMin, yMax };
523
+ if (r.font.instances.size > 6000) r.font.instances.clear();
524
+ r.font.instances.set(key, inst);
525
+ return inst;
526
+ }
527
+
528
+ // ---------------------------------------------------------------------------
529
+ // Layout + drawing
530
+
531
+ const ITALIC_SHEAR = Math.tan((12 * Math.PI) / 180);
532
+
533
+ interface LaidOutChar {
534
+ ch: string;
535
+ x: number; // pen position in px from the run start
536
+ inst: GlyphInstance | null;
537
+ fallbackWidth?: number;
538
+ }
539
+
540
+ type CanvasCtx = CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
541
+
542
+ interface Originals {
543
+ measureText: (this: CanvasCtx, text: string) => TextMetrics;
544
+ fillText: (this: CanvasCtx, text: string, x: number, y: number, maxWidth?: number) => void;
545
+ strokeText: (this: CanvasCtx, text: string, x: number, y: number, maxWidth?: number) => void;
546
+ }
547
+
548
+ const parsePx = (v: any): number => {
549
+ const n = parseFloat(String(v ?? '0'));
550
+ return Number.isFinite(n) ? n : 0;
551
+ };
552
+
553
+ function fallbackFontString(r: ResolvedFont): string {
554
+ const w = r.values.wght !== undefined ? Math.round(r.values.wght) : 400;
555
+ return `${r.italic ? 'italic ' : ''}${w} ${r.size}px sans-serif`;
556
+ }
557
+
558
+ function layoutRun(ctx: CanvasCtx, r: ResolvedFont, text: string, orig: Originals): { chars: LaidOutChar[]; width: number } {
559
+ const scale = r.size / r.font.asset.upm;
560
+ const letterSpacing = parsePx((ctx as any).letterSpacing);
561
+ const wordSpacing = parsePx((ctx as any).wordSpacing);
562
+ const kerning = (ctx as any).fontKerning !== 'none' ? r.font.asset.kern : undefined;
563
+ const chars: LaidOutChar[] = [];
564
+ let pen = 0;
565
+ let prev = '';
566
+ let savedFont: string | null = null;
567
+ for (const ch of Array.from(text)) {
568
+ if (kerning && prev) {
569
+ const k = kerning[prev + ch];
570
+ if (k) pen += k * scale;
571
+ }
572
+ const inst = glyphInstance(r, ch);
573
+ let w: number;
574
+ let fallbackWidth: number | undefined;
575
+ if (inst) {
576
+ w = inst.adv * scale;
577
+ } else {
578
+ if (savedFont === null) {
579
+ savedFont = ctx.font;
580
+ ctx.font = fallbackFontString(r);
581
+ }
582
+ fallbackWidth = orig.measureText.call(ctx, ch).width - letterSpacing;
583
+ w = fallbackWidth;
584
+ }
585
+ chars.push({ ch, x: pen, inst, fallbackWidth });
586
+ pen += w + letterSpacing + (ch === ' ' ? wordSpacing : 0);
587
+ prev = inst ? ch : '';
588
+ }
589
+ if (savedFont !== null) ctx.font = savedFont;
590
+ return { chars, width: pen };
591
+ }
592
+
593
+ /** Where a canvas textBaseline sits, in px above the alphabetic baseline. */
594
+ function baselineOffset(r: ResolvedFont, baseline: string): number {
595
+ const a = r.font.asset;
596
+ const s = r.size / a.upm;
597
+ const emAscent = (a.ascender / (a.ascender - a.descender)) * r.size;
598
+ const emDescent = r.size - emAscent;
599
+ switch (baseline) {
600
+ case 'top': return emAscent;
601
+ case 'hanging': return a.ascender * s * 0.8;
602
+ case 'middle': return (emAscent - emDescent) / 2;
603
+ case 'ideographic':
604
+ case 'bottom': return -emDescent;
605
+ default: return 0;
606
+ }
607
+ }
608
+
609
+ function runStartX(ctx: CanvasCtx, x: number, width: number): number {
610
+ const rtl = (ctx as any).direction === 'rtl';
611
+ let align = ctx.textAlign as string;
612
+ if (align === 'start') align = rtl ? 'right' : 'left';
613
+ else if (align === 'end') align = rtl ? 'left' : 'right';
614
+ if (align === 'center') return x - width / 2;
615
+ if (align === 'right') return x - width;
616
+ return x;
617
+ }
618
+
619
+ function measure(ctx: CanvasCtx, r: ResolvedFont, text: string, orig: Originals): TextMetrics {
620
+ const { chars, width } = layoutRun(ctx, r, text, orig);
621
+ const a = r.font.asset;
622
+ const s = r.size / a.upm;
623
+ const base = baselineOffset(r, ctx.textBaseline as string);
624
+ let yMax = -Infinity, yMin = Infinity, xMin = Infinity, xMax = -Infinity;
625
+ chars.forEach(c => {
626
+ if (c.inst && c.inst.coords.length) {
627
+ yMax = Math.max(yMax, c.inst.yMax * s);
628
+ yMin = Math.min(yMin, c.inst.yMin * s);
629
+ xMin = Math.min(xMin, c.x + c.inst.xMin * s);
630
+ xMax = Math.max(xMax, c.x + c.inst.xMax * s);
631
+ } else if (c.fallbackWidth !== undefined) {
632
+ yMax = Math.max(yMax, a.capHeight * s);
633
+ yMin = Math.min(yMin, 0);
634
+ xMin = Math.min(xMin, c.x);
635
+ xMax = Math.max(xMax, c.x + c.fallbackWidth);
636
+ }
637
+ });
638
+ if (!Number.isFinite(yMax)) { yMax = 0; yMin = 0; xMin = 0; xMax = 0; }
639
+ const startShift = runStartX(ctx, 0, width);
640
+ const emAscent = (a.ascender / (a.ascender - a.descender)) * r.size;
641
+ const metrics = {
642
+ width,
643
+ actualBoundingBoxLeft: -(xMin + startShift),
644
+ actualBoundingBoxRight: xMax + startShift,
645
+ actualBoundingBoxAscent: yMax - base,
646
+ actualBoundingBoxDescent: -yMin + base,
647
+ fontBoundingBoxAscent: a.ascender * s - base,
648
+ fontBoundingBoxDescent: -a.descender * s + base,
649
+ emHeightAscent: emAscent - base,
650
+ emHeightDescent: r.size - emAscent + base,
651
+ hangingBaseline: a.ascender * s * 0.8 - base,
652
+ alphabeticBaseline: -base,
653
+ ideographicBaseline: -(r.size - emAscent) - base,
654
+ };
655
+ return metrics as unknown as TextMetrics;
656
+ }
657
+
658
+ /** Point warp for liquid and shape effects, in canvas space (origin = the text layer's centre). */
659
+ function makeWarp(fx: FontFx, size: number, cx: number, cy: number): (x: number, y: number, gx: number, gy: number) => [number, number] {
660
+ const lq = fx.liquid, sh = fx.shape;
661
+ const t = lq?.speed ? (typeof performance !== 'undefined' ? performance.now() / 1000 : 0) * lq.speed : 0;
662
+ const phase = ((lq?.phase ?? 0) + t) * Math.PI * 2;
663
+ return (ax, ay, _gx, gy) => {
664
+ // Work around the line's own centre so every line bends the same way, wherever the caller draws from.
665
+ let x = ax - cx, y = ay - cy;
666
+ if (lq) {
667
+ const a = (lq.amount / 100) * size * 0.06;
668
+ x += a * Math.sin(y / (size * 0.18) + phase) + a * 0.5 * Math.sin(y / (size * 0.07) - phase * 1.7);
669
+ y += a * 0.6 * Math.sin(x / (size * 0.21) + phase * 1.3);
670
+ if (lq.drip && gy < 120) {
671
+ // Drips hang from the bottom of each letter, longer in some places than others.
672
+ const n = Math.sin(x * 0.083 + phase * 0.5) * 0.5 + Math.sin(x * 0.031 - phase * 0.3) * 0.5;
673
+ const k = Math.max(0, n) ** 3;
674
+ y += (lq.drip / 100) * size * 0.9 * k * (1 - Math.max(0, gy) / 120);
675
+ }
676
+ }
677
+ if (sh && sh.amount) {
678
+ const amt = sh.amount / 100;
679
+ if (sh.kind === 'arc') {
680
+ const R = (size * 7) / Math.max(0.05, Math.abs(amt));
681
+ const dir = Math.sign(amt);
682
+ const theta = x / R;
683
+ const rr = R - y * dir;
684
+ return [cx + rr * Math.sin(theta), cy + dir * (R - rr * Math.cos(theta))];
685
+ }
686
+ if (sh.kind === 'wave') {
687
+ const len = ((sh.length ?? 100) / 100) * size * 4;
688
+ return [cx + x, cy + y + amt * size * 0.35 * Math.sin((x / len) * Math.PI * 2 + (sh.phase ?? 0) * Math.PI * 2)];
689
+ }
690
+ if (sh.kind === 'bulge') {
691
+ const len = ((sh.length ?? 100) / 100) * size * 3.5;
692
+ const k = 1 + amt * 0.7 * Math.exp(-((x / len) ** 2));
693
+ return [cx + x, cy + (y + size * 0.35) * k - size * 0.35];
694
+ }
695
+ }
696
+ return [cx + x, cy + y];
697
+ };
698
+ }
699
+
700
+ /** Add a glyph to a path with every point moved through `map` (lines subdivided so warps bend them). */
701
+ function addWarped(path: Path2D, cmds: string, c: Float64Array, map: (gx: number, gy: number) => [number, number]) {
702
+ let k = 0;
703
+ let lx = 0, ly = 0;
704
+ for (const cmd of cmds) {
705
+ if (cmd === 'M') { const [x, y] = map(c[k], c[k + 1]); path.moveTo(x, y); lx = c[k]; ly = c[k + 1]; k += 2; }
706
+ else if (cmd === 'L') {
707
+ const tx = c[k], ty = c[k + 1];
708
+ const steps = Math.max(1, Math.min(12, Math.round(Math.hypot(tx - lx, ty - ly) / 60)));
709
+ for (let i = 1; i <= steps; i++) { const [x, y] = map(lx + ((tx - lx) * i) / steps, ly + ((ty - ly) * i) / steps); path.lineTo(x, y); }
710
+ lx = tx; ly = ty; k += 2;
711
+ } else if (cmd === 'Q') {
712
+ const [ax, ay] = map(c[k], c[k + 1]), [bx, by] = map(c[k + 2], c[k + 3]);
713
+ path.quadraticCurveTo(ax, ay, bx, by); lx = c[k + 2]; ly = c[k + 3]; k += 4;
714
+ } else if (cmd === 'C') {
715
+ const [ax, ay] = map(c[k], c[k + 1]), [bx, by] = map(c[k + 2], c[k + 3]), [ex, ey] = map(c[k + 4], c[k + 5]);
716
+ path.bezierCurveTo(ax, ay, bx, by, ex, ey); lx = c[k + 4]; ly = c[k + 5]; k += 6;
717
+ } else if (cmd === 'Z') path.closePath();
718
+ }
719
+ }
720
+
721
+ function shadeHex(hex: string, f: number): string {
722
+ const h = hex.replace('#', '');
723
+ const n = parseInt(h.length === 6 ? h : '333333', 16);
724
+ const ch = (v: number) => Math.max(0, Math.min(255, Math.round(v * (1 - f))));
725
+ return `rgb(${ch((n >> 16) & 255)},${ch((n >> 8) & 255)},${ch(n & 255)})`;
726
+ }
727
+
728
+ /** 3D: the letters' sides, drawn as stacked copies from the back to the front. */
729
+ function drawExtrusion(ctx: CanvasCtx, run: Path2D, d3: NonNullable<FontFx['d3']>, size: number) {
730
+ const depth = (d3.depth / 100) * size;
731
+ const a = (d3.angle * Math.PI) / 180;
732
+ const dx = Math.cos(a) * depth, dy = Math.sin(a) * depth;
733
+ const steps = Math.max(2, Math.min(80, Math.round(depth / 1.2)));
734
+ const saved = ctx.fillStyle;
735
+ for (let i = steps; i >= 1; i--) {
736
+ ctx.save();
737
+ ctx.translate((dx * i) / steps, (dy * i) / steps);
738
+ ctx.fillStyle = shadeHex(d3.color || '#333333', (d3.shade ?? 0.4) * (i / steps));
739
+ ctx.fill(run);
740
+ ctx.restore();
741
+ }
742
+ ctx.fillStyle = saved;
743
+ }
744
+
745
+ function draw(ctx: CanvasCtx, r: ResolvedFont, text: string, x: number, y: number, maxWidth: number | undefined, mode: 'fill' | 'stroke', orig: Originals) {
746
+ const { chars, width } = layoutRun(ctx, r, text, orig);
747
+ const s = r.size / r.font.asset.upm;
748
+ const squeeze = maxWidth !== undefined && maxWidth > 0 && width > maxWidth ? maxWidth / width : 1;
749
+ const x0 = runStartX(ctx, x, width * squeeze);
750
+ const yb = y + baselineOffset(r, ctx.textBaseline as string);
751
+ const shear = r.syntheticItalic ? ITALIC_SHEAR : 0;
752
+ const canMatrix = typeof DOMMatrix !== 'undefined' && typeof Path2D !== 'undefined';
753
+ const run = canMatrix ? new Path2D() : null;
754
+ const fallbacks: LaidOutChar[] = [];
755
+ const warp = r.fx && (r.fx.liquid || r.fx.shape) ? makeWarp(r.fx, r.size, x0 + (width * squeeze) / 2, yb) : null;
756
+ for (const c of chars) {
757
+ if (!c.inst) { fallbacks.push(c); continue; }
758
+ if (!c.inst.path || !run) continue;
759
+ const px = x0 + c.x * squeeze;
760
+ if (warp) {
761
+ const g = decodeGlyph(r.font, c.ch);
762
+ if (g) addWarped(run, g.cmds, c.inst.coords, (gx, gy) => warp(px + gx * s * squeeze + gy * s * shear, yb - gy * s, gx, gy));
763
+ } else {
764
+ run.addPath(c.inst.path, new DOMMatrix([s * squeeze, 0, s * shear, -s, px, yb]));
765
+ }
766
+ }
767
+ if (run) {
768
+ const d3 = r.fx?.d3;
769
+ if (d3 && d3.depth && mode === 'fill') drawExtrusion(ctx, run, d3, r.size);
770
+ if (mode === 'fill') ctx.fill(run);
771
+ else ctx.stroke(run);
772
+ }
773
+ if (fallbacks.length) {
774
+ const savedFont = ctx.font, savedAlign = ctx.textAlign, savedBaseline = ctx.textBaseline;
775
+ ctx.font = fallbackFontString(r);
776
+ ctx.textAlign = 'left';
777
+ ctx.textBaseline = 'alphabetic';
778
+ const ls = (ctx as any).letterSpacing;
779
+ if (ls !== undefined) (ctx as any).letterSpacing = '0px';
780
+ fallbacks.forEach(c => {
781
+ const fn = mode === 'fill' ? orig.fillText : orig.strokeText;
782
+ fn.call(ctx, c.ch, x0 + c.x * squeeze, yb);
783
+ });
784
+ if (ls !== undefined) (ctx as any).letterSpacing = ls;
785
+ ctx.font = savedFont;
786
+ ctx.textAlign = savedAlign;
787
+ ctx.textBaseline = savedBaseline;
788
+ }
789
+ }
790
+
791
+ let installed = false;
792
+
793
+ /** Route canvas text calls for Exode fonts through glyph paths. Safe to call more than once. */
794
+ export function installExodeFontHooks() {
795
+ if (installed) return;
796
+ installed = true;
797
+ const protos: any[] = [];
798
+ if (typeof CanvasRenderingContext2D !== 'undefined') protos.push(CanvasRenderingContext2D.prototype);
799
+ if (typeof OffscreenCanvasRenderingContext2D !== 'undefined') protos.push(OffscreenCanvasRenderingContext2D.prototype);
800
+ protos.forEach(proto => {
801
+ if (proto.__exodeFontHooks) return;
802
+ const orig: Originals = { measureText: proto.measureText, fillText: proto.fillText, strokeText: proto.strokeText };
803
+ proto.__exodeFontHooks = orig;
804
+ proto.measureText = function (this: CanvasCtx, text: string) {
805
+ const r = registry.size ? resolveFont(this.font) : null;
806
+ return r ? measure(this, r, String(text ?? ''), orig) : orig.measureText.call(this, text);
807
+ };
808
+ proto.fillText = function (this: CanvasCtx, text: string, x: number, y: number, maxWidth?: number) {
809
+ const r = registry.size ? resolveFont(this.font) : null;
810
+ if (r) draw(this, r, String(text ?? ''), x, y, maxWidth, 'fill', orig);
811
+ else if (maxWidth === undefined) orig.fillText.call(this, text, x, y);
812
+ else orig.fillText.call(this, text, x, y, maxWidth);
813
+ };
814
+ proto.strokeText = function (this: CanvasCtx, text: string, x: number, y: number, maxWidth?: number) {
815
+ const r = registry.size ? resolveFont(this.font) : null;
816
+ if (r) draw(this, r, String(text ?? ''), x, y, maxWidth, 'stroke', orig);
817
+ else if (maxWidth === undefined) orig.strokeText.call(this, text, x, y);
818
+ else orig.strokeText.call(this, text, x, y, maxWidth);
819
+ };
820
+ });
821
+ }
822
+
823
+ /** SVG path data for a string at the given axis values (previews, export to vector). */
824
+ export function textToSvgPath(family: string, text: string, size: number, axes?: Record<string, number>): { d: string; width: number } {
825
+ const r = resolveFont(`400 ${size}px "${familyWithAxes(family, axes || {})}"`);
826
+ if (!r) return { d: '', width: 0 };
827
+ const s = size / r.font.asset.upm;
828
+ const asc = r.font.asset.ascender * s;
829
+ const kern = r.font.asset.kern;
830
+ let pen = 0, prev = '';
831
+ const parts: string[] = [];
832
+ const f = (n: number) => String(Math.round(n * 100) / 100);
833
+ for (const ch of Array.from(text)) {
834
+ if (kern && prev) pen += (kern[prev + ch] || 0) * s;
835
+ const inst = glyphInstance(r, ch);
836
+ if (!inst) { prev = ''; pen += size * 0.5; continue; }
837
+ const g = decodeGlyph(r.font, ch)!;
838
+ let k = 0;
839
+ const X = (i: number) => f(pen + inst.coords[i] * s);
840
+ const Y = (i: number) => f(asc - inst.coords[i] * s);
841
+ for (const cmd of g.cmds) {
842
+ if (cmd === 'Z') { parts.push('Z'); continue; }
843
+ const n = COMMAND_POINTS[cmd];
844
+ const pts: string[] = [];
845
+ for (let j = 0; j < n; j++) pts.push(`${X(k + j * 2)} ${Y(k + j * 2 + 1)}`);
846
+ parts.push(cmd + pts.join(' '));
847
+ k += n * 2;
848
+ }
849
+ pen += inst.adv * s;
850
+ prev = ch;
851
+ }
852
+ return { d: parts.join(''), width: pen };
853
+ }
854
+
855
+ /** Blended outline and advance of one glyph at the given axis values (tests, export). */
856
+ export function glyphAt(asset: ExodeFontAsset, ch: string, values: Record<string, number>): { coords: number[]; adv: number } | null {
857
+ const raw = asset.glyphs[ch];
858
+ if (!raw) return null;
859
+ const base = decodeCoords(raw.p);
860
+ const out = new Float64Array(base.length + 1);
861
+ for (const tag of Object.keys(raw.v || {})) {
862
+ const axis = asset.axes.find(a => a.tag === tag);
863
+ const v = values[tag] ?? axis?.default;
864
+ if (v === undefined) continue;
865
+ const perStop = raw.v![tag].map(s => (s ? Float64Array.from(decodeInts(s)) : null));
866
+ axisDelta(asset.stops[tag], perStop, v, out, base.length + 1);
867
+ }
868
+ for (const group of Object.keys(raw.x || {})) {
869
+ const tags = group.split('|');
870
+ if (tags.some(t => !(t in asset.stops))) continue;
871
+ const vals = tags.map(t => values[t] ?? asset.axes.find(a => a.tag === t)!.default);
872
+ const grid = raw.x![group].map(s => (s ? Float64Array.from(decodeInts(s)) : null));
873
+ groupDelta(tags.map(t => asset.stops[t]), grid, vals, out, base.length + 1);
874
+ }
875
+ return { coords: base.map((b, k) => b + out[k]), adv: raw.a + out[base.length] };
876
+ }
877
+
878
+ /** Blended coordinates of one glyph at the given axis values. */
879
+ export function glyphCoordsAt(asset: ExodeFontAsset, ch: string, values: Record<string, number>): number[] | null {
880
+ return glyphAt(asset, ch, values)?.coords ?? null;
881
+ }
882
+
883
+ /** A copy of a font with only the listed axes kept (what a .exode file embeds). */
884
+ export function trimExodeFont(asset: ExodeFontAsset, keepAxes: string[]): ExodeFontAsset {
885
+ const keep = new Set(keepAxes.filter(t => t in asset.stops));
886
+ const stops: Record<string, number[]> = {};
887
+ keep.forEach(t => { stops[t] = asset.stops[t]; });
888
+ const glyphs: Record<string, ExodeFontGlyph> = {};
889
+ for (const ch of Object.keys(asset.glyphs)) {
890
+ const g = asset.glyphs[ch];
891
+ const v: Record<string, string[]> = {};
892
+ if (g.v) keep.forEach(t => { if (g.v![t]) v[t] = g.v![t]; });
893
+ const x: Record<string, string[]> = {};
894
+ if (g.x) Object.keys(g.x).forEach(p => { if (p.split('|').every(t => keep.has(t))) x[p] = g.x![p]; });
895
+ const out: ExodeFontGlyph = { c: g.c, p: g.p, a: g.a };
896
+ if (Object.keys(v).length) out.v = v;
897
+ if (Object.keys(x).length) out.x = x;
898
+ glyphs[ch] = out;
899
+ }
900
+ const pairs = (asset.pairs || []).filter(p => p.split('|').every(t => keep.has(t)));
901
+ return { ...asset, stops, pairs: pairs.length ? pairs : undefined, glyphs };
902
+ }