ultra-text 1.0.1 → 1.0.2

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 (150) hide show
  1. package/README.md +224 -1002
  2. package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
  3. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
  4. package/dist/atlas/appendAtlas.js +67 -25
  5. package/dist/atlas/appendAtlas.js.map +1 -1
  6. package/dist/atlas/buildAtlas.js +3 -2
  7. package/dist/atlas/buildAtlas.js.map +1 -1
  8. package/dist/atlas/cpuAtlas.d.ts +4 -1
  9. package/dist/atlas/cpuAtlas.js +8 -6
  10. package/dist/atlas/cpuAtlas.js.map +1 -1
  11. package/dist/atlas/cpuSdf.js +152 -40
  12. package/dist/atlas/cpuSdf.js.map +1 -1
  13. package/dist/atlas/cpuWorker.d.ts +5 -3
  14. package/dist/atlas/cpuWorker.js +119 -12
  15. package/dist/atlas/cpuWorker.js.map +1 -1
  16. package/dist/atlas/gpuAtlas.js +100 -276
  17. package/dist/atlas/gpuAtlas.js.map +1 -1
  18. package/dist/atlas/gpuCommon.d.ts +135 -0
  19. package/dist/atlas/gpuCommon.js +223 -0
  20. package/dist/atlas/gpuCommon.js.map +1 -0
  21. package/dist/atlas/jfaWgsl.js +47 -241
  22. package/dist/atlas/jfaWgsl.js.map +1 -1
  23. package/dist/atlas/rasterize.js +103 -58
  24. package/dist/atlas/rasterize.js.map +1 -1
  25. package/dist/atlas/shapeRaster.js +2 -1
  26. package/dist/atlas/shapeRaster.js.map +1 -1
  27. package/dist/atlas/vanillaBounds.d.ts +64 -0
  28. package/dist/atlas/vanillaBounds.js +42 -0
  29. package/dist/atlas/vanillaBounds.js.map +1 -0
  30. package/dist/atlas/vanillaCore.d.ts +100 -0
  31. package/dist/atlas/vanillaCore.js +1012 -0
  32. package/dist/atlas/vanillaCore.js.map +1 -0
  33. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  34. package/dist/atlas/vanillaCpuAtlas.js +87 -0
  35. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  36. package/dist/atlas/vanillaExtras.d.ts +8 -0
  37. package/dist/atlas/vanillaExtras.js +166 -0
  38. package/dist/atlas/vanillaExtras.js.map +1 -0
  39. package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
  40. package/dist/atlas/vanillaGpuHelpers.js +119 -0
  41. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  42. package/dist/dom/DomSdf.js +224 -284
  43. package/dist/dom/DomSdf.js.map +1 -1
  44. package/dist/dom/DomSlug.js +75 -151
  45. package/dist/dom/DomSlug.js.map +1 -1
  46. package/dist/dom/domAnalytic.d.ts +54 -0
  47. package/dist/dom/domAnalytic.js +282 -0
  48. package/dist/dom/domAnalytic.js.map +1 -0
  49. package/dist/dom/domExtras.d.ts +27 -0
  50. package/dist/dom/domExtras.js +137 -0
  51. package/dist/dom/domExtras.js.map +1 -0
  52. package/dist/dom/fontCanvas.js +27 -9
  53. package/dist/dom/fontCanvas.js.map +1 -1
  54. package/dist/dom/layoutSignature.js +150 -48
  55. package/dist/dom/layoutSignature.js.map +1 -1
  56. package/dist/dom/pretextLayout.js +55 -13
  57. package/dist/dom/pretextLayout.js.map +1 -1
  58. package/dist/dom/snapshot.js +369 -204
  59. package/dist/dom/snapshot.js.map +1 -1
  60. package/dist/dom/svgCapture.d.ts +8 -1
  61. package/dist/dom/svgCapture.js +75 -1
  62. package/dist/dom/svgCapture.js.map +1 -1
  63. package/dist/dom/tone.js +76 -36
  64. package/dist/dom/tone.js.map +1 -1
  65. package/dist/index.js +4 -3
  66. package/dist/slug/SlugMaterial.d.ts +11 -3
  67. package/dist/slug/SlugMaterial.js +54 -10
  68. package/dist/slug/SlugMaterial.js.map +1 -1
  69. package/dist/slug/coverage.d.ts +16 -12
  70. package/dist/slug/coverage.js +194 -221
  71. package/dist/slug/coverage.js.map +1 -1
  72. package/dist/slug/preprocessCore.d.ts +5 -1
  73. package/dist/slug/preprocessCore.js +118 -87
  74. package/dist/slug/preprocessCore.js.map +1 -1
  75. package/dist/slug/runtime.d.ts +1 -0
  76. package/dist/slug/runtime.js +90 -44
  77. package/dist/slug/runtime.js.map +1 -1
  78. package/dist/slug/standaloneRuntime.d.ts +3 -2
  79. package/dist/slug/standaloneRuntime.js +75 -40
  80. package/dist/slug/standaloneRuntime.js.map +1 -1
  81. package/dist/slug/truetype.js +166 -193
  82. package/dist/slug/truetype.js.map +1 -1
  83. package/dist/slug/vanillaCore.d.ts +340 -0
  84. package/dist/slug/vanillaCore.js +1621 -0
  85. package/dist/slug/vanillaCore.js.map +1 -0
  86. package/dist/slug-vanilla.d.ts +13 -364
  87. package/dist/slug-vanilla.js +5 -1453
  88. package/dist/slug.d.ts +1 -1
  89. package/dist/slug.js +6 -6
  90. package/dist/text/GlyphTextMaterial.d.ts +1 -1
  91. package/dist/text/GlyphTextMaterial.js +5 -5
  92. package/dist/text/GlyphTextMaterial.js.map +1 -1
  93. package/dist/text/SdfTextMaterial.js +7 -5
  94. package/dist/text/SdfTextMaterial.js.map +1 -1
  95. package/dist/text/decorations.js +36 -19
  96. package/dist/text/decorations.js.map +1 -1
  97. package/dist/text/geometry.d.ts +3 -22
  98. package/dist/text/geometryUtils.d.ts +11 -1
  99. package/dist/text/geometryUtils.js +22 -1
  100. package/dist/text/geometryUtils.js.map +1 -1
  101. package/dist/text/glyphGeometry.d.ts +9 -0
  102. package/dist/text/glyphGeometry.js +353 -0
  103. package/dist/text/glyphGeometry.js.map +1 -0
  104. package/dist/text/index.d.ts +2 -1
  105. package/dist/text/rectGeometry.d.ts +13 -0
  106. package/dist/text/rectGeometry.js +97 -0
  107. package/dist/text/rectGeometry.js.map +1 -0
  108. package/dist/text/reflow.d.ts +18 -1
  109. package/dist/text/reflow.js +108 -38
  110. package/dist/text/reflow.js.map +1 -1
  111. package/dist/text/snap.d.ts +1 -0
  112. package/dist/text/snap.js +26 -0
  113. package/dist/text/snap.js.map +1 -0
  114. package/dist/vanilla.d.ts +13 -363
  115. package/dist/vanilla.js +6 -1473
  116. package/dist/windfoil/geometry.d.ts +2 -2
  117. package/dist/windfoil/geometry.js +113 -40
  118. package/dist/windfoil/geometry.js.map +1 -1
  119. package/dist/windfoil/mixed.d.ts +1 -0
  120. package/dist/windfoil/mixed.js +44 -25
  121. package/dist/windfoil/mixed.js.map +1 -1
  122. package/dist/windfoil/preprocess.js +2 -2
  123. package/dist/windfoil/preprocessCore.d.ts +1 -0
  124. package/dist/windfoil/preprocessCore.js +9 -4
  125. package/dist/windfoil/preprocessCore.js.map +1 -1
  126. package/dist/windfoil/runtime.d.ts +3 -1
  127. package/dist/windfoil/runtime.js +62 -40
  128. package/dist/windfoil/runtime.js.map +1 -1
  129. package/dist/windfoil/storage.d.ts +60 -2
  130. package/dist/windfoil/storage.js +142 -6
  131. package/dist/windfoil/storage.js.map +1 -1
  132. package/dist/windfoil/trace/contours.d.ts +5 -0
  133. package/dist/windfoil/trace/contours.js +167 -43
  134. package/dist/windfoil/trace/contours.js.map +1 -1
  135. package/dist/windfoil/trace/fit.d.ts +3 -1
  136. package/dist/windfoil/trace/fit.js +471 -175
  137. package/dist/windfoil/trace/fit.js.map +1 -1
  138. package/dist/windfoil/trace/outline.js +55 -30
  139. package/dist/windfoil/trace/outline.js.map +1 -1
  140. package/dist/windfoil/trace/types.d.ts +10 -0
  141. package/dist/windfoil/tracedOutlines.js +59 -34
  142. package/dist/windfoil/tracedOutlines.js.map +1 -1
  143. package/package.json +11 -11
  144. package/skills/ultra-text/references/three-tsl.md +2 -2
  145. package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
  146. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
  147. package/dist/slug-vanilla.js.map +0 -1
  148. package/dist/text/geometry.js +0 -348
  149. package/dist/text/geometry.js.map +0 -1
  150. package/dist/vanilla.js.map +0 -1
@@ -0,0 +1,282 @@
1
+ import { isAnimatedMotion } from "../text/GlyphTextMaterial.js";
2
+ import { hasDecorations } from "../text/geometryUtils.js";
3
+ import { Group, Mesh } from "three/webgpu";
4
+ // src/dom/domAnalytic.ts
5
+ async function buildDomAnalyticBackend(renderer, doc, snapshot, opts, backendKind, analytic, headroom, existingTraced, resetAtlas, signal, throwIfAborted, callbacks) {
6
+ const outlineProvider = analytic.outlineProvider;
7
+ if (outlineProvider !== void 0 && typeof outlineProvider !== "function") throw new TypeError(`DomSdf: textBackend "${backendKind}" requires ${backendKind}.outlineProvider`);
8
+ let traced = existingTraced;
9
+ let resolved;
10
+ if (analytic.outlineProvider) resolved = {
11
+ ...analytic,
12
+ outlineProvider: analytic.outlineProvider
13
+ };
14
+ else {
15
+ if (!traced) {
16
+ const { createTracedOutlineProvider } = await callbacks.preloadTraced ?? await callbacks.loadTraced();
17
+ throwIfAborted(signal);
18
+ traced ??= createTracedOutlineProvider(doc, opts.colorGlyphs === void 0 ? {} : { colorGlyphs: opts.colorGlyphs });
19
+ } else if (resetAtlas) traced.clear();
20
+ resolved = {
21
+ ...analytic,
22
+ fallback: analytic.fallback ?? "sdf-glyphs",
23
+ outlineProvider: traced.provider
24
+ };
25
+ }
26
+ return {
27
+ retained: await (backendKind === "slug" ? (await callbacks.preloadBackend ?? await import("../slug/runtime.js")).buildSlugBackend : (await callbacks.preloadBackend ?? await import("../windfoil/runtime.js")).buildWindfoilBackend)(renderer, snapshot.requests, resolved, signal, {
28
+ build: callbacks.buildAtlas,
29
+ effects: opts,
30
+ headroom
31
+ }),
32
+ traced
33
+ };
34
+ }
35
+ function loadMixedExtras() {
36
+ return import("../windfoil/mixed.js");
37
+ }
38
+ var maxSeq = (s) => s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0);
39
+ function createAnalyticContent(snapshot, backend, options, motion, tone, makeExtraParts, extrasMod) {
40
+ const materialOptions = {
41
+ ...options,
42
+ tone: tone ?? false
43
+ };
44
+ const group = new Group();
45
+ group.name = "ultra-text generated DOM content";
46
+ group.matrixAutoUpdate = false;
47
+ group.updateMatrix();
48
+ const strength = motion.strength ?? 18;
49
+ let animated = isAnimatedMotion(motion);
50
+ const materialMotion = (live) => animated ? live : false;
51
+ const { geometry: glyphGeometry, maxSequence } = backend.createGeometry(snapshot, strength);
52
+ const hasExtras = !!(backend.companion ?? backend.color);
53
+ const usesColor = (layout) => !!backend.companion?.colorLayer && (options.colorGlyphs !== "none" || layout.requests.some((request) => request.shape?.bitmap));
54
+ const colorEnabled = usesColor(snapshot);
55
+ const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence;
56
+ let textMaterial;
57
+ try {
58
+ textMaterial = backend.createMaterial({
59
+ ...materialOptions,
60
+ maxSequence: hasExtras ? globalSequence : maxSequence,
61
+ motion: materialMotion(motion)
62
+ });
63
+ } catch (error) {
64
+ glyphGeometry.dispose();
65
+ throw error;
66
+ }
67
+ let extras;
68
+ try {
69
+ if (hasExtras) extras = makeExtraParts(snapshot, backend, materialOptions, materialMotion(motion), strength);
70
+ } catch (error) {
71
+ glyphGeometry.dispose();
72
+ textMaterial.dispose();
73
+ throw error;
74
+ }
75
+ const text = new Mesh(glyphGeometry, textMaterial);
76
+ text.name = "ultra-text text";
77
+ text.castShadow = options.castShadow !== false;
78
+ text.frustumCulled = false;
79
+ text.renderOrder = 2;
80
+ text.matrixAutoUpdate = false;
81
+ text.updateMatrix();
82
+ group.add(text);
83
+ const ownedMeshes = [text];
84
+ const disposeMeshes = () => {
85
+ for (const mesh of ownedMeshes) {
86
+ mesh.geometry.dispose();
87
+ for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material]) material.dispose();
88
+ }
89
+ ownedMeshes.length = 0;
90
+ group.clear();
91
+ };
92
+ try {
93
+ if (extras) {
94
+ for (const mesh of extras.meshes) {
95
+ group.add(mesh);
96
+ ownedMeshes.push(mesh);
97
+ }
98
+ extras.mergeRects(snapshot, text.geometry);
99
+ }
100
+ } catch (error) {
101
+ disposeMeshes();
102
+ throw error;
103
+ }
104
+ const glyphDrawable = (retained, key) => (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key);
105
+ let ce = null;
106
+ try {
107
+ if (extrasMod) ce = extrasMod.createContentExtras(snapshot, text.geometry, group, ownedMeshes, options, () => animated, motion, textMaterial.maxSequence.value, (key) => glyphDrawable(backend, key));
108
+ } catch (error) {
109
+ disposeMeshes();
110
+ throw error;
111
+ }
112
+ const swapGeometry = (mesh, geometry) => {
113
+ const previous = mesh.geometry;
114
+ mesh.geometry = geometry;
115
+ previous.dispose();
116
+ };
117
+ const setTone = (next) => {
118
+ if (!textMaterial.setTone(next)) return false;
119
+ for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next);
120
+ return true;
121
+ };
122
+ const toneFits = (next) => {
123
+ const current = textMaterial.tone;
124
+ return current && next ? current.fits(next) : !current && !next;
125
+ };
126
+ let disposed = false;
127
+ return {
128
+ g: group,
129
+ get m() {
130
+ return textMaterial;
131
+ },
132
+ get a() {
133
+ return animated;
134
+ },
135
+ sm(change, live) {
136
+ if (animated) {
137
+ textMaterial.setMotion(change);
138
+ extras?.setMotion(change);
139
+ ce?.setMotion(change);
140
+ return;
141
+ }
142
+ if (!isAnimatedMotion(live)) return;
143
+ const decMesh = ce?.decMesh();
144
+ const meshes = [
145
+ text,
146
+ ...extras?.meshes ?? [],
147
+ ...decMesh ? [decMesh] : []
148
+ ];
149
+ const twins = [];
150
+ try {
151
+ for (const mesh of meshes) twins.push(mesh.material.withMotion(live));
152
+ } catch (error) {
153
+ for (const twin of twins) twin.dispose();
154
+ throw error;
155
+ }
156
+ meshes.forEach((mesh, index) => {
157
+ const previous = mesh.material;
158
+ mesh.material = twins[index];
159
+ previous.dispose();
160
+ });
161
+ textMaterial = twins[0];
162
+ animated = true;
163
+ },
164
+ st: setTone,
165
+ ud(layout, retained, liveMotion) {
166
+ ce?.updateDec(layout, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, (key) => glyphDrawable(retained, key));
167
+ },
168
+ get tg() {
169
+ return text.geometry;
170
+ },
171
+ rg(geometry) {
172
+ swapGeometry(text, geometry);
173
+ },
174
+ u(nextSnapshot, nextBackend, liveMotion, nextTone) {
175
+ if (nextTone !== void 0 && (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))) return false;
176
+ if (hasExtras && !extras.fitsMotion(nextSnapshot)) return false;
177
+ if (colorEnabled !== usesColor(nextSnapshot)) return false;
178
+ if (ce ? !ce.fitsLayout(nextSnapshot) : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)) return false;
179
+ const strength = liveMotion.strength ?? 18;
180
+ const drawable = (key) => glyphDrawable(nextBackend, key);
181
+ const decorationsFit = ce ? ce.decorationsFit(nextSnapshot, drawable) : true;
182
+ if (hasExtras && !decorationsFit) return false;
183
+ const glyphsFit = decorationsFit && nextBackend.contentFits(text.geometry, nextSnapshot);
184
+ let built = null;
185
+ let nextParts = [];
186
+ let stagedExtras = null;
187
+ const releaseStaged = () => {
188
+ built?.geometry.dispose();
189
+ for (const geometry of nextParts) geometry?.dispose();
190
+ stagedExtras?.dispose();
191
+ };
192
+ try {
193
+ nextParts = extras?.prepare(nextSnapshot, strength) ?? [];
194
+ if (!glyphsFit) built = nextBackend.createGeometry(nextSnapshot, strength);
195
+ if (ce) stagedExtras = ce.prepare(nextSnapshot, built?.geometry ?? text.geometry, animated, liveMotion, built?.maxSequence ?? textMaterial.maxSequence.value, decorationsFit, drawable);
196
+ } catch (error) {
197
+ releaseStaged();
198
+ throw error;
199
+ }
200
+ if (built) {
201
+ swapGeometry(text, built.geometry);
202
+ textMaterial.maxSequence.value = built.maxSequence;
203
+ } else {
204
+ const maxSequence = nextBackend.updateGeometry(text.geometry, nextSnapshot, strength, void 0, true);
205
+ if (maxSequence === null) {
206
+ releaseStaged();
207
+ throw new Error("DomSdf: glyph buffers changed during the update");
208
+ }
209
+ textMaterial.maxSequence.value = maxSequence;
210
+ }
211
+ if (extras) {
212
+ extras.commit(nextParts, nextSnapshot, strength);
213
+ textMaterial.maxSequence.value = maxSeq(nextSnapshot);
214
+ extras.mergeRects(nextSnapshot, text.geometry);
215
+ }
216
+ ce?.commit(stagedExtras, nextSnapshot, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, drawable, swapGeometry);
217
+ if (nextTone !== void 0) setTone(nextTone);
218
+ return true;
219
+ },
220
+ d() {
221
+ if (disposed) return;
222
+ disposed = true;
223
+ disposeMeshes();
224
+ }
225
+ };
226
+ }
227
+ function reflowAnalytic(snapshot, retained, content, width, motion, rm, reflowState) {
228
+ retained.setGlyphEm(!!content.m.tone?.dilates);
229
+ const state = reflowState ?? rm.createReflowState(snapshot);
230
+ const reflowed = rm.reflowSnapshotWithState(snapshot, width, state);
231
+ const strength = motion.strength ?? 18;
232
+ if (retained.companion || retained.color) {
233
+ if (!content.u(reflowed, retained, motion)) throw new Error("DomSdf.reflow: incompatible retained content");
234
+ } else {
235
+ let maxSequence = retained.updateGeometry(content.tg, reflowed, strength);
236
+ if (maxSequence === null) {
237
+ const built = retained.createGeometry(reflowed, strength);
238
+ content.rg(built.geometry);
239
+ maxSequence = built.maxSequence;
240
+ }
241
+ content.m.maxSequence.value = maxSequence;
242
+ content.ud(reflowed, retained, motion);
243
+ }
244
+ return {
245
+ width: reflowed.width,
246
+ height: reflowed.height,
247
+ lines: reflowed.lineCount,
248
+ state
249
+ };
250
+ }
251
+ function countAnalyticStats(snapshot, windfoil) {
252
+ const glyphs = windfoil.companion?.glyphs;
253
+ const switchKeys = windfoil.sizeSwitch?.keys;
254
+ let glyphCount = 0;
255
+ let shapeCount = 0;
256
+ let colorGlyphCount = 0;
257
+ let fallbackGlyphCount = 0;
258
+ let switchableGlyphCount = 0;
259
+ for (const glyph of snapshot.glyphs) {
260
+ if (switchKeys?.has(glyph.glyphKey)) switchableGlyphCount++;
261
+ if (glyph.shapeGroup !== void 0) {
262
+ shapeCount++;
263
+ continue;
264
+ }
265
+ glyphCount++;
266
+ const slot = glyphs?.get(glyph.glyphKey);
267
+ if (slot && !windfoil.analyticCovers(glyph.glyphKey)) {
268
+ if (slot.color) colorGlyphCount++;
269
+ fallbackGlyphCount++;
270
+ }
271
+ }
272
+ return [
273
+ glyphCount,
274
+ shapeCount,
275
+ colorGlyphCount,
276
+ fallbackGlyphCount,
277
+ switchableGlyphCount
278
+ ];
279
+ }
280
+ export { buildDomAnalyticBackend, countAnalyticStats, createAnalyticContent, loadMixedExtras, reflowAnalytic };
281
+
282
+ //# sourceMappingURL=domAnalytic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domAnalytic.js","names":[],"sources":["../../src/dom/domAnalytic.ts"],"sourcesContent":["import { Group, Mesh, type InstancedBufferGeometry, type WebGPURenderer } from 'three/webgpu'\n\nimport type { createExtraTextParts } from '../windfoil/mixed.js'\nimport type { WindfoilBackend, WindfoilBuildOptions } from '../windfoil/runtime.js'\nimport type { TracedOutlines } from '../windfoil/tracedOutlines.js'\nimport type * as SlugRuntime from '../slug/runtime.js'\nimport type * as WindfoilRuntime from '../windfoil/runtime.js'\nimport type * as TracedOutlinesModule from '../windfoil/tracedOutlines.js'\nimport type { RasterizeOptions } from '../atlas/rasterize.js'\nimport { isAnimatedMotion, type GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport { hasDecorations } from '../text/geometryUtils.js'\nimport type { ReflowState } from '../text/reflow.js'\nimport type * as ReflowModule from '../text/reflow.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n DomSdfOptions,\n SdfAtlas,\n SdfMotionOptions,\n WindfoilOptions,\n} from '../types.js'\nimport type * as DomExtrasModule from './domExtras.js'\nimport type { ContentExtrasController, StagedExtras } from './domExtras.js'\n\nexport interface AnalyticRetainedResult {\n readonly retained: WindfoilBackend | null\n readonly traced: TracedOutlines | null\n}\n\nexport interface AnalyticBuildCallbacks {\n readonly preloadBackend: Promise<typeof SlugRuntime | typeof WindfoilRuntime | null> | null\n readonly preloadTraced: Promise<typeof TracedOutlinesModule | null> | null\n readonly loadTraced: () => Promise<typeof TracedOutlinesModule>\n readonly buildAtlas: (\n requests: DomLayoutSnapshot['requests'],\n signal: AbortSignal,\n appendable?: RasterizeOptions['appendable'],\n ) => Promise<SdfAtlas>\n}\n\nexport async function buildDomAnalyticBackend(\n renderer: WebGPURenderer,\n doc: Document,\n snapshot: DomLayoutSnapshot,\n opts: DomSdfOptions,\n backendKind: 'windfoil' | 'slug',\n analytic: WindfoilOptions,\n headroom: boolean,\n existingTraced: TracedOutlines | null,\n resetAtlas: boolean,\n signal: AbortSignal,\n throwIfAborted: (s: AbortSignal) => void,\n callbacks: AnalyticBuildCallbacks,\n): Promise<AnalyticRetainedResult> {\n const outlineProvider: unknown = analytic.outlineProvider\n if (outlineProvider !== undefined && typeof outlineProvider !== 'function') {\n throw new TypeError(\n `DomSdf: textBackend \"${backendKind}\" requires ${backendKind}.outlineProvider`,\n )\n }\n let traced = existingTraced\n let resolved: WindfoilBuildOptions\n if (analytic.outlineProvider) {\n resolved = { ...analytic, outlineProvider: analytic.outlineProvider }\n } else {\n if (!traced) {\n const { createTracedOutlineProvider } =\n (await callbacks.preloadTraced) ?? (await callbacks.loadTraced())\n throwIfAborted(signal)\n traced ??= createTracedOutlineProvider(\n doc,\n opts.colorGlyphs === undefined ? {} : { colorGlyphs: opts.colorGlyphs },\n )\n } else if (resetAtlas) {\n traced.clear()\n }\n resolved = {\n ...analytic,\n fallback: analytic.fallback ?? 'sdf-glyphs',\n outlineProvider: traced.provider,\n }\n }\n const build =\n backendKind === 'slug'\n ? (\n ((await callbacks.preloadBackend) as typeof SlugRuntime | null) ??\n (await import('../slug/runtime.js'))\n ).buildSlugBackend\n : (\n ((await callbacks.preloadBackend) as typeof WindfoilRuntime | null) ??\n (await import('../windfoil/runtime.js'))\n ).buildWindfoilBackend\n const retained = await build(renderer, snapshot.requests, resolved, signal, {\n build: callbacks.buildAtlas,\n effects: opts,\n headroom,\n })\n return { retained, traced }\n}\n\nexport function loadMixedExtras(): Promise<{ createExtraTextParts: typeof createExtraTextParts }> {\n return import('../windfoil/mixed.js')\n}\n\nexport interface AnalyticContentBundle {\n readonly g: Group\n readonly m: GlyphTextMaterial\n readonly tg: InstancedBufferGeometry\n readonly a: boolean\n sm(change: SdfMotionOptions, live: SdfMotionOptions): void\n st(tone: ResolvedTextTone | null): boolean\n ud(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, motion: SdfMotionOptions): void\n rg(geometry: InstancedBufferGeometry): void\n u(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n motion: SdfMotionOptions,\n tone?: ResolvedTextTone | null,\n ): boolean\n d(): void\n}\n\nconst maxSeq = (s: DomLayoutSnapshot): number =>\n s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0)\n\nexport function createAnalyticContent(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n options: DomSdfOptions,\n motion: SdfMotionOptions,\n tone: ResolvedTextTone | null,\n makeExtraParts?: typeof createExtraTextParts,\n extrasMod?: typeof DomExtrasModule | null,\n): AnalyticContentBundle {\n const materialOptions = { ...options, tone: tone ?? (false as const) }\n const group = new Group()\n group.name = 'ultra-text generated DOM content'\n group.matrixAutoUpdate = false\n group.updateMatrix()\n\n const strength = motion.strength ?? 18\n let animated = isAnimatedMotion(motion)\n const materialMotion = (live: SdfMotionOptions): SdfMotionOptions | false =>\n animated ? live : false\n const { geometry: glyphGeometry, maxSequence } = backend.createGeometry(snapshot, strength)\n const hasExtras = !!(backend.companion ?? backend.color)\n const usesColor = (layout: DomLayoutSnapshot): boolean =>\n !!backend.companion?.colorLayer &&\n (options.colorGlyphs !== 'none' || layout.requests.some((request) => request.shape?.bitmap))\n const colorEnabled = usesColor(snapshot)\n const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence\n let textMaterial: GlyphTextMaterial\n try {\n textMaterial = backend.createMaterial({\n ...materialOptions,\n maxSequence: hasExtras ? globalSequence : maxSequence,\n motion: materialMotion(motion),\n })\n } catch (error) {\n glyphGeometry.dispose()\n throw error\n }\n let extras: ReturnType<typeof createExtraTextParts> | undefined\n try {\n if (hasExtras)\n extras = makeExtraParts!(snapshot, backend, materialOptions, materialMotion(motion), strength)\n } catch (error) {\n glyphGeometry.dispose()\n textMaterial.dispose()\n throw error\n }\n const text = new Mesh(glyphGeometry, textMaterial)\n text.name = 'ultra-text text'\n text.castShadow = options.castShadow !== false\n text.frustumCulled = false\n text.renderOrder = 2\n text.matrixAutoUpdate = false\n text.updateMatrix()\n group.add(text)\n\n const ownedMeshes: Mesh[] = [text]\n const disposeMeshes = (): void => {\n for (const mesh of ownedMeshes) {\n mesh.geometry.dispose()\n for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material])\n material.dispose()\n }\n ownedMeshes.length = 0\n group.clear()\n }\n try {\n if (extras) {\n for (const mesh of extras.meshes) {\n group.add(mesh)\n ownedMeshes.push(mesh)\n }\n extras.mergeRects(snapshot, text.geometry)\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n const glyphDrawable = (retained: WindfoilBackend, key: string): boolean =>\n (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key)\n let ce: ContentExtrasController | null = null\n try {\n if (extrasMod) {\n ce = extrasMod.createContentExtras(\n snapshot,\n text.geometry,\n group,\n ownedMeshes,\n options,\n () => animated,\n motion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(backend, key),\n )\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n\n const swapGeometry = (mesh: Mesh, geometry: InstancedBufferGeometry): void => {\n const previous = mesh.geometry\n mesh.geometry = geometry\n previous.dispose()\n }\n const setTone = (next: ResolvedTextTone | null): boolean => {\n if (!textMaterial.setTone(next)) return false\n for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next)\n return true\n }\n const toneFits = (next: ResolvedTextTone | null): boolean => {\n const current = textMaterial.tone\n return current && next ? current.fits(next) : !current && !next\n }\n\n let disposed = false\n return {\n g: group,\n get m(): GlyphTextMaterial {\n return textMaterial\n },\n get a(): boolean {\n return animated\n },\n sm(change, live) {\n if (animated) {\n textMaterial.setMotion(change)\n extras?.setMotion(change)\n ce?.setMotion(change)\n return\n }\n if (!isAnimatedMotion(live)) return\n const decMesh = ce?.decMesh()\n const meshes: Mesh<InstancedBufferGeometry, GlyphTextMaterial>[] = [\n text,\n ...(extras?.meshes ?? []),\n ...(decMesh ? [decMesh] : []),\n ]\n const twins: GlyphTextMaterial[] = []\n try {\n for (const mesh of meshes) twins.push(mesh.material.withMotion(live))\n } catch (error) {\n for (const twin of twins) twin.dispose()\n throw error\n }\n meshes.forEach((mesh, index) => {\n const previous = mesh.material\n mesh.material = twins[index]!\n previous.dispose()\n })\n textMaterial = twins[0]!\n animated = true\n },\n st: setTone,\n ud(layout, retained, liveMotion) {\n ce?.updateDec(\n layout,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(retained, key),\n )\n },\n get tg(): InstancedBufferGeometry {\n return text.geometry\n },\n rg(geometry) {\n swapGeometry(text, geometry)\n },\n u(nextSnapshot, nextBackend, liveMotion, nextTone) {\n if (\n nextTone !== undefined &&\n (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))\n )\n return false\n if (hasExtras && !extras!.fitsMotion(nextSnapshot)) return false\n if (colorEnabled !== usesColor(nextSnapshot)) return false\n if (\n ce\n ? !ce.fitsLayout(nextSnapshot)\n : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)\n )\n return false\n const strength = liveMotion.strength ?? 18\n const drawable = (key: string): boolean => glyphDrawable(nextBackend, key)\n const decorationsFit = ce ? ce.decorationsFit(nextSnapshot, drawable) : true\n if (hasExtras && !decorationsFit) return false\n const glyphsFit = decorationsFit && nextBackend.contentFits(text.geometry, nextSnapshot)\n let built: { geometry: InstancedBufferGeometry; maxSequence: number } | null = null\n let nextParts: readonly (InstancedBufferGeometry | null)[] = []\n let stagedExtras: StagedExtras | null = null\n const releaseStaged = (): void => {\n built?.geometry.dispose()\n for (const geometry of nextParts) geometry?.dispose()\n stagedExtras?.dispose()\n }\n try {\n nextParts = extras?.prepare(nextSnapshot, strength) ?? []\n if (!glyphsFit) built = nextBackend.createGeometry(nextSnapshot, strength)\n if (ce) {\n stagedExtras = ce.prepare(\n nextSnapshot,\n built?.geometry ?? text.geometry,\n animated,\n liveMotion,\n built?.maxSequence ?? textMaterial.maxSequence.value,\n decorationsFit,\n drawable,\n )\n }\n } catch (error) {\n releaseStaged()\n throw error\n }\n if (built) {\n swapGeometry(text, built.geometry)\n textMaterial.maxSequence.value = built.maxSequence\n } else {\n const maxSequence = nextBackend.updateGeometry(\n text.geometry,\n nextSnapshot,\n strength,\n undefined,\n true,\n )\n if (maxSequence === null) {\n releaseStaged()\n throw new Error('DomSdf: glyph buffers changed during the update')\n }\n textMaterial.maxSequence.value = maxSequence\n }\n if (extras) {\n extras.commit(nextParts, nextSnapshot, strength)\n textMaterial.maxSequence.value = maxSeq(nextSnapshot)\n extras.mergeRects(nextSnapshot, text.geometry)\n }\n ce?.commit(\n stagedExtras!,\n nextSnapshot,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n drawable,\n swapGeometry,\n )\n if (nextTone !== undefined) setTone(nextTone)\n return true\n },\n d() {\n if (disposed) return\n disposed = true\n disposeMeshes()\n },\n }\n}\n\nexport function reflowAnalytic(\n snapshot: DomLayoutSnapshot,\n retained: WindfoilBackend,\n content: AnalyticContentBundle,\n width: number,\n motion: SdfMotionOptions,\n rm: typeof ReflowModule,\n reflowState: ReflowState | null,\n): {\n readonly width: number\n readonly height: number\n readonly lines: number\n readonly state: ReflowState\n} {\n retained.setGlyphEm(!!content.m.tone?.dilates)\n const state = reflowState ?? rm.createReflowState(snapshot)\n const reflowed = rm.reflowSnapshotWithState(snapshot, width, state)\n const strength = motion.strength ?? 18\n if (retained.companion || retained.color) {\n if (!content.u(reflowed, retained, motion))\n throw new Error('DomSdf.reflow: incompatible retained content')\n } else {\n let maxSequence = retained.updateGeometry(content.tg, reflowed, strength)\n if (maxSequence === null) {\n const built = retained.createGeometry(reflowed, strength)\n content.rg(built.geometry)\n maxSequence = built.maxSequence\n }\n content.m.maxSequence.value = maxSequence\n content.ud(reflowed, retained, motion)\n }\n return { width: reflowed.width, height: reflowed.height, lines: reflowed.lineCount, state }\n}\n\nexport function countAnalyticStats(\n snapshot: DomLayoutSnapshot,\n windfoil: WindfoilBackend,\n): readonly [\n glyphs: number,\n shapes: number,\n colorGlyphs: number,\n fallbackGlyphs: number,\n switchableGlyphs: number,\n] {\n const glyphs = windfoil.companion?.glyphs\n const switchKeys = windfoil.sizeSwitch?.keys\n let glyphCount = 0\n let shapeCount = 0\n let colorGlyphCount = 0\n let fallbackGlyphCount = 0\n let switchableGlyphCount = 0\n for (const glyph of snapshot.glyphs) {\n if (switchKeys?.has(glyph.glyphKey)) switchableGlyphCount++\n if (glyph.shapeGroup !== undefined) {\n shapeCount++\n continue\n }\n glyphCount++\n const slot = glyphs?.get(glyph.glyphKey)\n if (slot && !windfoil.analyticCovers(glyph.glyphKey)) {\n if (slot.color) colorGlyphCount++\n fallbackGlyphCount++\n }\n }\n return [glyphCount, shapeCount, colorGlyphCount, fallbackGlyphCount, switchableGlyphCount]\n}\n"],"mappings":";;;;AAwCA,eAAsB,wBACpB,UACA,KACA,UACA,MACA,aACA,UACA,UACA,gBACA,YACA,QACA,gBACA,WACiC;CACjC,MAAM,kBAA2B,SAAS;CAC1C,IAAI,oBAAoB,KAAA,KAAa,OAAO,oBAAoB,YAC9D,MAAM,IAAI,UACR,wBAAwB,YAAY,aAAa,YAAY,iBAC/D;CAEF,IAAI,SAAS;CACb,IAAI;CACJ,IAAI,SAAS,iBACX,WAAW;EAAE,GAAG;EAAU,iBAAiB,SAAS;CAAgB;MAC/D;EACL,IAAI,CAAC,QAAQ;GACX,MAAM,EAAE,gCACL,MAAM,UAAU,iBAAmB,MAAM,UAAU,WAAW;GACjE,eAAe,MAAM;GACrB,WA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EAAO,QAAQ,SAAS;EAAQ,OAAO,SAAS;EAAW;CAAM;AAC5F;AAEA,SAAgB,mBACd,UACA,UAOA;CACA,MAAM,SAAS,SAAS,WAAW;CACnC,MAAM,aAAa,SAAS,YAAY;CACxC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,kBAAkB;CACtB,IAAI,qBAAqB;CACzB,IAAI,uBAAuB;CAC3B,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,IAAI,YAAY,IAAI,MAAM,QAAQ,GAAG;EACrC,IAAI,MAAM,eAAe,KAAA,GAAW;GAClC;GACA;EACF;EACA;EACA,MAAM,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACvC,IAAI,QAAQ,CAAC,SAAS,eAAe,MAAM,QAAQ,GAAG;GACpD,IAAI,KAAK,OAAO;GAChB;EACF;CACF;CACA,OAAO;EAAC;EAAY;EAAY;EAAiB;EAAoB;CAAoB;AAC3F"}
@@ -0,0 +1,27 @@
1
+ import { Mesh, type Group, type InstancedBufferGeometry } from 'three/webgpu';
2
+ import { TextDecorationMaterial } from '../text/decorations.js';
3
+ import type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js';
4
+ import type { DomLayoutSnapshot, SdfMotionOptions } from '../types.js';
5
+ export interface ExtrasOptions {
6
+ readonly textShaping?: 'none' | 'browser';
7
+ readonly side?: GlyphTextMaterial['side'];
8
+ readonly vertex?: unknown;
9
+ readonly castShadow?: boolean;
10
+ readonly shadowFloor?: number;
11
+ }
12
+ export interface StagedExtras {
13
+ readonly plain: InstancedBufferGeometry | null;
14
+ readonly receivers: InstancedBufferGeometry | null;
15
+ readonly decorations: readonly [InstancedBufferGeometry | null, TextDecorationMaterial | null] | null;
16
+ dispose(): void;
17
+ }
18
+ export interface ContentExtrasController {
19
+ readonly decMesh: () => Mesh<InstancedBufferGeometry, TextDecorationMaterial> | null;
20
+ setMotion(change: SdfMotionOptions): void;
21
+ updateDec(layout: DomLayoutSnapshot, textGeo: InstancedBufferGeometry, animated: boolean, liveMotion: SdfMotionOptions, maxSequence: number, drawable: (key: string) => boolean): void;
22
+ fitsLayout(snapshot: DomLayoutSnapshot): boolean;
23
+ decorationsFit(snapshot: DomLayoutSnapshot, drawable: (key: string) => boolean): boolean;
24
+ prepare(snapshot: DomLayoutSnapshot, textGeo: InstancedBufferGeometry, animated: boolean, liveMotion: SdfMotionOptions, maxSequence: number, decorationsFit: boolean, drawable: (key: string) => boolean): StagedExtras;
25
+ commit(staged: StagedExtras, snapshot: DomLayoutSnapshot, textGeo: InstancedBufferGeometry, animated: boolean, liveMotion: SdfMotionOptions, maxSequence: number, drawable: (key: string) => boolean, swapGeometry: (mesh: Mesh, geometry: InstancedBufferGeometry) => void): void;
26
+ }
27
+ export declare function createContentExtras(snapshot: DomLayoutSnapshot, textGeo: InstancedBufferGeometry, group: Group, ownedMeshes: Mesh[], options: ExtrasOptions, animated: () => boolean, motion: SdfMotionOptions, maxSequence: number, drawable: (key: string) => boolean): ContentExtrasController;
@@ -0,0 +1,137 @@
1
+ import { createRectMaterial } from "../text/RectMaterial.js";
2
+ import { createRectGeometry, rectContentFits, updateRectGeometry } from "../text/rectGeometry.js";
3
+ import { TextDecorationMaterial, canUpdateDecorationGeometry, createDecorationGeometry, updateDecorationGeometry } from "../text/decorations.js";
4
+ import { Mesh } from "three/webgpu";
5
+ // src/dom/domExtras.ts
6
+ function createContentExtras(snapshot, textGeo, group, ownedMeshes, options, animated, motion, maxSequence, drawable) {
7
+ const materialMotion = (live) => animated() ? live : false;
8
+ let decorations = null;
9
+ const prepareDecorations = (layout, liveMotion, nextTextGeo, nextSequence, canDraw) => {
10
+ const geometry = createDecorationGeometry(layout, nextTextGeo, canDraw, liveMotion.strength ?? 18);
11
+ try {
12
+ return [geometry, geometry && !decorations ? new TextDecorationMaterial({
13
+ textShaping: options.textShaping ?? "none",
14
+ side: options.side,
15
+ vertex: options.vertex,
16
+ motion: materialMotion(liveMotion),
17
+ maxSequence: nextSequence
18
+ }) : null];
19
+ } catch (error) {
20
+ geometry?.dispose();
21
+ throw error;
22
+ }
23
+ };
24
+ const commitDecorations = ([geometry, material], liveMotion, seqValue) => {
25
+ if (!geometry) {
26
+ if (decorations) {
27
+ group.remove(decorations);
28
+ ownedMeshes.splice(ownedMeshes.indexOf(decorations), 1);
29
+ decorations.geometry.dispose();
30
+ decorations.material.dispose();
31
+ decorations = null;
32
+ }
33
+ return;
34
+ }
35
+ if (decorations) {
36
+ const previous = decorations.geometry;
37
+ decorations.geometry = geometry;
38
+ previous.dispose();
39
+ if (animated()) decorations.material.setMotion(liveMotion);
40
+ decorations.material.maxSequence.value = seqValue;
41
+ } else {
42
+ decorations = new Mesh(geometry, material);
43
+ decorations.name = "ultra-text text decorations";
44
+ decorations.castShadow = options.castShadow !== false;
45
+ decorations.renderOrder = 3;
46
+ decorations.frustumCulled = false;
47
+ group.add(decorations);
48
+ ownedMeshes.push(decorations);
49
+ }
50
+ };
51
+ const updateDec = (layout, textGeom, isAnim, liveMotion, seqValue, canDraw) => {
52
+ if (!decorations) return;
53
+ if (updateDecorationGeometry(decorations.geometry, layout, textGeom, canDraw, liveMotion.strength ?? 18)) {
54
+ if (isAnim) decorations.material.setMotion(liveMotion);
55
+ decorations.material.maxSequence.value = seqValue;
56
+ return;
57
+ }
58
+ commitDecorations(prepareDecorations(layout, liveMotion, textGeom, seqValue, canDraw), liveMotion, seqValue);
59
+ };
60
+ const addRects = (receiver, name) => {
61
+ const geometry = createRectGeometry(snapshot, receiver);
62
+ if (!geometry) return null;
63
+ let mesh;
64
+ try {
65
+ mesh = new Mesh(geometry, createRectMaterial(receiver, options.shadowFloor));
66
+ } catch (error) {
67
+ geometry.dispose();
68
+ throw error;
69
+ }
70
+ mesh.name = name;
71
+ mesh.receiveShadow = receiver;
72
+ mesh.frustumCulled = true;
73
+ mesh.renderOrder = 0;
74
+ mesh.matrixAutoUpdate = false;
75
+ mesh.updateMatrix();
76
+ group.add(mesh);
77
+ ownedMeshes.push(mesh);
78
+ return mesh;
79
+ };
80
+ const initialDecorations = prepareDecorations(snapshot, motion, textGeo, maxSequence, drawable);
81
+ if (initialDecorations[0]) commitDecorations(initialDecorations, motion, maxSequence);
82
+ const plainRects = addRects(false, "ultra-text DOM rectangles");
83
+ const receivers = addRects(true, "ultra-text shadow receivers");
84
+ return {
85
+ decMesh: () => decorations,
86
+ setMotion(change) {
87
+ decorations?.material.setMotion(change);
88
+ },
89
+ updateDec,
90
+ fitsLayout(nextSnapshot) {
91
+ const wantsPlain = nextSnapshot.rects.some((r) => !r.receiveShadow);
92
+ const wantsReceivers = nextSnapshot.rects.some((r) => r.receiveShadow);
93
+ return wantsPlain === (plainRects !== null) && wantsReceivers === (receivers !== null);
94
+ },
95
+ decorationsFit(nextSnapshot, canDraw) {
96
+ return canUpdateDecorationGeometry(decorations?.geometry ?? null, nextSnapshot, canDraw);
97
+ },
98
+ prepare(nextSnapshot, nextTextGeo, _isAnim, liveMotion, nextSequence, decFits, canDraw) {
99
+ const plainFit = !plainRects || rectContentFits(plainRects.geometry, nextSnapshot, false);
100
+ const receiverFit = !receivers || rectContentFits(receivers.geometry, nextSnapshot, true);
101
+ let plain = null;
102
+ let rec = null;
103
+ let dec = null;
104
+ const dispose = () => {
105
+ plain?.dispose();
106
+ rec?.dispose();
107
+ dec?.[0]?.dispose();
108
+ dec?.[1]?.dispose();
109
+ };
110
+ try {
111
+ if (plainRects && !plainFit) plain = createRectGeometry(nextSnapshot, false);
112
+ if (receivers && !receiverFit) rec = createRectGeometry(nextSnapshot, true);
113
+ if (!decFits) dec = prepareDecorations(nextSnapshot, liveMotion, nextTextGeo, nextSequence, canDraw);
114
+ } catch (error) {
115
+ dispose();
116
+ throw error;
117
+ }
118
+ return {
119
+ plain,
120
+ receivers: rec,
121
+ decorations: dec,
122
+ dispose
123
+ };
124
+ },
125
+ commit(staged, nextSnapshot, nextTextGeo, isAnim, liveMotion, seqValue, canDraw, swap) {
126
+ if (staged.decorations) commitDecorations(staged.decorations, liveMotion, seqValue);
127
+ else updateDec(nextSnapshot, nextTextGeo, isAnim, liveMotion, seqValue, canDraw);
128
+ if (plainRects && staged.plain) swap(plainRects, staged.plain);
129
+ else if (plainRects) updateRectGeometry(plainRects.geometry, nextSnapshot, false);
130
+ if (receivers && staged.receivers) swap(receivers, staged.receivers);
131
+ else if (receivers) updateRectGeometry(receivers.geometry, nextSnapshot, true);
132
+ }
133
+ };
134
+ }
135
+ export { createContentExtras };
136
+
137
+ //# sourceMappingURL=domExtras.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domExtras.js","names":[],"sources":["../../src/dom/domExtras.ts"],"sourcesContent":["import { Mesh, type Group, type InstancedBufferGeometry } from 'three/webgpu'\n\nimport {\n canUpdateDecorationGeometry,\n createDecorationGeometry,\n TextDecorationMaterial,\n updateDecorationGeometry,\n} from '../text/decorations.js'\nimport { createRectGeometry, rectContentFits, updateRectGeometry } from '../text/rectGeometry.js'\nimport { createRectMaterial } from '../text/RectMaterial.js'\nimport type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport type { DomLayoutSnapshot, SdfMotionOptions } from '../types.js'\n\nexport interface ExtrasOptions {\n readonly textShaping?: 'none' | 'browser'\n readonly side?: GlyphTextMaterial['side']\n readonly vertex?: unknown\n readonly castShadow?: boolean\n readonly shadowFloor?: number\n}\n\nexport interface StagedExtras {\n readonly plain: InstancedBufferGeometry | null\n readonly receivers: InstancedBufferGeometry | null\n readonly decorations:\n readonly [InstancedBufferGeometry | null, TextDecorationMaterial | null] | null\n dispose(): void\n}\n\nexport interface ContentExtrasController {\n readonly decMesh: () => Mesh<InstancedBufferGeometry, TextDecorationMaterial> | null\n setMotion(change: SdfMotionOptions): void\n updateDec(\n layout: DomLayoutSnapshot,\n textGeo: InstancedBufferGeometry,\n animated: boolean,\n liveMotion: SdfMotionOptions,\n maxSequence: number,\n drawable: (key: string) => boolean,\n ): void\n fitsLayout(snapshot: DomLayoutSnapshot): boolean\n decorationsFit(snapshot: DomLayoutSnapshot, drawable: (key: string) => boolean): boolean\n prepare(\n snapshot: DomLayoutSnapshot,\n textGeo: InstancedBufferGeometry,\n animated: boolean,\n liveMotion: SdfMotionOptions,\n maxSequence: number,\n decorationsFit: boolean,\n drawable: (key: string) => boolean,\n ): StagedExtras\n commit(\n staged: StagedExtras,\n snapshot: DomLayoutSnapshot,\n textGeo: InstancedBufferGeometry,\n animated: boolean,\n liveMotion: SdfMotionOptions,\n maxSequence: number,\n drawable: (key: string) => boolean,\n swapGeometry: (mesh: Mesh, geometry: InstancedBufferGeometry) => void,\n ): void\n}\n\nexport function createContentExtras(\n snapshot: DomLayoutSnapshot,\n textGeo: InstancedBufferGeometry,\n group: Group,\n ownedMeshes: Mesh[],\n options: ExtrasOptions,\n animated: () => boolean,\n motion: SdfMotionOptions,\n maxSequence: number,\n drawable: (key: string) => boolean,\n): ContentExtrasController {\n const materialMotion = (live: SdfMotionOptions): SdfMotionOptions | false =>\n animated() ? live : false\n let decorations: Mesh<InstancedBufferGeometry, TextDecorationMaterial> | null = null\n\n const prepareDecorations = (\n layout: DomLayoutSnapshot,\n liveMotion: SdfMotionOptions,\n nextTextGeo: InstancedBufferGeometry,\n nextSequence: number,\n canDraw: (key: string) => boolean,\n ): readonly [InstancedBufferGeometry | null, TextDecorationMaterial | null] => {\n const geometry = createDecorationGeometry(\n layout,\n nextTextGeo,\n canDraw,\n liveMotion.strength ?? 18,\n )\n try {\n return [\n geometry,\n geometry && !decorations\n ? new TextDecorationMaterial({\n textShaping: options.textShaping ?? 'none',\n side: options.side,\n vertex: options.vertex as never,\n motion: materialMotion(liveMotion),\n maxSequence: nextSequence,\n })\n : null,\n ]\n } catch (error) {\n geometry?.dispose()\n throw error\n }\n }\n\n const commitDecorations = (\n [geometry, material]: readonly [InstancedBufferGeometry | null, TextDecorationMaterial | null],\n liveMotion: SdfMotionOptions,\n seqValue: number,\n ): void => {\n if (!geometry) {\n if (decorations) {\n group.remove(decorations)\n ownedMeshes.splice(ownedMeshes.indexOf(decorations), 1)\n decorations.geometry.dispose()\n decorations.material.dispose()\n decorations = null\n }\n return\n }\n if (decorations) {\n const previous = decorations.geometry\n decorations.geometry = geometry\n previous.dispose()\n if (animated()) decorations.material.setMotion(liveMotion)\n decorations.material.maxSequence.value = seqValue\n } else {\n decorations = new Mesh(geometry, material!)\n decorations.name = 'ultra-text text decorations'\n decorations.castShadow = options.castShadow !== false\n decorations.renderOrder = 3\n decorations.frustumCulled = false\n group.add(decorations)\n ownedMeshes.push(decorations)\n }\n }\n\n const updateDec = (\n layout: DomLayoutSnapshot,\n textGeom: InstancedBufferGeometry,\n isAnim: boolean,\n liveMotion: SdfMotionOptions,\n seqValue: number,\n canDraw: (key: string) => boolean,\n ): void => {\n if (!decorations) return\n if (\n updateDecorationGeometry(\n decorations.geometry,\n layout,\n textGeom,\n canDraw,\n liveMotion.strength ?? 18,\n )\n ) {\n if (isAnim) decorations.material.setMotion(liveMotion)\n decorations.material.maxSequence.value = seqValue\n return\n }\n commitDecorations(\n prepareDecorations(layout, liveMotion, textGeom, seqValue, canDraw),\n liveMotion,\n seqValue,\n )\n }\n\n const addRects = (receiver: boolean, name: string): Mesh | null => {\n const geometry = createRectGeometry(snapshot, receiver)\n if (!geometry) return null\n let mesh: Mesh\n try {\n mesh = new Mesh(geometry, createRectMaterial(receiver, options.shadowFloor))\n } catch (error) {\n geometry.dispose()\n throw error\n }\n mesh.name = name\n mesh.receiveShadow = receiver\n mesh.frustumCulled = true\n mesh.renderOrder = 0\n mesh.matrixAutoUpdate = false\n mesh.updateMatrix()\n group.add(mesh)\n ownedMeshes.push(mesh)\n return mesh\n }\n\n const initialDecorations = prepareDecorations(snapshot, motion, textGeo, maxSequence, drawable)\n if (initialDecorations[0]) commitDecorations(initialDecorations, motion, maxSequence)\n const plainRects = addRects(false, 'ultra-text DOM rectangles')\n const receivers = addRects(true, 'ultra-text shadow receivers')\n\n return {\n decMesh: () => decorations,\n setMotion(change) {\n decorations?.material.setMotion(change)\n },\n updateDec,\n fitsLayout(nextSnapshot) {\n const wantsPlain = nextSnapshot.rects.some((r) => !r.receiveShadow)\n const wantsReceivers = nextSnapshot.rects.some((r) => r.receiveShadow)\n return wantsPlain === (plainRects !== null) && wantsReceivers === (receivers !== null)\n },\n decorationsFit(nextSnapshot, canDraw) {\n return canUpdateDecorationGeometry(decorations?.geometry ?? null, nextSnapshot, canDraw)\n },\n prepare(nextSnapshot, nextTextGeo, _isAnim, liveMotion, nextSequence, decFits, canDraw) {\n const plainFit =\n !plainRects ||\n rectContentFits(plainRects.geometry as InstancedBufferGeometry, nextSnapshot, false)\n const receiverFit =\n !receivers ||\n rectContentFits(receivers.geometry as InstancedBufferGeometry, nextSnapshot, true)\n let plain: InstancedBufferGeometry | null = null\n let rec: InstancedBufferGeometry | null = null\n let dec: readonly [InstancedBufferGeometry | null, TextDecorationMaterial | null] | null =\n null\n const dispose = (): void => {\n plain?.dispose()\n rec?.dispose()\n dec?.[0]?.dispose()\n dec?.[1]?.dispose()\n }\n try {\n if (plainRects && !plainFit) plain = createRectGeometry(nextSnapshot, false)\n if (receivers && !receiverFit) rec = createRectGeometry(nextSnapshot, true)\n if (!decFits)\n dec = prepareDecorations(nextSnapshot, liveMotion, nextTextGeo, nextSequence, canDraw)\n } catch (error) {\n dispose()\n throw error\n }\n return { plain, receivers: rec, decorations: dec, dispose }\n },\n commit(staged, nextSnapshot, nextTextGeo, isAnim, liveMotion, seqValue, canDraw, swap) {\n if (staged.decorations) commitDecorations(staged.decorations, liveMotion, seqValue)\n else updateDec(nextSnapshot, nextTextGeo, isAnim, liveMotion, seqValue, canDraw)\n if (plainRects && staged.plain) swap(plainRects, staged.plain)\n else if (plainRects)\n updateRectGeometry(plainRects.geometry as InstancedBufferGeometry, nextSnapshot, false)\n if (receivers && staged.receivers) swap(receivers, staged.receivers)\n else if (receivers)\n updateRectGeometry(receivers.geometry as InstancedBufferGeometry, nextSnapshot, true)\n },\n }\n}\n"],"mappings":";;;;;AA+DA,SAAgB,oBACd,UACA,SACA,OACA,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c,IAAI;GACnF,IAAI,QAAwC;GAC5C,IAAI,MAAsC;GAC1C,IAAI,MACF;GACF,MAAM,gBAAsB;IAC1B,OAAO,QAAQ;IACf,KAAK,QAAQ;IACb,MAAM,EAAE,EAAE,QAAQ;IAClB,MAAM,EAAE,EAAE,QAAQ;GACpB;GACA,IAAI;IACF,IAAI,cAAc,CAAC,UAAU,QAAQ,mBAAmB,cAAc,KAAK;IAC3E,IAAI,aAAa,CAAC,aAAa,MAAM,mBAAmB,cAAc,IAAI;IAC1E,IAAI,CAAC,SACH,MAAM,mBAAmB,cAAc,YAAY,aAAa,cAAc,OAAO;GACzF,SAAS,OAAO;IACd,QAAQ;IACR,MAAM;GACR;GACA,OAAO;IAAE;IAAO,WAAW;IAAK,aAAa;IAAK;GAAQ;EAC5D;EACA,OAAO,QAAQ,cAAc,aAAa,QAAQ,YAAY,UAAU,SAAS,MAAM;GACrF,IAAI,OAAO,aAAa,kBAAkB,OAAO,aAAa,YAAY,QAAQ;QAC7E,UAAU,cAAc,aAAa,QAAQ,YAAY,UAAU,OAAO;GAC/E,IAAI,cAAc,OAAO,OAAO,KAAK,YAAY,OAAO,KAAK;QACxD,IAAI,YACP,mBAAmB,WAAW,UAAqC,cAAc,KAAK;GACxF,IAAI,aAAa,OAAO,WAAW,KAAK,WAAW,OAAO,SAAS;QAC9D,IAAI,WACP,mBAAmB,UAAU,UAAqC,cAAc,IAAI;EACxF;CACF;AACF"}
@@ -34,7 +34,7 @@ function setFontContext(context, request, shaping, lastFont) {
34
34
  }
35
35
  if ("fontKerning" in extended) extended.fontKerning = font.kerning;
36
36
  if ("fontStretch" in extended) extended.fontStretch = canvasFontStretch(font.stretch);
37
- if ("fontVariantCaps" in extended) extended.fontVariantCaps = /\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\b/.exec(font.variant)?.[0] ?? "normal";
37
+ if ("fontVariantCaps" in extended) extended.fontVariantCaps = font.variant === "normal" ? "normal" : /\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\b/.exec(font.variant)?.[0] ?? "normal";
38
38
  }
39
39
  shaping?.(context, request);
40
40
  return font;
@@ -51,13 +51,7 @@ function createCanvas(document) {
51
51
  const canvas = document.createElement("canvas");
52
52
  canvas.width = 1;
53
53
  canvas.height = 1;
54
- for (const [property, value] of [
55
- ["all", "initial"],
56
- ["display", "none"],
57
- ["direction", "ltr"],
58
- ["-webkit-font-smoothing", "antialiased"],
59
- ["-moz-osx-font-smoothing", "grayscale"]
60
- ]) canvas.style.setProperty(property, value, "important");
54
+ canvas.style.cssText = "all:initial!important;display:none!important;direction:ltr!important;-webkit-font-smoothing:antialiased!important;-moz-osx-font-smoothing:grayscale!important;";
61
55
  canvas.dir = "ltr";
62
56
  canvas.lang = "";
63
57
  document.documentElement.append(canvas);
@@ -96,6 +90,30 @@ async function waitForFonts(document, requests, signal) {
96
90
  }));
97
91
  if (signal?.aborted) throw signal.reason ?? new DOMException("The atlas build was aborted", "AbortError");
98
92
  }
99
- export { allFontsLoaded, createCanvas, isColorCandidate, setFontContext, waitForFonts };
93
+ var sharedOffscreenMeasure;
94
+ /** @internal True in real browsers with native OffscreenCanvas and unmocked Canvas2D getContext. */
95
+ function isNativeMeasureBrowser(document) {
96
+ const view = document.defaultView;
97
+ if (!view) return false;
98
+ const fonts = document.fonts;
99
+ if (!("CanvasRenderingContext2D" in view) || !("OffscreenCanvas" in view) || fonts?.status !== "loaded" || !Function.prototype.toString.call(view.OffscreenCanvas).includes("[native")) return false;
100
+ const getContextFn = Object.getOwnPropertyDescriptor(view.HTMLCanvasElement.prototype, "getContext")?.value;
101
+ return !(getContextFn && "mock" in getContextFn);
102
+ }
103
+ /** @internal Shared OffscreenCanvas measurement context (without `willReadFrequently`) when native. */
104
+ function createSharedMeasureContext(document) {
105
+ const view = document.defaultView;
106
+ if (view && isNativeMeasureBrowser(document)) {
107
+ if (sharedOffscreenMeasure === void 0) sharedOffscreenMeasure = new view.OffscreenCanvas(1, 1).getContext("2d");
108
+ if (sharedOffscreenMeasure) {
109
+ if ("letterSpacing" in sharedOffscreenMeasure) sharedOffscreenMeasure.letterSpacing = "0px";
110
+ sharedOffscreenMeasure.textAlign = "left";
111
+ sharedOffscreenMeasure.textBaseline = "alphabetic";
112
+ return sharedOffscreenMeasure;
113
+ }
114
+ }
115
+ return document.createElement("canvas").getContext("2d");
116
+ }
117
+ export { allFontsLoaded, createCanvas, createSharedMeasureContext, isColorCandidate, isNativeMeasureBrowser, setFontContext, waitForFonts };
100
118
 
101
119
  //# sourceMappingURL=fontCanvas.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fontCanvas.js","names":[],"sources":["../../src/dom/fontCanvas.ts"],"sourcesContent":["import type { ColorGlyphMode, GlyphRequest } from '../types.js'\nimport type { setShapingContext } from './browserShaping.js'\nimport { isEmojiCandidate } from './clusters.js'\n\nexport type ShapingContext = typeof setShapingContext\n\ninterface CanvasFontContext extends CanvasRenderingContext2D {\n fontKerning: CanvasFontKerning\n fontStretch: CanvasFontStretch\n fontVariantCaps: CanvasFontVariantCaps\n letterSpacing: string\n wordSpacing: string\n}\n\nconst CANVAS_FONT_STRETCHES = [\n ['ultra-condensed', 50],\n ['extra-condensed', 62.5],\n ['condensed', 75],\n ['semi-condensed', 87.5],\n ['normal', 100],\n ['semi-expanded', 112.5],\n ['expanded', 125],\n ['extra-expanded', 150],\n ['ultra-expanded', 200],\n] as const satisfies readonly (readonly [CanvasFontStretch, number])[]\n\nfunction canvasFontStretch(value: string): CanvasFontStretch {\n if (value === '100%' || value === 'normal') return 'normal'\n const percentage = Number.parseFloat(value)\n if (!Number.isFinite(percentage)) {\n return CANVAS_FONT_STRETCHES.find(([name]) => name === value)?.[0] ?? 'normal'\n }\n return CANVAS_FONT_STRETCHES.reduce((a, b) =>\n Math.abs(b[1] - percentage) < Math.abs(a[1] - percentage) ? b : a,\n )[0]\n}\n\n/** @internal Shared atlas compatibility and raster candidacy rule. */\nexport function isColorCandidate(request: GlyphRequest, mode: ColorGlyphMode = 'emoji'): boolean {\n if (request.shape) return request.shape.bitmap === true\n return mode === 'all' || (mode === 'emoji' && isEmojiCandidate(request.character))\n}\n\n/** @internal The bake canvas's font state for a request, shared with the outline tracer. */\nexport function setFontContext(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n shaping: ShapingContext | undefined,\n lastFont: GlyphRequest['font'] | null,\n): GlyphRequest['font'] {\n const { font } = request\n if (lastFont !== font) {\n const extended: CanvasFontContext = context\n context.font = font.canvasFont\n if (!lastFont) {\n context.textAlign = 'left'\n context.textBaseline = 'alphabetic'\n }\n if ('fontKerning' in extended) extended.fontKerning = font.kerning as CanvasFontKerning\n if ('fontStretch' in extended) extended.fontStretch = canvasFontStretch(font.stretch)\n if ('fontVariantCaps' in extended)\n extended.fontVariantCaps =\n (/\\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\\b/.exec(font.variant)?.[0] ??\n 'normal') as CanvasFontVariantCaps\n }\n shaping?.(context, request)\n return font\n}\n\n/**\n * The bake canvas. Font smoothing follows the canvas element's computed style, and only while\n * the element is in a document: there it is turned off, in every engine, so a mask is the\n * outline itself. Everything else a page would hand down (spacing, font features and\n * variations, direction, language) is cut off, so the mask stays what a detached canvas draws.\n * The caller takes it out of the document again.\n * @internal Shared with the atlas append path and the outline tracer.\n */\nexport function createCanvas(document: Document): HTMLCanvasElement {\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n for (const [property, value] of [\n ['all', 'initial'],\n ['display', 'none'],\n ['direction', 'ltr'],\n ['-webkit-font-smoothing', 'antialiased'],\n ['-moz-osx-font-smoothing', 'grayscale'],\n ] as const)\n canvas.style.setProperty(property, value, 'important')\n canvas.dir = 'ltr'\n canvas.lang = ''\n document.documentElement.append(canvas)\n return canvas\n}\n\n/** @internal True when the document has a FontFaceSet whose registered faces are all loaded. */\nexport function allFontsLoaded(document: Document): boolean {\n const fonts = document.fonts as FontFaceSet | undefined\n if (fonts?.status !== 'loaded') return false\n const faceSet = fonts as {\n load?: unknown\n check?: unknown\n [Symbol.iterator]?: unknown\n }\n if (\n typeof faceSet.load !== 'function' ||\n 'mock' in faceSet.load ||\n typeof faceSet.check !== 'function' ||\n 'mock' in faceSet.check ||\n typeof faceSet[Symbol.iterator] !== 'function'\n ) {\n return false\n }\n for (const face of fonts as Iterable<FontFace>) {\n if (face.status !== 'loaded') return false\n }\n return true\n}\n\n/** @internal Loads every face the text requests draw with; shared with the outline tracer. */\nexport async function waitForFonts(\n document: Document,\n requests: readonly GlyphRequest[],\n signal?: AbortSignal,\n): Promise<void> {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n const fonts = document.fonts as FontFaceSet | undefined\n if (!fonts || allFontsLoaded(document)) return\n const byFont = new Map<string, { font: string; text: string }>()\n for (const request of requests) {\n if (request.shape) continue\n const current = byFont.get(request.font.key)\n if (current) current.text += request.character\n else byFont.set(request.font.key, { font: request.font.canvasFont, text: request.character })\n }\n const ok = fonts.status === 'loaded' && !('mock' in (fonts as { load: object }).load)\n await Promise.all(\n Array.from(byFont.values(), (i) => {\n try {\n if (ok && fonts.check(i.font, i.text)) return\n } catch {\n // Load below when check rejects an uncommon font shorthand.\n }\n return fonts.load(i.font, i.text)\n }) as Promise<unknown>[],\n )\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n"],"mappings":";;AAcA,IAAM,wBAAwB;CAC5B,CAAC,mBAAmB,EAAE;CACtB,CAAC,mBAAmB,IAAI;CACxB,CAAC,aAAa,EAAE;CAChB,CAAC,kBAAkB,IAAI;CACvB,CAAC,UAAU,GAAG;CACd,CAAC,iBAAiB,KAAK;CACvB,CAAC,YAAY,GAAG;CAChB,CAAC,kBAAkB,GAAG;CACtB,CAAC,kBAAkB,GAAG;AACxB;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,IAAI,UAAU,UAAU,UAAU,UAAU,OAAO;CACnD,MAAM,aAAa,OAAO,WAAW,K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Request } from '../types.js'\nimport type { setShapingContext } from './browserShaping.js'\nimport { isEmojiCandidate } from './clusters.js'\n\nexport type ShapingContext = typeof setShapingContext\n\ninterface CanvasFontContext extends CanvasRenderingContext2D {\n fontKerning: CanvasFontKerning\n fontStretch: CanvasFontStretch\n fontVariantCaps: CanvasFontVariantCaps\n letterSpacing: string\n wordSpacing: string\n}\n\nconst CANVAS_FONT_STRETCHES = [\n ['ultra-condensed', 50],\n ['extra-condensed', 62.5],\n ['condensed', 75],\n ['semi-condensed', 87.5],\n ['normal', 100],\n ['semi-expanded', 112.5],\n ['expanded', 125],\n ['extra-expanded', 150],\n ['ultra-expanded', 200],\n] as const satisfies readonly (readonly [CanvasFontStretch, number])[]\n\nfunction canvasFontStretch(value: string): CanvasFontStretch {\n if (value === '100%' || value === 'normal') return 'normal'\n const percentage = Number.parseFloat(value)\n if (!Number.isFinite(percentage)) {\n return CANVAS_FONT_STRETCHES.find(([name]) => name === value)?.[0] ?? 'normal'\n }\n return CANVAS_FONT_STRETCHES.reduce((a, b) =>\n Math.abs(b[1] - percentage) < Math.abs(a[1] - percentage) ? b : a,\n )[0]\n}\n\n/** @internal Shared atlas compatibility and raster candidacy rule. */\nexport function isColorCandidate(request: GlyphRequest, mode: ColorGlyphMode = 'emoji'): boolean {\n if (request.shape) return request.shape.bitmap === true\n return mode === 'all' || (mode === 'emoji' && isEmojiCandidate(request.character))\n}\n\n/** @internal The bake canvas's font state for a request, shared with the outline tracer. */\nexport function setFontContext(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n shaping: ShapingContext | undefined,\n lastFont: GlyphRequest['font'] | null,\n): GlyphRequest['font'] {\n const { font } = request\n if (lastFont !== font) {\n const extended: CanvasFontContext = context\n context.font = font.canvasFont\n if (!lastFont) {\n context.textAlign = 'left'\n context.textBaseline = 'alphabetic'\n }\n if ('fontKerning' in extended) extended.fontKerning = font.kerning as CanvasFontKerning\n if ('fontStretch' in extended) extended.fontStretch = canvasFontStretch(font.stretch)\n if ('fontVariantCaps' in extended)\n extended.fontVariantCaps =\n font.variant === 'normal'\n ? 'normal'\n : ((/\\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\\b/.exec(\n font.variant,\n )?.[0] ?? 'normal') as CanvasFontVariantCaps)\n }\n shaping?.(context, request)\n return font\n}\n\n/**\n * The bake canvas. Font smoothing follows the canvas element's computed style, and only while\n * the element is in a document: there it is turned off, in every engine, so a mask is the\n * outline itself. Everything else a page would hand down (spacing, font features and\n * variations, direction, language) is cut off, so the mask stays what a detached canvas draws.\n * The caller takes it out of the document again.\n * @internal Shared with the atlas append path and the outline tracer.\n */\nexport function createCanvas(document: Document): HTMLCanvasElement {\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n canvas.style.cssText =\n 'all:initial!important;display:none!important;direction:ltr!important;-webkit-font-smoothing:antialiased!important;-moz-osx-font-smoothing:grayscale!important;'\n canvas.dir = 'ltr'\n canvas.lang = ''\n document.documentElement.append(canvas)\n return canvas\n}\n\n/** @internal True when the document has a FontFaceSet whose registered faces are all loaded. */\nexport function allFontsLoaded(document: Document): boolean {\n const fonts = document.fonts as FontFaceSet | undefined\n if (fonts?.status !== 'loaded') return false\n const faceSet = fonts as {\n load?: unknown\n check?: unknown\n [Symbol.iterator]?: unknown\n }\n if (\n typeof faceSet.load !== 'function' ||\n 'mock' in faceSet.load ||\n typeof faceSet.check !== 'function' ||\n 'mock' in faceSet.check ||\n typeof faceSet[Symbol.iterator] !== 'function'\n ) {\n return false\n }\n for (const face of fonts as Iterable<FontFace>) {\n if (face.status !== 'loaded') return false\n }\n return true\n}\n\n/** @internal Loads every face the text requests draw with; shared with the outline tracer. */\nexport async function waitForFonts(\n document: Document,\n requests: readonly GlyphRequest[],\n signal?: AbortSignal,\n): Promise<void> {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n const fonts = document.fonts as FontFaceSet | undefined\n if (!fonts || allFontsLoaded(document)) return\n const byFont = new Map<string, { font: string; text: string }>()\n for (const request of requests) {\n if (request.shape) continue\n const current = byFont.get(request.font.key)\n if (current) current.text += request.character\n else byFont.set(request.font.key, { font: request.font.canvasFont, text: request.character })\n }\n const ok = fonts.status === 'loaded' && !('mock' in (fonts as { load: object }).load)\n await Promise.all(\n Array.from(byFont.values(), (i) => {\n try {\n if (ok && fonts.check(i.font, i.text)) return\n } catch {\n // Load below when check rejects an uncommon font shorthand.\n }\n return fonts.load(i.font, i.text)\n }) as Promise<unknown>[],\n )\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n\nlet sharedOffscreenMeasure: OffscreenCanvasRenderingContext2D | null | undefined\n\n/** @internal True in real browsers with native OffscreenCanvas and unmocked Canvas2D getContext. */\nexport function isNativeMeasureBrowser(document: Document): boolean {\n const view = document.defaultView\n if (!view) return false\n const fonts = document.fonts as FontFaceSet | undefined\n if (\n !('CanvasRenderingContext2D' in view) ||\n !('OffscreenCanvas' in view) ||\n fonts?.status !== 'loaded' ||\n !Function.prototype.toString.call(view.OffscreenCanvas).includes('[native')\n ) {\n return false\n }\n const getContextFn = Object.getOwnPropertyDescriptor(\n view.HTMLCanvasElement.prototype,\n 'getContext',\n )?.value as object | undefined\n return !(getContextFn && 'mock' in getContextFn)\n}\n\n/** @internal Shared OffscreenCanvas measurement context (without `willReadFrequently`) when native. */\nexport function createSharedMeasureContext(document: Document): CanvasRenderingContext2D | null {\n const view = document.defaultView\n if (view && isNativeMeasureBrowser(document)) {\n if (sharedOffscreenMeasure === undefined) {\n sharedOffscreenMeasure = new (\n view as Window & { OffscreenCanvas: typeof OffscreenCanvas }\n ).OffscreenCanvas(1, 1).getContext('2d')\n }\n if (sharedOffscreenMeasure) {\n if ('letterSpacing' in sharedOffscreenMeasure) sharedOffscreenMeasure.letterSpacing = '0px'\n sharedOffscreenMeasure.textAlign = 'left'\n sharedOffscreenMeasure.textBaseline = 'alphabetic'\n return sharedOffscreenMeasure as unknown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