ultra-text 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -115
- package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +35 -11
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +1 -1
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.js +8 -3
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +97 -42
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +10 -4
- package/dist/atlas/cpuWorker.js +99 -49
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +133 -56
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +140 -18
- package/dist/atlas/gpuCommon.js +726 -104
- package/dist/atlas/gpuCommon.js.map +1 -1
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +232 -61
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +237 -111
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/vanillaCore.js +156 -103
- package/dist/atlas/vanillaCore.js.map +1 -1
- package/dist/atlas/vanillaCpuAtlas.js +37 -52
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
- package/dist/atlas/vanillaExtras.js +91 -90
- package/dist/atlas/vanillaExtras.js.map +1 -1
- package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
- package/dist/atlas/vanillaGpuHelpers.js +262 -27
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
- package/dist/dom/DomSdf.js +85 -79
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +23 -18
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +1 -2
- package/dist/dom/domAnalytic.js +1 -1
- package/dist/dom/domAnalytic.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +4 -4
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +28 -12
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +27 -19
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +747 -505
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.js +30 -27
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +15 -8
- package/dist/dom/tone.js.map +1 -1
- package/dist/slug/SlugMaterial.d.ts +6 -0
- package/dist/slug/SlugMaterial.js +48 -20
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +3 -3
- package/dist/slug/coverage.js +283 -101
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -1
- package/dist/slug/preprocessCore.js +100 -80
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +32 -39
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.js +47 -37
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +190 -62
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +74 -4
- package/dist/slug/vanillaCore.js +226 -217
- package/dist/slug/vanillaCore.js.map +1 -1
- package/dist/slug-vanilla.d.ts +1 -1
- package/dist/slug-vanilla.js +5 -4
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +3 -3
- package/dist/text/GlyphTextMaterial.d.ts +5 -0
- package/dist/text/GlyphTextMaterial.js +11 -7
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +122 -37
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -96
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometryUtils.d.ts +5 -0
- package/dist/text/geometryUtils.js +63 -9
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +1 -1
- package/dist/text/glyphGeometry.js +281 -200
- package/dist/text/glyphGeometry.js.map +1 -1
- package/dist/text/rectGeometry.js +46 -42
- package/dist/text/rectGeometry.js.map +1 -1
- package/dist/text/reflow.d.ts +5 -0
- package/dist/text/reflow.js +127 -68
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -1
- package/dist/text/snap.js +1 -1
- package/dist/text/snap.js.map +1 -1
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.js +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +15 -0
- package/dist/windfoil/geometry.js +154 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.js +13 -4
- 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 +63 -36
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +1 -0
- package/dist/windfoil/runtime.js +8 -24
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +23 -9
- package/dist/windfoil/storage.js +49 -30
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.js +120 -50
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.js +578 -224
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +335 -70
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +26 -24
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
|
@@ -93,31 +93,43 @@ function shapeGlyphs(instances) {
|
|
|
93
93
|
}
|
|
94
94
|
return out;
|
|
95
95
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const rects = geometry.getAttribute("sdfRect").array, meta = geometry.getAttribute("sdfMeta").array, bbox = geometry.boundingBox ?? new Box3(), count = geometry.instanceCount;
|
|
96
|
+
function applyShapeBounds(geometry, count, minX, minY, minZ, maxX, maxY, maxZ) {
|
|
97
|
+
const bbox = geometry.boundingBox ?? new Box3();
|
|
99
98
|
if (count === 0) {
|
|
100
99
|
bbox.min.set(0, 0, 0);
|
|
101
100
|
bbox.max.set(0, 0, 0);
|
|
102
101
|
} else {
|
|
103
|
-
let minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
104
|
-
for (let i = 0; i < count; i++) {
|
|
105
|
-
const r = i * 4, z = meta[i * 2 + 1];
|
|
106
|
-
minX = Math.min(minX, rects[r], rects[r + 2]);
|
|
107
|
-
minY = Math.min(minY, rects[r + 1], rects[r + 3]);
|
|
108
|
-
if (z < minZ) minZ = z;
|
|
109
|
-
maxX = Math.max(maxX, rects[r], rects[r + 2]);
|
|
110
|
-
maxY = Math.max(maxY, rects[r + 1], rects[r + 3]);
|
|
111
|
-
if (z > maxZ) maxZ = z;
|
|
112
|
-
}
|
|
113
102
|
bbox.min.set(minX, minY, minZ);
|
|
114
103
|
bbox.max.set(maxX, maxY, maxZ);
|
|
115
104
|
}
|
|
116
105
|
geometry.boundingBox = bbox;
|
|
117
106
|
geometry.boundingSphere = bbox.getBoundingSphere(geometry.boundingSphere ?? new Sphere());
|
|
118
107
|
}
|
|
108
|
+
/** Tight local bounds of every written quad, at its instance depth. */
|
|
109
|
+
function setShapeBounds(geometry) {
|
|
110
|
+
const rects = geometry.getAttribute("sdfRect").array, meta = geometry.getAttribute("sdfMeta").array, count = geometry.instanceCount;
|
|
111
|
+
if (count === 0) {
|
|
112
|
+
applyShapeBounds(geometry, 0, 0, 0, 0, 0, 0, 0);
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
let minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
116
|
+
for (let i = 0; i < count; i++) {
|
|
117
|
+
const r = i * 4, z = meta[i * 2 + 1], x0 = rects[r], y0 = rects[r + 1], x1 = rects[r + 2], y1 = rects[r + 3];
|
|
118
|
+
if (x0 < minX) minX = x0;
|
|
119
|
+
if (x1 < minX) minX = x1;
|
|
120
|
+
if (x0 > maxX) maxX = x0;
|
|
121
|
+
if (x1 > maxX) maxX = x1;
|
|
122
|
+
if (y0 < minY) minY = y0;
|
|
123
|
+
if (y1 < minY) minY = y1;
|
|
124
|
+
if (y0 > maxY) maxY = y0;
|
|
125
|
+
if (y1 > maxY) maxY = y1;
|
|
126
|
+
if (z < minZ) minZ = z;
|
|
127
|
+
if (z > maxZ) maxZ = z;
|
|
128
|
+
}
|
|
129
|
+
applyShapeBounds(geometry, count, minX, minY, minZ, maxX, maxY, maxZ);
|
|
130
|
+
}
|
|
119
131
|
function writeInstances(instances, headers, attrs) {
|
|
120
|
-
let index = 0, maxSequence = 0;
|
|
132
|
+
let index = 0, maxSequence = 0, minX = Infinity, minY = Infinity, minZ = Infinity, maxX = -Infinity, maxY = -Infinity, maxZ = -Infinity;
|
|
121
133
|
const color = [
|
|
122
134
|
1,
|
|
123
135
|
1,
|
|
@@ -158,11 +170,36 @@ function writeInstances(instances, headers, attrs) {
|
|
|
158
170
|
glyph.sequence = sequence;
|
|
159
171
|
glyph.z = instance.z ?? 0;
|
|
160
172
|
const rect = hasLayers ? fillWindfoilGlyphRect(glyph, header) : void 0;
|
|
173
|
+
const startIdx = index;
|
|
161
174
|
for (const layer of hasLayers && header.layers || [header]) writeLayerInstance(glyph, header, layer, index++, ordinal, attrs, rect);
|
|
175
|
+
const z = glyph.z;
|
|
176
|
+
if (z < minZ) minZ = z;
|
|
177
|
+
if (z > maxZ) maxZ = z;
|
|
178
|
+
const rects = attrs.rects;
|
|
179
|
+
for (let i = startIdx; i < index; i++) {
|
|
180
|
+
const r = i * 4;
|
|
181
|
+
const x0 = rects[r], y0 = rects[r + 1], x1 = rects[r + 2], y1 = rects[r + 3];
|
|
182
|
+
if (x0 < minX) minX = x0;
|
|
183
|
+
if (x1 < minX) minX = x1;
|
|
184
|
+
if (x0 > maxX) maxX = x0;
|
|
185
|
+
if (x1 > maxX) maxX = x1;
|
|
186
|
+
if (y0 < minY) minY = y0;
|
|
187
|
+
if (y1 < minY) minY = y1;
|
|
188
|
+
if (y0 > maxY) maxY = y0;
|
|
189
|
+
if (y1 > maxY) maxY = y1;
|
|
190
|
+
}
|
|
162
191
|
if (sequence > maxSequence) maxSequence = sequence;
|
|
163
192
|
}
|
|
164
193
|
}
|
|
165
|
-
return
|
|
194
|
+
return {
|
|
195
|
+
maxSequence,
|
|
196
|
+
minX,
|
|
197
|
+
minY,
|
|
198
|
+
minZ,
|
|
199
|
+
maxX,
|
|
200
|
+
maxY,
|
|
201
|
+
maxZ
|
|
202
|
+
};
|
|
166
203
|
}
|
|
167
204
|
function createWindfoilShapeGeometry(instances, headers, layered = false) {
|
|
168
205
|
const count = countInstances(instances, headers, layered);
|
|
@@ -175,7 +212,7 @@ function createWindfoilShapeGeometry(instances, headers, layered = false) {
|
|
|
175
212
|
bands: new Float32Array(count * 4),
|
|
176
213
|
...layered ? { layers: new Float32Array(count * 4) } : {}
|
|
177
214
|
};
|
|
178
|
-
const
|
|
215
|
+
const written = writeInstances(instances, headers, attrs);
|
|
179
216
|
const geometry = new InstancedBufferGeometry();
|
|
180
217
|
geometry.name = "ultra-text instanced Windfoil shape quads";
|
|
181
218
|
setUnitQuad(geometry);
|
|
@@ -219,31 +256,40 @@ function createWindfoilShapeGeometry(instances, headers, layered = false) {
|
|
|
219
256
|
]) geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized));
|
|
220
257
|
if (attrs.layers) geometry.setAttribute("windfoilLayer", new InstancedBufferAttribute(attrs.layers, 4));
|
|
221
258
|
geometry.instanceCount = count;
|
|
222
|
-
|
|
259
|
+
applyShapeBounds(geometry, count, written.minX, written.minY, written.minZ, written.maxX, written.maxY, written.maxZ);
|
|
223
260
|
return {
|
|
224
261
|
geometry,
|
|
225
|
-
maxSequence
|
|
262
|
+
maxSequence: written.maxSequence
|
|
226
263
|
};
|
|
227
264
|
}
|
|
228
265
|
function updateWindfoilShapeGeometry(geometry, instances, headers) {
|
|
229
266
|
const layer = geometry.getAttribute("windfoilLayer");
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
267
|
+
const count = countInstances(instances, headers, !!layer);
|
|
268
|
+
if (geometry.instanceCount !== count) return null;
|
|
269
|
+
const rectAttr = geometry.getAttribute("sdfRect");
|
|
270
|
+
const clipAttr = geometry.getAttribute("sdfClip");
|
|
271
|
+
const colorAttr = geometry.getAttribute("sdfColor");
|
|
272
|
+
const metaAttr = geometry.getAttribute("sdfMeta");
|
|
273
|
+
const boundsAttr = geometry.getAttribute("windfoilBounds");
|
|
274
|
+
const bandAttr = geometry.getAttribute("windfoilBand");
|
|
275
|
+
rectAttr.needsUpdate = true;
|
|
276
|
+
clipAttr.needsUpdate = true;
|
|
277
|
+
colorAttr.needsUpdate = true;
|
|
278
|
+
metaAttr.needsUpdate = true;
|
|
279
|
+
boundsAttr.needsUpdate = true;
|
|
280
|
+
bandAttr.needsUpdate = true;
|
|
281
|
+
if (layer) layer.needsUpdate = true;
|
|
282
|
+
const written = writeInstances(instances, headers, {
|
|
283
|
+
rects: rectAttr.array,
|
|
284
|
+
clips: clipAttr.array,
|
|
285
|
+
colors: colorAttr.array,
|
|
286
|
+
metadata: metaAttr.array,
|
|
287
|
+
bounds: boundsAttr.array,
|
|
288
|
+
bands: bandAttr.array,
|
|
289
|
+
...layer ? { layers: layer.array } : {}
|
|
244
290
|
});
|
|
245
|
-
|
|
246
|
-
return maxSequence;
|
|
291
|
+
applyShapeBounds(geometry, count, written.minX, written.minY, written.minZ, written.maxX, written.maxY, written.maxZ);
|
|
292
|
+
return written.maxSequence;
|
|
247
293
|
}
|
|
248
294
|
export { createWindfoilShapeGeometry, setShapeBounds, shapeGlyphs, updateWindfoilShapeGeometry, validateShapeInstances };
|
|
249
295
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapeGeometry.js","names":[],"sources":["../../src/windfoil/shapeGeometry.ts"],"sourcesContent":["import {\n Box3,\n Color,\n InstancedBufferAttribute,\n InstancedBufferGeometry,\n Sphere,\n SRGBColorSpace,\n} from 'three/webgpu'\nimport type { GlyphLayout, WindfoilShapeInstance } from '../types.js'\nimport { setUnitQuad } from '../text/geometryUtils.js'\nimport {\n fillWindfoilGlyphRect,\n writeLayerInstance,\n type MutableWindfoilAttributes,\n} from './geometry.js'\nimport type { WindfoilGlyphHeader } from './preprocess.js'\nexport function validateShapeInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, unknown>,\n): void {\n let lastShape = ''\n for (let index = 0; index < instances.length; index++) {\n const instance = instances[index]!\n if (instance.shape !== lastShape) {\n if (!headers.has(instance.shape))\n throw new TypeError(`instances[${index}].shape is not an outline key`)\n lastShape = instance.shape\n }\n if (\n !Number.isFinite(instance.x) ||\n !Number.isFinite(instance.y) ||\n !Number.isFinite(instance.size) ||\n !Number.isFinite(instance.z ?? 0) ||\n !Number.isFinite(instance.sequence ?? 0) ||\n instance.size <= 0\n )\n throw new RangeError(`instances[${index}] requires finite coordinates and positive size`)\n const opacity = instance.opacity ?? 1\n if (!Number.isFinite(opacity) || opacity < 0 || opacity > 1)\n throw new RangeError(`instances[${index}].opacity must be in [0, 1]`)\n const clip = instance.clip\n if (\n clip &&\n ((clip as readonly number[]).length !== 4 ||\n !Number.isFinite(clip[0]) ||\n !Number.isFinite(clip[1]) ||\n !Number.isFinite(clip[2]) ||\n !Number.isFinite(clip[3]) ||\n clip[0] > clip[2] ||\n clip[1] > clip[3])\n )\n throw new RangeError(`instances[${index}].clip must be an ordered finite rectangle`)\n }\n}\nconst DEFAULT_CLIP = [-1e7, -1e7, 1e7, 1e7] as const\nconst DEFAULT_RGB = [1, 1, 1] as const\nconst sharedColor = new Color()\nconst sharedRgb = { r: 1, g: 1, b: 1 }\nconst colorCache = new Map<string | number, readonly [number, number, number]>()\n\nfunction resolveInstanceRgb(\n input: WindfoilShapeInstance['color'],\n): readonly [number, number, number] {\n if (input === undefined || input === 0xffffff) return DEFAULT_RGB\n const cached = colorCache.get(input as string | number)\n if (cached) return cached\n sharedColor.set(input).getRGB(sharedRgb, SRGBColorSpace)\n const rgb: readonly [number, number, number] = [sharedRgb.r, sharedRgb.g, sharedRgb.b]\n if (typeof input !== 'object') {\n if (colorCache.size > 999) colorCache.clear()\n colorCache.set(input, rgb)\n }\n return rgb\n}\n\nfunction countInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): number {\n let total = 0\n let lastShape = ''\n let lastCount = 0\n for (const instance of instances) {\n if (instance.shape !== lastShape) {\n lastShape = instance.shape\n const header = headers.get(lastShape)!\n lastCount = header.monotonePieceCount ? (layered ? (header.layers?.length ?? 1) : 1) : 0\n }\n total += lastCount\n }\n return total\n}\n/** Instance fields as the shared glyph layout used by layer and composite geometry. */\nexport function shapeGlyphs(instances: readonly WindfoilShapeInstance[]): GlyphLayout[] {\n const n = instances.length\n const out = new Array<GlyphLayout>(n)\n for (let i = 0; i < n; i++) {\n const instance = instances[i]!\n const rgb = resolveInstanceRgb(instance.color)\n out[i] = {\n glyphKey: instance.shape,\n fontSize: instance.size,\n originX: instance.x,\n lineBottom: instance.y,\n advance: 0,\n block: 0,\n breakBefore: 'none',\n clip: instance.clip ?? DEFAULT_CLIP,\n color: [rgb[0], rgb[1], rgb[2], instance.opacity ?? 1],\n sequence: instance.sequence ?? 0,\n z: instance.z ?? 0,\n }\n }\n return out\n}\n/** Tight local bounds of every written quad, at its instance depth. */\nexport function setShapeBounds(geometry: InstancedBufferGeometry): void {\n const rects = geometry.getAttribute('sdfRect').array as Float32Array,\n meta = geometry.getAttribute('sdfMeta').array as Float32Array,\n bbox = geometry.boundingBox ?? new Box3(),\n count = geometry.instanceCount\n if (count === 0) {\n bbox.min.set(0, 0, 0)\n bbox.max.set(0, 0, 0)\n } else {\n let minX = Infinity,\n minY = Infinity,\n minZ = Infinity,\n maxX = -Infinity,\n maxY = -Infinity,\n maxZ = -Infinity\n for (let i = 0; i < count; i++) {\n const r = i * 4,\n z = meta[i * 2 + 1]!\n minX = Math.min(minX, rects[r]!, rects[r + 2]!)\n minY = Math.min(minY, rects[r + 1]!, rects[r + 3]!)\n if (z < minZ) minZ = z\n maxX = Math.max(maxX, rects[r]!, rects[r + 2]!)\n maxY = Math.max(maxY, rects[r + 1]!, rects[r + 3]!)\n if (z > maxZ) maxZ = z\n }\n bbox.min.set(minX, minY, minZ)\n bbox.max.set(maxX, maxY, maxZ)\n }\n geometry.boundingBox = bbox\n geometry.boundingSphere = bbox.getBoundingSphere(geometry.boundingSphere ?? new Sphere())\n}\nfunction writeInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n attrs: MutableWindfoilAttributes,\n): number {\n let index = 0,\n maxSequence = 0\n const color: [number, number, number, number] = [1, 1, 1, 1]\n const glyph = {\n glyphKey: '',\n fontSize: 0,\n originX: 0,\n lineBottom: 0,\n advance: 0,\n block: 0,\n breakBefore: 'none' as const,\n clip: DEFAULT_CLIP as readonly [number, number, number, number],\n color,\n sequence: 0,\n z: 0,\n }\n const hasLayers = Boolean(attrs.layers)\n let lastShape = ''\n let lastHeader: WindfoilGlyphHeader | undefined\n for (let ordinal = 0; ordinal < instances.length; ordinal++) {\n const instance = instances[ordinal]!\n const header =\n instance.shape === lastShape\n ? lastHeader!\n : ((lastShape = instance.shape), (lastHeader = headers.get(lastShape)!))\n const sequence = instance.sequence ?? 0\n if (header.monotonePieceCount) {\n const rgb = resolveInstanceRgb(instance.color)\n color[0] = rgb[0]\n color[1] = rgb[1]\n color[2] = rgb[2]\n color[3] = instance.opacity ?? 1\n glyph.glyphKey = instance.shape\n glyph.fontSize = instance.size\n glyph.originX = instance.x\n glyph.lineBottom = instance.y\n glyph.clip = instance.clip ?? DEFAULT_CLIP\n glyph.sequence = sequence\n glyph.z = instance.z ?? 0\n const rect = hasLayers ? fillWindfoilGlyphRect(glyph, header) : undefined\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n for (const layer of (hasLayers && header.layers) || [header])\n writeLayerInstance(glyph, header, layer, index++, ordinal, attrs, rect)\n if (sequence > maxSequence) maxSequence = sequence\n }\n }\n return maxSequence\n}\nexport function createWindfoilShapeGeometry(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered = false,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const count = countInstances(instances, headers, layered)\n const attrs = {\n rects: new Float32Array(count * 4),\n clips: new Float32Array(count * 4),\n colors: new Uint8Array(count * 4),\n metadata: new Float32Array(count * 2),\n bounds: new Float32Array(count * 4),\n bands: new Float32Array(count * 4),\n ...(layered ? { layers: new Float32Array(count * 4) } : {}),\n }\n const maxSequence = writeInstances(instances, headers, attrs)\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil shape quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', attrs.rects, 4, false],\n ['sdfClip', attrs.clips, 4, false],\n ['sdfColor', attrs.colors, 4, true],\n ['sdfMeta', attrs.metadata, 2, false],\n ['windfoilBounds', attrs.bounds, 4, false],\n ['windfoilBand', attrs.bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (attrs.layers)\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(attrs.layers, 4))\n geometry.instanceCount = count\n setShapeBounds(geometry)\n return { geometry, maxSequence }\n}\nexport function updateWindfoilShapeGeometry(\n geometry: InstancedBufferGeometry,\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n): number | null {\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n if (geometry.instanceCount !== countInstances(instances, headers, !!layer)) return null\n const array = <T extends Float32Array | Uint8Array>(name: string): T => {\n const attribute = geometry.getAttribute(name)\n attribute.needsUpdate = true\n return attribute.array as T\n }\n const maxSequence = writeInstances(instances, headers, {\n rects: array('sdfRect'),\n clips: array('sdfClip'),\n colors: array('sdfColor'),\n metadata: array('sdfMeta'),\n bounds: array('windfoilBounds'),\n bands: array('windfoilBand'),\n ...(layer ? { layers: array<Float32Array>('windfoilLayer') } : {}),\n })\n setShapeBounds(geometry)\n return maxSequence\n}\n"],"mappings":";;;;AAgBA,SAAgB,uBACd,WACA,SACM;CACN,IAAI,YAAY;CAChB,KAAK,IAAI,QAAQ,GAAG,QAAQ,UAAU,QAAQ,SAAS;EACrD,MAAM,WAAW,UAAU;EAC3B,IAAI,SAAS,UAAU,WAAW;GAChC,IAAI,CAAC,QAAQ,IAAI,SAAS,KAAK,GAC7B,MAAM,IAAI,UAAU,aAAa,MAAM,8BAA8B;GACvE,YAAY,SAAS;EACvB;EACA,IACE,CAAC,OAAO,SAAS,SAAS,CAAC,KAC3B,CAAC,OAAO,SAAS,SAAS,CAAC,KAC3B,CAAC,OAAO,SAAS,SAAS,IAAI,KAC9B,CAAC,OAAO,SAAS,SAAS,KAAK,CAAC,KAChC,CAAC,OAAO,SAAS,SAAS,YAAY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AQ,CAAC,CAAC;CACtF,SAAS,gBAAgB;CACzB,eAAe,QAAQ;CACvB,OAAO;EAAE;EAAU;CAAY;AACjC;AACA,SAAgB,4BACd,UACA,WACA,SACe;CACf,MAAM,QAAQ,SAAS,aAAa,eAAe;CACnD,IAAI,SAAS,kBAAkB,eAAe,WAAW,SAAS,CAAC,CAAC,KAAK,GAAG,OAAO;CACnF,MAAM,SAA8C,SAAoB;EACtE,MAAM,YAAY,SAAS,aAAa,IAAI;EAC5C,UAAU,cAAc;EACxB,OAAO,UAAU;CACnB;CACA,MAAM,cAAc,eAAe,WAAW,SAAS;EACrD,OAAO,MAAM,SAAS;EACtB,OAAO,MAAM,SAAS;EACtB,QAAQ,MAAM,UAAU;EACxB,UAAU,MAAM,SAAS;EACzB,QAAQ,MAAM,gBAAgB;EAC9B,OAAO,MAAM,cAAc;EAC3B,GAAI,QAAQ,EAAE,QAAQ,MAAoB,eAAe,EAAE,IAAI,CAAC;CAClE,CAAC;CACD,eAAe,QAAQ;CACvB,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"shapeGeometry.js","names":[],"sources":["../../src/windfoil/shapeGeometry.ts"],"sourcesContent":["import {\n Box3,\n Color,\n InstancedBufferAttribute,\n InstancedBufferGeometry,\n Sphere,\n SRGBColorSpace,\n} from 'three/webgpu'\nimport type { GlyphLayout, WindfoilShapeInstance } from '../types.js'\nimport { setUnitQuad } from '../text/geometryUtils.js'\nimport {\n fillWindfoilGlyphRect,\n writeLayerInstance,\n type MutableWindfoilAttributes,\n} from './geometry.js'\nimport type { WindfoilGlyphHeader } from './preprocess.js'\nexport function validateShapeInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, unknown>,\n): void {\n let lastShape = ''\n for (let index = 0; index < instances.length; index++) {\n const instance = instances[index]!\n if (instance.shape !== lastShape) {\n if (!headers.has(instance.shape))\n throw new TypeError(`instances[${index}].shape is not an outline key`)\n lastShape = instance.shape\n }\n if (\n !Number.isFinite(instance.x) ||\n !Number.isFinite(instance.y) ||\n !Number.isFinite(instance.size) ||\n !Number.isFinite(instance.z ?? 0) ||\n !Number.isFinite(instance.sequence ?? 0) ||\n instance.size <= 0\n )\n throw new RangeError(`instances[${index}] requires finite coordinates and positive size`)\n const opacity = instance.opacity ?? 1\n if (!Number.isFinite(opacity) || opacity < 0 || opacity > 1)\n throw new RangeError(`instances[${index}].opacity must be in [0, 1]`)\n const clip = instance.clip\n if (\n clip &&\n ((clip as readonly number[]).length !== 4 ||\n !Number.isFinite(clip[0]) ||\n !Number.isFinite(clip[1]) ||\n !Number.isFinite(clip[2]) ||\n !Number.isFinite(clip[3]) ||\n clip[0] > clip[2] ||\n clip[1] > clip[3])\n )\n throw new RangeError(`instances[${index}].clip must be an ordered finite rectangle`)\n }\n}\nconst DEFAULT_CLIP = [-1e7, -1e7, 1e7, 1e7] as const\nconst DEFAULT_RGB = [1, 1, 1] as const\nconst sharedColor = new Color()\nconst sharedRgb = { r: 1, g: 1, b: 1 }\nconst colorCache = new Map<string | number, readonly [number, number, number]>()\n\nfunction resolveInstanceRgb(\n input: WindfoilShapeInstance['color'],\n): readonly [number, number, number] {\n if (input === undefined || input === 0xffffff) return DEFAULT_RGB\n const cached = colorCache.get(input as string | number)\n if (cached) return cached\n sharedColor.set(input).getRGB(sharedRgb, SRGBColorSpace)\n const rgb: readonly [number, number, number] = [sharedRgb.r, sharedRgb.g, sharedRgb.b]\n if (typeof input !== 'object') {\n if (colorCache.size > 999) colorCache.clear()\n colorCache.set(input, rgb)\n }\n return rgb\n}\n\nfunction countInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): number {\n let total = 0\n let lastShape = ''\n let lastCount = 0\n for (const instance of instances) {\n if (instance.shape !== lastShape) {\n lastShape = instance.shape\n const header = headers.get(lastShape)!\n lastCount = header.monotonePieceCount ? (layered ? (header.layers?.length ?? 1) : 1) : 0\n }\n total += lastCount\n }\n return total\n}\n/** Instance fields as the shared glyph layout used by layer and composite geometry. */\nexport function shapeGlyphs(instances: readonly WindfoilShapeInstance[]): GlyphLayout[] {\n const n = instances.length\n const out = new Array<GlyphLayout>(n)\n for (let i = 0; i < n; i++) {\n const instance = instances[i]!\n const rgb = resolveInstanceRgb(instance.color)\n out[i] = {\n glyphKey: instance.shape,\n fontSize: instance.size,\n originX: instance.x,\n lineBottom: instance.y,\n advance: 0,\n block: 0,\n breakBefore: 'none',\n clip: instance.clip ?? DEFAULT_CLIP,\n color: [rgb[0], rgb[1], rgb[2], instance.opacity ?? 1],\n sequence: instance.sequence ?? 0,\n z: instance.z ?? 0,\n }\n }\n return out\n}\nfunction applyShapeBounds(\n geometry: InstancedBufferGeometry,\n count: number,\n minX: number,\n minY: number,\n minZ: number,\n maxX: number,\n maxY: number,\n maxZ: number,\n): void {\n const bbox = geometry.boundingBox ?? new Box3()\n if (count === 0) {\n bbox.min.set(0, 0, 0)\n bbox.max.set(0, 0, 0)\n } else {\n bbox.min.set(minX, minY, minZ)\n bbox.max.set(maxX, maxY, maxZ)\n }\n geometry.boundingBox = bbox\n geometry.boundingSphere = bbox.getBoundingSphere(geometry.boundingSphere ?? new Sphere())\n}\n\n/** Tight local bounds of every written quad, at its instance depth. */\nexport function setShapeBounds(geometry: InstancedBufferGeometry): void {\n const rects = geometry.getAttribute('sdfRect').array as Float32Array,\n meta = geometry.getAttribute('sdfMeta').array as Float32Array,\n count = geometry.instanceCount\n if (count === 0) {\n applyShapeBounds(geometry, 0, 0, 0, 0, 0, 0, 0)\n return\n }\n let minX = Infinity,\n minY = Infinity,\n minZ = Infinity,\n maxX = -Infinity,\n maxY = -Infinity,\n maxZ = -Infinity\n for (let i = 0; i < count; i++) {\n const r = i * 4,\n z = meta[i * 2 + 1]!,\n x0 = rects[r]!,\n y0 = rects[r + 1]!,\n x1 = rects[r + 2]!,\n y1 = rects[r + 3]!\n if (x0 < minX) minX = x0\n if (x1 < minX) minX = x1\n if (x0 > maxX) maxX = x0\n if (x1 > maxX) maxX = x1\n if (y0 < minY) minY = y0\n if (y1 < minY) minY = y1\n if (y0 > maxY) maxY = y0\n if (y1 > maxY) maxY = y1\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n }\n applyShapeBounds(geometry, count, minX, minY, minZ, maxX, maxY, maxZ)\n}\nfunction writeInstances(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n attrs: MutableWindfoilAttributes,\n): {\n maxSequence: number\n minX: number\n minY: number\n minZ: number\n maxX: number\n maxY: number\n maxZ: number\n} {\n let index = 0,\n maxSequence = 0,\n minX = Infinity,\n minY = Infinity,\n minZ = Infinity,\n maxX = -Infinity,\n maxY = -Infinity,\n maxZ = -Infinity\n const color: [number, number, number, number] = [1, 1, 1, 1]\n const glyph = {\n glyphKey: '',\n fontSize: 0,\n originX: 0,\n lineBottom: 0,\n advance: 0,\n block: 0,\n breakBefore: 'none' as const,\n clip: DEFAULT_CLIP as readonly [number, number, number, number],\n color,\n sequence: 0,\n z: 0,\n }\n const hasLayers = Boolean(attrs.layers)\n let lastShape = ''\n let lastHeader: WindfoilGlyphHeader | undefined\n for (let ordinal = 0; ordinal < instances.length; ordinal++) {\n const instance = instances[ordinal]!\n const header =\n instance.shape === lastShape\n ? lastHeader!\n : ((lastShape = instance.shape), (lastHeader = headers.get(lastShape)!))\n const sequence = instance.sequence ?? 0\n if (header.monotonePieceCount) {\n const rgb = resolveInstanceRgb(instance.color)\n color[0] = rgb[0]\n color[1] = rgb[1]\n color[2] = rgb[2]\n color[3] = instance.opacity ?? 1\n glyph.glyphKey = instance.shape\n glyph.fontSize = instance.size\n glyph.originX = instance.x\n glyph.lineBottom = instance.y\n glyph.clip = instance.clip ?? DEFAULT_CLIP\n glyph.sequence = sequence\n glyph.z = instance.z ?? 0\n const rect = hasLayers ? fillWindfoilGlyphRect(glyph, header) : undefined\n const startIdx = index\n // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing\n for (const layer of (hasLayers && header.layers) || [header])\n writeLayerInstance(glyph, header, layer, index++, ordinal, attrs, rect)\n const z = glyph.z\n if (z < minZ) minZ = z\n if (z > maxZ) maxZ = z\n const rects = attrs.rects\n for (let i = startIdx; i < index; i++) {\n const r = i * 4\n const x0 = rects[r]!,\n y0 = rects[r + 1]!,\n x1 = rects[r + 2]!,\n y1 = rects[r + 3]!\n if (x0 < minX) minX = x0\n if (x1 < minX) minX = x1\n if (x0 > maxX) maxX = x0\n if (x1 > maxX) maxX = x1\n if (y0 < minY) minY = y0\n if (y1 < minY) minY = y1\n if (y0 > maxY) maxY = y0\n if (y1 > maxY) maxY = y1\n }\n if (sequence > maxSequence) maxSequence = sequence\n }\n }\n return { maxSequence, minX, minY, minZ, maxX, maxY, maxZ }\n}\nexport function createWindfoilShapeGeometry(\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered = false,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n const count = countInstances(instances, headers, layered)\n const attrs = {\n rects: new Float32Array(count * 4),\n clips: new Float32Array(count * 4),\n colors: new Uint8Array(count * 4),\n metadata: new Float32Array(count * 2),\n bounds: new Float32Array(count * 4),\n bands: new Float32Array(count * 4),\n ...(layered ? { layers: new Float32Array(count * 4) } : {}),\n }\n const written = writeInstances(instances, headers, attrs)\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil shape quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', attrs.rects, 4, false],\n ['sdfClip', attrs.clips, 4, false],\n ['sdfColor', attrs.colors, 4, true],\n ['sdfMeta', attrs.metadata, 2, false],\n ['windfoilBounds', attrs.bounds, 4, false],\n ['windfoilBand', attrs.bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (attrs.layers)\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(attrs.layers, 4))\n geometry.instanceCount = count\n applyShapeBounds(\n geometry,\n count,\n written.minX,\n written.minY,\n written.minZ,\n written.maxX,\n written.maxY,\n written.maxZ,\n )\n return { geometry, maxSequence: written.maxSequence }\n}\nexport function updateWindfoilShapeGeometry(\n geometry: InstancedBufferGeometry,\n instances: readonly WindfoilShapeInstance[],\n headers: ReadonlyMap<string, WindfoilGlyphHeader>,\n): number | null {\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n const count = countInstances(instances, headers, !!layer)\n if (geometry.instanceCount !== count) return null\n const rectAttr = geometry.getAttribute('sdfRect')\n const clipAttr = geometry.getAttribute('sdfClip')\n const colorAttr = geometry.getAttribute('sdfColor')\n const metaAttr = geometry.getAttribute('sdfMeta')\n const boundsAttr = geometry.getAttribute('windfoilBounds')\n const bandAttr = geometry.getAttribute('windfoilBand')\n rectAttr.needsUpdate = true\n clipAttr.needsUpdate = true\n colorAttr.needsUpdate = true\n metaAttr.needsUpdate = true\n boundsAttr.needsUpdate = true\n bandAttr.needsUpdate = true\n if (layer) layer.needsUpdate = true\n const written = writeInstances(instances, headers, {\n rects: rectAttr.array as Float32Array,\n clips: clipAttr.array as Float32Array,\n colors: colorAttr.array as Uint8Array,\n metadata: metaAttr.array as Float32Array,\n bounds: boundsAttr.array as Float32Array,\n bands: bandAttr.array as Float32Array,\n ...(layer ? { layers: layer.array as Float32Array } : {}),\n })\n applyShapeBounds(\n geometry,\n count,\n written.minX,\n written.minY,\n written.minZ,\n written.maxX,\n written.maxY,\n written.maxZ,\n )\n return written.maxSequence\n}\n"],"mappings":";;;;AAgBA,SAAgB,uBACd,WACA,SACM;CACN,IAAI,YAAY;CAChB,KAAK,IAAI,QAAQ,GAAG,QAAQ,UAAU,QAAQ,SAAS;EACrD,MAAM,WAAW,UAAU;EAC3B,IAAI,SAAS,UAAU,WAAW;GAChC,IAAI,CAAC,QAAQ,IAAI,SAAS,KAAK,GAC7B,MAAM,IAAI,UAAU,aAAa,MAAM,8BAA8B;GACvE,YAAY,SAAS;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Q,MACR,QAAQ,MACR,QAAQ,MACR,QAAQ,IACV;CACA,OAAO;EAAE;EAAU,aAAa,QAAQ;CAAY;AACtD;AACA,SAAgB,4BACd,UACA,WACA,SACe;CACf,MAAM,QAAQ,SAAS,aAAa,eAAe;CACnD,MAAM,QAAQ,eAAe,WAAW,SAAS,CAAC,CAAC,KAAK;CACxD,IAAI,SAAS,kBAAkB,OAAO,OAAO;CAC7C,MAAM,WAAW,SAAS,aAAa,SAAS;CAChD,MAAM,WAAW,SAAS,aAAa,SAAS;CAChD,MAAM,YAAY,SAAS,aAAa,UAAU;CAClD,MAAM,WAAW,SAAS,aAAa,SAAS;CAChD,MAAM,aAAa,SAAS,aAAa,gBAAgB;CACzD,MAAM,WAAW,SAAS,aAAa,cAAc;CACrD,SAAS,cAAc;CACvB,SAAS,cAAc;CACvB,UAAU,cAAc;CACxB,SAAS,cAAc;CACvB,WAAW,cAAc;CACzB,SAAS,cAAc;CACvB,IAAI,OAAO,MAAM,cAAc;CAC/B,MAAM,UAAU,eAAe,WAAW,SAAS;EACjD,OAAO,SAAS;EAChB,OAAO,SAAS;EAChB,QAAQ,UAAU;EAClB,UAAU,SAAS;EACnB,QAAQ,WAAW;EACnB,OAAO,SAAS;EAChB,GAAI,QAAQ,EAAE,QAAQ,MAAM,MAAsB,IAAI,CAAC;CACzD,CAAC;CACD,iBACE,UACA,OACA,QAAQ,MACR,QAAQ,MACR,QAAQ,MACR,QAAQ,MACR,QAAQ,MACR,QAAQ,IACV;CACA,OAAO,QAAQ;AACjB"}
|
|
@@ -7,7 +7,7 @@ export interface WindfoilSizeSwitch {
|
|
|
7
7
|
readonly sdf: GlyphKeepHook;
|
|
8
8
|
readonly windfoil: GlyphKeepHook;
|
|
9
9
|
/** The layout both batches draw: shared motion anchors plus each glyph's switch em. */
|
|
10
|
-
layout(snapshot: DomLayoutSnapshot): DomLayoutSnapshot;
|
|
10
|
+
layout(snapshot: DomLayoutSnapshot, fontEm?: boolean): DomLayoutSnapshot;
|
|
11
11
|
}
|
|
12
12
|
export declare function assertThreshold(value: unknown): void;
|
|
13
13
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isEmojiCandidate } from "../dom/clusters.js";
|
|
2
|
-
import { windfoilGlyphRect } from "./geometry.js";
|
|
2
|
+
import { fixedGlyphEm, windfoilGlyphRect } from "./geometry.js";
|
|
3
3
|
import { Fn, cameraProjectionMatrix, float, length, modelViewMatrix, uniform, vec2, vec4, viewportSize } from "three/tsl";
|
|
4
4
|
// src/windfoil/sizeSwitch.ts
|
|
5
5
|
/**
|
|
@@ -84,12 +84,14 @@ function createSizeSwitch(threshold, keys, glyphs, ordinalsOf) {
|
|
|
84
84
|
};
|
|
85
85
|
const fixed = (meta) => meta.z.lessThanEqual(0);
|
|
86
86
|
const derived = /* @__PURE__ */ new WeakMap();
|
|
87
|
+
let withFontEm;
|
|
87
88
|
return {
|
|
88
89
|
keys,
|
|
89
90
|
sdf: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(belowWithOverlap)),
|
|
90
91
|
windfoil: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(below).not()),
|
|
91
|
-
layout(snapshot) {
|
|
92
|
-
const
|
|
92
|
+
layout(snapshot, fontEm = false) {
|
|
93
|
+
const layouts = fontEm ? withFontEm ??= /* @__PURE__ */ new WeakMap() : derived;
|
|
94
|
+
const cached = layouts.get(snapshot);
|
|
93
95
|
if (cached) return cached;
|
|
94
96
|
const ordinals = ordinalsOf(snapshot);
|
|
95
97
|
const result = {
|
|
@@ -97,10 +99,13 @@ function createSizeSwitch(threshold, keys, glyphs, ordinalsOf) {
|
|
|
97
99
|
sizeSwitched: true,
|
|
98
100
|
glyphs: snapshot.glyphs.map((glyph, index) => {
|
|
99
101
|
const header = keys.has(glyph.glyphKey) ? glyphs.get(glyph.glyphKey) : void 0;
|
|
100
|
-
if (!header)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
102
|
+
if (!header) {
|
|
103
|
+
const em = fontEm ? fixedGlyphEm(glyph) : glyph.switchEm;
|
|
104
|
+
return {
|
|
105
|
+
...glyph,
|
|
106
|
+
switchEm: em ? -Math.abs(em) : 0
|
|
107
|
+
};
|
|
108
|
+
}
|
|
104
109
|
const rect = windfoilGlyphRect(glyph, header);
|
|
105
110
|
return {
|
|
106
111
|
...glyph,
|
|
@@ -113,7 +118,7 @@ function createSizeSwitch(threshold, keys, glyphs, ordinalsOf) {
|
|
|
113
118
|
};
|
|
114
119
|
})
|
|
115
120
|
};
|
|
116
|
-
|
|
121
|
+
layouts.set(snapshot, result);
|
|
117
122
|
return result;
|
|
118
123
|
}
|
|
119
124
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sizeSwitch.js","names":[],"sources":["../../src/windfoil/sizeSwitch.ts"],"sourcesContent":["import type { Node } from 'three/webgpu'\nimport {\n Fn,\n cameraProjectionMatrix,\n float,\n length,\n modelViewMatrix,\n uniform,\n vec2,\n vec4,\n viewportSize,\n} from 'three/tsl'\n\nimport { isEmojiCandidate } from '../dom/clusters.js'\nimport type { GlyphKeepHook } from '../text/GlyphTextMaterial.js'\nimport type {\n DomLayoutSnapshot,\n GlyphLayout,\n GlyphRequest,\n SdfAtlas,\n WindfoilGlyphOutline,\n} from '../types.js'\nimport { windfoilGlyphRect } from './geometry.js'\nimport type { WindfoilGlyphHeader } from './preprocessCore.js'\n\n/**\n * Both batches keep a glyph whose projected em lies in [T, T·OVERLAP). The two pipelines\n * evaluate the same function on bit-identical inputs, but compilers may contract or\n * reassociate differently. While their results agree within 2^-12, a glyph can be drawn twice\n * for a moment but never dropped; on an Apple M3 Max they agreed to about 1e-7 near the\n * origin and 7e-5 a million units out.\n */\nconst OVERLAP = 1 + 2 ** -12\n/** Anchors on or behind the eye plane go to Windfoil; WGSL has no infinity literal. */\nconst BEHIND_EYE = 3e38\n\nexport interface WindfoilSizeSwitch {\n /** Glyph keys drawn by the SDF companion when small and by Windfoil when large. */\n readonly keys: ReadonlySet<string>\n readonly sdf: GlyphKeepHook\n readonly windfoil: GlyphKeepHook\n /** The layout both batches draw: shared motion anchors plus each glyph's switch em. */\n layout(snapshot: DomLayoutSnapshot): DomLayoutSnapshot\n}\n\nexport function assertThreshold(value: unknown): void {\n // Beyond the sentinel the f32 uniforms stop separating anchors behind the eye.\n if (!(typeof value === 'number' && value > 0 && value * OVERLAP < BEHIND_EYE))\n throw new RangeError('DomSdf: windfoil.sdfBelowPx must be a finite number of pixels above 0')\n}\n\n/**\n * The companion atlas as the size switch draws it: glyphs without outlines plus the\n * switchable ones. A switchable glyph whose raster came back as colour ink would change\n * artwork at the switch, so it is left to Windfoil alone. The view shares the atlas, which\n * stays owned by its builder; a null view means nothing is left to draw.\n */\nexport function companionView(\n atlas: SdfAtlas,\n missing: readonly string[],\n switchable: readonly GlyphRequest[],\n): { readonly atlas: SdfAtlas | null; readonly keys: ReadonlySet<string> } {\n const keys = new Set(\n switchable\n .map((request) => request.key)\n .filter((key) => {\n const slot = atlas.glyphs.get(key)\n return !!slot && slot.color !== true\n }),\n )\n const kept = new Set([...missing, ...keys])\n return {\n keys,\n atlas: kept.size\n ? {\n ...atlas,\n glyphs: new Map([...atlas.glyphs].filter(([key]) => kept.has(key))),\n dispose() {\n /* Released by the builder that owns the atlas. */\n },\n }\n : null,\n }\n}\n\n/** Plain, drawable, single-paint outlines whose SDF raster shows the same artwork. */\nexport function switchableRequests(\n resolved: readonly {\n readonly request: GlyphRequest\n readonly outline: WindfoilGlyphOutline | null\n }[],\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): GlyphRequest[] {\n return resolved.flatMap(({ request, outline }) => {\n const header = outline ? glyphs.get(request.key) : undefined\n return header &&\n header.monotonePieceCount > 0 &&\n !header.layers &&\n !header.clipBox &&\n !isEmojiCandidate(request.character)\n ? [request]\n : []\n })\n}\n\nexport function createSizeSwitch(\n threshold: number,\n keys: ReadonlySet<string>,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n ordinalsOf: (snapshot: DomLayoutSnapshot) => Float32Array,\n): WindfoilSizeSwitch {\n const below = uniform(threshold)\n const belowWithOverlap = uniform(threshold * OVERLAP)\n // One layout function, so both pipelines compile the same WGSL for the decision.\n const projectedEm = Fn<\n [Node<'vec4'>, Node<'vec4'>, Node<'vec4'>, Node<'vec2'>, Node<'float'>],\n Node<'float'>\n >(([clip, axisX, axisY, halfViewport, em]) => {\n const w = clip.w\n // Pixels per local unit along each axis (scaled by w²): the quotient rule on clip.xy / clip.w,\n // exact in orthographic and perspective views. Since w² > 0 on the taken branch, factoring\n // 1 / w² outside length() is exact and avoids scaling both 2-vectors before their norms.\n const jx = axisX.xy.mul(w).sub(clip.xy.mul(axisX.w)).mul(halfViewport).toConst()\n const jy = axisY.xy.mul(w).sub(clip.xy.mul(axisY.w)).mul(halfViewport).toConst()\n // The largest singular value of [jx jy]: independent of roll, mirroring and shear, and\n // free of the cancellation in the eigenvalue formula.\n const stretch = length(vec2(jx.x.add(jy.y), jx.y.sub(jy.x)))\n .add(length(vec2(jx.x.sub(jy.y), jx.y.add(jy.x))))\n .mul(0.5)\n return w.greaterThan(0).select(stretch.mul(em).div(w.mul(w)), float(BEHIND_EYE))\n }).setLayout({\n name: 'ultraProjectedEm',\n type: 'float',\n inputs: [\n { name: 'clip', type: 'vec4' },\n { name: 'axisX', type: 'vec4' },\n { name: 'axisY', type: 'vec4' },\n { name: 'halfViewport', type: 'vec2' },\n { name: 'em', type: 'float' },\n ],\n })\n const emPixels = (anchor: Node<'vec2'>, meta: Node<'vec3'>): Node<'float'> => {\n const modelViewProjection = cameraProjectionMatrix.mul(modelViewMatrix)\n return projectedEm(\n modelViewProjection.mul(vec4(anchor, meta.y, 1)),\n modelViewProjection.mul(vec4(1, 0, 0, 0)),\n modelViewProjection.mul(vec4(0, 1, 0, 0)),\n viewportSize.mul(0.5),\n meta.z,\n ).toConst()\n }\n // A zero em marks glyphs that never switch: missing outlines, colour and layered glyphs.\n const fixed = (meta: Node<'vec3'>): Node<'bool'> => meta.z.lessThanEqual(0)\n const derived = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n return {\n keys,\n // A NaN em compares false: the SDF batch drops it and Windfoil keeps it.\n sdf: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(belowWithOverlap)),\n windfoil: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(below).not()),\n layout(snapshot) {\n const cached = derived.get(snapshot)\n if (cached) return cached\n const ordinals = ordinalsOf(snapshot)\n const result: DomLayoutSnapshot = {\n ...snapshot,\n sizeSwitched: true,\n glyphs: snapshot.glyphs.map((glyph, index): GlyphLayout => {\n const header = keys.has(glyph.glyphKey) ? glyphs.get(glyph.glyphKey) : undefined\n // Zero or below never switches; a dilating tone still reads the magnitude as the em.\n if (!header) return { ...glyph, switchEm: glyph.switchEm ? -Math.abs(glyph.switchEm) : 0 }\n const rect = windfoilGlyphRect(glyph, header)\n return {\n ...glyph,\n // Clamped above zero so a degenerate size still switches instead of meaning\n // \"never\", which would let both batches draw it.\n switchEm: Math.max(glyph.fontSize, 1e-30),\n motionOrigin: glyph.motionOrigin ?? [\n (rect[0] + rect[2]) / 2,\n (rect[1] + rect[3]) / 2,\n ordinals[index]!,\n ],\n }\n }),\n }\n derived.set(snapshot, result)\n return result\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AAgCA,IAAM,UAAU,IAAI,KAAK;;AAEzB,IAAM,aAAa;AAWnB,SAAgB,gBAAgB,OAAsB;CAEpD,IAAI,EAAE,OAAO,UAAU,YAAY,QAAQ,KAAK,QAAQ,UAAU,aAChE,MAAM,IAAI,WAAW,uEAAuE;AAChG;;;;;;;AAQA,SAAgB,cACd,OACA,SACA,YACyE;CACzE,MAAM,OAAO,IAAI,IACf,WACG,KAAK,YAAY,QAAQ,GAAG,CAAC,CAC7B,QAAQ,QAAQ;EACf,MAAM,OAAO,MAAM,OAAO,IAAI,GAAG;EACjC,OAAO,CAAC,CAAC,QAAQ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AAQ;GACpC,MAAM,SAA4B;IAChC,GAAG;IACH,cAAc;IACd,QAAQ,SAAS,OAAO,KAAK,OAAO,UAAuB;KACzD,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,KAAA;KAEvE,IAAI,CAAC,QAAQ,OAAO;MAAE,GAAG;MAAO,UAAU,MAAM,WAAW,CAAC,KAAK,IAAI,MAAM,QAAQ,IAAI;KAAE;KACzF,MAAM,OAAO,kBAAkB,OAAO,MAAM;KAC5C,OAAO;MACL,GAAG;MAGH,UAAU,KAAK,IAAI,MAAM,UAAU,KAAK;MACxC,cAAc,MAAM,gBAAgB;QACjC,KAAK,KAAK,KAAK,MAAM;QACrB,KAAK,KAAK,KAAK,MAAM;OACtB,SAAS;MACX;KACF;IACF,CAAC;GACH;GACA,QAAQ,IAAI,UAAU,MAAM;GAC5B,OAAO;EACT;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"sizeSwitch.js","names":[],"sources":["../../src/windfoil/sizeSwitch.ts"],"sourcesContent":["import type { Node } from 'three/webgpu'\nimport {\n Fn,\n cameraProjectionMatrix,\n float,\n length,\n modelViewMatrix,\n uniform,\n vec2,\n vec4,\n viewportSize,\n} from 'three/tsl'\n\nimport { isEmojiCandidate } from '../dom/clusters.js'\nimport type { GlyphKeepHook } from '../text/GlyphTextMaterial.js'\nimport type {\n DomLayoutSnapshot,\n GlyphLayout,\n GlyphRequest,\n SdfAtlas,\n WindfoilGlyphOutline,\n} from '../types.js'\nimport { fixedGlyphEm, windfoilGlyphRect } from './geometry.js'\nimport type { WindfoilGlyphHeader } from './preprocessCore.js'\n\n/**\n * Both batches keep a glyph whose projected em lies in [T, T·OVERLAP). The two pipelines\n * evaluate the same function on bit-identical inputs, but compilers may contract or\n * reassociate differently. While their results agree within 2^-12, a glyph can be drawn twice\n * for a moment but never dropped; on an Apple M3 Max they agreed to about 1e-7 near the\n * origin and 7e-5 a million units out.\n */\nconst OVERLAP = 1 + 2 ** -12\n/** Anchors on or behind the eye plane go to Windfoil; WGSL has no infinity literal. */\nconst BEHIND_EYE = 3e38\n\nexport interface WindfoilSizeSwitch {\n /** Glyph keys drawn by the SDF companion when small and by Windfoil when large. */\n readonly keys: ReadonlySet<string>\n readonly sdf: GlyphKeepHook\n readonly windfoil: GlyphKeepHook\n /** The layout both batches draw: shared motion anchors plus each glyph's switch em. */\n layout(snapshot: DomLayoutSnapshot, fontEm?: boolean): DomLayoutSnapshot\n}\n\nexport function assertThreshold(value: unknown): void {\n // Beyond the sentinel the f32 uniforms stop separating anchors behind the eye.\n if (!(typeof value === 'number' && value > 0 && value * OVERLAP < BEHIND_EYE))\n throw new RangeError('DomSdf: windfoil.sdfBelowPx must be a finite number of pixels above 0')\n}\n\n/**\n * The companion atlas as the size switch draws it: glyphs without outlines plus the\n * switchable ones. A switchable glyph whose raster came back as colour ink would change\n * artwork at the switch, so it is left to Windfoil alone. The view shares the atlas, which\n * stays owned by its builder; a null view means nothing is left to draw.\n */\nexport function companionView(\n atlas: SdfAtlas,\n missing: readonly string[],\n switchable: readonly GlyphRequest[],\n): { readonly atlas: SdfAtlas | null; readonly keys: ReadonlySet<string> } {\n const keys = new Set(\n switchable\n .map((request) => request.key)\n .filter((key) => {\n const slot = atlas.glyphs.get(key)\n return !!slot && slot.color !== true\n }),\n )\n const kept = new Set([...missing, ...keys])\n return {\n keys,\n atlas: kept.size\n ? {\n ...atlas,\n glyphs: new Map([...atlas.glyphs].filter(([key]) => kept.has(key))),\n dispose() {\n /* Released by the builder that owns the atlas. */\n },\n }\n : null,\n }\n}\n\n/** Plain, drawable, single-paint outlines whose SDF raster shows the same artwork. */\nexport function switchableRequests(\n resolved: readonly {\n readonly request: GlyphRequest\n readonly outline: WindfoilGlyphOutline | null\n }[],\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): GlyphRequest[] {\n return resolved.flatMap(({ request, outline }) => {\n const header = outline ? glyphs.get(request.key) : undefined\n return header &&\n header.monotonePieceCount > 0 &&\n !header.layers &&\n !header.clipBox &&\n !isEmojiCandidate(request.character)\n ? [request]\n : []\n })\n}\n\nexport function createSizeSwitch(\n threshold: number,\n keys: ReadonlySet<string>,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n ordinalsOf: (snapshot: DomLayoutSnapshot) => Float32Array,\n): WindfoilSizeSwitch {\n const below = uniform(threshold)\n const belowWithOverlap = uniform(threshold * OVERLAP)\n // One layout function, so both pipelines compile the same WGSL for the decision.\n const projectedEm = Fn<\n [Node<'vec4'>, Node<'vec4'>, Node<'vec4'>, Node<'vec2'>, Node<'float'>],\n Node<'float'>\n >(([clip, axisX, axisY, halfViewport, em]) => {\n const w = clip.w\n // Pixels per local unit along each axis (scaled by w²): the quotient rule on clip.xy / clip.w,\n // exact in orthographic and perspective views. Since w² > 0 on the taken branch, factoring\n // 1 / w² outside length() is exact and avoids scaling both 2-vectors before their norms.\n const jx = axisX.xy.mul(w).sub(clip.xy.mul(axisX.w)).mul(halfViewport).toConst()\n const jy = axisY.xy.mul(w).sub(clip.xy.mul(axisY.w)).mul(halfViewport).toConst()\n // The largest singular value of [jx jy]: independent of roll, mirroring and shear, and\n // free of the cancellation in the eigenvalue formula.\n const stretch = length(vec2(jx.x.add(jy.y), jx.y.sub(jy.x)))\n .add(length(vec2(jx.x.sub(jy.y), jx.y.add(jy.x))))\n .mul(0.5)\n return w.greaterThan(0).select(stretch.mul(em).div(w.mul(w)), float(BEHIND_EYE))\n }).setLayout({\n name: 'ultraProjectedEm',\n type: 'float',\n inputs: [\n { name: 'clip', type: 'vec4' },\n { name: 'axisX', type: 'vec4' },\n { name: 'axisY', type: 'vec4' },\n { name: 'halfViewport', type: 'vec2' },\n { name: 'em', type: 'float' },\n ],\n })\n const emPixels = (anchor: Node<'vec2'>, meta: Node<'vec3'>): Node<'float'> => {\n const modelViewProjection = cameraProjectionMatrix.mul(modelViewMatrix)\n return projectedEm(\n modelViewProjection.mul(vec4(anchor, meta.y, 1)),\n modelViewProjection.mul(vec4(1, 0, 0, 0)),\n modelViewProjection.mul(vec4(0, 1, 0, 0)),\n viewportSize.mul(0.5),\n meta.z,\n ).toConst()\n }\n // A zero em marks glyphs that never switch: missing outlines, colour and layered glyphs.\n const fixed = (meta: Node<'vec3'>): Node<'bool'> => meta.z.lessThanEqual(0)\n const derived = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n let withFontEm: WeakMap<DomLayoutSnapshot, DomLayoutSnapshot> | undefined\n return {\n keys,\n // A NaN em compares false: the SDF batch drops it and Windfoil keeps it.\n sdf: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(belowWithOverlap)),\n windfoil: (anchor, meta) => fixed(meta).or(emPixels(anchor, meta).lessThan(below).not()),\n layout(snapshot, fontEm = false) {\n const layouts = fontEm ? (withFontEm ??= new WeakMap()) : derived\n const cached = layouts.get(snapshot)\n if (cached) return cached\n const ordinals = ordinalsOf(snapshot)\n const result: DomLayoutSnapshot = {\n ...snapshot,\n sizeSwitched: true,\n glyphs: snapshot.glyphs.map((glyph, index): GlyphLayout => {\n const header = keys.has(glyph.glyphKey) ? glyphs.get(glyph.glyphKey) : undefined\n // Zero or below never switches; a dilating tone still reads the magnitude as the em.\n if (!header) {\n const em = fontEm ? fixedGlyphEm(glyph) : glyph.switchEm\n return { ...glyph, switchEm: em ? -Math.abs(em) : 0 }\n }\n const rect = windfoilGlyphRect(glyph, header)\n return {\n ...glyph,\n // Clamped above zero so a degenerate size still switches instead of meaning\n // \"never\", which would let both batches draw it.\n switchEm: Math.max(glyph.fontSize, 1e-30),\n motionOrigin: glyph.motionOrigin ?? [\n (rect[0] + rect[2]) / 2,\n (rect[1] + rect[3]) / 2,\n ordinals[index]!,\n ],\n }\n }),\n }\n layouts.set(snapshot, result)\n return result\n },\n }\n}\n"],"mappings":";;;;;;;;;;;AAgCA,IAAM,UAAU,IAAI,KAAK;;AAEzB,IAAM,aAAa;AAWnB,SAAgB,gBAAgB,OAAsB;CAEp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M,IAAI,CAAC,CAAC,GAAG,SAAS,QAAQ,IAAI,CAAC,CAAC,SAAS,gBAAgB,CAAC;EACvF,WAAW,QAAQ,SAAS,MAAM,IAAI,CAAC,CAAC,GAAG,SAAS,QAAQ,IAAI,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,IAAI,CAAC;EACvF,OAAO,UAAU,SAAS,OAAO;GAC/B,MAAM,UAAU,SAAU,+BAAe,IAAI,QAAQ,IAAK;GAC1D,MAAM,SAAS,QAAQ,IAAI,QAAQ;GACnC,IAAI,QAAQ,OAAO;GACnB,MAAM,WAAW,WAAW,QAAQ;GACpC,MAAM,SAA4B;IAChC,GAAG;IACH,cAAc;IACd,QAAQ,SAAS,OAAO,KAAK,OAAO,UAAuB;KACzD,MAAM,SAAS,KAAK,IAAI,MAAM,QAAQ,IAAI,OAAO,IAAI,MAAM,QAAQ,IAAI,KAAA;KAEvE,IAAI,CAAC,QAAQ;MACX,MAAM,KAAK,SAAS,aAAa,KAAK,IAAI,MAAM;MAChD,OAAO;OAAE,GAAG;OAAO,UAAU,KAAK,CAAC,KAAK,IAAI,EAAE,IAAI;MAAE;KACtD;KACA,MAAM,OAAO,kBAAkB,OAAO,MAAM;KAC5C,OAAO;MACL,GAAG;MAGH,UAAU,KAAK,IAAI,MAAM,UAAU,KAAK;MACxC,cAAc,MAAM,gBAAgB;QACjC,KAAK,KAAK,KAAK,MAAM;QACrB,KAAK,KAAK,KAAK,MAAM;OACtB,SAAS;MACX;KACF;IACF,CAAC;GACH;GACA,QAAQ,IAAI,UAAU,MAAM;GAC5B,OAAO;EACT;CACF;AACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type BufferAttribute, type StorageBufferNode, type WebGPURenderer } from 'three/webgpu';
|
|
2
|
-
import type { DomSdfOptions, GlyphRequest, WindfoilOptions, WindfoilOutlineProvider } from '../types.js';
|
|
2
|
+
import type { DomSdfOptions, GlyphRequest, SdfDropShadowOptions, SdfOutlineOptions, WindfoilOptions, WindfoilOutlineProvider } from '../types.js';
|
|
3
3
|
import { abortable, throwIfAborted } from './abortable.js';
|
|
4
|
+
import { type ResolvedOutline } from './resolveOutline.js';
|
|
4
5
|
import type * as WindfoilRequests from './requests.js';
|
|
5
6
|
import type { WindfoilStorage } from './WindfoilMaterial.js';
|
|
6
7
|
export { abortable, throwIfAborted };
|
|
@@ -34,11 +35,14 @@ export interface RetainedSlugStorage extends SlugStorage {
|
|
|
34
35
|
/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */
|
|
35
36
|
export type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>;
|
|
36
37
|
/**
|
|
37
|
-
* The effects that draw anything, or null: an outline unless its width
|
|
38
|
-
* at most zero, a drop shadow unless its opacity is at most zero. Values the SDF
|
|
39
|
-
* rejects, such as a negative width or a NaN, stay for it to reject.
|
|
38
|
+
* The effects that draw anything, or null: an outline unless both its width and blur are zero
|
|
39
|
+
* or its opacity at most zero, a drop shadow unless its opacity is at most zero. Values the SDF
|
|
40
|
+
* material rejects, such as a negative width or a NaN, stay for it to reject.
|
|
40
41
|
*/
|
|
41
|
-
export declare function drawnEffects({ outline, dropShadow }: TextEffects):
|
|
42
|
+
export declare function drawnEffects({ outline, dropShadow, }: TextEffects): {
|
|
43
|
+
outline?: SdfOutlineOptions;
|
|
44
|
+
dropShadow?: SdfDropShadowOptions;
|
|
45
|
+
} | null;
|
|
42
46
|
export declare function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void;
|
|
43
47
|
export declare function createRetainedWindfoilStorage(renderer: WebGPURenderer, data: {
|
|
44
48
|
curves: Float32Array;
|
|
@@ -62,12 +66,22 @@ export declare function createSlugStorage(renderer: WebGPURenderer, data: {
|
|
|
62
66
|
storageBytes: number;
|
|
63
67
|
dispose(): void;
|
|
64
68
|
};
|
|
69
|
+
export type ResolvedOutlineRecord = ResolvedOutline;
|
|
70
|
+
export declare function resolveOutlineRequestsFast(requests: readonly GlyphRequest[], options: WindfoilOptions & {
|
|
71
|
+
readonly outlineProvider: WindfoilOutlineProvider;
|
|
72
|
+
}, signal: AbortSignal, extensions: typeof WindfoilRequests | null): ResolvedOutline[] | Promise<ResolvedOutline[]>;
|
|
73
|
+
export interface PartitionedOutlines {
|
|
74
|
+
readonly missing: ResolvedOutlineRecord[];
|
|
75
|
+
readonly nonNull: (ResolvedOutlineRecord & {
|
|
76
|
+
outline: NonNullable<ResolvedOutlineRecord['outline']>;
|
|
77
|
+
})[];
|
|
78
|
+
readonly hasLayers: boolean;
|
|
79
|
+
readonly hasClipBox: boolean;
|
|
80
|
+
}
|
|
81
|
+
export declare function partitionResolvedOutlines(resolved: readonly ResolvedOutlineRecord[]): PartitionedOutlines;
|
|
65
82
|
export declare function resolveOutlineRequests(requests: readonly GlyphRequest[], options: WindfoilOptions & {
|
|
66
83
|
readonly outlineProvider: WindfoilOutlineProvider;
|
|
67
|
-
}, signal: AbortSignal, extensions: typeof WindfoilRequests | null): Promise<
|
|
68
|
-
request: GlyphRequest;
|
|
69
|
-
outline: Awaited<ReturnType<WindfoilOutlineProvider>>;
|
|
70
|
-
}[]>;
|
|
84
|
+
}, signal: AbortSignal, extensions: typeof WindfoilRequests | null): Promise<ResolvedOutlineRecord[]>;
|
|
71
85
|
export declare function collectMissingRequests(requests: readonly GlyphRequest[], covered: (key: string) => boolean): GlyphRequest[];
|
|
72
86
|
export declare function mergePreprocessStats<T extends {
|
|
73
87
|
readonly paintLayers: number;
|
package/dist/windfoil/storage.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { abortable, throwIfAborted } from "./abortable.js";
|
|
2
|
+
import { storeOutline } from "./resolveOutline.js";
|
|
2
3
|
import { StorageBufferAttribute } from "three/webgpu";
|
|
3
4
|
import { storage } from "three/tsl";
|
|
4
5
|
// src/windfoil/storage.ts
|
|
5
6
|
/**
|
|
6
|
-
* The effects that draw anything, or null: an outline unless its width
|
|
7
|
-
* at most zero, a drop shadow unless its opacity is at most zero. Values the SDF
|
|
8
|
-
* rejects, such as a negative width or a NaN, stay for it to reject.
|
|
7
|
+
* The effects that draw anything, or null: an outline unless both its width and blur are zero
|
|
8
|
+
* or its opacity at most zero, a drop shadow unless its opacity is at most zero. Values the SDF
|
|
9
|
+
* material rejects, such as a negative width or a NaN, stay for it to reject.
|
|
9
10
|
*/
|
|
10
11
|
function drawnEffects({ outline, dropShadow }) {
|
|
11
12
|
const drawn = {};
|
|
12
|
-
if (outline && outline.width !== 0 && !((outline.opacity ?? 1) <= 0)) drawn.outline = outline;
|
|
13
|
-
if (dropShadow && !((dropShadow.opacity ?? .5) <= 0)) drawn.dropShadow = dropShadow;
|
|
13
|
+
if (typeof outline === "object" && (outline.width !== 0 || (outline.blur ?? 0) > 0) && !((outline.opacity ?? 1) <= 0)) drawn.outline = outline;
|
|
14
|
+
if (typeof dropShadow === "object" && !((dropShadow.opacity ?? .5) <= 0)) drawn.dropShadow = dropShadow;
|
|
14
15
|
return drawn.outline ?? drawn.dropShadow ? drawn : null;
|
|
15
16
|
}
|
|
16
17
|
function disposeWindfoilStorage(renderer, attribute) {
|
|
@@ -105,8 +106,10 @@ function createRetainedCurveStorage(renderer, data, curveType, curveComponents,
|
|
|
105
106
|
throw error;
|
|
106
107
|
}
|
|
107
108
|
}
|
|
109
|
+
var VEC2_CURVES_SYM = Symbol.for("ultraTextVec2Curves");
|
|
108
110
|
function createRetainedWindfoilStorage(renderer, data, headroom) {
|
|
109
|
-
|
|
111
|
+
const isVec2 = data[VEC2_CURVES_SYM] === true;
|
|
112
|
+
return createRetainedCurveStorage(renderer, data, isVec2 ? "vec2" : "vec4", isVec2 ? 2 : 4, headroom);
|
|
110
113
|
}
|
|
111
114
|
function createRetainedSlugStorage(renderer, data, headroom) {
|
|
112
115
|
return createRetainedCurveStorage(renderer, data, "vec4", 4, headroom);
|
|
@@ -133,31 +136,47 @@ function createSlugStorage(renderer, data) {
|
|
|
133
136
|
}
|
|
134
137
|
};
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
request,
|
|
139
|
-
outline: await extensions.resolveShapeRequest(request, options, signal)
|
|
140
|
-
}))), signal);
|
|
141
|
-
const syncResolved = [];
|
|
139
|
+
function resolveOutlineRequestsFast(requests, options, signal, extensions) {
|
|
140
|
+
const resolved = new Array(requests.length);
|
|
142
141
|
let pending = null;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
request,
|
|
157
|
-
outline: out
|
|
158
|
-
});
|
|
142
|
+
try {
|
|
143
|
+
for (let i = 0; i < requests.length; i++) {
|
|
144
|
+
const request = requests[i];
|
|
145
|
+
const outline = extensions ? extensions.resolveShapeRequest(request, options, signal) : options.outlineProvider(request, signal);
|
|
146
|
+
const wait = storeOutline(resolved, i, request, outline);
|
|
147
|
+
if (wait) (pending ??= []).push(wait);
|
|
148
|
+
}
|
|
149
|
+
if (!pending) return resolved;
|
|
150
|
+
throwIfAborted(signal);
|
|
151
|
+
return abortable(Promise.all(pending).then(() => resolved), signal);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
if (pending) Promise.allSettled(pending);
|
|
154
|
+
throw error;
|
|
159
155
|
}
|
|
160
|
-
|
|
156
|
+
}
|
|
157
|
+
function partitionResolvedOutlines(resolved) {
|
|
158
|
+
const missing = [];
|
|
159
|
+
const nonNull = [];
|
|
160
|
+
let hasLayers = false;
|
|
161
|
+
let hasClipBox = false;
|
|
162
|
+
for (const item of resolved) {
|
|
163
|
+
const outline = item.outline;
|
|
164
|
+
if (outline === null) missing.push(item);
|
|
165
|
+
else {
|
|
166
|
+
nonNull.push(item);
|
|
167
|
+
if (outline.layers !== void 0) hasLayers = true;
|
|
168
|
+
if (outline.clipBox !== void 0) hasClipBox = true;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
missing,
|
|
173
|
+
nonNull,
|
|
174
|
+
hasLayers,
|
|
175
|
+
hasClipBox
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
async function resolveOutlineRequests(requests, options, signal, extensions) {
|
|
179
|
+
return resolveOutlineRequestsFast(requests, options, signal, extensions);
|
|
161
180
|
}
|
|
162
181
|
function collectMissingRequests(requests, covered) {
|
|
163
182
|
const missing = [];
|
|
@@ -181,6 +200,6 @@ function mergePreprocessStats(current, delta, uniqueGlyphs) {
|
|
|
181
200
|
duplication: monotonePieces > 0 ? bandedPieces / monotonePieces : current.duplication
|
|
182
201
|
};
|
|
183
202
|
}
|
|
184
|
-
export { abortable, collectMissingRequests, createRetainedSlugStorage, createRetainedWindfoilStorage, createSlugStorage, createWindfoilStorage, disposeWindfoilStorage, drawnEffects, mergePreprocessStats, resolveOutlineRequests, throwIfAborted };
|
|
203
|
+
export { abortable, collectMissingRequests, createRetainedSlugStorage, createRetainedWindfoilStorage, createSlugStorage, createWindfoilStorage, disposeWindfoilStorage, drawnEffects, mergePreprocessStats, partitionResolvedOutlines, resolveOutlineRequests, resolveOutlineRequestsFast, throwIfAborted };
|
|
185
204
|
|
|
186
205
|
//# sourceMappingURL=storage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","names":[],"sources":["../../src/windfoil/storage.ts"],"sourcesContent":["import {\n StorageBufferAttribute,\n type BufferAttribute,\n type StorageBufferNode,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type {\n DomSdfOptions,\n GlyphRequest,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './abortable.js'\nimport type * as WindfoilRequests from './requests.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n\nexport { abortable, throwIfAborted }\n\nexport interface WindfoilStorageHeadroom {\n readonly minCurveFloats?: number\n readonly minRowUints?: number\n readonly rowAlign?: number\n readonly maxCurveFloats?: number\n}\n\nexport interface RetainedWindfoilStorage extends WindfoilStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** Storage buffers retained by one vec4-packed Slug outline atlas. */\nexport interface SlugStorage {\n readonly curves: StorageBufferNode<'vec4'>\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface RetainedSlugStorage extends SlugStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */\nexport type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>\n/**\n * The effects that draw anything, or null: an outline unless its width is zero or its opacity\n * at most zero, a drop shadow unless its opacity is at most zero. Values the SDF material\n * rejects, such as a negative width or a NaN, stay for it to reject.\n */\nexport function drawnEffects({ outline, dropShadow }: TextEffects): TextEffects | null {\n const drawn: TextEffects = {}\n if (outline && outline.width !== 0 && !((outline.opacity ?? 1) <= 0)) drawn.outline = outline\n if (dropShadow && !((dropShadow.opacity ?? 0.5) <= 0)) drawn.dropShadow = dropShadow\n return (drawn.outline ?? drawn.dropShadow) ? drawn : null\n}\nexport function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void {\n attribute.dispose()\n const backend = renderer.backend as unknown as {\n has(object: object): boolean\n destroyAttribute(attribute: BufferAttribute): void\n }\n if (backend.has(attribute)) {\n backend.destroyAttribute(attribute)\n renderer.info.destroyAttribute(attribute)\n }\n}\nfunction backendHas(renderer: WebGPURenderer, attribute: BufferAttribute): boolean {\n return (\n (renderer.backend as unknown as { has?(object: object): boolean }).has?.(attribute) === true\n )\n}\n\nfunction alignUp(value: number, align: number): number {\n const rem = value % align\n return rem === 0 ? value : value + align - rem\n}\n\nfunction headroomCapacity(\n used: number,\n minExtra: number,\n align: number,\n maxAllowed: number,\n minNonEmpty: number,\n): number {\n const alignedMax = Math.max(align, Math.floor(maxAllowed / align) * align)\n if (used >= alignedMax) return Math.max(used, minNonEmpty)\n const target = alignUp(Math.max(Math.ceil(used * 1.5), used + minExtra, minNonEmpty), align)\n return Math.max(used, minNonEmpty, Math.min(target, alignedMax))\n}\n\nfunction createRetainedCurveStorage<T extends 'vec2' | 'vec4'>(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n curveType: T,\n curveComponents: 2 | 4,\n headroom?: WindfoilStorageHeadroom | false,\n): {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n readonly curves: StorageBufferNode<T>\n readonly rows: StorageBufferNode<'uint'>\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n} {\n const attributes: StorageBufferAttribute[] = []\n let disposed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n }\n try {\n let curvesData: Float32Array\n let rowsData: Uint32Array\n if (headroom) {\n const limits = (\n renderer.backend as unknown as {\n device?: { limits?: { maxStorageBufferBindingSize?: number; maxBufferSize?: number } }\n }\n ).device?.limits\n const maxBindingBytes = Math.min(\n limits?.maxStorageBufferBindingSize ?? 128 * 1024 * 1024,\n limits?.maxBufferSize ?? 256 * 1024 * 1024,\n )\n const curveBytesPerItem = curveComponents * 4\n const maxCurveFloats = Math.min(\n Math.floor(maxBindingBytes / curveBytesPerItem) * curveComponents,\n headroom.maxCurveFloats ?? Number.POSITIVE_INFINITY,\n )\n const rowAlign = headroom.rowAlign ?? 1\n const maxRowUints = Math.floor(maxBindingBytes / (4 * rowAlign)) * rowAlign\n const capCurves = headroomCapacity(\n data.curves.length,\n headroom.minCurveFloats ?? 4096,\n curveComponents,\n maxCurveFloats,\n curveComponents,\n )\n const capRows = headroomCapacity(\n data.rows.length,\n headroom.minRowUints ?? 512,\n rowAlign,\n maxRowUints,\n 1,\n )\n if (capCurves === data.curves.length && data.curves.length > 0) {\n curvesData = data.curves\n } else {\n curvesData = new Float32Array(capCurves)\n if (data.curves.length > 0) curvesData.set(data.curves)\n }\n if (capRows === data.rows.length && data.rows.length > 0) {\n rowsData = data.rows\n } else {\n rowsData = new Uint32Array(capRows)\n if (data.rows.length > 0) rowsData.set(data.rows)\n }\n } else {\n if (data.curves.length === 0) {\n curvesData = new Float32Array(curveComponents)\n } else if (data.curves.length % curveComponents !== 0) {\n curvesData = new Float32Array(alignUp(data.curves.length, curveComponents))\n curvesData.set(data.curves)\n } else {\n curvesData = data.curves\n }\n rowsData = data.rows.length ? data.rows : new Uint32Array(1)\n }\n const curveAttribute = new StorageBufferAttribute(curvesData, curveComponents)\n attributes.push(curveAttribute)\n const rowAttribute = new StorageBufferAttribute(rowsData, 1)\n attributes.push(rowAttribute)\n return {\n storageBytes: headroom\n ? curvesData.byteLength + rowsData.byteLength\n : data.curves.byteLength + data.rows.byteLength,\n curveCapacityFloats: curvesData.length,\n rowCapacityUints: rowsData.length,\n curves: storage(curveAttribute, curveType, curveAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilCurves'),\n rows: storage(rowAttribute, 'uint', rowAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilRows'),\n writeCurves(offsetFloats, source) {\n if (source.length === 0) return\n curvesData.set(source, offsetFloats)\n if (backendHas(renderer, curveAttribute)) {\n curveAttribute.addUpdateRange(offsetFloats, source.length)\n curveAttribute.needsUpdate = true\n }\n },\n writeRows(offsetUints, source) {\n if (source.length === 0) return\n rowsData.set(source, offsetUints)\n if (backendHas(renderer, rowAttribute)) {\n rowAttribute.addUpdateRange(offsetUints, source.length)\n rowAttribute.needsUpdate = true\n }\n },\n dispose,\n }\n } catch (error) {\n dispose()\n throw error\n }\n}\n\nexport function createRetainedWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedWindfoilStorage {\n return createRetainedCurveStorage(renderer, data, 'vec2', 2, headroom)\n}\n\nexport function createRetainedSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedSlugStorage {\n return createRetainedCurveStorage(renderer, data, 'vec4', 4, headroom)\n}\n\nexport function createWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): WindfoilStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedWindfoilStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport function createSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): SlugStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedSlugStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport async function resolveOutlineRequests(\n requests: readonly GlyphRequest[],\n options: WindfoilOptions & { readonly outlineProvider: WindfoilOutlineProvider },\n signal: AbortSignal,\n extensions: typeof WindfoilRequests | null,\n): Promise<{ request: GlyphRequest; outline: Awaited<ReturnType<WindfoilOutlineProvider>> }[]> {\n if (extensions) {\n return abortable(\n Promise.all(\n requests.map(async (request) => ({\n request,\n outline: await extensions.resolveShapeRequest(request, options, signal),\n })),\n ),\n signal,\n )\n }\n const syncResolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<WindfoilOutlineProvider>>\n }[] = []\n let pending: Promise<(typeof syncResolved)[number]>[] | null = null\n for (const request of requests) {\n const out = options.outlineProvider(request, signal)\n if (out instanceof Promise) {\n pending ??= syncResolved.map((item) => Promise.resolve(item))\n pending.push(out.then((outline) => ({ request, outline })))\n } else if (pending) {\n pending.push(Promise.resolve({ request, outline: out }))\n } else {\n syncResolved.push({ request, outline: out })\n }\n }\n return pending ? abortable(Promise.all(pending), signal) : syncResolved\n}\n\nexport function collectMissingRequests(\n requests: readonly GlyphRequest[],\n covered: (key: string) => boolean,\n): GlyphRequest[] {\n const missing: GlyphRequest[] = []\n const seen = new Set<string>()\n for (const req of requests) {\n if (seen.has(req.key) || covered(req.key)) continue\n seen.add(req.key)\n missing.push(req)\n }\n return missing\n}\n\nexport function mergePreprocessStats<\n T extends {\n readonly paintLayers: number\n readonly uniqueGlyphs: number\n readonly monotonePieces: number\n readonly bandCount: number\n readonly bandedPieces: number\n readonly duplication: number\n },\n>(current: T, delta: T, uniqueGlyphs: number): T {\n const monotonePieces = current.monotonePieces + delta.monotonePieces\n const bandedPieces = current.bandedPieces + delta.bandedPieces\n return {\n paintLayers: current.paintLayers + delta.paintLayers,\n uniqueGlyphs,\n monotonePieces,\n bandCount: current.bandCount + delta.bandCount,\n bandedPieces,\n duplication: monotonePieces > 0 ? bandedPieces / monotonePieces : current.duplication,\n } as T\n}\n"],"mappings":";;;;;;;;;AAyDA,SAAgB,aAAa,EAAE,SAAS,cAA+C;CACrF,MAAM,QAAqB,CAAC;CAC5B,IAAI,WAAW,QAAQ,UAAU,KAAK,GAAG,QAAQ,WAAW,MAAM,IAAI,MAAM,UAAU;CACtF,IAAI,cAAc,GAAG,WAAW,WAAW,OAAQ,IAAI,MAAM,aAAa;CAC1E,OAAQ,MAAM,WAAW,MAAM,aAAc,QAAQ;AACvD;AACA,SAAgB,uBAAuB,UAA0B,WAAkC;CACjG,UAAU,QAAQ;CAClB,MAAM,UAAU,SAAS;CAIzB,IAAI,QAAQ,IAAI,SAAS,GAAG;EAC1B,QAAQ,iBAAiB,SAAS;EAClC,SAAS,KAAK,iBAAiB,SAAS;CAC1C;AACF;AACA,SAAS,WAAW,UAA0B,WAAqC;CACjF,OACG,SAAS,QAAyD,MAAM,SAAS,MAAM;AAE5F;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M,aAAa;IAAE;IAAS;GAAQ,EAAE,CAAC;EAC5D,OAAO,IAAI,SACT,QAAQ,KAAK,QAAQ,QAAQ;GAAE;GAAS,SAAS;EAAI,CAAC,CAAC;OAEvD,aAAa,KAAK;GAAE;GAAS,SAAS;EAAI,CAAC;CAE/C;CACA,OAAO,UAAU,UAAU,QAAQ,IAAI,OAAO,GAAG,MAAM,IAAI;AAC7D;AAEA,SAAgB,uBACd,UACA,SACgB;CAChB,MAAM,UAA0B,CAAC;CACjC,MAAM,uBAAO,IAAI,IAAY;CAC7B,KAAK,MAAM,OAAO,UAAU;EAC1B,IAAI,KAAK,IAAI,IAAI,GAAG,KAAK,QAAQ,IAAI,GAAG,GAAG;EAC3C,KAAK,IAAI,IAAI,GAAG;EAChB,QAAQ,KAAK,GAAG;CAClB;CACA,OAAO;AACT;AAEA,SAAgB,qBASd,SAAY,OAAU,cAAyB;CAC/C,MAAM,iBAAiB,QAAQ,iBAAiB,MAAM;CACtD,MAAM,eAAe,QAAQ,eAAe,MAAM;CAClD,OAAO;EACL,aAAa,QAAQ,cAAc,MAAM;EACzC;EACA;EACA,WAAW,QAAQ,YAAY,MAAM;EACrC;EACA,aAAa,iBAAiB,IAAI,eAAe,iBAAiB,QAAQ;CAC5E;AACF"}
|
|
1
|
+
{"version":3,"file":"storage.js","names":[],"sources":["../../src/windfoil/storage.ts"],"sourcesContent":["import {\n StorageBufferAttribute,\n type BufferAttribute,\n type StorageBufferNode,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport { storage } from 'three/tsl'\nimport type {\n DomSdfOptions,\n GlyphRequest,\n SdfDropShadowOptions,\n SdfOutlineOptions,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport { abortable, throwIfAborted } from './abortable.js'\nimport { storeOutline, type ResolvedOutline } from './resolveOutline.js'\nimport type * as WindfoilRequests from './requests.js'\nimport type { WindfoilStorage } from './WindfoilMaterial.js'\n\nexport { abortable, throwIfAborted }\n\nexport interface WindfoilStorageHeadroom {\n readonly minCurveFloats?: number\n readonly minRowUints?: number\n readonly rowAlign?: number\n readonly maxCurveFloats?: number\n}\n\nexport interface RetainedWindfoilStorage extends WindfoilStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** Storage buffers retained by one vec4-packed Slug outline atlas. */\nexport interface SlugStorage {\n readonly curves: StorageBufferNode<'vec4'>\n readonly rows: StorageBufferNode<'uint'>\n}\n\nexport interface RetainedSlugStorage extends SlugStorage {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n}\n\n/** The text effects of `DomSdfOptions` that an SDF underlay draws for analytic text. */\nexport type TextEffects = Pick<DomSdfOptions, 'outline' | 'dropShadow'>\n/**\n * The effects that draw anything, or null: an outline unless both its width and blur are zero\n * or its opacity at most zero, a drop shadow unless its opacity is at most zero. Values the SDF\n * material rejects, such as a negative width or a NaN, stay for it to reject.\n */\nexport function drawnEffects({\n outline,\n dropShadow,\n}: TextEffects): { outline?: SdfOutlineOptions; dropShadow?: SdfDropShadowOptions } | null {\n const drawn: { outline?: SdfOutlineOptions; dropShadow?: SdfDropShadowOptions } = {}\n if (\n typeof outline === 'object' &&\n (outline.width !== 0 || (outline.blur ?? 0) > 0) &&\n !((outline.opacity ?? 1) <= 0)\n ) {\n drawn.outline = outline\n }\n if (typeof dropShadow === 'object' && !((dropShadow.opacity ?? 0.5) <= 0)) {\n drawn.dropShadow = dropShadow\n }\n return (drawn.outline ?? drawn.dropShadow) ? drawn : null\n}\nexport function disposeWindfoilStorage(renderer: WebGPURenderer, attribute: BufferAttribute): void {\n attribute.dispose()\n const backend = renderer.backend as unknown as {\n has(object: object): boolean\n destroyAttribute(attribute: BufferAttribute): void\n }\n if (backend.has(attribute)) {\n backend.destroyAttribute(attribute)\n renderer.info.destroyAttribute(attribute)\n }\n}\nfunction backendHas(renderer: WebGPURenderer, attribute: BufferAttribute): boolean {\n return (\n (renderer.backend as unknown as { has?(object: object): boolean }).has?.(attribute) === true\n )\n}\n\nfunction alignUp(value: number, align: number): number {\n const rem = value % align\n return rem === 0 ? value : value + align - rem\n}\n\nfunction headroomCapacity(\n used: number,\n minExtra: number,\n align: number,\n maxAllowed: number,\n minNonEmpty: number,\n): number {\n const alignedMax = Math.max(align, Math.floor(maxAllowed / align) * align)\n if (used >= alignedMax) return Math.max(used, minNonEmpty)\n const target = alignUp(Math.max(Math.ceil(used * 1.5), used + minExtra, minNonEmpty), align)\n return Math.max(used, minNonEmpty, Math.min(target, alignedMax))\n}\n\nfunction createRetainedCurveStorage<T extends 'vec2' | 'vec4'>(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n curveType: T,\n curveComponents: 2 | 4,\n headroom?: WindfoilStorageHeadroom | false,\n): {\n readonly storageBytes: number\n readonly curveCapacityFloats: number\n readonly rowCapacityUints: number\n readonly curves: StorageBufferNode<T>\n readonly rows: StorageBufferNode<'uint'>\n writeCurves(offsetFloats: number, source: Float32Array): void\n writeRows(offsetUints: number, source: Uint32Array): void\n dispose(): void\n} {\n const attributes: StorageBufferAttribute[] = []\n let disposed = false\n const dispose = (): void => {\n if (disposed) return\n disposed = true\n for (const attribute of attributes) disposeWindfoilStorage(renderer, attribute)\n }\n try {\n let curvesData: Float32Array\n let rowsData: Uint32Array\n if (headroom) {\n const limits = (\n renderer.backend as unknown as {\n device?: { limits?: { maxStorageBufferBindingSize?: number; maxBufferSize?: number } }\n }\n ).device?.limits\n const maxBindingBytes = Math.min(\n limits?.maxStorageBufferBindingSize ?? 128 * 1024 * 1024,\n limits?.maxBufferSize ?? 256 * 1024 * 1024,\n )\n const curveBytesPerItem = curveComponents * 4\n const maxCurveFloats = Math.min(\n Math.floor(maxBindingBytes / curveBytesPerItem) * curveComponents,\n headroom.maxCurveFloats ?? Number.POSITIVE_INFINITY,\n )\n const rowAlign = headroom.rowAlign ?? 1\n const maxRowUints = Math.floor(maxBindingBytes / (4 * rowAlign)) * rowAlign\n const capCurves = headroomCapacity(\n data.curves.length,\n headroom.minCurveFloats ?? 4096,\n curveComponents,\n maxCurveFloats,\n curveComponents,\n )\n const capRows = headroomCapacity(\n data.rows.length,\n headroom.minRowUints ?? 512,\n rowAlign,\n maxRowUints,\n 1,\n )\n if (capCurves === data.curves.length && data.curves.length > 0) {\n curvesData = data.curves\n } else {\n curvesData = new Float32Array(capCurves)\n if (data.curves.length > 0) curvesData.set(data.curves)\n }\n if (capRows === data.rows.length && data.rows.length > 0) {\n rowsData = data.rows\n } else {\n rowsData = new Uint32Array(capRows)\n if (data.rows.length > 0) rowsData.set(data.rows)\n }\n } else {\n if (data.curves.length === 0) {\n curvesData = new Float32Array(curveComponents)\n } else if (data.curves.length % curveComponents !== 0) {\n curvesData = new Float32Array(alignUp(data.curves.length, curveComponents))\n curvesData.set(data.curves)\n } else {\n curvesData = data.curves\n }\n rowsData = data.rows.length ? data.rows : new Uint32Array(1)\n }\n const curveAttribute = new StorageBufferAttribute(curvesData, curveComponents)\n attributes.push(curveAttribute)\n const rowAttribute = new StorageBufferAttribute(rowsData, 1)\n attributes.push(rowAttribute)\n return {\n storageBytes: headroom\n ? curvesData.byteLength + rowsData.byteLength\n : data.curves.byteLength + data.rows.byteLength,\n curveCapacityFloats: curvesData.length,\n rowCapacityUints: rowsData.length,\n curves: storage(curveAttribute, curveType, curveAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilCurves'),\n rows: storage(rowAttribute, 'uint', rowAttribute.count)\n .toReadOnly()\n .setName('ultraWindfoilRows'),\n writeCurves(offsetFloats, source) {\n if (source.length === 0) return\n curvesData.set(source, offsetFloats)\n if (backendHas(renderer, curveAttribute)) {\n curveAttribute.addUpdateRange(offsetFloats, source.length)\n curveAttribute.needsUpdate = true\n }\n },\n writeRows(offsetUints, source) {\n if (source.length === 0) return\n rowsData.set(source, offsetUints)\n if (backendHas(renderer, rowAttribute)) {\n rowAttribute.addUpdateRange(offsetUints, source.length)\n rowAttribute.needsUpdate = true\n }\n },\n dispose,\n }\n } catch (error) {\n dispose()\n throw error\n }\n}\n\nconst VEC2_CURVES_SYM = Symbol.for('ultraTextVec2Curves')\n\nexport function createRetainedWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedWindfoilStorage {\n const isVec2 = (data as { readonly [VEC2_CURVES_SYM]?: boolean })[VEC2_CURVES_SYM] === true\n return createRetainedCurveStorage(\n renderer,\n data,\n isVec2 ? 'vec2' : 'vec4',\n isVec2 ? 2 : 4,\n headroom,\n )\n}\n\nexport function createRetainedSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n headroom?: WindfoilStorageHeadroom | false,\n): RetainedSlugStorage {\n return createRetainedCurveStorage(renderer, data, 'vec4', 4, headroom)\n}\n\nexport function createWindfoilStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): WindfoilStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedWindfoilStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport function createSlugStorage(\n renderer: WebGPURenderer,\n data: { curves: Float32Array; rows: Uint32Array },\n): SlugStorage & { storageBytes: number; dispose(): void } {\n const retained = createRetainedSlugStorage(renderer, data)\n return {\n storageBytes: retained.storageBytes,\n curves: retained.curves,\n rows: retained.rows,\n dispose: (): void => {\n retained.dispose()\n },\n }\n}\n\nexport type ResolvedOutlineRecord = ResolvedOutline\n\nexport function resolveOutlineRequestsFast(\n requests: readonly GlyphRequest[],\n options: WindfoilOptions & { readonly outlineProvider: WindfoilOutlineProvider },\n signal: AbortSignal,\n extensions: typeof WindfoilRequests | null,\n): ResolvedOutline[] | Promise<ResolvedOutline[]> {\n const resolved = new Array<ResolvedOutline>(requests.length)\n let pending: Promise<void>[] | null = null\n try {\n for (let i = 0; i < requests.length; i++) {\n const request = requests[i]!\n const outline = extensions\n ? extensions.resolveShapeRequest(request, options, signal)\n : options.outlineProvider(request, signal)\n const wait = storeOutline(resolved, i, request, outline)\n if (wait) (pending ??= []).push(wait)\n }\n if (!pending) return resolved\n throwIfAborted(signal)\n return abortable(\n Promise.all(pending).then(() => resolved),\n signal,\n )\n } catch (error) {\n // A later provider can throw while earlier promises are still outstanding.\n if (pending) void Promise.allSettled(pending)\n throw error\n }\n}\n\nexport interface PartitionedOutlines {\n readonly missing: ResolvedOutlineRecord[]\n readonly nonNull: (ResolvedOutlineRecord & {\n outline: NonNullable<ResolvedOutlineRecord['outline']>\n })[]\n readonly hasLayers: boolean\n readonly hasClipBox: boolean\n}\n\nexport function partitionResolvedOutlines(\n resolved: readonly ResolvedOutlineRecord[],\n): PartitionedOutlines {\n const missing: ResolvedOutlineRecord[] = []\n const nonNull: (ResolvedOutlineRecord & {\n outline: NonNullable<ResolvedOutlineRecord['outline']>\n })[] = []\n let hasLayers = false\n let hasClipBox = false\n for (const item of resolved) {\n const outline = item.outline\n if (outline === null) {\n missing.push(item)\n } else {\n nonNull.push(\n item as ResolvedOutlineRecord & { outline: NonNullable<ResolvedOutlineRecord['outline']> },\n )\n if (outline.layers !== undefined) hasLayers = true\n if (outline.clipBox !== undefined) hasClipBox = true\n }\n }\n return { missing, nonNull, hasLayers, hasClipBox }\n}\n\nexport async function resolveOutlineRequests(\n requests: readonly GlyphRequest[],\n options: WindfoilOptions & { readonly outlineProvider: WindfoilOutlineProvider },\n signal: AbortSignal,\n extensions: typeof WindfoilRequests | null,\n): Promise<ResolvedOutlineRecord[]> {\n return resolveOutlineRequestsFast(requests, options, signal, extensions)\n}\n\nexport function collectMissingRequests(\n requests: readonly GlyphRequest[],\n covered: (key: string) => boolean,\n): GlyphRequest[] {\n const missing: GlyphRequest[] = []\n const seen = new Set<string>()\n for (const req of requests) {\n if (seen.has(req.key) || covered(req.key)) continue\n seen.add(req.key)\n missing.push(req)\n }\n return missing\n}\n\nexport function mergePreprocessStats<\n T extends {\n readonly paintLayers: number\n readonly uniqueGlyphs: number\n readonly monotonePieces: number\n readonly bandCount: number\n readonly bandedPieces: number\n readonly duplication: number\n },\n>(current: T, delta: T, uniqueGlyphs: number): T {\n const monotonePieces = current.monotonePieces + delta.monotonePieces\n const bandedPieces = current.bandedPieces + delta.bandedPieces\n return {\n paintLayers: current.paintLayers + delta.paintLayers,\n uniqueGlyphs,\n monotonePieces,\n bandCount: current.bandCount + delta.bandCount,\n bandedPieces,\n duplication: monotonePieces > 0 ? bandedPieces / monotonePieces : current.duplication,\n } as T\n}\n"],"mappings":";;;;;;;;;;AA4DA,SAAgB,aAAa,EAC3B,SACA,cACyF;CACzF,MAAM,QAA4E,CAAC;CACnF,IACE,OAAO,YAAY,aAClB,QAAQ,UAAU,MAAM,QAAQ,QAAQ,KAAK,MAC9C,GAAG,QAAQ,WAAW,MAAM,IAE5B,MAAM,UAAU;CAElB,IAAI,OAAO,eAAe,YAAY,GAAG,WAAW,WAAW,OAAQ,IACrE,MAAM,aAAa;CAErB,OAAQ,MAAM,WAAW,MAAM,aAAc,QAAQ;AACvD;AACA,SAAgB,uBAAuB,UAA0B,WAAkC;CACjG,UAAU,QAAQ;CAClB,MAAM,UAAU,SAAS;CAIzB,IAAI,QAAQ,IAAI,SAAS,GAAG;EAC1B,QAAQ,iBAAiB,SAAS;EAClC,SAAS,KAAK,iBAAiB,SAAS;CAC1C;AACF;AACA,SAAS,WAAW,UAA0B,WAAqC;CACjF,OACG,SAAS,QAAyD,MAAM,SAAS,MAAM;AAE5F;AAEA,SAAS,QAAQ,OAAe,OAAuB;CACrD,MAAM,MAAM,QAAQ;CACpB,OAAO,QAAQ,IAAI,QAAQ,QAAQ,QAAQ;AAC7C;AAEA,SAAS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