ultra-text 1.0.0 → 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 (200) hide show
  1. package/README.md +267 -962
  2. package/THIRD_PARTY_NOTICES.md +3 -0
  3. package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
  4. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
  5. package/dist/atlas/appendAtlas.js +69 -26
  6. package/dist/atlas/appendAtlas.js.map +1 -1
  7. package/dist/atlas/buildAtlas.js +5 -15
  8. package/dist/atlas/buildAtlas.js.map +1 -1
  9. package/dist/atlas/cpuAtlas.d.ts +4 -1
  10. package/dist/atlas/cpuAtlas.js +8 -6
  11. package/dist/atlas/cpuAtlas.js.map +1 -1
  12. package/dist/atlas/cpuSdf.js +164 -50
  13. package/dist/atlas/cpuSdf.js.map +1 -1
  14. package/dist/atlas/cpuWorker.d.ts +5 -3
  15. package/dist/atlas/cpuWorker.js +119 -12
  16. package/dist/atlas/cpuWorker.js.map +1 -1
  17. package/dist/atlas/gpuAtlas.d.ts +7 -6
  18. package/dist/atlas/gpuAtlas.js +206 -247
  19. package/dist/atlas/gpuAtlas.js.map +1 -1
  20. package/dist/atlas/gpuCommon.d.ts +135 -0
  21. package/dist/atlas/gpuCommon.js +223 -0
  22. package/dist/atlas/gpuCommon.js.map +1 -0
  23. package/dist/atlas/jfaWgsl.js +59 -125
  24. package/dist/atlas/jfaWgsl.js.map +1 -1
  25. package/dist/atlas/rasterize.d.ts +2 -0
  26. package/dist/atlas/rasterize.js +104 -144
  27. package/dist/atlas/rasterize.js.map +1 -1
  28. package/dist/atlas/shapeRaster.js +2 -1
  29. package/dist/atlas/shapeRaster.js.map +1 -1
  30. package/dist/atlas/vanillaBounds.d.ts +64 -0
  31. package/dist/atlas/vanillaBounds.js +42 -0
  32. package/dist/atlas/vanillaBounds.js.map +1 -0
  33. package/dist/atlas/vanillaCore.d.ts +100 -0
  34. package/dist/atlas/vanillaCore.js +1012 -0
  35. package/dist/atlas/vanillaCore.js.map +1 -0
  36. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  37. package/dist/atlas/vanillaCpuAtlas.js +87 -0
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  39. package/dist/atlas/vanillaExtras.d.ts +8 -0
  40. package/dist/atlas/vanillaExtras.js +166 -0
  41. package/dist/atlas/vanillaExtras.js.map +1 -0
  42. package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
  43. package/dist/atlas/vanillaGpuHelpers.js +119 -0
  44. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  45. package/dist/dom/DomSdf.js +263 -272
  46. package/dist/dom/DomSdf.js.map +1 -1
  47. package/dist/dom/DomSlug.d.ts +26 -0
  48. package/dist/dom/DomSlug.js +564 -0
  49. package/dist/dom/DomSlug.js.map +1 -0
  50. package/dist/dom/SlugText.d.ts +18 -0
  51. package/dist/dom/SlugText.js +94 -0
  52. package/dist/dom/SlugText.js.map +1 -0
  53. package/dist/dom/Text.js +4 -67
  54. package/dist/dom/Text.js.map +1 -1
  55. package/dist/dom/domAnalytic.d.ts +54 -0
  56. package/dist/dom/domAnalytic.js +282 -0
  57. package/dist/dom/domAnalytic.js.map +1 -0
  58. package/dist/dom/domExtras.d.ts +27 -0
  59. package/dist/dom/domExtras.js +137 -0
  60. package/dist/dom/domExtras.js.map +1 -0
  61. package/dist/dom/fontCanvas.d.ts +2 -0
  62. package/dist/dom/fontCanvas.js +119 -0
  63. package/dist/dom/fontCanvas.js.map +1 -0
  64. package/dist/dom/layoutSignature.js +156 -27
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/pretextLayout.js +55 -13
  67. package/dist/dom/pretextLayout.js.map +1 -1
  68. package/dist/dom/snapshot.js +563 -243
  69. package/dist/dom/snapshot.js.map +1 -1
  70. package/dist/dom/svgCapture.d.ts +8 -1
  71. package/dist/dom/svgCapture.js +75 -1
  72. package/dist/dom/svgCapture.js.map +1 -1
  73. package/dist/dom/textHost.d.ts +11 -0
  74. package/dist/dom/textHost.js +68 -0
  75. package/dist/dom/textHost.js.map +1 -0
  76. package/dist/dom/tone.js +76 -36
  77. package/dist/dom/tone.js.map +1 -1
  78. package/dist/index.js +4 -3
  79. package/dist/slug/SlugMaterial.d.ts +13 -4
  80. package/dist/slug/SlugMaterial.js +82 -12
  81. package/dist/slug/SlugMaterial.js.map +1 -1
  82. package/dist/slug/coverage.d.ts +17 -13
  83. package/dist/slug/coverage.js +195 -222
  84. package/dist/slug/coverage.js.map +1 -1
  85. package/dist/slug/preprocessCore.d.ts +6 -3
  86. package/dist/slug/preprocessCore.js +149 -95
  87. package/dist/slug/preprocessCore.js.map +1 -1
  88. package/dist/slug/runtime.d.ts +1 -0
  89. package/dist/slug/runtime.js +94 -46
  90. package/dist/slug/runtime.js.map +1 -1
  91. package/dist/slug/standaloneRuntime.d.ts +40 -0
  92. package/dist/slug/standaloneRuntime.js +175 -0
  93. package/dist/slug/standaloneRuntime.js.map +1 -0
  94. package/dist/slug/truetype.d.ts +22 -0
  95. package/dist/slug/truetype.js +467 -0
  96. package/dist/slug/truetype.js.map +1 -0
  97. package/dist/slug/vanillaCore.d.ts +340 -0
  98. package/dist/slug/vanillaCore.js +1621 -0
  99. package/dist/slug/vanillaCore.js.map +1 -0
  100. package/dist/slug-vanilla.d.ts +13 -0
  101. package/dist/slug-vanilla.js +13 -0
  102. package/dist/slug.d.ts +21 -0
  103. package/dist/slug.js +19 -0
  104. package/dist/text/GlyphTextMaterial.d.ts +11 -11
  105. package/dist/text/GlyphTextMaterial.js +102 -33
  106. package/dist/text/GlyphTextMaterial.js.map +1 -1
  107. package/dist/text/SdfTextMaterial.d.ts +5 -4
  108. package/dist/text/SdfTextMaterial.js +29 -9
  109. package/dist/text/SdfTextMaterial.js.map +1 -1
  110. package/dist/text/decorations.js +36 -19
  111. package/dist/text/decorations.js.map +1 -1
  112. package/dist/text/geometry.d.ts +3 -22
  113. package/dist/text/geometryUtils.d.ts +11 -1
  114. package/dist/text/geometryUtils.js +22 -1
  115. package/dist/text/geometryUtils.js.map +1 -1
  116. package/dist/text/glyphGeometry.d.ts +9 -0
  117. package/dist/text/glyphGeometry.js +353 -0
  118. package/dist/text/glyphGeometry.js.map +1 -0
  119. package/dist/text/index.d.ts +2 -1
  120. package/dist/text/rectGeometry.d.ts +13 -0
  121. package/dist/text/rectGeometry.js +97 -0
  122. package/dist/text/rectGeometry.js.map +1 -0
  123. package/dist/text/reflow.d.ts +18 -1
  124. package/dist/text/reflow.js +108 -38
  125. package/dist/text/reflow.js.map +1 -1
  126. package/dist/text/snap.d.ts +1 -0
  127. package/dist/text/snap.js +26 -0
  128. package/dist/text/snap.js.map +1 -0
  129. package/dist/types.d.ts +63 -14
  130. package/dist/vanilla.d.ts +13 -360
  131. package/dist/vanilla.js +8 -1402
  132. package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
  133. package/dist/windfoil/WindfoilMaterial.js +8 -1
  134. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  135. package/dist/windfoil/abortable.d.ts +2 -0
  136. package/dist/windfoil/abortable.js +26 -0
  137. package/dist/windfoil/abortable.js.map +1 -0
  138. package/dist/windfoil/color.js +2 -1
  139. package/dist/windfoil/color.js.map +1 -1
  140. package/dist/windfoil/coverage.d.ts +3 -20
  141. package/dist/windfoil/coverage.js +7 -20
  142. package/dist/windfoil/coverage.js.map +1 -1
  143. package/dist/windfoil/emoji.js +1 -1
  144. package/dist/windfoil/emoji.js.map +1 -1
  145. package/dist/windfoil/emojiMetrics.js +1 -1
  146. package/dist/windfoil/emojiMetrics.js.map +1 -1
  147. package/dist/windfoil/geometry.d.ts +2 -2
  148. package/dist/windfoil/geometry.js +204 -64
  149. package/dist/windfoil/geometry.js.map +1 -1
  150. package/dist/windfoil/layerGrid.js +14 -10
  151. package/dist/windfoil/layerGrid.js.map +1 -1
  152. package/dist/windfoil/layerNormalization.d.ts +1 -1
  153. package/dist/windfoil/layerNormalization.js +1 -1
  154. package/dist/windfoil/layerNormalization.js.map +1 -1
  155. package/dist/windfoil/mixed.d.ts +1 -0
  156. package/dist/windfoil/mixed.js +44 -25
  157. package/dist/windfoil/mixed.js.map +1 -1
  158. package/dist/windfoil/outlineValidation.d.ts +86 -0
  159. package/dist/windfoil/outlineValidation.js +65 -0
  160. package/dist/windfoil/outlineValidation.js.map +1 -0
  161. package/dist/windfoil/preprocess.js +3 -2
  162. package/dist/windfoil/preprocess.js.map +1 -1
  163. package/dist/windfoil/preprocessCore.d.ts +5 -85
  164. package/dist/windfoil/preprocessCore.js +218 -209
  165. package/dist/windfoil/preprocessCore.js.map +1 -1
  166. package/dist/windfoil/requests.js +1 -1
  167. package/dist/windfoil/requests.js.map +1 -1
  168. package/dist/windfoil/runtime.d.ts +5 -2
  169. package/dist/windfoil/runtime.js +63 -40
  170. package/dist/windfoil/runtime.js.map +1 -1
  171. package/dist/windfoil/shapeResources.js +2 -1
  172. package/dist/windfoil/shapeResources.js.map +1 -1
  173. package/dist/windfoil/shapes.js +1 -1
  174. package/dist/windfoil/skirt.d.ts +22 -0
  175. package/dist/windfoil/skirt.js +20 -0
  176. package/dist/windfoil/skirt.js.map +1 -0
  177. package/dist/windfoil/storage.d.ts +62 -4
  178. package/dist/windfoil/storage.js +143 -28
  179. package/dist/windfoil/storage.js.map +1 -1
  180. package/dist/windfoil/trace/contours.d.ts +3 -3
  181. package/dist/windfoil/trace/contours.js +228 -137
  182. package/dist/windfoil/trace/contours.js.map +1 -1
  183. package/dist/windfoil/trace/fit.d.ts +3 -7
  184. package/dist/windfoil/trace/fit.js +668 -376
  185. package/dist/windfoil/trace/fit.js.map +1 -1
  186. package/dist/windfoil/trace/outline.js +60 -35
  187. package/dist/windfoil/trace/outline.js.map +1 -1
  188. package/dist/windfoil/trace/types.d.ts +15 -3
  189. package/dist/windfoil/tracedOutlines.d.ts +37 -1
  190. package/dist/windfoil/tracedOutlines.js +228 -64
  191. package/dist/windfoil/tracedOutlines.js.map +1 -1
  192. package/package.json +60 -11
  193. package/skills/ultra-text/SKILL.md +114 -0
  194. package/skills/ultra-text/references/frameworks.md +43 -0
  195. package/skills/ultra-text/references/three-tsl.md +78 -0
  196. package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
  197. package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
  198. package/dist/text/geometry.js +0 -348
  199. package/dist/text/geometry.js.map +0 -1
  200. package/dist/vanilla.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultra-text",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "DOM to WebGPU/TSL: real HTML, laid out by the browser, rendered as live 3D text (Three.js, R3F, TresJS, Mini3, and vanilla JS).",
5
5
  "keywords": [
6
6
  "three",
@@ -23,7 +23,9 @@
23
23
  "mini3",
24
24
  "emoji",
25
25
  "svg",
26
- "vanilla"
26
+ "vanilla",
27
+ "slug",
28
+ "agent-skills"
27
29
  ],
28
30
  "homepage": "https://ultra-text.makio.io/docs",
29
31
  "bugs": {
@@ -42,6 +44,7 @@
42
44
  "sideEffects": false,
43
45
  "files": [
44
46
  "dist",
47
+ "skills",
45
48
  "LICENSE",
46
49
  "README.md",
47
50
  "THIRD_PARTY_NOTICES.md",
@@ -60,6 +63,14 @@
60
63
  "types": "./dist/vanilla.d.ts",
61
64
  "import": "./dist/vanilla.js"
62
65
  },
66
+ "./slug": {
67
+ "types": "./dist/slug.d.ts",
68
+ "import": "./dist/slug.js"
69
+ },
70
+ "./slug-vanilla": {
71
+ "types": "./dist/slug-vanilla.d.ts",
72
+ "import": "./dist/slug-vanilla.js"
73
+ },
63
74
  "./package.json": "./package.json"
64
75
  },
65
76
  "packageManager": "pnpm@12.3.4",
@@ -123,7 +134,7 @@
123
134
  {
124
135
  "name": "public entry",
125
136
  "path": "dist/index.js",
126
- "limit": "35 kB",
137
+ "limit": "46 kB",
127
138
  "ignore": [
128
139
  "three",
129
140
  "@chenglou/pretext",
@@ -152,7 +163,7 @@
152
163
  {
153
164
  "name": "vanilla entry (Three-free)",
154
165
  "path": "dist/vanilla.js",
155
- "limit": "28.5 kB",
166
+ "limit": "37 kB",
156
167
  "ignore": [
157
168
  "@chenglou/pretext",
158
169
  "./dist/dom/browserShaping.js",
@@ -164,10 +175,48 @@
164
175
  "./dist/windfoil/svg/pathConverter.js"
165
176
  ]
166
177
  },
178
+ {
179
+ "name": "slug entry (Three.js)",
180
+ "path": "dist/slug.js",
181
+ "limit": "52.5 kB",
182
+ "ignore": [
183
+ "three",
184
+ "@chenglou/pretext",
185
+ "./dist/dom/browserShaping.js",
186
+ "./dist/dom/pretextLayout.js",
187
+ "./dist/dom/svgCapture.js",
188
+ "./dist/atlas/colorGlyphs.js",
189
+ "./dist/windfoil/requests.js",
190
+ "./dist/windfoil/layerNormalization.js",
191
+ "./dist/windfoil/color.js",
192
+ "./dist/windfoil/svg/convert.js",
193
+ "./dist/windfoil/svg/pathConverter.js",
194
+ "./dist/windfoil/emoji.js",
195
+ "./dist/windfoil/emojiMetrics.js"
196
+ ]
197
+ },
198
+ {
199
+ "name": "slug-vanilla entry (Three-free)",
200
+ "path": "dist/slug-vanilla.js",
201
+ "limit": "45 kB",
202
+ "ignore": [
203
+ "@chenglou/pretext",
204
+ "./dist/dom/browserShaping.js",
205
+ "./dist/dom/pretextLayout.js",
206
+ "./dist/dom/svgCapture.js",
207
+ "./dist/atlas/colorGlyphs.js",
208
+ "./dist/windfoil/requests.js",
209
+ "./dist/windfoil/layerNormalization.js",
210
+ "./dist/windfoil/svg/convert.js",
211
+ "./dist/windfoil/svg/pathConverter.js",
212
+ "./dist/windfoil/emoji.js",
213
+ "./dist/windfoil/emojiMetrics.js"
214
+ ]
215
+ },
167
216
  {
168
217
  "name": "optional Pretext layout",
169
218
  "path": "dist/dom/pretextLayout.js",
170
- "limit": "2.7 kB",
219
+ "limit": "4 kB",
171
220
  "ignore": [
172
221
  "@chenglou/pretext",
173
222
  "./dist/dom/clusters.js",
@@ -182,7 +231,7 @@
182
231
  {
183
232
  "name": "optional Windfoil backend",
184
233
  "path": "dist/windfoil/runtime.js",
185
- "limit": "16 kB",
234
+ "limit": "19 kB",
186
235
  "ignore": [
187
236
  "three",
188
237
  "@chenglou/pretext",
@@ -197,7 +246,7 @@
197
246
  {
198
247
  "name": "optional Slug backend",
199
248
  "path": "dist/slug/runtime.js",
200
- "limit": "16 kB",
249
+ "limit": "19.5 kB",
201
250
  "ignore": [
202
251
  "three",
203
252
  "@chenglou/pretext",
@@ -212,7 +261,7 @@
212
261
  {
213
262
  "name": "optional CPU fallback",
214
263
  "path": "dist/atlas/cpuAtlas.js",
215
- "limit": "3 kB",
264
+ "limit": "4.5 kB",
216
265
  "ignore": [
217
266
  "three"
218
267
  ]
@@ -233,7 +282,7 @@
233
282
  {
234
283
  "name": "optional Windfoil shapes",
235
284
  "path": "dist/windfoil/shapes.js",
236
- "limit": "17.5 kB",
285
+ "limit": "18.5 kB",
237
286
  "ignore": [
238
287
  "three",
239
288
  "@chenglou/pretext",
@@ -354,7 +403,7 @@
354
403
  {
355
404
  "name": "optional atlas append",
356
405
  "path": "dist/atlas/appendAtlas.js",
357
- "limit": "4 kB",
406
+ "limit": "5.5 kB",
358
407
  "ignore": [
359
408
  "three",
360
409
  "./dist/atlas/rasterize.js",
@@ -366,7 +415,7 @@
366
415
  {
367
416
  "name": "optional traced outlines",
368
417
  "path": "dist/windfoil/tracedOutlines.js",
369
- "limit": "7 kB",
418
+ "limit": "12 kB",
370
419
  "ignore": [
371
420
  "three",
372
421
  "./dist/atlas/rasterize.js",
@@ -0,0 +1,114 @@
1
+ ---
2
+ name: ultra-text
3
+ description: >-
4
+ Guides coding agents integrating ultra-text for runtime DOM-to-WebGPU 3D text in Three.js
5
+ WebGPURenderer, TSL shaders, React Three Fiber (R3F), TresJS (Vue), Mini3, and vanilla WebGPU
6
+ engines. Use when installing, configuring, styling, reflowing, animating, or debugging
7
+ ultra-text, ultra-text/slug, ultra-text/vanilla, or ultra-text/slug-vanilla.
8
+ ---
9
+
10
+ <!-- SPDX-License-Identifier: MIT -->
11
+
12
+ # ultra-text
13
+
14
+ `ultra-text` captures real HTML/CSS laid out by the browser and renders it as retained WebGPU instanced geometry—either from a compact single-channel SDF atlas or analytic Slug/Windfoil quadratic outlines—with zero DOM reads in the render loop.
15
+
16
+ ## Choose the right entry point
17
+
18
+ Never import internal module paths or `THREE.WebGLRenderer` (unsupported). Do not invent framework subpaths like `ultra-text/r3f`, `ultra-text/tres`, or `ultra-text/mini3`.
19
+
20
+ | Entry point | Stack | Renderer / device | Coverage backend |
21
+ | ------------------------- | --------------------------- | --------------------------------- | -------------------------------------------------------------- |
22
+ | `ultra-text` | Three.js / R3F / TresJS | `WebGPURenderer` (`three/webgpu`) | SDF (GPU JFA / CPU EDT), plus optional `windfoil` or `slug` |
23
+ | `ultra-text/slug` | Three.js Slug-only apps | `WebGPURenderer` (`three/webgpu`) | Pure analytic Slug (zero SDF code, `DomSlug` / `SlugText`) |
24
+ | `ultra-text/vanilla` | Mini3 & custom engines | `GPUDevice` (Three.js-free) | SDF atlas + packed typed-array instance buffers |
25
+ | `ultra-text/slug-vanilla` | Mini3 & custom Slug engines | `GPUDevice` (Three.js-free) | Pure analytic Slug + `SLUG_WGSL` / `createVanillaSlugPipeline` |
26
+
27
+ - Install Three.js within `ultra-text`'s peer range (`three` `>=0.187.0 <0.188.0`) and keep a single Three.js instance across the app.
28
+ - For Three-free engines, `three` is an optional peer dependency and does not need to be installed.
29
+
30
+ ## Non-negotiable DOM & lifecycle invariants
31
+
32
+ 1. **Await renderer init and fonts before capture**: run `await renderer.init()` and `await document.fonts.ready` so CSS faces and line metrics settle before reading the DOM.
33
+ 2. **Keep the source connected, accessible, and measurable**: pass a real element with a non-zero layout box. Never use `display: none` or the `hidden` attribute on the captured source; keep semantic HTML in the accessibility tree and mark the WebGPU `<canvas aria-hidden="true">`.
34
+ 3. **Mark only what crosses into 3D**:
35
+ - `data-text-block` — capture text and inline descendants (legacy `data-sdf-block` also works)
36
+ - `data-text-rect` — capture solid background, opacity, box, and uniform border radius (`data-sdf-rect`)
37
+ - `data-text-ignore` — exclude a subtree (`data-sdf-ignore`)
38
+ - `data-text-depth="n"` — inherited Z depth (`data-sdf-depth`)
39
+ - `data-text-receive-shadow` — put the rectangle in the shadow-receiving batch (`data-sdf-receive-shadow`)
40
+ 4. **Never capture or rebuild inside the frame loop**: `DomText` observes DOM text, style, and resize changes by default (`observe: true`). Call `await copy.rebuild()` only after external stylesheet changes, or pass `{ reflowable: true }` and call `copy.reflow(widthPx)` for fast width-only re-wrapping without DOM reads.
41
+ 5. **Respect `DomText.create` argument order**:
42
+ - Three.js entries (`ultra-text`, `ultra-text/slug`): `DomText.create(renderer, source, options)`
43
+ - Vanilla entries (`ultra-text/vanilla`, `ultra-text/slug-vanilla`): `DomText.create(source, gpuDevice, options)`
44
+ 6. **Handle origin, scale, cancellation, and disposal**:
45
+ - Local `(0, 0)` is the bottom-left corner; center with `copy.position.set(-copy.width / 2, -copy.height / 2, 0)`.
46
+ - `pixelsPerUnit` divides X/Y positions, **not** Z depths or motion strength (`18 / pixelsPerUnit`, `panelDepth: -1 / pixelsPerUnit`).
47
+ - Pass an `AbortSignal` in async components; dispose late results if aborted after `await`, and call idempotent `copy.dispose()` on unmount (never dispose shared caller renderers, scenes, or `sharedAtlas`).
48
+ - In SSR frameworks (Next.js, Nuxt, Astro), guard browser capture and mount the WebGPU canvas on the client only.
49
+
50
+ ## Minimal Three.js WebGPU quickstart
51
+
52
+ ### Capture existing DOM (`DomText.create`)
53
+
54
+ ```ts
55
+ import { PerspectiveCamera, Scene, WebGPURenderer } from 'three/webgpu'
56
+ import { DomText } from 'ultra-text'
57
+
58
+ const renderer = new WebGPURenderer({ antialias: true })
59
+ renderer.setPixelRatio(devicePixelRatio)
60
+ renderer.setSize(innerWidth, innerHeight)
61
+ renderer.domElement.setAttribute('aria-hidden', 'true')
62
+ document.body.append(renderer.domElement)
63
+ await renderer.init()
64
+
65
+ const scene = new Scene()
66
+ const camera = new PerspectiveCamera(40, innerWidth / innerHeight, 0.1, 5000)
67
+ camera.position.z = 900
68
+
69
+ await document.fonts.ready
70
+ const source = document.querySelector<HTMLElement>('#profile')
71
+ if (!source) throw new Error('Missing #profile')
72
+
73
+ const copy = await DomText.create(renderer, source, { quality: 'high' })
74
+ copy.position.set(-copy.width / 2, -copy.height / 2, 0)
75
+ scene.add(copy)
76
+
77
+ renderer.setAnimationLoop(() => renderer.render(scene, camera))
78
+ // Cleanup: scene.remove(copy); copy.dispose()
79
+ ```
80
+
81
+ ### Direct string text (`Text`)
82
+
83
+ Use `Text` (in `ultra-text`) when there is no existing HTML block to mirror:
84
+
85
+ ```ts
86
+ import { Text } from 'ultra-text'
87
+
88
+ const label = new Text('Hello, WebGPU!', {
89
+ renderer,
90
+ css: { fontFamily: 'sans-serif', fontSize: 48, color: '#ffcc00', width: 320 },
91
+ cssClass: 'headline',
92
+ })
93
+ await label.ready
94
+ scene.add(label)
95
+
96
+ label.text = 'Updated text'
97
+ await label.rebuild()
98
+ ```
99
+
100
+ Note: `ultra-text` exports `new Text(message, options)` (`await label.ready`); `ultra-text/slug` (`SlugText`), `ultra-text/vanilla`, and `ultra-text/slug-vanilla` support both `new Text(...)` and `Text.create(...)`.
101
+
102
+ ## Read deeper references by task
103
+
104
+ Load only the reference matching the user's stack:
105
+
106
+ - Three.js options, SDF vs Slug vs Windfoil, TSL `fill`/`vertex` hooks, `motion`, `outline`, `dropShadow`, SVG/emoji, and shared-atlas stages: [Three.js & TSL reference](./references/three-tsl.md)
107
+ - React Three Fiber (v9 & v10 alpha), TresJS (Vue), and Mini3 copy-once starter components and lifecycle rules: [Framework integration reference](./references/frameworks.md)
108
+ - Zero-Three.js typed-array packers, GPU/CPU SDF builders, and raw WebGPU `SLUG_WGSL` pipelines: [Vanilla WebGPU & Mini3 reference](./references/vanilla-webgpu.md)
109
+
110
+ ## Verification checklist & licensing
111
+
112
+ - Confirm `tsc --noEmit` (or `vue-tsc`) passes with matching Three.js types.
113
+ - In a WebGPU-capable browser, verify initial render, normal DOM text edit, source swap, mobile viewport layout, and unmount cleanup (including React Strict Mode double-mount).
114
+ - `ultra-text`, its docs, and the starter components under `/integrations/` are **MIT licensed**. The showcase scenes on `ultra-text.makio.io` (`/`, `/demo`, `/konami`, `/text-effects`) are **all rights reserved**—never clone or port them; build original scenes with the library.
@@ -0,0 +1,43 @@
1
+ <!-- SPDX-License-Identifier: MIT -->
2
+
3
+ # Framework Integration Reference (R3F, TresJS, Mini3)
4
+
5
+ Starter components are **copy-once consumer source files** licensed under **MIT**—not npm subpaths (`ultra-text/r3f`, `ultra-text/tres`, or `ultra-text/mini3` do not exist). Always import runtime code from `ultra-text`, `ultra-text/slug`, `ultra-text/vanilla`, or `ultra-text/slug-vanilla`.
6
+
7
+ ## Starter files (download or copy from the docs site)
8
+
9
+ | Framework | Starter file(s) | Library entry | Notes |
10
+ | ----------------------------- | ------------------------------------------------------------------------------------- | -------------------- | ---------------------------------------------------------------------------------- |
11
+ | React Three Fiber v9 (stable) | `https://ultra-text.makio.io/integrations/r3f/UltraText.tsx` | `ultra-text` | Uses `gl={async ({ canvas }) => ...}` and `useThree((s) => s.gl)`. |
12
+ | React Three Fiber v10 (alpha) | `https://ultra-text.makio.io/integrations/r3f/v10/UltraText.tsx` | `ultra-text` | Uses `renderer={async ({ canvas }) => ...}` and `useThree((s) => s.renderer)`. |
13
+ | TresJS / Vue 3 | `https://ultra-text.makio.io/integrations/tres/UltraText.vue` & `UltraTextCanvas.vue` | `ultra-text` | Add `vue({ ...templateCompilerOptions })` from `@tresjs/core` in `vite.config.ts`. |
14
+ | Mini3 | `https://ultra-text.makio.io/integrations/mini3/UltraText.ts` | `ultra-text/vanilla` | Zero Three.js dependency; adopts the WebGPU `GPUTexture` into a Mini3 `Texture`. |
15
+
16
+ Canonical integration guide for coding agents: `https://ultra-text.makio.io/integrations/AGENTS.md`
17
+
18
+ ## Lifecycle & correctness rules for frameworks
19
+
20
+ 1. **Keep source HTML outside the canvas**: render normal semantic HTML (`<article ref={setSource}>`) in the DOM, mark blocks with `data-text-block` (or `data-sdf-block`), and never apply `hidden` or `display: none`.
21
+ 2. **Await initialization + fonts inside the async effect**:
22
+ - Wait for `await renderer.init()` (or `Promise.all([gpuRenderer.init(), document.fonts.ready])` in TresJS) before calling `DomText.create`.
23
+ - Always pass `{ signal: controller.signal }`, check `if (controller.signal.aborted)` before and after every `await`, and call `next.dispose()` immediately if aborted before state assignment (critical for React Strict Mode double-mounting and fast prop swaps).
24
+ 3. **Clean up on unmount or source change**:
25
+ - Abort the in-flight `AbortController`.
26
+ - Detach (`owned?.removeFromParent()`) and dispose (`owned?.dispose()`) the `DomText` instance.
27
+ - Keep `renderer.dispose()` owned by the canvas wrapper—never dispose the shared renderer from a text component.
28
+ 4. **Keep `options` reference-stable**: declare `const textOptions = { quality: 'high' } as const` outside the component or wrap in `useMemo`, because a new `options` object identity triggers a full teardown and rebuild.
29
+ 5. **Account for `pixelsPerUnit: 100` in 3D scenes**: the framework starters default to `100` CSS pixels per world unit so a 600 px card is `6` units wide. Scale Z depths and motion strength accordingly:
30
+ ```ts
31
+ const pixelsPerUnit = options?.pixelsPerUnit ?? 100
32
+ // e.g. panelDepth: -1 / pixelsPerUnit, motion: { enabled: false, strength: 18 / pixelsPerUnit }
33
+ ```
34
+ 6. **Continuous vs on-demand render loop**: keep `frameloop="always"` (R3F) or `render-mode="always"` (TresJS) when observing live DOM changes or TSL `motion`. If using an on-demand loop, invalidate the frame when mutations or `rebuild()` complete.
35
+ 7. **SSR frameworks (Next.js, Nuxt, SvelteKit, Astro)**: DOM measurement and WebGPU require a browser. Guard capture and mount `<UltraTextCanvas>` only on the client.
36
+
37
+ ## Verified baselines
38
+
39
+ - **Three.js**: `>=0.187.0 <0.188.0` (matches `package.json` peer dependency; use one Three.js copy).
40
+ - **R3F v9**: `@react-three/fiber` 9.8.2 + React 19.3.1.
41
+ - **R3F v10 alpha**: `@react-three/fiber` 10.0.0-alpha.6 + React 19.3.1 (prerelease APIs subject to change).
42
+ - **TresJS**: `@tresjs/core` 5.10.0 + Vue 3.5.44.
43
+ - **Mini3**: `0.1.0-alpha.0` with `ultra-text/vanilla`.
@@ -0,0 +1,78 @@
1
+ <!-- SPDX-License-Identifier: MIT -->
2
+
3
+ # Three.js & TSL Reference (`ultra-text` and `ultra-text/slug`)
4
+
5
+ Target runtime: ESM with `three` (`>=0.187.0 <0.188.0`), `WebGPURenderer` from `three/webgpu`, and nodes from `three/tsl`.
6
+
7
+ ## Core options (`DomTextOptions` / `DomSdfOptions`)
8
+
9
+ | Option | Default | Notes |
10
+ | ---------------------- | ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11
+ | `textBackend` | `'sdf'` | `'sdf'` (atlas), `'slug'` (dual-ray curves), or `'windfoil'` (row-band curves). |
12
+ | `atlasMode` | `'auto'` | SDF only: `'auto'` (GPU JFA with CPU fallback), `'gpu'`, or `'cpu'`. |
13
+ | `quality` | `'standard'` | SDF only: `'standard'` (1 tap, smallest) or `'high'` (4-tap sampling + mipmaps + up to 4× anisotropy). |
14
+ | `bakeSize / padding` | `96 / 12` | SDF texel size and field range (`maxAtlasSize` defaults to `2048`; enable `adaptiveBakeSize` near overflow). |
15
+ | `layoutEngine` | `'range'` | Browser `Range` fidelity, or lazy `'pretext'` Canvas layout. |
16
+ | `tone` | on | Matches browser ink weight; pass `{ backdrop: '#0b0b0d' }` when light text sits over a dark 3D scene, or `false` for exact coverage. |
17
+ | `extraGlyphs` | `—` | Pre-bake dynamic digits/symbols/emoji sequences so live edits repack instances without rebuilding the atlas. |
18
+ | `outline / dropShadow` | `—` | Local-unit outline (`width`, `color`, `opacity`) and hard shadow (`offsetX`, `offsetY`, `color`, `opacity`). Supported on all backends (uses an SDF underlay under Windfoil/Slug). |
19
+ | `motion` | `'slide-up'` | `{ enabled, mode, strength, speed, stagger }`. `mode: 'none'` omits the motion shader graph until upgraded via `setMotion()`. |
20
+ | `fill / vertex` | `—` | Build-time TSL callbacks (`TextFill`, `TextVertex`) evaluated only while constructing materials. |
21
+ | `observe / reflowable` | `true / false` | Automatic DOM/Resize observation; `reflowable: true` retains metrics for width-only `reflow(width)` without reading the DOM. |
22
+ | `pixelsPerUnit` | `1` | Scales captured X/Y coordinates (`textDepth: 1`, `rectDepth: 0`, `panelDepth: -1` are unscaled). |
23
+ | `pixelSnap` | `false` | Snaps lines/glyph origins to browser pixel grids for crisp flat 1:1 overlays. |
24
+ | `castShadow / side` | `true / FrontSide` | Set `castShadow: false` to skip shadow-map draws; `DoubleSide` for two-sided text. |
25
+ | `signal / onError` | `—` | Abort builds cleanly; handle errors from observer-triggered async rebuilds. |
26
+
27
+ ## TSL custom `fill` and `vertex` hooks
28
+
29
+ ```ts
30
+ import { mix, sin, time, vec3, vec4 } from 'three/tsl'
31
+ import { DomText } from 'ultra-text'
32
+
33
+ const copy = await DomText.create(renderer, source, {
34
+ padding: 24,
35
+ outline: { width: 1.2, color: '#cafae2', opacity: 0.8 },
36
+ dropShadow: { offsetX: 5, offsetY: -6, color: '#030c09', opacity: 1 },
37
+ fill: ({ position }) => {
38
+ const wave = sin(position.x.mul(0.02).add(time)).mul(0.5).add(0.5)
39
+ return vec4(mix(vec3(0.1, 0.8, 0.5), vec3(1, 0.25, 0.08), wave), 1)
40
+ },
41
+ vertex: ({ position, center, sequence }) => {
42
+ const bob = sin(time.mul(2).add(sequence.mul(0.35))).mul(2)
43
+ return position.add(vec3(0, bob, sin(center.x.mul(0.015).add(time)).mul(4)))
44
+ },
45
+ })
46
+ ```
47
+
48
+ - `fill` receives `{ uv, position, color, colorWeight, glyphIndex }` and returns linear RGBA `Node<'vec4'>`; coverage, `tone`, DOM opacity, and scene shadows still apply.
49
+ - `vertex` receives `{ position, center, uv, glyphIndex, sequence, rect, clip }` after built-in motion and returns displaced local `Node<'vec3'>` (runs on both beauty and shadow passes; block `clip` is computed beforehand so Z waves do not clip).
50
+
51
+ ## Analytic Slug & Windfoil outlines
52
+
53
+ - **Pure Slug bundle (`ultra-text/slug`)**: exports `DomSlug` (aliased `DomText`), `SlugText` (aliased `Text`), `SlugMaterial`, `createTrueTypeOutlineProvider`, `parseTrueTypeFont`, `createTracedOutlineProvider`, `createSvgEmojiOutlineProvider`, and omits all SDF rasterizer/JFA/worker code.
54
+ - **No `.ttf` file needed by default**: if `outlineProvider` is omitted, `DomSlug` / `textBackend: 'slug'` / `'windfoil'` traces the browser's rendered glyphs on Canvas 2D (`traceSize: 256`, `traceTolerance: 0.25`). Colour glyphs use an SDF companion on `ultra-text` (`fallback: 'sdf-glyphs'`) or `missingGlyphs: 'skip' | 'error'` on `ultra-text/slug`.
55
+ - **Exact TTF curves**: when bundling an uncompressed `.ttf` font, parse it once and reuse the provider:
56
+
57
+ ```ts
58
+ import { DomSlug, createTrueTypeOutlineProvider } from 'ultra-text/slug'
59
+
60
+ const ttfBytes = await fetch('/fonts/inter.ttf').then((r) => r.arrayBuffer())
61
+ const outlineProvider = createTrueTypeOutlineProvider(ttfBytes)
62
+ const copy = await DomSlug.create(renderer, source, { outlineProvider })
63
+ ```
64
+
65
+ - Note on Windfoil: `textBackend: 'windfoil'` adapts upstream Windfoil (Apache-2.0); upstream notes patent considerations to evaluate for commercial use.
66
+
67
+ ## SVG capture, standalone shapes, and vector emoji
68
+
69
+ - `svg: true` (or `{ render: 'bitmap', images: true, unsupported: 'error', maxPathData }`) captures inline `<svg>` elements using Range layout; shapes count in `stats.shapes`.
70
+ - For scene-authored shapes, import `svgToWindfoilOutlines`, `windfoilOutlineFromSvgPaths`, and `createWindfoilShapes` from `ultra-text`.
71
+ - For vector emoji on analytic backends, wrap your font provider with `createSvgEmojiOutlineProvider({ text, resolve, em })` and supply app-owned SVG artwork.
72
+
73
+ ## Runtime updates & shared atlases
74
+
75
+ - Motion uniforms update without rebuilding shaders or DOM: `copy.setMotion({ mode: 'offset', speed: 0.8 })`.
76
+ - Width-only re-wrap: create with `{ reflowable: true }`, then call `copy.reflow(widthPx)` (`0.041 ms` standalone CPU median in `benchmarks/reflow.js`, `1.46 ms` end-to-end with GPU completion on 1,000 glyphs vs full DOM `rebuild()`).
77
+ - Force rebuild: `await copy.rebuild()` (re-reads DOM, reuses retained atlas if glyph signature matches) or `await copy.rebuild({ atlas: true })`. Both SDF (`DomSdf`/`DomText`) and analytic (`DomSlug`, `DomSdf` with `textBackend: 'slug' | 'windfoil'`) allocate tight storage on `create()` and switch to headroom on the first unseen glyph so subsequent unseen glyphs append in place without recreating materials or pipelines.
78
+ - Lower-level SDF stages (`collectDomSnapshot`, `rasterizeGlyphAtlas`, `buildSdfAtlas`, `createGlyphGeometry`, `SdfTextMaterial`, `createRectGeometry`, `createRectMaterial`, `reflowSnapshot`) let multiple meshes share one `SdfAtlas`; pass `sharedAtlas` (matching `quality` and `colorGlyphs` mode) and dispose `sharedAtlas` only after every consumer has been disposed.
@@ -0,0 +1,96 @@
1
+ <!-- SPDX-License-Identifier: MIT -->
2
+
3
+ # Vanilla WebGPU & Mini3 Reference (`ultra-text/vanilla` and `ultra-text/slug-vanilla`)
4
+
5
+ Both vanilla entry points run DOM capture, Pretext/Range layout, `reflow()`, observers, and GPU preprocessing with **zero Three.js dependency** and **zero `@webgpu/types` dependency** (structural `GPUDevice` / `GPUTexture` / `GPUBuffer` interfaces).
6
+
7
+ ## SDF controller (`ultra-text/vanilla`)
8
+
9
+ Note the argument order: `DomText.create(element, gpuDevice, options)` takes the HTML element **first** and the `GPUDevice` (or `{ device }` object) **second**.
10
+
11
+ ```ts
12
+ import { DomText } from 'ultra-text/vanilla'
13
+
14
+ await document.fonts.ready
15
+ const source = document.querySelector<HTMLElement>('#card')!
16
+
17
+ const domText = await DomText.create(source, gpuDevice, {
18
+ quality: 'high',
19
+ reflowable: true,
20
+ onChange(instance, reason) {
21
+ // reason: 'create' | 'rebuild' | 'reflow' | 'motion' | 'dispose'
22
+ // instance.glyphs -> VanillaGlyphInstances (positions, uvs, colors, sdfParams, ...)
23
+ // instance.plainRects -> VanillaRectInstances | null
24
+ // instance.litRects -> VanillaRectInstances | null
25
+ // instance.decorations -> VanillaDecorationInstances | null
26
+ // instance.atlas -> VanillaSdfAtlas (gpuTexture on GPU, data Uint8Array on CPU)
27
+ },
28
+ })
29
+
30
+ // Fast width-only relayout: fires onChange(instance, 'reflow')
31
+ domText.reflow(560)
32
+ // Cleanup:
33
+ domText.dispose()
34
+ ```
35
+
36
+ - **String helper**: `Text` (`VanillaText`) supports `await Text.create('Hello', { device: gpuDevice, css, cssClass, onChange })` as well as `setText()`, `setCss()`, and `setClass()`.
37
+ - **Lazy mipmaps**: `MIP_WGSL` (`r8unorm` / `rgba8unorm-srgb`) mip render pipelines compile lazily (`getDeviceMipPipeline`), decoupling CPU-atlas GPU mipmaps from JFA compute compilation.
38
+ - **Lower-level exports**: `collectDomSnapshot`, `reflowSnapshot`, `buildVanillaSdfAtlas` (`buildSdfAtlas`), `buildVanillaGpuSdfAtlas`, `buildVanillaCpuSdfAtlas`, `rasterizeGlyphAtlas`, `packGlyphInstances`, `updateGlyphInstances`, `updateGlyphContentInstances`, `packRectInstances`, `updateRectInstances`, `packDecorationInstances`, `updateDecorationInstances`, `computeInstanceBounds`, `resolveDomTextTone`, `UNIT_QUAD_POSITIONS`, `UNIT_QUAD_NORMALS`, `UNIT_QUAD_INDICES`.
39
+
40
+ ## Pure Slug WebGPU pipeline (`ultra-text/slug-vanilla`)
41
+
42
+ `ultra-text/slug-vanilla` omits all SDF/JFA/CPU-EDT code and ships `SLUG_WGSL`, `createVanillaSlugPipeline`, and `uploadSlugGlyphBuffers` for immediate rendering in any raw `GPURenderPassEncoder`:
43
+
44
+ ```ts
45
+ import {
46
+ createVanillaSlugPipeline,
47
+ DomSlug,
48
+ uploadSlugGlyphBuffers,
49
+ type VanillaSlugGpuInstances,
50
+ } from 'ultra-text/slug-vanilla'
51
+
52
+ await document.fonts.ready
53
+
54
+ const pipeline = createVanillaSlugPipeline(gpuDevice, {
55
+ format: navigator.gpu.getPreferredCanvasFormat(),
56
+ depthFormat: 'depth24plus', // optional
57
+ })
58
+
59
+ let gpuInstances: VanillaSlugGpuInstances | null = null
60
+ let bindGroup: unknown = null
61
+
62
+ const domSlug = await DomSlug.create(source, gpuDevice, {
63
+ // Optional: outlineProvider: createTrueTypeOutlineProvider(ttfBuffer)
64
+ onChange(instance, reason) {
65
+ if (reason === 'dispose') {
66
+ gpuInstances?.dispose()
67
+ gpuInstances = null
68
+ bindGroup = null
69
+ return
70
+ }
71
+ bindGroup = pipeline.createBindGroup(instance.atlas)
72
+ if (!gpuInstances) {
73
+ gpuInstances = uploadSlugGlyphBuffers(gpuDevice, instance.glyphs)
74
+ } else {
75
+ gpuInstances.update(instance.glyphs)
76
+ }
77
+ },
78
+ })
79
+
80
+ // Inside render pass:
81
+ pipeline.writeUniforms({
82
+ mvp, // column-major 4x4 Float32Array
83
+ viewportWidth: canvas.width,
84
+ viewportHeight: canvas.height,
85
+ })
86
+ if (bindGroup && gpuInstances) {
87
+ pipeline.draw(pass, bindGroup, gpuInstances) // calls pass.draw(6, gpuInstances.count)
88
+ }
89
+
90
+ // Cleanup:
91
+ domSlug.dispose()
92
+ pipeline.dispose()
93
+ ```
94
+
95
+ - **Incremental rebuilds & buffer caution**: `DomSlug` (`VanillaDomSlug`) allocates tight curve/row `GPUBuffer`s on `create()` and switches to headroom on the first unseen glyph so subsequent unseen glyphs append via `device.queue.writeBuffer` without recreating storage buffers; `gpuInstances.update(next)` calls `writeBuffer` into the existing vertex buffers, so if a rebuild increases glyph capacity beyond initial sizes, recreate `gpuInstances = uploadSlugGlyphBuffers(gpuDevice, next)` after disposing the old one.
96
+ - **Standalone lower-level Slug exports**: `buildVanillaSlugAtlas` (`buildSlugAtlas`, which resolves missing `outlineProvider` requests concurrently via `Promise.all`), `packSlugGlyphInstances`, `updateSlugGlyphInstances`, `preprocessSlugGlyphs`, `createTrueTypeOutlineProvider`, `parseTrueTypeFont`, `createTracedOutlineProvider`, `createSvgEmojiOutlineProvider`, `svgToWindfoilOutlines`, `windfoilOutlineFromSvgPaths`, `SLUG_WGSL`.
@@ -1 +0,0 @@
1
- {"version":3,"file":"cpuSdf.worker-Du9o8q4p.js","names":[],"sources":["../../src/atlas/cpuSdf.ts","../../src/atlas/cpuSdf.worker.ts"],"sourcesContent":["/**\n * A finite stand-in for infinity in the squared-distance grids.\n *\n * Keeping the sentinel finite avoids `Infinity - Infinity` while constructing\n * the lower envelope of parabolas. Its square root is far beyond any practical\n * atlas extent, so missing inside/outside pixels still saturate at the correct\n * encoded endpoint.\n */\nconst FAR_DISTANCE_SQUARED = 1e20\n\ntype AlphaPixels = Uint8Array | Uint8ClampedArray\n\n/** The alpha byte of each RGBA pixel, as the encoder reads coverage. */\nexport function alphaOfRgba(rgba: Uint8ClampedArray, pixelCount: number): Uint8Array {\n const alpha = new Uint8Array(pixelCount)\n for (let source = 3, target = 0; target < pixelCount; source += 4, target++) {\n alpha[target] = rgba[source]!\n }\n return alpha\n}\n\nfunction assertInputs(alpha: AlphaPixels, width: number, height: number, pxRange: number): number {\n if (!(alpha instanceof Uint8Array) && !(alpha instanceof Uint8ClampedArray)) {\n throw new TypeError('encodeSdfFromAlpha: alpha must be a Uint8Array or Uint8ClampedArray')\n }\n if (!Number.isInteger(width) || width <= 0) {\n throw new RangeError('encodeSdfFromAlpha: width must be a positive integer')\n }\n if (!Number.isInteger(height) || height <= 0) {\n throw new RangeError('encodeSdfFromAlpha: height must be a positive integer')\n }\n\n const pixelCount = width * height\n if (!Number.isSafeInteger(pixelCount)) {\n throw new RangeError('encodeSdfFromAlpha: width * height exceeds the safe integer range')\n }\n if (alpha.length !== pixelCount) {\n throw new RangeError(\n `encodeSdfFromAlpha: alpha length ${alpha.length} does not match width * height (${pixelCount})`,\n )\n }\n if (!Number.isFinite(pxRange) || pxRange <= 0) {\n throw new RangeError('encodeSdfFromAlpha: pxRange must be a positive finite number')\n }\n\n return pixelCount\n}\n\nlet edtMinOut = 0\nlet edtMaxOut = -1\n\n/**\n * Exact one-dimensional squared Euclidean distance transform.\n *\n * This is the lower-envelope algorithm from Felzenszwalb and Huttenlocher. It\n * runs in O(length), performs no allocations, and accepts non-zero seed costs\n * so fractional alpha coverage can place the glyph edge between pixel centres.\n * The envelope retains the original costs before writing back into the grid,\n * avoiding a copy of each column in both directions.\n */\nfunction edt1d(\n grid: Float32Array,\n startSeed: number,\n endSeed: number,\n outStart: number,\n outEnd: number,\n clampSqDist: number,\n maxRadius: number,\n): void {\n let first = startSeed\n while (first <= endSeed && grid[first]! >= clampSqDist) first++\n if (first > endSeed) {\n edtMinOut = outEnd + 1\n edtMaxOut = outStart - 1\n return\n }\n\n const firstCost = grid[first]!\n if (first === outStart) {\n let different = first + 1\n if (firstCost <= 1) {\n while (different <= endSeed && grid[different]! <= 1) different++\n } else {\n while (different <= endSeed && grid[different] === firstCost) different++\n }\n // A constant line or a line of immediate seeds (cost <= 1) is already its own distance transform.\n if (different > endSeed && endSeed >= outEnd) {\n edtMinOut = outStart\n edtMaxOut = outEnd\n return\n }\n }\n\n const parabolaIndices = scratchParabolaIndices\n const parabolaCosts = scratchParabolaCosts\n const parabolaOffsets = scratchParabolaOffsets\n const boundaries = scratchBoundaries\n let envelopeEnd = 0\n parabolaIndices[0] = first\n parabolaCosts[0] = firstCost\n parabolaOffsets[0] = firstCost + first * first\n\n for (let q = first + 1; q <= endSeed; q++) {\n let cost = grid[q]!\n if (cost >= clampSqDist) {\n while (q < endSeed && grid[q + 1]! >= clampSqDist) q++\n continue\n }\n if (cost <= 1 && grid[q - 1]! <= 1) {\n while (q < endSeed && grid[q + 1]! <= 1) q++\n cost = grid[q]!\n } else if (cost === grid[q - 1]!) {\n while (q < endSeed && grid[q + 1] === cost) q++\n }\n const costPlusQSquared = cost + q * q\n while (\n envelopeEnd > 0 &&\n (costPlusQSquared - parabolaOffsets[envelopeEnd]!) * 0.5 <=\n boundaries[envelopeEnd]! * (q - parabolaIndices[envelopeEnd]!)\n ) {\n envelopeEnd--\n }\n const intersection =\n ((costPlusQSquared - parabolaOffsets[envelopeEnd]!) * 0.5) /\n (q - parabolaIndices[envelopeEnd]!)\n\n envelopeEnd++\n parabolaIndices[envelopeEnd] = q\n parabolaCosts[envelopeEnd] = cost\n parabolaOffsets[envelopeEnd] = costPlusQSquared\n boundaries[envelopeEnd] = intersection\n }\n\n const minOut = first - maxRadius > outStart ? first - maxRadius : outStart\n const lastSeed = parabolaIndices[envelopeEnd]!\n const maxOut = lastSeed + maxRadius < outEnd ? lastSeed + maxRadius : outEnd\n let b0 = minOut\n for (let e = 0; e <= envelopeEnd; e++) {\n const b1 = e === envelopeEnd ? maxOut : Math.floor(boundaries[e + 1]!)\n if (b1 >= b0) {\n const nearest = parabolaIndices[e]!\n const cost = parabolaCosts[e]!\n const r0 = nearest - maxRadius\n const r1 = nearest + maxRadius\n const s1 = maxOut < b1 ? maxOut : b1\n const segStart = b0 > r0 ? b0 : r0\n const segEnd = s1 < r1 ? s1 : r1\n for (let q = segStart; q <= segEnd; q++) {\n const cur = grid[q]!\n if (cur <= 1) continue\n const delta = q - nearest\n const d = delta * delta + cost\n if (d < cur) grid[q] = d\n }\n b0 = b1 + 1\n if (b0 > maxOut) break\n }\n }\n edtMinOut = minOut\n edtMaxOut = maxOut\n}\n\nconst SEED_COST = Float32Array.from({ length: 256 }, (_, coverage) => {\n const edgeOffset = 0.5 - coverage / 255\n return Math.fround(edgeOffset * edgeOffset)\n})\n\nlet scratchDistances = new Float32Array(0)\nlet scratchParabolaIndices = new Int32Array(0)\nlet scratchParabolaCosts = new Float32Array(0)\nlet scratchParabolaOffsets = new Float64Array(0)\nlet scratchBoundaries = new Float64Array(0)\nlet scratchInside = new Float32Array(0)\nlet scratchOutside = new Float32Array(0)\nlet scratchActiveRows = new Int32Array(0)\n\n/**\n * Alpha seeds cost less than 0.25. A closer seed therefore always beats a\n * farther seed in the same direction (squared integer distances differ by at\n * least one). Each empty or solid run is bounded by at most one seed on each\n * side, so one pass splits each run at its midpoint and fills both ends.\n */\nfunction horizontalRowDistances(\n alpha: AlphaPixels,\n alphaRow: number,\n distances: Float32Array,\n distRow: number,\n width: number,\n firstNonZero: number,\n maxRadius: number,\n): number {\n let lastNonZero = width - 1\n for (let x = 0; x < width; x++) {\n const coverage = alpha[alphaRow + x]!\n if (coverage === 0 || coverage === 255) {\n const a = x\n if (x === 0 && firstNonZero > 0) x = firstNonZero - 1\n else while (x + 1 < width && alpha[alphaRow + x + 1] === coverage) x++\n const isZero = coverage === 0\n if (isZero && x === width - 1) lastNonZero = a - 1\n const sign = isZero ? 1 : -1\n const lCov = a > 0 ? alpha[alphaRow + a - 1]! : -1\n const rCov = x + 1 < width ? alpha[alphaRow + x + 1]! : -1\n const lCost =\n lCov < 0 ? FAR_DISTANCE_SQUARED : (isZero ? lCov < 128 : lCov >= 128) ? SEED_COST[lCov]! : 0\n const rCost =\n rCov < 0 ? FAR_DISTANCE_SQUARED : (isZero ? rCov < 128 : rCov >= 128) ? SEED_COST[rCov]! : 0\n const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : (a + x - (rCost < lCost ? 1 : 0)) >> 1\n const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1\n const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1\n for (let p = a, d = 1; p <= lEnd; p++, d++) {\n distances[distRow + p] = sign * (d * d + lCost)\n }\n if (lEnd + 1 < rStart) {\n distances.fill(sign * FAR_DISTANCE_SQUARED, distRow + lEnd + 1, distRow + rStart)\n }\n for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) {\n distances[distRow + p] = sign * (d * d + rCost)\n }\n } else {\n distances[distRow + x] = coverage < 128 ? SEED_COST[coverage]! : -SEED_COST[coverage]!\n }\n }\n return lastNonZero\n}\n\n/**\n * Encode an alpha coverage mask as a single-channel signed distance field.\n *\n * The returned byte uses the conventional SDF encoding:\n *\n * - the edge is 0.5 (the nearest byte representation is 128),\n * - inside pixels are greater than 0.5,\n * - outside pixels are less than 0.5,\n * - `pxRange` pixels of signed distance span one encoded unit.\n *\n * Fractional source alpha is retained as a sub-pixel seed cost rather than\n * thresholded away. The two exact Euclidean distance transforms are O(width *\n * height); temporary storage is one grid plus O(height) scratch.\n */\nexport function encodeSdfFromAlpha(\n alpha: AlphaPixels,\n width: number,\n height: number,\n pxRange: number,\n): Uint8Array {\n const pixelCount = assertInputs(alpha, width, height, pxRange)\n const encoded = new Uint8Array(pixelCount)\n const scale255 = 255 / pxRange\n const clampSqDist = 0.25 * pxRange * pxRange * (1 + 1e-6)\n const skipEmptyRows = clampSqDist <= FAR_DISTANCE_SQUARED\n const maxRadius = skipEmptyRows ? Math.ceil(0.5 * pxRange + 1) : width > height ? width : height\n // Pad power-of-two widths by one 64-byte cache line (16 floats) so vertical\n // column gathers do not alias onto the same L1 cache set on every row.\n const distStride = (width & 63) === 0 ? width + 16 : width\n const requiredDistances = distStride * height\n if (scratchDistances.length < requiredDistances) {\n scratchDistances = new Float32Array(requiredDistances)\n }\n if (scratchParabolaIndices.length < height) {\n scratchParabolaIndices = new Int32Array(height)\n scratchParabolaCosts = new Float32Array(height)\n scratchParabolaOffsets = new Float64Array(height)\n scratchBoundaries = new Float64Array(height)\n scratchInside = new Float32Array(height)\n scratchOutside = new Float32Array(height)\n scratchActiveRows = new Int32Array(height)\n }\n const distances = scratchDistances\n const activeRows = scratchActiveRows\n const inside = scratchInside\n const outside = scratchOutside\n const sentinel = skipEmptyRows ? FAR_DISTANCE_SQUARED : clampSqDist\n inside.fill(sentinel, 0, height)\n outside.fill(0, 0, height)\n const lastRow = height - 1\n const u32 =\n (alpha.byteOffset & 3) === 0\n ? new Uint32Array(alpha.buffer, alpha.byteOffset, alpha.byteLength >>> 2)\n : null\n\n let anyNonZero = false\n let scanY = 0\n while (scanY < height) {\n let bandCount = 0\n let bandMinX = width\n let bandMaxX = -1\n let lastActiveY = -1\n for (; scanY < height; scanY++) {\n const alphaRow = scanY * width\n let firstNonZero = 0\n if (u32 !== null && (alphaRow & 3) === 0) {\n const wStart = alphaRow >>> 2\n const wEnd = wStart + (width >>> 2)\n let w = wStart\n while (w < wEnd && u32[w] === 0) w++\n firstNonZero = (w - wStart) << 2\n }\n while (firstNonZero < width && alpha[alphaRow + firstNonZero] === 0) firstNonZero++\n if (firstNonZero === width) {\n if (!skipEmptyRows) {\n const distRow = bandCount * distStride\n distances.fill(FAR_DISTANCE_SQUARED, distRow, distRow + width)\n activeRows[bandCount++] = scanY\n lastActiveY = scanY\n } else if (bandCount > 0 && scanY - lastActiveY >= 2 * maxRadius) {\n scanY++\n break\n }\n continue\n }\n anyNonZero = true\n const distRow = bandCount * distStride\n const lastNonZero = horizontalRowDistances(\n alpha,\n alphaRow,\n distances,\n distRow,\n width,\n firstNonZero,\n maxRadius,\n )\n activeRows[bandCount++] = scanY\n lastActiveY = scanY\n if (firstNonZero < bandMinX) bandMinX = firstNonZero\n if (lastNonZero > bandMaxX) bandMaxX = lastNonZero\n }\n\n if (bandCount === 0) break\n if (!anyNonZero) {\n const byte = 128 - Math.sqrt(FAR_DISTANCE_SQUARED) * scale255\n const fillByte = byte <= 0 ? 0 : byte | 0\n if (fillByte !== 0) encoded.fill(fillByte)\n if (scratchDistances.length > 4_500_000) scratchDistances = new Float32Array(0)\n return encoded\n }\n\n const firstActiveY = activeRows[0]!\n const bandMinY = skipEmptyRows ? (firstActiveY > maxRadius ? firstActiveY - maxRadius : 0) : 0\n const bandMaxY = skipEmptyRows\n ? lastActiveY + maxRadius < lastRow\n ? lastActiveY + maxRadius\n : lastRow\n : lastRow\n const bandHeight = bandMaxY - bandMinY + 1\n const colStart = skipEmptyRows ? (bandMinX > maxRadius ? bandMinX - maxRadius : 0) : 0\n const colEnd = skipEmptyRows\n ? bandMaxX + maxRadius < width - 1\n ? bandMaxX + maxRadius\n : width - 1\n : width - 1\n\n for (let x = colStart; x <= colEnd; x++) {\n // Transform contiguous columns in scratch instead of repeatedly traversing\n // two atlas-sized grids at a cache-unfriendly stride.\n let r = 0\n let offset = x\n while (r < bandCount && distances[offset]! >= clampSqDist) {\n r++\n offset += distStride\n }\n if (r === bandCount) continue\n const firstInSeed = activeRows[r]!\n let lastInSeed = firstInSeed\n let firstNeg = -1\n let lastNeg = -1\n let negCount = 0\n for (; r < bandCount; r++, offset += distStride) {\n const distance = distances[offset]!\n if (distance >= clampSqDist) continue\n const y = activeRows[r]!\n lastInSeed = y\n if (distance >= 0) {\n inside[y] = distance\n } else {\n inside[y] = 0\n outside[y] = -distance\n if (firstNeg < 0) firstNeg = y\n lastNeg = y\n negCount++\n }\n }\n const hasPositive = negCount < bandHeight\n let yStart = bandMinY\n let yEnd = bandMaxY\n if (hasPositive) {\n edt1d(inside, firstInSeed, lastInSeed, bandMinY, bandMaxY, clampSqDist, maxRadius)\n yStart = edtMinOut\n yEnd = edtMaxOut\n }\n const pureInEnd = firstNeg < 0 ? yEnd : firstNeg - 1\n let y = yStart\n let idx = y * width + x\n for (; y <= pureInEnd; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n }\n if (firstNeg >= 0) {\n edt1d(\n outside,\n firstNeg > 0 ? firstNeg - 1 : 0,\n lastNeg < lastRow ? lastNeg + 1 : lastRow,\n firstNeg,\n lastNeg,\n clampSqDist,\n maxRadius,\n )\n for (; y <= lastNeg; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq > 0) {\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n } else {\n const outSq = outside[y]!\n encoded[idx] = outSq >= clampSqDist ? 255 : (128 + Math.sqrt(outSq) * scale255) | 0\n }\n }\n for (; y <= yEnd; y++, idx += width) {\n const inSq = inside[y]!\n if (inSq < clampSqDist) encoded[idx] = (128 - Math.sqrt(inSq) * scale255) | 0\n }\n outside.fill(0, firstNeg, lastNeg + 1)\n }\n inside.fill(sentinel, yStart, yEnd + 1)\n }\n }\n\n if (scratchDistances.length > 4_500_000) scratchDistances = new Float32Array(0)\n return encoded\n}\n","import { alphaOfRgba, encodeSdfFromAlpha } from './cpuSdf.js'\n\nconst scope = globalThis as unknown as {\n onmessage: (\n event: MessageEvent<{\n rgba: Uint8ClampedArray\n width: number\n height: number\n pxRange: number\n }>,\n ) => void\n postMessage: (value: Uint8Array, transfer: ArrayBuffer[]) => void\n}\n\n// The page reads the canvas and sends the RGBA pixels: the alpha loop runs here.\nscope.onmessage = ({ data }) => {\n const alpha = alphaOfRgba(data.rgba, data.width * data.height)\n const result = encodeSdfFromAlpha(alpha, data.width, data.height, data.pxRange)\n scope.postMessage(result, [result.buffer as ArrayBuffer])\n}\n"],"mappings":";;;;;;;;;AAQA,MAAM,uBAAuB;;AAK7B,SAAgB,YAAY,MAAyB,YAAgC;CACnF,MAAM,QAAQ,IAAI,WAAW,UAAU;CACvC,KAAK,IAAI,SAAS,GAAG,SAAS,GAAG,SAAS,YAAY,UAAU,GAAG,UACjE,MAAM,UAAU,KAAK;CAEvB,OAAO;AACT;AAEA,SAAS,aAAa,OAAoB,OAAe,QAAgB,SAAyB;CAChG,IAAI,EAAE,iBAAiB,eAAe,EAAE,iBAAiB,oBACvD,MAAM,IAAI,UAAU,qEAAqE;CAE3F,IAAI,CAAC,OAAO,UAAU,KAAK,KAAK,SAAS,GACvC,MAAM,IAAI,WAAW,sDAAsD;CAE7E,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,UAAU,GACzC,MAAM,IAAI,WAAW,uDAAuD;CAG9E,MAAM,aAAa,QAAQ;CAC3B,IAAI,CAAC,OAAO,cAAc,UAAU,GAClC,MAAM,IAAI,WAAW,mEAAmE;CAE1F,IAAI,MAAM,WAAW,YACnB,MAAM,IAAI,WACR,oCAAoC,MAAM,OAAO,kCAAkC,WAAW,EAChG;CAEF,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,WAAW,GAC1C,MAAM,IAA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