ultra-text 1.0.0 → 1.0.1

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 (134) hide show
  1. package/README.md +168 -85
  2. package/THIRD_PARTY_NOTICES.md +3 -0
  3. package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker-xS57yQbP.js} +13 -11
  4. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +1 -0
  5. package/dist/atlas/appendAtlas.js +2 -1
  6. package/dist/atlas/appendAtlas.js.map +1 -1
  7. package/dist/atlas/buildAtlas.js +3 -14
  8. package/dist/atlas/buildAtlas.js.map +1 -1
  9. package/dist/atlas/cpuSdf.js +12 -10
  10. package/dist/atlas/cpuSdf.js.map +1 -1
  11. package/dist/atlas/cpuWorker.js +1 -1
  12. package/dist/atlas/cpuWorker.js.map +1 -1
  13. package/dist/atlas/gpuAtlas.d.ts +7 -6
  14. package/dist/atlas/gpuAtlas.js +280 -145
  15. package/dist/atlas/gpuAtlas.js.map +1 -1
  16. package/dist/atlas/jfaWgsl.js +201 -73
  17. package/dist/atlas/jfaWgsl.js.map +1 -1
  18. package/dist/atlas/rasterize.d.ts +2 -0
  19. package/dist/atlas/rasterize.js +2 -87
  20. package/dist/atlas/rasterize.js.map +1 -1
  21. package/dist/dom/DomSdf.js +66 -15
  22. package/dist/dom/DomSdf.js.map +1 -1
  23. package/dist/dom/DomSlug.d.ts +26 -0
  24. package/dist/dom/DomSlug.js +640 -0
  25. package/dist/dom/DomSlug.js.map +1 -0
  26. package/dist/dom/SlugText.d.ts +18 -0
  27. package/dist/dom/SlugText.js +94 -0
  28. package/dist/dom/SlugText.js.map +1 -0
  29. package/dist/dom/Text.js +4 -67
  30. package/dist/dom/Text.js.map +1 -1
  31. package/dist/dom/fontCanvas.d.ts +2 -0
  32. package/dist/dom/fontCanvas.js +101 -0
  33. package/dist/dom/fontCanvas.js.map +1 -0
  34. package/dist/dom/layoutSignature.js +29 -2
  35. package/dist/dom/layoutSignature.js.map +1 -1
  36. package/dist/dom/snapshot.js +251 -96
  37. package/dist/dom/snapshot.js.map +1 -1
  38. package/dist/dom/textHost.d.ts +11 -0
  39. package/dist/dom/textHost.js +68 -0
  40. package/dist/dom/textHost.js.map +1 -0
  41. package/dist/slug/SlugMaterial.d.ts +3 -2
  42. package/dist/slug/SlugMaterial.js +28 -2
  43. package/dist/slug/SlugMaterial.js.map +1 -1
  44. package/dist/slug/coverage.d.ts +1 -1
  45. package/dist/slug/coverage.js +1 -1
  46. package/dist/slug/coverage.js.map +1 -1
  47. package/dist/slug/preprocessCore.d.ts +1 -2
  48. package/dist/slug/preprocessCore.js +39 -16
  49. package/dist/slug/preprocessCore.js.map +1 -1
  50. package/dist/slug/runtime.js +6 -4
  51. package/dist/slug/runtime.js.map +1 -1
  52. package/dist/slug/standaloneRuntime.d.ts +39 -0
  53. package/dist/slug/standaloneRuntime.js +140 -0
  54. package/dist/slug/standaloneRuntime.js.map +1 -0
  55. package/dist/slug/truetype.d.ts +22 -0
  56. package/dist/slug/truetype.js +494 -0
  57. package/dist/slug/truetype.js.map +1 -0
  58. package/dist/slug-vanilla.d.ts +364 -0
  59. package/dist/slug-vanilla.js +1461 -0
  60. package/dist/slug-vanilla.js.map +1 -0
  61. package/dist/slug.d.ts +21 -0
  62. package/dist/slug.js +19 -0
  63. package/dist/text/GlyphTextMaterial.d.ts +11 -11
  64. package/dist/text/GlyphTextMaterial.js +98 -29
  65. package/dist/text/GlyphTextMaterial.js.map +1 -1
  66. package/dist/text/SdfTextMaterial.d.ts +5 -4
  67. package/dist/text/SdfTextMaterial.js +22 -4
  68. package/dist/text/SdfTextMaterial.js.map +1 -1
  69. package/dist/types.d.ts +63 -14
  70. package/dist/vanilla.d.ts +3 -0
  71. package/dist/vanilla.js +132 -59
  72. package/dist/vanilla.js.map +1 -1
  73. package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
  74. package/dist/windfoil/WindfoilMaterial.js +8 -1
  75. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  76. package/dist/windfoil/abortable.d.ts +2 -0
  77. package/dist/windfoil/abortable.js +26 -0
  78. package/dist/windfoil/abortable.js.map +1 -0
  79. package/dist/windfoil/color.js +2 -1
  80. package/dist/windfoil/color.js.map +1 -1
  81. package/dist/windfoil/coverage.d.ts +3 -20
  82. package/dist/windfoil/coverage.js +7 -20
  83. package/dist/windfoil/coverage.js.map +1 -1
  84. package/dist/windfoil/emoji.js +1 -1
  85. package/dist/windfoil/emoji.js.map +1 -1
  86. package/dist/windfoil/emojiMetrics.js +1 -1
  87. package/dist/windfoil/emojiMetrics.js.map +1 -1
  88. package/dist/windfoil/geometry.js +100 -33
  89. package/dist/windfoil/geometry.js.map +1 -1
  90. package/dist/windfoil/layerGrid.js +14 -10
  91. package/dist/windfoil/layerGrid.js.map +1 -1
  92. package/dist/windfoil/layerNormalization.d.ts +1 -1
  93. package/dist/windfoil/layerNormalization.js +1 -1
  94. package/dist/windfoil/layerNormalization.js.map +1 -1
  95. package/dist/windfoil/outlineValidation.d.ts +86 -0
  96. package/dist/windfoil/outlineValidation.js +65 -0
  97. package/dist/windfoil/outlineValidation.js.map +1 -0
  98. package/dist/windfoil/preprocess.js +3 -2
  99. package/dist/windfoil/preprocess.js.map +1 -1
  100. package/dist/windfoil/preprocessCore.d.ts +4 -85
  101. package/dist/windfoil/preprocessCore.js +210 -206
  102. package/dist/windfoil/preprocessCore.js.map +1 -1
  103. package/dist/windfoil/requests.js +1 -1
  104. package/dist/windfoil/requests.js.map +1 -1
  105. package/dist/windfoil/runtime.d.ts +2 -1
  106. package/dist/windfoil/runtime.js +3 -2
  107. package/dist/windfoil/runtime.js.map +1 -1
  108. package/dist/windfoil/shapeResources.js +2 -1
  109. package/dist/windfoil/shapeResources.js.map +1 -1
  110. package/dist/windfoil/shapes.js +1 -1
  111. package/dist/windfoil/skirt.d.ts +22 -0
  112. package/dist/windfoil/skirt.js +20 -0
  113. package/dist/windfoil/skirt.js.map +1 -0
  114. package/dist/windfoil/storage.d.ts +2 -2
  115. package/dist/windfoil/storage.js +1 -22
  116. package/dist/windfoil/storage.js.map +1 -1
  117. package/dist/windfoil/trace/contours.d.ts +0 -5
  118. package/dist/windfoil/trace/contours.js +81 -114
  119. package/dist/windfoil/trace/contours.js.map +1 -1
  120. package/dist/windfoil/trace/fit.d.ts +0 -6
  121. package/dist/windfoil/trace/fit.js +304 -308
  122. package/dist/windfoil/trace/fit.js.map +1 -1
  123. package/dist/windfoil/trace/outline.js +10 -10
  124. package/dist/windfoil/trace/outline.js.map +1 -1
  125. package/dist/windfoil/trace/types.d.ts +5 -3
  126. package/dist/windfoil/tracedOutlines.d.ts +37 -1
  127. package/dist/windfoil/tracedOutlines.js +172 -33
  128. package/dist/windfoil/tracedOutlines.js.map +1 -1
  129. package/package.json +57 -8
  130. package/skills/ultra-text/SKILL.md +114 -0
  131. package/skills/ultra-text/references/frameworks.md +43 -0
  132. package/skills/ultra-text/references/three-tsl.md +78 -0
  133. package/skills/ultra-text/references/vanilla-webgpu.md +95 -0
  134. package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
package/README.md CHANGED
@@ -178,6 +178,7 @@ They handle WebGPU setup, fonts, DOM updates and cleanup.
178
178
  - [React Three Fiber guide](https://ultra-text.makio.io/docs-r3f) — verified with R3F 9.8.2 and React 19.3.1,
179
179
  with a separate starter for the R3F 10 alpha.
180
180
  - [Mini3 & Vanilla JS guide](https://ultra-text.makio.io/docs-mini3) — verified with Mini3 0.1.0-alpha.0 and `ultra-text/vanilla`.
181
+ - [Agent skills](https://ultra-text.makio.io/skills) — progressive `skills/ultra-text/` (`npx skills add Makio64/ultra-text` or `npx skills add ultra-text`), also included in the npm package.
181
182
 
182
183
  With TresJS and React Three Fiber, install a Three.js release within the package's peer range.
183
184
  Mini3 and custom WebGPU/Canvas engines import from `ultra-text/vanilla`, which has zero
@@ -210,6 +211,39 @@ const domText = await DomText.create(source, gpuDevice, {
210
211
  `packGlyphInstances`, `packRectInstances`, `packDecorationInstances`, and
211
212
  `resolveDomTextTone`.
212
213
 
214
+ ### Slug-only entries (`ultra-text/slug` and `ultra-text/slug-vanilla`)
215
+
216
+ WebGPU-only apps that always render analytic quadratic curves—zoomable canvases, CAD/map labels,
217
+ hero 3D typography, or VRAM-constrained scenes (`0.17 MiB` vs `0.64–2.04 MiB`)—can import from
218
+ `ultra-text/slug` (Three.js `WebGPURenderer` + TSL, 40.2 kB min+brotli) or
219
+ `ultra-text/slug-vanilla` (Three.js-free raw WebGPU, 34.4 kB min+brotli):
220
+
221
+ ```ts
222
+ import { DomText, Text, createTrueTypeOutlineProvider } from 'ultra-text/slug'
223
+
224
+ // Zero-config: traces any loaded WOFF2/OTF/TTF/system webfont via Canvas 2D in one boot chunk
225
+ const traced = await DomText.create(renderer, source)
226
+
227
+ // Exact font curves from a .ttf ArrayBuffer (or family -> ArrayBuffer map)
228
+ const ttfBuffer = await fetch('/fonts/Inter-Regular.ttf').then((r) => r.arrayBuffer())
229
+ const exact = new Text('Infinite zoom, zero SDF atlas', {
230
+ renderer,
231
+ slug: { outlineProvider: createTrueTypeOutlineProvider(ttfBuffer) },
232
+ css: { fontFamily: 'Inter', fontSize: 64, color: '#ffffff' },
233
+ })
234
+ await exact.ready
235
+ ```
236
+
237
+ For Mini3 or custom WebGPU engines without Three.js, `ultra-text/slug-vanilla` provides retained
238
+ `DomText`/`Text` (`VanillaDomSlug`/`VanillaSlugText`), `buildVanillaSlugAtlas`,
239
+ `packSlugGlyphInstances`, `SLUG_WGSL`, and `createVanillaSlugPipeline` to draw Slug curves
240
+ directly on a `GPUDevice` and `GPURenderPassEncoder`.
241
+
242
+ Both Slug-only entries omit all SDF rasterization, GPU JFA, CPU EDT worker, and SDF material code.
243
+ In exchange, they require WebGPU (no WebGL2 or CPU atlas fallback) and omit the SDF companion used
244
+ on the main entry for bitmap colour emoji and `outline`/`dropShadow` underlays; supply vector
245
+ emoji artwork through `createSvgEmojiOutlineProvider` when needed.
246
+
213
247
  ## Markup contract
214
248
 
215
249
  | Attribute | Effect |
@@ -601,7 +635,7 @@ not a copy with defaults filled in.
601
635
  | `cpuWorker` | `true` | Run CPU encoding in a cancellable Worker when available; `false` uses the main thread. |
602
636
  | `fill` | — | TSL callback returning a linear RGBA fill inside each letter; works with every text backend and `createWindfoilShapes`. |
603
637
  | `vertex` | — | TSL callback returning a local `vec3` corner position for glyphs and text decorations; works with every text backend and `createWindfoilShapes`. |
604
- | `tone` | on | Text ink at the weight the browser gives it, for both backends: `{ strength, backdrop, model }`, or `false` for exact coverage; see [Matching the browser](#matching-the-browser). |
638
+ | `tone` | on | Text ink at the weight the browser gives it, on every backend: `{ strength, backdrop, model }`, or `false` for exact coverage; see [Matching the browser](#matching-the-browser). |
605
639
  | `outline` | — | Optional outline with local-unit `width`, `color`, and `opacity`, drawn from an SDF on every text backend. |
606
640
  | `dropShadow` | — | Optional hard shadow with local-unit `offsetX`/`offsetY`, `color`, and `opacity`, drawn from an SDF on every text backend. |
607
641
  | `threshold` | `0.5` | Sampled SDF edge threshold: the baked outline. Left unset, colour glyphs keep `0.515`, which hides the faint shading around some emoji. Text weight comes from `tone`. |
@@ -634,12 +668,13 @@ steady the edges; at 1:1 its wider filter draws small text lighter than the brow
634
668
  `bakeSize` and `padding` together for unusually large or oblique text, and adjust `threshold`
635
669
  only slightly around its default. `threshold`, `stemDarkening` and `quality` are ignored by
636
670
  active Windfoil coverage but still configure a requested whole-capture SDF fallback and the
637
- SDF companion of `fallback: 'sdf-glyphs'` and `sdfBelowPx`; `tone` applies to both backends.
671
+ SDF companion of `fallback: 'sdf-glyphs'` and `sdfBelowPx`; `tone` applies to every backend.
638
672
 
639
673
  ### Text effects, custom fills, and vertex hooks
640
674
 
641
675
  `DomText.create()` (`DomSdf.create()`), `Text`, `SdfTextMaterial`, and `createWindfoilShapes`
642
- accept custom TSL `fill` and `vertex` callbacks alongside SDF `outline` and `dropShadow` effects:
676
+ accept custom TSL `fill` and `vertex` callbacks; all but `createWindfoilShapes` also take SDF
677
+ `outline` and `dropShadow` effects:
643
678
 
644
679
  ```ts
645
680
  import { mix, sin, time, vec3, vec4 } from 'three/tsl'
@@ -660,8 +695,9 @@ const text = await DomText.create(renderer, source, {
660
695
  })
661
696
  ```
662
697
 
663
- The callbacks build TSL graphs once per material, including when a material is cloned or upgraded
664
- from static to animated by `setMotion()`; they do not run in the animation loop.
698
+ Both callbacks run only while TSL graphs are built, never in the animation loop: `fill` once for
699
+ each material, including clones and the animated twin a `setMotion()` upgrade creates, and
700
+ `vertex` each time three builds a pipeline from one, shadow passes included.
665
701
 
666
702
  `fill` receives `uv` (normalized glyph quad coordinates),
667
703
  `position` (animated capture-local position), `color` (per-pixel linear RGB), `colorWeight`
@@ -773,15 +809,17 @@ browsers are unmeasured. A provider that is not a function rejects before anythi
773
809
 
774
810
  `textBackend: 'slug'` uses an extrema-split dual-ray Slug evaluator (`slug` options, or `windfoil`
775
811
  options if `slug` is omitted) with endpoint-first `[p1, p3, p2]` storage, orthogonal degenerate
776
- segment culling, convex-hull winding bypass, and fine-grained 2-word band headers (`targetPiecesPerBand: 4`
812
+ segment culling, convex-hull winding bypass, and fine-grained single-word band headers (`targetPiecesPerBand: 2`
777
813
  by default). It shares the same outline provider contract, `fallback` modes, `sdfBelowPx` size
778
814
  switch, colour layers, tone weighting, outline and drop-shadow underlay, and Pretext/Range
779
815
  reflow as `'windfoil'`.
780
816
 
781
817
  The provider owns font fallback and variation mapping. It must emit every closed contour edge,
782
818
  promote lines and convert cubics to quadratics, preserve contour/hole winding for the nonzero
783
- fill rule, and return the glyph ink bounding box in the same font-unit coordinates. The
784
- placeholder resolver above is illustrative; this package does not ship a font parser. Windfoil
819
+ fill rule, and return the glyph ink bounding box in the same font-unit coordinates. The main
820
+ `ultra-text` entry keeps font parsing external to stay small, while `ultra-text/slug` and
821
+ `ultra-text/slug-vanilla` export `createTrueTypeOutlineProvider` (`parseTrueTypeFont`) for
822
+ uncompressed `.ttf` buffers alongside eager `createTracedOutlineProvider`. Windfoil
785
823
  keeps read-only curve/row buffers instead of a coverage texture. Each row band stores its curves
786
824
  twice, sorted from either side, so a fragment integrates only the curves on its own side of the
787
825
  band; `textStorageBytes` includes both copies. Adjacent band windows share their rounded
@@ -1101,25 +1139,26 @@ quads for those instances unless it rewrites `sdfTrim` with it.
1101
1139
  The HTML/3D demo's SDF mode explicitly uses CPU atlases to reduce first-use GPU compilation for its
1102
1140
  small document; `?atlas=gpu` compares the GPU path. The package default remains `auto`.
1103
1141
 
1104
- A GPU bake records the upload, the seed and jump-flood compute passes and the resolve in one
1105
- command buffer. The shader module and its pipelines are made on the device's first atlas and
1106
- kept for the device's lifetime, so later bakes and atlas patches only allocate their buffers,
1107
- which they destroy once the device has accepted the submission; a `DomSdf` makes them before it
1108
- reads the DOM, and the device compiles them meanwhile. When only a WebGPU atlas will read the
1109
- glyph mask (no colour candidates, `atlasMode` other than `'cpu'`, an initialized WebGPU
1110
- backend), the mask is drawn on a GPU-backed canvas, which skips the software canvas's set-up on
1111
- a page's first bake and is copied on the GPU; the CPU fallback of a failed GPU bake then reads
1112
- it back slowly. On Apple M3 Max with headless Chrome 156 (two back-to-back pairs on a lightly
1113
- loaded machine, with the comparison benchmark below), these and the capture fixes below (a faster layout
1114
- signature, requests sorted by code unit instead of `localeCompare`) took the first frame of a
1115
- 1,000-glyph paragraph from 58.4–58.7 to 41.8–42.3 ms and of 200 labels from 64.3–66.4 to
1116
- 46.1–46.8 ms, an edit of 10 letters from 6.0–6.2 to 4.8–5.1 ms and one adding a never-drawn
1117
- letter from 12.3 to 7.9–8.0 ms (GPU atlas), with the same rendered pixels.
1142
+ A GPU bake records the upload, the seed and jump-flood compute passes (ending in a shared-memory
1143
+ tiled `step = 2, 1` tail) and the resolve in one command buffer; when the adapter offers
1144
+ `texture-formats-tier1`, the resolve writes directly to the `r8unorm` atlas storage texture with no
1145
+ render pass. The shader module, its pipelines and per-step uniform slots are made on the device's
1146
+ first atlas and kept for the device's lifetime, so later bakes and atlas patches only allocate their
1147
+ seed buffers, which they destroy once the device has accepted the submission; a `DomSdf` makes them
1148
+ before it reads the DOM, and the device compiles them meanwhile. When only a WebGPU atlas will read
1149
+ the glyph mask (no colour candidates, `atlasMode` other than `'cpu'`, an initialized WebGPU
1150
+ backend), the mask is drawn on a GPU-backed canvas, which skips the software canvas's set-up on a
1151
+ page's first bake and is copied on the GPU; the CPU fallback of a failed GPU bake then reads it
1152
+ back slowly. On Apple M3 Max with headless Chrome 157 (the comparison benchmark below, `--full`), a
1153
+ 1,000-glyph paragraph reaches GPU completion of its first frame in 39.3 ms (200 labels in 45.3 ms),
1154
+ edits 10 known letters in 2.8 ms, and bakes plus draws a never-seen letter in 4.1 ms on the GPU
1155
+ atlas.
1118
1156
 
1119
1157
  `stats.textStorageBytes` is retained backend payload only. It excludes geometry, Canvas backing
1120
- stores, pipelines, provider caches, and transient bake memory; GPU SDF seeds use 16 bytes and
1121
- the glyph-mask copy 4 bytes (rows padded to 256 bytes) per atlas texel while a bake is active,
1122
- and the mask's upload texture, another 4 bytes per texel, lives only until it is copied. CPU
1158
+ stores, pipelines, provider caches, and transient bake memory; GPU SDF seeds use 8 bytes per atlas
1159
+ texel (`u32` packed `(x + 1) | ((y + 1) << 16)` across two ping-pong buffers) while a bake is
1160
+ active, and the mask's `rgba8unorm` upload texture (4 bytes per texel) lives only until the seed
1161
+ pass reads it. CPU
1123
1162
  encoding uses one 4-byte-per-texel working grid plus `28 × height + 8` bytes of column scratch,
1124
1163
  excluding the RGBA input, its alpha and the R8 output. DOM capture and the Canvas mask still
1125
1164
  run on the main thread, and so does the mask's `getImageData` readback for colour candidates and
@@ -1290,12 +1329,12 @@ high-contrast corners, or full CSS fidelity is required.
1290
1329
 
1291
1330
  ## Browser support
1292
1331
 
1293
- | Browser | Status | Notes |
1294
- | ------------------- | ------------------ | ---------------------------------------------------------------------------------------------- |
1295
- | Chrome / Edge 128+ | Tested | Chromium WebGPU end-to-end suite of the development repository. |
1296
- | Safari 26+ | Expected, untested | Ships WebGPU by default; not covered by automated tests. |
1297
- | Firefox 141+ | Expected, untested | Ships WebGPU; not covered by automated tests. |
1298
- | Non-WebGPU browsers | SDF only, untested | `WebGPURenderer` may fall back to WebGL2 with `atlasMode: 'auto'` or `'cpu'`; Windfoil cannot. |
1332
+ | Browser | Status | Notes |
1333
+ | ------------------- | ------------------ | ------------------------------------------------------------------------------------------------------- |
1334
+ | Chrome / Edge 128+ | Tested | Chromium WebGPU end-to-end suite of the development repository. |
1335
+ | Safari 26+ | Expected, untested | Ships WebGPU by default; not covered by automated tests. |
1336
+ | Firefox 141+ | Expected, untested | Ships WebGPU; not covered by automated tests. |
1337
+ | Non-WebGPU browsers | SDF only, untested | `WebGPURenderer` may fall back to WebGL2 with `atlasMode: 'auto'` or `'cpu'`; Windfoil and Slug cannot. |
1299
1338
 
1300
1339
  In production, serve over HTTPS, await `WebGPURenderer.init()`, and inspect the initialized
1301
1340
  backend instead of relying on `navigator.gpu` alone.
@@ -1312,64 +1351,108 @@ The package is browser-only at runtime. Guard `DomSdf.create()` during SSR.
1312
1351
 
1313
1352
  ultra-text renders the HTML you already have, with the fonts the page already loaded: there is
1314
1353
  no font file to fetch or bake, layout and line breaking come from the browser, colour emoji keep
1315
- their colours, and one capture draws a whole subtree. That is where it leads, with draw calls,
1316
- frame time and GPU memory. Its first frame now comes before glyph's and after troika's; the
1317
- libraries that skip the DOM read still edit text faster.
1354
+ their colours, and one capture draws a whole subtree. Both its single-channel SDF backend (GPU
1355
+ JFA) and its analytic Slug vector backend render faster per frame and hold less GPU memory than
1356
+ their distance-field and vector peers on an ASCII bake (0.64 MiB vs 1.44–2.04 MiB and 0.17 MiB vs
1357
+ 0.24 MiB, tying glyph Slug at 0.17 MiB if subsetted to the paragraph's 49 characters), while
1358
+ `reflow()` re-wraps 1,000 glyphs faster than any other engine. Editing characters already in the atlas lands within half a millisecond across all
1359
+ three libraries (2.4–2.9 ms); adding an unbaked glyph on the spot or rebuilding 200 DOM nodes at
1360
+ once remains faster in libraries that skip the DOM read or pre-bake every glyph.
1318
1361
 
1319
1362
  The numbers below come from one browser benchmark kept with the development sources (not part
1320
- of this repository): each library on the three.js renderer it supports, in the same headless Chrome, with the same font (Noto Sans Regular), the
1321
- same 1,000-glyph paragraph or 200 labels, and the same 3200×2400 render target. A quick run on
1322
- 2026-11-04: Apple M3 Max, macOS 15.8, Chrome 156, three 0.187.0-dev.ec2b745 on every page,
1323
- medians of 3 cold loads, 10 edits or 8 width changes. The machine was shared but lightly loaded
1324
- (1-minute load 4–6), so read them as ranges; a `--full` run is still to come. three-mesh-ui and
1325
- drei `<Html>` were not measured.
1326
-
1327
- | | `ultra-text` 0.1 (SDF) | `@pmndrs/glyph` 0.1.0 | `troika-three-text` 0.53.1 (drei `<Text>`) |
1328
- | :------------------------------------- | :-------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
1329
- | three.js renderer | `WebGPURenderer`; raw WebGPU through `ultra-text/vanilla` | `WebGPURenderer` (classic `WebGLRenderer` unsupported) | classic `WebGLRenderer` only (GLSL through `onBeforeCompile`) |
1330
- | Fonts | whatever the page loaded (WOFF2, system fonts, colour emoji), at its CSS weight; no bake step | a `.font.glb` from its CLI (Noto Sans, 304 glyphs: 7.4 s, 3.7 MB, 591 kB brotli) or a runtime bake of TTF/OTF; no WOFF/WOFF2 or variable fonts | a `.ttf`/`.otf`/`.woff` URL (`.woff2` throws); missing characters load from a CDN |
1331
- | Layout | the browser's own CSS layout (Range) or Pretext | its own shaping and layout (HarfRust in Wasm) | its own layout in a worker |
1332
- | First frame, 1,000-glyph paragraph [1] | 41 ms | 53 ms (MSDF), 58 ms (Slug) | **23 ms** |
1333
- | First frame, 200 labels [1] | 46 ms (one capture) | 80 ms | 42 ms (200 `Text`), **27 ms** (`BatchedText`) |
1334
- | Edit 10 letters already drawn [2] | 4.4 ms | **3.1 ms** | **3.1 ms** |
1335
- | Edit adding a never-drawn letter [2] | 7.4 ms (GPU atlas), 6.5 ms (CPU atlas), 5.1 ms with `extraGlyphs` | **2.8 ms** (baked ahead) | 3.0 ms |
1336
- | Width change, 1,000 glyphs [2] | **1.7 ms** with `reflow()`; 4.5 ms with CSS + `rebuild()` | 2.1 ms | 2.9 ms |
1337
- | Frame, 1,000 glyphs [3] | **0.09 ms** | 0.13 ms | 0.17 ms |
1338
- | Frame, 200 labels [3] | **0.09 ms** | 0.22 ms | 1.67 ms (200 `Text`), 0.19 ms (`BatchedText`) |
1339
- | Draw calls, paragraph / 200 labels | **1 / 1** | 2 / 2 (double-sided text in two passes) | 1 / 200 (1 with `BatchedText`) |
1340
- | GPU memory, paragraph [4] | **0.64 MiB** (15 MiB while the GPU atlas bakes) | 3.4 MiB MSDF, 0.35 MiB Slug (1.4 / 0.25 MiB for an ASCII-only bake) | 2.0 MiB |
1341
- | Zoom 10× / 100× [5] | sharp / edges waver (SDF); analytic with `textBackend: 'slug' \| 'windfoil'` | MSDF keeps corners; Slug exact | sharp / corners round |
1342
- | Outline and drop shadow | on every backend | MSDF only | outline with blur and offset, inner stroke |
1343
- | Colour emoji | **yes**, the browser's own | not yet (roadmap) | monochrome |
1344
- | JS, min+gzip | **38.7 kB** public entry | 134.2 kB Three adapter + 511.2 kB shaper Wasm | 46.3 kB with dependencies |
1363
+ of this repository; `--full` run on 2026-11-15): each library on the three.js renderer it supports, in the same
1364
+ headless Chrome 157, on an Apple M3 Max (macOS 15.8), with `three` `0.188.0-dev.29c99f4` on every
1365
+ page, the same font (Noto Sans Regular), the same 1,000-glyph paragraph or 200 HUD labels, and a
1366
+ shared 3200×2400 RGBA8 sRGB render target. Cells report medians across 10 cold loads, 30 dynamic
1367
+ edits, 32 width changes and 8 Williams-balanced steady-state rounds on a shared developer machine
1368
+ (read timings as ranges). three-mesh-ui and drei `<Html>` were not measured.
1369
+
1370
+ ```text
1371
+ Steady frame · 200 HUD labels (3200×2400, E1 ms/frame — lower is faster)
1372
+ ultra-text SDF (1 capture) █ 0.074 ms · 1 draw
1373
+ troika BatchedText ██ 0.153 ms · 1 draw
1374
+ @pmndrs/glyph MSDF ×200 ███ 0.211 ms · 2 draws
1375
+ troika 200 Text ████████████████████████ 1.69 ms · 200 draws
1376
+
1377
+ Steady frame · 1,000-glyph paragraph (3200×2400, E1 ms/frame — lower is faster)
1378
+ ultra-text SDF █████████ 0.075 ms · 1 draw
1379
+ @pmndrs/glyph MSDF ███████████████ 0.129 ms · 2 draws
1380
+ troika Text (WebGL2) █████████████████ 0.144 ms · 1 draw
1381
+ ultra-text Slug (vector) ██████████████████ 0.158 ms · 1 draw
1382
+ @pmndrs/glyph Slug (vector) ████████████████████████ 0.206 ms · 2 draws
1383
+
1384
+ Width relayout · 1,000 glyphs (480–720 px cycle — lower is faster)
1385
+ ultra-text reflow() ██████████ 1.51 ms
1386
+ @pmndrs/glyph MSDF █████████████ 1.95 ms
1387
+ troika Text ████████████████ 2.52 ms
1388
+ @pmndrs/glyph Slug ████████████████ 2.54 ms
1389
+ ultra-text CSS + rebuild() ████████████████████████ 3.74 ms
1390
+
1391
+ Resident GPU memory · 1,000-glyph paragraph (lower is leaner)
1392
+ ultra-text Slug (TTF) ██ 0.17 MiB
1393
+ @pmndrs/glyph Slug (ASCII) ███ 0.24 MiB (0.17 MiB subsetted to 49 chars)
1394
+ ultra-text SDF (96 px R8) ████████ 0.64 MiB
1395
+ @pmndrs/glyph MSDF (ASCII) █████████████████ 1.44 MiB (0.85 MiB subsetted to 49 chars)
1396
+ troika Text (slab + canvas) ████████████████████████ 2.04 MiB
1397
+ ```
1398
+
1399
+ | | `ultra-text` 0.1 (SDF) | `ultra-text` 0.1 (Slug) | `@pmndrs/glyph` 0.1.0 | `troika-three-text` 0.53.1 (drei `<Text>`) |
1400
+ | :------------------------------------- | :----------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
1401
+ | three.js renderer | `WebGPURenderer`; raw WebGPU through `ultra-text/vanilla` | `WebGPURenderer`; raw WebGPU through `ultra-text/slug-vanilla` | `WebGPURenderer` (classic `WebGLRenderer` unsupported) | classic `WebGLRenderer` only (GLSL through `onBeforeCompile`) |
1402
+ | Fonts | whatever the page loaded (WOFF2, variable, system fonts, colour emoji); no bake step | runtime font outlines or zero-file Canvas 2D glyph trace; no offline bake step | a `.font.glb` from its CLI (Noto Sans ASCII, 132 glyphs: 3.1 s, 1.55 MB, 295 kB brotli) or a runtime bake of TTF/OTF; no WOFF/WOFF2 or variable fonts | a `.ttf`/`.otf`/`.woff` URL (`.woff2` throws); missing characters load from a CDN |
1403
+ | Layout | the browser's own CSS layout (Range) or Pretext | the browser's own CSS layout (Range) or Pretext | its own shaping and layout (HarfRust in Wasm) | its own layout in a worker |
1404
+ | First frame, 1,000-glyph paragraph [1] | 39.3 ms (GPU), 63.8 ms (CPU) | 43.3 ms (TTF), 91.5 ms (traced) | 50.2 ms (MSDF), 56.8 ms (Slug) | **23.9 ms** |
1405
+ | First frame, 200 labels [1] | 45.3 ms (one capture) | one capture over all 200 | 76.0 ms | 39.0 ms (200 `Text`), **25.8 ms** (`BatchedText`) |
1406
+ | Edit 10 letters already drawn [2] | 2.8 ms | 3.0 ms (traced), 3.1 ms (TTF) | 2.9 ms (MSDF & Slug) | **2.4 ms** |
1407
+ | Edit adding a never-drawn letter [2] | 4.1 ms (GPU atlas), 3.6 ms (CPU atlas), 2.8 ms with `extraGlyphs` | 8.6 ms (TTF), 10.9 ms (traced) | **2.5 ms** MSDF, 2.8 ms Slug (baked ahead) | 3.0 ms |
1408
+ | Width change, 1,000 glyphs [2] | **1.51 ms** with `reflow()`; 3.7 ms with CSS + `rebuild()` | 3.6–3.7 ms with CSS + `rebuild()` | 1.95 ms (MSDF), 2.54 ms (Slug) | 2.52 ms |
1409
+ | Frame, 1,000 glyphs / 160 px [3] | **0.075 ms** / **0.087 ms** | 0.158 ms / 0.168 ms (0.053 ms net GPU at 160 px) | 0.129 / 0.156 ms (MSDF); 0.206 / 0.213 ms (Slug) | 0.144 ms / 0.142 ms |
1410
+ | Frame, 200 labels [3] | **0.074 ms** | 1 draw per subtree | 0.211 ms | 1.69 ms (200 `Text`), 0.153 ms (`BatchedText`) |
1411
+ | Draw calls, paragraph / 200 labels | **1 / 1** | **1 / 1** | 2 / 2 (double-sided text in two passes) | 1 / 200 (1 with `BatchedText`) |
1412
+ | GPU memory, paragraph [4] | **0.64 MiB** (10.0 MiB while the GPU atlas bakes; 0.64 MiB peak on CPU) | **0.17 MiB** TTF (0.28 MiB traced) | 1.44 MiB MSDF, 0.24 MiB Slug for ASCII bake (0.85 / 0.17 MiB for the paragraph's 49 chars) | 2.04 MiB (1.04 MiB 256-glyph RGBA slab & buffers + 1.00 MiB SDF generator canvas) |
1413
+ | Zoom 10× / 100× [5] | sharp / soft SDF stems (`textBackend: 'windfoil'` also analytic) | **exact quadratic curves** at 100× | MSDF keeps corners; Slug exact | sharp / corners round |
1414
+ | Outline and drop shadow | on every backend | on every backend (SDF underlay) | MSDF only | outline with blur and offset, inner stroke |
1415
+ | Colour emoji | **yes**, the browser's own | **yes**, SDF colour companion | not yet (roadmap) | monochrome |
1416
+ | JS + Wasm, min+gzip | **39.0 kB** `DomText + Text` (34.9 kB brotli; 51.2 kB gzip with SVG shape helpers) | +12.0 kB lazy chunk (+10.9 kB brotli; standalone `ultra-text/slug`: 43.8 kB, 38.8 kB brotli) | 122.3 kB JS + 501.0 kB shaper Wasm (623.3 kB; 494.6 kB brotli) | 42.2 kB `Text` (36.6 kB brotli; 44.3 kB with `BatchedText` + `preloadFont`) |
1345
1417
 
1346
1418
  1. From the first authoring call to GPU completion of the first frame, with the font already
1347
- loaded through each library's own API and a warm shader cache. ultra-text spends about 11 ms
1348
- of its 41 ms baking the SDF atlas, 7 ms reading the DOM layout and 14 ms in the first render,
1349
- where three builds the text material's shaders; troika typesets in a worker and generates
1350
- glyph SDFs with WebGL as they are first used. troika's paragraph figure is from a rerun of the
1351
- cold loads minutes later: in the full run and in another rerun its first frames took 49 and
1352
- 32 ms, 29 and 14 ms of it waiting for the GPU, which suggests its WebGL shaders missed the
1353
- cache. ultra-text measured 40–41 ms and glyph MSDF 49–50 ms in those reruns.
1354
- 2. From the change to GPU completion of the next frame. `rebuild()` reads the DOM again;
1355
- `reflow()` re-wraps the retained capture without reading it. A never-drawn letter is drawn
1356
- into the live atlas (see [Dynamic text and reflow](#dynamic-text-and-reflow)); glyph bakes
1357
- every glyph ahead of time.
1358
- 3. Whole frames at 3200×2400 by batch completion, including each renderer's clear and store of
1359
- the target; GPU timestamps and per-process GPU time rank them the same way (troika ÷
1360
- ultra-text 1.62–3.74 on the paragraph, glyph ÷ ultra-text 1.11–1.50). An empty frame costs
1361
- about 0.14–0.16 ms on `WebGLRenderer` and 0.06–0.07 ms on `WebGPURenderer`, so much of troika's
1362
- gap is the renderer: net of the empty frame, its text costs 0.010–0.114 ms (batch completion to
1363
- GPU timer queries) against ultra-text's 0.010–0.017 ms, and glyph's 0.018–0.061 ms (two
1364
- passes). 200 troika `Text` objects are CPU-bound (1.7 ms of CPU per frame).
1365
- 4. Textures and buffers each library allocates, estimated at the API. glyph's figures are for the
1366
- benchmark's 304-glyph bake; troika keeps its 1 MiB atlas both as a texture and as an SDF canvas.
1367
- 5. The contact sheet `shots/zoom-grid.png` of each run.
1368
-
1369
- Facts not measured here come from each project's documentation and source, checked on 2026-11-04:
1370
- [glyph's README](https://github.com/pmndrs/glyph) (renderers, formats, effects, emoji roadmap,
1371
- package sizes), [troika's README](https://github.com/protectwise/troika/tree/main/packages/troika-three-text)
1372
- (renderer, font formats, CDN fallback, effects) and bundlephobia (troika's size).
1419
+ loaded through each library's own API and warm native shader caches (`n = 10` Williams-balanced
1420
+ rounds). ultra-text spends 10.7 ms of its 39.3 ms SDF first frame baking the 96 px R8 atlas on
1421
+ the GPU (9.7 ms packing Slug curves in `U-slug`), 6.6 ms reading DOM layout and 13.8 ms in the
1422
+ first render, where three builds the text material's shaders; troika typesets in a worker and
1423
+ generates 64 px glyph SDFs with WebGL as they are first used.
1424
+ 2. From the mutation call to GPU completion of the next frame (`n = 30` edits, `n = 32` width
1425
+ changes). `rebuild()` reads the DOM again; `reflow()` re-wraps the retained capture in 0.61 ms
1426
+ of main-thread JS without reading the DOM. A never-drawn letter is rasterized from CSS and
1427
+ patched into the live atlas (see [Dynamic text and reflow](#dynamic-text-and-reflow)); glyph
1428
+ only switches among glyphs baked ahead into its `.font.glb`.
1429
+ 3. Whole frames at 3200×2400 by batch completion (`E1`, `n = 8` Williams-balanced rounds),
1430
+ including each renderer's clear and store of the target; GPU pass timestamps (`E2`) and
1431
+ per-process `ioreg` GPU time (`E3`) rank them the same way (`troika ÷ ultra-text` 1.67–2.02 on
1432
+ the paragraph, `glyph MSDF ÷ ultra-text` 1.10–1.73, `glyph Slug ÷ ultra-text SDF` 2.06–2.76;
1433
+ comparing vector backends directly on 160 px display text, `ultra-text` Slug costs 0.053 ms net
1434
+ GPU time against `glyph` Slug's 0.090 ms). An empty frame costs about 0.13–0.14 ms on
1435
+ `WebGLRenderer` and 0.058–0.060 ms on `WebGPURenderer`: net of the empty frame on the paragraph,
1436
+ text costs 0.010 ms (`E2`) to 0.016 ms (`E1`) on `ultra-text` SDF, 0.008 ms on `troika`, and
1437
+ 0.017–0.071 ms on `glyph` MSDF (two passes + per-frame `glyph.shape()`). 200 troika `Text`
1438
+ objects are CPU-bound (1.68 ms of CPU per frame vs 0.012 ms for one `ultra-text` capture and
1439
+ 0.208 ms for 200 `glyph` texts).
1440
+ 4. Textures and buffers each library allocates after renderer baseline, estimated at the API.
1441
+ glyph's `1.44 MiB` MSDF and `0.24 MiB` Slug figures are for the 132-glyph ASCII bake (subsetting
1442
+ to the paragraph's 49 code points yields `0.85 MiB` MSDF and `0.17 MiB` Slug); troika allocates a
1443
+ pre-sized `2048×128` RGBA8 256-glyph atlas slab + scratch/geometry buffers (`1.04 MiB`, 19%
1444
+ occupied at the paragraph's 48 unique glyphs) plus its persistent `preserveDrawingBuffer`
1445
+ auxiliary SDF generator canvas (`1.00 MiB`).
1446
+ 5. Verified on the `shots/zoom-grid.png` contact sheet of each run (1×, 10× and 100× magnification
1447
+ of `"Rag Kerning quartz 0.5% Ж"` at 18 px beside Chrome's own DOM text).
1448
+
1449
+ Bundle and Wasm download sizes (`JS + Wasm, min+gzip`) are measured locally under identical settings
1450
+ (Vite 8, `es2022`, `NODE_ENV=production`, `three/*`
1451
+ external, `gzip -9` and `brotli`, decimal `1 kB = 1,000 B`). Qualitative facts not measured here
1452
+ come from each project's documentation and source, checked on 2026-11-15:
1453
+ [glyph's README](https://github.com/pmndrs/glyph) (renderers, formats, effects, emoji roadmap) and
1454
+ [troika's README](https://github.com/protectwise/troika/tree/main/packages/troika-three-text)
1455
+ (renderer, font formats, CDN fallback, effects).
1373
1456
 
1374
1457
  ## Demo and documentation
1375
1458
 
@@ -49,3 +49,6 @@ These files are used only by tests and are not part of the npm package:
49
49
  - `tests/fixtures/svg/social/`: the X, GitHub and LinkedIn marks from
50
50
  [Simple Icons](https://github.com/simple-icons/simple-icons), CC0-1.0. Their owners retain
51
51
  all trademark rights.
52
+ - `tests/fixtures/fonts/latin.ttf`: Noto Sans Regular by the Noto Project Authors,
53
+ [SIL Open Font License 1.1](https://openfontlicense.org/); the license is in `latin-OFL.txt`
54
+ beside it.
@@ -73,20 +73,20 @@ function edt1d(grid, startSeed, endSeed, outStart, outEnd, clampSqDist, maxRadiu
73
73
  cost = grid[q];
74
74
  } else if (cost === grid[q - 1]) while (q < endSeed && grid[q + 1] === cost) q++;
75
75
  const costPlusQSquared = cost + q * q;
76
- while (envelopeEnd > 0 && (costPlusQSquared - parabolaOffsets[envelopeEnd]) * .5 <= boundaries[envelopeEnd] * (q - parabolaIndices[envelopeEnd])) envelopeEnd--;
77
- const intersection = (costPlusQSquared - parabolaOffsets[envelopeEnd]) * .5 / (q - parabolaIndices[envelopeEnd]);
76
+ while (envelopeEnd > 0 && costPlusQSquared - parabolaOffsets[envelopeEnd] <= boundaries[envelopeEnd] * (q - parabolaIndices[envelopeEnd])) envelopeEnd--;
77
+ const twiceIntersection = (costPlusQSquared - parabolaOffsets[envelopeEnd]) / (q - parabolaIndices[envelopeEnd]);
78
78
  envelopeEnd++;
79
79
  parabolaIndices[envelopeEnd] = q;
80
80
  parabolaCosts[envelopeEnd] = cost;
81
81
  parabolaOffsets[envelopeEnd] = costPlusQSquared;
82
- boundaries[envelopeEnd] = intersection;
82
+ boundaries[envelopeEnd] = twiceIntersection;
83
83
  }
84
84
  const minOut = first - maxRadius > outStart ? first - maxRadius : outStart;
85
85
  const lastSeed = parabolaIndices[envelopeEnd];
86
86
  const maxOut = lastSeed + maxRadius < outEnd ? lastSeed + maxRadius : outEnd;
87
87
  let b0 = minOut;
88
88
  for (let e = 0; e <= envelopeEnd; e++) {
89
- const b1 = e === envelopeEnd ? maxOut : Math.floor(boundaries[e + 1]);
89
+ const b1 = e === envelopeEnd ? maxOut : Math.floor(boundaries[e + 1] * .5);
90
90
  if (b1 >= b0) {
91
91
  const nearest = parabolaIndices[e];
92
92
  const cost = parabolaCosts[e];
@@ -111,7 +111,8 @@ function edt1d(grid, startSeed, endSeed, outStart, outEnd, clampSqDist, maxRadiu
111
111
  }
112
112
  const SEED_COST = Float32Array.from({ length: 256 }, (_, coverage) => {
113
113
  const edgeOffset = .5 - coverage / 255;
114
- return Math.fround(edgeOffset * edgeOffset);
114
+ const sq = Math.fround(edgeOffset * edgeOffset);
115
+ return coverage < 128 ? sq : -sq;
115
116
  });
116
117
  let scratchDistances = /* @__PURE__ */ new Float32Array(0);
117
118
  let scratchParabolaIndices = /* @__PURE__ */ new Int32Array(0);
@@ -140,15 +141,17 @@ function horizontalRowDistances(alpha, alphaRow, distances, distRow, width, firs
140
141
  const sign = isZero ? 1 : -1;
141
142
  const lCov = a > 0 ? alpha[alphaRow + a - 1] : -1;
142
143
  const rCov = x + 1 < width ? alpha[alphaRow + x + 1] : -1;
143
- const lCost = lCov < 0 ? FAR_DISTANCE_SQUARED : (isZero ? lCov < 128 : lCov >= 128) ? SEED_COST[lCov] : 0;
144
- const rCost = rCov < 0 ? FAR_DISTANCE_SQUARED : (isZero ? rCov < 128 : rCov >= 128) ? SEED_COST[rCov] : 0;
144
+ const lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov];
145
+ const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov];
146
+ const lCost = lSc > 0 ? lSc : 0;
147
+ const rCost = rSc > 0 ? rSc : 0;
145
148
  const mid = rCov < 0 ? x : lCov < 0 ? a - 1 : a + x - (rCost < lCost ? 1 : 0) >> 1;
146
149
  const lEnd = lCov < 0 ? a - 1 : mid < a + maxRadius - 1 ? mid : a + maxRadius - 1;
147
150
  const rStart = rCov < 0 ? x + 1 : mid + 1 > x - maxRadius + 1 ? mid + 1 : x - maxRadius + 1;
148
151
  for (let p = a, d = 1; p <= lEnd; p++, d++) distances[distRow + p] = sign * (d * d + lCost);
149
152
  if (lEnd + 1 < rStart) distances.fill(sign * FAR_DISTANCE_SQUARED, distRow + lEnd + 1, distRow + rStart);
150
153
  for (let p = rStart, d = x + 1 - rStart; p <= x; p++, d--) distances[distRow + p] = sign * (d * d + rCost);
151
- } else distances[distRow + x] = coverage < 128 ? SEED_COST[coverage] : -SEED_COST[coverage];
154
+ } else distances[distRow + x] = SEED_COST[coverage];
152
155
  }
153
156
  return lastNonZero;
154
157
  }
@@ -272,10 +275,9 @@ function encodeSdfFromAlpha(alpha, width, height, pxRange) {
272
275
  negCount++;
273
276
  }
274
277
  }
275
- const hasPositive = negCount < bandHeight;
276
278
  let yStart = bandMinY;
277
279
  let yEnd = bandMaxY;
278
- if (hasPositive) {
280
+ if (negCount < bandHeight) {
279
281
  edt1d(inside, firstInSeed, lastInSeed, bandMinY, bandMaxY, clampSqDist, maxRadius);
280
282
  yStart = edtMinOut;
281
283
  yEnd = edtMaxOut;
@@ -317,4 +319,4 @@ scope.onmessage = ({ data }) => {
317
319
  scope.postMessage(result, [result.buffer]);
318
320
  };
319
321
 
320
- //# sourceMappingURL=cpuSdf.worker-Du9o8q4p.js.map
322
+ //# sourceMappingURL=cpuSdf.worker-xS57yQbP.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cpuSdf.worker-xS57yQbP.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]! <=\n boundaries[envelopeEnd]! * (q - parabolaIndices[envelopeEnd]!)\n ) {\n envelopeEnd--\n }\n const twiceIntersection =\n (costPlusQSquared - parabolaOffsets[envelopeEnd]!) / (q - parabolaIndices[envelopeEnd]!)\n\n envelopeEnd++\n parabolaIndices[envelopeEnd] = q\n parabolaCosts[envelopeEnd] = cost\n parabolaOffsets[envelopeEnd] = costPlusQSquared\n boundaries[envelopeEnd] = twiceIntersection\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]! * 0.5)\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 const sq = Math.fround(edgeOffset * edgeOffset)\n return coverage < 128 ? sq : -sq\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 lSc = lCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[lCov]!\n const rSc = rCov < 0 ? FAR_DISTANCE_SQUARED : sign * SEED_COST[rCov]!\n const lCost = lSc > 0 ? lSc : 0\n const rCost = rSc > 0 ? rSc : 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] = 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 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 let yStart = bandMinY\n let yEnd = bandMaxY\n if (negCount < bandHeight) {\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,IAAI,WAAW,8DAA8D;CAGrF,OAAO;AACT;AAEA,IAAI,YAAY;AACh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C,UACA,SACA,aACA,SACF;IACA,OAAO,KAAK,SAAS,KAAK,OAAO,OAAO;KACtC,MAAM,OAAO,OAAO;KACpB,IAAI,OAAO,GACL;UAAA,OAAO,aAAa,QAAQ,OAAQ,MAAM,KAAK,KAAK,IAAI,IAAI,WAAY;KAAA,OACvE;MACL,MAAM,QAAQ,QAAQ;MACtB,QAAQ,OAAO,SAAS,cAAc,MAAO,MAAM,KAAK,KAAK,KAAK,IAAI,WAAY;KACpF;IACF;IACA,OAAO,KAAK,MAAM,KAAK,OAAO,OAAO;KACnC,MAAM,OAAO,OAAO;KACpB,IAAI,OAAO,aAAa,QAAQ,OAAQ,MAAM,KAAK,KAAK,IAAI,IAAI,WAAY;IAC9E;IACA,QAAQ,KAAK,GAAG,UAAU,UAAU,CAAC;GACvC;GACA,OAAO,KAAK,UAAU,QAAQ,OAAO,CAAC;EACxC;CACF;CAEA,IAAI,iBAAiB,SAAS,MAAW,mCAAmB,IAAI,aAAa,CAAC;CAC9E,OAAO;AACT;;ACvaA,MAAM,QAAQ;AAad,MAAM,aAAa,EAAE,WAAW;CAE9B,MAAM,SAAS,mBADD,YAAY,KAAK,MAAM,KAAK,QAAQ,KAAK,MACrB,GAAO,KAAK,OAAO,KAAK,QAAQ,KAAK,OAAO;CAC9E,MAAM,YAAY,QAAQ,CAAC,OAAO,MAAqB,CAAC;AAC1D"}
@@ -1,5 +1,6 @@
1
1
  import { atlasDevice, encodeGpuSdf, generateAtlasMips } from "./gpuAtlas.js";
2
- import { appendCursors, createCanvas, glyphPainter, isColorCandidate, measureGlyph, packShelves, slotOf, waitForFonts } from "./rasterize.js";
2
+ import { createCanvas, isColorCandidate, waitForFonts } from "../dom/fontCanvas.js";
3
+ import { appendCursors, glyphPainter, measureGlyph, packShelves, slotOf } from "./rasterize.js";
3
4
  import { alphaOfRgba, encodeSdfFromAlpha } from "./cpuSdf.js";
4
5
  import { Box2, DataTexture, RedFormat, UnsignedByteType, Vector2 } from "three/webgpu";
5
6
  // src/atlas/appendAtlas.ts