ultra-text 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +267 -962
- package/THIRD_PARTY_NOTICES.md +3 -0
- package/dist/assets/{cpuSdf.worker-Du9o8q4p.js → cpuSdf.worker--X1Qpmdp.js} +148 -57
- package/dist/assets/cpuSdf.worker--X1Qpmdp.js.map +1 -0
- package/dist/atlas/appendAtlas.js +69 -26
- package/dist/atlas/appendAtlas.js.map +1 -1
- package/dist/atlas/buildAtlas.js +5 -15
- package/dist/atlas/buildAtlas.js.map +1 -1
- package/dist/atlas/cpuAtlas.d.ts +4 -1
- package/dist/atlas/cpuAtlas.js +8 -6
- package/dist/atlas/cpuAtlas.js.map +1 -1
- package/dist/atlas/cpuSdf.js +164 -50
- package/dist/atlas/cpuSdf.js.map +1 -1
- package/dist/atlas/cpuWorker.d.ts +5 -3
- package/dist/atlas/cpuWorker.js +119 -12
- package/dist/atlas/cpuWorker.js.map +1 -1
- package/dist/atlas/gpuAtlas.d.ts +7 -6
- package/dist/atlas/gpuAtlas.js +206 -247
- package/dist/atlas/gpuAtlas.js.map +1 -1
- package/dist/atlas/gpuCommon.d.ts +135 -0
- package/dist/atlas/gpuCommon.js +223 -0
- package/dist/atlas/gpuCommon.js.map +1 -0
- package/dist/atlas/jfaWgsl.js +59 -125
- package/dist/atlas/jfaWgsl.js.map +1 -1
- package/dist/atlas/rasterize.d.ts +2 -0
- package/dist/atlas/rasterize.js +104 -144
- package/dist/atlas/rasterize.js.map +1 -1
- package/dist/atlas/shapeRaster.js +2 -1
- package/dist/atlas/shapeRaster.js.map +1 -1
- package/dist/atlas/vanillaBounds.d.ts +64 -0
- package/dist/atlas/vanillaBounds.js +42 -0
- package/dist/atlas/vanillaBounds.js.map +1 -0
- package/dist/atlas/vanillaCore.d.ts +100 -0
- package/dist/atlas/vanillaCore.js +1012 -0
- package/dist/atlas/vanillaCore.js.map +1 -0
- package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
- package/dist/atlas/vanillaCpuAtlas.js +87 -0
- package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
- package/dist/atlas/vanillaExtras.d.ts +8 -0
- package/dist/atlas/vanillaExtras.js +166 -0
- package/dist/atlas/vanillaExtras.js.map +1 -0
- package/dist/atlas/vanillaGpuHelpers.d.ts +232 -0
- package/dist/atlas/vanillaGpuHelpers.js +119 -0
- package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
- package/dist/dom/DomSdf.js +263 -272
- package/dist/dom/DomSdf.js.map +1 -1
- package/dist/dom/DomSlug.d.ts +26 -0
- package/dist/dom/DomSlug.js +564 -0
- package/dist/dom/DomSlug.js.map +1 -0
- package/dist/dom/SlugText.d.ts +18 -0
- package/dist/dom/SlugText.js +94 -0
- package/dist/dom/SlugText.js.map +1 -0
- package/dist/dom/Text.js +4 -67
- package/dist/dom/Text.js.map +1 -1
- package/dist/dom/domAnalytic.d.ts +54 -0
- package/dist/dom/domAnalytic.js +282 -0
- package/dist/dom/domAnalytic.js.map +1 -0
- package/dist/dom/domExtras.d.ts +27 -0
- package/dist/dom/domExtras.js +137 -0
- package/dist/dom/domExtras.js.map +1 -0
- package/dist/dom/fontCanvas.d.ts +2 -0
- package/dist/dom/fontCanvas.js +119 -0
- package/dist/dom/fontCanvas.js.map +1 -0
- package/dist/dom/layoutSignature.js +156 -27
- package/dist/dom/layoutSignature.js.map +1 -1
- package/dist/dom/pretextLayout.js +55 -13
- package/dist/dom/pretextLayout.js.map +1 -1
- package/dist/dom/snapshot.js +563 -243
- package/dist/dom/snapshot.js.map +1 -1
- package/dist/dom/svgCapture.d.ts +8 -1
- package/dist/dom/svgCapture.js +75 -1
- package/dist/dom/svgCapture.js.map +1 -1
- package/dist/dom/textHost.d.ts +11 -0
- package/dist/dom/textHost.js +68 -0
- package/dist/dom/textHost.js.map +1 -0
- package/dist/dom/tone.js +76 -36
- package/dist/dom/tone.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/slug/SlugMaterial.d.ts +13 -4
- package/dist/slug/SlugMaterial.js +82 -12
- package/dist/slug/SlugMaterial.js.map +1 -1
- package/dist/slug/coverage.d.ts +17 -13
- package/dist/slug/coverage.js +195 -222
- package/dist/slug/coverage.js.map +1 -1
- package/dist/slug/preprocessCore.d.ts +6 -3
- package/dist/slug/preprocessCore.js +149 -95
- package/dist/slug/preprocessCore.js.map +1 -1
- package/dist/slug/runtime.d.ts +1 -0
- package/dist/slug/runtime.js +94 -46
- package/dist/slug/runtime.js.map +1 -1
- package/dist/slug/standaloneRuntime.d.ts +40 -0
- package/dist/slug/standaloneRuntime.js +175 -0
- package/dist/slug/standaloneRuntime.js.map +1 -0
- package/dist/slug/truetype.d.ts +22 -0
- package/dist/slug/truetype.js +467 -0
- package/dist/slug/truetype.js.map +1 -0
- package/dist/slug/vanillaCore.d.ts +340 -0
- package/dist/slug/vanillaCore.js +1621 -0
- package/dist/slug/vanillaCore.js.map +1 -0
- package/dist/slug-vanilla.d.ts +13 -0
- package/dist/slug-vanilla.js +13 -0
- package/dist/slug.d.ts +21 -0
- package/dist/slug.js +19 -0
- package/dist/text/GlyphTextMaterial.d.ts +11 -11
- package/dist/text/GlyphTextMaterial.js +102 -33
- package/dist/text/GlyphTextMaterial.js.map +1 -1
- package/dist/text/SdfTextMaterial.d.ts +5 -4
- package/dist/text/SdfTextMaterial.js +29 -9
- package/dist/text/SdfTextMaterial.js.map +1 -1
- package/dist/text/decorations.js +36 -19
- package/dist/text/decorations.js.map +1 -1
- package/dist/text/geometry.d.ts +3 -22
- package/dist/text/geometryUtils.d.ts +11 -1
- package/dist/text/geometryUtils.js +22 -1
- package/dist/text/geometryUtils.js.map +1 -1
- package/dist/text/glyphGeometry.d.ts +9 -0
- package/dist/text/glyphGeometry.js +353 -0
- package/dist/text/glyphGeometry.js.map +1 -0
- package/dist/text/index.d.ts +2 -1
- package/dist/text/rectGeometry.d.ts +13 -0
- package/dist/text/rectGeometry.js +97 -0
- package/dist/text/rectGeometry.js.map +1 -0
- package/dist/text/reflow.d.ts +18 -1
- package/dist/text/reflow.js +108 -38
- package/dist/text/reflow.js.map +1 -1
- package/dist/text/snap.d.ts +1 -0
- package/dist/text/snap.js +26 -0
- package/dist/text/snap.js.map +1 -0
- package/dist/types.d.ts +63 -14
- package/dist/vanilla.d.ts +13 -360
- package/dist/vanilla.js +8 -1402
- package/dist/windfoil/WindfoilMaterial.d.ts +2 -1
- package/dist/windfoil/WindfoilMaterial.js +8 -1
- package/dist/windfoil/WindfoilMaterial.js.map +1 -1
- package/dist/windfoil/abortable.d.ts +2 -0
- package/dist/windfoil/abortable.js +26 -0
- package/dist/windfoil/abortable.js.map +1 -0
- package/dist/windfoil/color.js +2 -1
- package/dist/windfoil/color.js.map +1 -1
- package/dist/windfoil/coverage.d.ts +3 -20
- package/dist/windfoil/coverage.js +7 -20
- package/dist/windfoil/coverage.js.map +1 -1
- package/dist/windfoil/emoji.js +1 -1
- package/dist/windfoil/emoji.js.map +1 -1
- package/dist/windfoil/emojiMetrics.js +1 -1
- package/dist/windfoil/emojiMetrics.js.map +1 -1
- package/dist/windfoil/geometry.d.ts +2 -2
- package/dist/windfoil/geometry.js +204 -64
- package/dist/windfoil/geometry.js.map +1 -1
- package/dist/windfoil/layerGrid.js +14 -10
- package/dist/windfoil/layerGrid.js.map +1 -1
- package/dist/windfoil/layerNormalization.d.ts +1 -1
- package/dist/windfoil/layerNormalization.js +1 -1
- package/dist/windfoil/layerNormalization.js.map +1 -1
- package/dist/windfoil/mixed.d.ts +1 -0
- package/dist/windfoil/mixed.js +44 -25
- package/dist/windfoil/mixed.js.map +1 -1
- package/dist/windfoil/outlineValidation.d.ts +86 -0
- package/dist/windfoil/outlineValidation.js +65 -0
- package/dist/windfoil/outlineValidation.js.map +1 -0
- package/dist/windfoil/preprocess.js +3 -2
- package/dist/windfoil/preprocess.js.map +1 -1
- package/dist/windfoil/preprocessCore.d.ts +5 -85
- package/dist/windfoil/preprocessCore.js +218 -209
- package/dist/windfoil/preprocessCore.js.map +1 -1
- package/dist/windfoil/requests.js +1 -1
- package/dist/windfoil/requests.js.map +1 -1
- package/dist/windfoil/runtime.d.ts +5 -2
- package/dist/windfoil/runtime.js +63 -40
- package/dist/windfoil/runtime.js.map +1 -1
- package/dist/windfoil/shapeResources.js +2 -1
- package/dist/windfoil/shapeResources.js.map +1 -1
- package/dist/windfoil/shapes.js +1 -1
- package/dist/windfoil/skirt.d.ts +22 -0
- package/dist/windfoil/skirt.js +20 -0
- package/dist/windfoil/skirt.js.map +1 -0
- package/dist/windfoil/storage.d.ts +62 -4
- package/dist/windfoil/storage.js +143 -28
- package/dist/windfoil/storage.js.map +1 -1
- package/dist/windfoil/trace/contours.d.ts +3 -3
- package/dist/windfoil/trace/contours.js +228 -137
- package/dist/windfoil/trace/contours.js.map +1 -1
- package/dist/windfoil/trace/fit.d.ts +3 -7
- package/dist/windfoil/trace/fit.js +668 -376
- package/dist/windfoil/trace/fit.js.map +1 -1
- package/dist/windfoil/trace/outline.js +60 -35
- package/dist/windfoil/trace/outline.js.map +1 -1
- package/dist/windfoil/trace/types.d.ts +15 -3
- package/dist/windfoil/tracedOutlines.d.ts +37 -1
- package/dist/windfoil/tracedOutlines.js +228 -64
- package/dist/windfoil/tracedOutlines.js.map +1 -1
- package/package.json +60 -11
- package/skills/ultra-text/SKILL.md +114 -0
- package/skills/ultra-text/references/frameworks.md +43 -0
- package/skills/ultra-text/references/three-tsl.md +78 -0
- package/skills/ultra-text/references/vanilla-webgpu.md +96 -0
- package/dist/assets/cpuSdf.worker-Du9o8q4p.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":"rasterize.js","names":[],"sources":["../../src/atlas/rasterize.ts"],"sourcesContent":["import type {\n ColorGlyphMode,\n GlyphRequest,\n GlyphSlot,\n RasterAtlas,\n RasterColorBand,\n} from '../types.js'\nimport { isEmojiCandidate, isEmojiGrapheme } from '../dom/clusters.js'\nimport type { setShapingContext } from '../dom/browserShaping.js'\n\ntype ShapingContext = typeof setShapingContext\n\n/** @internal Shared measured slot used by the lazy shape rasterizer. */\nexport interface MeasuredGlyph {\n readonly request: GlyphRequest\n readonly width: number\n readonly height: number\n readonly planeX0: number\n readonly planeY0: number\n readonly planeX1: number\n readonly planeY1: number\n readonly descent: number\n readonly advance: number\n readonly drawOffsetX: number\n /**\n * The ink box of a text glyph in plane units (x0, y0, x1, y1, y up from the baseline), from\n * the canvas's own metrics; absent where the slot is drawn whole.\n */\n readonly ink?: readonly [number, number, number, number]\n x: number\n y: number\n}\n\n/**\n * @internal The first atlas row of the monochrome shapes, when the raster holds any. They are\n * packed below the text so that a material can tell them from text by their place in the atlas.\n */\nexport interface ShapeRows {\n readonly shapeTop?: number\n}\n\n/**\n * @internal Where later text glyphs fit in an atlas without moving any slot: a shelf cursor\n * over its text rows, which end at `bottom`, the first row of its shapes or colour band (or its\n * height). Every slot that reaches row `y` or below ends left of `x`; below `y + rowHeight`\n * the text rows are free.\n */\nexport interface AppendCursor {\n readonly width: number\n readonly height: number\n readonly bakeSize: number\n readonly pxRange: number\n readonly colorGlyphs: ColorGlyphMode\n readonly bottom: number\n readonly x: number\n readonly y: number\n readonly rowHeight: number\n}\n\n/**\n * @internal The cursors of the rasters built with `appendable`, keyed by their glyph map, which\n * every `SdfAtlas` built from the raster shares. A few numbers each: no canvas is kept.\n */\nexport const appendCursors = new WeakMap<ReadonlyMap<string, GlyphSlot>, AppendCursor>()\n\ninterface PackedGlyphs {\n width: number\n height: number\n}\n\ninterface CanvasFontContext extends CanvasRenderingContext2D {\n fontKerning: CanvasFontKerning\n fontStretch: CanvasFontStretch\n fontVariantCaps: CanvasFontVariantCaps\n letterSpacing: string\n wordSpacing: string\n}\n\nexport interface RasterizeOptions {\n /** Colour-glyph detection; defaults to 'emoji'. */\n colorGlyphs?: ColorGlyphMode\n /** Canvas font raster size in pixels; must be at least `16`. Defaults to `96`. */\n bakeSize?: number\n /**\n * Retry overflowing atlases at a smaller bake size, down to 16px.\n * Defaults to `false`; fitting atlases keep their requested resolution.\n */\n adaptiveBakeSize?: boolean\n /**\n * Glyph slot padding in texels; must be at least `2`. Defaults to `12`. The\n * padding doubles as the SDF pixel range (`RasterAtlas.pxRange`).\n */\n padding?: number\n /**\n * Maximum atlas dimension in texels; must be an integer of at least `64`.\n * Defaults to `2048`. Glyphs that cannot pack reject instead of dropping. Text, monochrome\n * shapes and colour glyphs take rows of their own, one kind below the other.\n */\n maxAtlasSize?: number\n /** Aborts the rasterization between font waits and glyph draws. */\n signal?: AbortSignal\n /**\n * An atlas built earlier for the same fonts, with this `bakeSize` and `padding`\n * (`pxRange`): a colour candidate whose slot there already carries `GlyphSlot.color` keeps\n * that classification, instead of being drawn twice on a scratch canvas and read back.\n * Bitmap SVG shapes and glyphs it lacks are classified as usual, and every glyph is still\n * measured, packed and drawn: only the classification is reused. Omit it after a webfont\n * swap. `DomSdf` passes its retained atlas when a capture's new glyphs rebuild it in full.\n */\n previousAtlas?: Pick<RasterAtlas, 'glyphs' | 'bakeSize' | 'pxRange'> | undefined\n /**\n * @internal Set by `DomSdf` for its own SDF atlases. The raster then records its\n * `AppendCursor` in `appendCursors`, so that `appendAtlas.ts` can draw later text glyphs\n * into the live texture. `'headroom'` also leaves free text rows for them, within\n * `maxAtlasSize`: a tallest text slot, or a quarter of the text rows when more, between\n * the text and the shapes and colour band, which therefore keep their rows across appends,\n * in an atlas at least two of its widest text glyphs wide. DomSdf asks for it once an\n * instance has gained glyphs; a capture that never gains any stays tight.\n */\n appendable?: boolean | 'headroom' | undefined\n /**\n * @internal Set by `DomSdf` when only a WebGPU atlas uploads the raster. Without colour\n * candidates, which are read back, the bake canvas is then GPU-backed (no\n * `willReadFrequently`): its first draw on a page skips the software canvas's set-up, 7 to\n * 12 ms on an M3 Max, and the atlas copies it on the GPU. Reading such a canvas back takes\n * hundreds of milliseconds, which only the CPU fallback of a failed GPU build pays.\n */\n gpuUpload?: boolean | undefined\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\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n\nfunction nextPowerOfTwo(value: number): number {\n return 2 ** Math.ceil(Math.log2(Math.max(1, value)))\n}\n\nfunction align4(value: number): number {\n return Math.max(4, Math.ceil(value / 4) * 4)\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 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/** @internal Measures one text glyph's slot; `appendAtlas.ts` shares it with the cold build. */\nexport function measureGlyph(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n padding: number,\n shaping: ShapingContext | undefined,\n candidate = false,\n lastFont: GlyphRequest['font'] | null = null,\n): [MeasuredGlyph, GlyphRequest['font']] {\n const nextFont = setFontContext(context, request, shaping, lastFont)\n const metrics = context.measureText(request.character)\n const slice = request.shaping?.slice\n const from = slice?.[0] ?? 0\n const to = slice?.[1] ?? 1\n const advance = metrics.width * (to - from)\n const left = from === 0 ? Math.max(0, metrics.actualBoundingBoxLeft) : 0\n const right = slice\n ? advance + (to === 1 ? Math.max(0, metrics.actualBoundingBoxRight - metrics.width) : 0)\n : Math.max(metrics.width, metrics.actualBoundingBoxRight)\n const ascent = Math.max(1, metrics.fontBoundingBoxAscent || metrics.actualBoundingBoxAscent)\n const descent = Math.max(1, metrics.fontBoundingBoxDescent || metrics.actualBoundingBoxDescent)\n // A canvas draws text on a whole pixel row and, across, on a quarter pixel at best, whatever\n // origin it is given. The slot's origin is therefore a whole pixel: ink left of the origin\n // or taller than the font box was otherwise baked up to half a texel off, and the tiles of\n // a sliced run a quarter texel off each other.\n const drawOffsetX = metrics.width * from\n const planeX0 = -Math.ceil(left + padding - drawOffsetX) - drawOffsetX\n const planeX1 = right + padding\n const inkBounds =\n request.shaping !== undefined || candidate || isEmojiCandidate(request.character)\n const planeY0 = -Math.max(descent, inkBounds ? metrics.actualBoundingBoxDescent : 0) - padding\n const planeY1 = Math.ceil(\n Math.max(ascent, inkBounds ? metrics.actualBoundingBoxAscent : 0) + padding,\n )\n // Only whole, plain text glyphs trim their quads: a tile of a shaped line is clipped to its\n // slice, and colour candidates are bitmaps whose ink the metrics need not bound.\n const ink: MeasuredGlyph['ink'] =\n inkBounds || slice\n ? undefined\n : [\n -metrics.actualBoundingBoxLeft,\n -metrics.actualBoundingBoxDescent,\n metrics.actualBoundingBoxRight,\n metrics.actualBoundingBoxAscent,\n ]\n\n return [\n {\n request,\n width: Math.max(2, Math.ceil(planeX1 - planeX0) + 2),\n height: Math.max(2, Math.ceil(planeY1 - planeY0) + 2),\n planeX0,\n planeY0,\n planeX1,\n planeY1,\n descent,\n advance,\n drawOffsetX,\n ...(ink?.every(Number.isFinite) ? { ink } : {}),\n x: 0,\n y: 0,\n },\n nextFont,\n ]\n}\n\n/**\n * @internal The slot of a glyph drawn at (glyph.x, glyph.y) of a `width`×`height` atlas. The\n * full build and an append patch both take their slots from here, so they cannot drift apart.\n * A `banded` glyph is a colour candidate in the band; an `uncoloured` one a candidate that\n * classified as text.\n */\nexport function slotOf(\n glyph: MeasuredGlyph,\n padding: number,\n bakeSize: number,\n width: number,\n height: number,\n banded: boolean,\n uncoloured: boolean,\n): GlyphSlot {\n // The sampled window must follow the drawn plane box, not the shelf slot:\n // the slot is `ceil(extent) + 2` texels wide and the glyph origin above is\n // offset by one, so the plane spans texels 1 .. 1 + extent. Both bounds move\n // inward by half a texel so bilinear filtering cannot reach a neighbour.\n const slice = glyph.request.shaping?.slice\n const planeX0 = glyph.planeX0 + (slice && slice[0] > 0 ? -glyph.planeX0 : 0.5)\n const planeY0 = glyph.planeY0 + 0.5\n const planeX1 = glyph.planeX1 - (slice && slice[1] < 1 ? glyph.planeX1 - glyph.advance : 0.5)\n const planeY1 = glyph.planeY1 - 0.5\n const uv = (x0: number, y0: number, x1: number, y1: number) => ({\n u0: (glyph.x + 1 + x0 - glyph.planeX0) / width,\n v0: (glyph.y + 1 + glyph.planeY1 - y1) / height,\n u1: (glyph.x + 1 + x1 - glyph.planeX0) / width,\n v1: (glyph.y + 1 + glyph.planeY1 - y0) / height,\n })\n const ink = banded ? undefined : glyph.ink\n const reach = padding / 2 + 2 + 0.006 * bakeSize\n const sx0 = ink ? Math.max(planeX0, Math.floor(ink[0] - reach)) : 0\n const sy0 = ink ? Math.max(planeY0, Math.floor(ink[1] - reach)) : 0\n const sx1 = ink ? Math.min(planeX1, Math.ceil(ink[2] + reach)) : 0\n const sy1 = ink ? Math.min(planeY1, Math.ceil(ink[3] + reach)) : 0\n return {\n ...(uncoloured ? { color: false } : {}),\n key: glyph.request.key,\n character: glyph.request.character,\n fontKey: glyph.request.font.key,\n ...uv(planeX0, planeY0, planeX1, planeY1),\n planeX0,\n planeY0,\n planeX1,\n planeY1,\n descent: glyph.descent,\n advance: glyph.advance,\n ...(ink && sx1 > sx0 && sy1 > sy0 ? { support: uv(sx0, sy0, sx1, sy1) } : {}),\n }\n}\n\n/**\n * @internal Draws glyphs into their slots of one canvas, by the rules of the full build and of\n * an append patch alike. `reset()` forgets the context state cached here: call it whenever\n * the canvas is resized, which resets that state.\n */\nexport function glyphPainter(\n context: CanvasRenderingContext2D,\n shaping: ShapingContext | undefined,\n signal: AbortSignal | undefined,\n drawShape?: (glyph: MeasuredGlyph) => void,\n): { draw(glyph: MeasuredGlyph, text: boolean, fill?: string): void; reset(): void } {\n // A text mask must be the outline itself on every platform. The bake canvas has font\n // smoothing off; where the engine has the property, text also asks for exact geometry,\n // and it takes a mid grey fill, the neutral middle of a rasterizer's contrast table.\n // Colour glyphs keep the default rendering and the fills their classification compares;\n // shapes are paths, which none of this affects.\n const exactText = 'textRendering' in context\n let lastFont: GlyphRequest['font'] | null = null\n let lastFill = ''\n let lastTextRendering = ''\n return {\n reset() {\n lastFont = null\n lastFill = ''\n lastTextRendering = ''\n },\n draw(glyph, text, fill = '#fff') {\n throwIfAborted(signal)\n const targetFill = text ? '#606060' : fill\n if (lastFill !== targetFill) {\n context.fillStyle = targetFill\n lastFill = targetFill\n }\n if (glyph.request.shape) {\n drawShape!(glyph)\n lastFill = ''\n return\n }\n lastFont = setFontContext(context, glyph.request, shaping, lastFont)\n if (exactText) {\n const targetRendering = text ? 'geometricPrecision' : 'auto'\n if (lastTextRendering !== targetRendering) {\n context.textRendering = targetRendering\n lastTextRendering = targetRendering\n }\n }\n const originX = glyph.x - glyph.planeX0 + 1\n const baselineY = glyph.y + glyph.planeY1 + 1\n if (glyph.request.shaping?.slice) {\n context.save()\n context.beginPath()\n context.rect(\n glyph.x + 1,\n glyph.y + 1,\n glyph.planeX1 - glyph.planeX0,\n glyph.planeY1 - glyph.planeY0,\n )\n context.clip()\n context.fillText(glyph.request.character, originX - glyph.drawOffsetX, baselineY)\n context.restore()\n } else context.fillText(glyph.request.character, originX, baselineY)\n },\n }\n}\n\n/** The first row of a non-empty run of packed glyphs. */\nfunction topOf(rows: readonly MeasuredGlyph[]): number {\n return rows.reduce((top, glyph) => (glyph.y < top ? glyph.y : top), rows[0]!.y)\n}\n\nlet lastOverflowWidth = Infinity\n\n/** @internal Row-major shelf packing; also lays out the colour candidates of an append. */\nexport function packShelves(\n glyphs: MeasuredGlyph[],\n width: number,\n maxSize: number,\n): { width: number; height: number } | null {\n let x = 0\n let y = 0\n let rowHeight = 0\n let usedWidth = 0\n\n for (const glyph of glyphs) {\n const gw = glyph.width\n const gh = glyph.height\n if (gw > width) {\n if (gw < lastOverflowWidth) lastOverflowWidth = gw\n return null\n }\n if (gh > maxSize) return null\n if (x + gw > width) {\n if (x + gw < lastOverflowWidth) lastOverflowWidth = x + gw\n x = 0\n y += rowHeight\n rowHeight = 0\n }\n if (y + gh > maxSize) return null\n glyph.x = x\n glyph.y = y\n x += gw\n if (gh > rowHeight) rowHeight = gh\n if (x > usedWidth) usedWidth = x\n }\n\n return {\n width: align4(usedWidth),\n height: align4(y + rowHeight),\n }\n}\n\nlet skylineX = new Int32Array(256)\nlet skylineY = new Int32Array(256)\nlet skylineW = new Int32Array(256)\n\n/** Bottom-left skyline packing fills the vertical gaps that fixed-height shelves leave behind. */\nfunction packSkyline(\n glyphs: MeasuredGlyph[],\n width: number,\n maxSize: number,\n): { width: number; height: number } | null {\n const needed = glyphs.length + 2\n if (skylineX.length < needed) {\n skylineX = new Int32Array(needed)\n skylineY = new Int32Array(needed)\n skylineW = new Int32Array(needed)\n }\n const sx = skylineX\n const sy = skylineY\n const sw = skylineW\n sx[0] = 0\n sy[0] = 0\n sw[0] = width\n let skylineLen = 1\n let usedWidth = 0\n let usedHeight = 0\n const shift = (to: number, from: number): void => {\n sx.copyWithin(to, from, skylineLen)\n sy.copyWithin(to, from, skylineLen)\n sw.copyWithin(to, from, skylineLen)\n }\n\n const minH = glyphs[glyphs.length - 1]!.height\n let wasteBudget = width * maxSize\n const over = (): null => (\n (lastOverflowWidth = Math.min(lastOverflowWidth, width + Math.ceil(-wasteBudget / maxSize))),\n null\n )\n for (const g of glyphs) wasteBudget -= g.width * g.height\n if (wasteBudget < 0) return over()\n\n for (const glyph of glyphs) {\n const gw = glyph.width\n const gh = glyph.height\n if (gh > maxSize) return null\n let bestIndex = -1\n let bestBottom = Infinity\n let bestWaste = Infinity\n const tail = skylineLen - 1\n let maxAllowedY = sw[tail]! >= gw && sy[tail]! < maxSize - gh ? sy[tail]! : maxSize - gh\n\n for (let index = 0; index < skylineLen; index++) {\n const firstY = sy[index]!\n if (firstY > maxAllowedY) continue\n const x = sx[index]!\n if (x + gw > width) {\n if (x + gw < lastOverflowWidth) lastOverflowWidth = x + gw\n break\n }\n\n let remaining = gw - sw[index]!\n let y = firstY\n let waste = 0\n if (remaining > 0) {\n let coveredArea = sw[index]! * firstY\n for (let cursor = index + 1; ; cursor++) {\n const nodeY = sy[cursor]!\n if (nodeY > maxAllowedY) {\n index = cursor\n remaining = 1\n break\n }\n if (nodeY > y) y = nodeY\n const nodeW = sw[cursor]!\n coveredArea += (remaining < nodeW ? remaining : nodeW) * nodeY\n if ((remaining -= nodeW) <= 0) break\n }\n if (remaining > 0) continue\n waste = y * gw - coveredArea\n }\n const bottom = y + gh\n if (bottom < bestBottom || waste < bestWaste) {\n bestIndex = index\n bestBottom = bottom\n bestWaste = waste\n maxAllowedY = waste === 0 ? y - 1 : y\n if (maxAllowedY < 0) break\n }\n }\n if (maxAllowedY >= 0 && usedWidth + gw < lastOverflowWidth) lastOverflowWidth = usedWidth + gw\n\n if (\n bestIndex < 0 ||\n (wasteBudget -= bestWaste + (bestBottom > maxSize - minH ? gw * (maxSize - bestBottom) : 0)) <\n 0\n )\n return bestIndex < 0 ? null : over()\n const gx = sx[bestIndex]!\n const right = gx + gw\n glyph.x = gx\n glyph.y = bestBottom - gh\n let cursor = bestIndex\n while (cursor < skylineLen && sx[cursor]! + sw[cursor]! <= right) cursor++\n if (cursor < skylineLen && sx[cursor]! < right) {\n sw[cursor] = sx[cursor]! + sw[cursor]! - right\n sx[cursor] = right\n }\n let newCount = 1\n if (bestIndex > 0 && sy[bestIndex - 1] === bestBottom) {\n sw[bestIndex - 1] = sw[bestIndex - 1]! + gw\n newCount = 0\n if (cursor < skylineLen && sy[cursor] === bestBottom) {\n sw[bestIndex - 1] = sw[bestIndex - 1]! + sw[cursor]!\n cursor++\n }\n } else if (cursor < skylineLen && sy[cursor] === bestBottom) {\n sx[cursor] = gx\n sw[cursor] = sw[cursor]! + gw\n newCount = 0\n }\n const delta = newCount - (cursor - bestIndex)\n if (delta !== 0 && cursor < skylineLen) shift(cursor + delta, cursor)\n skylineLen += delta\n if (newCount) {\n sx[bestIndex] = gx\n sy[bestIndex] = bestBottom\n sw[bestIndex] = gw\n }\n\n if (right > usedWidth) usedWidth = right\n if (bestBottom > usedHeight) usedHeight = bestBottom\n }\n\n return { width: align4(usedWidth), height: align4(usedHeight) }\n}\n\n/** Packs each group into rows of its own, one group below the other. */\nfunction packStacked(\n groups: readonly MeasuredGlyph[][],\n width: number,\n limit: number,\n pack: typeof packShelves,\n): { width: number; height: number } | null {\n let packedWidth = 0\n let height = 0\n for (const group of groups) {\n const packed = pack(group, width, limit - height)\n if (!packed || height + packed.height > limit) return null\n for (const glyph of group) glyph.y += height\n packedWidth = Math.max(packedWidth, packed.width)\n height += packed.height\n }\n return { width: packedWidth, height }\n}\n\nfunction rememberPacking(\n glyphs: readonly MeasuredGlyph[],\n size: { width: number; height: number },\n positions: Int32Array,\n): PackedGlyphs {\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n positions[index * 2] = glyph.x\n positions[index * 2 + 1] = glyph.y\n }\n return { width: size.width, height: size.height }\n}\n\nfunction isBetterPacking(\n candidate: Pick<PackedGlyphs, 'width' | 'height'>,\n current: PackedGlyphs,\n): boolean {\n return (\n (candidate.width * candidate.height - current.width * current.height ||\n Math.max(candidate.width, candidate.height) - Math.max(current.width, current.height) ||\n candidate.width - current.width) < 0\n )\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 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 const fonts = document.fonts as FontFaceSet | undefined\n if (!fonts) 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 throwIfAborted(signal)\n}\n\n/**\n * Rasterizes every required font-face/character or emoji-sequence pair into one tightly packed\n * alpha atlas. The output is a transient mask; the retained texture is a\n * single-channel distance field produced by the CPU or WebGPU compute backend.\n */\nexport async function rasterizeGlyphAtlas(\n document: Document,\n requests: readonly GlyphRequest[],\n options: RasterizeOptions = {},\n): Promise<RasterAtlas> {\n const bakeSize = options.bakeSize ?? 96\n const padding = options.padding ?? 12\n const maxAtlasSize = options.maxAtlasSize ?? 2048\n if (!Number.isFinite(bakeSize) || bakeSize < 16) {\n throw new RangeError('rasterizeGlyphAtlas: bakeSize must be at least 16')\n }\n if (!Number.isFinite(padding) || padding < 2) {\n throw new RangeError('rasterizeGlyphAtlas: padding must be at least 2')\n }\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 64) {\n throw new RangeError('rasterizeGlyphAtlas: maxAtlasSize must be an integer of at least 64')\n }\n\n throwIfAborted(options.signal)\n const [, shapingModule, shapes] = await Promise.all([\n waitForFonts(document, requests, options.signal),\n requests.some((request) => request.shaping) ? import('../dom/browserShaping.js') : undefined,\n requests.some((request) => request.shape) ? import('./shapeRaster.js') : undefined,\n ])\n const shaping = shapingModule?.setShapingContext\n throwIfAborted(options.signal)\n\n const canvas = createCanvas(document)\n try {\n // A glyph a matching previous atlas has classified keeps its classification. A bitmap\n // shape always keeps its place in the band, as on a cold build: never history-dependent.\n const previous =\n options.previousAtlas?.bakeSize === bakeSize && options.previousAtlas.pxRange === padding\n ? options.previousAtlas.glyphs\n : undefined\n const context = canvas.getContext('2d', {\n willReadFrequently:\n !options.gpuUpload ||\n requests.some(\n (request) =>\n isColorCandidate(request, options.colorGlyphs) &&\n (request.shape !== undefined ||\n ((options.colorGlyphs === 'all' || isEmojiGrapheme(request.character)) &&\n previous?.get(request.key)?.color !== false)),\n ),\n })\n if (!context) throw new Error('rasterizeGlyphAtlas: Canvas 2D is unavailable')\n\n const packingLimit = maxAtlasSize - (maxAtlasSize % 4)\n let lastFont: GlyphRequest['font'] | null = null\n const measured = requests.map((request) => {\n if (request.shape) return shapes!.measureShape(request, bakeSize, padding)\n const [glyph, nextFont] = measureGlyph(\n context,\n request,\n padding,\n shaping,\n isColorCandidate(request, options.colorGlyphs),\n lastFont,\n )\n lastFont = nextFont\n return glyph\n })\n measured.sort(\n (a, b) =>\n b.height - a.height ||\n b.width - a.width ||\n (a.request.key < b.request.key ? -1 : a.request.key > b.request.key ? 1 : 0),\n )\n\n const banded = new Set<MeasuredGlyph>()\n const uncoloured = new Set<MeasuredGlyph>()\n const tested: MeasuredGlyph[] = []\n for (const glyph of measured) {\n if (!isColorCandidate(glyph.request, options.colorGlyphs)) continue\n const known = glyph.request.shape ? undefined : previous?.get(glyph.request.key)?.color\n if (known === false) uncoloured.add(glyph)\n else {\n banded.add(glyph)\n if (!glyph.request.shape && known === undefined) tested.push(glyph)\n }\n }\n const painter = glyphPainter(context, shaping, options.signal, (glyph) => {\n shapes!.drawShapeSlot(context, glyph, bakeSize)\n })\n const drawGlyph = (glyph: MeasuredGlyph, fill?: string): void => {\n painter.draw(glyph, !glyph.request.shape && !banded.has(glyph), fill)\n }\n\n // A candidate the font draws in the fill colour alone is text, whatever Unicode lists it\n // as: a copyright sign, an arrow, the tiles of a shaped line beside the one that holds\n // its emoji. Each font candidate is drawn in black and in white on a pack of their own,\n // and only one with ink that ignores the fill keeps its place in the band; the others are\n // baked, packed and flagged with the text.\n const colorGlyphs = banded.size ? await import('./colorGlyphs.js') : undefined\n throwIfAborted(options.signal)\n const scratch = tested.length ? packShelves(tested, packingLimit, packingLimit) : null\n if (scratch) {\n canvas.width = scratch.width\n canvas.height = scratch.height\n painter.reset()\n const paint = (fill: string): Uint8ClampedArray => {\n context.clearRect(0, 0, canvas.width, canvas.height)\n for (const glyph of tested) drawGlyph(glyph, fill)\n return context.getImageData(0, 0, canvas.width, canvas.height).data\n }\n const dark = paint('#000')\n const { colored } = colorGlyphs!.encodeColorBand(\n paint('#fff'),\n dark,\n canvas.width,\n canvas.height,\n 0,\n tested,\n )\n tested.forEach((glyph, index) => {\n if (colored[index]) return\n banded.delete(glyph)\n uncoloured.add(glyph)\n })\n }\n\n // Three kinds of rows, top to bottom: text, monochrome shapes, colour.\n const textRows: MeasuredGlyph[] = []\n const shapeRows: MeasuredGlyph[] = []\n const band: MeasuredGlyph[] = []\n let totalArea = 0\n let widestGlyph = 4\n let exceedsLimit = false\n for (const glyph of measured) {\n totalArea += glyph.width * glyph.height\n if (glyph.width > widestGlyph) widestGlyph = glyph.width\n if (glyph.width > packingLimit || glyph.height > packingLimit) exceedsLimit = true\n if (banded.has(glyph)) band.push(glyph)\n else if (glyph.request.shape) shapeRows.push(glyph)\n else textRows.push(glyph)\n }\n const groups = [textRows, shapeRows, band].filter((group) => group.length)\n const packGlyphs = (pack: typeof packShelves, width: number, limit: number) =>\n groups.length > 1 ? packStacked(groups, width, limit, pack) : pack(measured, width, limit)\n const impossible = totalArea > packingLimit * packingLimit || exceedsLimit\n const bestPositions = new Int32Array(measured.length * 2)\n let shelfWidth = Math.min(packingLimit, Math.max(64, nextPowerOfTwo(Math.sqrt(totalArea))))\n let packed = impossible ? null : packGlyphs(packShelves, shelfWidth, packingLimit)\n while (!packed && shelfWidth < packingLimit) {\n shelfWidth = Math.min(packingLimit, shelfWidth * 2)\n packed = packGlyphs(packShelves, shelfWidth, packingLimit)\n }\n let best = packed && !impossible ? rememberPacking(measured, packed, bestPositions) : null\n\n if (!impossible && measured.length > 0) {\n const minRequiredLimit = groups.reduce((sum, g) => sum + align4(g[0]!.height), 0)\n const minimumWidth = Math.min(\n packingLimit,\n align4(Math.max(widestGlyph, Math.ceil(totalArea / packingLimit))),\n )\n // Search at most about 64 aligned widths. Trying both the shelf and skyline\n // heuristic keeps the old pack as a no-regression candidate while allowing\n // short glyphs to occupy holes below taller neighbours.\n const widthStep = align4(Math.max(4, Math.ceil((packingLimit - minimumWidth) / 64)))\n const maxHeightFor = (width: number): number =>\n best ? Math.min(packingLimit, Math.floor((best.width * best.height) / width)) : packingLimit\n const nextW = [minimumWidth, minimumWidth]\n for (let width = minimumWidth; ; width = Math.min(packingLimit, width + widthStep)) {\n throwIfAborted(options.signal)\n if (maxHeightFor(width) < minRequiredLimit) break\n const minH = align4(Math.max(minRequiredLimit, Math.ceil(totalArea / width)))\n for (let i = 0; i < 2; i++) {\n if (width < nextW[i]!) continue\n const maxCandidateHeight = maxHeightFor(width)\n if (minH > maxCandidateHeight) break\n lastOverflowWidth = Infinity\n const candidate = packGlyphs(i ? packSkyline : packShelves, width, maxCandidateHeight)\n nextW[i] = lastOverflowWidth\n if (candidate && (!best || isBetterPacking(candidate, best))) {\n best = rememberPacking(measured, candidate, bestPositions)\n }\n }\n if (width === packingLimit) break\n }\n }\n\n if (!best) {\n if (options.adaptiveBakeSize === true && bakeSize > 16) {\n const nextSize = Math.max(16, Math.floor(bakeSize * 0.8))\n const scaled = requests.map((request) => ({\n ...request,\n font: {\n ...request.font,\n canvasFont: request.font.canvasFont.replace(\n /[\\d.]+px/,\n (size) => `${(Number.parseFloat(size) * nextSize) / bakeSize}px`,\n ),\n },\n }))\n return await rasterizeGlyphAtlas(document, scaled, { ...options, bakeSize: nextSize })\n }\n throw new Error(\n `rasterizeGlyphAtlas: ${requests.length} glyphs exceed the ${maxAtlasSize}×${maxAtlasSize} atlas limit`,\n )\n }\n for (let index = 0; index < measured.length; index++) {\n measured[index]!.x = bestPositions[index * 2]!\n measured[index]!.y = bestPositions[index * 2 + 1]!\n }\n\n // The text rows, packed first, end where the shapes or else the colour band begin. Headroom\n // for later appends goes there, so the rows below move down once, now, never on an append.\n let textBottom = !textRows.length ? 0 : groups.length > 1 ? topOf(groups[1]!) : best.height\n if (options.appendable === 'headroom' && textRows.length) {\n // Rows of at least two of the widest text glyphs: a one-column atlas has no row that\n // takes a glyph wider than its own.\n let widestText = 0\n for (const glyph of textRows) if (glyph.width > widestText) widestText = glyph.width\n best.width = Math.min(packingLimit, Math.max(best.width, align4(2 * widestText)))\n const room = Math.min(\n packingLimit - best.height,\n align4(Math.max(textRows[0]!.height, textBottom / 4)),\n )\n if (room > 0) {\n for (const glyph of measured) if (glyph.y >= textBottom) glyph.y += room\n best.height += room\n textBottom += room\n }\n }\n\n canvas.width = best.width\n canvas.height = best.height\n painter.reset()\n context.clearRect(0, 0, canvas.width, canvas.height)\n const bandTop = band.length ? topOf(band) : 0\n const bandHeight = canvas.height - bandTop\n let black: Uint8ClampedArray | undefined\n if (band.length) {\n for (const glyph of band) drawGlyph(glyph, '#000')\n black = context.getImageData(0, bandTop, canvas.width, bandHeight).data\n context.clearRect(0, bandTop, canvas.width, bandHeight)\n }\n const glyphSlots = new Map<string, GlyphSlot>()\n for (const glyph of measured) {\n drawGlyph(glyph)\n glyphSlots.set(\n glyph.request.key,\n slotOf(\n glyph,\n padding,\n bakeSize,\n canvas.width,\n canvas.height,\n banded.has(glyph),\n uncoloured.has(glyph),\n ),\n )\n }\n\n let colorBand: RasterColorBand | undefined\n if (black) {\n const white = context.getImageData(0, bandTop, canvas.width, bandHeight).data\n const encoded = colorGlyphs!.encodeColorBand(\n white,\n black,\n canvas.width,\n bandHeight,\n padding,\n band.map((glyph) => ({ ...glyph, y: glyph.y - bandTop })),\n )\n for (const [index, glyph] of band.entries()) {\n const slot = glyphSlots.get(glyph.request.key)!\n glyphSlots.set(glyph.request.key, { ...slot, color: encoded.colored[index]! })\n }\n if (encoded.colored.some(Boolean))\n colorBand = { top: bandTop, height: bandHeight, data: encoded.data }\n }\n const shapeTop = shapeRows.length ? topOf(shapeRows) : undefined\n if (options.appendable) {\n // The last text row is the one the lowest-starting slot begins on; whatever reaches\n // that row or below bounds where the cursor starts and how far the row runs down.\n let x = 0\n let y = 0\n let rowHeight = 0\n for (const glyph of textRows)\n if (glyph.y > y && glyph.y + textRows[0]!.height <= textBottom) y = glyph.y\n for (const glyph of textRows) {\n const reach = glyph.y + glyph.height - y\n if (reach > 0) {\n if (glyph.x + glyph.width > x) x = glyph.x + glyph.width\n if (reach > rowHeight) rowHeight = reach\n }\n }\n appendCursors.set(glyphSlots, {\n width: canvas.width,\n height: canvas.height,\n bakeSize,\n pxRange: padding,\n colorGlyphs: options.colorGlyphs ?? 'emoji',\n bottom: textBottom,\n x,\n y,\n rowHeight,\n })\n }\n return {\n ...(colorBand ? { colorBand } : {}),\n ...(shapeTop !== undefined ? { shapeTop } : {}),\n canvas,\n width: canvas.width,\n height: canvas.height,\n bakeSize,\n pxRange: padding,\n glyphs: glyphSlots,\n }\n } finally {\n canvas.remove()\n }\n}\n"],"mappings":";;;;;;AA+DA,IAAa,gCAAgB,IAAI,QAAsD;;AAoEvF,SAAgB,iBAAiB,SAAuB,OAAuB,SAAkB;CAC/F,IAAI,QAAQ,OAAO,OAAO,QAAQ,MAAM,WAAW;CACnD,OAAO,SAAS,SAAU,SAAS,WAAW,iBAAiB,QAAQ,SAAS;AAClF;AAEA,SAAS,eAAe,QAA4B;CAClD,IAAI,QAAQ,SACV,MAAM,OAAO,UAAU,IAAI,aAAa,+BAA+B,YAAY;AAEvF;AAEA,SAAS,eAAe,OAAuB;CAC7C,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,CAAC;AACrD;AAEA,SAAS,OAAO,OAAuB;CACrC,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC;AAC7C;AAEA,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;CAC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;EACR,OAAO,OAAO;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"rasterize.js","names":[],"sources":["../../src/atlas/rasterize.ts"],"sourcesContent":["import type {\n ColorGlyphMode,\n GlyphRequest,\n GlyphSlot,\n RasterAtlas,\n RasterColorBand,\n} from '../types.js'\nimport { isEmojiCandidate, isEmojiGrapheme } from '../dom/clusters.js'\nimport {\n createCanvas,\n isColorCandidate,\n setFontContext,\n waitForFonts,\n type ShapingContext,\n} from '../dom/fontCanvas.js'\n\nexport { createCanvas, isColorCandidate, setFontContext, waitForFonts }\n\n/** @internal Shared measured slot used by the lazy shape rasterizer. */\nexport interface MeasuredGlyph {\n readonly request: GlyphRequest\n readonly width: number\n readonly height: number\n readonly planeX0: number\n readonly planeY0: number\n readonly planeX1: number\n readonly planeY1: number\n readonly descent: number\n readonly advance: number\n readonly drawOffsetX: number\n /**\n * The ink box of a text glyph in plane units (x0, y0, x1, y1, y up from the baseline), from\n * the canvas's own metrics; absent where the slot is drawn whole.\n */\n readonly ink?: readonly [number, number, number, number]\n x: number\n y: number\n flags?: number\n}\n\n/**\n * @internal The first atlas row of the monochrome shapes, when the raster holds any. They are\n * packed below the text so that a material can tell them from text by their place in the atlas.\n */\nexport interface ShapeRows {\n readonly shapeTop?: number\n}\n\n/**\n * @internal Where later text glyphs fit in an atlas without moving any slot: a shelf cursor\n * over its text rows, which end at `bottom`, the first row of its shapes or colour band (or its\n * height). Every slot that reaches row `y` or below ends left of `x`; below `y + rowHeight`\n * the text rows are free.\n */\nexport interface AppendCursor {\n readonly width: number\n readonly height: number\n readonly bakeSize: number\n readonly pxRange: number\n readonly colorGlyphs: ColorGlyphMode\n readonly bottom: number\n readonly x: number\n readonly y: number\n readonly rowHeight: number\n}\n\n/**\n * @internal The cursors of the rasters built with `appendable`, keyed by their glyph map, which\n * every `SdfAtlas` built from the raster shares. A few numbers each: no canvas is kept.\n */\nexport const appendCursors = new WeakMap<ReadonlyMap<string, GlyphSlot>, AppendCursor>()\n\ninterface PackedGlyphs {\n width: number\n height: number\n}\n\nexport interface RasterizeOptions {\n /** Colour-glyph detection; defaults to 'emoji'. */\n colorGlyphs?: ColorGlyphMode\n /** Canvas font raster size in pixels; must be at least `16`. Defaults to `96`. */\n bakeSize?: number\n /**\n * Retry overflowing atlases at a smaller bake size, down to 16px.\n * Defaults to `false`; fitting atlases keep their requested resolution.\n */\n adaptiveBakeSize?: boolean\n /**\n * Glyph slot padding in texels; must be at least `2`. Defaults to `12`. The\n * padding doubles as the SDF pixel range (`RasterAtlas.pxRange`).\n */\n padding?: number\n /**\n * Maximum atlas dimension in texels; must be an integer of at least `64`.\n * Defaults to `2048`. Glyphs that cannot pack reject instead of dropping. Text, monochrome\n * shapes and colour glyphs take rows of their own, one kind below the other.\n */\n maxAtlasSize?: number\n /** Aborts the rasterization between font waits and glyph draws. */\n signal?: AbortSignal\n /**\n * An atlas built earlier for the same fonts, with this `bakeSize` and `padding`\n * (`pxRange`): a colour candidate whose slot there already carries `GlyphSlot.color` keeps\n * that classification, instead of being drawn twice on a scratch canvas and read back.\n * Bitmap SVG shapes and glyphs it lacks are classified as usual, and every glyph is still\n * measured, packed and drawn: only the classification is reused. Omit it after a webfont\n * swap. `DomSdf` passes its retained atlas when a capture's new glyphs rebuild it in full.\n */\n previousAtlas?: Pick<RasterAtlas, 'glyphs' | 'bakeSize' | 'pxRange'> | undefined\n /**\n * @internal Set by `DomSdf` for its own SDF atlases. The raster then records its\n * `AppendCursor` in `appendCursors`, so that `appendAtlas.ts` can draw later text glyphs\n * into the live texture. `'headroom'` also leaves free text rows for them, within\n * `maxAtlasSize`: a tallest text slot, or a quarter of the text rows when more, between\n * the text and the shapes and colour band, which therefore keep their rows across appends,\n * in an atlas at least two of its widest text glyphs wide. DomSdf asks for it once an\n * instance has gained glyphs; a capture that never gains any stays tight.\n */\n appendable?: boolean | 'headroom' | undefined\n /**\n * @internal Set by `DomSdf` when only a WebGPU atlas uploads the raster. Without colour\n * candidates, which are read back, the bake canvas is then GPU-backed (no\n * `willReadFrequently`): its first draw on a page skips the software canvas's set-up, 7 to\n * 12 ms on an M3 Max, and the atlas copies it on the GPU. Reading such a canvas back takes\n * hundreds of milliseconds, which only the CPU fallback of a failed GPU build pays.\n */\n gpuUpload?: boolean | undefined\n}\n\nfunction throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) {\n throw signal.reason ?? new DOMException('The atlas build was aborted', 'AbortError')\n }\n}\n\nfunction nextPowerOfTwo(value: number): number {\n return 2 ** Math.ceil(Math.log2(Math.max(1, value)))\n}\n\nfunction align4(value: number): number {\n return Math.max(4, Math.ceil(value / 4) * 4)\n}\n\n/** @internal Measures one text glyph's slot; `appendAtlas.ts` shares it with the cold build. */\nexport function measureGlyph(\n context: CanvasRenderingContext2D,\n request: GlyphRequest,\n padding: number,\n shaping: ShapingContext | undefined,\n candidate = false,\n lastFont: GlyphRequest['font'] | null = null,\n): MeasuredGlyph {\n setFontContext(context, request, shaping, lastFont)\n const metrics = context.measureText(request.character)\n const slice = request.shaping?.slice\n const from = slice?.[0] ?? 0\n const to = slice?.[1] ?? 1\n const advance = metrics.width * (to - from)\n const left = from === 0 ? Math.max(0, metrics.actualBoundingBoxLeft) : 0\n const right = slice\n ? advance + (to === 1 ? Math.max(0, metrics.actualBoundingBoxRight - metrics.width) : 0)\n : Math.max(metrics.width, metrics.actualBoundingBoxRight)\n const ascent = Math.max(1, metrics.fontBoundingBoxAscent || metrics.actualBoundingBoxAscent)\n const descent = Math.max(1, metrics.fontBoundingBoxDescent || metrics.actualBoundingBoxDescent)\n // A canvas draws text on a whole pixel row and, across, on a quarter pixel at best, whatever\n // origin it is given. The slot's origin is therefore a whole pixel: ink left of the origin\n // or taller than the font box was otherwise baked up to half a texel off, and the tiles of\n // a sliced run a quarter texel off each other.\n const drawOffsetX = metrics.width * from\n const planeX0 = -Math.ceil(left + padding - drawOffsetX) - drawOffsetX\n const planeX1 = right + padding\n const inkBounds =\n request.shaping !== undefined || candidate || isEmojiCandidate(request.character)\n const planeY0 = -Math.max(descent, inkBounds ? metrics.actualBoundingBoxDescent : 0) - padding\n const planeY1 = Math.ceil(\n Math.max(ascent, inkBounds ? metrics.actualBoundingBoxAscent : 0) + padding,\n )\n // Only whole, plain text glyphs trim their quads: a tile of a shaped line is clipped to its\n // slice, and colour candidates are bitmaps whose ink the metrics need not bound.\n const ink: MeasuredGlyph['ink'] =\n inkBounds || slice\n ? undefined\n : [\n -metrics.actualBoundingBoxLeft,\n -metrics.actualBoundingBoxDescent,\n metrics.actualBoundingBoxRight,\n metrics.actualBoundingBoxAscent,\n ]\n\n return {\n request,\n width: Math.max(2, Math.ceil(planeX1 - planeX0) + 2),\n height: Math.max(2, Math.ceil(planeY1 - planeY0) + 2),\n planeX0,\n planeY0,\n planeX1,\n planeY1,\n descent,\n advance,\n drawOffsetX,\n ...(ink?.every(Number.isFinite) ? { ink } : {}),\n x: 0,\n y: 0,\n flags: 0,\n }\n}\n\n/**\n * @internal The slot of a glyph drawn at (glyph.x, glyph.y) of a `width`×`height` atlas. The\n * full build and an append patch both take their slots from here, so they cannot drift apart.\n * A `banded` glyph is a colour candidate in the band; an `uncoloured` one a candidate that\n * classified as text.\n */\nexport function slotOf(\n glyph: MeasuredGlyph,\n padding: number,\n bakeSize: number,\n width: number,\n height: number,\n banded: boolean,\n uncoloured: boolean,\n): GlyphSlot {\n // The sampled window must follow the drawn plane box, not the shelf slot:\n // the slot is `ceil(extent) + 2` texels wide and the glyph origin above is\n // offset by one, so the plane spans texels 1 .. 1 + extent. Both bounds move\n // inward by half a texel so bilinear filtering cannot reach a neighbour.\n const slice = glyph.request.shaping?.slice\n const planeX0 = glyph.planeX0 + (slice && slice[0] > 0 ? -glyph.planeX0 : 0.5)\n const planeY0 = glyph.planeY0 + 0.5\n const planeX1 = glyph.planeX1 - (slice && slice[1] < 1 ? glyph.planeX1 - glyph.advance : 0.5)\n const planeY1 = glyph.planeY1 - 0.5\n const baseU = glyph.x + 1 - glyph.planeX0\n const baseV = glyph.y + 1 + glyph.planeY1\n const invW = 1 / width\n const invH = 1 / height\n const ink = banded ? undefined : glyph.ink\n let support: GlyphSlot['support']\n if (ink) {\n const reach = padding / 2 + 2 + 0.006 * bakeSize\n const sx0 = Math.max(planeX0, Math.floor(ink[0] - reach))\n const sy0 = Math.max(planeY0, Math.floor(ink[1] - reach))\n const sx1 = Math.min(planeX1, Math.ceil(ink[2] + reach))\n const sy1 = Math.min(planeY1, Math.ceil(ink[3] + reach))\n if (sx1 > sx0 && sy1 > sy0) {\n support = {\n u0: (baseU + sx0) * invW,\n v0: (baseV - sy1) * invH,\n u1: (baseU + sx1) * invW,\n v1: (baseV - sy0) * invH,\n }\n }\n }\n return {\n ...(uncoloured ? { color: false } : {}),\n key: glyph.request.key,\n character: glyph.request.character,\n fontKey: glyph.request.font.key,\n u0: (baseU + planeX0) * invW,\n v0: (baseV - planeY1) * invH,\n u1: (baseU + planeX1) * invW,\n v1: (baseV - planeY0) * invH,\n planeX0,\n planeY0,\n planeX1,\n planeY1,\n descent: glyph.descent,\n advance: glyph.advance,\n ...(support ? { support } : {}),\n }\n}\n\n/**\n * @internal Draws glyphs into their slots of one canvas, by the rules of the full build and of\n * an append patch alike. `reset()` forgets the context state cached here: call it whenever\n * the canvas is resized, which resets that state.\n */\nexport function glyphPainter(\n context: CanvasRenderingContext2D,\n shaping: ShapingContext | undefined,\n signal: AbortSignal | undefined,\n drawShape?: (glyph: MeasuredGlyph) => void,\n): { draw(glyph: MeasuredGlyph, text: boolean, fill?: string): void; reset(): void } {\n // A text mask must be the outline itself on every platform. The bake canvas has font\n // smoothing off; where the engine has the property, text also asks for exact geometry,\n // and it takes a mid grey fill, the neutral middle of a rasterizer's contrast table.\n // Colour glyphs keep the default rendering and the fills their classification compares;\n // shapes are paths, which none of this affects.\n const exactText = 'textRendering' in context\n let lastFont: GlyphRequest['font'] | null = null\n let lastFill = ''\n let lastTextRendering = ''\n return {\n reset() {\n lastFont = null\n lastFill = ''\n lastTextRendering = ''\n },\n draw(glyph, text, fill = '#fff') {\n throwIfAborted(signal)\n const targetFill = text ? '#606060' : fill\n if (lastFill !== targetFill) {\n context.fillStyle = targetFill\n lastFill = targetFill\n }\n if (glyph.request.shape) {\n drawShape!(glyph)\n lastFill = ''\n return\n }\n lastFont = setFontContext(context, glyph.request, shaping, lastFont)\n if (exactText) {\n const targetRendering = text ? 'geometricPrecision' : 'auto'\n if (lastTextRendering !== targetRendering) {\n context.textRendering = targetRendering\n lastTextRendering = targetRendering\n }\n }\n const originX = glyph.x - glyph.planeX0 + 1\n const baselineY = glyph.y + glyph.planeY1 + 1\n if (glyph.request.shaping?.slice) {\n context.save()\n context.beginPath()\n context.rect(\n glyph.x + 1,\n glyph.y + 1,\n glyph.planeX1 - glyph.planeX0,\n glyph.planeY1 - glyph.planeY0,\n )\n context.clip()\n context.fillText(glyph.request.character, originX - glyph.drawOffsetX, baselineY)\n context.restore()\n } else context.fillText(glyph.request.character, originX, baselineY)\n },\n }\n}\n\n/** The first row of a non-empty run of packed glyphs. */\nfunction topOf(rows: readonly MeasuredGlyph[]): number {\n return rows.reduce((top, glyph) => (glyph.y < top ? glyph.y : top), rows[0]!.y)\n}\n\nlet lastOverflowWidth = Infinity\n\n/** @internal Row-major shelf packing; also lays out the colour candidates of an append. */\nexport function packShelves(\n glyphs: MeasuredGlyph[],\n width: number,\n maxSize: number,\n): { width: number; height: number } | null {\n let x = 0\n let y = 0\n let rowHeight = 0\n let usedWidth = 0\n\n for (const glyph of glyphs) {\n const gw = glyph.width\n const gh = glyph.height\n if (gw > width) {\n if (gw < lastOverflowWidth) lastOverflowWidth = gw\n return null\n }\n if (gh > maxSize) return null\n if (x + gw > width) {\n if (x + gw < lastOverflowWidth) lastOverflowWidth = x + gw\n x = 0\n y += rowHeight\n rowHeight = 0\n }\n if (y + gh > maxSize) return null\n glyph.x = x\n glyph.y = y\n x += gw\n if (gh > rowHeight) rowHeight = gh\n if (x > usedWidth) usedWidth = x\n }\n\n return {\n width: align4(usedWidth),\n height: align4(y + rowHeight),\n }\n}\n\nlet skylineX = new Int32Array(256)\nlet skylineY = new Int32Array(256)\nlet skylineW = new Int32Array(256)\n\nfunction shiftSkyline(to: number, from: number, len: number): void {\n skylineX.copyWithin(to, from, len)\n skylineY.copyWithin(to, from, len)\n skylineW.copyWithin(to, from, len)\n}\n\nfunction recordSkylineOverflow(width: number, maxSize: number, wasteBudget: number): null {\n lastOverflowWidth = Math.min(lastOverflowWidth, width + Math.ceil(-wasteBudget / maxSize))\n return null\n}\n\n/** Bottom-left skyline packing fills the vertical gaps that fixed-height shelves leave behind. */\nfunction packSkyline(\n glyphs: MeasuredGlyph[],\n width: number,\n maxSize: number,\n): { width: number; height: number } | null {\n const needed = glyphs.length + 2\n if (skylineX.length < needed) {\n skylineX = new Int32Array(needed)\n skylineY = new Int32Array(needed)\n skylineW = new Int32Array(needed)\n }\n const sx = skylineX\n const sy = skylineY\n const sw = skylineW\n sx[0] = 0\n sy[0] = 0\n sw[0] = width\n let skylineLen = 1\n let usedWidth = 0\n let usedHeight = 0\n\n const minH = glyphs[glyphs.length - 1]!.height\n let wasteBudget = width * maxSize\n for (const g of glyphs) wasteBudget -= g.width * g.height\n if (wasteBudget < 0) return recordSkylineOverflow(width, maxSize, wasteBudget)\n\n for (const glyph of glyphs) {\n const gw = glyph.width\n const gh = glyph.height\n if (gh > maxSize) return null\n let bestIndex = -1\n let bestBottom = Infinity\n let bestWaste = Infinity\n const tail = skylineLen - 1\n let maxAllowedY = sw[tail]! >= gw && sy[tail]! < maxSize - gh ? sy[tail]! : maxSize - gh\n\n for (let index = 0; index < skylineLen; index++) {\n const firstY = sy[index]!\n if (firstY > maxAllowedY) continue\n const x = sx[index]!\n if (x + gw > width) {\n if (x + gw < lastOverflowWidth) lastOverflowWidth = x + gw\n break\n }\n\n let remaining = gw - sw[index]!\n let y = firstY\n let waste = 0\n if (remaining > 0) {\n let coveredArea = sw[index]! * firstY\n for (let cursor = index + 1; ; cursor++) {\n const nodeY = sy[cursor]!\n if (nodeY > maxAllowedY) {\n index = cursor\n remaining = 1\n break\n }\n if (nodeY > y) y = nodeY\n const nodeW = sw[cursor]!\n coveredArea += (remaining < nodeW ? remaining : nodeW) * nodeY\n if ((remaining -= nodeW) <= 0) break\n }\n if (remaining > 0) continue\n waste = y * gw - coveredArea\n }\n const bottom = y + gh\n if (bottom < bestBottom || waste < bestWaste) {\n bestIndex = index\n bestBottom = bottom\n bestWaste = waste\n maxAllowedY = waste === 0 ? y - 1 : y\n if (maxAllowedY < 0) break\n }\n }\n if (maxAllowedY >= 0 && usedWidth + gw < lastOverflowWidth) lastOverflowWidth = usedWidth + gw\n\n if (\n bestIndex < 0 ||\n (wasteBudget -= bestWaste + (bestBottom > maxSize - minH ? gw * (maxSize - bestBottom) : 0)) <\n 0\n )\n return bestIndex < 0 ? null : recordSkylineOverflow(width, maxSize, wasteBudget)\n const gx = sx[bestIndex]!\n const right = gx + gw\n glyph.x = gx\n glyph.y = bestBottom - gh\n let cursor = bestIndex\n while (cursor < skylineLen && sx[cursor]! + sw[cursor]! <= right) cursor++\n if (cursor < skylineLen && sx[cursor]! < right) {\n sw[cursor] = sx[cursor]! + sw[cursor]! - right\n sx[cursor] = right\n }\n let newCount = 1\n if (bestIndex > 0 && sy[bestIndex - 1] === bestBottom) {\n sw[bestIndex - 1] = sw[bestIndex - 1]! + gw\n newCount = 0\n if (cursor < skylineLen && sy[cursor] === bestBottom) {\n sw[bestIndex - 1] = sw[bestIndex - 1]! + sw[cursor]!\n cursor++\n }\n } else if (cursor < skylineLen && sy[cursor] === bestBottom) {\n sx[cursor] = gx\n sw[cursor] = sw[cursor]! + gw\n newCount = 0\n }\n const delta = newCount - (cursor - bestIndex)\n if (delta !== 0 && cursor < skylineLen) shiftSkyline(cursor + delta, cursor, skylineLen)\n skylineLen += delta\n if (newCount) {\n sx[bestIndex] = gx\n sy[bestIndex] = bestBottom\n sw[bestIndex] = gw\n }\n\n if (right > usedWidth) usedWidth = right\n if (bestBottom > usedHeight) usedHeight = bestBottom\n }\n\n return { width: align4(usedWidth), height: align4(usedHeight) }\n}\n\n/** Packs each group into rows of its own, one group below the other. */\nfunction packStacked(\n groups: readonly MeasuredGlyph[][],\n width: number,\n limit: number,\n pack: typeof packShelves,\n): { width: number; height: number } | null {\n let packedWidth = 0\n let height = 0\n for (const group of groups) {\n const packed = pack(group, width, limit - height)\n if (!packed || height + packed.height > limit) return null\n for (const glyph of group) glyph.y += height\n packedWidth = Math.max(packedWidth, packed.width)\n height += packed.height\n }\n return { width: packedWidth, height }\n}\n\nfunction rememberPacking(\n glyphs: readonly MeasuredGlyph[],\n size: { width: number; height: number },\n positions: Int32Array,\n): PackedGlyphs {\n for (let index = 0; index < glyphs.length; index++) {\n const glyph = glyphs[index]!\n positions[index * 2] = glyph.x\n positions[index * 2 + 1] = glyph.y\n }\n return { width: size.width, height: size.height }\n}\n\nfunction isBetterPacking(\n candidate: Pick<PackedGlyphs, 'width' | 'height'>,\n current: PackedGlyphs,\n): boolean {\n return (\n (candidate.width * candidate.height - current.width * current.height ||\n Math.max(candidate.width, candidate.height) - Math.max(current.width, current.height) ||\n candidate.width - current.width) < 0\n )\n}\n\n/**\n * Rasterizes every required font-face/character or emoji-sequence pair into one tightly packed\n * alpha atlas. The output is a transient mask; the retained texture is a\n * single-channel distance field produced by the CPU or WebGPU compute backend.\n */\nexport async function rasterizeGlyphAtlas(\n document: Document,\n requests: readonly GlyphRequest[],\n options: RasterizeOptions = {},\n): Promise<RasterAtlas> {\n const bakeSize = options.bakeSize ?? 96\n const padding = options.padding ?? 12\n const maxAtlasSize = options.maxAtlasSize ?? 2048\n if (!Number.isFinite(bakeSize) || bakeSize < 16) {\n throw new RangeError('rasterizeGlyphAtlas: bakeSize must be at least 16')\n }\n if (!Number.isFinite(padding) || padding < 2) {\n throw new RangeError('rasterizeGlyphAtlas: padding must be at least 2')\n }\n if (!Number.isInteger(maxAtlasSize) || maxAtlasSize < 64) {\n throw new RangeError('rasterizeGlyphAtlas: maxAtlasSize must be an integer of at least 64')\n }\n\n throwIfAborted(options.signal)\n const [, shapingModule, shapes] = await Promise.all([\n waitForFonts(document, requests, options.signal),\n requests.some((request) => request.shaping) ? import('../dom/browserShaping.js') : undefined,\n requests.some((request) => request.shape) ? import('./shapeRaster.js') : undefined,\n ])\n const shaping = shapingModule?.setShapingContext\n throwIfAborted(options.signal)\n\n const canvas = createCanvas(document)\n let returned = false\n try {\n // A glyph a matching previous atlas has classified keeps its classification. A bitmap\n // shape always keeps its place in the band, as on a cold build: never history-dependent.\n const previous =\n options.previousAtlas?.bakeSize === bakeSize && options.previousAtlas.pxRange === padding\n ? options.previousAtlas.glyphs\n : undefined\n const willReadFrequently =\n !options.gpuUpload ||\n requests.some(\n (request) =>\n isColorCandidate(request, options.colorGlyphs) &&\n (request.shape !== undefined ||\n ((options.colorGlyphs === 'all' || isEmojiGrapheme(request.character)) &&\n previous?.get(request.key)?.color !== false)),\n )\n const context = canvas.getContext('2d', { willReadFrequently })\n if (!context) throw new Error('rasterizeGlyphAtlas: Canvas 2D is unavailable')\n\n const packingLimit = maxAtlasSize - (maxAtlasSize % 4)\n let lastFont: GlyphRequest['font'] | null = null\n const measured = requests.map((request) => {\n if (request.shape) return shapes!.measureShape(request, bakeSize, padding)\n const glyph = measureGlyph(\n context,\n request,\n padding,\n shaping,\n isColorCandidate(request, options.colorGlyphs),\n lastFont,\n )\n lastFont = request.font\n return glyph\n })\n measured.sort(\n (a, b) =>\n b.height - a.height ||\n b.width - a.width ||\n (a.request.key < b.request.key ? -1 : a.request.key > b.request.key ? 1 : 0),\n )\n\n let bandedCount = 0\n const tested: MeasuredGlyph[] = []\n for (const glyph of measured) {\n if (!isColorCandidate(glyph.request, options.colorGlyphs)) continue\n const known = glyph.request.shape ? undefined : previous?.get(glyph.request.key)?.color\n if (known === false) glyph.flags = 2\n else {\n glyph.flags = 1\n bandedCount++\n if (!glyph.request.shape && known === undefined) tested.push(glyph)\n }\n }\n const painter = glyphPainter(context, shaping, options.signal, (glyph) => {\n shapes!.drawShapeSlot(context, glyph, bakeSize)\n })\n const drawGlyph = (glyph: MeasuredGlyph, fill?: string): void => {\n painter.draw(glyph, !glyph.request.shape && (glyph.flags! & 1) === 0, fill)\n }\n\n // A candidate the font draws in the fill colour alone is text, whatever Unicode lists it\n // as: a copyright sign, an arrow, the tiles of a shaped line beside the one that holds\n // its emoji. Each font candidate is drawn in black and in white on a pack of their own,\n // and only one with ink that ignores the fill keeps its place in the band; the others are\n // baked, packed and flagged with the text.\n const colorGlyphs = bandedCount ? await import('./colorGlyphs.js') : undefined\n throwIfAborted(options.signal)\n const scratch = tested.length ? packShelves(tested, packingLimit, packingLimit) : null\n if (scratch) {\n const scratchCanvas = willReadFrequently ? null : createCanvas(document)\n try {\n const targetCanvas = scratchCanvas ?? canvas\n targetCanvas.width = scratch.width\n targetCanvas.height = scratch.height\n const targetContext = scratchCanvas\n ? scratchCanvas.getContext('2d', { willReadFrequently: true })\n : context\n if (!targetContext) throw new Error('rasterizeGlyphAtlas: Canvas 2D is unavailable')\n const targetPainter = scratchCanvas\n ? glyphPainter(targetContext, shaping, options.signal)\n : painter\n targetPainter.reset()\n const paint = (fill: string): Uint8ClampedArray => {\n targetContext.clearRect(0, 0, scratch.width, scratch.height)\n for (const glyph of tested) targetPainter.draw(glyph, false, fill)\n return targetContext.getImageData(0, 0, scratch.width, scratch.height).data\n }\n const dark = paint('#000')\n const { colored } = colorGlyphs!.encodeColorBand(\n paint('#fff'),\n dark,\n scratch.width,\n scratch.height,\n 0,\n tested,\n )\n tested.forEach((glyph, index) => {\n if (colored[index]) return\n glyph.flags = 2\n })\n } finally {\n if (scratchCanvas) {\n scratchCanvas.width = 0\n scratchCanvas.height = 0\n scratchCanvas.remove()\n }\n }\n }\n\n // Three kinds of rows, top to bottom: text, monochrome shapes, colour.\n const textRows: MeasuredGlyph[] = []\n const shapeRows: MeasuredGlyph[] = []\n const band: MeasuredGlyph[] = []\n let totalArea = 0\n let widestGlyph = 4\n let exceedsLimit = false\n for (const glyph of measured) {\n totalArea += glyph.width * glyph.height\n if (glyph.width > widestGlyph) widestGlyph = glyph.width\n if (glyph.width > packingLimit || glyph.height > packingLimit) exceedsLimit = true\n if (glyph.flags! & 1) band.push(glyph)\n else if (glyph.request.shape) shapeRows.push(glyph)\n else textRows.push(glyph)\n }\n const groups = [textRows, shapeRows, band].filter((group) => group.length)\n const packGlyphs = (pack: typeof packShelves, width: number, limit: number) =>\n groups.length > 1 ? packStacked(groups, width, limit, pack) : pack(measured, width, limit)\n const impossible = totalArea > packingLimit * packingLimit || exceedsLimit\n const bestPositions = new Int32Array(measured.length * 2)\n let shelfWidth = Math.min(packingLimit, Math.max(64, nextPowerOfTwo(Math.sqrt(totalArea))))\n let packed = impossible ? null : packGlyphs(packShelves, shelfWidth, packingLimit)\n while (!packed && shelfWidth < packingLimit) {\n shelfWidth = Math.min(packingLimit, shelfWidth * 2)\n packed = packGlyphs(packShelves, shelfWidth, packingLimit)\n }\n let best = packed && !impossible ? rememberPacking(measured, packed, bestPositions) : null\n\n if (!impossible && measured.length > 0) {\n const minRequiredLimit = groups.reduce((sum, g) => sum + align4(g[0]!.height), 0)\n const minimumWidth = Math.min(\n packingLimit,\n align4(Math.max(widestGlyph, Math.ceil(totalArea / packingLimit))),\n )\n // Skip skyline when every group has uniform heights so shelf packing is already tight.\n const packerCount = groups.some((g) => g[0]!.height !== g[g.length - 1]!.height) ? 2 : 1\n const maxHeightFor = (width: number): number =>\n best ? Math.min(packingLimit, Math.floor((best.width * best.height) / width)) : packingLimit\n const nextW = [minimumWidth, minimumWidth]\n for (let width = minimumWidth; width <= packingLimit; width += 4) {\n throwIfAborted(options.signal)\n if (maxHeightFor(width) < minRequiredLimit) break\n const minH = align4(Math.max(minRequiredLimit, Math.ceil(totalArea / width)))\n for (let i = 0; i < packerCount; i++) {\n if (width < nextW[i]!) continue\n const maxCandidateHeight = maxHeightFor(width)\n if (minH > maxCandidateHeight) break\n lastOverflowWidth = Infinity\n const candidate = packGlyphs(i ? packSkyline : packShelves, width, maxCandidateHeight)\n nextW[i] = lastOverflowWidth\n if (candidate && (!best || isBetterPacking(candidate, best))) {\n best = rememberPacking(measured, candidate, bestPositions)\n }\n }\n }\n }\n\n if (!best) {\n if (options.adaptiveBakeSize === true && bakeSize > 16) {\n const nextSize = Math.max(16, Math.floor(bakeSize * 0.8))\n const scaled = requests.map((request) => ({\n ...request,\n font: {\n ...request.font,\n canvasFont: request.font.canvasFont.replace(\n /[\\d.]+px/,\n (size) => `${(Number.parseFloat(size) * nextSize) / bakeSize}px`,\n ),\n },\n }))\n return await rasterizeGlyphAtlas(document, scaled, { ...options, bakeSize: nextSize })\n }\n throw new Error(\n `rasterizeGlyphAtlas: ${requests.length} glyphs exceed the ${maxAtlasSize}×${maxAtlasSize} atlas limit`,\n )\n }\n for (let index = 0; index < measured.length; index++) {\n measured[index]!.x = bestPositions[index * 2]!\n measured[index]!.y = bestPositions[index * 2 + 1]!\n }\n\n // The text rows, packed first, end where the shapes or else the colour band begin. Headroom\n // for later appends goes there, so the rows below move down once, now, never on an append.\n let textBottom = !textRows.length ? 0 : groups.length > 1 ? topOf(groups[1]!) : best.height\n if (options.appendable === 'headroom' && textRows.length) {\n // Rows of at least two of the widest text glyphs: a one-column atlas has no row that\n // takes a glyph wider than its own.\n let widestText = 0\n for (const glyph of textRows) if (glyph.width > widestText) widestText = glyph.width\n best.width = Math.min(packingLimit, Math.max(best.width, align4(2 * widestText)))\n const room = Math.min(\n packingLimit - best.height,\n align4(Math.max(textRows[0]!.height, textBottom / 4)),\n )\n if (room > 0) {\n for (const glyph of measured) if (glyph.y >= textBottom) glyph.y += room\n best.height += room\n textBottom += room\n }\n }\n\n canvas.width = best.width\n canvas.height = best.height\n painter.reset()\n if (scratch && willReadFrequently) context.clearRect(0, 0, canvas.width, canvas.height)\n const bandTop = band.length ? topOf(band) : 0\n const bandHeight = canvas.height - bandTop\n let black: Uint8ClampedArray | undefined\n if (band.length) {\n for (const glyph of band) drawGlyph(glyph, '#000')\n black = context.getImageData(0, bandTop, canvas.width, bandHeight).data\n context.clearRect(0, bandTop, canvas.width, bandHeight)\n }\n const glyphSlots = new Map<string, GlyphSlot>()\n const byFont = new Map<string, MeasuredGlyph[]>()\n const shapeGlyphs: MeasuredGlyph[] = []\n for (const glyph of measured) {\n if (glyph.request.shape) {\n shapeGlyphs.push(glyph)\n continue\n }\n let group = byFont.get(glyph.request.font.key)\n if (!group) byFont.set(glyph.request.font.key, (group = []))\n group.push(glyph)\n }\n const drawAndRecord = (glyph: MeasuredGlyph): void => {\n drawGlyph(glyph)\n glyphSlots.set(\n glyph.request.key,\n slotOf(\n glyph,\n padding,\n bakeSize,\n canvas.width,\n canvas.height,\n (glyph.flags! & 1) !== 0,\n (glyph.flags! & 2) !== 0,\n ),\n )\n }\n for (const group of byFont.values()) {\n for (const glyph of group) drawAndRecord(glyph)\n }\n for (const glyph of shapeGlyphs) drawAndRecord(glyph)\n\n let colorBand: RasterColorBand | undefined\n if (black) {\n const white = context.getImageData(0, bandTop, canvas.width, bandHeight).data\n const encoded = colorGlyphs!.encodeColorBand(\n white,\n black,\n canvas.width,\n bandHeight,\n padding,\n band.map((glyph) => ({ ...glyph, y: glyph.y - bandTop })),\n )\n for (const [index, glyph] of band.entries()) {\n const slot = glyphSlots.get(glyph.request.key)!\n glyphSlots.set(glyph.request.key, { ...slot, color: encoded.colored[index]! })\n }\n if (encoded.colored.some(Boolean))\n colorBand = { top: bandTop, height: bandHeight, data: encoded.data }\n }\n const shapeTop = shapeRows.length ? topOf(shapeRows) : undefined\n if (options.appendable) {\n // The last text row is the one the lowest-starting slot begins on; whatever reaches\n // that row or below bounds where the cursor starts and how far the row runs down.\n let x = 0\n let y = 0\n let rowHeight = 0\n for (const glyph of textRows)\n if (glyph.y > y && glyph.y + textRows[0]!.height <= textBottom) y = glyph.y\n for (const glyph of textRows) {\n const reach = glyph.y + glyph.height - y\n if (reach > 0) {\n if (glyph.x + glyph.width > x) x = glyph.x + glyph.width\n if (reach > rowHeight) rowHeight = reach\n }\n }\n appendCursors.set(glyphSlots, {\n width: canvas.width,\n height: canvas.height,\n bakeSize,\n pxRange: padding,\n colorGlyphs: options.colorGlyphs ?? 'emoji',\n bottom: textBottom,\n x,\n y,\n rowHeight,\n })\n }\n returned = true\n return {\n ...(colorBand ? { colorBand } : {}),\n ...(shapeTop !== undefined ? { shapeTop } : {}),\n canvas,\n width: canvas.width,\n height: canvas.height,\n bakeSize,\n pxRange: padding,\n glyphs: glyphSlots,\n }\n } finally {\n if (!returned) {\n canvas.width = 0\n canvas.height = 0\n }\n canvas.remove()\n }\n}\n"],"mappings":";;;;;;;AAsEA,IAAa,gCAAgB,IAAI,QAAsD;AA2DvF,SAAS,eAAe,QAA4B;CAClD,IAAI,QAAQ,SACV,MAAM,OAAO,UAAU,IAAI,aAAa,+BAA+B,YAAY;AAEvF;AAEA,SAAS,eAAe,OAAuB;CAC7C,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI,GAAG,KAAK,CAAC,CAAC;AACrD;AAEA,SAAS,OAAO,OAAuB;CACrC,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC;AAC7C;;AAGA,SAAgB,aACd,SACA,SACA,SACA,SACA,YAAY,OACZ,WAAwC,MACzB;CACf,eAAe,SAAS,SAAS,SAAS,QAAQ;CAClD,MAAM,UAAU,QAAQ,YAAY,QAAQ,SAAS;CACrD,MAAM,QAAQ,QAAQ,SAAS;CAC/B,MAAM,OAAO,QAAQ,MAAM;CAC3B,MAAM,KAAK,QAAQ,MAAM;CACzB,MAAM,UAAU,QAAQ,SAAS,KAAK;CACtC,MAAM,OAAO,SAAS,IAAI,KAAK,IAAI,GAAG,QAAQ,qBAAqB,IAAI;CACvE,MAAM,QAAQ,QACV,WAAW,OAAO,IAAI,KAAK,IAAI,GAAG,QAAQ,yBAAyB,QAAQ,KAAK,IAAI,KACpF,KAAK,IAAI,QAAQ,OAAO,QAAQ,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AAI,MAAM,QAAQ,KAAK;KAAE,GAAG;KAAM,OAAO,QAAQ,QAAQ;IAAQ,CAAC;GAC/E;GACA,IAAI,QAAQ,QAAQ,KAAK,OAAO,GAC9B,YAAY;IAAE,KAAK;IAAS,QAAQ;IAAY,MAAM,QAAQ;GAAK;EACvE;EACA,MAAM,WAAW,UAAU,SAAS,MAAM,SAAS,IAAI,KAAA;EACvD,IAAI,QAAQ,YAAY;GAGtB,IAAI,IAAI;GACR,IAAI,IAAI;GACR,IAAI,YAAY;GAChB,KAAK,MAAM,SAAS,UAClB,IAAI,MAAM,IAAI,KAAK,MAAM,IAAI,SAAS,EAAE,CAAE,UAAU,YAAY,IAAI,MAAM;GAC5E,KAAK,MAAM,SAAS,UAAU;IAC5B,MAAM,QAAQ,MAAM,IAAI,MAAM,SAAS;IACvC,IAAI,QAAQ,GAAG;KACb,IAAI,MAAM,IAAI,MAAM,QAAQ,GAAG,IAAI,MAAM,IAAI,MAAM;KACnD,IAAI,QAAQ,WAAW,YAAY;IACrC;GACF;GACA,cAAc,IAAI,YAAY;IAC5B,OAAO,OAAO;IACd,QAAQ,OAAO;IACf;IACA,SAAS;IACT,aAAa,QAAQ,eAAe;IACpC,QAAQ;IACR;IACA;IACA;GACF,CAAC;EACH;EACA,WAAW;EACX,OAAO;GACL,GAAI,YAAY,EAAE,UAAU,IAAI,CAAC;GACjC,GAAI,aAAa,KAAA,IAAY,EAAE,SAAS,IAAI,CAAC;GAC7C;GACA,OAAO,OAAO;GACd,QAAQ,OAAO;GACf;GACA,SAAS;GACT,QAAQ;EACV;CACF,UAAU;EACR,IAAI,CAAC,UAAU;GACb,OAAO,QAAQ;GACf,OAAO,SAAS;EAClB;EACA,OAAO,OAAO;CAChB;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapeRaster.js","names":[],"sources":["../../src/atlas/shapeRaster.ts"],"sourcesContent":["import type { GlyphRequest, GlyphShapePath } from '../types.js'\nimport type { MeasuredGlyph } from './rasterize.js'\n\n/** Shapes use the same texel-plane contract as font glyphs, with their baseline at box bottom. */\nexport function measureShape(\n request: GlyphRequest,\n bakeSize: number,\n padding: number,\n): MeasuredGlyph {\n const shape = request.shape!\n const scale = bakeSize / 1000\n const [x0, y0, x1, y1] = shape.bounds\n const planeX0 = x0 * scale - padding\n const planeX1 = x1 * scale + padding\n const planeY0 = (shape.box[1] - y1) * scale - padding\n const planeY1 = (shape.box[1] - y0) * scale + padding\n return {\n request,\n width: Math.max(2, Math.ceil(planeX1 - planeX0) + 2),\n height: Math.max(2, Math.ceil(planeY1 - planeY0) + 2),\n planeX0,\n planeX1,\n planeY0,\n planeY1,\n descent: 0,\n advance: 0,\n drawOffsetX: 0,\n x: 0,\n y: 0,\n }\n}\n\n/** Draw one retained mask; bitmap requests supply authored per-path colours. */\nexport function drawShapeSlot(\n context: CanvasRenderingContext2D,\n glyph: MeasuredGlyph,\n bakeSize: number,\n): void {\n const shape = glyph.request.shape!\n const scale = bakeSize / 1000\n const prepare = (target: CanvasRenderingContext2D, x: number, y: number) => {\n target.setTransform(\n scale,\n 0,\n 0,\n scale,\n x - glyph.planeX0 + 1,\n y + glyph.planeY1 + 1 - shape.box[1] * scale,\n )\n // The ink bounds may be cropped by a viewport; never spill into adjacent atlas slots.\n target.beginPath()\n target.rect(\n shape.bounds[0],\n shape.bounds[1],\n shape.bounds[2] - shape.bounds[0],\n shape.bounds[3] - shape.bounds[1],\n )\n target.clip()\n }\n const draw = (context: CanvasRenderingContext2D, item: GlyphShapePath) => {\n context.save()\n try {\n if (item.clip) {\n context.beginPath()\n context.rect(\n item.clip[0],\n item.clip[1],\n item.clip[2] - item.clip[0],\n item.clip[3] - item.clip[1],\n )\n context.clip()\n }\n if (shape.bitmap && item.color) {\n const [r, g, b, a] = item.color\n context.fillStyle = `rgba(${r * 255},${g * 255},${b * 255},${a})`\n }\n context.strokeStyle = context.fillStyle\n let path = new Path2D(item.d)\n const stroke = item.stroke\n if (stroke?.nonScaling) {\n const transformed = new Path2D()\n const [a, b, c, d, e, f] = item.transform\n transformed.addPath(path, { a, b, c, d, e, f })\n path = transformed\n } else context.transform(...item.transform)\n if (stroke) {\n context.lineWidth = stroke.width\n context.lineCap = stroke.lineCap\n context.lineJoin = stroke.lineJoin\n context.miterLimit = stroke.miterLimit\n context.setLineDash(stroke.dash ? [...stroke.dash] : [])\n context.lineDashOffset = stroke.dashOffset ?? 0\n context.stroke(path)\n } else context.fill(path, item.fillRule ?? 'nonzero')\n } finally {\n context.restore()\n }\n }\n context.save()\n try {\n prepare(context, glyph.x, glyph.y)\n if (shape.image) context.drawImage(shape.image, 0, 0, ...shape.box)\n else if (shape.bitmap && shape.paths.some((path) => path.opacityGroups?.length)) {\n // Canvas applies opacity to each paint. Isolate SVG element/group opacity so\n // overlapping children and fill/stroke are composited before the alpha scales.\n const stack: { id: number; alpha: number; context: CanvasRenderingContext2D }[] = []\n const close = () => {\n const group = stack.pop()!\n const parent = stack.at(-1)?.context ?? context\n parent.save()\n try {\n parent.setTransform(1, 0, 0, 1, 0, 0)\n parent.globalAlpha = group.alpha\n parent.drawImage(\n group.context.canvas,\n stack.length ? 0 : glyph.x,\n stack.length ? 0 : glyph.y,\n )\n } finally {\n parent.restore()\n group.context.canvas.width = group.context.canvas.height = 0\n }\n }\n try {\n for (const item of shape.paths) {\n const groups = item.opacityGroups ?? []\n let shared = 0\n while (shared < stack.length && stack[shared]!.id === groups[shared]?.[0]) shared++\n while (stack.length > shared) close()\n for (let i = shared; i < groups.length; i++) {\n const canvas = context.canvas.ownerDocument.createElement('canvas')\n canvas.width = glyph.width\n canvas.height = glyph.height\n const target = canvas.getContext('2d')\n if (!target) throw new Error('SVG opacity compositing requires Canvas 2D')\n prepare(target, 0, 0)\n stack.push({ id: groups[i]![0], alpha: groups[i]![1], context: target })\n }\n draw(stack.at(-1)?.context ?? context, item)\n }\n while (stack.length) close()\n } finally {\n for (const group of stack) group.context.canvas.width = group.context.canvas.height = 0\n }\n } else for (const item of shape.paths) draw(context, item)\n } finally {\n context.restore()\n }\n}\n"],"mappings":";;AAIA,SAAgB,aACd,SACA,UACA,SACe;CACf,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,WAAW;CACzB,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,MAAM;CAC/B,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,WAAW,MAAM,IAAI,KAAK,MAAM,QAAQ;CAC9C,MAAM,WAAW,MAAM,IAAI,KAAK,MAAM,QAAQ;CAC9C,OAAO;EACL;EACA,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,UAAU,OAAO,IAAI,CAAC;EACnD,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAK,UAAU,OAAO,IAAI,CAAC;EACpD;EACA;EACA;EACA;EACA,SAAS;EACT,SAAS;EACT,aAAa;EACb,GAAG;EACH,GAAG;
|
|
1
|
+
{"version":3,"file":"shapeRaster.js","names":[],"sources":["../../src/atlas/shapeRaster.ts"],"sourcesContent":["import type { GlyphRequest, GlyphShapePath } from '../types.js'\nimport type { MeasuredGlyph } from './rasterize.js'\n\n/** Shapes use the same texel-plane contract as font glyphs, with their baseline at box bottom. */\nexport function measureShape(\n request: GlyphRequest,\n bakeSize: number,\n padding: number,\n): MeasuredGlyph {\n const shape = request.shape!\n const scale = bakeSize / 1000\n const [x0, y0, x1, y1] = shape.bounds\n const planeX0 = x0 * scale - padding\n const planeX1 = x1 * scale + padding\n const planeY0 = (shape.box[1] - y1) * scale - padding\n const planeY1 = (shape.box[1] - y0) * scale + padding\n return {\n request,\n width: Math.max(2, Math.ceil(planeX1 - planeX0) + 2),\n height: Math.max(2, Math.ceil(planeY1 - planeY0) + 2),\n planeX0,\n planeX1,\n planeY0,\n planeY1,\n descent: 0,\n advance: 0,\n drawOffsetX: 0,\n x: 0,\n y: 0,\n flags: 0,\n }\n}\n\n/** Draw one retained mask; bitmap requests supply authored per-path colours. */\nexport function drawShapeSlot(\n context: CanvasRenderingContext2D,\n glyph: MeasuredGlyph,\n bakeSize: number,\n): void {\n const shape = glyph.request.shape!\n const scale = bakeSize / 1000\n const prepare = (target: CanvasRenderingContext2D, x: number, y: number) => {\n target.setTransform(\n scale,\n 0,\n 0,\n scale,\n x - glyph.planeX0 + 1,\n y + glyph.planeY1 + 1 - shape.box[1] * scale,\n )\n // The ink bounds may be cropped by a viewport; never spill into adjacent atlas slots.\n target.beginPath()\n target.rect(\n shape.bounds[0],\n shape.bounds[1],\n shape.bounds[2] - shape.bounds[0],\n shape.bounds[3] - shape.bounds[1],\n )\n target.clip()\n }\n const draw = (context: CanvasRenderingContext2D, item: GlyphShapePath) => {\n context.save()\n try {\n if (item.clip) {\n context.beginPath()\n context.rect(\n item.clip[0],\n item.clip[1],\n item.clip[2] - item.clip[0],\n item.clip[3] - item.clip[1],\n )\n context.clip()\n }\n if (shape.bitmap && item.color) {\n const [r, g, b, a] = item.color\n context.fillStyle = `rgba(${r * 255},${g * 255},${b * 255},${a})`\n }\n context.strokeStyle = context.fillStyle\n let path = new Path2D(item.d)\n const stroke = item.stroke\n if (stroke?.nonScaling) {\n const transformed = new Path2D()\n const [a, b, c, d, e, f] = item.transform\n transformed.addPath(path, { a, b, c, d, e, f })\n path = transformed\n } else context.transform(...item.transform)\n if (stroke) {\n context.lineWidth = stroke.width\n context.lineCap = stroke.lineCap\n context.lineJoin = stroke.lineJoin\n context.miterLimit = stroke.miterLimit\n context.setLineDash(stroke.dash ? [...stroke.dash] : [])\n context.lineDashOffset = stroke.dashOffset ?? 0\n context.stroke(path)\n } else context.fill(path, item.fillRule ?? 'nonzero')\n } finally {\n context.restore()\n }\n }\n context.save()\n try {\n prepare(context, glyph.x, glyph.y)\n if (shape.image) context.drawImage(shape.image, 0, 0, ...shape.box)\n else if (shape.bitmap && shape.paths.some((path) => path.opacityGroups?.length)) {\n // Canvas applies opacity to each paint. Isolate SVG element/group opacity so\n // overlapping children and fill/stroke are composited before the alpha scales.\n const stack: { id: number; alpha: number; context: CanvasRenderingContext2D }[] = []\n const close = () => {\n const group = stack.pop()!\n const parent = stack.at(-1)?.context ?? context\n parent.save()\n try {\n parent.setTransform(1, 0, 0, 1, 0, 0)\n parent.globalAlpha = group.alpha\n parent.drawImage(\n group.context.canvas,\n stack.length ? 0 : glyph.x,\n stack.length ? 0 : glyph.y,\n )\n } finally {\n parent.restore()\n group.context.canvas.width = group.context.canvas.height = 0\n }\n }\n try {\n for (const item of shape.paths) {\n const groups = item.opacityGroups ?? []\n let shared = 0\n while (shared < stack.length && stack[shared]!.id === groups[shared]?.[0]) shared++\n while (stack.length > shared) close()\n for (let i = shared; i < groups.length; i++) {\n const canvas = context.canvas.ownerDocument.createElement('canvas')\n canvas.width = glyph.width\n canvas.height = glyph.height\n const target = canvas.getContext('2d')\n if (!target) throw new Error('SVG opacity compositing requires Canvas 2D')\n prepare(target, 0, 0)\n stack.push({ id: groups[i]![0], alpha: groups[i]![1], context: target })\n }\n draw(stack.at(-1)?.context ?? context, item)\n }\n while (stack.length) close()\n } finally {\n for (const group of stack) group.context.canvas.width = group.context.canvas.height = 0\n }\n } else for (const item of shape.paths) draw(context, item)\n } finally {\n context.restore()\n }\n}\n"],"mappings":";;AAIA,SAAgB,aACd,SACA,UACA,SACe;CACf,MAAM,QAAQ,QAAQ;CACtB,MAAM,QAAQ,WAAW;CACzB,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,MAAM;CAC/B,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,UAAU,KAAK,QAAQ;CAC7B,MAAM,WAAW,MAAM,IAAI,KAAK,MAAM,QAAQ;CAC9C,MAAM,WAAW,MAAM,IAAI,KAAK,MAAM,QAAQ;CAC9C,OAAO;EACL;EACA,OAAO,KAAK,IAAI,GAAG,KAAK,KAAK,UAAU,OAAO,IAAI,CAAC;EACnD,QAAQ,KAAK,IAAI,GAAG,KAAK,KAAK,UAAU,OAAO,IAAI,CAAC;EACpD;EACA;EACA;EACA;EACA,SA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ACpC,KAAK,IAAI,IAAI,QAAQ,IAAI,OAAO,QAAQ,KAAK;MAC3C,MAAM,SAAS,QAAQ,OAAO,cAAc,cAAc,QAAQ;MAClE,OAAO,QAAQ,MAAM;MACrB,OAAO,SAAS,MAAM;MACtB,MAAM,SAAS,OAAO,WAAW,IAAI;MACrC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,4CAA4C;MACzE,QAAQ,QAAQ,GAAG,CAAC;MACpB,MAAM,KAAK;OAAE,IAAI,OAAO,EAAE,CAAE;OAAI,OAAO,OAAO,EAAE,CAAE;OAAI,SAAS;MAAO,CAAC;KACzE;KACA,KAAK,MAAM,GAAG,EAAE,CAAC,EAAE,WAAW,SAAS,IAAI;IAC7C;IACA,OAAO,MAAM,QAAQ,MAAM;GAC7B,UAAU;IACR,KAAK,MAAM,SAAS,OAAO,MAAM,QAAQ,OAAO,QAAQ,MAAM,QAAQ,OAAO,SAAS;GACxF;EACF,OAAO,KAAK,MAAM,QAAQ,MAAM,OAAO,KAAK,SAAS,IAAI;CAC3D,UAAU;EACR,QAAQ,QAAQ;CAClB;AACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Engine-agnostic 3D axis-aligned bounding box and bounding sphere. */
|
|
2
|
+
export interface VanillaBounds {
|
|
3
|
+
readonly min: readonly [x: number, y: number, z: number];
|
|
4
|
+
readonly max: readonly [x: number, y: number, z: number];
|
|
5
|
+
readonly center: readonly [x: number, y: number, z: number];
|
|
6
|
+
readonly radius: number;
|
|
7
|
+
}
|
|
8
|
+
/** Packed typed-array instance attributes for SDF glyphs. */
|
|
9
|
+
export interface VanillaGlyphInstances {
|
|
10
|
+
count: number;
|
|
11
|
+
maxSequence: number;
|
|
12
|
+
/** `[x0, y0, x1, y1]` per glyph in local capture units (`count * 4`). */
|
|
13
|
+
rects: Float32Array;
|
|
14
|
+
/** Normalized `unorm16` `[u0, v1, u1, v0]` per glyph (`count * 4`). */
|
|
15
|
+
uvRects: Uint16Array;
|
|
16
|
+
/** Normalized `unorm16` support trim `[u0, v1, u1, v0]` per glyph (`count * 4`), or `null` with `runMotion`. */
|
|
17
|
+
trims: Uint16Array | null;
|
|
18
|
+
/** `[x0, y0, x1, y1]` clip box per glyph (`count * 4`). */
|
|
19
|
+
clips: Float32Array;
|
|
20
|
+
/** Normalized `unorm8` `[r, g, b, a]` per glyph (`count * 4`). */
|
|
21
|
+
colors: Uint8Array;
|
|
22
|
+
/** `[sequence, z]` or `[sequence, z, switchEm]` per glyph (`count * metaItemSize`). */
|
|
23
|
+
metadata: Float32Array;
|
|
24
|
+
metaItemSize: 2 | 3;
|
|
25
|
+
/** `[centerX, centerY, ordinal]` per glyph (`count * 3`) when shaped runs or SVG groups are present. */
|
|
26
|
+
runMotion: Float32Array | null;
|
|
27
|
+
bounds: VanillaBounds;
|
|
28
|
+
}
|
|
29
|
+
/** Packed typed-array instance attributes for DOM background rectangles. */
|
|
30
|
+
export interface VanillaRectInstances {
|
|
31
|
+
count: number;
|
|
32
|
+
readonly receiveShadow: boolean;
|
|
33
|
+
/** `[x0, y0, x1, y1]` per rectangle (`count * 4`). */
|
|
34
|
+
rects: Float32Array;
|
|
35
|
+
/** Normalized `unorm8` `[r, g, b, a]` per rectangle (`count * 4`). */
|
|
36
|
+
colors: Uint8Array;
|
|
37
|
+
/** Corner radius per rectangle (`count`). */
|
|
38
|
+
radii: Float32Array;
|
|
39
|
+
/** Z depth per rectangle (`count`). */
|
|
40
|
+
depths: Float32Array;
|
|
41
|
+
bounds: VanillaBounds;
|
|
42
|
+
}
|
|
43
|
+
/** Packed typed-array instance attributes for CSS text decorations. */
|
|
44
|
+
export interface VanillaDecorationInstances {
|
|
45
|
+
count: number;
|
|
46
|
+
/** Source glyph `[x0, y0, x1, y1]` per decoration (`count * 4`). */
|
|
47
|
+
rects: Float32Array;
|
|
48
|
+
/** Decoration stroke `[x0, y0, x1, y1]` per decoration (`count * 4`). */
|
|
49
|
+
decorationRects: Float32Array;
|
|
50
|
+
/** Motion index per decoration (`count`). */
|
|
51
|
+
decorationIndices: Float32Array;
|
|
52
|
+
/** Normalized `unorm8` `[r, g, b, a]` per decoration (`count * 4`). */
|
|
53
|
+
colors: Uint8Array;
|
|
54
|
+
/** `[x0, y0, x1, y1]` clip box per decoration (`count * 4`). */
|
|
55
|
+
clips: Float32Array;
|
|
56
|
+
/** `[sequence, z]` per decoration (`count * 2`). */
|
|
57
|
+
metadata: Float32Array;
|
|
58
|
+
/** `[centerX, centerY, ordinal]` per decoration (`count * 3`) when shaped runs are present. */
|
|
59
|
+
runMotion: Float32Array | null;
|
|
60
|
+
bounds: VanillaBounds;
|
|
61
|
+
}
|
|
62
|
+
export declare function byte(value: number): number;
|
|
63
|
+
/** Computes a bounding box and sphere in local capture coordinates. */
|
|
64
|
+
export declare function computeInstanceBounds(width: number, height: number, padding?: number, minZ?: number, maxZ?: number): VanillaBounds;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/atlas/vanillaBounds.ts
|
|
2
|
+
function byte(value) {
|
|
3
|
+
if (value <= 0) return 0;
|
|
4
|
+
if (value >= 1) return 255;
|
|
5
|
+
return value * 255 + .5 | 0;
|
|
6
|
+
}
|
|
7
|
+
/** Computes a bounding box and sphere in local capture coordinates. */
|
|
8
|
+
function computeInstanceBounds(width, height, padding = 0, minZ = 0, maxZ = 0) {
|
|
9
|
+
const minX = -padding;
|
|
10
|
+
const minY = -padding;
|
|
11
|
+
const minBoundZ = minZ - padding;
|
|
12
|
+
const maxX = width + padding;
|
|
13
|
+
const maxY = height + padding;
|
|
14
|
+
const maxBoundZ = maxZ + padding;
|
|
15
|
+
const cx = (minX + maxX) * .5;
|
|
16
|
+
const cy = (minY + maxY) * .5;
|
|
17
|
+
const cz = (minBoundZ + maxBoundZ) * .5;
|
|
18
|
+
const dx = maxX - cx;
|
|
19
|
+
const dy = maxY - cy;
|
|
20
|
+
const dz = maxBoundZ - cz;
|
|
21
|
+
return {
|
|
22
|
+
min: [
|
|
23
|
+
minX,
|
|
24
|
+
minY,
|
|
25
|
+
minBoundZ
|
|
26
|
+
],
|
|
27
|
+
max: [
|
|
28
|
+
maxX,
|
|
29
|
+
maxY,
|
|
30
|
+
maxBoundZ
|
|
31
|
+
],
|
|
32
|
+
center: [
|
|
33
|
+
cx,
|
|
34
|
+
cy,
|
|
35
|
+
cz
|
|
36
|
+
],
|
|
37
|
+
radius: Math.sqrt(dx * dx + dy * dy + dz * dz)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export { byte, computeInstanceBounds };
|
|
41
|
+
|
|
42
|
+
//# sourceMappingURL=vanillaBounds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vanillaBounds.js","names":[],"sources":["../../src/atlas/vanillaBounds.ts"],"sourcesContent":["/** Engine-agnostic 3D axis-aligned bounding box and bounding sphere. */\nexport interface VanillaBounds {\n readonly min: readonly [x: number, y: number, z: number]\n readonly max: readonly [x: number, y: number, z: number]\n readonly center: readonly [x: number, y: number, z: number]\n readonly radius: number\n}\n\n/** Packed typed-array instance attributes for SDF glyphs. */\nexport interface VanillaGlyphInstances {\n count: number\n maxSequence: number\n /** `[x0, y0, x1, y1]` per glyph in local capture units (`count * 4`). */\n rects: Float32Array\n /** Normalized `unorm16` `[u0, v1, u1, v0]` per glyph (`count * 4`). */\n uvRects: Uint16Array\n /** Normalized `unorm16` support trim `[u0, v1, u1, v0]` per glyph (`count * 4`), or `null` with `runMotion`. */\n trims: Uint16Array | null\n /** `[x0, y0, x1, y1]` clip box per glyph (`count * 4`). */\n clips: Float32Array\n /** Normalized `unorm8` `[r, g, b, a]` per glyph (`count * 4`). */\n colors: Uint8Array\n /** `[sequence, z]` or `[sequence, z, switchEm]` per glyph (`count * metaItemSize`). */\n metadata: Float32Array\n metaItemSize: 2 | 3\n /** `[centerX, centerY, ordinal]` per glyph (`count * 3`) when shaped runs or SVG groups are present. */\n runMotion: Float32Array | null\n bounds: VanillaBounds\n}\n\n/** Packed typed-array instance attributes for DOM background rectangles. */\nexport interface VanillaRectInstances {\n count: number\n readonly receiveShadow: boolean\n /** `[x0, y0, x1, y1]` per rectangle (`count * 4`). */\n rects: Float32Array\n /** Normalized `unorm8` `[r, g, b, a]` per rectangle (`count * 4`). */\n colors: Uint8Array\n /** Corner radius per rectangle (`count`). */\n radii: Float32Array\n /** Z depth per rectangle (`count`). */\n depths: Float32Array\n bounds: VanillaBounds\n}\n\n/** Packed typed-array instance attributes for CSS text decorations. */\nexport interface VanillaDecorationInstances {\n count: number\n /** Source glyph `[x0, y0, x1, y1]` per decoration (`count * 4`). */\n rects: Float32Array\n /** Decoration stroke `[x0, y0, x1, y1]` per decoration (`count * 4`). */\n decorationRects: Float32Array\n /** Motion index per decoration (`count`). */\n decorationIndices: Float32Array\n /** Normalized `unorm8` `[r, g, b, a]` per decoration (`count * 4`). */\n colors: Uint8Array\n /** `[x0, y0, x1, y1]` clip box per decoration (`count * 4`). */\n clips: Float32Array\n /** `[sequence, z]` per decoration (`count * 2`). */\n metadata: Float32Array\n /** `[centerX, centerY, ordinal]` per decoration (`count * 3`) when shaped runs are present. */\n runMotion: Float32Array | null\n bounds: VanillaBounds\n}\n\nexport function byte(value: number): number {\n if (value <= 0) return 0\n if (value >= 1) return 255\n return (value * 255 + 0.5) | 0\n}\n\n/** Computes a bounding box and sphere in local capture coordinates. */\nexport function computeInstanceBounds(\n width: number,\n height: number,\n padding = 0,\n minZ = 0,\n maxZ = 0,\n): VanillaBounds {\n const minX = -padding\n const minY = -padding\n const minBoundZ = minZ - padding\n const maxX = width + padding\n const maxY = height + padding\n const maxBoundZ = maxZ + padding\n const cx = (minX + maxX) * 0.5\n const cy = (minY + maxY) * 0.5\n const cz = (minBoundZ + maxBoundZ) * 0.5\n const dx = maxX - cx\n const dy = maxY - cy\n const dz = maxBoundZ - cz\n return {\n min: [minX, minY, minBoundZ],\n max: [maxX, maxY, maxBoundZ],\n center: [cx, cy, cz],\n radius: Math.sqrt(dx * dx + dy * dy + dz * dz),\n }\n}\n"],"mappings":";AAiEA,SAAgB,KAAK,OAAuB;CAC1C,IAAI,SAAS,GAAG,OAAO;CACvB,IAAI,SAAS,GAAG,OAAO;CACvB,OAAQ,QAAQ,MAAM,KAAO;AAC/B;;AAGA,SAAgB,sBACd,OACA,QACA,UAAU,GACV,OAAO,GACP,OAAO,GACQ;CACf,MAAM,OAAO,CAAC;CACd,MAAM,OAAO,CAAC;CACd,MAAM,YAAY,OAAO;CACzB,MAAM,OAAO,QAAQ;CACrB,MAAM,OAAO,SAAS;CACtB,MAAM,YAAY,OAAO;CACzB,MAAM,MAAM,OAAO,QAAQ;CAC3B,MAAM,MAAM,OAAO,QAAQ;CAC3B,MAAM,MAAM,YAAY,aAAa;CACrC,MAAM,KAAK,OAAO;CAClB,MAAM,KAAK,OAAO;CAClB,MAAM,KAAK,YAAY;CACvB,OAAO;EACL,KAAK;GAAC;GAAM;GAAM;EAAS;EAC3B,KAAK;GAAC;GAAM;GAAM;EAAS;EAC3B,QAAQ;GAAC;GAAI;GAAI;EAAE;EACnB,QAAQ,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,EAAE;CAC/C;AACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { BuildSdfAtlasOptions, DomLayoutSnapshot, DomSdfOptions, DomSdfStats, RasterAtlas, SdfMotionOptions, TextClass, TextCss } from '../types.js';
|
|
2
|
+
import { type ResolvedTextTone } from '../dom/tone.js';
|
|
3
|
+
import type { PreparedCpuWorker } from './cpuWorker.js';
|
|
4
|
+
import { computeInstanceBounds, type VanillaBounds, type VanillaDecorationInstances, type VanillaGlyphInstances, type VanillaRectInstances } from './vanillaBounds.js';
|
|
5
|
+
import { type VanillaGpuDevice, type VanillaGpuDeviceSource, type VanillaGpuTexture, type VanillaSdfAtlas, type VanillaSdfColorLayer } from './vanillaGpuHelpers.js';
|
|
6
|
+
export { computeInstanceBounds, type VanillaBounds, type VanillaDecorationInstances, type VanillaGlyphInstances, type VanillaGpuDevice, type VanillaGpuDeviceSource, type VanillaGpuTexture, type VanillaRectInstances, type VanillaSdfAtlas, type VanillaSdfColorLayer, };
|
|
7
|
+
export declare function buildVanillaGpuSdfAtlas(device: VanillaGpuDevice, raster: RasterAtlas, options?: Omit<BuildSdfAtlasOptions, 'mode'>): Promise<VanillaSdfAtlas>;
|
|
8
|
+
/**
|
|
9
|
+
* Engine-agnostic SDF atlas builder. Accepts a `GPUDevice`, an object holding `{ device }`
|
|
10
|
+
* (such as a Mini3 `Renderer`), or `null`/`undefined` for CPU generation.
|
|
11
|
+
* In `'auto'` mode (default), tries the WebGPU JFA path when a device is provided and falls
|
|
12
|
+
* back to the exact CPU EDT encoder if the device is absent or rejects the passes.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildVanillaSdfAtlas(deviceOrRenderer: VanillaGpuDeviceSource, raster: RasterAtlas, options?: BuildSdfAtlasOptions,
|
|
15
|
+
/** @internal */
|
|
16
|
+
preparedWorker?: PreparedCpuWorker | null): Promise<VanillaSdfAtlas>;
|
|
17
|
+
export { buildVanillaSdfAtlas as buildSdfAtlas };
|
|
18
|
+
/** Unit quad vertex positions (`[0,0,0, 1,0,0, 1,1,0, 0,1,0]`, 4 vertices × 3 floats). */
|
|
19
|
+
export declare const UNIT_QUAD_POSITIONS: Float32Array<ArrayBuffer>;
|
|
20
|
+
/** Unit quad vertex normals (`[0,0,1, ...]`, 4 vertices × 3 floats). */
|
|
21
|
+
export declare const UNIT_QUAD_NORMALS: Float32Array<ArrayBuffer>;
|
|
22
|
+
/** Unit quad triangle indices (`[0, 1, 2, 0, 2, 3]`, 6 uint16 indices). */
|
|
23
|
+
export declare const UNIT_QUAD_INDICES: Uint16Array<ArrayBuffer>;
|
|
24
|
+
export type GlyphAtlasLookup = Pick<VanillaSdfAtlas, 'bakeSize' | 'glyphs'>;
|
|
25
|
+
/** Packs instanced glyph attribute arrays from a layout snapshot and SDF atlas. */
|
|
26
|
+
export declare function packGlyphInstances(snapshot: DomLayoutSnapshot, atlas: GlyphAtlasLookup, motionPadding?: number, motionOrdinals?: Float32Array): VanillaGlyphInstances;
|
|
27
|
+
/**
|
|
28
|
+
* Rewrites the glyph instance arrays that change on a reflow (`rects`, `clips`, `metadata`,
|
|
29
|
+
* `runMotion`, `bounds`) in place without reallocating. Returns `maxSequence`, or `null` when
|
|
30
|
+
* the glyph count no longer matches.
|
|
31
|
+
*/
|
|
32
|
+
export declare function updateGlyphInstances(instances: VanillaGlyphInstances, snapshot: DomLayoutSnapshot, atlas: GlyphAtlasLookup, motionPadding?: number, motionOrdinals?: Float32Array): number | null;
|
|
33
|
+
/**
|
|
34
|
+
* Rewrites all glyph instance arrays in place when the drawable count and layout match.
|
|
35
|
+
* Returns `maxSequence`, or `null` without mutating when the buffers do not fit.
|
|
36
|
+
*/
|
|
37
|
+
export declare function updateGlyphContentInstances(instances: VanillaGlyphInstances, snapshot: DomLayoutSnapshot, atlas: GlyphAtlasLookup, motionPadding?: number, motionOrdinals?: Float32Array): number | null;
|
|
38
|
+
export interface VanillaDomTextRebuildOptions {
|
|
39
|
+
signal?: AbortSignal;
|
|
40
|
+
}
|
|
41
|
+
export type VanillaChangeReason = 'create' | 'rebuild' | 'reflow' | 'motion' | 'dispose';
|
|
42
|
+
/** Options for `VanillaDomText` (`DomText` / `DomSdf` in `ultra-text/vanilla`). */
|
|
43
|
+
export interface VanillaDomTextOptions extends Omit<DomSdfOptions, 'fill' | 'vertex' | 'sharedAtlas' | 'side' | 'textBackend' | 'windfoil'> {
|
|
44
|
+
/** Optional shared `VanillaSdfAtlas` across multiple `VanillaDomText` instances. */
|
|
45
|
+
sharedAtlas?: VanillaSdfAtlas;
|
|
46
|
+
/** Called after initial creation, rebuild, reflow, motion update, or disposal. */
|
|
47
|
+
onChange?: (instance: VanillaDomText, reason: VanillaChangeReason) => void;
|
|
48
|
+
}
|
|
49
|
+
export declare class VanillaDomText {
|
|
50
|
+
#private;
|
|
51
|
+
readonly element: HTMLElement;
|
|
52
|
+
readonly device: VanillaGpuDevice | null;
|
|
53
|
+
readonly options: Readonly<VanillaDomTextOptions>;
|
|
54
|
+
glyphs: VanillaGlyphInstances;
|
|
55
|
+
plainRects: VanillaRectInstances | null;
|
|
56
|
+
litRects: VanillaRectInstances | null;
|
|
57
|
+
decorations: VanillaDecorationInstances | null;
|
|
58
|
+
tone: ResolvedTextTone | null;
|
|
59
|
+
motion: Required<SdfMotionOptions>;
|
|
60
|
+
protected constructor(element: HTMLElement, deviceOrRenderer: VanillaGpuDeviceSource, options: VanillaDomTextOptions);
|
|
61
|
+
static create(element: HTMLElement, deviceOrRenderer?: VanillaGpuDeviceSource, options?: VanillaDomTextOptions): Promise<VanillaDomText>;
|
|
62
|
+
get atlas(): VanillaSdfAtlas;
|
|
63
|
+
get stats(): Readonly<DomSdfStats>;
|
|
64
|
+
get snapshot(): DomLayoutSnapshot | null;
|
|
65
|
+
get width(): number;
|
|
66
|
+
get height(): number;
|
|
67
|
+
get isDisposed(): boolean;
|
|
68
|
+
subscribe(listener: (instance: VanillaDomText, reason: VanillaChangeReason) => void): () => void;
|
|
69
|
+
reflow(width: number): this;
|
|
70
|
+
setMotion(motion: SdfMotionOptions): this;
|
|
71
|
+
rebuild(rebuildOptions?: VanillaDomTextRebuildOptions): Promise<this>;
|
|
72
|
+
dispose(): void;
|
|
73
|
+
protected resolveCaptureTone(snapshot: DomLayoutSnapshot): ResolvedTextTone | null;
|
|
74
|
+
protected notify(reason: VanillaChangeReason): void;
|
|
75
|
+
protected applySelectableAttribute(): void;
|
|
76
|
+
protected setupObservers(): void;
|
|
77
|
+
}
|
|
78
|
+
export { VanillaDomText as DomSdf, VanillaDomText as DomText };
|
|
79
|
+
export interface VanillaTextOptions extends VanillaDomTextOptions {
|
|
80
|
+
device?: VanillaGpuDeviceSource;
|
|
81
|
+
renderer?: VanillaGpuDeviceSource;
|
|
82
|
+
css?: TextCss;
|
|
83
|
+
cssClass?: TextClass;
|
|
84
|
+
parent?: HTMLElement;
|
|
85
|
+
}
|
|
86
|
+
export declare class VanillaText extends VanillaDomText {
|
|
87
|
+
#private;
|
|
88
|
+
readonly ready: Promise<this>;
|
|
89
|
+
constructor(text: string, options?: VanillaTextOptions);
|
|
90
|
+
static create(text: string, options?: VanillaTextOptions): Promise<VanillaText>;
|
|
91
|
+
static create(element: HTMLElement, deviceOrRenderer?: VanillaGpuDeviceSource, options?: VanillaDomTextOptions): Promise<VanillaDomText>;
|
|
92
|
+
get text(): string;
|
|
93
|
+
set text(value: string);
|
|
94
|
+
setText(value: string, options?: VanillaDomTextRebuildOptions): Promise<this>;
|
|
95
|
+
setCss(css: TextCss | undefined, options?: VanillaDomTextRebuildOptions): Promise<this>;
|
|
96
|
+
setClass(cssClass: TextClass | undefined, options?: VanillaDomTextRebuildOptions): Promise<this>;
|
|
97
|
+
dispose(): void;
|
|
98
|
+
protected resolveCaptureTone(snapshot: DomLayoutSnapshot): ResolvedTextTone | null;
|
|
99
|
+
}
|
|
100
|
+
export { VanillaText as Text };
|