ultra-text 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/README.md +339 -1039
  2. package/dist/assets/cpuSdf.worker-Dy4P5_TI.js +466 -0
  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 +97 -31
  7. package/dist/atlas/appendAtlas.js.map +1 -1
  8. package/dist/atlas/buildAtlas.js +4 -3
  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.d.ts +4 -1
  17. package/dist/atlas/cpuAtlas.js +14 -7
  18. package/dist/atlas/cpuAtlas.js.map +1 -1
  19. package/dist/atlas/cpuSdf.d.ts +1 -1
  20. package/dist/atlas/cpuSdf.js +235 -68
  21. package/dist/atlas/cpuSdf.js.map +1 -1
  22. package/dist/atlas/cpuWorker.d.ts +11 -3
  23. package/dist/atlas/cpuWorker.js +179 -22
  24. package/dist/atlas/cpuWorker.js.map +1 -1
  25. package/dist/atlas/gpuAtlas.js +188 -287
  26. package/dist/atlas/gpuAtlas.js.map +1 -1
  27. package/dist/atlas/gpuCommon.d.ts +257 -0
  28. package/dist/atlas/gpuCommon.js +845 -0
  29. package/dist/atlas/gpuCommon.js.map +1 -0
  30. package/dist/atlas/jfaWgsl.d.ts +1 -1
  31. package/dist/atlas/jfaWgsl.js +226 -249
  32. package/dist/atlas/jfaWgsl.js.map +1 -1
  33. package/dist/atlas/rasterize.d.ts +22 -0
  34. package/dist/atlas/rasterize.js +329 -158
  35. package/dist/atlas/rasterize.js.map +1 -1
  36. package/dist/atlas/shapeRaster.js +2 -1
  37. package/dist/atlas/shapeRaster.js.map +1 -1
  38. package/dist/atlas/vanillaBounds.d.ts +64 -0
  39. package/dist/atlas/vanillaBounds.js +42 -0
  40. package/dist/atlas/vanillaBounds.js.map +1 -0
  41. package/dist/atlas/vanillaCore.d.ts +100 -0
  42. package/dist/atlas/vanillaCore.js +1065 -0
  43. package/dist/atlas/vanillaCore.js.map +1 -0
  44. package/dist/atlas/vanillaCpuAtlas.d.ts +9 -0
  45. package/dist/atlas/vanillaCpuAtlas.js +72 -0
  46. package/dist/atlas/vanillaCpuAtlas.js.map +1 -0
  47. package/dist/atlas/vanillaExtras.d.ts +8 -0
  48. package/dist/atlas/vanillaExtras.js +167 -0
  49. package/dist/atlas/vanillaExtras.js.map +1 -0
  50. package/dist/atlas/vanillaGpuHelpers.d.ts +295 -0
  51. package/dist/atlas/vanillaGpuHelpers.js +354 -0
  52. package/dist/atlas/vanillaGpuHelpers.js.map +1 -0
  53. package/dist/dom/DomSdf.js +243 -297
  54. package/dist/dom/DomSdf.js.map +1 -1
  55. package/dist/dom/DomSlug.js +94 -165
  56. package/dist/dom/DomSlug.js.map +1 -1
  57. package/dist/dom/Text.d.ts +4 -1
  58. package/dist/dom/Text.js +5 -1
  59. package/dist/dom/Text.js.map +1 -1
  60. package/dist/dom/browserShaping.js +31 -14
  61. package/dist/dom/browserShaping.js.map +1 -1
  62. package/dist/dom/clusters.js +13 -2
  63. package/dist/dom/clusters.js.map +1 -1
  64. package/dist/dom/cssEffects.d.ts +4 -0
  65. package/dist/dom/cssEffects.js +72 -0
  66. package/dist/dom/cssEffects.js.map +1 -0
  67. package/dist/dom/domAnalytic.d.ts +53 -0
  68. package/dist/dom/domAnalytic.js +282 -0
  69. package/dist/dom/domAnalytic.js.map +1 -0
  70. package/dist/dom/domExtras.d.ts +27 -0
  71. package/dist/dom/domExtras.js +137 -0
  72. package/dist/dom/domExtras.js.map +1 -0
  73. package/dist/dom/fontCanvas.d.ts +16 -0
  74. package/dist/dom/fontCanvas.js +31 -13
  75. package/dist/dom/fontCanvas.js.map +1 -1
  76. package/dist/dom/layoutSignature.js +175 -57
  77. package/dist/dom/layoutSignature.js.map +1 -1
  78. package/dist/dom/markup.d.ts +10 -0
  79. package/dist/dom/markup.js +16 -1
  80. package/dist/dom/markup.js.map +1 -1
  81. package/dist/dom/pretextLayout.js +78 -28
  82. package/dist/dom/pretextLayout.js.map +1 -1
  83. package/dist/dom/snapshot.d.ts +4 -0
  84. package/dist/dom/snapshot.js +891 -484
  85. package/dist/dom/snapshot.js.map +1 -1
  86. package/dist/dom/snapshotsEqual.d.ts +7 -0
  87. package/dist/dom/snapshotsEqual.js +68 -0
  88. package/dist/dom/snapshotsEqual.js.map +1 -0
  89. package/dist/dom/svgCapture.d.ts +8 -1
  90. package/dist/dom/svgCapture.js +105 -28
  91. package/dist/dom/svgCapture.js.map +1 -1
  92. package/dist/dom/textTransform.d.ts +13 -1
  93. package/dist/dom/textTransform.js +31 -13
  94. package/dist/dom/textTransform.js.map +1 -1
  95. package/dist/dom/tone.js +91 -44
  96. package/dist/dom/tone.js.map +1 -1
  97. package/dist/index.js +4 -3
  98. package/dist/slug/SlugMaterial.d.ts +17 -3
  99. package/dist/slug/SlugMaterial.js +98 -26
  100. package/dist/slug/SlugMaterial.js.map +1 -1
  101. package/dist/slug/cff.d.ts +5 -0
  102. package/dist/slug/cff.js +780 -0
  103. package/dist/slug/cff.js.map +1 -0
  104. package/dist/slug/coverage.d.ts +19 -15
  105. package/dist/slug/coverage.js +380 -225
  106. package/dist/slug/coverage.js.map +1 -1
  107. package/dist/slug/preprocessCore.d.ts +6 -2
  108. package/dist/slug/preprocessCore.js +199 -148
  109. package/dist/slug/preprocessCore.js.map +1 -1
  110. package/dist/slug/runtime.d.ts +1 -0
  111. package/dist/slug/runtime.js +113 -74
  112. package/dist/slug/runtime.js.map +1 -1
  113. package/dist/slug/standaloneRuntime.d.ts +3 -2
  114. package/dist/slug/standaloneRuntime.js +112 -67
  115. package/dist/slug/standaloneRuntime.js.map +1 -1
  116. package/dist/slug/truetype.d.ts +14 -6
  117. package/dist/slug/truetype.js +356 -255
  118. package/dist/slug/truetype.js.map +1 -1
  119. package/dist/slug/vanillaCore.d.ts +410 -0
  120. package/dist/slug/vanillaCore.js +1630 -0
  121. package/dist/slug/vanillaCore.js.map +1 -0
  122. package/dist/slug-vanilla.d.ts +13 -364
  123. package/dist/slug-vanilla.js +7 -1454
  124. package/dist/slug.d.ts +2 -2
  125. package/dist/slug.js +7 -7
  126. package/dist/text/GlyphTextMaterial.d.ts +6 -1
  127. package/dist/text/GlyphTextMaterial.js +16 -12
  128. package/dist/text/GlyphTextMaterial.js.map +1 -1
  129. package/dist/text/RectMaterial.js +6 -10
  130. package/dist/text/RectMaterial.js.map +1 -1
  131. package/dist/text/SdfTextMaterial.d.ts +9 -3
  132. package/dist/text/SdfTextMaterial.js +125 -38
  133. package/dist/text/SdfTextMaterial.js.map +1 -1
  134. package/dist/text/decorations.d.ts +7 -2
  135. package/dist/text/decorations.js +187 -79
  136. package/dist/text/decorations.js.map +1 -1
  137. package/dist/text/geometry.d.ts +3 -22
  138. package/dist/text/geometryUtils.d.ts +16 -1
  139. package/dist/text/geometryUtils.js +83 -8
  140. package/dist/text/geometryUtils.js.map +1 -1
  141. package/dist/text/glyphGeometry.d.ts +9 -0
  142. package/dist/text/glyphGeometry.js +434 -0
  143. package/dist/text/glyphGeometry.js.map +1 -0
  144. package/dist/text/index.d.ts +2 -1
  145. package/dist/text/rectGeometry.d.ts +13 -0
  146. package/dist/text/rectGeometry.js +101 -0
  147. package/dist/text/rectGeometry.js.map +1 -0
  148. package/dist/text/reflow.d.ts +23 -1
  149. package/dist/text/reflow.js +223 -94
  150. package/dist/text/reflow.js.map +1 -1
  151. package/dist/text/snap.d.ts +15 -0
  152. package/dist/text/snap.js +26 -0
  153. package/dist/text/snap.js.map +1 -0
  154. package/dist/text/tone.js +2 -2
  155. package/dist/text/tone.js.map +1 -1
  156. package/dist/types.d.ts +23 -7
  157. package/dist/vanilla.d.ts +13 -363
  158. package/dist/vanilla.js +7 -1474
  159. package/dist/windfoil/WindfoilCompositeMaterial.d.ts +1 -1
  160. package/dist/windfoil/WindfoilCompositeMaterial.js +10 -3
  161. package/dist/windfoil/WindfoilCompositeMaterial.js.map +1 -1
  162. package/dist/windfoil/WindfoilMaterial.d.ts +12 -5
  163. package/dist/windfoil/WindfoilMaterial.js +71 -8
  164. package/dist/windfoil/WindfoilMaterial.js.map +1 -1
  165. package/dist/windfoil/compositeGeometry.js +12 -5
  166. package/dist/windfoil/compositeGeometry.js.map +1 -1
  167. package/dist/windfoil/coverage.d.ts +10 -2
  168. package/dist/windfoil/coverage.js +147 -59
  169. package/dist/windfoil/coverage.js.map +1 -1
  170. package/dist/windfoil/geometry.d.ts +17 -2
  171. package/dist/windfoil/geometry.js +220 -57
  172. package/dist/windfoil/geometry.js.map +1 -1
  173. package/dist/windfoil/layerGrid.js +8 -8
  174. package/dist/windfoil/layerGrid.js.map +1 -1
  175. package/dist/windfoil/mixed.d.ts +1 -0
  176. package/dist/windfoil/mixed.js +57 -29
  177. package/dist/windfoil/mixed.js.map +1 -1
  178. package/dist/windfoil/preprocess.js +2 -2
  179. package/dist/windfoil/preprocessCore.d.ts +2 -0
  180. package/dist/windfoil/preprocessCore.js +69 -37
  181. package/dist/windfoil/preprocessCore.js.map +1 -1
  182. package/dist/windfoil/requests.d.ts +1 -1
  183. package/dist/windfoil/requests.js +11 -4
  184. package/dist/windfoil/requests.js.map +1 -1
  185. package/dist/windfoil/resolveOutline.d.ts +9 -0
  186. package/dist/windfoil/resolveOutline.js +20 -0
  187. package/dist/windfoil/resolveOutline.js.map +1 -0
  188. package/dist/windfoil/runtime.d.ts +4 -1
  189. package/dist/windfoil/runtime.js +69 -63
  190. package/dist/windfoil/runtime.js.map +1 -1
  191. package/dist/windfoil/shapeGeometry.js +80 -34
  192. package/dist/windfoil/shapeGeometry.js.map +1 -1
  193. package/dist/windfoil/sizeSwitch.d.ts +1 -1
  194. package/dist/windfoil/sizeSwitch.js +13 -8
  195. package/dist/windfoil/sizeSwitch.js.map +1 -1
  196. package/dist/windfoil/storage.d.ts +78 -6
  197. package/dist/windfoil/storage.js +166 -11
  198. package/dist/windfoil/storage.js.map +1 -1
  199. package/dist/windfoil/svg/curves.d.ts +20 -0
  200. package/dist/windfoil/svg/curves.js +145 -42
  201. package/dist/windfoil/svg/curves.js.map +1 -1
  202. package/dist/windfoil/svg/document.js +10 -1
  203. package/dist/windfoil/svg/document.js.map +1 -1
  204. package/dist/windfoil/svg/pathConverter.js +66 -50
  205. package/dist/windfoil/svg/pathConverter.js.map +1 -1
  206. package/dist/windfoil/svg/pathData.d.ts +9 -0
  207. package/dist/windfoil/svg/pathData.js +142 -109
  208. package/dist/windfoil/svg/pathData.js.map +1 -1
  209. package/dist/windfoil/svg/winding.js +34 -10
  210. package/dist/windfoil/svg/winding.js.map +1 -1
  211. package/dist/windfoil/trace/contours.d.ts +5 -0
  212. package/dist/windfoil/trace/contours.js +256 -62
  213. package/dist/windfoil/trace/contours.js.map +1 -1
  214. package/dist/windfoil/trace/fit.d.ts +3 -1
  215. package/dist/windfoil/trace/fit.js +915 -265
  216. package/dist/windfoil/trace/fit.js.map +1 -1
  217. package/dist/windfoil/trace/outline.js +55 -30
  218. package/dist/windfoil/trace/outline.js.map +1 -1
  219. package/dist/windfoil/trace/traceOutline.worker.d.ts +24 -0
  220. package/dist/windfoil/trace/traceWorker.d.ts +13 -0
  221. package/dist/windfoil/trace/traceWorker.js +192 -0
  222. package/dist/windfoil/trace/traceWorker.js.map +1 -0
  223. package/dist/windfoil/trace/types.d.ts +10 -0
  224. package/dist/windfoil/tracedOutlines.d.ts +2 -0
  225. package/dist/windfoil/tracedOutlines.js +393 -103
  226. package/dist/windfoil/tracedOutlines.js.map +1 -1
  227. package/package.json +48 -29
  228. package/skills/ultra-text/SKILL.md +9 -10
  229. package/skills/ultra-text/references/frameworks.md +46 -2
  230. package/skills/ultra-text/references/three-tsl.md +27 -25
  231. package/skills/ultra-text/references/vanilla-webgpu.md +5 -2
  232. package/dist/assets/cpuSdf.worker-xS57yQbP.js +0 -322
  233. package/dist/assets/cpuSdf.worker-xS57yQbP.js.map +0 -1
  234. package/dist/slug-vanilla.js.map +0 -1
  235. package/dist/text/geometry.js +0 -348
  236. package/dist/text/geometry.js.map +0 -1
  237. package/dist/vanilla.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"textTransform.js","names":[],"sources":["../../src/dom/textTransform.ts"],"sourcesContent":["import { glyphClusters } from './clusters.js'\n\n/**\n * @internal Computed `text-transform` of captured text. The DOM keeps the source characters\n * while the browser draws transformed ones, so capture maps them itself, following Blink:\n * case maps distinguish only Turkic, Greek and Lithuanian languages from the root mapping,\n * and `capitalize` ignores language. `full-width` applies where the browser computes it\n * (Firefox and Safari); `full-size-kana` and `math-auto` are not applied.\n */\nexport interface TextTransform {\n readonly caseMap: 'uppercase' | 'lowercase' | 'capitalize' | undefined\n /** `tr`, `az`, `el` or `lt` from the element's `lang`; empty for the root mapping. */\n readonly locale: string\n readonly fullWidth: boolean\n}\n\nconst FULL_WIDTH =\n /[!-~¢£¥¦¬¯₩](?![\\u{fe0e}\\u{fe0f}]?\\u{20e3})|[\\u{ff61}-\\u{ff9f}\\u{ffe8}-\\u{ffee}]/gu\nlet words: Intl.Segmenter | undefined\n\n/** @internal Null when the computed value changes nothing that capture can reproduce. */\nexport function resolveTextTransform(value: string, element: Element): TextTransform | null {\n if (!value || value === 'none') return null\n const keywords = value.split(' ')\n const caseMap = (['uppercase', 'lowercase', 'capitalize'] as const).find((k) =>\n keywords.includes(k),\n )\n const fullWidth = keywords.includes('full-width')\n if (!caseMap && !fullWidth) return null\n const lang =\n caseMap && caseMap !== 'capitalize'\n ? (element.closest('[lang]')?.getAttribute('lang') ?? '')\n : ''\n return {\n caseMap,\n locale: /^(?:tr|az|el|lt)(?=$|[-_])/i.exec(lang)?.[0].toLowerCase() ?? '',\n fullWidth,\n }\n}\n\n/**\n * @internal The whole transformed text, for layouts that measure it themselves. `previous`\n * is the character before the text, which decides whether `capitalize` starts a word.\n */\nexport function transformText(text: string, transform: TextTransform, previous = ' '): string {\n const { caseMap, locale } = transform\n const cased =\n caseMap === 'uppercase'\n ? locale\n ? text.toLocaleUpperCase(locale)\n : text.toUpperCase()\n : caseMap === 'lowercase'\n ? locale\n ? text.toLocaleLowerCase(locale)\n : text.toLowerCase()\n : caseMap === 'capitalize'\n ? capitalize(text, previous)\n : text\n return transform.fullWidth ? cased.replace(FULL_WIDTH, widen) : cased\n}\n\n/**\n * @internal What the browser draws for each glyph cluster of `text`, so Range offsets can keep\n * indexing the DOM text; `undefined` when the transform changes nothing. The whole text is\n * mapped at once (Greek final sigma and accents and the Turkic and Lithuanian dot rules\n * depend on context) and split back into shares, each found through its cluster's own\n * mapping. A share can be empty, for a mark the mapping absorbed, or hold several characters\n * (ß → SS). Clusters map one at a time when the shares do not line up.\n */\nexport function transformClusters(\n text: string,\n transform: TextTransform,\n previous = ' ',\n): string[] | undefined {\n const mapped = transformText(text, transform, previous)\n if (mapped === text) return undefined\n // Capitalize maps characters one for one, so only full-width applies alone.\n const alone =\n transform.caseMap === 'capitalize' ? { ...transform, caseMap: undefined } : transform\n const own = (cluster: string): string => transformText(cluster, alone)\n const clusters = Array.from(glyphClusters(text))\n const shares: string[] = []\n let offset = 0\n for (const cluster of clusters) {\n const expected = own(cluster)\n const point = mapped.codePointAt(offset)\n const share = mapped.startsWith(expected, offset)\n ? expected\n : /^\\p{M}/u.test(cluster)\n ? ''\n : point === undefined\n ? undefined\n : String.fromCodePoint(point)\n if (share === undefined) break\n shares.push(share)\n offset += share.length\n }\n return shares.length === clusters.length && offset === mapped.length ? shares : clusters.map(own)\n}\n\n/**\n * @internal The character before `node` as Blink's `capitalize` sees it: the last UTF-16 unit of\n * the nearest preceding text, read backwards through inline markup and into inline boxes, or a\n * space after a line break, a block or an empty box.\n */\nexport function precedingCharacter(\n node: Node,\n style: (element: Element) => CSSStyleDeclaration,\n): string {\n for (let current = node; ;) {\n const previous = current.previousSibling\n if (previous) {\n const character = lastCharacter(previous, style, true)\n if (character !== undefined) return character\n current = previous\n } else {\n const parent = current.parentElement\n if (!parent || !isInlineFlow(style(parent).display)) return ' '\n current = parent\n }\n }\n}\n\nconst isInlineFlow = (d: string): boolean => !d || d === 'inline' || d === 'contents'\n\nfunction lastCharacter(\n node: Node,\n style: (element: Element) => CSSStyleDeclaration,\n sibling: boolean,\n): string | undefined {\n // Blink reads one UTF-16 unit: half a supplementary-plane letter, which ends the word there.\n if (node.nodeType === 3) return (node as Text).data.slice(-1) || undefined\n if (node.nodeType !== 1) return undefined\n const element = node as Element\n if (element.tagName === 'BR') return ' '\n const display = style(element).display\n if (display === 'none') return undefined\n // Replaced elements are atomic boxes even when their display is inline.\n if (/^(?:audio|canvas|embed|iframe|img|math|object|svg|video)$/.test(element.localName))\n return ' '\n // Text after a block-level sibling starts an anonymous block of its own.\n if (sibling && !isInlineFlow(display) && !display.startsWith('inline')) return ' '\n for (let child = element.lastChild; child; child = child.previousSibling) {\n const character = lastCharacter(child, style, false)\n if (character !== undefined) return character\n }\n return isInlineFlow(display) ? undefined : ' '\n}\n\n/**\n * Blink title-cases the first UTF-16 unit of every word-break segment, seeded with the\n * character before the text so that a word split by inline markup stays one word.\n */\nfunction capitalize(text: string, previous: string): string {\n if (typeof Intl.Segmenter !== 'function') return text\n words ??= new Intl.Segmenter(undefined, { granularity: 'word' })\n let result = ''\n let end = 0\n for (const { index } of words.segment(previous + text)) {\n const start = index - previous.length\n if (start < 0) continue\n const point = String.fromCodePoint(text.codePointAt(start)!)\n result += text.slice(end, start) + titlecase(point)\n end = start + point.length\n }\n return result + text.slice(end)\n}\n\n/** Simple (single-character) titlecase, as ICU's `u_totitle` gives it for the BMP. */\nfunction titlecase(point: string): string {\n const code = point.codePointAt(0)!\n // Latin digraphs have titlecase letters of their own: dž and DŽ become Dž.\n if (code >= 0x1c4 && code <= 0x1cc)\n return String.fromCharCode(0x1c5 + 3 * (((code - 0x1c4) / 3) | 0))\n if (code >= 0x1f1 && code <= 0x1f3) return '\\u01f2'\n // Greek letters with ypogegrammeni take prosgegrammeni capitals: ᾳ becomes ᾼ.\n if (code >= 0x1f80 && code <= 0x1faf) return String.fromCharCode(code | 8)\n if (code === 0x1fb3 || code === 0x1fc3 || code === 0x1ff3) return String.fromCharCode(code + 9)\n // Georgian Mkhedruli is its own titlecase; Blink leaves supplementary planes alone.\n const upper = (code >= 0x10d0 && code <= 0x10ff) || code > 0xffff ? point : point.toUpperCase()\n return upper.length === 1 ? upper : point\n}\n\nfunction widen(character: string): string {\n const code = character.charCodeAt(0)\n return code >= 0xff61\n ? character.normalize('NFKC')\n : String.fromCharCode(code <= 0x7e ? code + 0xfee0 : 0xffe0 + '¢£¬¯¦¥₩'.indexOf(character))\n}\n"],"mappings":";;AAgBA,IAAM,aACJ;AACF,IAAI;;AAGJ,SAAgB,qBAAqB,OAAe,SAAwC;CAC1F,IAAI,CAAC,SAAS,UAAU,QAAQ,OAAO;CACvC,MAAM,WAAW,MAAM,MAAM,GAAG;CAChC,MAAM,UAAW;EAAC;EAAa;EAAa;CAAY,CAAC,CAAW,MAAM,MACxE,SAAS,SAAS,CAAC,CACrB;CACA,MAAM,YAAY,SAAS,SAAS,YAAY;CAChD,IAAI,CAAC,WAAW,CAAC,WAAW,OAAO;CACnC,MAAM,OACJ,WAAW,YAAY,eAClB,QAAQ,QAAQ,QAAQ,CAAC,EAAE,aAAa,MAAM,KAAK,KACpD;CACN,OAAO;EACL;EACA,QAAQ,8BAA8B,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,YAAY,KAAK;EACvE;CACF;AACF;;;;;AAMA,SAAgB,cAAc,MAAc,WAA0B,WAAW,KAAa;CAC5F,MAAM,EAAE,SAAS,W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AAM,GAAG;AAChC;;AAGA,SAAS,UAAU,OAAuB;CACxC,MAAM,OAAO,MAAM,YAAY,CAAC;CAEhC,IAAI,QAAQ,OAAS,QAAQ,KAC3B,OAAO,OAAO,aAAa,MAAQ,MAAO,OAAO,OAAS,IAAK,EAAE;CACnE,IAAI,QAAQ,OAAS,QAAQ,KAAO,OAAO;CAE3C,IAAI,QAAQ,QAAU,QAAQ,MAAQ,OAAO,OAAO,aAAa,OAAO,CAAC;CACzE,IAAI,SAAS,QAAU,SAAS,QAAU,SAAS,MAAQ,OAAO,OAAO,aAAa,OAAO,CAAC;CAE9F,MAAM,QAAS,QAAQ,QAAU,QAAQ,QAAW,OAAO,QAAS,QAAQ,MAAM,YAAY;CAC9F,OAAO,MAAM,WAAW,IAAI,QAAQ;AACtC;AAEA,SAAS,MAAM,WAA2B;CACxC,MAAM,OAAO,UAAU,WAAW,CAAC;CACnC,OAAO,QAAQ,QACX,UAAU,UAAU,MAAM,IAC1B,OAAO,aAAa,QAAQ,MAAO,OAAO,QAAS,QAAS,UAAU,QAAQ,SAAS,CAAC;AAC9F"}
1
+ {"version":3,"file":"textTransform.js","names":[],"sources":["../../src/dom/textTransform.ts"],"sourcesContent":["import { glyphClusters } from './clusters.js'\n\n/**\n * Computed `text-transform` of captured text. The DOM keeps the source characters\n * while the browser draws transformed ones, so capture maps them itself, following Blink:\n * case maps distinguish only Turkic, Greek and Lithuanian languages from the root mapping,\n * and `capitalize` ignores language. `full-width` applies where the browser computes it\n * (Firefox and Safari); `full-size-kana` and `math-auto` are not applied.\n */\nexport interface TextTransform {\n readonly caseMap: 'uppercase' | 'lowercase' | 'capitalize' | undefined\n /** `tr`, `az`, `el` or `lt` from the element's `lang`; empty for the root mapping. */\n readonly locale: string\n readonly fullWidth: boolean\n}\n\nconst FULL_WIDTH =\n /[!-~¢£¥¦¬¯₩](?![\\u{fe0e}\\u{fe0f}]?\\u{20e3})|[\\u{ff61}-\\u{ff9f}\\u{ffe8}-\\u{ffee}]/gu\nconst LANG_LOCALE_RE = /^(?:tr|az|el|lt)(?=$|[-_])/i\nconst REPLACED_ELEMENTS = new Set([\n 'audio',\n 'canvas',\n 'embed',\n 'iframe',\n 'img',\n 'math',\n 'object',\n 'svg',\n 'video',\n])\nlet words: Intl.Segmenter | undefined\n\n/** @internal Null when the computed value changes nothing that capture can reproduce. */\nexport function resolveTextTransform(value: string, element: Element): TextTransform | null {\n if (!value || value === 'none') return null\n let caseMap: TextTransform['caseMap']\n let fullWidth = false\n if (!value.includes(' ')) {\n if (value === 'uppercase' || value === 'lowercase' || value === 'capitalize') caseMap = value\n else if (value === 'full-width') fullWidth = true\n else return null\n } else {\n const keywords = value.split(' ')\n for (const k of keywords) {\n if (k === 'uppercase' || k === 'lowercase' || k === 'capitalize') caseMap ??= k\n else if (k === 'full-width') fullWidth = true\n }\n if (!caseMap && !fullWidth) return null\n }\n const lang =\n caseMap && caseMap !== 'capitalize'\n ? (element.closest('[lang]')?.getAttribute('lang') ?? '')\n : ''\n return {\n caseMap,\n locale: lang ? (LANG_LOCALE_RE.exec(lang)?.[0].toLowerCase() ?? '') : '',\n fullWidth,\n }\n}\n\n/**\n * @internal The whole transformed text, for layouts that measure it themselves. `previous`\n * is the character before the text, which decides whether `capitalize` starts a word.\n */\nexport function transformText(text: string, transform: TextTransform, previous = ' '): string {\n const { caseMap, locale } = transform\n const cased =\n caseMap === 'uppercase'\n ? locale\n ? text.toLocaleUpperCase(locale)\n : text.toUpperCase()\n : caseMap === 'lowercase'\n ? locale\n ? text.toLocaleLowerCase(locale)\n : text.toLowerCase()\n : caseMap === 'capitalize'\n ? capitalize(text, previous)\n : text\n return transform.fullWidth ? cased.replace(FULL_WIDTH, widen) : cased\n}\n\n/**\n * @internal What the browser draws for each glyph cluster of `text`, so Range offsets can keep\n * indexing the DOM text; `undefined` when the transform changes nothing. The whole text is\n * mapped at once (Greek final sigma and accents and the Turkic and Lithuanian dot rules\n * depend on context) and split back into shares, each found through its cluster's own\n * mapping. A share can be empty, for a mark the mapping absorbed, or hold several characters\n * (ß → SS). Clusters map one at a time when the shares do not line up.\n */\nexport function transformClusters(\n text: string,\n transform: TextTransform,\n previous = ' ',\n): string[] | undefined {\n const mapped = transformText(text, transform, previous)\n if (mapped === text) return undefined\n // Capitalize maps characters one for one, so only full-width applies alone.\n const alone =\n transform.caseMap === 'capitalize' ? { ...transform, caseMap: undefined } : transform\n const clusters = Array.from(glyphClusters(text))\n const shares: string[] = []\n let offset = 0\n for (const cluster of clusters) {\n const expected = transformText(cluster, alone)\n const point = mapped.codePointAt(offset)\n const share = mapped.startsWith(expected, offset)\n ? expected\n : /^\\p{M}/u.test(cluster)\n ? ''\n : point === undefined\n ? undefined\n : String.fromCodePoint(point)\n if (share === undefined) break\n shares.push(share)\n offset += share.length\n }\n if (shares.length === clusters.length && offset === mapped.length) return shares\n const fallback = new Array<string>(clusters.length)\n for (let i = 0; i < clusters.length; i++) fallback[i] = transformText(clusters[i]!, alone)\n return fallback\n}\n\n/**\n * @internal The character before `node` as Blink's `capitalize` sees it: the last UTF-16 unit of\n * the nearest preceding text, read backwards through inline markup and into inline boxes, or a\n * space after a line break, a block or an empty box.\n */\nexport function precedingCharacter(\n node: Node,\n style: (element: Element) => CSSStyleDeclaration,\n): string {\n for (let current = node; ;) {\n const previous = current.previousSibling\n if (previous) {\n const character = lastCharacter(previous, style, true)\n if (character !== undefined) return character\n current = previous\n } else {\n const parent = current.parentElement\n if (!parent || !isInlineFlow(style(parent).display)) return ' '\n current = parent\n }\n }\n}\n\nconst isInlineFlow = (d: string): boolean => !d || d === 'inline' || d === 'contents'\n\nfunction lastCharacter(\n node: Node,\n style: (element: Element) => CSSStyleDeclaration,\n sibling: boolean,\n): string | undefined {\n // Blink reads one UTF-16 unit: half a supplementary-plane letter, which ends the word there.\n if (node.nodeType === 3) return (node as Text).data.slice(-1) || undefined\n if (node.nodeType !== 1) return undefined\n const element = node as Element\n if (element.tagName === 'BR') return ' '\n const display = style(element).display\n if (display === 'none') return undefined\n // Replaced elements are atomic boxes even when their display is inline.\n if (REPLACED_ELEMENTS.has(element.localName)) return ' '\n // Text after a block-level sibling starts an anonymous block of its own.\n if (sibling && !isInlineFlow(display) && !display.startsWith('inline')) return ' '\n for (let child = element.lastChild; child; child = child.previousSibling) {\n const character = lastCharacter(child, style, false)\n if (character !== undefined) return character\n }\n return isInlineFlow(display) ? undefined : ' '\n}\n\n/**\n * Blink title-cases the first UTF-16 unit of every word-break segment, seeded with the\n * character before the text so that a word split by inline markup stays one word.\n */\nfunction capitalize(text: string, previous: string): string {\n if (typeof Intl.Segmenter !== 'function') return text\n words ??= new Intl.Segmenter(undefined, { granularity: 'word' })\n let result = ''\n let end = 0\n for (const { index } of words.segment(previous + text)) {\n const start = index - previous.length\n if (start < 0) continue\n const point = String.fromCodePoint(text.codePointAt(start)!)\n result += text.slice(end, start) + titlecase(point)\n end = start + point.length\n }\n return result + text.slice(end)\n}\n\n/** Simple (single-character) titlecase, as ICU's `u_totitle` gives it for the BMP. */\nfunction titlecase(point: string): string {\n const code = point.codePointAt(0)!\n // Latin digraphs have titlecase letters of their own: dž and DŽ become Dž.\n if (code >= 0x1c4 && code <= 0x1cc)\n return String.fromCharCode(0x1c5 + 3 * (((code - 0x1c4) / 3) | 0))\n if (code >= 0x1f1 && code <= 0x1f3) return '\\u01f2'\n // Greek letters with ypogegrammeni take prosgegrammeni capitals: ᾳ becomes ᾼ.\n if (code >= 0x1f80 && code <= 0x1faf) return String.fromCharCode(code | 8)\n if (code === 0x1fb3 || code === 0x1fc3 || code === 0x1ff3) return String.fromCharCode(code + 9)\n // Georgian Mkhedruli is its own titlecase; Blink leaves supplementary planes alone.\n const upper = (code >= 0x10d0 && code <= 0x10ff) || code > 0xffff ? point : point.toUpperCase()\n return upper.length === 1 ? upper : point\n}\n\nfunction widen(character: string): string {\n const code = character.charCodeAt(0)\n return code >= 0xff61\n ? character.normalize('NFKC')\n : String.fromCharCode(code <= 0x7e ? code + 0xfee0 : 0xffe0 + '¢£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,QAAQ,QAAU,QAAQ,MAAQ,OAAO,OAAO,aAAa,OAAO,CAAC;CACzE,IAAI,SAAS,QAAU,SAAS,QAAU,SAAS,MAAQ,OAAO,OAAO,aAAa,OAAO,CAAC;CAE9F,MAAM,QAAS,QAAQ,QAAU,QAAQ,QAAW,OAAO,QAAS,QAAQ,MAAM,YAAY;CAC9F,OAAO,MAAM,WAAW,IAAI,QAAQ;AACtC;AAEA,SAAS,MAAM,WAA2B;CACxC,MAAM,OAAO,UAAU,WAAW,CAAC;CACnC,OAAO,QAAQ,QACX,UAAU,UAAU,MAAM,IAC1B,OAAO,aAAa,QAAQ,MAAO,OAAO,QAAS,QAAS,UAAU,QAAQ,SAAS,CAAC;AAC9F"}
package/dist/dom/tone.js CHANGED
@@ -149,15 +149,21 @@ function over(below, [red, green, blue, alpha]) {
149
149
  */
150
150
  var parsedColors = /* @__PURE__ */ new Map();
151
151
  var colorProbe;
152
- function parseColor(document, value) {
152
+ /**
153
+ * Resolve a CSS colour to sRGB-encoded `[r, g, b, a]` channels, or `null` for transparent /
154
+ * unavailable probe. When `required` is true, failure to obtain a 2D probe throws instead of
155
+ * returning `null`.
156
+ * @internal
157
+ */
158
+ function parseCssColor(document, value, required = false) {
153
159
  if (!value || value === "transparent" || value === "rgba(0, 0, 0, 0)") return null;
154
160
  let rgba = parsedColors.get(value);
155
- if (rgba !== void 0) return rgba;
156
- const channels = splitFn(/^rgba?\(([^)]+)\)$/i, value);
161
+ if (rgba) return rgba;
162
+ const channels = splitFn(/^\s*rgba?\(([^)]+)\)\s*$/i, value);
157
163
  if (channels) {
158
164
  const read = (index, max) => {
159
165
  const channel = channels[index];
160
- return channel === void 0 ? 1 : parseFloat(channel) / (channel.endsWith("%") ? 100 : max);
166
+ return channel === void 0 ? max === 1 ? 1 : 0 : parseFloat(channel) / (channel.includes("%") ? 100 : max);
161
167
  };
162
168
  rgba = [
163
169
  read(0, 255),
@@ -165,53 +171,62 @@ function parseColor(document, value) {
165
171
  read(2, 255),
166
172
  read(3, 1)
167
173
  ];
168
- } else {
169
- rgba = null;
170
- try {
171
- if (colorProbe === void 0) {
172
- const canvas = document.createElement("canvas");
173
- canvas.width = canvas.height = 1;
174
- colorProbe = canvas.getContext("2d", { willReadFrequently: true }) ?? null;
175
- }
176
- if (colorProbe) {
177
- colorProbe.fillStyle = "#0000";
178
- colorProbe.fillStyle = value;
179
- colorProbe.clearRect(0, 0, 1, 1);
180
- colorProbe.fillRect(0, 0, 1, 1);
181
- const pixel = colorProbe.getImageData(0, 0, 1, 1).data;
182
- rgba = [
183
- pixel[0] / 255,
184
- pixel[1] / 255,
185
- pixel[2] / 255,
186
- pixel[3] / 255
187
- ];
188
- }
189
- } catch {
190
- colorProbe = null;
174
+ } else try {
175
+ if (colorProbe === void 0 || required && !colorProbe) {
176
+ const canvas = document.createElement("canvas");
177
+ canvas.width = canvas.height = 1;
178
+ colorProbe = canvas.getContext("2d", { willReadFrequently: true }) ?? null;
179
+ }
180
+ if (!colorProbe) {
181
+ if (required) throw new Error("collectDomSnapshot: Canvas 2D is unavailable");
182
+ return null;
191
183
  }
184
+ colorProbe.fillStyle = "#0000";
185
+ colorProbe.fillStyle = value;
186
+ colorProbe.clearRect(0, 0, 1, 1);
187
+ colorProbe.fillRect(0, 0, 1, 1);
188
+ const pixel = colorProbe.getImageData(0, 0, 1, 1).data;
189
+ rgba = [
190
+ pixel[0] / 255,
191
+ pixel[1] / 255,
192
+ pixel[2] / 255,
193
+ pixel[3] / 255
194
+ ];
195
+ } catch (error) {
196
+ colorProbe = null;
197
+ if (required) throw error;
198
+ return null;
192
199
  }
193
- if (parsedColors.size >= 256) parsedColors.clear();
200
+ if (parsedColors.size >= 1024) parsedColors.clear();
194
201
  parsedColors.set(value, rgba);
195
202
  return rgba;
196
203
  }
197
204
  var prop = (s, k) => s.getPropertyValue(k).trim();
198
205
  function domBackdrop(root, above) {
199
- const layers = [];
206
+ let layer0;
207
+ let layers;
200
208
  let known = false;
201
209
  let image = false;
202
210
  try {
203
211
  const document = root.ownerDocument;
204
212
  const view = document.defaultView;
205
213
  if (!view) return null;
206
- const parent = (element) => element.assignedSlot ?? element.parentElement ?? element.getRootNode().host ?? null;
207
- for (let element = root; element; element = parent(element)) {
214
+ const rootDocEl = document.documentElement;
215
+ const bodyEl = document.body;
216
+ for (let element = root; element; element = element.assignedSlot ?? element.parentElement ?? element.getRootNode().host ?? null) {
208
217
  const style = view.getComputedStyle(element);
209
- if (prop(style, "display") === "contents" || element !== document.documentElement && element !== document.body && (/hidden|collapse/.test(prop(style, "visibility")) || (prop(style, "background-clip") + prop(style, "-webkit-background-clip")).includes("text"))) continue;
210
- image ||= !/^(none)?$/.test(prop(style, "background-image"));
218
+ if (prop(style, "display") === "contents") continue;
219
+ if (element !== rootDocEl && element !== bodyEl && (/hidden|collapse/.test(prop(style, "visibility")) || style.getPropertyValue("background-clip").includes("text") || style.getPropertyValue("-webkit-background-clip").includes("text"))) continue;
220
+ const bgImg = prop(style, "background-image");
221
+ if (bgImg && bgImg !== "none") image = true;
211
222
  if (above && element === root) continue;
212
- const layer = parseColor(document, style.backgroundColor);
223
+ const layer = parseCssColor(document, style.backgroundColor);
213
224
  if (!layer || !(layer[3] > 0)) continue;
214
- layers.push(layer);
225
+ if (layer0 === void 0) layer0 = layer;
226
+ else {
227
+ layers ??= [layer0];
228
+ layers.push(layer);
229
+ }
215
230
  if (layer[3] >= 1) {
216
231
  known = !image;
217
232
  break;
@@ -220,6 +235,16 @@ function domBackdrop(root, above) {
220
235
  } catch {
221
236
  return null;
222
237
  }
238
+ if (layer0 === void 0) return [[
239
+ 1,
240
+ 1,
241
+ 1
242
+ ], known];
243
+ if (!layers) return [over([
244
+ 1,
245
+ 1,
246
+ 1
247
+ ], layer0), known];
223
248
  return [layers.reduceRight(over, [
224
249
  1,
225
250
  1,
@@ -227,27 +252,44 @@ function domBackdrop(root, above) {
227
252
  ]), known];
228
253
  }
229
254
  function captureBackdrop(base, { glyphs, rects }) {
255
+ const baseLightness = base ? lightnessOf(base) : void 0;
256
+ if (!rects.length || !glyphs.length) return [
257
+ baseLightness,
258
+ false,
259
+ true
260
+ ];
261
+ let sorted = true;
262
+ for (let i = 1; i < rects.length; i++) if (rects[i].z < rects[i - 1].z) {
263
+ sorted = false;
264
+ break;
265
+ }
266
+ const painted = sorted ? rects : [...rects].sort((first, second) => first.z - second.z);
230
267
  const samples = Math.min(glyphs.length, 512);
231
- const painted = rects.length > 1 ? [...rects].sort((first, second) => first.z - second.z) : rects;
268
+ const useMask = painted.length <= 32;
232
269
  const stacks = /* @__PURE__ */ new Map();
233
270
  let half = 0;
271
+ let prevColor;
272
+ let prevLift = 0;
234
273
  for (let sample = 0; sample < samples; sample++) {
235
274
  const glyph = glyphs[Math.floor(sample * glyphs.length / samples)];
236
- if (!rects.length || glyph.shapeGroup !== void 0) continue;
275
+ if (glyph.shapeGroup !== void 0) continue;
237
276
  const x = glyph.originX + glyph.advance / 2;
238
277
  const y = glyph.lineBottom + glyph.fontSize / 2;
239
- let key = "";
278
+ let key = useMask ? 0 : "";
240
279
  for (let order = 0; order < painted.length; order++) {
241
280
  const { rect, z } = painted[order];
242
- if (z > glyph.z || x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue;
243
- key += `${order},`;
281
+ if (z > glyph.z) break;
282
+ if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue;
283
+ if (typeof key === "number") key |= 1 << order;
284
+ else key += `${order},`;
244
285
  }
245
286
  let stack = stacks.get(key);
246
287
  if (!stack) {
247
288
  let color = base;
248
289
  let framed = false;
249
290
  for (const { rect, color: paint, z } of painted) {
250
- if (z > glyph.z || x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue;
291
+ if (z > glyph.z) break;
292
+ if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue;
251
293
  if (paint[3] >= 1) framed = true;
252
294
  color = paint[3] >= 1 ? [
253
295
  paint[0],
@@ -264,7 +306,12 @@ function captureBackdrop(base, { glyphs, rects }) {
264
306
  }
265
307
  stack[2] += glyph.fontSize;
266
308
  half += glyph.fontSize / 2;
267
- stack[3] += glyph.fontSize * Math.min(Math.floor(4 * lightnessOf(glyph.color)), 3);
309
+ const gColor = glyph.color;
310
+ if (gColor !== prevColor) {
311
+ prevColor = gColor;
312
+ prevLift = Math.min(Math.floor(4 * lightnessOf(gColor)), 3);
313
+ }
314
+ stack[3] += glyph.fontSize * prevLift;
268
315
  }
269
316
  for (const stack of [...stacks.values()].sort((a, b) => (a[0] ?? 1) - (b[0] ?? 1))) if ((half -= stack[2]) <= 0) {
270
317
  let lift = 0;
@@ -280,7 +327,7 @@ function captureBackdrop(base, { glyphs, rects }) {
280
327
  ];
281
328
  }
282
329
  return [
283
- base ? lightnessOf(base) : void 0,
330
+ baseLightness,
284
331
  false,
285
332
  true
286
333
  ];
@@ -334,6 +381,6 @@ function resolveDomTextTone(root, option, capture) {
334
381
  table: 0
335
382
  } : tone;
336
383
  }
337
- export { C1, C2, C3, LUMINANCE, backdropCurve, resolveDomTextTone, resolveTextTone, srgbEncode, toneCoverage, toneLightness };
384
+ export { C1, C2, C3, LUMINANCE, backdropCurve, parseCssColor, resolveDomTextTone, resolveTextTone, srgbEncode, toneCoverage, toneLightness };
338
385
 
339
386
  //# sourceMappingURL=tone.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tone.js","names":[],"sources":["../../src/dom/tone.ts"],"sourcesContent":["import type { DomLayoutSnapshot, TextToneModel, TextToneOptions } from '../types.js'\n\n/** A tone with every default applied; see `TextToneOptions`. */\nexport interface ResolvedTextTone {\n /** `0` keeps the exact coverage of the model's outline, `1` is the browser's full conversion. */\n readonly strength: number\n /** sRGB-encoded lightness of the colour the text is read against, `0` to `1`. */\n readonly backdrop: number\n /**\n * Whether the rasterizer re-weights its mask by ink class: `1` for macOS and Windows over a\n * known backdrop. The table lifts light ink for the darker backdrop a browser then thins it\n * against, so over a backdrop nobody knows it is `0` and light ink keeps its exact coverage.\n */\n readonly table: 0 | 1\n /** Outline dilation in ems, in device pixels at most `dilationPx`; zero outside macOS. */\n readonly dilationEm: number\n readonly dilationPx: number\n /** Device pixels per em from which the dilation and the table stop; `0` when unused. */\n readonly bigPx: number\n /**\n * Whether the backdrop is certain to be drawn in the frame behind the text: the options\n * named it, or the capture draws an opaque rectangle there. Otherwise the conversion only\n * applies in a render whose frame has a backdrop of its own; see `TextTone.frame`.\n */\n readonly framed?: boolean\n}\n\n/** What a caller knows about the page when the options say `'auto'`. */\nexport interface TextToneContext {\n readonly model?: Exclude<TextToneModel, 'auto'> | undefined\n /** sRGB-encoded lightness of what the text is drawn over; absent while nobody knows it. */\n readonly backdrop?: number | undefined\n /** True where the caller's own opaque rectangles lie behind the text. */\n readonly framed?: boolean | undefined\n}\n\n/** What a capture knows about the backgrounds it will draw behind its own text. */\nexport interface TextToneCapture extends Pick<DomLayoutSnapshot, 'glyphs' | 'rects'> {\n /** Whether `rects` holds the root's own background, so the page must not add it again. */\n readonly rootRect: boolean\n /**\n * False for a root that only exists to be captured, as the hidden source of a `Text`: the\n * page behind it is not what the text is drawn over, so it is not read, and only an opaque\n * rectangle of the capture makes the backdrop known. Defaults to true.\n */\n readonly page?: boolean\n}\n\ntype Rgb = readonly [red: number, green: number, blue: number]\ntype Rgba = readonly [red: number, green: number, blue: number, alpha: number]\n\n// P(x) = x(x(C3 x + C2) + C1) approximates the sRGB decode on [0, 1], and P(1) = 1.\nexport const C1 = 0.012522878\nexport const C2 = 0.682171111\nexport const C3 = 0.305306011\nexport const LUMINANCE = [0.2126, 0.7152, 0.0722] as const\n\nconst NAMED_COLORS: Readonly<Record<string, number>> = {\n black: 0x000000,\n white: 0xffffff,\n red: 0xff0000,\n green: 0x008000,\n blue: 0x0000ff,\n gray: 0x808080,\n grey: 0x808080,\n silver: 0xc0c0c0,\n yellow: 0xffff00,\n cyan: 0x00ffff,\n aqua: 0x00ffff,\n magenta: 0xff00ff,\n fuchsia: 0xff00ff,\n orange: 0xffa500,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n navy: 0x000080,\n teal: 0x008080,\n maroon: 0x800000,\n olive: 0x808000,\n lime: 0x00ff00,\n}\n\nfunction srgbToLinear(c: number): number {\n return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4)\n}\n\n/** The exact sRGB transfer function, linear to encoded; written so that white encodes to 1. */\nexport function srgbEncode(linear: number): number {\n const value = Math.min(1, Math.max(0, linear))\n return value <= 0.0031308 ? value * 12.92 : 1 + 1.055 * (value ** (1 / 2.4) - 1)\n}\n\nconst lightnessRgb = (red: number, green: number, blue: number): number =>\n srgbEncode(\n LUMINANCE[0] * srgbToLinear(red) +\n LUMINANCE[1] * srgbToLinear(green) +\n LUMINANCE[2] * srgbToLinear(blue),\n )\nconst lightnessOf = (color: Rgb): number => lightnessRgb(color[0], color[1], color[2])\nconst lightnessHex = (hex: number): number => {\n const n = Math.floor(hex)\n return lightnessRgb(((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255)\n}\n\nconst hueToRgb = (p: number, q: number, t: number): number => {\n const u = t < 0 ? t + 1 : t > 1 ? t - 1 : t\n return u < 1 / 6 ? p + (q - p) * 6 * u : u < 1 / 2 ? q : u < 2 / 3 ? p + (q - p) * (4 - 6 * u) : p\n}\n\nconst splitFn = (re: RegExp, s: string) =>\n re\n .exec(s)?.[1]\n ?.split(/[\\s,/]+/)\n .filter(Boolean)\n\n/** Encoded lightness of a colour's linear luminance: what the tone compares ink and backdrop by. */\nexport function toneLightness(\n color: string | number | { readonly r: number; readonly g: number; readonly b: number },\n): number {\n if (typeof color === 'number') return lightnessHex(color)\n if (typeof color === 'object') {\n const { r, g, b } = color\n return srgbEncode(LUMINANCE[0] * r + LUMINANCE[1] * g + LUMINANCE[2] * b)\n }\n const s = color.trim().toLowerCase()\n const named = NAMED_COLORS[s]\n if (named !== undefined) return lightnessHex(named)\n if (s.startsWith('#')) {\n const n = s.length - 1\n const w = n === 3 || n === 4 ? 1 : n === 6 || n === 8 ? 2 : 0\n if (w) {\n const ch = (i: number): number =>\n parseInt(s.slice(1 + i * w, 1 + i * w + w).repeat(3 - w), 16) / 255\n return lightnessRgb(ch(0), ch(1), ch(2))\n }\n }\n const rgbMatch = splitFn(/^rgba?\\(([^)]+)\\)$/i, s)\n if (rgbMatch) {\n const ch = (i: number): number => {\n const c = rgbMatch[i]\n return c === undefined\n ? 0\n : Math.min(1, Math.max(0, parseFloat(c) / (c.endsWith('%') ? 100 : 255)))\n }\n return lightnessRgb(ch(0), ch(1), ch(2))\n }\n const hslMatch = splitFn(/^hsla?\\(([^)]+)\\)$/i, s)\n if (hslMatch) {\n const h = (((parseFloat(hslMatch[0] ?? '0') % 360) + 360) % 360) / 360\n const sat = Math.min(1, Math.max(0, parseFloat(hslMatch[1] ?? '0') / 100))\n const l = Math.min(1, Math.max(0, parseFloat(hslMatch[2] ?? '0') / 100))\n if (sat === 0) return lightnessRgb(l, l, l)\n const q = l <= 0.5 ? l * (1 + sat) : l + sat - l * sat\n const p = 2 * l - q\n return lightnessRgb(hueToRgb(p, q, h + 1 / 3), hueToRgb(p, q, h), hueToRgb(p, q, h - 1 / 3))\n }\n return 0\n}\n\n/**\n * Applies the defaults. `false` means no conversion at all; an already resolved tone passes\n * through. `'auto'` takes what the context knows about the page: without a model the exact\n * outline, and without a backdrop white with the ink table off, whatever the model. Dark ink\n * then gains the weight it has on a white page, and light ink is neither thinned nor lifted.\n * A backdrop is known when the options name a colour or the context read one. From\n * JavaScript, `true` is the default tone and any other value that is not an object throws.\n */\nexport function resolveTextTone(\n options: TextToneOptions | ResolvedTextTone | false | undefined,\n context?: TextToneContext,\n): ResolvedTextTone | null {\n if (options === false) return null\n if ((options as unknown) === true) options = undefined\n else if (options != null && typeof options !== 'object')\n throw new TypeError('ultra-text: tone must be an options object or false')\n if (options && 'table' in options) return options\n const requested = options?.model ?? 'auto'\n const model = requested === 'auto' ? (context?.model ?? 'outline') : requested\n const requestedBackdrop = options?.backdrop ?? 'auto'\n const backdrop =\n requestedBackdrop === 'auto' ? context?.backdrop : toneLightness(requestedBackdrop)\n const strength = options?.strength ?? 1\n const macos = model === 'macos'\n return {\n // A strength that is not a number keeps the default.\n strength: Math.min(\n 1,\n Math.max(0, typeof strength !== 'number' || Number.isNaN(strength) ? 1 : strength),\n ),\n backdrop: backdrop ?? 1,\n table: model === 'outline' || backdrop === undefined ? 0 : 1,\n dilationEm: macos ? 0.0058 : 0,\n dilationPx: macos ? 0.3 : 0,\n bigPx: macos ? 256 : 0,\n framed: requestedBackdrop !== 'auto' || context?.framed === true,\n }\n}\n\n/** P'(b) and P''(b) / 2: the polynomial of the conversion around a backdrop of lightness b. */\nexport function backdropCurve(backdrop: number): [k0: number, k1: number] {\n const k1 = C2 + 3 * C3 * backdrop\n return [C1 + backdrop * (C2 + k1), k1]\n}\n\n/**\n * The same conversion on plain numbers, for CPU callers and tests. `ink` is the encoded\n * lightness of the text colour, `coverage` the exact pixel coverage and `opacity` the ink's\n * own alpha; the result is the alpha the pixel is blended with.\n */\nexport function toneCoverage(\n tone: ResolvedTextTone,\n ink: number,\n coverage: number,\n opacity = 1,\n): number {\n const { strength, backdrop } = tone\n const [k0, k1] = backdropCurve(backdrop)\n const delta = ink - backdrop\n const table = (strength * tone.table * Math.min(Math.floor(4 * ink), 3)) / 3\n const mask = coverage + table * coverage * (1 - coverage)\n const y = delta * mask * opacity\n return Math.min(\n 1,\n opacity *\n mask *\n (1 - strength + (strength / (k0 + delta * (k1 + C3 * delta))) * (k0 + y * (k1 + C3 * y))),\n )\n}\n\n/** Source-over on sRGB-encoded values, which is how a browser composites. */\nfunction over(below: Rgb, [red, green, blue, alpha]: Rgba): Rgb {\n const opacity = Math.min(1, alpha)\n return [\n below[0] + (red - below[0]) * opacity,\n below[1] + (green - below[1]) * opacity,\n below[2] + (blue - below[2]) * opacity,\n ]\n}\n\n/**\n * sRGB-encoded channels per colour string, null where the string could not be read. Any\n * syntax other than `rgb()` costs a canvas readback, so each string is resolved once.\n */\nconst parsedColors = new Map<string, Rgba | null>()\nlet colorProbe: CanvasRenderingContext2D | null | undefined\n\nfunction parseColor(document: Document, value: string): Rgba | null {\n if (!value || value === 'transparent' || value === 'rgba(0, 0, 0, 0)') return null\n let rgba = parsedColors.get(value)\n if (rgba !== undefined) return rgba\n const channels = splitFn(/^rgba?\\(([^)]+)\\)$/i, value)\n if (channels) {\n const read = (index: number, max: number): number => {\n const channel = channels[index]\n return channel === undefined ? 1 : parseFloat(channel) / (channel.endsWith('%') ? 100 : max)\n }\n rgba = [read(0, 255), read(1, 255), read(2, 255), read(3, 1)]\n } else {\n rgba = null\n try {\n if (colorProbe === undefined) {\n const canvas = document.createElement('canvas')\n canvas.width = canvas.height = 1\n colorProbe = canvas.getContext('2d', { willReadFrequently: true }) ?? null\n }\n if (colorProbe) {\n colorProbe.fillStyle = '#0000'\n colorProbe.fillStyle = value\n colorProbe.clearRect(0, 0, 1, 1)\n colorProbe.fillRect(0, 0, 1, 1)\n const pixel = colorProbe.getImageData(0, 0, 1, 1).data\n rgba = [pixel[0]! / 255, pixel[1]! / 255, pixel[2]! / 255, pixel[3]! / 255]\n }\n } catch {\n colorProbe = null\n }\n }\n if (parsedColors.size >= 256) parsedColors.clear()\n parsedColors.set(value, rgba)\n return rgba\n}\n\nconst prop = (s: CSSStyleDeclaration, k: string): string => s.getPropertyValue(k).trim()\n\nfunction domBackdrop(root: Element, above: boolean): readonly [Rgb, boolean] | null {\n const layers: Rgba[] = []\n let known = false\n let image = false\n try {\n const document = root.ownerDocument\n const view = document.defaultView\n if (!view) return null\n const parent = (element: Element): Element | null =>\n element.assignedSlot ??\n element.parentElement ??\n (element.getRootNode() as Partial<ShadowRoot>).host ??\n null\n for (let element: Element | null = root; element; element = parent(element)) {\n const style = view.getComputedStyle(element)\n if (\n prop(style, 'display') === 'contents' ||\n (element !== document.documentElement &&\n element !== document.body &&\n (/hidden|collapse/.test(prop(style, 'visibility')) ||\n (prop(style, 'background-clip') + prop(style, '-webkit-background-clip')).includes(\n 'text',\n )))\n )\n continue\n image ||= !/^(none)?$/.test(prop(style, 'background-image'))\n if (above && element === root) continue\n const layer = parseColor(document, style.backgroundColor)\n if (!layer || !(layer[3] > 0)) continue\n layers.push(layer)\n if (layer[3] >= 1) {\n known = !image\n break\n }\n }\n } catch {\n return null\n }\n return [layers.reduceRight<Rgb>(over, [1, 1, 1]), known]\n}\n\nfunction captureBackdrop(\n base: Rgb | null,\n { glyphs, rects }: TextToneCapture,\n): readonly [number | undefined, boolean, boolean] {\n const samples = Math.min(glyphs.length, 512)\n const painted = rects.length > 1 ? [...rects].sort((first, second) => first.z - second.z) : rects\n const stacks = new Map<string, [number | undefined, boolean, number, number]>()\n let half = 0\n for (let sample = 0; sample < samples; sample++) {\n const glyph = glyphs[Math.floor((sample * glyphs.length) / samples)]!\n if (!rects.length || glyph.shapeGroup !== undefined) continue\n const x = glyph.originX + glyph.advance / 2\n const y = glyph.lineBottom + glyph.fontSize / 2\n let key = ''\n for (let order = 0; order < painted.length; order++) {\n const { rect, z } = painted[order]!\n if (z > glyph.z || x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue\n key += `${order},`\n }\n let stack = stacks.get(key)\n if (!stack) {\n let color = base\n let framed = false\n for (const { rect, color: paint, z } of painted) {\n if (z > glyph.z || x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue\n if (paint[3] >= 1) framed = true\n color = paint[3] >= 1 ? [paint[0], paint[1], paint[2]] : color && over(color, paint)\n }\n stacks.set(key, (stack = [color ? lightnessOf(color) : undefined, framed, 0, 0]))\n }\n stack[2] += glyph.fontSize\n half += glyph.fontSize / 2\n stack[3] +=\n glyph.fontSize * Math.min(Math.floor(4 * lightnessOf(glyph.color as unknown as Rgb)), 3)\n }\n for (const stack of [...stacks.values()].sort((a, b) => (a[0] ?? 1) - (b[0] ?? 1)))\n if ((half -= stack[2]) <= 0) {\n let lift = 0\n let here = 0\n for (const other of stacks.values()) {\n lift += other[3]\n if (Math.abs((other[0] ?? 1) - (stack[0] ?? 1)) <= 0.25) here += other[3]\n }\n return [stack[0], stack[1], here * 2 >= lift]\n }\n return [base ? lightnessOf(base) : undefined, false, true]\n}\n\nfunction domModel(root: Element): Exclude<TextToneModel, 'auto'> {\n try {\n const view = root.ownerDocument.defaultView\n if (!view) return 'outline'\n const navigator = view.navigator as {\n readonly platform?: string\n readonly maxTouchPoints?: number\n readonly userAgentData?: { readonly platform?: string }\n }\n const brand = navigator.userAgentData?.platform\n const platform = navigator.platform ?? ''\n if (platform ? platform.startsWith('Win') : brand === 'Windows') return 'windows'\n if (\n platform\n ? !(\n platform.startsWith('Mac') &&\n (brand === 'macOS' || (navigator.maxTouchPoints ?? 0) <= 1)\n )\n : brand !== 'macOS'\n )\n return 'outline'\n const style = view.getComputedStyle(root)\n return /^(antialiased|none)$/i.test(prop(style, '-webkit-font-smoothing')) ||\n /^grayscale$/i.test(prop(style, '-moz-osx-font-smoothing')) ||\n /^geometricprecision$/i.test(prop(style, 'text-rendering'))\n ? 'outline'\n : 'macos'\n } catch {\n return 'outline'\n }\n}\n\n/**\n * Resolves a `tone` option against the page that holds `root`: `'auto'` values come from the\n * platform, the root's computed CSS and the backgrounds behind the text, which are the\n * rectangles of `capture` over the page, or the page alone without one. A backdrop that\n * cannot be read stays unknown, which `resolveTextTone` shows as white with the ink table\n * off: a page without computed styles, one whose backgrounds hold no opaque colour or put an\n * image in front of it, or a capture that is not drawn over its page and has no opaque\n * rectangle behind its text. The exact outline has no table, so it takes the colour the page\n * most likely shows. Reads computed styles, so it belongs to a capture, never to the render\n * loop; an explicit model and backdrop read nothing, and `false` resolves to null.\n */\nexport function resolveDomTextTone(\n root: Element,\n option: TextToneOptions | false | undefined,\n capture?: TextToneCapture,\n): ResolvedTextTone | null {\n if (option === false) return null\n const auto = (value: unknown): boolean => (value ?? 'auto') === 'auto'\n const model = auto(option?.model) ? domModel(root) : undefined\n let backdrop: number | undefined\n let framed = false\n let table = true\n if (auto(option?.backdrop)) {\n const read = capture?.page === false ? null : domBackdrop(root, !!capture?.rootRect)\n const page = read && (read[1] || (model ?? option?.model) === 'outline') ? read[0] : null\n if (capture) [backdrop, framed, table] = captureBackdrop(page, capture)\n else backdrop = page ? lightnessOf(page) : undefined\n }\n const tone = resolveTextTone(option, { model, backdrop, framed })\n return tone && !table ? { ...tone, table: 0 } : tone\n}\n"],"mappings":";AAoDA,IAAa,KAAK;AAClB,IAAa,KAAK;AAClB,IAAa,KAAK;AAClB,IAAa,YAAY;CAAC;CAAQ;CAAQ;AAAM;AAEhD,IAAM,eAAiD;CACrD,OAAO;CACP,OAAO;CACP,KAAK;CACL,OAAO;CACP,MAAM;CACN,MAAM;CACN,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,eAAe;CACf,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;CACP,MAAM;AACR;AAEA,SAAS,aAAa,GAAmB;CACvC,OAAO,IAAI,SAAU,IAAI,cAAe,KAAK,IAAI,IAAI,cAAe,aAAc,GAAG;AACvF;;AAGA,SAAgB,WAAW,QAAwB;CACjD,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC;CAC7C,OAAO,SAAS,WAAY,QAAQ,QAAQ,IAAI,SAAS,UAAU,IAAI,OAAO;AAChF;AAEA,IAAM,gBAAgB,KAAa,OAAe,SAChD,WACE,UAAU,KAAK,aAAa,GAAG,IAC7B,UAAU,KAAK,aAAa,KAAK,IACjC,UAAU,KAAK,aAAa,IAAI,CACpC;AACF,IAAM,eAAe,UAAuB,aAAa,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE;AACrF,IAAM,gBAAgB,QAAwB;CAC5C,MAAM,IAAI,KAAK,MAAM,GAAG;CACxB,OAAO,cAAe,KAAK,KAAM,OAAO,MAAO,KAAK,IAAK,OAAO,MAAM,IAAI,OAAO,GAAG;AACtF;AAE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,KAAK,KAAK;EACrF,IAAI,SAAS,CAAC,UAAU,QAAQ,SAAS,gBAAgB,MAAM,OAAO;OACjE,WAAW,OAAO,YAAY,IAAI,IAAI,KAAA;CAC7C;CACA,MAAM,OAAO,gBAAgB,QAAQ;EAAE;EAAO;EAAU;CAAO,CAAC;CAChE,OAAO,QAAQ,CAAC,QAAQ;EAAE,GAAG;EAAM,OAAO;CAAE,IAAI;AAClD"}
1
+ {"version":3,"file":"tone.js","names":[],"sources":["../../src/dom/tone.ts"],"sourcesContent":["import type { DomLayoutSnapshot, TextToneModel, TextToneOptions } from '../types.js'\n\n/** A tone with every default applied; see `TextToneOptions`. */\nexport interface ResolvedTextTone {\n /** `0` keeps the exact coverage of the model's outline, `1` is the browser's full conversion. */\n readonly strength: number\n /** sRGB-encoded lightness of the colour the text is read against, `0` to `1`. */\n readonly backdrop: number\n /**\n * Whether the rasterizer re-weights its mask by ink class: `1` for macOS and Windows over a\n * known backdrop. The table lifts light ink for the darker backdrop a browser then thins it\n * against, so over a backdrop nobody knows it is `0` and light ink keeps its exact coverage.\n */\n readonly table: 0 | 1\n /** Outline dilation in ems, in device pixels at most `dilationPx`; zero outside macOS. */\n readonly dilationEm: number\n readonly dilationPx: number\n /** Device pixels per em from which the dilation and the table stop; `0` when unused. */\n readonly bigPx: number\n /**\n * Whether the backdrop is certain to be drawn in the frame behind the text: the options\n * named it, or the capture draws an opaque rectangle there. Otherwise the conversion only\n * applies in a render whose frame has a backdrop of its own; see `TextTone.frame`.\n */\n readonly framed?: boolean\n}\n\n/** What a caller knows about the page when the options say `'auto'`. */\nexport interface TextToneContext {\n readonly model?: Exclude<TextToneModel, 'auto'> | undefined\n /** sRGB-encoded lightness of what the text is drawn over; absent while nobody knows it. */\n readonly backdrop?: number | undefined\n /** True where the caller's own opaque rectangles lie behind the text. */\n readonly framed?: boolean | undefined\n}\n\n/** What a capture knows about the backgrounds it will draw behind its own text. */\nexport interface TextToneCapture extends Pick<DomLayoutSnapshot, 'glyphs' | 'rects'> {\n /** Whether `rects` holds the root's own background, so the page must not add it again. */\n readonly rootRect: boolean\n /**\n * False for a root that only exists to be captured, as the hidden source of a `Text`: the\n * page behind it is not what the text is drawn over, so it is not read, and only an opaque\n * rectangle of the capture makes the backdrop known. Defaults to true.\n */\n readonly page?: boolean\n}\n\ntype Rgb = readonly [red: number, green: number, blue: number]\ntype Rgba = readonly [red: number, green: number, blue: number, alpha: number]\n\n// P(x) = x(x(C3 x + C2) + C1) approximates the sRGB decode on [0, 1], and P(1) = 1.\nexport const C1 = 0.012522878\nexport const C2 = 0.682171111\nexport const C3 = 0.305306011\nexport const LUMINANCE = [0.2126, 0.7152, 0.0722] as const\n\nconst NAMED_COLORS: Readonly<Record<string, number>> = {\n black: 0x000000,\n white: 0xffffff,\n red: 0xff0000,\n green: 0x008000,\n blue: 0x0000ff,\n gray: 0x808080,\n grey: 0x808080,\n silver: 0xc0c0c0,\n yellow: 0xffff00,\n cyan: 0x00ffff,\n aqua: 0x00ffff,\n magenta: 0xff00ff,\n fuchsia: 0xff00ff,\n orange: 0xffa500,\n purple: 0x800080,\n rebeccapurple: 0x663399,\n navy: 0x000080,\n teal: 0x008080,\n maroon: 0x800000,\n olive: 0x808000,\n lime: 0x00ff00,\n}\n\nfunction srgbToLinear(c: number): number {\n return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4)\n}\n\n/** The exact sRGB transfer function, linear to encoded; written so that white encodes to 1. */\nexport function srgbEncode(linear: number): number {\n const value = Math.min(1, Math.max(0, linear))\n return value <= 0.0031308 ? value * 12.92 : 1 + 1.055 * (value ** (1 / 2.4) - 1)\n}\n\nconst lightnessRgb = (red: number, green: number, blue: number): number =>\n srgbEncode(\n LUMINANCE[0] * srgbToLinear(red) +\n LUMINANCE[1] * srgbToLinear(green) +\n LUMINANCE[2] * srgbToLinear(blue),\n )\nconst lightnessOf = (color: Rgb): number => lightnessRgb(color[0], color[1], color[2])\nconst lightnessHex = (hex: number): number => {\n const n = Math.floor(hex)\n return lightnessRgb(((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255)\n}\n\nconst hueToRgb = (p: number, q: number, t: number): number => {\n const u = t < 0 ? t + 1 : t > 1 ? t - 1 : t\n return u < 1 / 6 ? p + (q - p) * 6 * u : u < 1 / 2 ? q : u < 2 / 3 ? p + (q - p) * (4 - 6 * u) : p\n}\n\nconst splitFn = (re: RegExp, s: string) =>\n re\n .exec(s)?.[1]\n ?.split(/[\\s,/]+/)\n .filter(Boolean)\n\n/** Encoded lightness of a colour's linear luminance: what the tone compares ink and backdrop by. */\nexport function toneLightness(\n color: string | number | { readonly r: number; readonly g: number; readonly b: number },\n): number {\n if (typeof color === 'number') return lightnessHex(color)\n if (typeof color === 'object') {\n const { r, g, b } = color\n return srgbEncode(LUMINANCE[0] * r + LUMINANCE[1] * g + LUMINANCE[2] * b)\n }\n const s = color.trim().toLowerCase()\n const named = NAMED_COLORS[s]\n if (named !== undefined) return lightnessHex(named)\n if (s.startsWith('#')) {\n const n = s.length - 1\n const w = n === 3 || n === 4 ? 1 : n === 6 || n === 8 ? 2 : 0\n if (w) {\n const ch = (i: number): number =>\n parseInt(s.slice(1 + i * w, 1 + i * w + w).repeat(3 - w), 16) / 255\n return lightnessRgb(ch(0), ch(1), ch(2))\n }\n }\n const rgbMatch = splitFn(/^rgba?\\(([^)]+)\\)$/i, s)\n if (rgbMatch) {\n const ch = (i: number): number => {\n const c = rgbMatch[i]\n return c === undefined\n ? 0\n : Math.min(1, Math.max(0, parseFloat(c) / (c.endsWith('%') ? 100 : 255)))\n }\n return lightnessRgb(ch(0), ch(1), ch(2))\n }\n const hslMatch = splitFn(/^hsla?\\(([^)]+)\\)$/i, s)\n if (hslMatch) {\n const h = (((parseFloat(hslMatch[0] ?? '0') % 360) + 360) % 360) / 360\n const sat = Math.min(1, Math.max(0, parseFloat(hslMatch[1] ?? '0') / 100))\n const l = Math.min(1, Math.max(0, parseFloat(hslMatch[2] ?? '0') / 100))\n if (sat === 0) return lightnessRgb(l, l, l)\n const q = l <= 0.5 ? l * (1 + sat) : l + sat - l * sat\n const p = 2 * l - q\n return lightnessRgb(hueToRgb(p, q, h + 1 / 3), hueToRgb(p, q, h), hueToRgb(p, q, h - 1 / 3))\n }\n return 0\n}\n\n/**\n * Applies the defaults. `false` means no conversion at all; an already resolved tone passes\n * through. `'auto'` takes what the context knows about the page: without a model the exact\n * outline, and without a backdrop white with the ink table off, whatever the model. Dark ink\n * then gains the weight it has on a white page, and light ink is neither thinned nor lifted.\n * A backdrop is known when the options name a colour or the context read one. From\n * JavaScript, `true` is the default tone and any other value that is not an object throws.\n */\nexport function resolveTextTone(\n options: TextToneOptions | ResolvedTextTone | false | undefined,\n context?: TextToneContext,\n): ResolvedTextTone | null {\n if (options === false) return null\n if ((options as unknown) === true) options = undefined\n else if (options != null && typeof options !== 'object')\n throw new TypeError('ultra-text: tone must be an options object or false')\n if (options && 'table' in options) return options\n const requested = options?.model ?? 'auto'\n const model = requested === 'auto' ? (context?.model ?? 'outline') : requested\n const requestedBackdrop = options?.backdrop ?? 'auto'\n const backdrop =\n requestedBackdrop === 'auto' ? context?.backdrop : toneLightness(requestedBackdrop)\n const strength = options?.strength ?? 1\n const macos = model === 'macos'\n return {\n // A strength that is not a number keeps the default.\n strength: Math.min(\n 1,\n Math.max(0, typeof strength !== 'number' || Number.isNaN(strength) ? 1 : strength),\n ),\n backdrop: backdrop ?? 1,\n table: model === 'outline' || backdrop === undefined ? 0 : 1,\n dilationEm: macos ? 0.0058 : 0,\n dilationPx: macos ? 0.3 : 0,\n bigPx: macos ? 256 : 0,\n framed: requestedBackdrop !== 'auto' || context?.framed === true,\n }\n}\n\n/** P'(b) and P''(b) / 2: the polynomial of the conversion around a backdrop of lightness b. */\nexport function backdropCurve(backdrop: number): [k0: number, k1: number] {\n const k1 = C2 + 3 * C3 * backdrop\n return [C1 + backdrop * (C2 + k1), k1]\n}\n\n/**\n * The same conversion on plain numbers, for CPU callers and tests. `ink` is the encoded\n * lightness of the text colour, `coverage` the exact pixel coverage and `opacity` the ink's\n * own alpha; the result is the alpha the pixel is blended with.\n */\nexport function toneCoverage(\n tone: ResolvedTextTone,\n ink: number,\n coverage: number,\n opacity = 1,\n): number {\n const { strength, backdrop } = tone\n const [k0, k1] = backdropCurve(backdrop)\n const delta = ink - backdrop\n const table = (strength * tone.table * Math.min(Math.floor(4 * ink), 3)) / 3\n const mask = coverage + table * coverage * (1 - coverage)\n const y = delta * mask * opacity\n return Math.min(\n 1,\n opacity *\n mask *\n (1 - strength + (strength / (k0 + delta * (k1 + C3 * delta))) * (k0 + y * (k1 + C3 * y))),\n )\n}\n\n/** Source-over on sRGB-encoded values, which is how a browser composites. */\nfunction over(below: Rgb, [red, green, blue, alpha]: Rgba): Rgb {\n const opacity = Math.min(1, alpha)\n return [\n below[0] + (red - below[0]) * opacity,\n below[1] + (green - below[1]) * opacity,\n below[2] + (blue - below[2]) * opacity,\n ]\n}\n\n/**\n * sRGB-encoded channels per colour string, null where the string could not be read. Any\n * syntax other than `rgb()` costs a canvas readback, so each string is resolved once.\n */\nconst parsedColors = new Map<string, [number, number, number, number]>()\nlet colorProbe: CanvasRenderingContext2D | null | undefined\n\n/**\n * Resolve a CSS colour to sRGB-encoded `[r, g, b, a]` channels, or `null` for transparent /\n * unavailable probe. When `required` is true, failure to obtain a 2D probe throws instead of\n * returning `null`.\n * @internal\n */\nexport function parseCssColor(\n document: Document,\n value: string,\n required = false,\n): [number, number, number, number] | null {\n if (!value || value === 'transparent' || value === 'rgba(0, 0, 0, 0)') return null\n let rgba = parsedColors.get(value)\n if (rgba) return rgba\n const channels = splitFn(/^\\s*rgba?\\(([^)]+)\\)\\s*$/i, value)\n if (channels) {\n const read = (index: number, max: number): number => {\n const channel = channels[index]\n return channel === undefined\n ? max === 1\n ? 1\n : 0\n : parseFloat(channel) / (channel.includes('%') ? 100 : max)\n }\n rgba = [read(0, 255), read(1, 255), read(2, 255), read(3, 1)]\n } else {\n try {\n if (colorProbe === undefined || (required && !colorProbe)) {\n const canvas = document.createElement('canvas')\n canvas.width = canvas.height = 1\n colorProbe = canvas.getContext('2d', { willReadFrequently: true }) ?? null\n }\n if (!colorProbe) {\n if (required) throw new Error('collectDomSnapshot: Canvas 2D is unavailable')\n return null\n }\n colorProbe.fillStyle = '#0000'\n colorProbe.fillStyle = value\n colorProbe.clearRect(0, 0, 1, 1)\n colorProbe.fillRect(0, 0, 1, 1)\n const pixel = colorProbe.getImageData(0, 0, 1, 1).data\n rgba = [pixel[0]! / 255, pixel[1]! / 255, pixel[2]! / 255, pixel[3]! / 255]\n } catch (error) {\n colorProbe = null\n if (required) throw error\n return null\n }\n }\n if (parsedColors.size >= 1024) parsedColors.clear()\n parsedColors.set(value, rgba)\n return rgba\n}\n\nconst prop = (s: CSSStyleDeclaration, k: string): string => s.getPropertyValue(k).trim()\n\nfunction domBackdrop(root: Element, above: boolean): readonly [Rgb, boolean] | null {\n let layer0: Rgba | undefined\n let layers: Rgba[] | undefined\n let known = false\n let image = false\n try {\n const document = root.ownerDocument\n const view = document.defaultView\n if (!view) return null\n const rootDocEl = document.documentElement\n const bodyEl = document.body\n for (\n let element: Element | null = root;\n element;\n element =\n element.assignedSlot ??\n element.parentElement ??\n (element.getRootNode() as Partial<ShadowRoot>).host ??\n null\n ) {\n const style = view.getComputedStyle(element)\n if (prop(style, 'display') === 'contents') continue\n if (\n element !== rootDocEl &&\n element !== bodyEl &&\n (/hidden|collapse/.test(prop(style, 'visibility')) ||\n style.getPropertyValue('background-clip').includes('text') ||\n style.getPropertyValue('-webkit-background-clip').includes('text'))\n ) {\n continue\n }\n const bgImg = prop(style, 'background-image')\n if (bgImg && bgImg !== 'none') image = true\n if (above && element === root) continue\n const layer = parseCssColor(document, style.backgroundColor)\n if (!layer || !(layer[3] > 0)) continue\n if (layer0 === undefined) layer0 = layer\n else {\n layers ??= [layer0]\n layers.push(layer)\n }\n if (layer[3] >= 1) {\n known = !image\n break\n }\n }\n } catch {\n return null\n }\n if (layer0 === undefined) return [[1, 1, 1], known]\n if (!layers) return [over([1, 1, 1], layer0), known]\n return [layers.reduceRight<Rgb>(over, [1, 1, 1]), known]\n}\n\nfunction captureBackdrop(\n base: Rgb | null,\n { glyphs, rects }: TextToneCapture,\n): readonly [number | undefined, boolean, boolean] {\n const baseLightness = base ? lightnessOf(base) : undefined\n if (!rects.length || !glyphs.length) return [baseLightness, false, true]\n let sorted = true\n for (let i = 1; i < rects.length; i++) {\n if (rects[i]!.z < rects[i - 1]!.z) {\n sorted = false\n break\n }\n }\n const painted = sorted ? rects : [...rects].sort((first, second) => first.z - second.z)\n const samples = Math.min(glyphs.length, 512)\n // A paint stack fits in one bit mask for up to 32 rectangles, including the sign bit.\n const useMask = painted.length <= 32\n const stacks = new Map<number | string, [number | undefined, boolean, number, number]>()\n let half = 0\n let prevColor: readonly [number, number, number, number] | undefined\n let prevLift = 0\n for (let sample = 0; sample < samples; sample++) {\n const glyph = glyphs[Math.floor((sample * glyphs.length) / samples)]!\n if (glyph.shapeGroup !== undefined) continue\n const x = glyph.originX + glyph.advance / 2\n const y = glyph.lineBottom + glyph.fontSize / 2\n let key: number | string = useMask ? 0 : ''\n for (let order = 0; order < painted.length; order++) {\n const { rect, z } = painted[order]!\n if (z > glyph.z) break\n if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue\n if (typeof key === 'number') key |= 1 << order\n else key += `${order},`\n }\n let stack = stacks.get(key)\n if (!stack) {\n let color = base\n let framed = false\n for (const { rect, color: paint, z } of painted) {\n if (z > glyph.z) break\n if (x < rect[0] || x > rect[2] || y < rect[1] || y > rect[3]) continue\n if (paint[3] >= 1) framed = true\n color = paint[3] >= 1 ? [paint[0], paint[1], paint[2]] : color && over(color, paint)\n }\n stacks.set(key, (stack = [color ? lightnessOf(color) : undefined, framed, 0, 0]))\n }\n stack[2] += glyph.fontSize\n half += glyph.fontSize / 2\n const gColor = glyph.color\n if (gColor !== prevColor) {\n prevColor = gColor\n prevLift = Math.min(Math.floor(4 * lightnessOf(gColor as unknown as Rgb)), 3)\n }\n stack[3] += glyph.fontSize * prevLift\n }\n for (const stack of [...stacks.values()].sort((a, b) => (a[0] ?? 1) - (b[0] ?? 1)))\n if ((half -= stack[2]) <= 0) {\n let lift = 0\n let here = 0\n for (const other of stacks.values()) {\n lift += other[3]\n if (Math.abs((other[0] ?? 1) - (stack[0] ?? 1)) <= 0.25) here += other[3]\n }\n return [stack[0], stack[1], here * 2 >= lift]\n }\n return [baseLightness, false, true]\n}\n\nfunction domModel(root: Element): Exclude<TextToneModel, 'auto'> {\n try {\n const view = root.ownerDocument.defaultView\n if (!view) return 'outline'\n const navigator = view.navigator as {\n readonly platform?: string\n readonly maxTouchPoints?: number\n readonly userAgentData?: { readonly platform?: string }\n }\n const brand = navigator.userAgentData?.platform\n const platform = navigator.platform ?? ''\n if (platform ? platform.startsWith('Win') : brand === 'Windows') return 'windows'\n if (\n platform\n ? !(\n platform.startsWith('Mac') &&\n (brand === 'macOS' || (navigator.maxTouchPoints ?? 0) <= 1)\n )\n : brand !== 'macOS'\n )\n return 'outline'\n const style = view.getComputedStyle(root)\n return /^(antialiased|none)$/i.test(prop(style, '-webkit-font-smoothing')) ||\n /^grayscale$/i.test(prop(style, '-moz-osx-font-smoothing')) ||\n /^geometricprecision$/i.test(prop(style, 'text-rendering'))\n ? 'outline'\n : 'macos'\n } catch {\n return 'outline'\n }\n}\n\n/**\n * Resolves a `tone` option against the page that holds `root`: `'auto'` values come from the\n * platform, the root's computed CSS and the backgrounds behind the text, which are the\n * rectangles of `capture` over the page, or the page alone without one. A backdrop that\n * cannot be read stays unknown, which `resolveTextTone` shows as white with the ink table\n * off: a page without computed styles, one whose backgrounds hold no opaque colour or put an\n * image in front of it, or a capture that is not drawn over its page and has no opaque\n * rectangle behind its text. The exact outline has no table, so it takes the colour the page\n * most likely shows. Reads computed styles, so it belongs to a capture, never to the render\n * loop; an explicit model and backdrop read nothing, and `false` resolves to null.\n */\nexport function resolveDomTextTone(\n root: Element,\n option: TextToneOptions | false | undefined,\n capture?: TextToneCapture,\n): ResolvedTextTone | null {\n if (option === false) return null\n const auto = (value: unknown): boolean => (value ?? 'auto') === 'auto'\n const model = auto(option?.model) ? domModel(root) : undefined\n let backdrop: number | undefined\n let framed = false\n let table = true\n if (auto(option?.backdrop)) {\n const read = capture?.page === false ? null : domBackdrop(root, !!capture?.rootRect)\n const page = read && (read[1] || (model ?? option?.model) === 'outline') ? read[0] : null\n if (capture) [backdrop, framed, table] = captureBackdrop(page, capture)\n else backdrop = page ? lightnessOf(page) : undefined\n }\n const tone = resolveTextTone(option, { model, backdrop, framed })\n return tone && !table ? { ...tone, table: 0 } : tone\n}\n"],"mappings":";AAoDA,IAAa,KAAK;AAClB,IAAa,KAAK;AAClB,IAAa,KAAK;AAClB,IAAa,YAAY;CAAC;CAAQ;CAAQ;AAAM;AAEhD,IAAM,eAAiD;CACrD,OAAO;CACP,OAAO;CACP,KAAK;CACL,OAAO;CACP,MAAM;CACN,MAAM;CACN,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,MAAM;CACN,SAAS;CACT,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,eAAe;CACf,MAAM;CACN,MAAM;CACN,QAAQ;CACR,OAAO;CACP,MAAM;AACR;AAEA,SAAS,aAAa,GAAmB;CACvC,OAAO,IAAI,SAAU,IAAI,cAAe,KAAK,IAAI,IAAI,cAAe,aAAc,GAAG;AACvF;;AAGA,SAAgB,WAAW,QAAwB;CACjD,MAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,MAAM,CAAC;CAC7C,OAAO,SAAS,WAAY,QAAQ,QAAQ,IAAI,SAAS,UAAU,IAAI,OAAO;AAChF;AAEA,IAAM,gBAAgB,KAAa,OAAe,SAChD,WACE,UAAU,KAAK,aAAa,GAAG,IAC7B,UAAU,KAAK,aAAa,KAAK,IACjC,UAAU,KAAK,aAAa,IAAI,CACpC;AACF,IAAM,eAAe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;EAAU;CAAO,CAAC;CAChE,OAAO,QAAQ,CAAC,QAAQ;EAAE,GAAG;EAAM,OAAO;CAAE,IAAI;AAClD"}
package/dist/index.js CHANGED
@@ -1,12 +1,13 @@
1
1
  import { buildSdfAtlas } from "./atlas/buildAtlas.js";
2
2
  import { rasterizeGlyphAtlas } from "./atlas/rasterize.js";
3
- import { createRectMaterial } from "./text/RectMaterial.js";
4
3
  import { SdfTextMaterial } from "./text/SdfTextMaterial.js";
5
- import { createGlyphGeometry, createRectGeometry } from "./text/geometry.js";
6
- import { reflowSnapshot } from "./text/reflow.js";
4
+ import { createGlyphGeometry } from "./text/glyphGeometry.js";
7
5
  import { collectDomSnapshot } from "./dom/snapshot.js";
8
6
  import { DomSdf } from "./dom/DomSdf.js";
9
7
  import { Text } from "./dom/Text.js";
8
+ import { createRectMaterial } from "./text/RectMaterial.js";
9
+ import { createRectGeometry } from "./text/rectGeometry.js";
10
+ import { reflowSnapshot } from "./text/reflow.js";
10
11
  import { windfoilOutlineFromSvgPaths } from "./windfoil/svg/pathConverter.js";
11
12
  import { svgToWindfoilOutlines } from "./windfoil/svg/convert.js";
12
13
  import { createSvgEmojiOutlineProvider } from "./windfoil/emoji.js";
@@ -1,10 +1,24 @@
1
- import { type UniformNode } from 'three/webgpu';
1
+ import { Node, type NodeBuilder, type UniformNode } from 'three/webgpu';
2
2
  import { GlyphTextMaterial } from '../text/GlyphTextMaterial.js';
3
- import type { WindfoilMaterialOptions } from '../windfoil/WindfoilMaterial.js';
4
- export type SlugMaterialOptions = WindfoilMaterialOptions;
3
+ import type { SlugStorage } from '../windfoil/storage.js';
4
+ import type { WindfoilMaterialOptions, WindfoilStorage } from '../windfoil/WindfoilMaterial.js';
5
+ export interface SlugMaterialOptions extends Omit<WindfoilMaterialOptions, 'curves'>, Pick<SlugStorage | WindfoilStorage, 'curves' | 'rows'> {
6
+ }
5
7
  /** Analytic, atlas-free quadratic-outline text using the dual-ray Slug coverage evaluator. */
6
8
  export declare class SlugMaterial extends GlyphTextMaterial {
7
9
  #private;
8
10
  get shadowCutoff(): UniformNode<'float', number>;
11
+ /**
12
+ * Keeps alpha-blended beauty draws discard-free on TBDR GPUs (`insideClip` gates coverage to 0),
13
+ * while opaque cutout (`transparent: false`), depth-writing, wireframe, and shadow draws still
14
+ * keep `maskNode` early discard.
15
+ */
16
+ setupDiffuseColor(builder: NodeBuilder): void;
17
+ /**
18
+ * Reuses `clip0 + colX * offset.x + colY * offset.y` from the skirt pass so
19
+ * Three skips the extra `modelViewMatrix * positionLocal` and projection matrix
20
+ * multiply when no custom `vertex`, `keepGlyph`, fog, or shadow pass overrides it.
21
+ */
22
+ setupVertex(builder: NodeBuilder): Node;
9
23
  constructor(options: SlugMaterialOptions);
10
24
  }