ultra-text 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -115
- package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
- package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
- package/dist/atlas/appendAtlas.js +35 -11
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +1 -1
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/colorGlyphs.d.ts +0 -10
- package/dist/atlas/colorGlyphs.js +97 -155
- package/dist/atlas/colorGlyphs.js.map +1 -1
- package/dist/atlas/colorTexture.d.ts +1 -0
- package/dist/atlas/colorTexture.js +64 -0
- package/dist/atlas/colorTexture.js.map +1 -0
- package/dist/atlas/cpuAtlas.js +8 -3
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +97 -42
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +10 -4
- package/dist/atlas/cpuWorker.js +99 -49
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +133 -56
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +140 -18
- package/dist/atlas/gpuCommon.js +726 -104
- package/dist/atlas/gpuCommon.js.map +1 -1
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +232 -61
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +237 -111
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/vanillaCore.js +156 -103
- package/dist/atlas/vanillaCore.js.map +1 -1
- package/dist/atlas/vanillaCpuAtlas.js +37 -52
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
- package/dist/atlas/vanillaExtras.js +91 -90
- package/dist/atlas/vanillaExtras.js.map +1 -1
- package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
- package/dist/atlas/vanillaGpuHelpers.js +262 -27
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
- package/dist/dom/DomSdf.js +85 -79
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +23 -18
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/Text.d.ts +4 -1
- package/dist/dom/Text.js +5 -1
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/browserShaping.js +31 -14
- package/dist/dom/browserShaping.js.map +1 -1
- package/dist/dom/clusters.js +13 -2
- package/dist/dom/clusters.js.map +1 -1
- package/dist/dom/cssEffects.d.ts +4 -0
- package/dist/dom/cssEffects.js +72 -0
- package/dist/dom/cssEffects.js.map +1 -0
- package/dist/dom/domAnalytic.d.ts +1 -2
- package/dist/dom/domAnalytic.js +1 -1
- package/dist/dom/domAnalytic.js.map +1 -1
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +4 -4
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +28 -12
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/markup.d.ts +10 -0
- package/dist/dom/markup.js +16 -1
- package/dist/dom/markup.js.map +1 -1
- package/dist/dom/pretextLayout.js +27 -19
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +747 -505
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/snapshotsEqual.d.ts +7 -0
- package/dist/dom/snapshotsEqual.js +68 -0
- package/dist/dom/snapshotsEqual.js.map +1 -0
- package/dist/dom/svgCapture.js +30 -27
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textTransform.d.ts +13 -1
- package/dist/dom/textTransform.js +31 -13
- package/dist/dom/textTransform.js.map +1 -1
- package/dist/dom/tone.js +15 -8
- package/dist/dom/tone.js.map +1 -1
- package/dist/slug/SlugMaterial.d.ts +6 -0
- package/dist/slug/SlugMaterial.js +48 -20
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/cff.d.ts +5 -0
- package/dist/slug/cff.js +780 -0
- package/dist/slug/cff.js.map +1 -0
- package/dist/slug/coverage.d.ts +3 -3
- package/dist/slug/coverage.js +283 -101
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +1 -1
- package/dist/slug/preprocessCore.js +100 -80
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.js +32 -39
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.js +47 -37
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +190 -62
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +74 -4
- package/dist/slug/vanillaCore.js +226 -217
- package/dist/slug/vanillaCore.js.map +1 -1
- package/dist/slug-vanilla.d.ts +1 -1
- package/dist/slug-vanilla.js +5 -4
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +3 -3
- package/dist/text/GlyphTextMaterial.d.ts +5 -0
- package/dist/text/GlyphTextMaterial.js +11 -7
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/RectMaterial.js +6 -10
- package/dist/text/RectMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +9 -3
- package/dist/text/SdfTextMaterial.js +122 -37
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -96
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometryUtils.d.ts +5 -0
- package/dist/text/geometryUtils.js +63 -9
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +1 -1
- package/dist/text/glyphGeometry.js +281 -200
- package/dist/text/glyphGeometry.js.map +1 -1
- package/dist/text/rectGeometry.js +46 -42
- package/dist/text/rectGeometry.js.map +1 -1
- package/dist/text/reflow.d.ts +5 -0
- package/dist/text/reflow.js +127 -68
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -1
- package/dist/text/snap.js +1 -1
- package/dist/text/snap.js.map +1 -1
- package/dist/text/tone.js +2 -2
- package/dist/text/tone.js.map +1 -1
- package/dist/types.d.ts +23 -7
- package/dist/vanilla.js +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
- package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
- package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
- package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
- package/dist/windfoil/WindfoilMaterial.js +71 -8
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/compositeGeometry.js +12 -5
- package/dist/windfoil/compositeGeometry.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +10 -2
- package/dist/windfoil/coverage.js +147 -59
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +15 -0
- package/dist/windfoil/geometry.js +154 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +8 -8
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/mixed.js +13 -4
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +63 -36
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.d.ts +1 -1
- package/dist/windfoil/requests.js +11 -4
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/resolveOutline.d.ts +9 -0
- package/dist/windfoil/resolveOutline.js +20 -0
- package/dist/windfoil/resolveOutline.js.map +1 -0
- package/dist/windfoil/runtime.d.ts +1 -0
- package/dist/windfoil/runtime.js +8 -24
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeGeometry.js +80 -34
- package/dist/windfoil/shapeGeometry.js.map +1 -1
- package/dist/windfoil/sizeSwitch.d.ts +1 -1
- package/dist/windfoil/sizeSwitch.js +13 -8
- package/dist/windfoil/sizeSwitch.js.map +1 -1
- package/dist/windfoil/storage.d.ts +23 -9
- package/dist/windfoil/storage.js +49 -30
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/svg/curves.d.ts +20 -0
- package/dist/windfoil/svg/curves.js +145 -42
- package/dist/windfoil/svg/curves.js.map +1 -1
- package/dist/windfoil/svg/document.js +10 -1
- package/dist/windfoil/svg/document.js.map +1 -1
- package/dist/windfoil/svg/pathConverter.js +66 -50
- package/dist/windfoil/svg/pathConverter.js.map +1 -1
- package/dist/windfoil/svg/pathData.d.ts +9 -0
- package/dist/windfoil/svg/pathData.js +142 -109
- package/dist/windfoil/svg/pathData.js.map +1 -1
- package/dist/windfoil/svg/winding.js +34 -10
- package/dist/windfoil/svg/winding.js.map +1 -1
- package/dist/windfoil/trace/contours.js +120 -50
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.js +578 -224
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
- package/dist/windfoil/trace/traceWorker.d.ts +13 -0
- package/dist/windfoil/trace/traceWorker.js +192 -0
- package/dist/windfoil/trace/traceWorker.js.map +1 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +335 -70
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +48 -29
- package/skills/ultra-text/SKILL.md +9 -10
- package/skills/ultra-text/references/frameworks.md +46 -2
- package/skills/ultra-text/references/three-tsl.md +26 -24
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +0 -1
package/dist/dom/snapshot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { glyphClusters, isEmojiCandidate } from "./clusters.js";
|
|
2
2
|
import { parseCssColor } from "./tone.js";
|
|
3
|
-
import { DEFAULT_IGNORE_SELECTOR, DEFAULT_TEXT_SELECTOR } from "./markup.js";
|
|
3
|
+
import { DEFAULT_IGNORE_SELECTOR, DEFAULT_TEXT_SELECTOR, isImmutableCapture, snapshotFlags } from "./markup.js";
|
|
4
4
|
import { snapGlyph } from "../text/snap.js";
|
|
5
5
|
import { precedingCharacter, resolveTextTransform, transformClusters } from "./textTransform.js";
|
|
6
6
|
// src/dom/snapshot.ts
|
|
@@ -55,9 +55,86 @@ var TRANSPARENT_SRGBA = [
|
|
|
55
55
|
0,
|
|
56
56
|
0
|
|
57
57
|
];
|
|
58
|
-
var STYLE_INSET_RE = /(?:^|;)\s*(?:left|top|right|bottom|inset)\s*:[^;]*/gi;
|
|
59
|
-
var STYLE_INSET_TEST_RE = /(?:^|;)\s*(?:left|top|right|bottom|inset)\s*:/i;
|
|
60
58
|
var SMALL_CAPS_RE = /(?:^|\s)small-caps(?:\s|$)/;
|
|
59
|
+
var strippedStyleCache = /* @__PURE__ */ new Map();
|
|
60
|
+
function stripStyleInsets(value) {
|
|
61
|
+
const cached = strippedStyleCache.get(value);
|
|
62
|
+
if (cached !== void 0) return cached;
|
|
63
|
+
const len = value.length;
|
|
64
|
+
let out = "";
|
|
65
|
+
let lastKept = 0;
|
|
66
|
+
let i = 0;
|
|
67
|
+
let declStart = 0;
|
|
68
|
+
while (i < len) {
|
|
69
|
+
while (i < len && value.charCodeAt(i) <= 32) i++;
|
|
70
|
+
let matchLen = 0;
|
|
71
|
+
if (i < len) {
|
|
72
|
+
const c0 = value.charCodeAt(i) | 32;
|
|
73
|
+
if (c0 === 108 && i + 4 < len) {
|
|
74
|
+
if ((value.charCodeAt(i + 1) | 32) === 101 && (value.charCodeAt(i + 2) | 32) === 102 && (value.charCodeAt(i + 3) | 32) === 116) matchLen = 4;
|
|
75
|
+
} else if (c0 === 116 && i + 3 < len) {
|
|
76
|
+
if ((value.charCodeAt(i + 1) | 32) === 111 && (value.charCodeAt(i + 2) | 32) === 112) matchLen = 3;
|
|
77
|
+
} else if (c0 === 114 && i + 5 < len) {
|
|
78
|
+
if ((value.charCodeAt(i + 1) | 32) === 105 && (value.charCodeAt(i + 2) | 32) === 103 && (value.charCodeAt(i + 3) | 32) === 104 && (value.charCodeAt(i + 4) | 32) === 116) matchLen = 5;
|
|
79
|
+
} else if (c0 === 98 && i + 6 < len) {
|
|
80
|
+
if ((value.charCodeAt(i + 1) | 32) === 111 && (value.charCodeAt(i + 2) | 32) === 116 && (value.charCodeAt(i + 3) | 32) === 116 && (value.charCodeAt(i + 4) | 32) === 111 && (value.charCodeAt(i + 5) | 32) === 109) matchLen = 6;
|
|
81
|
+
} else if (c0 === 105 && i + 5 < len) {
|
|
82
|
+
if ((value.charCodeAt(i + 1) | 32) === 110 && (value.charCodeAt(i + 2) | 32) === 115 && (value.charCodeAt(i + 3) | 32) === 101 && (value.charCodeAt(i + 4) | 32) === 116) matchLen = 5;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
let matched = false;
|
|
86
|
+
if (matchLen > 0) {
|
|
87
|
+
let j = i + matchLen;
|
|
88
|
+
while (j < len && value.charCodeAt(j) <= 32) j++;
|
|
89
|
+
if (j < len && value.charCodeAt(j) === 58) matched = true;
|
|
90
|
+
}
|
|
91
|
+
const semi = value.indexOf(";", i);
|
|
92
|
+
const nextDecl = semi >= 0 ? semi : len;
|
|
93
|
+
if (matched) {
|
|
94
|
+
if (declStart > lastKept) out += value.slice(lastKept, declStart);
|
|
95
|
+
lastKept = nextDecl;
|
|
96
|
+
}
|
|
97
|
+
if (semi < 0) break;
|
|
98
|
+
declStart = semi;
|
|
99
|
+
i = semi + 1;
|
|
100
|
+
}
|
|
101
|
+
const result = lastKept === 0 ? value : lastKept < len ? out + value.slice(lastKept) : out;
|
|
102
|
+
if (strippedStyleCache.size >= 1024) strippedStyleCache.clear();
|
|
103
|
+
strippedStyleCache.set(value, result);
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
function hasNonShareableRule(rules) {
|
|
107
|
+
for (const r of rules) {
|
|
108
|
+
if ("selectorText" in r) {
|
|
109
|
+
if (/[:+~]|\[style\b/i.test(r.selectorText)) return true;
|
|
110
|
+
}
|
|
111
|
+
if ("cssRules" in r) {
|
|
112
|
+
if ("start" in r || hasNonShareableRule(r.cssRules)) return true;
|
|
113
|
+
} else if ("href" in r) return true;
|
|
114
|
+
}
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
function measureExpansionBoxes(share, bLeft, bTop, bBottom, bWidth, bHeight, font, probe) {
|
|
118
|
+
if (share.length <= (share.codePointAt(0) > 65535 ? 2 : 1)) return void 0;
|
|
119
|
+
const parts = Array.from(share);
|
|
120
|
+
if (probe) probe.font = font.canvasFont;
|
|
121
|
+
const advances = parts.map((part) => /^\p{M}/u.test(part) ? 0 : probe?.measureText(part).width ?? 1);
|
|
122
|
+
const total = advances.reduce((sum, advance) => sum + advance, 0);
|
|
123
|
+
let left = bLeft;
|
|
124
|
+
return parts.map((c, index) => {
|
|
125
|
+
const width = total > 0 ? bWidth * advances[index] / total : bWidth / parts.length;
|
|
126
|
+
const item = {
|
|
127
|
+
left,
|
|
128
|
+
top: bTop,
|
|
129
|
+
bottom: bBottom,
|
|
130
|
+
width,
|
|
131
|
+
height: bHeight,
|
|
132
|
+
c
|
|
133
|
+
};
|
|
134
|
+
left += width;
|
|
135
|
+
return item;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
61
138
|
function cssColorToSrgba(document, value, opacity) {
|
|
62
139
|
if (opacity <= 0 || !value) return TRANSPARENT_SRGBA;
|
|
63
140
|
const rgba = parseCssColor(document, value, true);
|
|
@@ -124,19 +201,20 @@ function layoutDescents(context, boxHeights, scales, bakeSize, cache) {
|
|
|
124
201
|
return [result, scales.length === 1 ? scales[0] : scales[settled]];
|
|
125
202
|
}
|
|
126
203
|
function collectDomSnapshot(root, options = {}) {
|
|
127
|
-
if (options.svg || options.textShaping === "browser" || options.layoutEngine === "pretext") return Promise.all([
|
|
204
|
+
if (options.svg || options.textShaping === "browser" || options.layoutEngine === "pretext" || options.outline === "css" || options.dropShadow === "css") return Promise.all([
|
|
128
205
|
options.layoutEngine === "pretext" ? import("./pretextLayout.js") : void 0,
|
|
129
206
|
options.textShaping === "browser" ? import("./browserShaping.js") : void 0,
|
|
130
|
-
options.svg ? import("./svgCapture.js") : void 0
|
|
131
|
-
|
|
207
|
+
options.svg ? import("./svgCapture.js") : void 0,
|
|
208
|
+
options.outline === "css" || options.dropShadow === "css" ? import("./cssEffects.js") : void 0
|
|
209
|
+
]).then(([pretext, shaping, svg, cssEffects]) => {
|
|
132
210
|
if (svg && pretext) throw new RangeError("svg requires the Range layout engine");
|
|
133
211
|
svg?.resolveSvgOptions(options.svg);
|
|
134
212
|
shaping?.validateBrowserShaping(options);
|
|
135
|
-
return collectDomSnapshotSync(root, options, pretext, shaping, svg);
|
|
213
|
+
return collectDomSnapshotSync(root, options, pretext, shaping, svg, cssEffects);
|
|
136
214
|
});
|
|
137
215
|
return collectDomSnapshotSync(root, options);
|
|
138
216
|
}
|
|
139
|
-
function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
217
|
+
function collectDomSnapshotSync(root, options, pretext, shaping, svg, cssEffects) {
|
|
140
218
|
const document = root.ownerDocument;
|
|
141
219
|
const view = document.defaultView;
|
|
142
220
|
if (!view) throw new Error("collectDomSnapshot: the element is not attached to a browser document");
|
|
@@ -148,6 +226,10 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
148
226
|
const pixelsPerUnit = options.pixelsPerUnit ?? 1;
|
|
149
227
|
if (!Number.isFinite(pixelsPerUnit) || pixelsPerUnit <= 0) throw new RangeError("collectDomSnapshot: pixelsPerUnit must be a positive finite number");
|
|
150
228
|
const invScale = 1 / pixelsPerUnit;
|
|
229
|
+
const wantCssShadow = options.dropShadow === "css";
|
|
230
|
+
const wantCssOutline = options.outline === "css";
|
|
231
|
+
let cssDropShadow;
|
|
232
|
+
let cssOutline;
|
|
151
233
|
const rootRect = root.getBoundingClientRect();
|
|
152
234
|
const { left: rootLeft, top: rootTop, bottom: rootBottom } = rootRect;
|
|
153
235
|
if (rootRect.width <= 0 || rootRect.height <= 0) throw new Error("collectDomSnapshot: the source element has no layout box");
|
|
@@ -155,6 +237,7 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
155
237
|
const glyphs = [];
|
|
156
238
|
const blockLayouts = [];
|
|
157
239
|
let afterSpace = true;
|
|
240
|
+
let hasAnyDecorations = false;
|
|
158
241
|
const rects = [];
|
|
159
242
|
const requests = /* @__PURE__ */ new Map();
|
|
160
243
|
let lineCount = 0;
|
|
@@ -175,17 +258,6 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
175
258
|
const nativeCanvas = nativeBrowser && !(getContextDescriptor && "mock" in getContextDescriptor);
|
|
176
259
|
let share = !svg && !("mock" in view.getComputedStyle);
|
|
177
260
|
let shareChecked = false;
|
|
178
|
-
const hasNonShareableRule = (rules) => {
|
|
179
|
-
for (const r of rules) {
|
|
180
|
-
if ("selectorText" in r) {
|
|
181
|
-
if (/[:+~]|\[style\b/i.test(r.selectorText)) return true;
|
|
182
|
-
}
|
|
183
|
-
if ("cssRules" in r) {
|
|
184
|
-
if ("start" in r || hasNonShareableRule(r.cssRules)) return true;
|
|
185
|
-
} else if ("href" in r) return true;
|
|
186
|
-
}
|
|
187
|
-
return false;
|
|
188
|
-
};
|
|
189
261
|
const canShare = () => {
|
|
190
262
|
if (!share) return false;
|
|
191
263
|
if (!shareChecked) {
|
|
@@ -207,32 +279,55 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
207
279
|
};
|
|
208
280
|
const pathStyles = /* @__PURE__ */ new Map();
|
|
209
281
|
const nodes = /* @__PURE__ */ new Map();
|
|
282
|
+
let rootRec;
|
|
283
|
+
let nextNodeKid = 1;
|
|
284
|
+
const attrFlagOf = (name) => name === "data-text-block" || name === "data-sdf-block" ? 1 : name === "data-text-ignore" || name === "data-sdf-ignore" ? 2 : name === DEPTH_ATTRIBUTE || name === LEGACY_DEPTH_ATTRIBUTE ? 4 : 0;
|
|
210
285
|
const nodeOf = (el) => {
|
|
211
286
|
let rec = nodes.get(el);
|
|
212
287
|
if (!rec) {
|
|
213
288
|
const parent = el === root ? null : el.parentElement;
|
|
214
|
-
const u = parent ? nodeOf(parent) : null;
|
|
289
|
+
const u = parent ? parent === root && rootRec ? rootRec : nodeOf(parent) : null;
|
|
215
290
|
const attrs = el.attributes;
|
|
216
291
|
const attrCount = attrs.length;
|
|
217
292
|
const hasAttrs = !attrOnly || attrCount > 0;
|
|
218
|
-
|
|
293
|
+
const parentKid = u ? u.p ? u.p.kid : u.kid : 0;
|
|
294
|
+
let k = share && (el === root || u?.k !== void 0) ? `${parentKid}>${el.localName}` : void 0;
|
|
219
295
|
let attrFlags = 0;
|
|
220
296
|
if (attrCount > 0) {
|
|
221
297
|
const buildK = k !== void 0 && el !== root;
|
|
222
|
-
|
|
298
|
+
if (buildK && attrCount === 1) {
|
|
299
|
+
const a0 = attrs[0];
|
|
300
|
+
const n0 = a0.name;
|
|
301
|
+
attrFlags = attrFlagOf(n0);
|
|
302
|
+
const v0 = a0.value;
|
|
303
|
+
k = `${k}\u0001${n0}=${n0 === "style" && v0 ? strippedStyleCache.get(v0) ?? stripStyleInsets(v0) : v0}`;
|
|
304
|
+
} else if (buildK && attrCount === 2) {
|
|
305
|
+
const a0 = attrs[0];
|
|
306
|
+
const a1 = attrs[1];
|
|
307
|
+
const n0 = a0.name;
|
|
308
|
+
const n1 = a1.name;
|
|
309
|
+
attrFlags = attrFlagOf(n0) | attrFlagOf(n1);
|
|
310
|
+
const v0 = a0.value;
|
|
311
|
+
const v1 = a1.value;
|
|
312
|
+
const sv0 = n0 === "style" && v0 ? strippedStyleCache.get(v0) ?? stripStyleInsets(v0) : v0;
|
|
313
|
+
const sv1 = n1 === "style" && v1 ? strippedStyleCache.get(v1) ?? stripStyleInsets(v1) : v1;
|
|
314
|
+
k = `${k}\u0001${n0}=${sv0}\u0001${n1}=${sv1}`;
|
|
315
|
+
} else for (let i = 0; i < attrCount; i++) {
|
|
223
316
|
const a = attrs[i];
|
|
224
317
|
const name = a.name;
|
|
225
|
-
|
|
226
|
-
else if (name === "data-text-ignore" || name === "data-sdf-ignore") attrFlags |= 2;
|
|
227
|
-
else if (name === DEPTH_ATTRIBUTE || name === LEGACY_DEPTH_ATTRIBUTE) attrFlags |= 4;
|
|
318
|
+
attrFlags |= attrFlagOf(name);
|
|
228
319
|
if (buildK) {
|
|
229
320
|
const value = a.value;
|
|
230
|
-
k = `${k}\u0001${name}=${name === "style" && value
|
|
321
|
+
k = `${k}\u0001${name}=${name === "style" && value ? strippedStyleCache.get(value) ?? stripStyleInsets(value) : value}`;
|
|
231
322
|
}
|
|
232
323
|
}
|
|
233
324
|
}
|
|
234
325
|
let p = k ? pathStyles.get(k) : void 0;
|
|
235
|
-
if (p !== void 0 && !canShare())
|
|
326
|
+
if (p !== void 0 && !canShare()) {
|
|
327
|
+
p = void 0;
|
|
328
|
+
k = void 0;
|
|
329
|
+
}
|
|
330
|
+
const kid = k && !p ? nextNodeKid++ : void 0;
|
|
236
331
|
rec = {
|
|
237
332
|
el,
|
|
238
333
|
u,
|
|
@@ -240,10 +335,12 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
240
335
|
ig: (u?.ig ?? false) || hasAttrs && (defaultIgnoreAttr ? (attrFlags & 2) !== 0 : el.matches(ignoreSelector)),
|
|
241
336
|
do: (attrFlags & 4) !== 0 ? el : u?.do ?? null,
|
|
242
337
|
k,
|
|
338
|
+
kid,
|
|
243
339
|
p
|
|
244
340
|
};
|
|
245
341
|
if (k && !p) pathStyles.set(k, rec);
|
|
246
342
|
nodes.set(el, rec);
|
|
343
|
+
if (el === root) rootRec = rec;
|
|
247
344
|
}
|
|
248
345
|
return rec;
|
|
249
346
|
};
|
|
@@ -265,6 +362,15 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
265
362
|
return owner ? parsePx(owner.getAttribute(DEPTH_ATTRIBUTE) ?? owner.getAttribute(LEGACY_DEPTH_ATTRIBUTE), fallback) : fallback;
|
|
266
363
|
};
|
|
267
364
|
const isIgnored = (element) => nodeOf(element).ig;
|
|
365
|
+
const readCssEffects = (style, fontSize, opacity) => {
|
|
366
|
+
if (!cssEffects) return;
|
|
367
|
+
if (wantCssShadow && !cssDropShadow) cssDropShadow = cssEffects.parseCssTextShadow(document, parseCssColor, style, fontSize, invScale, opacity);
|
|
368
|
+
if (wantCssOutline && !cssOutline) cssOutline = cssEffects.parseCssTextStroke(document, parseCssColor, style, fontSize, invScale, opacity);
|
|
369
|
+
};
|
|
370
|
+
if (wantCssShadow || wantCssOutline) {
|
|
371
|
+
const rootStyle = styleOf(root);
|
|
372
|
+
readCssEffects(rootStyle, parsePx(rootStyle.fontSize, 16), opacityOf(root));
|
|
373
|
+
}
|
|
268
374
|
const svgRunner = svg ? svg.createSvgRunner(root, options.svg, {
|
|
269
375
|
style: styleOf,
|
|
270
376
|
opacity: opacityOf,
|
|
@@ -285,7 +391,9 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
285
391
|
return true;
|
|
286
392
|
};
|
|
287
393
|
const blockSet = blocks.length > 1 ? new Set(blocks) : null;
|
|
288
|
-
const
|
|
394
|
+
const treeWalkerFn = document.createTreeWalker;
|
|
395
|
+
const useNativeWalk = !("mock" in treeWalkerFn) && Function.prototype.toString.call(treeWalkerFn).includes("[native");
|
|
396
|
+
const nestedBlockFilter = !useNativeWalk && blockSet ? (node) => {
|
|
289
397
|
if (node.nodeType === 1 && node !== activeBlock && blockSet.has(node)) {
|
|
290
398
|
filterState.skippedNested = true;
|
|
291
399
|
return 2;
|
|
@@ -293,6 +401,7 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
293
401
|
return 1;
|
|
294
402
|
} : null;
|
|
295
403
|
const layoutEngine = options.layoutEngine ?? "range";
|
|
404
|
+
const cacheRangeRuns = layoutEngine === "range" && nativeBrowser && !options.reshape && !shaping && !svg;
|
|
296
405
|
if (options.rtlReflow && layoutEngine !== "range") throw new RangeError("collectDomSnapshot: rtlReflow requires the Range layout engine");
|
|
297
406
|
let range;
|
|
298
407
|
const appendBrowserRuns = shaping?.createBrowserCapture(document);
|
|
@@ -301,6 +410,13 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
301
410
|
const measuresBaselines = "CanvasRenderingContext2D" in view;
|
|
302
411
|
const deviceScale = view.devicePixelRatio > 0 ? view.devicePixelRatio : 1;
|
|
303
412
|
const textRuns = [];
|
|
413
|
+
const hitRuns = [];
|
|
414
|
+
const pendingTemplates = [];
|
|
415
|
+
const EMPTY_GLYPHS = [];
|
|
416
|
+
const snapTmplPrefix = `${rootRect.height}|${rootLeft}|${deviceScale}|${invScale}|${bakeSize}|${!!options.cjkLineBreaking}|${!!options.rtlReflow}|${options.textBackend ?? "sdf"}`;
|
|
417
|
+
let trackBlockGrid = false;
|
|
418
|
+
let blockOffCss = false;
|
|
419
|
+
let blockOffDev = false;
|
|
304
420
|
const boxHeights = /* @__PURE__ */ new Map();
|
|
305
421
|
let offCssGrid = false;
|
|
306
422
|
let offDeviceGrid = false;
|
|
@@ -309,10 +425,21 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
309
425
|
const scale64Device = 64 * deviceScale;
|
|
310
426
|
const offBox = (l, w, scale64) => offLayoutGrid(l, rootLeft, scale64, absRootLeft) || offLayoutGrid(l + w, rootLeft, scale64, absRootLeft);
|
|
311
427
|
const trackLayoutGrid = (l, w) => {
|
|
312
|
-
if (gridDone)
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
428
|
+
if (trackBlockGrid && !blockOffCss || !gridDone && !offCssGrid) {
|
|
429
|
+
if (offBox(l, w, 64)) {
|
|
430
|
+
if (trackBlockGrid) blockOffCss = true;
|
|
431
|
+
if (!gridDone) offCssGrid = true;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
if (deviceScale !== 1) {
|
|
435
|
+
if (trackBlockGrid && !blockOffDev || !gridDone && !offDeviceGrid) {
|
|
436
|
+
if (offBox(l, w, scale64Device)) {
|
|
437
|
+
if (trackBlockGrid) blockOffDev = true;
|
|
438
|
+
if (!gridDone) offDeviceGrid = true;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (!gridDone && offCssGrid && (deviceScale === 1 || offDeviceGrid)) gridDone = true;
|
|
316
443
|
};
|
|
317
444
|
const layoutScales = () => [...deviceScale === 1 || offDeviceGrid ? [] : [deviceScale], ...offCssGrid ? [] : [1]];
|
|
318
445
|
const measuresKerning = "OffscreenCanvas" in view;
|
|
@@ -375,8 +502,8 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
375
502
|
let key = code >= 0 && code < 128 ? asciiKeys[code] : keys.get(character);
|
|
376
503
|
if (key === void 0) {
|
|
377
504
|
key = `${fontRequestKey(font)}\u0000${character}`;
|
|
378
|
-
if (code >= 0 && code < 128) asciiKeys[code] = key;
|
|
379
|
-
keys.set(character, key);
|
|
505
|
+
if (asciiKeys && code >= 0 && code < 128) asciiKeys[code] = key;
|
|
506
|
+
else keys.set(character, key);
|
|
380
507
|
requests.set(key, {
|
|
381
508
|
key,
|
|
382
509
|
character,
|
|
@@ -495,11 +622,14 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
495
622
|
const opacity = opacityOf(parent);
|
|
496
623
|
if (opacity <= 0) return null;
|
|
497
624
|
const [font, keys, layoutFont, widths, space, asciiKeys, asciiWidths, pairWidths] = resolveFont(style);
|
|
625
|
+
if (wantCssShadow && !cssDropShadow || wantCssOutline && !cssOutline) readCssEffects(style, font.size, opacity);
|
|
498
626
|
const spacing = parsePx(style.letterSpacing, 0, font.size);
|
|
499
627
|
const wordSpacing = parsePx(style.wordSpacing, 0, font.size);
|
|
500
628
|
const whiteSpace = style.whiteSpace;
|
|
629
|
+
const decorations = readDecorations(parent, layoutFont, font.size, opacity);
|
|
630
|
+
if (decorations.length > 0) hasAnyDecorations = true;
|
|
501
631
|
return {
|
|
502
|
-
decorations
|
|
632
|
+
decorations,
|
|
503
633
|
font,
|
|
504
634
|
keys,
|
|
505
635
|
asciiKeys,
|
|
@@ -514,38 +644,18 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
514
644
|
keepsSpaces: whiteSpace !== "normal" && /pre(?!-l)|bre/.test(whiteSpace),
|
|
515
645
|
color: cssColorToSrgba(document, style.color, opacity),
|
|
516
646
|
z: depthOf(parent, options.textDepth ?? 1),
|
|
517
|
-
transform: resolveTextTransform(style.textTransform, parent)
|
|
647
|
+
transform: resolveTextTransform(style.textTransform, parent),
|
|
648
|
+
runKey: `${layoutFont}|${spacing}|${wordSpacing}`
|
|
518
649
|
};
|
|
519
650
|
};
|
|
520
651
|
const transformSeed = (node, transform) => transform.caseMap === "capitalize" ? precedingCharacter(node, styleOf) : void 0;
|
|
521
652
|
const expansionBoxes = (share, bLeft, bTop, bBottom, bWidth, bHeight, font) => {
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
if (probe) {
|
|
526
|
-
probe.font = font.canvasFont;
|
|
527
|
-
if (probe === kerningContext) lastKerningFont = "";
|
|
528
|
-
}
|
|
529
|
-
const advances = parts.map((part) => /^\p{M}/u.test(part) ? 0 : probe?.measureText(part).width ?? 1);
|
|
530
|
-
const total = advances.reduce((sum, advance) => sum + advance, 0);
|
|
531
|
-
let left = bLeft;
|
|
532
|
-
return parts.map((c, index) => {
|
|
533
|
-
const width = total > 0 ? bWidth * advances[index] / total : bWidth / parts.length;
|
|
534
|
-
const item = {
|
|
535
|
-
left,
|
|
536
|
-
top: bTop,
|
|
537
|
-
bottom: bBottom,
|
|
538
|
-
width,
|
|
539
|
-
height: bHeight,
|
|
540
|
-
c
|
|
541
|
-
};
|
|
542
|
-
left += width;
|
|
543
|
-
return item;
|
|
544
|
-
});
|
|
653
|
+
const probe = share.length > 1 ? ensureFontProbe() : null;
|
|
654
|
+
if (probe && probe === kerningContext) lastKerningFont = "";
|
|
655
|
+
return measureExpansionBoxes(share, bLeft, bTop, bBottom, bWidth, bHeight, font, probe);
|
|
545
656
|
};
|
|
546
657
|
const paragraphOf = (el, rec, block) => el === block || !isInlineBox(el, rec) ? el : rec.u?.owner === block ? rec.u.paragraph ??= paragraphOf(rec.u.el, rec.u, block) : block;
|
|
547
|
-
const resolveParent = (parent) => {
|
|
548
|
-
const rec = nodeOf(parent);
|
|
658
|
+
const resolveParent = (parent, rec = nodeOf(parent)) => {
|
|
549
659
|
if (rec.inline === void 0) {
|
|
550
660
|
if (rec.p) {
|
|
551
661
|
if (rec.p.inline === void 0) resolveParent(rec.p.el);
|
|
@@ -575,6 +685,8 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
575
685
|
overflowY: blockStyle.overflowY || overflow || "visible",
|
|
576
686
|
insetLeft: inset(blockStyle, "Left"),
|
|
577
687
|
insetRight: inset(blockStyle, "Right"),
|
|
688
|
+
insetTop: inset(blockStyle, "Top"),
|
|
689
|
+
textIndent: blockStyle.textIndent,
|
|
578
690
|
rtl,
|
|
579
691
|
align,
|
|
580
692
|
lastAlign,
|
|
@@ -591,94 +703,117 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
591
703
|
for (let blockIndex = 0; blockIndex < blocks.length; blockIndex++) {
|
|
592
704
|
const block = blocks[blockIndex];
|
|
593
705
|
blockLayouts[blockIndex] = EMPTY_BLOCK;
|
|
594
|
-
|
|
595
|
-
|
|
706
|
+
const blockRec = nodeOf(block);
|
|
707
|
+
if (blockRec.ig || displayNone(block, blockRec)) continue;
|
|
708
|
+
const blockRect = block === root ? rootRect : block.getBoundingClientRect();
|
|
596
709
|
if (blockRect.width <= 0 || blockRect.height <= 0) continue;
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
};
|
|
603
|
-
const { overflowX, overflowY, insetLeft, insetRight, rtl, align, lastAlign, justified, lineHeightRaw } = blockStyleOf(block);
|
|
604
|
-
const clip = toRect(blockRect);
|
|
605
|
-
const layoutClip = [
|
|
606
|
-
clip[0],
|
|
607
|
-
clip[1],
|
|
608
|
-
clip[2],
|
|
609
|
-
clip[3]
|
|
610
|
-
];
|
|
611
|
-
let minLeft = blockRect.left;
|
|
612
|
-
let maxRight = blockRect.right;
|
|
613
|
-
let minTop = blockRect.top;
|
|
614
|
-
let maxBottom = blockRect.bottom;
|
|
615
|
-
const includeTextBox = (left, top, bottom, width) => {
|
|
616
|
-
if (left < minLeft) minLeft = left;
|
|
617
|
-
if (left + width > maxRight) maxRight = left + width;
|
|
618
|
-
if (top < minTop) minTop = top;
|
|
619
|
-
if (bottom > maxBottom) maxBottom = bottom;
|
|
620
|
-
};
|
|
621
|
-
const includeTextBoxObj = (box) => includeTextBox(box.left, box.top, box.bottom, box.width);
|
|
710
|
+
const relLeft = blockRect.left - rootLeft;
|
|
711
|
+
const relTop = blockRect.top - rootTop;
|
|
712
|
+
const relWidth = blockRect.width;
|
|
713
|
+
const relHeight = blockRect.height;
|
|
714
|
+
const blockStyle = blockStyleOf(block, blockRec);
|
|
715
|
+
const { overflowX, overflowY, insetLeft, insetRight, insetTop, textIndent, rtl, align, lastAlign, justified, lineHeightRaw } = blockStyle;
|
|
622
716
|
const blockStart = glyphs.length;
|
|
623
717
|
const lineCountBefore = lineCount;
|
|
624
|
-
let
|
|
625
|
-
let blockWidth = clip[2] - clip[0] - (insetLeft + insetRight) * invScale;
|
|
626
|
-
let templateKey = "";
|
|
718
|
+
let tmplReady = false;
|
|
627
719
|
let templateTextNode = null;
|
|
628
720
|
let templateText = "";
|
|
721
|
+
let tmplScrollLeft = 0;
|
|
722
|
+
let tmplScrollTop = 0;
|
|
723
|
+
let tmplInlineTk = "";
|
|
724
|
+
let tmplBlkTk = "";
|
|
629
725
|
let templateBoxHeight = 0;
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
726
|
+
trackBlockGrid = false;
|
|
727
|
+
blockOffCss = false;
|
|
728
|
+
blockOffDev = false;
|
|
729
|
+
if (cacheRangeRuns && !options.pixelSnap && !block.firstElementChild && block.firstChild !== null && block.firstChild === block.lastChild && block.firstChild.nodeType === 3) {
|
|
730
|
+
const parentRec = resolveParent(block, blockRec);
|
|
634
731
|
const inline = parentRec.inline;
|
|
635
732
|
if (inline && parentRec.owner === block && !inline.transform && inline.decorations.length === 0) {
|
|
636
733
|
const templateFont = inline.font;
|
|
637
734
|
templateTextNode = block.firstChild;
|
|
638
735
|
templateText = templateTextNode.data;
|
|
639
736
|
const c = inline.color;
|
|
640
|
-
|
|
737
|
+
tmplInlineTk = inline.tk ?? (inline.tk = `${inline.layoutFont}|${templateFont.key}|${inline.letterSpacing}|${inline.wordSpacing}|${inline.z}|${inline.keepsSpaces}|${c[0]},${c[1]},${c[2]},${c[3]}`);
|
|
738
|
+
tmplBlkTk = blockStyle.tk ?? (blockStyle.tk = `${overflowX}|${overflowY}|${insetLeft}|${insetRight}|${insetTop}|${textIndent}|${rtl}|${align}|${lastAlign}|${lineHeightRaw}`);
|
|
739
|
+
tmplScrollLeft = block.scrollLeft;
|
|
740
|
+
tmplScrollTop = block.scrollTop;
|
|
641
741
|
const tmpl = cachedBlockTemplates.get(block);
|
|
642
|
-
if (tmpl?.n === templateTextNode && tmpl.s === templateText && tmpl.
|
|
643
|
-
|
|
742
|
+
if (tmpl?.n === templateTextNode && tmpl.s === templateText && tmpl.bi === blockIndex && tmpl.sl === tmplScrollLeft && tmpl.st === tmplScrollTop && tmpl.it === tmplInlineTk && tmpl.bt === tmplBlkTk && tmpl.p === snapTmplPrefix && tmpl.r.left === relLeft && tmpl.r.top === relTop && tmpl.r.width === relWidth && tmpl.r.height === relHeight) {
|
|
743
|
+
const immutableHit = isImmutableCapture();
|
|
644
744
|
const tGlyphs = tmpl.g;
|
|
645
|
-
for (let i = 0, len = tGlyphs.length; i < len; i++) glyphs.push(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
character: tq[i + 1],
|
|
657
|
-
font: templateFont
|
|
745
|
+
if (immutableHit) for (let i = 0, len = tGlyphs.length; i < len; i++) glyphs.push(tGlyphs[i]);
|
|
746
|
+
else {
|
|
747
|
+
const hitClip = [
|
|
748
|
+
tmpl.c[0],
|
|
749
|
+
tmpl.c[1],
|
|
750
|
+
tmpl.c[2],
|
|
751
|
+
tmpl.c[3]
|
|
752
|
+
];
|
|
753
|
+
for (let i = 0, len = tGlyphs.length; i < len; i++) glyphs.push({
|
|
754
|
+
...tGlyphs[i],
|
|
755
|
+
clip: hitClip
|
|
658
756
|
});
|
|
659
757
|
}
|
|
758
|
+
const tReq = tmpl.req;
|
|
759
|
+
for (let i = 0, len = tReq.length; i < len; i++) {
|
|
760
|
+
const req = tReq[i];
|
|
761
|
+
if (!requests.has(req.key)) requests.set(req.key, req);
|
|
762
|
+
}
|
|
660
763
|
if (measuresBaselines) {
|
|
661
|
-
|
|
662
|
-
if (
|
|
764
|
+
if (tmpl.oc) offCssGrid = true;
|
|
765
|
+
if (tmpl.od) offDeviceGrid = true;
|
|
766
|
+
if (offCssGrid && (deviceScale === 1 || offDeviceGrid)) gridDone = true;
|
|
663
767
|
if (tmpl.bh > 0) {
|
|
664
|
-
|
|
768
|
+
const prevHitRun = hitRuns[hitRuns.length - 1];
|
|
769
|
+
if (prevHitRun?.[0] === templateFont && prevHitRun[2] === blockStart && prevHitRun[3] === tmpl.bo) prevHitRun[2] = glyphs.length;
|
|
770
|
+
else hitRuns.push([
|
|
665
771
|
templateFont,
|
|
666
772
|
blockStart,
|
|
667
|
-
glyphs.length
|
|
773
|
+
glyphs.length,
|
|
774
|
+
tmpl.bo
|
|
668
775
|
]);
|
|
669
776
|
if (!boxHeights.has(templateFont)) boxHeights.set(templateFont, tmpl.bh);
|
|
670
777
|
}
|
|
671
778
|
}
|
|
672
779
|
lineCount += tmpl.l;
|
|
673
|
-
if (tGlyphs.length > 0) blockLayouts[blockIndex] = {
|
|
780
|
+
if (tGlyphs.length > 0) blockLayouts[blockIndex] = immutableHit ? tmpl.bl : {
|
|
674
781
|
...tmpl.bl,
|
|
675
|
-
clip:
|
|
782
|
+
clip: toRect(blockRect)
|
|
676
783
|
};
|
|
677
784
|
afterSpace = true;
|
|
678
785
|
continue;
|
|
679
786
|
}
|
|
787
|
+
tmplReady = true;
|
|
788
|
+
trackBlockGrid = measuresBaselines;
|
|
680
789
|
}
|
|
681
790
|
}
|
|
791
|
+
const relBlockRect = {
|
|
792
|
+
left: relLeft,
|
|
793
|
+
top: relTop,
|
|
794
|
+
width: relWidth,
|
|
795
|
+
height: relHeight
|
|
796
|
+
};
|
|
797
|
+
const clip = toRect(blockRect);
|
|
798
|
+
const layoutClip = [
|
|
799
|
+
clip[0],
|
|
800
|
+
clip[1],
|
|
801
|
+
clip[2],
|
|
802
|
+
clip[3]
|
|
803
|
+
];
|
|
804
|
+
let minLeft = blockRect.left;
|
|
805
|
+
let maxRight = blockRect.right;
|
|
806
|
+
let minTop = blockRect.top;
|
|
807
|
+
let maxBottom = blockRect.bottom;
|
|
808
|
+
const includeTextBox = (left, top, bottom, width) => {
|
|
809
|
+
if (left < minLeft) minLeft = left;
|
|
810
|
+
if (left + width > maxRight) maxRight = left + width;
|
|
811
|
+
if (top < minTop) minTop = top;
|
|
812
|
+
if (bottom > maxBottom) maxBottom = bottom;
|
|
813
|
+
};
|
|
814
|
+
const includeTextBoxObj = (box) => includeTextBox(box.left, box.top, box.bottom, box.width);
|
|
815
|
+
let blockLeft = clip[0] + insetLeft * invScale;
|
|
816
|
+
let blockWidth = clip[2] - clip[0] - (insetLeft + insetRight) * invScale;
|
|
682
817
|
if (appendBrowserRuns) {
|
|
683
818
|
const lineKeys = /* @__PURE__ */ new Set();
|
|
684
819
|
appendBrowserRuns(block, {
|
|
@@ -734,9 +869,11 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
734
869
|
sequences.set(lineKey, lastSeqNext);
|
|
735
870
|
return seq;
|
|
736
871
|
};
|
|
872
|
+
const hasElementChild = block.firstElementChild !== null;
|
|
737
873
|
activeBlock = block;
|
|
738
874
|
filterState.skippedNested = false;
|
|
739
|
-
const walker =
|
|
875
|
+
const walker = !useNativeWalk && hasElementChild ? document.createTreeWalker(block, 5, nestedBlockFilter) : null;
|
|
876
|
+
const blockRunKey = cacheRangeRuns ? `${blockRect.width}|${block.scrollLeft}|${block.scrollTop}|${insetLeft}|${insetRight}|${insetTop}|${textIndent}|${rtl}|${align}|${lastAlign}|${lineHeightRaw}` : "";
|
|
740
877
|
let markAnchorLineKey = 0;
|
|
741
878
|
let hasMarkAnchor = false;
|
|
742
879
|
let previousCharacter = "";
|
|
@@ -750,376 +887,423 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
750
887
|
let blockSynced = true;
|
|
751
888
|
let nodeIndex = 0;
|
|
752
889
|
let node = walker ? walker.nextNode() : block.firstChild;
|
|
753
|
-
|
|
754
|
-
if (consumeSkipped(filterState)) {
|
|
890
|
+
while (node) {
|
|
891
|
+
if (walker && consumeSkipped(filterState)) {
|
|
755
892
|
hasMarkAnchor = false;
|
|
756
893
|
previousCharacter = "";
|
|
757
894
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
895
|
+
let nextNode = null;
|
|
896
|
+
const nType = node.nodeType;
|
|
897
|
+
if (nType === 1) {
|
|
761
898
|
const element = node;
|
|
762
|
-
|
|
763
|
-
if (svgRunner && nodeOf(element).owner === block && svgRunner.capture(element, blockIndex, clip, (glyphs[glyphs.length - 1]?.sequence ?? -1) + 1)) {
|
|
764
|
-
const last = glyphs[glyphs.length - 1];
|
|
765
|
-
if (last?.shapeGroup !== void 0) {
|
|
766
|
-
const sequence = nextSequence(hasMarkAnchor ? markAnchorLineKey : Math.round(element.getBoundingClientRect().top * 4));
|
|
767
|
-
for (let i = glyphs.length - 1; i >= 0 && glyphs[i].shapeGroup === last.shapeGroup; i--) glyphs[i].sequence = sequence;
|
|
768
|
-
if (gap && justified && shapeStart < glyphs.length) glyphs[shapeStart].gapBefore = gap;
|
|
769
|
-
}
|
|
770
|
-
gap = 0;
|
|
771
|
-
afterSpace = true;
|
|
899
|
+
if (!walker && blockSet?.has(element)) {
|
|
772
900
|
hasMarkAnchor = false;
|
|
773
901
|
previousCharacter = "";
|
|
774
|
-
}
|
|
775
|
-
forced ||= element.tagName === "BR" && !displayNone(element);
|
|
776
|
-
if (forced || options.cjkLineBreaking && !isInlineBox(element)) previousCharacter = "";
|
|
777
|
-
continue;
|
|
778
|
-
}
|
|
779
|
-
const textNode = node;
|
|
780
|
-
const parent = textNode.parentElement;
|
|
781
|
-
if (svg && parent?.closest("svg") && !parent.closest("foreignObject")) continue;
|
|
782
|
-
const record = parent ? resolveParent(parent) : null;
|
|
783
|
-
if (!record?.inline || record.owner !== block) {
|
|
784
|
-
hasMarkAnchor = false;
|
|
785
|
-
previousCharacter = "";
|
|
786
|
-
continue;
|
|
787
|
-
}
|
|
788
|
-
const { font, keys, asciiKeys, fontSize, layoutFont, widths, asciiWidths, pairWidths, letterSpacing, wordSpacing, space, keepsSpaces, color, z, decorations, transform } = record.inline;
|
|
789
|
-
let utf16Offset = 0;
|
|
790
|
-
let textData = textNode.data;
|
|
791
|
-
let shown = transform ? transformClusters(textData, transform, transformSeed(textNode, transform)) : void 0;
|
|
792
|
-
if (options.reshape) {
|
|
793
|
-
const input = shown ? shown.join("") : textData;
|
|
794
|
-
const reshaped = options.reshape(input);
|
|
795
|
-
if (reshapeBoundaries(input) !== reshapeBoundaries(reshaped)) throw new RangeError("collectDomSnapshot: Range reshaping must preserve code point boundaries and whitespace");
|
|
796
|
-
let end = 0;
|
|
797
|
-
if (shown) shown = shown.map((share) => reshaped.slice(end, end += share.length));
|
|
798
|
-
else textData = reshaped;
|
|
799
|
-
}
|
|
800
|
-
const runStart = glyphs.length;
|
|
801
|
-
let boxHeight = 0;
|
|
802
|
-
let clusterIndex = 0;
|
|
803
|
-
let hasKernPrevious = false;
|
|
804
|
-
let kernPrevChar = "";
|
|
805
|
-
let kernPrevLeft = 0;
|
|
806
|
-
let kernPrevWidth = -1;
|
|
807
|
-
let kernPrevCarry = 0;
|
|
808
|
-
let hit;
|
|
809
|
-
let canSync = false;
|
|
810
|
-
let synced = false;
|
|
811
|
-
let syncSource;
|
|
812
|
-
let syncDelta = 0;
|
|
813
|
-
let prevRects;
|
|
814
|
-
let prevDelta = 0;
|
|
815
|
-
let suffixStart = Infinity;
|
|
816
|
-
let prevBmp = false;
|
|
817
|
-
let emojiText;
|
|
818
|
-
let clusters;
|
|
819
|
-
let rawString;
|
|
820
|
-
if (nativeBrowser && !shown && !options.reshape && !options.svg) {
|
|
821
|
-
const styleKey = `${nodeIndex}|${blockRect.width}|${block.scrollLeft}|${block.scrollTop}|${layoutFont}|${letterSpacing}|${wordSpacing}`;
|
|
822
|
-
const prevHit = cachedTextRuns.get(textNode);
|
|
823
|
-
if (prevHit?.styleKey === styleKey && prevHit.text === textData && sameBox(relBlockRect, prevHit.blockRect)) {
|
|
824
|
-
hit = prevHit;
|
|
825
|
-
emojiText = prevHit.emojiText;
|
|
826
|
-
clusters = prevHit.clusters;
|
|
827
|
-
rawString = prevHit.rawString;
|
|
828
|
-
canSync = true;
|
|
829
|
-
synced = blockSynced;
|
|
830
|
-
syncSource = prevHit.rects;
|
|
831
902
|
} else {
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
const minLen = nA < nB ? nA : nB;
|
|
841
|
-
let tail = 0;
|
|
842
|
-
while (tail < minLen && prevText.charCodeAt(nA - 1 - tail) === textData.charCodeAt(nB - 1 - tail)) tail++;
|
|
843
|
-
if (tail > 2) {
|
|
844
|
-
suffixStart = nB - tail;
|
|
845
|
-
prevRects = prevHit.rects;
|
|
846
|
-
prevDelta = nA - nB;
|
|
847
|
-
prevBmp = true;
|
|
903
|
+
nodeIndex++;
|
|
904
|
+
const shapeStart = glyphs.length;
|
|
905
|
+
if (svgRunner && nodeOf(element).owner === block && svgRunner.capture(element, blockIndex, clip, (glyphs[glyphs.length - 1]?.sequence ?? -1) + 1)) {
|
|
906
|
+
const last = glyphs[glyphs.length - 1];
|
|
907
|
+
if (last?.shapeGroup !== void 0) {
|
|
908
|
+
const sequence = nextSequence(hasMarkAnchor ? markAnchorLineKey : Math.round(element.getBoundingClientRect().top * 4));
|
|
909
|
+
for (let i = glyphs.length - 1; i >= 0 && glyphs[i].shapeGroup === last.shapeGroup; i--) glyphs[i].sequence = sequence;
|
|
910
|
+
if (gap && justified && shapeStart < glyphs.length) glyphs[shapeStart].gapBefore = gap;
|
|
848
911
|
}
|
|
849
|
-
|
|
850
|
-
cachedTextRuns.set(textNode, hit = {
|
|
851
|
-
styleKey,
|
|
852
|
-
text: textData,
|
|
853
|
-
rects: new Float64Array(textData.length * 5),
|
|
854
|
-
blockRect: void 0,
|
|
855
|
-
emojiText,
|
|
856
|
-
rawString,
|
|
857
|
-
clusters,
|
|
858
|
-
bmp: false
|
|
859
|
-
});
|
|
860
|
-
syncSource = hit.rects;
|
|
861
|
-
}
|
|
862
|
-
} else {
|
|
863
|
-
emojiText = isEmojiCandidate(textData);
|
|
864
|
-
clusters = glyphClusters(textData);
|
|
865
|
-
rawString = typeof clusters === "string";
|
|
866
|
-
}
|
|
867
|
-
const rects = hit?.rects;
|
|
868
|
-
let bmp = rawString;
|
|
869
|
-
const clusterArr = rawString ? null : clusters;
|
|
870
|
-
const totalItems = rawString ? textData.length : clusterArr.length;
|
|
871
|
-
let pos = 0;
|
|
872
|
-
let ci = -1;
|
|
873
|
-
while (pos < totalItems) {
|
|
874
|
-
ci++;
|
|
875
|
-
let cluster;
|
|
876
|
-
let step;
|
|
877
|
-
let isPrintableAscii = false;
|
|
878
|
-
if (rawString) {
|
|
879
|
-
const c0 = textData.charCodeAt(pos);
|
|
880
|
-
if (!shown && (c0 === 32 || c0 >= 9 && c0 <= 13)) {
|
|
881
|
-
if (!gap || keepsSpaces) gap += space;
|
|
912
|
+
gap = 0;
|
|
882
913
|
afterSpace = true;
|
|
883
|
-
hasMarkAnchor =
|
|
914
|
+
hasMarkAnchor = false;
|
|
884
915
|
previousCharacter = "";
|
|
885
|
-
pos++;
|
|
886
|
-
utf16Offset++;
|
|
887
|
-
continue;
|
|
888
916
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
isPrintableAscii = true;
|
|
893
|
-
} else if (c0 >= 55296 && c0 <= 56319 && pos + 1 < totalItems && textData.charCodeAt(pos + 1) >= 56320 && textData.charCodeAt(pos + 1) <= 57343) {
|
|
894
|
-
step = 2;
|
|
895
|
-
bmp = false;
|
|
896
|
-
cluster = textData.slice(pos, pos + 2);
|
|
897
|
-
} else {
|
|
898
|
-
step = 1;
|
|
899
|
-
cluster = c0 < 128 ? SINGLE_CHAR[c0] : textData[pos];
|
|
900
|
-
}
|
|
901
|
-
} else {
|
|
902
|
-
step = 1;
|
|
903
|
-
cluster = clusterArr[pos];
|
|
917
|
+
forced ||= element.tagName === "BR" && !displayNone(element);
|
|
918
|
+
if (forced || options.cjkLineBreaking && !isInlineBox(element)) previousCharacter = "";
|
|
919
|
+
if (!walker) nextNode = element.firstChild;
|
|
904
920
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
if (sc !== 160) afterSpace = true;
|
|
914
|
-
}
|
|
915
|
-
hasMarkAnchor = hasKernPrevious = false;
|
|
921
|
+
} else if (nType === 3) {
|
|
922
|
+
nodeIndex++;
|
|
923
|
+
const textNode = node;
|
|
924
|
+
const parent = textNode.parentElement;
|
|
925
|
+
if (!(svg && parent?.closest("svg") && !parent.closest("foreignObject"))) {
|
|
926
|
+
const record = parent ? resolveParent(parent) : null;
|
|
927
|
+
if (!record?.inline || record.owner !== block) {
|
|
928
|
+
hasMarkAnchor = false;
|
|
916
929
|
previousCharacter = "";
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
930
|
+
} else {
|
|
931
|
+
const { font, keys, asciiKeys, fontSize, layoutFont, widths, asciiWidths, pairWidths, letterSpacing, space, keepsSpaces, color, z, decorations, transform, runKey } = record.inline;
|
|
932
|
+
let utf16Offset = 0;
|
|
933
|
+
let textData = textNode.data;
|
|
934
|
+
let shown = transform ? transformClusters(textData, transform, transformSeed(textNode, transform)) : void 0;
|
|
935
|
+
if (options.reshape) {
|
|
936
|
+
const input = shown ? shown.join("") : textData;
|
|
937
|
+
const reshaped = options.reshape(input);
|
|
938
|
+
if (reshapeBoundaries(input) !== reshapeBoundaries(reshaped)) throw new RangeError("collectDomSnapshot: Range reshaping must preserve code point boundaries and whitespace");
|
|
939
|
+
let end = 0;
|
|
940
|
+
if (shown) shown = shown.map((share) => reshaped.slice(end, end += share.length));
|
|
941
|
+
else textData = reshaped;
|
|
942
|
+
}
|
|
943
|
+
const runStart = glyphs.length;
|
|
944
|
+
let boxHeight = 0;
|
|
945
|
+
let clusterIndex = 0;
|
|
946
|
+
let hasKernPrevious = false;
|
|
947
|
+
let kernPrevChar = "";
|
|
948
|
+
let kernPrevCode = -1;
|
|
949
|
+
let kernPrevLeft = 0;
|
|
950
|
+
let kernPrevWidth = -1;
|
|
951
|
+
let kernPrevCarry = 0;
|
|
952
|
+
let hit;
|
|
953
|
+
let canSync = false;
|
|
954
|
+
let synced = false;
|
|
955
|
+
let syncSource;
|
|
956
|
+
let syncDelta = 0;
|
|
957
|
+
let prevRects;
|
|
958
|
+
let prevDelta = 0;
|
|
959
|
+
let suffixStart = Infinity;
|
|
960
|
+
let emojiText;
|
|
961
|
+
let clusters;
|
|
962
|
+
let rawString;
|
|
963
|
+
if (cacheRangeRuns && !shown) {
|
|
964
|
+
const styleKey = `${nodeIndex}|${blockRunKey}|${runKey}`;
|
|
965
|
+
const prevHit = cachedTextRuns.get(textNode);
|
|
966
|
+
if (prevHit?.styleKey === styleKey && prevHit.text === textData && sameBox(relBlockRect, prevHit.blockRect)) {
|
|
967
|
+
hit = prevHit;
|
|
968
|
+
emojiText = prevHit.emojiText;
|
|
969
|
+
clusters = prevHit.clusters;
|
|
970
|
+
rawString = prevHit.rawString;
|
|
971
|
+
canSync = true;
|
|
972
|
+
synced = blockSynced;
|
|
973
|
+
syncSource = prevHit.rects;
|
|
974
|
+
} else {
|
|
975
|
+
blockSynced = false;
|
|
976
|
+
emojiText = isEmojiCandidate(textData);
|
|
977
|
+
clusters = glyphClusters(textData);
|
|
978
|
+
rawString = typeof clusters === "string";
|
|
979
|
+
if (prevHit?.styleKey === styleKey && prevHit.rawString && rawString && prevHit.bmp && sameBox(relBlockRect, prevHit.blockRect) && !justified && !textNode.nextSibling && (parent === block || parent !== null && !parent.nextSibling)) {
|
|
980
|
+
const prevText = prevHit.text;
|
|
981
|
+
const nA = prevText.length;
|
|
982
|
+
const nB = textData.length;
|
|
983
|
+
const minLen = nA < nB ? nA : nB;
|
|
984
|
+
let tail = 0;
|
|
985
|
+
while (tail < minLen && prevText.charCodeAt(nA - 1 - tail) === textData.charCodeAt(nB - 1 - tail)) tail++;
|
|
986
|
+
if (tail > 2) {
|
|
987
|
+
suffixStart = nB - tail;
|
|
988
|
+
prevRects = prevHit.rects;
|
|
989
|
+
prevDelta = nA - nB;
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
cachedTextRuns.set(textNode, hit = {
|
|
993
|
+
styleKey,
|
|
994
|
+
text: textData,
|
|
995
|
+
rects: new Float64Array(textData.length * 5),
|
|
996
|
+
blockRect: void 0,
|
|
997
|
+
emojiText,
|
|
998
|
+
rawString,
|
|
999
|
+
clusters,
|
|
1000
|
+
bmp: false
|
|
1001
|
+
});
|
|
1002
|
+
syncSource = hit.rects;
|
|
1003
|
+
}
|
|
966
1004
|
} else {
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1005
|
+
emojiText = isEmojiCandidate(textData);
|
|
1006
|
+
clusters = glyphClusters(textData);
|
|
1007
|
+
rawString = typeof clusters === "string";
|
|
1008
|
+
}
|
|
1009
|
+
const rects = hit?.rects;
|
|
1010
|
+
let bmp = rawString;
|
|
1011
|
+
const clusterArr = rawString ? null : clusters;
|
|
1012
|
+
const totalItems = rawString ? textData.length : clusterArr.length;
|
|
1013
|
+
let pos = 0;
|
|
1014
|
+
let ci = -1;
|
|
1015
|
+
while (pos < totalItems) {
|
|
1016
|
+
ci++;
|
|
1017
|
+
let cluster;
|
|
1018
|
+
let step;
|
|
1019
|
+
let asciiCode = -1;
|
|
1020
|
+
if (rawString) {
|
|
1021
|
+
const c0 = textData.charCodeAt(pos);
|
|
1022
|
+
if (!shown && (c0 === 32 || c0 >= 9 && c0 <= 13)) {
|
|
1023
|
+
if (!gap || keepsSpaces) gap += space;
|
|
1024
|
+
afterSpace = true;
|
|
1025
|
+
hasMarkAnchor = hasKernPrevious = false;
|
|
1026
|
+
previousCharacter = "";
|
|
1027
|
+
pos++;
|
|
1028
|
+
utf16Offset++;
|
|
1029
|
+
continue;
|
|
1030
|
+
}
|
|
1031
|
+
if (c0 >= 33 && c0 <= 126) {
|
|
1032
|
+
step = 1;
|
|
1033
|
+
cluster = SINGLE_CHAR[c0];
|
|
1034
|
+
asciiCode = c0;
|
|
1035
|
+
} else if (c0 >= 55296 && c0 <= 56319 && pos + 1 < totalItems && textData.charCodeAt(pos + 1) >= 56320 && textData.charCodeAt(pos + 1) <= 57343) {
|
|
1036
|
+
step = 2;
|
|
1037
|
+
bmp = false;
|
|
1038
|
+
cluster = textData.slice(pos, pos + 2);
|
|
1039
|
+
} else {
|
|
1040
|
+
step = 1;
|
|
1041
|
+
cluster = c0 < 128 ? SINGLE_CHAR[c0] : textData[pos];
|
|
1042
|
+
}
|
|
1043
|
+
} else {
|
|
1044
|
+
step = 1;
|
|
1045
|
+
cluster = clusterArr[pos];
|
|
1046
|
+
}
|
|
1047
|
+
pos += step;
|
|
1048
|
+
const share = shown ? shown[clusterIndex++] : cluster;
|
|
1049
|
+
const nextOffset = utf16Offset + cluster.length;
|
|
1050
|
+
if (asciiCode < 0 || shown) {
|
|
1051
|
+
const sc = share.length === 1 ? share.charCodeAt(0) : -1;
|
|
1052
|
+
if (sc === 32 || sc === 160 || sc >= 9 && (sc <= 13 || sc > 126 && /^\s$/u.test(share))) {
|
|
1053
|
+
if (sc === 32 || sc <= 13 || sc !== 8199 && sc !== 8239 && sc !== 65279) {
|
|
1054
|
+
if (!gap || keepsSpaces) gap += space;
|
|
1055
|
+
if (sc !== 160) afterSpace = true;
|
|
1056
|
+
}
|
|
1057
|
+
hasMarkAnchor = hasKernPrevious = false;
|
|
1058
|
+
previousCharacter = "";
|
|
1059
|
+
utf16Offset = nextOffset;
|
|
1060
|
+
continue;
|
|
1061
|
+
}
|
|
1062
|
+
if (!share) {
|
|
1063
|
+
hasKernPrevious = false;
|
|
1064
|
+
utf16Offset = nextOffset;
|
|
1065
|
+
continue;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
let bLeft;
|
|
1069
|
+
let bTop;
|
|
1070
|
+
let bBottom;
|
|
1071
|
+
let bWidth;
|
|
1072
|
+
let bHeight;
|
|
1073
|
+
const boxOff = ci * 5;
|
|
1074
|
+
if (rects && synced) {
|
|
1075
|
+
const sOff = (ci + syncDelta) * 5;
|
|
1076
|
+
const rLeft = syncSource[sOff];
|
|
1077
|
+
const rTop = syncSource[sOff + 1];
|
|
1078
|
+
const rBottom = syncSource[sOff + 2];
|
|
1079
|
+
bLeft = rLeft + rootLeft;
|
|
1080
|
+
bTop = rTop + rootTop;
|
|
1081
|
+
bBottom = rBottom + rootTop;
|
|
1082
|
+
bWidth = syncSource[sOff + 3];
|
|
1083
|
+
bHeight = syncSource[sOff + 4];
|
|
1084
|
+
if (syncSource !== rects) {
|
|
1085
|
+
rects[boxOff] = rLeft;
|
|
1086
|
+
rects[boxOff + 1] = rTop;
|
|
1087
|
+
rects[boxOff + 2] = rBottom;
|
|
1088
|
+
rects[boxOff + 3] = bWidth;
|
|
1089
|
+
rects[boxOff + 4] = bHeight;
|
|
1090
|
+
}
|
|
1091
|
+
} else {
|
|
1092
|
+
range.setEnd(textNode, nextOffset);
|
|
1093
|
+
range.setStart(textNode, utf16Offset);
|
|
1094
|
+
const d = range.getBoundingClientRect();
|
|
1095
|
+
bLeft = d.left;
|
|
1096
|
+
bTop = d.top;
|
|
1097
|
+
bBottom = d.bottom;
|
|
1098
|
+
bWidth = d.width;
|
|
1099
|
+
bHeight = d.height;
|
|
1100
|
+
if (rects) {
|
|
1101
|
+
const rLeft = bLeft - rootLeft;
|
|
1102
|
+
const rTop = bTop - rootTop;
|
|
1103
|
+
const rBottom = bBottom - rootTop;
|
|
1104
|
+
if (canSync && rects[boxOff] === rLeft && rects[boxOff + 1] === rTop && rects[boxOff + 3] === bWidth && rects[boxOff + 4] === bHeight) {
|
|
977
1105
|
synced = true;
|
|
978
|
-
syncSource =
|
|
979
|
-
syncDelta =
|
|
1106
|
+
syncSource = rects;
|
|
1107
|
+
syncDelta = 0;
|
|
1108
|
+
} else {
|
|
1109
|
+
rects[boxOff] = rLeft;
|
|
1110
|
+
rects[boxOff + 1] = rTop;
|
|
1111
|
+
rects[boxOff + 2] = rBottom;
|
|
1112
|
+
rects[boxOff + 3] = bWidth;
|
|
1113
|
+
rects[boxOff + 4] = bHeight;
|
|
1114
|
+
if (prevRects && pos - 1 > suffixStart + 1 && ci === pos - 1) {
|
|
1115
|
+
const prevGlyph = glyphs[glyphs.length - 1];
|
|
1116
|
+
if (prevGlyph?.block === blockIndex && prevGlyph.lineBottom !== (rootBottom - bBottom) * invScale || align === "left" && !rtl) {
|
|
1117
|
+
const pOff = (ci + prevDelta) * 5;
|
|
1118
|
+
if (pOff >= 0 && prevRects[pOff] === rLeft && prevRects[pOff + 1] === rTop && prevRects[pOff + 3] === bWidth && prevRects[pOff + 4] === bHeight) {
|
|
1119
|
+
synced = true;
|
|
1120
|
+
syncSource = prevRects;
|
|
1121
|
+
syncDelta = prevDelta;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
980
1125
|
}
|
|
981
1126
|
}
|
|
982
1127
|
}
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1128
|
+
utf16Offset = nextOffset;
|
|
1129
|
+
if (measuresBaselines && (!gridDone || trackBlockGrid)) trackLayoutGrid(bLeft, bWidth);
|
|
1130
|
+
const parts = !shown || share === cluster ? void 0 : expansionBoxes(share, bLeft, bTop, bBottom, bWidth, bHeight, font);
|
|
1131
|
+
const partLen = parts ? parts.length : 1;
|
|
1132
|
+
for (let part = 0; part < partLen; part++) {
|
|
1133
|
+
let pLeft = bLeft;
|
|
1134
|
+
let pTop = bTop;
|
|
1135
|
+
let pBottom = bBottom;
|
|
1136
|
+
let pWidth = bWidth;
|
|
1137
|
+
let pHeight = bHeight;
|
|
1138
|
+
let character = share;
|
|
1139
|
+
let partAscii = shown ? -1 : asciiCode;
|
|
1140
|
+
if (parts) {
|
|
1141
|
+
const box = parts[part];
|
|
1142
|
+
pLeft = box.left;
|
|
1143
|
+
pTop = box.top;
|
|
1144
|
+
pBottom = box.bottom;
|
|
1145
|
+
pWidth = box.width;
|
|
1146
|
+
pHeight = box.height;
|
|
1147
|
+
character = box.c;
|
|
1148
|
+
partAscii = -1;
|
|
1149
|
+
}
|
|
1150
|
+
if (pWidth <= 0 || pHeight <= 0) {
|
|
1151
|
+
const previous = glyphs[glyphs.length - 1];
|
|
1152
|
+
hasKernPrevious = false;
|
|
1153
|
+
if (!hasMarkAnchor || !previous || !/^\p{M}/u.test(character)) continue;
|
|
1154
|
+
const key = requestKey(font, keys, character, asciiKeys);
|
|
1155
|
+
const sequence = nextSequence(markAnchorLineKey);
|
|
1156
|
+
if (options.pixelSnap) paintLines[glyphs.length] = paintLines[glyphs.length - 1];
|
|
1157
|
+
glyphs.push({
|
|
1158
|
+
glyphKey: key,
|
|
1159
|
+
fontSize,
|
|
1160
|
+
originX: previous.originX + previous.advance,
|
|
1161
|
+
lineBottom: previous.lineBottom,
|
|
1162
|
+
advance: 0,
|
|
1163
|
+
...options.rtlReflow ? { decorationWidth: 0 } : {},
|
|
1164
|
+
block: blockIndex,
|
|
1165
|
+
breakBefore: "none",
|
|
1166
|
+
clip,
|
|
1167
|
+
color,
|
|
1168
|
+
sequence,
|
|
1169
|
+
z
|
|
1170
|
+
});
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
if (pLeft < minLeft) minLeft = pLeft;
|
|
1174
|
+
if (pLeft + pWidth > maxRight) maxRight = pLeft + pWidth;
|
|
1175
|
+
if (pTop < minTop) minTop = pTop;
|
|
1176
|
+
if (pBottom > maxBottom) maxBottom = pBottom;
|
|
1177
|
+
const key = (partAscii >= 0 ? asciiKeys[partAscii] : void 0) ?? requestKey(font, keys, character, asciiKeys);
|
|
1178
|
+
const previous = glyphs[glyphs.length - 1];
|
|
1179
|
+
const sameBlock = previous?.block === blockIndex;
|
|
1180
|
+
const emoji = partAscii < 0 && emojiText && isEmojiCandidate(character);
|
|
1181
|
+
const sharesLine = sameBlock && hasPrevBounds && Math.min(pBottom, prevBottom) - Math.max(pTop, prevTop) > Math.min(pHeight, prevHeight) * .5;
|
|
1182
|
+
const sameEmojiLine = sharesLine && (emoji || previousEmoji);
|
|
1183
|
+
const lineKey = sameEmojiLine ? markAnchorLineKey : Math.round(pTop * 4);
|
|
1184
|
+
const sequence = nextSequence(lineKey);
|
|
1185
|
+
const lineBottom = sameEmojiLine ? previous.lineBottom : (rootBottom - pBottom) * invScale;
|
|
1186
|
+
const lineChanged = sameBlock && previous.lineBottom !== lineBottom;
|
|
1187
|
+
let kernShift = 0;
|
|
1188
|
+
let kernCarry = 0;
|
|
1189
|
+
let charWidth = -1;
|
|
1190
|
+
if (hasKernPrevious && measuresKerning && !parts && !emoji && !lineChanged) {
|
|
1191
|
+
const firstWidth = kernPrevWidth >= 0 ? kernPrevWidth : canvasWidth(layoutFont, widths, asciiWidths, kernPrevChar);
|
|
1192
|
+
const shownKern = pLeft - kernPrevLeft - letterSpacing - firstWidth - kernPrevCarry;
|
|
1193
|
+
if (Math.abs(shownKern) > (nativeBrowser ? .02 : .0025)) {
|
|
1194
|
+
if (partAscii >= 0) {
|
|
1195
|
+
charWidth = asciiWidths[partAscii];
|
|
1196
|
+
if (charWidth < 0) charWidth = asciiWidths[partAscii] = measureCanvasWidth(layoutFont, character);
|
|
1197
|
+
} else charWidth = canvasWidth(layoutFont, widths, asciiWidths, character);
|
|
1198
|
+
let pairTotal;
|
|
1199
|
+
if (kernPrevCode >= 0 && partAscii >= 0) {
|
|
1200
|
+
const pairKey = kernPrevCode << 7 | partAscii;
|
|
1201
|
+
let cachedPair = pairWidths.get(pairKey);
|
|
1202
|
+
if (cachedPair === void 0) pairWidths.set(pairKey, cachedPair = measureCanvasWidth(layoutFont, kernPrevChar + character));
|
|
1203
|
+
pairTotal = cachedPair;
|
|
1204
|
+
} else pairTotal = canvasPairWidth(layoutFont, widths, pairWidths, kernPrevChar, character);
|
|
1205
|
+
const pair = pairTotal - firstWidth - charWidth;
|
|
1206
|
+
if (Math.abs(pair) > .01 && Math.abs(shownKern - pair / 2) <= Math.min(.25, Math.abs(pair) / 4)) {
|
|
1207
|
+
kernCarry = pair - shownKern;
|
|
1208
|
+
kernShift = kernCarry;
|
|
1209
|
+
}
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
const originX = (pLeft - rootLeft + kernShift) * invScale;
|
|
1213
|
+
boxHeight ||= pHeight;
|
|
1214
|
+
if (options.pixelSnap) {
|
|
1215
|
+
if (sharesLine) lineTops[lineTops.length - 1] = Math.min(lineTops[lineTops.length - 1], pTop);
|
|
1216
|
+
else lineTops.push(pTop);
|
|
1217
|
+
paintLines[glyphs.length] = lineTops.length - 1;
|
|
1218
|
+
}
|
|
1219
|
+
hasPrevBounds = true;
|
|
1220
|
+
prevTop = pTop;
|
|
1221
|
+
prevBottom = pBottom;
|
|
1222
|
+
prevHeight = pHeight;
|
|
1223
|
+
previousEmoji = emoji;
|
|
1224
|
+
const isCjkSoft = options.cjkLineBreaking === true && canBreakCjk(previousCharacter, character);
|
|
1225
|
+
if (sameBlock && !lineChanged && previous.shapeGroup === void 0) {
|
|
1226
|
+
if (gap || afterSpace || isCjkSoft) previous.decorationWidth ??= previous.advance;
|
|
1227
|
+
previous.advance = originX - previous.originX;
|
|
1228
|
+
}
|
|
1229
|
+
const soft = !sameBlock || isCjkSoft || afterSpace && !(forced && lineChanged);
|
|
1230
|
+
let lone;
|
|
1231
|
+
if (measuresKerning && !parts && !emoji) {
|
|
1232
|
+
if (charWidth < 0) {
|
|
1233
|
+
if (partAscii >= 0) {
|
|
1234
|
+
charWidth = asciiWidths[partAscii];
|
|
1235
|
+
if (charWidth < 0) charWidth = asciiWidths[partAscii] = measureCanvasWidth(layoutFont, character);
|
|
1236
|
+
} else charWidth = canvasWidth(layoutFont, widths, asciiWidths, character);
|
|
1237
|
+
}
|
|
1238
|
+
lone = charWidth + letterSpacing;
|
|
1239
|
+
} else lone = pWidth;
|
|
1240
|
+
const glyph = {
|
|
1241
|
+
glyphKey: key,
|
|
1242
|
+
fontSize,
|
|
1243
|
+
originX,
|
|
1244
|
+
lineBottom,
|
|
1245
|
+
advance: (Math.abs(lone - pWidth) < .04 ? lone : pWidth) * invScale,
|
|
1246
|
+
block: blockIndex,
|
|
1247
|
+
breakBefore: soft ? "soft" : lineChanged ? "hard" : "none",
|
|
1248
|
+
clip,
|
|
1249
|
+
color,
|
|
1250
|
+
sequence,
|
|
1251
|
+
z
|
|
1252
|
+
};
|
|
1253
|
+
if (isCjkSoft) glyph.gapBefore = 0;
|
|
1254
|
+
else if (gap && (justified ? soft || !lineChanged : soft && lineChanged && previous.shapeGroup === void 0)) glyph.gapBefore = gap;
|
|
1255
|
+
if (decorations.length || options.rtlReflow) {
|
|
1256
|
+
glyph.decorations = decorations;
|
|
1257
|
+
glyph.decorationWidth = glyph.advance;
|
|
1258
|
+
}
|
|
1259
|
+
glyphs.push(glyph);
|
|
1260
|
+
gap = 0;
|
|
1261
|
+
forced = false;
|
|
1262
|
+
if (parts || emoji) hasKernPrevious = false;
|
|
1263
|
+
else {
|
|
1264
|
+
hasKernPrevious = true;
|
|
1265
|
+
kernPrevChar = character;
|
|
1266
|
+
kernPrevCode = partAscii;
|
|
1267
|
+
kernPrevLeft = pLeft;
|
|
1268
|
+
kernPrevWidth = charWidth;
|
|
1269
|
+
kernPrevCarry = kernCarry;
|
|
1270
|
+
}
|
|
1271
|
+
afterSpace = false;
|
|
1272
|
+
if (options.cjkLineBreaking) previousCharacter = character;
|
|
1273
|
+
markAnchorLineKey = lineKey;
|
|
1274
|
+
hasMarkAnchor = true;
|
|
1053
1275
|
}
|
|
1054
1276
|
}
|
|
1277
|
+
if (hit) {
|
|
1278
|
+
hit.blockRect = relBlockRect;
|
|
1279
|
+
hit.bmp = bmp;
|
|
1280
|
+
}
|
|
1281
|
+
if (measuresBaselines && boxHeight > 0) {
|
|
1282
|
+
templateBoxHeight = boxHeight;
|
|
1283
|
+
textRuns.push([
|
|
1284
|
+
font,
|
|
1285
|
+
runStart,
|
|
1286
|
+
glyphs.length
|
|
1287
|
+
]);
|
|
1288
|
+
if (!boxHeights.has(font)) boxHeights.set(font, boxHeight);
|
|
1289
|
+
}
|
|
1055
1290
|
}
|
|
1056
|
-
const originX = (pLeft - rootLeft + kernShift) * invScale;
|
|
1057
|
-
boxHeight ||= pHeight;
|
|
1058
|
-
if (options.pixelSnap) {
|
|
1059
|
-
if (sharesLine) lineTops[lineTops.length - 1] = Math.min(lineTops[lineTops.length - 1], pTop);
|
|
1060
|
-
else lineTops.push(pTop);
|
|
1061
|
-
paintLines[glyphs.length] = lineTops.length - 1;
|
|
1062
|
-
}
|
|
1063
|
-
hasPrevBounds = true;
|
|
1064
|
-
prevTop = pTop;
|
|
1065
|
-
prevBottom = pBottom;
|
|
1066
|
-
prevHeight = pHeight;
|
|
1067
|
-
previousEmoji = emoji;
|
|
1068
|
-
const isCjkSoft = options.cjkLineBreaking === true && canBreakCjk(previousCharacter, character);
|
|
1069
|
-
if (sameBlock && !lineChanged && previous.shapeGroup === void 0) {
|
|
1070
|
-
if (gap || afterSpace || isCjkSoft) previous.decorationWidth ??= previous.advance;
|
|
1071
|
-
previous.advance = originX - previous.originX;
|
|
1072
|
-
}
|
|
1073
|
-
const soft = !sameBlock || isCjkSoft || afterSpace && !(forced && lineChanged);
|
|
1074
|
-
const lone = measuresKerning && !parts && !emoji ? (charWidth >= 0 ? charWidth : charWidth = canvasWidth(layoutFont, widths, asciiWidths, character)) + letterSpacing : pWidth;
|
|
1075
|
-
const glyph = {
|
|
1076
|
-
glyphKey: key,
|
|
1077
|
-
fontSize,
|
|
1078
|
-
originX,
|
|
1079
|
-
lineBottom,
|
|
1080
|
-
advance: (Math.abs(lone - pWidth) < .04 ? lone : pWidth) * invScale,
|
|
1081
|
-
block: blockIndex,
|
|
1082
|
-
breakBefore: soft ? "soft" : lineChanged ? "hard" : "none",
|
|
1083
|
-
clip,
|
|
1084
|
-
color,
|
|
1085
|
-
sequence,
|
|
1086
|
-
z
|
|
1087
|
-
};
|
|
1088
|
-
if (isCjkSoft) glyph.gapBefore = 0;
|
|
1089
|
-
else if (gap && (justified ? soft || !lineChanged : soft && lineChanged && previous.shapeGroup === void 0)) glyph.gapBefore = gap;
|
|
1090
|
-
if (decorations.length || options.rtlReflow) {
|
|
1091
|
-
glyph.decorations = decorations;
|
|
1092
|
-
glyph.decorationWidth = glyph.advance;
|
|
1093
|
-
}
|
|
1094
|
-
glyphs.push(glyph);
|
|
1095
|
-
gap = 0;
|
|
1096
|
-
forced = false;
|
|
1097
|
-
if (parts || emoji) hasKernPrevious = false;
|
|
1098
|
-
else {
|
|
1099
|
-
hasKernPrevious = true;
|
|
1100
|
-
kernPrevChar = character;
|
|
1101
|
-
kernPrevLeft = pLeft;
|
|
1102
|
-
kernPrevWidth = charWidth;
|
|
1103
|
-
kernPrevCarry = kernCarry;
|
|
1104
|
-
}
|
|
1105
|
-
afterSpace = false;
|
|
1106
|
-
if (options.cjkLineBreaking) previousCharacter = character;
|
|
1107
|
-
markAnchorLineKey = lineKey;
|
|
1108
|
-
hasMarkAnchor = true;
|
|
1109
1291
|
}
|
|
1110
1292
|
}
|
|
1111
|
-
if (
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1293
|
+
if (walker) node = walker.nextNode();
|
|
1294
|
+
else if (nextNode) node = nextNode;
|
|
1295
|
+
else if (!hasElementChild) node = node.nextSibling;
|
|
1296
|
+
else {
|
|
1297
|
+
let back = node;
|
|
1298
|
+
while (back && back !== block) {
|
|
1299
|
+
const sib = back.nextSibling;
|
|
1300
|
+
if (sib) {
|
|
1301
|
+
node = sib;
|
|
1302
|
+
break;
|
|
1303
|
+
}
|
|
1304
|
+
back = back.parentNode;
|
|
1305
|
+
}
|
|
1306
|
+
if (!back || back === block) node = null;
|
|
1123
1307
|
}
|
|
1124
1308
|
}
|
|
1125
1309
|
lineCount += sequences.size;
|
|
@@ -1166,42 +1350,53 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1166
1350
|
} : align !== natural ? { textAlign: align } : {}
|
|
1167
1351
|
};
|
|
1168
1352
|
}
|
|
1169
|
-
if (
|
|
1170
|
-
const tGlyphs = [];
|
|
1353
|
+
if (tmplReady && templateTextNode && !svg) {
|
|
1171
1354
|
const seen = /* @__PURE__ */ new Set();
|
|
1172
|
-
const
|
|
1355
|
+
const tReq = [];
|
|
1173
1356
|
for (let i = blockStart; i < glyphs.length; i++) {
|
|
1174
|
-
const
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
const req = requests.get(g.glyphKey);
|
|
1357
|
+
const key = glyphs[i].glyphKey;
|
|
1358
|
+
if (!seen.has(key)) {
|
|
1359
|
+
const req = requests.get(key);
|
|
1178
1360
|
if (req) {
|
|
1179
|
-
seen.add(
|
|
1180
|
-
|
|
1361
|
+
seen.add(key);
|
|
1362
|
+
tReq.push(req);
|
|
1181
1363
|
}
|
|
1182
1364
|
}
|
|
1183
1365
|
}
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1366
|
+
pendingTemplates.push([
|
|
1367
|
+
block,
|
|
1368
|
+
{
|
|
1369
|
+
n: templateTextNode,
|
|
1370
|
+
s: templateText,
|
|
1371
|
+
r: relBlockRect,
|
|
1372
|
+
p: snapTmplPrefix,
|
|
1373
|
+
sl: tmplScrollLeft,
|
|
1374
|
+
st: tmplScrollTop,
|
|
1375
|
+
bi: blockIndex,
|
|
1376
|
+
it: tmplInlineTk,
|
|
1377
|
+
bt: tmplBlkTk,
|
|
1378
|
+
g: EMPTY_GLYPHS,
|
|
1379
|
+
req: tReq,
|
|
1380
|
+
oc: blockOffCss,
|
|
1381
|
+
od: blockOffDev,
|
|
1382
|
+
bh: templateBoxHeight,
|
|
1383
|
+
l: lineCount - lineCountBefore,
|
|
1384
|
+
c: [
|
|
1385
|
+
clip[0],
|
|
1386
|
+
clip[1],
|
|
1387
|
+
clip[2],
|
|
1388
|
+
clip[3]
|
|
1389
|
+
],
|
|
1390
|
+
bl: blockLayouts[blockIndex],
|
|
1391
|
+
bo: void 0
|
|
1392
|
+
},
|
|
1393
|
+
blockStart,
|
|
1394
|
+
glyphs.length
|
|
1395
|
+
]);
|
|
1202
1396
|
}
|
|
1203
1397
|
}
|
|
1204
|
-
|
|
1398
|
+
trackBlockGrid = false;
|
|
1399
|
+
if (textRuns.length > 0 || hitRuns.length > 0) {
|
|
1205
1400
|
const scales = layoutScales();
|
|
1206
1401
|
const probe = scales.length > 0 ? ensureFontProbe() : null;
|
|
1207
1402
|
if (probe) {
|
|
@@ -1209,10 +1404,42 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1209
1404
|
layoutScale = scale;
|
|
1210
1405
|
for (const [font, from, to] of textRuns) {
|
|
1211
1406
|
const descent = descents.get(font);
|
|
1212
|
-
if (descent !== void 0)
|
|
1407
|
+
if (descent !== void 0) {
|
|
1408
|
+
const bo = descent * invScale;
|
|
1409
|
+
for (let index = from; index < to; index++) glyphs[index].baselineOffset = bo;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
for (const [font, from, to, oldBo] of hitRuns) {
|
|
1413
|
+
const descent = descents.get(font);
|
|
1414
|
+
const newBo = descent !== void 0 ? descent * invScale : void 0;
|
|
1415
|
+
if (newBo !== oldBo) for (let index = from; index < to; index++) {
|
|
1416
|
+
const clone = { ...glyphs[index] };
|
|
1417
|
+
if (newBo !== void 0) clone.baselineOffset = newBo;
|
|
1418
|
+
else delete clone.baselineOffset;
|
|
1419
|
+
glyphs[index] = clone;
|
|
1420
|
+
}
|
|
1213
1421
|
}
|
|
1214
1422
|
}
|
|
1215
1423
|
}
|
|
1424
|
+
const cloneForTemplate = !isImmutableCapture();
|
|
1425
|
+
for (const [el, tmpl, from, to] of pendingTemplates) {
|
|
1426
|
+
tmpl.bo = glyphs[from]?.baselineOffset;
|
|
1427
|
+
const slice = glyphs.slice(from, to);
|
|
1428
|
+
if (cloneForTemplate) {
|
|
1429
|
+
const c = tmpl.c;
|
|
1430
|
+
const copyClip = [
|
|
1431
|
+
c[0],
|
|
1432
|
+
c[1],
|
|
1433
|
+
c[2],
|
|
1434
|
+
c[3]
|
|
1435
|
+
];
|
|
1436
|
+
tmpl.g = slice.map((g) => ({
|
|
1437
|
+
...g,
|
|
1438
|
+
clip: copyClip
|
|
1439
|
+
}));
|
|
1440
|
+
} else tmpl.g = slice;
|
|
1441
|
+
cachedBlockTemplates.set(el, tmpl);
|
|
1442
|
+
}
|
|
1216
1443
|
let snapGrid;
|
|
1217
1444
|
if (options.pixelSnap) {
|
|
1218
1445
|
const rowScale = layoutScale ?? deviceScale;
|
|
@@ -1225,15 +1452,14 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1225
1452
|
snapGlyph(glyph, shaping ? 0 : rootLeft * 4 * deviceScale + glyph.originX * snapGrid[0], rootBottom * rowScale - glyph.lineBottom * snapGrid[1], snapGrid, top - Math.floor(top + .5 + 1e-6));
|
|
1226
1453
|
}
|
|
1227
1454
|
}
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
if (isIgnored(element) || displayNone(element)) continue;
|
|
1455
|
+
const captureRect = (element) => {
|
|
1456
|
+
if (isIgnored(element) || displayNone(element)) return;
|
|
1231
1457
|
const style = styleOf(element);
|
|
1232
|
-
if (isHidden(style))
|
|
1458
|
+
if (isHidden(style)) return;
|
|
1233
1459
|
const color = cssColorToSrgba(document, style.backgroundColor, opacityOf(element));
|
|
1234
|
-
if (color[3] <= 0)
|
|
1460
|
+
if (color[3] <= 0) return;
|
|
1235
1461
|
const bounds = element === root ? rootRect : element.getBoundingClientRect();
|
|
1236
|
-
if (bounds.width <= 0 || bounds.height <= 0)
|
|
1462
|
+
if (bounds.width <= 0 || bounds.height <= 0) return;
|
|
1237
1463
|
const zDefault = element === root ? options.panelDepth ?? -1 : options.rectDepth ?? 0;
|
|
1238
1464
|
const rawRad = style.borderTopLeftRadius.split(/[\s/]/, 1)[0] ?? "";
|
|
1239
1465
|
rects.push({
|
|
@@ -1243,7 +1469,10 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1243
1469
|
z: depthOf(element, zDefault),
|
|
1244
1470
|
receiveShadow: element.hasAttribute("data-text-receive-shadow") || element.hasAttribute("data-sdf-receive-shadow")
|
|
1245
1471
|
});
|
|
1246
|
-
}
|
|
1472
|
+
};
|
|
1473
|
+
if (options.includeRootBackground !== false || root.matches(rectSelector)) captureRect(root);
|
|
1474
|
+
const matchedRects = root.querySelectorAll(rectSelector);
|
|
1475
|
+
for (let i = 0, len = matchedRects.length; i < len; i++) captureRect(matchedRects[i]);
|
|
1247
1476
|
for (const character of glyphClusters(options.extraGlyphs ?? "")) {
|
|
1248
1477
|
if (/^\s$/u.test(character)) continue;
|
|
1249
1478
|
const emoji = isEmojiCandidate(character);
|
|
@@ -1253,9 +1482,18 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1253
1482
|
}
|
|
1254
1483
|
}
|
|
1255
1484
|
svgRunner?.finish();
|
|
1256
|
-
const requestList =
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1485
|
+
const requestList = Array.from(requests.values()).sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
1486
|
+
const requestKeys = new Array(requestList.length);
|
|
1487
|
+
for (let i = 0; i < requestList.length; i++) requestKeys[i] = requestList[i].key;
|
|
1488
|
+
const atlasSignature = requestKeys.join("");
|
|
1489
|
+
let hasRunMotion = Boolean(shaping);
|
|
1490
|
+
if (!hasRunMotion && svg) {
|
|
1491
|
+
for (const glyph of glyphs) if (glyph.motionOrigin !== void 0) {
|
|
1492
|
+
hasRunMotion = true;
|
|
1493
|
+
break;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const snapshot = {
|
|
1259
1497
|
...shaping ? { textShaping: "browser" } : {},
|
|
1260
1498
|
width: rootRect.width * invScale,
|
|
1261
1499
|
height: rootRect.height * invScale,
|
|
@@ -1265,8 +1503,12 @@ function collectDomSnapshotSync(root, options, pretext, shaping, svg) {
|
|
|
1265
1503
|
requests: requestList,
|
|
1266
1504
|
atlasSignature,
|
|
1267
1505
|
lineCount,
|
|
1268
|
-
...snapGrid ? { snapGrid } : {}
|
|
1506
|
+
...snapGrid ? { snapGrid } : {},
|
|
1507
|
+
...cssDropShadow ? { dropShadow: cssDropShadow } : {},
|
|
1508
|
+
...cssOutline ? { outline: cssOutline } : {}
|
|
1269
1509
|
};
|
|
1510
|
+
snapshotFlags.set(snapshot, (hasRunMotion ? 1 : 0) | 2 | (hasAnyDecorations ? 0 : 4));
|
|
1511
|
+
return snapshot;
|
|
1270
1512
|
}
|
|
1271
1513
|
export { collectDomSnapshot, physicalAlign };
|
|
1272
1514
|
|