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/clusters.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clusters.js","names":[],"sources":["../../src/dom/clusters.ts"],"sourcesContent":["// Hint-free prose keeps the native string iterator and allocates nothing.\nconst EMOJI_SEQUENCE_HINT =\n /\\u200D|\\u20E3|\\uFE0E|\\uFE0F|[\\u{1F1E6}-\\u{1F1FF}]|[\\u{1F3FB}-\\u{1F3FF}]|[\\u{E0020}-\\u{E007F}]/u\nconst EMOJI_SEQUENCE = /\\p{Extended_Pictographic}|\\p{Regional_Indicator}|^[#*0-9]\\uFE0F?\\u20E3$/u\nlet graphemes: Intl.Segmenter | undefined\n\n/** @internal Code points, except that emoji grapheme sequences stay whole. */\nexport function glyphClusters(text: string): Iterable<string> {\n if (!EMOJI_SEQUENCE_HINT.test(text) || typeof Intl.Segmenter !== 'function') return text\n graphemes ??= new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n const result: string[] = []\n for (
|
|
1
|
+
{"version":3,"file":"clusters.js","names":[],"sources":["../../src/dom/clusters.ts"],"sourcesContent":["// Hint-free prose keeps the native string iterator and allocates nothing.\nconst EMOJI_SEQUENCE_HINT =\n /\\u200D|\\u20E3|\\uFE0E|\\uFE0F|[\\u{1F1E6}-\\u{1F1FF}]|[\\u{1F3FB}-\\u{1F3FF}]|[\\u{E0020}-\\u{E007F}]/u\nconst EMOJI_SEQUENCE = /\\p{Extended_Pictographic}|\\p{Regional_Indicator}|^[#*0-9]\\uFE0F?\\u20E3$/u\n// Every adjacent pair in these BMP ranges has a grapheme break. They contain printable\n// Latin text, CJK punctuation, kana, Han and complete Hangul syllables (no joining jamo).\nconst SIMPLE_RUN =\n /[ -~\\u00c0-\\u024f\\u3000-\\u301f\\u3041-\\u3096\\u30a1-\\u30ff\\u3400-\\u4dbf\\u4e00-\\u9fff\\uac00-\\ud7a3\\uff01-\\uff5e]{32,}/g\nlet graphemes: Intl.Segmenter | undefined\n\nfunction appendGraphemes(result: string[], segmenter: Intl.Segmenter, text: string): void {\n for (const { segment } of segmenter.segment(text)) {\n if (segment.length > 1 && EMOJI_SEQUENCE.test(segment)) result.push(segment)\n else for (const point of segment) result.push(point)\n }\n}\n\n/** @internal Code points, except that emoji grapheme sequences stay whole. */\nexport function glyphClusters(text: string): Iterable<string> {\n if (!EMOJI_SEQUENCE_HINT.test(text) || typeof Intl.Segmenter !== 'function') return text\n graphemes ??= new Intl.Segmenter(undefined, { granularity: 'grapheme' })\n const result: string[] = []\n // Segment both edges with their neighbours for prepend marks, keycaps and joining jamo.\n let start = 0\n if (text.length >= 32) {\n for (const run of text.matchAll(SIMPLE_RUN)) {\n const end = run.index + run[0].length - 1\n appendGraphemes(result, graphemes, text.slice(start, run.index + 1))\n for (let i = run.index + 1; i < end; i++) result.push(text[i]!)\n start = end\n }\n }\n appendGraphemes(result, graphemes, text.slice(start))\n return result\n}\n\nconst nonAscii = (text: string): boolean => text.length > 1 || text.charCodeAt(0) >= 0xa9\n\n/** @internal Matches Pretext's emoji width-correction predicate. */\nexport function isEmojiGrapheme(text: string): boolean {\n return nonAscii(text) && /\\p{Emoji_Presentation}|\\uFE0F/u.test(text)\n}\n\n/** @internal Broad candidate predicate shared by capture and colour rasterization. */\nexport function isEmojiCandidate(text: string): boolean {\n return (\n nonAscii(text) && /[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3\\uFE0F]/u.test(text)\n )\n}\n"],"mappings":";AACA,IAAM,sBACJ;AACF,IAAM,iBAAiB;AAGvB,IAAM,aACJ;AACF,IAAI;AAEJ,SAAS,gBAAgB,QAAkB,WAA2B,MAAoB;CACxF,KAAK,MAAM,EAAE,aAAa,UAAU,QAAQ,IAAI,GAC9C,IAAI,QAAQ,SAAS,KAAK,eAAe,KAAK,OAAO,GAAG,OAAO,KAAK,OAAO;MACtE,KAAK,MAAM,SAAS,SAAS,OAAO,KAAK,KAAK;AAEvD;;AAGA,SAAgB,cAAc,MAAgC;CAC5D,IAAI,CAAC,oBAAoB,KAAK,IAAI,KAAK,OAAO,KAAK,cAAc,YAAY,OAAO;CACpF,cAAc,IAAI,KAAK,UAAU,KAAA,GAAW,EAAE,aAAa,WAAW,CAAC;CACvE,MAAM,SAAmB,CAAC;CAE1B,IAAI,QAAQ;CACZ,IAAI,KAAK,UAAU,IACjB,KAAK,MAAM,OAAO,KAAK,SAAS,UAAU,GAAG;EAC3C,MAAM,MAAM,IAAI,QAAQ,IAAI,EAAE,CAAC,SAAS;EACxC,gBAAgB,QAAQ,WAAW,KAAK,MAAM,OAAO,IAAI,QAAQ,CAAC,CAAC;EACnE,KAAK,IAAI,IAAI,IAAI,QAAQ,GAAG,IAAI,KAAK,KAAK,OAAO,KAAK,KAAK,EAAG;EAC9D,QAAQ;CACV;CAEF,gBAAgB,QAAQ,WAAW,KAAK,MAAM,KAAK,CAAC;CACpD,OAAO;AACT;AAEA,IAAM,YAAY,SAA0B,KAAK,SAAS,KAAK,KAAK,WAAW,CAAC,KAAK;;AAGrF,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,SAAS,IAAI,KAAK,iCAAiC,KAAK,IAAI;AACrE;;AAGA,SAAgB,iBAAiB,MAAuB;CACtD,OACE,SAAS,IAAI,KAAK,iEAAiE,KAAK,IAAI;AAEhG"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SdfDropShadowOptions, SdfOutlineOptions } from '../types.js';
|
|
2
|
+
export type CssColorParser = (document: Document, value: string) => [number, number, number, number] | null;
|
|
3
|
+
export declare function parseCssTextShadow(document: Document, parseColor: CssColorParser, style: CSSStyleDeclaration, fontSize: number, invScale: number, opacity: number): SdfDropShadowOptions | undefined;
|
|
4
|
+
export declare function parseCssTextStroke(document: Document, parseColor: CssColorParser, style: CSSStyleDeclaration, fontSize: number, invScale: number, opacity: number): SdfOutlineOptions | undefined;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// src/dom/cssEffects.ts
|
|
2
|
+
var LENGTH_TOKEN_RE = /^-?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?(?:px|em|rem|%)?$/i;
|
|
3
|
+
function parsePx(value, ref = 0) {
|
|
4
|
+
const parsed = Number.parseFloat(value);
|
|
5
|
+
return !Number.isFinite(parsed) ? 0 : ref && value.endsWith("%") ? parsed * ref / 100 : ref && (value.endsWith("em") || !/[a-z]/i.test(value)) ? parsed * ref : parsed;
|
|
6
|
+
}
|
|
7
|
+
function parseEffectColor(document, parseColor, value, opacity) {
|
|
8
|
+
const trimmed = value.trim();
|
|
9
|
+
if (!trimmed || /^transparent$/i.test(trimmed)) return null;
|
|
10
|
+
const rgba = parseColor(document, trimmed);
|
|
11
|
+
if (rgba) {
|
|
12
|
+
const alpha = Math.min(1, Math.max(0, rgba[3] * opacity));
|
|
13
|
+
return alpha <= 0 ? null : [(Math.round(Math.min(1, Math.max(0, rgba[0])) * 255) << 16 | Math.round(Math.min(1, Math.max(0, rgba[1])) * 255) << 8 | Math.round(Math.min(1, Math.max(0, rgba[2])) * 255)) >>> 0, alpha];
|
|
14
|
+
}
|
|
15
|
+
return opacity <= 0 ? null : [trimmed, Math.min(1, Math.max(0, opacity))];
|
|
16
|
+
}
|
|
17
|
+
function parseLengthsAndColor(raw, fontSize, invScale, stopAtComma) {
|
|
18
|
+
const lengths = [];
|
|
19
|
+
const colors = [];
|
|
20
|
+
let depth = 0;
|
|
21
|
+
let start = 0;
|
|
22
|
+
for (let i = 0; i <= raw.length; i++) {
|
|
23
|
+
const ch = raw[i];
|
|
24
|
+
if (ch === "(") depth++;
|
|
25
|
+
else if (ch === ")") depth = Math.max(0, depth - 1);
|
|
26
|
+
else if (depth === 0 && (i === raw.length || ch === "," || /\s/.test(ch))) {
|
|
27
|
+
if (i > start) {
|
|
28
|
+
const tok = raw.slice(start, i);
|
|
29
|
+
if (LENGTH_TOKEN_RE.test(tok)) lengths.push(parsePx(tok, fontSize) * invScale);
|
|
30
|
+
else colors.push(tok);
|
|
31
|
+
}
|
|
32
|
+
start = i + 1;
|
|
33
|
+
if (stopAtComma && ch === ",") break;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return [lengths, colors.join(" ")];
|
|
37
|
+
}
|
|
38
|
+
function parseCssTextShadow(document, parseColor, style, fontSize, invScale, opacity) {
|
|
39
|
+
const raw = style.textShadow.trim();
|
|
40
|
+
if (!raw || raw === "none") return void 0;
|
|
41
|
+
const [lengths, colorStr] = parseLengthsAndColor(raw, fontSize, invScale, true);
|
|
42
|
+
if (lengths.length < 2) return void 0;
|
|
43
|
+
const parsedColor = parseEffectColor(document, parseColor, colorStr || style.color || "#000", opacity);
|
|
44
|
+
if (!parsedColor) return void 0;
|
|
45
|
+
const blur = Math.max(0, lengths[2] ?? 0);
|
|
46
|
+
return {
|
|
47
|
+
offsetX: lengths[0],
|
|
48
|
+
offsetY: -lengths[1],
|
|
49
|
+
...blur > 0 ? { blur } : {},
|
|
50
|
+
color: parsedColor[0],
|
|
51
|
+
opacity: parsedColor[1]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function parseCssTextStroke(document, parseColor, style, fontSize, invScale, opacity) {
|
|
55
|
+
let width = parsePx(style.webkitTextStrokeWidth || style.getPropertyValue("-webkit-text-stroke-width"), fontSize) * invScale;
|
|
56
|
+
let rawColor = style.webkitTextStrokeColor || style.getPropertyValue("-webkit-text-stroke-color");
|
|
57
|
+
if (!(width > 0) && style.webkitTextStroke) {
|
|
58
|
+
const [lengths, colorStr] = parseLengthsAndColor(style.webkitTextStroke.trim(), fontSize, invScale, false);
|
|
59
|
+
width = lengths[0] ?? 0;
|
|
60
|
+
if (colorStr) rawColor = colorStr;
|
|
61
|
+
}
|
|
62
|
+
if (!(width > 0)) return void 0;
|
|
63
|
+
const parsedColor = parseEffectColor(document, parseColor, rawColor || style.color || "#000", opacity);
|
|
64
|
+
return parsedColor ? {
|
|
65
|
+
width,
|
|
66
|
+
color: parsedColor[0],
|
|
67
|
+
opacity: parsedColor[1]
|
|
68
|
+
} : void 0;
|
|
69
|
+
}
|
|
70
|
+
export { parseCssTextShadow, parseCssTextStroke };
|
|
71
|
+
|
|
72
|
+
//# sourceMappingURL=cssEffects.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssEffects.js","names":[],"sources":["../../src/dom/cssEffects.ts"],"sourcesContent":["import type { SdfDropShadowOptions, SdfOutlineOptions } from '../types.js'\n\nexport type CssColorParser = (\n document: Document,\n value: string,\n) => [number, number, number, number] | null\n\nconst LENGTH_TOKEN_RE = /^-?(?:\\d+\\.?\\d*|\\.\\d+)(?:e[+-]?\\d+)?(?:px|em|rem|%)?$/i\n\nfunction parsePx(value: string | null | undefined, ref = 0): number {\n const parsed = Number.parseFloat(value!)\n return !Number.isFinite(parsed)\n ? 0\n : ref && value!.endsWith('%')\n ? (parsed * ref) / 100\n : ref && (value!.endsWith('em') || !/[a-z]/i.test(value!))\n ? parsed * ref\n : parsed\n}\n\nfunction parseEffectColor(\n document: Document,\n parseColor: CssColorParser,\n value: string,\n opacity: number,\n): readonly [number | string, number] | null {\n const trimmed = value.trim()\n if (!trimmed || /^transparent$/i.test(trimmed)) return null\n const rgba = parseColor(document, trimmed)\n if (rgba) {\n const alpha = Math.min(1, Math.max(0, rgba[3] * opacity))\n return alpha <= 0\n ? null\n : [\n ((Math.round(Math.min(1, Math.max(0, rgba[0])) * 255) << 16) |\n (Math.round(Math.min(1, Math.max(0, rgba[1])) * 255) << 8) |\n Math.round(Math.min(1, Math.max(0, rgba[2])) * 255)) >>>\n 0,\n alpha,\n ]\n }\n return opacity <= 0 ? null : [trimmed, Math.min(1, Math.max(0, opacity))]\n}\n\nfunction parseLengthsAndColor(\n raw: string,\n fontSize: number,\n invScale: number,\n stopAtComma: boolean,\n): readonly [number[], string] {\n const lengths: number[] = []\n const colors: string[] = []\n let depth = 0\n let start = 0\n for (let i = 0; i <= raw.length; i++) {\n const ch = raw[i]\n if (ch === '(') depth++\n else if (ch === ')') depth = Math.max(0, depth - 1)\n else if (depth === 0 && (i === raw.length || ch === ',' || /\\s/.test(ch!))) {\n if (i > start) {\n const tok = raw.slice(start, i)\n if (LENGTH_TOKEN_RE.test(tok)) lengths.push(parsePx(tok, fontSize) * invScale)\n else colors.push(tok)\n }\n start = i + 1\n if (stopAtComma && ch === ',') break\n }\n }\n return [lengths, colors.join(' ')]\n}\n\nexport function parseCssTextShadow(\n document: Document,\n parseColor: CssColorParser,\n style: CSSStyleDeclaration,\n fontSize: number,\n invScale: number,\n opacity: number,\n): SdfDropShadowOptions | undefined {\n const raw = style.textShadow.trim()\n if (!raw || raw === 'none') return undefined\n const [lengths, colorStr] = parseLengthsAndColor(raw, fontSize, invScale, true)\n if (lengths.length < 2) return undefined\n const parsedColor = parseEffectColor(\n document,\n parseColor,\n colorStr || style.color || '#000',\n opacity,\n )\n if (!parsedColor) return undefined\n const blur = Math.max(0, lengths[2] ?? 0)\n return {\n offsetX: lengths[0]!,\n offsetY: -lengths[1]!,\n ...(blur > 0 ? { blur } : {}),\n color: parsedColor[0],\n opacity: parsedColor[1],\n }\n}\n\nexport function parseCssTextStroke(\n document: Document,\n parseColor: CssColorParser,\n style: CSSStyleDeclaration,\n fontSize: number,\n invScale: number,\n opacity: number,\n): SdfOutlineOptions | undefined {\n let width =\n parsePx(\n style.webkitTextStrokeWidth || style.getPropertyValue('-webkit-text-stroke-width'),\n fontSize,\n ) * invScale\n let rawColor = style.webkitTextStrokeColor || style.getPropertyValue('-webkit-text-stroke-color')\n if (!(width > 0) && style.webkitTextStroke) {\n const [lengths, colorStr] = parseLengthsAndColor(\n style.webkitTextStroke.trim(),\n fontSize,\n invScale,\n false,\n )\n width = lengths[0] ?? 0\n if (colorStr) rawColor = colorStr\n }\n if (!(width > 0)) return undefined\n const parsedColor = parseEffectColor(\n document,\n parseColor,\n rawColor || style.color || '#000',\n opacity,\n )\n return parsedColor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C,SAAS,YAAY,qBAC1B,MAAM,iBAAiB,KAAK,GAC5B,UACA,UACA,KACF;EACA,QAAQ,QAAQ,MAAM;EACtB,IAAI,UAAU,WAAW;CAC3B;CACA,IAAI,EAAE,QAAQ,IAAI,OAAO,KAAA;CACzB,MAAM,cAAc,iBAClB,UACA,YACA,YAAY,MAAM,SAAS,QAC3B,OACF;CACA,OAAO,cAAc;EAAE;EAAO,OAAO,YAAY;EAAI,SAAS,YAAY;CAAG,IAAI,KAAA;AACnF"}
|
|
@@ -5,7 +5,6 @@ import type { TracedOutlines } from '../windfoil/tracedOutlines.js';
|
|
|
5
5
|
import type * as SlugRuntime from '../slug/runtime.js';
|
|
6
6
|
import type * as WindfoilRuntime from '../windfoil/runtime.js';
|
|
7
7
|
import type * as TracedOutlinesModule from '../windfoil/tracedOutlines.js';
|
|
8
|
-
import type { RasterizeOptions } from '../atlas/rasterize.js';
|
|
9
8
|
import { type GlyphTextMaterial } from '../text/GlyphTextMaterial.js';
|
|
10
9
|
import type { ReflowState } from '../text/reflow.js';
|
|
11
10
|
import type * as ReflowModule from '../text/reflow.js';
|
|
@@ -20,7 +19,7 @@ export interface AnalyticBuildCallbacks {
|
|
|
20
19
|
readonly preloadBackend: Promise<typeof SlugRuntime | typeof WindfoilRuntime | null> | null;
|
|
21
20
|
readonly preloadTraced: Promise<typeof TracedOutlinesModule | null> | null;
|
|
22
21
|
readonly loadTraced: () => Promise<typeof TracedOutlinesModule>;
|
|
23
|
-
readonly buildAtlas: (requests: DomLayoutSnapshot['requests'], signal: AbortSignal, appendable?:
|
|
22
|
+
readonly buildAtlas: (requests: DomLayoutSnapshot['requests'], signal: AbortSignal, appendable?: boolean | 'headroom') => Promise<SdfAtlas>;
|
|
24
23
|
}
|
|
25
24
|
export declare function buildDomAnalyticBackend(renderer: WebGPURenderer, doc: Document, snapshot: DomLayoutSnapshot, opts: DomSdfOptions, backendKind: 'windfoil' | 'slug', analytic: WindfoilOptions, headroom: boolean, existingTraced: TracedOutlines | null, resetAtlas: boolean, signal: AbortSignal, throwIfAborted: (s: AbortSignal) => void, callbacks: AnalyticBuildCallbacks): Promise<AnalyticRetainedResult>;
|
|
26
25
|
export declare function loadMixedExtras(): Promise<{
|
package/dist/dom/domAnalytic.js
CHANGED
|
@@ -232,7 +232,7 @@ function reflowAnalytic(snapshot, retained, content, width, motion, rm, reflowSt
|
|
|
232
232
|
if (retained.companion || retained.color) {
|
|
233
233
|
if (!content.u(reflowed, retained, motion)) throw new Error("DomSdf.reflow: incompatible retained content");
|
|
234
234
|
} else {
|
|
235
|
-
let maxSequence = retained.
|
|
235
|
+
let maxSequence = retained.reflowGeometry(content.tg, reflowed, strength);
|
|
236
236
|
if (maxSequence === null) {
|
|
237
237
|
const built = retained.createGeometry(reflowed, strength);
|
|
238
238
|
content.rg(built.geometry);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domAnalytic.js","names":[],"sources":["../../src/dom/domAnalytic.ts"],"sourcesContent":["import { Group, Mesh, type InstancedBufferGeometry, type WebGPURenderer } from 'three/webgpu'\n\nimport type { createExtraTextParts } from '../windfoil/mixed.js'\nimport type { WindfoilBackend, WindfoilBuildOptions } from '../windfoil/runtime.js'\nimport type { TracedOutlines } from '../windfoil/tracedOutlines.js'\nimport type * as SlugRuntime from '../slug/runtime.js'\nimport type * as WindfoilRuntime from '../windfoil/runtime.js'\nimport type * as TracedOutlinesModule from '../windfoil/tracedOutlines.js'\nimport type { RasterizeOptions } from '../atlas/rasterize.js'\nimport { isAnimatedMotion, type GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport { hasDecorations } from '../text/geometryUtils.js'\nimport type { ReflowState } from '../text/reflow.js'\nimport type * as ReflowModule from '../text/reflow.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n DomSdfOptions,\n SdfAtlas,\n SdfMotionOptions,\n WindfoilOptions,\n} from '../types.js'\nimport type * as DomExtrasModule from './domExtras.js'\nimport type { ContentExtrasController, StagedExtras } from './domExtras.js'\n\nexport interface AnalyticRetainedResult {\n readonly retained: WindfoilBackend | null\n readonly traced: TracedOutlines | null\n}\n\nexport interface AnalyticBuildCallbacks {\n readonly preloadBackend: Promise<typeof SlugRuntime | typeof WindfoilRuntime | null> | null\n readonly preloadTraced: Promise<typeof TracedOutlinesModule | null> | null\n readonly loadTraced: () => Promise<typeof TracedOutlinesModule>\n readonly buildAtlas: (\n requests: DomLayoutSnapshot['requests'],\n signal: AbortSignal,\n appendable?: RasterizeOptions['appendable'],\n ) => Promise<SdfAtlas>\n}\n\nexport async function buildDomAnalyticBackend(\n renderer: WebGPURenderer,\n doc: Document,\n snapshot: DomLayoutSnapshot,\n opts: DomSdfOptions,\n backendKind: 'windfoil' | 'slug',\n analytic: WindfoilOptions,\n headroom: boolean,\n existingTraced: TracedOutlines | null,\n resetAtlas: boolean,\n signal: AbortSignal,\n throwIfAborted: (s: AbortSignal) => void,\n callbacks: AnalyticBuildCallbacks,\n): Promise<AnalyticRetainedResult> {\n const outlineProvider: unknown = analytic.outlineProvider\n if (outlineProvider !== undefined && typeof outlineProvider !== 'function') {\n throw new TypeError(\n `DomSdf: textBackend \"${backendKind}\" requires ${backendKind}.outlineProvider`,\n )\n }\n let traced = existingTraced\n let resolved: WindfoilBuildOptions\n if (analytic.outlineProvider) {\n resolved = { ...analytic, outlineProvider: analytic.outlineProvider }\n } else {\n if (!traced) {\n const { createTracedOutlineProvider } =\n (await callbacks.preloadTraced) ?? (await callbacks.loadTraced())\n throwIfAborted(signal)\n traced ??= createTracedOutlineProvider(\n doc,\n opts.colorGlyphs === undefined ? {} : { colorGlyphs: opts.colorGlyphs },\n )\n } else if (resetAtlas) {\n traced.clear()\n }\n resolved = {\n ...analytic,\n fallback: analytic.fallback ?? 'sdf-glyphs',\n outlineProvider: traced.provider,\n }\n }\n const build =\n backendKind === 'slug'\n ? (\n ((await callbacks.preloadBackend) as typeof SlugRuntime | null) ??\n (await import('../slug/runtime.js'))\n ).buildSlugBackend\n : (\n ((await callbacks.preloadBackend) as typeof WindfoilRuntime | null) ??\n (await import('../windfoil/runtime.js'))\n ).buildWindfoilBackend\n const retained = await build(renderer, snapshot.requests, resolved, signal, {\n build: callbacks.buildAtlas,\n effects: opts,\n headroom,\n })\n return { retained, traced }\n}\n\nexport function loadMixedExtras(): Promise<{ createExtraTextParts: typeof createExtraTextParts }> {\n return import('../windfoil/mixed.js')\n}\n\nexport interface AnalyticContentBundle {\n readonly g: Group\n readonly m: GlyphTextMaterial\n readonly tg: InstancedBufferGeometry\n readonly a: boolean\n sm(change: SdfMotionOptions, live: SdfMotionOptions): void\n st(tone: ResolvedTextTone | null): boolean\n ud(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, motion: SdfMotionOptions): void\n rg(geometry: InstancedBufferGeometry): void\n u(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n motion: SdfMotionOptions,\n tone?: ResolvedTextTone | null,\n ): boolean\n d(): void\n}\n\nconst maxSeq = (s: DomLayoutSnapshot): number =>\n s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0)\n\nexport function createAnalyticContent(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n options: DomSdfOptions,\n motion: SdfMotionOptions,\n tone: ResolvedTextTone | null,\n makeExtraParts?: typeof createExtraTextParts,\n extrasMod?: typeof DomExtrasModule | null,\n): AnalyticContentBundle {\n const materialOptions = { ...options, tone: tone ?? (false as const) }\n const group = new Group()\n group.name = 'ultra-text generated DOM content'\n group.matrixAutoUpdate = false\n group.updateMatrix()\n\n const strength = motion.strength ?? 18\n let animated = isAnimatedMotion(motion)\n const materialMotion = (live: SdfMotionOptions): SdfMotionOptions | false =>\n animated ? live : false\n const { geometry: glyphGeometry, maxSequence } = backend.createGeometry(snapshot, strength)\n const hasExtras = !!(backend.companion ?? backend.color)\n const usesColor = (layout: DomLayoutSnapshot): boolean =>\n !!backend.companion?.colorLayer &&\n (options.colorGlyphs !== 'none' || layout.requests.some((request) => request.shape?.bitmap))\n const colorEnabled = usesColor(snapshot)\n const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence\n let textMaterial: GlyphTextMaterial\n try {\n textMaterial = backend.createMaterial({\n ...materialOptions,\n maxSequence: hasExtras ? globalSequence : maxSequence,\n motion: materialMotion(motion),\n })\n } catch (error) {\n glyphGeometry.dispose()\n throw error\n }\n let extras: ReturnType<typeof createExtraTextParts> | undefined\n try {\n if (hasExtras)\n extras = makeExtraParts!(snapshot, backend, materialOptions, materialMotion(motion), strength)\n } catch (error) {\n glyphGeometry.dispose()\n textMaterial.dispose()\n throw error\n }\n const text = new Mesh(glyphGeometry, textMaterial)\n text.name = 'ultra-text text'\n text.castShadow = options.castShadow !== false\n text.frustumCulled = false\n text.renderOrder = 2\n text.matrixAutoUpdate = false\n text.updateMatrix()\n group.add(text)\n\n const ownedMeshes: Mesh[] = [text]\n const disposeMeshes = (): void => {\n for (const mesh of ownedMeshes) {\n mesh.geometry.dispose()\n for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material])\n material.dispose()\n }\n ownedMeshes.length = 0\n group.clear()\n }\n try {\n if (extras) {\n for (const mesh of extras.meshes) {\n group.add(mesh)\n ownedMeshes.push(mesh)\n }\n extras.mergeRects(snapshot, text.geometry)\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n const glyphDrawable = (retained: WindfoilBackend, key: string): boolean =>\n (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key)\n let ce: ContentExtrasController | null = null\n try {\n if (extrasMod) {\n ce = extrasMod.createContentExtras(\n snapshot,\n text.geometry,\n group,\n ownedMeshes,\n options,\n () => animated,\n motion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(backend, key),\n )\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n\n const swapGeometry = (mesh: Mesh, geometry: InstancedBufferGeometry): void => {\n const previous = mesh.geometry\n mesh.geometry = geometry\n previous.dispose()\n }\n const setTone = (next: ResolvedTextTone | null): boolean => {\n if (!textMaterial.setTone(next)) return false\n for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next)\n return true\n }\n const toneFits = (next: ResolvedTextTone | null): boolean => {\n const current = textMaterial.tone\n return current && next ? current.fits(next) : !current && !next\n }\n\n let disposed = false\n return {\n g: group,\n get m(): GlyphTextMaterial {\n return textMaterial\n },\n get a(): boolean {\n return animated\n },\n sm(change, live) {\n if (animated) {\n textMaterial.setMotion(change)\n extras?.setMotion(change)\n ce?.setMotion(change)\n return\n }\n if (!isAnimatedMotion(live)) return\n const decMesh = ce?.decMesh()\n const meshes: Mesh<InstancedBufferGeometry, GlyphTextMaterial>[] = [\n text,\n ...(extras?.meshes ?? []),\n ...(decMesh ? [decMesh] : []),\n ]\n const twins: GlyphTextMaterial[] = []\n try {\n for (const mesh of meshes) twins.push(mesh.material.withMotion(live))\n } catch (error) {\n for (const twin of twins) twin.dispose()\n throw error\n }\n meshes.forEach((mesh, index) => {\n const previous = mesh.material\n mesh.material = twins[index]!\n previous.dispose()\n })\n textMaterial = twins[0]!\n animated = true\n },\n st: setTone,\n ud(layout, retained, liveMotion) {\n ce?.updateDec(\n layout,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(retained, key),\n )\n },\n get tg(): InstancedBufferGeometry {\n return text.geometry\n },\n rg(geometry) {\n swapGeometry(text, geometry)\n },\n u(nextSnapshot, nextBackend, liveMotion, nextTone) {\n if (\n nextTone !== undefined &&\n (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))\n )\n return false\n if (hasExtras && !extras!.fitsMotion(nextSnapshot)) return false\n if (colorEnabled !== usesColor(nextSnapshot)) return false\n if (\n ce\n ? !ce.fitsLayout(nextSnapshot)\n : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)\n )\n return false\n const strength = liveMotion.strength ?? 18\n const drawable = (key: string): boolean => glyphDrawable(nextBackend, key)\n const decorationsFit = ce ? ce.decorationsFit(nextSnapshot, drawable) : true\n if (hasExtras && !decorationsFit) return false\n const glyphsFit = decorationsFit && nextBackend.contentFits(text.geometry, nextSnapshot)\n let built: { geometry: InstancedBufferGeometry; maxSequence: number } | null = null\n let nextParts: readonly (InstancedBufferGeometry | null)[] = []\n let stagedExtras: StagedExtras | null = null\n const releaseStaged = (): void => {\n built?.geometry.dispose()\n for (const geometry of nextParts) geometry?.dispose()\n stagedExtras?.dispose()\n }\n try {\n nextParts = extras?.prepare(nextSnapshot, strength) ?? []\n if (!glyphsFit) built = nextBackend.createGeometry(nextSnapshot, strength)\n if (ce) {\n stagedExtras = ce.prepare(\n nextSnapshot,\n built?.geometry ?? text.geometry,\n animated,\n liveMotion,\n built?.maxSequence ?? textMaterial.maxSequence.value,\n decorationsFit,\n drawable,\n )\n }\n } catch (error) {\n releaseStaged()\n throw error\n }\n if (built) {\n swapGeometry(text, built.geometry)\n textMaterial.maxSequence.value = built.maxSequence\n } else {\n const maxSequence = nextBackend.updateGeometry(\n text.geometry,\n nextSnapshot,\n strength,\n undefined,\n true,\n )\n if (maxSequence === null) {\n releaseStaged()\n throw new Error('DomSdf: glyph buffers changed during the update')\n }\n textMaterial.maxSequence.value = maxSequence\n }\n if (extras) {\n extras.commit(nextParts, nextSnapshot, strength)\n textMaterial.maxSequence.value = maxSeq(nextSnapshot)\n extras.mergeRects(nextSnapshot, text.geometry)\n }\n ce?.commit(\n stagedExtras!,\n nextSnapshot,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n drawable,\n swapGeometry,\n )\n if (nextTone !== undefined) setTone(nextTone)\n return true\n },\n d() {\n if (disposed) return\n disposed = true\n disposeMeshes()\n },\n }\n}\n\nexport function reflowAnalytic(\n snapshot: DomLayoutSnapshot,\n retained: WindfoilBackend,\n content: AnalyticContentBundle,\n width: number,\n motion: SdfMotionOptions,\n rm: typeof ReflowModule,\n reflowState: ReflowState | null,\n): {\n readonly width: number\n readonly height: number\n readonly lines: number\n readonly state: ReflowState\n} {\n retained.setGlyphEm(!!content.m.tone?.dilates)\n const state = reflowState ?? rm.createReflowState(snapshot)\n const reflowed = rm.reflowSnapshotWithState(snapshot, width, state)\n const strength = motion.strength ?? 18\n if (retained.companion || retained.color) {\n if (!content.u(reflowed, retained, motion))\n throw new Error('DomSdf.reflow: incompatible retained content')\n } else {\n let maxSequence = retained.updateGeometry(content.tg, reflowed, strength)\n if (maxSequence === null) {\n const built = retained.createGeometry(reflowed, strength)\n content.rg(built.geometry)\n maxSequence = built.maxSequence\n }\n content.m.maxSequence.value = maxSequence\n content.ud(reflowed, retained, motion)\n }\n return { width: reflowed.width, height: reflowed.height, lines: reflowed.lineCount, state }\n}\n\nexport function countAnalyticStats(\n snapshot: DomLayoutSnapshot,\n windfoil: WindfoilBackend,\n): readonly [\n glyphs: number,\n shapes: number,\n colorGlyphs: number,\n fallbackGlyphs: number,\n switchableGlyphs: number,\n] {\n const glyphs = windfoil.companion?.glyphs\n const switchKeys = windfoil.sizeSwitch?.keys\n let glyphCount = 0\n let shapeCount = 0\n let colorGlyphCount = 0\n let fallbackGlyphCount = 0\n let switchableGlyphCount = 0\n for (const glyph of snapshot.glyphs) {\n if (switchKeys?.has(glyph.glyphKey)) switchableGlyphCount++\n if (glyph.shapeGroup !== undefined) {\n shapeCount++\n continue\n }\n glyphCount++\n const slot = glyphs?.get(glyph.glyphKey)\n if (slot && !windfoil.analyticCovers(glyph.glyphKey)) {\n if (slot.color) colorGlyphCount++\n fallbackGlyphCount++\n }\n }\n return [glyphCount, shapeCount, colorGlyphCount, fallbackGlyphCount, switchableGlyphCount]\n}\n"],"mappings":";;;;AAwCA,eAAsB,wBACpB,UACA,KACA,UACA,MACA,aACA,UACA,UACA,gBACA,YACA,QACA,gBACA,WACiC;CACjC,MAAM,kBAA2B,SAAS;CAC1C,IAAI,oBAAoB,KAAA,KAAa,OAAO,oBAAoB,YAC9D,MAAM,IAAI,UACR,wBAAwB,YAAY,aAAa,YAAY,iBAC/D;CAEF,IAAI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;GACxB,MAAM,QAAQ,SAAS,eAAe,UAAU,QAAQ;GACxD,QAAQ,GAAG,MAAM,QAAQ;GACzB,cAAc,MAAM;EACtB;EACA,QAAQ,EAAE,YAAY,QAAQ;EAC9B,QAAQ,GAAG,UAAU,UAAU,MAAM;CACvC;CACA,OAAO;EAAE,OAAO,SAAS;EAAO,QAAQ,SAAS;EAAQ,OAAO,SAAS;EAAW;CAAM;AAC5F;AAEA,SAAgB,mBACd,UACA,UAOA;CACA,MAAM,SAAS,SAAS,WAAW;CACnC,MAAM,aAAa,SAAS,YAAY;CACxC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,kBAAkB;CACtB,IAAI,qBAAqB;CACzB,IAAI,uBAAuB;CAC3B,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,IAAI,YAAY,IAAI,MAAM,QAAQ,GAAG;EACrC,IAAI,MAAM,eAAe,KAAA,GAAW;GAClC;GACA;EACF;EACA;EACA,MAAM,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACvC,IAAI,QAAQ,CAAC,SAAS,eAAe,MAAM,QAAQ,GAAG;GACpD,IAAI,KAAK,OAAO;GAChB;EACF;CACF;CACA,OAAO;EAAC;EAAY;EAAY;EAAiB;EAAoB;CAAoB;AAC3F"}
|
|
1
|
+
{"version":3,"file":"domAnalytic.js","names":[],"sources":["../../src/dom/domAnalytic.ts"],"sourcesContent":["import { Group, Mesh, type InstancedBufferGeometry, type WebGPURenderer } from 'three/webgpu'\n\nimport type { createExtraTextParts } from '../windfoil/mixed.js'\nimport type { WindfoilBackend, WindfoilBuildOptions } from '../windfoil/runtime.js'\nimport type { TracedOutlines } from '../windfoil/tracedOutlines.js'\nimport type * as SlugRuntime from '../slug/runtime.js'\nimport type * as WindfoilRuntime from '../windfoil/runtime.js'\nimport type * as TracedOutlinesModule from '../windfoil/tracedOutlines.js'\nimport { isAnimatedMotion, type GlyphTextMaterial } from '../text/GlyphTextMaterial.js'\nimport { hasDecorations } from '../text/geometryUtils.js'\nimport type { ReflowState } from '../text/reflow.js'\nimport type * as ReflowModule from '../text/reflow.js'\nimport type { ResolvedTextTone } from '../text/tone.js'\nimport type {\n DomLayoutSnapshot,\n DomSdfOptions,\n SdfAtlas,\n SdfMotionOptions,\n WindfoilOptions,\n} from '../types.js'\nimport type * as DomExtrasModule from './domExtras.js'\nimport type { ContentExtrasController, StagedExtras } from './domExtras.js'\n\nexport interface AnalyticRetainedResult {\n readonly retained: WindfoilBackend | null\n readonly traced: TracedOutlines | null\n}\n\nexport interface AnalyticBuildCallbacks {\n readonly preloadBackend: Promise<typeof SlugRuntime | typeof WindfoilRuntime | null> | null\n readonly preloadTraced: Promise<typeof TracedOutlinesModule | null> | null\n readonly loadTraced: () => Promise<typeof TracedOutlinesModule>\n readonly buildAtlas: (\n requests: DomLayoutSnapshot['requests'],\n signal: AbortSignal,\n appendable?: boolean | 'headroom',\n ) => Promise<SdfAtlas>\n}\n\nexport async function buildDomAnalyticBackend(\n renderer: WebGPURenderer,\n doc: Document,\n snapshot: DomLayoutSnapshot,\n opts: DomSdfOptions,\n backendKind: 'windfoil' | 'slug',\n analytic: WindfoilOptions,\n headroom: boolean,\n existingTraced: TracedOutlines | null,\n resetAtlas: boolean,\n signal: AbortSignal,\n throwIfAborted: (s: AbortSignal) => void,\n callbacks: AnalyticBuildCallbacks,\n): Promise<AnalyticRetainedResult> {\n const outlineProvider: unknown = analytic.outlineProvider\n if (outlineProvider !== undefined && typeof outlineProvider !== 'function') {\n throw new TypeError(\n `DomSdf: textBackend \"${backendKind}\" requires ${backendKind}.outlineProvider`,\n )\n }\n let traced = existingTraced\n let resolved: WindfoilBuildOptions\n if (analytic.outlineProvider) {\n resolved = { ...analytic, outlineProvider: analytic.outlineProvider }\n } else {\n if (!traced) {\n const { createTracedOutlineProvider } =\n (await callbacks.preloadTraced) ?? (await callbacks.loadTraced())\n throwIfAborted(signal)\n traced ??= createTracedOutlineProvider(\n doc,\n opts.colorGlyphs === undefined ? {} : { colorGlyphs: opts.colorGlyphs },\n )\n } else if (resetAtlas) {\n traced.clear()\n }\n resolved = {\n ...analytic,\n fallback: analytic.fallback ?? 'sdf-glyphs',\n outlineProvider: traced.provider,\n }\n }\n const build =\n backendKind === 'slug'\n ? (\n ((await callbacks.preloadBackend) as typeof SlugRuntime | null) ??\n (await import('../slug/runtime.js'))\n ).buildSlugBackend\n : (\n ((await callbacks.preloadBackend) as typeof WindfoilRuntime | null) ??\n (await import('../windfoil/runtime.js'))\n ).buildWindfoilBackend\n const retained = await build(renderer, snapshot.requests, resolved, signal, {\n build: callbacks.buildAtlas,\n effects: opts,\n headroom,\n })\n return { retained, traced }\n}\n\nexport function loadMixedExtras(): Promise<{ createExtraTextParts: typeof createExtraTextParts }> {\n return import('../windfoil/mixed.js')\n}\n\nexport interface AnalyticContentBundle {\n readonly g: Group\n readonly m: GlyphTextMaterial\n readonly tg: InstancedBufferGeometry\n readonly a: boolean\n sm(change: SdfMotionOptions, live: SdfMotionOptions): void\n st(tone: ResolvedTextTone | null): boolean\n ud(snapshot: DomLayoutSnapshot, backend: WindfoilBackend, motion: SdfMotionOptions): void\n rg(geometry: InstancedBufferGeometry): void\n u(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n motion: SdfMotionOptions,\n tone?: ResolvedTextTone | null,\n ): boolean\n d(): void\n}\n\nconst maxSeq = (s: DomLayoutSnapshot): number =>\n s.glyphs.reduce((max, glyph) => Math.max(max, glyph.sequence), 0)\n\nexport function createAnalyticContent(\n snapshot: DomLayoutSnapshot,\n backend: WindfoilBackend,\n options: DomSdfOptions,\n motion: SdfMotionOptions,\n tone: ResolvedTextTone | null,\n makeExtraParts?: typeof createExtraTextParts,\n extrasMod?: typeof DomExtrasModule | null,\n): AnalyticContentBundle {\n const materialOptions = { ...options, tone: tone ?? (false as const) }\n const group = new Group()\n group.name = 'ultra-text generated DOM content'\n group.matrixAutoUpdate = false\n group.updateMatrix()\n\n const strength = motion.strength ?? 18\n let animated = isAnimatedMotion(motion)\n const materialMotion = (live: SdfMotionOptions): SdfMotionOptions | false =>\n animated ? live : false\n const { geometry: glyphGeometry, maxSequence } = backend.createGeometry(snapshot, strength)\n const hasExtras = !!(backend.companion ?? backend.color)\n const usesColor = (layout: DomLayoutSnapshot): boolean =>\n !!backend.companion?.colorLayer &&\n (options.colorGlyphs !== 'none' || layout.requests.some((request) => request.shape?.bitmap))\n const colorEnabled = usesColor(snapshot)\n const globalSequence = hasExtras ? maxSeq(snapshot) : maxSequence\n let textMaterial: GlyphTextMaterial\n try {\n textMaterial = backend.createMaterial({\n ...materialOptions,\n maxSequence: hasExtras ? globalSequence : maxSequence,\n motion: materialMotion(motion),\n })\n } catch (error) {\n glyphGeometry.dispose()\n throw error\n }\n let extras: ReturnType<typeof createExtraTextParts> | undefined\n try {\n if (hasExtras)\n extras = makeExtraParts!(snapshot, backend, materialOptions, materialMotion(motion), strength)\n } catch (error) {\n glyphGeometry.dispose()\n textMaterial.dispose()\n throw error\n }\n const text = new Mesh(glyphGeometry, textMaterial)\n text.name = 'ultra-text text'\n text.castShadow = options.castShadow !== false\n text.frustumCulled = false\n text.renderOrder = 2\n text.matrixAutoUpdate = false\n text.updateMatrix()\n group.add(text)\n\n const ownedMeshes: Mesh[] = [text]\n const disposeMeshes = (): void => {\n for (const mesh of ownedMeshes) {\n mesh.geometry.dispose()\n for (const material of Array.isArray(mesh.material) ? mesh.material : [mesh.material])\n material.dispose()\n }\n ownedMeshes.length = 0\n group.clear()\n }\n try {\n if (extras) {\n for (const mesh of extras.meshes) {\n group.add(mesh)\n ownedMeshes.push(mesh)\n }\n extras.mergeRects(snapshot, text.geometry)\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n const glyphDrawable = (retained: WindfoilBackend, key: string): boolean =>\n (retained.glyphs.get(key)?.monotonePieceCount ?? 0) > 0 || !!retained.companion?.glyphs.has(key)\n let ce: ContentExtrasController | null = null\n try {\n if (extrasMod) {\n ce = extrasMod.createContentExtras(\n snapshot,\n text.geometry,\n group,\n ownedMeshes,\n options,\n () => animated,\n motion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(backend, key),\n )\n }\n } catch (error) {\n disposeMeshes()\n throw error\n }\n\n const swapGeometry = (mesh: Mesh, geometry: InstancedBufferGeometry): void => {\n const previous = mesh.geometry\n mesh.geometry = geometry\n previous.dispose()\n }\n const setTone = (next: ResolvedTextTone | null): boolean => {\n if (!textMaterial.setTone(next)) return false\n for (const mesh of extras?.meshes ?? []) mesh.material.setTone(next)\n return true\n }\n const toneFits = (next: ResolvedTextTone | null): boolean => {\n const current = textMaterial.tone\n return current && next ? current.fits(next) : !current && !next\n }\n\n let disposed = false\n return {\n g: group,\n get m(): GlyphTextMaterial {\n return textMaterial\n },\n get a(): boolean {\n return animated\n },\n sm(change, live) {\n if (animated) {\n textMaterial.setMotion(change)\n extras?.setMotion(change)\n ce?.setMotion(change)\n return\n }\n if (!isAnimatedMotion(live)) return\n const decMesh = ce?.decMesh()\n const meshes: Mesh<InstancedBufferGeometry, GlyphTextMaterial>[] = [\n text,\n ...(extras?.meshes ?? []),\n ...(decMesh ? [decMesh] : []),\n ]\n const twins: GlyphTextMaterial[] = []\n try {\n for (const mesh of meshes) twins.push(mesh.material.withMotion(live))\n } catch (error) {\n for (const twin of twins) twin.dispose()\n throw error\n }\n meshes.forEach((mesh, index) => {\n const previous = mesh.material\n mesh.material = twins[index]!\n previous.dispose()\n })\n textMaterial = twins[0]!\n animated = true\n },\n st: setTone,\n ud(layout, retained, liveMotion) {\n ce?.updateDec(\n layout,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n (key) => glyphDrawable(retained, key),\n )\n },\n get tg(): InstancedBufferGeometry {\n return text.geometry\n },\n rg(geometry) {\n swapGeometry(text, geometry)\n },\n u(nextSnapshot, nextBackend, liveMotion, nextTone) {\n if (\n nextTone !== undefined &&\n (!toneFits(nextTone) || animated !== isAnimatedMotion(liveMotion))\n )\n return false\n if (hasExtras && !extras!.fitsMotion(nextSnapshot)) return false\n if (colorEnabled !== usesColor(nextSnapshot)) return false\n if (\n ce\n ? !ce.fitsLayout(nextSnapshot)\n : nextSnapshot.rects.length > 0 || hasDecorations(nextSnapshot)\n )\n return false\n const strength = liveMotion.strength ?? 18\n const drawable = (key: string): boolean => glyphDrawable(nextBackend, key)\n const decorationsFit = ce ? ce.decorationsFit(nextSnapshot, drawable) : true\n if (hasExtras && !decorationsFit) return false\n const glyphsFit = decorationsFit && nextBackend.contentFits(text.geometry, nextSnapshot)\n let built: { geometry: InstancedBufferGeometry; maxSequence: number } | null = null\n let nextParts: readonly (InstancedBufferGeometry | null)[] = []\n let stagedExtras: StagedExtras | null = null\n const releaseStaged = (): void => {\n built?.geometry.dispose()\n for (const geometry of nextParts) geometry?.dispose()\n stagedExtras?.dispose()\n }\n try {\n nextParts = extras?.prepare(nextSnapshot, strength) ?? []\n if (!glyphsFit) built = nextBackend.createGeometry(nextSnapshot, strength)\n if (ce) {\n stagedExtras = ce.prepare(\n nextSnapshot,\n built?.geometry ?? text.geometry,\n animated,\n liveMotion,\n built?.maxSequence ?? textMaterial.maxSequence.value,\n decorationsFit,\n drawable,\n )\n }\n } catch (error) {\n releaseStaged()\n throw error\n }\n if (built) {\n swapGeometry(text, built.geometry)\n textMaterial.maxSequence.value = built.maxSequence\n } else {\n const maxSequence = nextBackend.updateGeometry(\n text.geometry,\n nextSnapshot,\n strength,\n undefined,\n true,\n )\n if (maxSequence === null) {\n releaseStaged()\n throw new Error('DomSdf: glyph buffers changed during the update')\n }\n textMaterial.maxSequence.value = maxSequence\n }\n if (extras) {\n extras.commit(nextParts, nextSnapshot, strength)\n textMaterial.maxSequence.value = maxSeq(nextSnapshot)\n extras.mergeRects(nextSnapshot, text.geometry)\n }\n ce?.commit(\n stagedExtras!,\n nextSnapshot,\n text.geometry,\n animated,\n liveMotion,\n textMaterial.maxSequence.value,\n drawable,\n swapGeometry,\n )\n if (nextTone !== undefined) setTone(nextTone)\n return true\n },\n d() {\n if (disposed) return\n disposed = true\n disposeMeshes()\n },\n }\n}\n\nexport function reflowAnalytic(\n snapshot: DomLayoutSnapshot,\n retained: WindfoilBackend,\n content: AnalyticContentBundle,\n width: number,\n motion: SdfMotionOptions,\n rm: typeof ReflowModule,\n reflowState: ReflowState | null,\n): {\n readonly width: number\n readonly height: number\n readonly lines: number\n readonly state: ReflowState\n} {\n retained.setGlyphEm(!!content.m.tone?.dilates)\n const state = reflowState ?? rm.createReflowState(snapshot)\n const reflowed = rm.reflowSnapshotWithState(snapshot, width, state)\n const strength = motion.strength ?? 18\n if (retained.companion || retained.color) {\n if (!content.u(reflowed, retained, motion))\n throw new Error('DomSdf.reflow: incompatible retained content')\n } else {\n let maxSequence = retained.reflowGeometry(content.tg, reflowed, strength)\n if (maxSequence === null) {\n const built = retained.createGeometry(reflowed, strength)\n content.rg(built.geometry)\n maxSequence = built.maxSequence\n }\n content.m.maxSequence.value = maxSequence\n content.ud(reflowed, retained, motion)\n }\n return { width: reflowed.width, height: reflowed.height, lines: reflowed.lineCount, state }\n}\n\nexport function countAnalyticStats(\n snapshot: DomLayoutSnapshot,\n windfoil: WindfoilBackend,\n): readonly [\n glyphs: number,\n shapes: number,\n colorGlyphs: number,\n fallbackGlyphs: number,\n switchableGlyphs: number,\n] {\n const glyphs = windfoil.companion?.glyphs\n const switchKeys = windfoil.sizeSwitch?.keys\n let glyphCount = 0\n let shapeCount = 0\n let colorGlyphCount = 0\n let fallbackGlyphCount = 0\n let switchableGlyphCount = 0\n for (const glyph of snapshot.glyphs) {\n if (switchKeys?.has(glyph.glyphKey)) switchableGlyphCount++\n if (glyph.shapeGroup !== undefined) {\n shapeCount++\n continue\n }\n glyphCount++\n const slot = glyphs?.get(glyph.glyphKey)\n if (slot && !windfoil.analyticCovers(glyph.glyphKey)) {\n if (slot.color) colorGlyphCount++\n fallbackGlyphCount++\n }\n }\n return [glyphCount, shapeCount, colorGlyphCount, fallbackGlyphCount, switchableGlyphCount]\n}\n"],"mappings":";;;;AAuCA,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,OAAO,YAAY;CACpC,IAAI,SAAS,aAAa,SAAS,OAC7B;MAAA,CAAC,QAAQ,EAAE,UAAU,UAAU,MAAM,GACvC,MAAM,IAAI,MAAM,8CAA8C;CAAA,OAC3D;EACL,IAAI,cAAc,SAAS,eAAe,QAAQ,IAAI,UAAU,QAAQ;EACxE,IAAI,gBAAgB,MAAM;GACxB,MAAM,QAAQ,SAAS,eAAe,UAAU,QAAQ;GACxD,QAAQ,GAAG,MAAM,QAAQ;GACzB,cAAc,MAAM;EACtB;EACA,QAAQ,EAAE,YAAY,QAAQ;EAC9B,QAAQ,GAAG,UAAU,UAAU,MAAM;CACvC;CACA,OAAO;EAAE,OAAO,SAAS;EAAO,QAAQ,SAAS;EAAQ,OAAO,SAAS;EAAW;CAAM;AAC5F;AAEA,SAAgB,mBACd,UACA,UAOA;CACA,MAAM,SAAS,SAAS,WAAW;CACnC,MAAM,aAAa,SAAS,YAAY;CACxC,IAAI,aAAa;CACjB,IAAI,aAAa;CACjB,IAAI,kBAAkB;CACtB,IAAI,qBAAqB;CACzB,IAAI,uBAAuB;CAC3B,KAAK,MAAM,SAAS,SAAS,QAAQ;EACnC,IAAI,YAAY,IAAI,MAAM,QAAQ,GAAG;EACrC,IAAI,MAAM,eAAe,KAAA,GAAW;GAClC;GACA;EACF;EACA;EACA,MAAM,OAAO,QAAQ,IAAI,MAAM,QAAQ;EACvC,IAAI,QAAQ,CAAC,SAAS,eAAe,MAAM,QAAQ,GAAG;GACpD,IAAI,KAAK,OAAO;GAChB;EACF;CACF;CACA,OAAO;EAAC;EAAY;EAAY;EAAiB;EAAoB;CAAoB;AAC3F"}
|
package/dist/dom/fontCanvas.d.ts
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
import type { ColorGlyphMode, GlyphRequest } from '../types.js';
|
|
1
2
|
import type { setShapingContext } from './browserShaping.js';
|
|
2
3
|
export type ShapingContext = typeof setShapingContext;
|
|
4
|
+
/** Shared atlas compatibility and raster candidacy rule. */
|
|
5
|
+
export declare function isColorCandidate(request: GlyphRequest, mode?: ColorGlyphMode): boolean;
|
|
6
|
+
/** The bake canvas's font state for a request, shared with the outline tracer. */
|
|
7
|
+
export declare function setFontContext(context: CanvasRenderingContext2D, request: GlyphRequest, shaping: ShapingContext | undefined, lastFont: GlyphRequest['font'] | null): GlyphRequest['font'];
|
|
8
|
+
/**
|
|
9
|
+
* The bake canvas. Font smoothing follows the canvas element's computed style, and only while
|
|
10
|
+
* the element is in a document: there it is turned off, in every engine, so a mask is the
|
|
11
|
+
* outline itself. Everything else a page would hand down (spacing, font features and
|
|
12
|
+
* variations, direction, language) is cut off, so the mask stays what a detached canvas draws.
|
|
13
|
+
* The caller takes it out of the document again.
|
|
14
|
+
* Shared with the atlas append path and the outline tracer.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createCanvas(document: Document): HTMLCanvasElement;
|
|
17
|
+
/** Loads every face the text requests draw with; shared with the outline tracer. */
|
|
18
|
+
export declare function waitForFonts(document: Document, requests: readonly GlyphRequest[], signal?: AbortSignal): Promise<void>;
|
package/dist/dom/fontCanvas.js
CHANGED
|
@@ -17,12 +17,12 @@ function canvasFontStretch(value) {
|
|
|
17
17
|
if (!Number.isFinite(percentage)) return CANVAS_FONT_STRETCHES.find(([name]) => name === value)?.[0] ?? "normal";
|
|
18
18
|
return CANVAS_FONT_STRETCHES.reduce((a, b) => Math.abs(b[1] - percentage) < Math.abs(a[1] - percentage) ? b : a)[0];
|
|
19
19
|
}
|
|
20
|
-
/**
|
|
20
|
+
/** Shared atlas compatibility and raster candidacy rule. */
|
|
21
21
|
function isColorCandidate(request, mode = "emoji") {
|
|
22
22
|
if (request.shape) return request.shape.bitmap === true;
|
|
23
23
|
return mode === "all" || mode === "emoji" && isEmojiCandidate(request.character);
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
25
|
+
/** The bake canvas's font state for a request, shared with the outline tracer. */
|
|
26
26
|
function setFontContext(context, request, shaping, lastFont) {
|
|
27
27
|
const { font } = request;
|
|
28
28
|
if (lastFont !== font) {
|
|
@@ -45,7 +45,7 @@ function setFontContext(context, request, shaping, lastFont) {
|
|
|
45
45
|
* outline itself. Everything else a page would hand down (spacing, font features and
|
|
46
46
|
* variations, direction, language) is cut off, so the mask stays what a detached canvas draws.
|
|
47
47
|
* The caller takes it out of the document again.
|
|
48
|
-
*
|
|
48
|
+
* Shared with the atlas append path and the outline tracer.
|
|
49
49
|
*/
|
|
50
50
|
function createCanvas(document) {
|
|
51
51
|
const canvas = document.createElement("canvas");
|
|
@@ -66,7 +66,7 @@ function allFontsLoaded(document) {
|
|
|
66
66
|
for (const face of fonts) if (face.status !== "loaded") return false;
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
|
-
/**
|
|
69
|
+
/** Loads every face the text requests draw with; shared with the outline tracer. */
|
|
70
70
|
async function waitForFonts(document, requests, signal) {
|
|
71
71
|
if (signal?.aborted) throw signal.reason ?? new DOMException("The atlas build was aborted", "AbortError");
|
|
72
72
|
const fonts = document.fonts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fontCanvas.js","names":[],"sources":["../../src/dom/fontCanvas.ts"],"sourcesContent":["import type { ColorGlyphMode, GlyphRequest } from '../types.js'\nimport type { setShapingContext } from './browserShaping.js'\nimport { isEmojiCandidate } from './clusters.js'\n\nexport type ShapingContext = typeof setShapingContext\n\ninterface CanvasFontContext extends CanvasRenderingContext2D {\n fontKerning: CanvasFontKerning\n fontStretch: CanvasFontStretch\n fontVariantCaps: CanvasFontVariantCaps\n letterSpacing: string\n wordSpacing: string\n}\n\nconst CANVAS_FONT_STRETCHES = [\n ['ultra-condensed', 50],\n ['extra-condensed', 62.5],\n ['condensed', 75],\n ['semi-condensed', 87.5],\n ['normal', 100],\n ['semi-expanded', 112.5],\n ['expanded', 125],\n ['extra-expanded', 150],\n ['ultra-expanded', 200],\n] as const satisfies readonly (readonly [CanvasFontStretch, number])[]\n\nfunction canvasFontStretch(value: string): CanvasFontStretch {\n if (value === '100%' || value === 'normal') return 'normal'\n const percentage = Number.parseFloat(value)\n if (!Number.isFinite(percentage)) {\n return CANVAS_FONT_STRETCHES.find(([name]) => name === value)?.[0] ?? 'normal'\n }\n return CANVAS_FONT_STRETCHES.reduce((a, b) =>\n Math.abs(b[1] - percentage) < Math.abs(a[1] - percentage) ? b : a,\n )[0]\n}\n\n/** @internal Shared atlas compatibility and raster candidacy rule. */\nexport function isColorCandidate(request: GlyphRequest, mode: ColorGlyphMode = 'emoji'): boolean {\n if (request.shape) return request.shape.bitmap === true\n return mode === 'all' || (mode === 'emoji' && isEmojiCandidate(request.character))\n}\n\n/** @internal The bake canvas's font state for a request, shared with the outline tracer. */\nexport function setFontContext(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n shaping: ShapingContext | undefined,\n lastFont: GlyphRequest['font'] | null,\n): GlyphRequest['font'] {\n const { font } = request\n if (lastFont !== font) {\n const extended: CanvasFontContext = context\n context.font = font.canvasFont\n if (!lastFont) {\n context.textAlign = 'left'\n context.textBaseline = 'alphabetic'\n }\n if ('fontKerning' in extended) extended.fontKerning = font.kerning as CanvasFontKerning\n if ('fontStretch' in extended) extended.fontStretch = canvasFontStretch(font.stretch)\n if ('fontVariantCaps' in extended)\n extended.fontVariantCaps =\n font.variant === 'normal'\n ? 'normal'\n : ((/\\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\\b/.exec(\n font.variant,\n )?.[0] ?? 'normal') as CanvasFontVariantCaps)\n }\n shaping?.(context, request)\n return font\n}\n\n/**\n * The bake canvas. Font smoothing follows the canvas element's computed style, and only while\n * the element is in a document: there it is turned off, in every engine, so a mask is the\n * outline itself. Everything else a page would hand down (spacing, font features and\n * variations, direction, language) is cut off, so the mask stays what a detached canvas draws.\n * The caller takes it out of the document again.\n * @internal Shared with the atlas append path and the outline tracer.\n */\nexport function createCanvas(document: Document): HTMLCanvasElement {\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n canvas.style.cssText =\n 'all:initial!important;display:none!important;direction:ltr!important;-webkit-font-smoothing:antialiased!important;-moz-osx-font-smoothing:grayscale!important;'\n canvas.dir = 'ltr'\n canvas.lang = ''\n document.documentElement.append(canvas)\n return canvas\n}\n\n/** @internal True when the document has a FontFaceSet whose registered faces are all loaded. */\nexport function allFontsLoaded(document: Document): boolean {\n const fonts = document.fonts as FontFaceSet | undefined\n if (fonts?.status !== 'loaded') return false\n const faceSet = fonts as {\n load?: unknown\n check?: unknown\n [Symbol.iterator]?: unknown\n }\n if (\n typeof faceSet.load !== 'function' ||\n 'mock' in faceSet.load ||\n typeof faceSet.check !== 'function' ||\n 'mock' in faceSet.check ||\n typeof faceSet[Symbol.iterator] !== 'function'\n ) {\n return false\n }\n for (const face of fonts as Iterable<FontFace>) {\n if (face.status !== 'loaded') return false\n }\n return true\n}\n\n/** @internal Loads every face the text requests draw with; shared with the outline tracer. */\nexport async function waitForFonts(\n document: Document,\n requests: readonly GlyphRequest[],\n signal?: AbortSignal,\n): Promise<void> {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n const fonts = document.fonts as FontFaceSet | undefined\n if (!fonts || allFontsLoaded(document)) return\n const byFont = new Map<string, { font: string; text: string }>()\n for (const request of requests) {\n if (request.shape) continue\n const current = byFont.get(request.font.key)\n if (current) current.text += request.character\n else byFont.set(request.font.key, { font: request.font.canvasFont, text: request.character })\n }\n const ok = fonts.status === 'loaded' && !('mock' in (fonts as { load: object }).load)\n await Promise.all(\n Array.from(byFont.values(), (i) => {\n try {\n if (ok && fonts.check(i.font, i.text)) return\n } catch {\n // Load below when check rejects an uncommon font shorthand.\n }\n return fonts.load(i.font, i.text)\n }) as Promise<unknown>[],\n )\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n\nlet sharedOffscreenMeasure: OffscreenCanvasRenderingContext2D | null | undefined\n\n/** @internal True in real browsers with native OffscreenCanvas and unmocked Canvas2D getContext. */\nexport function isNativeMeasureBrowser(document: Document): boolean {\n const view = document.defaultView\n if (!view) return false\n const fonts = document.fonts as FontFaceSet | undefined\n if (\n !('CanvasRenderingContext2D' in view) ||\n !('OffscreenCanvas' in view) ||\n fonts?.status !== 'loaded' ||\n !Function.prototype.toString.call(view.OffscreenCanvas).includes('[native')\n ) {\n return false\n }\n const getContextFn = Object.getOwnPropertyDescriptor(\n view.HTMLCanvasElement.prototype,\n 'getContext',\n )?.value as object | undefined\n return !(getContextFn && 'mock' in getContextFn)\n}\n\n/** @internal Shared OffscreenCanvas measurement context (without `willReadFrequently`) when native. */\nexport function createSharedMeasureContext(document: Document): CanvasRenderingContext2D | null {\n const view = document.defaultView\n if (view && isNativeMeasureBrowser(document)) {\n if (sharedOffscreenMeasure === undefined) {\n sharedOffscreenMeasure = new (\n view as Window & { OffscreenCanvas: typeof OffscreenCanvas }\n ).OffscreenCanvas(1, 1).getContext('2d')\n }\n if (sharedOffscreenMeasure) {\n if ('letterSpacing' in sharedOffscreenMeasure) sharedOffscreenMeasure.letterSpacing = '0px'\n sharedOffscreenMeasure.textAlign = 'left'\n sharedOffscreenMeasure.textBaseline = 'alphabetic'\n return sharedOffscreenMeasure as unknown as CanvasRenderingContext2D\n }\n }\n return document.createElement('canvas').getContext('2d')\n}\n"],"mappings":";;AAcA,IAAM,wBAAwB;CAC5B,CAAC,mBAAmB,EAAE;CACtB,CAAC,mBAAmB,IAAI;CACxB,CAAC,aAAa,EAAE;CAChB,CAAC,kBAAkB,IAAI;CACvB,CAAC,UAAU,GAAG;CACd,CAAC,iBAAiB,KAAK;CACvB,CAAC,YAAY,GAAG;CAChB,CAAC,kBAAkB,GAAG;CACtB,CAAC,kBAAkB,GAAG;AACxB;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,IAAI,UAAU,UAAU,UAAU,UAAU,OAAO;CACnD,MAAM,aAAa,OAAO,WAAW,KAAK;CAC1C,IAAI,CAAC,OAAO,SAAS,UAAU,GAC7B,OAAO,sBAAsB,M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YACF,CAAC,EAAE;CACH,OAAO,EAAE,gBAAgB,UAAU;AACrC;;AAGA,SAAgB,2BAA2B,UAAqD;CAC9F,MAAM,OAAO,SAAS;CACtB,IAAI,QAAQ,uBAAuB,QAAQ,GAAG;EAC5C,IAAI,2BAA2B,KAAA,GAC7B,yBAAyB,IACvB,KACA,gBAAgB,GAAG,CAAC,CAAC,CAAC,WAAW,IAAI;EAEzC,IAAI,wBAAwB;GAC1B,IAAI,mBAAmB,wBAAwB,uBAAuB,gBAAgB;GACtF,uBAAuB,YAAY;GACnC,uBAAuB,eAAe;GACtC,OAAO;EACT;CACF;CACA,OAAO,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,IAAI;AACzD"}
|
|
1
|
+
{"version":3,"file":"fontCanvas.js","names":[],"sources":["../../src/dom/fontCanvas.ts"],"sourcesContent":["import type { ColorGlyphMode, GlyphRequest } from '../types.js'\nimport type { setShapingContext } from './browserShaping.js'\nimport { isEmojiCandidate } from './clusters.js'\n\nexport type ShapingContext = typeof setShapingContext\n\ninterface CanvasFontContext extends CanvasRenderingContext2D {\n fontKerning: CanvasFontKerning\n fontStretch: CanvasFontStretch\n fontVariantCaps: CanvasFontVariantCaps\n letterSpacing: string\n wordSpacing: string\n}\n\nconst CANVAS_FONT_STRETCHES = [\n ['ultra-condensed', 50],\n ['extra-condensed', 62.5],\n ['condensed', 75],\n ['semi-condensed', 87.5],\n ['normal', 100],\n ['semi-expanded', 112.5],\n ['expanded', 125],\n ['extra-expanded', 150],\n ['ultra-expanded', 200],\n] as const satisfies readonly (readonly [CanvasFontStretch, number])[]\n\nfunction canvasFontStretch(value: string): CanvasFontStretch {\n if (value === '100%' || value === 'normal') return 'normal'\n const percentage = Number.parseFloat(value)\n if (!Number.isFinite(percentage)) {\n return CANVAS_FONT_STRETCHES.find(([name]) => name === value)?.[0] ?? 'normal'\n }\n return CANVAS_FONT_STRETCHES.reduce((a, b) =>\n Math.abs(b[1] - percentage) < Math.abs(a[1] - percentage) ? b : a,\n )[0]\n}\n\n/** Shared atlas compatibility and raster candidacy rule. */\nexport function isColorCandidate(request: GlyphRequest, mode: ColorGlyphMode = 'emoji'): boolean {\n if (request.shape) return request.shape.bitmap === true\n return mode === 'all' || (mode === 'emoji' && isEmojiCandidate(request.character))\n}\n\n/** The bake canvas's font state for a request, shared with the outline tracer. */\nexport function setFontContext(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n shaping: ShapingContext | undefined,\n lastFont: GlyphRequest['font'] | null,\n): GlyphRequest['font'] {\n const { font } = request\n if (lastFont !== font) {\n const extended: CanvasFontContext = context\n context.font = font.canvasFont\n if (!lastFont) {\n context.textAlign = 'left'\n context.textBaseline = 'alphabetic'\n }\n if ('fontKerning' in extended) extended.fontKerning = font.kerning as CanvasFontKerning\n if ('fontStretch' in extended) extended.fontStretch = canvasFontStretch(font.stretch)\n if ('fontVariantCaps' in extended)\n extended.fontVariantCaps =\n font.variant === 'normal'\n ? 'normal'\n : ((/\\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\\b/.exec(\n font.variant,\n )?.[0] ?? 'normal') as CanvasFontVariantCaps)\n }\n shaping?.(context, request)\n return font\n}\n\n/**\n * The bake canvas. Font smoothing follows the canvas element's computed style, and only while\n * the element is in a document: there it is turned off, in every engine, so a mask is the\n * outline itself. Everything else a page would hand down (spacing, font features and\n * variations, direction, language) is cut off, so the mask stays what a detached canvas draws.\n * The caller takes it out of the document again.\n * Shared with the atlas append path and the outline tracer.\n */\nexport function createCanvas(document: Document): HTMLCanvasElement {\n const canvas = document.createElement('canvas')\n canvas.width = 1\n canvas.height = 1\n canvas.style.cssText =\n 'all:initial!important;display:none!important;direction:ltr!important;-webkit-font-smoothing:antialiased!important;-moz-osx-font-smoothing:grayscale!important;'\n canvas.dir = 'ltr'\n canvas.lang = ''\n document.documentElement.append(canvas)\n return canvas\n}\n\n/** @internal True when the document has a FontFaceSet whose registered faces are all loaded. */\nexport function allFontsLoaded(document: Document): boolean {\n const fonts = document.fonts as FontFaceSet | undefined\n if (fonts?.status !== 'loaded') return false\n const faceSet = fonts as {\n load?: unknown\n check?: unknown\n [Symbol.iterator]?: unknown\n }\n if (\n typeof faceSet.load !== 'function' ||\n 'mock' in faceSet.load ||\n typeof faceSet.check !== 'function' ||\n 'mock' in faceSet.check ||\n typeof faceSet[Symbol.iterator] !== 'function'\n ) {\n return false\n }\n for (const face of fonts as Iterable<FontFace>) {\n if (face.status !== 'loaded') return false\n }\n return true\n}\n\n/** Loads every face the text requests draw with; shared with the outline tracer. */\nexport async function waitForFonts(\n document: Document,\n requests: readonly GlyphRequest[],\n signal?: AbortSignal,\n): Promise<void> {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n const fonts = document.fonts as FontFaceSet | undefined\n if (!fonts || allFontsLoaded(document)) return\n const byFont = new Map<string, { font: string; text: string }>()\n for (const request of requests) {\n if (request.shape) continue\n const current = byFont.get(request.font.key)\n if (current) current.text += request.character\n else byFont.set(request.font.key, { font: request.font.canvasFont, text: request.character })\n }\n const ok = fonts.status === 'loaded' && !('mock' in (fonts as { load: object }).load)\n await Promise.all(\n Array.from(byFont.values(), (i) => {\n try {\n if (ok && fonts.check(i.font, i.text)) return\n } catch {\n // Load below when check rejects an uncommon font shorthand.\n }\n return fonts.load(i.font, i.text)\n }) as Promise<unknown>[],\n )\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n\nlet sharedOffscreenMeasure: OffscreenCanvasRenderingContext2D | null | undefined\n\n/** @internal True in real browsers with native OffscreenCanvas and unmocked Canvas2D getContext. */\nexport function isNativeMeasureBrowser(document: Document): boolean {\n const view = document.defaultView\n if (!view) return false\n const fonts = document.fonts as FontFaceSet | undefined\n if (\n !('CanvasRenderingContext2D' in view) ||\n !('OffscreenCanvas' in view) ||\n fonts?.status !== 'loaded' ||\n !Function.prototype.toString.call(view.OffscreenCanvas).includes('[native')\n ) {\n return false\n }\n const getContextFn = Object.getOwnPropertyDescriptor(\n view.HTMLCanvasElement.prototype,\n 'getContext',\n )?.value as object | undefined\n return !(getContextFn && 'mock' in getContextFn)\n}\n\n/** @internal Shared OffscreenCanvas measurement context (without `willReadFrequently`) when native. */\nexport function createSharedMeasureContext(document: Document): CanvasRenderingContext2D | null {\n const view = document.defaultView\n if (view && isNativeMeasureBrowser(document)) {\n if (sharedOffscreenMeasure === undefined) {\n sharedOffscreenMeasure = new (\n view as Window & { OffscreenCanvas: typeof OffscreenCanvas }\n ).OffscreenCanvas(1, 1).getContext('2d')\n }\n if (sharedOffscreenMeasure) {\n if ('letterSpacing' in sharedOffscreenMeasure) sharedOffscreenMeasure.letterSpacing = '0px'\n sharedOffscreenMeasure.textAlign = 'left'\n sharedOffscreenMeasure.textBaseline = 'alphabetic'\n return sharedOffscreenMeasure as unknown as CanvasRenderingContext2D\n }\n }\n return document.createElement('canvas').getContext('2d')\n}\n"],"mappings":";;AAcA,IAAM,wBAAwB;CAC5B,CAAC,mBAAmB,EAAE;CACtB,CAAC,mBAAmB,IAAI;CACxB,CAAC,aAAa,EAAE;CAChB,CAAC,kBAAkB,IAAI;CACvB,CAAC,UAAU,GAAG;CACd,CAAC,iBAAiB,KAAK;CACvB,CAAC,YAAY,GAAG;CAChB,CAAC,kBAAkB,GAAG;CACtB,CAAC,kBAAkB,GAAG;AACxB;AAEA,SAAS,kBAAkB,OAAkC;CAC3D,IAAI,UAAU,UAAU,UAAU,UAAU,OAAO;CACnD,MAAM,aAAa,OAAO,WAAW,KAAK;CAC1C,IAAI,CAAC,OAAO,SAAS,UAAU,GAC7B,OAAO,sBAAsB,MAAM,CAAC,UAAU,SAAS,KAAK,CAAC,GAAG,MAAM;CAExE,OAAO,sBAAsB,QAAQ,GAAG,MACtC,KAAK,IAAI,EAAE,KAAK,UAAU,IAAI,KAAK,IAAI,EAAE,KAAK,UAAU,IAAI,IAAI,CAClE,CAAC,CAAC;AACJ;;AAGA,SAAgB,iBAAiB,SAAu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G,CAAC,CAAC,CAAC,WAAW,IAAI;EAEzC,IAAI,wBAAwB;GAC1B,IAAI,mBAAmB,wBAAwB,uBAAuB,gBAAgB;GACtF,uBAAuB,YAAY;GACnC,uBAAuB,eAAe;GACtC,OAAO;EACT;CACF;CACA,OAAO,SAAS,cAAc,QAAQ,CAAC,CAAC,WAAW,IAAI;AACzD"}
|
|
@@ -6,6 +6,8 @@ var strings = /* @__PURE__ */ new Map();
|
|
|
6
6
|
var count = 0;
|
|
7
7
|
var h1 = 0;
|
|
8
8
|
var h2 = 0;
|
|
9
|
+
var h3 = 0;
|
|
10
|
+
var h4 = 0;
|
|
9
11
|
var STRING = -1e300;
|
|
10
12
|
var STRING_ID = -2e300;
|
|
11
13
|
var TRUE = -3e300;
|
|
@@ -14,15 +16,22 @@ var OPEN = -5e300;
|
|
|
14
16
|
var CLOSE = -6e300;
|
|
15
17
|
var OTHER = -7e300;
|
|
16
18
|
function flush() {
|
|
17
|
-
let
|
|
18
|
-
let
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let a0 = h1;
|
|
20
|
+
let b0 = h2;
|
|
21
|
+
let a1 = h3;
|
|
22
|
+
let b1 = h4;
|
|
23
|
+
for (let index = 0, end = count * 2; index < end; index += 2) {
|
|
24
|
+
const v0 = bits[index];
|
|
25
|
+
const v1 = bits[index + 1];
|
|
26
|
+
a0 = Math.imul(a0 ^ v0, 16777619);
|
|
27
|
+
b0 = Math.imul(b0 ^ v0, 1597334677);
|
|
28
|
+
a1 = Math.imul(a1 ^ v1, 16777619);
|
|
29
|
+
b1 = Math.imul(b1 ^ v1, 1597334677);
|
|
23
30
|
}
|
|
24
|
-
h1 =
|
|
25
|
-
h2 =
|
|
31
|
+
h1 = a0;
|
|
32
|
+
h2 = b0;
|
|
33
|
+
h3 = a1;
|
|
34
|
+
h4 = b1;
|
|
26
35
|
count = 0;
|
|
27
36
|
}
|
|
28
37
|
function push(value) {
|
|
@@ -35,15 +44,20 @@ function walkString(value) {
|
|
|
35
44
|
id = strings.size;
|
|
36
45
|
strings.set(value, id);
|
|
37
46
|
const len = value.length;
|
|
47
|
+
const packed = len + 1 >> 1;
|
|
38
48
|
if (len < 128) {
|
|
39
|
-
if (count + 2 +
|
|
49
|
+
if (count + 2 + packed > WORDS) flush();
|
|
40
50
|
words[count++] = STRING;
|
|
41
51
|
words[count++] = len;
|
|
42
|
-
|
|
52
|
+
let index = 0;
|
|
53
|
+
for (; index + 1 < len; index += 2) words[count++] = value.charCodeAt(index) + value.charCodeAt(index + 1) * 65536;
|
|
54
|
+
if (index < len) words[count++] = value.charCodeAt(index);
|
|
43
55
|
} else {
|
|
44
56
|
push(STRING);
|
|
45
57
|
push(len);
|
|
46
|
-
|
|
58
|
+
let index = 0;
|
|
59
|
+
for (; index + 1 < len; index += 2) push(value.charCodeAt(index) + value.charCodeAt(index + 1) * 65536);
|
|
60
|
+
if (index < len) push(value.charCodeAt(index));
|
|
47
61
|
}
|
|
48
62
|
} else {
|
|
49
63
|
if (count > 2046) flush();
|
|
@@ -77,6 +91,8 @@ function walk(value) {
|
|
|
77
91
|
function layoutSignatureOf(snapshot) {
|
|
78
92
|
h1 = 2166136261;
|
|
79
93
|
h2 = -624069552;
|
|
94
|
+
h3 = -1640531527;
|
|
95
|
+
h4 = -2048144789;
|
|
80
96
|
count = 0;
|
|
81
97
|
strings.clear();
|
|
82
98
|
const glyphs = snapshot.glyphs;
|
|
@@ -233,7 +249,7 @@ function layoutSignatureOf(snapshot) {
|
|
|
233
249
|
for (const key in root) if (key !== "requests" && key !== "glyphs" && key !== "blocks" && key !== "rects" && Object.hasOwn(root, key)) walk(root[key]);
|
|
234
250
|
flush();
|
|
235
251
|
strings.clear();
|
|
236
|
-
return `${h1}:${h2}`;
|
|
252
|
+
return `${(h1 ^ Math.imul(h3, 2246822507)) >>> 0}:${(h2 ^ Math.imul(h4, 3266489909)) >>> 0}`;
|
|
237
253
|
}
|
|
238
254
|
export { layoutSignatureOf };
|
|
239
255
|
|
|
@@ -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): 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,IAA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MAAM,WAAW,EAAE,IAAI;EACvB,MAAM,WAAW,EAAE,gBAAgB,OAAO;CAC5C;CAEA,MAAM,OAAO;CACb,KAAK,MAAM,OAAO,MAChB,IACE,QAAQ,cACR,QAAQ,YACR,QAAQ,YACR,QAAQ,WACR,OAAO,OAAO,MAAM,GAAG,GAEvB,KAAK,KAAK,IAAI;CAGlB,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\nlet h3 = 0\nlet h4 = 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 a0 = h1\n let b0 = h2\n let a1 = h3\n let b1 = h4\n for (let index = 0, end = count * 2; index < end; index += 2) {\n const v0 = bits[index]!\n const v1 = bits[index + 1]!\n a0 = Math.imul(a0 ^ v0, 16777619)\n b0 = Math.imul(b0 ^ v0, 1597334677)\n a1 = Math.imul(a1 ^ v1, 16777619)\n b1 = Math.imul(b1 ^ v1, 1597334677)\n }\n h1 = a0\n h2 = b0\n h3 = a1\n h4 = b1\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 const packed = (len + 1) >> 1\n if (len < 128) {\n if (count + 2 + packed > WORDS) flush()\n words[count++] = STRING\n words[count++] = len\n let index = 0\n for (; index + 1 < len; index += 2) {\n words[count++] = value.charCodeAt(index) + value.charCodeAt(index + 1) * 65536\n }\n if (index < len) words[count++] = value.charCodeAt(index)\n } else {\n push(STRING)\n push(len)\n let index = 0\n for (; index + 1 < len; index += 2) {\n push(value.charCodeAt(index) + value.charCodeAt(index + 1) * 65536)\n }\n if (index < len) 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 h3 = 0x9e3779b9 | 0\n h4 = 0x85ebca6b | 0\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 const out1 = (h1 ^ Math.imul(h3, 0x85ebca6b)) >>> 0\n const out2 = (h2 ^ Math.imul(h4, 0xc2b2ae35)) >>> 0\n return `${out1}:${out2}`\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;AACT,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,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,IAAI,KAAK;CACT,KAAK,IAAI,QAAQ,GAAG,MAAM,QAAQ,GAAG,QAAQ,KAAK,SAAS,GAAG;EAC5D,MAAM,KAAK,KAAK;EAChB,MAAM,KAAK,KAAK,QAAQ;EACxB,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ;EAChC,KAAK,K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B,MAAM,WAAW,EAAE,gBAAgB,OAAO;CAC5C;CAEA,MAAM,OAAO;CACb,KAAK,MAAM,OAAO,MAChB,IACE,QAAQ,cACR,QAAQ,YACR,QAAQ,YACR,QAAQ,WACR,OAAO,OAAO,MAAM,GAAG,GAEvB,KAAK,KAAK,IAAI;CAGlB,MAAM;CACN,QAAQ,MAAM;CAGd,OAAO,IAFO,KAAK,KAAK,KAAK,IAAI,UAAU,OAAO,EAEnC,IADD,KAAK,KAAK,KAAK,IAAI,UAAU,OAAO;AAEpD"}
|
package/dist/dom/markup.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DomLayoutSnapshot } from '../types.js';
|
|
1
2
|
/**
|
|
2
3
|
* The markup contract's default selectors. The `data-text-*` names lead; the original
|
|
3
4
|
* `data-sdf-*` names are still read, so existing markup keeps working.
|
|
@@ -5,3 +6,12 @@
|
|
|
5
6
|
export declare const DEFAULT_TEXT_SELECTOR = "[data-text-block], [data-sdf-block]";
|
|
6
7
|
export declare const DEFAULT_RECT_SELECTOR = "[data-text-rect], [data-sdf-rect]";
|
|
7
8
|
export declare const DEFAULT_IGNORE_SELECTOR = "[data-text-ignore], [data-sdf-ignore]";
|
|
9
|
+
export declare const SNAPSHOT_FLAG_RUN_MOTION = 1;
|
|
10
|
+
export declare const SNAPSHOT_FLAG_IMMUTABLE_DOM = 2;
|
|
11
|
+
/** Per-snapshot bitmask stamped by `collectDomSnapshotSync` for O(1) motion and immutability checks. */
|
|
12
|
+
export declare const snapshotFlags: WeakMap<DomLayoutSnapshot, number>;
|
|
13
|
+
/** Lineage from an appended `glyphs` map back to the root map whose existing slots never move. */
|
|
14
|
+
export declare const atlasBaseMap: WeakMap<ReadonlyMap<string, unknown>, ReadonlyMap<string, unknown>>;
|
|
15
|
+
export declare const atlasRootOf: (map: ReadonlyMap<string, unknown>) => ReadonlyMap<string, unknown>;
|
|
16
|
+
export declare const isImmutableCapture: () => boolean;
|
|
17
|
+
export declare function withImmutableCapture<T>(fn: () => T): T;
|
package/dist/dom/markup.js
CHANGED
|
@@ -6,6 +6,21 @@
|
|
|
6
6
|
var DEFAULT_TEXT_SELECTOR = "[data-text-block], [data-sdf-block]";
|
|
7
7
|
var DEFAULT_RECT_SELECTOR = "[data-text-rect], [data-sdf-rect]";
|
|
8
8
|
var DEFAULT_IGNORE_SELECTOR = "[data-text-ignore], [data-sdf-ignore]";
|
|
9
|
-
|
|
9
|
+
/** Per-snapshot bitmask stamped by `collectDomSnapshotSync` for O(1) motion and immutability checks. */
|
|
10
|
+
var snapshotFlags = /* @__PURE__ */ new WeakMap();
|
|
11
|
+
/** Lineage from an appended `glyphs` map back to the root map whose existing slots never move. */
|
|
12
|
+
var atlasBaseMap = /* @__PURE__ */ new WeakMap();
|
|
13
|
+
var atlasRootOf = (map) => atlasBaseMap.get(map) ?? map;
|
|
14
|
+
var immutableCaptureDepth = 0;
|
|
15
|
+
var isImmutableCapture = () => immutableCaptureDepth > 0;
|
|
16
|
+
function withImmutableCapture(fn) {
|
|
17
|
+
immutableCaptureDepth++;
|
|
18
|
+
try {
|
|
19
|
+
return fn();
|
|
20
|
+
} finally {
|
|
21
|
+
immutableCaptureDepth--;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export { DEFAULT_IGNORE_SELECTOR, DEFAULT_RECT_SELECTOR, DEFAULT_TEXT_SELECTOR, atlasBaseMap, atlasRootOf, isImmutableCapture, snapshotFlags, withImmutableCapture };
|
|
10
25
|
|
|
11
26
|
//# sourceMappingURL=markup.js.map
|
package/dist/dom/markup.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markup.js","names":[],"sources":["../../src/dom/markup.ts"],"sourcesContent":["/**\n * The markup contract's default selectors. The `data-text-*` names lead; the original\n * `data-sdf-*` names are still read, so existing markup keeps working.\n */\nexport const DEFAULT_TEXT_SELECTOR = '[data-text-block], [data-sdf-block]'\nexport const DEFAULT_RECT_SELECTOR = '[data-text-rect], [data-sdf-rect]'\nexport const DEFAULT_IGNORE_SELECTOR = '[data-text-ignore], [data-sdf-ignore]'\n"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"markup.js","names":[],"sources":["../../src/dom/markup.ts"],"sourcesContent":["import type { DomLayoutSnapshot } from '../types.js'\n\n/**\n * The markup contract's default selectors. The `data-text-*` names lead; the original\n * `data-sdf-*` names are still read, so existing markup keeps working.\n */\nexport const DEFAULT_TEXT_SELECTOR = '[data-text-block], [data-sdf-block]'\nexport const DEFAULT_RECT_SELECTOR = '[data-text-rect], [data-sdf-rect]'\nexport const DEFAULT_IGNORE_SELECTOR = '[data-text-ignore], [data-sdf-ignore]'\n\nexport const SNAPSHOT_FLAG_RUN_MOTION = 1\nexport const SNAPSHOT_FLAG_IMMUTABLE_DOM = 2\n\n/** Per-snapshot bitmask stamped by `collectDomSnapshotSync` for O(1) motion and immutability checks. */\nexport const snapshotFlags = new WeakMap<DomLayoutSnapshot, number>()\n\n/** Lineage from an appended `glyphs` map back to the root map whose existing slots never move. */\nexport const atlasBaseMap = new WeakMap<\n ReadonlyMap<string, unknown>,\n ReadonlyMap<string, unknown>\n>()\n\nexport const atlasRootOf = (map: ReadonlyMap<string, unknown>): ReadonlyMap<string, unknown> =>\n atlasBaseMap.get(map) ?? map\n\nlet immutableCaptureDepth = 0\n\nexport const isImmutableCapture = (): boolean => immutableCaptureDepth > 0\n\nexport function withImmutableCapture<T>(fn: () => T): T {\n immutableCaptureDepth++\n try {\n return fn()\n } finally {\n immutableCaptureDepth--\n }\n}\n"],"mappings":";;;;;AAMA,IAAa,wBAAwB;AACrC,IAAa,wBAAwB;AACrC,IAAa,0BAA0B;;AAMvC,IAAa,gCAAgB,IAAI,QAAmC;;AAGpE,IAAa,+BAAe,IAAI,QAG9B;AAEF,IAAa,eAAe,QAC1B,aAAa,IAAI,GAAG,KAAK;AAE3B,IAAI,wBAAwB;AAE5B,IAAa,2BAAoC,wBAAwB;AAEzE,SAAgB,qBAAwB,IAAgB;CACtD;CACA,IAAI;EACF,OAAO,GAAG;CACZ,UAAU;EACR;CACF;AACF"}
|