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
package/dist/slug/vanillaCore.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { resolveDomTextTone } from "../dom/tone.js";
|
|
2
|
+
import { snapshotFlags } from "../dom/markup.js";
|
|
2
3
|
import { collectDomSnapshot } from "../dom/snapshot.js";
|
|
3
|
-
import { layoutSignatureOf } from "../dom/layoutSignature.js";
|
|
4
4
|
import { classNames, copyTextOptions, createTextSource, cssDeclarations } from "../dom/textHost.js";
|
|
5
|
+
import { layoutSignatureOf } from "../dom/layoutSignature.js";
|
|
6
|
+
import { packDecorationInstances, updateDecorationInstances } from "../atlas/vanillaExtras.js";
|
|
7
|
+
import { storeOutline } from "../windfoil/resolveOutline.js";
|
|
5
8
|
import { preprocessSlugGlyphsBatch } from "./preprocessCore.js";
|
|
6
9
|
// src/slug/vanillaCore.ts
|
|
7
10
|
function resolveSlugGpuDevice(source) {
|
|
@@ -46,52 +49,53 @@ async function resolveVanillaSlugOutlines(requests, provider, signal) {
|
|
|
46
49
|
const resolved = new Array(requests.length);
|
|
47
50
|
let svgToOutlines;
|
|
48
51
|
const pending = [];
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
outline: null
|
|
57
|
-
};
|
|
58
|
-
else {
|
|
59
|
-
if (!svgToOutlines) {
|
|
60
|
-
({svgToWindfoilOutlines: svgToOutlines} = await import("../windfoil/svg/convert.js"));
|
|
61
|
-
signal.throwIfAborted();
|
|
62
|
-
}
|
|
63
|
-
const svg = svgToOutlines(shape.paths, {
|
|
64
|
-
em: {
|
|
65
|
-
unitsPerEm: 1e3,
|
|
66
|
-
ascent: shape.box[1],
|
|
67
|
-
descent: 0,
|
|
68
|
-
advance: shape.box[0]
|
|
69
|
-
},
|
|
70
|
-
viewBox: [
|
|
71
|
-
0,
|
|
72
|
-
0,
|
|
73
|
-
shape.box[0],
|
|
74
|
-
shape.box[1]
|
|
75
|
-
],
|
|
76
|
-
preserveAspectRatio: "none"
|
|
77
|
-
});
|
|
78
|
-
resolved[i] = {
|
|
52
|
+
try {
|
|
53
|
+
for (let i = 0; i < requests.length; i++) {
|
|
54
|
+
signal.throwIfAborted();
|
|
55
|
+
const request = requests[i];
|
|
56
|
+
if (request.shape) {
|
|
57
|
+
const shape = request.shape;
|
|
58
|
+
if (shape.bitmap || shape.paths.some((path) => path.stroke ?? path.clip)) resolved[i] = {
|
|
79
59
|
request,
|
|
80
|
-
outline:
|
|
60
|
+
outline: null
|
|
81
61
|
};
|
|
62
|
+
else {
|
|
63
|
+
if (!svgToOutlines) {
|
|
64
|
+
if (pending.length) Promise.allSettled(pending);
|
|
65
|
+
({svgToWindfoilOutlines: svgToOutlines} = await import("../windfoil/svg/convert.js"));
|
|
66
|
+
signal.throwIfAborted();
|
|
67
|
+
}
|
|
68
|
+
const svg = svgToOutlines(shape.paths, {
|
|
69
|
+
em: {
|
|
70
|
+
unitsPerEm: 1e3,
|
|
71
|
+
ascent: shape.box[1],
|
|
72
|
+
descent: 0,
|
|
73
|
+
advance: shape.box[0]
|
|
74
|
+
},
|
|
75
|
+
viewBox: [
|
|
76
|
+
0,
|
|
77
|
+
0,
|
|
78
|
+
shape.box[0],
|
|
79
|
+
shape.box[1]
|
|
80
|
+
],
|
|
81
|
+
preserveAspectRatio: "none"
|
|
82
|
+
});
|
|
83
|
+
resolved[i] = {
|
|
84
|
+
request,
|
|
85
|
+
outline: svg.warnings.some((w) => w.code === "evenodd-ambiguous") ? null : svg.outline
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
continue;
|
|
82
89
|
}
|
|
83
|
-
|
|
90
|
+
const wait = storeOutline(resolved, i, request, provider(request, signal));
|
|
91
|
+
if (wait) pending.push(wait);
|
|
84
92
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
};
|
|
91
|
-
}));
|
|
93
|
+
if (pending.length) await Promise.all(pending);
|
|
94
|
+
signal.throwIfAborted();
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (pending.length) Promise.allSettled(pending);
|
|
97
|
+
throw error;
|
|
92
98
|
}
|
|
93
|
-
if (pending.length > 0) await Promise.all(pending);
|
|
94
|
-
signal.throwIfAborted();
|
|
95
99
|
return resolved;
|
|
96
100
|
}
|
|
97
101
|
async function buildVanillaSlugAtlas(deviceOrRenderer, requests, options = {}) {
|
|
@@ -317,8 +321,13 @@ function byte(value) {
|
|
|
317
321
|
if (value >= 1) return 255;
|
|
318
322
|
return value * 255 + .5 | 0;
|
|
319
323
|
}
|
|
320
|
-
function
|
|
321
|
-
return
|
|
324
|
+
function isVanillaDomSnapshot(snapshot) {
|
|
325
|
+
return ((snapshotFlags.get(snapshot) ?? 0) & 2) !== 0;
|
|
326
|
+
}
|
|
327
|
+
function needsVanillaRunMotion(snapshot) {
|
|
328
|
+
const flags = snapshotFlags.get(snapshot);
|
|
329
|
+
if (flags !== void 0) return (flags & 1) !== 0;
|
|
330
|
+
return snapshot.textShaping === "browser" || snapshot.glyphs.some((glyph) => glyph.motionOrigin !== void 0);
|
|
322
331
|
}
|
|
323
332
|
var scratchSlugRect = [
|
|
324
333
|
0,
|
|
@@ -385,19 +394,47 @@ function writeSlugLayer(glyph, header, layer, index, ordinal, target, glyphRect)
|
|
|
385
394
|
layers[offset + 3] = paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : paint?.paintKind ?? 0;
|
|
386
395
|
}
|
|
387
396
|
}
|
|
388
|
-
function
|
|
389
|
-
let
|
|
397
|
+
function measureSlugLayout(snapshot, atlas) {
|
|
398
|
+
let layered = atlas.layered;
|
|
399
|
+
let metaItemSize = snapshot.sizeSwitched ? 3 : 2;
|
|
400
|
+
if (!layered && metaItemSize === 2 && isVanillaDomSnapshot(snapshot) && !needsVanillaRunMotion(snapshot)) {
|
|
401
|
+
let allPlainSingle = true;
|
|
402
|
+
for (const req of snapshot.requests) {
|
|
403
|
+
const h = atlas.glyphs.get(req.key);
|
|
404
|
+
if (!h?.monotonePieceCount || (h.layers?.length ?? 1) > 1) {
|
|
405
|
+
allPlainSingle = false;
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
if (allPlainSingle) {
|
|
410
|
+
const len = snapshot.glyphs.length;
|
|
411
|
+
return {
|
|
412
|
+
count: len,
|
|
413
|
+
drawable: len,
|
|
414
|
+
metaItemSize: 2,
|
|
415
|
+
layered: false
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
let layerCount = 0;
|
|
390
420
|
let drawable = 0;
|
|
421
|
+
let prevKey;
|
|
422
|
+
let prevHeader;
|
|
391
423
|
for (const glyph of snapshot.glyphs) {
|
|
392
|
-
|
|
424
|
+
if (glyph.motionOrigin) layered = true;
|
|
425
|
+
if (glyph.switchEm !== void 0) metaItemSize = 3;
|
|
426
|
+
const key = glyph.glyphKey;
|
|
427
|
+
const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = atlas.glyphs.get(key));
|
|
393
428
|
if (header?.monotonePieceCount) {
|
|
394
429
|
drawable++;
|
|
395
|
-
|
|
430
|
+
layerCount += header.layers?.length ?? 1;
|
|
396
431
|
}
|
|
397
432
|
}
|
|
398
433
|
return {
|
|
399
|
-
|
|
400
|
-
drawable
|
|
434
|
+
count: layered ? layerCount : drawable,
|
|
435
|
+
drawable,
|
|
436
|
+
metaItemSize,
|
|
437
|
+
layered
|
|
401
438
|
};
|
|
402
439
|
}
|
|
403
440
|
function populateSlugInstances(snapshot, glyphs, target) {
|
|
@@ -406,8 +443,11 @@ function populateSlugInstances(snapshot, glyphs, target) {
|
|
|
406
443
|
let maxSequence = 0;
|
|
407
444
|
let minZ = 0;
|
|
408
445
|
let maxZ = 0;
|
|
446
|
+
let prevKey;
|
|
447
|
+
let prevHeader;
|
|
409
448
|
for (const glyph of snapshot.glyphs) {
|
|
410
|
-
const
|
|
449
|
+
const key = glyph.glyphKey;
|
|
450
|
+
const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = glyphs.get(key));
|
|
411
451
|
if (!header?.monotonePieceCount) continue;
|
|
412
452
|
const ordinal = glyph.motionOrigin?.[2] ?? drawable;
|
|
413
453
|
const rect = fillSlugGlyphRect(glyph, header, scratchSlugRect);
|
|
@@ -430,9 +470,7 @@ function populateSlugInstances(snapshot, glyphs, target) {
|
|
|
430
470
|
};
|
|
431
471
|
}
|
|
432
472
|
function packSlugGlyphInstances(snapshot, atlas, motionPadding = 0) {
|
|
433
|
-
const
|
|
434
|
-
const { instances: count, drawable } = countSlugLayout(snapshot, atlas.glyphs, layered);
|
|
435
|
-
const metaItemSize = metaSize(snapshot);
|
|
473
|
+
const { count, drawable, metaItemSize, layered } = measureSlugLayout(snapshot, atlas);
|
|
436
474
|
const out = {
|
|
437
475
|
count,
|
|
438
476
|
drawableCount: drawable,
|
|
@@ -455,10 +493,8 @@ function packSlugGlyphInstances(snapshot, atlas, motionPadding = 0) {
|
|
|
455
493
|
return out;
|
|
456
494
|
}
|
|
457
495
|
function updateSlugGlyphInstances(instances, snapshot, atlas, motionPadding = 0) {
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
460
|
-
const { instances: count, drawable } = countSlugLayout(snapshot, atlas.glyphs, layered);
|
|
461
|
-
if (count !== instances.count || drawable !== instances.drawableCount) return null;
|
|
496
|
+
const { count, drawable, metaItemSize, layered } = measureSlugLayout(snapshot, atlas);
|
|
497
|
+
if (count !== instances.count || drawable !== instances.drawableCount || metaItemSize !== instances.metaItemSize || layered !== instances.layered) return null;
|
|
462
498
|
const { maxSequence, minZ, maxZ } = populateSlugInstances(snapshot, atlas.glyphs, instances);
|
|
463
499
|
instances.maxSequence = maxSequence;
|
|
464
500
|
instances.bounds = computeInstanceBounds(snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
@@ -516,106 +552,6 @@ function updateRectInstances(instances, snapshot, receiveShadow = instances.rece
|
|
|
516
552
|
instances.bounds = computeInstanceBounds(snapshot.width, snapshot.height, 0, minZ, maxZ);
|
|
517
553
|
return true;
|
|
518
554
|
}
|
|
519
|
-
function sameDecoration(a, b) {
|
|
520
|
-
return a.line === b.line && a.offset === b.offset && a.thickness === b.thickness && a.color.every((v, i) => v === b.color[i]);
|
|
521
|
-
}
|
|
522
|
-
function decorationRecords(snapshot, drawable) {
|
|
523
|
-
const glyphs = snapshot.glyphs;
|
|
524
|
-
const records = [];
|
|
525
|
-
if (!glyphs.some((glyph) => glyph.decorations?.length)) return records;
|
|
526
|
-
let glyphIndex = 0;
|
|
527
|
-
let motionIndex = -1;
|
|
528
|
-
let previousGroup;
|
|
529
|
-
for (let index = 0; index < glyphs.length; index++) {
|
|
530
|
-
const glyph = glyphs[index];
|
|
531
|
-
if (!drawable(glyph.glyphKey)) continue;
|
|
532
|
-
if (glyph.shapeGroup === void 0 || glyph.shapeGroup !== previousGroup) motionIndex++;
|
|
533
|
-
previousGroup = glyph.shapeGroup;
|
|
534
|
-
const decorations = glyph.decorations;
|
|
535
|
-
if (decorations) for (const decoration of decorations) {
|
|
536
|
-
if (decoration.thickness <= 0 || decoration.color[3] <= 0) continue;
|
|
537
|
-
const next = glyphs[index + 1];
|
|
538
|
-
let right = glyph.originX + (glyph.decorationWidth ?? Math.abs(glyph.advance));
|
|
539
|
-
if (next?.block === glyph.block && next.lineBottom === glyph.lineBottom && next.decorations?.some((candidate) => sameDecoration(decoration, candidate))) right = Math.max(right, next.originX);
|
|
540
|
-
const y = glyph.lineBottom + decoration.offset;
|
|
541
|
-
records.push([
|
|
542
|
-
[
|
|
543
|
-
glyph.originX,
|
|
544
|
-
y - decoration.thickness / 2,
|
|
545
|
-
right,
|
|
546
|
-
y + decoration.thickness / 2
|
|
547
|
-
],
|
|
548
|
-
glyphIndex,
|
|
549
|
-
glyph.motionOrigin?.[2] ?? motionIndex,
|
|
550
|
-
decoration.color,
|
|
551
|
-
glyph.clip,
|
|
552
|
-
glyph.sequence,
|
|
553
|
-
glyph.z,
|
|
554
|
-
glyph.motionOrigin ?? null
|
|
555
|
-
]);
|
|
556
|
-
}
|
|
557
|
-
glyphIndex++;
|
|
558
|
-
}
|
|
559
|
-
return records;
|
|
560
|
-
}
|
|
561
|
-
function writeDecorationBatch(records, sourceRects, rects, strokes, indices, colors, clips, metadata, runMotion) {
|
|
562
|
-
let minZ = 0;
|
|
563
|
-
let maxZ = 0;
|
|
564
|
-
for (let index = 0; index < records.length; index++) {
|
|
565
|
-
const [stroke, rectIndex, motionIndex, color, clip, sequence, z, motionOrigin] = records[index];
|
|
566
|
-
const offset = index * 4;
|
|
567
|
-
const srcOffset = rectIndex * 4;
|
|
568
|
-
rects[offset] = sourceRects[srcOffset] ?? 0;
|
|
569
|
-
rects[offset + 1] = sourceRects[srcOffset + 1] ?? 0;
|
|
570
|
-
rects[offset + 2] = sourceRects[srcOffset + 2] ?? 0;
|
|
571
|
-
rects[offset + 3] = sourceRects[srcOffset + 3] ?? 0;
|
|
572
|
-
strokes.set(stroke, offset);
|
|
573
|
-
clips.set(clip, offset);
|
|
574
|
-
indices[index] = motionIndex;
|
|
575
|
-
colors[offset] = byte(color[0]);
|
|
576
|
-
colors[offset + 1] = byte(color[1]);
|
|
577
|
-
colors[offset + 2] = byte(color[2]);
|
|
578
|
-
colors[offset + 3] = byte(color[3]);
|
|
579
|
-
metadata[index * 2] = sequence;
|
|
580
|
-
metadata[index * 2 + 1] = z;
|
|
581
|
-
if (runMotion && motionOrigin) runMotion.set(motionOrigin, index * 3);
|
|
582
|
-
if (z < minZ) minZ = z;
|
|
583
|
-
if (z > maxZ) maxZ = z;
|
|
584
|
-
}
|
|
585
|
-
return [minZ, maxZ];
|
|
586
|
-
}
|
|
587
|
-
function packDecorationInstances(snapshot, sourceGlyphRects, drawable, motionPadding = 0) {
|
|
588
|
-
const records = decorationRecords(snapshot, drawable);
|
|
589
|
-
const count = records.length;
|
|
590
|
-
if (count === 0) return null;
|
|
591
|
-
const rects = new Float32Array(count * 4);
|
|
592
|
-
const decorationRects = new Float32Array(count * 4);
|
|
593
|
-
const decorationIndices = new Float32Array(count);
|
|
594
|
-
const colors = new Uint8Array(count * 4);
|
|
595
|
-
const clips = new Float32Array(count * 4);
|
|
596
|
-
const metadata = new Float32Array(count * 2);
|
|
597
|
-
const runMotion = records.some((record) => record[7] !== null) ? new Float32Array(count * 3) : null;
|
|
598
|
-
const [minZ, maxZ] = writeDecorationBatch(records, sourceGlyphRects, rects, decorationRects, decorationIndices, colors, clips, metadata, runMotion);
|
|
599
|
-
return {
|
|
600
|
-
count,
|
|
601
|
-
rects,
|
|
602
|
-
decorationRects,
|
|
603
|
-
decorationIndices,
|
|
604
|
-
colors,
|
|
605
|
-
clips,
|
|
606
|
-
metadata,
|
|
607
|
-
runMotion,
|
|
608
|
-
bounds: computeInstanceBounds(snapshot.width, snapshot.height, motionPadding, minZ, maxZ)
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
|
-
function updateDecorationInstances(instances, snapshot, sourceGlyphRects, drawable, motionPadding = 0) {
|
|
612
|
-
const records = decorationRecords(snapshot, drawable);
|
|
613
|
-
if (records.length === 0 || records.length !== instances.count) return false;
|
|
614
|
-
if (records.some((record) => record[7] !== null) !== (instances.runMotion !== null)) return false;
|
|
615
|
-
const [minZ, maxZ] = writeDecorationBatch(records, sourceGlyphRects, instances.rects, instances.decorationRects, instances.decorationIndices, instances.colors, instances.clips, instances.metadata, instances.runMotion);
|
|
616
|
-
instances.bounds = computeInstanceBounds(snapshot.width, snapshot.height, motionPadding, minZ, maxZ);
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
555
|
/**
|
|
620
556
|
* Standalone WGSL vertex + fragment shader implementing Ultra-Text's dual-ray
|
|
621
557
|
* SoA GPU Slug evaluator (`slugVert` + `slugFrag`) with perspective-safe
|
|
@@ -650,8 +586,9 @@ struct SlugVSOut {
|
|
|
650
586
|
@location(1) localPos: vec2f,
|
|
651
587
|
@location(2) @interpolate(flat, either) clip: vec4f,
|
|
652
588
|
@location(3) @interpolate(flat, either) color: vec4f,
|
|
653
|
-
@location(4) @interpolate(flat, either)
|
|
589
|
+
@location(4) @interpolate(flat, either) bandScale: vec4f,
|
|
654
590
|
@location(5) @interpolate(flat, either) bandOrigin: vec4f,
|
|
591
|
+
@location(6) @interpolate(flat, either) bandRows: vec2u,
|
|
655
592
|
}
|
|
656
593
|
|
|
657
594
|
fn slug_vertex_skirt(
|
|
@@ -692,7 +629,7 @@ fn slugVert(
|
|
|
692
629
|
let skirt = slugUniforms.viewportAndSkirt.z;
|
|
693
630
|
let colX = slugUniforms.mvp[0];
|
|
694
631
|
let colY = slugUniforms.mvp[1];
|
|
695
|
-
let clip0 = slugUniforms.mvp *
|
|
632
|
+
let clip0 = colX * baseLocal.x + colY * baseLocal.y + slugUniforms.mvp[2] * depth + slugUniforms.mvp[3];
|
|
696
633
|
let localOffset = slug_vertex_skirt(colX, colY, clip0, viewport, quad, skirt);
|
|
697
634
|
let expandedLocal = baseLocal + localOffset;
|
|
698
635
|
let localSize = max(rect.zw - rect.xy, vec2f(1e-6));
|
|
@@ -701,20 +638,23 @@ fn slugVert(
|
|
|
701
638
|
let packedCounts = u32(rawBand.y);
|
|
702
639
|
let hBandCount = max(packedCounts & 255u, 1u);
|
|
703
640
|
let vBandCount = max(packedCounts >> 8u, 1u);
|
|
641
|
+
let hRowBase = u32(rawBand.x);
|
|
704
642
|
|
|
705
643
|
var out: SlugVSOut;
|
|
706
|
-
|
|
644
|
+
let emptyClip = clip.x > clip.z || clip.y > clip.w;
|
|
645
|
+
out.position = select(clip0 + colX * localOffset.x + colY * localOffset.y, vec4f(0.0, 0.0, 2.0, 1.0), emptyClip);
|
|
707
646
|
out.glyphPos = glyphBounds.xy + boundsSize * (quad + localOffset / localSize);
|
|
708
647
|
out.localPos = expandedLocal;
|
|
709
648
|
out.clip = clip;
|
|
710
649
|
out.color = vec4f(color.rgb * slugUniforms.tintAndFlags.rgb, color.a * slugUniforms.viewportAndSkirt.w);
|
|
711
|
-
out.
|
|
650
|
+
out.bandScale = vec4f(rawBand.z, rawBand.w, f32(hBandCount - 1u), f32(vBandCount - 1u));
|
|
712
651
|
out.bandOrigin = vec4f(
|
|
713
652
|
-glyphBounds.y * rawBand.w,
|
|
714
653
|
glyphBounds.z * rawBand.z,
|
|
715
654
|
16.0 / f32(hBandCount),
|
|
716
655
|
16.0 / f32(vBandCount),
|
|
717
656
|
);
|
|
657
|
+
out.bandRows = vec2u(hRowBase, hRowBase + hBandCount);
|
|
718
658
|
return out;
|
|
719
659
|
}
|
|
720
660
|
|
|
@@ -730,7 +670,6 @@ fn slug_band_active(
|
|
|
730
670
|
packedRow: u32,
|
|
731
671
|
orthoBf: f32,
|
|
732
672
|
orthoHalf: f32,
|
|
733
|
-
orthoCount: u32,
|
|
734
673
|
orthoScale16: f32,
|
|
735
674
|
flip: bool,
|
|
736
675
|
) -> bool {
|
|
@@ -738,7 +677,7 @@ fn slug_band_active(
|
|
|
738
677
|
return false;
|
|
739
678
|
}
|
|
740
679
|
let lo = (orthoBf + orthoHalf) * orthoScale16;
|
|
741
|
-
let hi = (
|
|
680
|
+
let hi = fma(orthoHalf - orthoBf, orthoScale16, 16.0);
|
|
742
681
|
let qMin = f32((packedRow >> 6u) & 15u);
|
|
743
682
|
let qMax = f32((packedRow >> 10u) & 15u);
|
|
744
683
|
return select(lo > qMin && hi > qMax, hi > qMin && lo > qMax, flip);
|
|
@@ -763,9 +702,11 @@ fn slug_gather_band(
|
|
|
763
702
|
packedRow: u32,
|
|
764
703
|
rc: vec2f,
|
|
765
704
|
halfPx: f32,
|
|
705
|
+
halfPy: f32,
|
|
766
706
|
invDiam: f32,
|
|
767
|
-
) ->
|
|
707
|
+
) -> vec3f {
|
|
768
708
|
var cw = vec2f(0.0);
|
|
709
|
+
var touched = 0.0;
|
|
769
710
|
let count = packedRow & 63u;
|
|
770
711
|
let start = packedRow >> 15u;
|
|
771
712
|
let allLinear = (packedRow & 0x4000u) != 0u;
|
|
@@ -781,6 +722,7 @@ fn slug_gather_band(
|
|
|
781
722
|
}
|
|
782
723
|
let dy1 = c1.y - rc.y;
|
|
783
724
|
let dy3 = c3.y - rc.y;
|
|
725
|
+
touched = select(touched, 1.0, min(abs(dy1), abs(dy3)) <= halfPy);
|
|
784
726
|
let u1 = bitcast<u32>(dy1);
|
|
785
727
|
let u3 = bitcast<u32>(dy3);
|
|
786
728
|
if ((u1 ^ u3) < 0x80000000u) {
|
|
@@ -791,6 +733,7 @@ fn slug_gather_band(
|
|
|
791
733
|
cw.x += s;
|
|
792
734
|
continue;
|
|
793
735
|
}
|
|
736
|
+
touched = 1.0;
|
|
794
737
|
var hit: vec2f;
|
|
795
738
|
if (allLinear) {
|
|
796
739
|
hit = slug_solve_linear_straddle(c1, c3, xLo, dy1, dy3, s, invDiam);
|
|
@@ -802,15 +745,17 @@ fn slug_gather_band(
|
|
|
802
745
|
cw.x += hit.x;
|
|
803
746
|
cw.y = max(cw.y, hit.y);
|
|
804
747
|
}
|
|
805
|
-
return cw;
|
|
748
|
+
return vec3f(cw, touched);
|
|
806
749
|
}
|
|
807
750
|
|
|
808
751
|
fn slug_combine_rays(xc: vec2f, yc: vec2f) -> f32 {
|
|
809
752
|
let ax = abs(xc.x);
|
|
810
753
|
let ay = abs(yc.x);
|
|
811
|
-
let
|
|
812
|
-
let
|
|
813
|
-
let
|
|
754
|
+
let wx2 = xc.y * xc.y;
|
|
755
|
+
let wy2 = yc.y * yc.y;
|
|
756
|
+
let wx = wx2 * wx2;
|
|
757
|
+
let wy = wy2 * wy2;
|
|
758
|
+
let weighted = fma(ax, wx, ay * wy) / max(wx + wy, 1e-24);
|
|
814
759
|
return saturate(max(weighted, min(ax, ay)));
|
|
815
760
|
}
|
|
816
761
|
|
|
@@ -825,39 +770,45 @@ fn slugFrag(input: SlugVSOut) -> @location(0) vec4f {
|
|
|
825
770
|
var coverage = 0.0;
|
|
826
771
|
if (insideClip) {
|
|
827
772
|
let center = input.glyphPos;
|
|
828
|
-
let
|
|
829
|
-
let hBandCount = max(packedCounts & 255u, 1u);
|
|
830
|
-
let vBandCount = max(packedCounts >> 8u, 1u);
|
|
831
|
-
let hRowBase = u32(input.band.x);
|
|
832
|
-
let vRowBase = hRowBase + hBandCount;
|
|
833
|
-
let totalBands = vec2f(f32(hBandCount), f32(vBandCount));
|
|
834
|
-
let maxBands = totalBands - vec2f(1.0);
|
|
773
|
+
let maxBands = input.bandScale.zw;
|
|
835
774
|
let bf = vec2f(
|
|
836
|
-
fma(center.y, input.
|
|
837
|
-
|
|
775
|
+
fma(center.y, input.bandScale.y, input.bandOrigin.x),
|
|
776
|
+
fma(-center.x, input.bandScale.x, input.bandOrigin.y),
|
|
838
777
|
);
|
|
839
|
-
let halfBand = fma(metrics.yx, input.
|
|
778
|
+
let halfBand = fma(metrics.yx, input.bandScale.yx, vec2f(1e-4));
|
|
840
779
|
let scale16 = input.bandOrigin.zw;
|
|
841
780
|
|
|
842
781
|
var xc = vec2f(0.0);
|
|
843
782
|
var earlyZero = false;
|
|
844
|
-
if (bf.x >= -1e-4 && bf.x <=
|
|
783
|
+
if (bf.x >= -1e-4 && bf.x <= maxBands.x + 1.0001) {
|
|
845
784
|
let hBi = u32(clamp(bf.x, 0.0, maxBands.x));
|
|
846
|
-
let hPackedRow = slugRows[
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
785
|
+
let hPackedRow = slugRows[input.bandRows.x + hBi];
|
|
786
|
+
let hInterior = abs((bf.x - f32(hBi)) - 0.5) <= 0.5 - halfBand.x;
|
|
787
|
+
if (slug_band_active(hPackedRow, bf.y, halfBand.y, scale16.y, true)) {
|
|
788
|
+
let hRes = slug_gather_band(hPackedRow, center, metrics.x, metrics.y, metrics.z);
|
|
789
|
+
xc = hRes.xy;
|
|
790
|
+
if (hInterior && hRes.z == 0.0 && (hPackedRow & 63u) < 63u) {
|
|
791
|
+
earlyZero = true;
|
|
792
|
+
coverage = saturate(abs(xc.x));
|
|
793
|
+
}
|
|
794
|
+
} else if (hInterior) {
|
|
850
795
|
earlyZero = true;
|
|
851
796
|
}
|
|
852
797
|
}
|
|
853
798
|
|
|
854
799
|
if (!earlyZero) {
|
|
855
800
|
var yc = vec2f(0.0);
|
|
856
|
-
if (bf.y >= -1e-4 && bf.y <=
|
|
801
|
+
if (bf.y >= -1e-4 && bf.y <= maxBands.y + 1.0001) {
|
|
857
802
|
let vBi = u32(clamp(bf.y, 0.0, maxBands.y));
|
|
858
|
-
let vPackedRow = slugRows[
|
|
859
|
-
if (slug_band_active(vPackedRow, bf.x, halfBand.x,
|
|
860
|
-
yc = slug_gather_band(
|
|
803
|
+
let vPackedRow = slugRows[input.bandRows.y + vBi];
|
|
804
|
+
if (slug_band_active(vPackedRow, bf.x, halfBand.x, scale16.x, false)) {
|
|
805
|
+
yc = slug_gather_band(
|
|
806
|
+
vPackedRow,
|
|
807
|
+
vec2f(center.y, -center.x),
|
|
808
|
+
metrics.y,
|
|
809
|
+
0.0,
|
|
810
|
+
metrics.w,
|
|
811
|
+
).xy;
|
|
861
812
|
}
|
|
862
813
|
}
|
|
863
814
|
coverage = slug_combine_rays(xc, yc);
|
|
@@ -880,11 +831,13 @@ function uploadSlugGlyphBuffers(device, instances) {
|
|
|
880
831
|
if (view.byteLength > 0) device.queue.writeBuffer(buffer, 0, view);
|
|
881
832
|
return buffer;
|
|
882
833
|
};
|
|
834
|
+
let metaStaging = null;
|
|
883
835
|
const expandMeta = (src) => {
|
|
884
836
|
if (src.metaItemSize >= 2) return src.metadata;
|
|
885
|
-
const
|
|
886
|
-
|
|
887
|
-
|
|
837
|
+
const needed = src.count * 2;
|
|
838
|
+
if (!metaStaging || metaStaging.length < needed) metaStaging = new Float32Array(needed);
|
|
839
|
+
for (let i = 0; i < src.count; i++) metaStaging[i * 2] = src.metadata[i] ?? 0;
|
|
840
|
+
return metaStaging.subarray(0, needed);
|
|
888
841
|
};
|
|
889
842
|
const rects = make("ultra-slug-rects", instances.rects);
|
|
890
843
|
const clips = make("ultra-slug-clips", instances.clips);
|
|
@@ -927,19 +880,64 @@ function uploadSlugGlyphBuffers(device, instances) {
|
|
|
927
880
|
}
|
|
928
881
|
};
|
|
929
882
|
}
|
|
930
|
-
/**
|
|
931
|
-
function
|
|
932
|
-
|
|
883
|
+
/** Strips line comments and excess whitespace from WGSL while keeping all token boundaries intact. */
|
|
884
|
+
function minifySlugWgsl(code) {
|
|
885
|
+
return code.replace(/\/\/[^\n]*/g, "").replace(/[ \t]+/g, " ").replace(/\n[ \t]+/g, "\n").replace(/\n{2,}/g, "\n").trim();
|
|
886
|
+
}
|
|
887
|
+
var DEFAULT_SHADER_STAGE = {
|
|
888
|
+
VERTEX: 1,
|
|
889
|
+
FRAGMENT: 2
|
|
890
|
+
};
|
|
891
|
+
var shaderStageOf = () => globalThis.GPUShaderStage ?? DEFAULT_SHADER_STAGE;
|
|
892
|
+
var slugDeviceLayouts = /* @__PURE__ */ new WeakMap();
|
|
893
|
+
function getExplicitSlugLayouts(device) {
|
|
894
|
+
let cached = slugDeviceLayouts.get(device);
|
|
895
|
+
if (cached) return cached;
|
|
896
|
+
if (typeof device.createBindGroupLayout !== "function" || typeof device.createPipelineLayout !== "function") return null;
|
|
897
|
+
const stage = shaderStageOf();
|
|
898
|
+
const bindGroupLayout = device.createBindGroupLayout({
|
|
899
|
+
label: "ultra-slug-bind-group-layout",
|
|
900
|
+
entries: [
|
|
901
|
+
{
|
|
902
|
+
binding: 0,
|
|
903
|
+
visibility: stage.VERTEX | stage.FRAGMENT,
|
|
904
|
+
buffer: { type: "uniform" }
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
binding: 1,
|
|
908
|
+
visibility: stage.FRAGMENT,
|
|
909
|
+
buffer: { type: "read-only-storage" }
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
binding: 2,
|
|
913
|
+
visibility: stage.FRAGMENT,
|
|
914
|
+
buffer: { type: "read-only-storage" }
|
|
915
|
+
}
|
|
916
|
+
]
|
|
917
|
+
});
|
|
918
|
+
cached = {
|
|
919
|
+
bindGroupLayout,
|
|
920
|
+
pipelineLayout: device.createPipelineLayout({
|
|
921
|
+
label: "ultra-slug-pipeline-layout",
|
|
922
|
+
bindGroupLayouts: [bindGroupLayout]
|
|
923
|
+
})
|
|
924
|
+
};
|
|
925
|
+
slugDeviceLayouts.set(device, cached);
|
|
926
|
+
return cached;
|
|
927
|
+
}
|
|
928
|
+
function buildSlugPipelineDescriptor(device, options) {
|
|
933
929
|
const format = options.format ?? "bgra8unorm";
|
|
934
930
|
const metaStride = (options.metaItemSize ?? 2) * 4;
|
|
935
|
-
const
|
|
931
|
+
const rawCode = options.depthWriteEnabled ? SLUG_WGSL : SLUG_WGSL.replace(SLUG_WGSL_DISCARD_TAIL, "");
|
|
932
|
+
const code = options.minifyWgsl === false ? rawCode : minifySlugWgsl(rawCode);
|
|
936
933
|
const module = device.createShaderModule({
|
|
937
934
|
label: "ultra-slug-wgsl",
|
|
938
935
|
code
|
|
939
936
|
});
|
|
940
|
-
const
|
|
937
|
+
const explicitLayouts = getExplicitSlugLayouts(device);
|
|
938
|
+
return {
|
|
941
939
|
label: "ultra-slug-pipeline",
|
|
942
|
-
layout: "auto",
|
|
940
|
+
layout: explicitLayouts ? explicitLayouts.pipelineLayout : "auto",
|
|
943
941
|
vertex: {
|
|
944
942
|
module,
|
|
945
943
|
entryPoint: "slugVert",
|
|
@@ -1029,7 +1027,10 @@ function createVanillaSlugPipeline(device, options = {}) {
|
|
|
1029
1027
|
depthCompare: options.depthCompare ?? "less-equal"
|
|
1030
1028
|
} } : {},
|
|
1031
1029
|
...options.sampleCount === void 0 ? {} : { multisample: { count: options.sampleCount } }
|
|
1032
|
-
}
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
function wrapVanillaSlugPipeline(device, pipeline) {
|
|
1033
|
+
const usage = bufUsageOf();
|
|
1033
1034
|
const uniformData = /* @__PURE__ */ new Float32Array(24);
|
|
1034
1035
|
const uniformBuffer = device.createBuffer({
|
|
1035
1036
|
label: "ultra-slug-uniforms",
|
|
@@ -1055,9 +1056,10 @@ function createVanillaSlugPipeline(device, options = {}) {
|
|
|
1055
1056
|
},
|
|
1056
1057
|
createBindGroup(atlas) {
|
|
1057
1058
|
if (!atlas.curvesBuffer || !atlas.rowsBuffer) throw new Error("createVanillaSlugPipeline.createBindGroup: atlas has no GPU storage buffers; pass a GPUDevice to buildVanillaSlugAtlas");
|
|
1059
|
+
const bindGroupLayout = getExplicitSlugLayouts(device)?.bindGroupLayout ?? pipeline.getBindGroupLayout(0);
|
|
1058
1060
|
return device.createBindGroup({
|
|
1059
1061
|
label: "ultra-slug-bind-group",
|
|
1060
|
-
layout:
|
|
1062
|
+
layout: bindGroupLayout,
|
|
1061
1063
|
entries: [
|
|
1062
1064
|
{
|
|
1063
1065
|
binding: 0,
|
|
@@ -1093,6 +1095,10 @@ function createVanillaSlugPipeline(device, options = {}) {
|
|
|
1093
1095
|
}
|
|
1094
1096
|
};
|
|
1095
1097
|
}
|
|
1098
|
+
/** Creates a ready-to-draw premultiplied-alpha WebGPU render pipeline for `SLUG_WGSL`. */
|
|
1099
|
+
function createVanillaSlugPipeline(device, options = {}) {
|
|
1100
|
+
return wrapVanillaSlugPipeline(device, device.createRenderPipeline(buildSlugPipelineDescriptor(device, options)));
|
|
1101
|
+
}
|
|
1096
1102
|
function nowMs() {
|
|
1097
1103
|
return typeof performance !== "undefined" ? performance.now() : Date.now();
|
|
1098
1104
|
}
|
|
@@ -1148,7 +1154,6 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1148
1154
|
motion;
|
|
1149
1155
|
#a;
|
|
1150
1156
|
#s = null;
|
|
1151
|
-
#rw = null;
|
|
1152
1157
|
#rs = null;
|
|
1153
1158
|
#rf = null;
|
|
1154
1159
|
#rm = null;
|
|
@@ -1209,8 +1214,8 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1209
1214
|
return this.#st;
|
|
1210
1215
|
}
|
|
1211
1216
|
get snapshot() {
|
|
1212
|
-
|
|
1213
|
-
return this.#
|
|
1217
|
+
if (this.#rs) this.#rf = null;
|
|
1218
|
+
return this.#rs ?? this.#s;
|
|
1214
1219
|
}
|
|
1215
1220
|
get width() {
|
|
1216
1221
|
return this.#w;
|
|
@@ -1233,16 +1238,22 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1233
1238
|
if (this.options.reflowable !== true || !this.#s || !reflow) throw new Error("VanillaDomSlug.reflow requires { reflowable: true } at creation time");
|
|
1234
1239
|
if (!Number.isFinite(width) || width <= 0) throw new RangeError("VanillaDomSlug.reflow: width must be a positive finite number");
|
|
1235
1240
|
const geometryStart = nowMs();
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
if (
|
|
1241
|
+
let nextSnapshot;
|
|
1242
|
+
try {
|
|
1243
|
+
nextSnapshot = reflow.reflowSnapshotWithState(this.#s, width, this.#rf ??= reflow.createReflowState(this.#s));
|
|
1244
|
+
const motionPadding = Math.max(0, this.motion.strength);
|
|
1245
|
+
if (updateSlugGlyphInstances(this.glyphs, nextSnapshot, this.#a, motionPadding) === null) this.glyphs = packSlugGlyphInstances(nextSnapshot, this.#a, motionPadding);
|
|
1246
|
+
if (this.decorations) {
|
|
1247
|
+
const drawable = (key) => (this.#a.glyphs.get(key)?.monotonePieceCount ?? 0) > 0;
|
|
1248
|
+
if (!updateDecorationInstances(this.decorations, nextSnapshot, this.glyphs.glyphRects, drawable, motionPadding)) this.decorations = packDecorationInstances(nextSnapshot, this.glyphs.glyphRects, drawable, motionPadding);
|
|
1249
|
+
}
|
|
1250
|
+
} catch (error) {
|
|
1251
|
+
if (this.#rs && this.#rs.glyphs === this.#rf?.glyphs) this.#rs = reflow.reflowSnapshot(this.#s, this.#w);
|
|
1252
|
+
this.#rf = null;
|
|
1253
|
+
throw error;
|
|
1242
1254
|
}
|
|
1243
1255
|
const geometryBuildMs = nowMs() - geometryStart;
|
|
1244
|
-
this.#
|
|
1245
|
-
this.#rs = null;
|
|
1256
|
+
this.#rs = nextSnapshot;
|
|
1246
1257
|
this.#w = nextSnapshot.width;
|
|
1247
1258
|
this.#h = nextSnapshot.height;
|
|
1248
1259
|
this.#ls = "";
|
|
@@ -1327,12 +1338,11 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1327
1338
|
const canUseSharedAtlas = Boolean(!forceOutlines && sharedAtlas && snapshot.requests.every((r) => sharedAtlas.covers(r.key)));
|
|
1328
1339
|
const canReusePrivateAtlas = Boolean(!forceOutlines && !canUseSharedAtlas && currentAtlas && this.#o && (this.#as === snapshot.atlasSignature || snapshot.requests.every((r) => currentAtlas.covers(r.key))));
|
|
1329
1340
|
const nextLayoutSignature = layoutSignatureOf(snapshot);
|
|
1330
|
-
if (this.#ls === "" && this.#s) this.#ls = layoutSignatureOf(this
|
|
1341
|
+
if (this.#ls === "" && this.#s) this.#ls = layoutSignatureOf(this.#rs ?? this.#s);
|
|
1331
1342
|
if ((canUseSharedAtlas || canReusePrivateAtlas) && this.#ls !== "" && nextLayoutSignature === this.#ls) {
|
|
1332
1343
|
if (version !== this.#rv || this.#d) throw makeAbortError();
|
|
1333
1344
|
this.tone = nextTone;
|
|
1334
1345
|
this.#s = snapshot;
|
|
1335
|
-
this.#rw = null;
|
|
1336
1346
|
this.#rs = null;
|
|
1337
1347
|
this.#rf = null;
|
|
1338
1348
|
this.#w = snapshot.width;
|
|
@@ -1399,7 +1409,6 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1399
1409
|
this.#o = nextOwnsAtlas;
|
|
1400
1410
|
this.tone = nextTone;
|
|
1401
1411
|
this.#s = snapshot;
|
|
1402
|
-
this.#rw = null;
|
|
1403
1412
|
this.#rs = null;
|
|
1404
1413
|
this.#rf = null;
|
|
1405
1414
|
this.#w = snapshot.width;
|
|
@@ -1407,11 +1416,12 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1407
1416
|
if (!canUseSharedAtlas && !canReusePrivateAtlas) this.#as = snapshot.atlasSignature;
|
|
1408
1417
|
this.#ls = nextLayoutSignature;
|
|
1409
1418
|
this.#av = version;
|
|
1410
|
-
this.#to
|
|
1419
|
+
if (this.#to) this.#to.retain(snapshot.requests.map((request) => request.key));
|
|
1411
1420
|
let textGlyphs = 0;
|
|
1412
1421
|
let shapes = 0;
|
|
1413
1422
|
let skipped = 0;
|
|
1414
|
-
|
|
1423
|
+
if (isVanillaDomSnapshot(snapshot) && resolvedAtlas.skippedKeys.size === 0 && !snapshot.requests.some((request) => request.shape !== void 0)) textGlyphs = snapshot.glyphs.length;
|
|
1424
|
+
else for (const glyph of snapshot.glyphs) if (glyph.shapeGroup !== void 0) shapes++;
|
|
1415
1425
|
else {
|
|
1416
1426
|
textGlyphs++;
|
|
1417
1427
|
if (resolvedAtlas.skippedKeys.has(glyph.glyphKey)) skipped++;
|
|
@@ -1470,7 +1480,6 @@ var VanillaDomSlug = class VanillaDomSlug {
|
|
|
1470
1480
|
const currentAtlas = this.#a;
|
|
1471
1481
|
if (currentAtlas && this.#o) currentAtlas.dispose();
|
|
1472
1482
|
this.#s = null;
|
|
1473
|
-
this.#rw = null;
|
|
1474
1483
|
this.#rs = null;
|
|
1475
1484
|
this.#rf = null;
|
|
1476
1485
|
this.#w = 0;
|
|
@@ -1616,6 +1625,6 @@ var VanillaSlugText = class VanillaSlugText extends VanillaDomSlug {
|
|
|
1616
1625
|
});
|
|
1617
1626
|
}
|
|
1618
1627
|
};
|
|
1619
|
-
export { VanillaDomSlug as DomSlug, VanillaDomSlug as DomText, VanillaDomSlug, VanillaDomSlug as VanillaDomText, SLUG_WGSL, VanillaSlugText as SlugText, VanillaSlugText as Text, VanillaSlugText, VanillaSlugText as VanillaText, UNIT_QUAD_INDICES, UNIT_QUAD_NORMALS, UNIT_QUAD_POSITIONS, buildVanillaSlugAtlas as buildSlugAtlas, buildVanillaSlugAtlas, computeInstanceBounds, createVanillaSlugPipeline, packDecorationInstances, packRectInstances, packSlugGlyphInstances, updateDecorationInstances, updateRectInstances, updateSlugGlyphInstances, uploadSlugGlyphBuffers };
|
|
1628
|
+
export { VanillaDomSlug as DomSlug, VanillaDomSlug as DomText, VanillaDomSlug, VanillaDomSlug as VanillaDomText, SLUG_WGSL, VanillaSlugText as SlugText, VanillaSlugText as Text, VanillaSlugText, VanillaSlugText as VanillaText, UNIT_QUAD_INDICES, UNIT_QUAD_NORMALS, UNIT_QUAD_POSITIONS, buildVanillaSlugAtlas as buildSlugAtlas, buildVanillaSlugAtlas, computeInstanceBounds, createVanillaSlugPipeline, minifySlugWgsl, packDecorationInstances, packRectInstances, packSlugGlyphInstances, updateDecorationInstances, updateRectInstances, updateSlugGlyphInstances, uploadSlugGlyphBuffers };
|
|
1620
1629
|
|
|
1621
1630
|
//# sourceMappingURL=vanillaCore.js.map
|