ultra-text 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +193 -115
  2. package/dist/assets/{cpuSdf.worker--X1Qpmdp.js → cpuSdf.worker-Dy4P5_TI.js} +98 -43
  3. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js.map +1 -0
  4. package/dist/assets/traceOutline.worker-B5uVKmR4.js +1725 -0
  5. package/dist/assets/traceOutline.worker-B5uVKmR4.js.map +1 -0
  6. package/dist/atlas/appendAtlas.js +35 -11
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +1 -1
  9. package/dist/atlas/buildAtlas.js.map +1 -1
  10. package/dist/atlas/colorGlyphs.d.ts +0 -10
  11. package/dist/atlas/colorGlyphs.js +97 -155
  12. package/dist/atlas/colorGlyphs.js.map +1 -1
  13. package/dist/atlas/colorTexture.d.ts +1 -0
  14. package/dist/atlas/colorTexture.js +64 -0
  15. package/dist/atlas/colorTexture.js.map +1 -0
  16. package/dist/atlas/cpuAtlas.js +8 -3
  17. package/dist/atlas/cpuAtlas.js.map +1 -1
  18. package/dist/atlas/cpuSdf.d.ts +1 -1
  19. package/dist/atlas/cpuSdf.js +97 -42
  20. package/dist/atlas/cpuSdf.js.map +1 -1
  21. package/dist/atlas/cpuWorker.d.ts +10 -4
  22. package/dist/atlas/cpuWorker.js +99 -49
  23. package/dist/atlas/cpuWorker.js.map +1 -1
  24. package/dist/atlas/gpuAtlas.js +133 -56
  25. package/dist/atlas/gpuAtlas.js.map +1 -1
  26. package/dist/atlas/gpuCommon.d.ts +140 -18
  27. package/dist/atlas/gpuCommon.js +726 -104
  28. package/dist/atlas/gpuCommon.js.map +1 -1
  29. package/dist/atlas/jfaWgsl.d.ts +1 -1
  30. package/dist/atlas/jfaWgsl.js +232 -61
  31. package/dist/atlas/jfaWgsl.js.map +1 -1
  32. package/dist/atlas/rasterize.d.ts +22 -0
  33. package/dist/atlas/rasterize.js +237 -111
  34. package/dist/atlas/rasterize.js.map +1 -1
  35. package/dist/atlas/vanillaCore.js +156 -103
  36. package/dist/atlas/vanillaCore.js.map +1 -1
  37. package/dist/atlas/vanillaCpuAtlas.js +37 -52
  38. package/dist/atlas/vanillaCpuAtlas.js.map +1 -1
  39. package/dist/atlas/vanillaExtras.js +91 -90
  40. package/dist/atlas/vanillaExtras.js.map +1 -1
  41. package/dist/atlas/vanillaGpuHelpers.d.ts +70 -7
  42. package/dist/atlas/vanillaGpuHelpers.js +262 -27
  43. package/dist/atlas/vanillaGpuHelpers.js.map +1 -1
  44. package/dist/dom/DomSdf.js +85 -79
  45. package/dist/dom/DomSdf.js.map +1 -1
  46. package/dist/dom/DomSlug.js +23 -18
  47. package/dist/dom/DomSlug.js.map +1 -1
  48. package/dist/dom/Text.d.ts +4 -1
  49. package/dist/dom/Text.js +5 -1
  50. package/dist/dom/Text.js.map +1 -1
  51. package/dist/dom/browserShaping.js +31 -14
  52. package/dist/dom/browserShaping.js.map +1 -1
  53. package/dist/dom/clusters.js +13 -2
  54. package/dist/dom/clusters.js.map +1 -1
  55. package/dist/dom/cssEffects.d.ts +4 -0
  56. package/dist/dom/cssEffects.js +72 -0
  57. package/dist/dom/cssEffects.js.map +1 -0
  58. package/dist/dom/domAnalytic.d.ts +1 -2
  59. package/dist/dom/domAnalytic.js +1 -1
  60. package/dist/dom/domAnalytic.js.map +1 -1
  61. package/dist/dom/fontCanvas.d.ts +16 -0
  62. package/dist/dom/fontCanvas.js +4 -4
  63. package/dist/dom/fontCanvas.js.map +1 -1
  64. package/dist/dom/layoutSignature.js +28 -12
  65. package/dist/dom/layoutSignature.js.map +1 -1
  66. package/dist/dom/markup.d.ts +10 -0
  67. package/dist/dom/markup.js +16 -1
  68. package/dist/dom/markup.js.map +1 -1
  69. package/dist/dom/pretextLayout.js +27 -19
  70. package/dist/dom/pretextLayout.js.map +1 -1
  71. package/dist/dom/snapshot.d.ts +4 -0
  72. package/dist/dom/snapshot.js +747 -505
  73. package/dist/dom/snapshot.js.map +1 -1
  74. package/dist/dom/snapshotsEqual.d.ts +7 -0
  75. package/dist/dom/snapshotsEqual.js +68 -0
  76. package/dist/dom/snapshotsEqual.js.map +1 -0
  77. package/dist/dom/svgCapture.js +30 -27
  78. package/dist/dom/svgCapture.js.map +1 -1
  79. package/dist/dom/textTransform.d.ts +13 -1
  80. package/dist/dom/textTransform.js +31 -13
  81. package/dist/dom/textTransform.js.map +1 -1
  82. package/dist/dom/tone.js +15 -8
  83. package/dist/dom/tone.js.map +1 -1
  84. package/dist/slug/SlugMaterial.d.ts +6 -0
  85. package/dist/slug/SlugMaterial.js +48 -20
  86. package/dist/slug/SlugMaterial.js.map +1 -1
  87. package/dist/slug/cff.d.ts +5 -0
  88. package/dist/slug/cff.js +780 -0
  89. package/dist/slug/cff.js.map +1 -0
  90. package/dist/slug/coverage.d.ts +3 -3
  91. package/dist/slug/coverage.js +283 -101
  92. package/dist/slug/coverage.js.map +1 -1
  93. package/dist/slug/preprocessCore.d.ts +1 -1
  94. package/dist/slug/preprocessCore.js +100 -80
  95. package/dist/slug/preprocessCore.js.map +1 -1
  96. package/dist/slug/runtime.js +32 -39
  97. package/dist/slug/runtime.js.map +1 -1
  98. package/dist/slug/standaloneRuntime.js +47 -37
  99. package/dist/slug/standaloneRuntime.js.map +1 -1
  100. package/dist/slug/truetype.d.ts +14 -6
  101. package/dist/slug/truetype.js +190 -62
  102. package/dist/slug/truetype.js.map +1 -1
  103. package/dist/slug/vanillaCore.d.ts +74 -4
  104. package/dist/slug/vanillaCore.js +226 -217
  105. package/dist/slug/vanillaCore.js.map +1 -1
  106. package/dist/slug-vanilla.d.ts +1 -1
  107. package/dist/slug-vanilla.js +5 -4
  108. package/dist/slug.d.ts +1 -1
  109. package/dist/slug.js +3 -3
  110. package/dist/text/GlyphTextMaterial.d.ts +5 -0
  111. package/dist/text/GlyphTextMaterial.js +11 -7
  112. package/dist/text/GlyphTextMaterial.js.map +1 -1
  113. package/dist/text/RectMaterial.js +6 -10
  114. package/dist/text/RectMaterial.js.map +1 -1
  115. package/dist/text/SdfTextMaterial.d.ts +9 -3
  116. package/dist/text/SdfTextMaterial.js +122 -37
  117. package/dist/text/SdfTextMaterial.js.map +1 -1
  118. package/dist/text/decorations.d.ts +7 -2
  119. package/dist/text/decorations.js +187 -96
  120. package/dist/text/decorations.js.map +1 -1
  121. package/dist/text/geometryUtils.d.ts +5 -0
  122. package/dist/text/geometryUtils.js +63 -9
  123. package/dist/text/geometryUtils.js.map +1 -1
  124. package/dist/text/glyphGeometry.d.ts +1 -1
  125. package/dist/text/glyphGeometry.js +281 -200
  126. package/dist/text/glyphGeometry.js.map +1 -1
  127. package/dist/text/rectGeometry.js +46 -42
  128. package/dist/text/rectGeometry.js.map +1 -1
  129. package/dist/text/reflow.d.ts +5 -0
  130. package/dist/text/reflow.js +127 -68
  131. package/dist/text/reflow.js.map +1 -1
  132. package/dist/text/snap.d.ts +15 -1
  133. package/dist/text/snap.js +1 -1
  134. package/dist/text/snap.js.map +1 -1
  135. package/dist/text/tone.js +2 -2
  136. package/dist/text/tone.js.map +1 -1
  137. package/dist/types.d.ts +23 -7
  138. package/dist/vanilla.js +1 -1
  139. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  140. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  141. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  142. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  143. package/dist/windfoil/WindfoilMaterial.js +71 -8
  144. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  145. package/dist/windfoil/compositeGeometry.js +12 -5
  146. package/dist/windfoil/compositeGeometry.js.map +1 -1
  147. package/dist/windfoil/coverage.d.ts +10 -2
  148. package/dist/windfoil/coverage.js +147 -59
  149. package/dist/windfoil/coverage.js.map +1 -1
  150. package/dist/windfoil/geometry.d.ts +15 -0
  151. package/dist/windfoil/geometry.js +154 -64
  152. package/dist/windfoil/geometry.js.map +1 -1
  153. package/dist/windfoil/layerGrid.js +8 -8
  154. package/dist/windfoil/layerGrid.js.map +1 -1
  155. package/dist/windfoil/mixed.js +13 -4
  156. package/dist/windfoil/mixed.js.map +1 -1
  157. package/dist/windfoil/preprocess.js +2 -2
  158. package/dist/windfoil/preprocessCore.d.ts +1 -0
  159. package/dist/windfoil/preprocessCore.js +63 -36
  160. package/dist/windfoil/preprocessCore.js.map +1 -1
  161. package/dist/windfoil/requests.d.ts +1 -1
  162. package/dist/windfoil/requests.js +11 -4
  163. package/dist/windfoil/requests.js.map +1 -1
  164. package/dist/windfoil/resolveOutline.d.ts +9 -0
  165. package/dist/windfoil/resolveOutline.js +20 -0
  166. package/dist/windfoil/resolveOutline.js.map +1 -0
  167. package/dist/windfoil/runtime.d.ts +1 -0
  168. package/dist/windfoil/runtime.js +8 -24
  169. package/dist/windfoil/runtime.js.map +1 -1
  170. package/dist/windfoil/shapeGeometry.js +80 -34
  171. package/dist/windfoil/shapeGeometry.js.map +1 -1
  172. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  173. package/dist/windfoil/sizeSwitch.js +13 -8
  174. package/dist/windfoil/sizeSwitch.js.map +1 -1
  175. package/dist/windfoil/storage.d.ts +23 -9
  176. package/dist/windfoil/storage.js +49 -30
  177. package/dist/windfoil/storage.js.map +1 -1
  178. package/dist/windfoil/svg/curves.d.ts +20 -0
  179. package/dist/windfoil/svg/curves.js +145 -42
  180. package/dist/windfoil/svg/curves.js.map +1 -1
  181. package/dist/windfoil/svg/document.js +10 -1
  182. package/dist/windfoil/svg/document.js.map +1 -1
  183. package/dist/windfoil/svg/pathConverter.js +66 -50
  184. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  185. package/dist/windfoil/svg/pathData.d.ts +9 -0
  186. package/dist/windfoil/svg/pathData.js +142 -109
  187. package/dist/windfoil/svg/pathData.js.map +1 -1
  188. package/dist/windfoil/svg/winding.js +34 -10
  189. package/dist/windfoil/svg/winding.js.map +1 -1
  190. package/dist/windfoil/trace/contours.js +120 -50
  191. package/dist/windfoil/trace/contours.js.map +1 -1
  192. package/dist/windfoil/trace/fit.js +578 -224
  193. package/dist/windfoil/trace/fit.js.map +1 -1
  194. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  195. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  196. package/dist/windfoil/trace/traceWorker.js +192 -0
  197. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  198. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  199. package/dist/windfoil/tracedOutlines.js +335 -70
  200. package/dist/windfoil/tracedOutlines.js.map +1 -1
  201. package/package.json +48 -29
  202. package/skills/ultra-text/SKILL.md +9 -10
  203. package/skills/ultra-text/references/frameworks.md +46 -2
  204. package/skills/ultra-text/references/three-tsl.md +26 -24
  205. package/skills/ultra-text/references/vanilla-webgpu.md +3 -1
  206. package/dist/assets/cpuSdf.worker--X1Qpmdp.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 {\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,C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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
+ {"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 { registerDeferredColorBleed } from './gpuCommon.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/** 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 readonly boxHeight?: 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 * @internal Defer CPU BFS colour-band dilation so WebGPU callers can run GPU colour-band bleed.\n */\n deferColorBleed?: 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 hasActualY =\n !inkBounds &&\n Number.isFinite(metrics.actualBoundingBoxAscent) &&\n Number.isFinite(metrics.actualBoundingBoxDescent) &&\n metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent >= 0\n const boxY0 = -Math.max(descent, inkBounds ? metrics.actualBoundingBoxDescent : 0) - padding\n const boxY1 = Math.ceil(\n Math.max(ascent, inkBounds ? metrics.actualBoundingBoxAscent : 0) + padding,\n )\n const planeY0 = hasActualY ? Math.floor(-metrics.actualBoundingBoxDescent - padding) : boxY0\n const planeY1 = hasActualY ? Math.ceil(metrics.actualBoundingBoxAscent + padding) : boxY1\n const boxHeight = Math.max(2, Math.ceil(boxY1 - boxY0) + 2)\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 ...(hasActualY ? { boxHeight } : {}),\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\ninterface PackingGroup {\n readonly glyphs: MeasuredGlyph[]\n readonly prefixWidths: Float64Array | null\n readonly area: number\n}\n\nconst DIRECT_SHELF_LIMIT = 24\n\nfunction preparePackingGroup(glyphs: MeasuredGlyph[]): PackingGroup {\n const first = glyphs[0]!\n const last = glyphs[glyphs.length - 1]!\n // Equal endpoints in height-then-width order imply a uniform grid.\n if (first.width === last.width && first.height === last.height) {\n return { glyphs, prefixWidths: null, area: first.width * first.height * glyphs.length }\n }\n // Direct shelf scans cost less than setting up row searches for short runs.\n const prefixWidths =\n glyphs.length > DIRECT_SHELF_LIMIT ? new Float64Array(glyphs.length + 1) : null\n let area = 0\n for (let i = 0; i < glyphs.length; i++) {\n const g = glyphs[i]!\n if (prefixWidths) prefixWidths[i + 1] = prefixWidths[i]! + g.width\n area += g.width * g.height\n }\n return { glyphs, prefixWidths, area }\n}\n\n/** Measures greedy shelves from their row ends. Groups are sorted tallest first. */\nfunction measureShelves(group: PackingGroup, width: number, limit: number): PackedGlyphs | null {\n const { glyphs, prefixWidths } = group\n const count = glyphs.length\n if (!prefixWidths) {\n if (count <= DIRECT_SHELF_LIMIT) return packShelves(glyphs, width, limit)\n const { width: gw, height: gh } = glyphs[0]!\n if (gw > width) {\n lastOverflowWidth = Math.min(lastOverflowWidth, gw)\n return null\n }\n if (gh > limit) return null\n const columns = Math.floor(width / gw)\n if (count > columns) lastOverflowWidth = Math.min(lastOverflowWidth, (columns + 1) * gw)\n const height = Math.ceil(count / columns) * gh\n return height > limit\n ? null\n : { width: align4(Math.min(count, columns) * gw), height: align4(height) }\n }\n\n let usedWidth = 0\n let height = 0\n for (let start = 0; start < count;) {\n const first = glyphs[start]!\n if (first.width > width) {\n lastOverflowWidth = Math.min(lastOverflowWidth, first.width)\n return null\n }\n height += first.height\n if (height > limit) return null\n const target = prefixWidths[start]! + width\n let lo = start + 1\n let hi = count\n while (lo < hi) {\n const mid = lo + ((hi - lo + 1) >>> 1)\n if (prefixWidths[mid]! <= target) lo = mid\n else hi = mid - 1\n }\n const used = prefixWidths[lo]! - prefixWidths[start]!\n if (used > usedWidth) usedWidth = used\n if (lo < count) {\n const nextWidth = glyphs[lo]!.width\n lastOverflowWidth = Math.min(\n lastOverflowWidth,\n nextWidth > width ? nextWidth : used + nextWidth,\n )\n }\n start = lo\n }\n return { width: align4(usedWidth), height: align4(height) }\n}\n\n// Consecutive x, y and width values let one overlap-safe copy move a run of skyline nodes.\nlet skylineNodes = new Int32Array(256 * 3)\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, area }: PackingGroup,\n width: number,\n maxSize: number,\n place: boolean,\n): { width: number; height: number } | null {\n const needed = (glyphs.length + 2) * 3\n if (skylineNodes.length < needed) skylineNodes = new Int32Array(needed)\n const nodes = skylineNodes\n nodes[0] = 0\n nodes[1] = 0\n nodes[2] = width\n let skylineEnd = 3\n let usedWidth = 0\n let usedHeight = 0\n\n const minH = glyphs[glyphs.length - 1]!.height\n let wasteBudget = width * maxSize - area\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 = skylineEnd - 3\n const tailY = nodes[tail + 1]!\n let maxAllowedY = nodes[tail + 2]! >= gw ? Math.min(tailY, maxSize - gh) : maxSize - gh\n\n for (let index = 0; index < skylineEnd; index += 3) {\n const firstY = nodes[index + 1]!\n if (firstY > maxAllowedY) continue\n const x = nodes[index]!\n if (x + gw > width) {\n if (x + gw < lastOverflowWidth) lastOverflowWidth = x + gw\n break\n }\n\n let remaining = gw - nodes[index + 2]!\n let y = firstY\n let waste = 0\n if (remaining > 0) {\n let coveredArea = nodes[index + 2]! * firstY\n for (let cursor = index + 3; ; cursor += 3) {\n const nodeY = nodes[cursor + 1]!\n if (nodeY > maxAllowedY) {\n index = cursor\n remaining = 1\n break\n }\n if (nodeY > y) y = nodeY\n const nodeW = nodes[cursor + 2]!\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 = nodes[bestIndex]!\n const right = gx + gw\n if (place) {\n glyph.x = gx\n glyph.y = bestBottom - gh\n }\n let cursor = bestIndex\n while (cursor < skylineEnd && nodes[cursor]! + nodes[cursor + 2]! <= right) cursor += 3\n if (cursor < skylineEnd && nodes[cursor]! < right) {\n nodes[cursor + 2] = nodes[cursor]! + nodes[cursor + 2]! - right\n nodes[cursor] = right\n }\n let insertLength = 3\n if (bestIndex > 0 && nodes[bestIndex - 2] === bestBottom) {\n nodes[bestIndex - 1] = nodes[bestIndex - 1]! + gw\n insertLength = 0\n if (cursor < skylineEnd && nodes[cursor + 1] === bestBottom) {\n nodes[bestIndex - 1] = nodes[bestIndex - 1]! + nodes[cursor + 2]!\n cursor += 3\n }\n } else if (cursor < skylineEnd && nodes[cursor + 1] === bestBottom) {\n nodes[cursor] = gx\n nodes[cursor + 2] = nodes[cursor + 2]! + gw\n insertLength = 0\n }\n const delta = insertLength - (cursor - bestIndex)\n if (delta !== 0 && cursor < skylineEnd) nodes.copyWithin(cursor + delta, cursor, skylineEnd)\n skylineEnd += delta\n if (insertLength) {\n nodes[bestIndex] = gx\n nodes[bestIndex + 1] = bestBottom\n nodes[bestIndex + 2] = 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 packGroups(\n groups: PackingGroup[],\n width: number,\n limit: number,\n skyline: boolean,\n place = false,\n): PackedGlyphs | null {\n if (!groups.length) return { width: 4, height: 4 }\n let packedWidth = 0\n let height = 0\n for (const group of groups) {\n const available = limit - height\n const packed = skyline\n ? packSkyline(group, width, available, place)\n : place\n ? packShelves(group.glyphs, width, available)\n : measureShelves(group, width, available)\n if (!packed || (groups.length > 1 && height + packed.height > limit)) return null\n if (place && height) for (const glyph of group.glyphs) glyph.y += height\n packedWidth = Math.max(packedWidth, packed.width)\n height += packed.height\n }\n return { width: packedWidth, 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 light = paint('#fff')\n for (const glyph of tested) {\n if (!colorGlyphs!.slotHasColor(light, dark, scratch.width, glyph)) 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 impossible = totalArea > packingLimit * packingLimit || exceedsLimit\n const packing = impossible ? [] : groups.map(preparePackingGroup)\n let bestWidth = Math.min(packingLimit, Math.max(64, nextPowerOfTwo(Math.sqrt(totalArea))))\n let bestLimit = packingLimit\n let bestSkyline = false\n let best = impossible ? null : packGroups(packing, bestWidth, bestLimit, false)\n while (!best && !impossible && bestWidth < packingLimit) {\n bestWidth = Math.min(packingLimit, bestWidth * 2)\n best = packGroups(packing, bestWidth, bestLimit, false)\n }\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 let shelfBestWidth = best?.width ?? minimumWidth\n let nextShelfW = minimumWidth\n for (let width = minimumWidth; width <= packingLimit; width += 4) {\n throwIfAborted(options.signal)\n if (maxHeightFor(width) < minRequiredLimit) break\n if (width < nextShelfW) continue\n const minH = align4(Math.max(minRequiredLimit, Math.ceil(totalArea / width)))\n const maxCandidateHeight = maxHeightFor(width)\n if (minH > maxCandidateHeight) break\n lastOverflowWidth = Infinity\n const candidate = packGroups(packing, width, maxCandidateHeight, false)\n nextShelfW = lastOverflowWidth\n if (candidate && (!best || isBetterPacking(candidate, best))) {\n best = candidate\n bestWidth = width\n bestLimit = maxCandidateHeight\n bestSkyline = false\n shelfBestWidth = best.width\n }\n }\n if (packerCount === 2) {\n const trySkylineRange = (start: number, end: number, step: number): void => {\n const lo = Math.max(minimumWidth, align4(start))\n const hi = Math.min(packingLimit, align4(end))\n let nextSkyW = lo\n for (let width = lo; width <= hi; width += step) {\n throwIfAborted(options.signal)\n if (maxHeightFor(width) < minRequiredLimit) break\n if (width < nextSkyW) continue\n const minH = align4(Math.max(minRequiredLimit, Math.ceil(totalArea / width)))\n const maxCandidateHeight = maxHeightFor(width)\n if (minH > maxCandidateHeight) break\n lastOverflowWidth = Infinity\n const candidate = packGroups(packing, width, maxCandidateHeight, true)\n nextSkyW = lastOverflowWidth\n if (candidate && (!best || isBetterPacking(candidate, best))) {\n best = candidate\n bestWidth = width\n bestLimit = maxCandidateHeight\n bestSkyline = true\n }\n }\n }\n const refineAround = (center: number): void => {\n trySkylineRange(center - 48, center + 48, 16)\n const c2 = best?.width ?? center\n trySkylineRange(c2 - 12, c2 + 12, 4)\n }\n if (measured.length <= 24 || packingLimit - minimumWidth <= 128) {\n trySkylineRange(minimumWidth, packingLimit, 4)\n } else {\n trySkylineRange(minimumWidth, packingLimit, 64)\n if (best) {\n const maxValidW = align4(\n Math.min(packingLimit, Math.floor((best.width * best.height) / minRequiredLimit)),\n )\n if (maxValidW >= minimumWidth) trySkylineRange(maxValidW, maxValidW, 4)\n }\n const skyCoarseW = best?.width ?? minimumWidth\n refineAround(skyCoarseW)\n if (shelfBestWidth !== skyCoarseW) refineAround(shelfBestWidth)\n if (!best) trySkylineRange(minimumWidth, packingLimit, 4)\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 // Reproduce the winning trial with its original height limit and tie order.\n packGroups(packing, bestWidth, bestLimit, bestSkyline, true)\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 let tallestFontBox = textRows[0]!.height\n for (const glyph of textRows) {\n if (glyph.width > widestText) widestText = glyph.width\n if (glyph.boxHeight !== undefined && glyph.boxHeight > tallestFontBox) {\n tallestFontBox = glyph.boxHeight\n }\n }\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(tallestFontBox, 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 bandSlots = band.map((glyph) => ({ ...glyph, y: glyph.y - bandTop }))\n const deferBleed =\n options.deferColorBleed === true && padding > 0 && canvas.width * bandHeight >= 16384\n const encoded = colorGlyphs!.encodeColorBand(\n white,\n black,\n canvas.width,\n bandHeight,\n deferBleed ? 0 : padding,\n bandSlots,\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 if (deferBleed) {\n const w = canvas.width\n const h = bandHeight\n const range = padding\n const encodeFn = colorGlyphs!.encodeColorBand\n registerDeferredColorBleed(encoded.data, {\n white,\n black,\n width: w,\n height: h,\n pxRange: range,\n applyCpu: () => {\n encoded.data.set(encodeFn(white, black, w, h, range, []).data)\n },\n })\n }\n colorBand = { top: bandTop, height: bandHeight, data: encoded.data }\n }\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 + glyph.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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