ultra-text 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +224 -1002
- package/dist/assets/{cpuSdf.worker-xS57yQbP.js → cpuSdf.worker--X1Qpmdp.js} +136 -47
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +67 -25
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +3 -2
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +152 -40
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +100 -276
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +47 -241
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.js +103 -58
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +224 -284
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +75 -151
- package/dist/dom/DomSlug.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.js +27 -9
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +150 -48
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +369 -204
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +11 -3
- package/dist/slug/SlugMaterial.js +54 -10
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +16 -12
- package/dist/slug/coverage.js +194 -221
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +5 -1
- package/dist/slug/preprocessCore.js +118 -87
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +90 -44
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +75 -40
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.js +166 -193
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +5 -1453
- package/dist/slug.d.ts +1 -1
- package/dist/slug.js +6 -6
- package/dist/text/GlyphTextMaterial.d.ts +1 -1
- package/dist/text/GlyphTextMaterial.js +5 -5
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.js +7 -5
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/vanilla.d.ts +13 -363
- package/dist/vanilla.js +6 -1473
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +113 -40
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +1 -0
- package/dist/windfoil/preprocessCore.js +9 -4
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +3 -1
- package/dist/windfoil/runtime.js +62 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/storage.d.ts +60 -2
- package/dist/windfoil/storage.js +142 -6
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +167 -43
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +471 -175
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.js +59 -34
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +11 -11
- package/skills/ultra-text/references/three-tsl.md +2 -2
- package/skills/ultra-text/references/vanilla-webgpu.md +3 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -30,16 +30,27 @@ function push(value) {
|
|
|
30
30
|
words[count++] = value;
|
|
31
31
|
}
|
|
32
32
|
function walkString(value) {
|
|
33
|
-
|
|
33
|
+
let id = strings.get(value);
|
|
34
34
|
if (id === void 0) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
id = strings.size;
|
|
36
|
+
strings.set(value, id);
|
|
37
|
+
const len = value.length;
|
|
38
|
+
if (len < 128) {
|
|
39
|
+
if (count + 2 + len > WORDS) flush();
|
|
40
|
+
words[count++] = STRING;
|
|
41
|
+
words[count++] = len;
|
|
42
|
+
for (let index = 0; index < len; index++) words[count++] = value.charCodeAt(index);
|
|
43
|
+
} else {
|
|
44
|
+
push(STRING);
|
|
45
|
+
push(len);
|
|
46
|
+
for (let index = 0; index < len; index++) push(value.charCodeAt(index));
|
|
47
|
+
}
|
|
39
48
|
} else {
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
if (count > 2046) flush();
|
|
50
|
+
words[count++] = STRING_ID;
|
|
51
|
+
words[count++] = id;
|
|
42
52
|
}
|
|
53
|
+
return id;
|
|
43
54
|
}
|
|
44
55
|
function walk(value) {
|
|
45
56
|
if (typeof value === "number") {
|
|
@@ -72,37 +83,73 @@ function layoutSignatureOf(snapshot) {
|
|
|
72
83
|
push(glyphs.length);
|
|
73
84
|
let prevKey;
|
|
74
85
|
let prevKeyId = -1;
|
|
86
|
+
let prevClip;
|
|
87
|
+
let pClip0 = 0;
|
|
88
|
+
let pClip1 = 0;
|
|
89
|
+
let pClip2 = 0;
|
|
90
|
+
let pClip3 = 0;
|
|
91
|
+
let prevColor;
|
|
92
|
+
let pColor0 = 0;
|
|
93
|
+
let pColor1 = 0;
|
|
94
|
+
let pColor2 = 0;
|
|
95
|
+
let pColor3 = 0;
|
|
75
96
|
for (let index = 0, length = glyphs.length; index < length; index++) {
|
|
76
97
|
const g = glyphs[index];
|
|
77
98
|
const { clip, color } = g;
|
|
78
99
|
const glyphKey = g.glyphKey;
|
|
79
100
|
if (glyphKey === prevKey) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
prevKeyId = id;
|
|
101
|
+
if (count > 2046) flush();
|
|
102
|
+
words[count++] = STRING_ID;
|
|
103
|
+
words[count++] = prevKeyId;
|
|
104
|
+
} else prevKeyId = walkString(prevKey = glyphKey);
|
|
105
|
+
let sameClip = index > 0 && clip === prevClip;
|
|
106
|
+
let c0 = 0;
|
|
107
|
+
let c1 = 0;
|
|
108
|
+
let c2 = 0;
|
|
109
|
+
let c3 = 0;
|
|
110
|
+
if (!sameClip) {
|
|
111
|
+
c0 = clip[0] + 0;
|
|
112
|
+
c1 = clip[1] + 0;
|
|
113
|
+
c2 = clip[2] + 0;
|
|
114
|
+
c3 = clip[3] + 0;
|
|
115
|
+
sameClip = index > 0 && c0 === pClip0 && c1 === pClip1 && c2 === pClip2 && c3 === pClip3;
|
|
96
116
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
117
|
+
let sameColor = index > 0 && color === prevColor;
|
|
118
|
+
let col0 = 0;
|
|
119
|
+
let col1 = 0;
|
|
120
|
+
let col2 = 0;
|
|
121
|
+
let col3 = 0;
|
|
122
|
+
if (!sameColor) {
|
|
123
|
+
col0 = color[0] + 0;
|
|
124
|
+
col1 = color[1] + 0;
|
|
125
|
+
col2 = color[2] + 0;
|
|
126
|
+
col3 = color[3] + 0;
|
|
127
|
+
sameColor = index > 0 && col0 === pColor0 && col1 === pColor1 && col2 === pColor2 && col3 === pColor3;
|
|
104
128
|
}
|
|
105
|
-
|
|
129
|
+
const breakBefore = g.breakBefore;
|
|
130
|
+
let flags = breakBefore === "none" ? 0 : breakBefore === "soft" ? 1 : breakBefore === "hard" ? 2 : 3;
|
|
131
|
+
if (sameClip) flags |= 4;
|
|
132
|
+
if (sameColor) flags |= 8;
|
|
133
|
+
const shapeGroup = g.shapeGroup;
|
|
134
|
+
const decorationWidth = g.decorationWidth;
|
|
135
|
+
const baselineOffset = g.baselineOffset;
|
|
136
|
+
const switchEm = g.switchEm;
|
|
137
|
+
const gapBefore = g.gapBefore;
|
|
138
|
+
const decorations = g.decorations;
|
|
139
|
+
const snap = g.snap;
|
|
140
|
+
const motionOrigin = g.motionOrigin;
|
|
141
|
+
if (shapeGroup !== void 0) flags |= 16;
|
|
142
|
+
if (decorationWidth !== void 0) flags |= 32;
|
|
143
|
+
if (baselineOffset !== void 0) flags |= 64;
|
|
144
|
+
if (switchEm !== void 0) flags |= 128;
|
|
145
|
+
if (gapBefore !== void 0) flags |= 256;
|
|
146
|
+
if (decorations !== void 0) flags |= 512;
|
|
147
|
+
if (snap !== void 0) flags |= 1024;
|
|
148
|
+
if (motionOrigin !== void 0) flags |= 2048;
|
|
149
|
+
if (count === WORDS) flush();
|
|
150
|
+
words[count++] = flags;
|
|
151
|
+
if ((flags & 3) === 3) walkString(breakBefore);
|
|
152
|
+
if (count > 2022) flush();
|
|
106
153
|
words[count++] = g.fontSize + 0;
|
|
107
154
|
words[count++] = g.originX + 0;
|
|
108
155
|
words[count++] = g.lineBottom + 0;
|
|
@@ -110,25 +157,80 @@ function layoutSignatureOf(snapshot) {
|
|
|
110
157
|
words[count++] = g.block + 0;
|
|
111
158
|
words[count++] = g.sequence + 0;
|
|
112
159
|
words[count++] = g.z + 0;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
if (
|
|
160
|
+
if (!sameClip) {
|
|
161
|
+
words[count++] = pClip0 = c0;
|
|
162
|
+
words[count++] = pClip1 = c1;
|
|
163
|
+
words[count++] = pClip2 = c2;
|
|
164
|
+
words[count++] = pClip3 = c3;
|
|
165
|
+
prevClip = clip;
|
|
166
|
+
}
|
|
167
|
+
if (!sameColor) {
|
|
168
|
+
words[count++] = pColor0 = col0;
|
|
169
|
+
words[count++] = pColor1 = col1;
|
|
170
|
+
words[count++] = pColor2 = col2;
|
|
171
|
+
words[count++] = pColor3 = col3;
|
|
172
|
+
prevColor = color;
|
|
173
|
+
}
|
|
174
|
+
if (shapeGroup !== void 0) words[count++] = shapeGroup + 0;
|
|
175
|
+
if (decorationWidth !== void 0) words[count++] = decorationWidth + 0;
|
|
176
|
+
if (baselineOffset !== void 0) words[count++] = baselineOffset + 0;
|
|
177
|
+
if (switchEm !== void 0) words[count++] = switchEm + 0;
|
|
178
|
+
if (gapBefore !== void 0) words[count++] = gapBefore + 0;
|
|
179
|
+
if (snap !== void 0) {
|
|
180
|
+
words[count++] = snap[0] + 0;
|
|
181
|
+
words[count++] = snap[1] + 0;
|
|
182
|
+
}
|
|
183
|
+
if (motionOrigin !== void 0) {
|
|
184
|
+
words[count++] = motionOrigin[0] + 0;
|
|
185
|
+
words[count++] = motionOrigin[1] + 0;
|
|
186
|
+
words[count++] = motionOrigin[2] + 0;
|
|
187
|
+
}
|
|
188
|
+
if (decorations !== void 0) walk(decorations);
|
|
189
|
+
}
|
|
190
|
+
const blocks = snapshot.blocks;
|
|
191
|
+
push(blocks.length);
|
|
192
|
+
for (let index = 0, length = blocks.length; index < length; index++) {
|
|
193
|
+
const b = blocks[index];
|
|
194
|
+
const bClip = b.clip;
|
|
195
|
+
if (count > 2038) flush();
|
|
196
|
+
words[count++] = b.left + 0;
|
|
197
|
+
words[count++] = b.firstBaseline + 0;
|
|
198
|
+
words[count++] = b.linePitch + 0;
|
|
199
|
+
words[count++] = b.width + 0;
|
|
200
|
+
words[count++] = bClip[0] + 0;
|
|
201
|
+
words[count++] = bClip[1] + 0;
|
|
202
|
+
words[count++] = bClip[2] + 0;
|
|
203
|
+
words[count++] = bClip[3] + 0;
|
|
204
|
+
let bFlags = 0;
|
|
205
|
+
if (b.direction !== void 0) bFlags |= 1;
|
|
206
|
+
if (b.textAlign !== void 0) bFlags |= 2;
|
|
207
|
+
if (b.textAlignLast !== void 0) bFlags |= 4;
|
|
208
|
+
words[count++] = bFlags;
|
|
209
|
+
if (b.direction !== void 0) walkString(b.direction);
|
|
210
|
+
if (b.textAlign !== void 0) walkString(b.textAlign);
|
|
211
|
+
if (b.textAlignLast !== void 0) walkString(b.textAlignLast);
|
|
212
|
+
}
|
|
213
|
+
const rects = snapshot.rects;
|
|
214
|
+
push(rects.length);
|
|
215
|
+
for (let index = 0, length = rects.length; index < length; index++) {
|
|
216
|
+
const r = rects[index];
|
|
217
|
+
const rr = r.rect;
|
|
218
|
+
const rc = r.color;
|
|
219
|
+
if (count > 2036) flush();
|
|
220
|
+
words[count++] = rr[0] + 0;
|
|
221
|
+
words[count++] = rr[1] + 0;
|
|
222
|
+
words[count++] = rr[2] + 0;
|
|
223
|
+
words[count++] = rr[3] + 0;
|
|
224
|
+
words[count++] = rc[0] + 0;
|
|
225
|
+
words[count++] = rc[1] + 0;
|
|
226
|
+
words[count++] = rc[2] + 0;
|
|
227
|
+
words[count++] = rc[3] + 0;
|
|
228
|
+
words[count++] = r.radius + 0;
|
|
229
|
+
words[count++] = r.z + 0;
|
|
230
|
+
words[count++] = r.receiveShadow ? TRUE : FALSE;
|
|
129
231
|
}
|
|
130
232
|
const root = snapshot;
|
|
131
|
-
for (const key in root) if (key !== "requests" && key !== "glyphs" && Object.hasOwn(root, key)) walk(root[key]);
|
|
233
|
+
for (const key in root) if (key !== "requests" && key !== "glyphs" && key !== "blocks" && key !== "rects" && Object.hasOwn(root, key)) walk(root[key]);
|
|
132
234
|
flush();
|
|
133
235
|
strings.clear();
|
|
134
236
|
return `${h1}:${h2}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layoutSignature.js","names":[],"sources":["../../src/dom/layoutSignature.ts"],"sourcesContent":["import type { DomLayoutSnapshot } from '../types.js'\n\n// The walk below writes the capture's values as float64 words into this small buffer, which\n// is hashed in one tight loop whenever it fills: about 2.5 times faster than mixing each value\n// through a closure, and nothing larger than these 16 KB stays allocated.\nconst WORDS = 2048\nconst words = new Float64Array(WORDS)\nconst bits = new Int32Array(words.buffer)\nconst strings = new Map<string, number>()\nlet count = 0\nlet h1 = 0\nlet h2 = 0\n\n// Markers for what is not a number; values this large never occur in a capture.\nconst STRING = -1e300\nconst STRING_ID = -2e300\nconst TRUE = -3e300\nconst FALSE = -4e300\nconst OPEN = -5e300\nconst CLOSE = -6e300\nconst OTHER = -7e300\n\nfunction flush(): void {\n let a = h1\n let b = h2\n for (let index = 0, end = count * 2; index < end; index++) {\n const value = bits[index]!\n a = Math.imul(a ^ value, 16777619)\n b = Math.imul(b ^ value, 1597334677)\n }\n h1 = a\n h2 = b\n count = 0\n}\n\nfunction push(value: number): void {\n if (count === WORDS) flush()\n words[count++] = value\n}\n\nfunction walkString(value: string): void {\n const id = strings.get(value)\n if (id === undefined) {\n strings.set(value, strings.size)\n push(STRING)\n push(value.length)\n for (let index = 0; index < value.length; index++) push(value.charCodeAt(index))\n } else {\n push(STRING_ID)\n push(id)\n }\n}\n\nfunction walk(value: unknown): void {\n // `+ 0` folds -0 into 0: both lay out the same.\n if (typeof value === 'number') {\n if (count === WORDS) flush()\n words[count++] = value + 0\n } else if (typeof value === 'string') walkString(value)\n else if (typeof value === 'boolean') push(value ? TRUE : FALSE)\n else if (typeof value === 'object' && value !== null) {\n push(OPEN)\n // Capture records have a fixed schema and stable declaration order.\n // Field names are identical across captures; only their values matter.\n if (Array.isArray(value)) {\n const length = value.length\n if (length > 0 && typeof value[0] === 'number') {\n if (count + length > WORDS) flush()\n for (let index = 0; index < length; index++) words[count++] = (value[index] as number) + 0\n } else {\n for (let index = 0; index < length; index++) walk(value[index])\n }\n } else {\n const record = value as Record<string, unknown>\n for (const key in record) {\n if (Object.hasOwn(record, key)) walk(record[key])\n }\n }\n push(CLOSE)\n } else push(OTHER)\n}\n\n/** Hash the capture directly, without allocating its much larger JSON string. */\nexport function layoutSignatureOf(snapshot: DomLayoutSnapshot): string {\n h1 = 0x811c9dc5\n h2 = 0x811c9dc5 ^ 0x5bd1e995\n count = 0\n strings.clear()\n const glyphs = snapshot.glyphs\n push(glyphs.length)\n let prevKey: string | undefined\n let prevKeyId = -1\n for (let index = 0, length = glyphs.length; index < length; index++) {\n const g = glyphs[index]!\n const { clip, color } = g\n const glyphKey = g.glyphKey\n if (glyphKey === prevKey) {\n push(STRING_ID)\n push(prevKeyId)\n } else {\n prevKey = glyphKey\n let id = strings.get(glyphKey)\n if (id === undefined) {\n id = strings.size\n strings.set(glyphKey, id)\n push(STRING)\n push(glyphKey.length)\n for (let i = 0; i < glyphKey.length; i++) push(glyphKey.charCodeAt(i))\n } else {\n push(STRING_ID)\n push(id)\n }\n prevKeyId = id\n }\n const breakBefore: string = g.breakBefore\n if (breakBefore === 'none') push(0)\n else if (breakBefore === 'soft') push(1)\n else if (breakBefore === 'hard') push(2)\n else {\n push(3)\n walkString(breakBefore)\n }\n if (count > WORDS - 24) flush()\n words[count++] = g.fontSize + 0\n words[count++] = g.originX + 0\n words[count++] = g.lineBottom + 0\n words[count++] = g.advance + 0\n words[count++] = g.block + 0\n words[count++] = g.sequence + 0\n words[count++] = g.z + 0\n words[count++] = clip[0] + 0\n words[count++] = clip[1] + 0\n words[count++] = clip[2] + 0\n words[count++] = clip[3] + 0\n words[count++] = color[0] + 0\n words[count++] = color[1] + 0\n words[count++] = color[2] + 0\n words[count++] = color[3] + 0\n words[count++] = (g.shapeGroup ?? OTHER) + 0\n words[count++] = (g.decorationWidth ?? OTHER) + 0\n words[count++] = (g.baselineOffset ?? OTHER) + 0\n words[count++] = (g.switchEm ?? OTHER) + 0\n words[count++] = (g.gapBefore ?? OTHER) + 0\n if (g.decorations) walk(g.decorations)\n if (g.snap) walk(g.snap)\n if (g.motionOrigin) walk(g.motionOrigin)\n }\n // Requests select retained glyph data separately through atlasSignature.\n const root = snapshot as unknown as Record<string, unknown>\n for (const key in root) {\n if (key !== 'requests' && key !== 'glyphs' && Object.hasOwn(root, key)) walk(root[key])\n }\n flush()\n strings.clear()\n return `${h1}:${h2}`\n}\n"],"mappings":";AAKA,IAAM,QAAQ;AACd,IAAM,QAAQ,IAAI,aAAa,KAAK;AACpC,IAAM,OAAO,IAAI,WAAW,MAAM,MAAM;AACxC,IAAM,0BAAU,IAAI,IAAoB;AACxC,IAAI,QAAQ;AACZ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ACxB;EACA,IAAI,QAAQ,MAAY,MAAM;EAC9B,MAAM,WAAW,EAAE,WAAW;EAC9B,MAAM,WAAW,EAAE,UAAU;EAC7B,MAAM,WAAW,EAAE,aAAa;EAChC,MAAM,WAAW,EAAE,UAAU;EAC7B,MAAM,WAAW,EAAE,QAAQ;EAC3B,MAAM,WAAW,EAAE,WAAW;EAC9B,MAAM,WAAW,EAAE,IAAI;EACvB,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,YAAY,EAAE,cAAc,SAAS;EAC3C,MAAM,YAAY,EAAE,mBAAmB,SAAS;EAChD,MAAM,YAAY,EAAE,kBAAkB,SAAS;EAC/C,MAAM,YAAY,EAAE,YAAY,SAAS;EACzC,MAAM,YAAY,EAAE,aAAa,SAAS;EAC1C,IAAI,EAAE,aAAa,KAAK,EAAE,WAAW;EACrC,IAAI,EAAE,MAAM,KAAK,EAAE,IAAI;EACvB,IAAI,EAAE,cAAc,KAAK,EAAE,YAAY;CACzC;CAEA,MAAM,OAAO;CACb,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,cAAc,QAAQ,YAAY,OAAO,OAAO,MAAM,GAAG,GAAG,KAAK,KAAK,IAAI;CAExF,MAAM;CACN,QAAQ,MAAM;CACd,OAAO,GAAG,GAAG,GAAG;AAClB"}
|
|
1
|
+
{"version":3,"file":"layoutSignature.js","names":[],"sources":["../../src/dom/layoutSignature.ts"],"sourcesContent":["import type { DomLayoutSnapshot } from '../types.js'\n\n// The walk below writes the capture's values as float64 words into this small buffer, which\n// is hashed in one tight loop whenever it fills: about 2.5 times faster than mixing each value\n// through a closure, and nothing larger than these 16 KB stays allocated.\nconst WORDS = 2048\nconst words = new Float64Array(WORDS)\nconst bits = new Int32Array(words.buffer)\nconst strings = new Map<string, number>()\nlet count = 0\nlet h1 = 0\nlet h2 = 0\n\n// Markers for what is not a number; values this large never occur in a capture.\nconst STRING = -1e300\nconst STRING_ID = -2e300\nconst TRUE = -3e300\nconst FALSE = -4e300\nconst OPEN = -5e300\nconst CLOSE = -6e300\nconst OTHER = -7e300\n\nfunction flush(): void {\n let a = h1\n let b = h2\n for (let index = 0, end = count * 2; index < end; index++) {\n const value = bits[index]!\n a = Math.imul(a ^ value, 16777619)\n b = Math.imul(b ^ value, 1597334677)\n }\n h1 = a\n h2 = b\n count = 0\n}\n\nfunction push(value: number): void {\n if (count === WORDS) flush()\n words[count++] = value\n}\n\nfunction walkString(value: string): number {\n let id = strings.get(value)\n if (id === undefined) {\n id = strings.size\n strings.set(value, id)\n const len = value.length\n if (len < 128) {\n if (count + 2 + len > WORDS) flush()\n words[count++] = STRING\n words[count++] = len\n for (let index = 0; index < len; index++) words[count++] = value.charCodeAt(index)\n } else {\n push(STRING)\n push(len)\n for (let index = 0; index < len; index++) push(value.charCodeAt(index))\n }\n } else {\n if (count > WORDS - 2) flush()\n words[count++] = STRING_ID\n words[count++] = id\n }\n return id\n}\n\nfunction walk(value: unknown): void {\n // `+ 0` folds -0 into 0: both lay out the same.\n if (typeof value === 'number') {\n if (count === WORDS) flush()\n words[count++] = value + 0\n } else if (typeof value === 'string') walkString(value)\n else if (typeof value === 'boolean') push(value ? TRUE : FALSE)\n else if (typeof value === 'object' && value !== null) {\n push(OPEN)\n // Capture records have a fixed schema and stable declaration order.\n // Field names are identical across captures; only their values matter.\n if (Array.isArray(value)) {\n const length = value.length\n if (length > 0 && typeof value[0] === 'number') {\n if (count + length > WORDS) flush()\n for (let index = 0; index < length; index++) words[count++] = (value[index] as number) + 0\n } else {\n for (let index = 0; index < length; index++) walk(value[index])\n }\n } else {\n const record = value as Record<string, unknown>\n for (const key in record) {\n if (Object.hasOwn(record, key)) walk(record[key])\n }\n }\n push(CLOSE)\n } else push(OTHER)\n}\n\n/** Hash the capture directly, without allocating its much larger JSON string. */\nexport function layoutSignatureOf(snapshot: DomLayoutSnapshot): string {\n h1 = 0x811c9dc5\n h2 = 0x811c9dc5 ^ 0x5bd1e995\n count = 0\n strings.clear()\n const glyphs = snapshot.glyphs\n push(glyphs.length)\n let prevKey: string | undefined\n let prevKeyId = -1\n let prevClip: readonly [number, number, number, number] | undefined\n let pClip0 = 0\n let pClip1 = 0\n let pClip2 = 0\n let pClip3 = 0\n let prevColor: readonly [number, number, number, number] | undefined\n let pColor0 = 0\n let pColor1 = 0\n let pColor2 = 0\n let pColor3 = 0\n for (let index = 0, length = glyphs.length; index < length; index++) {\n const g = glyphs[index]!\n const { clip, color } = g\n const glyphKey = g.glyphKey\n if (glyphKey === prevKey) {\n if (count > WORDS - 2) flush()\n words[count++] = STRING_ID\n words[count++] = prevKeyId\n } else {\n prevKeyId = walkString((prevKey = glyphKey))\n }\n let sameClip = index > 0 && clip === prevClip\n let c0 = 0\n let c1 = 0\n let c2 = 0\n let c3 = 0\n if (!sameClip) {\n c0 = clip[0] + 0\n c1 = clip[1] + 0\n c2 = clip[2] + 0\n c3 = clip[3] + 0\n sameClip = index > 0 && c0 === pClip0 && c1 === pClip1 && c2 === pClip2 && c3 === pClip3\n }\n let sameColor = index > 0 && color === prevColor\n let col0 = 0\n let col1 = 0\n let col2 = 0\n let col3 = 0\n if (!sameColor) {\n col0 = color[0] + 0\n col1 = color[1] + 0\n col2 = color[2] + 0\n col3 = color[3] + 0\n sameColor =\n index > 0 && col0 === pColor0 && col1 === pColor1 && col2 === pColor2 && col3 === pColor3\n }\n const breakBefore: string = g.breakBefore\n let flags =\n breakBefore === 'none' ? 0 : breakBefore === 'soft' ? 1 : breakBefore === 'hard' ? 2 : 3\n if (sameClip) flags |= 4\n if (sameColor) flags |= 8\n const shapeGroup = g.shapeGroup\n const decorationWidth = g.decorationWidth\n const baselineOffset = g.baselineOffset\n const switchEm = g.switchEm\n const gapBefore = g.gapBefore\n const decorations = g.decorations\n const snap = g.snap\n const motionOrigin = g.motionOrigin\n if (shapeGroup !== undefined) flags |= 16\n if (decorationWidth !== undefined) flags |= 32\n if (baselineOffset !== undefined) flags |= 64\n if (switchEm !== undefined) flags |= 128\n if (gapBefore !== undefined) flags |= 256\n if (decorations !== undefined) flags |= 512\n if (snap !== undefined) flags |= 1024\n if (motionOrigin !== undefined) flags |= 2048\n if (count === WORDS) flush()\n words[count++] = flags\n if ((flags & 3) === 3) walkString(breakBefore)\n if (count > WORDS - 26) flush()\n words[count++] = g.fontSize + 0\n words[count++] = g.originX + 0\n words[count++] = g.lineBottom + 0\n words[count++] = g.advance + 0\n words[count++] = g.block + 0\n words[count++] = g.sequence + 0\n words[count++] = g.z + 0\n if (!sameClip) {\n words[count++] = pClip0 = c0\n words[count++] = pClip1 = c1\n words[count++] = pClip2 = c2\n words[count++] = pClip3 = c3\n prevClip = clip\n }\n if (!sameColor) {\n words[count++] = pColor0 = col0\n words[count++] = pColor1 = col1\n words[count++] = pColor2 = col2\n words[count++] = pColor3 = col3\n prevColor = color\n }\n if (shapeGroup !== undefined) words[count++] = shapeGroup + 0\n if (decorationWidth !== undefined) words[count++] = decorationWidth + 0\n if (baselineOffset !== undefined) words[count++] = baselineOffset + 0\n if (switchEm !== undefined) words[count++] = switchEm + 0\n if (gapBefore !== undefined) words[count++] = gapBefore + 0\n if (snap !== undefined) {\n words[count++] = snap[0] + 0\n words[count++] = snap[1] + 0\n }\n if (motionOrigin !== undefined) {\n words[count++] = motionOrigin[0] + 0\n words[count++] = motionOrigin[1] + 0\n words[count++] = motionOrigin[2] + 0\n }\n if (decorations !== undefined) walk(decorations)\n }\n const blocks = snapshot.blocks\n push(blocks.length)\n for (let index = 0, length = blocks.length; index < length; index++) {\n const b = blocks[index]!\n const bClip = b.clip\n if (count > WORDS - 10) flush()\n words[count++] = b.left + 0\n words[count++] = b.firstBaseline + 0\n words[count++] = b.linePitch + 0\n words[count++] = b.width + 0\n words[count++] = bClip[0] + 0\n words[count++] = bClip[1] + 0\n words[count++] = bClip[2] + 0\n words[count++] = bClip[3] + 0\n let bFlags = 0\n if (b.direction !== undefined) bFlags |= 1\n if (b.textAlign !== undefined) bFlags |= 2\n if (b.textAlignLast !== undefined) bFlags |= 4\n words[count++] = bFlags\n if (b.direction !== undefined) walkString(b.direction)\n if (b.textAlign !== undefined) walkString(b.textAlign)\n if (b.textAlignLast !== undefined) walkString(b.textAlignLast)\n }\n const rects = snapshot.rects\n push(rects.length)\n for (let index = 0, length = rects.length; index < length; index++) {\n const r = rects[index]!\n const rr = r.rect\n const rc = r.color\n if (count > WORDS - 12) flush()\n words[count++] = rr[0] + 0\n words[count++] = rr[1] + 0\n words[count++] = rr[2] + 0\n words[count++] = rr[3] + 0\n words[count++] = rc[0] + 0\n words[count++] = rc[1] + 0\n words[count++] = rc[2] + 0\n words[count++] = rc[3] + 0\n words[count++] = r.radius + 0\n words[count++] = r.z + 0\n words[count++] = r.receiveShadow ? TRUE : FALSE\n }\n // Requests select retained glyph data separately through atlasSignature.\n const root = snapshot as unknown as Record<string, unknown>\n for (const key in root) {\n if (\n key !== 'requests' &&\n key !== 'glyphs' &&\n key !== 'blocks' &&\n key !== 'rects' &&\n Object.hasOwn(root, key)\n ) {\n walk(root[key])\n }\n }\n flush()\n strings.clear()\n return `${h1}:${h2}`\n}\n"],"mappings":";AAKA,IAAM,QAAQ;AACd,IAAM,QAAQ,IAAI,aAAa,KAAK;AACpC,IAAM,OAAO,IAAI,WAAW,MAAM,MAAM;AACxC,IAAM,0BAAU,IAAI,IAAoB;AACxC,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,KAAK;AAGT,IAAM,SAAS;AACf,IAAM,YAAY;AAClB,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,OAAO;AACb,IAAM,QAAQ;AACd,IAAM,QAAQ;AAEd,SAAS,QAAc;CACrB,IAAI,IAAI;CACR,IA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MAAM;CACd,OAAO,GAAG,GAAG,GAAG;AAClB"}
|
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
import { glyphClusters, isEmojiGrapheme } from "./clusters.js";
|
|
2
|
+
import { createSharedMeasureContext, isNativeMeasureBrowser } from "./fontCanvas.js";
|
|
2
3
|
import { transformText } from "./textTransform.js";
|
|
3
4
|
import { materializeRichInlineLineRange, prepareRichInline, walkRichInlineLineRanges } from "@chenglou/pretext/rich-inline";
|
|
4
5
|
// src/dom/pretextLayout.ts
|
|
6
|
+
var MAX_FONT_METRICS_CACHE = 64;
|
|
7
|
+
var ASCII_CHARS = Array.from({ length: 128 }, (_, i) => String.fromCharCode(i));
|
|
8
|
+
var sharedFontMetricsCache = /* @__PURE__ */ new Map();
|
|
9
|
+
var lastPretextFontSetSize = -1;
|
|
10
|
+
function acquireFontEntry(cache, layoutFont) {
|
|
11
|
+
const hit = cache.get(layoutFont);
|
|
12
|
+
if (hit) {
|
|
13
|
+
cache.delete(layoutFont);
|
|
14
|
+
cache.set(layoutFont, hit);
|
|
15
|
+
return hit;
|
|
16
|
+
}
|
|
17
|
+
let entry;
|
|
18
|
+
if (cache.size >= MAX_FONT_METRICS_CACHE) {
|
|
19
|
+
const oldestKey = cache.keys().next().value;
|
|
20
|
+
entry = cache.get(oldestKey);
|
|
21
|
+
cache.delete(oldestKey);
|
|
22
|
+
entry[0].clear();
|
|
23
|
+
entry[1].fill(NaN);
|
|
24
|
+
} else entry = [/* @__PURE__ */ new Map(), (/* @__PURE__ */ new Float64Array(16513)).fill(NaN)];
|
|
25
|
+
cache.set(layoutFont, entry);
|
|
26
|
+
return entry;
|
|
27
|
+
}
|
|
5
28
|
function createPretextCapture(root, document, options, bakeSize, invScale, rootRect, measuresBaselines, deviceScale, boxHeights, glyphs, displayNone, inlineBox, ignored, resolveParent, transformSeed, requestKey, parsePx, canvasFont, fontMetrics, trackLayoutGrid, resolveLayoutScale, canBreakCjk) {
|
|
6
|
-
const context = document
|
|
29
|
+
const context = createSharedMeasureContext(document);
|
|
7
30
|
if (!context) throw new Error("collectDomSnapshot: Canvas 2D is unavailable");
|
|
31
|
+
const nativeMeasure = isNativeMeasureBrowser(document);
|
|
32
|
+
if (nativeMeasure) {
|
|
33
|
+
const fontCount = document.fonts?.size ?? 0;
|
|
34
|
+
if (fontCount !== lastPretextFontSetSize) {
|
|
35
|
+
lastPretextFontSetSize = fontCount;
|
|
36
|
+
sharedFontMetricsCache.clear();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
8
39
|
const measureAdvance = (advances, previous, character) => {
|
|
9
40
|
const cacheKey = previous ? previous + "" + character : character;
|
|
10
41
|
let advance = advances.get(cacheKey);
|
|
@@ -38,7 +69,7 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
38
69
|
}
|
|
39
70
|
const pretextScale = layoutScale ?? 1;
|
|
40
71
|
const runMetrics = /* @__PURE__ */ new Map();
|
|
41
|
-
const fontMetricsCache = /* @__PURE__ */ new Map();
|
|
72
|
+
const fontMetricsCache = nativeMeasure ? sharedFontMetricsCache : /* @__PURE__ */ new Map();
|
|
42
73
|
const lineCache = /* @__PURE__ */ new Map();
|
|
43
74
|
const blockStyleCache = /* @__PURE__ */ new Map();
|
|
44
75
|
return [
|
|
@@ -174,16 +205,9 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
174
205
|
let previousCode = -1;
|
|
175
206
|
let runWidth = 0;
|
|
176
207
|
let renderedCharacters = 0;
|
|
177
|
-
const
|
|
178
|
-
let
|
|
179
|
-
|
|
180
|
-
fontEntry = [/* @__PURE__ */ new Map(), (/* @__PURE__ */ new Float64Array(16513)).fill(NaN)];
|
|
181
|
-
fontMetricsCache.set(inline.layoutFont, fontEntry);
|
|
182
|
-
}
|
|
183
|
-
const [advances, ascii] = fontEntry;
|
|
184
|
-
for (const character of glyphClusters(fragment.text)) {
|
|
185
|
-
const code = character.length === 1 ? character.charCodeAt(0) : -1;
|
|
186
|
-
const isAscii = code >= 0 && code < 128;
|
|
208
|
+
const [advances, ascii] = acquireFontEntry(fontMetricsCache, inline.layoutFont);
|
|
209
|
+
let emojiFragment = false;
|
|
210
|
+
const emitCharacter = (character, code, isAscii) => {
|
|
187
211
|
let loneAdvance = isAscii ? ascii[code] : NaN;
|
|
188
212
|
if (Number.isNaN(loneAdvance)) {
|
|
189
213
|
loneAdvance = measureAdvance(advances, "", character);
|
|
@@ -223,7 +247,7 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
223
247
|
previousCharacter = character;
|
|
224
248
|
previousCode = code;
|
|
225
249
|
renderedCharacters++;
|
|
226
|
-
|
|
250
|
+
return;
|
|
227
251
|
}
|
|
228
252
|
const key = requestKey(inline.font, inline.keys, character);
|
|
229
253
|
const isCjkSoft = options.cjkLineBreaking === true && canBreakCjk(previousBreakCharacter, character);
|
|
@@ -262,6 +286,24 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
262
286
|
previousCharacter = character;
|
|
263
287
|
previousCode = code;
|
|
264
288
|
renderedCharacters++;
|
|
289
|
+
};
|
|
290
|
+
const text = fragment.text;
|
|
291
|
+
const textLen = text.length;
|
|
292
|
+
let index = 0;
|
|
293
|
+
while (index < textLen) {
|
|
294
|
+
const code = text.charCodeAt(index);
|
|
295
|
+
if (code >= 128) break;
|
|
296
|
+
if (index + 1 < textLen && (text.charCodeAt(index + 1) >= 128 || code === 13)) break;
|
|
297
|
+
emitCharacter(ASCII_CHARS[code], code, true);
|
|
298
|
+
index++;
|
|
299
|
+
}
|
|
300
|
+
if (index < textLen) {
|
|
301
|
+
const tail = index === 0 ? text : text.slice(index);
|
|
302
|
+
emojiFragment = isEmojiGrapheme(tail);
|
|
303
|
+
for (const character of glyphClusters(tail)) {
|
|
304
|
+
const code = character.length === 1 ? character.charCodeAt(0) : -1;
|
|
305
|
+
emitCharacter(character, code, code >= 0 && code < 128);
|
|
306
|
+
}
|
|
265
307
|
}
|
|
266
308
|
penX += fragment.occupiedWidth;
|
|
267
309
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pretextLayout.js","names":[],"sources":["../../src/dom/pretextLayout.ts"],"sourcesContent":["import {\n materializeRichInlineLineRange,\n prepareRichInline,\n walkRichInlineLineRanges,\n} from '@chenglou/pretext/rich-inline'\n\nimport type {\n DomSdfOptions,\n FontStyleSnapshot,\n GlyphLayout,\n TextBlockLayout,\n TextDecorationLayout,\n} from '../types.js'\nimport { glyphClusters, isEmojiGrapheme } from './clusters.js'\nimport { transformText, type TextTransform } from './textTransform.js'\n\ntype MutableGlyph = { -readonly [K in keyof GlyphLayout]: GlyphLayout[K] }\n\nexport interface PretextInlineStyle {\n readonly decorations: readonly TextDecorationLayout[]\n readonly font: FontStyleSnapshot\n readonly keys: Map<string, string>\n readonly fontSize: number\n readonly layoutFont: string\n readonly letterSpacing: number\n readonly color: readonly [number, number, number, number]\n readonly z: number\n readonly transform: TextTransform | null\n}\n\nexport interface PretextParentRecord {\n readonly owner: Element | null\n readonly inline: PretextInlineStyle | null\n readonly paragraph: Element | null\n}\n\nexport function createPretextCapture(\n root: HTMLElement,\n document: Document,\n options: DomSdfOptions,\n bakeSize: number,\n invScale: number,\n rootRect: DOMRect,\n measuresBaselines: boolean,\n deviceScale: number,\n boxHeights: Map<FontStyleSnapshot, number>,\n glyphs: MutableGlyph[],\n displayNone: (element: Element) => boolean,\n inlineBox: (element: Element) => boolean,\n ignored: (element: Element) => boolean,\n resolveParent: (parent: HTMLElement) => PretextParentRecord,\n transformSeed: (node: Text, transform: TextTransform) => string | undefined,\n requestKey: (font: FontStyleSnapshot, keys: Map<string, string>, character: string) => string,\n parsePx: (value: string, fallback?: number, ref?: number) => number,\n canvasFont: (style: CSSStyleDeclaration, bakeSize: number) => string,\n fontMetrics: (\n context: CanvasRenderingContext2D,\n font: string,\n fontSize: number,\n ) => readonly [number, number],\n trackLayoutGrid: (box: { readonly left: number; readonly width: number }) => void,\n resolveLayoutScale: (context: CanvasRenderingContext2D) => number | undefined,\n canBreakCjk: (p: string, c: string) => boolean,\n) {\n const context = document.createElement('canvas').getContext('2d', { willReadFrequently: true })\n if (!context) {\n throw new Error('collectDomSnapshot: Canvas 2D is unavailable')\n }\n\n const measureAdvance = (\n advances: Map<string, number>,\n previous: string,\n character: string,\n ): number => {\n const cacheKey = previous ? previous + '\\u0001' + character : character\n let advance = advances.get(cacheKey)\n if (advance === undefined) {\n advance = previous\n ? context.measureText(previous + character).width - measureAdvance(advances, '', previous)\n : context.measureText(character).width\n advances.set(cacheKey, advance)\n }\n return advance\n }\n\n let layoutScale: number | undefined\n if (measuresBaselines && deviceScale !== 1) {\n const range = document.createRange()\n const walker = document.createTreeWalker(root, 4)\n let samples = 16\n for (let node = walker.nextNode(); node && samples > 0; node = walker.nextNode()) {\n const text = node as Text\n const record = text.parentElement ? resolveParent(text.parentElement) : null\n if (!record?.inline || !record.owner) continue\n for (const { index, 0: character } of text.data.matchAll(/\\S/gu)) {\n range.setStart(text, index)\n range.setEnd(text, index + character.length)\n const box = range.getBoundingClientRect()\n const height = box.height\n if (box.width <= 0 || height <= 0) continue\n trackLayoutGrid(box)\n if (!boxHeights.has(record.inline.font)) boxHeights.set(record.inline.font, height)\n if (--samples === 0) break\n }\n }\n layoutScale = resolveLayoutScale(context)\n }\n const pretextScale = layoutScale ?? 1\n\n const runMetrics = new Map<FontStyleSnapshot, readonly [number, number]>()\n const fontMetricsCache = new Map<string, readonly [Map<string, number>, Float64Array]>()\n const lineCache = new Map<string, ReturnType<typeof materializeRichInlineLineRange>[]>()\n const blockStyleCache = new Map<\n CSSStyleDeclaration,\n readonly [number, number, number, number, number, 'pre-wrap' | 'normal', 'keep-all' | 'normal']\n >()\n\n return [\n context,\n layoutScale,\n (\n block: HTMLElement,\n blockIndex: number,\n blockStyle: CSSStyleDeclaration,\n blockRect: DOMRect,\n clip: readonly [number, number, number, number],\n includeTextBox: (box: {\n readonly left: number\n readonly top: number\n readonly bottom: number\n readonly width: number\n readonly height: number\n }) => void,\n align: NonNullable<TextBlockLayout['textAlign']>,\n lastAlign: NonNullable<TextBlockLayout['textAlign']>,\n ): readonly [number, number, number] => {\n interface PretextItem {\n readonly text: string\n readonly font: string\n readonly letterSpacing: number\n readonly inline: PretextInlineStyle\n }\n let current: PretextItem[] = []\n const segments: PretextItem[][] = [current]\n let currentParagraph: Element | null = null\n const walker = document.createTreeWalker(block, 5)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (node.nodeType !== 3) {\n const element = node as HTMLElement\n if (element.tagName === 'BR') {\n if (\n !ignored(element) &&\n !displayNone(element) &&\n resolveParent(element).owner === block\n ) {\n segments.push((current = []))\n }\n } else if (\n (current.length > 0 || currentParagraph !== null) &&\n !displayNone(element) &&\n !inlineBox(element)\n ) {\n if (current.length > 0) segments.push((current = []))\n currentParagraph = null\n }\n continue\n }\n const textNode = node as Text\n const record = textNode.parentElement ? resolveParent(textNode.parentElement) : null\n if (!record?.inline || record.owner !== block) continue\n if (record.paragraph !== currentParagraph) {\n if (currentParagraph !== null && current.length > 0) segments.push((current = []))\n currentParagraph = record.paragraph\n }\n if (textNode.data.length > 0) {\n const { inline } = record\n const { transform } = inline\n const shown = transform\n ? transformText(textNode.data, transform, transformSeed(textNode, transform))\n : textNode.data\n const text = options.reshape ? options.reshape(shown) : shown\n current.push({\n text,\n font: inline.layoutFont,\n letterSpacing: inline.letterSpacing,\n inline,\n })\n }\n }\n\n let bm = blockStyleCache.get(blockStyle)\n if (!bm) {\n const inset = (side: 'Left' | 'Right' | 'Top'): number =>\n (/none|hidden/.test(blockStyle[`border${side}Style`])\n ? 0\n : parsePx(blockStyle[`border${side}Width`])) + parsePx(blockStyle[`padding${side}`])\n const cssSize = parsePx(blockStyle.fontSize, 16)\n const blockSize = cssSize * pretextScale\n const [bAscent, bDescent] = fontMetrics(\n context,\n canvasFont(blockStyle, blockSize),\n blockSize,\n )\n const ascent = bAscent / pretextScale\n const fontHeight = ascent + bDescent / pretextScale\n const lineHeight = parsePx(blockStyle.lineHeight, fontHeight, cssSize)\n const lineUnits = Math.round(lineHeight * pretextScale * 64)\n const lineLayout =\n Math.abs(lineUnits / 64 - lineHeight * pretextScale) < 1e-3\n ? lineUnits / 64\n : lineHeight * pretextScale\n const leading = lineLayout - bAscent - bDescent\n bm = [\n inset('Left'),\n inset('Right'),\n inset('Top'),\n lineHeight,\n Math.floor(leading / 2) / pretextScale + ascent,\n /pre(?!-l)|bre/.test(blockStyle.whiteSpace) ? 'pre-wrap' : 'normal',\n blockStyle.wordBreak === 'keep-all' ? 'keep-all' : 'normal',\n ]\n blockStyleCache.set(blockStyle, bm)\n }\n const [insetLeft, insetRight, insetTop, lineHeight, baselineOffset, whiteSpace, wordBreak] =\n bm\n const contentWidth = Math.max(1, blockRect.width - insetLeft - insetRight)\n const contentLeft = blockRect.left - rootRect.left + insetLeft\n const contentTop = blockRect.top - rootRect.top + insetTop\n for (const segment of segments)\n for (const { inline } of segment) {\n if (runMetrics.has(inline.font)) continue\n const size = inline.font.size * pretextScale\n const [mAscent, mDescent] = fontMetrics(\n context,\n inline.font.canvasFont.replace(`${bakeSize}px`, `${size}px`),\n size,\n )\n runMetrics.set(inline.font, [mAscent / pretextScale, mDescent / pretextScale])\n }\n let lines = 0\n let lineIndex = 0\n let measuredFont = ''\n let afterSpace = true\n let joined = false\n const justified = align === 'justify' || lastAlign === 'justify'\n for (let segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {\n const segment = segments[segmentIndex]!\n if (segment.length === 0) {\n if (segments.length > 1) lineIndex++\n continue\n }\n let hardPending = segmentIndex > 0\n let previousBreakCharacter = ''\n let prepKey = `${contentWidth}|${whiteSpace}|${wordBreak}`\n for (const s of segment) prepKey += `\\u0001${s.font}\\u0002${s.letterSpacing}\\u0002${s.text}`\n let materializedLines = lineCache.get(prepKey)\n if (!materializedLines) {\n const prepared = prepareRichInline(segment, { whiteSpace, wordBreak })\n materializedLines = []\n walkRichInlineLineRanges(prepared, contentWidth, (lineRange) =>\n materializedLines!.push(materializeRichInlineLineRange(prepared, lineRange)),\n )\n lineCache.set(prepKey, materializedLines)\n }\n for (let rangeIndex = 0; rangeIndex < materializedLines.length; rangeIndex++) {\n const line = materializedLines[rangeIndex]!\n const lineAlign = rangeIndex < materializedLines.length - 1 ? align : lastAlign\n const slack = contentWidth - line.width\n const baselineCss = contentTop + baselineOffset + lineIndex * lineHeight\n lines++\n let penX =\n contentLeft + (lineAlign === 'center' ? slack * 0.5 : lineAlign === 'right' ? slack : 0)\n let sequence = 0\n let linePrevious: MutableGlyph | undefined\n const lineStart = glyphs.length\n\n for (const fragment of line.fragments) {\n const item = segment[fragment.itemIndex]\n if (!item) continue\n const { inline } = item\n if (fragment.gapBefore > 0) {\n previousBreakCharacter = ''\n afterSpace = true\n }\n penX += fragment.gapBefore\n if (measuredFont !== inline.layoutFont) {\n context.font = measuredFont = inline.layoutFont\n }\n const [runAscent, runDescent] = runMetrics.get(inline.font)!\n const descent = runDescent * invScale\n const lineBottom = (rootRect.height - baselineCss) * invScale - descent\n const top = rootRect.top + baselineCss - runAscent\n const bottom = rootRect.top + baselineCss + descent / invScale\n includeTextBox({\n left: rootRect.left + penX,\n top,\n bottom,\n width: fragment.occupiedWidth,\n height: bottom - top,\n })\n let previousCharacter = ''\n let previousCode = -1\n let runWidth = 0\n let renderedCharacters = 0\n\n const emojiFragment = isEmojiGrapheme(fragment.text)\n let fontEntry = fontMetricsCache.get(inline.layoutFont)\n if (!fontEntry) {\n fontEntry = [new Map(), new Float64Array(16513).fill(NaN)]\n fontMetricsCache.set(inline.layoutFont, fontEntry)\n }\n const [advances, ascii] = fontEntry\n for (const character of glyphClusters(fragment.text)) {\n const code = character.length === 1 ? character.charCodeAt(0) : -1\n const isAscii = code >= 0 && code < 128\n let loneAdvance = isAscii ? ascii[code]! : NaN\n if (Number.isNaN(loneAdvance)) {\n loneAdvance = measureAdvance(advances, '', character)\n if (isAscii) ascii[code] = loneAdvance\n }\n let advance = loneAdvance\n if (previousCharacter) {\n if (isAscii && previousCode >= 0 && previousCode < 128) {\n const pairIdx = ((previousCode + 1) << 7) | code\n advance = ascii[pairIdx]!\n if (Number.isNaN(advance)) {\n ascii[pairIdx] = advance =\n context.measureText(previousCharacter + character).width -\n ascii[previousCode]!\n }\n } else {\n advance = measureAdvance(advances, previousCharacter, character)\n }\n }\n const kerning = advance - loneAdvance\n if (emojiFragment && isEmojiGrapheme(character)) {\n if (Number.isNaN(ascii[16512]!)) {\n const probe = prepareRichInline([{ text: '\\u{1F600}', font: inline.layoutFont }])\n let corrected = 0\n walkRichInlineLineRanges(probe, 1e6, (probeLine) => {\n corrected = probeLine.width\n })\n context.font = measuredFont = inline.layoutFont\n ascii[16512] = Math.max(0, context.measureText('\\u{1F600}').width - corrected)\n }\n advance -= ascii[16512]!\n }\n const spacing = renderedCharacters > 0 ? inline.letterSpacing : 0\n const nextWidth = runWidth + spacing + advance\n if (\n code <= 32\n ? code === 32 || (code >= 9 && code <= 13)\n : code >= 0x85 && /^\\s$/u.test(character)\n ) {\n if (code === 0xa0) joined = true\n else if (!/[\\u2007\\u202f\\ufeff]/.test(character)) afterSpace = true\n previousBreakCharacter = ''\n runWidth = nextWidth\n previousCharacter = character\n previousCode = code\n renderedCharacters++\n continue\n }\n const key = requestKey(inline.font, inline.keys, character)\n const isCjkSoft =\n options.cjkLineBreaking === true && canBreakCjk(previousBreakCharacter, character)\n const originX = (penX + runWidth + spacing + kerning) * invScale\n if (linePrevious) {\n if (afterSpace || isCjkSoft || joined)\n linePrevious.decorationWidth ??= linePrevious.advance\n linePrevious.advance = originX - linePrevious.originX\n }\n const glyph: MutableGlyph = {\n glyphKey: key,\n fontSize: inline.fontSize,\n originX,\n lineBottom,\n baselineOffset: descent,\n advance: (nextWidth - runWidth - kerning) * invScale,\n block: blockIndex,\n breakBefore: hardPending\n ? 'hard'\n : afterSpace || sequence === 0 || isCjkSoft\n ? 'soft'\n : 'none',\n clip,\n color: inline.color,\n sequence,\n z: inline.z,\n }\n if (isCjkSoft) glyph.gapBefore = 0\n else if (linePrevious ? (afterSpace || joined) && justified : rangeIndex > 0)\n glyph.gapBefore = linePrevious\n ? linePrevious.advance - linePrevious.decorationWidth!\n : (measureAdvance(advances, '', ' ') + inline.letterSpacing) * invScale\n if (inline.decorations.length) {\n glyph.decorations = inline.decorations\n glyph.decorationWidth = glyph.advance\n }\n glyphs.push(glyph)\n linePrevious = glyph\n hardPending = false\n if (options.cjkLineBreaking) previousBreakCharacter = character\n afterSpace = joined = false\n sequence++\n runWidth = nextWidth\n previousCharacter = character\n previousCode = code\n renderedCharacters++\n }\n penX += fragment.occupiedWidth\n }\n if (lineAlign === 'justify' && slack > 0) {\n let spaces = 0\n for (let i = lineStart + 1; i < glyphs.length; i++)\n if (glyphs[i]!.gapBefore !== undefined) spaces++\n const share = (slack * invScale) / spaces\n for (let i = lineStart + 1, k = 0; spaces && i < glyphs.length; i++) {\n if (glyphs[i]!.gapBefore !== undefined) {\n k++\n glyphs[i - 1]!.advance += share\n }\n glyphs[i]!.originX += k * share\n }\n }\n afterSpace = true\n lineIndex++\n }\n }\n return [lines, contentLeft * invScale, contentWidth * invScale]\n },\n ] as const\n}\n"],"mappings":";;;;AAoCA,SAAgB,qBACd,MACA,UACA,SACA,UACA,UACA,UACA,mBACA,aACA,YACA,QACA,aACA,WACA,SACA,eACA,eACA,YACA,SACA,YACA,aAKA,iBACA,oBACA,aACA;CACA,MAAM,UAAU,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,MAAM,EAAE,oBAAoB,KAAK,CAAC;CAC9F,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8CAA8C;CAGhE,MAAM,kBACJ,UACA,UACA,cACW;EACX,MAAM,WAAW,WAAW,WAAW,MAAW,YAAY;EAC9D,IAAI,UAAU,SAAS,IAAI,QAAQ;EACnC,IAAI,YAAY,KAAA,GAAW;GACzB,UAAU,WACN,QAAQ,YAAY,WAAW,SAAS,CAAC,CAAC,QAAQ,eAAe,UAAU,IAAI,QAAQ,IAC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C5B,IAAI,gBAAgB,cAAc,WAAW,YAAY,aAAa,GACzE,MAAM,YAAY,eACd,aAAa,UAAU,aAAa,mBACnC,eAAe,UAAU,IAAI,GAAG,IAAI,OAAO,iBAAiB;OACnE,IAAI,OAAO,YAAY,QAAQ;QAC7B,MAAM,cAAc,OAAO;QAC3B,MAAM,kBAAkB,MAAM;OAChC;OACA,OAAO,KAAK,KAAK;OACjB,eAAe;OACf,cAAc;OACd,IAAI,QAAQ,iBAAiB,yBAAyB;OACtD,aAAa,SAAS;OACtB;OACA,WAAW;OACX,oBAAoB;OACpB,eAAe;OACf;MACF;MACA,QAAQ,SAAS;KACnB;KACA,IAAI,cAAc,aAAa,QAAQ,GAAG;MACxC,IAAI,SAAS;MACb,KAAK,IAAI,IAAI,YAAY,GAAG,IAAI,OAAO,QAAQ,KAC7C,IAAI,OAAO,EAAE,CAAE,cAAc,KAAA,GAAW;MAC1C,MAAM,QAAS,QAAQ,WAAY;MACnC,KAAK,IAAI,IAAI,YAAY,GAAG,IAAI,GAAG,UAAU,IAAI,OAAO,QAAQ,KAAK;OACnE,IAAI,OAAO,EAAE,CAAE,cAAc,KAAA,GAAW;QACtC;QACA,OAAO,IAAI,EAAE,CAAE,WAAW;OAC5B;OACA,OAAO,EAAE,CAAE,WAAW,IAAI;MAC5B;KACF;KACA,aAAa;KACb;IACF;GACF;GACA,OAAO;IAAC;IAAO,cAAc;IAAU,eAAe;GAAQ;EAChE;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"pretextLayout.js","names":[],"sources":["../../src/dom/pretextLayout.ts"],"sourcesContent":["import {\n materializeRichInlineLineRange,\n prepareRichInline,\n walkRichInlineLineRanges,\n} from '@chenglou/pretext/rich-inline'\n\nimport type {\n DomSdfOptions,\n FontStyleSnapshot,\n GlyphLayout,\n TextBlockLayout,\n TextDecorationLayout,\n} from '../types.js'\nimport { glyphClusters, isEmojiGrapheme } from './clusters.js'\nimport { createSharedMeasureContext, isNativeMeasureBrowser } from './fontCanvas.js'\nimport { transformText, type TextTransform } from './textTransform.js'\n\nconst MAX_FONT_METRICS_CACHE = 64\nconst ASCII_CHARS = Array.from({ length: 128 }, (_, i) => String.fromCharCode(i))\ntype FontMetricsEntry = readonly [Map<string, number>, Float64Array]\nconst sharedFontMetricsCache = new Map<string, FontMetricsEntry>()\nlet lastPretextFontSetSize = -1\n\nfunction acquireFontEntry(\n cache: Map<string, FontMetricsEntry>,\n layoutFont: string,\n): FontMetricsEntry {\n const hit = cache.get(layoutFont)\n if (hit) {\n cache.delete(layoutFont)\n cache.set(layoutFont, hit)\n return hit\n }\n let entry: FontMetricsEntry\n if (cache.size >= MAX_FONT_METRICS_CACHE) {\n const oldestKey = cache.keys().next().value!\n entry = cache.get(oldestKey)!\n cache.delete(oldestKey)\n entry[0].clear()\n entry[1].fill(NaN)\n } else {\n entry = [new Map(), new Float64Array(16513).fill(NaN)]\n }\n cache.set(layoutFont, entry)\n return entry\n}\n\ntype MutableGlyph = { -readonly [K in keyof GlyphLayout]: GlyphLayout[K] }\n\nexport interface PretextInlineStyle {\n readonly decorations: readonly TextDecorationLayout[]\n readonly font: FontStyleSnapshot\n readonly keys: Map<string, string>\n readonly fontSize: number\n readonly layoutFont: string\n readonly letterSpacing: number\n readonly color: readonly [number, number, number, number]\n readonly z: number\n readonly transform: TextTransform | null\n}\n\nexport interface PretextParentRecord {\n readonly owner: Element | null\n readonly inline: PretextInlineStyle | null\n readonly paragraph: Element | null\n}\n\nexport function createPretextCapture(\n root: HTMLElement,\n document: Document,\n options: DomSdfOptions,\n bakeSize: number,\n invScale: number,\n rootRect: DOMRect,\n measuresBaselines: boolean,\n deviceScale: number,\n boxHeights: Map<FontStyleSnapshot, number>,\n glyphs: MutableGlyph[],\n displayNone: (element: Element) => boolean,\n inlineBox: (element: Element) => boolean,\n ignored: (element: Element) => boolean,\n resolveParent: (parent: HTMLElement) => PretextParentRecord,\n transformSeed: (node: Text, transform: TextTransform) => string | undefined,\n requestKey: (font: FontStyleSnapshot, keys: Map<string, string>, character: string) => string,\n parsePx: (value: string, fallback?: number, ref?: number) => number,\n canvasFont: (style: CSSStyleDeclaration, bakeSize: number) => string,\n fontMetrics: (\n context: CanvasRenderingContext2D,\n font: string,\n fontSize: number,\n ) => readonly [number, number],\n trackLayoutGrid: (box: { readonly left: number; readonly width: number }) => void,\n resolveLayoutScale: (context: CanvasRenderingContext2D) => number | undefined,\n canBreakCjk: (p: string, c: string) => boolean,\n) {\n const context = createSharedMeasureContext(document)\n if (!context) {\n throw new Error('collectDomSnapshot: Canvas 2D is unavailable')\n }\n const nativeMeasure = isNativeMeasureBrowser(document)\n if (nativeMeasure) {\n const fontCount = (document.fonts as FontFaceSet | undefined)?.size ?? 0\n if (fontCount !== lastPretextFontSetSize) {\n lastPretextFontSetSize = fontCount\n sharedFontMetricsCache.clear()\n }\n }\n\n const measureAdvance = (\n advances: Map<string, number>,\n previous: string,\n character: string,\n ): number => {\n const cacheKey = previous ? previous + '\\u0001' + character : character\n let advance = advances.get(cacheKey)\n if (advance === undefined) {\n advance = previous\n ? context.measureText(previous + character).width - measureAdvance(advances, '', previous)\n : context.measureText(character).width\n advances.set(cacheKey, advance)\n }\n return advance\n }\n\n let layoutScale: number | undefined\n if (measuresBaselines && deviceScale !== 1) {\n const range = document.createRange()\n const walker = document.createTreeWalker(root, 4)\n let samples = 16\n for (let node = walker.nextNode(); node && samples > 0; node = walker.nextNode()) {\n const text = node as Text\n const record = text.parentElement ? resolveParent(text.parentElement) : null\n if (!record?.inline || !record.owner) continue\n for (const { index, 0: character } of text.data.matchAll(/\\S/gu)) {\n range.setStart(text, index)\n range.setEnd(text, index + character.length)\n const box = range.getBoundingClientRect()\n const height = box.height\n if (box.width <= 0 || height <= 0) continue\n trackLayoutGrid(box)\n if (!boxHeights.has(record.inline.font)) boxHeights.set(record.inline.font, height)\n if (--samples === 0) break\n }\n }\n layoutScale = resolveLayoutScale(context)\n }\n const pretextScale = layoutScale ?? 1\n\n const runMetrics = new Map<FontStyleSnapshot, readonly [number, number]>()\n const fontMetricsCache = nativeMeasure\n ? sharedFontMetricsCache\n : new Map<string, FontMetricsEntry>()\n const lineCache = new Map<string, ReturnType<typeof materializeRichInlineLineRange>[]>()\n const blockStyleCache = new Map<\n CSSStyleDeclaration,\n readonly [number, number, number, number, number, 'pre-wrap' | 'normal', 'keep-all' | 'normal']\n >()\n\n return [\n context,\n layoutScale,\n (\n block: HTMLElement,\n blockIndex: number,\n blockStyle: CSSStyleDeclaration,\n blockRect: DOMRect,\n clip: readonly [number, number, number, number],\n includeTextBox: (box: {\n readonly left: number\n readonly top: number\n readonly bottom: number\n readonly width: number\n readonly height: number\n }) => void,\n align: NonNullable<TextBlockLayout['textAlign']>,\n lastAlign: NonNullable<TextBlockLayout['textAlign']>,\n ): readonly [number, number, number] => {\n interface PretextItem {\n readonly text: string\n readonly font: string\n readonly letterSpacing: number\n readonly inline: PretextInlineStyle\n }\n let current: PretextItem[] = []\n const segments: PretextItem[][] = [current]\n let currentParagraph: Element | null = null\n const walker = document.createTreeWalker(block, 5)\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n if (node.nodeType !== 3) {\n const element = node as HTMLElement\n if (element.tagName === 'BR') {\n if (\n !ignored(element) &&\n !displayNone(element) &&\n resolveParent(element).owner === block\n ) {\n segments.push((current = []))\n }\n } else if (\n (current.length > 0 || currentParagraph !== null) &&\n !displayNone(element) &&\n !inlineBox(element)\n ) {\n if (current.length > 0) segments.push((current = []))\n currentParagraph = null\n }\n continue\n }\n const textNode = node as Text\n const record = textNode.parentElement ? resolveParent(textNode.parentElement) : null\n if (!record?.inline || record.owner !== block) continue\n if (record.paragraph !== currentParagraph) {\n if (currentParagraph !== null && current.length > 0) segments.push((current = []))\n currentParagraph = record.paragraph\n }\n if (textNode.data.length > 0) {\n const { inline } = record\n const { transform } = inline\n const shown = transform\n ? transformText(textNode.data, transform, transformSeed(textNode, transform))\n : textNode.data\n const text = options.reshape ? options.reshape(shown) : shown\n current.push({\n text,\n font: inline.layoutFont,\n letterSpacing: inline.letterSpacing,\n inline,\n })\n }\n }\n\n let bm = blockStyleCache.get(blockStyle)\n if (!bm) {\n const inset = (side: 'Left' | 'Right' | 'Top'): number =>\n (/none|hidden/.test(blockStyle[`border${side}Style`])\n ? 0\n : parsePx(blockStyle[`border${side}Width`])) + parsePx(blockStyle[`padding${side}`])\n const cssSize = parsePx(blockStyle.fontSize, 16)\n const blockSize = cssSize * pretextScale\n const [bAscent, bDescent] = fontMetrics(\n context,\n canvasFont(blockStyle, blockSize),\n blockSize,\n )\n const ascent = bAscent / pretextScale\n const fontHeight = ascent + bDescent / pretextScale\n const lineHeight = parsePx(blockStyle.lineHeight, fontHeight, cssSize)\n const lineUnits = Math.round(lineHeight * pretextScale * 64)\n const lineLayout =\n Math.abs(lineUnits / 64 - lineHeight * pretextScale) < 1e-3\n ? lineUnits / 64\n : lineHeight * pretextScale\n const leading = lineLayout - bAscent - bDescent\n bm = [\n inset('Left'),\n inset('Right'),\n inset('Top'),\n lineHeight,\n Math.floor(leading / 2) / pretextScale + ascent,\n /pre(?!-l)|bre/.test(blockStyle.whiteSpace) ? 'pre-wrap' : 'normal',\n blockStyle.wordBreak === 'keep-all' ? 'keep-all' : 'normal',\n ]\n blockStyleCache.set(blockStyle, bm)\n }\n const [insetLeft, insetRight, insetTop, lineHeight, baselineOffset, whiteSpace, wordBreak] =\n bm\n const contentWidth = Math.max(1, blockRect.width - insetLeft - insetRight)\n const contentLeft = blockRect.left - rootRect.left + insetLeft\n const contentTop = blockRect.top - rootRect.top + insetTop\n for (const segment of segments)\n for (const { inline } of segment) {\n if (runMetrics.has(inline.font)) continue\n const size = inline.font.size * pretextScale\n const [mAscent, mDescent] = fontMetrics(\n context,\n inline.font.canvasFont.replace(`${bakeSize}px`, `${size}px`),\n size,\n )\n runMetrics.set(inline.font, [mAscent / pretextScale, mDescent / pretextScale])\n }\n let lines = 0\n let lineIndex = 0\n let measuredFont = ''\n let afterSpace = true\n let joined = false\n const justified = align === 'justify' || lastAlign === 'justify'\n for (let segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {\n const segment = segments[segmentIndex]!\n if (segment.length === 0) {\n if (segments.length > 1) lineIndex++\n continue\n }\n let hardPending = segmentIndex > 0\n let previousBreakCharacter = ''\n let prepKey = `${contentWidth}|${whiteSpace}|${wordBreak}`\n for (const s of segment) prepKey += `\\u0001${s.font}\\u0002${s.letterSpacing}\\u0002${s.text}`\n let materializedLines = lineCache.get(prepKey)\n if (!materializedLines) {\n const prepared = prepareRichInline(segment, { whiteSpace, wordBreak })\n materializedLines = []\n walkRichInlineLineRanges(prepared, contentWidth, (lineRange) =>\n materializedLines!.push(materializeRichInlineLineRange(prepared, lineRange)),\n )\n lineCache.set(prepKey, materializedLines)\n }\n for (let rangeIndex = 0; rangeIndex < materializedLines.length; rangeIndex++) {\n const line = materializedLines[rangeIndex]!\n const lineAlign = rangeIndex < materializedLines.length - 1 ? align : lastAlign\n const slack = contentWidth - line.width\n const baselineCss = contentTop + baselineOffset + lineIndex * lineHeight\n lines++\n let penX =\n contentLeft + (lineAlign === 'center' ? slack * 0.5 : lineAlign === 'right' ? slack : 0)\n let sequence = 0\n let linePrevious: MutableGlyph | undefined\n const lineStart = glyphs.length\n\n for (const fragment of line.fragments) {\n const item = segment[fragment.itemIndex]\n if (!item) continue\n const { inline } = item\n if (fragment.gapBefore > 0) {\n previousBreakCharacter = ''\n afterSpace = true\n }\n penX += fragment.gapBefore\n if (measuredFont !== inline.layoutFont) {\n context.font = measuredFont = inline.layoutFont\n }\n const [runAscent, runDescent] = runMetrics.get(inline.font)!\n const descent = runDescent * invScale\n const lineBottom = (rootRect.height - baselineCss) * invScale - descent\n const top = rootRect.top + baselineCss - runAscent\n const bottom = rootRect.top + baselineCss + descent / invScale\n includeTextBox({\n left: rootRect.left + penX,\n top,\n bottom,\n width: fragment.occupiedWidth,\n height: bottom - top,\n })\n let previousCharacter = ''\n let previousCode = -1\n let runWidth = 0\n let renderedCharacters = 0\n\n const [advances, ascii] = acquireFontEntry(fontMetricsCache, inline.layoutFont)\n let emojiFragment = false\n const emitCharacter = (character: string, code: number, isAscii: boolean): void => {\n let loneAdvance = isAscii ? ascii[code]! : NaN\n if (Number.isNaN(loneAdvance)) {\n loneAdvance = measureAdvance(advances, '', character)\n if (isAscii) ascii[code] = loneAdvance\n }\n let advance = loneAdvance\n if (previousCharacter) {\n if (isAscii && previousCode >= 0 && previousCode < 128) {\n const pairIdx = ((previousCode + 1) << 7) | code\n advance = ascii[pairIdx]!\n if (Number.isNaN(advance)) {\n ascii[pairIdx] = advance =\n context.measureText(previousCharacter + character).width -\n ascii[previousCode]!\n }\n } else {\n advance = measureAdvance(advances, previousCharacter, character)\n }\n }\n const kerning = advance - loneAdvance\n if (emojiFragment && isEmojiGrapheme(character)) {\n if (Number.isNaN(ascii[16512]!)) {\n const probe = prepareRichInline([{ text: '\\u{1F600}', font: inline.layoutFont }])\n let corrected = 0\n walkRichInlineLineRanges(probe, 1e6, (probeLine) => {\n corrected = probeLine.width\n })\n context.font = measuredFont = inline.layoutFont\n ascii[16512] = Math.max(0, context.measureText('\\u{1F600}').width - corrected)\n }\n advance -= ascii[16512]!\n }\n const spacing = renderedCharacters > 0 ? inline.letterSpacing : 0\n const nextWidth = runWidth + spacing + advance\n if (\n code <= 32\n ? code === 32 || (code >= 9 && code <= 13)\n : code >= 0x85 && /^\\s$/u.test(character)\n ) {\n if (code === 0xa0) joined = true\n else if (!/[\\u2007\\u202f\\ufeff]/.test(character)) afterSpace = true\n previousBreakCharacter = ''\n runWidth = nextWidth\n previousCharacter = character\n previousCode = code\n renderedCharacters++\n return\n }\n const key = requestKey(inline.font, inline.keys, character)\n const isCjkSoft =\n options.cjkLineBreaking === true && canBreakCjk(previousBreakCharacter, character)\n const originX = (penX + runWidth + spacing + kerning) * invScale\n if (linePrevious) {\n if (afterSpace || isCjkSoft || joined)\n linePrevious.decorationWidth ??= linePrevious.advance\n linePrevious.advance = originX - linePrevious.originX\n }\n const glyph: MutableGlyph = {\n glyphKey: key,\n fontSize: inline.fontSize,\n originX,\n lineBottom,\n baselineOffset: descent,\n advance: (nextWidth - runWidth - kerning) * invScale,\n block: blockIndex,\n breakBefore: hardPending\n ? 'hard'\n : afterSpace || sequence === 0 || isCjkSoft\n ? 'soft'\n : 'none',\n clip,\n color: inline.color,\n sequence,\n z: inline.z,\n }\n if (isCjkSoft) glyph.gapBefore = 0\n else if (linePrevious ? (afterSpace || joined) && justified : rangeIndex > 0)\n glyph.gapBefore = linePrevious\n ? linePrevious.advance - linePrevious.decorationWidth!\n : (measureAdvance(advances, '', ' ') + inline.letterSpacing) * invScale\n if (inline.decorations.length) {\n glyph.decorations = inline.decorations\n glyph.decorationWidth = glyph.advance\n }\n glyphs.push(glyph)\n linePrevious = glyph\n hardPending = false\n if (options.cjkLineBreaking) previousBreakCharacter = character\n afterSpace = joined = false\n sequence++\n runWidth = nextWidth\n previousCharacter = character\n previousCode = code\n renderedCharacters++\n }\n const text = fragment.text\n const textLen = text.length\n let index = 0\n while (index < textLen) {\n const code = text.charCodeAt(index)\n if (code >= 128) break\n if (index + 1 < textLen && (text.charCodeAt(index + 1) >= 128 || code === 13)) break\n emitCharacter(ASCII_CHARS[code]!, code, true)\n index++\n }\n if (index < textLen) {\n const tail = index === 0 ? text : text.slice(index)\n emojiFragment = isEmojiGrapheme(tail)\n for (const character of glyphClusters(tail)) {\n const code = character.length === 1 ? character.charCodeAt(0) : -1\n emitCharacter(character, code, code >= 0 && code < 128)\n }\n }\n penX += fragment.occupiedWidth\n }\n if (lineAlign === 'justify' && slack > 0) {\n let spaces = 0\n for (let i = lineStart + 1; i < glyphs.length; i++)\n if (glyphs[i]!.gapBefore !== undefined) spaces++\n const share = (slack * invScale) / spaces\n for (let i = lineStart + 1, k = 0; spaces && i < glyphs.length; i++) {\n if (glyphs[i]!.gapBefore !== undefined) {\n k++\n glyphs[i - 1]!.advance += share\n }\n glyphs[i]!.originX += k * share\n }\n }\n afterSpace = true\n lineIndex++\n }\n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