ultra-text 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (200) hide show
  1. package/README.md +267 -962
  2. package/THIRD_PARTY_NOTICES.md +3 -0
  3. package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
  4. package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
  5. package/dist/atlas/appendAtlas.js +69 -26
  6. package/dist/atlas/appendAtlas.js.map +1 -1
  7. package/dist/atlas/buildAtlas.js +5 -15
  8. package/dist/atlas/buildAtlas.js.map +1 -1
  9. package/dist/atlas/cpuAtlas.d.ts +4 -1
  10. package/dist/atlas/cpuAtlas.js +8 -6
  11. package/dist/atlas/cpuAtlas.js.map +1 -1
  12. package/dist/atlas/cpuSdf.js +164 -50
  13. package/dist/atlas/cpuSdf.js.map +1 -1
  14. package/dist/atlas/cpuWorker.d.ts +5 -3
  15. package/dist/atlas/cpuWorker.js +119 -12
  16. package/dist/atlas/cpuWorker.js.map +1 -1
  17. package/dist/atlas/gpuAtlas.d.ts +7 -6
  18. package/dist/atlas/gpuAtlas.js +206 -247
  19. package/dist/atlas/gpuAtlas.js.map +1 -1
  20. package/dist/atlas/gpuCommon.d.ts +135 -0
  21. package/dist/atlas/gpuCommon.js +223 -0
  22. package/dist/atlas/gpuCommon.js.map +1 -0
  23. package/dist/atlas/jfaWgsl.js +59 -125
  24. package/dist/atlas/jfaWgsl.js.map +1 -1
  25. package/dist/atlas/rasterize.d.ts +2 -0
  26. package/dist/atlas/rasterize.js +104 -144
  27. package/dist/atlas/rasterize.js.map +1 -1
  28. package/dist/atlas/shapeRaster.js +2 -1
  29. package/dist/atlas/shapeRaster.js.map +1 -1
  30. package/dist/atlas/vanillaBounds.d.ts +64 -0
  31. package/dist/atlas/vanillaBounds.js +42 -0
  32. package/dist/atlas/vanillaBounds.js.map +1 -0
  33. package/dist/atlas/vanillaCore.d.ts +100 -0
  34. package/dist/atlas/vanillaCore.js +1012 -0
  35. package/dist/atlas/vanillaCore.js.map +1 -0
  36. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  37. package/dist/atlas/vanillaCpuAtlas.js +87 -0
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  39. package/dist/atlas/vanillaExtras.d.ts +8 -0
  40. package/dist/atlas/vanillaExtras.js +166 -0
  41. package/dist/atlas/vanillaExtras.js.map +1 -0
  42. package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
  43. package/dist/atlas/vanillaGpuHelpers.js +119 -0
  44. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  45. package/dist/dom/DomSdf.js +263 -272
  46. package/dist/dom/DomSdf.js.map +1 -1
  47. package/dist/dom/DomSlug.d.ts +26 -0
  48. package/dist/dom/DomSlug.js +564 -0
  49. package/dist/dom/DomSlug.js.map +1 -0
  50. package/dist/dom/SlugText.d.ts +18 -0
  51. package/dist/dom/SlugText.js +94 -0
  52. package/dist/dom/SlugText.js.map +1 -0
  53. package/dist/dom/Text.js +4 -67
  54. package/dist/dom/Text.js.map +1 -1
  55. package/dist/dom/domAnalytic.d.ts +54 -0
  56. package/dist/dom/domAnalytic.js +282 -0
  57. package/dist/dom/domAnalytic.js.map +1 -0
  58. package/dist/dom/domExtras.d.ts +27 -0
  59. package/dist/dom/domExtras.js +137 -0
  60. package/dist/dom/domExtras.js.map +1 -0
  61. package/dist/dom/fontCanvas.d.ts +2 -0
  62. package/dist/dom/fontCanvas.js +119 -0
  63. package/dist/dom/fontCanvas.js.map +1 -0
  64. package/dist/dom/layoutSignature.js +156 -27
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/pretextLayout.js +55 -13
  67. package/dist/dom/pretextLayout.js.map +1 -1
  68. package/dist/dom/snapshot.js +563 -243
  69. package/dist/dom/snapshot.js.map +1 -1
  70. package/dist/dom/svgCapture.d.ts +8 -1
  71. package/dist/dom/svgCapture.js +75 -1
  72. package/dist/dom/svgCapture.js.map +1 -1
  73. package/dist/dom/textHost.d.ts +11 -0
  74. package/dist/dom/textHost.js +68 -0
  75. package/dist/dom/textHost.js.map +1 -0
  76. package/dist/dom/tone.js +76 -36
  77. package/dist/dom/tone.js.map +1 -1
  78. package/dist/index.js +4 -3
  79. package/dist/slug/SlugMaterial.d.ts +13 -4
  80. package/dist/slug/SlugMaterial.js +82 -12
  81. package/dist/slug/SlugMaterial.js.map +1 -1
  82. package/dist/slug/coverage.d.ts +17 -13
  83. package/dist/slug/coverage.js +195 -222
  84. package/dist/slug/coverage.js.map +1 -1
  85. package/dist/slug/preprocessCore.d.ts +6 -3
  86. package/dist/slug/preprocessCore.js +149 -95
  87. package/dist/slug/preprocessCore.js.map +1 -1
  88. package/dist/slug/runtime.d.ts +1 -0
  89. package/dist/slug/runtime.js +94 -46
  90. package/dist/slug/runtime.js.map +1 -1
  91. package/dist/slug/standaloneRuntime.d.ts +40 -0
  92. package/dist/slug/standaloneRuntime.js +175 -0
  93. package/dist/slug/standaloneRuntime.js.map +1 -0
  94. package/dist/slug/truetype.d.ts +22 -0
  95. package/dist/slug/truetype.js +467 -0
  96. package/dist/slug/truetype.js.map +1 -0
  97. package/dist/slug/vanillaCore.d.ts +340 -0
  98. package/dist/slug/vanillaCore.js +1621 -0
  99. package/dist/slug/vanillaCore.js.map +1 -0
  100. package/dist/slug-vanilla.d.ts +13 -0
  101. package/dist/slug-vanilla.js +13 -0
  102. package/dist/slug.d.ts +21 -0
  103. package/dist/slug.js +19 -0
  104. package/dist/text/GlyphTextMaterial.d.ts +11 -11
  105. package/dist/text/GlyphTextMaterial.js +102 -33
  106. package/dist/text/GlyphTextMaterial.js.map +1 -1
  107. package/dist/text/SdfTextMaterial.d.ts +5 -4
  108. package/dist/text/SdfTextMaterial.js +29 -9
  109. package/dist/text/SdfTextMaterial.js.map +1 -1
  110. package/dist/text/decorations.js +36 -19
  111. package/dist/text/decorations.js.map +1 -1
  112. package/dist/text/geometry.d.ts +3 -22
  113. package/dist/text/geometryUtils.d.ts +11 -1
  114. package/dist/text/geometryUtils.js +22 -1
  115. package/dist/text/geometryUtils.js.map +1 -1
  116. package/dist/text/glyphGeometry.d.ts +9 -0
  117. package/dist/text/glyphGeometry.js +353 -0
  118. package/dist/text/glyphGeometry.js.map +1 -0
  119. package/dist/text/index.d.ts +2 -1
  120. package/dist/text/rectGeometry.d.ts +13 -0
  121. package/dist/text/rectGeometry.js +97 -0
  122. package/dist/text/rectGeometry.js.map +1 -0
  123. package/dist/text/reflow.d.ts +18 -1
  124. package/dist/text/reflow.js +108 -38
  125. package/dist/text/reflow.js.map +1 -1
  126. package/dist/text/snap.d.ts +1 -0
  127. package/dist/text/snap.js +26 -0
  128. package/dist/text/snap.js.map +1 -0
  129. package/dist/types.d.ts +63 -14
  130. package/dist/vanilla.d.ts +13 -360
  131. package/dist/vanilla.js +8 -1402
  132. package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
  133. package/dist/windfoil/WindfoilMaterial.js +8 -1
  134. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  135. package/dist/windfoil/abortable.d.ts +2 -0
  136. package/dist/windfoil/abortable.js +26 -0
  137. package/dist/windfoil/abortable.js.map +1 -0
  138. package/dist/windfoil/color.js +2 -1
  139. package/dist/windfoil/color.js.map +1 -1
  140. package/dist/windfoil/coverage.d.ts +3 -20
  141. package/dist/windfoil/coverage.js +7 -20
  142. package/dist/windfoil/coverage.js.map +1 -1
  143. package/dist/windfoil/emoji.js +1 -1
  144. package/dist/windfoil/emoji.js.map +1 -1
  145. package/dist/windfoil/emojiMetrics.js +1 -1
  146. package/dist/windfoil/emojiMetrics.js.map +1 -1
  147. package/dist/windfoil/geometry.d.ts +2 -2
  148. package/dist/windfoil/geometry.js +204 -64
  149. package/dist/windfoil/geometry.js.map +1 -1
  150. package/dist/windfoil/layerGrid.js +14 -10
  151. package/dist/windfoil/layerGrid.js.map +1 -1
  152. package/dist/windfoil/layerNormalization.d.ts +1 -1
  153. package/dist/windfoil/layerNormalization.js +1 -1
  154. package/dist/windfoil/layerNormalization.js.map +1 -1
  155. package/dist/windfoil/mixed.d.ts +1 -0
  156. package/dist/windfoil/mixed.js +44 -25
  157. package/dist/windfoil/mixed.js.map +1 -1
  158. package/dist/windfoil/outlineValidation.d.ts +86 -0
  159. package/dist/windfoil/outlineValidation.js +65 -0
  160. package/dist/windfoil/outlineValidation.js.map +1 -0
  161. package/dist/windfoil/preprocess.js +3 -2
  162. package/dist/windfoil/preprocess.js.map +1 -1
  163. package/dist/windfoil/preprocessCore.d.ts +5 -85
  164. package/dist/windfoil/preprocessCore.js +218 -209
  165. package/dist/windfoil/preprocessCore.js.map +1 -1
  166. package/dist/windfoil/requests.js +1 -1
  167. package/dist/windfoil/requests.js.map +1 -1
  168. package/dist/windfoil/runtime.d.ts +5 -2
  169. package/dist/windfoil/runtime.js +63 -40
  170. package/dist/windfoil/runtime.js.map +1 -1
  171. package/dist/windfoil/shapeResources.js +2 -1
  172. package/dist/windfoil/shapeResources.js.map +1 -1
  173. package/dist/windfoil/shapes.js +1 -1
  174. package/dist/windfoil/skirt.d.ts +22 -0
  175. package/dist/windfoil/skirt.js +20 -0
  176. package/dist/windfoil/skirt.js.map +1 -0
  177. package/dist/windfoil/storage.d.ts +62 -4
  178. package/dist/windfoil/storage.js +143 -28
  179. package/dist/windfoil/storage.js.map +1 -1
  180. package/dist/windfoil/trace/contours.d.ts +3 -3
  181. package/dist/windfoil/trace/contours.js +228 -137
  182. package/dist/windfoil/trace/contours.js.map +1 -1
  183. package/dist/windfoil/trace/fit.d.ts +3 -7
  184. package/dist/windfoil/trace/fit.js +668 -376
  185. package/dist/windfoil/trace/fit.js.map +1 -1
  186. package/dist/windfoil/trace/outline.js +60 -35
  187. package/dist/windfoil/trace/outline.js.map +1 -1
  188. package/dist/windfoil/trace/types.d.ts +15 -3
  189. package/dist/windfoil/tracedOutlines.d.ts +37 -1
  190. package/dist/windfoil/tracedOutlines.js +228 -64
  191. package/dist/windfoil/tracedOutlines.js.map +1 -1
  192. package/package.json +60 -11
  193. package/skills/ultra-text/SKILL.md +114 -0
  194. package/skills/ultra-text/references/frameworks.md +43 -0
  195. package/skills/ultra-text/references/three-tsl.md +78 -0
  196. package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
  197. package/dist/assets/cpuSdf.worker-Du9o8q4p.js.map +0 -1
  198. package/dist/text/geometry.js +0 -348
  199. package/dist/text/geometry.js.map +0 -1
  200. package/dist/vanilla.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { readBox, readFiniteFloat32, readFlatNumbers } from "../windfoil/preprocessCore.js";
1
+ import { readBox, readFiniteFloat32, readFlatNumbers } from "../windfoil/outlineValidation.js";
2
2
  function throwIfAborted(signal) {
3
3
  if (signal?.aborted) throw signal.reason ?? new DOMException("Slug preprocessing was aborted", "AbortError");
4
4
  }
@@ -6,10 +6,6 @@ function chooseBandCount(pieceCount, targetPiecesPerBand) {
6
6
  if (pieceCount <= targetPiecesPerBand) return 1;
7
7
  return Math.min(Math.ceil(pieceCount / targetPiecesPerBand), 32);
8
8
  }
9
- function bandIndex(coord, origin, invSpan, bandCount) {
10
- if (invSpan <= 0) return 0;
11
- return Math.min(Math.max(Math.floor((coord - origin) * invSpan), 0), bandCount - 1);
12
- }
13
9
  function extremumParameter(start, control, end) {
14
10
  const secondDifference = start - 2 * control + end;
15
11
  if (Math.abs(secondDifference) <= 1e-7) return void 0;
@@ -99,7 +95,7 @@ function splitOutline(quadratics, signal) {
99
95
  }
100
96
  return at;
101
97
  }
102
- var bucketCapacity = 256;
98
+ var bucketCapacity = 64;
103
99
  var hBucketData = new Int32Array(32 * bucketCapacity);
104
100
  var vBucketData = new Int32Array(32 * bucketCapacity);
105
101
  var hBucketCounts = /* @__PURE__ */ new Int32Array(32);
@@ -109,8 +105,10 @@ var xMaxScratch = /* @__PURE__ */ new Float32Array(256);
109
105
  var yMinScratch = /* @__PURE__ */ new Float32Array(256);
110
106
  var yMaxScratch = /* @__PURE__ */ new Float32Array(256);
111
107
  var spanFlagsScratch = /* @__PURE__ */ new Uint8Array(256);
108
+ var collinearScratch = /* @__PURE__ */ new Uint8Array(256);
112
109
  var bandClippedScratch = /* @__PURE__ */ new Float32Array(1536);
113
110
  var bandRayMaxScratch = /* @__PURE__ */ new Float32Array(256);
111
+ var bandLinearScratch = /* @__PURE__ */ new Uint8Array(256);
114
112
  var descOrder = /* @__PURE__ */ new Int32Array(256);
115
113
  var scratchCurves = /* @__PURE__ */ new Float32Array(1024);
116
114
  var scratchRows = /* @__PURE__ */ new Uint32Array(256);
@@ -140,21 +138,31 @@ function solveMonotoneT(v0, vc, v1, target) {
140
138
  const q = v0 < v1 ? b - d : b + d;
141
139
  return Math.abs(q) > 1e-12 ? Math.min(Math.max(c / q, 0), 1) : 0;
142
140
  }
143
- function packBandRow(curveStart, count, bandUMin, bandUMax, uMinGlyph, uMaxGlyph, uInvSpan) {
141
+ var SLUG_CURVE_START_LIMIT = 1 << 17;
142
+ var SLUG_CURVE_START_LIMIT_VEC2 = 1 << 18;
143
+ var SLUG_ALL_LINEAR_BIT = 16384;
144
+ var SLUG_LINEAR_EPS = 1e-6;
145
+ function packBandRow(curveStart, count, bandUMin, bandUMax, uMinGlyph, uMaxGlyph, uInvSpan, allLinear, vec4Curves) {
146
+ const shift = vec4Curves ? 15 : 14;
147
+ const limit = vec4Curves ? SLUG_CURVE_START_LIMIT : SLUG_CURVE_START_LIMIT_VEC2;
148
+ if (curveStart >= limit) throw new RangeError(`Slug curve buffer exceeded ${vec4Curves ? 17 : 18}-bit band start limit (${curveStart} >= ${limit})`);
144
149
  const safeCount = count > 63 ? 63 : count;
145
- if (safeCount === 0 || uInvSpan <= 0) return curveStart << 12 | safeCount;
150
+ const linearBit = vec4Curves && allLinear ? SLUG_ALL_LINEAR_BIT : 0;
151
+ if (safeCount === 0 || uInvSpan <= 0) return (curveStart << shift | linearBit | safeCount) >>> 0;
146
152
  const qMin = Math.max(0, Math.min(15, Math.floor((bandUMin - uMinGlyph) * uInvSpan * 16 - .001)));
147
- const qMax = Math.max(0, Math.min(3, Math.floor((uMaxGlyph - bandUMax) * uInvSpan * 4 - .001)));
148
- return curveStart << 12 | qMax << 10 | qMin << 6 | safeCount;
153
+ const qMax = Math.max(0, Math.min(15, Math.floor((uMaxGlyph - bandUMax) * uInvSpan * 16 - .001)));
154
+ return (curveStart << shift | linearBit | qMax << 10 | qMin << 6 | safeCount) >>> 0;
149
155
  }
150
- function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, bandCount, bandOrigin, bandStep, epsOrtho, uMinGlyph, uMaxGlyph, uInvSpan, rotated, packed) {
156
+ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, bandCount, bandOrigin, bandStep, epsOrtho, uMinGlyph, uMaxGlyph, uInvSpan, rotated, vec4Curves, packed) {
151
157
  let bandedPieces = 0;
152
158
  const rows = ensureSlugRowCapacity(packed.rowLen + bandCount, packed.rowLen);
159
+ const startShift = vec4Curves ? 15 : 14;
160
+ const startLimit = vec4Curves ? SLUG_CURVE_START_LIMIT : SLUG_CURVE_START_LIMIT_VEC2;
153
161
  for (let band = 0; band < bandCount; band++) {
154
162
  const count = bucketCounts[band];
155
- const curveStart = packed.curveLen >>> 1;
163
+ const curveStart = (vec4Curves ? packed.curveLen >>> 2 : packed.curveLen >>> 1) + packed.curveStartOffset;
156
164
  if (count === 0) {
157
- rows[packed.rowLen++] = curveStart << 12;
165
+ rows[packed.rowLen++] = curveStart >= startLimit ? 0 : curveStart << startShift >>> 0;
158
166
  continue;
159
167
  }
160
168
  if (bandRayMaxScratch.length < count) {
@@ -162,6 +170,7 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
162
170
  while (size < count) size *= 2;
163
171
  bandRayMaxScratch = new Float32Array(size);
164
172
  bandClippedScratch = new Float32Array(size * 6);
173
+ bandLinearScratch = new Uint8Array(size);
165
174
  descOrder = new Int32Array(size);
166
175
  }
167
176
  const vLo = bandOrigin + band * bandStep - epsOrtho;
@@ -169,7 +178,8 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
169
178
  const bucketBase = band * bucketStride;
170
179
  let bandUMin = Infinity;
171
180
  for (let i = 0; i < count; i++) {
172
- const offset = bucketData[bucketBase + i] * 6;
181
+ const pieceIdx = bucketData[bucketBase + i];
182
+ const offset = pieceIdx * 6;
173
183
  const u0 = rotated ? pieces[offset + 1] : pieces[offset];
174
184
  const v0 = rotated ? -pieces[offset] : pieces[offset + 1];
175
185
  const uc = rotated ? pieces[offset + 3] : pieces[offset + 2];
@@ -177,19 +187,38 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
177
187
  const u1 = rotated ? pieces[offset + 5] : pieces[offset + 4];
178
188
  const v1 = rotated ? -pieces[offset + 4] : pieces[offset + 5];
179
189
  let q0u = u0, q0v = v0, q1u = uc, q1v = vc, q2u = u1, q2v = v1;
180
- if (bandCount > 1 && bandStep > 0 && !(u0 === u1 && u0 === uc)) {
190
+ if (bandCount > 1 && bandStep > 0 && !(u0 === u1 && u0 === uc) && ((v0 < v1 ? v0 : v1) < vLo || (v0 < v1 ? v1 : v0) > vHi)) {
181
191
  const rising = v0 < v1;
182
- const ta = rising ? v0 < vLo ? solveMonotoneT(v0, vc, v1, vLo) : 0 : v0 > vHi ? solveMonotoneT(v0, vc, v1, vHi) : 0;
183
- const tb = rising ? v1 > vHi ? solveMonotoneT(v0, vc, v1, vHi) : 1 : v1 < vLo ? solveMonotoneT(v0, vc, v1, vLo) : 1;
192
+ const collinear = collinearScratch[pieceIdx] === 1;
193
+ let ta;
194
+ let tb;
195
+ if (collinear && v1 !== v0) {
196
+ const invDv = 1 / (v1 - v0);
197
+ ta = rising ? v0 < vLo ? Math.min(Math.max((vLo - v0) * invDv, 0), 1) : 0 : v0 > vHi ? Math.min(Math.max((vHi - v0) * invDv, 0), 1) : 0;
198
+ tb = rising ? v1 > vHi ? Math.min(Math.max((vHi - v0) * invDv, 0), 1) : 1 : v1 < vLo ? Math.min(Math.max((vLo - v0) * invDv, 0), 1) : 1;
199
+ } else {
200
+ ta = rising ? v0 < vLo ? solveMonotoneT(v0, vc, v1, vLo) : 0 : v0 > vHi ? solveMonotoneT(v0, vc, v1, vHi) : 0;
201
+ tb = rising ? v1 > vHi ? solveMonotoneT(v0, vc, v1, vHi) : 1 : v1 < vLo ? solveMonotoneT(v0, vc, v1, vLo) : 1;
202
+ }
184
203
  if ((ta > 0 || tb < 1) && tb > ta) {
185
- const ua = 1 - ta;
186
- const ub = 1 - tb;
187
- q0u = ua * ua * u0 + 2 * ua * ta * uc + ta * ta * u1;
188
- q0v = ta === 0 ? v0 : rising ? vLo : vHi;
189
- q2u = ub * ub * u0 + 2 * ub * tb * uc + tb * tb * u1;
190
- q2v = tb === 1 ? v1 : rising ? vHi : vLo;
191
- q1u = ua * ub * u0 + (ua * tb + ta * ub) * uc + ta * tb * u1;
192
- q1v = ua * ub * v0 + (ua * tb + ta * ub) * vc + ta * tb * v1;
204
+ if (collinear) {
205
+ const du = u1 - u0;
206
+ q0u = Math.fround(u0 + du * ta);
207
+ q0v = Math.fround(ta === 0 ? v0 : rising ? vLo : vHi);
208
+ q2u = Math.fround(u0 + du * tb);
209
+ q2v = Math.fround(tb === 1 ? v1 : rising ? vHi : vLo);
210
+ q1u = (q0u + q2u) * .5;
211
+ q1v = (q0v + q2v) * .5;
212
+ } else {
213
+ const ua = 1 - ta;
214
+ const ub = 1 - tb;
215
+ q0u = ua * ua * u0 + 2 * ua * ta * uc + ta * ta * u1;
216
+ q0v = ta === 0 ? v0 : rising ? vLo : vHi;
217
+ q2u = ub * ub * u0 + 2 * ub * tb * uc + tb * tb * u1;
218
+ q2v = tb === 1 ? v1 : rising ? vHi : vLo;
219
+ q1u = ua * ub * u0 + (ua * tb + ta * ub) * uc + ta * tb * u1;
220
+ q1v = ua * ub * v0 + (ua * tb + ta * ub) * vc + ta * tb * v1;
221
+ }
193
222
  }
194
223
  }
195
224
  const pieceUMin = q0u < q2u ? q0u : q2u;
@@ -201,20 +230,7 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
201
230
  if (q1v < pieceVMin) q1v = pieceVMin;
202
231
  else if (q1v > pieceVMax) q1v = pieceVMax;
203
232
  if (pieceUMin < bandUMin) bandUMin = pieceUMin;
204
- if (count === 1) {
205
- const curves = ensureSlugCurveCapacity(packed.curveLen + 6, packed.curveLen);
206
- const w = packed.curveLen;
207
- curves[w] = q0u;
208
- curves[w + 1] = q0v;
209
- curves[w + 2] = q2u;
210
- curves[w + 3] = q2v;
211
- curves[w + 4] = q1u;
212
- curves[w + 5] = q1v;
213
- packed.curveLen = w + 6;
214
- rows[packed.rowLen++] = packBandRow(curveStart, 1, bandUMin, pieceUMax, uMinGlyph, uMaxGlyph, uInvSpan);
215
- bandedPieces += 1;
216
- break;
217
- }
233
+ const isLinear = Math.abs(q0u - 2 * q1u + q2u) <= SLUG_LINEAR_EPS && Math.abs(q0v - 2 * q1v + q2v) <= SLUG_LINEAR_EPS;
218
234
  const outOffset = i * 6;
219
235
  bandClippedScratch[outOffset] = q0u;
220
236
  bandClippedScratch[outOffset + 1] = q0v;
@@ -223,33 +239,9 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
223
239
  bandClippedScratch[outOffset + 4] = q1u;
224
240
  bandClippedScratch[outOffset + 5] = q1v;
225
241
  bandRayMaxScratch[i] = pieceUMax;
242
+ bandLinearScratch[i] = isLinear ? 1 : 0;
226
243
  descOrder[i] = i;
227
244
  }
228
- if (count === 1) continue;
229
- if (count === 2) {
230
- const curves = ensureSlugCurveCapacity(packed.curveLen + 12, packed.curveLen);
231
- const w = packed.curveLen;
232
- const r0 = bandRayMaxScratch[0];
233
- const r1 = bandRayMaxScratch[1];
234
- const firstOff = r0 >= r1 ? 0 : 6;
235
- const secondOff = 6 - firstOff;
236
- curves[w] = bandClippedScratch[firstOff];
237
- curves[w + 1] = bandClippedScratch[firstOff + 1];
238
- curves[w + 2] = bandClippedScratch[firstOff + 2];
239
- curves[w + 3] = bandClippedScratch[firstOff + 3];
240
- curves[w + 4] = bandClippedScratch[secondOff];
241
- curves[w + 5] = bandClippedScratch[secondOff + 1];
242
- curves[w + 6] = bandClippedScratch[secondOff + 2];
243
- curves[w + 7] = bandClippedScratch[secondOff + 3];
244
- curves[w + 8] = bandClippedScratch[firstOff + 4];
245
- curves[w + 9] = bandClippedScratch[firstOff + 5];
246
- curves[w + 10] = bandClippedScratch[secondOff + 4];
247
- curves[w + 11] = bandClippedScratch[secondOff + 5];
248
- packed.curveLen = w + 12;
249
- rows[packed.rowLen++] = packBandRow(curveStart, 2, bandUMin, r0 >= r1 ? r0 : r1, uMinGlyph, uMaxGlyph, uInvSpan);
250
- bandedPieces += 2;
251
- continue;
252
- }
253
245
  for (let i = 1; i < count; i++) {
254
246
  const idx = descOrder[i];
255
247
  const key = bandRayMaxScratch[i];
@@ -263,7 +255,15 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
263
255
  descOrder[j + 1] = idx;
264
256
  }
265
257
  const emitCount = count > 63 ? 63 : count;
266
- const curves = ensureSlugCurveCapacity(packed.curveLen + emitCount * 6, packed.curveLen);
258
+ let allLinear = vec4Curves;
259
+ if (allLinear) {
260
+ for (let i = 0; i < emitCount; i++) if (bandLinearScratch[descOrder[i]] === 0) {
261
+ allLinear = false;
262
+ break;
263
+ }
264
+ }
265
+ const c2Floats = vec4Curves ? allLinear ? 0 : (emitCount + 1 >>> 1) * 4 : emitCount * 2;
266
+ const curves = ensureSlugCurveCapacity(packed.curveLen + emitCount * 4 + c2Floats, packed.curveLen);
267
267
  let curveWrite = packed.curveLen;
268
268
  for (let i = 0; i < emitCount; i++) {
269
269
  const outOffset = descOrder[i] * 6;
@@ -273,25 +273,33 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
273
273
  curves[curveWrite + 3] = bandClippedScratch[outOffset + 3];
274
274
  curveWrite += 4;
275
275
  }
276
- for (let i = 0; i < emitCount; i++) {
277
- const outOffset = descOrder[i] * 6;
278
- curves[curveWrite] = bandClippedScratch[outOffset + 4];
279
- curves[curveWrite + 1] = bandClippedScratch[outOffset + 5];
280
- curveWrite += 2;
276
+ if (!allLinear) {
277
+ for (let i = 0; i < emitCount; i++) {
278
+ const outOffset = descOrder[i] * 6;
279
+ curves[curveWrite] = bandClippedScratch[outOffset + 4];
280
+ curves[curveWrite + 1] = bandClippedScratch[outOffset + 5];
281
+ curveWrite += 2;
282
+ }
283
+ if (vec4Curves && (emitCount & 1) !== 0) {
284
+ curves[curveWrite] = 0;
285
+ curves[curveWrite + 1] = 0;
286
+ curveWrite += 2;
287
+ }
281
288
  }
282
289
  packed.curveLen = curveWrite;
283
- rows[packed.rowLen++] = packBandRow(curveStart, emitCount, bandUMin, bandRayMaxScratch[0], uMinGlyph, uMaxGlyph, uInvSpan);
290
+ rows[packed.rowLen++] = packBandRow(curveStart, emitCount, bandUMin, bandRayMaxScratch[0], uMinGlyph, uMaxGlyph, uInvSpan, allLinear, vec4Curves);
284
291
  bandedPieces += emitCount;
285
292
  }
286
293
  return bandedPieces;
287
294
  }
288
- function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
295
+ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, vec4Curves, packed, signal) {
289
296
  const pieceLen = splitOutline(quadratics, signal);
290
297
  const pieces = scratchPieces;
291
298
  const monotonePieceCount = pieceLen / 6;
292
299
  const rowBase = packed.rowLen;
293
300
  if (monotonePieceCount === 0) {
294
- const emptyRow = packed.curveLen >>> 1 << 12;
301
+ const emptyStart = (vec4Curves ? packed.curveLen >>> 2 : packed.curveLen >>> 1) + packed.curveStartOffset;
302
+ const emptyRow = vec4Curves ? emptyStart >= SLUG_CURVE_START_LIMIT ? 0 : emptyStart << 15 >>> 0 : emptyStart >= SLUG_CURVE_START_LIMIT_VEC2 ? 0 : emptyStart << 14 >>> 0;
295
303
  const rows = ensureSlugRowCapacity(packed.rowLen + 2, packed.rowLen);
296
304
  rows[packed.rowLen++] = emptyRow;
297
305
  rows[packed.rowLen++] = emptyRow;
@@ -313,6 +321,7 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
313
321
  yMinScratch = new Float32Array(size);
314
322
  yMaxScratch = new Float32Array(size);
315
323
  spanFlagsScratch = new Uint8Array(size);
324
+ collinearScratch = new Uint8Array(size);
316
325
  }
317
326
  if (bucketCapacity < monotonePieceCount) {
318
327
  while (bucketCapacity < monotonePieceCount) bucketCapacity *= 2;
@@ -323,11 +332,12 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
323
332
  let vActivePieces = 0;
324
333
  for (let i = 0; i < monotonePieceCount; i++) {
325
334
  const offset = i * 6;
326
- const x0 = pieces[offset], y0 = pieces[offset + 1], x1 = pieces[offset + 4], y1 = pieces[offset + 5];
335
+ const x0 = pieces[offset], y0 = pieces[offset + 1], cx = pieces[offset + 2], cy = pieces[offset + 3], x1 = pieces[offset + 4], y1 = pieces[offset + 5];
327
336
  xMinScratch[i] = x0 < x1 ? x0 : x1;
328
337
  xMaxScratch[i] = x0 > x1 ? x0 : x1;
329
338
  yMinScratch[i] = y0 < y1 ? y0 : y1;
330
339
  yMaxScratch[i] = y0 > y1 ? y0 : y1;
340
+ collinearScratch[i] = Math.abs(x0 - 2 * cx + x1) <= 1e-7 && Math.abs(y0 - 2 * cy + y1) <= 1e-7 ? 1 : 0;
331
341
  const hActive = yMinScratch[i] !== yMaxScratch[i] ? 1 : 0;
332
342
  const vActive = xMinScratch[i] !== xMaxScratch[i] ? 2 : 0;
333
343
  spanFlagsScratch[i] = hActive | vActive;
@@ -348,11 +358,22 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
348
358
  vBucketCounts.fill(0, 0, vBandCount);
349
359
  const rotY0 = -bbox[2];
350
360
  const stride = bucketCapacity;
361
+ const hOrigin = bbox[1];
362
+ const hMax = hBandCount - 1;
363
+ const vMax = vBandCount - 1;
364
+ const hasHInv = invH > 0;
365
+ const hasVInv = invW > 0;
351
366
  for (let i = 0; i < monotonePieceCount; i++) {
352
367
  const flags = spanFlagsScratch[i];
353
368
  if (flags & 1) {
354
- const firstH = hBandCount > 1 ? bandIndex(yMinScratch[i] - epsY, bbox[1], invH, hBandCount) : 0;
355
- const lastH = hBandCount > 1 ? bandIndex(yMaxScratch[i] + epsY, bbox[1], invH, hBandCount) : 0;
369
+ let firstH = 0;
370
+ let lastH = 0;
371
+ if (hBandCount > 1 && hasHInv) {
372
+ const f = Math.floor((yMinScratch[i] - epsY - hOrigin) * invH);
373
+ const l = Math.floor((yMaxScratch[i] + epsY - hOrigin) * invH);
374
+ firstH = f < 0 ? 0 : f > hMax ? hMax : f;
375
+ lastH = l < 0 ? 0 : l > hMax ? hMax : l;
376
+ }
356
377
  for (let band = firstH; band <= lastH; band++) {
357
378
  const idx = hBucketCounts[band];
358
379
  hBucketData[band * stride + idx] = i;
@@ -360,8 +381,14 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
360
381
  }
361
382
  }
362
383
  if (flags & 2) {
363
- const firstV = vBandCount > 1 ? bandIndex(-xMaxScratch[i] - epsX, rotY0, invW, vBandCount) : 0;
364
- const lastV = vBandCount > 1 ? bandIndex(-xMinScratch[i] + epsX, rotY0, invW, vBandCount) : 0;
384
+ let firstV = 0;
385
+ let lastV = 0;
386
+ if (vBandCount > 1 && hasVInv) {
387
+ const f = Math.floor((-xMaxScratch[i] - epsX - rotY0) * invW);
388
+ const l = Math.floor((-xMinScratch[i] + epsX - rotY0) * invW);
389
+ firstV = f < 0 ? 0 : f > vMax ? vMax : f;
390
+ lastV = l < 0 ? 0 : l > vMax ? vMax : l;
391
+ }
365
392
  for (let band = firstV; band <= lastV; band++) {
366
393
  const idx = vBucketCounts[band];
367
394
  vBucketData[band * stride + idx] = i;
@@ -369,8 +396,8 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
369
396
  }
370
397
  }
371
398
  }
372
- const hBanded = emitDirectionalBands(pieces, hBucketData, hBucketCounts, stride, hBandCount, bbox[1], height > 0 ? height / hBandCount : 0, epsY, bbox[0], bbox[2], invSpanX, false, packed);
373
- const vBanded = emitDirectionalBands(pieces, vBucketData, vBucketCounts, stride, vBandCount, rotY0, width > 0 ? width / vBandCount : 0, epsX, bbox[1], bbox[3], invSpanY, true, packed);
399
+ const hBanded = emitDirectionalBands(pieces, hBucketData, hBucketCounts, stride, hBandCount, bbox[1], height > 0 ? height / hBandCount : 0, epsY, bbox[0], bbox[2], invSpanX, false, vec4Curves, packed);
400
+ const vBanded = emitDirectionalBands(pieces, vBucketData, vBucketCounts, stride, vBandCount, rotY0, width > 0 ? width / vBandCount : 0, epsX, bbox[1], bbox[3], invSpanY, true, vec4Curves, packed);
374
401
  return {
375
402
  rowBase,
376
403
  bandCount: hBandCount | vBandCount << 8,
@@ -384,19 +411,25 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
384
411
  function readQuadraticsFast(value, label) {
385
412
  if (value instanceof Float32Array) {
386
413
  let check = 0;
387
- for (const v of value) check += v - v;
388
- if (!Number.isNaN(check)) return value;
389
- } else if (value instanceof Float64Array) {
390
- let check = 0;
391
- for (const raw of value) {
392
- const v = Math.fround(raw);
414
+ const len = value.length;
415
+ let i = 0;
416
+ for (const end = len - 3; i < end; i += 4) {
417
+ const v0 = value[i];
418
+ const v1 = value[i + 1];
419
+ const v2 = value[i + 2];
420
+ const v3 = value[i + 3];
421
+ check += v0 - v0 + (v1 - v1) + (v2 - v2) + (v3 - v3);
422
+ }
423
+ for (; i < len; i++) {
424
+ const v = value[i];
393
425
  check += v - v;
394
426
  }
395
427
  if (!Number.isNaN(check)) return value;
396
- } else if (Array.isArray(value)) {
428
+ } else if (value instanceof Float64Array || Array.isArray(value)) {
397
429
  const list = value;
398
430
  let valid = true;
399
- for (const item of list) {
431
+ for (let i = 0, len = list.length; i < len; i++) {
432
+ const item = list[i];
400
433
  if (typeof item !== "number") {
401
434
  valid = false;
402
435
  break;
@@ -460,6 +493,9 @@ function outlinesEqual(left, right) {
460
493
  * bands with endpoint-first `[p1, p3, p2]` layout and orthogonal degenerate culling.
461
494
  */
462
495
  function preprocessSlugGlyphs(sources, options = {}) {
496
+ return preprocessSlugGlyphsBatch(sources, options, 0, 0);
497
+ }
498
+ function preprocessSlugGlyphsBatch(sources, options = {}, curveFloatOffset = 0, rowUintOffset = 0) {
463
499
  throwIfAborted(options.signal);
464
500
  if (!Array.isArray(sources)) throw new TypeError("sources must be an array of SlugGlyphSource records");
465
501
  const targetPiecesPerBand = options.targetPiecesPerBand === void 0 ? 2 : readFiniteFloat32(options.targetPiecesPerBand, "options.targetPiecesPerBand");
@@ -483,10 +519,28 @@ function preprocessSlugGlyphs(sources, options = {}) {
483
519
  uniqueByKey.set(key, outline);
484
520
  uniqueRaw.set(key, raw.outline);
485
521
  }
522
+ const vec4Curves = options.vec4Curves !== false;
523
+ if (vec4Curves && (curveFloatOffset & 3) !== 0) throw new RangeError("curveFloatOffset must be a multiple of 4 for vec4 Slug curves");
524
+ if (!vec4Curves && (curveFloatOffset & 1) !== 0) throw new RangeError("curveFloatOffset must be a multiple of 2 for vec2 Slug curves");
486
525
  const sortedKeys = [...uniqueByKey.keys()].sort();
526
+ let estimatedQuadFloats = 0;
527
+ let estimatedLayers = 0;
528
+ for (const key of sortedKeys) {
529
+ const outline = uniqueByKey.get(key);
530
+ if (outline.layers !== void 0) {
531
+ estimatedLayers += outline.layers.length;
532
+ for (const layer of outline.layers) estimatedQuadFloats += layer.quadratics.length;
533
+ } else {
534
+ estimatedLayers++;
535
+ estimatedQuadFloats += outline.quadratics.length;
536
+ }
537
+ }
538
+ ensureSlugCurveCapacity(Math.ceil(estimatedQuadFloats * 4.5), 0);
539
+ ensureSlugRowCapacity(estimatedLayers * 16, 0);
487
540
  const packed = {
488
541
  curveLen: 0,
489
- rowLen: 0
542
+ rowLen: 0,
543
+ curveStartOffset: vec4Curves ? curveFloatOffset >>> 2 : curveFloatOffset >>> 1
490
544
  };
491
545
  const glyphs = /* @__PURE__ */ new Map();
492
546
  let totalMonotonePieces = 0;
@@ -502,14 +556,14 @@ function preprocessSlugGlyphs(sources, options = {}) {
502
556
  const layerHeaders = [];
503
557
  let glyphPieces = 0;
504
558
  for (const layer of outline.layers) {
505
- const built = buildSlugBands(layer.quadratics, layer.bbox, targetPiecesPerBand, packed, options.signal);
559
+ const built = buildSlugBands(layer.quadratics, layer.bbox, targetPiecesPerBand, vec4Curves, packed, options.signal);
506
560
  glyphPieces += built.monotonePieceCount;
507
561
  totalMonotonePieces += built.monotonePieceCount;
508
562
  totalBands += built.bandRows;
509
563
  totalBandedPieces += built.bandedPieces;
510
564
  totalPaintLayers++;
511
565
  layerHeaders.push({
512
- rowBase: built.rowBase,
566
+ rowBase: built.rowBase + rowUintOffset,
513
567
  bandCount: built.bandCount,
514
568
  bandH: built.bandH,
515
569
  invH: built.invH,
@@ -523,7 +577,7 @@ function preprocessSlugGlyphs(sources, options = {}) {
523
577
  }
524
578
  const first = layerHeaders[0];
525
579
  glyphs.set(key, {
526
- rowBase: first?.rowBase ?? packed.rowLen,
580
+ rowBase: first?.rowBase ?? packed.rowLen + rowUintOffset,
527
581
  bandCount: first ? 1 : 0,
528
582
  bandH: first?.bandH ?? 0,
529
583
  invH: first?.invH ?? 0,
@@ -537,13 +591,13 @@ function preprocessSlugGlyphs(sources, options = {}) {
537
591
  });
538
592
  continue;
539
593
  }
540
- const built = buildSlugBands(outline.quadratics, outline.bbox, targetPiecesPerBand, packed, options.signal);
594
+ const built = buildSlugBands(outline.quadratics, outline.bbox, targetPiecesPerBand, vec4Curves, packed, options.signal);
541
595
  totalMonotonePieces += built.monotonePieceCount;
542
596
  totalBands += built.bandRows;
543
597
  totalBandedPieces += built.bandedPieces;
544
598
  if (built.monotonePieceCount > 0) totalPaintLayers++;
545
599
  glyphs.set(key, {
546
- rowBase: built.rowBase,
600
+ rowBase: built.rowBase + rowUintOffset,
547
601
  bandCount: built.bandCount,
548
602
  bandH: built.bandH,
549
603
  invH: built.invH,
@@ -570,6 +624,6 @@ function preprocessSlugGlyphs(sources, options = {}) {
570
624
  }
571
625
  };
572
626
  }
573
- export { preprocessSlugGlyphs };
627
+ export { preprocessSlugGlyphs, preprocessSlugGlyphsBatch };
574
628
 
575
629
  //# sourceMappingURL=preprocessCore.js.map