ultra-text 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -115
- package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +35 -11
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +1 -1
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.js +8 -3
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +97 -42
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +10 -4
- package/dist/atlas/cpuWorker.js +99 -49
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +133 -56
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +140 -18
- package/dist/atlas/gpuCommon.js +726 -104
- package/dist/atlas/gpuCommon.js.map +1 -1
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +232 -61
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +237 -111
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/vanillaCore.js +156 -103
- package/dist/atlas/vanillaCore.js.map +1 -1
- package/dist/atlas/vanillaCpuAtlas.js +37 -52
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
- package/dist/atlas/vanillaExtras.js +91 -90
- package/dist/atlas/vanillaExtras.js.map +1 -1
- package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
- package/dist/atlas/vanillaGpuHelpers.js +262 -27
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
- package/dist/dom/DomSdf.js +85 -79
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +23 -18
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +1 -2
- package/dist/dom/domAnalytic.js +1 -1
- package/dist/dom/domAnalytic.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +4 -4
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +28 -12
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +27 -19
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +747 -505
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.js +30 -27
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +15 -8
- package/dist/dom/tone.js.map +1 -1
- package/dist/slug/SlugMaterial.d.ts +6 -0
- package/dist/slug/SlugMaterial.js +48 -20
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +3 -3
- package/dist/slug/coverage.js +283 -101
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -1
- package/dist/slug/preprocessCore.js +100 -80
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +32 -39
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.js +47 -37
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +190 -62
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +74 -4
- package/dist/slug/vanillaCore.js +226 -217
- package/dist/slug/vanillaCore.js.map +1 -1
- package/dist/slug-vanilla.d.ts +1 -1
- package/dist/slug-vanilla.js +5 -4
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +3 -3
- package/dist/text/GlyphTextMaterial.d.ts +5 -0
- package/dist/text/GlyphTextMaterial.js +11 -7
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +122 -37
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -96
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometryUtils.d.ts +5 -0
- package/dist/text/geometryUtils.js +63 -9
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +1 -1
- package/dist/text/glyphGeometry.js +281 -200
- package/dist/text/glyphGeometry.js.map +1 -1
- package/dist/text/rectGeometry.js +46 -42
- package/dist/text/rectGeometry.js.map +1 -1
- package/dist/text/reflow.d.ts +5 -0
- package/dist/text/reflow.js +127 -68
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -1
- package/dist/text/snap.js +1 -1
- package/dist/text/snap.js.map +1 -1
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.js +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +15 -0
- package/dist/windfoil/geometry.js +154 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.js +13 -4
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +63 -36
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +1 -0
- package/dist/windfoil/runtime.js +8 -24
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +23 -9
- package/dist/windfoil/storage.js +49 -30
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.js +120 -50
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.js +578 -224
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +335 -70
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +26 -24
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { byte, metaSize, setBounds, setUnitQuad
|
|
1
|
+
import { byte, flushAttributeUpdate, isDomSnapshot, metaSize, needsRunMotion, setBounds, setUnitQuad } from "../text/geometryUtils.js";
|
|
2
2
|
import { GLYPH_RECTS_KEY } from "../text/decorations.js";
|
|
3
3
|
import { InstancedBufferAttribute, InstancedBufferGeometry } from "three/webgpu";
|
|
4
4
|
// src/windfoil/geometry.ts
|
|
5
|
+
var prevWindfoilCache = /* @__PURE__ */ new WeakMap();
|
|
5
6
|
var ATTRIBUTES = [
|
|
6
7
|
"sdfRect",
|
|
7
8
|
"sdfClip",
|
|
@@ -32,28 +33,6 @@ function recordDirty(slot, start, end) {
|
|
|
32
33
|
if (start < dirtyBounds[base]) dirtyBounds[base] = start;
|
|
33
34
|
if (end > dirtyBounds[base + 1]) dirtyBounds[base + 1] = end;
|
|
34
35
|
}
|
|
35
|
-
function flushAttributeUpdate(attribute, dirtyStart, dirtyEnd) {
|
|
36
|
-
if (attribute.version === 0) {
|
|
37
|
-
attribute.needsUpdate = true;
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (dirtyEnd <= dirtyStart) return;
|
|
41
|
-
let start = dirtyStart;
|
|
42
|
-
let end = dirtyEnd;
|
|
43
|
-
for (const range of attribute.updateRanges) {
|
|
44
|
-
if (range.count < 0) {
|
|
45
|
-
start = 0;
|
|
46
|
-
end = attribute.array.length;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
if (range.start < start) start = range.start;
|
|
50
|
-
const rangeEnd = range.start + range.count;
|
|
51
|
-
if (rangeEnd > end) end = rangeEnd;
|
|
52
|
-
}
|
|
53
|
-
attribute.clearUpdateRanges();
|
|
54
|
-
attribute.addUpdateRange(start, end - start);
|
|
55
|
-
attribute.needsUpdate = true;
|
|
56
|
-
}
|
|
57
36
|
function writeFloat4(target, offset, a, b, c, d, trackDirty, slot) {
|
|
58
37
|
if (trackDirty) {
|
|
59
38
|
const fa = Math.fround(a);
|
|
@@ -96,7 +75,11 @@ function windfoilGlyphRect(glyph, header, bbox = header.bbox) {
|
|
|
96
75
|
0
|
|
97
76
|
]);
|
|
98
77
|
}
|
|
99
|
-
|
|
78
|
+
/** The negative font size feeds tone dilation while keeping the analytic batch selected. */
|
|
79
|
+
function fixedGlyphEm(glyph) {
|
|
80
|
+
return glyph.shapeGroup === void 0 ? -glyph.fontSize : 0;
|
|
81
|
+
}
|
|
82
|
+
function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1, c2, c3, fc0, fc1, fc2, fc3, glyphRect, trackDirty = false) {
|
|
100
83
|
const offset = index * 4;
|
|
101
84
|
const scale = glyph.fontSize / header.unitsPerEm;
|
|
102
85
|
const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale);
|
|
@@ -104,8 +87,7 @@ function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1,
|
|
|
104
87
|
const lBox = layer.bbox;
|
|
105
88
|
const b0 = lBox[0], b1 = lBox[1], b2 = lBox[2], b3 = lBox[3];
|
|
106
89
|
writeFloat4(attributes.rects, offset, ox + b0 * scale, baseline + b1 * scale, ox + b2 * scale, baseline + b3 * scale, trackDirty, SLOT_RECT);
|
|
107
|
-
|
|
108
|
-
writeFloat4(attributes.clips, offset, clip[0], clip[1], clip[2], clip[3], trackDirty, SLOT_CLIP);
|
|
90
|
+
writeFloat4(attributes.clips, offset, fc0, fc1, fc2, fc3, trackDirty, SLOT_CLIP);
|
|
109
91
|
const colors = attributes.colors;
|
|
110
92
|
if (trackDirty) {
|
|
111
93
|
if (colors[offset] !== c0 || colors[offset + 1] !== c1 || colors[offset + 2] !== c2 || colors[offset + 3] !== c3) {
|
|
@@ -123,16 +105,15 @@ function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1,
|
|
|
123
105
|
}
|
|
124
106
|
const metaSizeValue = attributes.metaSize ?? 2;
|
|
125
107
|
const metadata = attributes.metadata;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
} else writeMeta(metadata, index, metaSizeValue, glyph);
|
|
108
|
+
const m = index * metaSizeValue;
|
|
109
|
+
let em = 0;
|
|
110
|
+
if (metaSizeValue === 3) em = attributes.fontEm ? fixedGlyphEm(glyph) : glyph.switchEm ?? 0;
|
|
111
|
+
if (!trackDirty || metadata[m] !== Math.fround(glyph.sequence) || metadata[m + 1] !== Math.fround(glyph.z) || metaSizeValue === 3 && metadata[m + 2] !== Math.fround(em)) {
|
|
112
|
+
metadata[m] = glyph.sequence;
|
|
113
|
+
metadata[m + 1] = glyph.z;
|
|
114
|
+
if (metaSizeValue === 3) metadata[m + 2] = em;
|
|
115
|
+
if (trackDirty) recordDirty(SLOT_META, m, m + metaSizeValue);
|
|
116
|
+
}
|
|
136
117
|
writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS);
|
|
137
118
|
writeFloat4(attributes.bands, offset, layer.rowBase, layer.bandCount, layer.bandH, layer.invH, trackDirty, SLOT_BAND);
|
|
138
119
|
const layers = attributes.layers;
|
|
@@ -147,7 +128,8 @@ function writeInstance(glyph, header, layer, index, ordinal, attributes, c0, c1,
|
|
|
147
128
|
function writeLayerInstance(glyph, header, layer, index, ordinal, attributes, glyphRect, trackDirty = false) {
|
|
148
129
|
const paint = "paintKind" in layer ? layer : null;
|
|
149
130
|
const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color;
|
|
150
|
-
|
|
131
|
+
const clip = glyph.clip;
|
|
132
|
+
writeInstance(glyph, header, layer, index, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)), clip[0], clip[1], clip[2], clip[3], glyphRect, trackDirty);
|
|
151
133
|
}
|
|
152
134
|
function countLayout(snapshot, glyphs, layered) {
|
|
153
135
|
let instances = 0, drawable = 0;
|
|
@@ -163,7 +145,7 @@ function countLayout(snapshot, glyphs, layered) {
|
|
|
163
145
|
drawable
|
|
164
146
|
};
|
|
165
147
|
}
|
|
166
|
-
function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = false) {
|
|
148
|
+
function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = false, prev) {
|
|
167
149
|
let instance = 0, drawable = 0, maxSequence = 0, minZ = 0, maxZ = 0;
|
|
168
150
|
let prevKey;
|
|
169
151
|
let prevHeader;
|
|
@@ -172,12 +154,30 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = fals
|
|
|
172
154
|
let pc1 = 0;
|
|
173
155
|
let pc2 = 0;
|
|
174
156
|
let pc3 = 0;
|
|
157
|
+
let prevClip;
|
|
158
|
+
let fc0 = 0;
|
|
159
|
+
let fc1 = 0;
|
|
160
|
+
let fc2 = 0;
|
|
161
|
+
let fc3 = 0;
|
|
175
162
|
const glyphList = snapshot.glyphs;
|
|
163
|
+
let canSkip = trackDirty && prev !== void 0 && prev.allSingleDrawn && !prev.layered && !attributes.layers && prev.glyphsMap === glyphs && prev.metaSize === (attributes.metaSize ?? 2) && prev.fontEm === Boolean(attributes.fontEm) && prev.hasOrdinals === Boolean(ordinals);
|
|
164
|
+
const prevGlyphs = canSkip ? prev.glyphs : void 0;
|
|
176
165
|
for (let i = 0; i < glyphList.length; i++) {
|
|
177
166
|
const glyph = glyphList[i];
|
|
167
|
+
if (canSkip && instance === i && drawable === i && i < prevGlyphs.length && glyph === prevGlyphs[i]) {
|
|
168
|
+
instance++;
|
|
169
|
+
drawable++;
|
|
170
|
+
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
171
|
+
if (glyph.z < minZ) minZ = glyph.z;
|
|
172
|
+
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
178
175
|
const key = glyph.glyphKey;
|
|
179
176
|
const header = key === prevKey ? prevHeader : (prevKey = key, prevHeader = glyphs.get(key));
|
|
180
|
-
if (!header?.monotonePieceCount)
|
|
177
|
+
if (!header?.monotonePieceCount) {
|
|
178
|
+
canSkip = false;
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
181
|
const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable;
|
|
182
182
|
const rect = attributes.layers || attributes.glyphRects ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect) : void 0;
|
|
183
183
|
if (attributes.glyphRects && rect) {
|
|
@@ -187,13 +187,21 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = fals
|
|
|
187
187
|
attributes.glyphRects[rectOffset + 2] = rect[2];
|
|
188
188
|
attributes.glyphRects[rectOffset + 3] = rect[3];
|
|
189
189
|
}
|
|
190
|
+
const clip = glyph.clip;
|
|
191
|
+
if (clip !== prevClip) {
|
|
192
|
+
prevClip = clip;
|
|
193
|
+
fc0 = trackDirty ? Math.fround(clip[0]) : clip[0];
|
|
194
|
+
fc1 = trackDirty ? Math.fround(clip[1]) : clip[1];
|
|
195
|
+
fc2 = trackDirty ? Math.fround(clip[2]) : clip[2];
|
|
196
|
+
fc3 = trackDirty ? Math.fround(clip[3]) : clip[3];
|
|
197
|
+
}
|
|
190
198
|
if (attributes.layers && header.layers) for (const layer of header.layers) writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty);
|
|
191
199
|
else {
|
|
192
200
|
const layer = header.layers?.[0] ?? header;
|
|
193
201
|
const paint = "paintKind" in layer ? layer : null;
|
|
194
202
|
if (paint) {
|
|
195
203
|
const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color;
|
|
196
|
-
writeInstance(glyph, header, layer, instance++, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * paint.rgba[3]), rect, trackDirty);
|
|
204
|
+
writeInstance(glyph, header, layer, instance++, ordinal, attributes, byte(rgb[0]), byte(rgb[1]), byte(rgb[2]), byte(glyph.color[3] * paint.rgba[3]), fc0, fc1, fc2, fc3, rect, trackDirty);
|
|
197
205
|
} else {
|
|
198
206
|
const color = glyph.color;
|
|
199
207
|
if (color !== prevColor) {
|
|
@@ -203,7 +211,7 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = fals
|
|
|
203
211
|
pc2 = byte(color[2]);
|
|
204
212
|
pc3 = byte(color[3]);
|
|
205
213
|
}
|
|
206
|
-
writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, rect, trackDirty);
|
|
214
|
+
writeInstance(glyph, header, layer, instance++, ordinal, attributes, pc0, pc1, pc2, pc3, fc0, fc1, fc2, fc3, rect, trackDirty);
|
|
207
215
|
}
|
|
208
216
|
}
|
|
209
217
|
drawable++;
|
|
@@ -220,8 +228,11 @@ function writeGeometry(snapshot, glyphs, attributes, ordinals, trackDirty = fals
|
|
|
220
228
|
}
|
|
221
229
|
/** Ordinary outlines retain the original six instance attributes. */
|
|
222
230
|
function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered = false, ordinals) {
|
|
231
|
+
return createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, false);
|
|
232
|
+
}
|
|
233
|
+
function createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, fontEm) {
|
|
223
234
|
layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin);
|
|
224
|
-
const meta = metaSize(snapshot);
|
|
235
|
+
const meta = fontEm ? 3 : metaSize(snapshot);
|
|
225
236
|
let count;
|
|
226
237
|
let rects;
|
|
227
238
|
let clips;
|
|
@@ -258,6 +269,7 @@ function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered =
|
|
|
258
269
|
colors,
|
|
259
270
|
metadata,
|
|
260
271
|
metaSize: meta,
|
|
272
|
+
fontEm,
|
|
261
273
|
bounds,
|
|
262
274
|
bands,
|
|
263
275
|
...layers && glyphRects ? {
|
|
@@ -322,16 +334,42 @@ function createWindfoilGlyphGeometry(snapshot, glyphs, motionPadding, layered =
|
|
|
322
334
|
}
|
|
323
335
|
geometry.instanceCount = count;
|
|
324
336
|
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
|
|
337
|
+
if (isDomSnapshot(snapshot)) prevWindfoilCache.set(geometry, {
|
|
338
|
+
glyphs: snapshot.glyphs,
|
|
339
|
+
glyphsMap: glyphs,
|
|
340
|
+
metaSize: meta,
|
|
341
|
+
fontEm,
|
|
342
|
+
layered: Boolean(layers),
|
|
343
|
+
hasOrdinals: Boolean(ordinals),
|
|
344
|
+
allSingleDrawn: !layers && result.instances === snapshot.glyphs.length
|
|
345
|
+
});
|
|
325
346
|
return {
|
|
326
347
|
geometry,
|
|
327
348
|
maxSequence: result.maxSequence
|
|
328
349
|
};
|
|
329
350
|
}
|
|
330
351
|
function windfoilContentFits(geometry, snapshot, glyphs) {
|
|
331
|
-
|
|
352
|
+
return analyticGeometryFits(geometry, snapshot, glyphs, false);
|
|
353
|
+
}
|
|
354
|
+
function analyticGeometryFits(geometry, snapshot, glyphs, fontEm) {
|
|
355
|
+
const attrs = geometry.attributes;
|
|
356
|
+
const layered = attrs["windfoilLayer"] !== void 0;
|
|
332
357
|
const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES;
|
|
333
|
-
|
|
334
|
-
|
|
358
|
+
const count = geometry.instanceCount;
|
|
359
|
+
for (const name of names) if (attrs[name]?.count !== count) return false;
|
|
360
|
+
const metaSizeVal = fontEm ? 3 : metaSize(snapshot);
|
|
361
|
+
if (attrs["sdfMeta"]?.itemSize !== metaSizeVal) return false;
|
|
362
|
+
if (!layered && isDomSnapshot(snapshot) && !needsRunMotion(snapshot) && snapshot.glyphs.length === count) {
|
|
363
|
+
let allPlainSingle = true;
|
|
364
|
+
for (const req of snapshot.requests) {
|
|
365
|
+
const header = glyphs.get(req.key);
|
|
366
|
+
if (!header?.monotonePieceCount || (header.layers?.length ?? 1) > 1) {
|
|
367
|
+
allPlainSingle = false;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (allPlainSingle) return true;
|
|
372
|
+
}
|
|
335
373
|
let instances = 0, drawable = 0;
|
|
336
374
|
for (const glyph of snapshot.glyphs) {
|
|
337
375
|
const header = glyphs.get(glyph.glyphKey);
|
|
@@ -342,37 +380,89 @@ function windfoilContentFits(geometry, snapshot, glyphs) {
|
|
|
342
380
|
instances += layered ? layers : 1;
|
|
343
381
|
}
|
|
344
382
|
}
|
|
345
|
-
return instances ===
|
|
383
|
+
return instances === count && (!layered || geometry.userData["ultraOwnGlyphRects"]?.length === drawable * 4);
|
|
384
|
+
}
|
|
385
|
+
/** A width change moves single-layer glyphs while keeping their paint and curve data. */
|
|
386
|
+
function reflowWindfoilGlyphGeometry(geometry, snapshot, backend, padding, glyphEm) {
|
|
387
|
+
const glyphs = backend.glyphs;
|
|
388
|
+
if (backend.layered || geometry.hasAttribute("windfoilLayer") || !analyticGeometryFits(geometry, snapshot, glyphs, glyphEm)) return backend.updateGeometry(geometry, snapshot, padding);
|
|
389
|
+
prevWindfoilCache.delete(geometry);
|
|
390
|
+
const rects = geometry.getAttribute("sdfRect");
|
|
391
|
+
const clips = geometry.getAttribute("sdfClip");
|
|
392
|
+
const meta = geometry.getAttribute("sdfMeta");
|
|
393
|
+
let count = 0, maxSequence = 0, minZ = 0, maxZ = 0;
|
|
394
|
+
resetDirtyBounds();
|
|
395
|
+
for (const glyph of snapshot.glyphs) {
|
|
396
|
+
const header = glyphs.get(glyph.glyphKey);
|
|
397
|
+
if (!header?.monotonePieceCount) continue;
|
|
398
|
+
const rect = fillWindfoilGlyphRect(glyph, header, header.layers?.[0]?.bbox ?? header.bbox);
|
|
399
|
+
const offset = count * 4;
|
|
400
|
+
writeFloat4(rects.array, offset, rect[0], rect[1], rect[2], rect[3], true, SLOT_RECT);
|
|
401
|
+
const clip = glyph.clip;
|
|
402
|
+
writeFloat4(clips.array, offset, clip[0], clip[1], clip[2], clip[3], true, SLOT_CLIP);
|
|
403
|
+
const sequence = Math.fround(glyph.sequence);
|
|
404
|
+
const m = count++ * meta.itemSize;
|
|
405
|
+
if (meta.array[m] !== sequence) {
|
|
406
|
+
meta.array[m] = sequence;
|
|
407
|
+
recordDirty(SLOT_META, m, m + 1);
|
|
408
|
+
}
|
|
409
|
+
if (glyph.sequence > maxSequence) maxSequence = glyph.sequence;
|
|
410
|
+
if (glyph.z < minZ) minZ = glyph.z;
|
|
411
|
+
if (glyph.z > maxZ) maxZ = glyph.z;
|
|
412
|
+
}
|
|
413
|
+
flushAttributeUpdate(rects, dirtyBounds[0], dirtyBounds[1]);
|
|
414
|
+
flushAttributeUpdate(clips, dirtyBounds[2], dirtyBounds[3]);
|
|
415
|
+
flushAttributeUpdate(meta, dirtyBounds[6], dirtyBounds[7]);
|
|
416
|
+
setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ);
|
|
417
|
+
return maxSequence;
|
|
346
418
|
}
|
|
347
419
|
function updateWindfoilGlyphGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked = false) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
420
|
+
return updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, false);
|
|
421
|
+
}
|
|
422
|
+
function updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, fontEm) {
|
|
423
|
+
if (!checked && !analyticGeometryFits(geometry, snapshot, glyphs, fontEm)) return null;
|
|
424
|
+
const rectAttr = geometry.getAttribute("sdfRect");
|
|
425
|
+
const clipAttr = geometry.getAttribute("sdfClip");
|
|
426
|
+
const colorAttr = geometry.getAttribute("sdfColor");
|
|
427
|
+
const metaAttr = geometry.getAttribute("sdfMeta");
|
|
428
|
+
const boundsAttr = geometry.getAttribute("windfoilBounds");
|
|
429
|
+
const bandAttr = geometry.getAttribute("windfoilBand");
|
|
430
|
+
const layer = geometry.attributes["windfoilLayer"];
|
|
431
|
+
resetDirtyBounds();
|
|
432
|
+
const domSnap = isDomSnapshot(snapshot);
|
|
433
|
+
const metaItemSize = metaAttr.itemSize;
|
|
353
434
|
const result = writeGeometry(snapshot, glyphs, {
|
|
354
|
-
rects: array
|
|
355
|
-
clips: array
|
|
356
|
-
colors:
|
|
357
|
-
metadata: array
|
|
358
|
-
metaSize:
|
|
359
|
-
|
|
360
|
-
|
|
435
|
+
rects: rectAttr.array,
|
|
436
|
+
clips: clipAttr.array,
|
|
437
|
+
colors: colorAttr.array,
|
|
438
|
+
metadata: metaAttr.array,
|
|
439
|
+
metaSize: metaItemSize,
|
|
440
|
+
fontEm,
|
|
441
|
+
bounds: boundsAttr.array,
|
|
442
|
+
bands: bandAttr.array,
|
|
361
443
|
...layer ? {
|
|
362
444
|
layers: layer.array,
|
|
363
445
|
glyphRects: geometry.userData["ultraOwnGlyphRects"]
|
|
364
446
|
} : {}
|
|
365
|
-
}, ordinals,
|
|
447
|
+
}, ordinals, true, domSnap ? prevWindfoilCache.get(geometry) : void 0);
|
|
448
|
+
if (domSnap) prevWindfoilCache.set(geometry, {
|
|
449
|
+
glyphs: snapshot.glyphs,
|
|
450
|
+
glyphsMap: glyphs,
|
|
451
|
+
metaSize: metaItemSize,
|
|
452
|
+
fontEm,
|
|
453
|
+
layered: Boolean(layer),
|
|
454
|
+
hasOrdinals: Boolean(ordinals),
|
|
455
|
+
allSingleDrawn: !layer && result.instances === snapshot.glyphs.length
|
|
456
|
+
});
|
|
457
|
+
else prevWindfoilCache.delete(geometry);
|
|
366
458
|
const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES;
|
|
367
|
-
|
|
459
|
+
for (let i = 0; i < list.length; i++) {
|
|
368
460
|
const attribute = geometry.getAttribute(list[i]);
|
|
369
|
-
|
|
370
|
-
flushAttributeUpdate(attribute, dirtyBounds[base], dirtyBounds[base + 1]);
|
|
461
|
+
flushAttributeUpdate(attribute, dirtyBounds[i * 2], dirtyBounds[i * 2 + 1]);
|
|
371
462
|
}
|
|
372
|
-
else for (const name of list) geometry.getAttribute(name).needsUpdate = true;
|
|
373
463
|
setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ);
|
|
374
464
|
return result.maxSequence;
|
|
375
465
|
}
|
|
376
|
-
export { createWindfoilGlyphGeometry, fillWindfoilGlyphRect, updateWindfoilGlyphGeometry, windfoilContentFits, windfoilGlyphRect, writeLayerInstance };
|
|
466
|
+
export { analyticGeometryFits, createAnalyticGeometry, createWindfoilGlyphGeometry, fillWindfoilGlyphRect, fixedGlyphEm, reflowWindfoilGlyphGeometry, updateAnalyticGeometry, updateWindfoilGlyphGeometry, windfoilContentFits, windfoilGlyphRect, writeLayerInstance };
|
|
377
467
|
|
|
378
468
|
//# sourceMappingURL=geometry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport { byte, metaSize, setBounds, setUnitQuad, writeMeta } from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nconst SLOT_RECT = 0\nconst SLOT_CLIP = 1\nconst SLOT_COLOR = 2\nconst SLOT_META = 3\nconst SLOT_BOUNDS = 4\nconst SLOT_BAND = 5\nconst SLOT_LAYER = 6\nconst DIRTY_UNSET = 0x7fffffff\nconst dirtyBounds = new Int32Array(14)\n\nfunction resetDirtyBounds(): void {\n for (let slot = 0; slot < 7; slot++) {\n const base = slot * 2\n dirtyBounds[base] = DIRTY_UNSET\n dirtyBounds[base + 1] = 0\n }\n}\n\nfunction recordDirty(slot: number, start: number, end: number): void {\n const base = slot * 2\n if (start < dirtyBounds[base]!) dirtyBounds[base] = start\n if (end > dirtyBounds[base + 1]!) dirtyBounds[base + 1] = end\n}\n\nfunction flushAttributeUpdate(\n attribute: InstancedBufferAttribute,\n dirtyStart: number,\n dirtyEnd: number,\n): void {\n if (attribute.version === 0) {\n attribute.needsUpdate = true\n return\n }\n if (dirtyEnd <= dirtyStart) return\n let start = dirtyStart\n let end = dirtyEnd\n for (const range of attribute.updateRanges) {\n if (range.count < 0) {\n start = 0\n end = attribute.array.length\n break\n }\n if (range.start < start) start = range.start\n const rangeEnd = range.start + range.count\n if (rangeEnd > end) end = rangeEnd\n }\n attribute.clearUpdateRanges()\n attribute.addUpdateRange(start, end - start)\n attribute.needsUpdate = true\n}\n\nfunction writeFloat4(\n target: Float32Array,\n offset: number,\n a: number,\n b: number,\n c: number,\n d: number,\n trackDirty: boolean,\n slot: number,\n): void {\n if (trackDirty) {\n const fa = Math.fround(a)\n const fb = Math.fround(b)\n const fc = Math.fround(c)\n const fd = Math.fround(d)\n if (\n target[offset] === fa &&\n target[offset + 1] === fb &&\n target[offset + 2] === fc &&\n target[offset + 3] === fd\n ) {\n return\n }\n target[offset] = fa\n target[offset + 1] = fb\n target[offset + 2] = fc\n target[offset + 3] = fd\n recordDirty(slot, offset, offset + 4)\n return\n }\n target[offset] = a\n target[offset + 1] = b\n target[offset + 2] = c\n target[offset + 3] = d\n}\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\nfunction writeInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n c0: number,\n c1: number,\n c2: number,\n c3: number,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n writeFloat4(\n attributes.rects,\n offset,\n ox + b0 * scale,\n baseline + b1 * scale,\n ox + b2 * scale,\n baseline + b3 * scale,\n trackDirty,\n SLOT_RECT,\n )\n const clip = glyph.clip\n writeFloat4(attributes.clips, offset, clip[0], clip[1], clip[2], clip[3], trackDirty, SLOT_CLIP)\n const colors = attributes.colors\n if (trackDirty) {\n if (\n colors[offset] !== c0 ||\n colors[offset + 1] !== c1 ||\n colors[offset + 2] !== c2 ||\n colors[offset + 3] !== c3\n ) {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n recordDirty(SLOT_COLOR, offset, offset + 4)\n }\n } else {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n }\n const metaSizeValue = attributes.metaSize ?? 2\n const metadata = attributes.metadata\n if (trackDirty) {\n const mOffset = index * metaSizeValue\n const seq = Math.fround(glyph.sequence)\n const gz = Math.fround(glyph.z)\n const sw = metaSizeValue === 3 ? Math.fround(glyph.switchEm ?? 0) : 0\n if (\n metadata[mOffset] !== seq ||\n metadata[mOffset + 1] !== gz ||\n (metaSizeValue === 3 && metadata[mOffset + 2] !== sw)\n ) {\n writeMeta(metadata, index, metaSizeValue, glyph)\n recordDirty(SLOT_META, mOffset, mOffset + metaSizeValue)\n }\n } else {\n writeMeta(metadata, index, metaSizeValue, glyph)\n }\n writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS)\n writeFloat4(\n attributes.bands,\n offset,\n layer.rowBase,\n layer.bandCount,\n layer.bandH,\n layer.invH,\n trackDirty,\n SLOT_BAND,\n )\n const layers = attributes.layers\n if (layers) {\n const paint = 'paintKind' in layer ? layer : null\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n writeFloat4(\n layers,\n offset,\n mo ? mo[0] : (rect[0] + rect[2]) / 2,\n mo ? mo[1] : (rect[1] + rect[3]) / 2,\n ordinal,\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0),\n trackDirty,\n SLOT_LAYER,\n )\n }\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n index,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)),\n glyphRect,\n trackDirty,\n )\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n trackDirty = false,\n): { instances: number; maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n let prevKey: string | undefined\n let prevHeader: WindfoilGlyphHeader | undefined\n let prevColor: GlyphLayout['color'] | undefined\n let pc0 = 0\n let pc1 = 0\n let pc2 = 0\n let pc3 = 0\n const glyphList = snapshot.glyphs\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n const key = glyph.glyphKey\n const header = key === prevKey ? prevHeader : ((prevKey = key), (prevHeader = glyphs.get(key)))\n if (!header?.monotonePieceCount) continue\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty)\n }\n } else {\n const layer = header.layers?.[0] ?? header\n const paint = 'paintKind' in layer ? layer : null\n if (paint) {\n const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * paint.rgba[3]),\n rect,\n trackDirty,\n )\n } else {\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n pc0,\n pc1,\n pc2,\n pc3,\n rect,\n trackDirty,\n )\n }\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { instances: instance, maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const meta = metaSize(snapshot)\n let count: number\n let rects: Float32Array\n let clips: Float32Array\n let colors: Uint8Array\n let metadata: Float32Array\n let bounds: Float32Array\n let bands: Float32Array\n let layers: Float32Array | undefined\n let glyphRects: Float32Array | undefined\n if (layered) {\n const counted = countLayout(snapshot, glyphs, true)\n count = counted.instances\n rects = new Float32Array(count * 4)\n clips = new Float32Array(count * 4)\n colors = new Uint8Array(count * 4)\n metadata = new Float32Array(count * meta)\n bounds = new Float32Array(count * 4)\n bands = new Float32Array(count * 4)\n layers = new Float32Array(count * 4)\n glyphRects = new Float32Array(counted.drawable * 4)\n } else {\n const total = snapshot.glyphs.length\n count = total\n rects = new Float32Array(total * 4)\n clips = new Float32Array(total * 4)\n colors = new Uint8Array(total * 4)\n metadata = new Float32Array(total * meta)\n bounds = new Float32Array(total * 4)\n bands = new Float32Array(total * 4)\n }\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects,\n clips,\n colors,\n metadata,\n metaSize: meta,\n bounds,\n bands,\n ...(layers && glyphRects ? { layers, glyphRects } : {}),\n },\n ordinals,\n )\n if (!layered && result.instances < count) {\n count = result.instances\n rects = rects.subarray(0, count * 4)\n clips = clips.subarray(0, count * 4)\n colors = colors.subarray(0, count * 4)\n metadata = metadata.subarray(0, count * meta)\n bounds = bounds.subarray(0, count * 4)\n bands = bands.subarray(0, count * 4)\n }\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['windfoilBounds', bounds, 4, false],\n ['windfoilBand', bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = glyphRects\n geometry.userData['ultraOwnGlyphRects'] = glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n const layered =\n (geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined) !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (const name of names) {\n if (\n (geometry.getAttribute(name) as InstancedBufferAttribute | undefined)?.count !==\n geometry.instanceCount\n )\n return false\n }\n if (\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).itemSize !== metaSize(snapshot)\n )\n return false\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === geometry.instanceCount &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n checked = false,\n): number | null {\n if (!checked && !windfoilContentFits(geometry, snapshot, glyphs)) return null\n const array = (name: string): Float32Array => geometry.getAttribute(name).array as Float32Array\n const layer = geometry.getAttribute('windfoilLayer') as InstancedBufferAttribute | undefined\n const trackDirty =\n (geometry.getAttribute('sdfRect') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfClip') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfColor') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('sdfMeta') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute).version > 0 ||\n (geometry.getAttribute('windfoilBand') as InstancedBufferAttribute).version > 0 ||\n (layer?.version ?? 0) > 0\n if (trackDirty) resetDirtyBounds()\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects: array('sdfRect'),\n clips: array('sdfClip'),\n colors: geometry.getAttribute('sdfColor').array as Uint8Array,\n metadata: array('sdfMeta'),\n metaSize: geometry.getAttribute('sdfMeta').itemSize,\n bounds: array('windfoilBounds'),\n bands: array('windfoilBand'),\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n trackDirty,\n )\n const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES\n if (trackDirty) {\n for (let i = 0; i < list.length; i++) {\n const attribute = geometry.getAttribute(list[i]!) as InstancedBufferAttribute\n const base = i * 2\n flushAttributeUpdate(attribute, dirtyBounds[base]!, dirtyBounds[base + 1]!)\n }\n } else {\n for (const name of list)\n (geometry.getAttribute(name) as InstancedBufferAttribute).needsUpdate = true\n }\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAMA,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAE1D,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,aAAa;AACnB,IAAM,YAAY;AAClB,IAAM,cAAc;AACpB,IAAM,YAAY;AAClB,IAAM,aAAa;AACnB,IAAM,cAAc;AACpB,IAAM,8BAAc,IAAI,WAAW,EAAE;AAErC,SAAS,mBAAyB;CAChC,KAAK,IAAI,OAAO,GAAG,OAAO,GAAG,QAAQ;EACnC,MAAM,OAAO,OAAO;EACpB,YAAY,QAAQ;EACpB,YAAY,OAAO,KAAK;CAC1B;AACF;AAEA,SAAS,YAAY,MAAc,OAAe,KAAmB;CACnE,MAAM,OAAO,OAAO;CACpB,IAAI,QAAQ,YAAY,OAAQ,YAAY,QAAQ;CACpD,IAAI,MAAM,YAAY,OAA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.js","names":[],"sources":["../../src/windfoil/geometry.ts"],"sourcesContent":["import { InstancedBufferAttribute, InstancedBufferGeometry } from 'three/webgpu'\nimport {\n byte,\n flushAttributeUpdate,\n isDomSnapshot,\n metaSize,\n needsRunMotion,\n setBounds,\n setUnitQuad,\n} from '../text/geometryUtils.js'\nimport { GLYPH_RECTS_KEY } from '../text/decorations.js'\nimport type { DomLayoutSnapshot, GlyphLayout, WindfoilBoundingBox } from '../types.js'\nimport type { WindfoilGlyphHeader, WindfoilLayerHeader } from './preprocess.js'\n\ninterface PrevWindfoilBatch {\n readonly glyphs: readonly GlyphLayout[]\n readonly glyphsMap: ReadonlyMap<string, WindfoilGlyphHeader>\n readonly metaSize: number\n readonly fontEm: boolean\n readonly layered: boolean\n readonly hasOrdinals: boolean\n readonly allSingleDrawn: boolean\n}\n\nconst prevWindfoilCache = new WeakMap<InstancedBufferGeometry, PrevWindfoilBatch>()\n\nconst ATTRIBUTES = [\n 'sdfRect',\n 'sdfClip',\n 'sdfColor',\n 'sdfMeta',\n 'windfoilBounds',\n 'windfoilBand',\n] as const\nconst LAYERED_ATTRIBUTES = [...ATTRIBUTES, 'windfoilLayer'] as const\n\nconst SLOT_RECT = 0\nconst SLOT_CLIP = 1\nconst SLOT_COLOR = 2\nconst SLOT_META = 3\nconst SLOT_BOUNDS = 4\nconst SLOT_BAND = 5\nconst SLOT_LAYER = 6\nconst DIRTY_UNSET = 0x7fffffff\nconst dirtyBounds = new Int32Array(14)\n\nfunction resetDirtyBounds(): void {\n for (let slot = 0; slot < 7; slot++) {\n const base = slot * 2\n dirtyBounds[base] = DIRTY_UNSET\n dirtyBounds[base + 1] = 0\n }\n}\n\nfunction recordDirty(slot: number, start: number, end: number): void {\n const base = slot * 2\n if (start < dirtyBounds[base]!) dirtyBounds[base] = start\n if (end > dirtyBounds[base + 1]!) dirtyBounds[base + 1] = end\n}\n\nfunction writeFloat4(\n target: Float32Array,\n offset: number,\n a: number,\n b: number,\n c: number,\n d: number,\n trackDirty: boolean,\n slot: number,\n): void {\n if (trackDirty) {\n const fa = Math.fround(a)\n const fb = Math.fround(b)\n const fc = Math.fround(c)\n const fd = Math.fround(d)\n if (\n target[offset] === fa &&\n target[offset + 1] === fb &&\n target[offset + 2] === fc &&\n target[offset + 3] === fd\n ) {\n return\n }\n target[offset] = fa\n target[offset + 1] = fb\n target[offset + 2] = fc\n target[offset + 3] = fd\n recordDirty(slot, offset, offset + 4)\n return\n }\n target[offset] = a\n target[offset + 1] = b\n target[offset + 2] = c\n target[offset + 3] = d\n}\n\nexport interface MutableWindfoilAttributes {\n readonly rects: Float32Array\n readonly clips: Float32Array\n readonly colors: Uint8Array\n readonly metadata: Float32Array\n /** Components per `sdfMeta` entry; `3` carries the size-switch em. Defaults to `2`. */\n readonly metaSize?: number\n readonly fontEm?: boolean\n readonly bounds: Float32Array\n readonly bands: Float32Array\n readonly layers?: Float32Array\n readonly glyphRects?: Float32Array\n}\n\nconst scratchRect: [number, number, number, number] = [0, 0, 0, 0]\n\nexport function fillWindfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n out: [number, number, number, number] = scratchRect,\n): [number, number, number, number] {\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n out[0] = glyph.originX + bbox[0] * scale\n out[1] = baseline + bbox[1] * scale\n out[2] = glyph.originX + bbox[2] * scale\n out[3] = baseline + bbox[3] * scale\n return out\n}\n\nexport function windfoilGlyphRect(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n bbox: WindfoilBoundingBox = header.bbox,\n): readonly [number, number, number, number] {\n return fillWindfoilGlyphRect(glyph, header, bbox, [0, 0, 0, 0])\n}\n\n/** The negative font size feeds tone dilation while keeping the analytic batch selected. */\nexport function fixedGlyphEm(glyph: GlyphLayout): number {\n return glyph.shapeGroup === undefined ? -glyph.fontSize : 0\n}\n\nfunction writeInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n c0: number,\n c1: number,\n c2: number,\n c3: number,\n fc0: number,\n fc1: number,\n fc2: number,\n fc3: number,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const offset = index * 4\n const scale = glyph.fontSize / header.unitsPerEm\n const baseline = glyph.lineBottom + (glyph.baselineOffset ?? -header.descent * scale)\n const ox = glyph.originX\n const lBox = layer.bbox\n const b0 = lBox[0],\n b1 = lBox[1],\n b2 = lBox[2],\n b3 = lBox[3]\n writeFloat4(\n attributes.rects,\n offset,\n ox + b0 * scale,\n baseline + b1 * scale,\n ox + b2 * scale,\n baseline + b3 * scale,\n trackDirty,\n SLOT_RECT,\n )\n writeFloat4(attributes.clips, offset, fc0, fc1, fc2, fc3, trackDirty, SLOT_CLIP)\n const colors = attributes.colors\n if (trackDirty) {\n if (\n colors[offset] !== c0 ||\n colors[offset + 1] !== c1 ||\n colors[offset + 2] !== c2 ||\n colors[offset + 3] !== c3\n ) {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n recordDirty(SLOT_COLOR, offset, offset + 4)\n }\n } else {\n colors[offset] = c0\n colors[offset + 1] = c1\n colors[offset + 2] = c2\n colors[offset + 3] = c3\n }\n const metaSizeValue = attributes.metaSize ?? 2\n const metadata = attributes.metadata\n const m = index * metaSizeValue\n let em = 0\n if (metaSizeValue === 3) em = attributes.fontEm ? fixedGlyphEm(glyph) : (glyph.switchEm ?? 0)\n if (\n !trackDirty ||\n metadata[m] !== Math.fround(glyph.sequence) ||\n metadata[m + 1] !== Math.fround(glyph.z) ||\n (metaSizeValue === 3 && metadata[m + 2] !== Math.fround(em))\n ) {\n metadata[m] = glyph.sequence\n metadata[m + 1] = glyph.z\n if (metaSizeValue === 3) metadata[m + 2] = em\n if (trackDirty) recordDirty(SLOT_META, m, m + metaSizeValue)\n }\n writeFloat4(attributes.bounds, offset, b0, b1, b2, b3, trackDirty, SLOT_BOUNDS)\n writeFloat4(\n attributes.bands,\n offset,\n layer.rowBase,\n layer.bandCount,\n layer.bandH,\n layer.invH,\n trackDirty,\n SLOT_BAND,\n )\n const layers = attributes.layers\n if (layers) {\n const paint = 'paintKind' in layer ? layer : null\n const rect = glyphRect ?? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n const mo = glyph.motionOrigin\n writeFloat4(\n layers,\n offset,\n mo ? mo[0] : (rect[0] + rect[2]) / 2,\n mo ? mo[1] : (rect[1] + rect[3]) / 2,\n ordinal,\n paint?.paintKind === 2 ? 2 + (paint.paintIndex ?? 0) : (paint?.paintKind ?? 0),\n trackDirty,\n SLOT_LAYER,\n )\n }\n}\n\n/** Shared by text and shape geometry; one layer adds only one vertex attribute. */\nexport function writeLayerInstance(\n glyph: GlyphLayout,\n header: WindfoilGlyphHeader,\n layer: WindfoilGlyphHeader | WindfoilLayerHeader,\n index: number,\n ordinal: number,\n attributes: MutableWindfoilAttributes,\n glyphRect?: readonly [number, number, number, number],\n trackDirty = false,\n): void {\n const paint = 'paintKind' in layer ? layer : null\n const rgb = paint?.paintKind === 1 ? paint.rgba : glyph.color\n const clip = glyph.clip\n writeInstance(\n glyph,\n header,\n layer,\n index,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * (paint ? paint.rgba[3] : 1)),\n clip[0],\n clip[1],\n clip[2],\n clip[3],\n glyphRect,\n trackDirty,\n )\n}\n\nfunction countLayout(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n layered: boolean,\n): { instances: number; drawable: number } {\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? (header.layers?.length ?? 1) : 1\n }\n }\n return { instances, drawable }\n}\n\nfunction writeGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n attributes: MutableWindfoilAttributes,\n ordinals?: Float32Array,\n trackDirty = false,\n prev?: PrevWindfoilBatch,\n): { instances: number; maxSequence: number; minZ: number; maxZ: number } {\n let instance = 0,\n drawable = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n let prevKey: string | undefined\n let prevHeader: WindfoilGlyphHeader | undefined\n let prevColor: GlyphLayout['color'] | undefined\n let pc0 = 0\n let pc1 = 0\n let pc2 = 0\n let pc3 = 0\n let prevClip: GlyphLayout['clip'] | undefined\n let fc0 = 0\n let fc1 = 0\n let fc2 = 0\n let fc3 = 0\n const glyphList = snapshot.glyphs\n let canSkip =\n trackDirty &&\n prev !== undefined &&\n prev.allSingleDrawn &&\n !prev.layered &&\n !attributes.layers &&\n prev.glyphsMap === glyphs &&\n prev.metaSize === (attributes.metaSize ?? 2) &&\n prev.fontEm === Boolean(attributes.fontEm) &&\n prev.hasOrdinals === Boolean(ordinals)\n const prevGlyphs = canSkip ? prev!.glyphs : undefined\n for (let i = 0; i < glyphList.length; i++) {\n const glyph = glyphList[i]!\n if (\n canSkip &&\n instance === i &&\n drawable === i &&\n i < prevGlyphs!.length &&\n glyph === prevGlyphs![i]\n ) {\n instance++\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n continue\n }\n const key = glyph.glyphKey\n const header = key === prevKey ? prevHeader : ((prevKey = key), (prevHeader = glyphs.get(key)))\n if (!header?.monotonePieceCount) {\n canSkip = false\n continue\n }\n const ordinal = ordinals?.[i] ?? glyph.motionOrigin?.[2] ?? drawable\n const rect =\n attributes.layers || attributes.glyphRects\n ? fillWindfoilGlyphRect(glyph, header, header.bbox, scratchRect)\n : undefined\n if (attributes.glyphRects && rect) {\n const rectOffset = drawable * 4\n attributes.glyphRects[rectOffset] = rect[0]\n attributes.glyphRects[rectOffset + 1] = rect[1]\n attributes.glyphRects[rectOffset + 2] = rect[2]\n attributes.glyphRects[rectOffset + 3] = rect[3]\n }\n const clip = glyph.clip\n if (clip !== prevClip) {\n prevClip = clip\n fc0 = trackDirty ? Math.fround(clip[0]) : clip[0]\n fc1 = trackDirty ? Math.fround(clip[1]) : clip[1]\n fc2 = trackDirty ? Math.fround(clip[2]) : clip[2]\n fc3 = trackDirty ? Math.fround(clip[3]) : clip[3]\n }\n if (attributes.layers && header.layers) {\n for (const layer of header.layers) {\n writeLayerInstance(glyph, header, layer, instance++, ordinal, attributes, rect, trackDirty)\n }\n } else {\n const layer = header.layers?.[0] ?? header\n const paint = 'paintKind' in layer ? layer : null\n if (paint) {\n const rgb = paint.paintKind === 1 ? paint.rgba : glyph.color\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n byte(rgb[0]),\n byte(rgb[1]),\n byte(rgb[2]),\n byte(glyph.color[3] * paint.rgba[3]),\n fc0,\n fc1,\n fc2,\n fc3,\n rect,\n trackDirty,\n )\n } else {\n const color = glyph.color\n if (color !== prevColor) {\n prevColor = color\n pc0 = byte(color[0])\n pc1 = byte(color[1])\n pc2 = byte(color[2])\n pc3 = byte(color[3])\n }\n writeInstance(\n glyph,\n header,\n layer,\n instance++,\n ordinal,\n attributes,\n pc0,\n pc1,\n pc2,\n pc3,\n fc0,\n fc1,\n fc2,\n fc3,\n rect,\n trackDirty,\n )\n }\n }\n drawable++\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n return { instances: instance, maxSequence, minZ, maxZ }\n}\n\n/** Ordinary outlines retain the original six instance attributes. */\nexport function createWindfoilGlyphGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered = false,\n ordinals?: Float32Array,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n return createAnalyticGeometry(snapshot, glyphs, motionPadding, layered, ordinals, false)\n}\n\nexport function createAnalyticGeometry(\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n layered: boolean,\n ordinals: Float32Array | undefined,\n fontEm: boolean,\n): { geometry: InstancedBufferGeometry; maxSequence: number } {\n layered ||= !!ordinals || snapshot.glyphs.some((glyph) => !!glyph.motionOrigin)\n const meta = fontEm ? 3 : metaSize(snapshot)\n let count: number\n let rects: Float32Array\n let clips: Float32Array\n let colors: Uint8Array\n let metadata: Float32Array\n let bounds: Float32Array\n let bands: Float32Array\n let layers: Float32Array | undefined\n let glyphRects: Float32Array | undefined\n if (layered) {\n const counted = countLayout(snapshot, glyphs, true)\n count = counted.instances\n rects = new Float32Array(count * 4)\n clips = new Float32Array(count * 4)\n colors = new Uint8Array(count * 4)\n metadata = new Float32Array(count * meta)\n bounds = new Float32Array(count * 4)\n bands = new Float32Array(count * 4)\n layers = new Float32Array(count * 4)\n glyphRects = new Float32Array(counted.drawable * 4)\n } else {\n const total = snapshot.glyphs.length\n count = total\n rects = new Float32Array(total * 4)\n clips = new Float32Array(total * 4)\n colors = new Uint8Array(total * 4)\n metadata = new Float32Array(total * meta)\n bounds = new Float32Array(total * 4)\n bands = new Float32Array(total * 4)\n }\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\n rects,\n clips,\n colors,\n metadata,\n metaSize: meta,\n fontEm,\n bounds,\n bands,\n ...(layers && glyphRects ? { layers, glyphRects } : {}),\n },\n ordinals,\n )\n if (!layered && result.instances < count) {\n count = result.instances\n rects = rects.subarray(0, count * 4)\n clips = clips.subarray(0, count * 4)\n colors = colors.subarray(0, count * 4)\n metadata = metadata.subarray(0, count * meta)\n bounds = bounds.subarray(0, count * 4)\n bands = bands.subarray(0, count * 4)\n }\n const geometry = new InstancedBufferGeometry()\n geometry.name = 'ultra-text instanced Windfoil glyph quads'\n setUnitQuad(geometry)\n for (const [name, data, size, normalized] of [\n ['sdfRect', rects, 4, false],\n ['sdfClip', clips, 4, false],\n ['sdfColor', colors, 4, true],\n ['sdfMeta', metadata, meta, false],\n ['windfoilBounds', bounds, 4, false],\n ['windfoilBand', bands, 4, false],\n ] as const)\n geometry.setAttribute(name, new InstancedBufferAttribute(data, size, normalized))\n if (layers) {\n geometry.setAttribute('windfoilLayer', new InstancedBufferAttribute(layers, 4))\n geometry.userData[GLYPH_RECTS_KEY] = glyphRects\n geometry.userData['ultraOwnGlyphRects'] = glyphRects\n }\n geometry.instanceCount = count\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n if (isDomSnapshot(snapshot)) {\n prevWindfoilCache.set(geometry, {\n glyphs: snapshot.glyphs,\n glyphsMap: glyphs,\n metaSize: meta,\n fontEm,\n layered: Boolean(layers),\n hasOrdinals: Boolean(ordinals),\n allSingleDrawn: !layers && result.instances === snapshot.glyphs.length,\n })\n }\n return { geometry, maxSequence: result.maxSequence }\n}\n\nexport function windfoilContentFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n): boolean {\n return analyticGeometryFits(geometry, snapshot, glyphs, false)\n}\n\nexport function analyticGeometryFits(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n fontEm: boolean,\n): boolean {\n const attrs = geometry.attributes\n const layered = attrs['windfoilLayer'] !== undefined\n const names = layered ? LAYERED_ATTRIBUTES : ATTRIBUTES\n const count = geometry.instanceCount\n for (const name of names) {\n if (attrs[name]?.count !== count) return false\n }\n const metaSizeVal = fontEm ? 3 : metaSize(snapshot)\n if (attrs['sdfMeta']?.itemSize !== metaSizeVal) return false\n if (\n !layered &&\n isDomSnapshot(snapshot) &&\n !needsRunMotion(snapshot) &&\n snapshot.glyphs.length === count\n ) {\n let allPlainSingle = true\n for (const req of snapshot.requests) {\n const header = glyphs.get(req.key)\n if (!header?.monotonePieceCount || (header.layers?.length ?? 1) > 1) {\n allPlainSingle = false\n break\n }\n }\n if (allPlainSingle) return true\n }\n let instances = 0,\n drawable = 0\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n const layers = header?.layers?.length ?? 1\n if (!layered && (glyph.motionOrigin || layers > 1)) return false\n if (header?.monotonePieceCount) {\n drawable++\n instances += layered ? layers : 1\n }\n }\n return (\n instances === count &&\n (!layered ||\n (geometry.userData['ultraOwnGlyphRects'] as Float32Array | undefined)?.length ===\n drawable * 4)\n )\n}\n\n/** A width change moves single-layer glyphs while keeping their paint and curve data. */\nexport function reflowWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n backend: {\n readonly layered: boolean\n readonly glyphs: ReadonlyMap<string, WindfoilGlyphHeader>\n updateGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n padding: number,\n ): number | null\n },\n padding: number,\n glyphEm: boolean,\n): number | null {\n const glyphs = backend.glyphs\n if (\n backend.layered ||\n geometry.hasAttribute('windfoilLayer') ||\n !analyticGeometryFits(geometry, snapshot, glyphs, glyphEm)\n )\n return backend.updateGeometry(geometry, snapshot, padding)\n prevWindfoilCache.delete(geometry)\n const rects = geometry.getAttribute('sdfRect') as InstancedBufferAttribute\n const clips = geometry.getAttribute('sdfClip') as InstancedBufferAttribute\n const meta = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute\n let count = 0,\n maxSequence = 0,\n minZ = 0,\n maxZ = 0\n resetDirtyBounds()\n for (const glyph of snapshot.glyphs) {\n const header = glyphs.get(glyph.glyphKey)\n if (!header?.monotonePieceCount) continue\n const bbox = header.layers?.[0]?.bbox ?? header.bbox\n const rect = fillWindfoilGlyphRect(glyph, header, bbox)\n const offset = count * 4\n writeFloat4(\n rects.array as Float32Array,\n offset,\n rect[0],\n rect[1],\n rect[2],\n rect[3],\n true,\n SLOT_RECT,\n )\n const clip = glyph.clip\n writeFloat4(\n clips.array as Float32Array,\n offset,\n clip[0],\n clip[1],\n clip[2],\n clip[3],\n true,\n SLOT_CLIP,\n )\n const sequence = Math.fround(glyph.sequence)\n const m = count++ * meta.itemSize\n if (meta.array[m] !== sequence) {\n meta.array[m] = sequence\n recordDirty(SLOT_META, m, m + 1)\n }\n if (glyph.sequence > maxSequence) maxSequence = glyph.sequence\n if (glyph.z < minZ) minZ = glyph.z\n if (glyph.z > maxZ) maxZ = glyph.z\n }\n flushAttributeUpdate(rects, dirtyBounds[SLOT_RECT * 2]!, dirtyBounds[SLOT_RECT * 2 + 1]!)\n flushAttributeUpdate(clips, dirtyBounds[SLOT_CLIP * 2]!, dirtyBounds[SLOT_CLIP * 2 + 1]!)\n flushAttributeUpdate(meta, dirtyBounds[SLOT_META * 2]!, dirtyBounds[SLOT_META * 2 + 1]!)\n setBounds(geometry, snapshot.width, snapshot.height, padding, minZ, maxZ)\n return maxSequence\n}\n\nexport function updateWindfoilGlyphGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals?: Float32Array,\n checked = false,\n): number | null {\n return updateAnalyticGeometry(geometry, snapshot, glyphs, motionPadding, ordinals, checked, false)\n}\n\nexport function updateAnalyticGeometry(\n geometry: InstancedBufferGeometry,\n snapshot: DomLayoutSnapshot,\n glyphs: ReadonlyMap<string, WindfoilGlyphHeader>,\n motionPadding: number,\n ordinals: Float32Array | undefined,\n checked: boolean,\n fontEm: boolean,\n): number | null {\n if (!checked && !analyticGeometryFits(geometry, snapshot, glyphs, fontEm)) return null\n const rectAttr = geometry.getAttribute('sdfRect') as InstancedBufferAttribute\n const clipAttr = geometry.getAttribute('sdfClip') as InstancedBufferAttribute\n const colorAttr = geometry.getAttribute('sdfColor') as InstancedBufferAttribute\n const metaAttr = geometry.getAttribute('sdfMeta') as InstancedBufferAttribute\n const boundsAttr = geometry.getAttribute('windfoilBounds') as InstancedBufferAttribute\n const bandAttr = geometry.getAttribute('windfoilBand') as InstancedBufferAttribute\n const layer = geometry.attributes['windfoilLayer'] as InstancedBufferAttribute | undefined\n resetDirtyBounds()\n const domSnap = isDomSnapshot(snapshot)\n const metaItemSize = metaAttr.itemSize\n const result = writeGeometry(\n snapshot,\n glyphs,\n {\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 metaSize: metaItemSize,\n fontEm,\n bounds: boundsAttr.array as Float32Array,\n bands: bandAttr.array as Float32Array,\n ...(layer\n ? {\n layers: layer.array as Float32Array,\n glyphRects: geometry.userData['ultraOwnGlyphRects'] as Float32Array,\n }\n : {}),\n },\n ordinals,\n true,\n domSnap ? prevWindfoilCache.get(geometry) : undefined,\n )\n if (domSnap) {\n prevWindfoilCache.set(geometry, {\n glyphs: snapshot.glyphs,\n glyphsMap: glyphs,\n metaSize: metaItemSize,\n fontEm,\n layered: Boolean(layer),\n hasOrdinals: Boolean(ordinals),\n allSingleDrawn: !layer && result.instances === snapshot.glyphs.length,\n })\n } else {\n prevWindfoilCache.delete(geometry)\n }\n const list = layer ? LAYERED_ATTRIBUTES : ATTRIBUTES\n for (let i = 0; i < list.length; i++) {\n const attribute = geometry.getAttribute(list[i]!) as InstancedBufferAttribute\n flushAttributeUpdate(attribute, dirtyBounds[i * 2]!, dirtyBounds[i * 2 + 1]!)\n }\n setBounds(geometry, snapshot.width, snapshot.height, motionPadding, result.minZ, result.maxZ)\n return result.maxSequence\n}\n"],"mappings":";;;;AAwBA,IAAM,oCAAoB,IAAI,QAAoD;AAElF,IAAM,aAAa;CACjB;CACA;CACA;CACA;CACA;CACA;AACF;AACA,IAAM,qBAAqB,CAAC,GAAG,YAAY,eAAe;AAE1D,IAAM,YAAY;AAClB,IAAM,YAAY;AAClB,IAAM,aAAa;AACnB,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AAU;EAClB,UAAU,SAAS;EACnB,UAAU;EACV;EACA,QAAQ,WAAW;EACnB,OAAO,SAAS;EAChB,GAAI,QACA;GACE,QAAQ,MAAM;GACd,YAAY,SAAS,SAAS;EAChC,IACA,CAAC;CACP,GACA,UACA,MACA,UAAU,kBAAkB,IAAI,QAAQ,IAAI,KAAA,CAC9C;CACA,IAAI,SACF,kBAAkB,IAAI,UAAU;EAC9B,QAAQ,SAAS;EACjB,WAAW;EACX,UAAU;EACV;EACA,SAAS,QAAQ,KAAK;EACtB,aAAa,QAAQ,QAAQ;EAC7B,gBAAgB,CAAC,SAAS,OAAO,cAAc,SAAS,OAAO;CACjE,CAAC;MAED,kBAAkB,OAAO,QAAQ;CAEnC,MAAM,OAAO,QAAQ,qBAAqB;CAC1C,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,YAAY,SAAS,aAAa,KAAK,EAAG;EAChD,qBAAqB,WAAW,YAAY,IAAI,IAAK,YAAY,IAAI,IAAI,EAAG;CAC9E;CACA,UAAU,UAAU,SAAS,OAAO,SAAS,QAAQ,eAAe,OAAO,MAAM,OAAO,IAAI;CAC5F,OAAO,OAAO;AAChB"}
|
|
@@ -220,13 +220,14 @@ function sortByLow(arr, start, end, keys) {
|
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
|
-
function prepareBand(bandRecord, start,
|
|
223
|
+
function prepareBand(bandRecord, start, rawCount, curves) {
|
|
224
|
+
const pieceCount = rawCount & 2147483647, allLinear = (rawCount & 2147483648) !== 0;
|
|
224
225
|
if (pieceCount > scratchBandLow.length) {
|
|
225
226
|
const capLen = Math.max(scratchBandLow.length * 2, pieceCount);
|
|
226
227
|
scratchBandLow = new Float64Array(capLen);
|
|
227
228
|
scratchBandHeight = new Float64Array(capLen);
|
|
228
229
|
}
|
|
229
|
-
const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start *
|
|
230
|
+
const lowScratch = scratchBandLow, heightScratch = scratchBandHeight, cArr = poolPieceC, midArr = poolPieceMid, boundsArr = poolPieceBounds, shortLow = poolPieceLow, bandFloatBase = start * 4, q2FloatBase = bandFloatBase + pieceCount * 4;
|
|
230
231
|
let bottom = Infinity, top = -Infinity, activeCount = 0;
|
|
231
232
|
for (let k = 0; k < pieceCount; k++) {
|
|
232
233
|
const pair = bandFloatBase + k * 4, y0 = curves[pair + 1], y1 = curves[pair + 3], lo = y0 < y1 ? y0 : y1, hi = y0 < y1 ? y1 : y0, h = hi - lo;
|
|
@@ -269,7 +270,7 @@ function prepareBand(bandRecord, start, pieceCount, curves) {
|
|
|
269
270
|
sortByLow(cArr, shortBase, activeEnd, lowScratch);
|
|
270
271
|
}
|
|
271
272
|
for (let i = start; i < activeEnd; i++) {
|
|
272
|
-
const k = cArr[i], pair = bandFloatBase + k * 4, mid = q2FloatBase + k * 2, px0 = curves[pair], py0 = curves[pair + 1],
|
|
273
|
+
const k = cArr[i], pair = bandFloatBase + k * 4, mid = allLinear ? ~pair : q2FloatBase + (k >> 1) * 4 + (k & 1) * 2, px0 = curves[pair], py0 = curves[pair + 1], px2 = curves[pair + 2], py2 = curves[pair + 3], px1 = allLinear ? (px0 + px2) * .5 : curves[mid], up = py2 > py0, lo = up ? py0 : py2, i4 = i * 4;
|
|
273
274
|
cArr[i] = up ? pair : ~pair;
|
|
274
275
|
midArr[i] = mid;
|
|
275
276
|
shortLow[i] = lo;
|
|
@@ -323,24 +324,23 @@ function classifyLayer(layer, ey0, ex1, ey1, ex0Tol, ex1Tol, ey0Tol, ey1Tol) {
|
|
|
323
324
|
let xh = boundsArr[k4 + 3];
|
|
324
325
|
if (xh >= ex0Tol) {
|
|
325
326
|
if (yl >= s0 && yh <= s1) return 1;
|
|
326
|
-
const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2];
|
|
327
|
+
const pair = cs < 0 ? ~cs : cs, mid = midArr[k], px0 = curves[pair], px2 = curves[pair + 2], py0 = curves[pair + 1], py2 = curves[pair + 3], px1 = mid < 0 ? (px0 + px2) * .5 : curves[mid], py1 = mid < 0 ? (py0 + py2) * .5 : curves[mid + 1];
|
|
327
328
|
let a;
|
|
328
329
|
if (yl >= s0) {
|
|
329
330
|
a = sign > 0 ? px0 : px2;
|
|
330
331
|
if (a >= ex0Tol && a <= ex1Tol) return 1;
|
|
331
|
-
const b = at(px0,
|
|
332
|
+
const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
|
|
332
333
|
xl = a < b ? a : b;
|
|
333
334
|
xh = a < b ? b : a;
|
|
334
335
|
if (xh >= ex0Tol && xl <= ex1Tol) return 1;
|
|
335
336
|
} else if (yh <= s1) {
|
|
336
337
|
const b = sign > 0 ? px2 : px0;
|
|
337
338
|
if (b >= ex0Tol && b <= ex1Tol) return 1;
|
|
338
|
-
a = at(px0,
|
|
339
|
+
a = at(px0, px1, px2, solve(py0, py1, py2, s0));
|
|
339
340
|
xl = a < b ? a : b;
|
|
340
341
|
xh = a < b ? b : a;
|
|
341
342
|
if (xh >= ex0Tol && xl <= ex1Tol) return 1;
|
|
342
343
|
} else {
|
|
343
|
-
const px1 = curves[mid], py0 = curves[pair + 1], py1 = curves[mid + 1], py2 = curves[pair + 3];
|
|
344
344
|
a = at(px0, px1, px2, solve(py0, py1, py2, s0));
|
|
345
345
|
if (a >= ex0Tol && a <= ex1Tol) return 1;
|
|
346
346
|
const b = at(px0, px1, px2, solve(py0, py1, py2, s1));
|
|
@@ -489,7 +489,7 @@ function appendWindfoilLayerGrids(table, glyphs, coverage, opaque, signal, tunin
|
|
|
489
489
|
gridTableLen = table.length;
|
|
490
490
|
gridUsed = 0;
|
|
491
491
|
ensureLayerPools(totalLayers);
|
|
492
|
-
const totalPieces = Math.ceil(curves.length /
|
|
492
|
+
const totalPieces = Math.ceil(curves.length / 4), totalBands = Math.ceil(rows.length / 6);
|
|
493
493
|
if (poolPieceC.length < totalPieces) {
|
|
494
494
|
const cap = Math.max(poolPieceC.length * 2, totalPieces);
|
|
495
495
|
poolPieceC = new Int32Array(cap);
|