ultra-text 1.0.1 → 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 +339 -1039
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
- 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 +97 -31
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +4 -3
- 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.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +14 -7
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +235 -68
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +11 -3
- package/dist/atlas/cpuWorker.js +179 -22
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +188 -287
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +257 -0
- package/dist/atlas/gpuCommon.js +845 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +226 -249
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +329 -158
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1065 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +72 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +167 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
- package/dist/atlas/vanillaGpuHelpers.js +354 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +243 -297
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +94 -165
- 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 +53 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +31 -13
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +175 -57
- 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 +78 -28
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +891 -484
- 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.d.ts +8 -1
- package/dist/dom/svgCapture.js +105 -28
- 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 +91 -44
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +17 -3
- package/dist/slug/SlugMaterial.js +98 -26
- 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 +19 -15
- package/dist/slug/coverage.js +380 -225
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -2
- package/dist/slug/preprocessCore.js +199 -148
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +113 -74
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +112 -67
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +356 -255
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +410 -0
- package/dist/slug/vanillaCore.js +1630 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +7 -1454
- package/dist/slug.d.ts +2 -2
- package/dist/slug.js +7 -7
- package/dist/text/GlyphTextMaterial.d.ts +6 -1
- package/dist/text/GlyphTextMaterial.js +16 -12
- 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 +125 -38
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -79
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +16 -1
- package/dist/text/geometryUtils.js +83 -8
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +434 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +101 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +23 -1
- package/dist/text/reflow.js +223 -94
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- 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.d.ts +13 -363
- package/dist/vanilla.js +7 -1474
- 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 +17 -2
- package/dist/windfoil/geometry.js +220 -57
- 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.d.ts +1 -0
- package/dist/windfoil/mixed.js +57 -29
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +2 -0
- package/dist/windfoil/preprocessCore.js +69 -37
- 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 +4 -1
- package/dist/windfoil/runtime.js +69 -63
- 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 +78 -6
- package/dist/windfoil/storage.js +166 -11
- 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.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +256 -62
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +915 -265
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/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/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +393 -103
- 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 +27 -25
- package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
package/dist/windfoil/runtime.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { abortable, throwIfAborted } from "./abortable.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { analyticGeometryFits, createAnalyticGeometry, reflowWindfoilGlyphGeometry, updateAnalyticGeometry } from "./geometry.js";
|
|
3
|
+
import { collectMissingRequests, createRetainedWindfoilStorage, drawnEffects, mergePreprocessStats, resolveOutlineRequests } from "./storage.js";
|
|
4
4
|
import { WindfoilMaterial } from "./WindfoilMaterial.js";
|
|
5
|
-
import {
|
|
5
|
+
import { preprocessWindfoilGlyphsBatch } from "./preprocessCore.js";
|
|
6
6
|
import { WebGPUBackend } from "three/webgpu";
|
|
7
7
|
// src/windfoil/runtime.ts
|
|
8
8
|
/** All asynchronous resolution completes before retaining GPU storage. */
|
|
9
9
|
async function buildWindfoilBackend(renderer, requests, options, signal, companionBuilder) {
|
|
10
|
+
const headroom = companionBuilder?.headroom === true;
|
|
10
11
|
const sdfBelow = options.sdfBelowPx;
|
|
11
12
|
const switchModule = sdfBelow === void 0 ? null : await abortable(import("./sizeSwitch.js"), signal);
|
|
12
13
|
switchModule?.assertThreshold(sdfBelow);
|
|
@@ -24,33 +25,7 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
24
25
|
}
|
|
25
26
|
const effects = companionBuilder?.effects ? drawnEffects(companionBuilder.effects) : null;
|
|
26
27
|
let extensions = !!effects || requests.some((request) => request.shape) || options.fallback === "sdf-glyphs" || options.compositing === "shader" || sdfBelow !== void 0 ? await abortable(import("./requests.js"), signal) : null;
|
|
27
|
-
|
|
28
|
-
if (extensions) resolved = await abortable(Promise.all(requests.map(async (request) => ({
|
|
29
|
-
request,
|
|
30
|
-
outline: await extensions.resolveShapeRequest(request, options, signal)
|
|
31
|
-
}))), signal);
|
|
32
|
-
else {
|
|
33
|
-
const syncResolved = [];
|
|
34
|
-
let pending = null;
|
|
35
|
-
for (const request of requests) {
|
|
36
|
-
const out = options.outlineProvider(request, signal);
|
|
37
|
-
if (out instanceof Promise) {
|
|
38
|
-
pending ??= syncResolved.map((item) => Promise.resolve(item));
|
|
39
|
-
pending.push(out.then((outline) => ({
|
|
40
|
-
request,
|
|
41
|
-
outline
|
|
42
|
-
})));
|
|
43
|
-
} else if (pending) pending.push(Promise.resolve({
|
|
44
|
-
request,
|
|
45
|
-
outline: out
|
|
46
|
-
}));
|
|
47
|
-
else syncResolved.push({
|
|
48
|
-
request,
|
|
49
|
-
outline: out
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
resolved = pending ? await abortable(Promise.all(pending), signal) : syncResolved;
|
|
53
|
-
}
|
|
28
|
+
const resolved = await resolveOutlineRequests(requests, options, signal, extensions);
|
|
54
29
|
throwIfAborted(signal);
|
|
55
30
|
const missing = resolved.filter((item) => item.outline === null);
|
|
56
31
|
if (missing.length) {
|
|
@@ -59,9 +34,10 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
59
34
|
}
|
|
60
35
|
const needsRequests = !extensions && resolved.some((item) => item.outline?.clipBox);
|
|
61
36
|
const needsLayerNormalization = resolved.some((item) => item.outline?.layers !== void 0 || item.outline?.clipBox !== void 0);
|
|
62
|
-
const [lateExtensions,
|
|
37
|
+
const [lateExtensions, initialLayerModule] = needsRequests || needsLayerNormalization ? await abortable(Promise.all([needsRequests ? import("./requests.js") : Promise.resolve(null), needsLayerNormalization ? import("./layerNormalization.js") : Promise.resolve(null)]), signal) : [null, null];
|
|
63
38
|
extensions ??= lateExtensions;
|
|
64
|
-
|
|
39
|
+
let layerModule = initialLayerModule;
|
|
40
|
+
const prepared = preprocessWindfoilGlyphsBatch(resolved.filter((item) => item.outline !== null), {
|
|
65
41
|
signal,
|
|
66
42
|
orientLayers: (outline) => options.compositing === "shader" || !!outline.clipBox,
|
|
67
43
|
...layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {},
|
|
@@ -86,14 +62,22 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
86
62
|
try {
|
|
87
63
|
const colorModule = colorPromise ? await abortable(colorPromise, signal) : null;
|
|
88
64
|
throwIfAborted(signal);
|
|
89
|
-
coverage =
|
|
65
|
+
coverage = createRetainedWindfoilStorage(renderer, prepared, headroom ? {
|
|
66
|
+
minCurveFloats: 4096,
|
|
67
|
+
minRowUints: 1536,
|
|
68
|
+
rowAlign: 6
|
|
69
|
+
} : false);
|
|
90
70
|
colorResources = colorModule?.buildWindfoilColorResources(renderer, prepared, options, coverage, signal) ?? null;
|
|
71
|
+
const glyphs = prepared.glyphs;
|
|
91
72
|
const plainGlyphs = colorResources?.plainGlyphs ?? prepared.glyphs;
|
|
73
|
+
let usedCurves = prepared.curves.length;
|
|
74
|
+
let usedRows = prepared.rows.length;
|
|
75
|
+
let stats = prepared.stats;
|
|
92
76
|
const ordinalsCache = /* @__PURE__ */ new WeakMap();
|
|
93
77
|
const motionOrdinals = (snapshot) => {
|
|
94
78
|
let cached = ordinalsCache.get(snapshot);
|
|
95
79
|
if (!cached) {
|
|
96
|
-
if (extensions) cached = extensions.motionOrdinals(snapshot,
|
|
80
|
+
if (extensions) cached = extensions.motionOrdinals(snapshot, glyphs, companion);
|
|
97
81
|
else {
|
|
98
82
|
const count = snapshot.glyphs.length;
|
|
99
83
|
cached = new Float32Array(count);
|
|
@@ -103,28 +87,9 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
103
87
|
}
|
|
104
88
|
return cached;
|
|
105
89
|
};
|
|
106
|
-
const sizeSwitch = view?.keys.size ? switchModule.createSizeSwitch(sdfBelow, view.keys,
|
|
90
|
+
const sizeSwitch = view?.keys.size ? switchModule.createSizeSwitch(sdfBelow, view.keys, glyphs, motionOrdinals) : null;
|
|
107
91
|
let glyphEm = false;
|
|
108
|
-
const
|
|
109
|
-
const withEm = (snapshot) => {
|
|
110
|
-
let layout = sized.get(snapshot);
|
|
111
|
-
if (!layout) {
|
|
112
|
-
layout = {
|
|
113
|
-
...snapshot,
|
|
114
|
-
sizeSwitched: true,
|
|
115
|
-
glyphs: snapshot.glyphs.map((glyph) => ({
|
|
116
|
-
...glyph,
|
|
117
|
-
switchEm: glyph.shapeGroup === void 0 ? -glyph.fontSize : 0
|
|
118
|
-
}))
|
|
119
|
-
};
|
|
120
|
-
sized.set(snapshot, layout);
|
|
121
|
-
}
|
|
122
|
-
return layout;
|
|
123
|
-
};
|
|
124
|
-
const switched = (snapshot) => {
|
|
125
|
-
const layout = glyphEm ? withEm(snapshot) : snapshot;
|
|
126
|
-
return sizeSwitch?.layout(layout) ?? layout;
|
|
127
|
-
};
|
|
92
|
+
const switched = (snapshot) => sizeSwitch?.layout(snapshot, glyphEm) ?? snapshot;
|
|
128
93
|
let geometryLayered = layered, disposed = false;
|
|
129
94
|
const retained = coverage;
|
|
130
95
|
return {
|
|
@@ -135,9 +100,9 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
135
100
|
color: colorResources?.composite ?? null,
|
|
136
101
|
sizeSwitch,
|
|
137
102
|
motionOrdinals,
|
|
138
|
-
glyphs
|
|
103
|
+
glyphs,
|
|
139
104
|
covers(key) {
|
|
140
|
-
return
|
|
105
|
+
return glyphs.has(key) || !!companion?.glyphs.has(key);
|
|
141
106
|
},
|
|
142
107
|
primaryCovers(key) {
|
|
143
108
|
return !!plainGlyphs.get(key)?.monotonePieceCount;
|
|
@@ -146,28 +111,69 @@ async function buildWindfoilBackend(renderer, requests, options, signal, compani
|
|
|
146
111
|
return !!plainGlyphs.get(key)?.monotonePieceCount || !!colorResources?.composite?.glyphs.get(key)?.monotonePieceCount;
|
|
147
112
|
},
|
|
148
113
|
storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),
|
|
149
|
-
preprocessStats
|
|
114
|
+
get preprocessStats() {
|
|
115
|
+
return stats;
|
|
116
|
+
},
|
|
150
117
|
contentFits(geometry, snapshot) {
|
|
151
|
-
return
|
|
118
|
+
return analyticGeometryFits(geometry, switched(snapshot), plainGlyphs, glyphEm && !sizeSwitch);
|
|
119
|
+
},
|
|
120
|
+
reflowGeometry(geometry, snapshot, padding) {
|
|
121
|
+
return reflowWindfoilGlyphGeometry(geometry, snapshot, this, padding, glyphEm);
|
|
152
122
|
},
|
|
153
123
|
createGeometry(snapshot, padding, ordinals) {
|
|
154
124
|
snapshot = switched(snapshot);
|
|
155
125
|
ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : void 0;
|
|
156
126
|
geometryLayered = layered || !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin);
|
|
157
127
|
if (geometryLayered && limit < 8) throw new Error("DomSdf: layered Windfoil requires eight vertex buffers");
|
|
158
|
-
return
|
|
128
|
+
return createAnalyticGeometry(snapshot, plainGlyphs, padding, geometryLayered, ordinals, glyphEm && !sizeSwitch);
|
|
159
129
|
},
|
|
160
|
-
updateGeometry(geometry, snapshot, padding, ordinals) {
|
|
130
|
+
updateGeometry(geometry, snapshot, padding, ordinals, checked = false) {
|
|
161
131
|
snapshot = switched(snapshot);
|
|
162
132
|
ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : void 0;
|
|
163
|
-
return
|
|
133
|
+
return updateAnalyticGeometry(geometry, snapshot, plainGlyphs, padding, ordinals, checked, glyphEm && !sizeSwitch);
|
|
134
|
+
},
|
|
135
|
+
async append(nextRequests, appendSignal) {
|
|
136
|
+
if (disposed || effects) return false;
|
|
137
|
+
const missingReqs = collectMissingRequests(nextRequests, (key) => glyphs.has(key) || !!companion?.glyphs.has(key));
|
|
138
|
+
if (missingReqs.length === 0) return true;
|
|
139
|
+
if (!extensions && missingReqs.some((req) => req.shape !== void 0)) extensions = await abortable(import("./requests.js"), appendSignal);
|
|
140
|
+
const deltaResolved = await resolveOutlineRequests(missingReqs, options, appendSignal, extensions);
|
|
141
|
+
throwIfAborted(appendSignal);
|
|
142
|
+
if (deltaResolved.some((item) => item.outline === null)) return false;
|
|
143
|
+
const nonNull = deltaResolved;
|
|
144
|
+
if (!layerModule && nonNull.some((item) => item.outline.layers !== void 0 || item.outline.clipBox !== void 0)) {
|
|
145
|
+
layerModule = await abortable(import("./layerNormalization.js"), appendSignal);
|
|
146
|
+
throwIfAborted(appendSignal);
|
|
147
|
+
}
|
|
148
|
+
const delta = preprocessWindfoilGlyphsBatch(nonNull, {
|
|
149
|
+
signal: appendSignal,
|
|
150
|
+
orientLayers: (outline) => options.compositing === "shader" || !!outline.clipBox,
|
|
151
|
+
...layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {},
|
|
152
|
+
...options.targetPiecesPerBand === void 0 ? {} : { targetPiecesPerBand: options.targetPiecesPerBand }
|
|
153
|
+
}, usedCurves, usedRows);
|
|
154
|
+
if (delta.layered && !layered) return false;
|
|
155
|
+
if (companionBuilder && switchModule && switchModule.switchableRequests(deltaResolved, delta.glyphs).length > 0) return false;
|
|
156
|
+
for (const header of delta.glyphs.values()) if ((header.layers?.some((layer) => layer.paintKind === 2) ?? false) || header.layers && (options.compositing === "shader" || !!header.clipBox)) return false;
|
|
157
|
+
if (usedCurves + delta.curves.length > retained.curveCapacityFloats || usedRows + delta.rows.length > retained.rowCapacityUints) return false;
|
|
158
|
+
throwIfAborted(appendSignal);
|
|
159
|
+
retained.writeCurves(usedCurves, delta.curves);
|
|
160
|
+
retained.writeRows(usedRows, delta.rows);
|
|
161
|
+
usedCurves += delta.curves.length;
|
|
162
|
+
usedRows += delta.rows.length;
|
|
163
|
+
for (const [key, header] of delta.glyphs) {
|
|
164
|
+
glyphs.set(key, header);
|
|
165
|
+
if (plainGlyphs !== glyphs) plainGlyphs.set(key, header);
|
|
166
|
+
}
|
|
167
|
+
stats = mergePreprocessStats(stats, delta.stats, glyphs.size);
|
|
168
|
+
return true;
|
|
164
169
|
},
|
|
165
170
|
setGlyphEm(value) {
|
|
166
171
|
glyphEm = value;
|
|
167
172
|
},
|
|
168
173
|
createMaterial(materialOptions) {
|
|
169
174
|
return new WindfoilMaterial({
|
|
170
|
-
|
|
175
|
+
curves: retained.curves,
|
|
176
|
+
rows: retained.rows,
|
|
171
177
|
layered: geometryLayered,
|
|
172
178
|
...colorResources ? { paintFunctions: colorResources.paintFunctions } : {},
|
|
173
179
|
...materialOptions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/windfoil/runtime.ts"],"sourcesContent":["import {\n WebGPUBackend,\n type InstancedBufferGeometry,\n type Side,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n GlyphRequest,\n SdfAtlas,\n SdfMotionOptions,\n TextFill,\n TextToneOptions,\n TextVertex,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport type { WindfoilColorPart, WindfoilColorResources } from './color.js'\nimport {\n createWindfoilGlyphGeometry,\n updateWindfoilGlyphGeometry,\n windfoilContentFits,\n} from './geometry.js'\nimport { WindfoilMaterial } from './WindfoilMaterial.js'\nimport {\n preprocessWindfoilGlyphs,\n type WindfoilGlyphHeader,\n type WindfoilPreprocessStats,\n} from './preprocessCore.js'\nimport type { WindfoilSizeSwitch } from './sizeSwitch.js'\nimport {\n abortable,\n createWindfoilStorage,\n drawnEffects,\n throwIfAborted,\n type TextEffects,\n} from './storage.js'\nexport interface WindfoilBackend {\n readonly kind: 'windfoil' | 'slug'\n readonly layered: boolean\n /**\n * SDF atlas drawn by the companion part: glyphs without outlines plus size-switched glyphs,\n * and with `effects` every drawable outline.\n */\n readonly companion: SdfAtlas | null\n /**\n * The outline and drop shadow that an SDF underlay draws under the analytic glyphs, from\n * their companion slots; null without effects that draw anything.\n */\n readonly effects: TextEffects | null\n readonly color: WindfoilColorPart | null\n /** The `windfoil.sdfBelowPx` switch, or null when no glyph can switch. */\n readonly sizeSwitch: WindfoilSizeSwitch | null\n covers(key: string): boolean\n /** Whether the Windfoil primary batch draws this glyph. */\n primaryCovers(key: string): boolean\n /** Whether the primary batch or the colour part draws this glyph from its outline. */\n analyticCovers(key: string): boolean\n motionOrdinals(snapshot: DomLayoutSnapshot): Float32Array\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly storageBytes: number\n readonly preprocessStats: WindfoilPreprocessStats\n contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean\n createGeometry(\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): number | null\n /** Whether geometry carries each glyph's font size, which a tone that dilates reads. */\n setGlyphEm(value: boolean): void\n createMaterial(options: {\n readonly fill?: TextFill\n readonly vertex?: TextVertex\n readonly shadowCutoff?: number\n readonly side?: Side\n /** `false` builds static text, without the motion graph. */\n readonly motion: SdfMotionOptions | false\n readonly maxSequence: number\n readonly layered?: boolean\n /** Reaches the text ink of the primary batch; colour parts and shapes stay exact. */\n readonly tone?: TextToneOptions | ResolvedTextTone | false\n }): GlyphTextMaterial\n dispose(): void\n}\n\n/** Windfoil or Slug options once `DomSdf` or `DomSlug` has chosen the outline provider. */\nexport type WindfoilBuildOptions = WindfoilOptions & {\n readonly outlineProvider: WindfoilOutlineProvider\n readonly missingGlyphs?: 'skip' | 'error'\n}\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildWindfoilBackend(\n renderer: WebGPURenderer,\n requests: readonly GlyphRequest[],\n options: WindfoilBuildOptions,\n signal: AbortSignal,\n companionBuilder?: {\n build(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<SdfAtlas>\n /** The caller's outline and drop shadow, which the companion then bakes every glyph for. */\n readonly effects?: TextEffects\n },\n): Promise<WindfoilBackend | null> {\n const sdfBelow = options.sdfBelowPx\n const switchModule =\n sdfBelow === undefined ? null : await abortable(import('./sizeSwitch.js'), signal)\n // Before init, so an invalid threshold fails even where a fallback would be chosen.\n switchModule?.assertThreshold(sdfBelow)\n await abortable(renderer.init(), signal)\n throwIfAborted(signal)\n const fallback = options.fallback === 'sdf' || options.fallback === 'sdf-glyphs'\n if (!(renderer.backend instanceof WebGPUBackend)) {\n if (fallback) return null\n throw new Error(\n 'DomSdf: the Windfoil text backend requires WebGPU; set windfoil.fallback to \"sdf\" to fall back',\n )\n }\n const limit =\n (renderer.backend as unknown as { device?: { limits: { maxVertexBuffers: number } } }).device\n ?.limits.maxVertexBuffers ?? 8\n if (limit < 7) {\n if (fallback) return null\n throw new Error('DomSdf: Windfoil requires at least seven vertex buffers')\n }\n const effects = companionBuilder?.effects ? drawnEffects(companionBuilder.effects) : null\n const extended =\n !!effects ||\n requests.some((request) => request.shape) ||\n options.fallback === 'sdf-glyphs' ||\n options.compositing === 'shader' ||\n sdfBelow !== undefined\n let extensions = extended ? await abortable(import('./requests.js'), signal) : null\n let resolved: {\n request: GlyphRequest\n outline: Awaited<ReturnType<typeof options.outlineProvider>>\n }[]\n if (extensions) {\n resolved = await 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 } else {\n const syncResolved: typeof resolved = []\n let pending: Promise<(typeof resolved)[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 resolved = pending ? await abortable(Promise.all(pending), signal) : syncResolved\n }\n throwIfAborted(signal)\n const missing = resolved.filter((item) => item.outline === null)\n if (missing.length) {\n if (\n options.fallback === 'sdf' ||\n (options.fallback === 'sdf-glyphs' && missing.length === resolved.length)\n )\n return null\n if (options.fallback !== 'sdf-glyphs' || !companionBuilder)\n throw new Error(\n `DomSdf: Windfoil outlineProvider returned null for ${JSON.stringify(missing[0]!.request.character)} in ${missing[0]!.request.font.family}`,\n )\n }\n const needsRequests = !extensions && resolved.some((item) => item.outline?.clipBox)\n const needsLayerNormalization = resolved.some(\n (item) => item.outline?.layers !== undefined || item.outline?.clipBox !== undefined,\n )\n const [lateExtensions, layerModule] =\n needsRequests || needsLayerNormalization\n ? await abortable(\n Promise.all([\n needsRequests ? import('./requests.js') : Promise.resolve(null),\n needsLayerNormalization ? import('./layerNormalization.js') : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n const prepared = preprocessWindfoilGlyphs(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\n // Colour glyphs the composite shader draws (see buildWindfoilColorResources).\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n )\n const switchable = companionBuilder\n ? (switchModule?.switchableRequests(resolved, prepared.glyphs) ?? [])\n : []\n // Effects bake every drawable outline for the underlay; an empty one is drawn by nothing.\n const companionReqs = effects\n ? resolved.flatMap((i) =>\n prepared.glyphs.get(i.request.key)?.monotonePieceCount ? [i.request] : [],\n )\n : switchable\n const layered = prepared.layered || missing.length > 0 || companionReqs.length > 0\n if (layered && limit < 8) {\n if (fallback) return null\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n }\n const wantsColor = [...prepared.glyphs.values()].some(\n (header) =>\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox)),\n )\n const colorPromise = wantsColor ? import('./color.js') : null\n const companionResource =\n (missing.length || companionReqs.length) && companionBuilder\n ? await extensions!.buildCompanion(\n companionBuilder,\n [...missing.map((item) => item.request), ...companionReqs],\n signal,\n )\n : null\n let companion = companionResource?.atlas ?? null\n const view =\n companion && switchable.length\n ? switchModule!.companionView(\n companion,\n missing.map((item) => item.request.key),\n switchable,\n )\n : null\n if (view && !effects) {\n companion = view.atlas\n if (!companion) companionResource!.dispose()\n }\n let coverage: ReturnType<typeof createWindfoilStorage> | undefined,\n colorResources: WindfoilColorResources | null = null\n try {\n const colorModule = colorPromise ? await abortable(colorPromise, signal) : null\n throwIfAborted(signal)\n coverage = createWindfoilStorage(renderer, prepared)\n colorResources =\n colorModule?.buildWindfoilColorResources(renderer, prepared, options, coverage, signal) ??\n null\n const plainGlyphs = colorResources?.plainGlyphs ?? prepared.glyphs\n const ordinalsCache = new WeakMap<DomLayoutSnapshot, Float32Array>()\n const motionOrdinals = (snapshot: DomLayoutSnapshot): Float32Array => {\n let cached = ordinalsCache.get(snapshot)\n if (!cached) {\n if (extensions) {\n cached = extensions.motionOrdinals(snapshot, prepared.glyphs, companion)\n } else {\n const count = snapshot.glyphs.length\n cached = new Float32Array(count)\n for (let i = 0; i < count; i++) cached[i] = i\n }\n ordinalsCache.set(snapshot, cached)\n }\n return cached\n }\n const sizeSwitch = view?.keys.size\n ? switchModule!.createSizeSwitch(sdfBelow!, view.keys, prepared.glyphs, motionOrdinals)\n : null\n // A tone that dilates the outline reads each glyph's font size from `sdfMeta.z`: zero or\n // below never switches, so the size switch keeps its own meaning of the sign. An SVG\n // shape has no font size: its outline stays where it is.\n let glyphEm = false\n const sized = new WeakMap<DomLayoutSnapshot, DomLayoutSnapshot>()\n const withEm = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n let layout = sized.get(snapshot)\n if (!layout) {\n layout = {\n ...snapshot,\n sizeSwitched: true,\n glyphs: snapshot.glyphs.map((glyph) => ({\n ...glyph,\n switchEm: glyph.shapeGroup === undefined ? -glyph.fontSize : 0,\n })),\n }\n sized.set(snapshot, layout)\n }\n return layout\n }\n const switched = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot => {\n const layout = glyphEm ? withEm(snapshot) : snapshot\n return sizeSwitch?.layout(layout) ?? layout\n }\n let geometryLayered = layered,\n disposed = false\n const retained = coverage\n return {\n kind: 'windfoil',\n layered,\n companion,\n effects,\n color: colorResources?.composite ?? null,\n sizeSwitch,\n motionOrdinals,\n glyphs: prepared.glyphs,\n covers(key) {\n return prepared.glyphs.has(key) || !!companion?.glyphs.has(key)\n },\n primaryCovers(key) {\n return !!plainGlyphs.get(key)?.monotonePieceCount\n },\n analyticCovers(key) {\n return (\n !!plainGlyphs.get(key)?.monotonePieceCount ||\n !!colorResources?.composite?.glyphs.get(key)?.monotonePieceCount\n )\n },\n storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),\n preprocessStats: prepared.stats,\n contentFits(geometry, snapshot) {\n return windfoilContentFits(geometry, switched(snapshot), plainGlyphs)\n },\n createGeometry(snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n geometryLayered =\n layered || !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n if (geometryLayered && limit < 8)\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n return createWindfoilGlyphGeometry(\n snapshot,\n plainGlyphs,\n padding,\n geometryLayered,\n ordinals,\n )\n },\n updateGeometry(geometry, snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n return updateWindfoilGlyphGeometry(geometry, snapshot, plainGlyphs, padding, ordinals)\n },\n setGlyphEm(value) {\n glyphEm = value\n },\n createMaterial(materialOptions) {\n return new WindfoilMaterial({\n ...retained,\n layered: geometryLayered,\n ...(colorResources ? { paintFunctions: colorResources.paintFunctions } : {}),\n ...materialOptions,\n ...(sizeSwitch ? { keepGlyph: sizeSwitch.windfoil } : {}),\n })\n },\n dispose() {\n if (disposed) return\n disposed = true\n retained.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n },\n }\n } catch (error) {\n coverage?.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;;AAoGA,eAAsB,qBACpB,UACA,UACA,SACA,QACA,kBAKiC;CACjC,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,oBAAoB,M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AAgB;GACvE,iBAAiB,SAAS;GAC1B,YAAY,UAAU,UAAU;IAC9B,OAAO,oBAAoB,UAAU,SAAS,QAAQ,GAAG,WAAW;GACtE;GACA,eAAe,UAAU,SAAS,UAAU;IAC1C,WAAW,SAAS,QAAQ;IAC5B,aAAa,aAAa,gBAAgB,YAAY,eAAe,QAAQ,IAAI,KAAA;IACjF,kBACE,WAAW,CAAC,CAAC,YAAY,SAAS,OAAO,MAAM,UAAU,CAAC,CAAC,MAAM,YAAY;IAC/E,IAAI,mBAAmB,QAAQ,GAC7B,MAAM,IAAI,MAAM,wDAAwD;IAC1E,OAAO,4BACL,UACA,aACA,SACA,iBACA,QACF;GACF;GACA,eAAe,UAAU,UAAU,SAAS,UAAU;IACpD,WAAW,SAAS,QAAQ;IAC5B,aAAa,aAAa,gBAAgB,YAAY,eAAe,QAAQ,IAAI,KAAA;IACjF,OAAO,4BAA4B,UAAU,UAAU,aAAa,SAAS,QAAQ;GACvF;GACA,WAAW,OAAO;IAChB,UAAU;GACZ;GACA,eAAe,iBAAiB;IAC9B,OAAO,IAAI,iBAAiB;KAC1B,GAAG;KACH,SAAS;KACT,GAAI,iBAAiB,EAAE,gBAAgB,eAAe,eAAe,IAAI,CAAC;KAC1E,GAAG;KACH,GAAI,aAAa,EAAE,WAAW,WAAW,SAAS,IAAI,CAAC;IACzD,CAAC;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,mBAAmB,QAAQ;GAC7B;EACF;CACF,SAAS,OAAO;EACd,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,mBAAmB,QAAQ;EAC3B,MAAM;CACR;AACF"}
|
|
1
|
+
{"version":3,"file":"runtime.js","names":[],"sources":["../../src/windfoil/runtime.ts"],"sourcesContent":["import {\n WebGPUBackend,\n type InstancedBufferGeometry,\n type Side,\n type WebGPURenderer,\n} from 'three/webgpu'\nimport type { GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n GlyphRequest,\n SdfAtlas,\n SdfMotionOptions,\n TextFill,\n TextToneOptions,\n TextVertex,\n WindfoilOptions,\n WindfoilOutlineProvider,\n} from '../types.js'\nimport type { WindfoilColorPart, WindfoilColorResources } from './color.js'\nimport {\n createAnalyticGeometry,\n updateAnalyticGeometry,\n analyticGeometryFits,\n reflowWindfoilGlyphGeometry,\n} from './geometry.js'\nimport { WindfoilMaterial } from './WindfoilMaterial.js'\nimport {\n preprocessWindfoilGlyphsBatch,\n type WindfoilGlyphHeader,\n type WindfoilPreprocessStats,\n} from './preprocessCore.js'\nimport type { WindfoilSizeSwitch } from './sizeSwitch.js'\nimport {\n abortable,\n collectMissingRequests,\n createRetainedWindfoilStorage,\n drawnEffects,\n mergePreprocessStats,\n resolveOutlineRequests,\n throwIfAborted,\n type TextEffects,\n} from './storage.js'\nexport interface WindfoilBackend {\n readonly kind: 'windfoil' | 'slug'\n readonly layered: boolean\n /**\n * SDF atlas drawn by the companion part: glyphs without outlines plus size-switched glyphs,\n * and with `effects` every drawable outline.\n */\n readonly companion: SdfAtlas | null\n /**\n * The outline and drop shadow that an SDF underlay draws under the analytic glyphs, from\n * their companion slots; null without effects that draw anything.\n */\n readonly effects: TextEffects | null\n readonly color: WindfoilColorPart | null\n /** The `windfoil.sdfBelowPx` switch, or null when no glyph can switch. */\n readonly sizeSwitch: WindfoilSizeSwitch | null\n covers(key: string): boolean\n /** Whether the Windfoil primary batch draws this glyph. */\n primaryCovers(key: string): boolean\n /** Whether the primary batch or the colour part draws this glyph from its outline. */\n analyticCovers(key: string): boolean\n motionOrdinals(snapshot: DomLayoutSnapshot): Float32Array\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly storageBytes: number\n readonly preprocessStats: WindfoilPreprocessStats\n reflowGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n padding: number,\n ): number | null\n contentFits(geometry: InstancedBufferGeometry, snapshot: DomLayoutSnapshot): boolean\n createGeometry(\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n ): { geometry: InstancedBufferGeometry; maxSequence: number }\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n motionPadding: number,\n ordinals?: Float32Array,\n checked?: boolean,\n ): number | null\n append?(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<boolean>\n /** Whether geometry carries each glyph's font size, which a tone that dilates reads. */\n setGlyphEm(value: boolean): void\n createMaterial(options: {\n readonly fill?: TextFill\n readonly vertex?: TextVertex\n readonly shadowCutoff?: number\n readonly side?: Side\n /** `false` builds static text, without the motion graph. */\n readonly motion: SdfMotionOptions | false\n readonly maxSequence: number\n readonly layered?: boolean\n /** Reaches the text ink of the primary batch; colour parts and shapes stay exact. */\n readonly tone?: TextToneOptions | ResolvedTextTone | false\n }): GlyphTextMaterial\n dispose(): void\n}\n\n/** Windfoil or Slug options once `DomSdf` or `DomSlug` has chosen the outline provider. */\nexport type WindfoilBuildOptions = WindfoilOptions & {\n readonly outlineProvider: WindfoilOutlineProvider\n readonly missingGlyphs?: 'skip' | 'error'\n}\n\n/** All asynchronous resolution completes before retaining GPU storage. */\nexport async function buildWindfoilBackend(\n renderer: WebGPURenderer,\n requests: readonly GlyphRequest[],\n options: WindfoilBuildOptions,\n signal: AbortSignal,\n companionBuilder?: {\n build(requests: readonly GlyphRequest[], signal: AbortSignal): Promise<SdfAtlas>\n /** The caller's outline and drop shadow, which the companion then bakes every glyph for. */\n readonly effects?: TextEffects\n readonly headroom?: boolean\n },\n): Promise<WindfoilBackend | null> {\n const headroom = companionBuilder?.headroom === true\n const sdfBelow = options.sdfBelowPx\n const switchModule =\n sdfBelow === undefined ? null : await abortable(import('./sizeSwitch.js'), signal)\n // Before init, so an invalid threshold fails even where a fallback would be chosen.\n switchModule?.assertThreshold(sdfBelow)\n await abortable(renderer.init(), signal)\n throwIfAborted(signal)\n const fallback = options.fallback === 'sdf' || options.fallback === 'sdf-glyphs'\n if (!(renderer.backend instanceof WebGPUBackend)) {\n if (fallback) return null\n throw new Error(\n 'DomSdf: the Windfoil text backend requires WebGPU; set windfoil.fallback to \"sdf\" to fall back',\n )\n }\n const limit =\n (renderer.backend as unknown as { device?: { limits: { maxVertexBuffers: number } } }).device\n ?.limits.maxVertexBuffers ?? 8\n if (limit < 7) {\n if (fallback) return null\n throw new Error('DomSdf: Windfoil requires at least seven vertex buffers')\n }\n const effects = companionBuilder?.effects ? drawnEffects(companionBuilder.effects) : null\n const extended =\n !!effects ||\n requests.some((request) => request.shape) ||\n options.fallback === 'sdf-glyphs' ||\n options.compositing === 'shader' ||\n sdfBelow !== undefined\n let extensions = extended ? await abortable(import('./requests.js'), signal) : null\n const resolved = await resolveOutlineRequests(requests, options, signal, extensions)\n throwIfAborted(signal)\n const missing = resolved.filter((item) => item.outline === null)\n if (missing.length) {\n if (\n options.fallback === 'sdf' ||\n (options.fallback === 'sdf-glyphs' && missing.length === resolved.length)\n )\n return null\n if (options.fallback !== 'sdf-glyphs' || !companionBuilder)\n throw new Error(\n `DomSdf: Windfoil outlineProvider returned null for ${JSON.stringify(missing[0]!.request.character)} in ${missing[0]!.request.font.family}`,\n )\n }\n const needsRequests = !extensions && resolved.some((item) => item.outline?.clipBox)\n const needsLayerNormalization = resolved.some(\n (item) => item.outline?.layers !== undefined || item.outline?.clipBox !== undefined,\n )\n const [lateExtensions, initialLayerModule] =\n needsRequests || needsLayerNormalization\n ? await abortable(\n Promise.all([\n needsRequests ? import('./requests.js') : Promise.resolve(null),\n needsLayerNormalization ? import('./layerNormalization.js') : Promise.resolve(null),\n ]),\n signal,\n )\n : [null, null]\n extensions ??= lateExtensions\n let layerModule = initialLayerModule\n const prepared = preprocessWindfoilGlyphsBatch(\n resolved.filter(\n (item): item is typeof item & { outline: NonNullable<typeof item.outline> } =>\n item.outline !== null,\n ),\n {\n signal,\n // Colour glyphs the composite shader draws (see buildWindfoilColorResources).\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n )\n const switchable = companionBuilder\n ? (switchModule?.switchableRequests(resolved, prepared.glyphs) ?? [])\n : []\n // Effects bake every drawable outline for the underlay; an empty one is drawn by nothing.\n const companionReqs = effects\n ? resolved.flatMap((i) =>\n prepared.glyphs.get(i.request.key)?.monotonePieceCount ? [i.request] : [],\n )\n : switchable\n const layered = prepared.layered || missing.length > 0 || companionReqs.length > 0\n if (layered && limit < 8) {\n if (fallback) return null\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n }\n const wantsColor = [...prepared.glyphs.values()].some(\n (header) =>\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox)),\n )\n const colorPromise = wantsColor ? import('./color.js') : null\n const companionResource =\n (missing.length || companionReqs.length) && companionBuilder\n ? await extensions!.buildCompanion(\n companionBuilder,\n [...missing.map((item) => item.request), ...companionReqs],\n signal,\n )\n : null\n let companion = companionResource?.atlas ?? null\n const view =\n companion && switchable.length\n ? switchModule!.companionView(\n companion,\n missing.map((item) => item.request.key),\n switchable,\n )\n : null\n if (view && !effects) {\n companion = view.atlas\n if (!companion) companionResource!.dispose()\n }\n let coverage: ReturnType<typeof createRetainedWindfoilStorage> | undefined,\n colorResources: WindfoilColorResources | null = null\n try {\n const colorModule = colorPromise ? await abortable(colorPromise, signal) : null\n throwIfAborted(signal)\n coverage = createRetainedWindfoilStorage(\n renderer,\n prepared,\n headroom ? { minCurveFloats: 4096, minRowUints: 1536, rowAlign: 6 } : false,\n )\n colorResources =\n colorModule?.buildWindfoilColorResources(renderer, prepared, options, coverage, signal) ??\n null\n const glyphs = prepared.glyphs as Map<string, WindfoilGlyphHeader>\n const plainGlyphs = (colorResources?.plainGlyphs ?? prepared.glyphs) as Map<\n string,\n WindfoilGlyphHeader\n >\n let usedCurves = prepared.curves.length\n let usedRows = prepared.rows.length\n let stats = prepared.stats\n const ordinalsCache = new WeakMap<DomLayoutSnapshot, Float32Array>()\n const motionOrdinals = (snapshot: DomLayoutSnapshot): Float32Array => {\n let cached = ordinalsCache.get(snapshot)\n if (!cached) {\n if (extensions) {\n cached = extensions.motionOrdinals(snapshot, glyphs, companion)\n } else {\n const count = snapshot.glyphs.length\n cached = new Float32Array(count)\n for (let i = 0; i < count; i++) cached[i] = i\n }\n ordinalsCache.set(snapshot, cached)\n }\n return cached\n }\n const sizeSwitch = view?.keys.size\n ? switchModule!.createSizeSwitch(sdfBelow!, view.keys, glyphs, motionOrdinals)\n : null\n // A tone that dilates the outline reads each glyph's font size from `sdfMeta.z`: zero or\n // below never switches, so the size switch keeps its own meaning of the sign. An SVG\n // shape has no font size: its outline stays where it is.\n let glyphEm = false\n const switched = (snapshot: DomLayoutSnapshot): DomLayoutSnapshot =>\n sizeSwitch?.layout(snapshot, glyphEm) ?? snapshot\n let geometryLayered = layered,\n disposed = false\n const retained = coverage\n return {\n kind: 'windfoil',\n layered,\n companion,\n effects,\n color: colorResources?.composite ?? null,\n sizeSwitch,\n motionOrdinals,\n glyphs,\n covers(key) {\n return glyphs.has(key) || !!companion?.glyphs.has(key)\n },\n primaryCovers(key) {\n return !!plainGlyphs.get(key)?.monotonePieceCount\n },\n analyticCovers(key) {\n return (\n !!plainGlyphs.get(key)?.monotonePieceCount ||\n !!colorResources?.composite?.glyphs.get(key)?.monotonePieceCount\n )\n },\n storageBytes: coverage.storageBytes + (colorResources?.storageBytes ?? 0),\n get preprocessStats() {\n return stats\n },\n contentFits(geometry, snapshot) {\n return analyticGeometryFits(\n geometry,\n switched(snapshot),\n plainGlyphs,\n glyphEm && !sizeSwitch,\n )\n },\n reflowGeometry(this: WindfoilBackend, geometry, snapshot, padding) {\n return reflowWindfoilGlyphGeometry(geometry, snapshot, this, padding, glyphEm)\n },\n createGeometry(snapshot, padding, ordinals) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n geometryLayered =\n layered || !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n if (geometryLayered && limit < 8)\n throw new Error('DomSdf: layered Windfoil requires eight vertex buffers')\n return createAnalyticGeometry(\n snapshot,\n plainGlyphs,\n padding,\n geometryLayered,\n ordinals,\n glyphEm && !sizeSwitch,\n )\n },\n updateGeometry(geometry, snapshot, padding, ordinals, checked = false) {\n snapshot = switched(snapshot)\n ordinals ??= companion || colorResources?.composite ? motionOrdinals(snapshot) : undefined\n return updateAnalyticGeometry(\n geometry,\n snapshot,\n plainGlyphs,\n padding,\n ordinals,\n checked,\n glyphEm && !sizeSwitch,\n )\n },\n async append(nextRequests, appendSignal) {\n if (disposed || effects) return false\n const missingReqs = collectMissingRequests(\n nextRequests,\n (key) => glyphs.has(key) || !!companion?.glyphs.has(key),\n )\n if (missingReqs.length === 0) return true\n if (!extensions && missingReqs.some((req) => req.shape !== undefined)) {\n extensions = await abortable(import('./requests.js'), appendSignal)\n }\n const deltaResolved = await resolveOutlineRequests(\n missingReqs,\n options,\n appendSignal,\n extensions,\n )\n throwIfAborted(appendSignal)\n if (deltaResolved.some((item) => item.outline === null)) return false\n const nonNull = deltaResolved as {\n request: GlyphRequest\n outline: NonNullable<(typeof deltaResolved)[number]['outline']>\n }[]\n if (\n !layerModule &&\n nonNull.some(\n (item) => item.outline.layers !== undefined || item.outline.clipBox !== undefined,\n )\n ) {\n layerModule = await abortable(import('./layerNormalization.js'), appendSignal)\n throwIfAborted(appendSignal)\n }\n const delta = preprocessWindfoilGlyphsBatch(\n nonNull,\n {\n signal: appendSignal,\n orientLayers: (outline) => options.compositing === 'shader' || !!outline.clipBox,\n ...(layerModule ? { normalizeLayers: layerModule.normalizeLayers } : {}),\n ...(options.targetPiecesPerBand === undefined\n ? {}\n : { targetPiecesPerBand: options.targetPiecesPerBand }),\n },\n usedCurves,\n usedRows,\n )\n if (delta.layered && !layered) return false\n if (\n companionBuilder &&\n switchModule &&\n switchModule.switchableRequests(deltaResolved, delta.glyphs).length > 0\n ) {\n return false\n }\n for (const header of delta.glyphs.values()) {\n if (\n (header.layers?.some((layer) => layer.paintKind === 2) ?? false) ||\n (header.layers && (options.compositing === 'shader' || !!header.clipBox))\n ) {\n return false\n }\n }\n if (\n usedCurves + delta.curves.length > retained.curveCapacityFloats ||\n usedRows + delta.rows.length > retained.rowCapacityUints\n ) {\n return false\n }\n throwIfAborted(appendSignal)\n retained.writeCurves(usedCurves, delta.curves)\n retained.writeRows(usedRows, delta.rows)\n usedCurves += delta.curves.length\n usedRows += delta.rows.length\n for (const [key, header] of delta.glyphs) {\n glyphs.set(key, header)\n if (plainGlyphs !== glyphs) plainGlyphs.set(key, header)\n }\n stats = mergePreprocessStats(stats, delta.stats, glyphs.size)\n return true\n },\n setGlyphEm(value) {\n glyphEm = value\n },\n createMaterial(materialOptions) {\n return new WindfoilMaterial({\n curves: retained.curves,\n rows: retained.rows,\n layered: geometryLayered,\n ...(colorResources ? { paintFunctions: colorResources.paintFunctions } : {}),\n ...materialOptions,\n ...(sizeSwitch ? { keepGlyph: sizeSwitch.windfoil } : {}),\n })\n },\n dispose() {\n if (disposed) return\n disposed = true\n retained.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n },\n }\n } catch (error) {\n coverage?.dispose()\n colorResources?.dispose()\n companionResource?.dispose()\n throw error\n }\n}\n"],"mappings":";;;;;;;;AA+GA,eAAsB,qBACpB,UACA,UACA,SACA,QACA,kBAMiC;CACjC,MAAM,WAAW,kBAAkB,aAAa;CAChD,MAAM,WAAW,QAAQ;CACzB,MAAM,eACJ,aAAa,KAAA,IAAY,OAAO,MAAM,UAAU,OAAO,oBAAoB,MAAM;CAEnF,cAAc,gBAAgB,QAAQ;CACtC,MAAM,UAAU,SAAS,KAAK,GAAG,MAAM;CACvC,e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,MAAM,OAAO;IAC3B,YAAY,MAAM,KAAK;IACvB,KAAK,MAAM,CAAC,KAAK,WAAW,MAAM,QAAQ;KACxC,OAAO,IAAI,KAAK,MAAM;KACtB,IAAI,gBAAgB,QAAQ,YAAY,IAAI,KAAK,MAAM;IACzD;IACA,QAAQ,qBAAqB,OAAO,MAAM,OAAO,OAAO,IAAI;IAC5D,OAAO;GACT;GACA,WAAW,OAAO;IAChB,UAAU;GACZ;GACA,eAAe,iBAAiB;IAC9B,OAAO,IAAI,iBAAiB;KAC1B,QAAQ,SAAS;KACjB,MAAM,SAAS;KACf,SAAS;KACT,GAAI,iBAAiB,EAAE,gBAAgB,eAAe,eAAe,IAAI,CAAC;KAC1E,GAAG;KACH,GAAI,aAAa,EAAE,WAAW,WAAW,SAAS,IAAI,CAAC;IACzD,CAAC;GACH;GACA,UAAU;IACR,IAAI,UAAU;IACd,WAAW;IACX,SAAS,QAAQ;IACjB,gBAAgB,QAAQ;IACxB,mBAAmB,QAAQ;GAC7B;EACF;CACF,SAAS,OAAO;EACd,UAAU,QAAQ;EAClB,gBAAgB,QAAQ;EACxB,mBAAmB,QAAQ;EAC3B,MAAM;CACR;AACF"}
|
|
@@ -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,CAAC,KACvC,SAAS,QAAQ,GAEjB,MAAM,IAAI,WAAW,aAAa,MAAM,gDAAgD;EAC1F,MAAM,UAAU,SAAS,WAAW;EACpC,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,UAAU,KAAK,UAAU,GACxD,MAAM,IAAI,WAAW,aAAa,MAAM,4BAA4B;EACtE,MAAM,OAAO,SAAS;EACtB,IACE,SACE,KAA2B,WAAW,KACtC,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,KAAK,KAAK,KAAK,MACf,KAAK,KAAK,KAAK,KAEjB,MAAM,IAAI,WAAW,aAAa,MAAM,2CAA2C;CACvF;AACF;AACA,IAAM,eAAe;CAAC;CAAM;CAAM;CAAK;AAAG;AAC1C,IAAM,cAAc;CAAC;CAAG;CAAG;AAAC;AAC5B,I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,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;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,CAAC,KACvC,SAAS,QAAQ,GAEjB,MAAM,IAAI,WAAW,aAAa,MAAM,gDAAgD;EAC1F,MAAM,UAAU,SAAS,WAAW;EACpC,IAAI,CAAC,OAAO,SAAS,OAAO,KAAK,UAAU,KAAK,UAAU,GACxD,MAAM,IAAI,WAAW,aAAa,MAAM,4BAA4B;EACtE,MAAM,OAAO,SAAS;EACtB,IACE,SACE,KAA2B,WAAW,KACtC,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACxB,CAAC,OAAO,SAAS,KAAK,EAAE,KACx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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
|
};
|