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.
- package/README.md +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +164 -50
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +563 -243
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,59 +14,40 @@
|
|
|
14
14
|
|
|
15
15
|
[](https://ultra-text.makio.io/)
|
|
16
16
|
|
|
17
|
-
`ultra-text` measures marked HTML or a styled
|
|
18
|
-
`THREE.Group
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
- Browser-native layout and line breaking
|
|
22
|
-
-
|
|
23
|
-
- GPU SDF baking with
|
|
24
|
-
- TSL motion, clipping, antialiasing,
|
|
25
|
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- Enforced bundle budget: the public entry stays at or under 35 kB min+brotli
|
|
30
|
-
(size-limit, excluding Three.js, Pretext, and separately budgeted optional feature chunks)
|
|
31
|
-
|
|
32
|
-
The optional CPU builder has a separate 3 kB budget, plus 2.5 kB for its worker asset.
|
|
17
|
+
`ultra-text` measures marked HTML or a CSS-styled string with the browser and returns a retained
|
|
18
|
+
`THREE.Group` (or packed typed arrays via `ultra-text/vanilla`). Default rendering bakes a
|
|
19
|
+
single-channel SDF atlas; experimental `windfoil` and `slug` backends retain quadratic curves.
|
|
20
|
+
|
|
21
|
+
- Browser-native layout and line breaking (`Range`, or lazy Pretext Canvas layout)
|
|
22
|
+
- Retained instanced geometry with zero DOM reads in the render loop
|
|
23
|
+
- Single-pass tiled GPU SDF baking (with exact CPU worker fallback) or analytic quadratic outlines
|
|
24
|
+
- TSL motion, clipping, antialiasing, custom `fill`/`vertex` hooks, `outline`, `dropShadow`,
|
|
25
|
+
solid CSS decorations, and [browser-matched ink weight](#matching-the-browser) (`tone`)
|
|
26
|
+
- Tree-shaken `DomText + Text`: **41.1 kB** min+gzip (**36.6 kB** brotli; Vite build). Enforced
|
|
27
|
+
`size-limit` IIFE budget: **44.1 kB** min+brotli (limit 46 kB, excluding Three.js and lazy chunks),
|
|
28
|
+
plus **3.6 kB** CPU fallback (limit 4.5 kB) and **2.2 kB** worker asset (limit 2.5 kB).
|
|
33
29
|
|
|
34
30
|
> [!NOTE]
|
|
35
|
-
> The
|
|
36
|
-
>
|
|
37
|
-
> [Limitations](#limitations) before using either path for demanding typography.
|
|
31
|
+
> The SDF atlas is single-channel (not MSDF). Analytic backends (`slug`, `windfoil`) are WebGPU-only
|
|
32
|
+
> and experimental. See [Limitations](#limitations).
|
|
38
33
|
|
|
39
34
|
## Requirements and install
|
|
40
35
|
|
|
41
|
-
- ESM only
|
|
42
|
-
|
|
43
|
-
- Three.js r187
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
- `
|
|
47
|
-
|
|
48
|
-
`atlasMode: 'gpu'` requires a real WebGPU backend. The default `auto` mode can fall back to
|
|
49
|
-
the CPU atlas when `WebGPURenderer` is using its WebGL2 backend, or when the WebGPU device
|
|
50
|
-
cannot run the GPU passes.
|
|
51
|
-
The Windfoil and Slug paths require WebGPU and quadratic font outlines, from an app-supplied
|
|
52
|
-
resolver or, without one, traced from the browser's own glyphs. With `fallback: 'sdf'`,
|
|
53
|
-
selecting them can instead degrade the whole capture to SDF when WebGPU or an outline is
|
|
54
|
-
unavailable.
|
|
36
|
+
- ESM only (`require()` unsupported), Canvas 2D, font-loading APIs, `Range`, and
|
|
37
|
+
`ResizeObserver`/`MutationObserver` (unless `observe: false`).
|
|
38
|
+
- Three.js r187 (`>=0.187.0 <0.188.0`) with `WebGPURenderer` (classic `WebGLRenderer` is
|
|
39
|
+
unsupported). Three-free engines use `ultra-text/vanilla` or `ultra-text/slug-vanilla` (`three`
|
|
40
|
+
optional).
|
|
41
|
+
- `atlasMode: 'auto'` falls back to CPU EDT on WebGL2 or unsupported GPU limits; `windfoil`/`slug`
|
|
42
|
+
require WebGPU unless `fallback: 'sdf'` is set.
|
|
55
43
|
|
|
56
44
|
```sh
|
|
57
45
|
npm install ultra-text three@0.187
|
|
46
|
+
npm install --save-dev @types/three@0.187 # TypeScript declarations
|
|
58
47
|
```
|
|
59
48
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```sh
|
|
63
|
-
npm install --save-dev @types/three@0.187
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
The package has one runtime dependency, `@chenglou/pretext` (`^1.0.0`). It is installed for
|
|
67
|
-
every consumer but never loaded eagerly: `collectDomSnapshot` imports the
|
|
68
|
-
`@chenglou/pretext/rich-inline` subpath dynamically, only when `layoutEngine: 'pretext'` is
|
|
69
|
-
requested, which loads about 38 kB min+brotli more. The default Range engine never touches it.
|
|
49
|
+
`@chenglou/pretext` (`^1.0.0`) is the only runtime dependency, loaded dynamically (~38 kB
|
|
50
|
+
min+brotli) only when `layoutEngine: 'pretext'` is requested.
|
|
70
51
|
|
|
71
52
|
## Quick start
|
|
72
53
|
|
|
@@ -136,60 +117,43 @@ scene.remove(text)
|
|
|
136
117
|
text.dispose()
|
|
137
118
|
```
|
|
138
119
|
|
|
139
|
-
`css` accepts a
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
`{ headline: true, muted: false }`. Sass, SCSS, and Stylus work through stylesheets compiled
|
|
148
|
-
by your app's build tool: pass the resulting class names to `cssClass`. Runtime `css` strings
|
|
149
|
-
use standard CSS declaration syntax.
|
|
150
|
-
|
|
151
|
-
`Text` owns a visually clipped, measurable DOM source whose content is literal text, including
|
|
152
|
-
HTML-looking strings. Its source is attached to `document.body` by default; pass a connected
|
|
153
|
-
`parent` element to inherit its CSS and match selectors scoped beneath it. The initial build
|
|
154
|
-
waits for fonts. The same [CSS capture limitations](#limitations) and `DomText` rendering
|
|
155
|
-
options apply, including `observe: false` for manual updates. A `Text` cannot see what your
|
|
156
|
-
scene draws behind it: name that colour as `tone: { backdrop }` so light text is weighted for
|
|
157
|
-
it; see [Matching the browser](#matching-the-browser).
|
|
120
|
+
`css` accepts a camelCase/kebab-case style object or CSS string (numeric lengths default to `px`;
|
|
121
|
+
unitless properties like `lineHeight`/`opacity` stay numeric; custom properties like `'--accent'`
|
|
122
|
+
and strings like `'2rem'` work). `cssClass` takes a string, array, or conditional map for
|
|
123
|
+
compiled stylesheet / Sass / SCSS classes.
|
|
124
|
+
|
|
125
|
+
`Text` mounts a visually clipped hidden source on `document.body` (or `parent`) with literal text
|
|
126
|
+
content and shares all `DomText` options and [limitations](#limitations). Pass `tone: { backdrop }`
|
|
127
|
+
so light text weights correctly against your scene; see [Matching the browser](#matching-the-browser).
|
|
158
128
|
|
|
159
129
|
```ts
|
|
160
130
|
text.text = 'Updated text'
|
|
161
|
-
text.setCss({ fontSize: 36, color: 'tomato' }) //
|
|
162
|
-
text.setClass(['headline', 'compact']) //
|
|
163
|
-
await text.rebuild() //
|
|
131
|
+
text.setCss({ fontSize: 36, color: 'tomato' }) // replaces inline CSS
|
|
132
|
+
text.setClass(['headline', 'compact']) // replaces classes
|
|
133
|
+
await text.rebuild() // required only with observe: false or external stylesheet edits
|
|
164
134
|
```
|
|
165
135
|
|
|
166
|
-
Default observers
|
|
167
|
-
|
|
168
|
-
`
|
|
169
|
-
source. `TextOptions`, `TextCss`, and `TextClass` are available as package-root type exports.
|
|
136
|
+
Default observers auto-rebuild on text, inline style, or class changes. Call `dispose()` to clean
|
|
137
|
+
up GPU resources, observers, and the owned DOM node. Types `TextOptions`, `TextCss`, and
|
|
138
|
+
`TextClass` are exported at the root.
|
|
170
139
|
|
|
171
140
|
## TresJS, React Three Fiber, Mini3, and Vanilla JS
|
|
172
141
|
|
|
173
|
-
Copy
|
|
174
|
-
|
|
175
|
-
They handle WebGPU setup, fonts, DOM updates and cleanup.
|
|
142
|
+
Copy a starter once, then use `<UltraText source={source} />` (React/Vue) or
|
|
143
|
+
`await UltraText.create(renderer, source)` (Mini3):
|
|
176
144
|
|
|
177
|
-
- [TresJS guide](https://ultra-text.makio.io/docs-tres) —
|
|
178
|
-
- [React Three Fiber guide](https://ultra-text.makio.io/docs-r3f) —
|
|
179
|
-
|
|
180
|
-
- [
|
|
145
|
+
- [TresJS guide](https://ultra-text.makio.io/docs-tres) — TresJS 5.10.0 · Vue 3.5.44
|
|
146
|
+
- [React Three Fiber guide](https://ultra-text.makio.io/docs-r3f) — R3F 9.8.2 · React 19.3.1 (plus R3F 10 alpha)
|
|
147
|
+
- [Mini3 & Vanilla JS guide](https://ultra-text.makio.io/docs-mini3) — Mini3 0.1.0-alpha.0 · `ultra-text/vanilla`
|
|
148
|
+
- [Agent skills](https://ultra-text.makio.io/skills) — `npx skills add Makio64/ultra-text` (`skills/ultra-text/` in git and npm)
|
|
181
149
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
Three.js runtime dependencies (`three` is an optional peer dependency). These starter
|
|
185
|
-
components are MIT consumer components to copy into your app, including with a coding agent;
|
|
186
|
-
they are not additional framework npm entry points. See the
|
|
150
|
+
Starters are MIT copyable source, not framework subpaths. Keep one Three.js copy in the peer range,
|
|
151
|
+
or zero Three.js with `ultra-text/vanilla`; see
|
|
187
152
|
[agent instructions](https://ultra-text.makio.io/integrations/AGENTS.md).
|
|
188
153
|
|
|
189
154
|
### Engine-agnostic Vanilla JS (`ultra-text/vanilla`)
|
|
190
155
|
|
|
191
|
-
|
|
192
|
-
Three.js:
|
|
156
|
+
No Three.js dependency (`31.7 kB` min+gzip / `28.4 kB` brotli for `DomText + Text`):
|
|
193
157
|
|
|
194
158
|
```ts
|
|
195
159
|
import { DomText } from 'ultra-text/vanilla'
|
|
@@ -204,11 +168,38 @@ const domText = await DomText.create(source, gpuDevice, {
|
|
|
204
168
|
})
|
|
205
169
|
```
|
|
206
170
|
|
|
207
|
-
|
|
208
|
-
`
|
|
209
|
-
|
|
210
|
-
`
|
|
211
|
-
|
|
171
|
+
Exports `DomText` (`DomSdf`, `VanillaDomText`), `Text` (`VanillaText`), `collectDomSnapshot`,
|
|
172
|
+
`reflowSnapshot`, `rasterizeGlyphAtlas`, `buildVanillaSdfAtlas` (`buildSdfAtlas`),
|
|
173
|
+
`buildVanillaGpuSdfAtlas`, `buildVanillaCpuSdfAtlas`, `packGlyphInstances`, `packRectInstances`,
|
|
174
|
+
`packDecorationInstances`, and `resolveDomTextTone`.
|
|
175
|
+
|
|
176
|
+
### Slug-only entries (`ultra-text/slug` and `ultra-text/slug-vanilla`)
|
|
177
|
+
|
|
178
|
+
Dedicated WebGPU curve entries with zero SDF/JFA/worker code and `0.17 MiB` paragraph VRAM:
|
|
179
|
+
`ultra-text/slug` (`40.9 kB` gz / `36.1 kB` br) and Three-free `ultra-text/slug-vanilla` (`33.7 kB`
|
|
180
|
+
gz / `30.1 kB` br):
|
|
181
|
+
|
|
182
|
+
```ts
|
|
183
|
+
import { DomText, Text, createTrueTypeOutlineProvider } from 'ultra-text/slug'
|
|
184
|
+
|
|
185
|
+
// Zero-config: lazily traces loaded fonts via Canvas 2D
|
|
186
|
+
const traced = await DomText.create(renderer, source)
|
|
187
|
+
|
|
188
|
+
// Exact outlines from an uncompressed .ttf ArrayBuffer
|
|
189
|
+
const ttfBuffer = await fetch('/fonts/Inter-Regular.ttf').then((r) => r.arrayBuffer())
|
|
190
|
+
const exact = new Text('Infinite zoom, zero SDF atlas', {
|
|
191
|
+
renderer,
|
|
192
|
+
slug: { outlineProvider: createTrueTypeOutlineProvider(ttfBuffer) },
|
|
193
|
+
css: { fontFamily: 'Inter', fontSize: 64, color: '#ffffff' },
|
|
194
|
+
})
|
|
195
|
+
await exact.ready
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
`ultra-text/slug-vanilla` exports `DomText`/`Text` (`VanillaDomSlug`/`VanillaSlugText`),
|
|
199
|
+
`buildVanillaSlugAtlas`, `packSlugGlyphInstances`, `SLUG_WGSL`, and `createVanillaSlugPipeline`.
|
|
200
|
+
Note: Slug-only entries omit the SDF companion used on `ultra-text` for bitmap emoji and
|
|
201
|
+
`outline`/`dropShadow` underlays; supply vector emoji with `createSvgEmojiOutlineProvider` when
|
|
202
|
+
needed.
|
|
212
203
|
|
|
213
204
|
## Markup contract
|
|
214
205
|
|
|
@@ -232,53 +223,35 @@ build without adding `aria-hidden`. Keep a separate semantic copy for any UI tha
|
|
|
232
223
|
|
|
233
224
|
## Coordinates and lifecycle
|
|
234
225
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
local dimensions.
|
|
226
|
+
Local `(0, 0)` sits at the root's bottom-left corner. X/Y divide CSS px by `pixelsPerUnit`; Z is
|
|
227
|
+
unscaled. `width` and `height` expose local bounds.
|
|
238
228
|
|
|
239
229
|
```ts
|
|
240
230
|
domSdf.setMotion({ enabled: true, mode: 'slide-up', speed: 0.8 })
|
|
241
231
|
|
|
242
|
-
await domSdf.rebuild() // Re-read
|
|
243
|
-
await domSdf.rebuild({ atlas: true }) // Force fresh SDF/Windfoil data.
|
|
232
|
+
await domSdf.rebuild() // Re-read DOM; reuse retained data when possible.
|
|
233
|
+
await domSdf.rebuild({ atlas: true }) // Force fresh SDF/Windfoil/Slug data.
|
|
244
234
|
|
|
245
235
|
console.table(domSdf.stats)
|
|
246
236
|
console.log(domSdf.width, domSdf.height, domSdf.atlasTexture)
|
|
247
237
|
```
|
|
248
238
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
shaders, so adding or changing lights never rebuilds them; shadow receivers stay lit.
|
|
260
|
-
|
|
261
|
-
By default, a root `ResizeObserver`, a subtree `MutationObserver`, and font-loading events
|
|
262
|
-
schedule coalesced rebuilds. Attribute-only mutation storms (a CSS transition, a JS tween)
|
|
263
|
-
are debounced, and a re-read that captures identical content stops before rebuilding
|
|
264
|
-
any geometry. Change detection hashes capture values directly, avoiding a serialized copy of
|
|
265
|
-
the entire layout. Set `observe: false` for manual control. Awaited builds reject normally;
|
|
266
|
-
`onError` receives errors from observer-scheduled rebuilds.
|
|
267
|
-
|
|
268
|
-
Rebuilds are atomic. A newer build aborts superseded work, and the previous rendered content
|
|
269
|
-
stays live until the replacement is ready. When retained text data and mesh structure are unchanged, a
|
|
270
|
-
rebuild reuses the compiled materials and meshes and only refreshes geometry; a capture that
|
|
271
|
-
is byte-identical to the current content stops right after the DOM read.
|
|
272
|
-
Rectangle and decoration replacements are staged with the text: an allocation failure
|
|
273
|
-
releases the replacements and preserves the previous meshes and material uniforms.
|
|
274
|
-
|
|
275
|
-
`dispose()` is idempotent. It cancels builds, disconnects observers, and releases every
|
|
276
|
-
geometry, material, texture, and render target created by the instance. The renderer, scene,
|
|
277
|
-
source HTML, lights, and cameras remain yours.
|
|
239
|
+
- **Static-first materials**: `mode: 'none'` (and `createWindfoilShapes`) omits motion graphs from
|
|
240
|
+
shaders. The first `setMotion()` to another mode compiles animated materials once; subsequent
|
|
241
|
+
changes (`'none'` included) update uniforms only. Text and unlit rects never compile light/AO
|
|
242
|
+
graphs; shadow-receiving rects stay lit.
|
|
243
|
+
- **Observers & atomic rebuilds**: root `ResizeObserver`, `MutationObserver`, and `document.fonts`
|
|
244
|
+
coalesce updates (pass `observe: false` for manual `rebuild()`). Rebuilds hash snapshots directly,
|
|
245
|
+
skip identical content after DOM read, abort superseded work, stage replacements safely, and swap
|
|
246
|
+
only when ready (`onError` catches observer errors).
|
|
247
|
+
- **Idempotent `dispose()`**: cancels in-flight work, disconnects observers, and frees owned
|
|
248
|
+
resources without touching renderer, scene, DOM, or `sharedAtlas`.
|
|
278
249
|
|
|
279
250
|
## Dynamic text and reflow
|
|
280
251
|
|
|
281
|
-
Reserve
|
|
252
|
+
Reserve future glyphs for dynamic readouts so rebuilds never re-bake the atlas (`rebuild()` still
|
|
253
|
+
reuses retained data whenever the glyph set is a subset, or you can share one `sharedAtlas` across
|
|
254
|
+
instances — each falls back to a private atlas only on a missing glyph):
|
|
282
255
|
|
|
283
256
|
```ts
|
|
284
257
|
const domSdf = await DomSdf.create(renderer, source, {
|
|
@@ -286,87 +259,40 @@ const domSdf = await DomSdf.create(renderer, source, {
|
|
|
286
259
|
})
|
|
287
260
|
|
|
288
261
|
readout.textContent = `${ms.toFixed(1)} ms`
|
|
289
|
-
await domSdf.rebuild() // stats.atlasBuildMs
|
|
262
|
+
await domSdf.rebuild() // stats.atlasBuildMs === 0 while glyphs match
|
|
290
263
|
```
|
|
291
264
|
|
|
292
|
-
|
|
293
|
-
already available. Removing text and restoring those glyphs does not rebake. A new text glyph
|
|
294
|
-
is usually drawn into the SDF atlas in place (see below); a new font, or a glyph that cannot be
|
|
295
|
-
patched in, rebuilds the data for the current capture. `extraGlyphs` keeps future characters
|
|
296
|
-
reserved.
|
|
297
|
-
They are reserved as written, so list capitals for `text-transform: uppercase` copy.
|
|
298
|
-
Use `rebuild({ atlas: true })` to regenerate or compact the retained data explicitly.
|
|
299
|
-
|
|
300
|
-
`extraGlyphs` prevents rebaking. A rebuild whose glyph count and attribute layout match the
|
|
301
|
-
retained geometry writes the new rects, UVs, colours and depth into those buffers instead of
|
|
302
|
-
allocating replacements. A count change still replaces the geometry. The DOM read and the GPU
|
|
303
|
-
upload of the changed attributes remain. Coalesce and await manual rebuilds for low-cadence copy,
|
|
304
|
-
and always handle awaited or observed errors.
|
|
305
|
-
|
|
306
|
-
Several groups can share one atlas. Build it once, pass it as `sharedAtlas`, and dispose it
|
|
307
|
-
yourself after the instances are gone. An instance whose capture needs a glyph the atlas does
|
|
308
|
-
not contain builds a private atlas instead of mutating the shared one.
|
|
309
|
-
|
|
310
|
-
For fast width-only changes, retain the capture and re-wrap from its measured advances:
|
|
265
|
+
For fast width-only re-wrapping without reading the DOM, baking, or reallocating buffers:
|
|
311
266
|
|
|
312
267
|
```ts
|
|
313
268
|
const domSdf = await DomSdf.create(renderer, source, { reflowable: true })
|
|
314
269
|
domSdf.reflow(560)
|
|
315
270
|
```
|
|
316
271
|
|
|
317
|
-
`reflow()`
|
|
318
|
-
|
|
319
|
-
stagger
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
differently from the browser, and with `pixelSnap` a right-aligned or justified line can move
|
|
336
|
-
one quarter-pixel snap step. RTL scripts need `rtlReflow: true`. A capture made without
|
|
337
|
-
`OffscreenCanvas` (jsdom) records no natural word spaces, so its justified blocks reflow at their
|
|
338
|
-
measured spacing. Use `rebuild()` when CSS layout must be measured again.
|
|
339
|
-
|
|
340
|
-
A rebuild that adds text glyphs to an instance's own SDF atlas draws them into its free text rows
|
|
341
|
-
in place instead of baking a new atlas. Only the new glyphs are measured, drawn and encoded, with
|
|
342
|
-
the atlas's own encoder (the GPU jump flood for a GPU atlas, the exact CPU transform for a CPU
|
|
343
|
-
atlas); they are then copied into the live texture and its mipmaps are regenerated, so the
|
|
344
|
-
texture and the compiled materials stay. Patched glyphs match a full build exactly on a CPU atlas
|
|
345
|
-
and within one 8-bit step on a GPU atlas. After its first new glyph, an instance builds its
|
|
346
|
-
atlas with headroom: free rows of max(tallest text slot, a
|
|
347
|
-
quarter of the text rows) above any shapes and colour glyphs, in an atlas at least two widest
|
|
348
|
-
glyphs wide, which makes short texts' atlases 1.5–2.6 times larger. Glyphs that classify as
|
|
349
|
-
colour, SVG shapes, `rebuild({ atlas: true })` and webfont loads, Windfoil and Slug companions, a
|
|
350
|
-
caller's `sharedAtlas`, a lowered adaptive bake size, more than 2¹⁸ new texels, and glyphs that
|
|
351
|
-
do not fit rebuild the atlas in full; glyphs the text no longer uses stay until such a full
|
|
352
|
-
build. `ultra-text/vanilla` always rebuilds in full. On a 188-glyph text gaining one character
|
|
353
|
-
per rebuild (headless Chrome 156, Apple M3 Max, shared GPU, n = 50), the median time from
|
|
354
|
-
`rebuild()` to the first frame went from 9.0 to 6.7 ms with a GPU atlas and from 11.0 to 2.9 ms
|
|
355
|
-
with a CPU atlas; the first new glyph after a capture is still a full rebuild.
|
|
356
|
-
|
|
357
|
-
Reflow creates a new CPU snapshot with one shared clipping rectangle per block and places
|
|
358
|
-
words as it measures them, without retaining an intermediate word list.
|
|
272
|
+
`reflow()` preserves `text-align` and `text-align-last` (`left`, `center`, `right`, `justify`,
|
|
273
|
+
`start`/`end`), matches Chrome within 0.04 px (`0.06 px` justify) across 200–560 px tests, and
|
|
274
|
+
recomputes stagger in place (`0.041 ms` standalone CPU median at 1,000 glyphs / `0.326 ms` at
|
|
275
|
+
10,000 glyphs on Apple M3 Max, `2026-11-23`). It is a
|
|
276
|
+
block-flow pass: it skips `text-indent`, mixed line sizes, hyphenation, mixed bidi (RTL needs
|
|
277
|
+
`rtlReflow: true`, CJK `cjkLineBreaking: true`), floats, and rect geometry; call `rebuild()` when
|
|
278
|
+
CSS changes.
|
|
279
|
+
|
|
280
|
+
Both SDF (`DomSdf`/`DomText`) and analytic (`slug`/`windfoil`) instances patch new unseen glyphs
|
|
281
|
+
in-place after their first miss:
|
|
282
|
+
|
|
283
|
+
- On the first miss, SDF atlases allocate headroom (`1.5–2.6×` on small texts) and append new text
|
|
284
|
+
glyphs into free rows (`6.7 ms` vs `9.0 ms` GPU, `2.9 ms` vs `11.0 ms` CPU on 188 glyphs in
|
|
285
|
+
Chrome 156); full rebuilds occur on new fonts, colour/SVG glyphs, overflow (`rebuild({ atlas: true })`),
|
|
286
|
+
or `ultra-text/vanilla`.
|
|
287
|
+
- Analytic instances allocate tight cold buffers (`0.17 MiB` paragraph) and add headroom on the
|
|
288
|
+
first miss, cutting unseen-glyph Slug rebuilds from `8.61 → 2.89 ms` (TTF) and `10.91 → 4.14 ms`
|
|
289
|
+
(traced) in `2026-11-19` `vs-ecosystem`.
|
|
359
290
|
|
|
360
291
|
## Layout engines
|
|
361
292
|
|
|
362
|
-
- `range`
|
|
363
|
-
|
|
364
|
-
- `
|
|
365
|
-
It avoids one DOM geometry read per glyph, but models `white-space: normal`. It aligns and
|
|
366
|
-
justifies inside its own line pass, following `text-align-last`. Prefer `range` for `<br>`,
|
|
367
|
-
bidi-sensitive placement, floats, indentation, vertical writing, or exact CSS parity. On a
|
|
368
|
-
display scale other than 1 it reads up to 16 glyph boxes per capture, to learn which pixel the
|
|
369
|
-
browser rounds on.
|
|
293
|
+
- `range` (default): synchronous DOM `Range` capture for exact CSS placement and wrapping.
|
|
294
|
+
- `pretext`: async dynamic `@chenglou/pretext` Canvas pass (faster DOM read, models
|
|
295
|
+
`white-space: normal`; prefer `range` for `<br>`, bidi, floats, indent, vertical text, or exact CSS).
|
|
370
296
|
|
|
371
297
|
```ts
|
|
372
298
|
import { collectDomSnapshot } from 'ultra-text'
|
|
@@ -375,29 +301,12 @@ const exact = collectDomSnapshot(source)
|
|
|
375
301
|
const fast = await collectDomSnapshot(source, { layoutEngine: 'pretext' })
|
|
376
302
|
```
|
|
377
303
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
CSS pixels under device emulation), so it can sit half a pixel from the font's own descent
|
|
381
|
-
scaled to the size. Each glyph carries that rounded descent as `baselineOffset`, and both text
|
|
382
|
-
backends draw from it. Range captures and browser-shaped runs measure it through Canvas and
|
|
383
|
-
keep it only when it reproduces the text box the DOM reports; otherwise a Range glyph falls
|
|
384
|
-
back to the atlas or outline descent, and a shaped run to the descent Canvas reports at its
|
|
385
|
-
CSS size. Pretext builds its lines from the same rounded metrics, rounds the half-leading down
|
|
386
|
-
as the browser does, and takes a `normal` line height from the font's ascent plus descent.
|
|
387
|
-
|
|
388
|
-
Capture caches font metrics, glyph keys, and hidden/decoration ancestry within each read;
|
|
389
|
-
later captures refresh them so CSS and loaded-font changes stay visible. The glyph loops
|
|
390
|
-
avoid temporary object copies and redundant font assignments; layout-change detection hashes
|
|
391
|
-
each distinct glyph-key string once per capture. Browser shaping shares its Range, grapheme
|
|
392
|
-
segmenter, and Canvas context across blocks, and reuses descents for identical text at the
|
|
393
|
-
same font and size within a capture. The Range engine still measures each visible glyph for
|
|
394
|
-
exact placement. For width-only updates, use
|
|
395
|
-
`reflowable: true` and `reflow(width)` to avoid DOM capture entirely.
|
|
304
|
+
Both engines record browser baseline rounding (`baselineOffset` from rounded descent) and reuse
|
|
305
|
+
metrics/scratch caches within a capture.
|
|
396
306
|
|
|
397
307
|
### Optional language support
|
|
398
308
|
|
|
399
|
-
|
|
400
|
-
mixed-direction text, enable native browser shaping:
|
|
309
|
+
For joined scripts, ligatures, combining marks, and mixed bidi, opt into lazy `textShaping: 'browser'`:
|
|
401
310
|
|
|
402
311
|
```ts
|
|
403
312
|
const text = await DomText.create(renderer, source, {
|
|
@@ -405,165 +314,53 @@ const text = await DomText.create(renderer, source, {
|
|
|
405
314
|
})
|
|
406
315
|
```
|
|
407
316
|
|
|
408
|
-
|
|
409
|
-
Indic conjuncts, Hebrew marks, and grapheme sequences. Equivalent inline markup shares shaping
|
|
410
|
-
context. It uses Range layout and SDF; Windfoil needs `fallback: 'sdf'`. No shaping dependency
|
|
411
|
-
or font is bundled. Supply fonts that cover your text.
|
|
412
|
-
|
|
413
|
-
Requested shaping and SVG rasterization modules load alongside font preparation. A capture
|
|
414
|
-
requesting both SVG and browser shaping also loads those modules together. These imports
|
|
415
|
-
remain conditional; the default glyph path does not load them.
|
|
416
|
-
|
|
417
|
-
Shaping, animation, and atlas reuse operate per run; wide runs use atlas tiles. Resize through
|
|
418
|
-
`rebuild()` (automatic with observation), not `reflow(width)`. Low-level `collectDomSnapshot()`
|
|
419
|
-
returns a promise; pass the same `textShaping` option to `SdfTextMaterial`. Run masks can use
|
|
420
|
-
more atlas memory than reusable glyphs. Changes in font or paint style split shaping context.
|
|
421
|
-
Emoji sequences (ZWJ, skin tone, flags, keycaps, tags and presentation selectors) stay whole
|
|
422
|
-
with both layout engines, without requiring browser shaping. SDF emoji retain the browser's
|
|
423
|
-
colours, including within mixed shaped runs; `colorGlyphs: 'none'` restores silhouettes.
|
|
424
|
-
Arbitrary OpenType feature settings remain unsupported.
|
|
425
|
-
|
|
426
|
-
For the default glyph path, `cjkLineBreaking: true` enables basic CJK reflow punctuation rules,
|
|
427
|
-
and `rtlReflow: true` enables uniform RTL word reflow. Neither implements mixed bidi reordering.
|
|
428
|
-
The legacy `reshape(text)` hook receives text after CSS `text-transform`. It must preserve code
|
|
429
|
-
point boundaries and whitespace with Range, and cannot be combined with browser shaping.
|
|
430
|
-
`adaptiveBakeSize: true` separately allows lowering SDF resolution on atlas overflow. All three
|
|
431
|
-
booleans default to `false`.
|
|
317
|
+
Uses Range layout + SDF (Windfoil requires `fallback: 'sdf'`) with no bundled shaper or fonts; wide runs use atlas tiles. Emoji sequences stay whole on both layout engines; SDF emoji keep browser colours (`colorGlyphs: 'none'` for silhouettes). Vertical writing and arbitrary OpenType features are unsupported; resize via `rebuild()`, not `reflow()`.
|
|
432
318
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
A browser blends its glyph mask on sRGB-encoded values; a scene blends coverage in linear
|
|
436
|
-
light. The same glyph therefore reads differently in the two: in linear light, dark text on a
|
|
437
|
-
light background comes out lighter and thinner than in the page, and light text on a dark
|
|
438
|
-
background heavier. `tone` converts the coverage of text ink so that the linear-light result
|
|
439
|
-
lands on the pixel the browser shows. It is on by default for both text backends, and it is
|
|
440
|
-
arithmetic on coverage the shader already has: no extra texture read and no extra draw.
|
|
441
|
-
|
|
442
|
-
```ts
|
|
443
|
-
// The page behind `source` is white, but the scene shows this text on a dark wall.
|
|
444
|
-
const label = await DomText.create(renderer, source, {
|
|
445
|
-
tone: { backdrop: '#101418' },
|
|
446
|
-
})
|
|
319
|
+
Opt-in booleans (all default `false`): `cjkLineBreaking`, `rtlReflow`, and `adaptiveBakeSize` (shrinks SDF bake size on overflow instead of rejecting). Legacy `reshape(text)` cannot be combined with browser shaping.
|
|
447
320
|
|
|
448
|
-
|
|
449
|
-
const exact = await DomText.create(renderer, source, { tone: false })
|
|
450
|
-
```
|
|
321
|
+
## Matching the browser
|
|
451
322
|
|
|
452
|
-
|
|
453
|
-
| ------------ | -------- | --------------------------------------------------------------------------------------------- |
|
|
454
|
-
| `backdrop` | `'auto'` | Colour the text is read against: a hex value, a colour name, comma-separated `rgb()`/`hsl()`. |
|
|
455
|
-
| `model` | `'auto'` | Rasterizer to imitate: `'outline'`, `'macos'` or `'windows'`. |
|
|
456
|
-
| `strength` | `1` | From `0` to `1`: how much of the conversion applies. |
|
|
457
|
-
|
|
458
|
-
Each capture resolves the `'auto'` values from the page, never in the render loop:
|
|
459
|
-
|
|
460
|
-
- **Model.** The platform and the source element's computed CSS decide. macOS with default
|
|
461
|
-
font smoothing gives `'macos'`: CoreGraphics smoothing, which also grows every outline by
|
|
462
|
-
min(0.0058 em, 0.30 px) to either side and twice that upwards, below 256 device pixels per
|
|
463
|
-
em. macOS with `-webkit-font-smoothing: antialiased` or `none`,
|
|
464
|
-
`-moz-osx-font-smoothing: grayscale` or `text-rendering: geometricPrecision` gives
|
|
465
|
-
`'outline'`, exact outline coverage. Windows gives `'windows'`, Skia's contrast table.
|
|
466
|
-
Linux, Android, iOS and iPadOS give `'outline'`.
|
|
467
|
-
- **Backdrop.** What the capture draws behind the text (its rectangles and root background),
|
|
468
|
-
over the nearest opaque CSS background colour behind the source element. One backdrop
|
|
469
|
-
serves a whole capture: the one behind most of its text.
|
|
470
|
-
- **Unknown backdrop.** Where nothing can tell (no opaque background colour behind the
|
|
471
|
-
source, a background image in front of it, a `Text`, whose source is hidden, or a material
|
|
472
|
-
you build yourself), dark text gets the weight it has on a white page and light text keeps
|
|
473
|
-
its exact coverage: it is neither thinned nor lifted.
|
|
474
|
-
|
|
475
|
-
Set `tone.backdrop` to the colour your scene shows behind the text whenever that is not the
|
|
476
|
-
page's: text captured from a white page and shown on a dark wall, a `Text`, a standalone
|
|
477
|
-
`SdfTextMaterial`, or your own backdrop mesh on a transparent canvas. A `Text` whose CSS
|
|
478
|
-
gives it an opaque `background` of its own already knows its backdrop.
|
|
323
|
+
Because browsers blend glyph coverage on sRGB values while 3D scenes blend in linear light, `tone` (on by default across all backends) adjusts coverage arithmetically in shader with zero extra texture reads or draws:
|
|
479
324
|
|
|
480
325
|
```ts
|
|
481
|
-
const
|
|
482
|
-
|
|
483
|
-
css: { fontSize: 48, color: '#ffffff' },
|
|
484
|
-
tone: { backdrop: '#101418' },
|
|
485
|
-
})
|
|
326
|
+
const label = await DomText.create(renderer, source, { tone: { backdrop: '#101418' } })
|
|
327
|
+
const exact = await DomText.create(renderer, source, { tone: false }) // exact font outline coverage
|
|
486
328
|
```
|
|
487
329
|
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
`outline` or `dropShadow` converts as opaque ink. Emoji and other colour glyphs, SVG paint,
|
|
494
|
-
outline rings, drop shadows and shadow masks keep their exact coverage. `strength` scales
|
|
495
|
-
the conversion, not the `'macos'` model's outline growth: use `tone: false` or the
|
|
496
|
-
`'outline'` model for the font's own outline.
|
|
330
|
+
| `tone` field | Default | Meaning |
|
|
331
|
+
| ------------ | -------- | ------------------------------------------------------------------ |
|
|
332
|
+
| `backdrop` | `'auto'` | Background colour behind text (hex, name, comma `rgb()`/`hsl()`). |
|
|
333
|
+
| `model` | `'auto'` | Platform rasterizer model: `'outline'`, `'macos'`, or `'windows'`. |
|
|
334
|
+
| `strength` | `1` | Weight scaling `0..1` (does not scale `'macos'` outline dilation). |
|
|
497
335
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
`stemDarkening`); the weight comes from `tone` alone.
|
|
336
|
+
- **`model` resolution**: macOS default smoothing → `'macos'` (CoreGraphics weight + min(0.0058 em, 0.30 px) sideways / 2× upwards below 256 device px/em); macOS `antialiased`/`none` or `geometricPrecision`, Linux, Android, iOS → `'outline'`; Windows → `'windows'` (Skia contrast table).
|
|
337
|
+
- **`backdrop` resolution**: uses captured rects / opaque ancestor background; falls back to black-on-white defaults on transparent canvas overlays, `Text`, or `SdfTextMaterial` unless `tone.backdrop` is set. Translucent ink weights as browser-blended; colour glyphs, SVG paints, outlines, and shadows keep exact coverage. SDF text bakes the font outline (`threshold: 0.5`, `stemDarkening: 0`) so weight comes from `tone` alone.
|
|
501
338
|
|
|
502
339
|
### Pixel snapping
|
|
503
340
|
|
|
504
|
-
|
|
505
|
-
upright text on a whole pixel row, and each glyph origin on a quarter of a device pixel while
|
|
506
|
-
the glyph is under 162 device pixels per em. `pixelSnap: true` moves captured lines and glyph
|
|
507
|
-
origins there, with no extra DOM read:
|
|
508
|
-
|
|
509
|
-
```ts
|
|
510
|
-
const overlay = await DomText.create(renderer, source, { pixelSnap: true })
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
Use it for text shown flat, unscaled and pixel-aligned over the page it was captured from.
|
|
514
|
-
It holds for the element's position at capture: capture again once the element has moved by a
|
|
515
|
-
fraction of a pixel. Under any other transform it only gives up the layout positions, so it
|
|
516
|
-
is off by default. `reflow()` snaps the re-wrapped layout again; browser-shaped runs take the
|
|
517
|
-
rows only, and inline SVG shapes are not moved.
|
|
341
|
+
`pixelSnap: true` (default `false`) aligns captured lines to whole device pixel rows and glyph origins to quarter pixels below 162 device px/em for flat 1:1 DOM overlays (`reflow()` re-snaps; recapture if moved sub-pixel).
|
|
518
342
|
|
|
519
343
|
### Multisampled targets
|
|
520
344
|
|
|
521
|
-
Windfoil pads
|
|
522
|
-
multisampled canvas or render target keeps the coverage of its edge samples. There is
|
|
523
|
-
nothing to set, and single-sampled passes keep the tighter quad. A 4× pass shades more
|
|
524
|
-
fragments per glyph for it: 30% more at 8 px per em and 4.5% more at 64 (Noto Sans, counted
|
|
525
|
-
on the GPU).
|
|
345
|
+
Windfoil automatically pads glyph quads on 4× MSAA targets to keep edge sample coverage (+30% fragments at 8 px/em, +4.5% at 64 px/em on Noto Sans).
|
|
526
346
|
|
|
527
347
|
### Measured limits
|
|
528
348
|
|
|
529
|
-
Measured
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
|
535
|
-
|
|
|
536
|
-
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
- Only Chrome on macOS was measured. The `'windows'` model and the choices for Linux and
|
|
546
|
-
Android follow Chromium's and Skia's source and were not run; Safari and Firefox were not
|
|
547
|
-
measured.
|
|
548
|
-
- From 162 to 255 device pixels per em, Chrome on macOS draws smoothed text whatever
|
|
549
|
-
`text-rendering: geometricPrecision` or `-webkit-font-smoothing: antialiased` ask for. The
|
|
550
|
-
library keeps the exact outline on such pages, so text in that band carries about 0.95 of
|
|
551
|
-
Chrome's ink (third row). A capture whose text all lies in the band can set
|
|
552
|
-
`tone: { model: 'macos' }`.
|
|
553
|
-
- At whole-pixel font sizes below about 18 device pixels, Chrome fits glyph heights to whole
|
|
554
|
-
pixels at some sizes: Lato capitals by up to 0.8 px between 9 and 17 px. The library draws
|
|
555
|
-
the font's outline at every size, as Chrome does at fractional sizes.
|
|
556
|
-
- At 16 CSS px and below, some sizes sit 1/8 to 1/4 px from Chrome vertically (52 of 416
|
|
557
|
-
measured cells), which costs up to 4.9 levels.
|
|
558
|
-
- From 256 device pixels per em, Chrome draws glyphs as paths with four coverage samples per
|
|
559
|
-
pixel. Exact coverage stays 16–21 levels from that on edge pixels, at equal ink.
|
|
560
|
-
- One backdrop serves a capture. Text of one capture that stands on several backgrounds is
|
|
561
|
-
toned for the one behind most of it; capture such regions separately for an exact match.
|
|
562
|
-
- With Windfoil, an inline SVG layer painted with the text colour is toned like the text.
|
|
563
|
-
Solid and gradient paints keep their exact coverage.
|
|
564
|
-
- The `'macos'` outline growth is approximate on a CPU-built atlas (0.26 px sideways and
|
|
565
|
-
0.28 px upwards at 96 px per em, where a GPU atlas gives 0.30 and 0.57), and is cut short
|
|
566
|
-
below about 10 device pixels per em at the default `bakeSize` and `padding`.
|
|
349
|
+
Measured 2026-10-08 in headless Chromium 153 on macOS 15 (Apple M3 Max) vs Chrome screenshots (mean 8-bit sRGB edge diff, lower is closer; ink ratio vs Chrome):
|
|
350
|
+
|
|
351
|
+
| Text, default options | `geometricPrecision`, 1× / 2× | Default smoothing, 1× / 2× | Ink |
|
|
352
|
+
| ------------------------------------ | ----------------------------- | -------------------------- | --------- |
|
|
353
|
+
| SDF, 9–24 CSS px | 15.5 / 13.7 | 16.9 / 14.0 | 0.95–1.06 |
|
|
354
|
+
| Windfoil, under 162 device px per em | 12.3 / 12.6 | 11.2 / 11.3 | 0.98–1.02 |
|
|
355
|
+
| Windfoil, 162–255 device px per em | 47.6 / 49.0 | 16.0 / 16.9 | 0.95–1.01 |
|
|
356
|
+
| Windfoil, from 256 device px per em | 17.7 / 16.7 | 17.7 / 16.7 | 1.00 |
|
|
357
|
+
|
|
358
|
+
(`tone: false` scored 44–47 vs 14–16 at 64–128 px; `pixelSnap` dropped 13–24 px sub-pixel overlays from 29–36 to 8–20.)
|
|
359
|
+
|
|
360
|
+
- Only Chrome/macOS was measured (Windows/Linux/Android follow Chromium/Skia source; Safari/Firefox unmeasured).
|
|
361
|
+
- 162–255 device px/em triggers macOS smoothing even under `geometricPrecision` (`tone: { model: 'macos' }` overrides).
|
|
362
|
+
- Chrome hints glyph heights below ~18 device px (`9–17 px`); ultra-text always uses true outline proportions.
|
|
363
|
+
- One backdrop serves the whole capture; split regions over distinct backgrounds. `'macos'` CPU-atlas dilation is approximate and clips below ~10 device px/em at default padding.
|
|
567
364
|
|
|
568
365
|
## Options
|
|
569
366
|
|
|
@@ -601,7 +398,7 @@ not a copy with defaults filled in.
|
|
|
601
398
|
| `cpuWorker` | `true` | Run CPU encoding in a cancellable Worker when available; `false` uses the main thread. |
|
|
602
399
|
| `fill` | — | TSL callback returning a linear RGBA fill inside each letter; works with every text backend and `createWindfoilShapes`. |
|
|
603
400
|
| `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,
|
|
401
|
+
| `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
402
|
| `outline` | — | Optional outline with local-unit `width`, `color`, and `opacity`, drawn from an SDF on every text backend. |
|
|
606
403
|
| `dropShadow` | — | Optional hard shadow with local-unit `offsetX`/`offsetY`, `color`, and `opacity`, drawn from an SDF on every text backend. |
|
|
607
404
|
| `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`. |
|
|
@@ -627,19 +424,11 @@ not a copy with defaults filled in.
|
|
|
627
424
|
|
|
628
425
|
</details>
|
|
629
426
|
|
|
630
|
-
|
|
631
|
-
baked `threshold`, no `stemDarkening`, and its weight left to [`tone`](#matching-the-browser).
|
|
632
|
-
`quality: 'high'` is for minified or steeply angled SDF text, where its four taps and mipmaps
|
|
633
|
-
steady the edges; at 1:1 its wider filter draws small text lighter than the browser does. Raise
|
|
634
|
-
`bakeSize` and `padding` together for unusually large or oblique text, and adjust `threshold`
|
|
635
|
-
only slightly around its default. `threshold`, `stemDarkening` and `quality` are ignored by
|
|
636
|
-
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.
|
|
427
|
+
`quality: 'standard'` matches 1:1 DOM text closest; `'high'` (4-tap sampling + mipmaps + anisotropy) steadies minified/oblique SDF text. Raise `bakeSize` and `padding` together for oversized/tilted display copy.
|
|
638
428
|
|
|
639
429
|
### Text effects, custom fills, and vertex hooks
|
|
640
430
|
|
|
641
|
-
`DomText.create()
|
|
642
|
-
accept custom TSL `fill` and `vertex` callbacks alongside SDF `outline` and `dropShadow` effects:
|
|
431
|
+
`DomText.create()`, `Text`, `SdfTextMaterial`, and `createWindfoilShapes` accept TSL `fill` and `vertex` hooks (`outline` and `dropShadow` work on all text backends; they never execute per frame on CPU):
|
|
643
432
|
|
|
644
433
|
```ts
|
|
645
434
|
import { mix, sin, time, vec3, vec4 } from 'three/tsl'
|
|
@@ -660,93 +449,20 @@ const text = await DomText.create(renderer, source, {
|
|
|
660
449
|
})
|
|
661
450
|
```
|
|
662
451
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
`
|
|
667
|
-
`position` (animated capture-local position), `color` (per-pixel linear RGB), `colorWeight`
|
|
668
|
-
(0 for CSS-tinted ink, 1 for baked colour ink), and `glyphIndex`
|
|
669
|
-
(the drawable index, which can change after a rebuild; layered Windfoil and its SDF companion
|
|
670
|
-
share a capture-order ordinal, so it stays continuous across `sdfBelowPx`). It is a whole number
|
|
671
|
-
at each pixel of a glyph, so `array.element(int(glyphIndex))` reads that glyph's entry. Return a `vec4`
|
|
672
|
-
containing linear RGB and an opacity multiplier. Glyph coverage, DOM opacity, motion, and block
|
|
673
|
-
clipping remain applied. Custom opacity also masks scene shadows. Use TSL `time`, uniforms, noise,
|
|
674
|
-
or `texture(myTexture, uv)` for animated, procedural, or textured letters; the caller owns
|
|
675
|
-
those uniforms and textures. SDF UVs include the glyph's baked padding. The fill hook works
|
|
676
|
-
with SDF, Windfoil, and Slug; it does not shade decorations, outlines, or drop shadows. With
|
|
677
|
-
[`tone`](#matching-the-browser) on, filled ink is weighted for the fill's own colour at each
|
|
678
|
-
pixel; pass `tone: false` when a fill paints artwork, such as a texture, rather than ink. On SDF,
|
|
679
|
-
style text while retaining emoji colours with `vec4(mix(myGradient, color, colorWeight), 1)`;
|
|
680
|
-
a fill that ignores `color` also recolours those emoji. Windfoil and Slug apply the fill to
|
|
681
|
-
foreground layers; fixed solid and gradient paints retain their own colours and alpha. CSS text alpha
|
|
682
|
-
and effective opacity multiply SDF colour glyphs once; outline, drop-shadow and scene-shadow
|
|
683
|
-
colours use the SDF silhouette.
|
|
684
|
-
|
|
685
|
-
`vertex` receives `position` (the rendered local `vec3` corner after built-in motion, `sdfTrim`
|
|
686
|
-
tightening, `outline`/`dropShadow` padding, and Windfoil/Slug edge skirts), `center` (un-animated
|
|
687
|
-
local `vec2` glyph anchor, shared across shaped runs, paint layers, companions, and decorations),
|
|
688
|
-
`uv` (corner UV in `0..1`, including SDF trim or effect padding when active), `glyphIndex`
|
|
689
|
-
(drawable instance index), `sequence` (per-line stagger index), `rect` (`[x0, y0, x1, y1]` glyph
|
|
690
|
-
bounding box in capture-local coordinates), and `clip` (`[x0, y0, x1, y1]` block clip rectangle in
|
|
691
|
-
capture-local coordinates). Return the final local `vec3` corner position. Block clipping reads the
|
|
692
|
-
pre-hook position, so 3D waves, twists, and Z-extrusions are not clipped at a block's static
|
|
693
|
-
bounds; size-switch rejected quads collapse after the hook. `vertex` runs on SDF, Windfoil, Slug,
|
|
694
|
-
their SDF companion and effect underlays, `DomText`/`DomSdf` text decorations, and
|
|
695
|
-
`createWindfoilShapes`.
|
|
696
|
-
|
|
697
|
-
Outlines and drop shadows are drawn from an SDF on every text backend. On `'windfoil'` and
|
|
698
|
-
`'slug'`, glyphs drawn from outlines keep their analytic fill and take their ring and shadow from
|
|
699
|
-
an SDF underlay: those glyphs are also baked into the SDF companion atlas, and one extra draw at
|
|
700
|
-
the text's own render order lays the ring and shadow under the fill, blended to match
|
|
701
|
-
single-pass SDF text (no light seam inside the ring, no gap at concave corners, no shadow through
|
|
702
|
-
see-through ink; exact without `tone`, and for opaque ink with it). Glyphs without outlines and
|
|
703
|
-
size-switched glyphs below `sdfBelowPx` are plain SDF text with their effects. The ring keeps SDF
|
|
704
|
-
edges under magnification, and an outline of width or opacity 0, or a shadow of opacity 0, draws
|
|
705
|
-
and bakes nothing. For a 77-glyph paragraph (headless Chrome 156, Apple M3 Max), Windfoil alone
|
|
706
|
-
holds no atlas and 45,840 bytes in one draw; with an outline it adds a 1072×472 companion atlas,
|
|
707
|
-
for 551,824 bytes in two draws. The underlay sorts with its own text, but the colour and fallback
|
|
708
|
-
parts of separate texts sort by render order rather than depth, and with
|
|
709
|
-
`renderer.sortObjects = false` the underlay draws over its fill. Width and offsets use local units (CSS pixels divided by `pixelsPerUnit`); positive Y points up.
|
|
710
|
-
An empty `outline` uses a black, fully opaque, 1-unit outline. An empty `dropShadow` uses
|
|
711
|
-
black at 0.5 opacity with offsets `(2, -2)`. Opacity is clamped to `0..1`; widths must be
|
|
712
|
-
non-negative and all numeric effect options must be finite. Effects remain clipped to the
|
|
713
|
-
marked text block, so leave room around its content when an effect should extend outward.
|
|
714
|
-
|
|
715
|
-
The outline expands outward and is limited to slightly less than half the atlas pixel
|
|
716
|
-
range, scaled to the glyph size. Increase `padding` to bake a wider usable field. Sampling
|
|
717
|
-
is clamped to each atlas cell to keep shifted lookups within that glyph. Drop
|
|
718
|
-
shadows are hard silhouettes with antialiased edges, without blur. They appear in the text
|
|
719
|
-
plane; `castShadow` still controls scene shadow casting independently.
|
|
720
|
-
|
|
721
|
-
Use `quality: 'high'` to apply the same four-sample antialiasing to fills, outlines, and drop
|
|
722
|
-
shadows. Thin outlines expose the baked contour more readily than plain fills; for large
|
|
723
|
-
display text, start with `bakeSize: 192` and `padding: 24`, as in the text lab. A denser bake
|
|
724
|
-
uses more atlas memory and takes longer to build. CPU and GPU fields can still differ in
|
|
725
|
-
their contour reconstruction; increasing canvas resolution alone does not remove atlas steps.
|
|
726
|
-
|
|
727
|
-
Solid CSS `underline`, `overline`, and `line-through` decorations are captured automatically,
|
|
728
|
-
including ancestor decorations, color, thickness, and underline offset. They use a separate
|
|
729
|
-
instanced batch, share glyph clipping and motion, and follow `reflow()`. Default/from-font
|
|
730
|
-
thickness and line positions use font-metric approximations; skip-ink, wavy, dotted, dashed,
|
|
731
|
-
and double decorations are not reproduced. The captured decoration metadata is available
|
|
732
|
-
on `GlyphLayout` for lower-level renderers; `DomSdf` owns the automatic decoration batch.
|
|
733
|
-
|
|
734
|
-
Open the interactive [text lab](https://ultra-text.makio.io/text-effects) to compare
|
|
735
|
-
worker/main-thread CPU baking with WebGPU and toggle each visual effect.
|
|
452
|
+
- **`fill({ uv, position, color, colorWeight, glyphIndex })`** → linear RGBA `vec4`. Coverage, DOM opacity, clipping, motion, and shadow masking remain applied. Pass `tone: false` for textured/painted fills; on SDF, mix via `colorWeight` to keep emoji colours.
|
|
453
|
+
- **`vertex({ position, center, uv, glyphIndex, sequence, rect, clip })`** → displaced local `vec3`. Clipping runs pre-hook so Z waves do not get clipped; runs across beauty, shadow passes, decorations, and companions.
|
|
454
|
+
- **Outlines & drop shadows**: rendered from SDF on every backend (analytic backends add an SDF companion underlay batch in 2 draws: e.g. 45,840 B in 1 draw vs 551,824 B in 2 draws on 77 glyphs in Chrome 156 / M3 Max). Outlines cap below half `padding`; drop shadows are hard silhouettes (no blur). Empty `outline` defaults to black `1` unit; empty `dropShadow` to black `0.5` opacity at `(2, -2)`.
|
|
455
|
+
- **Decorations**: solid CSS `underline`, `overline`, and `line-through` capture into an instanced batch that tracks `reflow()` and motion (wavy/dotted/double/skip-ink omitted). See the [text effects lab](https://ultra-text.makio.io/text-effects).
|
|
736
456
|
|
|
737
457
|
### Experimental Windfoil and Slug backends
|
|
738
458
|
|
|
739
|
-
|
|
740
|
-
resolver that returns OpenType-style, Y-up quadratic outlines, or omit it to trace the browser's
|
|
741
|
-
own glyphs:
|
|
459
|
+
Supply OpenType Y-up closed quadratic outlines (`outlineProvider`), or omit it to trace browser glyphs at 256 px/em (~0.006 em accuracy, ~0.5–0.6 ms Latin / 1.1–1.2 ms CJK on main thread in ~8 ms slices, cached per instance):
|
|
742
460
|
|
|
743
461
|
```ts
|
|
744
462
|
import { DomText, type WindfoilOutlineProvider } from 'ultra-text'
|
|
745
463
|
|
|
746
|
-
// No outlineProvider: outlines traced from the browser's own glyphs at 256 px per em
|
|
747
464
|
const traced = await DomText.create(renderer, source, { textBackend: 'slug' })
|
|
748
465
|
|
|
749
|
-
// Exact outlines from an app-owned resolver
|
|
750
466
|
const outlineProvider: WindfoilOutlineProvider = (request, signal) =>
|
|
751
467
|
myFontRegistry.resolveQuadraticOutline(request, signal)
|
|
752
468
|
|
|
@@ -756,53 +472,7 @@ const domText = await DomText.create(renderer, source, {
|
|
|
756
472
|
})
|
|
757
473
|
```
|
|
758
474
|
|
|
759
|
-
|
|
760
|
-
Once `document.fonts.load()` resolves, a glyph is drawn at 256 px per em on the SDF bake's
|
|
761
|
-
in-document canvas (the captured canvas font with its stretch and kerning, no font smoothing),
|
|
762
|
-
and its half-coverage contour is fitted with quadratic curves. Against Noto Sans Regular's own
|
|
763
|
-
outlines (94 printable ASCII glyphs, headless Chrome 156 on macOS, Apple M3 Max), traced outlines
|
|
764
|
-
stay within 0.006 em (mean deviation 0.0002 em), keep every glyph's contour count and winding,
|
|
765
|
-
and hold 1.3 times the font's curves (Slug buffers of 381 kB against 180 kB from exact outlines).
|
|
766
|
-
Edges stay analytic under magnification but follow that raster, not the font file; supply a
|
|
767
|
-
provider for exact edges. Font-variation and feature settings are not applied, `fallback`
|
|
768
|
-
defaults to `'sdf-glyphs'`, and colour glyphs, fonts the canvas rejects and glyphs whose ink
|
|
769
|
-
overflows their box are drawn by the SDF companion. Tracing runs on the main thread in slices of
|
|
770
|
-
about 8 ms, about 0.5–0.6 ms per Latin glyph and 1.1–1.2 ms per CJK glyph, and is cached per
|
|
771
|
-
instance; `rebuild({ atlas: true })` and webfont loads trace again. Other rasterizers and
|
|
772
|
-
browsers are unmeasured. A provider that is not a function rejects before anything is allocated.
|
|
773
|
-
|
|
774
|
-
`textBackend: 'slug'` uses an extrema-split dual-ray Slug evaluator (`slug` options, or `windfoil`
|
|
775
|
-
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`
|
|
777
|
-
by default). It shares the same outline provider contract, `fallback` modes, `sdfBelowPx` size
|
|
778
|
-
switch, colour layers, tone weighting, outline and drop-shadow underlay, and Pretext/Range
|
|
779
|
-
reflow as `'windfoil'`.
|
|
780
|
-
|
|
781
|
-
The provider owns font fallback and variation mapping. It must emit every closed contour edge,
|
|
782
|
-
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
|
|
785
|
-
keeps read-only curve/row buffers instead of a coverage texture. Each row band stores its curves
|
|
786
|
-
twice, sorted from either side, so a fragment integrates only the curves on its own side of the
|
|
787
|
-
band; `textStorageBytes` includes both copies. Adjacent band windows share their rounded
|
|
788
|
-
boundary and include neighbouring bands when necessary, keeping solid interiors continuous
|
|
789
|
-
under extreme magnification. Already monotone curves bypass temporary subdivision arrays
|
|
790
|
-
during preparation. A null outline either rejects or falls the whole capture back to SDF;
|
|
791
|
-
`fallback: 'sdf-glyphs'` (the default without an `outlineProvider`) retains available outlines
|
|
792
|
-
and adds one SDF companion for missing glyphs, whose colour emoji follow `colorGlyphs`. Lower
|
|
793
|
-
`targetPiecesPerBand` values trade more duplicated storage and preprocessing for less fragment
|
|
794
|
-
curve work; higher values do the reverse. Cache resolved outlines, honor the abort signal, and
|
|
795
|
-
avoid per-glyph network fetches. Requests using automatic optical sizing are separated by CSS font
|
|
796
|
-
size. Upstream describes the algorithm as novel and advises adopters to assess patent risk; see
|
|
797
|
-
[texel-org/windfoil](https://github.com/texel-org/windfoil) and the included
|
|
798
|
-
[third-party notice](./THIRD_PARTY_NOTICES.md).
|
|
799
|
-
|
|
800
|
-
The mixed mode paints its SDF companion above Windfoil, with decorations on top. Overlapping
|
|
801
|
-
glyphs or SVG paints split across those batches can therefore change painter order; use
|
|
802
|
-
whole-capture `fallback: 'sdf'` when that ordering must match the source exactly.
|
|
803
|
-
|
|
804
|
-
Windfoil text takes the same [`tone`](#matching-the-browser) as SDF text; `tone: false`
|
|
805
|
-
draws the exact outline area.
|
|
475
|
+
`ultra-text/slug` and `ultra-text/slug-vanilla` export `createTrueTypeOutlineProvider` (uncompressed `.ttf`) and `createTracedOutlineProvider`. Missing/colour outlines use whole-capture `fallback: 'sdf'` or per-glyph `'sdf-glyphs'` companion (companion paints above vectors). Lower `targetPiecesPerBand` trades more storage for less fragment work. Windfoil upstream advises assessing patent risk ([texel-org/windfoil](https://github.com/texel-org/windfoil), [Apache-2.0 notice](./THIRD_PARTY_NOTICES.md)).
|
|
806
476
|
|
|
807
477
|
#### Size switch: SDF while small (experimental)
|
|
808
478
|
|
|
@@ -813,37 +483,11 @@ const domText = await DomText.create(renderer, source, {
|
|
|
813
483
|
})
|
|
814
484
|
```
|
|
815
485
|
|
|
816
|
-
`
|
|
817
|
-
analytic Windfoil coverage once it is shown large. Plain single-paint outline glyphs, including
|
|
818
|
-
filled SVG paint layers, are also baked into the SDF companion atlas. For every glyph and every
|
|
819
|
-
render pass, the GPU measures the projected em: the font size times the largest stretch of the
|
|
820
|
-
local-to-pixel mapping at the glyph's centre, in render-target (device) pixels, so a 48 CSS px
|
|
821
|
-
heading at DPR 2 seen 1:1 measures 96. Below `sdfBelowPx` the glyph comes from the atlas; at or
|
|
822
|
-
above it, from Windfoil. Nothing runs on the CPU per frame, and shadow maps and other passes
|
|
823
|
-
decide with their own camera and resolution. `fallback` only governs glyphs without an outline,
|
|
824
|
-
and a value that is not a positive finite number rejects the build.
|
|
825
|
-
|
|
826
|
-
Setting it to `bakeSize` (96 by default) never magnifies the atlas beyond one texel per pixel;
|
|
827
|
-
lower both together, including with `adaptiveBakeSize`. The switch is immediate. Both sides
|
|
828
|
-
draw the font's own outline under the same tone, so little moves at the threshold: with Lato
|
|
829
|
-
and Noto Sans at the default bake, in Chromium 153 on an Apple M3 Max, the SDF companion
|
|
830
|
-
carried 0.99–1.00 of Windfoil's ink at 24 and 32 CSS px (1× and 2×), and its edges sat within
|
|
831
|
-
about 0.1 px of Windfoil's at 96 px per em.
|
|
832
|
-
|
|
833
|
-
Colour and layered glyphs and emoji always use Windfoil; glyphs without an outline always use
|
|
834
|
-
the companion, as `fallback` allows. Fills keyed on `uv` change at the switch, so key them on
|
|
835
|
-
`position` or `glyphIndex`. The companion costs one more atlas bake (about 1.1 MiB for
|
|
836
|
-
printable ASCII at the default bake) and one more draw per pass, and very large glyph sets can
|
|
837
|
-
exceed `maxAtlasSize` and reject the rebuild. The outline provider must return the face the
|
|
838
|
-
browser renders, or the switch shows a different design. Glyphs split between the two batches
|
|
839
|
-
follow the painter-order caveat above.
|
|
486
|
+
Per-frame GPU size test switches glyphs below `sdfBelowPx` device px/em to the SDF companion (~1.1 MiB for printable ASCII, 1 extra draw; colour/layer glyphs always stay vector). Set near `bakeSize`; key `fill` on `position` or `glyphIndex` rather than `uv`.
|
|
840
487
|
|
|
841
488
|
### SVG shapes (experimental)
|
|
842
489
|
|
|
843
|
-
`svgToWindfoilOutlines`
|
|
844
|
-
structural result of Three's `SVGLoader.parse()` into closed quadratic outlines. It is
|
|
845
|
-
synchronous and tree-shaken when unused. The smaller `windfoilOutlineFromSvgPaths` accepts
|
|
846
|
-
DOM-free path records in workers and Node without `DOMParser`.
|
|
490
|
+
`svgToWindfoilOutlines` (and DOM-free `windfoilOutlineFromSvgPaths`) convert SVG paths/shapes/gradients into quadratic outlines for `createWindfoilShapes`:
|
|
847
491
|
|
|
848
492
|
```ts
|
|
849
493
|
import { svgToWindfoilOutlines, createWindfoilShapes } from 'ultra-text'
|
|
@@ -852,304 +496,41 @@ const converted = svgToWindfoilOutlines(
|
|
|
852
496
|
'<svg viewBox="0 0 24 24"><path d="M12 2L22 22H2Z"/></svg>',
|
|
853
497
|
{ onWarning: (warning) => console.warn(warning.code, warning.message) },
|
|
854
498
|
)
|
|
855
|
-
const
|
|
856
|
-
const shapes = await createWindfoilShapes(renderer, outlines, [
|
|
499
|
+
const shapes = await createWindfoilShapes(renderer, { triangle: converted.outline }, [
|
|
857
500
|
{ shape: 'triangle', x: 20, y: 20, size: 64, color: '#fc0' },
|
|
858
501
|
])
|
|
859
502
|
scene.add(shapes)
|
|
860
503
|
shapes.setInstances([{ shape: 'triangle', x: 40, y: 20, size: 96 }])
|
|
861
|
-
//
|
|
862
|
-
shapes.dispose()
|
|
504
|
+
// shapes.dispose()
|
|
863
505
|
```
|
|
864
506
|
|
|
865
|
-
|
|
866
|
-
in local units. The scale is `size / unitsPerEm`.
|
|
867
|
-
`setInstances()` changes positions, colours, clipping and counts while keeping preprocessed
|
|
868
|
-
outlines. It validates the complete input before updating and reuses geometry buffers when
|
|
869
|
-
the expanded paint-layer count is unchanged.
|
|
870
|
-
Shapes are static by default (mode `'none'`): `setMotion()` updates uniforms, and the first other
|
|
871
|
-
mode swaps in an animated material once. The handle is a `Group` with `mesh` and frozen
|
|
872
|
-
`stats`; disposal is idempotent. It requires WebGPU and does not allocate an SDF atlas.
|
|
873
|
-
Instance `clip` rectangles work in both compositing modes; outline `clipBox` requires
|
|
874
|
-
`compositing: 'shader'`.
|
|
875
|
-
|
|
876
|
-
Separate calls using the same outlines record or `Map`, renderer, compositing mode and band
|
|
877
|
-
setting share prepared curves, layer indexes and GPU storage while any handle remains alive.
|
|
878
|
-
Keep the outlines container to reuse that work; newly allocated containers build independently.
|
|
879
|
-
Each call checks the outline contents, so edits build a new resource set while existing handles
|
|
880
|
-
retain their original artwork. Geometry, materials and motion remain independent. Disposing the
|
|
881
|
-
last handle releases the shared resources. A reuse reports `stats.preprocessMs: 0`;
|
|
882
|
-
`stats.storageBytes` reports each handle's full logical storage, including shared buffers, so
|
|
883
|
-
adding those values does not measure unique GPU allocation.
|
|
884
|
-
|
|
885
|
-
Shape handles accept `compositing: 'shader'`: one quad per instance composites its paint layers
|
|
886
|
-
top-down in the fragment shader and stops once a pixel is opaque, instead of blending one quad per
|
|
887
|
-
layer. Each artwork also gets an adaptive layer index: a quadtree whose cells list, top-down, only
|
|
888
|
-
the layers that can change a pixel there, classified exactly against the curves the shader
|
|
889
|
-
integrates. A pixel walks the deepest cell its footprint fits, so close zoom uses small cells. It
|
|
890
|
-
skips layers whose fill cannot reach the cell, takes full coverage without integrating from a layer
|
|
891
|
-
that covers the whole cell, and stops below the first such opaque one. The result matches walking
|
|
892
|
-
every layer, within 1/255 where a covering layer's integral would return 1 − ε. Composited layers
|
|
893
|
-
that a pixel crosses in fewer pieces along columns, typically wide and short ones, are integrated in
|
|
894
|
-
vertical bands. Outlines may hold up to 1024 layers, so large artwork composites in one quad.
|
|
895
|
-
|
|
896
|
-
Prefer shader compositing for densely layered or magnified artwork. On one Apple M3 Max whose GPU was
|
|
897
|
-
shared with other work, as ranges over four timing estimators and two sessions:
|
|
898
|
-
|
|
899
|
-
- On the 304-layer Ghostscript tiger in a 2048² frame, it took 1.5–2.2× less GPU time than the
|
|
900
|
-
previous 16×16 cell index at every size from 256 to 16384 px tall (2.02 against 4.24 ms at the
|
|
901
|
-
largest). Against upstream windfoil at its best band setting it was 2.2–5.5× faster from 1024 px
|
|
902
|
-
up, and level at 256 px.
|
|
903
|
-
- On the demo owl it took 1.0–1.5× less time than that index.
|
|
904
|
-
|
|
905
|
-
Per-layer quads (`'layers'`) still draw a thumbnail of detailed artwork faster: 1.3–1.6× on the tiger at
|
|
906
|
-
256 px. There, few pixels each walk several exact integrals in sequence, while per-layer quads run
|
|
907
|
-
them in parallel.
|
|
908
|
-
|
|
909
|
-
The index is built once per outline on the main thread, and the larger fragment shader compiles
|
|
910
|
-
more slowly. On the demo, switching to the three animals cost about 80 ms more for their indexes
|
|
911
|
-
(about 110 kB each) than with the previous grid. A cold first view also compiled 80–160 ms longer, on
|
|
912
|
-
top of the shader-compositing pipeline already costing about 90 ms more than per-layer quads. That was
|
|
913
|
-
measured on the same machine while other work loaded its CPU and GPU. Colour glyphs in DOM text get a
|
|
914
|
-
much smaller index. A table past the device's storage-binding limit falls back to one cell per glyph.
|
|
915
|
-
|
|
916
|
-
With shader compositing, instance opacity applies to the whole artwork, layers blend in encoded sRGB,
|
|
917
|
-
plain outlines draw as one foreground layer, and `stats.instances` counts drawn instances rather than
|
|
918
|
-
layers.
|
|
919
|
-
|
|
920
|
-
Conversion supports all SVG path commands, basic shapes, transforms, same-document
|
|
921
|
-
`use`/`symbol`, nested viewports, and nonzero/evenodd contour winding. Curves are approximated
|
|
922
|
-
within `tolerance` (default `unitsPerEm / 4000`), with bounded subdivision and warnings when
|
|
923
|
-
that bound cannot be met. Connected SVG elements can use `computedStyle: true`; markup does
|
|
924
|
-
not load stylesheets or network resources. `layers` preserves painter order and solid,
|
|
925
|
-
foreground, and supported gradient paints. `outline` is the merged monochrome result.
|
|
926
|
-
Self-intersecting evenodd contours warn and fall back to nonzero; pre-resolve them with an
|
|
927
|
-
SVG simplifier when exact parity is required. Stroke expansion, masks, filters, patterns and
|
|
928
|
-
arbitrary clipping are not supported by this converter; inspect `warnings` or use
|
|
929
|
-
`unsupported: 'error'` and `strokes: 'error'`.
|
|
507
|
+
Identical outline containers share GPU buffers across calls; `compositing: 'shader'` builds an adaptive quadtree layer index (up to 1024 layers/artwork in 1 quad: 1.5–2.2× less GPU time on the 304-layer tiger from 256–16384 px than the old 16×16 grid, 2.02 vs 4.24 ms at max size on M3 Max, at the cost of +80 ms CPU index build / +80–160 ms cold shader compile vs per-layer `'layers'` quads).
|
|
930
508
|
|
|
931
509
|
### Inline SVG
|
|
932
510
|
|
|
933
|
-
|
|
934
|
-
const text = await DomSdf.create(renderer, root, {
|
|
935
|
-
svg: { unsupported: 'error', maxPathData: 1_000_000 },
|
|
936
|
-
motion: { enabled: false, mode: 'none' },
|
|
937
|
-
})
|
|
938
|
-
```
|
|
939
|
-
|
|
940
|
-
`svg: true` opts in to SVGs inside text blocks and standalone SVGs inside the capture root.
|
|
941
|
-
The object form also accepts a `selector` (default `svg`). It requires Range layout and makes
|
|
942
|
-
`collectDomSnapshot` asynchronous. SVG paint layers share the text atlas, clipping, shadows
|
|
943
|
-
and motion; every layer of one icon moves together. CSS colours, fills, strokes, basic shapes
|
|
944
|
-
and element transforms are captured at rebuild time. SVG text and foreign content, external
|
|
945
|
-
references, filters, masks and arbitrary clip paths are not reproduced. `unsupported` defaults
|
|
946
|
-
to `'skip'`; `'error'` reports unsupported content. CSS/SMIL animation requires explicit
|
|
947
|
-
rebuilds. Root rotation/skew is rejected or skipped because capture layout is axis-aligned.
|
|
948
|
-
|
|
949
|
-
The SDF route uses native `Path2D` for exact fill rules, strokes, joins and dashes. Filled SVGs
|
|
950
|
-
can use Windfoil; stroke layers or ambiguous evenodd outlines follow `windfoil.fallback`.
|
|
951
|
-
`svg: { render: 'bitmap' }` stores all authored paint colours in a single SDF slot per SVG.
|
|
952
|
-
`images: true` also captures decoded images that pass a canvas taint probe; the library never
|
|
953
|
-
fetches their URLs. Capture images after loading them. Bitmap shapes remain colour candidates
|
|
954
|
-
regardless of the text `colorGlyphs` option. Bitmap capture composites nested SVG opacity
|
|
955
|
-
groups before rasterization, then applies root and DOM opacity once. Baked paint alpha still
|
|
956
|
-
uses the SDF silhouette: alpha below 50% is discarded, and interior alpha is hardened.
|
|
957
|
-
|
|
958
|
-
`stats.glyphs` counts text glyphs, `stats.shapes` counts SVG paint-layer instances, and
|
|
959
|
-
`stats.fallbackGlyphs` counts text glyphs without a Windfoil outline, drawn by the SDF
|
|
960
|
-
companion, and `stats.switchableGlyphs` counts instances the size switch can draw either way.
|
|
961
|
-
Atlas dimensions and `atlasTexture` describe that companion in mixed mode. `textStorageBytes`
|
|
962
|
-
includes curve, paint, composite-layer and companion texture storage. No GPU work runs on a steady frame
|
|
963
|
-
except rendering; capture and rasterization happen during rebuilds.
|
|
511
|
+
`svg: true` (or `{ render: 'bitmap', images: true, unsupported: 'error', maxPathData }`) captures inline SVGs alongside text (requires Range layout; SVG text/filters/masks/arbitrary clips are omitted).
|
|
964
512
|
|
|
965
513
|
### Colour layers and SVG emoji
|
|
966
514
|
|
|
967
|
-
|
|
968
|
-
optional tight `bbox`, and a `paint`. `{ type: 'foreground' }` uses the captured CSS colour;
|
|
969
|
-
`{ type: 'solid', color: [r, g, b, a] }` uses sRGBA components in 0–1. Nonempty top-level
|
|
970
|
-
quadratics form an initial foreground layer. All layers share one glyph's motion and
|
|
971
|
-
stagger index. Layer opacity multiplies captured text alpha once. In the default
|
|
972
|
-
`compositing: 'layers'` mode they use ordinary painter-order blending; overlapping partially
|
|
973
|
-
transparent layers apply opacity separately and abutting antialiased edges may show seams.
|
|
974
|
-
|
|
975
|
-
```ts
|
|
976
|
-
import { createSvgEmojiOutlineProvider } from 'ultra-text'
|
|
977
|
-
|
|
978
|
-
const outlineProvider = createSvgEmojiOutlineProvider({
|
|
979
|
-
text: fontOutlineProvider,
|
|
980
|
-
resolve: async (cluster, signal) => loadAppEmojiSvg(cluster, signal),
|
|
981
|
-
em: { unitsPerEm: 1000, ascent: 800, descent: -200 },
|
|
982
|
-
})
|
|
983
|
-
const text = await DomSdf.create(renderer, root, {
|
|
984
|
-
textBackend: 'windfoil',
|
|
985
|
-
windfoil: { outlineProvider, fallback: 'sdf-glyphs' },
|
|
986
|
-
})
|
|
987
|
-
```
|
|
988
|
-
|
|
989
|
-
The application owns the art and loading. `resolve` receives the original complete cluster
|
|
990
|
-
and returns SVG text or `null`; no artwork or network client ships in the library. The helper
|
|
991
|
-
caches converted emoji, centres them in the measured platform advance, and respects aborts.
|
|
992
|
-
Its cache uses Twemoji's filename convention: remove FE0F only for clusters without ZWJ,
|
|
993
|
-
then join lowercase hexadecimal code points with hyphens. FE0E requests use the text font.
|
|
994
|
-
Provide `em.descent` to select the reference baseline explicitly, or let the text provider
|
|
995
|
-
supply its metrics. That baseline sits on the captured text baseline; where a capture has
|
|
996
|
-
none, the bottom of the em box sits on the bottom of the text box. Keep emoji artwork
|
|
997
|
-
licences and attribution with your assets.
|
|
998
|
-
Translucent SVG groups containing multiple paints cannot be flattened faithfully into layers;
|
|
999
|
-
the helper returns `null` for those SVGs so the configured fallback can render them.
|
|
1000
|
-
|
|
1001
|
-
The demo's emoji comparison preserves the platform font instead of substituting SVG
|
|
1002
|
-
artwork. For Windfoil it vectorises each native emoji bitmap in the browser: regions of
|
|
1003
|
-
smoothly varying colour become layers with curve-fitted outlines, flat regions use solid
|
|
1004
|
-
paints, and `fill` paints the shaded ones from colour sheets cut from the same bitmap, with
|
|
1005
|
-
matching layout and glyph metrics. The first frame shows the traced bitmap; the layers
|
|
1006
|
-
replace it once the page is idle. Hard edges are analytic at any zoom, while gradients,
|
|
1007
|
-
glows, see-through artwork and detail about two texels wide keep the bitmap's softness.
|
|
1008
|
-
No traced artwork ships with the package.
|
|
1009
|
-
|
|
1010
|
-
Windfoil also accepts `linear`, `radial` and `sweep` gradient paints. Stops contain `offset`
|
|
1011
|
-
and sRGBA `color`; `extend` is `'pad'`, `'repeat'` or `'reflect'`. Paint coordinates are in
|
|
1012
|
-
outline font units; an optional affine transform maps the gradient into those units.
|
|
1013
|
-
Linear gradients use `p0`, `p1` and optional `p2`; radial gradients use `c0`, `r0`, `c1`, `r1`;
|
|
1014
|
-
sweeps use `center`, `startAngle` and `endAngle` in degrees. SVG linear/radial gradients are
|
|
1015
|
-
imported, including stop opacity and gradient transforms. Sweep gradients are authored through
|
|
1016
|
-
the paint API because SVG has no native sweep-gradient element. Gradient interpolation and
|
|
1017
|
-
shader layer compositing use encoded sRGB, then convert the resulting colour to linear RGB.
|
|
1018
|
-
|
|
1019
|
-
Opt-in `windfoil: { outlineProvider, compositing: 'shader' }` composites all layers of each
|
|
1020
|
-
colour glyph before applying text alpha. It gives correct whole-glyph group opacity and walks
|
|
1021
|
-
only the layers that can reach each pixel, stopping once it is opaque; nested SVG opacity groups
|
|
1022
|
-
are not represented.
|
|
1023
|
-
A glyph-local `clipBox: [xMin, yMin, xMax, yMax]` uses analytic
|
|
1024
|
-
rectangle coverage in `DomSdf` and automatically selects this composite path for that glyph, including
|
|
1025
|
-
base-only outlines and captures using `compositing: 'layers'`. Colour glyphs use their own instanced
|
|
1026
|
-
batch, and ordinary glyphs retain their simpler shader. The default remains `'layers'`;
|
|
1027
|
-
measure both modes on your target hardware for dense or large artwork. Shape handles support
|
|
1028
|
-
layer paints and gradients and accept the same `compositing` option.
|
|
1029
|
-
|
|
1030
|
-
An application adapting COLRv1 data must expand `PaintColrLayers` and `PaintColrGlyph` into
|
|
1031
|
-
ordered layers, bake outline transforms into the paths, and put paint-only transforms in
|
|
1032
|
-
the paint's `transform`. Only source-over composition is supported; map a font ClipBox to
|
|
1033
|
-
the outline's `clipBox`. Other composite modes, arbitrary clip paths, masks, filters and
|
|
1034
|
-
variable paints need an application fallback. Coincident antialiased edges can show seams;
|
|
1035
|
-
gradient output is not dithered.
|
|
515
|
+
`WindfoilGlyphOutline` supports up to 1024 solid, foreground, `linear`, `radial`, or `sweep` gradient layers with optional `clipBox`. Wrap your text provider with `createSvgEmojiOutlineProvider` (Twemoji hyphenated hex cache, app-owned SVG files) to draw vector emoji on analytic backends.
|
|
1036
516
|
|
|
1037
517
|
## Text backends and atlas modes
|
|
1038
518
|
|
|
1039
|
-
SDF
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
`
|
|
1043
|
-
|
|
1044
|
-
CPU upload copy is excluded. Captures without verified colour ink keep the original shader.
|
|
1045
|
-
`stats.colorGlyphs` counts captured text glyphs with colour ink, so a mixed browser run counts
|
|
1046
|
-
once. Low-level callers pass `atlas.colorLayer`, `atlas.bakeSize` and `atlas.shapeTop` to
|
|
1047
|
-
`SdfTextMaterial` and dispose the full atlas. `shapeTop` marks the atlas rows of monochrome SVG
|
|
1048
|
-
shapes, which keep their exact coverage while text takes the tone: keep it with the other
|
|
1049
|
-
fields wherever an atlas is copied or restored from stored bytes.
|
|
1050
|
-
Apple Color Emoji is a bitmap font whose largest strike is 160 px. In Chrome on macOS, a larger
|
|
1051
|
-
`bakeSize` resamples that bitmap and ripples emoji edges once magnified; bake large emoji at 160.
|
|
1052
|
-
|
|
1053
|
-
Colour extraction uses a byte visitation grid and dilates from the ink boundary. Temporary
|
|
1054
|
-
classification/queue arrays use five bytes per band texel, in addition to the four-byte RGBA
|
|
1055
|
-
output.
|
|
1056
|
-
|
|
1057
|
-
An atlas made with `colorGlyphs: 'none'` or an older library version has untested slots.
|
|
1058
|
-
Such an atlas is not reused for colour candidates: the capture builds a private atlas.
|
|
1059
|
-
Rebuild atlases stored by an earlier version: the bake no longer carries the platform's font
|
|
1060
|
-
smoothing, and the colour band's alpha now tells colour ink (1) from text ink (0).
|
|
1061
|
-
Whole emoji sequences use different keys from their former components, so rebuild shared
|
|
1062
|
-
atlases that were prepared per code point. Each sequence needs roughly a 1.2 em square slot.
|
|
1063
|
-
|
|
1064
|
-
`textBackend` chooses retained coverage. `atlasMode` only changes SDF generation:
|
|
1065
|
-
|
|
1066
|
-
`DOM → layout snapshot → Canvas glyph mask → SDF atlas → instanced geometry + TSL materials`
|
|
1067
|
-
|
|
1068
|
-
The transient mask uses deterministic shelf and skyline candidates across a bounded search
|
|
1069
|
-
of aligned widths. Glyphs are never rotated, and the smallest tested used area is retained.
|
|
1070
|
-
|
|
1071
|
-
- `gpu` requires a real `WebGPUBackend` and fails if one is unavailable, if the device's
|
|
1072
|
-
limits cannot hold the passes (workgroup size, storage buffers per stage, two of them in the
|
|
1073
|
-
fragment stage, the atlas's jump-flood buffers at 8 bytes per texel and its glyph-mask copy
|
|
1074
|
-
at 4 bytes per texel in 256-byte rows, or its largest 2D texture), if the backend cannot copy
|
|
1075
|
-
the mask into a buffer, or if the device reports an error for them. The passes read the mask
|
|
1076
|
-
from that buffer, so none of their pipelines samples a texture. It runs on
|
|
1077
|
-
compatibility-mode devices as well as core ones. The passes are WGSL compute and render
|
|
1078
|
-
passes on the renderer's own device, compiled once per device, and the atlas texture is an
|
|
1079
|
-
`ExternalTexture` the atlas owns.
|
|
1080
|
-
- `cpu` runs an exact Euclidean distance transform and uploads an R8 `DataTexture`.
|
|
1081
|
-
By default the transform runs in a short-lived module Worker; `cpuWorker: false` runs it
|
|
1082
|
-
on the main thread. Both modes produce identical bytes.
|
|
1083
|
-
- `auto` tries the GPU path first, then falls back to the CPU path in each of those
|
|
1084
|
-
cases, including when an atlas is too large for the GPU path.
|
|
1085
|
-
- `textBackend: 'windfoil'` resolves quadratic outlines, splits them into monotone pieces,
|
|
1086
|
-
files horizontal row bands, and evaluates analytic coverage per fragment. Beauty and
|
|
1087
|
-
shadow masks reject fragments outside the block before integrating curves.
|
|
1088
|
-
|
|
1089
|
-
Both SDF modes consume the same Canvas glyph mask and produce the same retained atlas.
|
|
1090
|
-
Windfoil has a separate lifecycle. It reports no atlas texture unless the opt-in mixed mode or size switch has an SDF companion.
|
|
1091
|
-
|
|
1092
|
-
Plain text glyphs draw only the part of their quad where the distance field is not empty:
|
|
1093
|
-
`rasterizeGlyphAtlas` records that box as `GlyphSlot.support`, `createGlyphGeometry` writes it
|
|
1094
|
-
per glyph as the `sdfTrim` attribute, and `SdfTextMaterial` shrinks each quad to it, which
|
|
1095
|
-
leaves about 60% fewer fragments for the same ink. Quads stay whole with outlines or drop
|
|
1096
|
-
shadows, with run motion, and over mipmapped atlases (`quality: 'high'` DomSdf captures). A
|
|
1097
|
-
custom position graph that places corners from `positionGeometry` itself should delete
|
|
1098
|
-
`sdfTrim` from its geometry; code that rewrites `sdfUvRect` to show another glyph keeps whole
|
|
1099
|
-
quads for those instances unless it rewrites `sdfTrim` with it.
|
|
1100
|
-
|
|
1101
|
-
The HTML/3D demo's SDF mode explicitly uses CPU atlases to reduce first-use GPU compilation for its
|
|
1102
|
-
small document; `?atlas=gpu` compares the GPU path. The package default remains `auto`.
|
|
1103
|
-
|
|
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.
|
|
1118
|
-
|
|
1119
|
-
`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
|
|
1123
|
-
encoding uses one 4-byte-per-texel working grid plus `28 × height + 8` bytes of column scratch,
|
|
1124
|
-
excluding the RGBA input, its alpha and the R8 output. DOM capture and the Canvas mask still
|
|
1125
|
-
run on the main thread, and so does the mask's `getImageData` readback for colour candidates and
|
|
1126
|
-
CPU atlases. CPU workers receive the mask's RGBA
|
|
1127
|
-
pixels, take their alpha and transfer the encoded bytes back; they terminate on completion or
|
|
1128
|
-
cancellation and preserve the previous content during transactional rebuilds. If Workers are unavailable or blocked by
|
|
1129
|
-
CSP, baking falls back to the synchronous CPU encoder. A cancellation never starts that
|
|
1130
|
-
fallback. Ship the generated worker asset with the package and allow it in `worker-src`.
|
|
1131
|
-
The GPU path is unchanged and does not create a CPU worker. Latency- and memory-constrained
|
|
1132
|
-
apps should cap `maxAtlasSize`, prefer strict `atlasMode: 'gpu'`, reserve known characters,
|
|
1133
|
-
and retain native UI if WebGPU initialization fails:
|
|
519
|
+
- **SDF (`textBackend: 'sdf'`, default)**: `DOM → layout snapshot → Canvas glyph mask → SDF atlas → instanced geometry + TSL materials`.
|
|
520
|
+
- GPU bake (`atlasMode: 'gpu'` / `'auto'`): writes mask once into a buffer, runs a **single tiled compute pass** (`tiledStoreMain`) directly to the `r8unorm` storage texture on `texture-formats-tier1` when `padding <= 12` (**1 lazily compiled compute pipeline** instead of 4; multi-pass `seed`/`jump`/`resolve` compile lazily only for larger `padding` or non-tier1 fallback). On Apple M3 Max / Chrome 157: **4.56 ms** GPU bake (`2026-11-22` W5; `5.35 ms` in `2026-11-19` `33.9 ms` cold full run), **`5.3 MiB`** peak VRAM (`0.64 MiB` resident). `sdfTrim` trims empty quad padding (~60% fewer fragments).
|
|
521
|
+
- CPU bake (`atlasMode: 'cpu'` or automatic fallback): exact EDT in a cancellable Worker (`cpuWorker: true`), uploading the identical R8 `DataTexture`.
|
|
522
|
+
- Colour glyphs (`colorGlyphs: 'emoji'` / `'all'`) share an optional sRGB RGBA band (~80 KB/emoji at `bakeSize: 96`; Apple Color Emoji max strike is 160 px on macOS).
|
|
523
|
+
- **Analytic (`'slug'` / `'windfoil'`)**: monotone-split curve buffers (`0.17 MiB` TTF / `0.21 MiB` traced for 1,000 glyphs); no atlas texture unless `outline`, `dropShadow`, or `sdf-glyphs` creates an SDF companion.
|
|
1134
524
|
|
|
1135
|
-
|
|
1136
|
-
const hud = await DomSdf.create(renderer, source, {
|
|
1137
|
-
atlasMode: 'gpu',
|
|
1138
|
-
maxAtlasSize: 1024,
|
|
1139
|
-
extraGlyphs: '0123456789.%+-/ms',
|
|
1140
|
-
observe: false,
|
|
1141
|
-
castShadow: false,
|
|
1142
|
-
motion: { enabled: false, mode: 'none' },
|
|
1143
|
-
})
|
|
1144
|
-
```
|
|
525
|
+
Perf-sensitive HUDs should set `atlasMode: 'gpu'`, `maxAtlasSize: 1024`, `extraGlyphs`, `observe: false`, `castShadow: false`, and `motion: { enabled: false, mode: 'none' }`.
|
|
1145
526
|
|
|
1146
527
|
## Public API
|
|
1147
528
|
|
|
1148
|
-
Import
|
|
529
|
+
Import from `ultra-text`, `ultra-text/slug`, `ultra-text/vanilla`, or `ultra-text/slug-vanilla` only; deep imports are unsupported.
|
|
1149
530
|
[`src/index.ts`](https://github.com/Makio64/ultra-text/blob/main/src/index.ts)
|
|
1150
|
-
defines
|
|
531
|
+
defines the root boundary, and
|
|
1151
532
|
[`src/types.ts`](https://github.com/Makio64/ultra-text/blob/main/src/types.ts)
|
|
1152
|
-
defines
|
|
533
|
+
defines public contracts.
|
|
1153
534
|
|
|
1154
535
|
| Export | Purpose |
|
|
1155
536
|
| --------------------- | ----------------------------------------------------------------------------------------------- |
|
|
@@ -1163,18 +544,7 @@ defines its public data contracts.
|
|
|
1163
544
|
| `createRectMaterial` | Build the lit or unlit TSL rounded-rectangle material; `DoubleSide` draws in one pass. |
|
|
1164
545
|
| `reflowSnapshot` | Re-wrap a retained snapshot without reading the DOM. |
|
|
1165
546
|
|
|
1166
|
-
`DomText` (
|
|
1167
|
-
`height`, `stats`, and `atlasTexture`, plus `setMotion()`, `reflow()`, `rebuild()`, and `dispose()`.
|
|
1168
|
-
`stats.textBackend` reports the active path. `atlasMode` is null for pure Windfoil; mixed mode reports its companion atlas, and
|
|
1169
|
-
`textStorageBytes` estimates retained texture or curve/row storage. `atlasTexture` is also
|
|
1170
|
-
null under pure Windfoil.
|
|
1171
|
-
|
|
1172
|
-
The package root also exports all matching TypeScript types. Callers own resources returned
|
|
1173
|
-
by the lower-level atlas, geometry, and material APIs.
|
|
1174
|
-
|
|
1175
|
-
The root also exports `svgToWindfoilOutlines`, `windfoilOutlineFromSvgPaths`,
|
|
1176
|
-
`createWindfoilShapes`, and `createSvgEmojiOutlineProvider`. All are imported from
|
|
1177
|
-
`'ultra-text'`; internal modules are not public package subpaths.
|
|
547
|
+
`DomText` (`DomSdf`) extends `THREE.Group` and exposes `width`, `height`, `stats`, `atlasTexture`, `setMotion()`, `reflow()`, `rebuild()`, and `dispose()`. Under pure Windfoil/Slug, `atlasTexture` and `atlasMode` are `null` (`textStorageBytes` reports curve/row storage). Callers own resources returned by lower-level helpers and types exported alongside `svgToWindfoilOutlines`, `windfoilOutlineFromSvgPaths`, `createWindfoilShapes`, and `createSvgEmojiOutlineProvider`.
|
|
1178
548
|
|
|
1179
549
|
### Exported types
|
|
1180
550
|
|
|
@@ -1235,181 +605,116 @@ Additional SVG/vector contracts are exported as types:
|
|
|
1235
605
|
|
|
1236
606
|
## Limitations
|
|
1237
607
|
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
- SDF silhouettes remain single-channel, without true-MSDF corner reconstruction. Colour
|
|
1241
|
-
glyphs use the canvas default palette; `font-palette` and `font-variant-emoji` are not
|
|
1242
|
-
captured. Interior raster alpha below 50% is outside the SDF silhouette. Colour detail
|
|
1243
|
-
magnifies at the baked resolution, while the silhouette retains its SDF edge.
|
|
1244
|
-
- Windfoil and Slug are experimental, WebGPU-only and nonzero-fill, and their edges are only as
|
|
1245
|
-
exact as their outlines: app-owned font outlines are exact, while traced outlines (no
|
|
1246
|
-
`outlineProvider`) follow the browser's raster at 256 px per em to about 0.006 em and cost
|
|
1247
|
-
main-thread time, about 1.2 ms per CJK glyph. They do not add shaping or CSS fidelity. Their
|
|
1248
|
-
antialiasing box is axis-aligned in glyph space and sized to each pixel's footprint, so rotated
|
|
1249
|
-
or sheared text approximates, rather than equals, an exact screen-pixel filter.
|
|
1250
|
-
- By default, glyphs are rasterized by code point, except whole emoji sequences. Emoji
|
|
1251
|
-
sequences split across text nodes require browser shaping. Combining marks (U+0301 and friends) are
|
|
1252
|
-
approximated, not shaped: a zero-width mark is anchored at the caret after its base glyph
|
|
1253
|
-
using canvas metrics, which covers common accents but is not full shaping.
|
|
1254
|
-
- Browser shaping, CJK reflow, RTL reflow, and legacy reshaping are [opt-in](#optional-language-support).
|
|
1255
|
-
Browser shaping retains ligatures and emoji ZWJ sequences as run masks. Vertical writing
|
|
1256
|
-
remains unsupported.
|
|
1257
|
-
- `selectable: true` adds a CSS class only. The app must align and style the native DOM
|
|
1258
|
-
overlay for selection and copying.
|
|
1259
|
-
- Form controls: interactive input elements (`<input>`, `<textarea>`, `<select>`, and
|
|
1260
|
-
`contenteditable`) should remain native DOM elements rather than converted to SDF blocks, as
|
|
1261
|
-
IME composition, caret navigation, and form state are native browser responsibilities.
|
|
1262
|
-
- CSS `text-transform` follows Chrome's rules: `uppercase` and `lowercase` honour `lang` only
|
|
1263
|
-
for Turkish, Azerbaijani, Greek and Lithuanian, and `capitalize` ignores it. `full-width`
|
|
1264
|
-
applies where the browser computes it (Firefox, Safari); `full-size-kana`, `math-auto` and
|
|
1265
|
-
`::first-letter`/`::first-line` styles are not applied. With Range, a character that maps to
|
|
1266
|
-
several (ß → SS) splits its source box by advance, and their marks (ǰ → J̌) are approximated
|
|
1267
|
-
like other combining marks. A text node whose mapping cannot be split back per character maps
|
|
1268
|
-
each character alone, without context rules such as Lithuanian dot insertion.
|
|
1269
|
-
- Strokes, shadows, gradients, filters, blend modes, masks, and CSS-transformed text are not
|
|
1270
|
-
reproduced. Use the explicit `outline`, `dropShadow`, and `fill` options for supported GPU
|
|
1271
|
-
text effects.
|
|
1272
|
-
- Rectangles support a solid background, effective opacity, and one uniform radius. Borders,
|
|
1273
|
-
per-corner radii, images, CSS shadows, transforms, and clip paths are not reproduced.
|
|
1274
|
-
- Text uses a finite rectangular clip per marked block. On axes with CSS `overflow: visible`,
|
|
1275
|
-
it includes the captured text boxes so tight line heights keep their descenders. Other
|
|
1276
|
-
overflow values keep the block bounds; arbitrary ancestor clipping is not reproduced.
|
|
1277
|
-
- A captured line keeps its layout position. The browser paints each line with its top rounded
|
|
1278
|
-
to a whole layout pixel, so text laid out between pixel rows (a `1.4` line height at 16 px,
|
|
1279
|
-
a block centred on a half pixel) can sit up to half a layout pixel from the painted DOM in a
|
|
1280
|
-
1:1 overlay. Whole-pixel line heights and offsets match the DOM exactly, and the opt-in
|
|
1281
|
-
[`pixelSnap`](#pixel-snapping) applies the browser's rounding to a flat 1:1 overlay.
|
|
1282
|
-
- Text weight follows the browser through `tone`, measured against Chrome on macOS only; see
|
|
1283
|
-
the [measured limits](#measured-limits).
|
|
1284
|
-
- Hidden, transparent, disconnected, or zero-size source content is skipped or rejected.
|
|
1285
|
-
- Creation and rebuilds perform real layout and atlas work; very large dynamic documents can
|
|
1286
|
-
be expensive.
|
|
1287
|
-
|
|
1288
|
-
Use native DOM text or a shaping-aware true-MSDF pipeline when exact shaping, sharp
|
|
1289
|
-
high-contrast corners, or full CSS fidelity is required.
|
|
1290
|
-
|
|
1291
|
-
## Browser support
|
|
608
|
+
Selective visual reconstruction, not a general DOM renderer:
|
|
1292
609
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
610
|
+
- Single-channel SDF (no true-MSDF corners); colour detail magnifies at `bakeSize` (interior alpha < 50% outside silhouette).
|
|
611
|
+
- Analytic `windfoil`/`slug` follow outline fidelity (~0.006 em if traced on main thread; ~1.2 ms/CJK glyph) with axis-aligned glyph-space AA boxes.
|
|
612
|
+
- Code-point glyphs by default (zero-width marks approximated; vertical writing unsupported). Full shaping/ligatures/bidi need opt-in `textShaping: 'browser'`.
|
|
613
|
+
- Keep interactive form controls (`<input>`, `<textarea>`, `<select>`, `contenteditable`) and selectable text (`selectable: true` CSS overlay) in native DOM.
|
|
614
|
+
- CSS strokes, gradients, filters, blend modes, masks, borders, images on boxes, CSS transforms, `::first-letter`/`::first-line`, and ancestor non-block clips are omitted.
|
|
615
|
+
- Half-pixel line placement without `pixelSnap: true`; `tone` calibrated against Chrome on macOS only.
|
|
1299
616
|
|
|
1300
|
-
|
|
1301
|
-
backend instead of relying on `navigator.gpu` alone.
|
|
617
|
+
## Browser support
|
|
1302
618
|
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
619
|
+
| Browser | Status | Notes |
|
|
620
|
+
| ------------------- | ------------------ | ---------------------------------------------------------------------------------------------------- |
|
|
621
|
+
| Chrome / Edge 128+ | Tested | Chromium WebGPU end-to-end suite (local and manual CI). |
|
|
622
|
+
| Safari 26+ | Expected, untested | Ships WebGPU by default; not automated. |
|
|
623
|
+
| Firefox 141+ | Expected, untested | Ships WebGPU; not automated. |
|
|
624
|
+
| Non-WebGPU browsers | SDF only, untested | `WebGPURenderer` falls back to WebGL2 with `atlasMode: 'auto'` or `'cpu'`; Windfoil and Slug cannot. |
|
|
1308
625
|
|
|
1309
|
-
|
|
626
|
+
Serve over HTTPS in production, await `renderer.init()`, guard SSR (`DomSdf.create()` is browser-only), and inspect the active backend.
|
|
1310
627
|
|
|
1311
628
|
## Comparison with other 3D web text libraries
|
|
1312
629
|
|
|
1313
|
-
ultra-text renders
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
frame
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
5.
|
|
1368
|
-
|
|
1369
|
-
|
|
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).
|
|
630
|
+
`ultra-text` renders browser HTML/CSS and loaded fonts directly—zero offline bake or font-file fetch—in 1 draw call per subtree. Compared head-to-head on [the online benchmark summary](https://ultra-text.makio.io/docs#comparison) (headless Chrome 157, Apple M3 Max / macOS 15.8, `three` `0.188.0-dev.29c99f4`, Noto Sans Regular, 1,000-glyph paragraph & 200 HUD labels, `3200×2400` RGBA8 sRGB): steady frames from the uncontended `2026-11-15` `--full` baseline (`U-sdf` A/A within ±1% `E2`), cold/update/relayout from `2026-11-19` `--full` (`n=10/30/32`, W4 `P-tilt`/`D-160` had external load so `2026-11-15` holds steady cells), GPU memory from `2026-11-22` (`ultimate-perf-1122` W5), and payloads/reflow CPU from `2026-11-23`. `three-mesh-ui` and drei `<Html>` were not measured.
|
|
631
|
+
|
|
632
|
+
```text
|
|
633
|
+
Steady frame · 200 HUD labels (3200×2400, E1 ms/frame — lower is faster)
|
|
634
|
+
ultra-text SDF (1 capture) █ 0.074 ms · 1 draw
|
|
635
|
+
troika BatchedText ██ 0.153 ms · 1 draw
|
|
636
|
+
@pmndrs/glyph MSDF ×200 ███ 0.211 ms · 2 draws
|
|
637
|
+
troika 200 Text ████████████████████████ 1.69 ms · 200 draws
|
|
638
|
+
|
|
639
|
+
Steady frame · 1,000-glyph paragraph (3200×2400, E1 ms/frame — lower is faster)
|
|
640
|
+
ultra-text SDF █████████ 0.075 ms · 1 draw
|
|
641
|
+
@pmndrs/glyph MSDF ███████████████ 0.129 ms · 2 draws
|
|
642
|
+
troika Text (WebGL2) █████████████████ 0.144 ms · 1 draw
|
|
643
|
+
ultra-text Slug (vector) ██████████████████ 0.158 ms · 1 draw
|
|
644
|
+
@pmndrs/glyph Slug (vector) ████████████████████████ 0.206 ms · 2 draws
|
|
645
|
+
|
|
646
|
+
Width relayout · 1,000 glyphs (480–720 px cycle — lower is faster)
|
|
647
|
+
ultra-text reflow() █████████ 1.46 ms
|
|
648
|
+
@pmndrs/glyph MSDF █████████████ 1.95 ms
|
|
649
|
+
@pmndrs/glyph Slug ███████████████ 2.31 ms
|
|
650
|
+
troika Text ███████████████ 2.37 ms
|
|
651
|
+
ultra-text CSS + rebuild() ████████████████████████ 3.71 ms
|
|
652
|
+
|
|
653
|
+
Resident GPU memory · 1,000-glyph paragraph (lower is leaner)
|
|
654
|
+
ultra-text Slug (TTF) ██ 0.17 MiB
|
|
655
|
+
@pmndrs/glyph Slug (ASCII) ███ 0.24 MiB (0.17 MiB subsetted to 49 chars)
|
|
656
|
+
ultra-text SDF (96 px R8) ████████ 0.64 MiB
|
|
657
|
+
@pmndrs/glyph MSDF (ASCII) █████████████████ 1.44 MiB (0.85 MiB subsetted to 49 chars)
|
|
658
|
+
troika Text (slab + canvas) ████████████████████████ 2.04 MiB
|
|
659
|
+
```
|
|
660
|
+
|
|
661
|
+
| | `ultra-text` 1.0 (SDF) | `ultra-text` 1.0 (Slug) | `@pmndrs/glyph` 0.1.0 | `troika-three-text` 0.53.1 (drei `<Text>`) |
|
|
662
|
+
| :------------------------------------- | :----------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------- |
|
|
663
|
+
| 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`) |
|
|
664
|
+
| 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 |
|
|
665
|
+
| 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 |
|
|
666
|
+
| First frame, 1,000-glyph paragraph [1] | 33.9 ms (GPU), 58.9 ms (CPU) | 35.7 ms (TTF), 74.8 ms (traced) | 48.8 ms (MSDF), 56.4 ms (Slug) | **23.4 ms** |
|
|
667
|
+
| First frame, 200 labels [1] | 39.7 ms (one capture) | one capture over all 200 | 75.5 ms | 39.1 ms (200 `Text`), **26.2 ms** (`BatchedText`) |
|
|
668
|
+
| Edit 10 letters already drawn [2] | 3.0 ms (GPU), **2.4 ms** (CPU) | 2.7 ms (TTF), 2.8 ms (traced) | 2.5 ms MSDF, 2.8 ms Slug | 2.5 ms |
|
|
669
|
+
| Edit adding a never-drawn letter [2] | 4.3 ms (GPU atlas), 3.1 ms (CPU atlas), 2.6 ms with `extraGlyphs` | **2.9 ms** (TTF, `#ga` in-place), 4.1 ms (traced) | **2.2 ms** MSDF, 2.7 ms Slug (baked ahead) | 3.0 ms |
|
|
670
|
+
| Width change, 1,000 glyphs [2] | **1.46 ms** with `reflow()` (0.041 ms CPU only); 3.7 ms with CSS + `rebuild()` | 3.5–3.6 ms with CSS + `rebuild()` | 1.95 ms (MSDF), 2.31 ms (Slug) | 2.37 ms |
|
|
671
|
+
| 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 |
|
|
672
|
+
| Frame, 200 labels [3] | **0.074 ms** | 1 draw per subtree | 0.211 ms | 1.69 ms (200 `Text`), 0.153 ms (`BatchedText`) |
|
|
673
|
+
| Draw calls, paragraph / 200 labels | **1 / 1** | **1 / 1** | 2 / 2 (double-sided text in two passes) | 1 / 200 (1 with `BatchedText`) |
|
|
674
|
+
| GPU memory, paragraph [4] | **0.64 MiB** (5.3 MiB GPU JFA peak; 0.64 MiB CPU peak) | **0.17 MiB** TTF (0.21 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) |
|
|
675
|
+
| 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 |
|
|
676
|
+
| Outline and drop shadow | on every backend | on every backend (SDF underlay) | MSDF only | outline with blur and offset, inner stroke |
|
|
677
|
+
| Colour emoji | **yes**, the browser's own | **yes**, SDF colour companion | not yet (roadmap) | monochrome |
|
|
678
|
+
| JS + Wasm, min+gzip | **41.1 kB** `DomText + Text` (36.6 kB brotli; 56.3 kB gzip full root; **31.7 kB** vanilla) | +17.1 kB lazy (+15.5 kB brotli; `ultra-text/slug`: 40.9 kB, 36.1 kB brotli; vanilla: 33.7 kB, 30.1 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`) |
|
|
679
|
+
|
|
680
|
+
1. Cold authoring call → first frame GPU completion, fonts preloaded, warm shader cache (`n = 10`). `ultra-text` SDF builds in `5.35 ms` GPU (`4.56 ms` in `2026-11-22` W5) + `6.66 ms` layout + `13.3 ms` first submit (`4.30 / 5.89 / 15.1 ms` on Slug TTF).
|
|
681
|
+
2. Mutation → GPU completion (`n = 30` edits, `n = 32` width changes). `reflow()` avoids DOM reads (**`0.041 ms`** standalone CPU median on Apple M3 Max, `2026-11-23`; **`1.46 ms`** end-to-end). Headroom-on-first-miss cuts unseen-glyph Slug rebuilds to `2.89 ms` (TTF) and `4.14 ms` (traced).
|
|
682
|
+
3. Whole `3200×2400` frame batches (`E1`, `n = 8`), `E2` GPU timestamps, `E3` `ioreg` (`troika ÷ ultra-text` `1.67–2.02`, `glyph MSDF ÷ ultra-text` `1.10–1.73`, `glyph Slug ÷ ultra-text SDF` `2.06–2.76`; 160 px net GPU Slug `0.053 ms` vs `glyph` `0.090 ms`). Net text cost over empty frame: `0.010–0.016 ms` (`ultra-text` SDF) vs `0.008 ms` (`troika`) vs `0.017–0.071 ms` (`glyph` MSDF). 200 `troika Text` calls are CPU-bound (`1.68 ms` CPU/frame vs `0.012 ms`).
|
|
683
|
+
4. Post-renderer GPU allocations: `glyph` ASCII bake `1.44 / 0.24 MiB` (`0.85 / 0.17 MiB` at 49 chars); `troika` allocates `2048×128` 256-glyph RGBA slab + buffers (`1.04 MiB`) + auxiliary generator canvas (`1.00 MiB`).
|
|
684
|
+
5. Verified on the `shots/zoom-grid.png` contact sheet (`"Rag Kerning quartz 0.5% Ж"` at 1×/10×/100× vs Chrome DOM).
|
|
685
|
+
|
|
686
|
+
Payloads (Vite 8, `es2022`, `NODE_ENV=production`, `three/*` external, `1 kB = 1,000 B`, run `2026-11-23`). Qualitative notes checked `2026-11-15` in [glyph](https://github.com/pmndrs/glyph) and [troika](https://github.com/protectwise/troika/tree/main/packages/troika-three-text).
|
|
1373
687
|
|
|
1374
688
|
## Demo and documentation
|
|
1375
689
|
|
|
1376
|
-
- [Documentation](https://ultra-text.makio.io/docs), with the TresJS, React Three Fiber and
|
|
1377
|
-
|
|
1378
|
-
- [HTML/3D demo](https://ultra-text.makio.io/demo): live HTML beside its retained WebGPU copy,
|
|
1379
|
-
with colour emoji and SVG exhibits.
|
|
690
|
+
- [Documentation](https://ultra-text.makio.io/docs), with the TresJS, React Three Fiber, and Mini3 guides linked [above](#tresjs-react-three-fiber-mini3-and-vanilla-js).
|
|
691
|
+
- [HTML/3D demo](https://ultra-text.makio.io/demo): live HTML beside its retained WebGPU copy, with colour emoji and SVG exhibits.
|
|
1380
692
|
- [Gallery](https://ultra-text.makio.io/): a WebGPU exhibition built with the library.
|
|
1381
693
|
|
|
1382
694
|
This repository holds the library only; the demo and gallery sources are not part of it.
|
|
1383
695
|
|
|
1384
696
|
## Development
|
|
1385
697
|
|
|
1386
|
-
|
|
1387
|
-
TypeScript 7 runs type checks and declaration builds through `tsc`; the `typescript`
|
|
1388
|
-
dependency aliases the TypeScript 6 compatibility package required by typescript-eslint.
|
|
698
|
+
Node 22.23.2 (`.node-version`), pnpm 12.3.4, TypeScript 7 (`typescript` aliases TS 6 for eslint).
|
|
1389
699
|
|
|
1390
700
|
```sh
|
|
1391
|
-
pnpm install --frozen-lockfile
|
|
1392
|
-
pnpm test
|
|
701
|
+
pnpm install --frozen-lockfile && pnpm test
|
|
1393
702
|
```
|
|
1394
703
|
|
|
1395
|
-
| Command | Purpose
|
|
1396
|
-
| ---------------- |
|
|
1397
|
-
| `pnpm test` | Run the Vitest unit suite.
|
|
1398
|
-
| `pnpm typecheck` | Type-check browser and Node
|
|
1399
|
-
| `pnpm lint` | Run ESLint
|
|
1400
|
-
| `pnpm build` | Build ESM modules
|
|
1401
|
-
| `pnpm check` | Run formatting, lint, types, coverage,
|
|
1402
|
-
|
|
1403
|
-
The unit suite runs in jsdom: it checks CPU logic, generated shader text, graph wiring,
|
|
1404
|
-
lifecycle and public behavior, but does not render. Pull requests and pushes to `main` run
|
|
1405
|
-
`pnpm check`.
|
|
704
|
+
| Command | Purpose |
|
|
705
|
+
| ---------------- | ----------------------------------------------------------------- |
|
|
706
|
+
| `pnpm test` | Run the Vitest unit suite in jsdom. |
|
|
707
|
+
| `pnpm typecheck` | Type-check browser and Node configs. |
|
|
708
|
+
| `pnpm lint` | Run ESLint (`--max-warnings 0`). |
|
|
709
|
+
| `pnpm build` | Build ESM modules + `.d.ts` into `dist/`. |
|
|
710
|
+
| `pnpm check` | Run formatting, lint, types, coverage, builds, size & package QA. |
|
|
1406
711
|
|
|
1407
|
-
|
|
1408
|
-
|
|
712
|
+
The unit suite does not render; prefer local WebGPU hardware for rendering checks. See
|
|
713
|
+
[`CONTRIBUTING.md`](./CONTRIBUTING.md) and [`AGENTS.md`](./AGENTS.md).
|
|
1409
714
|
|
|
1410
715
|
## License
|
|
1411
716
|
|
|
1412
|
-
[MIT](./LICENSE) © David Ronai. Windfoil-derived preprocessing and shader portions are
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
717
|
+
[MIT](./LICENSE) © David Ronai. Windfoil-derived preprocessing and shader portions are Apache-2.0,
|
|
718
|
+
and the Glyph-derived SDF effect composition and Slug-derived coverage evaluator keep their
|
|
719
|
+
upstream MIT notices; see [third-party notices](./THIRD_PARTY_NOTICES.md), which also lists the
|
|
720
|
+
licensed test fixtures.
|