ultra-text 1.0.1 → 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 +339 -1039
- package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
- 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 +97 -31
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +4 -3
- 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.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +14 -7
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.d.ts +1 -1
- package/dist/atlas/cpuSdf.js +235 -68
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +11 -3
- package/dist/atlas/cpuWorker.js +179 -22
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.js +188 -287
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +257 -0
- package/dist/atlas/gpuCommon.js +845 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.d.ts +1 -1
- package/dist/atlas/jfaWgsl.js +226 -249
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +22 -0
- package/dist/atlas/rasterize.js +329 -158
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1065 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +72 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +167 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
- package/dist/atlas/vanillaGpuHelpers.js +354 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +243 -297
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.js +94 -165
- 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 +53 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +16 -0
- package/dist/dom/fontCanvas.js +31 -13
- package/dist/dom/fontCanvas.js.map +1 -1
- package/dist/dom/layoutSignature.js +175 -57
- 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 +78 -28
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.d.ts +4 -0
- package/dist/dom/snapshot.js +891 -484
- 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.d.ts +8 -1
- package/dist/dom/svgCapture.js +105 -28
- 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 +91 -44
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +17 -3
- package/dist/slug/SlugMaterial.js +98 -26
- 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 +19 -15
- package/dist/slug/coverage.js +380 -225
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -2
- package/dist/slug/preprocessCore.js +199 -148
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +113 -74
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +3 -2
- package/dist/slug/standaloneRuntime.js +112 -67
- package/dist/slug/standaloneRuntime.js.map +1 -1
- package/dist/slug/truetype.d.ts +14 -6
- package/dist/slug/truetype.js +356 -255
- package/dist/slug/truetype.js.map +1 -1
- package/dist/slug/vanillaCore.d.ts +410 -0
- package/dist/slug/vanillaCore.js +1630 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -364
- package/dist/slug-vanilla.js +7 -1454
- package/dist/slug.d.ts +2 -2
- package/dist/slug.js +7 -7
- package/dist/text/GlyphTextMaterial.d.ts +6 -1
- package/dist/text/GlyphTextMaterial.js +16 -12
- 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 +125 -38
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.d.ts +7 -2
- package/dist/text/decorations.js +187 -79
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +16 -1
- package/dist/text/geometryUtils.js +83 -8
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +434 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +101 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +23 -1
- package/dist/text/reflow.js +223 -94
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +15 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- 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.d.ts +13 -363
- package/dist/vanilla.js +7 -1474
- 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 +17 -2
- package/dist/windfoil/geometry.js +220 -57
- 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.d.ts +1 -0
- package/dist/windfoil/mixed.js +57 -29
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/preprocess.js +2 -2
- package/dist/windfoil/preprocessCore.d.ts +2 -0
- package/dist/windfoil/preprocessCore.js +69 -37
- 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 +4 -1
- package/dist/windfoil/runtime.js +69 -63
- 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 +78 -6
- package/dist/windfoil/storage.js +166 -11
- 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.d.ts +5 -0
- package/dist/windfoil/trace/contours.js +256 -62
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -1
- package/dist/windfoil/trace/fit.js +915 -265
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +55 -30
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/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/trace/types.d.ts +10 -0
- package/dist/windfoil/tracedOutlines.d.ts +2 -0
- package/dist/windfoil/tracedOutlines.js +393 -103
- 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 +27 -25
- package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
- package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
- package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
- package/dist/slug-vanilla.js.map +0 -1
- package/dist/text/geometry.js +0 -348
- package/dist/text/geometry.js.map +0 -1
- package/dist/vanilla.js.map +0 -1
|
@@ -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 (/\\b(?:(?:all-)?(?:small|petite)-caps|unicase|titling-caps)\\b/.exec(font.variant)?.[0] ??\n '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 for (const [property, value] of [\n ['all', 'initial'],\n ['display', 'none'],\n ['direction', 'ltr'],\n ['-webkit-font-smoothing', 'antialiased'],\n ['-moz-osx-font-smoothing', 'grayscale'],\n ] as const)\n canvas.style.setProperty(property, value, '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"],"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,SAAuB,OAAuB,SAAkB;CAC/F,IAAI,QAAQ,OAAO,OAAO,QAAQ,MAAM,WAAW;CACnD,OAAO,SAAS,SAAU,SAAS,WAAW,iBAAiB,QAAQ,SAAS;AAClF;;AAGA,SAAgB,eACd,SACA,SACA,SACA,UACsB;CACtB,MAAM,EAAE,SAAS;CACjB,IAAI,aAAa,MAAM;EACrB,MAAM,WAA8B;EACpC,QAAQ,OAAO,KAAK;EACpB,IAAI,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,MAAM,WAAW,UAAU;EAC9B,IAAI,QAAQ,OAAO;EACnB,MAAM,UAAU,OAAO,IAAI,QAAQ,KAAK,GAAG;EAC3C,IAAI,SAAS,QAAQ,QAAQ,QAAQ;OAChC,OAAO,IAAI,QAAQ,KAAK,KAAK;GAAE,MAAM,QAAQ,KAAK;GAAY,MAAM,QAAQ;EAAU,CAAC;CAC9F;CACA,MAAM,KAAK,MAAM,WAAW,YAAY,EAAE,UAAW,MAA2B;CAChF,MAAM,QAAQ,IACZ,MAAM,KAAK,OAAO,OAAO,IAAI,MAAM;EACjC,IAAI;GACF,IAAI,MAAM,MAAM,MAAM,EAAE,MAAM,EAAE,IAAI,GAAG;EACzC,QAAQ,CAER;EACA,OAAO,MAAM,KAAK,EAAE,MAAM,EAAE,IAAI;CAClC,CAAC,CACH;CACA,IAAI,QAAQ,SACV,MAAM,OAAO,UAAU,IAAI,aAAa,+BAA+B,YAAY;AAEvF"}
|
|
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,GA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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"}
|
|
@@ -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) {
|
|
@@ -30,16 +39,32 @@ function push(value) {
|
|
|
30
39
|
words[count++] = value;
|
|
31
40
|
}
|
|
32
41
|
function walkString(value) {
|
|
33
|
-
|
|
42
|
+
let id = strings.get(value);
|
|
34
43
|
if (id === void 0) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
id = strings.size;
|
|
45
|
+
strings.set(value, id);
|
|
46
|
+
const len = value.length;
|
|
47
|
+
const packed = len + 1 >> 1;
|
|
48
|
+
if (len < 128) {
|
|
49
|
+
if (count + 2 + packed > WORDS) flush();
|
|
50
|
+
words[count++] = STRING;
|
|
51
|
+
words[count++] = len;
|
|
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);
|
|
55
|
+
} else {
|
|
56
|
+
push(STRING);
|
|
57
|
+
push(len);
|
|
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));
|
|
61
|
+
}
|
|
39
62
|
} else {
|
|
40
|
-
|
|
41
|
-
|
|
63
|
+
if (count > 2046) flush();
|
|
64
|
+
words[count++] = STRING_ID;
|
|
65
|
+
words[count++] = id;
|
|
42
66
|
}
|
|
67
|
+
return id;
|
|
43
68
|
}
|
|
44
69
|
function walk(value) {
|
|
45
70
|
if (typeof value === "number") {
|
|
@@ -66,43 +91,81 @@ function walk(value) {
|
|
|
66
91
|
function layoutSignatureOf(snapshot) {
|
|
67
92
|
h1 = 2166136261;
|
|
68
93
|
h2 = -624069552;
|
|
94
|
+
h3 = -1640531527;
|
|
95
|
+
h4 = -2048144789;
|
|
69
96
|
count = 0;
|
|
70
97
|
strings.clear();
|
|
71
98
|
const glyphs = snapshot.glyphs;
|
|
72
99
|
push(glyphs.length);
|
|
73
100
|
let prevKey;
|
|
74
101
|
let prevKeyId = -1;
|
|
102
|
+
let prevClip;
|
|
103
|
+
let pClip0 = 0;
|
|
104
|
+
let pClip1 = 0;
|
|
105
|
+
let pClip2 = 0;
|
|
106
|
+
let pClip3 = 0;
|
|
107
|
+
let prevColor;
|
|
108
|
+
let pColor0 = 0;
|
|
109
|
+
let pColor1 = 0;
|
|
110
|
+
let pColor2 = 0;
|
|
111
|
+
let pColor3 = 0;
|
|
75
112
|
for (let index = 0, length = glyphs.length; index < length; index++) {
|
|
76
113
|
const g = glyphs[index];
|
|
77
114
|
const { clip, color } = g;
|
|
78
115
|
const glyphKey = g.glyphKey;
|
|
79
116
|
if (glyphKey === prevKey) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
prevKeyId = id;
|
|
117
|
+
if (count > 2046) flush();
|
|
118
|
+
words[count++] = STRING_ID;
|
|
119
|
+
words[count++] = prevKeyId;
|
|
120
|
+
} else prevKeyId = walkString(prevKey = glyphKey);
|
|
121
|
+
let sameClip = index > 0 && clip === prevClip;
|
|
122
|
+
let c0 = 0;
|
|
123
|
+
let c1 = 0;
|
|
124
|
+
let c2 = 0;
|
|
125
|
+
let c3 = 0;
|
|
126
|
+
if (!sameClip) {
|
|
127
|
+
c0 = clip[0] + 0;
|
|
128
|
+
c1 = clip[1] + 0;
|
|
129
|
+
c2 = clip[2] + 0;
|
|
130
|
+
c3 = clip[3] + 0;
|
|
131
|
+
sameClip = index > 0 && c0 === pClip0 && c1 === pClip1 && c2 === pClip2 && c3 === pClip3;
|
|
96
132
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
133
|
+
let sameColor = index > 0 && color === prevColor;
|
|
134
|
+
let col0 = 0;
|
|
135
|
+
let col1 = 0;
|
|
136
|
+
let col2 = 0;
|
|
137
|
+
let col3 = 0;
|
|
138
|
+
if (!sameColor) {
|
|
139
|
+
col0 = color[0] + 0;
|
|
140
|
+
col1 = color[1] + 0;
|
|
141
|
+
col2 = color[2] + 0;
|
|
142
|
+
col3 = color[3] + 0;
|
|
143
|
+
sameColor = index > 0 && col0 === pColor0 && col1 === pColor1 && col2 === pColor2 && col3 === pColor3;
|
|
104
144
|
}
|
|
105
|
-
|
|
145
|
+
const breakBefore = g.breakBefore;
|
|
146
|
+
let flags = breakBefore === "none" ? 0 : breakBefore === "soft" ? 1 : breakBefore === "hard" ? 2 : 3;
|
|
147
|
+
if (sameClip) flags |= 4;
|
|
148
|
+
if (sameColor) flags |= 8;
|
|
149
|
+
const shapeGroup = g.shapeGroup;
|
|
150
|
+
const decorationWidth = g.decorationWidth;
|
|
151
|
+
const baselineOffset = g.baselineOffset;
|
|
152
|
+
const switchEm = g.switchEm;
|
|
153
|
+
const gapBefore = g.gapBefore;
|
|
154
|
+
const decorations = g.decorations;
|
|
155
|
+
const snap = g.snap;
|
|
156
|
+
const motionOrigin = g.motionOrigin;
|
|
157
|
+
if (shapeGroup !== void 0) flags |= 16;
|
|
158
|
+
if (decorationWidth !== void 0) flags |= 32;
|
|
159
|
+
if (baselineOffset !== void 0) flags |= 64;
|
|
160
|
+
if (switchEm !== void 0) flags |= 128;
|
|
161
|
+
if (gapBefore !== void 0) flags |= 256;
|
|
162
|
+
if (decorations !== void 0) flags |= 512;
|
|
163
|
+
if (snap !== void 0) flags |= 1024;
|
|
164
|
+
if (motionOrigin !== void 0) flags |= 2048;
|
|
165
|
+
if (count === WORDS) flush();
|
|
166
|
+
words[count++] = flags;
|
|
167
|
+
if ((flags & 3) === 3) walkString(breakBefore);
|
|
168
|
+
if (count > 2022) flush();
|
|
106
169
|
words[count++] = g.fontSize + 0;
|
|
107
170
|
words[count++] = g.originX + 0;
|
|
108
171
|
words[count++] = g.lineBottom + 0;
|
|
@@ -110,28 +173,83 @@ function layoutSignatureOf(snapshot) {
|
|
|
110
173
|
words[count++] = g.block + 0;
|
|
111
174
|
words[count++] = g.sequence + 0;
|
|
112
175
|
words[count++] = g.z + 0;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
if (
|
|
176
|
+
if (!sameClip) {
|
|
177
|
+
words[count++] = pClip0 = c0;
|
|
178
|
+
words[count++] = pClip1 = c1;
|
|
179
|
+
words[count++] = pClip2 = c2;
|
|
180
|
+
words[count++] = pClip3 = c3;
|
|
181
|
+
prevClip = clip;
|
|
182
|
+
}
|
|
183
|
+
if (!sameColor) {
|
|
184
|
+
words[count++] = pColor0 = col0;
|
|
185
|
+
words[count++] = pColor1 = col1;
|
|
186
|
+
words[count++] = pColor2 = col2;
|
|
187
|
+
words[count++] = pColor3 = col3;
|
|
188
|
+
prevColor = color;
|
|
189
|
+
}
|
|
190
|
+
if (shapeGroup !== void 0) words[count++] = shapeGroup + 0;
|
|
191
|
+
if (decorationWidth !== void 0) words[count++] = decorationWidth + 0;
|
|
192
|
+
if (baselineOffset !== void 0) words[count++] = baselineOffset + 0;
|
|
193
|
+
if (switchEm !== void 0) words[count++] = switchEm + 0;
|
|
194
|
+
if (gapBefore !== void 0) words[count++] = gapBefore + 0;
|
|
195
|
+
if (snap !== void 0) {
|
|
196
|
+
words[count++] = snap[0] + 0;
|
|
197
|
+
words[count++] = snap[1] + 0;
|
|
198
|
+
}
|
|
199
|
+
if (motionOrigin !== void 0) {
|
|
200
|
+
words[count++] = motionOrigin[0] + 0;
|
|
201
|
+
words[count++] = motionOrigin[1] + 0;
|
|
202
|
+
words[count++] = motionOrigin[2] + 0;
|
|
203
|
+
}
|
|
204
|
+
if (decorations !== void 0) walk(decorations);
|
|
205
|
+
}
|
|
206
|
+
const blocks = snapshot.blocks;
|
|
207
|
+
push(blocks.length);
|
|
208
|
+
for (let index = 0, length = blocks.length; index < length; index++) {
|
|
209
|
+
const b = blocks[index];
|
|
210
|
+
const bClip = b.clip;
|
|
211
|
+
if (count > 2038) flush();
|
|
212
|
+
words[count++] = b.left + 0;
|
|
213
|
+
words[count++] = b.firstBaseline + 0;
|
|
214
|
+
words[count++] = b.linePitch + 0;
|
|
215
|
+
words[count++] = b.width + 0;
|
|
216
|
+
words[count++] = bClip[0] + 0;
|
|
217
|
+
words[count++] = bClip[1] + 0;
|
|
218
|
+
words[count++] = bClip[2] + 0;
|
|
219
|
+
words[count++] = bClip[3] + 0;
|
|
220
|
+
let bFlags = 0;
|
|
221
|
+
if (b.direction !== void 0) bFlags |= 1;
|
|
222
|
+
if (b.textAlign !== void 0) bFlags |= 2;
|
|
223
|
+
if (b.textAlignLast !== void 0) bFlags |= 4;
|
|
224
|
+
words[count++] = bFlags;
|
|
225
|
+
if (b.direction !== void 0) walkString(b.direction);
|
|
226
|
+
if (b.textAlign !== void 0) walkString(b.textAlign);
|
|
227
|
+
if (b.textAlignLast !== void 0) walkString(b.textAlignLast);
|
|
228
|
+
}
|
|
229
|
+
const rects = snapshot.rects;
|
|
230
|
+
push(rects.length);
|
|
231
|
+
for (let index = 0, length = rects.length; index < length; index++) {
|
|
232
|
+
const r = rects[index];
|
|
233
|
+
const rr = r.rect;
|
|
234
|
+
const rc = r.color;
|
|
235
|
+
if (count > 2036) flush();
|
|
236
|
+
words[count++] = rr[0] + 0;
|
|
237
|
+
words[count++] = rr[1] + 0;
|
|
238
|
+
words[count++] = rr[2] + 0;
|
|
239
|
+
words[count++] = rr[3] + 0;
|
|
240
|
+
words[count++] = rc[0] + 0;
|
|
241
|
+
words[count++] = rc[1] + 0;
|
|
242
|
+
words[count++] = rc[2] + 0;
|
|
243
|
+
words[count++] = rc[3] + 0;
|
|
244
|
+
words[count++] = r.radius + 0;
|
|
245
|
+
words[count++] = r.z + 0;
|
|
246
|
+
words[count++] = r.receiveShadow ? TRUE : FALSE;
|
|
129
247
|
}
|
|
130
248
|
const root = snapshot;
|
|
131
|
-
for (const key in root) if (key !== "requests" && key !== "glyphs" && Object.hasOwn(root, key)) walk(root[key]);
|
|
249
|
+
for (const key in root) if (key !== "requests" && key !== "glyphs" && key !== "blocks" && key !== "rects" && Object.hasOwn(root, key)) walk(root[key]);
|
|
132
250
|
flush();
|
|
133
251
|
strings.clear();
|
|
134
|
-
return `${h1}:${h2}`;
|
|
252
|
+
return `${(h1 ^ Math.imul(h3, 2246822507)) >>> 0}:${(h2 ^ Math.imul(h4, 3266489909)) >>> 0}`;
|
|
135
253
|
}
|
|
136
254
|
export { layoutSignatureOf };
|
|
137
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): void {\n const id = strings.get(value)\n if (id === undefined) {\n strings.set(value, strings.size)\n push(STRING)\n push(value.length)\n for (let index = 0; index < value.length; index++) push(value.charCodeAt(index))\n } else {\n push(STRING_ID)\n push(id)\n }\n}\n\nfunction walk(value: unknown): void {\n // `+ 0` folds -0 into 0: both lay out the same.\n if (typeof value === 'number') {\n if (count === WORDS) flush()\n words[count++] = value + 0\n } else if (typeof value === 'string') walkString(value)\n else if (typeof value === 'boolean') push(value ? TRUE : FALSE)\n else if (typeof value === 'object' && value !== null) {\n push(OPEN)\n // Capture records have a fixed schema and stable declaration order.\n // Field names are identical across captures; only their values matter.\n if (Array.isArray(value)) {\n const length = value.length\n if (length > 0 && typeof value[0] === 'number') {\n if (count + length > WORDS) flush()\n for (let index = 0; index < length; index++) words[count++] = (value[index] as number) + 0\n } else {\n for (let index = 0; index < length; index++) walk(value[index])\n }\n } else {\n const record = value as Record<string, unknown>\n for (const key in record) {\n if (Object.hasOwn(record, key)) walk(record[key])\n }\n }\n push(CLOSE)\n } else push(OTHER)\n}\n\n/** Hash the capture directly, without allocating its much larger JSON string. */\nexport function layoutSignatureOf(snapshot: DomLayoutSnapshot): string {\n h1 = 0x811c9dc5\n h2 = 0x811c9dc5 ^ 0x5bd1e995\n count = 0\n strings.clear()\n const glyphs = snapshot.glyphs\n push(glyphs.length)\n let prevKey: string | undefined\n let prevKeyId = -1\n for (let index = 0, length = glyphs.length; index < length; index++) {\n const g = glyphs[index]!\n const { clip, color } = g\n const glyphKey = g.glyphKey\n if (glyphKey === prevKey) {\n push(STRING_ID)\n push(prevKeyId)\n } else {\n prevKey = glyphKey\n let id = strings.get(glyphKey)\n if (id === undefined) {\n id = strings.size\n strings.set(glyphKey, id)\n push(STRING)\n push(glyphKey.length)\n for (let i = 0; i < glyphKey.length; i++) push(glyphKey.charCodeAt(i))\n } else {\n push(STRING_ID)\n push(id)\n }\n prevKeyId = id\n }\n const breakBefore: string = g.breakBefore\n if (breakBefore === 'none') push(0)\n else if (breakBefore === 'soft') push(1)\n else if (breakBefore === 'hard') push(2)\n else {\n push(3)\n walkString(breakBefore)\n }\n if (count > WORDS - 24) flush()\n words[count++] = g.fontSize + 0\n words[count++] = g.originX + 0\n words[count++] = g.lineBottom + 0\n words[count++] = g.advance + 0\n words[count++] = g.block + 0\n words[count++] = g.sequence + 0\n words[count++] = g.z + 0\n words[count++] = clip[0] + 0\n words[count++] = clip[1] + 0\n words[count++] = clip[2] + 0\n words[count++] = clip[3] + 0\n words[count++] = color[0] + 0\n words[count++] = color[1] + 0\n words[count++] = color[2] + 0\n words[count++] = color[3] + 0\n words[count++] = (g.shapeGroup ?? OTHER) + 0\n words[count++] = (g.decorationWidth ?? OTHER) + 0\n words[count++] = (g.baselineOffset ?? OTHER) + 0\n words[count++] = (g.switchEm ?? OTHER) + 0\n words[count++] = (g.gapBefore ?? OTHER) + 0\n if (g.decorations) walk(g.decorations)\n if (g.snap) walk(g.snap)\n if (g.motionOrigin) walk(g.motionOrigin)\n }\n // Requests select retained glyph data separately through atlasSignature.\n const root = snapshot as unknown as Record<string, unknown>\n for (const key in root) {\n if (key !== 'requests' && key !== 'glyphs' && Object.hasOwn(root, key)) walk(root[key])\n }\n flush()\n strings.clear()\n return `${h1}:${h2}`\n}\n"],"mappings":";AAKA,IAAM,QAAQ;AACd,IAAM,QAAQ,IAAI,aAAa,KAAK;AACpC,IAAM,OAAO,IAAI,WAAW,MAAM,MAAM;AACxC,IAAM,0BAAU,IAAI,IAAoB;AACxC,IAAI,QAAQ;AACZ,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,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AAM,WAAW,EAAE,QAAQ;EAC3B,MAAM,WAAW,EAAE,WAAW;EAC9B,MAAM,WAAW,EAAE,IAAI;EACvB,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,KAAK,KAAK;EAC3B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,WAAW,MAAM,KAAK;EAC5B,MAAM,YAAY,EAAE,cAAc,SAAS;EAC3C,MAAM,YAAY,EAAE,mBAAmB,SAAS;EAChD,MAAM,YAAY,EAAE,kBAAkB,SAAS;EAC/C,MAAM,YAAY,EAAE,YAAY,SAAS;EACzC,MAAM,YAAY,EAAE,aAAa,SAAS;EAC1C,IAAI,EAAE,aAAa,KAAK,EAAE,WAAW;EACrC,IAAI,EAAE,MAAM,KAAK,EAAE,IAAI;EACvB,IAAI,EAAE,cAAc,KAAK,EAAE,YAAY;CACzC;CAEA,MAAM,OAAO;CACb,KAAK,MAAM,OAAO,MAChB,IAAI,QAAQ,cAAc,QAAQ,YAAY,OAAO,OAAO,MAAM,GAAG,GAAG,KAAK,KAAK,IAAI;CAExF,MAAM;CACN,QAAQ,MAAM;CACd,OAAO,GAAG,GAAG,GAAG;AAClB"}
|
|
1
|
+
{"version":3,"file":"layoutSignature.js","names":[],"sources":["../../src/dom/layoutSignature.ts"],"sourcesContent":["import type { DomLayoutSnapshot } from '../types.js'\n\n// The walk below writes the capture's values as float64 words into this small buffer, which\n// is hashed in one tight loop whenever it fills: about 2.5 times faster than mixing each value\n// through a closure, and nothing larger than these 16 KB stays allocated.\nconst WORDS = 2048\nconst words = new Float64Array(WORDS)\nconst bits = new Int32Array(words.buffer)\nconst strings = new Map<string, number>()\nlet count = 0\nlet h1 = 0\nlet h2 = 0\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,K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,KAAA,GAAW,WAAW,EAAE,aAAa;CAC/D;CACA,MAAM,QAAQ,SAAS;CACvB,KAAK,MAAM,MAAM;CACjB,KAAK,IAAI,QAAQ,GAAG,SAAS,MAAM,QAAQ,QAAQ,QAAQ,SAAS;EAClE,MAAM,IAAI,MAAM;EAChB,MAAM,KAAK,EAAE;EACb,MAAM,KAAK,EAAE;EACb,IAAI,QAAQ,MAAY,MAAM;EAC9B,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,GAAG,KAAK;EACzB,MAAM,WAAW,EAAE,SAAS;EAC5B,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;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"}
|
|
@@ -1,10 +1,49 @@
|
|
|
1
1
|
import { glyphClusters, isEmojiGrapheme } from "./clusters.js";
|
|
2
|
+
import { createSharedMeasureContext, isNativeMeasureBrowser } from "./fontCanvas.js";
|
|
2
3
|
import { transformText } from "./textTransform.js";
|
|
3
4
|
import { materializeRichInlineLineRange, prepareRichInline, walkRichInlineLineRanges } from "@chenglou/pretext/rich-inline";
|
|
4
5
|
// src/dom/pretextLayout.ts
|
|
6
|
+
var MAX_FONT_METRICS_CACHE = 64;
|
|
7
|
+
var ASCII_CHARS = Array.from({ length: 128 }, (_, i) => String.fromCharCode(i));
|
|
8
|
+
var sharedFontMetricsCache = /* @__PURE__ */ new Map();
|
|
9
|
+
var lastPretextFontSetSize = -1;
|
|
10
|
+
function acquireFontEntry(cache, layoutFont) {
|
|
11
|
+
const hit = cache.get(layoutFont);
|
|
12
|
+
if (hit) {
|
|
13
|
+
if (cache.size === 1) return hit;
|
|
14
|
+
cache.delete(layoutFont);
|
|
15
|
+
cache.set(layoutFont, hit);
|
|
16
|
+
return hit;
|
|
17
|
+
}
|
|
18
|
+
let entry;
|
|
19
|
+
if (cache.size >= MAX_FONT_METRICS_CACHE) {
|
|
20
|
+
const oldestKey = cache.keys().next().value;
|
|
21
|
+
entry = cache.get(oldestKey);
|
|
22
|
+
cache.delete(oldestKey);
|
|
23
|
+
entry.advances.clear();
|
|
24
|
+
entry.singles.length = 0;
|
|
25
|
+
for (const row of entry.pairs) row?.fill(NaN);
|
|
26
|
+
entry.emojiCorrection = NaN;
|
|
27
|
+
} else entry = {
|
|
28
|
+
advances: /* @__PURE__ */ new Map(),
|
|
29
|
+
singles: [],
|
|
30
|
+
pairs: [],
|
|
31
|
+
emojiCorrection: NaN
|
|
32
|
+
};
|
|
33
|
+
cache.set(layoutFont, entry);
|
|
34
|
+
return entry;
|
|
35
|
+
}
|
|
5
36
|
function createPretextCapture(root, document, options, bakeSize, invScale, rootRect, measuresBaselines, deviceScale, boxHeights, glyphs, displayNone, inlineBox, ignored, resolveParent, transformSeed, requestKey, parsePx, canvasFont, fontMetrics, trackLayoutGrid, resolveLayoutScale, canBreakCjk) {
|
|
6
|
-
const context = document
|
|
37
|
+
const context = createSharedMeasureContext(document);
|
|
7
38
|
if (!context) throw new Error("collectDomSnapshot: Canvas 2D is unavailable");
|
|
39
|
+
const nativeMeasure = isNativeMeasureBrowser(document);
|
|
40
|
+
if (nativeMeasure) {
|
|
41
|
+
const fontCount = document.fonts?.size ?? 0;
|
|
42
|
+
if (fontCount !== lastPretextFontSetSize) {
|
|
43
|
+
lastPretextFontSetSize = fontCount;
|
|
44
|
+
sharedFontMetricsCache.clear();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
8
47
|
const measureAdvance = (advances, previous, character) => {
|
|
9
48
|
const cacheKey = previous ? previous + "" + character : character;
|
|
10
49
|
let advance = advances.get(cacheKey);
|
|
@@ -18,27 +57,30 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
18
57
|
if (measuresBaselines && deviceScale !== 1) {
|
|
19
58
|
const range = document.createRange();
|
|
20
59
|
const walker = document.createTreeWalker(root, 4);
|
|
60
|
+
const nonWs = /\S/gu;
|
|
21
61
|
let samples = 16;
|
|
22
62
|
for (let node = walker.nextNode(); node && samples > 0; node = walker.nextNode()) {
|
|
23
63
|
const text = node;
|
|
24
64
|
const record = text.parentElement ? resolveParent(text.parentElement) : null;
|
|
25
65
|
if (!record?.inline || !record.owner) continue;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
nonWs.lastIndex = 0;
|
|
67
|
+
let match;
|
|
68
|
+
while (samples > 0 && (match = nonWs.exec(text.data)) !== null) {
|
|
69
|
+
range.setStart(text, match.index);
|
|
70
|
+
range.setEnd(text, match.index + match[0].length);
|
|
29
71
|
const box = range.getBoundingClientRect();
|
|
30
72
|
const height = box.height;
|
|
31
73
|
if (box.width <= 0 || height <= 0) continue;
|
|
32
74
|
trackLayoutGrid(box);
|
|
33
75
|
if (!boxHeights.has(record.inline.font)) boxHeights.set(record.inline.font, height);
|
|
34
|
-
|
|
76
|
+
samples--;
|
|
35
77
|
}
|
|
36
78
|
}
|
|
37
79
|
layoutScale = resolveLayoutScale(context);
|
|
38
80
|
}
|
|
39
81
|
const pretextScale = layoutScale ?? 1;
|
|
40
82
|
const runMetrics = /* @__PURE__ */ new Map();
|
|
41
|
-
const fontMetricsCache = /* @__PURE__ */ new Map();
|
|
83
|
+
const fontMetricsCache = nativeMeasure ? sharedFontMetricsCache : /* @__PURE__ */ new Map();
|
|
42
84
|
const lineCache = /* @__PURE__ */ new Map();
|
|
43
85
|
const blockStyleCache = /* @__PURE__ */ new Map();
|
|
44
86
|
return [
|
|
@@ -174,32 +216,22 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
174
216
|
let previousCode = -1;
|
|
175
217
|
let runWidth = 0;
|
|
176
218
|
let renderedCharacters = 0;
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
const [advances, ascii] = fontEntry;
|
|
184
|
-
for (const character of glyphClusters(fragment.text)) {
|
|
185
|
-
const code = character.length === 1 ? character.charCodeAt(0) : -1;
|
|
186
|
-
const isAscii = code >= 0 && code < 128;
|
|
187
|
-
let loneAdvance = isAscii ? ascii[code] : NaN;
|
|
188
|
-
if (Number.isNaN(loneAdvance)) {
|
|
189
|
-
loneAdvance = measureAdvance(advances, "", character);
|
|
190
|
-
if (isAscii) ascii[code] = loneAdvance;
|
|
191
|
-
}
|
|
219
|
+
const entry = acquireFontEntry(fontMetricsCache, inline.layoutFont);
|
|
220
|
+
const { advances, singles, pairs } = entry;
|
|
221
|
+
let emojiFragment = false;
|
|
222
|
+
const emitCharacter = (character, code, isAscii) => {
|
|
223
|
+
const loneAdvance = isAscii ? singles[code] ??= measureAdvance(advances, "", character) : measureAdvance(advances, "", character);
|
|
192
224
|
let advance = loneAdvance;
|
|
193
225
|
if (previousCharacter) {
|
|
194
226
|
if (isAscii && previousCode >= 0 && previousCode < 128) {
|
|
195
|
-
const
|
|
196
|
-
advance =
|
|
197
|
-
if (Number.isNaN(advance))
|
|
227
|
+
const row = pairs[previousCode] ??= (/* @__PURE__ */ new Float64Array(128)).fill(NaN);
|
|
228
|
+
advance = row[code];
|
|
229
|
+
if (Number.isNaN(advance)) row[code] = advance = context.measureText(previousCharacter + character).width - singles[previousCode];
|
|
198
230
|
} else advance = measureAdvance(advances, previousCharacter, character);
|
|
199
231
|
}
|
|
200
232
|
const kerning = advance - loneAdvance;
|
|
201
233
|
if (emojiFragment && isEmojiGrapheme(character)) {
|
|
202
|
-
if (Number.isNaN(
|
|
234
|
+
if (Number.isNaN(entry.emojiCorrection)) {
|
|
203
235
|
const probe = prepareRichInline([{
|
|
204
236
|
text: "😀",
|
|
205
237
|
font: inline.layoutFont
|
|
@@ -209,9 +241,9 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
209
241
|
corrected = probeLine.width;
|
|
210
242
|
});
|
|
211
243
|
context.font = measuredFont = inline.layoutFont;
|
|
212
|
-
|
|
244
|
+
entry.emojiCorrection = Math.max(0, context.measureText("😀").width - corrected);
|
|
213
245
|
}
|
|
214
|
-
advance -=
|
|
246
|
+
advance -= entry.emojiCorrection;
|
|
215
247
|
}
|
|
216
248
|
const spacing = renderedCharacters > 0 ? inline.letterSpacing : 0;
|
|
217
249
|
const nextWidth = runWidth + spacing + advance;
|
|
@@ -223,7 +255,7 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
223
255
|
previousCharacter = character;
|
|
224
256
|
previousCode = code;
|
|
225
257
|
renderedCharacters++;
|
|
226
|
-
|
|
258
|
+
return;
|
|
227
259
|
}
|
|
228
260
|
const key = requestKey(inline.font, inline.keys, character);
|
|
229
261
|
const isCjkSoft = options.cjkLineBreaking === true && canBreakCjk(previousBreakCharacter, character);
|
|
@@ -262,6 +294,24 @@ function createPretextCapture(root, document, options, bakeSize, invScale, rootR
|
|
|
262
294
|
previousCharacter = character;
|
|
263
295
|
previousCode = code;
|
|
264
296
|
renderedCharacters++;
|
|
297
|
+
};
|
|
298
|
+
const text = fragment.text;
|
|
299
|
+
const textLen = text.length;
|
|
300
|
+
let index = 0;
|
|
301
|
+
while (index < textLen) {
|
|
302
|
+
const code = text.charCodeAt(index);
|
|
303
|
+
if (code >= 128) break;
|
|
304
|
+
if (index + 1 < textLen && (text.charCodeAt(index + 1) >= 128 || code === 13)) break;
|
|
305
|
+
emitCharacter(ASCII_CHARS[code], code, true);
|
|
306
|
+
index++;
|
|
307
|
+
}
|
|
308
|
+
if (index < textLen) {
|
|
309
|
+
const tail = index === 0 ? text : text.slice(index);
|
|
310
|
+
emojiFragment = isEmojiGrapheme(tail);
|
|
311
|
+
for (const character of glyphClusters(tail)) {
|
|
312
|
+
const code = character.length === 1 ? character.charCodeAt(0) : -1;
|
|
313
|
+
emitCharacter(character, code, code >= 0 && code < 128);
|
|
314
|
+
}
|
|
265
315
|
}
|
|
266
316
|
penX += fragment.occupiedWidth;
|
|
267
317
|
}
|