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,7 +1,8 @@
1
- import { byte, metaSize, setBounds, setUnitQuad, writeMeta } from "../text/geometryUtils.js";
1
+ import { byte, flushAttributeUpdate, isDomSnapshot, metaSize, needsRunMotion, setBounds, setUnitQuad } from "../text/geometryUtils.js";
2
2
  import { GLYPH_RECTS_KEY } from "../text/decorations.js";
3
3
  import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
4
4
  // src/windfoil/geometry.ts
5
+ var prevWindfoilCache = /* @__PURE__ */ new WeakMap();
5
6
  var ATTRIBUTES = [
6
7
  "sdfRect",
7
8
  "sdfClip",
@@ -11,6 +12,46 @@ var ATTRIBUTES = [
11
12
  "windfoilBand"
12
13
  ];
13
14
  var LAYERED_ATTRIBUTES = [...ATTRIBUTES, "windfoilLayer"];
15
+ var SLOT_RECT = 0;
16
+ var SLOT_CLIP = 1;
17
+ var SLOT_COLOR = 2;
18
+ var SLOT_META = 3;
19
+ var SLOT_BOUNDS = 4;
20
+ var SLOT_BAND = 5;
21
+ var SLOT_LAYER = 6;
22
+ var DIRTY_UNSET = 2147483647;
23
+ var dirtyBounds = /* @__PURE__ */ new Int32Array(14);
24
+ function resetDirtyBounds() {
25
+ for (let slot = 0; slot < 7; slot++) {
26
+ const base = slot * 2;
27
+ dirtyBounds[base] = DIRTY_UNSET;
28
+ dirtyBounds[base + 1] = 0;
29
+ }
30
+ }
31
+ function recordDirty(slot, start, end) {
32
+ const base = slot * 2;
33
+ if (start < dirtyBounds[base]) dirtyBounds[base] = start;
34
+ if (end > dirtyBounds[base + 1]) dirtyBounds[base + 1] = end;
35
+ }
36
+ function writeFloat4(target, offset, a, b, c, d, trackDirty, slot) {
37
+ if (trackDirty) {
38
+ const fa = Math.fround(a);
39
+ const fb = Math.fround(b);
40
+ const fc = Math.fround(c);
41
+ const fd = Math.fround(d);
42
+ if (target[offset] === fa && target[offset + 1] === fb && target[offset + 2] === fc && target[offset + 3] === fd) return;
43
+ target[offset] = fa;
44
+ target[offset + 1] = fb;
45
+ target[offset + 2] = fc;
46
+ target[offset + 3] = fd;
47
+ recordDirty(slot, offset, offset + 4);
48
+ return;
49
+ }
50
+ target[offset] = a;
51
+ target[offset + 1] = b;
52
+ target[offset + 2] = c;
53
+ target[offset + 3] = d;
54
+ }
14
55
  var scratchRect = [
15
56
  0,
16
57
  0,
@@ -34,55 +75,61 @@ function windfoilGlyphRect(glyph, header, bbox = header.bbox) {
34
75
  0
35
76
  ]);
36
77
  }
37
- function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1, c2, c3, glyphRect) {
78
+ /** The negative font size feeds tone dilation while keeping the analytic batch selected. */
79
+ function fixedGlyphEm(glyph) {
80
+ return glyph.shapeGroup === void 0 ? -glyph.fontSize : 0;
81
+ }
82
+ function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1, c2, c3, fc0, fc1, fc2, fc3, glyphRect, trackDirty = false) {
38
83
  const offset = index * 4;
39
84
  const scale = glyph.fontSize / header.unitsPerEm;
40
85
  const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale);
41
86
  const ox = glyph.originX;
42
87
  const lBox = layer.bbox;
43
88
  const b0 = lBox[0], b1 = lBox[1], b2 = lBox[2], b3 = lBox[3];
44
- const rects = attributes.rects;
45
- rects[offset] = ox + b0 * scale;
46
- rects[offset + 1] = baseline + b1 * scale;
47
- rects[offset + 2] = ox + b2 * scale;
48
- rects[offset + 3] = baseline + b3 * scale;
49
- const clips = attributes.clips, clip = glyph.clip;
50
- clips[offset] = clip[0];
51
- clips[offset + 1] = clip[1];
52
- clips[offset + 2] = clip[2];
53
- clips[offset + 3] = clip[3];
89
+ writeFloat4(attributes.rects, offset, ox + b0 * scale, baseline + b1 * scale, ox + b2 * scale, baseline + b3 * scale, trackDirty, SLOT_RECT);
90
+ writeFloat4(attributes.clips, offset, fc0, fc1, fc2, fc3, trackDirty, SLOT_CLIP);
54
91
  const colors = attributes.colors;
55
- colors[offset] = c0;
56
- colors[offset + 1] = c1;
57
- colors[offset + 2] = c2;
58
- colors[offset + 3] = c3;
59
- writeMeta(attributes.metadata, index, attributes.metaSize ?? 2, glyph);
60
- const bounds = attributes.bounds;
61
- bounds[offset] = b0;
62
- bounds[offset + 1] = b1;
63
- bounds[offset + 2] = b2;
64
- bounds[offset + 3] = b3;
65
- const bands = attributes.bands;
66
- bands[offset] = layer.rowBase;
67
- bands[offset + 1] = layer.bandCount;
68
- bands[offset + 2] = layer.bandH;
69
- bands[offset + 3] = layer.invH;
92
+ if (trackDirty) {
93
+ if (colors[offset] !== c0 || colors[offset + 1] !== c1 || colors[offset + 2] !== c2 || colors[offset + 3] !== c3) {
94
+ colors[offset] = c0;
95
+ colors[offset + 1] = c1;
96
+ colors[offset + 2] = c2;
97
+ colors[offset + 3] = c3;
98
+ recordDirty(SLOT_COLOR, offset, offset + 4);
99
+ }
100
+ } else {
101
+ colors[offset] = c0;
102
+ colors[offset + 1] = c1;
103
+ colors[offset + 2] = c2;
104
+ colors[offset + 3] = c3;
105
+ }
106
+ const metaSizeValue = attributes.metaSize ?? 2;
107
+ const metadata = attributes.metadata;
108
+ const m = index * metaSizeValue;
109
+ let em = 0;
110
+ if (metaSizeValue === 3) em = attributes.fontEm ? fixedGlyphEm(glyph) : glyph.switchEm ?? 0;
111
+ if (!trackDirty || metadata[m] !== Math.fround(glyph.sequence) || metadata[m + 1] !== Math.fround(glyph.z) || metaSizeValue === 3 && metadata[m + 2] !== Math.fround(em)) {
112
+ metadata[m] = glyph.sequence;
113
+ metadata[m + 1] = glyph.z;
114
+ if (metaSizeValue === 3) metadata[m + 2] = em;
115
+ if (trackDirty) recordDirty(SLOT_META, m, m + metaSizeValue);
116
+ }
117
+ writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS);
118
+ writeFloat4(attributes.bands, offset, layer.rowBase, layer.bandCount, layer.bandH, layer.invH, trackDirty, SLOT_BAND);
70
119
  const layers = attributes.layers;
71
120
  if (layers) {
72
121
  const paint = "paintKind" in layer ? layer : null;
73
122
  const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect);
74
123
  const mo = glyph.motionOrigin;
75
- layers[offset] = mo ? mo[0] : (rect[0] + rect[2]) / 2;
76
- layers[offset + 1] = mo ? mo[1] : (rect[1] + rect[3]) / 2;
77
- layers[offset + 2] = ordinal;
78
- layers[offset + 3] = paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0;
124
+ writeFloat4(layers, offset, mo ? mo[0] : (rect[0] + rect[2]) / 2, mo ? mo[1] : (rect[1] + rect[3]) / 2, ordinal, paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0, trackDirty, SLOT_LAYER);
79
125
  }
80
126
  }
81
127
  /** Shared by text and shape geometry; one layer adds only one vertex attribute. */
82
- function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect) {
128
+ function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect, trackDirty = false) {
83
129
  const paint = "paintKind" in layer ? layer : null;
84
130
  const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color;
85
- writeInstance(glyph, header, layer, index, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)), glyphRect);
131
+ const clip = glyph.clip;
132
+ writeInstance(glyph, header, layer, index, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)), clip[0], clip[1], clip[2], clip[3], glyphRect, trackDirty);
86
133
  }
87
134
  function countLayout(snapshot, glyphs, layered) {
88
135
  let instances = 0, drawable = 0;
@@ -98,7 +145,7 @@ function countLayout(snapshot, glyphs, layered) {
98
145
  drawable
99
146
  };
100
147
  }
101
- function writeGeometry(snapshot, glyphs, attributes, ordinals) {
148
+ function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = false, prev) {
102
149
  let instance = 0, drawable = 0, maxSequence = 0, minZ = 0, maxZ = 0;
103
150
  let prevKey;
104
151
  let prevHeader;
@@ -107,12 +154,30 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
107
154
  let pc1 = 0;
108
155
  let pc2 = 0;
109
156
  let pc3 = 0;
157
+ let prevClip;
158
+ let fc0 = 0;
159
+ let fc1 = 0;
160
+ let fc2 = 0;
161
+ let fc3 = 0;
110
162
  const glyphList = snapshot.glyphs;
163
+ let canSkip = trackDirty && prev !== void 0 && prev.allSingleDrawn && !prev.layered && !attributes.layers && prev.glyphsMap === glyphs && prev.metaSize === (attributes.metaSize ?? 2) && prev.fontEm === Boolean(attributes.fontEm) && prev.hasOrdinals === Boolean(ordinals);
164
+ const prevGlyphs = canSkip ? prev.glyphs : void 0;
111
165
  for (let i = 0; i < glyphList.length; i++) {
112
166
  const glyph = glyphList[i];
167
+ if (canSkip && instance === i && drawable === i && i < prevGlyphs.length && glyph === prevGlyphs[i]) {
168
+ instance++;
169
+ drawable++;
170
+ if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
171
+ if (glyph.z < minZ) minZ = glyph.z;
172
+ if (glyph.z > maxZ) maxZ = glyph.z;
173
+ continue;
174
+ }
113
175
  const key = glyph.glyphKey;
114
176
  const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = glyphs.get(key));
115
- if (!header?.monotonePieceCount) continue;
177
+ if (!header?.monotonePieceCount) {
178
+ canSkip = false;
179
+ continue;
180
+ }
116
181
  const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable;
117
182
  const rect = attributes.layers || attributes.glyphRects ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect) : void 0;
118
183
  if (attributes.glyphRects && rect) {
@@ -122,13 +187,21 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
122
187
  attributes.glyphRects[rectOffset + 2] = rect[2];
123
188
  attributes.glyphRects[rectOffset + 3] = rect[3];
124
189
  }
125
- if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect);
190
+ const clip = glyph.clip;
191
+ if (clip !== prevClip) {
192
+ prevClip = clip;
193
+ fc0 = trackDirty ? Math.fround(clip[0]) : clip[0];
194
+ fc1 = trackDirty ? Math.fround(clip[1]) : clip[1];
195
+ fc2 = trackDirty ? Math.fround(clip[2]) : clip[2];
196
+ fc3 = trackDirty ? Math.fround(clip[3]) : clip[3];
197
+ }
198
+ if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty);
126
199
  else {
127
200
  const layer = header.layers?.[0] ?? header;
128
201
  const paint = "paintKind" in layer ? layer : null;
129
202
  if (paint) {
130
203
  const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color;
131
- writeInstance(glyph, header, layer, instance++, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * paint.rgba[3]), rect);
204
+ writeInstance(glyph, header, layer, instance++, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * paint.rgba[3]), fc0, fc1, fc2, fc3, rect, trackDirty);
132
205
  } else {
133
206
  const color = glyph.color;
134
207
  if (color !== prevColor) {
@@ -138,7 +211,7 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
138
211
  pc2 = byte(color[2]);
139
212
  pc3 = byte(color[3]);
140
213
  }
141
- writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, rect);
214
+ writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, fc0, fc1, fc2, fc3, rect, trackDirty);
142
215
  }
143
216
  }
144
217
  drawable++;
@@ -155,8 +228,11 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
155
228
  }
156
229
  /** Ordinary outlines retain the original six instance attributes. */
157
230
  function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered = false, ordinals) {
231
+ return createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, false);
232
+ }
233
+ function createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, fontEm) {
158
234
  layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin);
159
- const meta = metaSize(snapshot);
235
+ const meta = fontEm ? 3 : metaSize(snapshot);
160
236
  let count;
161
237
  let rects;
162
238
  let clips;
@@ -193,6 +269,7 @@ function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered =
193
269
  colors,
194
270
  metadata,
195
271
  metaSize: meta,
272
+ fontEm,
196
273
  bounds,
197
274
  bands,
198
275
  ...layers && glyphRects ? {
@@ -257,16 +334,42 @@ function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered =
257
334
  }
258
335
  geometry.instanceCount = count;
259
336
  setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
337
+ if (isDomSnapshot(snapshot)) prevWindfoilCache.set(geometry, {
338
+ glyphs: snapshot.glyphs,
339
+ glyphsMap: glyphs,
340
+ metaSize: meta,
341
+ fontEm,
342
+ layered: Boolean(layers),
343
+ hasOrdinals: Boolean(ordinals),
344
+ allSingleDrawn: !layers && result.instances === snapshot.glyphs.length
345
+ });
260
346
  return {
261
347
  geometry,
262
348
  maxSequence: result.maxSequence
263
349
  };
264
350
  }
265
351
  function windfoilContentFits(geometry, snapshot, glyphs) {
266
- const layered = geometry.getAttribute("windfoilLayer") !== void 0;
352
+ return analyticGeometryFits(geometry, snapshot, glyphs, false);
353
+ }
354
+ function analyticGeometryFits(geometry, snapshot, glyphs, fontEm) {
355
+ const attrs = geometry.attributes;
356
+ const layered = attrs["windfoilLayer"] !== void 0;
267
357
  const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES;
268
- for (const name of names) if (geometry.getAttribute(name)?.count !== geometry.instanceCount) return false;
269
- if (geometry.getAttribute("sdfMeta").itemSize !== metaSize(snapshot)) return false;
358
+ const count = geometry.instanceCount;
359
+ for (const name of names) if (attrs[name]?.count !== count) return false;
360
+ const metaSizeVal = fontEm ? 3 : metaSize(snapshot);
361
+ if (attrs["sdfMeta"]?.itemSize !== metaSizeVal) return false;
362
+ if (!layered && isDomSnapshot(snapshot) && !needsRunMotion(snapshot) && snapshot.glyphs.length === count) {
363
+ let allPlainSingle = true;
364
+ for (const req of snapshot.requests) {
365
+ const header = glyphs.get(req.key);
366
+ if (!header?.monotonePieceCount || (header.layers?.length ?? 1) > 1) {
367
+ allPlainSingle = false;
368
+ break;
369
+ }
370
+ }
371
+ if (allPlainSingle) return true;
372
+ }
270
373
  let instances = 0, drawable = 0;
271
374
  for (const glyph of snapshot.glyphs) {
272
375
  const header = glyphs.get(glyph.glyphKey);
@@ -277,29 +380,89 @@ function windfoilContentFits(geometry, snapshot, glyphs) {
277
380
  instances += layered ? layers : 1;
278
381
  }
279
382
  }
280
- return instances === geometry.instanceCount && (!layered || geometry.userData["ultraOwnGlyphRects"]?.length === drawable * 4);
383
+ return instances === count && (!layered || geometry.userData["ultraOwnGlyphRects"]?.length === drawable * 4);
384
+ }
385
+ /** A width change moves single-layer glyphs while keeping their paint and curve data. */
386
+ function reflowWindfoilGlyphGeometry(geometry, snapshot, backend, padding, glyphEm) {
387
+ const glyphs = backend.glyphs;
388
+ if (backend.layered || geometry.hasAttribute("windfoilLayer") || !analyticGeometryFits(geometry, snapshot, glyphs, glyphEm)) return backend.updateGeometry(geometry, snapshot, padding);
389
+ prevWindfoilCache.delete(geometry);
390
+ const rects = geometry.getAttribute("sdfRect");
391
+ const clips = geometry.getAttribute("sdfClip");
392
+ const meta = geometry.getAttribute("sdfMeta");
393
+ let count = 0, maxSequence = 0, minZ = 0, maxZ = 0;
394
+ resetDirtyBounds();
395
+ for (const glyph of snapshot.glyphs) {
396
+ const header = glyphs.get(glyph.glyphKey);
397
+ if (!header?.monotonePieceCount) continue;
398
+ const rect = fillWindfoilGlyphRect(glyph, header, header.layers?.[0]?.bbox ?? header.bbox);
399
+ const offset = count * 4;
400
+ writeFloat4(rects.array, offset, rect[0], rect[1], rect[2], rect[3], true, SLOT_RECT);
401
+ const clip = glyph.clip;
402
+ writeFloat4(clips.array, offset, clip[0], clip[1], clip[2], clip[3], true, SLOT_CLIP);
403
+ const sequence = Math.fround(glyph.sequence);
404
+ const m = count++ * meta.itemSize;
405
+ if (meta.array[m] !== sequence) {
406
+ meta.array[m] = sequence;
407
+ recordDirty(SLOT_META, m, m + 1);
408
+ }
409
+ if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
410
+ if (glyph.z < minZ) minZ = glyph.z;
411
+ if (glyph.z > maxZ) maxZ = glyph.z;
412
+ }
413
+ flushAttributeUpdate(rects, dirtyBounds[0], dirtyBounds[1]);
414
+ flushAttributeUpdate(clips, dirtyBounds[2], dirtyBounds[3]);
415
+ flushAttributeUpdate(meta, dirtyBounds[6], dirtyBounds[7]);
416
+ setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ);
417
+ return maxSequence;
418
+ }
419
+ function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked = false) {
420
+ return updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, false);
281
421
  }
282
- function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding, ordinals) {
283
- if (!windfoilContentFits(geometry, snapshot, glyphs)) return null;
284
- const array = (name) => geometry.getAttribute(name).array;
285
- const layer = geometry.getAttribute("windfoilLayer");
422
+ function updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, fontEm) {
423
+ if (!checked && !analyticGeometryFits(geometry, snapshot, glyphs, fontEm)) return null;
424
+ const rectAttr = geometry.getAttribute("sdfRect");
425
+ const clipAttr = geometry.getAttribute("sdfClip");
426
+ const colorAttr = geometry.getAttribute("sdfColor");
427
+ const metaAttr = geometry.getAttribute("sdfMeta");
428
+ const boundsAttr = geometry.getAttribute("windfoilBounds");
429
+ const bandAttr = geometry.getAttribute("windfoilBand");
430
+ const layer = geometry.attributes["windfoilLayer"];
431
+ resetDirtyBounds();
432
+ const domSnap = isDomSnapshot(snapshot);
433
+ const metaItemSize = metaAttr.itemSize;
286
434
  const result = writeGeometry(snapshot, glyphs, {
287
- rects: array("sdfRect"),
288
- clips: array("sdfClip"),
289
- colors: geometry.getAttribute("sdfColor").array,
290
- metadata: array("sdfMeta"),
291
- metaSize: geometry.getAttribute("sdfMeta").itemSize,
292
- bounds: array("windfoilBounds"),
293
- bands: array("windfoilBand"),
435
+ rects: rectAttr.array,
436
+ clips: clipAttr.array,
437
+ colors: colorAttr.array,
438
+ metadata: metaAttr.array,
439
+ metaSize: metaItemSize,
440
+ fontEm,
441
+ bounds: boundsAttr.array,
442
+ bands: bandAttr.array,
294
443
  ...layer ? {
295
444
  layers: layer.array,
296
445
  glyphRects: geometry.userData["ultraOwnGlyphRects"]
297
446
  } : {}
298
- }, ordinals);
299
- for (const name of layer ? LAYERED_ATTRIBUTES : ATTRIBUTES) geometry.getAttribute(name).needsUpdate = true;
447
+ }, ordinals, true, domSnap ? prevWindfoilCache.get(geometry) : void 0);
448
+ if (domSnap) prevWindfoilCache.set(geometry, {
449
+ glyphs: snapshot.glyphs,
450
+ glyphsMap: glyphs,
451
+ metaSize: metaItemSize,
452
+ fontEm,
453
+ layered: Boolean(layer),
454
+ hasOrdinals: Boolean(ordinals),
455
+ allSingleDrawn: !layer && result.instances === snapshot.glyphs.length
456
+ });
457
+ else prevWindfoilCache.delete(geometry);
458
+ const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES;
459
+ for (let i = 0; i < list.length; i++) {
460
+ const attribute = geometry.getAttribute(list[i]);
461
+ flushAttributeUpdate(attribute, dirtyBounds[i * 2], dirtyBounds[i * 2 + 1]);
462
+ }
300
463
  setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
301
464
  return result.maxSequence;
302
465
  }
303
- export { createWindfoilGlyphGeometry, fillWindfoilGlyphRect, updateWindfoilGlyphGeometry, windfoilContentFits, windfoilGlyphRect, writeLayerInstance };
466
+ export { analyticGeometryFits, createAnalyticGeometry, createWindfoilGlyphGeometry, fillWindfoilGlyphRect, fixedGlyphEm, reflowWindfoilGlyphGeometry, updateAnalyticGeometry, updateWindfoilGlyphGeometry, windfoilContentFits, windfoilGlyphRect, writeLayerInstance };
304
467
 
305
468
  //# sourceMappingURL=geometry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, metaSize, setBounds, setUnitQuad, writeMeta } from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\nfunction writeInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n c0: number,\n c1: number,\n c2: number,\n c3: number,\n glyphRect?: readonly [number, number, number, number],\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n const rects = attributes.rects\n rects[offset] = ox + b0 * scale\n rects[offset + 1] = baseline + b1 * scale\n rects[offset + 2] = ox + b2 * scale\n rects[offset + 3] = baseline + b3 * scale\n const clips = attributes.clips,\n clip = glyph.clip\n clips[offset] = clip[0]\n clips[offset + 1] = clip[1]\n clips[offset + 2] = clip[2]\n clips[offset + 3] = clip[3]\n const colors = attributes.colors\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n writeMeta(attributes.metadata, index, attributes.metaSize ?? 2, glyph)\n const bounds = attributes.bounds\n bounds[offset] = b0\n bounds[offset + 1] = b1\n bounds[offset + 2] = b2\n bounds[offset + 3] = b3\n const bands = attributes.bands\n bands[offset] = layer.rowBase\n bands[offset + 1] = layer.bandCount\n bands[offset + 2] = layer.bandH\n bands[offset + 3] = layer.invH\n const layers = attributes.layers\n if (layers) {\n const paint = 'paintKind' in layer ? layer : null\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n layers[offset] = mo ? mo[0] : (rect[0] + rect[2]) / 2\n layers[offset + 1] = mo ? mo[1] : (rect[1] + rect[3]) / 2\n layers[offset + 2] = ordinal\n layers[offset + 3] =\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0)\n }\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n): void {\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n index,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)),\n glyphRect,\n )\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n): { instances: number; maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n let prevKey: string | undefined\n let prevHeader: WindfoilGlyphHeader | undefined\n let prevColor: GlyphLayout['color'] | undefined\n let pc0 = 0\n let pc1 = 0\n let pc2 = 0\n let pc3 = 0\n const glyphList = snapshot.glyphs\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n const key = glyph.glyphKey\n const header = key === prevKey ? prevHeader : ((prevKey = key), (prevHeader = glyphs.get(key)))\n if (!header?.monotonePieceCount) continue\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect)\n }\n } else {\n const layer = header.layers?.[0] ?? header\n const paint = 'paintKind' in layer ? layer : null\n if (paint) {\n const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * paint.rgba[3]),\n rect,\n )\n } else {\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n pc0,\n pc1,\n pc2,\n pc3,\n rect,\n )\n }\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { instances: instance, maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const meta = metaSize(snapshot)\n let count: number\n let rects: Float32Array\n let clips: Float32Array\n let colors: Uint8Array\n let metadata: Float32Array\n let bounds: Float32Array\n let bands: Float32Array\n let layers: Float32Array | undefined\n let glyphRects: Float32Array | undefined\n if (layered) {\n const counted = countLayout(snapshot, glyphs, true)\n count = counted.instances\n rects = new Float32Array(count * 4)\n clips = new Float32Array(count * 4)\n colors = new Uint8Array(count * 4)\n metadata = new Float32Array(count * meta)\n bounds = new Float32Array(count * 4)\n bands = new Float32Array(count * 4)\n layers = new Float32Array(count * 4)\n glyphRects = new Float32Array(counted.drawable * 4)\n } else {\n const total = snapshot.glyphs.length\n count = total\n rects = new Float32Array(total * 4)\n clips = new Float32Array(total * 4)\n colors = new Uint8Array(total * 4)\n metadata = new Float32Array(total * meta)\n bounds = new Float32Array(total * 4)\n bands = new Float32Array(total * 4)\n }\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects,\n clips,\n colors,\n metadata,\n metaSize: meta,\n bounds,\n bands,\n ...(layers && glyphRects ? { layers, glyphRects } : {}),\n },\n ordinals,\n )\n if (!layered && result.instances < count) {\n count = result.instances\n rects = rects.subarray(0, count * 4)\n clips = clips.subarray(0, count * 4)\n colors = colors.subarray(0, count * 4)\n metadata = metadata.subarray(0, count * meta)\n bounds = bounds.subarray(0, count * 4)\n bands = bands.subarray(0, count * 4)\n }\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['windfoilBounds', bounds, 4, false],\n ['windfoilBand', bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = glyphRects\n geometry.userData['ultraOwnGlyphRects'] = glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n const layered =\n (geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined) !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (const name of names) {\n if (\n (geometry.getAttribute(name) as InstancedBufferAttribute | undefined)?.count !==\n geometry.instanceCount\n )\n return false\n }\n if (\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).itemSize !== metaSize(snapshot)\n )\n return false\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === geometry.instanceCount &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n): number | null {\n if (!windfoilContentFits(geometry, snapshot, glyphs)) return null\n const array = (name: string): Float32Array => geometry.getAttribute(name).array as Float32Array\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects: array('sdfRect'),\n clips: array('sdfClip'),\n colors: geometry.getAttribute('sdfColor').array as Uint8Array,\n metadata: array('sdfMeta'),\n metaSize: geometry.getAttribute('sdfMeta').itemSize,\n bounds: array('windfoilBounds'),\n bands: array('windfoilBand'),\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n )\n for (const name of layer ? LAYERED_ATTRIBUTES : ATTRIBUTES)\n (geometry.getAttribute(name) as InstancedBufferAttribute).needsUpdate = true\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAMA,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAe1D,IAAM,cAAgD;CAAC;CAAG;CAAG;CAAG;AAAC;AAEjE,SAAgB,sBACd,OACA,QACA,OAA4B,OAAO,MACnC,MAAwC,aACN;CAClC,MAAM,QAAQ,MAAM,WAAW,OAAO;CACtC,MAAM,WAAW,MAAM,cAAc,MAAM,kBAAkB,CAAC,OAAO,UAAU;CAC/E,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK;CACnC,IAAI,KAAK,WAAW,KAAK,KAAK;CAC9B,IAAI,KAAK,MAAM,UAAU,KAAK,KAAK;CACnC,IAAI,KAAK,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"version":3,"file":"geometry.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport {\n byte,\n flushAttributeUpdate,\n isDomSnapshot,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n} from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\ninterface PrevWindfoilBatch {\n readonly glyphs: readonly GlyphLayout[]\n readonly glyphsMap: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly metaSize: number\n readonly fontEm: boolean\n readonly layered: boolean\n readonly hasOrdinals: boolean\n readonly allSingleDrawn: boolean\n}\n\nconst prevWindfoilCache = new WeakMap<InstancedBufferGeometry, PrevWindfoilBatch>()\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nconst SLOT_RECT = 0\nconst SLOT_CLIP = 1\nconst SLOT_COLOR = 2\nconst SLOT_META = 3\nconst SLOT_BOUNDS = 4\nconst SLOT_BAND = 5\nconst SLOT_LAYER = 6\nconst DIRTY_UNSET = 0x7fffffff\nconst dirtyBounds = new Int32Array(14)\n\nfunction resetDirtyBounds(): void {\n for (let slot = 0; slot < 7; slot++) {\n const base = slot * 2\n dirtyBounds[base] = DIRTY_UNSET\n dirtyBounds[base + 1] = 0\n }\n}\n\nfunction recordDirty(slot: number, start: number, end: number): void {\n const base = slot * 2\n if (start < dirtyBounds[base]!) dirtyBounds[base] = start\n if (end > dirtyBounds[base + 1]!) dirtyBounds[base + 1] = end\n}\n\nfunction writeFloat4(\n target: Float32Array,\n offset: number,\n a: number,\n b: number,\n c: number,\n d: number,\n trackDirty: boolean,\n slot: number,\n): void {\n if (trackDirty) {\n const fa = Math.fround(a)\n const fb = Math.fround(b)\n const fc = Math.fround(c)\n const fd = Math.fround(d)\n if (\n target[offset] === fa &&\n target[offset + 1] === fb &&\n target[offset + 2] === fc &&\n target[offset + 3] === fd\n ) {\n return\n }\n target[offset] = fa\n target[offset + 1] = fb\n target[offset + 2] = fc\n target[offset + 3] = fd\n recordDirty(slot, offset, offset + 4)\n return\n }\n target[offset] = a\n target[offset + 1] = b\n target[offset + 2] = c\n target[offset + 3] = d\n}\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly fontEm?: boolean\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\n/** The negative font size feeds tone dilation while keeping the analytic batch selected. */\nexport function fixedGlyphEm(glyph: GlyphLayout): number {\n return glyph.shapeGroup === undefined ? -glyph.fontSize : 0\n}\n\nfunction writeInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n c0: number,\n c1: number,\n c2: number,\n c3: number,\n fc0: number,\n fc1: number,\n fc2: number,\n fc3: number,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n writeFloat4(\n attributes.rects,\n offset,\n ox + b0 * scale,\n baseline + b1 * scale,\n ox + b2 * scale,\n baseline + b3 * scale,\n trackDirty,\n SLOT_RECT,\n )\n writeFloat4(attributes.clips, offset, fc0, fc1, fc2, fc3, trackDirty, SLOT_CLIP)\n const colors = attributes.colors\n if (trackDirty) {\n if (\n colors[offset] !== c0 ||\n colors[offset + 1] !== c1 ||\n colors[offset + 2] !== c2 ||\n colors[offset + 3] !== c3\n ) {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n recordDirty(SLOT_COLOR, offset, offset + 4)\n }\n } else {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n }\n const metaSizeValue = attributes.metaSize ?? 2\n const metadata = attributes.metadata\n const m = index * metaSizeValue\n let em = 0\n if (metaSizeValue === 3) em = attributes.fontEm ? fixedGlyphEm(glyph) : (glyph.switchEm ?? 0)\n if (\n !trackDirty ||\n metadata[m] !== Math.fround(glyph.sequence) ||\n metadata[m + 1] !== Math.fround(glyph.z) ||\n (metaSizeValue === 3 && metadata[m + 2] !== Math.fround(em))\n ) {\n metadata[m] = glyph.sequence\n metadata[m + 1] = glyph.z\n if (metaSizeValue === 3) metadata[m + 2] = em\n if (trackDirty) recordDirty(SLOT_META, m, m + metaSizeValue)\n }\n writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS)\n writeFloat4(\n attributes.bands,\n offset,\n layer.rowBase,\n layer.bandCount,\n layer.bandH,\n layer.invH,\n trackDirty,\n SLOT_BAND,\n )\n const layers = attributes.layers\n if (layers) {\n const paint = 'paintKind' in layer ? layer : null\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n writeFloat4(\n layers,\n offset,\n mo ? mo[0] : (rect[0] + rect[2]) / 2,\n mo ? mo[1] : (rect[1] + rect[3]) / 2,\n ordinal,\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0),\n trackDirty,\n SLOT_LAYER,\n )\n }\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n const clip = glyph.clip\n writeInstance(\n glyph,\n header,\n layer,\n index,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)),\n clip[0],\n clip[1],\n clip[2],\n clip[3],\n glyphRect,\n trackDirty,\n )\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n trackDirty = false,\n prev?: PrevWindfoilBatch,\n): { instances: number; maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n let prevKey: string | undefined\n let prevHeader: WindfoilGlyphHeader | undefined\n let prevColor: GlyphLayout['color'] | undefined\n let pc0 = 0\n let pc1 = 0\n let pc2 = 0\n let pc3 = 0\n let prevClip: GlyphLayout['clip'] | undefined\n let fc0 = 0\n let fc1 = 0\n let fc2 = 0\n let fc3 = 0\n const glyphList = snapshot.glyphs\n let canSkip =\n trackDirty &&\n prev !== undefined &&\n prev.allSingleDrawn &&\n !prev.layered &&\n !attributes.layers &&\n prev.glyphsMap === glyphs &&\n prev.metaSize === (attributes.metaSize ?? 2) &&\n prev.fontEm === Boolean(attributes.fontEm) &&\n prev.hasOrdinals === Boolean(ordinals)\n const prevGlyphs = canSkip ? prev!.glyphs : undefined\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n if (\n canSkip &&\n instance === i &&\n drawable === i &&\n i < prevGlyphs!.length &&\n glyph === prevGlyphs![i]\n ) {\n instance++\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n continue\n }\n const key = glyph.glyphKey\n const header = key === prevKey ? prevHeader : ((prevKey = key), (prevHeader = glyphs.get(key)))\n if (!header?.monotonePieceCount) {\n canSkip = false\n continue\n }\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = trackDirty ? Math.fround(clip[0]) : clip[0]\n fc1 = trackDirty ? Math.fround(clip[1]) : clip[1]\n fc2 = trackDirty ? Math.fround(clip[2]) : clip[2]\n fc3 = trackDirty ? Math.fround(clip[3]) : clip[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty)\n }\n } else {\n const layer = header.layers?.[0] ?? header\n const paint = 'paintKind' in layer ? layer : null\n if (paint) {\n const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * paint.rgba[3]),\n fc0,\n fc1,\n fc2,\n fc3,\n rect,\n trackDirty,\n )\n } else {\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n pc0,\n pc1,\n pc2,\n pc3,\n fc0,\n fc1,\n fc2,\n fc3,\n rect,\n trackDirty,\n )\n }\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { instances: instance, maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n return createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, false)\n}\n\nexport function createAnalyticGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered: boolean,\n ordinals: Float32Array | undefined,\n fontEm: boolean,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const meta = fontEm ? 3 : metaSize(snapshot)\n let count: number\n let rects: Float32Array\n let clips: Float32Array\n let colors: Uint8Array\n let metadata: Float32Array\n let bounds: Float32Array\n let bands: Float32Array\n let layers: Float32Array | undefined\n let glyphRects: Float32Array | undefined\n if (layered) {\n const counted = countLayout(snapshot, glyphs, true)\n count = counted.instances\n rects = new Float32Array(count * 4)\n clips = new Float32Array(count * 4)\n colors = new Uint8Array(count * 4)\n metadata = new Float32Array(count * meta)\n bounds = new Float32Array(count * 4)\n bands = new Float32Array(count * 4)\n layers = new Float32Array(count * 4)\n glyphRects = new Float32Array(counted.drawable * 4)\n } else {\n const total = snapshot.glyphs.length\n count = total\n rects = new Float32Array(total * 4)\n clips = new Float32Array(total * 4)\n colors = new Uint8Array(total * 4)\n metadata = new Float32Array(total * meta)\n bounds = new Float32Array(total * 4)\n bands = new Float32Array(total * 4)\n }\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects,\n clips,\n colors,\n metadata,\n metaSize: meta,\n fontEm,\n bounds,\n bands,\n ...(layers && glyphRects ? { layers, glyphRects } : {}),\n },\n ordinals,\n )\n if (!layered && result.instances < count) {\n count = result.instances\n rects = rects.subarray(0, count * 4)\n clips = clips.subarray(0, count * 4)\n colors = colors.subarray(0, count * 4)\n metadata = metadata.subarray(0, count * meta)\n bounds = bounds.subarray(0, count * 4)\n bands = bands.subarray(0, count * 4)\n }\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['windfoilBounds', bounds, 4, false],\n ['windfoilBand', bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = glyphRects\n geometry.userData['ultraOwnGlyphRects'] = glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n if (isDomSnapshot(snapshot)) {\n prevWindfoilCache.set(geometry, {\n glyphs: snapshot.glyphs,\n glyphsMap: glyphs,\n metaSize: meta,\n fontEm,\n layered: Boolean(layers),\n hasOrdinals: Boolean(ordinals),\n allSingleDrawn: !layers && result.instances === snapshot.glyphs.length,\n })\n }\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n return analyticGeometryFits(geometry, snapshot, glyphs, false)\n}\n\nexport function analyticGeometryFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n fontEm: boolean,\n): boolean {\n const attrs = geometry.attributes\n const layered = attrs['windfoilLayer'] !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n const count = geometry.instanceCount\n for (const name of names) {\n if (attrs[name]?.count !== count) return false\n }\n const metaSizeVal = fontEm ? 3 : metaSize(snapshot)\n if (attrs['sdfMeta']?.itemSize !== metaSizeVal) return false\n if (\n !layered &&\n isDomSnapshot(snapshot) &&\n !needsRunMotion(snapshot) &&\n snapshot.glyphs.length === count\n ) {\n let allPlainSingle = true\n for (const req of snapshot.requests) {\n const header = glyphs.get(req.key)\n if (!header?.monotonePieceCount || (header.layers?.length ?? 1) > 1) {\n allPlainSingle = false\n break\n }\n }\n if (allPlainSingle) return true\n }\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === count &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\n/** A width change moves single-layer glyphs while keeping their paint and curve data. */\nexport function reflowWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n backend: {\n readonly layered: boolean\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n padding: number,\n ): number | null\n },\n padding: number,\n glyphEm: boolean,\n): number | null {\n const glyphs = backend.glyphs\n if (\n backend.layered ||\n geometry.hasAttribute('windfoilLayer') ||\n !analyticGeometryFits(geometry, snapshot, glyphs, glyphEm)\n )\n return backend.updateGeometry(geometry, snapshot, padding)\n prevWindfoilCache.delete(geometry)\n const rects = geometry.getAttribute('sdfRect') as InstancedBufferAttribute\n const clips = geometry.getAttribute('sdfClip') as InstancedBufferAttribute\n const meta = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute\n let count = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n resetDirtyBounds()\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (!header?.monotonePieceCount) continue\n const bbox = header.layers?.[0]?.bbox ?? header.bbox\n const rect = fillWindfoilGlyphRect(glyph, header, bbox)\n const offset = count * 4\n writeFloat4(\n rects.array as Float32Array,\n offset,\n rect[0],\n rect[1],\n rect[2],\n rect[3],\n true,\n SLOT_RECT,\n )\n const clip = glyph.clip\n writeFloat4(\n clips.array as Float32Array,\n offset,\n clip[0],\n clip[1],\n clip[2],\n clip[3],\n true,\n SLOT_CLIP,\n )\n const sequence = Math.fround(glyph.sequence)\n const m = count++ * meta.itemSize\n if (meta.array[m] !== sequence) {\n meta.array[m] = sequence\n recordDirty(SLOT_META, m, m + 1)\n }\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n flushAttributeUpdate(rects, dirtyBounds[SLOT_RECT * 2]!, dirtyBounds[SLOT_RECT * 2 + 1]!)\n flushAttributeUpdate(clips, dirtyBounds[SLOT_CLIP * 2]!, dirtyBounds[SLOT_CLIP * 2 + 1]!)\n flushAttributeUpdate(meta, dirtyBounds[SLOT_META * 2]!, dirtyBounds[SLOT_META * 2 + 1]!)\n setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ)\n return maxSequence\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n checked = false,\n): number | null {\n return updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, false)\n}\n\nexport function updateAnalyticGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals: Float32Array | undefined,\n checked: boolean,\n fontEm: boolean,\n): number | null {\n if (!checked && !analyticGeometryFits(geometry, snapshot, glyphs, fontEm)) return null\n const rectAttr = geometry.getAttribute('sdfRect') as InstancedBufferAttribute\n const clipAttr = geometry.getAttribute('sdfClip') as InstancedBufferAttribute\n const colorAttr = geometry.getAttribute('sdfColor') as InstancedBufferAttribute\n const metaAttr = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute\n const boundsAttr = geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute\n const bandAttr = geometry.getAttribute('windfoilBand') as InstancedBufferAttribute\n const layer = geometry.attributes['windfoilLayer'] as InstancedBufferAttribute | undefined\n resetDirtyBounds()\n const domSnap = isDomSnapshot(snapshot)\n const metaItemSize = metaAttr.itemSize\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects: rectAttr.array as Float32Array,\n clips: clipAttr.array as Float32Array,\n colors: colorAttr.array as Uint8Array,\n metadata: metaAttr.array as Float32Array,\n metaSize: metaItemSize,\n fontEm,\n bounds: boundsAttr.array as Float32Array,\n bands: bandAttr.array as Float32Array,\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n true,\n domSnap ? prevWindfoilCache.get(geometry) : undefined,\n )\n if (domSnap) {\n prevWindfoilCache.set(geometry, {\n glyphs: snapshot.glyphs,\n glyphsMap: glyphs,\n metaSize: metaItemSize,\n fontEm,\n layered: Boolean(layer),\n hasOrdinals: Boolean(ordinals),\n allSingleDrawn: !layer && result.instances === snapshot.glyphs.length,\n })\n } else {\n prevWindfoilCache.delete(geometry)\n }\n const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (let i = 0; i < list.length; i++) {\n const attribute = geometry.getAttribute(list[i]!) as InstancedBufferAttribute\n flushAttributeUpdate(attribute, dirtyBounds[i * 2]!, dirtyBounds[i * 2 + 1]!)\n }\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAwBA,IAAM,oCAAoB,IAAI,QAAoD;AAElF,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAE1D,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAA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EAChB,QAAQ,UAAU;EAClB,UAAU,SAAS;EACnB,UAAU;EACV;EACA,QAAQ,WAAW;EACnB,OAAO,SAAS;EAChB,GAAI,QACA;GACE,QAAQ,MAAM;GACd,YAAY,SAAS,SAAS;EAChC,IACA,CAAC;CACP,GACA,UACA,MACA,UAAU,kBAAkB,IAAI,QAAQ,IAAI,KAAA,CAC9C;CACA,IAAI,SACF,kBAAkB,IAAI,UAAU;EAC9B,QAAQ,SAAS;EACjB,WAAW;EACX,UAAU;EACV;EACA,SAAS,QAAQ,KAAK;EACtB,aAAa,QAAQ,QAAQ;EAC7B,gBAAgB,CAAC,SAAS,OAAO,cAAc,SAAS,OAAO;CACjE,CAAC;MAED,kBAAkB,OAAO,QAAQ;CAEnC,MAAM,OAAO,QAAQ,qBAAqB;CAC1C,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,YAAY,SAAS,aAAa,KAAK,EAAG;EAChD,qBAAqB,WAAW,YAAY,IAAI,IAAK,YAAY,IAAI,IAAI,EAAG;CAC9E;CACA,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
@@ -220,13 +220,14 @@ function sortByLow(arr, start, end, keys) {
220
220
  }
221
221
  }
222
222
  }
223
- function prepareBand(bandRecord, start, pieceCount, curves) {
223
+ function prepareBand(bandRecord, start, rawCount, curves) {
224
+ const pieceCount = rawCount & 2147483647, allLinear = (rawCount & 2147483648) !== 0;
224
225
  if (pieceCount > scratchBandLow.length) {
225
226
  const capLen = Math.max(scratchBandLow.length * 2, pieceCount);
226
227
  scratchBandLow = new Float64Array(capLen);
227
228
  scratchBandHeight = new Float64Array(capLen);
228
229
  }
229
- const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start * 6, q2FloatBase = bandFloatBase + pieceCount * 4;
230
+ const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start * 4, q2FloatBase = bandFloatBase + pieceCount * 4;
230
231
  let bottom = Infinity, top = -Infinity, activeCount = 0;
231
232
  for (let k = 0; k < pieceCount; k++) {
232
233
  const pair = bandFloatBase + k * 4, y0 = curves[pair + 1], y1 = curves[pair + 3], lo = y0 < y1 ? y0 : y1, hi = y0 < y1 ? y1 : y0, h = hi - lo;
@@ -269,7 +270,7 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
269
270
  sortByLow(cArr, shortBase, activeEnd, lowScratch);
270
271
  }
271
272
  for (let i = start; i < activeEnd; i++) {
272
- const k = cArr[i], pair = bandFloatBase + k * 4, mid = q2FloatBase + k * 2, px0 = curves[pair], py0 = curves[pair + 1], px1 = curves[mid], px2 = curves[pair + 2], py2 = curves[pair + 3], up = py2 > py0, lo = up ? py0 : py2, i4 = i * 4;
273
+ const k = cArr[i], pair = bandFloatBase + k * 4, mid = allLinear ? ~pair : q2FloatBase + (k >> 1) * 4 + (k & 1) * 2, px0 = curves[pair], py0 = curves[pair + 1], px2 = curves[pair + 2], py2 = curves[pair + 3], px1 = allLinear ? (px0 + px2) * .5 : curves[mid], up = py2 > py0, lo = up ? py0 : py2, i4 = i * 4;
273
274
  cArr[i] = up ? pair : ~pair;
274
275
  midArr[i] = mid;
275
276
  shortLow[i] = lo;
@@ -323,24 +324,23 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
323
324
  let xh = boundsArr[k4 + 3];
324
325
  if (xh >= ex0Tol) {
325
326
  if (yl >= s0 && yh <= s1) return 1;
326
- const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2];
327
+ const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2], py0 = curves[pair + 1], py2 = curves[pair + 3], px1 = mid < 0 ? (px0 + px2) * .5 : curves[mid], py1 = mid < 0 ? (py0 + py2) * .5 : curves[mid + 1];
327
328
  let a;
328
329
  if (yl >= s0) {
329
330
  a = sign > 0 ? px0 : px2;
330
331
  if (a >= ex0Tol && a <= ex1Tol) return 1;
331
- const b = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s1));
332
+ const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
332
333
  xl = a < b ? a : b;
333
334
  xh = a < b ? b : a;
334
335
  if (xh >= ex0Tol && xl <= ex1Tol) return 1;
335
336
  } else if (yh <= s1) {
336
337
  const b = sign > 0 ? px2 : px0;
337
338
  if (b >= ex0Tol && b <= ex1Tol) return 1;
338
- a = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s0));
339
+ a = at(px0, px1, px2, solve(py0, py1, py2, s0));
339
340
  xl = a < b ? a : b;
340
341
  xh = a < b ? b : a;
341
342
  if (xh >= ex0Tol && xl <= ex1Tol) return 1;
342
343
  } else {
343
- const px1 = curves[mid], py0 = curves[pair + 1], py1 = curves[mid + 1], py2 = curves[pair + 3];
344
344
  a = at(px0, px1, px2, solve(py0, py1, py2, s0));
345
345
  if (a >= ex0Tol && a <= ex1Tol) return 1;
346
346
  const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
@@ -489,7 +489,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
489
489
  gridTableLen = table.length;
490
490
  gridUsed = 0;
491
491
  ensureLayerPools(totalLayers);
492
- const totalPieces = Math.ceil(curves.length / 6), totalBands = Math.ceil(rows.length / 6);
492
+ const totalPieces = Math.ceil(curves.length / 4), totalBands = Math.ceil(rows.length / 6);
493
493
  if (poolPieceC.length < totalPieces) {
494
494
  const cap = Math.max(poolPieceC.length * 2, totalPieces);
495
495
  poolPieceC = new Int32Array(cap);