ultra-text 1.0.0 → 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 +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- 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 +164 -50
- 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.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- 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 +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- 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 +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.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.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- 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 +563 -243
- 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/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- 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 +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- 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 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- 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/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.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/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.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
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { prepareAtlasPasses } from "../atlas/gpuAtlas.js";
|
|
2
2
|
import { buildSdfAtlas } from "../atlas/buildAtlas.js";
|
|
3
|
-
import { isColorCandidate
|
|
3
|
+
import { isColorCandidate } from "./fontCanvas.js";
|
|
4
|
+
import { rasterizeGlyphAtlas } from "../atlas/rasterize.js";
|
|
4
5
|
import { resolveDomTextTone } from "./tone.js";
|
|
5
6
|
import { isAnimatedMotion } from "../text/GlyphTextMaterial.js";
|
|
6
|
-
import { createRectMaterial } from "../text/RectMaterial.js";
|
|
7
7
|
import { SdfTextMaterial } from "../text/SdfTextMaterial.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
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";
|
|
11
10
|
import "./markup.js";
|
|
12
11
|
import { collectDomSnapshot } from "./snapshot.js";
|
|
13
12
|
import { layoutSignatureOf } from "./layoutSignature.js";
|
|
@@ -34,9 +33,6 @@ var EMPTY_STATS = Object.freeze({
|
|
|
34
33
|
function isWindfoilBackend(backend) {
|
|
35
34
|
return "kind" in backend;
|
|
36
35
|
}
|
|
37
|
-
function buildGlyphGeometry(snapshot, backend, motionPadding) {
|
|
38
|
-
return isWindfoilBackend(backend) ? backend.createGeometry(snapshot, motionPadding) : createGlyphGeometry(snapshot, backend, motionPadding);
|
|
39
|
-
}
|
|
40
36
|
function sdfStorageBytes(atlas, mipmaps) {
|
|
41
37
|
const count = (w, h, bpp) => w * h * bpp + (mipmaps && (w > 1 || h > 1) ? count(w >> 1 || 1, h >> 1 || 1, bpp) : 0);
|
|
42
38
|
return count(atlas.width, atlas.height, 1) + (atlas.colorLayer ? count(atlas.width, atlas.colorLayer.height, 4) : 0);
|
|
@@ -48,13 +44,17 @@ var ATTRIBUTE_MAX_WAIT_MS = 320;
|
|
|
48
44
|
function now() {
|
|
49
45
|
return performance.now();
|
|
50
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
|
+
}
|
|
51
51
|
function abortError(message = "The DOM SDF build was aborted") {
|
|
52
52
|
return new DOMException(message, "AbortError");
|
|
53
53
|
}
|
|
54
54
|
function throwIfAborted(signal) {
|
|
55
55
|
if (signal.aborted) throw signal.reason ?? abortError();
|
|
56
56
|
}
|
|
57
|
-
function createContent(snapshot, backend, options, motion, tone,
|
|
57
|
+
function createContent(snapshot, backend, options, motion, tone, extrasMod) {
|
|
58
58
|
const materialOptions = {
|
|
59
59
|
...options,
|
|
60
60
|
tone: tone ?? false
|
|
@@ -66,20 +66,13 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
66
66
|
const strength = motion.strength ?? 18;
|
|
67
67
|
let animated = isAnimatedMotion(motion);
|
|
68
68
|
const materialMotion = (live) => animated ? live : false;
|
|
69
|
-
const { geometry: glyphGeometry, maxSequence } =
|
|
70
|
-
const
|
|
71
|
-
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));
|
|
72
71
|
const colorEnabled = usesColor(snapshot);
|
|
73
|
-
const runMotion = needsRunMotion(snapshot)
|
|
74
|
-
const maxSeq = (s) => s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0);
|
|
75
|
-
const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence;
|
|
72
|
+
const runMotion = needsRunMotion(snapshot);
|
|
76
73
|
let textMaterial;
|
|
77
74
|
try {
|
|
78
|
-
textMaterial =
|
|
79
|
-
...materialOptions,
|
|
80
|
-
maxSequence: hasExtras ? globalSequence : maxSequence,
|
|
81
|
-
motion: materialMotion(motion)
|
|
82
|
-
}) : new SdfTextMaterial({
|
|
75
|
+
textMaterial = new SdfTextMaterial({
|
|
83
76
|
...materialOptions,
|
|
84
77
|
runMotion,
|
|
85
78
|
...colorEnabled ? { colorLayer: backend.colorLayer } : {},
|
|
@@ -96,14 +89,6 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
96
89
|
glyphGeometry.dispose();
|
|
97
90
|
throw error;
|
|
98
91
|
}
|
|
99
|
-
let extras;
|
|
100
|
-
try {
|
|
101
|
-
if (hasExtras && isWindfoilBackend(backend)) extras = makeExtraParts(snapshot, backend, materialOptions, materialMotion(motion), strength);
|
|
102
|
-
} catch (error) {
|
|
103
|
-
glyphGeometry.dispose();
|
|
104
|
-
textMaterial.dispose();
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
92
|
const text = new Mesh(glyphGeometry, textMaterial);
|
|
108
93
|
text.name = "ultra-text text";
|
|
109
94
|
text.castShadow = options.castShadow !== false;
|
|
@@ -121,101 +106,10 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
121
106
|
ownedMeshes.length = 0;
|
|
122
107
|
group.clear();
|
|
123
108
|
};
|
|
109
|
+
const glyphDrawable = (retained, key) => retained.glyphs.has(key);
|
|
110
|
+
let ce = null;
|
|
124
111
|
try {
|
|
125
|
-
if (
|
|
126
|
-
for (const mesh of extras.meshes) {
|
|
127
|
-
group.add(mesh);
|
|
128
|
-
ownedMeshes.push(mesh);
|
|
129
|
-
}
|
|
130
|
-
extras.mergeRects(snapshot, text.geometry);
|
|
131
|
-
}
|
|
132
|
-
} catch (error) {
|
|
133
|
-
disposeMeshes();
|
|
134
|
-
throw error;
|
|
135
|
-
}
|
|
136
|
-
let decorations = null;
|
|
137
|
-
const glyphDrawable = (retained, key) => {
|
|
138
|
-
if (isWindfoilBackend(retained)) return (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key);
|
|
139
|
-
return retained.glyphs.has(key);
|
|
140
|
-
};
|
|
141
|
-
const prepareDecorations = (layout, retained, liveMotion, nextTextGeometry, nextSequence, drawable = (key) => glyphDrawable(retained, key)) => {
|
|
142
|
-
const geometry = createDecorationGeometry(layout, nextTextGeometry, drawable, liveMotion.strength ?? 18);
|
|
143
|
-
try {
|
|
144
|
-
return [geometry, geometry && !decorations ? new TextDecorationMaterial({
|
|
145
|
-
textShaping: options.textShaping ?? "none",
|
|
146
|
-
side: options.side,
|
|
147
|
-
vertex: options.vertex,
|
|
148
|
-
motion: materialMotion(liveMotion),
|
|
149
|
-
maxSequence: nextSequence
|
|
150
|
-
}) : null];
|
|
151
|
-
} catch (error) {
|
|
152
|
-
geometry?.dispose();
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
const commitDecorations = ([geometry, material], liveMotion) => {
|
|
157
|
-
if (!geometry) {
|
|
158
|
-
if (decorations) {
|
|
159
|
-
group.remove(decorations);
|
|
160
|
-
ownedMeshes.splice(ownedMeshes.indexOf(decorations), 1);
|
|
161
|
-
decorations.geometry.dispose();
|
|
162
|
-
decorations.material.dispose();
|
|
163
|
-
decorations = null;
|
|
164
|
-
}
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (decorations) {
|
|
168
|
-
const previous = decorations.geometry;
|
|
169
|
-
decorations.geometry = geometry;
|
|
170
|
-
previous.dispose();
|
|
171
|
-
if (animated) decorations.material.setMotion(liveMotion);
|
|
172
|
-
decorations.material.maxSequence.value = textMaterial.maxSequence.value;
|
|
173
|
-
} else {
|
|
174
|
-
decorations = new Mesh(geometry, material);
|
|
175
|
-
decorations.name = "ultra-text text decorations";
|
|
176
|
-
decorations.castShadow = options.castShadow !== false;
|
|
177
|
-
decorations.renderOrder = 3;
|
|
178
|
-
decorations.frustumCulled = false;
|
|
179
|
-
group.add(decorations);
|
|
180
|
-
ownedMeshes.push(decorations);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
const updateDecorations = (layout, retained, liveMotion, drawable = (key) => glyphDrawable(retained, key)) => {
|
|
184
|
-
if (!decorations) return;
|
|
185
|
-
if (updateDecorationGeometry(decorations.geometry, layout, text.geometry, drawable, liveMotion.strength ?? 18)) {
|
|
186
|
-
if (animated) decorations.material.setMotion(liveMotion);
|
|
187
|
-
decorations.material.maxSequence.value = textMaterial.maxSequence.value;
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
commitDecorations(prepareDecorations(layout, retained, liveMotion, text.geometry, textMaterial.maxSequence.value, drawable), liveMotion);
|
|
191
|
-
};
|
|
192
|
-
const addRects = (receiver, name) => {
|
|
193
|
-
const geometry = createRectGeometry(snapshot, receiver);
|
|
194
|
-
if (!geometry) return null;
|
|
195
|
-
let mesh;
|
|
196
|
-
try {
|
|
197
|
-
mesh = new Mesh(geometry, createRectMaterial(receiver, options.shadowFloor));
|
|
198
|
-
} catch (error) {
|
|
199
|
-
geometry.dispose();
|
|
200
|
-
throw error;
|
|
201
|
-
}
|
|
202
|
-
mesh.name = name;
|
|
203
|
-
mesh.receiveShadow = receiver;
|
|
204
|
-
mesh.frustumCulled = true;
|
|
205
|
-
mesh.renderOrder = 0;
|
|
206
|
-
mesh.matrixAutoUpdate = false;
|
|
207
|
-
mesh.updateMatrix();
|
|
208
|
-
group.add(mesh);
|
|
209
|
-
ownedMeshes.push(mesh);
|
|
210
|
-
return mesh;
|
|
211
|
-
};
|
|
212
|
-
let plainRects = null;
|
|
213
|
-
let receivers = null;
|
|
214
|
-
try {
|
|
215
|
-
const initialDecorations = prepareDecorations(snapshot, backend, motion, text.geometry, textMaterial.maxSequence.value);
|
|
216
|
-
if (initialDecorations[0]) commitDecorations(initialDecorations, motion);
|
|
217
|
-
plainRects = addRects(false, "ultra-text DOM rectangles");
|
|
218
|
-
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));
|
|
219
113
|
} catch (error) {
|
|
220
114
|
disposeMeshes();
|
|
221
115
|
throw error;
|
|
@@ -225,12 +119,7 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
225
119
|
mesh.geometry = geometry;
|
|
226
120
|
previous.dispose();
|
|
227
121
|
};
|
|
228
|
-
const setTone = (next) =>
|
|
229
|
-
if (!textMaterial.setTone(next)) return false;
|
|
230
|
-
for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next);
|
|
231
|
-
return true;
|
|
232
|
-
};
|
|
233
|
-
/** Whether `setTone` would accept this tone, without writing it. */
|
|
122
|
+
const setTone = (next) => textMaterial.setTone(next);
|
|
234
123
|
const toneFits = (next) => {
|
|
235
124
|
const current = textMaterial.tone;
|
|
236
125
|
return current && next ? current.fits(next) : !current && !next;
|
|
@@ -247,16 +136,12 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
247
136
|
sm(change, live) {
|
|
248
137
|
if (animated) {
|
|
249
138
|
textMaterial.setMotion(change);
|
|
250
|
-
|
|
251
|
-
decorations?.material.setMotion(change);
|
|
139
|
+
ce?.setMotion(change);
|
|
252
140
|
return;
|
|
253
141
|
}
|
|
254
142
|
if (!isAnimatedMotion(live)) return;
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
...extras?.meshes ?? [],
|
|
258
|
-
...decorations ? [decorations] : []
|
|
259
|
-
];
|
|
143
|
+
const decMesh = ce?.decMesh();
|
|
144
|
+
const meshes = [text, ...decMesh ? [decMesh] : []];
|
|
260
145
|
const twins = [];
|
|
261
146
|
try {
|
|
262
147
|
for (const mesh of meshes) twins.push(mesh.material.withMotion(live));
|
|
@@ -273,7 +158,9 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
273
158
|
animated = true;
|
|
274
159
|
},
|
|
275
160
|
st: setTone,
|
|
276
|
-
ud
|
|
161
|
+
ud(layout, retained, liveMotion) {
|
|
162
|
+
ce?.updateDec(layout, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, (key) => glyphDrawable(retained, key));
|
|
163
|
+
},
|
|
277
164
|
get tg() {
|
|
278
165
|
return text.geometry;
|
|
279
166
|
},
|
|
@@ -282,40 +169,22 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
282
169
|
},
|
|
283
170
|
u(nextSnapshot, nextBackend, liveMotion, nextTone) {
|
|
284
171
|
if (nextTone !== void 0 && (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))) return false;
|
|
285
|
-
if (runMotion !==
|
|
172
|
+
if (runMotion !== needsRunMotion(nextSnapshot)) return false;
|
|
286
173
|
if (colorEnabled !== usesColor(nextSnapshot)) return false;
|
|
287
|
-
|
|
288
|
-
const wantsReceivers = nextSnapshot.rects.some((rect) => rect.receiveShadow);
|
|
289
|
-
if (wantsPlain !== (plainRects !== null) || wantsReceivers !== (receivers !== null)) return false;
|
|
174
|
+
if (ce ? !ce.fitsLayout(nextSnapshot) : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)) return false;
|
|
290
175
|
const strength = liveMotion.strength ?? 18;
|
|
291
176
|
const drawable = (key) => glyphDrawable(nextBackend, key);
|
|
292
|
-
const decorationsFit =
|
|
293
|
-
|
|
294
|
-
const glyphsFit = decorationsFit && (isWindfoilBackend(nextBackend) ? nextBackend.contentFits(text.geometry, nextSnapshot) : glyphContentFits(text.geometry, nextSnapshot, nextBackend));
|
|
295
|
-
const plainFit = !plainRects || rectContentFits(plainRects.geometry, nextSnapshot, false);
|
|
296
|
-
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);
|
|
297
179
|
let built = null;
|
|
298
|
-
let
|
|
299
|
-
let nextPlain = null;
|
|
300
|
-
let nextReceivers = null;
|
|
301
|
-
let nextDecorations = null;
|
|
180
|
+
let stagedExtras = null;
|
|
302
181
|
const releaseStaged = () => {
|
|
303
182
|
built?.geometry.dispose();
|
|
304
|
-
|
|
305
|
-
nextPlain?.dispose();
|
|
306
|
-
nextReceivers?.dispose();
|
|
307
|
-
nextDecorations?.[0]?.dispose();
|
|
308
|
-
nextDecorations?.[1]?.dispose();
|
|
183
|
+
stagedExtras?.dispose();
|
|
309
184
|
};
|
|
310
185
|
try {
|
|
311
|
-
|
|
312
|
-
if (
|
|
313
|
-
if (plainRects && !plainFit) nextPlain = createRectGeometry(nextSnapshot, false);
|
|
314
|
-
if (receivers && !receiverFit) nextReceivers = createRectGeometry(nextSnapshot, true);
|
|
315
|
-
if (!decorationsFit) {
|
|
316
|
-
const source = built?.geometry ?? text.geometry;
|
|
317
|
-
nextDecorations = prepareDecorations(nextSnapshot, nextBackend, liveMotion, source, built?.maxSequence ?? textMaterial.maxSequence.value, drawable);
|
|
318
|
-
}
|
|
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);
|
|
319
188
|
} catch (error) {
|
|
320
189
|
releaseStaged();
|
|
321
190
|
throw error;
|
|
@@ -324,24 +193,14 @@ function createContent(snapshot, backend, options, motion, tone, makeExtraParts)
|
|
|
324
193
|
swapGeometry(text, built.geometry);
|
|
325
194
|
textMaterial.maxSequence.value = built.maxSequence;
|
|
326
195
|
} else {
|
|
327
|
-
const maxSequence =
|
|
196
|
+
const maxSequence = updateGlyphContent(text.geometry, nextSnapshot, nextBackend, strength, void 0, true);
|
|
328
197
|
if (maxSequence === null) {
|
|
329
198
|
releaseStaged();
|
|
330
199
|
throw new Error("DomSdf: glyph buffers changed during the update");
|
|
331
200
|
}
|
|
332
201
|
textMaterial.maxSequence.value = maxSequence;
|
|
333
202
|
}
|
|
334
|
-
|
|
335
|
-
extras.commit(nextParts, nextSnapshot, strength);
|
|
336
|
-
textMaterial.maxSequence.value = maxSeq(nextSnapshot);
|
|
337
|
-
extras.mergeRects(nextSnapshot, text.geometry);
|
|
338
|
-
}
|
|
339
|
-
if (nextDecorations) commitDecorations(nextDecorations, liveMotion);
|
|
340
|
-
else updateDecorations(nextSnapshot, nextBackend, liveMotion, drawable);
|
|
341
|
-
if (plainRects && nextPlain) swapGeometry(plainRects, nextPlain);
|
|
342
|
-
else if (plainRects) updateRectGeometry(plainRects.geometry, nextSnapshot, false);
|
|
343
|
-
if (receivers && nextReceivers) swapGeometry(receivers, nextReceivers);
|
|
344
|
-
else if (receivers) updateRectGeometry(receivers.geometry, nextSnapshot, true);
|
|
203
|
+
ce?.commit(stagedExtras, nextSnapshot, text.geometry, animated, liveMotion, textMaterial.maxSequence.value, drawable, swapGeometry);
|
|
345
204
|
if (nextTone !== void 0) setTone(nextTone);
|
|
346
205
|
return true;
|
|
347
206
|
},
|
|
@@ -371,10 +230,17 @@ var DomSdf = class DomSdf extends Group {
|
|
|
371
230
|
#mo = null;
|
|
372
231
|
#uf = null;
|
|
373
232
|
snapshot = null;
|
|
233
|
+
#rf = null;
|
|
234
|
+
#rm = null;
|
|
235
|
+
#em = null;
|
|
236
|
+
#am = null;
|
|
237
|
+
#sm = null;
|
|
374
238
|
#w = 0;
|
|
375
239
|
#h = 0;
|
|
376
240
|
#as = "";
|
|
377
241
|
#ls = "";
|
|
242
|
+
#ps = null;
|
|
243
|
+
#pc = null;
|
|
378
244
|
#cm = false;
|
|
379
245
|
#ga = false;
|
|
380
246
|
#ac;
|
|
@@ -438,32 +304,43 @@ var DomSdf = class DomSdf extends Group {
|
|
|
438
304
|
}
|
|
439
305
|
reflow(width) {
|
|
440
306
|
if (this.#d) throw new Error("DomSdf.reflow: this instance is disposed");
|
|
441
|
-
|
|
307
|
+
const rm = this.#rm;
|
|
308
|
+
if (!this.snapshot || !rm) throw new Error("DomSdf.reflow: create the instance with reflowable: true first");
|
|
442
309
|
if (!this.#r || !this.#c) return this;
|
|
443
310
|
const retained = this.#r;
|
|
444
311
|
const content = this.#c;
|
|
445
|
-
if (isWindfoilBackend(retained)) retained.setGlyphEm(!!content.m.tone?.dilates);
|
|
446
312
|
const started = now();
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
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;
|
|
451
322
|
} else {
|
|
452
|
-
|
|
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);
|
|
453
327
|
if (maxSequence === null) {
|
|
454
|
-
const built =
|
|
455
|
-
|
|
328
|
+
const built = createGlyphGeometry(reflowed, retained, strength);
|
|
329
|
+
sdfContent.rg(built.geometry);
|
|
456
330
|
maxSequence = built.maxSequence;
|
|
457
331
|
}
|
|
458
|
-
|
|
459
|
-
|
|
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;
|
|
460
337
|
}
|
|
461
338
|
this.#cm = false;
|
|
462
|
-
this.#w =
|
|
463
|
-
this.#h =
|
|
339
|
+
this.#w = reflowedWidth;
|
|
340
|
+
this.#h = reflowedHeight;
|
|
464
341
|
this.#st = Object.freeze({
|
|
465
342
|
...this.#st,
|
|
466
|
-
lines:
|
|
343
|
+
lines: reflowedLines,
|
|
467
344
|
layoutReadMs: 0,
|
|
468
345
|
atlasBuildMs: 0,
|
|
469
346
|
geometryBuildMs: now() - started
|
|
@@ -486,15 +363,41 @@ var DomSdf = class DomSdf extends Group {
|
|
|
486
363
|
let ownsNextRetained = false;
|
|
487
364
|
let appended = false;
|
|
488
365
|
let nextContent = null;
|
|
366
|
+
const staged = {
|
|
367
|
+
content: null,
|
|
368
|
+
atlas: null,
|
|
369
|
+
ms: 0
|
|
370
|
+
};
|
|
371
|
+
let preparedWorkerPromise = null;
|
|
372
|
+
let reflowPromise = null;
|
|
489
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
|
+
});
|
|
490
387
|
await Promise.resolve();
|
|
491
388
|
throwIfAborted(controller.signal);
|
|
492
389
|
if (generation !== this.#g) throw abortError("Superseded by a newer DOM SDF build");
|
|
493
|
-
const opts = this.options;
|
|
494
390
|
const gpuUpload = opts.atlasMode !== "cpu" && this.renderer.initialized && this.renderer.backend.isWebGPUBackend === true;
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
391
|
+
if (gpuUpload && mayBuildSdf && !this.#r) prepareAtlasPasses(this.renderer, opts.padding);
|
|
392
|
+
let preloadAnalytic = null;
|
|
393
|
+
let preloadBackend = null;
|
|
394
|
+
let preloadTraced = null;
|
|
395
|
+
if (isAnalyticOption && opts.textShaping !== "browser") {
|
|
396
|
+
if (!this.#am) preloadAnalytic = import("./domAnalytic.js").then((m) => this.#am = m);
|
|
397
|
+
preloadBackend = (backendKind === "slug" ? import("../slug/runtime.js") : import("../windfoil/runtime.js")).catch(() => null);
|
|
398
|
+
if (!analytic.outlineProvider && !this.#to) preloadTraced = import("../windfoil/tracedOutlines.js").catch(() => null);
|
|
399
|
+
}
|
|
400
|
+
const svgPromise = opts.svg && !this.#sm ? import("./svgCapture.js").then((m) => this.#sm = m) : null;
|
|
498
401
|
const layoutStarted = now();
|
|
499
402
|
const snapshot = await collectDomSnapshot(this.source, opts);
|
|
500
403
|
const tone = resolveDomTextTone(this.source, opts.tone, {
|
|
@@ -505,6 +408,17 @@ var DomSdf = class DomSdf extends Group {
|
|
|
505
408
|
});
|
|
506
409
|
const layoutReadMs = now() - layoutStarted;
|
|
507
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
|
+
};
|
|
508
422
|
let bitmap;
|
|
509
423
|
const atlasCovers = (atlas) => {
|
|
510
424
|
if (opts.colorGlyphs === "none") bitmap ??= snapshot.requests.some((request) => request.shape?.bitmap);
|
|
@@ -515,7 +429,14 @@ var DomSdf = class DomSdf extends Group {
|
|
|
515
429
|
};
|
|
516
430
|
const retained = this.#r;
|
|
517
431
|
const canReuseRetainedText = rebuildOptions.atlas !== true && retained !== null && (this.#as === snapshot.atlasSignature || (isWindfoilBackend(retained) ? snapshot.requests.every((request) => retained.covers(request.key)) : atlasCovers(retained)));
|
|
518
|
-
|
|
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;
|
|
519
440
|
if (canReuseRetainedText && this.#c !== null && this.#cm && signature === this.#ls && generation === this.#g && this.#c.st(tone)) {
|
|
520
441
|
this.#st = Object.freeze({
|
|
521
442
|
...this.#st,
|
|
@@ -523,6 +444,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
523
444
|
atlasBuildMs: 0,
|
|
524
445
|
geometryBuildMs: 0
|
|
525
446
|
});
|
|
447
|
+
if (svgPromise) await svgPromise;
|
|
526
448
|
if (opts.svg) this.#om();
|
|
527
449
|
return;
|
|
528
450
|
}
|
|
@@ -535,73 +457,125 @@ var DomSdf = class DomSdf extends Group {
|
|
|
535
457
|
ownsNextRetained = false;
|
|
536
458
|
} else {
|
|
537
459
|
const atlasStarted = now();
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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
|
+
}
|
|
544
471
|
}
|
|
545
472
|
const previousAtlas = rebuildOptions.atlas !== true && retained !== null && !isWindfoilBackend(retained) && retained !== opts.sharedAtlas ? retained : void 0;
|
|
546
|
-
const buildAtlas = async (requests, signal, appendable) => {
|
|
547
|
-
const
|
|
548
|
-
const raster = await rasterizeGlyphAtlas(this.source.ownerDocument, requests, {
|
|
473
|
+
const buildAtlas = async (requests, signal, appendable, allowProvisional = false) => {
|
|
474
|
+
const rasterOptions = {
|
|
549
475
|
signal,
|
|
550
476
|
previousAtlas,
|
|
551
477
|
appendable,
|
|
552
|
-
...gpuUpload ? { gpuUpload } : {}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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);
|
|
488
|
+
const atlasOptions = {
|
|
556
489
|
signal,
|
|
557
490
|
mipmaps: opts.quality === "high",
|
|
558
491
|
anisotropy: opts.quality === "high" ? 4 : 1,
|
|
559
|
-
...opts.atlasMode === void 0 ? {} : { mode: opts.atlasMode }
|
|
560
|
-
...def("cpuWorker")
|
|
561
|
-
});
|
|
562
|
-
};
|
|
563
|
-
if (!appended && isAnalyticOption && opts.textShaping !== "browser") {
|
|
564
|
-
const analytic = (backendKind === "slug" ? opts.slug ?? opts.windfoil : opts.windfoil) ?? {};
|
|
565
|
-
const outlineProvider = analytic.outlineProvider;
|
|
566
|
-
if (outlineProvider !== void 0 && typeof outlineProvider !== "function") throw new TypeError(`DomSdf: textBackend "${backendKind}" requires ${backendKind}.outlineProvider`);
|
|
567
|
-
let resolved;
|
|
568
|
-
if (analytic.outlineProvider) resolved = {
|
|
569
|
-
...analytic,
|
|
570
|
-
outlineProvider: analytic.outlineProvider
|
|
492
|
+
...opts.atlasMode === void 0 ? {} : { mode: opts.atlasMode }
|
|
571
493
|
};
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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();
|
|
513
|
+
staged.content = null;
|
|
514
|
+
staged.atlas = null;
|
|
515
|
+
staged.ms = 0;
|
|
516
|
+
}
|
|
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;
|
|
583
522
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
523
|
+
};
|
|
524
|
+
if (!appended && isAnalyticOption && opts.textShaping !== "browser") {
|
|
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
|
|
587
534
|
});
|
|
535
|
+
if (res.traced) this.#to = res.traced;
|
|
536
|
+
nextRetained = res.retained;
|
|
588
537
|
}
|
|
589
538
|
if (!appended) {
|
|
590
|
-
nextRetained ??= await buildAtlas(snapshot.requests, controller.signal, this.#ga ? "headroom" : true);
|
|
539
|
+
nextRetained ??= await buildAtlas(snapshot.requests, controller.signal, this.#ga ? "headroom" : true, true);
|
|
591
540
|
ownsNextRetained = true;
|
|
592
541
|
}
|
|
593
|
-
atlasBuildMs = now() - atlasStarted;
|
|
542
|
+
atlasBuildMs = Math.max(0, now() - atlasStarted - staged.ms);
|
|
594
543
|
}
|
|
595
544
|
throwIfAborted(controller.signal);
|
|
596
545
|
if (generation !== this.#g || !nextRetained) throw abortError("Superseded by a newer DOM SDF build");
|
|
597
|
-
|
|
598
|
-
if (isWindfoilBackend(nextRetained))
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
546
|
+
let geometryBuildMs = 0;
|
|
547
|
+
if (staged.content !== null && staged.atlas === nextRetained && !isWindfoilBackend(nextRetained)) {
|
|
548
|
+
nextContent = staged.content;
|
|
549
|
+
staged.content = null;
|
|
550
|
+
staged.atlas = null;
|
|
551
|
+
geometryBuildMs = staged.ms;
|
|
552
|
+
} else {
|
|
553
|
+
if (staged.content) {
|
|
554
|
+
staged.content.d();
|
|
555
|
+
staged.content = null;
|
|
556
|
+
staged.atlas = null;
|
|
557
|
+
staged.ms = 0;
|
|
558
|
+
}
|
|
559
|
+
await ensureLazyMods();
|
|
560
|
+
const geometryStarted = now();
|
|
561
|
+
if (isWindfoilBackend(nextRetained)) {
|
|
562
|
+
nextRetained.setGlyphEm(!!tone?.dilationPx);
|
|
563
|
+
const am = this.#am ?? (this.#am = await (preloadAnalytic ?? import("./domAnalytic.js")));
|
|
564
|
+
throwIfAborted(controller.signal);
|
|
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);
|
|
574
|
+
}
|
|
575
|
+
geometryBuildMs = now() - geometryStarted;
|
|
603
576
|
}
|
|
604
|
-
|
|
577
|
+
if (reflowPromise) await reflowPromise;
|
|
578
|
+
if (svgPromise) await svgPromise;
|
|
605
579
|
throwIfAborted(controller.signal);
|
|
606
580
|
const oldContent = this.#c;
|
|
607
581
|
const oldRetained = this.#r;
|
|
@@ -615,34 +589,34 @@ var DomSdf = class DomSdf extends Group {
|
|
|
615
589
|
const ownedPrevious = this.#o;
|
|
616
590
|
this.#r = nextRetained;
|
|
617
591
|
this.#o = canReuseRetainedText || appended ? ownedPrevious : ownsNextRetained;
|
|
592
|
+
this.#cs();
|
|
618
593
|
this.snapshot = opts.reflowable === true ? snapshot : null;
|
|
594
|
+
this.#rf = null;
|
|
619
595
|
this.#w = snapshot.width;
|
|
620
596
|
this.#h = snapshot.height;
|
|
621
597
|
this.#as = snapshot.atlasSignature;
|
|
622
|
-
this.#ls = signature;
|
|
623
598
|
this.#cm = true;
|
|
599
|
+
if (signature !== void 0) this.#ls = signature;
|
|
600
|
+
else {
|
|
601
|
+
this.#ls = "";
|
|
602
|
+
this.#ds(snapshot);
|
|
603
|
+
}
|
|
624
604
|
if (opts.svg) this.#om();
|
|
625
605
|
this.#to?.retain(snapshot.requests.map((request) => request.key));
|
|
626
606
|
const windfoil = isWindfoilBackend(nextRetained) ? nextRetained : null;
|
|
627
607
|
const atlas = windfoil ? windfoil.companion : nextRetained;
|
|
628
|
-
const glyphs = atlas?.glyphs;
|
|
629
|
-
const switchKeys = windfoil?.sizeSwitch?.keys;
|
|
630
608
|
let glyphCount = 0;
|
|
631
609
|
let shapeCount = 0;
|
|
632
610
|
let colorGlyphCount = 0;
|
|
633
611
|
let fallbackGlyphCount = 0;
|
|
634
612
|
let switchableGlyphCount = 0;
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const slot = glyphs?.get(glyph.glyphKey);
|
|
643
|
-
if (slot && !windfoil?.analyticCovers(glyph.glyphKey)) {
|
|
644
|
-
if (slot.color) colorGlyphCount++;
|
|
645
|
-
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++;
|
|
646
620
|
}
|
|
647
621
|
}
|
|
648
622
|
this.#st = Object.freeze({
|
|
@@ -668,14 +642,46 @@ var DomSdf = class DomSdf extends Group {
|
|
|
668
642
|
if (oldContent && oldContent !== activeContent) oldContent.d();
|
|
669
643
|
if (oldRetained && oldRetained !== nextRetained && ownedPrevious && !appended) oldRetained.dispose();
|
|
670
644
|
} catch (error) {
|
|
645
|
+
staged.content?.d();
|
|
671
646
|
nextContent?.d();
|
|
672
647
|
if (ownsNextRetained) nextRetained?.dispose();
|
|
673
648
|
throw error;
|
|
674
649
|
} finally {
|
|
650
|
+
preparedWorkerPromise?.then((worker) => worker?.dispose());
|
|
675
651
|
externalSignal?.removeEventListener("abort", forwardAbort);
|
|
676
652
|
if (this.#a === controller) this.#a = null;
|
|
677
653
|
}
|
|
678
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
|
+
}
|
|
679
685
|
#sr(forceAtlas = false, lazy = false) {
|
|
680
686
|
if (this.#d) return;
|
|
681
687
|
this.#fa ||= forceAtlas;
|
|
@@ -744,23 +750,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
744
750
|
subtree: true
|
|
745
751
|
};
|
|
746
752
|
observer.observe(this.source, options);
|
|
747
|
-
if (
|
|
748
|
-
const seen = /* @__PURE__ */ new Set([this.source]);
|
|
749
|
-
const pending = [this.source];
|
|
750
|
-
while (pending.length) {
|
|
751
|
-
const source = pending.pop();
|
|
752
|
-
const uses = [...source.querySelectorAll("use")];
|
|
753
|
-
if (source.localName === "use") uses.unshift(source);
|
|
754
|
-
for (const use of uses) {
|
|
755
|
-
const href = use.getAttribute("href") ?? use.getAttribute("xlink:href") ?? "";
|
|
756
|
-
const tree = use.getRootNode();
|
|
757
|
-
const target = href.startsWith("#") ? tree.getElementById(href.slice(1)) : null;
|
|
758
|
-
if (!target || seen.has(target)) continue;
|
|
759
|
-
seen.add(target);
|
|
760
|
-
if (!this.source.contains(target)) observer.observe(target, options);
|
|
761
|
-
pending.push(target);
|
|
762
|
-
}
|
|
763
|
-
}
|
|
753
|
+
if (this.options.svg) this.#sm?.observeSvgUses(observer, this.source, options);
|
|
764
754
|
}
|
|
765
755
|
dispose() {
|
|
766
756
|
if (this.#d) return;
|
|
@@ -777,6 +767,7 @@ var DomSdf = class DomSdf extends Group {
|
|
|
777
767
|
this.remove(this.#c.g);
|
|
778
768
|
this.#c.d();
|
|
779
769
|
}
|
|
770
|
+
this.#cs();
|
|
780
771
|
if (this.#o) this.#r?.dispose();
|
|
781
772
|
this.#to?.clear();
|
|
782
773
|
this.#a = this.#ro = this.#mo = this.#uf = this.#c = this.#r = this.#to = this.snapshot = null;
|