ultra-text 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
package/dist/dom/DomSdf.js
CHANGED
|
@@ -4,11 +4,9 @@ import { isColorCandidate } from "./fontCanvas.js";
|
|
|
4
4
|
import { rasterizeGlyphAtlas } from "../atlas/rasterize.js";
|
|
5
5
|
import { resolveDomTextTone } from "./tone.js";
|
|
6
6
|
import { isAnimatedMotion } from "../text/GlyphTextMaterial.js";
|
|
7
|
-
import { createRectMaterial } from "../text/RectMaterial.js";
|
|
8
7
|
import { SdfTextMaterial } from "../text/SdfTextMaterial.js";
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { TextDecorationMaterial, canUpdateDecorationGeometry, createDecorationGeometry, updateDecorationGeometry } from "../text/decorations.js";
|
|
8
|
+
import { hasDecorations, needsRunMotion } from "../text/geometryUtils.js";
|
|
9
|
+
import { createGlyphGeometry, glyphContentFits, updateGlyphContent, updateGlyphGeometry } from "../text/glyphGeometry.js";
|
|
12
10
|
import "./markup.js";
|
|
13
11
|
import { collectDomSnapshot } from "./snapshot.js";
|
|
14
12
|
import { layoutSignatureOf } from "./layoutSignature.js";
|
|
@@ -35,9 +33,6 @@ var EMPTY_STATS = Object.freeze({
|
|
|
35
33
|
function isWindfoilBackend(backend) {
|
|
36
34
|
return "kind" in backend;
|
|
37
35
|
}
|
|
38
|
-
function buildGlyphGeometry(snapshot, backend, motionPadding) {
|
|
39
|
-
return isWindfoilBackend(backend) ? backend.createGeometry(snapshot, motionPadding) : createGlyphGeometry(snapshot, backend, motionPadding);
|
|
40
|
-
}
|
|
41
36
|
function sdfStorageBytes(atlas, mipmaps) {
|
|
42
37
|
const count = (w, h, bpp) => w * h * bpp + (mipmaps && (w > 1 || h > 1) ? count(w >> 1 || 1, h >> 1 || 1, bpp) : 0);
|
|
43
38
|
return count(atlas.width, atlas.height, 1) + (atlas.colorLayer ? count(atlas.width, atlas.colorLayer.height, 4) : 0);
|
|
@@ -49,13 +44,17 @@ var ATTRIBUTE_MAX_WAIT_MS = 320;
|
|
|
49
44
|
function now() {
|
|
50
45
|
return performance.now();
|
|
51
46
|
}
|
|
47
|
+
function copyDefined(target, source, keys) {
|
|
48
|
+
const src = source;
|
|
49
|
+
for (const key of keys) if (src[key] !== void 0) target[key] = src[key];
|
|
50
|
+
}
|
|
52
51
|
function abortError(message = "The DOM SDF build was aborted") {
|
|
53
52
|
return new DOMException(message, "AbortError");
|
|
54
53
|
}
|
|
55
54
|
function throwIfAborted(signal) {
|
|
56
55
|
if (signal.aborted) throw signal.reason ?? abortError();
|
|
57
56
|
}
|
|
58
|
-
function createContent(snapshot, backend, options, motion, tone,
|
|
57
|
+
function createContent(snapshot, backend, options, motion, tone, extrasMod) {
|
|
59
58
|
const materialOptions = {
|
|
60
59
|
...options,
|
|
61
60
|
tone: tone ?? false
|
|
@@ -67,20 +66,13 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
67
66
|
const strength = motion.strength ?? 18;
|
|
68
67
|
let animated = isAnimatedMotion(motion);
|
|
69
68
|
const materialMotion = (live) => animated ? live : false;
|
|
70
|
-
const { geometry: glyphGeometry, maxSequence } =
|
|
71
|
-
const
|
|
72
|
-
const usesColor = (layout) => !!(isWindfoilBackend(backend) ? backend.companion?.colorLayer : backend.colorLayer) && (options.colorGlyphs !== "none" || layout.requests.some((request) => request.shape?.bitmap));
|
|
69
|
+
const { geometry: glyphGeometry, maxSequence } = createGlyphGeometry(snapshot, backend, strength);
|
|
70
|
+
const usesColor = (layout) => !!backend.colorLayer && (options.colorGlyphs !== "none" || layout.requests.some((request) => request.shape?.bitmap));
|
|
73
71
|
const colorEnabled = usesColor(snapshot);
|
|
74
|
-
const runMotion = needsRunMotion(snapshot)
|
|
75
|
-
const maxSeq = (s) => s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0);
|
|
76
|
-
const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence;
|
|
72
|
+
const runMotion = needsRunMotion(snapshot);
|
|
77
73
|
let textMaterial;
|
|
78
74
|
try {
|
|
79
|
-
textMaterial =
|
|
80
|
-
...materialOptions,
|
|
81
|
-
maxSequence: hasExtras ? globalSequence : maxSequence,
|
|
82
|
-
motion: materialMotion(motion)
|
|
83
|
-
}) : new SdfTextMaterial({
|
|
75
|
+
textMaterial = new SdfTextMaterial({
|
|
84
76
|
...materialOptions,
|
|
85
77
|
runMotion,
|
|
86
78
|
...colorEnabled ? { colorLayer: backend.colorLayer } : {},
|
|
@@ -97,14 +89,6 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
97
89
|
glyphGeometry.dispose();
|
|
98
90
|
throw error;
|
|
99
91
|
}
|
|
100
|
-
let extras;
|
|
101
|
-
try {
|
|
102
|
-
if (hasExtras && isWindfoilBackend(backend)) extras = makeExtraParts(snapshot, backend, materialOptions, materialMotion(motion), strength);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
glyphGeometry.dispose();
|
|
105
|
-
textMaterial.dispose();
|
|
106
|
-
throw error;
|
|
107
|
-
}
|
|
108
92
|
const text = new Mesh(glyphGeometry, textMaterial);
|
|
109
93
|
text.name = "ultra-text text";
|
|
110
94
|
text.castShadow = options.castShadow !== false;
|
|
@@ -122,101 +106,10 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
122
106
|
ownedMeshes.length = 0;
|
|
123
107
|
group.clear();
|
|
124
108
|
};
|
|
109
|
+
const glyphDrawable = (retained, key) => retained.glyphs.has(key);
|
|
110
|
+
let ce = null;
|
|
125
111
|
try {
|
|
126
|
-
if (
|
|
127
|
-
for (const mesh of extras.meshes) {
|
|
128
|
-
group.add(mesh);
|
|
129
|
-
ownedMeshes.push(mesh);
|
|
130
|
-
}
|
|
131
|
-
extras.mergeRects(snapshot, text.geometry);
|
|
132
|
-
}
|
|
133
|
-
} catch (error) {
|
|
134
|
-
disposeMeshes();
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
let decorations = null;
|
|
138
|
-
const glyphDrawable = (retained, key) => {
|
|
139
|
-
if (isWindfoilBackend(retained)) return (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key);
|
|
140
|
-
return retained.glyphs.has(key);
|
|
141
|
-
};
|
|
142
|
-
const prepareDecorations = (layout, retained, liveMotion, nextTextGeometry, nextSequence, drawable = (key) => glyphDrawable(retained, key)) => {
|
|
143
|
-
const geometry = createDecorationGeometry(layout, nextTextGeometry, drawable, liveMotion.strength ?? 18);
|
|
144
|
-
try {
|
|
145
|
-
return [geometry, geometry && !decorations ? new TextDecorationMaterial({
|
|
146
|
-
textShaping: options.textShaping ?? "none",
|
|
147
|
-
side: options.side,
|
|
148
|
-
vertex: options.vertex,
|
|
149
|
-
motion: materialMotion(liveMotion),
|
|
150
|
-
maxSequence: nextSequence
|
|
151
|
-
}) : null];
|
|
152
|
-
} catch (error) {
|
|
153
|
-
geometry?.dispose();
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const commitDecorations = ([geometry, material], liveMotion) => {
|
|
158
|
-
if (!geometry) {
|
|
159
|
-
if (decorations) {
|
|
160
|
-
group.remove(decorations);
|
|
161
|
-
ownedMeshes.splice(ownedMeshes.indexOf(decorations), 1);
|
|
162
|
-
decorations.geometry.dispose();
|
|
163
|
-
decorations.material.dispose();
|
|
164
|
-
decorations = null;
|
|
165
|
-
}
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
if (decorations) {
|
|
169
|
-
const previous = decorations.geometry;
|
|
170
|
-
decorations.geometry = geometry;
|
|
171
|
-
previous.dispose();
|
|
172
|
-
if (animated) decorations.material.setMotion(liveMotion);
|
|
173
|
-
decorations.material.maxSequence.value = textMaterial.maxSequence.value;
|
|
174
|
-
} else {
|
|
175
|
-
decorations = new Mesh(geometry, material);
|
|
176
|
-
decorations.name = "ultra-text text decorations";
|
|
177
|
-
decorations.castShadow = options.castShadow !== false;
|
|
178
|
-
decorations.renderOrder = 3;
|
|
179
|
-
decorations.frustumCulled = false;
|
|
180
|
-
group.add(decorations);
|
|
181
|
-
ownedMeshes.push(decorations);
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
const updateDecorations = (layout, retained, liveMotion, drawable = (key) => glyphDrawable(retained, key)) => {
|
|
185
|
-
if (!decorations) return;
|
|
186
|
-
if (updateDecorationGeometry(decorations.geometry, layout, text.geometry, drawable, liveMotion.strength ?? 18)) {
|
|
187
|
-
if (animated) decorations.material.setMotion(liveMotion);
|
|
188
|
-
decorations.material.maxSequence.value = textMaterial.maxSequence.value;
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
commitDecorations(prepareDecorations(layout, retained, liveMotion, text.geometry, textMaterial.maxSequence.value, drawable), liveMotion);
|
|
192
|
-
};
|
|
193
|
-
const addRects = (receiver, name) => {
|
|
194
|
-
const geometry = createRectGeometry(snapshot, receiver);
|
|
195
|
-
if (!geometry) return null;
|
|
196
|
-
let mesh;
|
|
197
|
-
try {
|
|
198
|
-
mesh = new Mesh(geometry, createRectMaterial(receiver, options.shadowFloor));
|
|
199
|
-
} catch (error) {
|
|
200
|
-
geometry.dispose();
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
mesh.name = name;
|
|
204
|
-
mesh.receiveShadow = receiver;
|
|
205
|
-
mesh.frustumCulled = true;
|
|
206
|
-
mesh.renderOrder = 0;
|
|
207
|
-
mesh.matrixAutoUpdate = false;
|
|
208
|
-
mesh.updateMatrix();
|
|
209
|
-
group.add(mesh);
|
|
210
|
-
ownedMeshes.push(mesh);
|
|
211
|
-
return mesh;
|
|
212
|
-
};
|
|
213
|
-
let plainRects = null;
|
|
214
|
-
let receivers = null;
|
|
215
|
-
try {
|
|
216
|
-
const initialDecorations = prepareDecorations(snapshot, backend, motion, text.geometry, textMaterial.maxSequence.value);
|
|
217
|
-
if (initialDecorations[0]) commitDecorations(initialDecorations, motion);
|
|
218
|
-
plainRects = addRects(false, "ultra-text DOM rectangles");
|
|
219
|
-
receivers = addRects(true, "ultra-text shadow receivers");
|
|
112
|
+
if (extrasMod) ce = extrasMod.createContentExtras(snapshot, text.geometry, group, ownedMeshes, options, () => animated, motion, textMaterial.maxSequence.value, (key) => glyphDrawable(backend, key));
|
|
220
113
|
} catch (error) {
|
|
221
114
|
disposeMeshes();
|
|
222
115
|
throw error;
|
|
@@ -226,12 +119,7 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
226
119
|
mesh.geometry = geometry;
|
|
227
120
|
previous.dispose();
|
|
228
121
|
};
|
|
229
|
-
const setTone = (next) =>
|
|
230
|
-
if (!textMaterial.setTone(next)) return false;
|
|
231
|
-
for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next);
|
|
232
|
-
return true;
|
|
233
|
-
};
|
|
234
|
-
/** Whether `setTone` would accept this tone, without writing it. */
|
|
122
|
+
const setTone = (next) => textMaterial.setTone(next);
|
|
235
123
|
const toneFits = (next) => {
|
|
236
124
|
const current = textMaterial.tone;
|
|
237
125
|
return current && next ? current.fits(next) : !current && !next;
|
|
@@ -248,16 +136,12 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
248
136
|
sm(change, live) {
|
|
249
137
|
if (animated) {
|
|
250
138
|
textMaterial.setMotion(change);
|
|
251
|
-
|
|
252
|
-
decorations?.material.setMotion(change);
|
|
139
|
+
ce?.setMotion(change);
|
|
253
140
|
return;
|
|
254
141
|
}
|
|
255
142
|
if (!isAnimatedMotion(live)) return;
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
...extras?.meshes ?? [],
|
|
259
|
-
...decorations ? [decorations] : []
|
|
260
|
-
];
|
|
143
|
+
const decMesh = ce?.decMesh();
|
|
144
|
+
const meshes = [text, ...decMesh ? [decMesh] : []];
|
|
261
145
|
const twins = [];
|
|
262
146
|
try {
|
|
263
147
|
for (const mesh of meshes) twins.push(mesh.material.withMotion(live));
|
|
@@ -274,7 +158,9 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
274
158
|
animated = true;
|
|
275
159
|
},
|
|
276
160
|
st: setTone,
|
|
277
|
-
ud
|
|
161
|
+
ud(layout, retained, liveMotion) {
|
|
162
|
+
ce?.updateDec(layout, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, (key) => glyphDrawable(retained, key));
|
|
163
|
+
},
|
|
278
164
|
get tg() {
|
|
279
165
|
return text.geometry;
|
|
280
166
|
},
|
|
@@ -283,40 +169,22 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
283
169
|
},
|
|
284
170
|
u(nextSnapshot, nextBackend, liveMotion, nextTone) {
|
|
285
171
|
if (nextTone !== void 0 && (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))) return false;
|
|
286
|
-
if (runMotion !==
|
|
172
|
+
if (runMotion !== needsRunMotion(nextSnapshot)) return false;
|
|
287
173
|
if (colorEnabled !== usesColor(nextSnapshot)) return false;
|
|
288
|
-
|
|
289
|
-
const wantsReceivers = nextSnapshot.rects.some((rect) => rect.receiveShadow);
|
|
290
|
-
if (wantsPlain !== (plainRects !== null) || wantsReceivers !== (receivers !== null)) return false;
|
|
174
|
+
if (ce ? !ce.fitsLayout(nextSnapshot) : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)) return false;
|
|
291
175
|
const strength = liveMotion.strength ?? 18;
|
|
292
176
|
const drawable = (key) => glyphDrawable(nextBackend, key);
|
|
293
|
-
const decorationsFit =
|
|
294
|
-
|
|
295
|
-
const glyphsFit = decorationsFit && (isWindfoilBackend(nextBackend) ? nextBackend.contentFits(text.geometry, nextSnapshot) : glyphContentFits(text.geometry, nextSnapshot, nextBackend));
|
|
296
|
-
const plainFit = !plainRects || rectContentFits(plainRects.geometry, nextSnapshot, false);
|
|
297
|
-
const receiverFit = !receivers || rectContentFits(receivers.geometry, nextSnapshot, true);
|
|
177
|
+
const decorationsFit = ce ? ce.decorationsFit(nextSnapshot, drawable) : true;
|
|
178
|
+
const glyphsFit = decorationsFit && glyphContentFits(text.geometry, nextSnapshot, nextBackend);
|
|
298
179
|
let built = null;
|
|
299
|
-
let
|
|
300
|
-
let nextPlain = null;
|
|
301
|
-
let nextReceivers = null;
|
|
302
|
-
let nextDecorations = null;
|
|
180
|
+
let stagedExtras = null;
|
|
303
181
|
const releaseStaged = () => {
|
|
304
182
|
built?.geometry.dispose();
|
|
305
|
-
|
|
306
|
-
nextPlain?.dispose();
|
|
307
|
-
nextReceivers?.dispose();
|
|
308
|
-
nextDecorations?.[0]?.dispose();
|
|
309
|
-
nextDecorations?.[1]?.dispose();
|
|
183
|
+
stagedExtras?.dispose();
|
|
310
184
|
};
|
|
311
185
|
try {
|
|
312
|
-
|
|
313
|
-
if (
|
|
314
|
-
if (plainRects && !plainFit) nextPlain = createRectGeometry(nextSnapshot, false);
|
|
315
|
-
if (receivers && !receiverFit) nextReceivers = createRectGeometry(nextSnapshot, true);
|
|
316
|
-
if (!decorationsFit) {
|
|
317
|
-
const source = built?.geometry ?? text.geometry;
|
|
318
|
-
nextDecorations = prepareDecorations(nextSnapshot, nextBackend, liveMotion, source, built?.maxSequence ?? textMaterial.maxSequence.value, drawable);
|
|
319
|
-
}
|
|
186
|
+
if (!glyphsFit) built = createGlyphGeometry(nextSnapshot, nextBackend, strength);
|
|
187
|
+
if (ce) stagedExtras = ce.prepare(nextSnapshot, built?.geometry ?? text.geometry, animated, liveMotion, built?.maxSequence ?? textMaterial.maxSequence.value, decorationsFit, drawable);
|
|
320
188
|
} catch (error) {
|
|
321
189
|
releaseStaged();
|
|
322
190
|
throw error;
|
|
@@ -325,24 +193,14 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
325
193
|
swapGeometry(text, built.geometry);
|
|
326
194
|
textMaterial.maxSequence.value = built.maxSequence;
|
|
327
195
|
} else {
|
|
328
|
-
const maxSequence =
|
|
196
|
+
const maxSequence = updateGlyphContent(text.geometry, nextSnapshot, nextBackend, strength, void 0, true);
|
|
329
197
|
if (maxSequence === null) {
|
|
330
198
|
releaseStaged();
|
|
331
199
|
throw new Error("DomSdf: glyph buffers changed during the update");
|
|
332
200
|
}
|
|
333
201
|
textMaterial.maxSequence.value = maxSequence;
|
|
334
202
|
}
|
|
335
|
-
|
|
336
|
-
extras.commit(nextParts, nextSnapshot, strength);
|
|
337
|
-
textMaterial.maxSequence.value = maxSeq(nextSnapshot);
|
|
338
|
-
extras.mergeRects(nextSnapshot, text.geometry);
|
|
339
|
-
}
|
|
340
|
-
if (nextDecorations) commitDecorations(nextDecorations, liveMotion);
|
|
341
|
-
else updateDecorations(nextSnapshot, nextBackend, liveMotion, drawable);
|
|
342
|
-
if (plainRects && nextPlain) swapGeometry(plainRects, nextPlain);
|
|
343
|
-
else if (plainRects) updateRectGeometry(plainRects.geometry, nextSnapshot, false);
|
|
344
|
-
if (receivers && nextReceivers) swapGeometry(receivers, nextReceivers);
|
|
345
|
-
else if (receivers) updateRectGeometry(receivers.geometry, nextSnapshot, true);
|
|
203
|
+
ce?.commit(stagedExtras, nextSnapshot, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, drawable, swapGeometry);
|
|
346
204
|
if (nextTone !== void 0) setTone(nextTone);
|
|
347
205
|
return true;
|
|
348
206
|
},
|
|
@@ -372,10 +230,17 @@ var DomSdf = class DomSdf extends Group {
|
|
|
372
230
|
#mo = null;
|
|
373
231
|
#uf = null;
|
|
374
232
|
snapshot = null;
|
|
233
|
+
#rf = null;
|
|
234
|
+
#rm = null;
|
|
235
|
+
#em = null;
|
|
236
|
+
#am = null;
|
|
237
|
+
#sm = null;
|
|
375
238
|
#w = 0;
|
|
376
239
|
#h = 0;
|
|
377
240
|
#as = "";
|
|
378
241
|
#ls = "";
|
|
242
|
+
#ps = null;
|
|
243
|
+
#pc = null;
|
|
379
244
|
#cm = false;
|
|
380
245
|
#ga = false;
|
|
381
246
|
#ac;
|
|
@@ -439,32 +304,43 @@ var DomSdf = class DomSdf extends Group {
|
|
|
439
304
|
}
|
|
440
305
|
reflow(width) {
|
|
441
306
|
if (this.#d) throw new Error("DomSdf.reflow: this instance is disposed");
|
|
442
|
-
|
|
307
|
+
const rm = this.#rm;
|
|
308
|
+
if (!this.snapshot || !rm) throw new Error("DomSdf.reflow: create the instance with reflowable: true first");
|
|
443
309
|
if (!this.#r || !this.#c) return this;
|
|
444
310
|
const retained = this.#r;
|
|
445
311
|
const content = this.#c;
|
|
446
|
-
if (isWindfoilBackend(retained)) retained.setGlyphEm(!!content.m.tone?.dilates);
|
|
447
312
|
const started = now();
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
313
|
+
let reflowedWidth;
|
|
314
|
+
let reflowedHeight;
|
|
315
|
+
let reflowedLines;
|
|
316
|
+
if (isWindfoilBackend(retained)) {
|
|
317
|
+
const res = this.#am.reflowAnalytic(this.snapshot, retained, content, width, this.#m, rm, this.#rf);
|
|
318
|
+
this.#rf = res.state;
|
|
319
|
+
reflowedWidth = res.width;
|
|
320
|
+
reflowedHeight = res.height;
|
|
321
|
+
reflowedLines = res.lines;
|
|
452
322
|
} else {
|
|
453
|
-
|
|
323
|
+
const reflowed = rm.reflowSnapshotWithState(this.snapshot, width, this.#rf ??= rm.createReflowState(this.snapshot));
|
|
324
|
+
const sdfContent = content;
|
|
325
|
+
const strength = this.#m.strength ?? 18;
|
|
326
|
+
let maxSequence = updateGlyphGeometry(sdfContent.tg, reflowed, retained, strength);
|
|
454
327
|
if (maxSequence === null) {
|
|
455
|
-
const built =
|
|
456
|
-
|
|
328
|
+
const built = createGlyphGeometry(reflowed, retained, strength);
|
|
329
|
+
sdfContent.rg(built.geometry);
|
|
457
330
|
maxSequence = built.maxSequence;
|
|
458
331
|
}
|
|
459
|
-
|
|
460
|
-
|
|
332
|
+
sdfContent.m.maxSequence.value = maxSequence;
|
|
333
|
+
sdfContent.ud(reflowed, retained, this.#m);
|
|
334
|
+
reflowedWidth = reflowed.width;
|
|
335
|
+
reflowedHeight = reflowed.height;
|
|
336
|
+
reflowedLines = reflowed.lineCount;
|
|
461
337
|
}
|
|
462
338
|
this.#cm = false;
|
|
463
|
-
this.#w =
|
|
464
|
-
this.#h =
|
|
339
|
+
this.#w = reflowedWidth;
|
|
340
|
+
this.#h = reflowedHeight;
|
|
465
341
|
this.#st = Object.freeze({
|
|
466
342
|
...this.#st,
|
|
467
|
-
lines:
|
|
343
|
+
lines: reflowedLines,
|
|
468
344
|
layoutReadMs: 0,
|
|
469
345
|
atlasBuildMs: 0,
|
|
470
346
|
geometryBuildMs: now() - started
|
|
@@ -492,21 +368,36 @@ var DomSdf = class DomSdf extends Group {
|
|
|
492
368
|
atlas: null,
|
|
493
369
|
ms: 0
|
|
494
370
|
};
|
|
371
|
+
let preparedWorkerPromise = null;
|
|
372
|
+
let reflowPromise = null;
|
|
495
373
|
try {
|
|
374
|
+
const opts = this.options;
|
|
375
|
+
const backendKind = opts.textBackend;
|
|
376
|
+
const isAnalyticOption = backendKind === "windfoil" || backendKind === "slug";
|
|
377
|
+
const analytic = (backendKind === "slug" ? opts.slug ?? opts.windfoil : opts.windfoil) ?? {};
|
|
378
|
+
const fallback = analytic.fallback ?? (analytic.outlineProvider ? "error" : "sdf-glyphs");
|
|
379
|
+
const mayBuildSdf = !isAnalyticOption || opts.textShaping === "browser" || fallback !== "error" || analytic.sdfBelowPx !== void 0 || opts.outline !== void 0 || opts.dropShadow !== void 0;
|
|
380
|
+
if (opts.atlasMode === "cpu" && mayBuildSdf && !this.#r) {
|
|
381
|
+
import("../atlas/cpuAtlas.js").catch(() => null);
|
|
382
|
+
if (opts.cpuWorker !== false && typeof Worker !== "undefined") preparedWorkerPromise = import("../atlas/cpuWorker.js").then(({ prepareCpuWorker }) => prepareCpuWorker()).catch(() => null);
|
|
383
|
+
}
|
|
384
|
+
if (opts.reflowable === true && !this.#rm) reflowPromise = import("../text/reflow.js").then((mod) => {
|
|
385
|
+
this.#rm = mod;
|
|
386
|
+
});
|
|
496
387
|
await Promise.resolve();
|
|
497
388
|
throwIfAborted(controller.signal);
|
|
498
389
|
if (generation !== this.#g) throw abortError("Superseded by a newer DOM SDF build");
|
|
499
|
-
const opts = this.options;
|
|
500
390
|
const gpuUpload = opts.atlasMode !== "cpu" && this.renderer.initialized && this.renderer.backend.isWebGPUBackend === true;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (gpuUpload && !isAnalyticOption && !this.#r) prepareAtlasPasses(this.renderer);
|
|
391
|
+
if (gpuUpload && mayBuildSdf && !this.#r) prepareAtlasPasses(this.renderer, opts.padding);
|
|
392
|
+
let preloadAnalytic = null;
|
|
504
393
|
let preloadBackend = null;
|
|
505
394
|
let preloadTraced = null;
|
|
506
395
|
if (isAnalyticOption && opts.textShaping !== "browser") {
|
|
396
|
+
if (!this.#am) preloadAnalytic = import("./domAnalytic.js").then((m) => this.#am = m);
|
|
507
397
|
preloadBackend = (backendKind === "slug" ? import("../slug/runtime.js") : import("../windfoil/runtime.js")).catch(() => null);
|
|
508
|
-
if (!
|
|
398
|
+
if (!analytic.outlineProvider && !this.#to) preloadTraced = import("../windfoil/tracedOutlines.js").catch(() => null);
|
|
509
399
|
}
|
|
400
|
+
const svgPromise = opts.svg && !this.#sm ? import("./svgCapture.js").then((m) => this.#sm = m) : null;
|
|
510
401
|
const layoutStarted = now();
|
|
511
402
|
const snapshot = await collectDomSnapshot(this.source, opts);
|
|
512
403
|
const tone = resolveDomTextTone(this.source, opts.tone, {
|
|
@@ -517,6 +408,17 @@ var DomSdf = class DomSdf extends Group {
|
|
|
517
408
|
});
|
|
518
409
|
const layoutReadMs = now() - layoutStarted;
|
|
519
410
|
throwIfAborted(controller.signal);
|
|
411
|
+
let extrasPromise = !this.#em && (snapshot.rects.length > 0 || hasDecorations(snapshot)) ? import("./domExtras.js").then((mod) => {
|
|
412
|
+
this.#em = mod;
|
|
413
|
+
}) : null;
|
|
414
|
+
const ensureLazyMods = async () => {
|
|
415
|
+
if (!extrasPromise) return;
|
|
416
|
+
const p = extrasPromise;
|
|
417
|
+
extrasPromise = null;
|
|
418
|
+
await p;
|
|
419
|
+
throwIfAborted(controller.signal);
|
|
420
|
+
if (generation !== this.#g) throw abortError("Superseded by a newer DOM SDF build");
|
|
421
|
+
};
|
|
520
422
|
let bitmap;
|
|
521
423
|
const atlasCovers = (atlas) => {
|
|
522
424
|
if (opts.colorGlyphs === "none") bitmap ??= snapshot.requests.some((request) => request.shape?.bitmap);
|
|
@@ -527,7 +429,14 @@ var DomSdf = class DomSdf extends Group {
|
|
|
527
429
|
};
|
|
528
430
|
const retained = this.#r;
|
|
529
431
|
const canReuseRetainedText = rebuildOptions.atlas !== true && retained !== null && (this.#as === snapshot.atlasSignature || (isWindfoilBackend(retained) ? snapshot.requests.every((request) => retained.covers(request.key)) : atlasCovers(retained)));
|
|
530
|
-
|
|
432
|
+
if (canReuseRetainedText && this.#c !== null && this.#cm && this.#ls === "") {
|
|
433
|
+
const previousSnapshot = this.#ps ?? this.snapshot;
|
|
434
|
+
if (previousSnapshot) {
|
|
435
|
+
this.#ls = layoutSignatureOf(previousSnapshot);
|
|
436
|
+
this.#cs();
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
const signature = canReuseRetainedText && this.#c !== null && this.#cm ? layoutSignatureOf(snapshot) : void 0;
|
|
531
440
|
if (canReuseRetainedText && this.#c !== null && this.#cm && signature === this.#ls && generation === this.#g && this.#c.st(tone)) {
|
|
532
441
|
this.#st = Object.freeze({
|
|
533
442
|
...this.#st,
|
|
@@ -535,6 +444,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
535
444
|
atlasBuildMs: 0,
|
|
536
445
|
geometryBuildMs: 0
|
|
537
446
|
});
|
|
447
|
+
if (svgPromise) await svgPromise;
|
|
538
448
|
if (opts.svg) this.#om();
|
|
539
449
|
return;
|
|
540
450
|
}
|
|
@@ -547,79 +457,83 @@ var DomSdf = class DomSdf extends Group {
|
|
|
547
457
|
ownsNextRetained = false;
|
|
548
458
|
} else {
|
|
549
459
|
const atlasStarted = now();
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
460
|
+
if (isAnalyticOption && opts.textShaping !== "browser" && rebuildOptions.atlas !== true && retained !== null && isWindfoilBackend(retained) && retained.append && await retained.append(snapshot.requests, controller.signal)) {
|
|
461
|
+
appended = true;
|
|
462
|
+
nextRetained = retained;
|
|
463
|
+
} else {
|
|
464
|
+
const appendTo = !isAnalyticOption && rebuildOptions.atlas !== true && this.#o && retained && !isWindfoilBackend(retained) ? retained : null;
|
|
465
|
+
const chunk = appendTo && await (this.#ac ??= import("../atlas/appendAtlas.js").catch(() => null));
|
|
466
|
+
if (appendTo && chunk) {
|
|
467
|
+
this.#ga = true;
|
|
468
|
+
nextRetained = await chunk.appendGlyphs(this.renderer, this.source.ownerDocument, appendTo, snapshot.requests, opts, controller.signal);
|
|
469
|
+
appended = !!nextRetained;
|
|
470
|
+
}
|
|
556
471
|
}
|
|
557
472
|
const previousAtlas = rebuildOptions.atlas !== true && retained !== null && !isWindfoilBackend(retained) && retained !== opts.sharedAtlas ? retained : void 0;
|
|
558
473
|
const buildAtlas = async (requests, signal, appendable, allowProvisional = false) => {
|
|
559
|
-
const
|
|
560
|
-
const raster = await rasterizeGlyphAtlas(this.source.ownerDocument, requests, {
|
|
474
|
+
const rasterOptions = {
|
|
561
475
|
signal,
|
|
562
476
|
previousAtlas,
|
|
563
477
|
appendable,
|
|
564
|
-
...gpuUpload ? { gpuUpload } : {}
|
|
565
|
-
|
|
566
|
-
|
|
478
|
+
...gpuUpload ? { gpuUpload } : {}
|
|
479
|
+
};
|
|
480
|
+
copyDefined(rasterOptions, opts, [
|
|
481
|
+
"colorGlyphs",
|
|
482
|
+
"bakeSize",
|
|
483
|
+
"padding",
|
|
484
|
+
"maxAtlasSize",
|
|
485
|
+
"adaptiveBakeSize"
|
|
486
|
+
]);
|
|
487
|
+
const raster = await rasterizeGlyphAtlas(this.source.ownerDocument, requests, rasterOptions);
|
|
567
488
|
const atlasOptions = {
|
|
568
489
|
signal,
|
|
569
490
|
mipmaps: opts.quality === "high",
|
|
570
491
|
anisotropy: opts.quality === "high" ? 4 : 1,
|
|
571
|
-
...opts.atlasMode === void 0 ? {} : { mode: opts.atlasMode }
|
|
572
|
-
...def("cpuWorker")
|
|
492
|
+
...opts.atlasMode === void 0 ? {} : { mode: opts.atlasMode }
|
|
573
493
|
};
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
494
|
+
copyDefined(atlasOptions, opts, ["cpuWorker"]);
|
|
495
|
+
await ensureLazyMods();
|
|
496
|
+
try {
|
|
497
|
+
if (allowProvisional && gpuUpload && opts.quality !== "high") return await buildSdfAtlas(this.renderer, raster, atlasOptions, {
|
|
498
|
+
stage: (provisionalAtlas) => {
|
|
499
|
+
if (signal.aborted || generation !== this.#g || staged.content) return;
|
|
500
|
+
const geometryT0 = now();
|
|
501
|
+
try {
|
|
502
|
+
staged.content = createContent(snapshot, provisionalAtlas, opts, this.#m, tone, this.#em);
|
|
503
|
+
staged.atlas = provisionalAtlas;
|
|
504
|
+
staged.ms = now() - geometryT0;
|
|
505
|
+
} catch {
|
|
506
|
+
staged.content = null;
|
|
507
|
+
staged.atlas = null;
|
|
508
|
+
staged.ms = 0;
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
rollback: () => {
|
|
512
|
+
staged.content?.d();
|
|
584
513
|
staged.content = null;
|
|
585
514
|
staged.atlas = null;
|
|
586
515
|
staged.ms = 0;
|
|
587
516
|
}
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
return buildSdfAtlas(this.renderer, raster, atlasOptions);
|
|
517
|
+
}, preparedWorkerPromise ?? void 0);
|
|
518
|
+
return await (preparedWorkerPromise ? buildSdfAtlas(this.renderer, raster, atlasOptions, void 0, preparedWorkerPromise) : buildSdfAtlas(this.renderer, raster, atlasOptions));
|
|
519
|
+
} finally {
|
|
520
|
+
raster.canvas.width = 0;
|
|
521
|
+
raster.canvas.height = 0;
|
|
522
|
+
}
|
|
597
523
|
};
|
|
598
524
|
if (!appended && isAnalyticOption && opts.textShaping !== "browser") {
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
if (!this.#to) {
|
|
609
|
-
const { createTracedOutlineProvider } = await preloadTraced ?? await import("../windfoil/tracedOutlines.js");
|
|
610
|
-
throwIfAborted(controller.signal);
|
|
611
|
-
this.#to ??= createTracedOutlineProvider(this.source.ownerDocument, opts.colorGlyphs === void 0 ? {} : { colorGlyphs: opts.colorGlyphs });
|
|
612
|
-
} else if (rebuildOptions.atlas === true) this.#to.clear();
|
|
613
|
-
resolved = {
|
|
614
|
-
...analytic,
|
|
615
|
-
fallback: analytic.fallback ?? "sdf-glyphs",
|
|
616
|
-
outlineProvider: this.#to.provider
|
|
617
|
-
};
|
|
618
|
-
}
|
|
619
|
-
nextRetained = await (backendKind === "slug" ? (await preloadBackend ?? await import("../slug/runtime.js")).buildSlugBackend : (await preloadBackend ?? await import("../windfoil/runtime.js")).buildWindfoilBackend)(this.renderer, snapshot.requests, resolved, controller.signal, {
|
|
620
|
-
build: buildAtlas,
|
|
621
|
-
effects: opts
|
|
525
|
+
if (rebuildOptions.atlas === true) this.#ga = false;
|
|
526
|
+
else if (retained !== null) this.#ga = true;
|
|
527
|
+
const am = this.#am ?? (this.#am = await (preloadAnalytic ?? import("./domAnalytic.js")));
|
|
528
|
+
throwIfAborted(controller.signal);
|
|
529
|
+
const res = await am.buildDomAnalyticBackend(this.renderer, this.source.ownerDocument, snapshot, opts, backendKind, analytic, this.#ga, this.#to, rebuildOptions.atlas === true, controller.signal, throwIfAborted, {
|
|
530
|
+
preloadBackend,
|
|
531
|
+
preloadTraced,
|
|
532
|
+
loadTraced: () => import("../windfoil/tracedOutlines.js"),
|
|
533
|
+
buildAtlas
|
|
622
534
|
});
|
|
535
|
+
if (res.traced) this.#to = res.traced;
|
|
536
|
+
nextRetained = res.retained;
|
|
623
537
|
}
|
|
624
538
|
if (!appended) {
|
|
625
539
|
nextRetained ??= await buildAtlas(snapshot.requests, controller.signal, this.#ga ? "headroom" : true, true);
|
|
@@ -642,17 +556,27 @@ var DomSdf = class DomSdf extends Group {
|
|
|
642
556
|
staged.atlas = null;
|
|
643
557
|
staged.ms = 0;
|
|
644
558
|
}
|
|
559
|
+
await ensureLazyMods();
|
|
645
560
|
const geometryStarted = now();
|
|
646
|
-
if (isWindfoilBackend(nextRetained))
|
|
647
|
-
|
|
648
|
-
const
|
|
561
|
+
if (isWindfoilBackend(nextRetained)) {
|
|
562
|
+
nextRetained.setGlyphEm(!!tone?.dilationPx);
|
|
563
|
+
const am = this.#am ?? (this.#am = await (preloadAnalytic ?? import("./domAnalytic.js")));
|
|
649
564
|
throwIfAborted(controller.signal);
|
|
650
|
-
|
|
565
|
+
const analyticBundle = this.#c;
|
|
566
|
+
if (!((canReuseRetainedText || appended) && (analyticBundle?.u(snapshot, nextRetained, this.#m, tone) ?? false))) {
|
|
567
|
+
const extra = nextRetained.companion || nextRetained.color ? await am.loadMixedExtras() : void 0;
|
|
568
|
+
throwIfAborted(controller.signal);
|
|
569
|
+
nextContent = am.createAnalyticContent(snapshot, nextRetained, opts, this.#m, tone, extra?.createExtraTextParts, this.#em);
|
|
570
|
+
}
|
|
571
|
+
} else {
|
|
572
|
+
const sdfBundle = this.#c;
|
|
573
|
+
if (!((canReuseRetainedText || appended) && (sdfBundle?.u(snapshot, nextRetained, this.#m, tone) ?? false))) nextContent = createContent(snapshot, nextRetained, opts, this.#m, tone, this.#em);
|
|
651
574
|
}
|
|
652
575
|
geometryBuildMs = now() - geometryStarted;
|
|
653
576
|
}
|
|
577
|
+
if (reflowPromise) await reflowPromise;
|
|
578
|
+
if (svgPromise) await svgPromise;
|
|
654
579
|
throwIfAborted(controller.signal);
|
|
655
|
-
signature ??= layoutSignatureOf(snapshot);
|
|
656
580
|
const oldContent = this.#c;
|
|
657
581
|
const oldRetained = this.#r;
|
|
658
582
|
let activeContent;
|
|
@@ -665,34 +589,34 @@ var DomSdf = class DomSdf extends Group {
|
|
|
665
589
|
const ownedPrevious = this.#o;
|
|
666
590
|
this.#r = nextRetained;
|
|
667
591
|
this.#o = canReuseRetainedText || appended ? ownedPrevious : ownsNextRetained;
|
|
592
|
+
this.#cs();
|
|
668
593
|
this.snapshot = opts.reflowable === true ? snapshot : null;
|
|
594
|
+
this.#rf = null;
|
|
669
595
|
this.#w = snapshot.width;
|
|
670
596
|
this.#h = snapshot.height;
|
|
671
597
|
this.#as = snapshot.atlasSignature;
|
|
672
|
-
this.#ls = signature;
|
|
673
598
|
this.#cm = true;
|
|
599
|
+
if (signature !== void 0) this.#ls = signature;
|
|
600
|
+
else {
|
|
601
|
+
this.#ls = "";
|
|
602
|
+
this.#ds(snapshot);
|
|
603
|
+
}
|
|
674
604
|
if (opts.svg) this.#om();
|
|
675
605
|
this.#to?.retain(snapshot.requests.map((request) => request.key));
|
|
676
606
|
const windfoil = isWindfoilBackend(nextRetained) ? nextRetained : null;
|
|
677
607
|
const atlas = windfoil ? windfoil.companion : nextRetained;
|
|
678
|
-
const glyphs = atlas?.glyphs;
|
|
679
|
-
const switchKeys = windfoil?.sizeSwitch?.keys;
|
|
680
608
|
let glyphCount = 0;
|
|
681
609
|
let shapeCount = 0;
|
|
682
610
|
let colorGlyphCount = 0;
|
|
683
611
|
let fallbackGlyphCount = 0;
|
|
684
612
|
let switchableGlyphCount = 0;
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
const slot = glyphs?.get(glyph.glyphKey);
|
|
693
|
-
if (slot && !windfoil?.analyticCovers(glyph.glyphKey)) {
|
|
694
|
-
if (slot.color) colorGlyphCount++;
|
|
695
|
-
if (windfoil) fallbackGlyphCount++;
|
|
613
|
+
if (windfoil && this.#am) [glyphCount, shapeCount, colorGlyphCount, fallbackGlyphCount, switchableGlyphCount] = this.#am.countAnalyticStats(snapshot, windfoil);
|
|
614
|
+
else {
|
|
615
|
+
const glyphs = atlas?.glyphs;
|
|
616
|
+
for (const glyph of snapshot.glyphs) if (glyph.shapeGroup !== void 0) shapeCount++;
|
|
617
|
+
else {
|
|
618
|
+
glyphCount++;
|
|
619
|
+
if (glyphs?.get(glyph.glyphKey)?.color) colorGlyphCount++;
|
|
696
620
|
}
|
|
697
621
|
}
|
|
698
622
|
this.#st = Object.freeze({
|
|
@@ -723,10 +647,41 @@ var DomSdf = class DomSdf extends Group {
|
|
|
723
647
|
if (ownsNextRetained) nextRetained?.dispose();
|
|
724
648
|
throw error;
|
|
725
649
|
} finally {
|
|
650
|
+
preparedWorkerPromise?.then((worker) => worker?.dispose());
|
|
726
651
|
externalSignal?.removeEventListener("abort", forwardAbort);
|
|
727
652
|
if (this.#a === controller) this.#a = null;
|
|
728
653
|
}
|
|
729
654
|
}
|
|
655
|
+
#cs() {
|
|
656
|
+
this.#pc?.();
|
|
657
|
+
this.#pc = null;
|
|
658
|
+
this.#ps = null;
|
|
659
|
+
}
|
|
660
|
+
#ds(snapshot) {
|
|
661
|
+
this.#cs();
|
|
662
|
+
if (this.snapshot === snapshot) return;
|
|
663
|
+
if (typeof MessageChannel !== "function") {
|
|
664
|
+
this.#ls = layoutSignatureOf(snapshot);
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
this.#ps = snapshot;
|
|
668
|
+
const { port1, port2 } = new MessageChannel();
|
|
669
|
+
const cancel = () => {
|
|
670
|
+
port1.onmessage = null;
|
|
671
|
+
port1.close();
|
|
672
|
+
port2.close();
|
|
673
|
+
};
|
|
674
|
+
this.#pc = cancel;
|
|
675
|
+
port1.onmessage = () => {
|
|
676
|
+
cancel();
|
|
677
|
+
if (this.#pc === cancel) this.#pc = null;
|
|
678
|
+
if (!this.#d && this.#ps === snapshot) {
|
|
679
|
+
this.#ps = null;
|
|
680
|
+
this.#ls = layoutSignatureOf(snapshot);
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
port2.postMessage(null);
|
|
684
|
+
}
|
|
730
685
|
#sr(forceAtlas = false, lazy = false) {
|
|
731
686
|
if (this.#d) return;
|
|
732
687
|
this.#fa ||= forceAtlas;
|
|
@@ -795,23 +750,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
795
750
|
subtree: true
|
|
796
751
|
};
|
|
797
752
|
observer.observe(this.source, options);
|
|
798
|
-
if (
|
|
799
|
-
const seen = /* @__PURE__ */ new Set([this.source]);
|
|
800
|
-
const pending = [this.source];
|
|
801
|
-
while (pending.length) {
|
|
802
|
-
const source = pending.pop();
|
|
803
|
-
const uses = [...source.querySelectorAll("use")];
|
|
804
|
-
if (source.localName === "use") uses.unshift(source);
|
|
805
|
-
for (const use of uses) {
|
|
806
|
-
const href = use.getAttribute("href") ?? use.getAttribute("xlink:href") ?? "";
|
|
807
|
-
const tree = use.getRootNode();
|
|
808
|
-
const target = href.startsWith("#") ? tree.getElementById(href.slice(1)) : null;
|
|
809
|
-
if (!target || seen.has(target)) continue;
|
|
810
|
-
seen.add(target);
|
|
811
|
-
if (!this.source.contains(target)) observer.observe(target, options);
|
|
812
|
-
pending.push(target);
|
|
813
|
-
}
|
|
814
|
-
}
|
|
753
|
+
if (this.options.svg) this.#sm?.observeSvgUses(observer, this.source, options);
|
|
815
754
|
}
|
|
816
755
|
dispose() {
|
|
817
756
|
if (this.#d) return;
|
|
@@ -828,6 +767,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
828
767
|
this.remove(this.#c.g);
|
|
829
768
|
this.#c.d();
|
|
830
769
|
}
|
|
770
|
+
this.#cs();
|
|
831
771
|
if (this.#o) this.#r?.dispose();
|
|
832
772
|
this.#to?.clear();
|
|
833
773
|
this.#a = this.#ro = this.#mo = this.#uf = this.#c = this.#r = this.#to = this.snapshot = null;
|