ultra-text 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +339 -1039
  2. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
  3. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
  4. package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
  5. package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
  6. package/dist/atlas/appendAtlas.js +97 -31
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +4 -3
  9. package/dist/atlas/buildAtlas.js.map +1 -1
  10. package/dist/atlas/colorGlyphs.d.ts +0 -10
  11. package/dist/atlas/colorGlyphs.js +97 -155
  12. package/dist/atlas/colorGlyphs.js.map +1 -1
  13. package/dist/atlas/colorTexture.d.ts +1 -0
  14. package/dist/atlas/colorTexture.js +64 -0
  15. package/dist/atlas/colorTexture.js.map +1 -0
  16. package/dist/atlas/cpuAtlas.d.ts +4 -1
  17. package/dist/atlas/cpuAtlas.js +14 -7
  18. package/dist/atlas/cpuAtlas.js.map +1 -1
  19. package/dist/atlas/cpuSdf.d.ts +1 -1
  20. package/dist/atlas/cpuSdf.js +235 -68
  21. package/dist/atlas/cpuSdf.js.map +1 -1
  22. package/dist/atlas/cpuWorker.d.ts +11 -3
  23. package/dist/atlas/cpuWorker.js +179 -22
  24. package/dist/atlas/cpuWorker.js.map +1 -1
  25. package/dist/atlas/gpuAtlas.js +188 -287
  26. package/dist/atlas/gpuAtlas.js.map +1 -1
  27. package/dist/atlas/gpuCommon.d.ts +257 -0
  28. package/dist/atlas/gpuCommon.js +845 -0
  29. package/dist/atlas/gpuCommon.js.map +1 -0
  30. package/dist/atlas/jfaWgsl.d.ts +1 -1
  31. package/dist/atlas/jfaWgsl.js +226 -249
  32. package/dist/atlas/jfaWgsl.js.map +1 -1
  33. package/dist/atlas/rasterize.d.ts +22 -0
  34. package/dist/atlas/rasterize.js +329 -158
  35. package/dist/atlas/rasterize.js.map +1 -1
  36. package/dist/atlas/shapeRaster.js +2 -1
  37. package/dist/atlas/shapeRaster.js.map +1 -1
  38. package/dist/atlas/vanillaBounds.d.ts +64 -0
  39. package/dist/atlas/vanillaBounds.js +42 -0
  40. package/dist/atlas/vanillaBounds.js.map +1 -0
  41. package/dist/atlas/vanillaCore.d.ts +100 -0
  42. package/dist/atlas/vanillaCore.js +1065 -0
  43. package/dist/atlas/vanillaCore.js.map +1 -0
  44. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  45. package/dist/atlas/vanillaCpuAtlas.js +72 -0
  46. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  47. package/dist/atlas/vanillaExtras.d.ts +8 -0
  48. package/dist/atlas/vanillaExtras.js +167 -0
  49. package/dist/atlas/vanillaExtras.js.map +1 -0
  50. package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
  51. package/dist/atlas/vanillaGpuHelpers.js +354 -0
  52. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  53. package/dist/dom/DomSdf.js +243 -297
  54. package/dist/dom/DomSdf.js.map +1 -1
  55. package/dist/dom/DomSlug.js +94 -165
  56. package/dist/dom/DomSlug.js.map +1 -1
  57. package/dist/dom/Text.d.ts +4 -1
  58. package/dist/dom/Text.js +5 -1
  59. package/dist/dom/Text.js.map +1 -1
  60. package/dist/dom/browserShaping.js +31 -14
  61. package/dist/dom/browserShaping.js.map +1 -1
  62. package/dist/dom/clusters.js +13 -2
  63. package/dist/dom/clusters.js.map +1 -1
  64. package/dist/dom/cssEffects.d.ts +4 -0
  65. package/dist/dom/cssEffects.js +72 -0
  66. package/dist/dom/cssEffects.js.map +1 -0
  67. package/dist/dom/domAnalytic.d.ts +53 -0
  68. package/dist/dom/domAnalytic.js +282 -0
  69. package/dist/dom/domAnalytic.js.map +1 -0
  70. package/dist/dom/domExtras.d.ts +27 -0
  71. package/dist/dom/domExtras.js +137 -0
  72. package/dist/dom/domExtras.js.map +1 -0
  73. package/dist/dom/fontCanvas.d.ts +16 -0
  74. package/dist/dom/fontCanvas.js +31 -13
  75. package/dist/dom/fontCanvas.js.map +1 -1
  76. package/dist/dom/layoutSignature.js +175 -57
  77. package/dist/dom/layoutSignature.js.map +1 -1
  78. package/dist/dom/markup.d.ts +10 -0
  79. package/dist/dom/markup.js +16 -1
  80. package/dist/dom/markup.js.map +1 -1
  81. package/dist/dom/pretextLayout.js +78 -28
  82. package/dist/dom/pretextLayout.js.map +1 -1
  83. package/dist/dom/snapshot.d.ts +4 -0
  84. package/dist/dom/snapshot.js +891 -484
  85. package/dist/dom/snapshot.js.map +1 -1
  86. package/dist/dom/snapshotsEqual.d.ts +7 -0
  87. package/dist/dom/snapshotsEqual.js +68 -0
  88. package/dist/dom/snapshotsEqual.js.map +1 -0
  89. package/dist/dom/svgCapture.d.ts +8 -1
  90. package/dist/dom/svgCapture.js +105 -28
  91. package/dist/dom/svgCapture.js.map +1 -1
  92. package/dist/dom/textTransform.d.ts +13 -1
  93. package/dist/dom/textTransform.js +31 -13
  94. package/dist/dom/textTransform.js.map +1 -1
  95. package/dist/dom/tone.js +91 -44
  96. package/dist/dom/tone.js.map +1 -1
  97. package/dist/index.js +4 -3
  98. package/dist/slug/SlugMaterial.d.ts +17 -3
  99. package/dist/slug/SlugMaterial.js +98 -26
  100. package/dist/slug/SlugMaterial.js.map +1 -1
  101. package/dist/slug/cff.d.ts +5 -0
  102. package/dist/slug/cff.js +780 -0
  103. package/dist/slug/cff.js.map +1 -0
  104. package/dist/slug/coverage.d.ts +19 -15
  105. package/dist/slug/coverage.js +380 -225
  106. package/dist/slug/coverage.js.map +1 -1
  107. package/dist/slug/preprocessCore.d.ts +6 -2
  108. package/dist/slug/preprocessCore.js +199 -148
  109. package/dist/slug/preprocessCore.js.map +1 -1
  110. package/dist/slug/runtime.d.ts +1 -0
  111. package/dist/slug/runtime.js +113 -74
  112. package/dist/slug/runtime.js.map +1 -1
  113. package/dist/slug/standaloneRuntime.d.ts +3 -2
  114. package/dist/slug/standaloneRuntime.js +112 -67
  115. package/dist/slug/standaloneRuntime.js.map +1 -1
  116. package/dist/slug/truetype.d.ts +14 -6
  117. package/dist/slug/truetype.js +356 -255
  118. package/dist/slug/truetype.js.map +1 -1
  119. package/dist/slug/vanillaCore.d.ts +410 -0
  120. package/dist/slug/vanillaCore.js +1630 -0
  121. package/dist/slug/vanillaCore.js.map +1 -0
  122. package/dist/slug-vanilla.d.ts +13 -364
  123. package/dist/slug-vanilla.js +7 -1454
  124. package/dist/slug.d.ts +2 -2
  125. package/dist/slug.js +7 -7
  126. package/dist/text/GlyphTextMaterial.d.ts +6 -1
  127. package/dist/text/GlyphTextMaterial.js +16 -12
  128. package/dist/text/GlyphTextMaterial.js.map +1 -1
  129. package/dist/text/RectMaterial.js +6 -10
  130. package/dist/text/RectMaterial.js.map +1 -1
  131. package/dist/text/SdfTextMaterial.d.ts +9 -3
  132. package/dist/text/SdfTextMaterial.js +125 -38
  133. package/dist/text/SdfTextMaterial.js.map +1 -1
  134. package/dist/text/decorations.d.ts +7 -2
  135. package/dist/text/decorations.js +187 -79
  136. package/dist/text/decorations.js.map +1 -1
  137. package/dist/text/geometry.d.ts +3 -22
  138. package/dist/text/geometryUtils.d.ts +16 -1
  139. package/dist/text/geometryUtils.js +83 -8
  140. package/dist/text/geometryUtils.js.map +1 -1
  141. package/dist/text/glyphGeometry.d.ts +9 -0
  142. package/dist/text/glyphGeometry.js +434 -0
  143. package/dist/text/glyphGeometry.js.map +1 -0
  144. package/dist/text/index.d.ts +2 -1
  145. package/dist/text/rectGeometry.d.ts +13 -0
  146. package/dist/text/rectGeometry.js +101 -0
  147. package/dist/text/rectGeometry.js.map +1 -0
  148. package/dist/text/reflow.d.ts +23 -1
  149. package/dist/text/reflow.js +223 -94
  150. package/dist/text/reflow.js.map +1 -1
  151. package/dist/text/snap.d.ts +15 -0
  152. package/dist/text/snap.js +26 -0
  153. package/dist/text/snap.js.map +1 -0
  154. package/dist/text/tone.js +2 -2
  155. package/dist/text/tone.js.map +1 -1
  156. package/dist/types.d.ts +23 -7
  157. package/dist/vanilla.d.ts +13 -363
  158. package/dist/vanilla.js +7 -1474
  159. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  160. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  161. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  162. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  163. package/dist/windfoil/WindfoilMaterial.js +71 -8
  164. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  165. package/dist/windfoil/compositeGeometry.js +12 -5
  166. package/dist/windfoil/compositeGeometry.js.map +1 -1
  167. package/dist/windfoil/coverage.d.ts +10 -2
  168. package/dist/windfoil/coverage.js +147 -59
  169. package/dist/windfoil/coverage.js.map +1 -1
  170. package/dist/windfoil/geometry.d.ts +17 -2
  171. package/dist/windfoil/geometry.js +220 -57
  172. package/dist/windfoil/geometry.js.map +1 -1
  173. package/dist/windfoil/layerGrid.js +8 -8
  174. package/dist/windfoil/layerGrid.js.map +1 -1
  175. package/dist/windfoil/mixed.d.ts +1 -0
  176. package/dist/windfoil/mixed.js +57 -29
  177. package/dist/windfoil/mixed.js.map +1 -1
  178. package/dist/windfoil/preprocess.js +2 -2
  179. package/dist/windfoil/preprocessCore.d.ts +2 -0
  180. package/dist/windfoil/preprocessCore.js +69 -37
  181. package/dist/windfoil/preprocessCore.js.map +1 -1
  182. package/dist/windfoil/requests.d.ts +1 -1
  183. package/dist/windfoil/requests.js +11 -4
  184. package/dist/windfoil/requests.js.map +1 -1
  185. package/dist/windfoil/resolveOutline.d.ts +9 -0
  186. package/dist/windfoil/resolveOutline.js +20 -0
  187. package/dist/windfoil/resolveOutline.js.map +1 -0
  188. package/dist/windfoil/runtime.d.ts +4 -1
  189. package/dist/windfoil/runtime.js +69 -63
  190. package/dist/windfoil/runtime.js.map +1 -1
  191. package/dist/windfoil/shapeGeometry.js +80 -34
  192. package/dist/windfoil/shapeGeometry.js.map +1 -1
  193. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  194. package/dist/windfoil/sizeSwitch.js +13 -8
  195. package/dist/windfoil/sizeSwitch.js.map +1 -1
  196. package/dist/windfoil/storage.d.ts +78 -6
  197. package/dist/windfoil/storage.js +166 -11
  198. package/dist/windfoil/storage.js.map +1 -1
  199. package/dist/windfoil/svg/curves.d.ts +20 -0
  200. package/dist/windfoil/svg/curves.js +145 -42
  201. package/dist/windfoil/svg/curves.js.map +1 -1
  202. package/dist/windfoil/svg/document.js +10 -1
  203. package/dist/windfoil/svg/document.js.map +1 -1
  204. package/dist/windfoil/svg/pathConverter.js +66 -50
  205. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  206. package/dist/windfoil/svg/pathData.d.ts +9 -0
  207. package/dist/windfoil/svg/pathData.js +142 -109
  208. package/dist/windfoil/svg/pathData.js.map +1 -1
  209. package/dist/windfoil/svg/winding.js +34 -10
  210. package/dist/windfoil/svg/winding.js.map +1 -1
  211. package/dist/windfoil/trace/contours.d.ts +5 -0
  212. package/dist/windfoil/trace/contours.js +256 -62
  213. package/dist/windfoil/trace/contours.js.map +1 -1
  214. package/dist/windfoil/trace/fit.d.ts +3 -1
  215. package/dist/windfoil/trace/fit.js +915 -265
  216. package/dist/windfoil/trace/fit.js.map +1 -1
  217. package/dist/windfoil/trace/outline.js +55 -30
  218. package/dist/windfoil/trace/outline.js.map +1 -1
  219. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  220. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  221. package/dist/windfoil/trace/traceWorker.js +192 -0
  222. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  223. package/dist/windfoil/trace/types.d.ts +10 -0
  224. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  225. package/dist/windfoil/tracedOutlines.js +393 -103
  226. package/dist/windfoil/tracedOutlines.js.map +1 -1
  227. package/package.json +48 -29
  228. package/skills/ultra-text/SKILL.md +9 -10
  229. package/skills/ultra-text/references/frameworks.md +46 -2
  230. package/skills/ultra-text/references/three-tsl.md +27 -25
  231. package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
  232. package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
  233. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
  234. package/dist/slug-vanilla.js.map +0 -1
  235. package/dist/text/geometry.js +0 -348
  236. package/dist/text/geometry.js.map +0 -1
  237. package/dist/vanilla.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"tracedOutlines.js","names":[],"sources":["../../src/windfoil/tracedOutlines.ts"],"sourcesContent":["import {\n allFontsLoaded,\n createCanvas,\n isColorCandidate,\n setFontContext,\n waitForFonts,\n} from '../dom/fontCanvas.js'\nimport type {\n ColorGlyphMode,\n FontStyleSnapshot,\n GlyphRequest,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { createTraceScratch, traceCoverage } from './trace/outline.js'\n\n/** Options of the built-in Canvas 2D outline tracer. */\nexport interface TracedOutlineOptions {\n /** Trace resolution in pixels per em, also each outline's `unitsPerEm`. Defaults to `256`. */\n readonly size?: number\n /** Furthest, in trace pixels, a fitted curve may stray from its contour. Defaults to `0.25`. */\n readonly tolerance?: number\n /** Which glyphs to test for colour ink, as `DomSdfOptions.colorGlyphs`. Defaults to `'emoji'`. */\n readonly colorGlyphs?: ColorGlyphMode\n}\n\n/** A `WindfoilOutlineProvider` that traces the browser's own glyphs, and its cache. */\nexport interface TracedOutlines {\n readonly provider: WindfoilOutlineProvider\n /** Forgets every traced outline, as after a webfont load; work in flight is not kept. */\n clear(): void\n /** Forgets the outlines of every glyph key not listed. */\n retain(keys: Iterable<string>): void\n}\n\n/** A batch yields to the page once it has traced for this long. */\nconst SLICE_MS = 8\n/** A font assignment the canvas rejects leaves this one in place. */\nconst SENTINEL_FONT = '1px serif'\nconst SIZE_TOKEN = /[\\d.]+px/\n\n/** The requests one task made with one signal, traced together. */\ninterface Batch {\n readonly signal: AbortSignal\n readonly requests: Map<string, GlyphRequest>\n readonly done: Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>>\n}\n\n/** One glyph between measuring and tracing, in trace pixels; y grows downwards. */\ninterface Measured {\n readonly request: GlyphRequest\n readonly ascent: number\n readonly descent: number\n /** How far the ink box and the font box reach from the pen: left, right, up and down. */\n readonly reach: readonly [number, number, number, number]\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n if (signal.aborted) {\n throw signal.reason ?? new DOMException('The outline trace was aborted', 'AbortError')\n }\n}\n\n/**\n * A task after the page's own: a message is not clamped to 4 ms as a nested timer is, and it\n * does not run ahead of rendering as a `scheduler.yield()` continuation does, which held frames\n * back for 100 ms at a time in Chrome 156.\n */\nfunction nextTask(): Promise<void> {\n return new Promise((resolve) => {\n if (typeof MessageChannel !== 'function') {\n setTimeout(resolve, 0)\n return\n }\n const { port1, port2 } = new MessageChannel()\n port1.onmessage = () => {\n port1.close()\n resolve()\n }\n port2.postMessage(null)\n })\n}\n\n/** Canvas box of a glyph with `margin` pixels around its reach: pen position and size. */\nfunction boxOf(\n reach: Measured['reach'],\n margin: number,\n): [originX: number, baselineY: number, width: number, height: number] {\n const originX = margin + Math.ceil(reach[0])\n const baselineY = margin + Math.ceil(reach[2])\n return [\n originX,\n baselineY,\n originX + Math.ceil(reach[1]) + margin,\n baselineY + Math.ceil(reach[3]) + margin,\n ]\n}\n\n/** Whether any texel on the edge of a `width` x `height` RGBA read holds ink. */\nfunction touchesEdge(\n rgba: Uint8ClampedArray,\n width: number,\n height: number,\n rowStride = width * 4,\n baseOffset = 0,\n): boolean {\n for (let x = 0; x < width; x++) {\n if (\n rgba[baseOffset + x * 4 + 3]! > 0 ||\n rgba[baseOffset + (height - 1) * rowStride + x * 4 + 3]! > 0\n ) {\n return true\n }\n }\n for (let y = 0; y < height; y++) {\n const row = baseOffset + y * rowStride\n if (rgba[row + 3]! > 0 || rgba[row + (width - 1) * 4 + 3]! > 0) return true\n }\n return false\n}\n\nconst MAX_SHEET = 2048\nconst SHEET_GAP = 1\n\n/**\n * The outline provider `DomSdf` and `DomSlug` use for Windfoil and Slug text when the caller gives\n * none. Each glyph is drawn as the SDF rasterizer draws it (the captured canvas font with its\n * stretch and kerning, an in-document canvas without font smoothing, exact geometry, a neutral\n * grey), at `size` pixels per em, then traced at half coverage and fitted with quadratics. The\n * outline follows that raster, not the font file: font-variation and feature settings are not\n * applied, as on any canvas. Colour glyphs, glyphs of a font the canvas rejects and shaped runs\n * resolve to `null`, for the SDF companion; a glyph without ink to an empty outline. Without a\n * 2D canvas every glyph is `null`, so the whole capture falls back to SDF. `descent` is the SDF\n * slot's, measured at the captured font's own size, so analytic and SDF glyphs share a baseline.\n * Ink the metrics miss is drawn again with half an em more room all round; a glyph whose ink\n * still reaches the edge of its box resolves to `null` too, rather than trace clipped.\n *\n * Calls made in one task with one signal trace as one batch, in slices of about 8 ms between\n * which the page runs and the signal is checked. Each batch has its own working memory, which\n * goes with it. Outlines stay cached per instance until `clear()` or `retain()` drops them; one\n * traced while `document.fonts.check()` still reported its font as not ready is never cached.\n */\nexport function createTracedOutlineProvider(\n document: Document,\n options: TracedOutlineOptions = {},\n): TracedOutlines {\n const size = options.size ?? 256\n const tolerance = options.tolerance ?? 0.25\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const cache = new Map<string, WindfoilGlyphOutline | null>()\n let epoch = 0\n /** The batches still open to requests of this task, by signal. */\n const open = new Map<AbortSignal, Batch>()\n\n const run = async (\n signal: AbortSignal,\n requests: ReadonlyMap<string, GlyphRequest>,\n started: number,\n ): Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>> => {\n const results = new Map<string, WindfoilGlyphOutline | null>()\n // Each font of the batch, as captured and as traced: the captured canvas font with only\n // its size rewritten, as an adaptive SDF bake does.\n const groups = new Map<string, [GlyphRequest[], FontStyleSnapshot]>()\n for (const request of requests.values()) {\n // Shapes resolve elsewhere; a shaped run is one tile of a line, which no outline covers.\n if (request.shape || request.shaping) {\n results.set(request.key, null)\n continue\n }\n const group = groups.get(request.font.key)\n if (group) group[0].push(request)\n else {\n const font = request.font\n groups.set(font.key, [\n [request],\n { ...font, canvasFont: font.canvasFont.replace(SIZE_TOKEN, `${size}px`) },\n ])\n }\n }\n const traced = (request: GlyphRequest): GlyphRequest => ({\n ...request,\n font: groups.get(request.font.key)![1],\n })\n await waitForFonts(\n document,\n [...groups.values()].flatMap(([list]) => list.map(traced)),\n signal,\n )\n throwIfAborted(signal)\n\n const preloaded = allFontsLoaded(document)\n const fonts = document.fonts as FontFaceSet | undefined\n const keep = (request: GlyphRequest, outline: WindfoilGlyphOutline | null): void => {\n results.set(request.key, outline)\n let ready = epoch === started\n if (ready && !preloaded) {\n try {\n ready = fonts?.check(traced(request).font.canvasFont, request.character) ?? true\n } catch {\n ready = false\n }\n }\n if (ready) cache.set(request.key, outline)\n }\n\n const canvas = createCanvas(document)\n try {\n const context = canvas.getContext('2d', { willReadFrequently: true })\n if (!context) {\n // Not cached: the whole capture falls back to SDF, and a later build may try again.\n for (const [list] of groups.values())\n for (const request of list) results.set(request.key, null)\n return results\n }\n let current: FontStyleSnapshot | null = null\n const accepted = new Map<FontStyleSnapshot, boolean>()\n /** Applies a request's font as the rasterizer does; false when the canvas rejected it. */\n const use = (request: GlyphRequest): boolean => {\n if (current !== request.font) {\n context.font = SENTINEL_FONT\n const sentinel = context.font\n setFontContext(context, request, undefined, null)\n current = request.font\n accepted.set(request.font, context.font !== sentinel)\n }\n return accepted.get(request.font)!\n }\n\n // Measure every glyph first: sizing the canvas resets its context.\n const margin = Math.max(4, Math.ceil(size / 32))\n const measured: Measured[] = []\n let canvasWidth = 1\n let canvasHeight = 1\n for (const [list] of groups.values()) {\n throwIfAborted(signal)\n const bake = Number.parseFloat(SIZE_TOKEN.exec(list[0]!.font.canvasFont)?.[0] ?? '')\n if (!(bake > 0) || !use(list[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n // The SDF slot's metrics, measured at the captured font's own size.\n const scale = size / bake\n const slots = list.map((request) => {\n const slot = context.measureText(request.character)\n return [\n Math.max(1, slot.fontBoundingBoxAscent || slot.actualBoundingBoxAscent) * scale,\n Math.max(1, slot.fontBoundingBoxDescent || slot.actualBoundingBoxDescent) * scale,\n ] as const\n })\n if (!use(traced(list[0]!))) {\n for (const request of list) keep(request, null)\n continue\n }\n list.forEach((request, index) => {\n const [ascent, descent] = slots[index]!\n // Ink can only be found in the ink box and the font box.\n const metrics = context.measureText(request.character)\n const reach = [\n Math.max(0, metrics.actualBoundingBoxLeft || 0),\n Math.max(metrics.width || 0, metrics.actualBoundingBoxRight || 0),\n Math.max(ascent, metrics.actualBoundingBoxAscent || 0),\n Math.max(descent, metrics.actualBoundingBoxDescent || 0),\n ] as const\n const [, , width, height] = boxOf(reach, margin)\n if (!(width <= 8 * size && height <= 8 * size)) {\n keep(request, null)\n return\n }\n canvasWidth = Math.max(canvasWidth, width)\n canvasHeight = Math.max(canvasHeight, height)\n measured.push({ request: traced(request), ascent, descent, reach })\n })\n }\n const resize = (width: number, height: number): void => {\n if (width <= canvas.width && height <= canvas.height) return\n canvas.width = Math.max(width, canvas.width)\n canvas.height = Math.max(height, canvas.height)\n current = null\n }\n resize(canvasWidth, canvasHeight)\n\n const exact = 'textRendering' in context\n const draw = (\n glyph: Measured,\n [originX, baselineY, width, height]: ReturnType<typeof boxOf>,\n fill: string,\n rendering: CanvasTextRendering,\n ): Uint8ClampedArray => {\n resize(width, height)\n use(glyph.request)\n context.fillStyle = fill\n if (exact) context.textRendering = rendering\n context.clearRect(0, 0, width, height)\n context.fillText(glyph.request.character, originX, baselineY)\n return context.getImageData(0, 0, width, height).data\n }\n const colorModule = measured.some((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n ? await import('../atlas/colorGlyphs.js')\n : null\n throwIfAborted(signal)\n // This batch's working memory, grown to fit its largest glyph (about 1 MB at 256 px per\n // em) and released with the batch, so an idle tracer holds none.\n const scratch = createTraceScratch()\n let sliceStart = performance.now()\n const view = document.defaultView\n const getContextFn = view\n ? (Object.getOwnPropertyDescriptor(view.HTMLCanvasElement.prototype, 'getContext')\n ?.value as object | undefined)\n : undefined\n const mockedCanvas = !getContextFn || 'mock' in getContextFn\n const finishGlyph = async (\n glyph: Measured,\n box: ReturnType<typeof boxOf>,\n retried: boolean,\n ): Promise<void> => {\n // The SDF bake's text rendering: exact geometry, the neutral middle of a contrast table.\n let currentBox = box\n let rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n let clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n if (clipped && !retried) {\n // The metrics missed some ink: once more with half an em of room all round.\n currentBox = boxOf(glyph.reach, margin + size / 2)\n rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n }\n // Ink past even that room would trace clipped: the SDF companion draws the glyph.\n let outline: WindfoilGlyphOutline | null = null\n if (!clipped) {\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width: currentBox[2],\n height: currentBox[3],\n stride: 4,\n offset: 3,\n originX: currentBox[0],\n baselineY: currentBox[1],\n },\n tolerance,\n scratch,\n )\n outline = {\n unitsPerEm: size,\n ascent: glyph.ascent,\n descent: -glyph.descent,\n bbox,\n quadratics,\n }\n }\n keep(requests.get(glyph.request.key)!, outline)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n\n if (mockedCanvas || measured.length < 2) {\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, margin)\n const [, , width, height] = box\n // A candidate the font draws in the fill colour alone is text, as in the SDF bake:\n // only ink that ignores the fill goes to the companion.\n const colored =\n colorModule !== null &&\n isColorCandidate(glyph.request, colorGlyphs) &&\n colorModule.encodeColorBand(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n height,\n 0,\n [{ x: 0, y: 0, width, height }],\n ).colored[0] === true\n if (colored) {\n keep(requests.get(glyph.request.key)!, null)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n continue\n }\n await finishGlyph(glyph, box, false)\n }\n } else {\n interface Tile {\n readonly glyph: Measured\n readonly box: ReturnType<typeof boxOf>\n readonly x: number\n readonly y: number\n }\n const plain: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const oversized: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const retries: Measured[] = []\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, margin)\n const [, , width, height] = box\n const colored =\n colorModule !== null &&\n isColorCandidate(glyph.request, colorGlyphs) &&\n colorModule.encodeColorBand(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n height,\n 0,\n [{ x: 0, y: 0, width, height }],\n ).colored[0] === true\n if (colored) {\n keep(requests.get(glyph.request.key)!, null)\n continue\n }\n if (width > MAX_SHEET || height > MAX_SHEET) oversized.push({ glyph, box })\n else plain.push({ glyph, box })\n }\n\n const flushSheet = async (sheet: Tile[], sheetW: number, sheetH: number): Promise<void> => {\n resize(sheetW, sheetH)\n context.clearRect(0, 0, sheetW, sheetH)\n context.fillStyle = '#606060'\n if (exact) context.textRendering = 'geometricPrecision'\n for (const item of sheet) {\n throwIfAborted(signal)\n use(item.glyph.request)\n context.fillText(\n item.glyph.request.character,\n item.x + item.box[0],\n item.y + item.box[1],\n )\n }\n const rgba = context.getImageData(0, 0, sheetW, sheetH).data\n const rowStride = sheetW * 4\n for (const item of sheet) {\n throwIfAborted(signal)\n const [originX, baselineY, width, height] = item.box\n const tileOffset = (item.y * sheetW + item.x) * 4\n if (touchesEdge(rgba, width, height, rowStride, tileOffset)) {\n retries.push(item.glyph)\n continue\n }\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width,\n height,\n stride: 4,\n offset: tileOffset + 3,\n rowStride,\n originX,\n baselineY,\n },\n tolerance,\n scratch,\n )\n keep(requests.get(item.glyph.request.key)!, {\n unitsPerEm: size,\n ascent: item.glyph.ascent,\n descent: -item.glyph.descent,\n bbox,\n quadratics,\n })\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n }\n\n if (plain.length < 2) {\n for (const item of plain) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n } else {\n let sheet: Tile[] = []\n let packX = 0\n let packY = 0\n let rowH = 0\n let sheetW = 0\n let sheetH = 0\n for (const { glyph, box } of plain) {\n const width = box[2]\n const height = box[3]\n if (packX > 0 && packX + width > MAX_SHEET) {\n packX = 0\n packY += rowH + SHEET_GAP\n rowH = 0\n }\n if (packY + height > MAX_SHEET) {\n await flushSheet(sheet, sheetW, sheetH)\n sheet = []\n packX = 0\n packY = 0\n rowH = 0\n sheetW = 0\n sheetH = 0\n }\n sheet.push({ glyph, box, x: packX, y: packY })\n sheetW = Math.max(sheetW, packX + width)\n sheetH = Math.max(sheetH, packY + height)\n packX += width + SHEET_GAP\n rowH = Math.max(rowH, height)\n }\n if (sheet.length > 0) await flushSheet(sheet, sheetW, sheetH)\n }\n for (const item of oversized) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n for (const glyph of retries) {\n throwIfAborted(signal)\n await finishGlyph(glyph, boxOf(glyph.reach, margin + size / 2), true)\n }\n }\n return results\n } finally {\n // Release the backing store now: Safari counts a detached canvas against its canvas\n // memory until it is collected.\n canvas.width = 0\n canvas.height = 0\n canvas.remove()\n }\n }\n\n const provider: WindfoilOutlineProvider = (request, signal) => {\n throwIfAborted(signal)\n const cached = cache.get(request.key)\n if (cached !== undefined) return cached\n let batch = open.get(signal)\n if (!batch) {\n const requests = new Map<string, GlyphRequest>()\n // Everything this task asks for with this signal joins before the batch starts. What a\n // clear() before then would drop is not cached either.\n const started = epoch\n const next: Batch = {\n signal,\n requests,\n done: Promise.resolve().then(() => {\n if (open.get(signal) === next) open.delete(signal)\n return run(signal, requests, started)\n }),\n }\n open.set(signal, (batch = next))\n }\n batch.requests.set(request.key, request)\n return batch.done.then((results) => results.get(request.key) ?? null)\n }\n\n return {\n provider,\n clear() {\n epoch++\n cache.clear()\n },\n retain(keys) {\n const live = new Set(keys)\n for (const key of cache.keys()) if (!live.has(key)) cache.delete(key)\n },\n }\n}\n"],"mappings":";;;;AAoCA,IAAM,WAAW;;AAEjB,IAAM,gBAAgB;AACtB,IAAM,aAAa;AAkBnB,SAAS,eAAe,QAA2B;CACjD,IAAI,OAAO,SACT,MAAM,OAAO,UAAU,IAAI,aAAa,iCAAiC,YAAY;AAEzF;;;;;;AAOA,SAAS,WAA0B;CACjC,OAAO,IAAI,SAAS,YAAY;EAC9B,IAAI,OAAO,mBAAmB,YAAY;GACxC,WAAW,SAAS,CAAC;GACrB;EACF;EACA,MAAM,EAAE,OAAO,UAAU,IAAI,eAAe;EAC5C,MAAM,kBAAkB;GACtB,MAAM,MAAM;GACZ,QAAQ;EACV;EACA,MAAM,YAAY,IAAI;CACxB,CAAC;AACH;;AAGA,SAAS,MACP,OACA,QACqE;CACrE,MAAM,UAAU,SAAS,KAAK,KAAK,MAAM,EAAE;CAC3C,MAAM,YAAY,SAAS,KAAK,KAAK,MAAM,EAAE;CAC7C,OAAO;EACL;EACA;EACA,UAAU,KAAK,KAAK,MAAM,EAAE,IAAI;EAChC,YAAY,KAAK,KAAK,MAAM,EAAE,IAAI;CACpC;AACF;;AAGA,SAAS,YACP,MACA,OACA,QACA,YAAY,QAAQ,GACpB,aAAa,GACJ;CACT,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,KACzB,IACE,KAAK,aAAa,IAAI,IAAI,KAAM,KAChC,KAAK,cAAc,SAAS,KAAK,YAAY,IAAI,IAAI,KAAM,GAE3D,OAAO;CAGX,KAAK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Ae,MAAM;KACrB,MAAM,YAAY,OAAO,MAAM,MAAM,OAAO,SAAS,OAAO,CAAC,GAAG,IAAI;IACtE;GACF;GACA,OAAO;EACT,UAAU;GAGR,OAAO,QAAQ;GACf,OAAO,SAAS;GAChB,OAAO,OAAO;EAChB;CACF;CAEA,MAAM,YAAqC,SAAS,WAAW;EAC7D,eAAe,MAAM;EACrB,MAAM,SAAS,MAAM,IAAI,QAAQ,GAAG;EACpC,IAAI,WAAW,KAAA,GAAW,OAAO;EACjC,IAAI,QAAQ,KAAK,IAAI,MAAM;EAC3B,IAAI,CAAC,OAAO;GACV,MAAM,2BAAW,IAAI,IAA0B;GAG/C,MAAM,UAAU;GAChB,MAAM,OAAc;IAClB;IACA;IACA,MAAM,QAAQ,QAAQ,CAAC,CAAC,WAAW;KACjC,IAAI,KAAK,IAAI,MAAM,MAAM,MAAM,KAAK,OAAO,MAAM;KACjD,OAAO,IAAI,QAAQ,UAAU,OAAO;IACtC,CAAC;GACH;GACA,KAAK,IAAI,QAAS,QAAQ,IAAK;EACjC;EACA,MAAM,SAAS,IAAI,QAAQ,KAAK,OAAO;EACvC,OAAO,MAAM,KAAK,MAAM,YAAY,QAAQ,IAAI,QAAQ,GAAG,KAAK,IAAI;CACtE;CAEA,OAAO;EACL;EACA,QAAQ;GACN;GACA,MAAM,MAAM;EACd;EACA,OAAO,MAAM;GACX,MAAM,OAAO,IAAI,IAAI,IAAI;GACzB,KAAK,MAAM,OAAO,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,GAAG,GAAG,MAAM,OAAO,GAAG;EACtE;CACF;AACF"}
1
+ {"version":3,"file":"tracedOutlines.js","names":[],"sources":["../../src/windfoil/tracedOutlines.ts"],"sourcesContent":["import {\n allFontsLoaded,\n createCanvas,\n isColorCandidate,\n setFontContext,\n waitForFonts,\n} from '../dom/fontCanvas.js'\nimport type {\n ColorGlyphMode,\n FontStyleSnapshot,\n GlyphRequest,\n WindfoilGlyphOutline,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { createTraceScratch, traceCoverage } from './trace/outline.js'\nimport {\n prepareTraceWorker,\n traceSheetInWorker,\n type PreparedTraceWorker,\n type TraceWorkerTile,\n} from './trace/traceWorker.js'\n\n/** Options of the built-in Canvas 2D outline tracer. */\nexport interface TracedOutlineOptions {\n /** Trace resolution in pixels per em, also each outline's `unitsPerEm`. Defaults to `256`. */\n readonly size?: number\n /** Furthest, in trace pixels, a fitted curve may stray from its contour. Defaults to `0.25`. */\n readonly tolerance?: number\n /** Which glyphs to test for colour ink, as `DomSdfOptions.colorGlyphs`. Defaults to `'emoji'`. */\n readonly colorGlyphs?: ColorGlyphMode\n /** Run contour tracing and quadratic fitting in Web Workers when available. Defaults to `true`. */\n readonly worker?: boolean\n}\n\n/** A `WindfoilOutlineProvider` that traces the browser's own glyphs, and its cache. */\nexport interface TracedOutlines {\n readonly provider: WindfoilOutlineProvider\n /** Forgets every traced outline, as after a webfont load; work in flight is not kept. */\n clear(): void\n /** Forgets the outlines of every glyph key not listed. */\n retain(keys: Iterable<string>): void\n}\n\n/** A batch yields to the page once it has traced for this long. */\nconst SLICE_MS = 8\n/** A font assignment the canvas rejects leaves this one in place. */\nconst SENTINEL_FONT = '1px serif'\nconst SIZE_TOKEN = /[\\d.]+px/\n\n/** The requests one task made with one signal, traced together. */\ninterface Batch {\n readonly signal: AbortSignal\n readonly requests: Map<string, GlyphRequest>\n readonly done: Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>>\n}\n\n/** One glyph between measuring and tracing, in trace pixels; y grows downwards. */\ninterface Measured {\n readonly request: GlyphRequest\n readonly ascent: number\n readonly descent: number\n /** How far the ink box and the font box reach from the pen: left, right, up and down. */\n readonly reach: readonly [number, number, number, number]\n}\n\nfunction throwIfAborted(signal: AbortSignal): void {\n if (signal.aborted) {\n throw signal.reason ?? new DOMException('The outline trace was aborted', 'AbortError')\n }\n}\n\n/**\n * A task after the page's own: a message is not clamped to 4 ms as a nested timer is, and it\n * does not run ahead of rendering as a `scheduler.yield()` continuation does, which held frames\n * back for 100 ms at a time in Chrome 156.\n */\nfunction nextTask(): Promise<void> {\n return new Promise((resolve) => {\n if (typeof MessageChannel !== 'function') {\n setTimeout(resolve, 0)\n return\n }\n const { port1, port2 } = new MessageChannel()\n port1.onmessage = () => {\n port1.close()\n resolve()\n }\n port2.postMessage(null)\n })\n}\n\n/** Canvas box of a glyph with `margin` pixels around its reach: pen position and size. */\nfunction boxOf(\n reach: Measured['reach'],\n margin: number,\n): [originX: number, baselineY: number, width: number, height: number] {\n const originX = margin + Math.ceil(reach[0])\n const baselineY = margin + Math.ceil(reach[2])\n return [\n originX,\n baselineY,\n originX + Math.ceil(reach[1]) + margin,\n baselineY + Math.ceil(reach[3]) + margin,\n ]\n}\n\n/** Whether any texel on the edge of a `width` x `height` RGBA read holds ink. */\nconst ALPHA_MASK_U32 =\n new Uint8Array(new Uint32Array([0x01020304]).buffer)[0] === 0x04 ? 0xff000000 : 0x000000ff\n\nfunction touchesEdge(\n rgba: Uint8ClampedArray,\n width: number,\n height: number,\n rowStride = width * 4,\n baseOffset = 0,\n pixels32?: Uint32Array,\n): boolean {\n if (pixels32) {\n const rowWords = rowStride >>> 2\n const baseWord = baseOffset >>> 2\n const bottomWord = baseWord + (height - 1) * rowWords\n for (let x = 0; x < width; x++) {\n if (\n (pixels32[baseWord + x]! & ALPHA_MASK_U32) !== 0 ||\n (pixels32[bottomWord + x]! & ALPHA_MASK_U32) !== 0\n ) {\n return true\n }\n }\n const rightCol = width - 1\n for (let y = 0; y < height; y++) {\n const row = baseWord + y * rowWords\n if (\n (pixels32[row]! & ALPHA_MASK_U32) !== 0 ||\n (pixels32[row + rightCol]! & ALPHA_MASK_U32) !== 0\n ) {\n return true\n }\n }\n return false\n }\n for (let x = 0; x < width; x++) {\n if (\n rgba[baseOffset + x * 4 + 3]! > 0 ||\n rgba[baseOffset + (height - 1) * rowStride + x * 4 + 3]! > 0\n ) {\n return true\n }\n }\n for (let y = 0; y < height; y++) {\n const row = baseOffset + y * rowStride\n if (rgba[row + 3]! > 0 || rgba[row + (width - 1) * 4 + 3]! > 0) return true\n }\n return false\n}\n\nconst MAX_SHEET = 2048\nconst SHEET_GAP = 0\n\n/**\n * The outline provider `DomSdf` and `DomSlug` use for Windfoil and Slug text when the caller gives\n * none. Each glyph is drawn as the SDF rasterizer draws it (the captured canvas font with its\n * stretch and kerning, an in-document canvas without font smoothing, exact geometry, a neutral\n * grey), at `size` pixels per em, then traced at half coverage and fitted with quadratics. The\n * outline follows that raster, not the font file: font-variation and feature settings are not\n * applied, as on any canvas. Colour glyphs, glyphs of a font the canvas rejects and shaped runs\n * resolve to `null`, for the SDF companion; a glyph without ink to an empty outline. Without a\n * 2D canvas every glyph is `null`, so the whole capture falls back to SDF. `descent` is the SDF\n * slot's, measured at the captured font's own size, so analytic and SDF glyphs share a baseline.\n * Ink the metrics miss is drawn again with half an em more room all round; a glyph whose ink\n * still reaches the edge of its box resolves to `null` too, rather than trace clipped.\n *\n * Calls made in one task with one signal trace as one batch, in slices of about 8 ms between\n * which the page runs and the signal is checked. Each batch has its own working memory, which\n * goes with it. Outlines stay cached per instance until `clear()` or `retain()` drops them; one\n * traced while `document.fonts.check()` still reported its font as not ready is never cached.\n */\nexport function createTracedOutlineProvider(\n document: Document,\n options: TracedOutlineOptions = {},\n): TracedOutlines {\n const size = options.size ?? 256\n const tolerance = options.tolerance ?? 0.25\n const colorGlyphs = options.colorGlyphs ?? 'emoji'\n const workerEnabled = options.worker ?? true\n const cache = new Map<string, WindfoilGlyphOutline | null>()\n let epoch = 0\n let cachedCanvas: HTMLCanvasElement | null = null\n let cachedContext: CanvasRenderingContext2D | null = null\n /** The batches still open to requests of this task, by signal. */\n const open = new Map<AbortSignal, Batch>()\n\n const run = async (\n signal: AbortSignal,\n requests: ReadonlyMap<string, GlyphRequest>,\n started: number,\n ): Promise<ReadonlyMap<string, WindfoilGlyphOutline | null>> => {\n const results = new Map<string, WindfoilGlyphOutline | null>()\n // Each font of the batch, as captured and as traced: the captured canvas font with only\n // its size rewritten, as an adaptive SDF bake does.\n const groups = new Map<string, [GlyphRequest[], GlyphRequest[], FontStyleSnapshot]>()\n const waitList: GlyphRequest[] = []\n for (const request of requests.values()) {\n // Shapes resolve elsewhere; a shaped run is one tile of a line, which no outline covers.\n if (request.shape || request.shaping) {\n results.set(request.key, null)\n continue\n }\n let group = groups.get(request.font.key)\n if (!group) {\n const font = request.font\n group = [[], [], { ...font, canvasFont: font.canvasFont.replace(SIZE_TOKEN, `${size}px`) }]\n groups.set(font.key, group)\n }\n const tracedReq: GlyphRequest = {\n key: request.key,\n character: request.character,\n font: group[2],\n }\n group[0].push(request)\n group[1].push(tracedReq)\n waitList.push(tracedReq)\n }\n await waitForFonts(document, waitList, signal)\n throwIfAborted(signal)\n\n const preloaded = allFontsLoaded(document)\n const fonts = document.fonts as FontFaceSet | undefined\n const keep = (request: GlyphRequest, outline: WindfoilGlyphOutline | null): void => {\n results.set(request.key, outline)\n let ready = epoch === started\n if (ready && !preloaded) {\n try {\n ready =\n fonts?.check(groups.get(request.font.key)![2].canvasFont, request.character) ?? true\n } catch {\n ready = false\n }\n }\n if (ready) cache.set(request.key, outline)\n }\n\n let canvas: HTMLCanvasElement\n let context: CanvasRenderingContext2D | null\n if (cachedCanvas?.ownerDocument === document && cachedContext) {\n canvas = cachedCanvas\n canvas.width = 1\n canvas.height = 1\n document.documentElement.append(canvas)\n context = cachedContext\n } else {\n canvas = createCanvas(document)\n context = canvas.getContext('2d', { willReadFrequently: true })\n if (context) {\n cachedCanvas = canvas\n cachedContext = context\n }\n }\n try {\n if (!context) {\n // Not cached: the whole capture falls back to SDF, and a later build may try again.\n for (const [list] of groups.values())\n for (const request of list) results.set(request.key, null)\n return results\n }\n let current: FontStyleSnapshot | null = null\n const accepted = new Map<FontStyleSnapshot, boolean>()\n /** Applies a request's font as the rasterizer does; false when the canvas rejected it. */\n const use = (request: GlyphRequest): boolean => {\n if (current !== request.font) {\n context.font = SENTINEL_FONT\n const sentinel = context.font\n setFontContext(context, request, undefined, null)\n current = request.font\n accepted.set(request.font, context.font !== sentinel)\n }\n return accepted.get(request.font)!\n }\n\n // Measure every glyph first: sizing the canvas resets its context.\n const margin = Math.max(4, Math.ceil(size / 32))\n const measured: Measured[] = []\n for (const [list, tracedList] of groups.values()) {\n throwIfAborted(signal)\n const bake = Number.parseFloat(SIZE_TOKEN.exec(list[0]!.font.canvasFont)?.[0] ?? '')\n if (!(bake > 0) || !use(list[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n // The SDF slot's metrics, measured at the captured font's own size.\n const scale = size / bake\n const firstSlot = list.length > 0 ? context.measureText(list[0]!.character) : null\n const sharedSlot =\n firstSlot && firstSlot.fontBoundingBoxAscent > 0 && firstSlot.fontBoundingBoxDescent > 0\n ? ([\n Math.max(1, firstSlot.fontBoundingBoxAscent) * scale,\n Math.max(1, firstSlot.fontBoundingBoxDescent) * scale,\n ] as const)\n : null\n const slots = sharedSlot\n ? list.map(() => sharedSlot)\n : list.map((request) => {\n const slot = context.measureText(request.character)\n return [\n Math.max(1, slot.fontBoundingBoxAscent || slot.actualBoundingBoxAscent) * scale,\n Math.max(1, slot.fontBoundingBoxDescent || slot.actualBoundingBoxDescent) * scale,\n ] as const\n })\n if (!use(tracedList[0]!)) {\n for (const request of list) keep(request, null)\n continue\n }\n for (let index = 0; index < list.length; index++) {\n const request = list[index]!\n const tracedReq = tracedList[index]!\n const [ascent, descent] = slots[index]!\n // Ink can only be found in the tight actual bounding box when reported, or the font box.\n const metrics = context.measureText(request.character)\n const hasHBox = metrics.actualBoundingBoxLeft > 0 || metrics.actualBoundingBoxRight > 0\n const hasVBox =\n metrics.actualBoundingBoxAscent > 0 || metrics.actualBoundingBoxDescent > 0\n const reach = [\n Math.max(0, metrics.actualBoundingBoxLeft || 0),\n Math.max(hasHBox ? 0 : metrics.width || 0, metrics.actualBoundingBoxRight || 0),\n Math.max(hasVBox ? 0 : ascent, metrics.actualBoundingBoxAscent || 0),\n Math.max(hasVBox ? 0 : descent, metrics.actualBoundingBoxDescent || 0),\n ] as const\n const [, , width, height] = boxOf(reach, margin)\n if (!(width <= 8 * size && height <= 8 * size)) {\n keep(request, null)\n continue\n }\n measured.push({ request: tracedReq, ascent, descent, reach })\n }\n }\n const resize = (width: number, height: number): boolean => {\n if (width <= canvas.width && height <= canvas.height) return false\n canvas.width = Math.max(width, canvas.width)\n canvas.height = Math.max(height, canvas.height)\n current = null\n return true\n }\n\n const exact = 'textRendering' in context\n const draw = (\n glyph: Measured,\n [originX, baselineY, width, height]: ReturnType<typeof boxOf>,\n fill: string,\n rendering: CanvasTextRendering,\n ): Uint8ClampedArray => {\n const resized = resize(width, height)\n use(glyph.request)\n context.fillStyle = fill\n if (exact) context.textRendering = rendering\n if (!resized) context.clearRect(0, 0, width, height)\n context.fillText(glyph.request.character, originX, baselineY)\n return context.getImageData(0, 0, width, height).data\n }\n const colorModule = measured.some((glyph) => isColorCandidate(glyph.request, colorGlyphs))\n ? await import('../atlas/colorGlyphs.js')\n : null\n throwIfAborted(signal)\n // This batch's working memory, grown to fit its largest glyph (about 1 MB at 256 px per\n // em) and released with the batch, so an idle tracer holds none.\n const scratch = createTraceScratch()\n let sliceStart = performance.now()\n const view = document.defaultView\n const getContextFn = view\n ? (Object.getOwnPropertyDescriptor(view.HTMLCanvasElement.prototype, 'getContext')\n ?.value as object | undefined)\n : undefined\n const mockedCanvas = !getContextFn || 'mock' in getContextFn\n // Candidates drawn entirely in the fill colour can be traced as monochrome outlines.\n const hasColor = (glyph: Measured, box: ReturnType<typeof boxOf>): boolean => {\n if (!colorModule || !isColorCandidate(glyph.request, colorGlyphs)) return false\n const [, , width, height] = box\n return colorModule.slotHasColor(\n draw(glyph, box, '#fff', 'auto'),\n draw(glyph, box, '#000', 'auto'),\n width,\n { x: 0, y: 0, width, height },\n )\n }\n const useWorker = workerEnabled && !mockedCanvas && typeof Worker !== 'undefined'\n const preparedWorkers: PreparedTraceWorker[] = []\n const cropRetryRgba = (\n rgba: Uint8ClampedArray,\n box: readonly [number, number, number, number],\n ): {\n alpha: Uint8ClampedArray\n width: number\n height: number\n rowStride: number\n offset: number\n originX: number\n baselineY: number\n } | null => {\n const w = box[2]\n const h = box[3]\n const words = new Int32Array(rgba.buffer, rgba.byteOffset, rgba.byteLength >>> 2)\n let minX = w\n let maxX = -1\n let minY = h\n let maxY = -1\n for (let y = 0, row = 0; y < h; y++, row += w) {\n let rowHasInk = false\n for (let x = 0; x < w; x++) {\n if (words[row + x]! < 0) {\n if (!rowHasInk) {\n rowHasInk = true\n if (y < minY) minY = y\n maxY = y\n }\n if (x < minX) minX = x\n if (x > maxX) maxX = x\n }\n }\n }\n if (maxX < minX || maxY < minY) return null\n const pad = 2\n const x0 = Math.max(0, minX - pad)\n const y0 = Math.max(0, minY - pad)\n const x1 = Math.min(w, maxX + pad + 1)\n const y1 = Math.min(h, maxY + pad + 1)\n return {\n alpha: rgba,\n width: x1 - x0,\n height: y1 - y0,\n rowStride: w * 4,\n offset: (y0 * w + x0) * 4 + 3,\n originX: box[0] - x0,\n baselineY: box[1] - y0,\n }\n }\n const finishGlyph = async (\n glyph: Measured,\n box: ReturnType<typeof boxOf>,\n retried: boolean,\n ): Promise<void> => {\n // The SDF bake's text rendering: exact geometry, the neutral middle of a contrast table.\n let currentBox = box\n let rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n let clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n if (clipped && !retried) {\n // The metrics missed some ink: once more with half an em of room all round.\n currentBox = boxOf(glyph.reach, margin + size / 2)\n rgba = draw(glyph, currentBox, '#606060', 'geometricPrecision')\n clipped = touchesEdge(rgba, currentBox[2], currentBox[3])\n retried = true\n }\n // Ink past even that room would trace clipped: the SDF companion draws the glyph.\n let outline: WindfoilGlyphOutline | null = null\n if (!clipped) {\n const cropped = !mockedCanvas && retried ? cropRetryRgba(rgba, currentBox) : null\n const { quadratics, bbox } = traceCoverage(\n cropped\n ? {\n alpha: cropped.alpha,\n width: cropped.width,\n height: cropped.height,\n stride: 4,\n offset: cropped.offset,\n rowStride: cropped.rowStride,\n originX: cropped.originX,\n baselineY: cropped.baselineY,\n }\n : {\n alpha: rgba,\n width: currentBox[2],\n height: currentBox[3],\n stride: 4,\n offset: 3,\n originX: currentBox[0],\n baselineY: currentBox[1],\n },\n tolerance,\n scratch,\n )\n outline = {\n unitsPerEm: size,\n ascent: glyph.ascent,\n descent: -glyph.descent,\n bbox,\n quadratics,\n }\n }\n keep(requests.get(glyph.request.key)!, outline)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n\n if (mockedCanvas || measured.length < 2) {\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, margin)\n if (hasColor(glyph, box)) {\n keep(requests.get(glyph.request.key)!, null)\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n continue\n }\n await finishGlyph(glyph, box, false)\n }\n } else {\n interface Tile {\n readonly glyph: Measured\n readonly box: ReturnType<typeof boxOf>\n readonly x: number\n readonly y: number\n }\n const plain: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const oversized: { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[] = []\n const retries: Measured[] = []\n const sheetMargin = Math.max(2, Math.round(size / 128))\n for (const glyph of measured) {\n throwIfAborted(signal)\n const box = boxOf(glyph.reach, sheetMargin)\n const [, , width, height] = box\n if (hasColor(glyph, box)) {\n keep(requests.get(glyph.request.key)!, null)\n continue\n }\n if (width > MAX_SHEET || height > MAX_SHEET) oversized.push({ glyph, box })\n else plain.push({ glyph, box })\n }\n\n const hw = typeof navigator !== 'undefined' ? navigator.hardwareConcurrency || 2 : 2\n const maxShards = useWorker ? Math.max(1, Math.min(4, hw)) : 1\n const shardCount =\n useWorker && plain.length >= 12 && maxShards > 1\n ? Math.min(maxShards, Math.floor(plain.length / 6))\n : 1\n if (useWorker && plain.length >= 2) {\n for (let i = 0; i < shardCount; i++) {\n const worker = prepareTraceWorker()\n if (worker) preparedWorkers.push(worker)\n }\n }\n\n const drawSheet = (\n sheet: readonly Tile[],\n sheetW: number,\n sheetH: number,\n ): Uint8ClampedArray => {\n const resized = resize(sheetW, sheetH)\n if (!resized) context.clearRect(0, 0, sheetW, sheetH)\n context.fillStyle = '#606060'\n if (exact) context.textRendering = 'geometricPrecision'\n for (const item of sheet) {\n throwIfAborted(signal)\n use(item.glyph.request)\n context.fillText(\n item.glyph.request.character,\n item.x + item.box[0],\n item.y + item.box[1],\n )\n }\n return context.getImageData(0, 0, sheetW, sheetH).data\n }\n\n const traceSheetMain = async (\n tiles: readonly Tile[],\n rgba: Uint8ClampedArray,\n rowStride: number,\n ): Promise<void> => {\n for (const item of tiles) {\n throwIfAborted(signal)\n const [originX, baselineY, width, height] = item.box\n const tileOffset = (item.y * (rowStride >>> 2) + item.x) * 4\n const { quadratics, bbox } = traceCoverage(\n {\n alpha: rgba,\n width,\n height,\n stride: 4,\n offset: tileOffset + 3,\n rowStride,\n originX,\n baselineY,\n },\n tolerance,\n scratch,\n )\n keep(requests.get(item.glyph.request.key)!, {\n unitsPerEm: size,\n ascent: item.glyph.ascent,\n descent: -item.glyph.descent,\n bbox,\n quadratics,\n })\n if (performance.now() - sliceStart > SLICE_MS) {\n await nextTask()\n throwIfAborted(signal)\n sliceStart = performance.now()\n }\n }\n }\n\n const inFlight: Promise<void>[] = []\n\n const flushSheet = async (sheet: Tile[], sheetW: number, sheetH: number): Promise<void> => {\n const rgba = drawSheet(sheet, sheetW, sheetH)\n const rowStride = sheetW * 4\n const pixels32 =\n (rgba.byteOffset & 3) === 0 && (rgba.byteLength & 3) === 0 && (rowStride & 3) === 0\n ? new Uint32Array(rgba.buffer, rgba.byteOffset, rgba.byteLength >>> 2)\n : undefined\n const validTiles: Tile[] = []\n const workerTiles: TraceWorkerTile[] = []\n for (const item of sheet) {\n throwIfAborted(signal)\n const [originX, baselineY, width, height] = item.box\n const tileOffset = (item.y * sheetW + item.x) * 4\n if (touchesEdge(rgba, width, height, rowStride, tileOffset, pixels32)) {\n retries.push(item.glyph)\n continue\n }\n validTiles.push(item)\n if (useWorker) {\n workerTiles.push({ x: item.x, y: item.y, originX, baselineY, width, height })\n }\n }\n if (validTiles.length === 0) return\n\n if (!useWorker) {\n await traceSheetMain(validTiles, rgba, rowStride)\n return\n }\n\n const transferRgba =\n rgba.byteOffset === 0 && rgba.byteLength === rgba.buffer.byteLength\n ? rgba\n : rgba.slice()\n const ownedPrepared = preparedWorkers.shift() ?? null\n inFlight.push(\n (async () => {\n try {\n const traced = await traceSheetInWorker(\n { rgba: transferRgba, rowStride, tolerance, tiles: workerTiles },\n signal,\n ownedPrepared,\n )\n throwIfAborted(signal)\n for (let i = 0; i < validTiles.length; i++) {\n const item = validTiles[i]!\n const result = traced[i]!\n keep(requests.get(item.glyph.request.key)!, {\n unitsPerEm: size,\n ascent: item.glyph.ascent,\n descent: -item.glyph.descent,\n bbox: result.bbox,\n quadratics: result.quadratics,\n })\n }\n } catch (error) {\n if (signal.aborted) throw error\n const fallbackRgba =\n transferRgba.byteLength > 0 ? transferRgba : drawSheet(validTiles, sheetW, sheetH)\n await traceSheetMain(validTiles, fallbackRgba, rowStride)\n }\n })(),\n )\n }\n\n interface PackedSheet {\n readonly tiles: Tile[]\n readonly sheetW: number\n readonly sheetH: number\n }\n const packSkyline = (\n items: readonly { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[],\n ): PackedSheet[] => {\n let totalArea = 0\n let maxItemW = 0\n for (const { box } of items) {\n totalArea += box[2] * box[3]\n if (box[2] > maxItemW) maxItemW = box[2]\n }\n const packWithWidth = (targetW: number): PackedSheet[] => {\n const sheets: PackedSheet[] = []\n let sky: { x: number; y: number; w: number }[] = [{ x: 0, y: 0, w: targetW }]\n let tiles: Tile[] = []\n let sheetW = 0\n let sheetH = 0\n const placeItem = (\n glyph: Measured,\n box: ReturnType<typeof boxOf>,\n limitW: number,\n ): boolean => {\n const width = box[2]\n const height = box[3]\n const bw = width + SHEET_GAP\n const bh = height + SHEET_GAP\n let bestY = Infinity\n let bestIdx = -1\n let bestX = 0\n for (let i = 0; i < sky.length; i++) {\n const sx = sky[i]!.x\n if (sx + width > limitW) break\n let maxY = 0\n let rem = bw\n let j = i\n while (j < sky.length && rem > 0) {\n if (sky[j]!.y > maxY) maxY = sky[j]!.y\n rem -= sky[j]!.w\n j++\n }\n if (maxY + height <= MAX_SHEET && maxY < bestY) {\n bestY = maxY\n bestIdx = i\n bestX = sx\n }\n }\n if (bestIdx === -1) return false\n tiles.push({ glyph, box, x: bestX, y: bestY })\n sheetW = Math.max(sheetW, bestX + width)\n sheetH = Math.max(sheetH, bestY + height)\n const newW = Math.min(bw, limitW - bestX)\n const nEnd = bestX + newW\n const next: { x: number; y: number; w: number }[] = []\n for (const seg of sky) {\n const sEnd = seg.x + seg.w\n if (sEnd <= bestX || seg.x >= nEnd) {\n next.push(seg)\n } else {\n if (seg.x < bestX) next.push({ x: seg.x, y: seg.y, w: bestX - seg.x })\n if (sEnd > nEnd) next.push({ x: nEnd, y: seg.y, w: sEnd - nEnd })\n }\n }\n next.push({ x: bestX, y: bestY + bh, w: newW })\n next.sort((a, b) => a.x - b.x)\n sky = [next[0]!]\n for (let i = 1; i < next.length; i++) {\n const seg = next[i]!\n const prev = sky[sky.length - 1]!\n if (seg.y === prev.y) prev.w += seg.w\n else sky.push(seg)\n }\n return true\n }\n for (const { glyph, box } of items) {\n if (!placeItem(glyph, box, targetW)) {\n if (tiles.length > 0) sheets.push({ tiles, sheetW, sheetH })\n sky = [{ x: 0, y: 0, w: targetW }]\n tiles = []\n sheetW = 0\n sheetH = 0\n placeItem(glyph, box, targetW)\n }\n }\n if (tiles.length > 0) sheets.push({ tiles, sheetW, sheetH })\n return sheets\n }\n const areaOf = (sheets: PackedSheet[]): number => {\n let sum = 0\n for (const s of sheets) sum += s.sheetW * s.sheetH\n return sum\n }\n const w1 = Math.min(MAX_SHEET, Math.max(maxItemW, Math.ceil(Math.sqrt(totalArea * 0.96))))\n const best = packWithWidth(w1)\n const w2 = Math.min(MAX_SHEET, Math.max(maxItemW, Math.ceil(Math.sqrt(totalArea * 1.12))))\n if (w2 !== w1) {\n const cand = packWithWidth(w2)\n if (areaOf(cand) < areaOf(best)) return cand\n }\n return best\n }\n\n try {\n if (plain.length < 2) {\n for (const item of plain) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n } else {\n plain.sort((a, b) => b.box[3] - a.box[3] || b.box[2] - a.box[2])\n const packedSheets: PackedSheet[] = []\n if (shardCount === 1) {\n packedSheets.push(...packSkyline(plain))\n } else {\n // Front-load earlier shards (draw+post serially feeds workers 0..k-1), weighting\n // tile complexity by box perimeter so every worker finishes near the last sheet's draw.\n const shards = Array.from(\n { length: shardCount },\n () => [] as { readonly glyph: Measured; readonly box: ReturnType<typeof boxOf> }[],\n )\n const load = new Float64Array(shardCount)\n let totalWeight = 0\n for (const item of plain) totalWeight += item.box[2] + item.box[3]\n const target = new Float64Array(shardCount)\n let norm = 0\n for (let s = 0; s < shardCount; s++) {\n const w = 1 + (shardCount - 1 - s) * 0.25\n target[s] = w\n norm += w\n }\n for (let s = 0; s < shardCount; s++) {\n target[s] = Math.max(1, (target[s]! / norm) * totalWeight)\n }\n let cursor = 0\n for (const item of plain) {\n const weight = item.box[2] + item.box[3]\n // Rotate starting check round-robin so tall heavy glyphs spread evenly, while\n // keeping earlier shards slightly fuller to overlap with later draws.\n let best = cursor % shardCount\n let bestRatio = load[best]! / target[best]!\n for (let off = 1; off < shardCount; off++) {\n const s = (cursor + off) % shardCount\n const ratio = load[s]! / target[s]!\n if (ratio < bestRatio) {\n bestRatio = ratio\n best = s\n }\n }\n cursor = best + 1\n shards[best]!.push(item)\n load[best]! += weight\n }\n for (const shard of shards) {\n if (shard.length > 0) packedSheets.push(...packSkyline(shard))\n }\n }\n let maxW = 0\n let maxH = 0\n for (const sheet of packedSheets) {\n if (sheet.sheetW > maxW) maxW = sheet.sheetW\n if (sheet.sheetH > maxH) maxH = sheet.sheetH\n }\n if (maxW > 0 && maxH > 0) resize(maxW, maxH)\n for (const sheet of packedSheets) {\n await flushSheet(sheet.tiles, sheet.sheetW, sheet.sheetH)\n }\n }\n for (const item of oversized) {\n throwIfAborted(signal)\n await finishGlyph(item.glyph, item.box, false)\n }\n for (const glyph of retries) {\n throwIfAborted(signal)\n await finishGlyph(glyph, boxOf(glyph.reach, margin + size / 2), true)\n }\n } catch (error) {\n for (const worker of preparedWorkers) worker.dispose()\n if (inFlight.length > 0) await Promise.allSettled(inFlight)\n throw error\n }\n for (const worker of preparedWorkers) worker.dispose()\n if (inFlight.length > 0) await Promise.all(inFlight)\n }\n return results\n } finally {\n // Release the backing store now: Safari counts a detached canvas against its canvas\n // memory until it is collected.\n canvas.width = 0\n canvas.height = 0\n canvas.remove()\n }\n }\n\n const provider: WindfoilOutlineProvider = (request, signal) => {\n throwIfAborted(signal)\n const cached = cache.get(request.key)\n if (cached !== undefined) return cached\n let batch = open.get(signal)\n if (!batch) {\n const requests = new Map<string, GlyphRequest>()\n // Everything this task asks for with this signal joins before the batch starts. What a\n // clear() before then would drop is not cached either.\n const started = epoch\n const next: Batch = {\n signal,\n requests,\n done: Promise.resolve().then(() => {\n if (open.get(signal) === next) open.delete(signal)\n return run(signal, requests, started)\n }),\n }\n open.set(signal, (batch = next))\n }\n batch.requests.set(request.key, request)\n return batch.done.then((results) => results.get(request.key) ?? null)\n }\n\n return {\n provider,\n clear() {\n epoch++\n cache.clear()\n },\n retain(keys) {\n const live = new Set(keys)\n for (const key of cache.keys()) if (!live.has(key)) cache.delete(key)\n },\n }\n}\n"],"mappings":";;;;;AA4CA,IAAM,WAAW;;AAEjB,IAAM,gBAAgB;AACtB,IAAM,aAAa;AAkBnB,SAAS,eAAe,QAA2B;CACjD,IAAI,OAAO,SACT,MAAM,OAAO,UAAU,IAAI,aA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AG,GAAG,MAAM,OAAO,GAAG;EACtE;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ultra-text",
3
- "version": "1.0.1",
4
- "description": "DOM to WebGPU/TSL: real HTML, laid out by the browser, rendered as live 3D text (Three.js, R3F, TresJS, Mini3, and vanilla JS).",
3
+ "version": "1.0.3",
4
+ "description": "Real HTML & CSS rendered as live 3D WebGPU text in 1 draw call (SDF & analytic Slug) for Three.js TSL, R3F, TresJS, Mini3, and vanilla WebGPU.",
5
5
  "keywords": [
6
6
  "three",
7
7
  "three.js",
@@ -36,6 +36,7 @@
36
36
  "url": "git+https://github.com/Makio64/ultra-text.git"
37
37
  },
38
38
  "license": "MIT",
39
+ "funding": "https://github.com/sponsors/Makio64",
39
40
  "author": {
40
41
  "name": "David Ronai",
41
42
  "url": "https://makio.io"
@@ -134,16 +135,18 @@
134
135
  {
135
136
  "name": "public entry",
136
137
  "path": "dist/index.js",
137
- "limit": "38.5 kB",
138
+ "limit": "57 kB",
138
139
  "ignore": [
139
140
  "three",
140
141
  "@chenglou/pretext",
141
142
  "./dist/atlas/cpuAtlas.js",
142
143
  "./dist/dom/browserShaping.js",
144
+ "./dist/dom/cssEffects.js",
143
145
  "./dist/dom/pretextLayout.js",
144
146
  "./dist/windfoil/runtime.js",
145
147
  "./dist/slug/runtime.js",
146
148
  "./dist/atlas/colorGlyphs.js",
149
+ "./dist/atlas/colorTexture.js",
147
150
  "./dist/windfoil/shapes.js",
148
151
  "./dist/windfoil/svg/convert.js",
149
152
  "./dist/dom/svgCapture.js",
@@ -163,10 +166,11 @@
163
166
  {
164
167
  "name": "vanilla entry (Three-free)",
165
168
  "path": "dist/vanilla.js",
166
- "limit": "31 kB",
169
+ "limit": "47 kB",
167
170
  "ignore": [
168
171
  "@chenglou/pretext",
169
172
  "./dist/dom/browserShaping.js",
173
+ "./dist/dom/cssEffects.js",
170
174
  "./dist/dom/pretextLayout.js",
171
175
  "./dist/atlas/colorGlyphs.js",
172
176
  "./dist/windfoil/svg/convert.js",
@@ -178,11 +182,12 @@
178
182
  {
179
183
  "name": "slug entry (Three.js)",
180
184
  "path": "dist/slug.js",
181
- "limit": "44 kB",
185
+ "limit": "67 kB",
182
186
  "ignore": [
183
187
  "three",
184
188
  "@chenglou/pretext",
185
189
  "./dist/dom/browserShaping.js",
190
+ "./dist/dom/cssEffects.js",
186
191
  "./dist/dom/pretextLayout.js",
187
192
  "./dist/dom/svgCapture.js",
188
193
  "./dist/atlas/colorGlyphs.js",
@@ -198,10 +203,11 @@
198
203
  {
199
204
  "name": "slug-vanilla entry (Three-free)",
200
205
  "path": "dist/slug-vanilla.js",
201
- "limit": "38 kB",
206
+ "limit": "56.5 kB",
202
207
  "ignore": [
203
208
  "@chenglou/pretext",
204
209
  "./dist/dom/browserShaping.js",
210
+ "./dist/dom/cssEffects.js",
205
211
  "./dist/dom/pretextLayout.js",
206
212
  "./dist/dom/svgCapture.js",
207
213
  "./dist/atlas/colorGlyphs.js",
@@ -216,7 +222,7 @@
216
222
  {
217
223
  "name": "optional Pretext layout",
218
224
  "path": "dist/dom/pretextLayout.js",
219
- "limit": "2.7 kB",
225
+ "limit": "3.5 kB",
220
226
  "ignore": [
221
227
  "@chenglou/pretext",
222
228
  "./dist/dom/clusters.js",
@@ -226,12 +232,17 @@
226
232
  {
227
233
  "name": "optional browser shaping",
228
234
  "path": "dist/dom/browserShaping.js",
229
- "limit": "4.5 kB"
235
+ "limit": "3.6 kB"
236
+ },
237
+ {
238
+ "name": "optional CSS text effects",
239
+ "path": "dist/dom/cssEffects.js",
240
+ "limit": "1 kB"
230
241
  },
231
242
  {
232
243
  "name": "optional Windfoil backend",
233
244
  "path": "dist/windfoil/runtime.js",
234
- "limit": "16.5 kB",
245
+ "limit": "20.5 kB",
235
246
  "ignore": [
236
247
  "three",
237
248
  "@chenglou/pretext",
@@ -246,7 +257,7 @@
246
257
  {
247
258
  "name": "optional Slug backend",
248
259
  "path": "dist/slug/runtime.js",
249
- "limit": "16 kB",
260
+ "limit": "20.5 kB",
250
261
  "ignore": [
251
262
  "three",
252
263
  "@chenglou/pretext",
@@ -261,7 +272,7 @@
261
272
  {
262
273
  "name": "optional CPU fallback",
263
274
  "path": "dist/atlas/cpuAtlas.js",
264
- "limit": "3 kB",
275
+ "limit": "4.8 kB",
265
276
  "ignore": [
266
277
  "three"
267
278
  ]
@@ -269,12 +280,15 @@
269
280
  {
270
281
  "name": "CPU worker asset",
271
282
  "path": "dist/assets/cpuSdf.worker-*.js",
272
- "limit": "2.5 kB"
283
+ "limit": "2.8 kB"
273
284
  },
274
285
  {
275
286
  "name": "optional colour glyphs",
276
- "path": "dist/atlas/colorGlyphs.js",
277
- "limit": "2.5 kB",
287
+ "path": [
288
+ "dist/atlas/colorGlyphs.js",
289
+ "dist/atlas/colorTexture.js"
290
+ ],
291
+ "limit": "1.6 kB",
278
292
  "ignore": [
279
293
  "three"
280
294
  ]
@@ -282,7 +296,7 @@
282
296
  {
283
297
  "name": "optional Windfoil shapes",
284
298
  "path": "dist/windfoil/shapes.js",
285
- "limit": "18.5 kB",
299
+ "limit": "21 kB",
286
300
  "ignore": [
287
301
  "three",
288
302
  "@chenglou/pretext",
@@ -292,7 +306,7 @@
292
306
  {
293
307
  "name": "complete SVG converter",
294
308
  "path": "dist/windfoil/svg/convert.js",
295
- "limit": "14.5 kB",
309
+ "limit": "12 kB",
296
310
  "ignore": [
297
311
  "three"
298
312
  ]
@@ -300,19 +314,19 @@
300
314
  {
301
315
  "name": "optional SVG capture",
302
316
  "path": "dist/dom/svgCapture.js",
303
- "limit": "8.5 kB",
317
+ "limit": "5.6 kB",
304
318
  "ignore": []
305
319
  },
306
320
  {
307
321
  "name": "optional SVG raster",
308
322
  "path": "dist/atlas/shapeRaster.js",
309
- "limit": "2.5 kB",
323
+ "limit": "1.1 kB",
310
324
  "ignore": []
311
325
  },
312
326
  {
313
327
  "name": "optional Windfoil colour",
314
328
  "path": "dist/windfoil/color.js",
315
- "limit": "12.5 kB",
329
+ "limit": "11.5 kB",
316
330
  "ignore": [
317
331
  "three",
318
332
  "@chenglou/pretext",
@@ -324,7 +338,7 @@
324
338
  {
325
339
  "name": "optional SVG emoji provider",
326
340
  "path": "dist/windfoil/emoji.js",
327
- "limit": "2 kB",
341
+ "limit": "1.2 kB",
328
342
  "ignore": [
329
343
  "./dist/windfoil/svg/convert.js",
330
344
  "./dist/windfoil/emojiMetrics.js"
@@ -333,7 +347,7 @@
333
347
  {
334
348
  "name": "optional mixed text parts",
335
349
  "path": "dist/windfoil/mixed.js",
336
- "limit": "4 kB",
350
+ "limit": "4.7 kB",
337
351
  "ignore": [
338
352
  "three",
339
353
  "./dist/text/geometry.js",
@@ -345,7 +359,7 @@
345
359
  {
346
360
  "name": "optional Windfoil size switch",
347
361
  "path": "dist/windfoil/sizeSwitch.js",
348
- "limit": "2 kB",
362
+ "limit": "1.3 kB",
349
363
  "ignore": [
350
364
  "three",
351
365
  "./dist/dom/clusters.js",
@@ -357,7 +371,7 @@
357
371
  {
358
372
  "name": "DOM-free SVG path converter",
359
373
  "path": "dist/windfoil/svg/pathConverter.js",
360
- "limit": "9 kB",
374
+ "limit": "7.8 kB",
361
375
  "ignore": [
362
376
  "three"
363
377
  ]
@@ -365,7 +379,7 @@
365
379
  {
366
380
  "name": "SVG document adapter increment",
367
381
  "path": "dist/windfoil/svg/convert.js",
368
- "limit": "8.5 kB",
382
+ "limit": "5.8 kB",
369
383
  "ignore": [
370
384
  "three",
371
385
  "./dist/windfoil/svg/pathConverter.js"
@@ -374,7 +388,7 @@
374
388
  {
375
389
  "name": "optional Windfoil request handling",
376
390
  "path": "dist/windfoil/requests.js",
377
- "limit": "2.5 kB",
391
+ "limit": "1.2 kB",
378
392
  "ignore": [
379
393
  "three",
380
394
  "./dist/windfoil/svg/convert.js",
@@ -385,7 +399,7 @@
385
399
  {
386
400
  "name": "optional Windfoil layer validation",
387
401
  "path": "dist/windfoil/layerNormalization.js",
388
- "limit": "2.5 kB",
402
+ "limit": "1.6 kB",
389
403
  "ignore": [
390
404
  "./dist/windfoil/preprocessCore.js"
391
405
  ]
@@ -393,7 +407,7 @@
393
407
  {
394
408
  "name": "optional SVG emoji metrics",
395
409
  "path": "dist/windfoil/emojiMetrics.js",
396
- "limit": "2 kB",
410
+ "limit": "1.4 kB",
397
411
  "ignore": [
398
412
  "./dist/windfoil/svg/convert.js",
399
413
  "./dist/windfoil/svg/pathConverter.js",
@@ -403,7 +417,7 @@
403
417
  {
404
418
  "name": "optional atlas append",
405
419
  "path": "dist/atlas/appendAtlas.js",
406
- "limit": "4.5 kB",
420
+ "limit": "5.6 kB",
407
421
  "ignore": [
408
422
  "three",
409
423
  "./dist/atlas/rasterize.js",
@@ -415,12 +429,17 @@
415
429
  {
416
430
  "name": "optional traced outlines",
417
431
  "path": "dist/windfoil/tracedOutlines.js",
418
- "limit": "8.5 kB",
432
+ "limit": "15.6 kB",
419
433
  "ignore": [
420
434
  "three",
421
435
  "./dist/atlas/rasterize.js",
422
436
  "./dist/atlas/colorGlyphs.js"
423
437
  ]
438
+ },
439
+ {
440
+ "name": "trace worker asset",
441
+ "path": "dist/assets/traceOutline.worker-*.js",
442
+ "limit": "9.8 kB"
424
443
  }
425
444
  ]
426
445
  }
@@ -17,12 +17,12 @@ description: >-
17
17
 
18
18
  Never import internal module paths or `THREE.WebGLRenderer` (unsupported). Do not invent framework subpaths like `ultra-text/r3f`, `ultra-text/tres`, or `ultra-text/mini3`.
19
19
 
20
- | Entry point | Stack | Renderer / device | Coverage backend |
21
- | ------------------------- | --------------------------- | --------------------------------- | -------------------------------------------------------------- |
22
- | `ultra-text` | Three.js / R3F / TresJS | `WebGPURenderer` (`three/webgpu`) | SDF (GPU JFA / CPU EDT), plus optional `windfoil` or `slug` |
23
- | `ultra-text/slug` | Three.js Slug-only apps | `WebGPURenderer` (`three/webgpu`) | Pure analytic Slug (zero SDF code, `DomSlug` / `SlugText`) |
24
- | `ultra-text/vanilla` | Mini3 & custom engines | `GPUDevice` (Three.js-free) | SDF atlas + packed typed-array instance buffers |
25
- | `ultra-text/slug-vanilla` | Mini3 & custom Slug engines | `GPUDevice` (Three.js-free) | Pure analytic Slug + `SLUG_WGSL` / `createVanillaSlugPipeline` |
20
+ | Entry point | Stack | Renderer / device | Coverage backend |
21
+ | ------------------------- | --------------------------- | --------------------------------- | --------------------------------------------------------------------------- |
22
+ | `ultra-text` | Three.js / R3F / TresJS | `WebGPURenderer` (`three/webgpu`) | SDF (GPU AA-EDT / multi-worker CPU EDT), plus optional `windfoil` or `slug` |
23
+ | `ultra-text/slug` | Three.js Slug-only apps | `WebGPURenderer` (`three/webgpu`) | Pure analytic Slug (zero SDF code, `DomSlug` / `SlugText`) |
24
+ | `ultra-text/vanilla` | Mini3 & custom engines | `GPUDevice` (Three.js-free) | SDF atlas + packed typed-array instance buffers |
25
+ | `ultra-text/slug-vanilla` | Mini3 & custom Slug engines | `GPUDevice` (Three.js-free) | Pure analytic Slug + `SLUG_WGSL` / `createVanillaSlugPipeline` |
26
26
 
27
27
  - Install Three.js within `ultra-text`'s peer range (`three` `>=0.187.0 <0.188.0`) and keep a single Three.js instance across the app.
28
28
  - For Three-free engines, `three` is an optional peer dependency and does not need to be installed.
@@ -80,24 +80,23 @@ renderer.setAnimationLoop(() => renderer.render(scene, camera))
80
80
 
81
81
  ### Direct string text (`Text`)
82
82
 
83
- Use `Text` (in `ultra-text`) when there is no existing HTML block to mirror:
83
+ Use `Text` (in `ultra-text`, `ultra-text/slug`, `ultra-text/vanilla`, or `ultra-text/slug-vanilla`) when there is no existing HTML block to mirror:
84
84
 
85
85
  ```ts
86
86
  import { Text } from 'ultra-text'
87
87
 
88
- const label = new Text('Hello, WebGPU!', {
88
+ const label = await Text.create('Hello, WebGPU!', {
89
89
  renderer,
90
90
  css: { fontFamily: 'sans-serif', fontSize: 48, color: '#ffcc00', width: 320 },
91
91
  cssClass: 'headline',
92
92
  })
93
- await label.ready
94
93
  scene.add(label)
95
94
 
96
95
  label.text = 'Updated text'
97
96
  await label.rebuild()
98
97
  ```
99
98
 
100
- Note: `ultra-text` exports `new Text(message, options)` (`await label.ready`); `ultra-text/slug` (`SlugText`), `ultra-text/vanilla`, and `ultra-text/slug-vanilla` support both `new Text(...)` and `Text.create(...)`.
99
+ Note: every entry supports both `await Text.create(...)` and `new Text(...)` (`await label.ready`). Pass `textBackend: 'auto'` to use hybrid Slug + SDF on WebGPU and fall back automatically to `'sdf'` on WebGL2.
101
100
 
102
101
  ## Read deeper references by task
103
102
 
@@ -15,6 +15,50 @@ Starter components are **copy-once consumer source files** licensed under **MIT*
15
15
 
16
16
  Canonical integration guide for coding agents: `https://ultra-text.makio.io/integrations/AGENTS.md`
17
17
 
18
+ ## Declarative & HTML-capture usage
19
+
20
+ All copy-once starters support **both** declarative string text (`Text`) and live DOM capture (`DomText`):
21
+
22
+ - **R3F (`UltraText.tsx` / `v10/UltraText.tsx`)**:
23
+ ```tsx
24
+ <UltraTextCanvas>
25
+ <UltraText css={{ fontSize: 48, color: '#ffffff', width: 400, textAlign: 'center' }}>
26
+ Hello WebGPU
27
+ </UltraText>
28
+ <UltraText source={sourceEl} />
29
+ </UltraTextCanvas>
30
+ ```
31
+ - **TresJS (`UltraText.vue` / `UltraTextCanvas.vue`)**:
32
+ ```vue
33
+ <UltraTextCanvas>
34
+ <UltraText text="Hello WebGPU" :css="{ fontSize: 48, color: '#ffffff' }" />
35
+ <UltraText :source="sourceEl" />
36
+ </UltraTextCanvas>
37
+ ```
38
+ - **Mini3 (`UltraText.ts`)**:
39
+ ```ts
40
+ const label = await UltraText.createText(renderer, 'Hello WebGPU', {
41
+ css: { fontSize: 48, color: '#ffffff' },
42
+ })
43
+ const card = await UltraText.create(renderer, sourceEl)
44
+ ```
45
+
46
+ ## Migrating from `troika-three-text` / `@react-three/drei <Text>`
47
+
48
+ With the starters' default `pixelsPerUnit: 100`, `1` world unit = `100` CSS px:
49
+
50
+ | `troika` / `drei <Text>` | `ultra-text` equivalent |
51
+ | ----------------------------------- | ---------------------------------------------------------------------------- |
52
+ | `fontSize={0.48}` | `css={{ fontSize: 48 }}` |
53
+ | `color="#ff5500"` | `css={{ color: '#ff5500' }}` |
54
+ | `maxWidth={4}` | `css={{ width: 400 }}` (add `options={{ reflowable: true }}` for `reflow()`) |
55
+ | `textAlign="center"` | `css={{ textAlign: 'center' }}` |
56
+ | `outlineWidth={0.02}` | `options={{ outline: { width: 2 }, padding: 24 }}` |
57
+ | `outlineColor="#000"` | `options={{ outline: { color: '#000', opacity: 1 } }}` |
58
+ | `outlineBlur` | `options={{ outline: { width: 2, blur: 1, color: '#000' }, padding: 24 }}` |
59
+ | `anchorX="center" anchorY="middle"` | `center={true}` (default on starters) or `position.set(-w * ax, -h * ay, 0)` |
60
+ | `onSync={fn}` | `await text.ready` / `await DomText.create(...)` / `await text.rebuild()` |
61
+
18
62
  ## Lifecycle & correctness rules for frameworks
19
63
 
20
64
  1. **Keep source HTML outside the canvas**: render normal semantic HTML (`<article ref={setSource}>`) in the DOM, mark blocks with `data-text-block` (or `data-sdf-block`), and never apply `hidden` or `display: none`.
@@ -37,7 +81,7 @@ Canonical integration guide for coding agents: `https://ultra-text.makio.io/inte
37
81
  ## Verified baselines
38
82
 
39
83
  - **Three.js**: `>=0.187.0 <0.188.0` (matches `package.json` peer dependency; use one Three.js copy).
40
- - **R3F v9**: `@react-three/fiber` 9.8.2 + React 19.3.1.
84
+ - **R3F v9**: `@react-three/fiber` 9.8.2 + React 19.3.1 (verified 24 November 2026 with Three.js `0.187.0`).
41
85
  - **R3F v10 alpha**: `@react-three/fiber` 10.0.0-alpha.6 + React 19.3.1 (prerelease APIs subject to change).
42
- - **TresJS**: `@tresjs/core` 5.10.0 + Vue 3.5.44.
86
+ - **TresJS**: `@tresjs/core` 5.12.0 + Vue 3.5.46 (verified 24 November 2026 with Three.js `0.187.0`).
43
87
  - **Mini3**: `0.1.0-alpha.0` with `ultra-text/vanilla`.