ultra-text 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +168 -85
  2. package/THIRD_PARTY_NOTICES.md +3 -0
  3. package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker-xS57yQbP.js} +13 -11
  4. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +1 -0
  5. package/dist/atlas/appendAtlas.js +2 -1
  6. package/dist/atlas/appendAtlas.js.map +1 -1
  7. package/dist/atlas/buildAtlas.js +3 -14
  8. package/dist/atlas/buildAtlas.js.map +1 -1
  9. package/dist/atlas/cpuSdf.js +12 -10
  10. package/dist/atlas/cpuSdf.js.map +1 -1
  11. package/dist/atlas/cpuWorker.js +1 -1
  12. package/dist/atlas/cpuWorker.js.map +1 -1
  13. package/dist/atlas/gpuAtlas.d.ts +7 -6
  14. package/dist/atlas/gpuAtlas.js +280 -145
  15. package/dist/atlas/gpuAtlas.js.map +1 -1
  16. package/dist/atlas/jfaWgsl.js +201 -73
  17. package/dist/atlas/jfaWgsl.js.map +1 -1
  18. package/dist/atlas/rasterize.d.ts +2 -0
  19. package/dist/atlas/rasterize.js +2 -87
  20. package/dist/atlas/rasterize.js.map +1 -1
  21. package/dist/dom/DomSdf.js +66 -15
  22. package/dist/dom/DomSdf.js.map +1 -1
  23. package/dist/dom/DomSlug.d.ts +26 -0
  24. package/dist/dom/DomSlug.js +640 -0
  25. package/dist/dom/DomSlug.js.map +1 -0
  26. package/dist/dom/SlugText.d.ts +18 -0
  27. package/dist/dom/SlugText.js +94 -0
  28. package/dist/dom/SlugText.js.map +1 -0
  29. package/dist/dom/Text.js +4 -67
  30. package/dist/dom/Text.js.map +1 -1
  31. package/dist/dom/fontCanvas.d.ts +2 -0
  32. package/dist/dom/fontCanvas.js +101 -0
  33. package/dist/dom/fontCanvas.js.map +1 -0
  34. package/dist/dom/layoutSignature.js +29 -2
  35. package/dist/dom/layoutSignature.js.map +1 -1
  36. package/dist/dom/snapshot.js +251 -96
  37. package/dist/dom/snapshot.js.map +1 -1
  38. package/dist/dom/textHost.d.ts +11 -0
  39. package/dist/dom/textHost.js +68 -0
  40. package/dist/dom/textHost.js.map +1 -0
  41. package/dist/slug/SlugMaterial.d.ts +3 -2
  42. package/dist/slug/SlugMaterial.js +28 -2
  43. package/dist/slug/SlugMaterial.js.map +1 -1
  44. package/dist/slug/coverage.d.ts +1 -1
  45. package/dist/slug/coverage.js +1 -1
  46. package/dist/slug/coverage.js.map +1 -1
  47. package/dist/slug/preprocessCore.d.ts +1 -2
  48. package/dist/slug/preprocessCore.js +39 -16
  49. package/dist/slug/preprocessCore.js.map +1 -1
  50. package/dist/slug/runtime.js +6 -4
  51. package/dist/slug/runtime.js.map +1 -1
  52. package/dist/slug/standaloneRuntime.d.ts +39 -0
  53. package/dist/slug/standaloneRuntime.js +140 -0
  54. package/dist/slug/standaloneRuntime.js.map +1 -0
  55. package/dist/slug/truetype.d.ts +22 -0
  56. package/dist/slug/truetype.js +494 -0
  57. package/dist/slug/truetype.js.map +1 -0
  58. package/dist/slug-vanilla.d.ts +364 -0
  59. package/dist/slug-vanilla.js +1461 -0
  60. package/dist/slug-vanilla.js.map +1 -0
  61. package/dist/slug.d.ts +21 -0
  62. package/dist/slug.js +19 -0
  63. package/dist/text/GlyphTextMaterial.d.ts +11 -11
  64. package/dist/text/GlyphTextMaterial.js +98 -29
  65. package/dist/text/GlyphTextMaterial.js.map +1 -1
  66. package/dist/text/SdfTextMaterial.d.ts +5 -4
  67. package/dist/text/SdfTextMaterial.js +22 -4
  68. package/dist/text/SdfTextMaterial.js.map +1 -1
  69. package/dist/types.d.ts +63 -14
  70. package/dist/vanilla.d.ts +3 -0
  71. package/dist/vanilla.js +132 -59
  72. package/dist/vanilla.js.map +1 -1
  73. package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
  74. package/dist/windfoil/WindfoilMaterial.js +8 -1
  75. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  76. package/dist/windfoil/abortable.d.ts +2 -0
  77. package/dist/windfoil/abortable.js +26 -0
  78. package/dist/windfoil/abortable.js.map +1 -0
  79. package/dist/windfoil/color.js +2 -1
  80. package/dist/windfoil/color.js.map +1 -1
  81. package/dist/windfoil/coverage.d.ts +3 -20
  82. package/dist/windfoil/coverage.js +7 -20
  83. package/dist/windfoil/coverage.js.map +1 -1
  84. package/dist/windfoil/emoji.js +1 -1
  85. package/dist/windfoil/emoji.js.map +1 -1
  86. package/dist/windfoil/emojiMetrics.js +1 -1
  87. package/dist/windfoil/emojiMetrics.js.map +1 -1
  88. package/dist/windfoil/geometry.js +100 -33
  89. package/dist/windfoil/geometry.js.map +1 -1
  90. package/dist/windfoil/layerGrid.js +14 -10
  91. package/dist/windfoil/layerGrid.js.map +1 -1
  92. package/dist/windfoil/layerNormalization.d.ts +1 -1
  93. package/dist/windfoil/layerNormalization.js +1 -1
  94. package/dist/windfoil/layerNormalization.js.map +1 -1
  95. package/dist/windfoil/outlineValidation.d.ts +86 -0
  96. package/dist/windfoil/outlineValidation.js +65 -0
  97. package/dist/windfoil/outlineValidation.js.map +1 -0
  98. package/dist/windfoil/preprocess.js +3 -2
  99. package/dist/windfoil/preprocess.js.map +1 -1
  100. package/dist/windfoil/preprocessCore.d.ts +4 -85
  101. package/dist/windfoil/preprocessCore.js +210 -206
  102. package/dist/windfoil/preprocessCore.js.map +1 -1
  103. package/dist/windfoil/requests.js +1 -1
  104. package/dist/windfoil/requests.js.map +1 -1
  105. package/dist/windfoil/runtime.d.ts +2 -1
  106. package/dist/windfoil/runtime.js +3 -2
  107. package/dist/windfoil/runtime.js.map +1 -1
  108. package/dist/windfoil/shapeResources.js +2 -1
  109. package/dist/windfoil/shapeResources.js.map +1 -1
  110. package/dist/windfoil/shapes.js +1 -1
  111. package/dist/windfoil/skirt.d.ts +22 -0
  112. package/dist/windfoil/skirt.js +20 -0
  113. package/dist/windfoil/skirt.js.map +1 -0
  114. package/dist/windfoil/storage.d.ts +2 -2
  115. package/dist/windfoil/storage.js +1 -22
  116. package/dist/windfoil/storage.js.map +1 -1
  117. package/dist/windfoil/trace/contours.d.ts +0 -5
  118. package/dist/windfoil/trace/contours.js +81 -114
  119. package/dist/windfoil/trace/contours.js.map +1 -1
  120. package/dist/windfoil/trace/fit.d.ts +0 -6
  121. package/dist/windfoil/trace/fit.js +304 -308
  122. package/dist/windfoil/trace/fit.js.map +1 -1
  123. package/dist/windfoil/trace/outline.js +10 -10
  124. package/dist/windfoil/trace/outline.js.map +1 -1
  125. package/dist/windfoil/trace/types.d.ts +5 -3
  126. package/dist/windfoil/tracedOutlines.d.ts +37 -1
  127. package/dist/windfoil/tracedOutlines.js +172 -33
  128. package/dist/windfoil/tracedOutlines.js.map +1 -1
  129. package/package.json +57 -8
  130. package/skills/ultra-text/SKILL.md +114 -0
  131. package/skills/ultra-text/references/frameworks.md +43 -0
  132. package/skills/ultra-text/references/three-tsl.md +78 -0
  133. package/skills/ultra-text/references/vanilla-webgpu.md +95 -0
  134. package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
@@ -34,8 +34,7 @@ function windfoilGlyphRect(glyph, header, bbox = header.bbox) {
34
34
  0
35
35
  ]);
36
36
  }
37
- /** Shared by text and shape geometry; one layer adds only one vertex attribute. */
38
- function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect) {
37
+ function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1, c2, c3, glyphRect) {
39
38
  const offset = index * 4;
40
39
  const scale = glyph.fontSize / header.unitsPerEm;
41
40
  const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale);
@@ -52,13 +51,11 @@ function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, gl
52
51
  clips[offset + 1] = clip[1];
53
52
  clips[offset + 2] = clip[2];
54
53
  clips[offset + 3] = clip[3];
55
- const paint = "paintKind" in layer ? layer : null;
56
- const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color;
57
54
  const colors = attributes.colors;
58
- colors[offset] = byte(rgb[0]);
59
- colors[offset + 1] = byte(rgb[1]);
60
- colors[offset + 2] = byte(rgb[2]);
61
- colors[offset + 3] = byte(glyph.color[3] * (paint ? paint.rgba[3] : 1));
55
+ colors[offset] = c0;
56
+ colors[offset + 1] = c1;
57
+ colors[offset + 2] = c2;
58
+ colors[offset + 3] = c3;
62
59
  writeMeta(attributes.metadata, index, attributes.metaSize ?? 2, glyph);
63
60
  const bounds = attributes.bounds;
64
61
  bounds[offset] = b0;
@@ -72,6 +69,7 @@ function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, gl
72
69
  bands[offset + 3] = layer.invH;
73
70
  const layers = attributes.layers;
74
71
  if (layers) {
72
+ const paint = "paintKind" in layer ? layer : null;
75
73
  const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect);
76
74
  const mo = glyph.motionOrigin;
77
75
  layers[offset] = mo ? mo[0] : (rect[0] + rect[2]) / 2;
@@ -80,6 +78,12 @@ function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, gl
80
78
  layers[offset + 3] = paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0;
81
79
  }
82
80
  }
81
+ /** Shared by text and shape geometry; one layer adds only one vertex attribute. */
82
+ function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect) {
83
+ const paint = "paintKind" in layer ? layer : null;
84
+ 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);
86
+ }
83
87
  function countLayout(snapshot, glyphs, layered) {
84
88
  let instances = 0, drawable = 0;
85
89
  for (const glyph of snapshot.glyphs) {
@@ -96,10 +100,18 @@ function countLayout(snapshot, glyphs, layered) {
96
100
  }
97
101
  function writeGeometry(snapshot, glyphs, attributes, ordinals) {
98
102
  let instance = 0, drawable = 0, maxSequence = 0, minZ = 0, maxZ = 0;
103
+ let prevKey;
104
+ let prevHeader;
105
+ let prevColor;
106
+ let pc0 = 0;
107
+ let pc1 = 0;
108
+ let pc2 = 0;
109
+ let pc3 = 0;
99
110
  const glyphList = snapshot.glyphs;
100
111
  for (let i = 0; i < glyphList.length; i++) {
101
112
  const glyph = glyphList[i];
102
- const header = glyphs.get(glyph.glyphKey);
113
+ const key = glyph.glyphKey;
114
+ const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = glyphs.get(key));
103
115
  if (!header?.monotonePieceCount) continue;
104
116
  const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable;
105
117
  const rect = attributes.layers || attributes.glyphRects ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect) : void 0;
@@ -111,13 +123,31 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
111
123
  attributes.glyphRects[rectOffset + 3] = rect[3];
112
124
  }
113
125
  if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect);
114
- else writeLayerInstance(glyph, header, header.layers?.[0] ?? header, instance++, ordinal, attributes, rect);
126
+ else {
127
+ const layer = header.layers?.[0] ?? header;
128
+ const paint = "paintKind" in layer ? layer : null;
129
+ if (paint) {
130
+ 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);
132
+ } else {
133
+ const color = glyph.color;
134
+ if (color !== prevColor) {
135
+ prevColor = color;
136
+ pc0 = byte(color[0]);
137
+ pc1 = byte(color[1]);
138
+ pc2 = byte(color[2]);
139
+ pc3 = byte(color[3]);
140
+ }
141
+ writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, rect);
142
+ }
143
+ }
115
144
  drawable++;
116
145
  if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
117
146
  if (glyph.z < minZ) minZ = glyph.z;
118
147
  if (glyph.z > maxZ) maxZ = glyph.z;
119
148
  }
120
149
  return {
150
+ instances: instance,
121
151
  maxSequence,
122
152
  minZ,
123
153
  maxZ
@@ -126,67 +156,104 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals) {
126
156
  /** Ordinary outlines retain the original six instance attributes. */
127
157
  function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered = false, ordinals) {
128
158
  layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin);
129
- const { instances: count, drawable } = countLayout(snapshot, glyphs, layered);
130
159
  const meta = metaSize(snapshot);
131
- const mutable = {
132
- rects: new Float32Array(count * 4),
133
- clips: new Float32Array(count * 4),
134
- colors: new Uint8Array(count * 4),
135
- metadata: new Float32Array(count * meta),
160
+ let count;
161
+ let rects;
162
+ let clips;
163
+ let colors;
164
+ let metadata;
165
+ let bounds;
166
+ let bands;
167
+ let layers;
168
+ let glyphRects;
169
+ if (layered) {
170
+ const counted = countLayout(snapshot, glyphs, true);
171
+ count = counted.instances;
172
+ rects = new Float32Array(count * 4);
173
+ clips = new Float32Array(count * 4);
174
+ colors = new Uint8Array(count * 4);
175
+ metadata = new Float32Array(count * meta);
176
+ bounds = new Float32Array(count * 4);
177
+ bands = new Float32Array(count * 4);
178
+ layers = new Float32Array(count * 4);
179
+ glyphRects = new Float32Array(counted.drawable * 4);
180
+ } else {
181
+ const total = snapshot.glyphs.length;
182
+ count = total;
183
+ rects = new Float32Array(total * 4);
184
+ clips = new Float32Array(total * 4);
185
+ colors = new Uint8Array(total * 4);
186
+ metadata = new Float32Array(total * meta);
187
+ bounds = new Float32Array(total * 4);
188
+ bands = new Float32Array(total * 4);
189
+ }
190
+ const result = writeGeometry(snapshot, glyphs, {
191
+ rects,
192
+ clips,
193
+ colors,
194
+ metadata,
136
195
  metaSize: meta,
137
- bounds: new Float32Array(count * 4),
138
- bands: new Float32Array(count * 4),
139
- ...layered ? {
140
- layers: new Float32Array(count * 4),
141
- glyphRects: new Float32Array(drawable * 4)
196
+ bounds,
197
+ bands,
198
+ ...layers && glyphRects ? {
199
+ layers,
200
+ glyphRects
142
201
  } : {}
143
- };
144
- const result = writeGeometry(snapshot, glyphs, mutable, ordinals);
202
+ }, ordinals);
203
+ if (!layered && result.instances < count) {
204
+ count = result.instances;
205
+ rects = rects.subarray(0, count * 4);
206
+ clips = clips.subarray(0, count * 4);
207
+ colors = colors.subarray(0, count * 4);
208
+ metadata = metadata.subarray(0, count * meta);
209
+ bounds = bounds.subarray(0, count * 4);
210
+ bands = bands.subarray(0, count * 4);
211
+ }
145
212
  const geometry = new InstancedBufferGeometry();
146
213
  geometry.name = "ultra-text instanced Windfoil glyph quads";
147
214
  setUnitQuad(geometry);
148
215
  for (const [name, data, size, normalized] of [
149
216
  [
150
217
  "sdfRect",
151
- mutable.rects,
218
+ rects,
152
219
  4,
153
220
  false
154
221
  ],
155
222
  [
156
223
  "sdfClip",
157
- mutable.clips,
224
+ clips,
158
225
  4,
159
226
  false
160
227
  ],
161
228
  [
162
229
  "sdfColor",
163
- mutable.colors,
230
+ colors,
164
231
  4,
165
232
  true
166
233
  ],
167
234
  [
168
235
  "sdfMeta",
169
- mutable.metadata,
236
+ metadata,
170
237
  meta,
171
238
  false
172
239
  ],
173
240
  [
174
241
  "windfoilBounds",
175
- mutable.bounds,
242
+ bounds,
176
243
  4,
177
244
  false
178
245
  ],
179
246
  [
180
247
  "windfoilBand",
181
- mutable.bands,
248
+ bands,
182
249
  4,
183
250
  false
184
251
  ]
185
252
  ]) geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized));
186
- if (mutable.layers) {
187
- geometry.setAttribute("windfoilLayer", new InstancedBufferAttribute(mutable.layers, 4));
188
- geometry.userData[GLYPH_RECTS_KEY] = mutable.glyphRects;
189
- geometry.userData["ultraOwnGlyphRects"] = mutable.glyphRects;
253
+ if (layers) {
254
+ geometry.setAttribute("windfoilLayer", new InstancedBufferAttribute(layers, 4));
255
+ geometry.userData[GLYPH_RECTS_KEY] = glyphRects;
256
+ geometry.userData["ultraOwnGlyphRects"] = glyphRects;
190
257
  }
191
258
  geometry.instanceCount = count;
192
259
  setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
@@ -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\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 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 paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n const colors = attributes.colors\n colors[offset] = byte(rgb[0])\n colors[offset + 1] = byte(rgb[1])\n colors[offset + 2] = byte(rgb[2])\n colors[offset + 3] = byte(glyph.color[3] * (paint ? paint.rgba[3] : 1))\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 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\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): { maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n const glyphList = snapshot.glyphs\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n const header = glyphs.get(glyph.glyphKey)\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 writeLayerInstance(\n glyph,\n header,\n header.layers?.[0] ?? header,\n instance++,\n ordinal,\n attributes,\n rect,\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 { 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 { instances: count, drawable } = countLayout(snapshot, glyphs, layered)\n const meta = metaSize(snapshot)\n const mutable: MutableWindfoilAttributes = {\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 metaSize: meta,\n bounds: new Float32Array(count * 4),\n bands: new Float32Array(count * 4),\n ...(layered\n ? {\n layers: new Float32Array(count * 4),\n glyphRects: new Float32Array(drawable * 4),\n }\n : {}),\n }\n const result = writeGeometry(snapshot, glyphs, mutable, ordinals)\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', mutable.rects, 4, false],\n ['sdfClip', mutable.clips, 4, false],\n ['sdfColor', mutable.colors, 4, true],\n ['sdfMeta', mutable.metadata, meta, false],\n ['windfoilBounds', mutable.bounds, 4, false],\n ['windfoilBand', mutable.bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (mutable.layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(mutable.layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = mutable.glyphRects\n geometry.userData['ultraOwnGlyphRects'] = mutable.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,WAAW,KAAK,KAAK;CAC9B,OAAO;AACT;AAEA,SAAgB,kBACd,OACA,QACA,OAA4B,OAAO,MACQ;CAC3C,OAAO,sBAAsB,OAAO,QAAQ,MAAM;EAAC;EAAG;EAAG;EAAG;CAAC,CAAC;AAChE;;AAGA,SAAgB,mBACd,OACA,QACA,OACA,OACA,SACA,YACA,WACM;CACN,MAAM,SAAS,QAAQ;CACvB,MAAM,QAAQ,MAAM,WAAW,OAAO;CACtC,MAAM,WAAW,MAAM,cAAc,MAAM,kBAAkB,CAAC,OAAO,UAAU;CAC/E,MAAM,KAAK,MAAM;CACjB,MAAM,OAAO,MAAM;CACnB,MAAM,KAAK,KAAK,IACd,KAAK,KAAK,IACV,KAAK,KA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tB,QAAQ,SAAS,aAAa,UAAU,CAAC,CAAC;EAC1C,UAAU,MAAM,SAAS;EACzB,UAAU,SAAS,aAAa,SAAS,CAAC,CAAC;EAC3C,QAAQ,MAAM,gBAAgB;EAC9B,OAAO,MAAM,cAAc;EAC3B,GAAI,QACA;GACE,QAAQ,MAAM;GACd,YAAY,SAAS,SAAS;EAChC,IACA,CAAC;CACP,GACA,QACF;CACA,KAAK,MAAM,QAAQ,QAAQ,qBAAqB,YAC9C,SAAU,aAAa,IAAI,CAAC,CAA8B,cAAc;CAC1E,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
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,WAAW,KAAK,KAAK;CAC9B,OAAO;AACT;AAEA,SAAgB,kBACd,OACA,QACA,OAA4B,OAAO,MACQ;CAC3C,OAAO,sBAAsB,OAAO,QAAQ,MAAM;EAAC;EAAG;EAAG;EAAG;CAAC,CAAC;AAChE;AAEA,SA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AAW;CACb,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,MAAM,SAAS,OAAO,IAAI,MAAM,QAAQ;EACxC,MAAM,SAAS,QAAQ,QAAQ,UAAU;EACzC,IAAI,CAAC,YAAY,MAAM,gBAAgB,SAAS,IAAI,OAAO;EAC3D,IAAI,QAAQ,oBAAoB;GAC9B;GACA,aAAa,UAAU,SAAS;EAClC;CACF;CACA,OACE,cAAc,SAAS,kBACtB,CAAC,WACC,SAAS,SAAS,qBAAqB,EAA+B,WACrE,WAAW;AAEnB;AAEA,SAAgB,4BACd,UACA,UACA,QACA,eACA,UACe;CACf,IAAI,CAAC,oBAAoB,UAAU,UAAU,MAAM,GAAG,OAAO;CAC7D,MAAM,SAAS,SAA+B,SAAS,aAAa,IAAI,CAAC,CAAC;CAC1E,MAAM,QAAQ,SAAS,aAAa,eAAe;CACnD,MAAM,SAAS,cACb,UACA,QACA;EACE,OAAO,MAAM,SAAS;EACtB,OAAO,MAAM,SAAS;EACtB,QAAQ,SAAS,aAAa,UAAU,CAAC,CAAC;EAC1C,UAAU,MAAM,SAAS;EACzB,UAAU,SAAS,aAAa,SAAS,CAAC,CAAC;EAC3C,QAAQ,MAAM,gBAAgB;EAC9B,OAAO,MAAM,cAAc;EAC3B,GAAI,QACA;GACE,QAAQ,MAAM;GACd,YAAY,SAAS,SAAS;EAChC,IACA,CAAC;CACP,GACA,QACF;CACA,KAAK,MAAM,QAAQ,QAAQ,qBAAqB,YAC9C,SAAU,aAAa,IAAI,CAAC,CAA8B,cAAc;CAC1E,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
@@ -1,4 +1,4 @@
1
- import { throwIfAborted } from "./storage.js";
1
+ import { throwIfAborted } from "./abortable.js";
2
2
  import { windfoilCompositeBox } from "./compositeGeometry.js";
3
3
  import { floatBits } from "./paint.js";
4
4
  /** List-entry flag: the layer covers the whole cell, so its coverage is exactly 1. */
@@ -89,6 +89,7 @@ var gridBandGen = 0;
89
89
  var scratchBandLow = /* @__PURE__ */ new Float64Array(64);
90
90
  var scratchBandHeight = /* @__PURE__ */ new Float64Array(64);
91
91
  var poolPieceC = /* @__PURE__ */ new Int32Array(0);
92
+ var poolPieceMid = /* @__PURE__ */ new Int32Array(0);
92
93
  var poolPieceBounds = /* @__PURE__ */ new Float64Array(0);
93
94
  var poolPieceLow = /* @__PURE__ */ new Float64Array(0);
94
95
  var poolBandPrepared = /* @__PURE__ */ new Int32Array(0);
@@ -225,10 +226,10 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
225
226
  scratchBandLow = new Float64Array(capLen);
226
227
  scratchBandHeight = new Float64Array(capLen);
227
228
  }
228
- const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, boundsArr = poolPieceBounds, shortLow = poolPieceLow;
229
+ const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start * 6, q2FloatBase = bandFloatBase + pieceCount * 4;
229
230
  let bottom = Infinity, top = -Infinity, activeCount = 0;
230
231
  for (let k = 0; k < pieceCount; k++) {
231
- const c = (start + k) * 6, y0 = curves[c + 1], y1 = curves[c + 5], lo = y0 < y1 ? y0 : y1, hi = y0 < y1 ? y1 : y0, h = hi - lo;
232
+ 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;
232
233
  lowScratch[k] = lo;
233
234
  heightScratch[k] = h;
234
235
  if (h !== 0) activeCount++;
@@ -268,8 +269,9 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
268
269
  sortByLow(cArr, shortBase, activeEnd, lowScratch);
269
270
  }
270
271
  for (let i = start; i < activeEnd; i++) {
271
- const c = (start + cArr[i]) * 6, px0 = curves[c], py0 = curves[c + 1], px1 = curves[c + 2], px2 = curves[c + 4], py2 = curves[c + 5], up = py2 > py0, lo = up ? py0 : py2, i4 = i * 4;
272
- cArr[i] = up ? c : ~c;
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
+ cArr[i] = up ? pair : ~pair;
274
+ midArr[i] = mid;
273
275
  shortLow[i] = lo;
274
276
  boundsArr[i4] = lo;
275
277
  boundsArr[i4 + 1] = up ? py2 : py0;
@@ -289,7 +291,7 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
289
291
  const bx0 = poolLayerBx0[layer], by0 = poolLayerBy0[layer], bx1 = poolLayerBx1[layer], by1Cap = poolLayerBy1Cap[layer];
290
292
  if (ey1Tol < by0 || ey0Tol > by1Cap || ex1Tol < bx0 || ex0Tol > bx1) return 0;
291
293
  const bands = poolLayerBands[layer], bandH = poolLayerBandH[layer], rowBase = poolLayerRowBase[layer], tol = gridTol, bandGen = gridBandGen, low = bands > 1 ? ey0Tol <= by0 ? 0 : Math.min(bands, Math.floor((ey0Tol - by0) / bandH)) : 0, high = bands > 1 ? ey1Tol >= by1Cap ? bands - 1 : Math.min(bands - 1, Math.floor((ey1Tol - by0) / bandH)) : 0, insideBox = bx0 < ex0Tol && bx1 > ex1Tol && by0 < ey0Tol && by1Cap > ey1Tol;
292
- const cArr = poolPieceC, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandPrepared = poolBandPrepared, bandTallEnd = poolBandTallEnd, bandActiveEnd = poolBandActiveEnd, bandTallest = poolBandTallest, curves = gridCurves, rows = gridRows, rowFloats = gridRowFloats;
294
+ const cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandPrepared = poolBandPrepared, bandTallEnd = poolBandTallEnd, bandActiveEnd = poolBandActiveEnd, bandTallest = poolBandTallest, curves = gridCurves, rows = gridRows, rowFloats = gridRowFloats;
293
295
  let winding = UNSET;
294
296
  for (let band = low; band <= high; band++) {
295
297
  const s0 = bands > 1 ? Math.max(ey0, by0 + band * bandH - tol) : ey0, s1 = bands > 1 ? Math.min(ey1, by0 + (band + 1) * bandH + tol) : ey1;
@@ -321,24 +323,24 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
321
323
  let xh = boundsArr[k4 + 3];
322
324
  if (xh >= ex0Tol) {
323
325
  if (yl >= s0 && yh <= s1) return 1;
324
- const c = cs < 0 ? ~cs : cs, px0 = curves[c], px2 = curves[c + 4];
326
+ const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2];
325
327
  let a;
326
328
  if (yl >= s0) {
327
329
  a = sign > 0 ? px0 : px2;
328
330
  if (a >= ex0Tol && a <= ex1Tol) return 1;
329
- const b = at(px0, curves[c + 2], px2, solve(curves[c + 1], curves[c + 3], curves[c + 5], s1));
331
+ const b = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s1));
330
332
  xl = a < b ? a : b;
331
333
  xh = a < b ? b : a;
332
334
  if (xh >= ex0Tol && xl <= ex1Tol) return 1;
333
335
  } else if (yh <= s1) {
334
336
  const b = sign > 0 ? px2 : px0;
335
337
  if (b >= ex0Tol && b <= ex1Tol) return 1;
336
- a = at(px0, curves[c + 2], px2, solve(curves[c + 1], curves[c + 3], curves[c + 5], s0));
338
+ a = at(px0, curves[mid], px2, solve(curves[pair + 1], curves[mid + 1], curves[pair + 3], s0));
337
339
  xl = a < b ? a : b;
338
340
  xh = a < b ? b : a;
339
341
  if (xh >= ex0Tol && xl <= ex1Tol) return 1;
340
342
  } else {
341
- const px1 = curves[c + 2], py0 = curves[c + 1], py1 = curves[c + 3], py2 = curves[c + 5];
343
+ const px1 = curves[mid], py0 = curves[pair + 1], py1 = curves[mid + 1], py2 = curves[pair + 3];
342
344
  a = at(px0, px1, px2, solve(py0, py1, py2, s0));
343
345
  if (a >= ex0Tol && a <= ex1Tol) return 1;
344
346
  const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
@@ -491,6 +493,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
491
493
  if (poolPieceC.length < totalPieces) {
492
494
  const cap = Math.max(poolPieceC.length * 2, totalPieces);
493
495
  poolPieceC = new Int32Array(cap);
496
+ poolPieceMid = new Int32Array(cap);
494
497
  poolPieceBounds = new Float64Array(cap * 4);
495
498
  poolPieceLow = new Float64Array(cap);
496
499
  }
@@ -658,6 +661,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
658
661
  result.set(poolOut.subarray(0, used), table.length);
659
662
  if (poolPieceC.length > 262144) {
660
663
  poolPieceC = /* @__PURE__ */ new Int32Array(0);
664
+ poolPieceMid = /* @__PURE__ */ new Int32Array(0);
661
665
  poolPieceBounds = /* @__PURE__ */ new Float64Array(0);
662
666
  poolPieceLow = /* @__PURE__ */ new Float64Array(0);
663
667
  }