@alfadocs/ui-kit-debug 0.57.0 → 0.59.0

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 (151) hide show
  1. package/dist/_chunks/{bishop-score-CMQxsdy4.js → bishop-score-B9tvgoIq.js} +2 -2
  2. package/dist/_chunks/{bishop-score-CMQxsdy4.js.map → bishop-score-B9tvgoIq.js.map} +1 -1
  3. package/dist/_chunks/{bmi-calculator-DuUneHuZ.js → bmi-calculator-DA2NGmVK.js} +2 -2
  4. package/dist/_chunks/{bmi-calculator-DuUneHuZ.js.map → bmi-calculator-DA2NGmVK.js.map} +1 -1
  5. package/dist/_chunks/{calendar-oYWOCrnf.js → calendar-CkuJIg3s.js} +1 -1
  6. package/dist/_chunks/{calendar-oYWOCrnf.js.map → calendar-CkuJIg3s.js.map} +1 -1
  7. package/dist/_chunks/{cycle-calculator-vTtZZAmn.js → cycle-calculator-C_t1Hs8V.js} +2 -2
  8. package/dist/_chunks/{cycle-calculator-vTtZZAmn.js.map → cycle-calculator-C_t1Hs8V.js.map} +1 -1
  9. package/dist/_chunks/date-picker-variants-CXEAx3O_.js.map +1 -1
  10. package/dist/_chunks/{due-date-calculator-CUm5KJbf.js → due-date-calculator-Q8MIwEVV.js} +2 -2
  11. package/dist/_chunks/{due-date-calculator-CUm5KJbf.js.map → due-date-calculator-Q8MIwEVV.js.map} +1 -1
  12. package/dist/_chunks/{fetal-weight-Xf8-ZoDy.js → fetal-weight-D1a6BmM-.js} +2 -2
  13. package/dist/_chunks/{fetal-weight-Xf8-ZoDy.js.map → fetal-weight-D1a6BmM-.js.map} +1 -1
  14. package/dist/_chunks/{gestational-age-calculator-830KJql3.js → gestational-age-calculator-AkNFfZYs.js} +2 -2
  15. package/dist/_chunks/{gestational-age-calculator-830KJql3.js.map → gestational-age-calculator-AkNFfZYs.js.map} +1 -1
  16. package/dist/_chunks/{hcg-doubling-kVOpDfny.js → hcg-doubling-Dg0Hr7ey.js} +2 -2
  17. package/dist/_chunks/{hcg-doubling-kVOpDfny.js.map → hcg-doubling-Dg0Hr7ey.js.map} +1 -1
  18. package/dist/_chunks/{insert-result-njqBthzT.js → insert-result-C1SYdueh.js} +125 -115
  19. package/dist/_chunks/insert-result-C1SYdueh.js.map +1 -0
  20. package/dist/_chunks/{pregnancy-dating-BA37LSkF.js → pregnancy-dating-Dg6dTe1p.js} +2 -2
  21. package/dist/_chunks/{pregnancy-dating-BA37LSkF.js.map → pregnancy-dating-Dg6dTe1p.js.map} +1 -1
  22. package/dist/_chunks/{pregnancy-weight-gain-BMRBeA8V.js → pregnancy-weight-gain-DI7X-0JX.js} +2 -2
  23. package/dist/_chunks/{pregnancy-weight-gain-BMRBeA8V.js.map → pregnancy-weight-gain-DI7X-0JX.js.map} +1 -1
  24. package/dist/_chunks/rich-text-editor-B03qM22-.js +334 -0
  25. package/dist/_chunks/rich-text-editor-B03qM22-.js.map +1 -0
  26. package/dist/_chunks/{unit-converter-BQ6lEYvd.js → unit-converter-3sINXO3m.js} +2 -2
  27. package/dist/_chunks/{unit-converter-BQ6lEYvd.js.map → unit-converter-3sINXO3m.js.map} +1 -1
  28. package/dist/agent-catalog.json +2 -2
  29. package/dist/components/_shared/safe-html.d.ts +1 -1
  30. package/dist/components/bishop-score/index.js +1 -1
  31. package/dist/components/bmi-calculator/index.js +1 -1
  32. package/dist/components/calendar/index.js +1 -1
  33. package/dist/components/cycle-calculator/index.js +1 -1
  34. package/dist/components/due-date-calculator/index.js +1 -1
  35. package/dist/components/fetal-weight/index.js +1 -1
  36. package/dist/components/gestational-age-calculator/index.js +1 -1
  37. package/dist/components/hcg-doubling/index.js +1 -1
  38. package/dist/components/pregnancy-dating/index.js +1 -1
  39. package/dist/components/pregnancy-weight-gain/index.js +1 -1
  40. package/dist/components/rich-text-editor/index.d.ts +2 -2
  41. package/dist/components/rich-text-editor/index.d.ts.map +1 -1
  42. package/dist/components/rich-text-editor/index.js +4 -7
  43. package/dist/components/rich-text-editor/rich-text-editor.agent.d.ts.map +1 -1
  44. package/dist/components/rich-text-editor/rich-text-editor.d.ts +21 -15
  45. package/dist/components/rich-text-editor/rich-text-editor.d.ts.map +1 -1
  46. package/dist/components/unit-converter/index.js +1 -1
  47. package/dist/hooks/index.d.ts +1 -0
  48. package/dist/hooks/index.d.ts.map +1 -1
  49. package/dist/hooks/index.js +99 -77
  50. package/dist/hooks/index.js.map +1 -1
  51. package/dist/hooks/use-countdown.d.ts +34 -0
  52. package/dist/hooks/use-countdown.d.ts.map +1 -0
  53. package/dist/i18n/locales/ar.d.ts +1 -0
  54. package/dist/i18n/locales/ar.d.ts.map +1 -1
  55. package/dist/i18n/locales/ar.js +1 -0
  56. package/dist/i18n/locales/ar.js.map +1 -1
  57. package/dist/i18n/locales/de.d.ts +1 -0
  58. package/dist/i18n/locales/de.d.ts.map +1 -1
  59. package/dist/i18n/locales/de.js +1 -0
  60. package/dist/i18n/locales/de.js.map +1 -1
  61. package/dist/i18n/locales/el.d.ts +1 -0
  62. package/dist/i18n/locales/el.d.ts.map +1 -1
  63. package/dist/i18n/locales/el.js +1 -0
  64. package/dist/i18n/locales/el.js.map +1 -1
  65. package/dist/i18n/locales/en.d.ts +1 -0
  66. package/dist/i18n/locales/en.d.ts.map +1 -1
  67. package/dist/i18n/locales/en.js +1 -0
  68. package/dist/i18n/locales/en.js.map +1 -1
  69. package/dist/i18n/locales/es.d.ts +1 -0
  70. package/dist/i18n/locales/es.d.ts.map +1 -1
  71. package/dist/i18n/locales/es.js +1 -0
  72. package/dist/i18n/locales/es.js.map +1 -1
  73. package/dist/i18n/locales/fr.d.ts +1 -0
  74. package/dist/i18n/locales/fr.d.ts.map +1 -1
  75. package/dist/i18n/locales/fr.js +1 -0
  76. package/dist/i18n/locales/fr.js.map +1 -1
  77. package/dist/i18n/locales/hi.d.ts +1 -0
  78. package/dist/i18n/locales/hi.d.ts.map +1 -1
  79. package/dist/i18n/locales/hi.js +1 -0
  80. package/dist/i18n/locales/hi.js.map +1 -1
  81. package/dist/i18n/locales/it.d.ts +1 -0
  82. package/dist/i18n/locales/it.d.ts.map +1 -1
  83. package/dist/i18n/locales/it.js +1 -0
  84. package/dist/i18n/locales/it.js.map +1 -1
  85. package/dist/i18n/locales/ja.d.ts +1 -0
  86. package/dist/i18n/locales/ja.d.ts.map +1 -1
  87. package/dist/i18n/locales/ja.js +1 -0
  88. package/dist/i18n/locales/ja.js.map +1 -1
  89. package/dist/i18n/locales/nl.d.ts +1 -0
  90. package/dist/i18n/locales/nl.d.ts.map +1 -1
  91. package/dist/i18n/locales/nl.js +1 -0
  92. package/dist/i18n/locales/nl.js.map +1 -1
  93. package/dist/i18n/locales/pl.d.ts +1 -0
  94. package/dist/i18n/locales/pl.d.ts.map +1 -1
  95. package/dist/i18n/locales/pl.js +1 -0
  96. package/dist/i18n/locales/pl.js.map +1 -1
  97. package/dist/i18n/locales/pt.d.ts +1 -0
  98. package/dist/i18n/locales/pt.d.ts.map +1 -1
  99. package/dist/i18n/locales/pt.js +1 -0
  100. package/dist/i18n/locales/pt.js.map +1 -1
  101. package/dist/i18n/locales/ro.d.ts +1 -0
  102. package/dist/i18n/locales/ro.d.ts.map +1 -1
  103. package/dist/i18n/locales/ro.js +1 -0
  104. package/dist/i18n/locales/ro.js.map +1 -1
  105. package/dist/i18n/locales/ru.d.ts +1 -0
  106. package/dist/i18n/locales/ru.d.ts.map +1 -1
  107. package/dist/i18n/locales/ru.js +1 -0
  108. package/dist/i18n/locales/ru.js.map +1 -1
  109. package/dist/i18n/locales/sq.d.ts +1 -0
  110. package/dist/i18n/locales/sq.d.ts.map +1 -1
  111. package/dist/i18n/locales/sq.js +1 -0
  112. package/dist/i18n/locales/sq.js.map +1 -1
  113. package/dist/i18n/locales/sv.d.ts +1 -0
  114. package/dist/i18n/locales/sv.d.ts.map +1 -1
  115. package/dist/i18n/locales/sv.js +1 -0
  116. package/dist/i18n/locales/sv.js.map +1 -1
  117. package/dist/i18n/locales/tr.d.ts +1 -0
  118. package/dist/i18n/locales/tr.d.ts.map +1 -1
  119. package/dist/i18n/locales/tr.js +1 -0
  120. package/dist/i18n/locales/tr.js.map +1 -1
  121. package/dist/i18n/locales/zh.d.ts +1 -0
  122. package/dist/i18n/locales/zh.d.ts.map +1 -1
  123. package/dist/i18n/locales/zh.js +1 -0
  124. package/dist/i18n/locales/zh.js.map +1 -1
  125. package/dist/index.js +143 -146
  126. package/dist/locales/ar.json +1 -0
  127. package/dist/locales/de.json +1 -0
  128. package/dist/locales/el.json +1 -0
  129. package/dist/locales/en.json +1 -0
  130. package/dist/locales/es.json +1 -0
  131. package/dist/locales/fr.json +1 -0
  132. package/dist/locales/hi.json +1 -0
  133. package/dist/locales/it.json +1 -0
  134. package/dist/locales/ja.json +1 -0
  135. package/dist/locales/nl.json +1 -0
  136. package/dist/locales/pl.json +1 -0
  137. package/dist/locales/pt.json +1 -0
  138. package/dist/locales/ro.json +1 -0
  139. package/dist/locales/ru.json +1 -0
  140. package/dist/locales/sq.json +1 -0
  141. package/dist/locales/sv.json +1 -0
  142. package/dist/locales/tr.json +1 -0
  143. package/dist/locales/zh.json +1 -0
  144. package/dist/safe-html/index.js.map +1 -1
  145. package/dist/tokens.css +23 -25
  146. package/package.json +2 -52
  147. package/dist/_chunks/image-C6RM5hfF.js +0 -16
  148. package/dist/_chunks/image-C6RM5hfF.js.map +0 -1
  149. package/dist/_chunks/insert-result-njqBthzT.js.map +0 -1
  150. package/dist/_chunks/rich-text-editor-DhGIBd4a.js +0 -921
  151. package/dist/_chunks/rich-text-editor-DhGIBd4a.js.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfadocs/ui-kit-debug",
3
- "version": "0.57.0",
3
+ "version": "0.59.0",
4
4
  "type": "module",
5
5
  "description": "AlfaDocs shared design system — tokens, components, patterns, and translations for platform, booking, and alfascribe. (debug build — identical runtime to @alfadocs/ui-kit, ships source maps for symbolication).",
6
6
  "license": "BUSL-1.1",
@@ -725,15 +725,6 @@
725
725
  "@fullcalendar/timeline": "^6.1.20",
726
726
  "@stripe/react-stripe-js": "^1.16.0 || ^2 || ^3 || ^6",
727
727
  "@stripe/stripe-js": "^1.41.0 || ^2 || ^3 || ^4 || ^5 || ^6 || ^7 || ^8 || ^9",
728
- "@tiptap/extension-image": "^3.22.3",
729
- "@tiptap/extension-link": "^3.22.3",
730
- "@tiptap/extension-table": "^3.22.3",
731
- "@tiptap/extension-table-cell": "^3.22.3",
732
- "@tiptap/extension-table-header": "^3.22.3",
733
- "@tiptap/extension-table-row": "^3.22.3",
734
- "@tiptap/pm": "^3.22.3",
735
- "@tiptap/react": "^3.22.3",
736
- "@tiptap/starter-kit": "^3.22.3",
737
728
  "@vis.gl/react-google-maps": "^1.1.0 || ^2",
738
729
  "ag-grid-community": "^35.2.1",
739
730
  "ag-grid-react": "^35.2.1",
@@ -745,8 +736,7 @@
745
736
  "react-apexcharts": "^2.0.0",
746
737
  "react-dom": "^18.2.0 || ^19.0.0",
747
738
  "react-i18next": "^17.0.3",
748
- "signature_pad": "^5.1.3",
749
- "tiptap-markdown": "^0.9.0"
739
+ "signature_pad": "^5.1.3"
750
740
  },
751
741
  "peerDependenciesMeta": {
752
742
  "react": {
@@ -797,33 +787,6 @@
797
787
  "@stripe/stripe-js": {
798
788
  "optional": true
799
789
  },
800
- "@tiptap/extension-image": {
801
- "optional": true
802
- },
803
- "@tiptap/extension-link": {
804
- "optional": true
805
- },
806
- "@tiptap/extension-table": {
807
- "optional": true
808
- },
809
- "@tiptap/extension-table-cell": {
810
- "optional": true
811
- },
812
- "@tiptap/extension-table-header": {
813
- "optional": true
814
- },
815
- "@tiptap/extension-table-row": {
816
- "optional": true
817
- },
818
- "@tiptap/pm": {
819
- "optional": true
820
- },
821
- "@tiptap/react": {
822
- "optional": true
823
- },
824
- "@tiptap/starter-kit": {
825
- "optional": true
826
- },
827
790
  "@vis.gl/react-google-maps": {
828
791
  "optional": true
829
792
  },
@@ -847,9 +810,6 @@
847
810
  },
848
811
  "signature_pad": {
849
812
  "optional": true
850
- },
851
- "tiptap-markdown": {
852
- "optional": true
853
813
  }
854
814
  },
855
815
  "dependencies": {
@@ -915,15 +875,6 @@
915
875
  "@tailwindcss/postcss": "^4.2.2",
916
876
  "@testing-library/jest-dom": "^6.6.3",
917
877
  "@testing-library/react": "^16.1.0",
918
- "@tiptap/extension-image": "^3.22.3",
919
- "@tiptap/extension-link": "^3.22.3",
920
- "@tiptap/extension-table": "^3.22.3",
921
- "@tiptap/extension-table-cell": "^3.22.3",
922
- "@tiptap/extension-table-header": "^3.22.3",
923
- "@tiptap/extension-table-row": "^3.22.3",
924
- "@tiptap/pm": "^3.22.3",
925
- "@tiptap/react": "^3.22.3",
926
- "@tiptap/starter-kit": "^3.22.3",
927
878
  "@types/dompurify": "^3.0.5",
928
879
  "@types/google.maps": "^3.58.1",
929
880
  "@types/react": "^19.2.0",
@@ -964,7 +915,6 @@
964
915
  "stylelint": "^16.26.1",
965
916
  "stylelint-config-standard": "^36.0.1",
966
917
  "tailwindcss": "^4.2.2",
967
- "tiptap-markdown": "^0.9.0",
968
918
  "typescript": "^5.9.3",
969
919
  "typescript-eslint": "^8.59.3",
970
920
  "vite": "^6.4.2",
@@ -1,16 +0,0 @@
1
- import { c as e } from "./createLucideIcon-CrFbzy84.js";
2
- /**
3
- * @license lucide-react v1.8.0 - ISC
4
- *
5
- * This source code is licensed under the ISC license.
6
- * See the LICENSE file in the root directory of this source tree.
7
- */
8
- const c = [
9
- ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", ry: "2", key: "1m3agn" }],
10
- ["circle", { cx: "9", cy: "9", r: "2", key: "af1f0g" }],
11
- ["path", { d: "m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21", key: "1xmnt7" }]
12
- ], a = e("image", c);
13
- export {
14
- a as I
15
- };
16
- //# sourceMappingURL=image-C6RM5hfF.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"image-C6RM5hfF.js","sources":["../../node_modules/lucide-react/dist/esm/icons/image.js"],"sourcesContent":["/**\n * @license lucide-react v1.8.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst __iconNode = [\n [\"rect\", { width: \"18\", height: \"18\", x: \"3\", y: \"3\", rx: \"2\", ry: \"2\", key: \"1m3agn\" }],\n [\"circle\", { cx: \"9\", cy: \"9\", r: \"2\", key: \"af1f0g\" }],\n [\"path\", { d: \"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21\", key: \"1xmnt7\" }]\n];\nconst Image = createLucideIcon(\"image\", __iconNode);\n\nexport { __iconNode, Image as default };\n//# sourceMappingURL=image.js.map\n"],"names":["__iconNode","Image","createLucideIcon"],"mappings":";AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAMA,IAAa;AAAA,EACjB,CAAC,QAAQ,EAAE,OAAO,MAAM,QAAQ,MAAM,GAAG,KAAK,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK,KAAK,UAAU;AAAA,EACvF,CAAC,UAAU,EAAE,IAAI,KAAK,IAAI,KAAK,GAAG,KAAK,KAAK,UAAU;AAAA,EACtD,CAAC,QAAQ,EAAE,GAAG,6CAA6C,KAAK,SAAQ,CAAE;AAC5E,GACMC,IAAQC,EAAiB,SAASF,CAAU;","x_google_ignoreList":[0]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"insert-result-njqBthzT.js","sources":["../../node_modules/lucide-react/dist/esm/icons/type.js","../../src/components/_shared/banded-gauge.tsx","../../src/components/_shared/insert-result.tsx"],"sourcesContent":["/**\n * @license lucide-react v1.8.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.js';\n\nconst __iconNode = [\n [\"path\", { d: \"M12 4v16\", key: \"1654pz\" }],\n [\"path\", { d: \"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2\", key: \"e0r10z\" }],\n [\"path\", { d: \"M9 20h6\", key: \"s66wpe\" }]\n];\nconst Type = createLucideIcon(\"type\", __iconNode);\n\nexport { __iconNode, Type as default };\n//# sourceMappingURL=type.js.map\n","/* ------------------------------------------------------------------ */\n/* Shared banded-linear gauge — a horizontal track split into coloured */\n/* zones with a marker at the value's position. */\n/* */\n/* Two surfaces, one geometry: */\n/* */\n/* • the INSERT CARD bakes a PNG (`<img>` → `<canvas>` → `toBlob`), */\n/* so it needs concrete colours embedded in an SVG STRING. It calls */\n/* {@link buildBandedGaugeSvgString} with a resolver that maps a */\n/* token NAME to the probe-resolved `rgb(...)` (same path the donut */\n/* gauge uses in `insert-result.tsx`). */\n/* */\n/* • the ON-SCREEN widget renders {@link BandedGauge} as JSX. Its */\n/* resolver returns `var(<token>)` so the live CSS theme resolves */\n/* each band fill — it tracks a theme switch with no JS re-sample. */\n/* */\n/* Both surfaces derive every coordinate from */\n/* {@link computeBandedGaugeGeometry}, so the card raster and the live */\n/* widget are pixel-equivalent for the same model — no drift. */\n/* */\n/* Native SVG only: `<rect>` / `<line>` / `<polygon>` / `<path>` / */\n/* `<text>` / `<title>`. NEVER `<foreignObject>` (it silently drops in */\n/* the `<img>` raster) and no charting library. */\n/* */\n/* RTL: the numeric scale ALWAYS runs low→high left-to-right, even under */\n/* `dir=\"rtl\"` — a measurement axis is not a reading axis, so the gauge */\n/* root pins `dir=\"ltr\"`. Logical properties govern only the SURROUNDING */\n/* layout (the card/widget that hosts the gauge), never the axis itself. */\n/* ------------------------------------------------------------------ */\n\nimport { forwardRef } from 'react';\n\n/* ------------------------------------------------------------------ */\n/* Model + WHO BMI source-of-truth */\n/* ------------------------------------------------------------------ */\n\n/** One coloured zone of the track, filled up to (and excluding) `upTo`. */\nexport interface BandedGaugeBand {\n /**\n * Upper boundary of the band on the scale (exclusive). The final band's\n * `upTo` is conventionally the scale `max` so it fills to the bar end.\n */\n upTo: number;\n /**\n * DS token NAME for the band fill — e.g. `'--info'`, `'--success'`,\n * `'--warning-readable'`, `'--destructive'`. Resolved by the surface's\n * `resolve` callback (concrete `rgb()` for the card, `var(<token>)` for the\n * widget). Never a hex/rgb literal in source.\n */\n colorToken: string;\n}\n\n/**\n * A banded-linear gauge. Every visible string (`valueLabel`, `categoryLabel`,\n * `rangeLabel`, `ariaLabel`) arrives ALREADY TRANSLATED — this module is\n * i18n-agnostic; the BMI calculator supplies `t()`-resolved text.\n */\nexport interface BandedGaugeModel {\n /** The true value (printed verbatim even when clamped to a bar end). */\n value: number;\n /** Ascending coloured zones; the last `upTo` should equal `max`. */\n bands: BandedGaugeBand[];\n /** Low end of the drawn scale (maps to the bar's inline start). */\n min: number;\n /** High end of the drawn scale (maps to the bar's inline end). */\n max: number;\n /** Big number rendered above the marker (e.g. `'24.6'`). */\n valueLabel: string;\n /** Band name shown beside the value (e.g. `'normal'`). Pre-translated. */\n categoryLabel?: string;\n /** Range string for the band (e.g. `'18.5–24.9'`). Pre-translated. */\n rangeLabel?: string;\n /** Full accessible name, e.g. `'BMI 24.6 — normal (18.5–24.9)'`. */\n ariaLabel: string;\n /** Threshold tick values drawn under the bar (e.g. `[18.5, 25, 30]`). */\n ticks?: number[];\n}\n\n/* ---- WHO BMI bands — shared source of truth for both surfaces -------- */\n\n/** Drawn BMI scale: 15 (deep underweight) → 40 (deep obesity). */\nexport const BMI_BANDED_MIN = 15;\nexport const BMI_BANDED_MAX = 40;\n\n/** WHO adult cut-offs drawn as ticks under the bar. */\nexport const BMI_BAND_THRESHOLDS = [18.5, 25, 30] as const;\n\n/**\n * The four WHO zones as `{ upTo, colorToken }`, plus the scale + ticks, so\n * both the on-screen widget and the insert card share ONE definition:\n *\n * underweight < 18.5 → `--info`\n * normal 18.5–24.9 → `--success`\n * overweight 25–29.9 → `--warning-readable` (contrast-safe orange)\n * obese ≥ 30 → `--destructive` (one obese zone)\n *\n * `--warning-readable` is the kit's contrast-safe orange token — it already\n * resolves correctly per theme (orange-600 in light/non-accessible, `--warning`\n * elsewhere), so NO `document.documentElement` JS override is needed here.\n */\nexport function bmiBands(): {\n bands: BandedGaugeBand[];\n min: number;\n max: number;\n ticks: number[];\n} {\n return {\n bands: [\n { upTo: 18.5, colorToken: '--info' },\n { upTo: 25, colorToken: '--success' },\n { upTo: 30, colorToken: '--warning-readable' },\n { upTo: BMI_BANDED_MAX, colorToken: '--destructive' },\n ],\n min: BMI_BANDED_MIN,\n max: BMI_BANDED_MAX,\n ticks: [...BMI_BAND_THRESHOLDS],\n };\n}\n\n/* ------------------------------------------------------------------ */\n/* Geometry — single source of positional truth */\n/* ------------------------------------------------------------------ */\n\n/** One filled zone rect in card/widget coordinates. */\nexport interface BandRect {\n /** Inline-start x of the zone. */\n x: number;\n /** Zone width. */\n w: number;\n /** Token NAME to fill it with (resolved by the surface). */\n colorToken: string;\n}\n\n/** The value marker: its drawn x plus the clamp envelope it lives in. */\nexport interface MarkerGeometry {\n /** Drawn x of the marker (clamped into `[clampedStart, clampedEnd]`). */\n x: number;\n /** Inline-start x the marker can reach (bar start). */\n clampedStart: number;\n /** Inline-end x the marker can reach (bar end). */\n clampedEnd: number;\n /**\n * `'start'` when the true value sits below `min` (marker pinned to the bar\n * start), `'end'` when it sits above `max`, `null` when it's in range. Drives\n * the out-of-range caret/chevron.\n */\n overflow: 'start' | 'end' | null;\n}\n\n/** A threshold tick: its x plus the scale value it marks. */\nexport interface TickGeometry {\n x: number;\n value: number;\n}\n\n/** Everything the two builders need, derived once. */\nexport interface BandedGaugeGeometry {\n /** Outer SVG width. */\n width: number;\n /** Outer SVG height. */\n height: number;\n /** Inline-start x of the bar. */\n barStart: number;\n /** Inline-end x of the bar. */\n barEnd: number;\n /** Bar top y. */\n barY: number;\n /** Bar thickness. */\n barH: number;\n /** Bar corner radius. */\n barRadius: number;\n /** Coloured zones, left → right. */\n bands: BandRect[];\n /** The value marker. */\n marker: MarkerGeometry;\n /** Threshold ticks under the bar. */\n ticks: TickGeometry[];\n /** Baseline y for the value label above the bar. */\n valueLabelY: number;\n /** Baseline y for the tick number labels under the bar. */\n tickLabelY: number;\n /** Pre-translated value label (verbatim from the model). */\n valueLabel: string;\n /** Optional `category (range)` summary shown beside the value. */\n summaryLabel: string;\n /** Full accessible name for `<title>` / `aria-label`. */\n ariaLabel: string;\n}\n\n/** Layout knobs for {@link computeBandedGaugeGeometry}. */\nexport interface BandedGaugeLayoutOptions {\n /** Outer SVG width. */\n width: number;\n /** Outer SVG height. */\n height: number;\n}\n\n/* Internal layout constants — the inset of the bar within the SVG box, the\n bar thickness, and the vertical rhythm. Pure numbers (no design tokens) —\n these are geometry, not colours/spacing-from-CSS. */\nexport const INSET_X = 14;\nconst BAR_H = 12;\nconst BAR_RADIUS = BAR_H / 2;\nconst VALUE_LABEL_BASELINE = 18; // y of the value label baseline\nconst BAR_TOP_GAP = 12; // gap below the value label to the bar\nconst TICK_LABEL_GAP = 16; // gap below the bar to the tick numbers\n\n/** Linear map of a scale value to a bar x, NOT clamped. */\nfunction scaleToX(\n value: number,\n min: number,\n max: number,\n barStart: number,\n barEnd: number,\n): number {\n if (max <= min) return barStart;\n const t = (value - min) / (max - min);\n return barStart + t * (barEnd - barStart);\n}\n\n/**\n * Pure geometry pass — the ONE place value→x mapping, band widths, marker\n * clamping, and tick positions are computed. Both the SVG-string builder and\n * the JSX component consume this so the two surfaces never drift.\n *\n * The marker x is CLAMPED to `[barStart, barEnd]`, but `valueLabel` always\n * prints the true value; `marker.overflow` flags an out-of-range value so the\n * surface can draw a caret at the clamped end.\n */\nexport function computeBandedGaugeGeometry(\n model: BandedGaugeModel,\n { width, height }: BandedGaugeLayoutOptions,\n): BandedGaugeGeometry {\n const barStart = INSET_X;\n const barEnd = width - INSET_X;\n const barY = VALUE_LABEL_BASELINE + BAR_TOP_GAP;\n const valueLabelY = VALUE_LABEL_BASELINE;\n const tickLabelY = barY + BAR_H + TICK_LABEL_GAP;\n\n // Bands fill consecutively from the scale min up to each `upTo`, the last\n // capping at `max`. A band whose range falls outside the scale collapses to\n // zero width rather than spilling past the bar.\n let cursor = model.min;\n const bands: BandRect[] = model.bands.map((band) => {\n const lower = Math.max(model.min, Math.min(cursor, model.max));\n const upper = Math.max(model.min, Math.min(band.upTo, model.max));\n cursor = band.upTo;\n const x = scaleToX(lower, model.min, model.max, barStart, barEnd);\n const xEnd = scaleToX(upper, model.min, model.max, barStart, barEnd);\n return { x, w: Math.max(0, xEnd - x), colorToken: band.colorToken };\n });\n\n // Marker: true x, then clamp into the bar, flagging out-of-range.\n const rawX = scaleToX(model.value, model.min, model.max, barStart, barEnd);\n const overflow: MarkerGeometry['overflow'] =\n model.value < model.min ? 'start' : model.value > model.max ? 'end' : null;\n const markerX = Math.min(barEnd, Math.max(barStart, rawX));\n\n const ticks: TickGeometry[] = (model.ticks ?? [])\n .filter((value) => value >= model.min && value <= model.max)\n .map((value) => ({\n x: scaleToX(value, model.min, model.max, barStart, barEnd),\n value,\n }));\n\n const summaryLabel = model.categoryLabel\n ? model.rangeLabel\n ? `${model.categoryLabel} (${model.rangeLabel})`\n : model.categoryLabel\n : '';\n\n return {\n width,\n height,\n barStart,\n barEnd,\n barY,\n barH: BAR_H,\n barRadius: BAR_RADIUS,\n bands,\n marker: {\n x: markerX,\n clampedStart: barStart,\n clampedEnd: barEnd,\n overflow,\n },\n ticks,\n valueLabelY,\n tickLabelY,\n valueLabel: model.valueLabel,\n summaryLabel,\n ariaLabel: model.ariaLabel,\n };\n}\n\n/** Round to 2dp so emitted coordinates stay compact + deterministic. */\nconst r2 = (n: number): number => Math.round(n * 100) / 100;\n\n/* ------------------------------------------------------------------ */\n/* SVG-string builder (insert card surface) */\n/* ------------------------------------------------------------------ */\n\n/** XML-escape a string for safe insertion into the SVG markup. */\nconst escapeXml = (s: string): string =>\n s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n\n/** A token-name → concrete-colour resolver supplied by each surface. */\nexport type ColorResolver = (colorToken: string) => string;\n\n/** Theme colours + font + resolver for {@link buildBandedGaugeSvgString}. */\nexport interface BandedGaugeSvgOptions {\n /**\n * Maps a band token NAME to the colour string painted into the markup. The\n * card passes a probe-resolved `rgb(...)` resolver so the baked PNG carries\n * theme-correct colours; never a literal in source.\n */\n resolve: ColorResolver;\n /** Font family for the text (resolved from the theme, e.g. `--font-sans`). */\n font: string;\n /** Foreground colour for the value label + marker (concrete). */\n fg: string;\n /** Muted colour for the tick numbers + summary (concrete). */\n muted: string;\n /** Track / unfilled-rail colour, also used for tick rules (concrete). */\n track: string;\n}\n\n/**\n * Build the banded gauge as a native-SVG `<g>` STRING the card can place at an\n * arbitrary offset. Pure native SVG (`<rect>`/`<line>`/`<polygon>`/`<text>`) —\n * no `<foreignObject>`. The bands fill from the resolver; the marker is a thin\n * vertical rule + a downward triangle; an out-of-range value adds a caret at\n * the clamped end.\n *\n * Returns just the `<g>…</g>` group (origin at 0,0) so the card can translate\n * it; the card wraps the whole gauge with the accessible name on its own\n * `role=\"img\"` group, but this group also carries a `<title>` for standalone\n * use (e.g. when rendered as a complete SVG in a test).\n */\n/**\n * Path for a band with independently rounded left/right corners. `<rect rx>`\n * rounds ALL four corners, which notches the inner band boundaries — so the\n * strip rounds only its OUTER corners (first band on the left, last on the\n * right) while every inner boundary stays a crisp vertical seam.\n */\nfunction bandPath(\n x: number,\n y: number,\n w: number,\n h: number,\n rL: number,\n rR: number,\n): string {\n const x2 = x + w;\n const y2 = y + h;\n const tr = rR > 0 ? `A${rR} ${rR} 0 0 1 ${r2(x2)} ${r2(y + rR)}` : '';\n const br = rR > 0 ? `A${rR} ${rR} 0 0 1 ${r2(x2 - rR)} ${r2(y2)}` : '';\n const bl = rL > 0 ? `A${rL} ${rL} 0 0 1 ${r2(x)} ${r2(y2 - rL)}` : '';\n const tl = rL > 0 ? `A${rL} ${rL} 0 0 1 ${r2(x + rL)} ${r2(y)}` : '';\n return `M${r2(x + rL)} ${r2(y)} H${r2(x2 - rR)} ${tr} V${r2(\n y2 - rR,\n )} ${br} H${r2(x + rL)} ${bl} V${r2(y + rL)} ${tl} Z`;\n}\n\nexport function buildBandedGaugeSvgString(\n geometry: BandedGaugeGeometry,\n options: BandedGaugeSvgOptions,\n): string {\n const { resolve, font, fg, muted, track } = options;\n const fontFamily = escapeXml(font);\n\n // Track rail behind the bands (so any inter-band gap reads as a rail, and the\n // rounded ends are consistent).\n const rail = `<rect x=\"${r2(geometry.barStart)}\" y=\"${r2(\n geometry.barY,\n )}\" width=\"${r2(geometry.barEnd - geometry.barStart)}\" height=\"${\n geometry.barH\n }\" rx=\"${geometry.barRadius}\" fill=\"${track}\"/>`;\n\n // Band zones. Only the strip's outer corners round (first band on the left,\n // last on the right) via `bandPath`; every inner boundary is a crisp seam.\n const bandCount = geometry.bands.length;\n const bandRects = geometry.bands\n .map((band, i) => {\n const fill = resolve(band.colorToken);\n const rL = i === 0 ? geometry.barRadius : 0;\n const rR = i === bandCount - 1 ? geometry.barRadius : 0;\n return `<path d=\"${bandPath(\n band.x,\n geometry.barY,\n band.w,\n geometry.barH,\n rL,\n rR,\n )}\" fill=\"${fill}\"/>`;\n })\n .join('');\n\n // Threshold ticks: a short hairline under the bar + the value number.\n const tickY1 = geometry.barY + geometry.barH;\n const tickY2 = tickY1 + 4;\n const ticks = geometry.ticks\n .map((tick) => {\n const rule = `<line x1=\"${r2(tick.x)}\" y1=\"${r2(tickY1)}\" x2=\"${r2(\n tick.x,\n )}\" y2=\"${r2(tickY2)}\" stroke=\"${track}\" stroke-width=\"1\"/>`;\n const label = `<text x=\"${r2(\n tick.x,\n )}\" y=\"${r2(geometry.tickLabelY)}\" text-anchor=\"middle\" font-family=\"${fontFamily}\" font-size=\"9\" fill=\"${muted}\">${escapeXml(\n String(tick.value),\n )}</text>`;\n return rule + label;\n })\n .join('');\n\n // Marker: thin vertical rule spanning the bar + a downward triangle resting\n // on the bar top. Drawn in the foreground colour so it reads over any band.\n const mx = r2(geometry.marker.x);\n const ruleTop = geometry.barY - 3;\n const ruleBottom = geometry.barY + geometry.barH + 3;\n const markerRule = `<line x1=\"${mx}\" y1=\"${r2(ruleTop)}\" x2=\"${mx}\" y2=\"${r2(\n ruleBottom,\n )}\" stroke=\"${fg}\" stroke-width=\"2\" stroke-linecap=\"round\"/>`;\n const triTop = geometry.barY - 4;\n const triangle = `<polygon points=\"${mx},${r2(geometry.barY + 1)} ${r2(\n geometry.marker.x - 4,\n )},${r2(triTop)} ${r2(geometry.marker.x + 4)},${r2(triTop)}\" fill=\"${fg}\"/>`;\n\n // Out-of-range caret: a chevron at the clamped end pointing outward.\n let caret = '';\n if (geometry.marker.overflow) {\n const cy = geometry.barY + geometry.barH / 2;\n if (geometry.marker.overflow === 'start') {\n const tipX = geometry.barStart - 2;\n caret = `<polyline points=\"${r2(tipX + 5)},${r2(cy - 4)} ${r2(\n tipX,\n )},${r2(cy)} ${r2(tipX + 5)},${r2(\n cy + 4,\n )}\" fill=\"none\" stroke=\"${fg}\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n } else {\n const tipX = geometry.barEnd + 2;\n caret = `<polyline points=\"${r2(tipX - 5)},${r2(cy - 4)} ${r2(\n tipX,\n )},${r2(cy)} ${r2(tipX - 5)},${r2(\n cy + 4,\n )}\" fill=\"none\" stroke=\"${fg}\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/>`;\n }\n }\n\n // Value label (bold) + the muted category(range) summary trailing it.\n const valueLabel = `<text x=\"${r2(\n geometry.barStart,\n )}\" y=\"${r2(geometry.valueLabelY)}\" font-family=\"${fontFamily}\" font-size=\"13\" font-weight=\"700\" fill=\"${fg}\">${escapeXml(\n geometry.valueLabel,\n )}</text>`;\n const summary = geometry.summaryLabel\n ? `<text x=\"${r2(geometry.barEnd)}\" y=\"${r2(\n geometry.valueLabelY,\n )}\" text-anchor=\"end\" font-family=\"${fontFamily}\" font-size=\"10\" fill=\"${muted}\">${escapeXml(\n geometry.summaryLabel,\n )}</text>`\n : '';\n\n const title = `<title>${escapeXml(geometry.ariaLabel)}</title>`;\n\n return `<g role=\"img\" aria-label=\"${escapeXml(\n geometry.ariaLabel,\n )}\">${title}${rail}${bandRects}${ticks}${markerRule}${triangle}${caret}${valueLabel}${summary}</g>`;\n}\n\n/* ------------------------------------------------------------------ */\n/* React component (on-screen widget surface) */\n/* ------------------------------------------------------------------ */\n\n/** Default on-screen gauge box. */\nconst DEFAULT_WIDTH = 260;\nexport const DEFAULT_HEIGHT = 64;\n\n/**\n * The on-screen resolver: a token NAME → `var(<token>)`. The live CSS theme\n * resolves it, so a theme switch repaints the bands with no JS re-sample. This\n * mirrors the card's concrete-colour resolver one-for-one on geometry.\n */\nfunction cssVarResolver(colorToken: string): string {\n return `var(${colorToken})`;\n}\n\nexport interface BandedGaugeProps {\n /** The gauge model (value, bands, scale, pre-translated labels). */\n model: BandedGaugeModel;\n /** SVG width. Defaults to {@link DEFAULT_WIDTH}. */\n width?: number;\n /** SVG height. Defaults to {@link DEFAULT_HEIGHT}. */\n height?: number;\n /** Extra class names on the root `<svg>`. */\n className?: string;\n}\n\n/**\n * Presentational banded-linear gauge for the on-screen widget. Renders the SAME\n * geometry as {@link buildBandedGaugeSvgString} but as JSX, filling each band\n * with `fill=\"var(<token>)\"` so the live theme resolves the colour (and a theme\n * switch repaints with no re-sample). Visually equivalent to the card string.\n *\n * The track + marker are decorative; the accessible name on the root carries\n * the meaning (`role=\"img\"` + `aria-label`, mirrored in `<title>`). All text in\n * the model is pre-translated by the caller.\n *\n * The measurement axis runs low→high left-to-right regardless of document\n * direction — SVG coordinates are inherently LTR (a `<rect x>` is unaffected by\n * `direction`), and `direction=\"ltr\"` is pinned on the root to keep any nested\n * `<text>` directionality explicit. Logical properties govern the surrounding\n * layout, never this axis.\n */\nexport const BandedGauge = forwardRef<SVGSVGElement, BandedGaugeProps>(\n function BandedGauge(\n { model, width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT, className },\n ref,\n ) {\n const g = computeBandedGaugeGeometry(model, { width, height });\n const tickY1 = g.barY + g.barH;\n const tickY2 = tickY1 + 4;\n const ruleTop = g.barY - 3;\n const ruleBottom = g.barY + g.barH + 3;\n const triTop = g.barY - 4;\n const bandCount = g.bands.length;\n const caretCy = g.barY + g.barH / 2;\n\n return (\n <svg\n ref={ref}\n data-component=\"banded-gauge\"\n direction=\"ltr\"\n role=\"img\"\n aria-label={g.ariaLabel}\n width={width}\n height={height}\n viewBox={`0 0 ${width} ${height}`}\n className={['ds:[font-family:var(--font-sans)]', className]\n .filter(Boolean)\n .join(' ')}\n >\n <title>{g.ariaLabel}</title>\n\n {/* Track rail behind the zones. */}\n <rect\n x={r2(g.barStart)}\n y={r2(g.barY)}\n width={r2(g.barEnd - g.barStart)}\n height={g.barH}\n rx={g.barRadius}\n className=\"ds:fill-[color:var(--muted)]\"\n />\n\n {/* Coloured band zones — fill via the live CSS var. Only the strip's\n outer corners round; inner boundaries stay crisp (see bandPath). */}\n {g.bands.map((band, i) => (\n <path\n key={`${band.colorToken}-${i}`}\n d={bandPath(\n band.x,\n g.barY,\n band.w,\n g.barH,\n i === 0 ? g.barRadius : 0,\n i === bandCount - 1 ? g.barRadius : 0,\n )}\n fill={cssVarResolver(band.colorToken)}\n />\n ))}\n\n {/* Threshold ticks: hairline + number. */}\n {g.ticks.map((tick) => (\n <g key={tick.value}>\n <line\n x1={r2(tick.x)}\n y1={r2(tickY1)}\n x2={r2(tick.x)}\n y2={r2(tickY2)}\n strokeWidth={1}\n className=\"ds:stroke-[color:var(--border)]\"\n />\n <text\n x={r2(tick.x)}\n y={r2(g.tickLabelY)}\n textAnchor=\"middle\"\n fontSize={9}\n className=\"ds:fill-[color:var(--muted-foreground)]\"\n >\n {tick.value}\n </text>\n </g>\n ))}\n\n {/* Marker: vertical rule + triangle. */}\n <line\n x1={r2(g.marker.x)}\n y1={r2(ruleTop)}\n x2={r2(g.marker.x)}\n y2={r2(ruleBottom)}\n strokeWidth={2}\n strokeLinecap=\"round\"\n className=\"ds:stroke-[color:var(--foreground)]\"\n />\n <polygon\n points={`${r2(g.marker.x)},${r2(g.barY + 1)} ${r2(\n g.marker.x - 4,\n )},${r2(triTop)} ${r2(g.marker.x + 4)},${r2(triTop)}`}\n className=\"ds:fill-[color:var(--foreground)]\"\n />\n\n {/* Out-of-range caret at the clamped end. */}\n {g.marker.overflow === 'start' ? (\n <polyline\n points={`${r2(g.barStart + 3)},${r2(caretCy - 4)} ${r2(\n g.barStart - 2,\n )},${r2(caretCy)} ${r2(g.barStart + 3)},${r2(caretCy + 4)}`}\n fill=\"none\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"ds:stroke-[color:var(--foreground)]\"\n />\n ) : null}\n {g.marker.overflow === 'end' ? (\n <polyline\n points={`${r2(g.barEnd - 3)},${r2(caretCy - 4)} ${r2(\n g.barEnd + 2,\n )},${r2(caretCy)} ${r2(g.barEnd - 3)},${r2(caretCy + 4)}`}\n fill=\"none\"\n strokeWidth={2}\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"ds:stroke-[color:var(--foreground)]\"\n />\n ) : null}\n\n {/* Value label + muted summary. */}\n <text\n x={r2(g.barStart)}\n y={r2(g.valueLabelY)}\n fontSize={13}\n fontWeight={700}\n className=\"ds:fill-[color:var(--foreground)]\"\n >\n {g.valueLabel}\n </text>\n {g.summaryLabel ? (\n <text\n x={r2(g.barEnd)}\n y={r2(g.valueLabelY)}\n textAnchor=\"end\"\n fontSize={10}\n className=\"ds:fill-[color:var(--muted-foreground)]\"\n >\n {g.summaryLabel}\n </text>\n ) : null}\n </svg>\n );\n },\n);\n\nBandedGauge.displayName = 'BandedGauge';\n","/* ------------------------------------------------------------------ */\n/* InsertButton — shared \"use this result\" control for the calculator */\n/* toolset. */\n/* */\n/* Two variants, one set of payload builders: */\n/* */\n/* • `insert` (default) — editor-extension context. Each button hands */\n/* the built InsertPayload to `onInsert`, who drops it into whatever */\n/* editor they use. The kit never touches an editor. */\n/* */\n/* • `copy` — app-shell context. Each button writes the chosen */\n/* representation(s) to the clipboard as a multi-format ClipboardItem */\n/* so a single copy serves any paste target. The image format is a */\n/* REAL raster PNG (the SVG card rasterised to a canvas) — clipboards */\n/* reject SVG as an image, so copying the data-URI as text is the */\n/* exact \"copied text without the image\" bug this variant fixes. */\n/* */\n/* Three inline buttons, one per mode (text / image / text + image). */\n/* */\n/* The SVG card embeds CONCRETE colours so it renders standalone as an */\n/* <img>. To stay within the \"no hardcoded colours\" rule, those colours */\n/* are sampled at click time from hidden probe spans that carry the */\n/* token utility classes — i.e. resolved from the live theme, never */\n/* written as literals in source. */\n/* ------------------------------------------------------------------ */\n\nimport { forwardRef, useRef } from 'react';\nimport { useTranslation } from 'react-i18next';\nimport { cva } from 'class-variance-authority';\nimport { Type, Image as ImageIcon, Layers } from 'lucide-react';\nimport { Button, type ButtonProps } from '../button';\nimport {\n computeBandedGaugeGeometry,\n buildBandedGaugeSvgString,\n INSET_X as BANDED_GAUGE_INSET_X,\n DEFAULT_HEIGHT as BANDED_GAUGE_HEIGHT,\n type BandedGaugeBand,\n} from './banded-gauge';\n\nexport type InsertMode = 'text' | 'image' | 'text-image';\n\nexport type InsertVariant = 'insert' | 'copy';\n\n/**\n * The handful of lucide glyphs the result-card header can carry. Each maps to a\n * static native-SVG geometry string in {@link ICON_GEOMETRY}, hand-transcribed\n * from lucide-react 1.8.0's `__iconNode` arrays (pinned to that version so the\n * paths match the on-screen React glyphs exactly). We do NOT import the lucide\n * React components into the raster path — they can't be serialised into the\n * `<img>` data-URI — so the geometry is inlined as raw `<path>` elements.\n */\nexport type IconKey =\n | 'activity'\n | 'scale'\n | 'ruler'\n | 'calendar'\n | 'calendar-heart'\n | 'baby'\n | 'heart'\n | 'droplets'\n | 'clock'\n | 'tag'\n | 'trending-up'\n | 'percent';\n\n/** lucide native authoring grid — every glyph is drawn on a 24×24 viewBox. */\nconst ICON_VIEWBOX = 24;\n/** Header glyph render size (px in card space). */\nconst ICON_SLOT = 18;\n/** Leading field-row glyph render size (px in card space). */\nconst FIELD_ICON_SLOT = 12;\n\n/**\n * Inner SVG element strings for each glyph, copied verbatim from lucide-react\n * 1.8.0 `__iconNode` (the `key` attr dropped — it's React-only). Rendered inside\n * a `<g>` carrying lucide's canonical presentation attrs (`fill=\"none\"`,\n * `stroke-width=\"2\"`, round caps/joins), scaled `slot/24` to the target size.\n * Pure `<path>`/`<rect>`/`<circle>` — native SVG, raster-safe, no `<foreignObject>`.\n */\nconst ICON_GEOMETRY: Record<IconKey, string> = {\n activity:\n '<path d=\"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2\"/>',\n scale:\n '<path d=\"M12 3v18\"/><path d=\"m19 8 3 8a5 5 0 0 1-6 0zV7\"/><path d=\"M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1\"/><path d=\"m5 8 3 8a5 5 0 0 1-6 0zV7\"/><path d=\"M7 21h10\"/>',\n ruler:\n '<path d=\"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z\"/><path d=\"m14.5 12.5 2-2\"/><path d=\"m11.5 9.5 2-2\"/><path d=\"m8.5 6.5 2-2\"/><path d=\"m17.5 15.5 2-2\"/>',\n calendar:\n '<path d=\"M8 2v4\"/><path d=\"M16 2v4\"/><rect width=\"18\" height=\"18\" x=\"3\" y=\"4\" rx=\"2\"/><path d=\"M3 10h18\"/>',\n 'calendar-heart':\n '<path d=\"M12.127 22H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v5.125\"/><path d=\"M14.62 18.8A2.25 2.25 0 1 1 18 15.836a2.25 2.25 0 1 1 3.38 2.966l-2.626 2.856a.998.998 0 0 1-1.507 0z\"/><path d=\"M16 2v4\"/><path d=\"M3 10h18\"/><path d=\"M8 2v4\"/>',\n baby: '<path d=\"M10 16c.5.3 1.2.5 2 .5s1.5-.2 2-.5\"/><path d=\"M15 12h.01\"/><path d=\"M19.38 6.813A9 9 0 0 1 20.8 10.2a2 2 0 0 1 0 3.6 9 9 0 0 1-17.6 0 2 2 0 0 1 0-3.6A9 9 0 0 1 12 3c2 0 3.5 1.1 3.5 2.5s-.9 2.5-2 2.5c-.8 0-1.5-.4-1.5-1\"/><path d=\"M9 12h.01\"/>',\n heart:\n '<path d=\"M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5\"/>',\n droplets:\n '<path d=\"M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z\"/><path d=\"M12.56 6.6A10.97 10.97 0 0 0 14 3.02c.5 2.5 2 4.9 4 6.5s3 3.5 3 5.5a6.98 6.98 0 0 1-11.91 4.97\"/>',\n clock: '<circle cx=\"12\" cy=\"12\" r=\"10\"/><path d=\"M12 6v6l4 2\"/>',\n tag: '<path d=\"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z\"/><circle cx=\"7.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"/>',\n 'trending-up': '<path d=\"M16 7h6v6\"/><path d=\"m22 7-8.5 8.5-5-5L2 17\"/>',\n percent:\n '<line x1=\"19\" x2=\"5\" y1=\"5\" y2=\"19\"/><circle cx=\"6.5\" cy=\"6.5\" r=\"2.5\"/><circle cx=\"17.5\" cy=\"17.5\" r=\"2.5\"/>',\n};\n\n/** True when `key` is a known {@link IconKey} with embedded geometry. */\nfunction isIconKey(key: string): key is IconKey {\n return Object.prototype.hasOwnProperty.call(ICON_GEOMETRY, key);\n}\n\n/**\n * Emit a glyph as a translated + scaled `<g>` carrying lucide's canonical\n * presentation attrs. `slot` is the on-card render size; the group scales the\n * 24-grid geometry down to it (so `stroke-width=\"2\"` in the grid yields a\n * proportionally lighter visual stroke, matching lucide's optical weight).\n * Returns `''` for an unknown key so an unmapped card simply omits the glyph.\n */\nfunction buildIconGroup(\n icon: string,\n colour: string,\n x: number,\n y: number,\n slot: number,\n): string {\n if (!isIconKey(icon)) return '';\n const scale = slot / ICON_VIEWBOX;\n // `color` is set alongside `stroke` so the rare glyph that fills a detail with\n // `currentColor` (e.g. `tag`'s centre dot) resolves to the same glyph colour.\n return `<g transform=\"translate(${x} ${y}) scale(${scale})\" fill=\"none\" color=\"${colour}\" stroke=\"${colour}\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\">${ICON_GEOMETRY[icon]}</g>`;\n}\n\nexport interface InsertCardField {\n label: string;\n value: string;\n /**\n * Optional leading glyph for the row, drawn at {@link FIELD_ICON_SLOT} in\n * place of the default bullet dot. One of the known {@link IconKey} names; an\n * unknown / omitted value falls back to the muted bullet (fully\n * back-compatible — a field without an icon renders exactly as before).\n */\n icon?: IconKey;\n}\n\n/**\n * Radial gauge — a hand-rolled native-SVG donut (track `<circle>` + value arc\n * via `stroke-dasharray`) drawn in the card's inline-end corner box. Survives\n * the `<img>` → `<canvas>` → `toBlob` raster. No `<foreignObject>`, no charting\n * lib.\n *\n * This is the original gauge shape; `variant` is optional and defaults to\n * `'radial'`, so a gauge object authored before the banded variant existed\n * renders exactly as before.\n */\nexport interface InsertCardRadialGauge {\n /** Discriminant. Optional — omitted means `'radial'` (back-compat). */\n variant?: 'radial';\n /** Big number rendered in the gauge centre (e.g. `'22.4'`). */\n value: string;\n /**\n * Filled fraction of the ring, `0`–`1`. Takes precedence when supplied;\n * otherwise derived from a `value`/`max` numeric parse (falling back to a\n * full ring when neither is numeric).\n */\n fraction?: number;\n /** Denominator used to derive `fraction` when `fraction` is omitted. */\n max?: number;\n /**\n * Number of evenly-spaced segment gaps to notch into the ring (e.g. `4` for\n * a quartered dial). `0`/omitted draws a continuous arc.\n */\n segments?: number;\n /**\n * DS token NAME for the arc colour — e.g. `'--success'`, `'--warning'`,\n * `'--destructive'`, `'--info'`, or the light-orange overweight override.\n * Resolved to a concrete colour from a probe span at raster time; never a\n * hex literal in source.\n */\n colorToken: string;\n /** Small category label under the value inside the ring. */\n label?: string;\n}\n\n/**\n * Banded gauge — a full-width horizontal track split into coloured zones with a\n * marker at the value's position (the WHO BMI dial, drawn via the shared\n * `banded-gauge` module). It spans the card edge-to-edge below the field rows.\n * Same raster-safety guarantees as the radial donut: pure native SVG, no\n * `<foreignObject>`.\n *\n * Every visible string (`valueLabel`, `categoryLabel`, `rangeLabel`,\n * `ariaLabel`) arrives ALREADY TRANSLATED — the calculator supplies `t()`-\n * resolved text. Every band's `colorToken` is registered for probe sampling so\n * the baked raster carries theme-correct fills.\n */\nexport interface InsertCardBandedGauge {\n /** Discriminant for the banded layout. */\n variant: 'banded';\n /** The true value (printed verbatim even when clamped to a bar end). */\n value: number;\n /** Ascending coloured zones; the last `upTo` should equal `max`. */\n bands: BandedGaugeBand[];\n /** Low end of the drawn scale (maps to the bar's inline start). */\n min: number;\n /** High end of the drawn scale (maps to the bar's inline end). */\n max: number;\n /** Big number rendered above the marker (e.g. `'24.6'`). */\n valueLabel: string;\n /** Band name shown beside the value (e.g. `'normal'`). Pre-translated. */\n categoryLabel?: string;\n /** Range string for the band (e.g. `'18.5–24.9'`). Pre-translated. */\n rangeLabel?: string;\n /** Full accessible name, e.g. `'BMI 24.6 — normal (18.5–24.9)'`. */\n ariaLabel: string;\n /** Threshold tick values drawn under the bar (e.g. `[18.5, 25, 30]`). */\n ticks?: number[];\n}\n\n/**\n * Optional in-card gauge. A discriminated union on `variant`:\n *\n * • `'radial'` (default when `variant` is omitted) — the corner-box donut.\n * • `'banded'` — a full-width horizontal banded bar below the fields.\n */\nexport type InsertCardGauge = InsertCardRadialGauge | InsertCardBandedGauge;\n\n/** True when the gauge is the full-width banded variant. */\nfunction isBandedGauge(gauge: InsertCardGauge): gauge is InsertCardBandedGauge {\n return gauge.variant === 'banded';\n}\n\nexport interface InsertCardData {\n /** Card heading. */\n title: string;\n /** Key/value rows. */\n fields: InsertCardField[];\n /**\n * Optional header glyph drawn inline-end of the title, tinted with the card's\n * category colour ({@link InsertCardData.highlightToken}). One of the known\n * {@link IconKey} names; an unknown / omitted value simply skips the glyph\n * (fully back-compatible — a card without an icon renders as before).\n */\n icon?: IconKey;\n /** Optional highlighted line, rendered as a category chip (pill). */\n highlight?: string;\n /**\n * DS token NAME for the highlight chip fill. Defaults to the accent token\n * (`--primary`). The chip text uses the matching `<token>-foreground` when it\n * resolves, else falls back to the card background for contrast.\n */\n highlightToken?: string;\n /** Optional radial gauge drawn natively in the card. */\n gauge?: InsertCardGauge;\n /**\n * Optional brand wordmark line printed at the foot of the card.\n *\n * - omitted / `false` → no brand line and no footer at all; the card ends\n * after the fields/gauge.\n * - a string → that wordmark, rendered as a single quiet line (no hairline\n * rule above it).\n *\n * A `brand` passed to {@link SvgCardToPngOptions} overrides this per-render.\n */\n brand?: string | false;\n}\n\nexport interface InsertPayload {\n /** Which button the user chose. */\n mode: InsertMode;\n /** Plain-text summary. Always present. */\n text: string;\n /** Rich HTML summary (heading + list). Always present. */\n html: string;\n /**\n * Branded SVG result-card markup. Empty for mode `'text'`.\n *\n * Kept for back-compat and for callers that need the live, copy-pasteable\n * vector. NOTE: SVG can carry `<script>` and is routinely stripped by\n * rich-text sanitisers, so it is NOT the format to insert into an editor —\n * use {@link InsertPayload.pngDataUri} for that.\n */\n svg: string;\n /**\n * SVG as an `image/svg+xml` data URI for `<img src>`. Empty for `'text'`.\n *\n * Same caveat as {@link InsertPayload.svg}: fine for a preview `<img>`, but a\n * sanitiser-stripped vector once it reaches an editor. Prefer\n * {@link InsertPayload.pngDataUri}.\n */\n imageDataUri: string;\n /**\n * Async thunk that resolves the result-card raster — the format intended for\n * editor insertion. PNG is a flat raster: it carries no script and survives\n * the rich-text sanitiser that strips SVG.\n *\n * Resolves to `{ dataUri, width, height }` where `width`/`height` are the\n * **logical (un-scaled) CSS pixel** dimensions: set them on the inserted\n * `<img width height>` and the supersampled (`>= 2×`) PNG renders crisp with\n * no consumer-side shim. For mode `'text'` resolves to an empty\n * `{ dataUri: '', width: 0, height: 0 }`. Rendered lazily so the synchronous\n * payload stays cheap; `await payload.pngDataUri()` only when you need it.\n *\n * @since 0.43.0 — this return shape changed from a bare `Promise<string>` to\n * `Promise<{ dataUri; width; height }>` (see CHANGELOG).\n */\n pngDataUri: () => Promise<InsertPngResult>;\n}\n\n/** Resolved PNG raster plus its logical (un-scaled) `<img>` dimensions. */\nexport interface InsertPngResult {\n /** `image/png` data URI, or `''` for the text-only mode. */\n dataUri: string;\n /** Logical (CSS px) width to set on the inserted `<img>`. `0` when empty. */\n width: number;\n /** Logical (CSS px) height to set on the inserted `<img>`. `0` when empty. */\n height: number;\n}\n\nexport interface InsertButtonProps {\n /** Structured result used to build every payload representation. */\n card: InsertCardData;\n /**\n * Verb the buttons perform. Defaults to `'insert'`.\n *\n * - `'insert'` — fires `onInsert(payload)` (editor-extension context).\n * - `'copy'` — writes the chosen representation(s) to the clipboard as a\n * multi-format `ClipboardItem` (app-shell context).\n */\n variant?: InsertVariant;\n /**\n * Receives the built payload when a button is pressed.\n *\n * Required for the `insert` variant; optional (and ignored) for `copy`.\n */\n onInsert?: (payload: InsertPayload) => void;\n /** `copy` variant only — fired after a successful clipboard write. */\n onCopy?: (mode: InsertMode) => void;\n /** `copy` variant only — fired if the clipboard write can't proceed. */\n onError?: (error: unknown) => void;\n /** Trigger size. Defaults to `'sm'`. */\n size?: 'sm' | 'md' | 'lg';\n /**\n * Visual intent of the three trigger buttons (text / image / text+image).\n * Mirrors the `Button` `intent` prop and applies to every trigger uniformly\n * so the three stay visually consistent. Defaults to `'primary'`.\n */\n intent?: ButtonProps['intent'];\n}\n\ninterface ThemeColours {\n fg: string;\n muted: string;\n accent: string;\n border: string;\n bg: string;\n font: string;\n /**\n * Concrete colours resolved from arbitrary DS token names, keyed by the token\n * name the caller passed (e.g. `'--success'`). Populated for the gauge arc\n * and the highlight chip; consulted by {@link buildResultCardSvg} via\n * {@link resolveToken}.\n */\n tokens?: Record<string, string>;\n}\n\n/* Fixed probe keys → the resolved colour they sample. */\nconst PROBE_KEYS = ['fg', 'muted', 'accent', 'border', 'bg'] as const;\n\n/** Default DS token names driving the chip and the on-token text colours. */\nconst DEFAULT_HIGHLIGHT_TOKEN = '--primary';\n\nconst SVG_W = 380;\n\n/** Strip a leading `--`/whitespace so a token name is a safe class/probe id. */\nconst tokenName = (token: string): string => token.trim().replace(/^--/, '');\n\n/**\n * The probe-span utility class that resolves a given token to a concrete colour\n * at sample time: the token is read as `var(<token>)` so `getComputedStyle`\n * returns the live theme's concrete `rgb()` — never a literal in source.\n */\nfunction probeClassForToken(token: string): string {\n return `ds:text-[color:var(${token})]`;\n}\n\n/**\n * The card's category fill token: the chip token when one is set, otherwise the\n * default highlight token. Drives the left accent rule, header icon, and\n * primary-value colour even on cards without a chip.\n */\nfunction categoryFillToken(card: InsertCardData): string {\n return card.highlightToken ?? DEFAULT_HIGHLIGHT_TOKEN;\n}\n\n/**\n * Extra `<token>` → resolved-colour probes a given card needs beyond the five\n * fixed keys: the gauge arc colour, the highlight chip fill (+ its `-foreground`\n * companion for contrasting on-token text), and the category solid that tints\n * the left-rule/header-icon/primary-value.\n */\nfunction extraTokensForCard(card: InsertCardData): string[] {\n const wanted = new Set<string>();\n if (card.highlight) {\n const fill = card.highlightToken ?? DEFAULT_HIGHLIGHT_TOKEN;\n wanted.add(fill);\n wanted.add(`${fill}-foreground`);\n }\n // The category accents (left rule, header icon, primary value) all use the\n // card's category solid — requested even without a chip.\n const category = categoryFillToken(card);\n wanted.add(category);\n // Gauge colours: the radial arc's single token, or EVERY banded zone token so\n // each band fill resolves to a probe-sampled rgb in the baked raster.\n if (card.gauge) {\n if (isBandedGauge(card.gauge)) {\n for (const band of card.gauge.bands) wanted.add(band.colorToken);\n } else {\n wanted.add(card.gauge.colorToken);\n }\n }\n return [...wanted];\n}\n\nfunction readThemeColours(\n probe: HTMLElement | null,\n extraTokens: string[] = [],\n): ThemeColours {\n const fallback: ThemeColours = {\n fg: 'currentColor',\n muted: 'currentColor',\n accent: 'currentColor',\n border: 'currentColor',\n bg: 'transparent',\n font: 'sans-serif',\n tokens: {},\n };\n if (!probe) return fallback;\n const read = (key: string): string => {\n const el = probe.querySelector<HTMLElement>(`[data-k=\"${key}\"]`);\n if (!el) return 'currentColor';\n return getComputedStyle(el).color || 'currentColor';\n };\n const tokens: Record<string, string> = {};\n for (const token of extraTokens) {\n const el = probe.querySelector<HTMLElement>(\n `[data-token=\"${tokenName(token)}\"]`,\n );\n if (el) {\n const colour = getComputedStyle(el).color;\n if (colour) tokens[token] = colour;\n }\n }\n return {\n fg: read('fg'),\n muted: read('muted'),\n accent: read('accent'),\n border: read('border'),\n bg: read('bg'),\n font: getComputedStyle(probe).fontFamily || 'sans-serif',\n tokens,\n };\n}\n\n/**\n * Internal resolved-colour shape, re-exported for tests that construct a card\n * raster without a live DOM probe. Not part of the public component API.\n */\nexport type ThemeColoursForTest = ThemeColours;\n\n/** Resolve a token NAME to a concrete colour, or a fallback when unsampled. */\nfunction resolveToken(\n c: ThemeColours,\n token: string | undefined,\n fallback: string,\n): string {\n if (!token) return fallback;\n return c.tokens?.[token] ?? fallback;\n}\n\nconst escapeXml = (s: string): string =>\n s\n .replace(/&/g, '&amp;')\n .replace(/</g, '&lt;')\n .replace(/>/g, '&gt;')\n .replace(/\"/g, '&quot;');\n\nexport function buildResultText(card: InsertCardData): string {\n const lines = [card.title];\n if (card.highlight) lines.push(card.highlight);\n for (const f of card.fields) lines.push(`• ${f.label}: ${f.value}`);\n return lines.join('\\n');\n}\n\nexport function buildResultHtml(card: InsertCardData): string {\n const items = card.fields\n .map((f) => `<li>${escapeXml(f.label)}: ${escapeXml(f.value)}</li>`)\n .join('');\n const highlight = card.highlight\n ? `<p><strong>${escapeXml(card.highlight)}</strong></p>`\n : '';\n return `<p><strong>${escapeXml(card.title)}</strong></p>${highlight}<ul>${items}</ul>`;\n}\n\n/* Layout constants — shared by the height calc and the markup builder. */\nconst PAD = 20;\nconst TITLE_BASELINE = PAD + 18;\nconst CHIP_H = 22;\nconst CHIP_GAP = 10;\nconst ROW_H = 22;\nconst FIELDS_GAP = 16;\nconst FOOTER_GAP = 12;\nconst FOOTER_H = 12;\nconst GAUGE_R = 34; // outer radius\nconst GAUGE_STROKE = 9;\nconst GAUGE_BOX = (GAUGE_R + GAUGE_STROKE) * 2; // gauge group bounding box\n\n/* Banded gauge — a full-width horizontal bar drawn BELOW the field rows. The\n bar inset (BANDED_GAUGE_INSET_X) and total occupied height (BANDED_GAUGE_HEIGHT)\n are imported from the shared module so the card and the gauge can't drift. */\nconst BANDED_GAUGE_GAP = 16; // gap between the fields block and the bar\n\n/* Accent geometry — additive \"pop\" elements that don't move existing baselines. */\nconst HEADER_ICON_BOX = ICON_SLOT; // header glyph render box\nconst FIELD_ICON_GAP = 6; // gap between a field-row glyph and its label text\n\n/* ------------------------------------------------------------------ */\n/* Field-row text wrapping */\n/* */\n/* The result card is a fixed `SVG_W`-wide raster with no native text */\n/* reflow, so a long field row (e.g. an antenatal-schedule entry with a */\n/* long label + a date range) would clip at the card's inline-end edge. */\n/* We lay each row out ourselves: a row that fits stays on one line */\n/* (pixel-identical to before); a row that doesn't wraps its label and */\n/* value onto indented continuation lines, and the card grows taller to */\n/* clear them. */\n/* ------------------------------------------------------------------ */\n\n/** Field-row text origin (past the leading marker) and its width budget. */\nconst FIELD_TEXT_X = PAD + FIELD_ICON_SLOT + FIELD_ICON_GAP;\nconst FIELD_TEXT_BUDGET = SVG_W - PAD - FIELD_TEXT_X;\n/** Field-row font sizes — the first (primary) row prints its value larger. */\nconst FIELD_LABEL_SIZE = 13;\nconst PRIMARY_VALUE_SIZE = 14;\nconst FIELD_VALUE_SIZE = 13;\n/** Baseline advance between wrapped continuation lines within one row. */\nconst WRAP_LINE_H = 16;\n\n/** True for CJK / Hangul / Kana / full-width codepoints (≈ 1em wide). */\nfunction isWideGlyph(code: number): boolean {\n return (\n (code >= 0x1100 && code <= 0x115f) || // Hangul Jamo\n (code >= 0x2e80 && code <= 0xa4cf) || // CJK radicals … Yi\n (code >= 0xac00 && code <= 0xd7a3) || // Hangul syllables\n (code >= 0xf900 && code <= 0xfaff) || // CJK compatibility ideographs\n (code >= 0xfe30 && code <= 0xfe4f) || // CJK compatibility forms\n (code >= 0xff00 && code <= 0xff60) || // full-width forms\n (code >= 0xffe0 && code <= 0xffe6) // full-width signs\n );\n}\n\n/**\n * Estimate a string's rendered width at a font size, without a DOM. Latin\n * glyphs average ≈ 0.62em; CJK / full-width glyphs occupy ≈ 1em. We deliberately\n * over- rather than under-estimate so a row wraps just BEFORE it would clip — an\n * early wrap is cosmetic, a missed wrap loses clinical data off the edge.\n */\nfunction estimateTextWidth(text: string, fontSize: number): number {\n let units = 0;\n for (const ch of text) {\n units += isWideGlyph(ch.codePointAt(0) ?? 0) ? 1 : 0.62;\n }\n return units * fontSize;\n}\n\n/** Hard-break a single space-less token (or CJK run) to fit `maxWidth`. */\nfunction hardBreak(\n token: string,\n fontSize: number,\n maxWidth: number,\n): string[] {\n const out: string[] = [];\n let cur = '';\n for (const ch of token) {\n if (cur && estimateTextWidth(cur + ch, fontSize) > maxWidth) {\n out.push(cur);\n cur = ch;\n } else {\n cur += ch;\n }\n }\n if (cur) out.push(cur);\n return out.length ? out : [''];\n}\n\n/**\n * Greedily wrap `text` to `maxWidth`, breaking on spaces and — for an over-long\n * token or a space-less script — within the token by character. Always returns\n * at least one line.\n */\nfunction wrapToWidth(\n text: string,\n fontSize: number,\n maxWidth: number,\n): string[] {\n const lines: string[] = [];\n let cur = '';\n const pushBroken = (token: string): void => {\n const pieces = hardBreak(token, fontSize, maxWidth);\n for (let i = 0; i < pieces.length - 1; i += 1) lines.push(pieces[i]);\n cur = pieces[pieces.length - 1];\n };\n for (const token of text.split(' ')) {\n const candidate = cur ? `${cur} ${token}` : token;\n if (!cur) {\n if (estimateTextWidth(token, fontSize) > maxWidth) pushBroken(token);\n else cur = token;\n } else if (estimateTextWidth(candidate, fontSize) <= maxWidth) {\n cur = candidate;\n } else {\n lines.push(cur);\n cur = '';\n if (estimateTextWidth(token, fontSize) > maxWidth) pushBroken(token);\n else cur = token;\n }\n }\n if (cur) lines.push(cur);\n return lines.length ? lines : [''];\n}\n\n/** One laid-out line of a field row. */\ninterface FieldRowLine {\n /**\n * `inline` renders the original label + value together on one line\n * (unchanged); `label` / `value` each render one wrapped fragment in the\n * matching style.\n */\n kind: 'inline' | 'label' | 'value';\n /** Text for a `label` / `value` line (ignored for `inline`). */\n text: string;\n}\n\n/** A field placed on the card: its first-line offset + its line breakdown. */\ninterface FieldPlacement {\n field: InsertCardField;\n index: number;\n /** Baseline offset (px) of this row's first line from the first field's. */\n firstLineDy: number;\n lines: FieldRowLine[];\n}\n\n/**\n * Lay every field into one-or-more lines. A row whose `label: value` fits the\n * text budget stays a single inline line (pixel-identical to before); otherwise\n * the label and value each wrap onto their own indented continuation lines.\n * Pure geometry (no colours / DOM) so the height calc and the markup builder\n * share it and can never drift. `endDy` is the baseline offset of the LAST line.\n */\nfunction placeFields(card: InsertCardData): {\n placements: FieldPlacement[];\n endDy: number;\n} {\n const placements: FieldPlacement[] = [];\n let dy = 0;\n card.fields.forEach((field, index) => {\n const valueSize = index === 0 ? PRIMARY_VALUE_SIZE : FIELD_VALUE_SIZE;\n const oneLineWidth =\n estimateTextWidth(`${field.label}: `, FIELD_LABEL_SIZE) +\n estimateTextWidth(field.value, valueSize);\n const lines: FieldRowLine[] =\n oneLineWidth <= FIELD_TEXT_BUDGET\n ? [{ kind: 'inline', text: '' }]\n : [\n ...wrapToWidth(\n `${field.label}:`,\n FIELD_LABEL_SIZE,\n FIELD_TEXT_BUDGET,\n ).map((text): FieldRowLine => ({ kind: 'label', text })),\n ...wrapToWidth(field.value, valueSize, FIELD_TEXT_BUDGET).map(\n (text): FieldRowLine => ({ kind: 'value', text }),\n ),\n ];\n placements.push({ field, index, firstLineDy: dy, lines });\n dy += ROW_H + (lines.length - 1) * WRAP_LINE_H;\n });\n const last = placements[placements.length - 1];\n const endDy = last\n ? last.firstLineDy + (last.lines.length - 1) * WRAP_LINE_H\n : 0;\n return { placements, endDy };\n}\n\n/**\n * Resolve the brand line for a render: option override wins over card field.\n * The default is **no brand** — an omitted brand renders no footer at all; a\n * string opts a single quiet wordmark line in.\n */\nfunction resolveBrand(\n card: InsertCardData,\n override: string | false | undefined,\n): string | false {\n const value = override !== undefined ? override : card.brand;\n if (typeof value === 'string') return value;\n return false;\n}\n\n/** Filled fraction `0`–`1` for a radial gauge, from `fraction` or `value`/`max`. */\nfunction gaugeFraction(gauge: InsertCardRadialGauge): number {\n if (typeof gauge.fraction === 'number') {\n return Math.min(1, Math.max(0, gauge.fraction));\n }\n const v = parseFloat(gauge.value);\n if (Number.isFinite(v) && typeof gauge.max === 'number' && gauge.max > 0) {\n return Math.min(1, Math.max(0, v / gauge.max));\n }\n return 1;\n}\n\ninterface CardLayout {\n hasChip: boolean;\n chipY: number;\n firstFieldY: number;\n fieldsEndY: number;\n /**\n * Top y of the banded-gauge group when the card carries a banded gauge, else\n * `null`. The radial gauge is `null` here — it lives in the corner box, not\n * the full-width band below the fields.\n */\n bandedGaugeY: number | null;\n footerY: number;\n height: number;\n}\n\n/** Compute the vertical layout once; reused by height + markup. */\nfunction layoutCard(card: InsertCardData, hasBrand: boolean): CardLayout {\n const hasChip = Boolean(card.highlight);\n const chipY = TITLE_BASELINE + CHIP_GAP; // chip top\n const firstFieldY =\n (hasChip ? chipY + CHIP_H + FIELDS_GAP : TITLE_BASELINE + FIELDS_GAP) +\n ROW_H -\n 6;\n // Field rows may wrap (long labels / values), so the block's end is the last\n // laid-out line — not a flat `(n-1) * ROW_H`. For all-single-line cards this\n // is identical to the old formula, so existing layouts are unchanged.\n const fieldsEndY = firstFieldY + placeFields(card).endDy;\n\n const banded = card.gauge && isBandedGauge(card.gauge);\n const radial = card.gauge && !isBandedGauge(card.gauge);\n\n // Radial gauge: keep the body at least as tall as the corner donut so it\n // never clips. Banded gauge does NOT use the corner floor — it lives below.\n const bodyTop = hasChip ? chipY : TITLE_BASELINE;\n const gaugeFloor = radial ? bodyTop + GAUGE_BOX : 0;\n\n // Banded gauge: a full-width bar slung below the fields, then the footer/\n // height grow to clear it.\n const bandedGaugeY = banded ? fieldsEndY + BANDED_GAUGE_GAP : null;\n const bandedBottom =\n bandedGaugeY !== null ? bandedGaugeY + BANDED_GAUGE_HEIGHT : 0;\n\n const contentBottom = Math.max(fieldsEndY, gaugeFloor, bandedBottom);\n const footerY = hasBrand\n ? contentBottom + FOOTER_GAP + FOOTER_H - 4\n : contentBottom;\n const height = Math.round(footerY + (hasBrand ? FOOTER_GAP : PAD));\n return {\n hasChip,\n chipY,\n firstFieldY,\n fieldsEndY,\n bandedGaugeY,\n footerY,\n height,\n };\n}\n\n/** Result-card SVG height for a given card — kept in sync with the markup. */\nfunction svgHeight(card: InsertCardData, brand: string | false): number {\n return layoutCard(card, brand !== false).height;\n}\n\n/**\n * Build the radial gauge group: a track `<circle>` plus a value arc drawn with\n * `stroke-dasharray`/`stroke-dashoffset` (optionally notched into `segments`),\n * a centred value + label, and a `<title>` accessible name. Pure native SVG —\n * never `<foreignObject>`.\n */\nfunction buildGauge(\n gauge: InsertCardRadialGauge,\n c: ThemeColours,\n font: string,\n cx: number,\n cy: number,\n): string {\n const r = GAUGE_R;\n const circumference = 2 * Math.PI * r;\n const frac = gaugeFraction(gauge);\n const arc = resolveToken(c, gauge.colorToken, c.accent);\n const segments =\n typeof gauge.segments === 'number' && gauge.segments > 1\n ? gauge.segments\n : 0;\n // Notch the ring into evenly-spaced segments via a dasharray pattern.\n const gap = segments ? 3 : 0;\n const segLen = segments ? circumference / segments - gap : circumference;\n const trackDash = segments ? `${segLen} ${gap}` : '';\n const valueDash = `${circumference * frac} ${circumference}`;\n const rotate = `transform=\"rotate(-90 ${cx} ${cy})\"`;\n const title = escapeXml(\n gauge.label ? `${gauge.value} — ${gauge.label}` : gauge.value,\n );\n const track = `<circle cx=\"${cx}\" cy=\"${cy}\" r=\"${r}\" fill=\"none\" stroke=\"${c.border}\" stroke-width=\"${GAUGE_STROKE}\"${\n trackDash ? ` stroke-dasharray=\"${trackDash}\"` : ''\n } ${rotate}/>`;\n const valueArc = `<circle cx=\"${cx}\" cy=\"${cy}\" r=\"${r}\" fill=\"none\" stroke=\"${arc}\" stroke-width=\"${GAUGE_STROKE}\" stroke-linecap=\"round\" stroke-dasharray=\"${valueDash}\" ${rotate}/>`;\n const centreValue = `<text x=\"${cx}\" y=\"${cy + 1}\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"${font}\" font-size=\"16\" font-weight=\"700\" fill=\"${c.fg}\">${escapeXml(\n gauge.value,\n )}</text>`;\n const centreLabel = gauge.label\n ? `<text x=\"${cx}\" y=\"${cy + 15}\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"${font}\" font-size=\"9\" fill=\"${c.muted}\">${escapeXml(\n gauge.label,\n )}</text>`\n : '';\n return `<g role=\"img\" aria-label=\"${title}\"><title>${title}</title>${track}${valueArc}${centreValue}${centreLabel}</g>`;\n}\n\n/**\n * Build the full-width banded gauge group via the shared `banded-gauge` module.\n * Geometry is computed for the card's full content width (`PAD..W-PAD`), then\n * emitted as a native-SVG `<g>` translated to the band's top y. The resolver is\n * bound to the card's probe-resolved colours — each band token falls back to the\n * accent when unsampled (the SSR / no-probe path) — so the baked raster carries\n * theme-correct fills with no literal in source. Pure native SVG; never a\n * `<foreignObject>`.\n */\nfunction buildBandedGauge(\n gauge: InsertCardBandedGauge,\n c: ThemeColours,\n cardWidth: number,\n y: number,\n): string {\n // The shared module insets its bar by a fixed INSET_X (14) from the geometry\n // box edges. To land the bar precisely on the card's PAD..(W-PAD) content\n // edges, hand it a slightly narrower box and translate by the inset delta so\n // INSET_X + offset === PAD. The bar then spans the full card content width.\n const offsetX = PAD - BANDED_GAUGE_INSET_X;\n const geometryWidth = cardWidth - 2 * offsetX;\n const geometry = computeBandedGaugeGeometry(\n {\n value: gauge.value,\n bands: gauge.bands,\n min: gauge.min,\n max: gauge.max,\n valueLabel: gauge.valueLabel,\n categoryLabel: gauge.categoryLabel,\n rangeLabel: gauge.rangeLabel,\n ariaLabel: gauge.ariaLabel,\n ticks: gauge.ticks,\n },\n { width: geometryWidth, height: BANDED_GAUGE_HEIGHT },\n );\n const group = buildBandedGaugeSvgString(geometry, {\n resolve: (token) => resolveToken(c, token, c.accent),\n // Raw theme font — buildBandedGaugeSvgString escapes it once. Passing the\n // card's already-escaped `font` here would double-escape and break it.\n font: c.font,\n fg: c.fg,\n muted: c.muted,\n track: c.border,\n });\n return `<g transform=\"translate(${offsetX} ${y})\">${group}</g>`;\n}\n\n/**\n * Parse a `getComputedStyle().color` string (`rgb(r, g, b)` / `rgba(...)`) to an\n * `[r, g, b]` triple, or `null` for the SSR placeholders (`currentColor` /\n * `transparent`) where no concrete colour is available.\n */\nfunction parseRgb(colour: string): [number, number, number] | null {\n const m = colour.match(/rgba?\\(\\s*(\\d+)[,\\s]+(\\d+)[,\\s]+(\\d+)/i);\n return m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;\n}\n\n/** WCAG relative luminance of an sRGB triple (0–255 channels). */\nfunction relativeLuminance([r, g, b]: [number, number, number]): number {\n const lin = (v: number) => {\n const s = v / 255;\n return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;\n };\n return 0.2126 * lin(r) + 0.7152 * lin(g) + 0.0722 * lin(b);\n}\n\n/**\n * WCAG contrast ratio between two `getComputedStyle` colour strings. Returns 0\n * when either side isn't a concrete rgb (the SSR path), so callers fall back.\n */\nfunction contrastRatio(a: string, b: string): number {\n const ca = parseRgb(a);\n const cb = parseRgb(b);\n if (!ca || !cb) return 0;\n const la = relativeLuminance(ca);\n const lb = relativeLuminance(cb);\n return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);\n}\n\n/** Build the highlight chip: rounded `<rect>` pill + centred `<text>`. */\nfunction buildChip(\n card: InsertCardData,\n c: ThemeColours,\n font: string,\n y: number,\n): string {\n const text = card.highlight as string;\n const fillToken = card.highlightToken ?? DEFAULT_HIGHLIGHT_TOKEN;\n const fill = resolveToken(c, fillToken, c.accent);\n // Chip label colour: the card surface (`c.bg`, white in light theme) reads as\n // crisp knockout text on the saturated fill when it clears 3:1. In dark /\n // accessible themes the surface is dark and the fills are lighter, so this\n // flips to a dark label automatically. Falls back to the card foreground when\n // the surface can't beat the fill, or colours aren't probe-resolved (SSR).\n const textColour = contrastRatio(c.bg, fill) >= 3 ? c.bg : c.fg;\n // Rough monospace-free width estimate: glyph ≈ 7.2px at 12px + 28px padding.\n const chipW = Math.round(text.length * 7.2 + 28);\n const textX = PAD + chipW / 2;\n const textY = y + CHIP_H / 2 + 1;\n return `<rect x=\"${PAD}\" y=\"${y}\" width=\"${chipW}\" height=\"${CHIP_H}\" rx=\"${\n CHIP_H / 2\n }\" fill=\"${fill}\"/><text x=\"${textX}\" y=\"${textY}\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"${font}\" font-size=\"12\" font-weight=\"600\" fill=\"${textColour}\">${escapeXml(\n text,\n )}</text>`;\n}\n\nexport function buildResultCardSvg(\n card: InsertCardData,\n c: ThemeColours,\n brand: string | false = false,\n): string {\n const W = SVG_W;\n const L = layoutCard(card, brand !== false);\n const H = L.height;\n const font = escapeXml(c.font);\n\n const categoryToken = categoryFillToken(card);\n // Category solid drives the header icon, the field-row glyphs, and the primary\n // value. It is the same resolved colour the chip uses, so the card stays\n // AA-safe upstream (each calculator passes a contrast-checked highlightToken).\n const categorySolid = resolveToken(c, categoryToken, c.accent);\n\n // Header glyph — drawn inline-end of the title row, vertically centred on the\n // title cap-height, tinted with the category solid. Omitted for an unset /\n // unknown icon (fully back-compatible).\n const headerIcon = card.icon\n ? buildIconGroup(\n card.icon,\n categorySolid,\n W - PAD - HEADER_ICON_BOX,\n TITLE_BASELINE - HEADER_ICON_BOX + 2,\n ICON_SLOT,\n )\n : '';\n\n // Fields flow on the inline-start edge; when a gauge is present it sits on\n // the inline-end edge so the rows don't run under it. Each row carries a small\n // leading marker so the list stays scannable: a per-field glyph when one is\n // set, else the quiet muted bullet dot (back-compat); the label/value text\n // indents past it. A row whose `label: value` fits stays one inline line; a\n // long row wraps its label + value onto indented continuation lines.\n const { placements } = placeFields(card);\n const rows = placements\n .map((p) => {\n const baseY = L.firstFieldY + p.firstLineDy;\n // The first row's value is the primary metric: heavier + category colour.\n const isPrimary = p.index === 0;\n const valueSize = isPrimary ? PRIMARY_VALUE_SIZE : FIELD_VALUE_SIZE;\n const valueWeight = isPrimary ? 700 : 500;\n const valueFill = isPrimary ? categorySolid : c.fg;\n // Leading marker on the row's FIRST line only: a per-field glyph in the\n // category solid (every row, so all glyphs — header + fields — share one\n // colour) drawn in the FIELD_ICON_SLOT box centred on the text baseline,\n // else the muted bullet dot for a field with no icon.\n const markerCy = baseY - 4; // visual centre of the row's cap-height\n let marker: string;\n if (p.field.icon && isIconKey(p.field.icon)) {\n marker = buildIconGroup(\n p.field.icon,\n categorySolid,\n PAD,\n markerCy - FIELD_ICON_SLOT / 2,\n FIELD_ICON_SLOT,\n );\n } else {\n const dotCx = PAD + FIELD_ICON_SLOT / 2;\n marker = `<circle cx=\"${dotCx}\" cy=\"${markerCy}\" r=\"2\" fill=\"${c.muted}\"/>`;\n }\n const lines = p.lines\n .map((line, li) => {\n const y = baseY + li * WRAP_LINE_H;\n if (line.kind === 'inline') {\n return `<text x=\"${FIELD_TEXT_X}\" y=\"${y}\" font-family=\"${font}\" font-size=\"13\"><tspan fill=\"${c.muted}\">${escapeXml(\n p.field.label,\n )}: </tspan><tspan font-size=\"${valueSize}\" font-weight=\"${valueWeight}\" fill=\"${valueFill}\">${escapeXml(\n p.field.value,\n )}</tspan></text>`;\n }\n if (line.kind === 'label') {\n return `<text x=\"${FIELD_TEXT_X}\" y=\"${y}\" font-family=\"${font}\" font-size=\"13\" fill=\"${c.muted}\">${escapeXml(\n line.text,\n )}</text>`;\n }\n return `<text x=\"${FIELD_TEXT_X}\" y=\"${y}\" font-family=\"${font}\" font-size=\"${valueSize}\" font-weight=\"${valueWeight}\" fill=\"${valueFill}\">${escapeXml(\n line.text,\n )}</text>`;\n })\n .join('');\n return `${marker}${lines}`;\n })\n .join('');\n\n const chip = L.hasChip ? buildChip(card, c, font, L.chipY) : '';\n\n // Gauge: the banded variant is a full-width bar below the fields; the radial\n // variant is the inline-end corner donut. The radial path is unchanged.\n let gauge = '';\n if (card.gauge) {\n if (isBandedGauge(card.gauge) && L.bandedGaugeY !== null) {\n gauge = buildBandedGauge(card.gauge, c, W, L.bandedGaugeY);\n } else if (!isBandedGauge(card.gauge)) {\n gauge = buildGauge(\n card.gauge,\n c,\n font,\n W - PAD - GAUGE_BOX / 2,\n (L.hasChip ? L.chipY : TITLE_BASELINE) + GAUGE_BOX / 2,\n );\n }\n }\n\n // Brand wordmark — an opt-in single quiet line at the foot of the card. No\n // hairline rule above it; an omitted / `false` brand renders no footer at all.\n const footer =\n brand !== false\n ? `<text x=\"${PAD}\" y=\"${\n L.footerY\n }\" font-family=\"${font}\" font-size=\"10\" font-weight=\"500\" fill=\"${c.muted}\">${escapeXml(\n brand,\n )}</text>`\n : '';\n\n const title = `<text x=\"${PAD}\" y=\"${TITLE_BASELINE}\" font-family=\"${font}\" font-size=\"16\" font-weight=\"700\" fill=\"${c.fg}\">${escapeXml(\n card.title,\n )}</text>`;\n\n // Layer order: surface fill → content → bordered outline LAST (fill=\"none\")\n // so the rx=\"12\" stroke draws cleanly over the plain card surface.\n const surface = `<rect x=\"0.5\" y=\"0.5\" width=\"${W - 1}\" height=\"${\n H - 1\n }\" rx=\"12\" fill=\"${c.bg}\"/>`;\n const outline = `<rect x=\"0.5\" y=\"0.5\" width=\"${W - 1}\" height=\"${\n H - 1\n }\" rx=\"12\" fill=\"none\" stroke=\"${c.border}\"/>`;\n\n return `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"${W}\" height=\"${H}\" viewBox=\"0 0 ${W} ${H}\" role=\"img\" aria-label=\"${escapeXml(\n card.title,\n )}\">${surface}${title}${headerIcon}${chip}${gauge}${rows}${footer}${outline}</svg>`;\n}\n\n/* ------------------------------------------------------------------ */\n/* Clipboard helpers (copy variant) */\n/* ------------------------------------------------------------------ */\n\n/** True when a multi-format clipboard write is reachable in this context. */\nfunction canWriteRichClipboard(): boolean {\n return (\n typeof navigator !== 'undefined' &&\n typeof navigator.clipboard?.write === 'function' &&\n typeof ClipboardItem !== 'undefined'\n );\n}\n\n/**\n * Rasterise the result-card SVG data-URI to a PNG Blob. Clipboards reject\n * SVG as an image, so we load the SVG into an <img>, paint it onto a canvas\n * at the SVG's intrinsic size, and read the canvas back as `image/png`.\n */\nfunction rasteriseSvgToPng(\n imageDataUri: string,\n width: number,\n height: number,\n): Promise<Blob> {\n return new Promise<Blob>((resolve, reject) => {\n const img = new Image();\n img.decoding = 'async';\n img.onload = () => {\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n const ctx = canvas.getContext('2d');\n if (!ctx) {\n reject(new Error('2D canvas context unavailable'));\n return;\n }\n ctx.drawImage(img, 0, 0, width, height);\n canvas.toBlob((blob) => {\n if (blob) resolve(blob);\n else reject(new Error('canvas.toBlob produced no PNG'));\n }, 'image/png');\n };\n img.onerror = () => reject(new Error('SVG failed to decode as an image'));\n img.src = imageDataUri;\n });\n}\n\n/** Options for {@link svgCardToPngDataUri}. */\nexport interface SvgCardToPngOptions {\n /**\n * Resolved theme colours to paint into the card. When omitted, the card\n * renders with `currentColor` / transparent fallbacks (see\n * {@link buildResultCardSvg}) — pass sampled colours for a branded raster.\n */\n colours?: ThemeColours;\n /**\n * Device-pixel scale factor for the raster. `2` yields a retina-sharp PNG.\n * Defaults to `Math.max(2, devicePixelRatio)` so the inserted image is crisp\n * without a consumer-side supersampling shim.\n */\n scale?: number;\n /**\n * Brand wordmark for the footer. Omitted → the card's own `brand` (then the\n * default `'AlfaDocs'`); a string overrides it; `false` removes it.\n */\n brand?: string | false;\n}\n\n/** dpr-aware default raster scale — never below 2× so the PNG stays crisp. */\nfunction defaultRasterScale(): number {\n const dpr =\n typeof window !== 'undefined' && typeof window.devicePixelRatio === 'number'\n ? window.devicePixelRatio\n : 1;\n return Math.max(2, dpr);\n}\n\n/**\n * Render an {@link InsertCardData} result card to an `image/png` data URI.\n *\n * This is the format intended for editor insertion: a flat raster carries no\n * `<script>` and survives the rich-text sanitiser that strips inline SVG. The\n * card is built as SVG, loaded into an `<img>`, painted onto a canvas at the\n * card's intrinsic size (optionally scaled), and read back as `image/png`.\n *\n * Browser-only — relies on `Image`, `<canvas>`, and `canvas.toBlob`. Throws if\n * called in a non-DOM context or if the SVG fails to decode.\n */\nexport async function svgCardToPngDataUri(\n card: InsertCardData,\n opts: SvgCardToPngOptions = {},\n): Promise<string> {\n return (await svgCardToPng(card, opts)).dataUri;\n}\n\n/**\n * Like {@link svgCardToPngDataUri} but also returns the **logical (un-scaled)**\n * card dimensions so consumers can size the inserted `<img width height>` and\n * drop their own supersampling shim. The PNG itself is rasterised at `scale`\n * (default `Math.max(2, devicePixelRatio)`) for crispness.\n */\nexport async function svgCardToPng(\n card: InsertCardData,\n opts: SvgCardToPngOptions = {},\n): Promise<InsertPngResult> {\n const { colours, scale = defaultRasterScale() } = opts;\n const resolved: ThemeColours = colours ?? readThemeColours(null);\n const brand = resolveBrand(card, opts.brand);\n const svg = buildResultCardSvg(card, resolved, brand);\n const imageDataUri = `data:image/svg+xml,${encodeURIComponent(svg)}`;\n const logicalW = SVG_W;\n const logicalH = svgHeight(card, brand);\n const blob = await rasteriseSvgToPng(\n imageDataUri,\n Math.round(logicalW * scale),\n Math.round(logicalH * scale),\n );\n const dataUri = await blobToDataUri(blob);\n return { dataUri, width: logicalW, height: logicalH };\n}\n\n/** Read a Blob back as a `data:` URI string. */\nfunction blobToDataUri(blob: Blob): Promise<string> {\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader();\n reader.onload = () => resolve(String(reader.result));\n reader.onerror = () =>\n reject(reader.error ?? new Error('FileReader error'));\n reader.readAsDataURL(blob);\n });\n}\n\n/** Build the per-mode ClipboardItem contents map for a copy. */\nasync function buildClipboardItem(\n mode: InsertMode,\n card: InsertCardData,\n colours: ThemeColours,\n): Promise<ClipboardItem> {\n const text = buildResultText(card);\n const textBlob = new Blob([text], { type: 'text/plain' });\n\n if (mode === 'text') {\n return new ClipboardItem({ 'text/plain': textBlob });\n }\n\n const brand = resolveBrand(card, undefined);\n const svg = buildResultCardSvg(card, colours, brand);\n const imageDataUri = `data:image/svg+xml,${encodeURIComponent(svg)}`;\n const scale = defaultRasterScale();\n const pngBlob = await rasteriseSvgToPng(\n imageDataUri,\n Math.round(SVG_W * scale),\n Math.round(svgHeight(card, brand) * scale),\n );\n\n if (mode === 'image') {\n return new ClipboardItem({ 'image/png': pngBlob, 'text/plain': textBlob });\n }\n\n const htmlBlob = new Blob([buildResultHtml(card)], { type: 'text/html' });\n return new ClipboardItem({\n 'text/html': htmlBlob,\n 'image/png': pngBlob,\n 'text/plain': textBlob,\n });\n}\n\n/* ------------------------------------------------------------------ */\n/* Component */\n/* ------------------------------------------------------------------ */\n\nconst rowVariants = cva(\n 'ds:inline-flex ds:items-center ds:gap-[var(--spacing-xs)]',\n {\n variants: {\n variant: {\n insert: '',\n copy: '',\n },\n },\n defaultVariants: { variant: 'insert' },\n },\n);\n\nconst MODES: readonly InsertMode[] = ['text', 'image', 'text-image'] as const;\n\nconst MODE_ICON: Record<InsertMode, React.ReactNode> = {\n text: <Type aria-hidden />,\n image: <ImageIcon aria-hidden />,\n 'text-image': <Layers aria-hidden />,\n};\n\n/* i18n leaf keys per variant × mode — bare keys against the `ui` namespace. */\nconst LABEL_KEY: Record<InsertVariant, Record<InsertMode, string>> = {\n insert: {\n text: 'insert.text',\n image: 'insert.image',\n 'text-image': 'insert.textImage',\n },\n copy: {\n text: 'insert.copyText',\n image: 'insert.copyImage',\n 'text-image': 'insert.copyTextImage',\n },\n};\n\nexport const InsertButton = forwardRef<HTMLDivElement, InsertButtonProps>(\n function InsertButton(\n {\n card,\n variant = 'insert',\n onInsert,\n onCopy,\n onError,\n size = 'sm',\n intent = 'primary',\n },\n ref,\n ) {\n const { t } = useTranslation();\n const probeRef = useRef<HTMLSpanElement>(null);\n\n const buildPayload = (mode: InsertMode): InsertPayload => {\n const text = buildResultText(card);\n const html = buildResultHtml(card);\n let svg = '';\n let imageDataUri = '';\n // Sample the live theme once, at click time (including any gauge/chip\n // token colours the card needs), so both the SVG fields and the lazy PNG\n // thunk paint with the same resolved colours.\n const colours =\n mode === 'text'\n ? null\n : readThemeColours(probeRef.current, extraTokensForCard(card));\n if (colours) {\n svg = buildResultCardSvg(card, colours, resolveBrand(card, undefined));\n imageDataUri = `data:image/svg+xml,${encodeURIComponent(svg)}`;\n }\n const pngDataUri = (): Promise<InsertPngResult> =>\n colours\n ? svgCardToPng(card, { colours })\n : Promise.resolve({ dataUri: '', width: 0, height: 0 });\n return { mode, text, html, svg, imageDataUri, pngDataUri };\n };\n\n const handleInsert = (mode: InsertMode): void => {\n onInsert?.(buildPayload(mode));\n };\n\n const handleCopy = (mode: InsertMode): void => {\n if (!canWriteRichClipboard()) {\n onError?.(new Error('Clipboard write unavailable in this context'));\n return;\n }\n const colours = readThemeColours(\n probeRef.current,\n extraTokensForCard(card),\n );\n void (async () => {\n try {\n const item = await buildClipboardItem(mode, card, colours);\n await navigator.clipboard.write([item]);\n onCopy?.(mode);\n } catch (error) {\n onError?.(error);\n }\n })();\n };\n\n const onActivate = variant === 'copy' ? handleCopy : handleInsert;\n\n return (\n <div\n ref={ref}\n data-component=\"insert-result\"\n data-variant={variant}\n className={rowVariants({ variant })}\n >\n {/* Hidden colour probes — sampled at click time so the SVG card uses\n the live theme's resolved colours (no literals in source). The\n fixed five plus any per-card gauge/chip token colours. */}\n <span ref={probeRef} aria-hidden className=\"ds:sr-only\">\n {PROBE_KEYS.map((k) => (\n <span\n key={k}\n data-k={k}\n className={\n k === 'fg'\n ? 'ds:text-foreground'\n : k === 'muted'\n ? 'ds:text-muted-foreground'\n : k === 'accent'\n ? 'ds:text-[color:var(--primary)]'\n : k === 'border'\n ? 'ds:text-[color:var(--border)]'\n : 'ds:text-[color:var(--card)]'\n }\n />\n ))}\n {extraTokensForCard(card).map((token) => (\n <span\n key={token}\n data-token={tokenName(token)}\n className={probeClassForToken(token)}\n />\n ))}\n </span>\n {MODES.map((mode) => (\n <Button\n key={mode}\n type=\"button\"\n intent={intent}\n size={size}\n startIcon={MODE_ICON[mode]}\n aria-label={t(LABEL_KEY[variant][mode])}\n onClick={() => onActivate(mode)}\n >\n {t(LABEL_KEY[variant][mode])}\n </Button>\n ))}\n </div>\n );\n },\n);\n\nInsertButton.displayName = 'InsertButton';\n"],"names":["__iconNode","Type","createLucideIcon","BMI_BANDED_MIN","BMI_BANDED_MAX","BMI_BAND_THRESHOLDS","bmiBands","INSET_X","BAR_H","BAR_RADIUS","VALUE_LABEL_BASELINE","BAR_TOP_GAP","TICK_LABEL_GAP","scaleToX","value","min","max","barStart","barEnd","t","computeBandedGaugeGeometry","model","width","height","barY","valueLabelY","tickLabelY","cursor","bands","band","lower","upper","x","xEnd","rawX","overflow","markerX","ticks","summaryLabel","r2","n","escapeXml","s","bandPath","y","w","h","rL","rR","x2","y2","tr","br","bl","tl","buildBandedGaugeSvgString","geometry","options","resolve","font","fg","muted","track","fontFamily","rail","bandCount","bandRects","i","fill","tickY1","tickY2","tick","rule","label","mx","ruleTop","ruleBottom","markerRule","triTop","triangle","caret","cy","tipX","valueLabel","summary","title","DEFAULT_WIDTH","DEFAULT_HEIGHT","cssVarResolver","colorToken","BandedGauge","forwardRef","className","ref","g","caretCy","jsxs","jsx","ICON_VIEWBOX","ICON_SLOT","FIELD_ICON_SLOT","ICON_GEOMETRY","isIconKey","key","buildIconGroup","icon","colour","slot","scale","isBandedGauge","gauge","PROBE_KEYS","DEFAULT_HIGHLIGHT_TOKEN","SVG_W","tokenName","token","probeClassForToken","categoryFillToken","card","extraTokensForCard","wanted","category","readThemeColours","probe","extraTokens","fallback","read","el","tokens","resolveToken","c","_a","buildResultText","lines","f","buildResultHtml","items","highlight","PAD","TITLE_BASELINE","CHIP_H","CHIP_GAP","ROW_H","FIELDS_GAP","FOOTER_GAP","FOOTER_H","GAUGE_R","GAUGE_STROKE","GAUGE_BOX","BANDED_GAUGE_GAP","HEADER_ICON_BOX","FIELD_ICON_GAP","FIELD_TEXT_X","FIELD_TEXT_BUDGET","FIELD_LABEL_SIZE","PRIMARY_VALUE_SIZE","FIELD_VALUE_SIZE","WRAP_LINE_H","isWideGlyph","code","estimateTextWidth","text","fontSize","units","ch","hardBreak","maxWidth","out","cur","wrapToWidth","pushBroken","pieces","candidate","placeFields","placements","dy","field","index","valueSize","last","endDy","resolveBrand","override","gaugeFraction","v","layoutCard","hasBrand","hasChip","chipY","firstFieldY","fieldsEndY","banded","gaugeFloor","bandedGaugeY","bandedBottom","BANDED_GAUGE_HEIGHT","contentBottom","footerY","svgHeight","brand","buildGauge","cx","circumference","frac","arc","segments","gap","segLen","trackDash","valueDash","rotate","valueArc","centreValue","centreLabel","buildBandedGauge","cardWidth","offsetX","BANDED_GAUGE_INSET_X","geometryWidth","group","parseRgb","m","relativeLuminance","r","b","lin","contrastRatio","a","ca","cb","la","lb","buildChip","fillToken","textColour","chipW","textX","textY","buildResultCardSvg","W","L","H","categoryToken","categorySolid","headerIcon","rows","baseY","isPrimary","valueWeight","valueFill","markerCy","marker","line","li","chip","footer","surface","outline","canWriteRichClipboard","rasteriseSvgToPng","imageDataUri","reject","img","canvas","ctx","blob","defaultRasterScale","dpr","svgCardToPngDataUri","opts","svgCardToPng","colours","resolved","svg","logicalW","logicalH","blobToDataUri","reader","buildClipboardItem","mode","textBlob","pngBlob","htmlBlob","rowVariants","cva","MODES","MODE_ICON","ImageIcon","Layers","LABEL_KEY","InsertButton","variant","onInsert","onCopy","onError","size","intent","useTranslation","probeRef","useRef","buildPayload","html","onActivate","item","error","k","Button"],"mappings":";;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,MAAMA,KAAa;AAAA,EACjB,CAAC,QAAQ,EAAE,GAAG,YAAY,KAAK,SAAQ,CAAE;AAAA,EACzC,CAAC,QAAQ,EAAE,GAAG,2CAA2C,KAAK,SAAQ,CAAE;AAAA,EACxE,CAAC,QAAQ,EAAE,GAAG,WAAW,KAAK,SAAQ,CAAE;AAC1C,GACMC,KAAOC,GAAiB,QAAQF,EAAU,GCmEnCG,KAAiB,IACjBC,KAAiB,IAGjBC,KAAsB,CAAC,MAAM,IAAI,EAAE;AAezC,SAASC,KAKd;AACA,SAAO;AAAA,IACL,OAAO;AAAA,MACL,EAAE,MAAM,MAAM,YAAY,SAAA;AAAA,MAC1B,EAAE,MAAM,IAAI,YAAY,YAAA;AAAA,MACxB,EAAE,MAAM,IAAI,YAAY,qBAAA;AAAA,MACxB,EAAE,MAAMF,IAAgB,YAAY,gBAAA;AAAA,IAAgB;AAAA,IAEtD,KAAKD;AAAA,IACL,KAAKC;AAAA,IACL,OAAO,CAAC,GAAGC,EAAmB;AAAA,EAAA;AAElC;AAmFO,MAAME,IAAU,IACjBC,IAAQ,IACRC,KAAaD,IAAQ,GACrBE,KAAuB,IACvBC,KAAc,IACdC,KAAiB;AAGvB,SAASC,EACPC,GACAC,GACAC,GACAC,GACAC,GACQ;AACR,MAAIF,KAAOD,EAAK,QAAOE;AACvB,QAAME,KAAKL,IAAQC,MAAQC,IAAMD;AACjC,SAAOE,I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