ultra-text 1.0.2 → 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 (206) hide show
  1. package/README.md +193 -115
  2. package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
  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 +35 -11
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +1 -1
  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.js +8 -3
  17. package/dist/atlas/cpuAtlas.js.map +1 -1
  18. package/dist/atlas/cpuSdf.d.ts +1 -1
  19. package/dist/atlas/cpuSdf.js +97 -42
  20. package/dist/atlas/cpuSdf.js.map +1 -1
  21. package/dist/atlas/cpuWorker.d.ts +10 -4
  22. package/dist/atlas/cpuWorker.js +99 -49
  23. package/dist/atlas/cpuWorker.js.map +1 -1
  24. package/dist/atlas/gpuAtlas.js +133 -56
  25. package/dist/atlas/gpuAtlas.js.map +1 -1
  26. package/dist/atlas/gpuCommon.d.ts +140 -18
  27. package/dist/atlas/gpuCommon.js +726 -104
  28. package/dist/atlas/gpuCommon.js.map +1 -1
  29. package/dist/atlas/jfaWgsl.d.ts +1 -1
  30. package/dist/atlas/jfaWgsl.js +232 -61
  31. package/dist/atlas/jfaWgsl.js.map +1 -1
  32. package/dist/atlas/rasterize.d.ts +22 -0
  33. package/dist/atlas/rasterize.js +237 -111
  34. package/dist/atlas/rasterize.js.map +1 -1
  35. package/dist/atlas/vanillaCore.js +156 -103
  36. package/dist/atlas/vanillaCore.js.map +1 -1
  37. package/dist/atlas/vanillaCpuAtlas.js +37 -52
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
  39. package/dist/atlas/vanillaExtras.js +91 -90
  40. package/dist/atlas/vanillaExtras.js.map +1 -1
  41. package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
  42. package/dist/atlas/vanillaGpuHelpers.js +262 -27
  43. package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
  44. package/dist/dom/DomSdf.js +85 -79
  45. package/dist/dom/DomSdf.js.map +1 -1
  46. package/dist/dom/DomSlug.js +23 -18
  47. package/dist/dom/DomSlug.js.map +1 -1
  48. package/dist/dom/Text.d.ts +4 -1
  49. package/dist/dom/Text.js +5 -1
  50. package/dist/dom/Text.js.map +1 -1
  51. package/dist/dom/browserShaping.js +31 -14
  52. package/dist/dom/browserShaping.js.map +1 -1
  53. package/dist/dom/clusters.js +13 -2
  54. package/dist/dom/clusters.js.map +1 -1
  55. package/dist/dom/cssEffects.d.ts +4 -0
  56. package/dist/dom/cssEffects.js +72 -0
  57. package/dist/dom/cssEffects.js.map +1 -0
  58. package/dist/dom/domAnalytic.d.ts +1 -2
  59. package/dist/dom/domAnalytic.js +1 -1
  60. package/dist/dom/domAnalytic.js.map +1 -1
  61. package/dist/dom/fontCanvas.d.ts +16 -0
  62. package/dist/dom/fontCanvas.js +4 -4
  63. package/dist/dom/fontCanvas.js.map +1 -1
  64. package/dist/dom/layoutSignature.js +28 -12
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/markup.d.ts +10 -0
  67. package/dist/dom/markup.js +16 -1
  68. package/dist/dom/markup.js.map +1 -1
  69. package/dist/dom/pretextLayout.js +27 -19
  70. package/dist/dom/pretextLayout.js.map +1 -1
  71. package/dist/dom/snapshot.d.ts +4 -0
  72. package/dist/dom/snapshot.js +747 -505
  73. package/dist/dom/snapshot.js.map +1 -1
  74. package/dist/dom/snapshotsEqual.d.ts +7 -0
  75. package/dist/dom/snapshotsEqual.js +68 -0
  76. package/dist/dom/snapshotsEqual.js.map +1 -0
  77. package/dist/dom/svgCapture.js +30 -27
  78. package/dist/dom/svgCapture.js.map +1 -1
  79. package/dist/dom/textTransform.d.ts +13 -1
  80. package/dist/dom/textTransform.js +31 -13
  81. package/dist/dom/textTransform.js.map +1 -1
  82. package/dist/dom/tone.js +15 -8
  83. package/dist/dom/tone.js.map +1 -1
  84. package/dist/slug/SlugMaterial.d.ts +6 -0
  85. package/dist/slug/SlugMaterial.js +48 -20
  86. package/dist/slug/SlugMaterial.js.map +1 -1
  87. package/dist/slug/cff.d.ts +5 -0
  88. package/dist/slug/cff.js +780 -0
  89. package/dist/slug/cff.js.map +1 -0
  90. package/dist/slug/coverage.d.ts +3 -3
  91. package/dist/slug/coverage.js +283 -101
  92. package/dist/slug/coverage.js.map +1 -1
  93. package/dist/slug/preprocessCore.d.ts +1 -1
  94. package/dist/slug/preprocessCore.js +100 -80
  95. package/dist/slug/preprocessCore.js.map +1 -1
  96. package/dist/slug/runtime.js +32 -39
  97. package/dist/slug/runtime.js.map +1 -1
  98. package/dist/slug/standaloneRuntime.js +47 -37
  99. package/dist/slug/standaloneRuntime.js.map +1 -1
  100. package/dist/slug/truetype.d.ts +14 -6
  101. package/dist/slug/truetype.js +190 -62
  102. package/dist/slug/truetype.js.map +1 -1
  103. package/dist/slug/vanillaCore.d.ts +74 -4
  104. package/dist/slug/vanillaCore.js +226 -217
  105. package/dist/slug/vanillaCore.js.map +1 -1
  106. package/dist/slug-vanilla.d.ts +1 -1
  107. package/dist/slug-vanilla.js +5 -4
  108. package/dist/slug.d.ts +1 -1
  109. package/dist/slug.js +3 -3
  110. package/dist/text/GlyphTextMaterial.d.ts +5 -0
  111. package/dist/text/GlyphTextMaterial.js +11 -7
  112. package/dist/text/GlyphTextMaterial.js.map +1 -1
  113. package/dist/text/RectMaterial.js +6 -10
  114. package/dist/text/RectMaterial.js.map +1 -1
  115. package/dist/text/SdfTextMaterial.d.ts +9 -3
  116. package/dist/text/SdfTextMaterial.js +122 -37
  117. package/dist/text/SdfTextMaterial.js.map +1 -1
  118. package/dist/text/decorations.d.ts +7 -2
  119. package/dist/text/decorations.js +187 -96
  120. package/dist/text/decorations.js.map +1 -1
  121. package/dist/text/geometryUtils.d.ts +5 -0
  122. package/dist/text/geometryUtils.js +63 -9
  123. package/dist/text/geometryUtils.js.map +1 -1
  124. package/dist/text/glyphGeometry.d.ts +1 -1
  125. package/dist/text/glyphGeometry.js +281 -200
  126. package/dist/text/glyphGeometry.js.map +1 -1
  127. package/dist/text/rectGeometry.js +46 -42
  128. package/dist/text/rectGeometry.js.map +1 -1
  129. package/dist/text/reflow.d.ts +5 -0
  130. package/dist/text/reflow.js +127 -68
  131. package/dist/text/reflow.js.map +1 -1
  132. package/dist/text/snap.d.ts +15 -1
  133. package/dist/text/snap.js +1 -1
  134. package/dist/text/snap.js.map +1 -1
  135. package/dist/text/tone.js +2 -2
  136. package/dist/text/tone.js.map +1 -1
  137. package/dist/types.d.ts +23 -7
  138. package/dist/vanilla.js +1 -1
  139. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  140. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  141. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  142. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  143. package/dist/windfoil/WindfoilMaterial.js +71 -8
  144. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  145. package/dist/windfoil/compositeGeometry.js +12 -5
  146. package/dist/windfoil/compositeGeometry.js.map +1 -1
  147. package/dist/windfoil/coverage.d.ts +10 -2
  148. package/dist/windfoil/coverage.js +147 -59
  149. package/dist/windfoil/coverage.js.map +1 -1
  150. package/dist/windfoil/geometry.d.ts +15 -0
  151. package/dist/windfoil/geometry.js +154 -64
  152. package/dist/windfoil/geometry.js.map +1 -1
  153. package/dist/windfoil/layerGrid.js +8 -8
  154. package/dist/windfoil/layerGrid.js.map +1 -1
  155. package/dist/windfoil/mixed.js +13 -4
  156. package/dist/windfoil/mixed.js.map +1 -1
  157. package/dist/windfoil/preprocess.js +2 -2
  158. package/dist/windfoil/preprocessCore.d.ts +1 -0
  159. package/dist/windfoil/preprocessCore.js +63 -36
  160. package/dist/windfoil/preprocessCore.js.map +1 -1
  161. package/dist/windfoil/requests.d.ts +1 -1
  162. package/dist/windfoil/requests.js +11 -4
  163. package/dist/windfoil/requests.js.map +1 -1
  164. package/dist/windfoil/resolveOutline.d.ts +9 -0
  165. package/dist/windfoil/resolveOutline.js +20 -0
  166. package/dist/windfoil/resolveOutline.js.map +1 -0
  167. package/dist/windfoil/runtime.d.ts +1 -0
  168. package/dist/windfoil/runtime.js +8 -24
  169. package/dist/windfoil/runtime.js.map +1 -1
  170. package/dist/windfoil/shapeGeometry.js +80 -34
  171. package/dist/windfoil/shapeGeometry.js.map +1 -1
  172. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  173. package/dist/windfoil/sizeSwitch.js +13 -8
  174. package/dist/windfoil/sizeSwitch.js.map +1 -1
  175. package/dist/windfoil/storage.d.ts +23 -9
  176. package/dist/windfoil/storage.js +49 -30
  177. package/dist/windfoil/storage.js.map +1 -1
  178. package/dist/windfoil/svg/curves.d.ts +20 -0
  179. package/dist/windfoil/svg/curves.js +145 -42
  180. package/dist/windfoil/svg/curves.js.map +1 -1
  181. package/dist/windfoil/svg/document.js +10 -1
  182. package/dist/windfoil/svg/document.js.map +1 -1
  183. package/dist/windfoil/svg/pathConverter.js +66 -50
  184. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  185. package/dist/windfoil/svg/pathData.d.ts +9 -0
  186. package/dist/windfoil/svg/pathData.js +142 -109
  187. package/dist/windfoil/svg/pathData.js.map +1 -1
  188. package/dist/windfoil/svg/winding.js +34 -10
  189. package/dist/windfoil/svg/winding.js.map +1 -1
  190. package/dist/windfoil/trace/contours.js +120 -50
  191. package/dist/windfoil/trace/contours.js.map +1 -1
  192. package/dist/windfoil/trace/fit.js +578 -224
  193. package/dist/windfoil/trace/fit.js.map +1 -1
  194. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  195. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  196. package/dist/windfoil/trace/traceWorker.js +192 -0
  197. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  198. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  199. package/dist/windfoil/tracedOutlines.js +335 -70
  200. package/dist/windfoil/tracedOutlines.js.map +1 -1
  201. package/package.json +48 -29
  202. package/skills/ultra-text/SKILL.md +9 -10
  203. package/skills/ultra-text/references/frameworks.md +46 -2
  204. package/skills/ultra-text/references/three-tsl.md +26 -24
  205. package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
  206. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
@@ -1,82 +1,109 @@
1
- import { checkCommonAtlasLimits, encodeJfaWork, jfaSteps, openErrorScopes, prefersTiledJfa, selectWorkgroupDimension, supportsDirectStore } from "./gpuCommon.js";
2
1
  import { buildJfaWgsl } from "./jfaWgsl.js";
2
+ import { checkCommonAtlasLimits, edtRadius, encodeJfaWork, flushDeferredColorBleed, getDeviceGpuPool, getJfaLayouts, openErrorScopes, peekDeferredColorBleed, selectAtlasMode, selectWorkgroupDimension, storageBufferFits, supportsDirectStore, takeDeferredColorBleed } from "./gpuCommon.js";
3
+ import { bufUsageOf, canUseSpdMips, createGpuColorLayer, encodeMipmapChain, encodeSpdMipmapChain, encodeVanillaGpuColorLayer, getDeviceMipPipeline, getDeviceSpdMipPipeline, mipCount, resolveGpuDevice, texUsageOf, vanillaMipPipelines, vanillaSpdPipelines } from "./vanillaGpuHelpers.js";
3
4
  import { isColorCandidate } from "../dom/fontCanvas.js";
4
5
  import { rasterizeGlyphAtlas } from "./rasterize.js";
5
6
  import { resolveDomTextTone } from "../dom/tone.js";
6
7
  import { collectDomSnapshot } from "../dom/snapshot.js";
7
8
  import { layoutSignatureOf } from "../dom/layoutSignature.js";
8
9
  import { byte, computeInstanceBounds } from "./vanillaBounds.js";
9
- import { bufUsageOf, createGpuColorLayer, encodeMipmapChain, getDeviceMipPipeline, mipCount, resolveGpuDevice, texUsageOf, vanillaMipPipelines } from "./vanillaGpuHelpers.js";
10
10
  // src/atlas/vanillaCore.ts
11
11
  var devicePipelines = /* @__PURE__ */ new WeakMap();
12
- function getDevicePipelines(device, tiledOnly) {
12
+ function getDevicePipelines(device, mode) {
13
13
  const directStore = supportsDirectStore(device.features);
14
14
  const workgroupDim = selectWorkgroupDimension(device.limits);
15
+ const needWideTiled = mode === "tiled32";
15
16
  let cache = devicePipelines.get(device);
16
- if (cache?.directStore !== directStore || cache.workgroupDim !== workgroupDim) {
17
+ if (cache?.directStore !== directStore || cache.workgroupDim !== workgroupDim || needWideTiled && !cache.includeWideTiled) {
18
+ const includeWideTiled = needWideTiled || !storageBufferFits(device.limits, 4096, 4096);
17
19
  cache = {
18
20
  workgroupDim,
19
21
  directStore,
20
- module: device.createShaderModule({ code: buildJfaWgsl(workgroupDim, directStore) })
22
+ includeWideTiled,
23
+ layouts: getJfaLayouts(device),
24
+ module: device.createShaderModule({ code: buildJfaWgsl(workgroupDim, directStore, true, includeWideTiled) })
21
25
  };
22
26
  devicePipelines.set(device, cache);
23
27
  }
24
- const compute = (entryPoint) => device.createComputePipeline({
25
- layout: "auto",
28
+ const { layouts, module } = cache;
29
+ const wrap = (tiledStore, tiledStoreWide, multi, sep12) => ({
30
+ workgroupDim,
31
+ directStore,
32
+ layouts,
33
+ sepHoriz: multi?.sepHoriz ?? null,
34
+ sepVertStore: multi?.sepVertStore ?? null,
35
+ sepHorizPx12: sep12?.sepHorizPx12 ?? null,
36
+ sepVertPx12: sep12?.sepVertPx12 ?? null,
37
+ tiledStore,
38
+ tiledStoreWide,
39
+ resolve: multi?.resolve ?? null
40
+ });
41
+ const computeSync = (entryPoint, layout) => device.createComputePipeline({
42
+ layout,
26
43
  compute: {
27
- module: cache.module,
44
+ module,
28
45
  entryPoint
29
46
  }
30
47
  });
31
- if (tiledOnly) return {
32
- workgroupDim,
33
- directStore,
34
- seed: null,
35
- jump: null,
36
- jumpStore: null,
37
- tiledStore: cache.tiledStore ??= compute("tiledStoreMain"),
38
- resolve: null
39
- };
40
- return {
41
- workgroupDim,
42
- directStore,
43
- ...cache.multi ??= {
44
- seed: compute("seedMain"),
45
- jump: compute("jumpMain"),
46
- jumpStore: directStore ? compute("jumpStoreMain") : null,
47
- resolve: directStore ? null : device.createRenderPipeline({
48
- layout: "auto",
49
- vertex: {
50
- module: cache.module,
51
- entryPoint: "fullscreenVert"
52
- },
53
- fragment: {
54
- module: cache.module,
55
- entryPoint: "resolveFrag",
56
- targets: [{ format: "r8unorm" }]
57
- }
58
- })
48
+ if (mode === "sep12") {
49
+ if (cache.sep12) return wrap(null, null, void 0, cache.sep12);
50
+ return wrap(null, null, void 0, cache.sep12 = {
51
+ sepHorizPx12: computeSync("sepHorizPx12", layouts ? layouts.sepHorizPipeline : "auto"),
52
+ sepVertPx12: computeSync("sepVertPx12", layouts ? layouts.sepVertStorePipeline : "auto")
53
+ });
54
+ }
55
+ if (mode === "tiled12") {
56
+ if (cache.tiledStore) return wrap(cache.tiledStore, null);
57
+ return wrap(cache.tiledStore = computeSync("tiledStoreMain", layouts ? layouts.tiledPipeline : "auto"), null);
58
+ }
59
+ if (mode === "tiled32") {
60
+ if (cache.tiledStoreWide) return wrap(null, cache.tiledStoreWide);
61
+ return wrap(null, cache.tiledStoreWide = computeSync("tiledStoreWideMain", layouts ? layouts.tiledPipeline : "auto"));
62
+ }
63
+ if (cache.multi) return wrap(null, null, cache.multi);
64
+ const resolveDesc = {
65
+ layout: layouts ? layouts.resolvePipeline : "auto",
66
+ vertex: {
67
+ module,
68
+ entryPoint: "fullscreenVert"
59
69
  },
60
- tiledStore: null
70
+ fragment: {
71
+ module,
72
+ entryPoint: "resolveFrag",
73
+ targets: [{ format: "r8unorm" }]
74
+ }
61
75
  };
76
+ const horizLayout = layouts ? layouts.sepHorizPipeline : "auto";
77
+ const vertLayout = layouts ? layouts.sepVertStorePipeline : "auto";
78
+ return wrap(null, null, cache.multi = {
79
+ sepHoriz: computeSync("sepHorizMain", horizLayout),
80
+ sepVertStore: directStore ? computeSync("sepVertStoreMain", vertLayout) : null,
81
+ resolve: directStore ? null : device.createRenderPipeline(resolveDesc)
82
+ });
62
83
  }
63
84
  async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
64
85
  options.signal?.throwIfAborted();
65
86
  const { width, height } = raster;
66
- const steps = jfaSteps(raster.pxRange);
87
+ const radius = edtRadius(raster.pxRange);
67
88
  const directStore = supportsDirectStore(device.features);
68
- checkCommonAtlasLimits("buildVanillaGpuSdfAtlas", device.limits, width, height, steps[0], directStore);
89
+ const mode = selectAtlasMode(directStore, raster.pxRange, device.limits, width, height);
90
+ checkCommonAtlasLimits("buildVanillaGpuSdfAtlas", device.limits, width, height, radius, directStore, "", mode);
69
91
  const bufUsage = bufUsageOf();
70
92
  const texUsage = texUsageOf();
71
93
  const scopes = openErrorScopes(device);
72
94
  const mipmaps = options.mipmaps === true;
73
95
  const mipLevelCount = mipCount(width, height, mipmaps);
74
- let rasterTexture;
96
+ const pool = getDeviceGpuPool(device);
97
+ const retainPool = pool.beginBuild();
75
98
  let outputTexture;
76
- let retainOutput = false;
99
+ let gpuColorLayer;
77
100
  const transient = [];
101
+ const deferredBleed = raster.colorBand ? peekDeferredColorBleed(raster.colorBand.data) : void 0;
78
102
  try {
79
- const pipelines = getDevicePipelines(device, directStore && steps[0] === 4);
103
+ const workgroupDim = selectWorkgroupDimension(device.limits);
104
+ const useSpdMips = mipLevelCount > 1 && canUseSpdMips(device, directStore, workgroupDim);
105
+ const pipelines = getDevicePipelines(device, mode);
106
+ const spd = useSpdMips ? await getDeviceSpdMipPipeline(device) : null;
80
107
  outputTexture = device.createTexture({
81
108
  size: [width, height],
82
109
  mipLevelCount,
@@ -84,32 +111,41 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
84
111
  usage: texUsage.RENDER_ATTACHMENT | texUsage.TEXTURE_BINDING | texUsage.COPY_SRC | (pipelines.directStore ? texUsage.STORAGE_BINDING ?? 0 : 0)
85
112
  });
86
113
  const encoder = device.createCommandEncoder();
87
- rasterTexture = encodeJfaWork(device, encoder, pipelines, raster.canvas, width, height, raster.pxRange, steps, outputTexture, transient, bufUsage, texUsage);
114
+ encodeJfaWork(device, encoder, pipelines, raster.canvas, width, height, raster.pxRange, radius, outputTexture, transient, bufUsage, texUsage, pool);
88
115
  if (mipLevelCount > 1) {
89
- const mip = getDeviceMipPipeline(device, "r8unorm");
90
- encodeMipmapChain(device, encoder, outputTexture, mipLevelCount, mip.pipeline, mip.sampler);
116
+ if (spd) encodeSpdMipmapChain(device, encoder, outputTexture, width, height, mipLevelCount, spd, pool);
117
+ else {
118
+ const mip = getDeviceMipPipeline(device, "r8unorm");
119
+ encodeMipmapChain(device, encoder, outputTexture, mipLevelCount, mip.pipeline, mip.sampler, mip.layout);
120
+ }
91
121
  }
122
+ if (deferredBleed && raster.colorBand) gpuColorLayer = encodeVanillaGpuColorLayer(device, encoder, width, raster.colorBand, deferredBleed, mipmaps, pool, transient);
92
123
  device.queue.submit([encoder.finish()]);
124
+ pool.resetRing();
93
125
  } catch (error) {
94
126
  scopes.close();
95
- for (const b of transient) b.destroy();
127
+ pool.endBuild(transient, false, true);
128
+ gpuColorLayer?.gpuTexture?.destroy();
96
129
  outputTexture?.destroy();
97
130
  throw error;
98
- } finally {
99
- rasterTexture?.destroy();
100
131
  }
101
132
  const rejection = await scopes.close();
102
- for (const b of transient) b.destroy();
103
133
  if (rejection !== null) {
134
+ pool.endBuild(transient, false, true);
104
135
  devicePipelines.delete(device);
105
136
  vanillaMipPipelines.delete(device);
137
+ vanillaSpdPipelines.get(device)?.dummyTexture.destroy();
138
+ vanillaSpdPipelines.delete(device);
139
+ gpuColorLayer?.gpuTexture?.destroy();
106
140
  outputTexture.destroy();
107
141
  throw new Error(`buildVanillaGpuSdfAtlas: the device rejected the atlas passes: ${rejection}`);
108
142
  }
143
+ pool.endBuild(transient, retainPool, false);
144
+ if (gpuColorLayer && raster.colorBand) takeDeferredColorBleed(raster.colorBand.data);
145
+ let colorLayer;
109
146
  try {
110
147
  options.signal?.throwIfAborted();
111
- const colorLayer = raster.colorBand ? createGpuColorLayer(device, width, raster.colorBand, mipmaps) : void 0;
112
- retainOutput = true;
148
+ colorLayer = gpuColorLayer ?? (raster.colorBand ? createGpuColorLayer(device, width, raster.colorBand, mipmaps) : void 0);
113
149
  const retainedTexture = outputTexture;
114
150
  let disposed = false;
115
151
  const { shapeTop } = raster;
@@ -132,8 +168,10 @@ async function buildVanillaGpuSdfAtlas(device, raster, options = {}) {
132
168
  retainedTexture.destroy();
133
169
  }
134
170
  };
135
- } finally {
136
- if (!retainOutput) outputTexture.destroy();
171
+ } catch (error) {
172
+ (colorLayer ?? gpuColorLayer)?.gpuTexture?.destroy();
173
+ outputTexture.destroy();
174
+ throw error;
137
175
  }
138
176
  }
139
177
  var warnedVanillaGpuFallback = false;
@@ -148,6 +186,7 @@ async function buildVanillaSdfAtlas(deviceOrRenderer, raster, options = {}, prep
148
186
  const mode = options.mode ?? "auto";
149
187
  const device = resolveGpuDevice(deviceOrRenderer);
150
188
  if (mode === "cpu") {
189
+ if (raster.colorBand) flushDeferredColorBleed(raster.colorBand.data);
151
190
  const { buildVanillaCpuSdfAtlas } = await import("./vanillaCpuAtlas.js");
152
191
  return buildVanillaCpuSdfAtlas(raster, {
153
192
  ...options,
@@ -159,6 +198,7 @@ async function buildVanillaSdfAtlas(deviceOrRenderer, raster, options = {}, prep
159
198
  preparedWorker?.dispose();
160
199
  throw new Error("buildVanillaSdfAtlas: mode \"gpu\" requires a WebGPU GPUDevice; use mode \"auto\" or \"cpu\" without a device");
161
200
  }
201
+ if (raster.colorBand) flushDeferredColorBleed(raster.colorBand.data);
162
202
  const { buildVanillaCpuSdfAtlas } = await import("./vanillaCpuAtlas.js");
163
203
  return buildVanillaCpuSdfAtlas(raster, options, preparedWorker);
164
204
  }
@@ -176,6 +216,7 @@ async function buildVanillaSdfAtlas(deviceOrRenderer, raster, options = {}, prep
176
216
  warnedVanillaGpuFallback = true;
177
217
  console.warn("[ultra-text] WebGPU JFA atlas generation failed; falling back to the CPU EDT generator.", error);
178
218
  }
219
+ if (raster.colorBand) flushDeferredColorBleed(raster.colorBand.data);
179
220
  const { buildVanillaCpuSdfAtlas } = await import("./vanillaCpuAtlas.js");
180
221
  return buildVanillaCpuSdfAtlas(raster, {
181
222
  ...options,
@@ -222,8 +263,18 @@ var UNIT_QUAD_INDICES = new Uint16Array([
222
263
  2,
223
264
  3
224
265
  ]);
225
- function metaSize(snapshot) {
226
- return snapshot.sizeSwitched || snapshot.glyphs.some((glyph) => glyph.switchEm !== void 0) ? 3 : 2;
266
+ function measureGlyphLayout(snapshot) {
267
+ let hasMotion = snapshot.textShaping === "browser";
268
+ let metaItemSize = snapshot.sizeSwitched ? 3 : 2;
269
+ for (const glyph of snapshot.glyphs) {
270
+ if (hasMotion && metaItemSize === 3) break;
271
+ if (glyph.motionOrigin !== void 0) hasMotion = true;
272
+ if (glyph.switchEm !== void 0) metaItemSize = 3;
273
+ }
274
+ return {
275
+ hasMotion,
276
+ metaItemSize
277
+ };
227
278
  }
228
279
  function writeMeta(target, index, size, glyph) {
229
280
  target[index * size] = glyph.sequence;
@@ -233,20 +284,6 @@ function writeMeta(target, index, size, glyph) {
233
284
  function needsRunMotion(snapshot) {
234
285
  return snapshot.textShaping === "browser" || snapshot.glyphs.some((glyph) => glyph.motionOrigin !== void 0);
235
286
  }
236
- function shapeOrdinals(snapshot) {
237
- const glyphs = snapshot.glyphs;
238
- if (!glyphs.some((glyph) => glyph.shapeGroup !== void 0)) return void 0;
239
- const out = new Float32Array(glyphs.length);
240
- let ordinal = -1;
241
- let previous;
242
- for (let index = 0; index < glyphs.length; index++) {
243
- const glyph = glyphs[index];
244
- if (glyph.shapeGroup === void 0 || glyph.shapeGroup !== previous) ordinal++;
245
- previous = glyph.shapeGroup;
246
- out[index] = glyph.motionOrigin?.[2] ?? ordinal;
247
- }
248
- return out;
249
- }
250
287
  function writeUvRect(target, offset, slot) {
251
288
  target[offset] = slot.u0 * 65535 + .5 | 0;
252
289
  target[offset + 1] = slot.v1 * 65535 + .5 | 0;
@@ -278,13 +315,12 @@ function writeGlyphRect(rects, offset, glyph, slot, bakeSize, shaped) {
278
315
  rects[offset + 2] = glyph.originX + slot.planeX1 * scaleX;
279
316
  rects[offset + 3] = baseline + slot.planeY1 * scale;
280
317
  }
281
- function writeVanillaRunMotion(runMotion, index, ordinal, glyph, rects, offset, motionOrdinals) {
282
- if (!runMotion) return;
318
+ function writeVanillaRunMotion(runMotion, index, ordinal, glyph, rects, offset) {
283
319
  const rOffset = index * 3;
284
320
  const origin = glyph.motionOrigin;
285
321
  runMotion[rOffset] = origin ? origin[0] : (rects[offset] + rects[offset + 2]) * .5;
286
322
  runMotion[rOffset + 1] = origin ? origin[1] : (rects[offset + 1] + rects[offset + 3]) * .5;
287
- runMotion[rOffset + 2] = origin ? origin[2] : motionOrdinals?.[ordinal] ?? ordinal;
323
+ runMotion[rOffset + 2] = origin ? origin[2] : ordinal;
288
324
  }
289
325
  function writeVanillaGlyphBatch(snapshot, atlas, rects, uvRects, trims, clips, colors, metadata, metaItemSize, runMotion, motionOrdinals) {
290
326
  const glyphs = snapshot.glyphs;
@@ -292,12 +328,19 @@ function writeVanillaGlyphBatch(snapshot, atlas, rects, uvRects, trims, clips, c
292
328
  const shaped = snapshot.textShaping === "browser";
293
329
  const bakeSize = atlas.bakeSize;
294
330
  const atlasGlyphs = atlas.glyphs;
331
+ const groupMotion = runMotion !== null && motionOrdinals === void 0;
295
332
  let count = 0;
296
333
  let maxSequence = 0;
297
334
  let minZ = 0;
298
335
  let maxZ = 0;
336
+ let previousGroup;
337
+ let grouped = 0;
299
338
  for (let ordinal = 0; ordinal < total; ordinal++) {
300
339
  const glyph = glyphs[ordinal];
340
+ if (groupMotion) {
341
+ if (glyph.shapeGroup !== void 0 && glyph.shapeGroup === previousGroup) grouped++;
342
+ previousGroup = glyph.shapeGroup;
343
+ }
301
344
  const slot = atlasGlyphs.get(glyph.glyphKey);
302
345
  if (!slot) continue;
303
346
  const index = count++;
@@ -316,7 +359,7 @@ function writeVanillaGlyphBatch(snapshot, atlas, rects, uvRects, trims, clips, c
316
359
  colors[offset + 2] = byte(color[2]);
317
360
  colors[offset + 3] = byte(color[3]);
318
361
  writeMeta(metadata, index, metaItemSize, glyph);
319
- writeVanillaRunMotion(runMotion, index, ordinal, glyph, rects, offset, motionOrdinals);
362
+ if (runMotion) writeVanillaRunMotion(runMotion, index, motionOrdinals?.[ordinal] ?? ordinal - grouped, glyph, rects, offset);
320
363
  if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
321
364
  if (glyph.z < minZ) minZ = glyph.z;
322
365
  if (glyph.z > maxZ) maxZ = glyph.z;
@@ -330,16 +373,14 @@ function writeVanillaGlyphBatch(snapshot, atlas, rects, uvRects, trims, clips, c
330
373
  }
331
374
  /** Packs instanced glyph attribute arrays from a layout snapshot and SDF atlas. */
332
375
  function packGlyphInstances(snapshot, atlas, motionPadding = 0, motionOrdinals) {
333
- const hasRunMotion = needsRunMotion(snapshot);
334
- motionOrdinals ??= hasRunMotion ? shapeOrdinals(snapshot) : void 0;
376
+ const { hasMotion, metaItemSize } = measureGlyphLayout(snapshot);
335
377
  const total = snapshot.glyphs.length;
336
378
  const rects = new Float32Array(total * 4);
337
379
  const uvRects = new Uint16Array(total * 4);
338
380
  const clips = new Float32Array(total * 4);
339
381
  const colors = new Uint8Array(total * 4);
340
- const metaItemSize = metaSize(snapshot);
341
382
  const metadata = new Float32Array(total * metaItemSize);
342
- const runMotion = hasRunMotion || motionOrdinals ? new Float32Array(total * 3) : null;
383
+ const runMotion = hasMotion || motionOrdinals ? new Float32Array(total * 3) : null;
343
384
  const trims = runMotion ? null : new Uint16Array(total * 4);
344
385
  const [count, maxSequence, minZ, maxZ] = writeVanillaGlyphBatch(snapshot, atlas, rects, uvRects, trims, clips, colors, metadata, metaItemSize, runMotion, motionOrdinals);
345
386
  const full = count === total;
@@ -367,7 +408,7 @@ function updateGlyphInstances(instances, snapshot, atlas, motionPadding = 0, mot
367
408
  const glyphs = snapshot.glyphs;
368
409
  const total = glyphs.length;
369
410
  if (total < instanceCount) return null;
370
- motionOrdinals ??= needsRunMotion(snapshot) ? shapeOrdinals(snapshot) : void 0;
411
+ const groupMotion = runMotion !== null && motionOrdinals === void 0 && needsRunMotion(snapshot);
371
412
  const shaped = snapshot.textShaping === "browser";
372
413
  const bakeSize = atlas.bakeSize;
373
414
  const atlasGlyphs = atlas.glyphs;
@@ -375,8 +416,14 @@ function updateGlyphInstances(instances, snapshot, atlas, motionPadding = 0, mot
375
416
  let maxSequence = 0;
376
417
  let minZ = 0;
377
418
  let maxZ = 0;
419
+ let previousGroup;
420
+ let grouped = 0;
378
421
  for (let ordinal = 0; ordinal < total; ordinal++) {
379
422
  const glyph = glyphs[ordinal];
423
+ if (groupMotion) {
424
+ if (glyph.shapeGroup !== void 0 && glyph.shapeGroup === previousGroup) grouped++;
425
+ previousGroup = glyph.shapeGroup;
426
+ }
380
427
  const slot = atlasGlyphs.get(glyph.glyphKey);
381
428
  if (!slot) continue;
382
429
  if (count >= instanceCount) return null;
@@ -389,7 +436,7 @@ function updateGlyphInstances(instances, snapshot, atlas, motionPadding = 0, mot
389
436
  clips[offset + 2] = clip[2];
390
437
  clips[offset + 3] = clip[3];
391
438
  metadata[index * metaItemSize] = glyph.sequence;
392
- writeVanillaRunMotion(runMotion, index, ordinal, glyph, rects, offset, motionOrdinals);
439
+ if (runMotion) writeVanillaRunMotion(runMotion, index, motionOrdinals?.[ordinal] ?? ordinal - grouped, glyph, rects, offset);
393
440
  if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
394
441
  if (glyph.z < minZ) minZ = glyph.z;
395
442
  if (glyph.z > maxZ) maxZ = glyph.z;
@@ -407,10 +454,10 @@ function updateGlyphContentInstances(instances, snapshot, atlas, motionPadding =
407
454
  const glyphs = snapshot.glyphs;
408
455
  const total = glyphs.length;
409
456
  const expectedCount = instances.count;
410
- if (total < expectedCount || metaSize(snapshot) !== instances.metaItemSize) return null;
411
- const hasRun = needsRunMotion(snapshot);
412
- motionOrdinals ??= hasRun ? shapeOrdinals(snapshot) : void 0;
413
- if ((hasRun || !!motionOrdinals) !== (instances.runMotion !== null)) return null;
457
+ if (total < expectedCount) return null;
458
+ const { hasMotion, metaItemSize } = measureGlyphLayout(snapshot);
459
+ if (metaItemSize !== instances.metaItemSize) return null;
460
+ if ((hasMotion || !!motionOrdinals) !== (instances.runMotion !== null)) return null;
414
461
  const atlasGlyphs = atlas.glyphs;
415
462
  let drawable = 0;
416
463
  for (let i = 0; i < total; i++) if (atlasGlyphs.has(glyphs[i].glyphKey)) {
@@ -494,7 +541,6 @@ var VanillaDomText = class VanillaDomText {
494
541
  motion;
495
542
  #a;
496
543
  #s = null;
497
- #rw = null;
498
544
  #rs = null;
499
545
  #rf = null;
500
546
  #rm = null;
@@ -551,7 +597,8 @@ var VanillaDomText = class VanillaDomText {
551
597
  return this.#st;
552
598
  }
553
599
  get snapshot() {
554
- return this.#rw === null ? this.#s : this.#rs ??= this.#rm.reflowSnapshot(this.#s, this.#rw);
600
+ if (this.#rs) this.#rf = null;
601
+ return this.#rs ?? this.#s;
555
602
  }
556
603
  get width() {
557
604
  return this.#w;
@@ -575,17 +622,23 @@ var VanillaDomText = class VanillaDomText {
575
622
  if (!Number.isFinite(width) || width <= 0) throw new RangeError("VanillaDomText.reflow: width must be a positive finite number");
576
623
  const reflowMod = this.#rm;
577
624
  const geometryStart = nowMs();
578
- const nextSnapshot = reflowMod.reflowSnapshotWithState(this.#s, width, this.#rf ??= reflowMod.createReflowState(this.#s));
579
- const motionPadding = Math.max(0, this.motion.strength);
580
- if (updateGlyphInstances(this.glyphs, nextSnapshot, this.#a, motionPadding) === null) this.glyphs = packGlyphInstances(nextSnapshot, this.#a, motionPadding);
581
- if (this.decorations) {
582
- const extras = this.#ex;
583
- const drawable = (key) => this.#a.glyphs.has(key);
584
- if (!extras.updateDecorationInstances(this.decorations, nextSnapshot, this.glyphs.rects, drawable, motionPadding)) this.decorations = extras.packDecorationInstances(nextSnapshot, this.glyphs.rects, drawable, motionPadding);
625
+ let nextSnapshot;
626
+ try {
627
+ nextSnapshot = reflowMod.reflowSnapshotWithState(this.#s, width, this.#rf ??= reflowMod.createReflowState(this.#s));
628
+ const motionPadding = Math.max(0, this.motion.strength);
629
+ if (updateGlyphInstances(this.glyphs, nextSnapshot, this.#a, motionPadding) === null) this.glyphs = packGlyphInstances(nextSnapshot, this.#a, motionPadding);
630
+ if (this.decorations) {
631
+ const extras = this.#ex;
632
+ const drawable = (key) => this.#a.glyphs.has(key);
633
+ if (!extras.updateDecorationInstances(this.decorations, nextSnapshot, this.glyphs.rects, drawable, motionPadding)) this.decorations = extras.packDecorationInstances(nextSnapshot, this.glyphs.rects, drawable, motionPadding);
634
+ }
635
+ } catch (error) {
636
+ if (this.#rs && this.#rs.glyphs === this.#rf?.glyphs) this.#rs = reflowMod.reflowSnapshot(this.#s, this.#w);
637
+ this.#rf = null;
638
+ throw error;
585
639
  }
586
640
  const geometryBuildMs = nowMs() - geometryStart;
587
- this.#rw = width;
588
- this.#rs = null;
641
+ this.#rs = nextSnapshot;
589
642
  this.#w = nextSnapshot.width;
590
643
  this.#h = nextSnapshot.height;
591
644
  this.#ls = "";
@@ -647,10 +700,10 @@ var VanillaDomText = class VanillaDomText {
647
700
  const sharedAtlas = opts.sharedAtlas;
648
701
  const currentAtlas = this.#a;
649
702
  const gpuUpload = opts.atlasMode !== "cpu" && typeof device?.createShaderModule === "function";
650
- const tiledOnly = gpuUpload ? prefersTiledJfa(supportsDirectStore(device.features), opts.padding) : false;
703
+ const prewarmMode = gpuUpload ? selectAtlasMode(supportsDirectStore(device.features), opts.padding, device.limits) : "multi";
651
704
  const cached = gpuUpload ? devicePipelines.get(device) : void 0;
652
- if (gpuUpload && (tiledOnly ? !cached?.tiledStore : !cached?.multi) && !sharedAtlas && !currentAtlas) try {
653
- getDevicePipelines(device, tiledOnly);
705
+ if (gpuUpload && (prewarmMode === "tiled32" ? !cached?.tiledStoreWide : prewarmMode === "sep12" ? !cached?.sep12 : prewarmMode === "tiled12" ? !cached?.tiledStore : !cached?.multi) && !sharedAtlas && !currentAtlas) try {
706
+ getDevicePipelines(device, prewarmMode);
654
707
  device.queue.submit([]);
655
708
  } catch {}
656
709
  else if (!gpuUpload && !sharedAtlas && !currentAtlas && opts.cpuWorker !== false && typeof Worker !== "undefined") preparedWorkerPromise = import("./cpuWorker.js").then((mod) => mod.prepareCpuWorker()).catch(() => null);
@@ -671,13 +724,12 @@ var VanillaDomText = class VanillaDomText {
671
724
  const canUseSharedAtlas = Boolean(sharedAtlas && hasAllGlyphs(sharedAtlas, snapshot, opts.colorGlyphs));
672
725
  const canReusePrivateAtlas = Boolean(!canUseSharedAtlas && currentAtlas && this.#o && (this.#as === snapshot.atlasSignature || hasAllGlyphs(currentAtlas, snapshot, opts.colorGlyphs)));
673
726
  const nextLayoutSignature = layoutSignatureOf(snapshot);
674
- if (this.#ls === "" && this.#s) this.#ls = layoutSignatureOf(this.snapshot);
727
+ if (this.#ls === "" && this.#s) this.#ls = layoutSignatureOf(this.#rs ?? this.#s);
675
728
  if ((canUseSharedAtlas || canReusePrivateAtlas) && this.#ls !== "" && nextLayoutSignature === this.#ls) {
676
729
  if (reflowPromise) await reflowPromise;
677
730
  if (version !== this.#rv || this.#d) throw makeAbortError();
678
731
  this.tone = nextTone;
679
732
  this.#s = snapshot;
680
- this.#rw = null;
681
733
  this.#rs = null;
682
734
  this.#rf = null;
683
735
  this.#w = snapshot.width;
@@ -703,7 +755,10 @@ var VanillaDomText = class VanillaDomText {
703
755
  const raster = await rasterizeGlyphAtlas(this.element.ownerDocument, snapshot.requests, {
704
756
  ...opts,
705
757
  previousAtlas: currentAtlas !== sharedAtlas ? currentAtlas : void 0,
706
- ...gpuUpload ? { gpuUpload } : {},
758
+ ...gpuUpload ? {
759
+ gpuUpload,
760
+ deferColorBleed: true
761
+ } : {},
707
762
  signal
708
763
  });
709
764
  signal.throwIfAborted();
@@ -749,7 +804,6 @@ var VanillaDomText = class VanillaDomText {
749
804
  this.#o = nextOwnsAtlas;
750
805
  this.tone = nextTone;
751
806
  this.#s = snapshot;
752
- this.#rw = null;
753
807
  this.#rs = null;
754
808
  this.#rf = null;
755
809
  this.#w = snapshot.width;
@@ -821,7 +875,6 @@ var VanillaDomText = class VanillaDomText {
821
875
  const currentAtlas = this.#a;
822
876
  if (currentAtlas && this.#o) currentAtlas.dispose();
823
877
  this.#s = null;
824
- this.#rw = null;
825
878
  this.#rs = null;
826
879
  this.#rf = null;
827
880
  this.#w = 0;
@@ -897,7 +950,7 @@ var BASE_TEXT_STYLE = {
897
950
  pointerEvents: "none",
898
951
  userSelect: "none",
899
952
  webkitUserSelect: "none",
900
- visibility: "hidden",
953
+ clipPath: "inset(100%)",
901
954
  zIndex: "-2147483648"
902
955
  };
903
956
  function kebabProperty(name) {