ultra-text 1.0.1 → 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.
- package/README.md +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -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;
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|
|
148
|
-
return curveStart <<
|
|
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 <<
|
|
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
|
|
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,9 +187,9 @@ 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 collinear =
|
|
192
|
+
const collinear = collinearScratch[pieceIdx] === 1;
|
|
183
193
|
let ta;
|
|
184
194
|
let tb;
|
|
185
195
|
if (collinear && v1 !== v0) {
|
|
@@ -197,8 +207,8 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
|
|
|
197
207
|
q0v = Math.fround(ta === 0 ? v0 : rising ? vLo : vHi);
|
|
198
208
|
q2u = Math.fround(u0 + du * tb);
|
|
199
209
|
q2v = Math.fround(tb === 1 ? v1 : rising ? vHi : vLo);
|
|
200
|
-
q1u =
|
|
201
|
-
q1v =
|
|
210
|
+
q1u = (q0u + q2u) * .5;
|
|
211
|
+
q1v = (q0v + q2v) * .5;
|
|
202
212
|
} else {
|
|
203
213
|
const ua = 1 - ta;
|
|
204
214
|
const ub = 1 - tb;
|
|
@@ -220,20 +230,7 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
|
|
|
220
230
|
if (q1v < pieceVMin) q1v = pieceVMin;
|
|
221
231
|
else if (q1v > pieceVMax) q1v = pieceVMax;
|
|
222
232
|
if (pieceUMin < bandUMin) bandUMin = pieceUMin;
|
|
223
|
-
|
|
224
|
-
const curves = ensureSlugCurveCapacity(packed.curveLen + 6, packed.curveLen);
|
|
225
|
-
const w = packed.curveLen;
|
|
226
|
-
curves[w] = q0u;
|
|
227
|
-
curves[w + 1] = q0v;
|
|
228
|
-
curves[w + 2] = q2u;
|
|
229
|
-
curves[w + 3] = q2v;
|
|
230
|
-
curves[w + 4] = q1u;
|
|
231
|
-
curves[w + 5] = q1v;
|
|
232
|
-
packed.curveLen = w + 6;
|
|
233
|
-
rows[packed.rowLen++] = packBandRow(curveStart, 1, bandUMin, pieceUMax, uMinGlyph, uMaxGlyph, uInvSpan);
|
|
234
|
-
bandedPieces += 1;
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
233
|
+
const isLinear = Math.abs(q0u - 2 * q1u + q2u) <= SLUG_LINEAR_EPS && Math.abs(q0v - 2 * q1v + q2v) <= SLUG_LINEAR_EPS;
|
|
237
234
|
const outOffset = i * 6;
|
|
238
235
|
bandClippedScratch[outOffset] = q0u;
|
|
239
236
|
bandClippedScratch[outOffset + 1] = q0v;
|
|
@@ -242,33 +239,9 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
|
|
|
242
239
|
bandClippedScratch[outOffset + 4] = q1u;
|
|
243
240
|
bandClippedScratch[outOffset + 5] = q1v;
|
|
244
241
|
bandRayMaxScratch[i] = pieceUMax;
|
|
242
|
+
bandLinearScratch[i] = isLinear ? 1 : 0;
|
|
245
243
|
descOrder[i] = i;
|
|
246
244
|
}
|
|
247
|
-
if (count === 1) continue;
|
|
248
|
-
if (count === 2) {
|
|
249
|
-
const curves = ensureSlugCurveCapacity(packed.curveLen + 12, packed.curveLen);
|
|
250
|
-
const w = packed.curveLen;
|
|
251
|
-
const r0 = bandRayMaxScratch[0];
|
|
252
|
-
const r1 = bandRayMaxScratch[1];
|
|
253
|
-
const firstOff = r0 >= r1 ? 0 : 6;
|
|
254
|
-
const secondOff = 6 - firstOff;
|
|
255
|
-
curves[w] = bandClippedScratch[firstOff];
|
|
256
|
-
curves[w + 1] = bandClippedScratch[firstOff + 1];
|
|
257
|
-
curves[w + 2] = bandClippedScratch[firstOff + 2];
|
|
258
|
-
curves[w + 3] = bandClippedScratch[firstOff + 3];
|
|
259
|
-
curves[w + 4] = bandClippedScratch[secondOff];
|
|
260
|
-
curves[w + 5] = bandClippedScratch[secondOff + 1];
|
|
261
|
-
curves[w + 6] = bandClippedScratch[secondOff + 2];
|
|
262
|
-
curves[w + 7] = bandClippedScratch[secondOff + 3];
|
|
263
|
-
curves[w + 8] = bandClippedScratch[firstOff + 4];
|
|
264
|
-
curves[w + 9] = bandClippedScratch[firstOff + 5];
|
|
265
|
-
curves[w + 10] = bandClippedScratch[secondOff + 4];
|
|
266
|
-
curves[w + 11] = bandClippedScratch[secondOff + 5];
|
|
267
|
-
packed.curveLen = w + 12;
|
|
268
|
-
rows[packed.rowLen++] = packBandRow(curveStart, 2, bandUMin, r0 >= r1 ? r0 : r1, uMinGlyph, uMaxGlyph, uInvSpan);
|
|
269
|
-
bandedPieces += 2;
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
245
|
for (let i = 1; i < count; i++) {
|
|
273
246
|
const idx = descOrder[i];
|
|
274
247
|
const key = bandRayMaxScratch[i];
|
|
@@ -282,7 +255,15 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
|
|
|
282
255
|
descOrder[j + 1] = idx;
|
|
283
256
|
}
|
|
284
257
|
const emitCount = count > 63 ? 63 : count;
|
|
285
|
-
|
|
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);
|
|
286
267
|
let curveWrite = packed.curveLen;
|
|
287
268
|
for (let i = 0; i < emitCount; i++) {
|
|
288
269
|
const outOffset = descOrder[i] * 6;
|
|
@@ -292,25 +273,33 @@ function emitDirectionalBands(pieces, bucketData, bucketCounts, bucketStride, ba
|
|
|
292
273
|
curves[curveWrite + 3] = bandClippedScratch[outOffset + 3];
|
|
293
274
|
curveWrite += 4;
|
|
294
275
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
+
}
|
|
300
288
|
}
|
|
301
289
|
packed.curveLen = curveWrite;
|
|
302
|
-
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);
|
|
303
291
|
bandedPieces += emitCount;
|
|
304
292
|
}
|
|
305
293
|
return bandedPieces;
|
|
306
294
|
}
|
|
307
|
-
function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
295
|
+
function buildSlugBands(quadratics, bbox, targetPiecesPerBand, vec4Curves, packed, signal) {
|
|
308
296
|
const pieceLen = splitOutline(quadratics, signal);
|
|
309
297
|
const pieces = scratchPieces;
|
|
310
298
|
const monotonePieceCount = pieceLen / 6;
|
|
311
299
|
const rowBase = packed.rowLen;
|
|
312
300
|
if (monotonePieceCount === 0) {
|
|
313
|
-
const
|
|
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;
|
|
314
303
|
const rows = ensureSlugRowCapacity(packed.rowLen + 2, packed.rowLen);
|
|
315
304
|
rows[packed.rowLen++] = emptyRow;
|
|
316
305
|
rows[packed.rowLen++] = emptyRow;
|
|
@@ -332,6 +321,7 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
332
321
|
yMinScratch = new Float32Array(size);
|
|
333
322
|
yMaxScratch = new Float32Array(size);
|
|
334
323
|
spanFlagsScratch = new Uint8Array(size);
|
|
324
|
+
collinearScratch = new Uint8Array(size);
|
|
335
325
|
}
|
|
336
326
|
if (bucketCapacity < monotonePieceCount) {
|
|
337
327
|
while (bucketCapacity < monotonePieceCount) bucketCapacity *= 2;
|
|
@@ -342,11 +332,12 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
342
332
|
let vActivePieces = 0;
|
|
343
333
|
for (let i = 0; i < monotonePieceCount; i++) {
|
|
344
334
|
const offset = i * 6;
|
|
345
|
-
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];
|
|
346
336
|
xMinScratch[i] = x0 < x1 ? x0 : x1;
|
|
347
337
|
xMaxScratch[i] = x0 > x1 ? x0 : x1;
|
|
348
338
|
yMinScratch[i] = y0 < y1 ? y0 : y1;
|
|
349
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;
|
|
350
341
|
const hActive = yMinScratch[i] !== yMaxScratch[i] ? 1 : 0;
|
|
351
342
|
const vActive = xMinScratch[i] !== xMaxScratch[i] ? 2 : 0;
|
|
352
343
|
spanFlagsScratch[i] = hActive | vActive;
|
|
@@ -367,11 +358,22 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
367
358
|
vBucketCounts.fill(0, 0, vBandCount);
|
|
368
359
|
const rotY0 = -bbox[2];
|
|
369
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;
|
|
370
366
|
for (let i = 0; i < monotonePieceCount; i++) {
|
|
371
367
|
const flags = spanFlagsScratch[i];
|
|
372
368
|
if (flags & 1) {
|
|
373
|
-
|
|
374
|
-
|
|
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
|
+
}
|
|
375
377
|
for (let band = firstH; band <= lastH; band++) {
|
|
376
378
|
const idx = hBucketCounts[band];
|
|
377
379
|
hBucketData[band * stride + idx] = i;
|
|
@@ -379,8 +381,14 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
379
381
|
}
|
|
380
382
|
}
|
|
381
383
|
if (flags & 2) {
|
|
382
|
-
|
|
383
|
-
|
|
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
|
+
}
|
|
384
392
|
for (let band = firstV; band <= lastV; band++) {
|
|
385
393
|
const idx = vBucketCounts[band];
|
|
386
394
|
vBucketData[band * stride + idx] = i;
|
|
@@ -388,8 +396,8 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
388
396
|
}
|
|
389
397
|
}
|
|
390
398
|
}
|
|
391
|
-
const hBanded = emitDirectionalBands(pieces, hBucketData, hBucketCounts, stride, hBandCount, bbox[1], height > 0 ? height / hBandCount : 0, epsY, bbox[0], bbox[2], invSpanX, false, packed);
|
|
392
|
-
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);
|
|
393
401
|
return {
|
|
394
402
|
rowBase,
|
|
395
403
|
bandCount: hBandCount | vBandCount << 8,
|
|
@@ -403,19 +411,21 @@ function buildSlugBands(quadratics, bbox, targetPiecesPerBand, packed, signal) {
|
|
|
403
411
|
function readQuadraticsFast(value, label) {
|
|
404
412
|
if (value instanceof Float32Array) {
|
|
405
413
|
let check = 0;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
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);
|
|
409
422
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
let check = 0;
|
|
413
|
-
for (let i = 0, len = value.length; i < len; i++) {
|
|
414
|
-
const v = Math.fround(value[i]);
|
|
423
|
+
for (; i < len; i++) {
|
|
424
|
+
const v = value[i];
|
|
415
425
|
check += v - v;
|
|
416
426
|
}
|
|
417
427
|
if (!Number.isNaN(check)) return value;
|
|
418
|
-
} else if (Array.isArray(value)) {
|
|
428
|
+
} else if (value instanceof Float64Array || Array.isArray(value)) {
|
|
419
429
|
const list = value;
|
|
420
430
|
let valid = true;
|
|
421
431
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
@@ -483,6 +493,9 @@ function outlinesEqual(left, right) {
|
|
|
483
493
|
* bands with endpoint-first `[p1, p3, p2]` layout and orthogonal degenerate culling.
|
|
484
494
|
*/
|
|
485
495
|
function preprocessSlugGlyphs(sources, options = {}) {
|
|
496
|
+
return preprocessSlugGlyphsBatch(sources, options, 0, 0);
|
|
497
|
+
}
|
|
498
|
+
function preprocessSlugGlyphsBatch(sources, options = {}, curveFloatOffset = 0, rowUintOffset = 0) {
|
|
486
499
|
throwIfAborted(options.signal);
|
|
487
500
|
if (!Array.isArray(sources)) throw new TypeError("sources must be an array of SlugGlyphSource records");
|
|
488
501
|
const targetPiecesPerBand = options.targetPiecesPerBand === void 0 ? 2 : readFiniteFloat32(options.targetPiecesPerBand, "options.targetPiecesPerBand");
|
|
@@ -506,10 +519,28 @@ function preprocessSlugGlyphs(sources, options = {}) {
|
|
|
506
519
|
uniqueByKey.set(key, outline);
|
|
507
520
|
uniqueRaw.set(key, raw.outline);
|
|
508
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");
|
|
509
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);
|
|
510
540
|
const packed = {
|
|
511
541
|
curveLen: 0,
|
|
512
|
-
rowLen: 0
|
|
542
|
+
rowLen: 0,
|
|
543
|
+
curveStartOffset: vec4Curves ? curveFloatOffset >>> 2 : curveFloatOffset >>> 1
|
|
513
544
|
};
|
|
514
545
|
const glyphs = /* @__PURE__ */ new Map();
|
|
515
546
|
let totalMonotonePieces = 0;
|
|
@@ -525,14 +556,14 @@ function preprocessSlugGlyphs(sources, options = {}) {
|
|
|
525
556
|
const layerHeaders = [];
|
|
526
557
|
let glyphPieces = 0;
|
|
527
558
|
for (const layer of outline.layers) {
|
|
528
|
-
const built = buildSlugBands(layer.quadratics, layer.bbox, targetPiecesPerBand, packed, options.signal);
|
|
559
|
+
const built = buildSlugBands(layer.quadratics, layer.bbox, targetPiecesPerBand, vec4Curves, packed, options.signal);
|
|
529
560
|
glyphPieces += built.monotonePieceCount;
|
|
530
561
|
totalMonotonePieces += built.monotonePieceCount;
|
|
531
562
|
totalBands += built.bandRows;
|
|
532
563
|
totalBandedPieces += built.bandedPieces;
|
|
533
564
|
totalPaintLayers++;
|
|
534
565
|
layerHeaders.push({
|
|
535
|
-
rowBase: built.rowBase,
|
|
566
|
+
rowBase: built.rowBase + rowUintOffset,
|
|
536
567
|
bandCount: built.bandCount,
|
|
537
568
|
bandH: built.bandH,
|
|
538
569
|
invH: built.invH,
|
|
@@ -546,7 +577,7 @@ function preprocessSlugGlyphs(sources, options = {}) {
|
|
|
546
577
|
}
|
|
547
578
|
const first = layerHeaders[0];
|
|
548
579
|
glyphs.set(key, {
|
|
549
|
-
rowBase: first?.rowBase ?? packed.rowLen,
|
|
580
|
+
rowBase: first?.rowBase ?? packed.rowLen + rowUintOffset,
|
|
550
581
|
bandCount: first ? 1 : 0,
|
|
551
582
|
bandH: first?.bandH ?? 0,
|
|
552
583
|
invH: first?.invH ?? 0,
|
|
@@ -560,13 +591,13 @@ function preprocessSlugGlyphs(sources, options = {}) {
|
|
|
560
591
|
});
|
|
561
592
|
continue;
|
|
562
593
|
}
|
|
563
|
-
const built = buildSlugBands(outline.quadratics, outline.bbox, targetPiecesPerBand, packed, options.signal);
|
|
594
|
+
const built = buildSlugBands(outline.quadratics, outline.bbox, targetPiecesPerBand, vec4Curves, packed, options.signal);
|
|
564
595
|
totalMonotonePieces += built.monotonePieceCount;
|
|
565
596
|
totalBands += built.bandRows;
|
|
566
597
|
totalBandedPieces += built.bandedPieces;
|
|
567
598
|
if (built.monotonePieceCount > 0) totalPaintLayers++;
|
|
568
599
|
glyphs.set(key, {
|
|
569
|
-
rowBase: built.rowBase,
|
|
600
|
+
rowBase: built.rowBase + rowUintOffset,
|
|
570
601
|
bandCount: built.bandCount,
|
|
571
602
|
bandH: built.bandH,
|
|
572
603
|
invH: built.invH,
|
|
@@ -593,6 +624,6 @@ function preprocessSlugGlyphs(sources, options = {}) {
|
|
|
593
624
|
}
|
|
594
625
|
};
|
|
595
626
|
}
|
|
596
|
-
export { preprocessSlugGlyphs };
|
|
627
|
+
export { preprocessSlugGlyphs, preprocessSlugGlyphsBatch };
|
|
597
628
|
|
|
598
629
|
//# sourceMappingURL=preprocessCore.js.map
|